From 6df1c6bb5cf2eb2032588f80d708ad3290893c1a Mon Sep 17 00:00:00 2001 From: David Catuhe Date: Thu, 24 Oct 2024 11:06:42 -0700 Subject: [PATCH] Add warning when detecting negative genus (#15736) * Add warning when detecting negative genus * revert unwanted changes * . * . --- packages/dev/core/src/Meshes/csg2.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/dev/core/src/Meshes/csg2.ts b/packages/dev/core/src/Meshes/csg2.ts index e480448ce83..26321bba678 100644 --- a/packages/dev/core/src/Meshes/csg2.ts +++ b/packages/dev/core/src/Meshes/csg2.ts @@ -119,7 +119,7 @@ export class CSG2 implements IDisposable { private _process(operation: "difference" | "intersection" | "union", csg: CSG2) { if (this.numProp !== csg.numProp) { - throw new Error("CSG must have the same number of properties"); + throw new Error("CSG must be used with geometries having the same number of properties"); } return new CSG2(Manifold[operation](this._manifold, csg._manifold), this.numProp, this._vertexStructure); } @@ -301,11 +301,18 @@ export class CSG2 implements IDisposable { const manifoldMesh = new ManifoldMesh({ numProp: numProp, vertProperties, triVerts, runIndex, runOriginalID }); manifoldMesh.merge(); + let returnValue: CSG2; try { - return new CSG2(new Manifold(manifoldMesh), numProp, structure); + returnValue = new CSG2(new Manifold(manifoldMesh), numProp, structure); } catch (e) { throw new Error("Error while creating the CSG: " + e.message); } + + if (returnValue._manifold.genus() < 0) { + throw new Error("Incorrect volume detected. Make sure you are not using a double sided geometry"); + } + + return returnValue; } private static _Construct(data: IVertexDataLike, worldMatrix: Nullable, runIndex?: Uint32Array, runOriginalID?: Uint32Array) {