更新爆炸图例子
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import * as THREE from 'three';
|
||||
import { Geometry, Vector, Vector2, Vector3 } from 'three';
|
||||
import { Geometry, Vector, Vector2, Vector3, Box3 } from 'three';
|
||||
import { Matrix2 } from './Matrix2';
|
||||
|
||||
|
||||
@@ -168,51 +168,47 @@ export function midPtCir(v1: THREE.Vector3, v2: THREE.Vector3)
|
||||
return v1.clone().add(midLine);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得Three对象的包围盒.
|
||||
* @param obj
|
||||
* @param [updateMatrix] 是否应该更新对象矩阵
|
||||
* @returns box
|
||||
*/
|
||||
export function GetBox(obj: THREE.Object3D, updateMatrix?: boolean): THREE.Box3
|
||||
{
|
||||
let box = new Box3();
|
||||
if (updateMatrix) obj.updateMatrixWorld(false);
|
||||
if (obj.hasOwnProperty("geometry"))
|
||||
if (!obj.visible) return box;
|
||||
|
||||
obj.traverse(o =>
|
||||
{
|
||||
let geo = obj["geometry"];
|
||||
if (geo instanceof THREE.Geometry || geo instanceof THREE.BufferGeometry)
|
||||
//因为实体Erase时,实体仍然保存在Scene中.
|
||||
if (o.visible === false)
|
||||
return;
|
||||
|
||||
//@ts-ignore
|
||||
let geo = o.geometry as BufferGeometry;
|
||||
if (geo)
|
||||
{
|
||||
if (!geo.boundingBox)
|
||||
geo.computeBoundingBox();
|
||||
return geo.boundingBox.clone().applyMatrix4(obj.matrixWorld);
|
||||
box.union(geo.boundingBox.clone().applyMatrix4(o.matrixWorld));
|
||||
}
|
||||
}
|
||||
else if (obj.children.length > 0)
|
||||
{
|
||||
let box = obj.children.reduce((sumBox, itemObj) =>
|
||||
{
|
||||
let itemBox = GetBox(itemObj);
|
||||
if (itemBox)
|
||||
sumBox.union(itemBox);
|
||||
return sumBox;
|
||||
}, new THREE.Box3())
|
||||
// if (box) box.applyMatrix4(obj.matrixWorld);
|
||||
return box;
|
||||
}
|
||||
else
|
||||
return null;
|
||||
});
|
||||
|
||||
return box;
|
||||
}
|
||||
|
||||
export function GetBoxArr(arr: Array<THREE.Object3D>): THREE.Box3
|
||||
{
|
||||
if (arr.length == 0)
|
||||
let box = new Box3();
|
||||
for (let o of arr)
|
||||
{
|
||||
return null;
|
||||
let b = GetBox(o);
|
||||
if (!b.isEmpty())
|
||||
box.union(b);
|
||||
}
|
||||
return arr.map(o =>
|
||||
{
|
||||
return GetBox(o);
|
||||
}).filter(o =>
|
||||
{
|
||||
return o;
|
||||
}).reduce((sumBox: THREE.Box3, objBox: THREE.Box3) =>
|
||||
{
|
||||
return sumBox.union(objBox)
|
||||
}, new THREE.Box3());
|
||||
return box;
|
||||
}
|
||||
|
||||
export function MoveMatrix(v: THREE.Vector3): THREE.Matrix4
|
||||
|
||||
Reference in New Issue
Block a user