Skip to content

Commit 0402dc7

Browse files
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>
1 parent b49785e commit 0402dc7

File tree

2 files changed

+43
-29
lines changed

2 files changed

+43
-29
lines changed

packages/base/src/3dview/helpers.ts

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,14 @@ export function buildShape(options: {
112112
data: IParsedShape;
113113
clippingPlanes: THREE.Plane[];
114114
selected: boolean;
115+
isSolid: boolean;
115116
guidata?: IDict;
116117
}): {
117118
meshGroup: THREE.Group;
118119
mainMesh: THREE.Mesh<THREE.BufferGeometry, THREE.MeshPhongMaterial>;
119120
edgesMeshes: LineSegments2[];
120121
} | null {
121-
const { objName, data, guidata, clippingPlanes, selected } = options;
122+
const { objName, data, guidata, isSolid, clippingPlanes, selected } = options;
122123
const { faceList, edgeList, jcObject } = data;
123124

124125
const vertices: Array<number> = [];
@@ -191,34 +192,39 @@ export function buildShape(options: {
191192
meshGroup.name = `${objName}-group`;
192193
meshGroup.visible = visible;
193194

194-
const baseMat = new THREE.MeshBasicMaterial();
195-
baseMat.depthWrite = false;
196-
baseMat.depthTest = false;
197-
baseMat.colorWrite = false;
198-
baseMat.stencilWrite = true;
199-
baseMat.stencilFunc = THREE.AlwaysStencilFunc;
200-
201-
// back faces
202-
const mat0 = baseMat.clone();
203-
mat0.side = THREE.BackSide;
204-
mat0.clippingPlanes = clippingPlanes;
205-
mat0.stencilFail = THREE.IncrementWrapStencilOp;
206-
mat0.stencilZFail = THREE.IncrementWrapStencilOp;
207-
mat0.stencilZPass = THREE.IncrementWrapStencilOp;
208-
const backFaces = new THREE.Mesh(geometry, mat0);
209-
backFaces.name = `${objName}-back`;
210-
meshGroup.add(backFaces);
211-
212-
// front faces
213-
const mat1 = baseMat.clone();
214-
mat1.side = THREE.FrontSide;
215-
mat1.clippingPlanes = clippingPlanes;
216-
mat1.stencilFail = THREE.DecrementWrapStencilOp;
217-
mat1.stencilZFail = THREE.DecrementWrapStencilOp;
218-
mat1.stencilZPass = THREE.DecrementWrapStencilOp;
219-
const frontFaces = new THREE.Mesh(geometry, mat1);
220-
frontFaces.name = `${objName}-front`;
221-
meshGroup.add(frontFaces);
195+
// We only build the stencil logic for solid meshes
196+
if (isSolid) {
197+
const baseMat = new THREE.MeshBasicMaterial();
198+
baseMat.depthWrite = false;
199+
baseMat.depthTest = false;
200+
baseMat.colorWrite = false;
201+
baseMat.stencilWrite = true;
202+
baseMat.stencilFunc = THREE.AlwaysStencilFunc;
203+
204+
// back faces
205+
const mat0 = baseMat.clone();
206+
mat0.side = THREE.BackSide;
207+
mat0.clippingPlanes = clippingPlanes;
208+
mat0.stencilFail = THREE.IncrementWrapStencilOp;
209+
mat0.stencilZFail = THREE.IncrementWrapStencilOp;
210+
mat0.stencilZPass = THREE.IncrementWrapStencilOp;
211+
const backFaces = new THREE.Mesh(geometry, mat0);
212+
backFaces.name = `${objName}-back`;
213+
meshGroup.add(backFaces);
214+
215+
// front faces
216+
const mat1 = baseMat.clone();
217+
mat1.side = THREE.FrontSide;
218+
mat1.clippingPlanes = clippingPlanes;
219+
mat1.stencilFail = THREE.DecrementWrapStencilOp;
220+
mat1.stencilZFail = THREE.DecrementWrapStencilOp;
221+
mat1.stencilZPass = THREE.DecrementWrapStencilOp;
222+
const frontFaces = new THREE.Mesh(geometry, mat1);
223+
frontFaces.name = `${objName}-front`;
224+
meshGroup.add(frontFaces);
225+
} else {
226+
material.side = THREE.DoubleSide;
227+
}
222228

223229
const mainMesh = new THREE.Mesh(geometry, material);
224230
mainMesh.name = objName;

packages/base/src/3dview/mainview.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,11 +585,19 @@ export class MainView extends React.Component<IProps, IStates> {
585585

586586
Object.entries(payload).forEach(([objName, data]) => {
587587
const selected = selectedNames.includes(objName);
588+
const obj = this._model.sharedModel.getObjectByName(objName);
589+
590+
// TODO Have a more generic way to spot non-solid objects
591+
const isSolid = !(
592+
obj!.shape === 'Part::Extrusion' && !obj!.parameters?.['Solid']
593+
);
594+
588595
const output = buildShape({
589596
objName,
590597
data,
591598
clippingPlanes: this._clippingPlanes,
592599
selected,
600+
isSolid,
593601
guidata
594602
});
595603

0 commit comments

Comments
 (0)