{"record":{"id":"06a9ac8cfe04f0e3","repo":"BabylonJS/Babylon.js","slug":"unable-to-build-a-mesh-manifold-has-0-vertex","errorCode":null,"errorMessage":"Unable to build a mesh. Manifold has 0 vertex","messagePattern":"Unable to build a mesh\\. Manifold has 0 vertex","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/Meshes/csg2.ts","lineNumber":233,"sourceCode":"     * @returns a new Mesh\r\n     */\r\n    public toMesh(name: string, scene?: Scene, options?: Partial<IMeshRebuildOptions>): Mesh {\r\n        const localOptions = {\r\n            rebuildNormals: false,\r\n            centerMesh: true,\r\n            ...options,\r\n        };\r\n        const vertexData = this.toVertexData({ rebuildNormals: localOptions.rebuildNormals });\r\n        const normalComponent = this._vertexStructure.find((c) => c.kind === VertexBuffer.NormalKind);\r\n        const manifoldMesh: IManifoldMesh = this._manifold.getMesh(localOptions.rebuildNormals && normalComponent ? [3, 4, 5] : undefined);\r\n        const vertexCount = manifoldMesh.vertProperties.length / manifoldMesh.numProp;\r\n\r\n        // Rebuild mesh from vertex data\r\n        const output = new Mesh(name, scene);\r\n        vertexData.applyToMesh(output);\r\n\r\n        if (!vertexCount) {\r\n            throw new Error(\"Unable to build a mesh. Manifold has 0 vertex\");\r\n        }\r\n\r\n        // Center mesh\r\n        if (localOptions.centerMesh) {\r\n            const extents = output.getBoundingInfo().boundingSphere.center;\r\n            output.position.set(-extents.x, -extents.y, -extents.z);\r\n            output.bakeCurrentTransformIntoVertices();\r\n        }\r\n\r\n        // Submeshes\r\n        let id = manifoldMesh.runOriginalID[0];\r\n        let start = manifoldMesh.runIndex[0];\r\n        let materialIndex = 0;\r\n        const materials: Material[] = [];\r\n        scene = output.getScene();\r\n        for (let run = 0; run < manifoldMesh.numRun; ++run) {\r\n            const nextID = manifoldMesh.runOriginalID[run + 1];\r\n            if (nextID !== id) {\r","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/Meshes/csg2.ts#L215-L251","documentation":"toMesh rebuilds a Babylon Mesh from the CSG2's vertex data; if the resulting Manifold contains zero vertices (e.g. an empty result geometry), it throws because a mesh cannot be built from empty vertex data. This guards against producing degenerate, invisible meshes from a CSG operation.","triggerScenarios":"Calling csg.toMesh() after an operation whose result was empty — subtracting a mesh that fully contains the other, intersecting disjoint solids, or building the CSG from an empty/invalid mesh.","commonSituations":"Boolean ops between non-overlapping objects; a subtract where the tool body completely swallows the target; importing meshes that failed to produce geometry.","solutions":["Verify the operands actually overlap before the boolean operation","Check the CSG result (vertex/vertexCount) for emptiness and fall back to the original mesh","Fix the source mesh so it contains geometry (non-zero vertex count) before converting"],"exampleFix":"// before\nconst result = a.subtract(b).toMesh('diff', scene); // may be empty\n// after\nconst c = a.subtract(b);\nif (c.getCVertices?.() ?? true) { /* check non-empty */ }\nconst result = c.toMesh('diff', scene);","handlingStrategy":"validation","validationCode":"const result = a.intersect(b);\n// guard against empty boolean result before toMesh\nif (!result) throw new Error('CSG result is empty');","typeGuard":"const nonEmpty = (c: CSG2): boolean => { try { return !!c; } catch { return false; } };","tryCatchPattern":"try {\n  mesh = result.toMesh(name, scene);\n} catch (e) {\n  if (String(e).includes('0 vertex')) { mesh = fallbackOriginalMesh(); }\n  else throw e;\n}","preventionTips":["Check operand bounding boxes overlap before boolean ops","Avoid subtracting a body that fully contains the target","Ensure source meshes have non-zero vertex counts before CSG2.FromMesh"],"tags":["csg","geometry","empty-result"],"backgroundTag":"empty-geometry-result","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}