{"record":{"id":"34ca2411ebe25094","repo":"BabylonJS/Babylon.js","slug":"the-vertexdata-must-at-least-have-positions-and-in","errorCode":null,"errorMessage":"The vertexData must at least have positions and indices","messagePattern":"The vertexData must at least have positions and indices","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/Meshes/csg2.ts","lineNumber":413,"sourceCode":"        if (sourceColors) {\r\n            numProp += 4;\r\n            structure.push({ stride: 4, kind: VertexBuffer.ColorKind, data: sourceColors });\r\n        }\r\n\r\n        return this._ProcessData(data.positions!.length / 3, triVerts, structure, numProp, runIndex, runOriginalID);\r\n    }\r\n\r\n    /**\r\n     * Create a new Constructive Solid Geometry from a vertexData\r\n     * @param vertexData defines the vertexData to use to create the CSG\r\n     * @returns a new CSG2 class\r\n     */\r\n    public static FromVertexData(vertexData: VertexData): CSG2 {\r\n        const sourceVertices = vertexData.positions;\r\n        const sourceIndices = vertexData.indices;\r\n\r\n        if (!sourceVertices || !sourceIndices) {\r\n            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","sourceCodeStart":395,"sourceCodeEnd":431,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/Meshes/csg2.ts#L395-L431","documentation":"CSG2.FromVertexData requires the supplied VertexData to contain both `positions` and `indices`; a CSG solid cannot be built from bare normals/uvs or non-indexed primitives in this API path. The guard throws before any geometry processing when either array is missing or empty.","triggerScenarios":"Calling `CSG2.FromVertexData(vertexData)` where `vertexData.positions` or `vertexData.indices` is undefined/null — e.g. a VertexData built with only normals/uvs, or positions set but applyToMesh/indices never generated.","commonSituations":"Hand-constructing VertexData and forgetting setIndex/indices; converting a mesh whose geometry was created non-indexed; passing VertexData extracted from a mesh that had its geometry disposed.","solutions":["Ensure both `vertexData.positions` (Float32Array of xyz triples) and `vertexData.indices` (Uint32Array/number[]) are populated before the call.","If starting from a mesh, prefer `CSG2.FromMesh(mesh)` which fetches positions/indices for you.","For non-indexed geometry, generate a trivial index array [0,1,2,3,4,5,...] matching the position count."],"exampleFix":"// before\nconst vd = new VertexData();\nvd.positions = positions; // indices never set\nconst csg = CSG2.FromVertexData(vd);\n// after\nconst vd = new VertexData();\nvd.positions = positions;\nvd.indices = positions.map((_, i) => i); // or real triangle indices\nconst csg = CSG2.FromVertexData(vd);","handlingStrategy":"validation","validationCode":"function canBuildCsgFromVertexData(vd: VertexData): boolean {\n  return !!vd.positions && vd.positions.length > 0 && !!vd.indices && vd.indices.length > 0;\n}\nif (!canBuildCsgFromVertexData(vertexData)) throw new Error(\"positions and indices required for CSG\");","typeGuard":"function hasPositionsAndIndices(vd: VertexData): vd is VertexData & { positions: ArrayLike<number>; indices: ArrayLike<number> } {\n  return vd.positions != null && vd.indices != null;\n}","tryCatchPattern":null,"preventionTips":["After constructing VertexData, assert positions/indices exist before downstream use.","Prefer CSG2.FromMesh for mesh inputs; it handles data extraction.","Generate indices for non-indexed geometry as a trivial sequence."],"tags":["csg","vertex-data","validation"],"backgroundTag":"missing-required-geometry-data","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}