mirror of
https://github.com/Doodle3D/Doodle3D-Core.git
synced 2024-12-22 19:13:49 +01:00
update 3d cut
This commit is contained in:
parent
3bce03175a
commit
7a93b3e5c8
54
src/d3/ShapeMesh.js
vendored
54
src/d3/ShapeMesh.js
vendored
@ -62,18 +62,30 @@ class ShapeMesh extends THREE.Object3D {
|
|||||||
this._color = color;
|
this._color = color;
|
||||||
this._fill = fill;
|
this._fill = fill;
|
||||||
|
|
||||||
this.visible = shapeData.solid;
|
|
||||||
|
|
||||||
this.updatePoints(shapeData);
|
this.updatePoints(shapeData);
|
||||||
|
|
||||||
this._checkHoles(holes, active);
|
this._checkHoles(holes, active);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
add(object) {
|
||||||
|
if (!this.children.includes(object)) super.add(object);
|
||||||
|
}
|
||||||
|
remove(object) {
|
||||||
|
if (this.children.includes(object)) super.remove(object);
|
||||||
|
}
|
||||||
|
|
||||||
_checkHoles(holes, active) {
|
_checkHoles(holes, active) {
|
||||||
|
let changed = false;
|
||||||
|
|
||||||
|
const visible = this._shapeData.solid || active;
|
||||||
|
if (visible !== this.visible) {
|
||||||
|
this.visible = visible;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (active) {
|
if (active) {
|
||||||
this._holeMesh.visible = false;
|
this.remove(this._holeMesh);
|
||||||
this._mesh.visible = true;
|
this.add(this._mesh);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
holes = holes.map(hole => hole.mesh._mesh);
|
holes = holes.map(hole => hole.mesh._mesh);
|
||||||
@ -84,23 +96,26 @@ class ShapeMesh extends THREE.Object3D {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (holes.length === 0) {
|
if (holes.length === 0) {
|
||||||
this._holeMesh.visible = false;
|
this.remove(this._holeMesh);
|
||||||
this._mesh.visible = true;
|
this.add(this._mesh);
|
||||||
return false;
|
return changed;
|
||||||
}
|
}
|
||||||
// is coliding with holes
|
// is coliding with holes
|
||||||
|
|
||||||
const objectGeometry = new THREE.Geometry().fromBufferGeometry(this._mesh.geometry);
|
const objectGeometry = new THREE.Geometry().fromBufferGeometry(this._mesh.geometry);
|
||||||
let objectBSP = new THREE_BSP(objectGeometry);
|
let objectBSP = new THREE_BSP(objectGeometry);
|
||||||
|
objectGeometry.dispose();
|
||||||
for (const hole of holes) {
|
for (const hole of holes) {
|
||||||
const holeGeometry = new THREE.Geometry().fromBufferGeometry(hole.geometry);
|
const holeGeometry = new THREE.Geometry().fromBufferGeometry(hole.geometry);
|
||||||
const holeBSP = new THREE_BSP(holeGeometry)
|
const holeBSP = new THREE_BSP(holeGeometry);
|
||||||
|
holeGeometry.dispose();
|
||||||
objectBSP = objectBSP.subtract(holeBSP)
|
objectBSP = objectBSP.subtract(holeBSP)
|
||||||
}
|
}
|
||||||
|
this._holeMesh.geometry.dispose();
|
||||||
this._holeMesh.geometry = objectBSP.toMesh().geometry;
|
this._holeMesh.geometry = objectBSP.toMesh().geometry;
|
||||||
|
|
||||||
this._holeMesh.visible = true;
|
this.add(this._holeMesh);
|
||||||
this._mesh.visible = false;
|
this.remove(this._mesh);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,12 +152,6 @@ class ShapeMesh extends THREE.Object3D {
|
|||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!shapeData.solid) {
|
|
||||||
this.visible = shapeData.solid || active;
|
|
||||||
this.setOpaque(true);
|
|
||||||
changed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this._checkHoles(holes, active)) {
|
if (this._checkHoles(holes, active)) {
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
@ -152,12 +161,19 @@ class ShapeMesh extends THREE.Object3D {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setOpaque(opaque) {
|
setOpaque(opaque) {
|
||||||
this._mesh.material.opacity = opaque ? 1.0 : 1.0 - DESELECT_TRANSPARENCY;
|
let opacity;
|
||||||
this._mesh.material.transparent = !opaque;
|
if (this._shapeData.solid) {
|
||||||
|
opacity = opaque ? 1.0 : DESELECT_TRANSPARENCY;
|
||||||
|
} else {
|
||||||
|
opacity = 0.0;
|
||||||
|
}
|
||||||
|
this._mesh.material.opacity = opacity;
|
||||||
|
this._mesh.material.transparent = opacity !== 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
this._mesh.geometry.dispose();
|
this._mesh.geometry.dispose();
|
||||||
|
this._meshHole.geometry.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
updatePoints(shapeData) {
|
updatePoints(shapeData) {
|
||||||
|
@ -72,6 +72,12 @@ function shapeDataToShapeRaw(shapeData) {
|
|||||||
|
|
||||||
// TODO can maybe be memoized
|
// TODO can maybe be memoized
|
||||||
export const determineActiveShape = (state) => {
|
export const determineActiveShape = (state) => {
|
||||||
|
const activeTransformer = state.d2.eraser.active ||
|
||||||
|
state.d2.transform.active ||
|
||||||
|
state.d3.height.active ||
|
||||||
|
state.d3.sculpt.activeHandle !== null ||
|
||||||
|
state.d3.twist.active;
|
||||||
|
|
||||||
const selectedObjects = state.selection.objects.map(({ id }) => id);
|
const selectedObjects = state.selection.objects.map(({ id }) => id);
|
||||||
const activeShapes = {};
|
const activeShapes = {};
|
||||||
for (const id in state.objectsById) {
|
for (const id in state.objectsById) {
|
||||||
@ -79,7 +85,11 @@ export const determineActiveShape = (state) => {
|
|||||||
activeShapes[id] = true;
|
activeShapes[id] = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
activeShapes[id] = state.d2.transform.active && selectedObjects.includes(id);
|
if (activeTransformer && !state.objectsById[id].solid) {
|
||||||
|
activeShapes[id] = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
activeShapes[id] = selectedObjects.includes(id) && activeTransformer;
|
||||||
}
|
}
|
||||||
return activeShapes;
|
return activeShapes;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user