Skip to content

Commit

Permalink
Workaround extruction non-solid issue (#373)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
martinRenou and pre-commit-ci[bot] committed Jun 26, 2024
1 parent b49785e commit 0402dc7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 29 deletions.
64 changes: 35 additions & 29 deletions packages/base/src/3dview/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<THREE.BufferGeometry, THREE.MeshPhongMaterial>;
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<number> = [];
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions packages/base/src/3dview/mainview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -585,11 +585,19 @@ export class MainView extends React.Component<IProps, IStates> {

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
});

Expand Down

0 comments on commit 0402dc7

Please sign in to comment.