{"record":{"id":"1f9c59f0c7445a3a","repo":"BabylonJS/Babylon.js","slug":"the-mesh-must-at-least-have-positions-and-indices","errorCode":null,"errorMessage":"The mesh must at least have positions and indices","messagePattern":"The mesh must at least have positions and indices","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/Meshes/csg2.ts","lineNumber":431,"sourceCode":"            throw new Error(\"The vertexData must at least have positions and indices\");\r\n        }\r\n\r\n        return this._Construct(vertexData, null);\r\n    }\r\n\r\n    /**\r\n     * Create a new Constructive Solid Geometry from a mesh\r\n     * @param mesh defines the mesh to use to create the CSG\r\n     * @param ignoreWorldMatrix defines if the world matrix should be ignored\r\n     * @returns a new CSG2 class\r\n     */\r\n    public static FromMesh(mesh: Mesh, ignoreWorldMatrix = false): CSG2 {\r\n        const sourceVertices = mesh.getVerticesData(VertexBuffer.PositionKind);\r\n        const sourceIndices = mesh.getIndices();\r\n        const worldMatrix = mesh.computeWorldMatrix(true);\r\n\r\n        if (!sourceVertices || !sourceIndices) {\r\n            throw new Error(\"The mesh must at least have positions and indices\");\r\n        }\r\n\r\n        // Create a triangle run for each submesh (material)\r\n        const starts = [...Array(mesh.subMeshes.length)].map((_, idx) => mesh.subMeshes[idx].indexStart);\r\n\r\n        // Map the materials to ID.\r\n        const sourceMaterial = mesh.material || mesh.getScene().defaultMaterial;\r\n        const isMultiMaterial = sourceMaterial.getClassName() === \"MultiMaterial\";\r\n        const originalIDs = [...Array(mesh.subMeshes.length)].map((_, idx) => {\r\n            if (isMultiMaterial) {\r\n                return FirstID + (sourceMaterial as MultiMaterial).subMaterials[mesh.subMeshes[idx].materialIndex]!.uniqueId;\r\n            }\r\n\r\n            return FirstID + sourceMaterial.uniqueId;\r\n        });\r\n\r\n        // List the runs in sequence.\r\n        const indices = Array.from(starts.keys());\r","sourceCodeStart":413,"sourceCodeEnd":449,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/Meshes/csg2.ts#L413-L449","documentation":"CSG2.FromMesh reads position vertices and the index buffer from the mesh's geometry. If either is absent, the mesh has no renderable geometry usable for CSG and this error is thrown before submesh/material mapping begins.","triggerScenarios":"Calling `CSG2.FromMesh(mesh)` on a mesh created with `new Mesh(...)` but never given geometry (no setVerticesData/Geometry), a mesh whose geometry was disposed, or a Lines/Points mesh with no index buffer.","commonSituations":"Forgetting to call MeshBuilder creation or applyToMesh on a VertexData; disposing geometry earlier in the frame; targeting thin instances or GPU-picked meshes whose CPU-side geometry was never uploaded; LinesMesh/GroundMesh edge cases without indices.","solutions":["Verify the mesh has geometry: `mesh.getVerticesData(VertexBuffer.PositionKind)` and `mesh.getIndices()` are non-null before calling.","If building from VertexData, call `vertexData.applyToMesh(mesh)` first, or use `CSG2.FromVertexData` directly.","Use a solid (triangle-indexed) mesh as CSG input; lines/points are not valid solids."],"exampleFix":"// before\nconst empty = new BABYLON.Mesh(\"empty\", scene);\nconst csg = CSG2.FromMesh(empty); // throws\n// after\nconst box = BABYLON.MeshBuilder.CreateBox(\"box\", { size: 2 }, scene);\nconst csg = CSG2.FromMesh(box);","handlingStrategy":"validation","validationCode":"function canBuildCsgFromMesh(mesh: Mesh): boolean {\n  return !!mesh.geometry\n    && !!mesh.getVerticesData(VertexBuffer.PositionKind)\n    && mesh.getIndices().length > 0;\n}\nif (!canBuildCsgFromMesh(mesh)) throw new Error(`Mesh '${mesh.name}' lacks positions/indices for CSG`);","typeGuard":"function hasRenderableGeometry(mesh: Mesh): boolean {\n  const pos = mesh.getVerticesData(VertexBuffer.PositionKind);\n  return pos != null && pos.length > 0 && mesh.getIndices().length > 0;\n}","tryCatchPattern":null,"preventionTips":["Check mesh.geometry is not null/disposed before CSG operations.","Use MeshBuilder-created solid meshes as CSG inputs.","Never feed LinesMesh/PointsMesh into CSG2.FromMesh."],"tags":["csg","mesh","validation"],"backgroundTag":"missing-required-geometry-data","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}