-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
InstancedMeshBVH: optional get box from boundingSphere (#10)
- Loading branch information
Showing
6 changed files
with
94 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@three.ez/instanced-mesh", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "Simplified and enhanced InstancedMesh with frustum culling, fast raycasting (using BVH), sorting, visibility management and more.", | ||
"author": "Andrea Gargaro <[email protected]>", | ||
"license": "MIT", | ||
|
@@ -21,7 +21,8 @@ | |
"performance", | ||
"BVH", | ||
"acceleration", | ||
"raycasting" | ||
"raycasting", | ||
"LOD" | ||
], | ||
"scripts": { | ||
"start": "vite", | ||
|
@@ -36,7 +37,7 @@ | |
"devDependencies": { | ||
"@eslint/js": "^9.10.0", | ||
"@three.ez/main": "^0.5.7", | ||
"@types/three": "^0.168.0", | ||
"@types/three": "^0.169.0", | ||
"eslint": "^9.9.0", | ||
"typescript": "^5.1.3", | ||
"typescript-eslint": "^8.1.0", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { FloatArray } from "bvh.js"; | ||
|
||
export interface SphereTarget { | ||
centerX: number; | ||
centerY: number; | ||
centerZ: number; | ||
maxScale: number; | ||
} | ||
|
||
// this method works if geometry is centered | ||
export function getSphereFromMatrix(id: number, array: FloatArray, target: SphereTarget): SphereTarget { | ||
const offset = id * 16; | ||
|
||
// get max scale from matrix | ||
const m0 = array[offset + 0]; | ||
const m1 = array[offset + 1]; | ||
const m2 = array[offset + 2]; | ||
const m4 = array[offset + 4]; | ||
const m5 = array[offset + 5]; | ||
const m6 = array[offset + 6]; | ||
const m8 = array[offset + 8]; | ||
const m9 = array[offset + 9]; | ||
const m10 = array[offset + 10]; | ||
|
||
const scaleXSq = m0 * m0 + m1 * m1 + m2 * m2; | ||
const scaleYSq = m4 * m4 + m5 * m5 + m6 * m6; | ||
const scaleZSq = m8 * m8 + m9 * m9 + m10 * m10; | ||
|
||
target.maxScale = Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq)); | ||
|
||
// get position from matrix | ||
target.centerX = array[offset + 12]; | ||
target.centerY = array[offset + 13]; | ||
target.centerZ = array[offset + 14]; | ||
|
||
return target; | ||
} |