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;
|
if (holes === this._holes && !this._changedGeometry) return false;
|
||||||
|
|
||||||
const fill = this._shapeData.type === 'EXPORT_SHAPE' ? !this._shapeData.originalFill : !this._fill;
|
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;
|
if (this._holeMeshIsOriginal && !this._changedGeometry) return false;
|
||||||
|
|
||||||
this._holeMesh.geometry.dispose();
|
this._holeMesh.geometry.dispose();
|
||||||
@ -76,10 +76,16 @@ class ShapeMesh extends THREE.Object3D {
|
|||||||
|
|
||||||
const objectGeometry = new THREE.Geometry().fromBufferGeometry(this._mesh.geometry);
|
const objectGeometry = new THREE.Geometry().fromBufferGeometry(this._mesh.geometry);
|
||||||
objectGeometry.mergeVertices();
|
objectGeometry.mergeVertices();
|
||||||
let objectBSP = new THREE_BSP(objectGeometry);
|
const box = new THREE.Box3().setFromPoints(objectGeometry.vertices);
|
||||||
|
let bsp = new THREE_BSP(objectGeometry);
|
||||||
objectGeometry.dispose();
|
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._holes = holes;
|
||||||
this._changedGeometry = false;
|
this._changedGeometry = false;
|
||||||
|
40
src/d3/ShapesManager.js
vendored
40
src/d3/ShapesManager.js
vendored
@ -14,7 +14,7 @@ export default class ShapesManager extends THREE.Object3D {
|
|||||||
this._spaces = {};
|
this._spaces = {};
|
||||||
this.name = 'shapes-manager';
|
this.name = 'shapes-manager';
|
||||||
|
|
||||||
this._holes = null;
|
this._holes = [];
|
||||||
|
|
||||||
// this._edges = {};
|
// this._edges = {};
|
||||||
}
|
}
|
||||||
@ -77,23 +77,33 @@ export default class ShapesManager extends THREE.Object3D {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (holesChanged) {
|
if (holesChanged) {
|
||||||
this._holes = null;
|
this._holes = [];
|
||||||
for (let i = 0; i < ids.length; i ++) {
|
for (let i = 0; i < ids.length; i ++) {
|
||||||
const id = ids[i];
|
const id = ids[i];
|
||||||
|
if (activeShapes[id]) continue;
|
||||||
|
|
||||||
const { solid, type } = state.objectsById[id];
|
const { solid, type } = state.objectsById[id];
|
||||||
const d3Visible = SHAPE_TYPE_PROPERTIES[type].D3Visible;
|
const d3Visible = SHAPE_TYPE_PROPERTIES[type].D3Visible;
|
||||||
if (!solid && d3Visible) {
|
if (solid || !d3Visible) continue;
|
||||||
const hole = this._meshes[id].mesh._mesh;
|
|
||||||
const holeGeometry = new THREE.Geometry().fromBufferGeometry(hole.geometry);
|
const holeMesh = this._meshes[id].mesh._mesh;
|
||||||
if (holeGeometry.vertices.length === 0) continue;
|
const geometry = new THREE.Geometry().fromBufferGeometry(holeMesh.geometry);
|
||||||
const holeBSP = new THREE_BSP(holeGeometry);
|
if (geometry.vertices.length === 0) continue;
|
||||||
if (!this._holes) {
|
|
||||||
this._holes = holeBSP;
|
const box = new THREE.Box3().setFromPoints(geometry.vertices);
|
||||||
} else {
|
const intersectHole = this._holes.find(hole => hole.box.intersectsBox(box));
|
||||||
this._holes = this._holes.union(holeBSP);
|
|
||||||
}
|
const bsp = new THREE_BSP(geometry);
|
||||||
holeGeometry.dispose();
|
|
||||||
|
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.push({ bsp, box });
|
||||||
}
|
}
|
||||||
|
geometry.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,9 +114,7 @@ export default class ShapesManager extends THREE.Object3D {
|
|||||||
const d3Visible = SHAPE_TYPE_PROPERTIES[type].D3Visible;
|
const d3Visible = SHAPE_TYPE_PROPERTIES[type].D3Visible;
|
||||||
if (!active && solid && d3Visible) {
|
if (!active && solid && d3Visible) {
|
||||||
const shape = this._meshes[id].mesh;
|
const shape = this._meshes[id].mesh;
|
||||||
if (shape.updateHoleGeometry(this._holes)) {
|
if (shape.updateHoleGeometry(this._holes)) render = true;
|
||||||
render = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user