I'm totally lost. I'm trying to split/divide/extract/separate a mesh into sub-meshes via bbox test. But I just realized that I need to properly split indices and vertex and I have no idea how o.o... here is the splitting code that "fails" because my indices/vertex needs a proper re-arranging that I have no idea how to solve o.o.
for (auto &box:aabb) { //// list of bboxes
for (int indi = 0; indi < mIndices.size(); indi += 3) { /// get 3 indices for 1 triangle
offX = mIndices[indi];
offY = mIndices[indi + 1];
offZ = mIndices[indi + 2];
/// Check if any of the vertex is inside the box
if (box.contains(mVertex[offX]) || box.contains(mVertex[offY]) || box.contains(mVertex[offZ]))
{
/// bellow code is wrong, I'm over-adding vertex even if they
/// exist, and I'm adding wrong indices because new mVertex/indices arrays are of
/// different sizes to source one... oh dear... I need to add an only missing vertex,
/// and indices re-mapped to proper existing/new vertexes.
box.mVertex.push_back(mVertex[offX]);
box.mVertex.push_back(mVertex[offY]);
box.mVertex.push_back(mVertex[offZ]);
box.mIndices.push_back(offX);
box.mIndices.push_back(offY);
box.mIndices.push_back(offZ);
};
}
}
If any1 could help with this, this would be amazing. I'm not worried if 1 triangle is being duplicated across 2 bounding boxes or even more. As the aaBB can have random positions. I just need each aabb with its own vertex/indices set that can create mesh.
EDIT1.
The only way I could think of doing it is this > it feels quite..."bad tho...
void aabb::addTriangle(QVector3D &x, QVector3D &y, QVector3D &z) {
if (mVertex.contains(x)) {
mIndices.push_back(mVertex.indexOf(x));
} else {
mVertex.push_back(x);
mIndices.push_back(mVertex.size() - 1);
}
if (mVertex.contains(y)) {
mIndices.push_back(mVertex.indexOf(y));
} else {
mVertex.push_back(y);
mIndices.push_back(mVertex.size() - 1);
}
if (mVertex.contains(z)) {
mIndices.push_back(mVertex.indexOf(z));
} else {
mVertex.push_back(z);
mIndices.push_back(mVertex.size() - 1);
}
}
EDIT 2. Thanks to ErnieDingo I'm now not copying vertex in to each aabb object, but only adding triangles(3indices) that if either is being contained by bbox. Then I pass pointer to base mesh vertexArray for further tests down the line