mirror of
https://github.com/Doodle3D/Doodle3D-Core.git
synced 2024-12-22 11:03:48 +01:00
increase performance of holes
This commit is contained in:
parent
ab27e7c8c2
commit
834ca531fd
14
src/d3/ShapeMesh.js
vendored
14
src/d3/ShapeMesh.js
vendored
@ -64,7 +64,7 @@ class ShapeMesh extends THREE.Object3D {
|
||||
if (holes === this._holes && !this._changedGeometry) return false;
|
||||
|
||||
const fill = this._shapeData.type === 'EXPORT_SHAPE' ? !this._shapeData.originalFill : !this._fill;
|
||||
if (holes === null || fill) {
|
||||
if (holes.length === 0 || fill) {
|
||||
if (this._holeMeshIsOriginal && !this._changedGeometry) return false;
|
||||
|
||||
this._holeMesh.geometry.dispose();
|
||||
@ -76,10 +76,16 @@ class ShapeMesh extends THREE.Object3D {
|
||||
|
||||
const objectGeometry = new THREE.Geometry().fromBufferGeometry(this._mesh.geometry);
|
||||
objectGeometry.mergeVertices();
|
||||
let objectBSP = new THREE_BSP(objectGeometry);
|
||||
const box = new THREE.Box3().setFromPoints(objectGeometry.vertices);
|
||||
let bsp = new THREE_BSP(objectGeometry);
|
||||
objectGeometry.dispose();
|
||||
objectBSP = objectBSP.subtract(holes);
|
||||
this._holeMesh.geometry = objectBSP.toMesh().geometry;
|
||||
|
||||
for (const hole of holes) {
|
||||
if (hole.box.intersectsBox(box)) {
|
||||
bsp = bsp.subtract(hole.bsp);
|
||||
}
|
||||
}
|
||||
this._holeMesh.geometry = bsp.toMesh().geometry;
|
||||
|
||||
this._holes = holes;
|
||||
this._changedGeometry = false;
|
||||
|
38
src/d3/ShapesManager.js
vendored
38
src/d3/ShapesManager.js
vendored
@ -14,7 +14,7 @@ export default class ShapesManager extends THREE.Object3D {
|
||||
this._spaces = {};
|
||||
this.name = 'shapes-manager';
|
||||
|
||||
this._holes = null;
|
||||
this._holes = [];
|
||||
|
||||
// this._edges = {};
|
||||
}
|
||||
@ -77,23 +77,33 @@ export default class ShapesManager extends THREE.Object3D {
|
||||
}
|
||||
|
||||
if (holesChanged) {
|
||||
this._holes = null;
|
||||
this._holes = [];
|
||||
for (let i = 0; i < ids.length; i ++) {
|
||||
const id = ids[i];
|
||||
if (activeShapes[id]) continue;
|
||||
|
||||
const { solid, type } = state.objectsById[id];
|
||||
const d3Visible = SHAPE_TYPE_PROPERTIES[type].D3Visible;
|
||||
if (!solid && d3Visible) {
|
||||
const hole = this._meshes[id].mesh._mesh;
|
||||
const holeGeometry = new THREE.Geometry().fromBufferGeometry(hole.geometry);
|
||||
if (holeGeometry.vertices.length === 0) continue;
|
||||
const holeBSP = new THREE_BSP(holeGeometry);
|
||||
if (!this._holes) {
|
||||
this._holes = holeBSP;
|
||||
if (solid || !d3Visible) continue;
|
||||
|
||||
const holeMesh = this._meshes[id].mesh._mesh;
|
||||
const geometry = new THREE.Geometry().fromBufferGeometry(holeMesh.geometry);
|
||||
if (geometry.vertices.length === 0) continue;
|
||||
|
||||
const box = new THREE.Box3().setFromPoints(geometry.vertices);
|
||||
const intersectHole = this._holes.find(hole => hole.box.intersectsBox(box));
|
||||
|
||||
const bsp = new THREE_BSP(geometry);
|
||||
|
||||
if (intersectHole) {
|
||||
intersectHole.bsp = intersectHole.bsp.union(bsp);
|
||||
const min = box.min.min(intersectHole.box.min);
|
||||
const max = box.max.max(intersectHole.box.max);
|
||||
intersectHole.box = new THREE.Box3(min, max);
|
||||
} else {
|
||||
this._holes = this._holes.union(holeBSP);
|
||||
}
|
||||
holeGeometry.dispose();
|
||||
this._holes.push({ bsp, box });
|
||||
}
|
||||
geometry.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@ -104,9 +114,7 @@ export default class ShapesManager extends THREE.Object3D {
|
||||
const d3Visible = SHAPE_TYPE_PROPERTIES[type].D3Visible;
|
||||
if (!active && solid && d3Visible) {
|
||||
const shape = this._meshes[id].mesh;
|
||||
if (shape.updateHoleGeometry(this._holes)) {
|
||||
render = true;
|
||||
}
|
||||
if (shape.updateHoleGeometry(this._holes)) render = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user