From 0402dc772b5800a3e7b2b54c77e76f16bcf7205c Mon Sep 17 00:00:00 2001 From: martinRenou Date: Wed, 26 Jun 2024 16:20:47 +0100 Subject: [PATCH] Workaround extruction non-solid issue (#373) * Workaround extruction non-solid issue * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove console --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- packages/base/src/3dview/helpers.ts | 64 +++++++++++++++------------ packages/base/src/3dview/mainview.tsx | 8 ++++ 2 files changed, 43 insertions(+), 29 deletions(-) diff --git a/packages/base/src/3dview/helpers.ts b/packages/base/src/3dview/helpers.ts index 697c866c..f47937ca 100644 --- a/packages/base/src/3dview/helpers.ts +++ b/packages/base/src/3dview/helpers.ts @@ -112,13 +112,14 @@ export function buildShape(options: { data: IParsedShape; clippingPlanes: THREE.Plane[]; selected: boolean; + isSolid: boolean; guidata?: IDict; }): { meshGroup: THREE.Group; mainMesh: THREE.Mesh; edgesMeshes: LineSegments2[]; } | null { - const { objName, data, guidata, clippingPlanes, selected } = options; + const { objName, data, guidata, isSolid, clippingPlanes, selected } = options; const { faceList, edgeList, jcObject } = data; const vertices: Array = []; @@ -191,34 +192,39 @@ export function buildShape(options: { meshGroup.name = `${objName}-group`; meshGroup.visible = visible; - const baseMat = new THREE.MeshBasicMaterial(); - baseMat.depthWrite = false; - baseMat.depthTest = false; - baseMat.colorWrite = false; - baseMat.stencilWrite = true; - baseMat.stencilFunc = THREE.AlwaysStencilFunc; - - // back faces - const mat0 = baseMat.clone(); - mat0.side = THREE.BackSide; - mat0.clippingPlanes = clippingPlanes; - mat0.stencilFail = THREE.IncrementWrapStencilOp; - mat0.stencilZFail = THREE.IncrementWrapStencilOp; - mat0.stencilZPass = THREE.IncrementWrapStencilOp; - const backFaces = new THREE.Mesh(geometry, mat0); - backFaces.name = `${objName}-back`; - meshGroup.add(backFaces); - - // front faces - const mat1 = baseMat.clone(); - mat1.side = THREE.FrontSide; - mat1.clippingPlanes = clippingPlanes; - mat1.stencilFail = THREE.DecrementWrapStencilOp; - mat1.stencilZFail = THREE.DecrementWrapStencilOp; - mat1.stencilZPass = THREE.DecrementWrapStencilOp; - const frontFaces = new THREE.Mesh(geometry, mat1); - frontFaces.name = `${objName}-front`; - meshGroup.add(frontFaces); + // We only build the stencil logic for solid meshes + if (isSolid) { + const baseMat = new THREE.MeshBasicMaterial(); + baseMat.depthWrite = false; + baseMat.depthTest = false; + baseMat.colorWrite = false; + baseMat.stencilWrite = true; + baseMat.stencilFunc = THREE.AlwaysStencilFunc; + + // back faces + const mat0 = baseMat.clone(); + mat0.side = THREE.BackSide; + mat0.clippingPlanes = clippingPlanes; + mat0.stencilFail = THREE.IncrementWrapStencilOp; + mat0.stencilZFail = THREE.IncrementWrapStencilOp; + mat0.stencilZPass = THREE.IncrementWrapStencilOp; + const backFaces = new THREE.Mesh(geometry, mat0); + backFaces.name = `${objName}-back`; + meshGroup.add(backFaces); + + // front faces + const mat1 = baseMat.clone(); + mat1.side = THREE.FrontSide; + mat1.clippingPlanes = clippingPlanes; + mat1.stencilFail = THREE.DecrementWrapStencilOp; + mat1.stencilZFail = THREE.DecrementWrapStencilOp; + mat1.stencilZPass = THREE.DecrementWrapStencilOp; + const frontFaces = new THREE.Mesh(geometry, mat1); + frontFaces.name = `${objName}-front`; + meshGroup.add(frontFaces); + } else { + material.side = THREE.DoubleSide; + } const mainMesh = new THREE.Mesh(geometry, material); mainMesh.name = objName; diff --git a/packages/base/src/3dview/mainview.tsx b/packages/base/src/3dview/mainview.tsx index 3588f6e2..390a4b48 100644 --- a/packages/base/src/3dview/mainview.tsx +++ b/packages/base/src/3dview/mainview.tsx @@ -585,11 +585,19 @@ export class MainView extends React.Component { Object.entries(payload).forEach(([objName, data]) => { const selected = selectedNames.includes(objName); + const obj = this._model.sharedModel.getObjectByName(objName); + + // TODO Have a more generic way to spot non-solid objects + const isSolid = !( + obj!.shape === 'Part::Extrusion' && !obj!.parameters?.['Solid'] + ); + const output = buildShape({ objName, data, clippingPlanes: this._clippingPlanes, selected, + isSolid, guidata });