Skip to content

Workaround extruction non-solid issue #373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading