MergeVectorsDifferentLengths
The Manifold library emits this error when the mergeFromVert and mergeToVert arrays in a MeshGL structure have different lengths, preventing valid vertex merging.
The MergeVectorsDifferentLengths diagnostic is an error status emitted by the Manifold geometry library when it encounters a mismatch in the lengths of the mergeFromVert and mergeToVert vectors within an input MeshGL or MeshGL64 object. These vectors are utilized to specify which vertices (often duplicated to accommodate sudden changes in vertex properties like normals or UV coordinates across seams) correspond to the same physical location. They guide the engine in losslessly stitching these vertices back together to recover a valid topological manifold. When the lengths of these two vectors differ, Manifold cannot pair every source vertex with a target vertex, resulting in an invalid merge specification.
This error is triggered during the construction of a manifold::Manifold from a raw graphics mesh (e.g., calling Manifold(const MeshGL&) in C++ or its JavaScript equivalent). The internal validation logic strictly checks the sizes of the mergeFromVert and mergeToVert arrays. If a developer or an importer script populates one array but not the other, or pushes mismatched numbers of indices into them, the constraint mergeFromVert.size() == mergeToVert.size() is violated. Consequently, the library aborts the construction of the solid and sets the object's status to MergeVectorsDifferentLengths, typically returning an empty or invalid mesh representation.
#include <manifold.h>
#include <vector>
int main() {
manifold::MeshGL mesh;
mesh.numProp = 3;
mesh.vertProperties = {
0.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f
};
mesh.triVerts = {0, 1, 2};
// Cause the error by providing mismatched merge arrays
mesh.mergeFromVert = {1, 2};
mesh.mergeToVert = {1};
manifold::Manifold m(mesh);
if (m.Status() == manifold::Manifold::Error::MergeVectorsDifferentLengths) {
return 1;
}
return 0;
}
Ensure that the mergeFromVert and mergeToVert arrays in the MeshGL structure are of exactly the same length, or omit them entirely if vertex merging is unneeded.
```C++
#include <manifold.h>
#include <vector>
int main() {
manifold::MeshGL mesh;
mesh.numProp = 3;
mesh.vertProperties = {
0.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f
};
mesh.triVerts = {0, 1, 2};
// Fix the error by matching lengths or clearing both vectors
mesh.mergeFromVert = {1, 2};
mesh.mergeToVert = {0, 0}; // Same length as mergeFromVert
manifold::Manifold m(mesh);
if (m.Status() != manifold::Manifold::Error::NoError) {
return 1;
}
return 0;
}
```
manifold/manifold.h Header File
SplitByPlane() doesn't handle empty Manifold objects < Issue #1515
Manifold is merging coplanar faces despite unique vertex properties < Issue #1316