更新爆炸图例子
This commit is contained in:
parent
bda2b05204
commit
d79d759091
2
config/umd/cad.js
Normal file
2
config/umd/cad.js
Normal file
File diff suppressed because one or more lines are too long
1
config/umd/cad.js.map
Normal file
1
config/umd/cad.js.map
Normal file
File diff suppressed because one or more lines are too long
@ -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;
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -1,9 +1,11 @@
|
||||
// import { Color, Face3, MeshBasicMaterial, Object3D, Vector2, Vector3 } from "three";
|
||||
// import "./style.css";
|
||||
import { data } from "../data";
|
||||
import { Viewer } from "../Viewer";
|
||||
import { Vector3 } from "three";
|
||||
import { CameraControlState } from "../CameraControls";
|
||||
import { data } from "../data";
|
||||
import { GetBox } from "../GeUtils";
|
||||
import { LoadBoard } from "../Utils";
|
||||
import { Viewer } from "../Viewer";
|
||||
|
||||
let btn = document.createElement("button");
|
||||
btn.innerHTML = "载入"
|
||||
@ -13,6 +15,10 @@ let btn2 = document.createElement("button");
|
||||
btn2.innerHTML = "清理"
|
||||
document.body.appendChild(btn2);
|
||||
|
||||
let btn3 = document.createElement("button");
|
||||
btn3.innerHTML = "爆炸图"
|
||||
document.body.appendChild(btn3);
|
||||
|
||||
let el = document.createElement("canvas");
|
||||
|
||||
el.style.width = "80%";
|
||||
@ -39,3 +45,51 @@ btn2.onclick = () =>
|
||||
{
|
||||
// LoadBoard(view, []);
|
||||
}
|
||||
|
||||
btn3.onclick = () =>
|
||||
{
|
||||
let box = GetBox(view.m_Scene);
|
||||
|
||||
let cen = box.getCenter(new Vector3());
|
||||
let m = [];
|
||||
for (let obj of view.m_Scene.children)
|
||||
{
|
||||
if (obj.userData && obj.userData instanceof Vector3)
|
||||
{
|
||||
let objCen = GetBox(obj).getCenter(new Vector3());
|
||||
|
||||
let v = objCen.clone().sub(cen);
|
||||
|
||||
let zv = obj.userData as Vector3;
|
||||
if (zv instanceof Vector3)
|
||||
{
|
||||
let d = zv.dot(v);
|
||||
// m.set(obj, zv.clone().multiplyScalar(d));
|
||||
m.push([obj, zv.clone().multiplyScalar(d)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let count = 0;
|
||||
|
||||
let t = setInterval(() =>
|
||||
{
|
||||
for (let [o, v] of m)
|
||||
{
|
||||
o.position.add(
|
||||
v.clone().multiplyScalar(1.5 / 120)
|
||||
);
|
||||
o.updateMatrix();
|
||||
}
|
||||
|
||||
view.ZoomAll();
|
||||
|
||||
view.m_bNeedUpdate = true;
|
||||
|
||||
count++;
|
||||
|
||||
if (count === 60)
|
||||
clearInterval(t);
|
||||
}, 16)
|
||||
}
|
||||
|
@ -90,7 +90,6 @@ export function createBoard(boardData: object)
|
||||
let boardMat = new THREE.Matrix4();
|
||||
let matInv: THREE.Matrix4 = new THREE.Matrix4();
|
||||
//InitBoardMat
|
||||
{
|
||||
let xD = getVec(boardData["XVec"]);
|
||||
let yD = getVec(boardData["YVec"]);
|
||||
let ZD = getVec(boardData["ZVec"]);
|
||||
@ -99,7 +98,6 @@ export function createBoard(boardData: object)
|
||||
boardMat.makeBasis(xD, yD, ZD);
|
||||
boardMat.setPosition(pBase);
|
||||
matInv.getInverse(boardMat, true);
|
||||
}
|
||||
|
||||
if (boardPts && boardPts.length !== 0)
|
||||
for (let i = 0; i < boardPts.length; i++)
|
||||
@ -188,6 +186,8 @@ export function createBoard(boardData: object)
|
||||
RotateUVs(ext);
|
||||
|
||||
let mesh = new THREE.Mesh(ext, boardMaterial);
|
||||
mesh.userData = ZD;
|
||||
edges.forEach(e => e.userData = ZD);
|
||||
return { mesh, edges };
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user