{"record":{"id":"dcbcd94817382616","repo":"BabylonJS/Babylon.js","slug":"cannot-merge-vertex-data-that-do-not-have-the-same","errorCode":null,"errorMessage":"Cannot merge vertex data that do not have the same set of attributes","messagePattern":"Cannot merge vertex data that do not have the same set of attributes","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/Meshes/mesh.vertexData.ts","lineNumber":880,"sourceCode":"\r\n            if (!enableCompletion) {\r\n                other._validate();\r\n                if (\r\n                    !this.normals !== !other.normals ||\r\n                    !this.tangents !== !other.tangents ||\r\n                    !this.uvs !== !other.uvs ||\r\n                    !this.uvs2 !== !other.uvs2 ||\r\n                    !this.uvs3 !== !other.uvs3 ||\r\n                    !this.uvs4 !== !other.uvs4 ||\r\n                    !this.uvs5 !== !other.uvs5 ||\r\n                    !this.uvs6 !== !other.uvs6 ||\r\n                    !this.colors !== !other.colors ||\r\n                    !this.matricesIndices !== !other.matricesIndices ||\r\n                    !this.matricesWeights !== !other.matricesWeights ||\r\n                    !this.matricesIndicesExtra !== !other.matricesIndicesExtra ||\r\n                    !this.matricesWeightsExtra !== !other.matricesWeightsExtra\r\n                ) {\r\n                    throw new Error(\"Cannot merge vertex data that do not have the same set of attributes\");\r\n                }\r\n            } else {\r\n                // Align the others with main set of attributes\r\n                if (this.normals && !other.normals) {\r\n                    other.normals = new Float32Array(other.positions!.length);\r\n                }\r\n\r\n                if (this.tangents && !other.tangents) {\r\n                    other.tangents = new Float32Array((other.positions!.length / 3) * 4);\r\n                }\r\n\r\n                if (this.uvs && !other.uvs) {\r\n                    other.uvs = new Float32Array((other.positions!.length / 3) * 2);\r\n                }\r\n\r\n                if (this.uvs2 && !other.uvs2) {\r\n                    other.uvs2 = new Float32Array((other.positions!.length / 3) * 2);\r\n                }\r","sourceCodeStart":862,"sourceCodeEnd":898,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/Meshes/mesh.vertexData.ts#L862-L898","documentation":"VertexData.merge() requires that all merged VertexData objects expose the same set of vertex attributes (positions, normals/uvs, colors, matricesIndices/Weights and their Extra variants). When `useStridedVertexData` is true and a strict boolean-presence comparison shows one dataset has an attribute another lacks, merging would produce a corrupt buffer, so it throws.","triggerScenarios":"Calling mesh.mergeMeshes(...) or vertexData.merge(other, dispose, ..., true) where e.g. one mesh has UVs/colors/skin weights and another does not.","commonSituations":"Merging a mesh that was loaded from a model with vertex colors together with a programmatically created mesh without colors; mixing skinned (matricesWeights) and non-skinned meshes; meshes where one has tangents/uvs and the other was built without them.","solutions":["Ensure every mesh being merged has the same vertex kinds: add matching uvs/colors/normals to the deficient meshes (e.g. VertexData computeNormals or set a default color set)","Call merge with useStridedVertexData = false so missing attributes are auto-aligned with zeroed Float32Arrays","Convert meshes so their VertexBuffer kinds match before merging (clone with identical material/vertex setup)"],"exampleFix":"// before\nconst merged = mesh.mergeMeshes([meshA /* no uvs */, meshB /* has uvs */], true, true, undefined, false, true); // throws\n// after\nconst merged = mesh.mergeMeshes([meshA, meshB], true, true, undefined, false, false); // aligns missing attributes automatically","handlingStrategy":"validation","validationCode":"function sameKinds(a: BABYLON.VertexData, b: BABYLON.VertexData): boolean {\n  const has = (v: BABYLON.VertexData) => ({ pos: !!v.positions, nrm: !!v.normals, uv: !!(v as any).uvs, col: !!v.colors, mi: !!(v as any).matricesIndices, mw: !!(v as any).matricesWeights });\n  const ha = has(a), hb = has(b);\n  return Object.keys(ha).every(k => ha[k] === hb[k]);\n}\nif (!sameKinds(vd, other)) {\n  // pass useStridedVertexData=false or normalize attributes first\n}","typeGuard":"const hasMatchingAttributes = (a: BABYLON.VertexData, b: BABYLON.VertexData): boolean =>\n  (!!a.normals === !!b.normals) && (!!a.colors === !!b.colors) &&\n  (!!a.matricesIndices === !!b.matricesIndices) && (!!a.matricesWeights === !!b.matricesWeights);","tryCatchPattern":"try {\n  merged = mesh.mergeMeshes(list, true, true, undefined, false, true);\n} catch (e) {\n  if (String((e as Error).message).includes(\"same set of attributes\")) {\n    merged = mesh.mergeMeshes(list, true, true, undefined, false, false); // auto-align\n  } else { throw e; }\n}","preventionTips":["Verify all meshes to merge have identical vertex kinds (debug with mesh.getVerticesData(kinds))","Add uvs/colors to deficient meshes before merging","Pass useStridedVertexData=false when attribute sets may differ","Don't mix skinned and non-skinned meshes in a merge"],"tags":["babylonjs","vertexdata","mesh-merge","geometry"],"backgroundTag":"vertex-attribute-mismatch","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}