So I’ve been trying to generate meshes.
I have a new class copied from CustomGeometry
.
I create a test function
void TestDrawable::DrawTestGeometry() {
batches_.Clear();
geometries_.Clear();
primitiveTypes_.Clear();
batches_.Resize(1);
geometries_.Resize(1);
primitiveTypes_.Resize(1);
geometries_[0] = new Geometry(context_);
batches_[0].geometry_ = geometries_[0];
// Current geometry being updated.
geometryIndex_ = 0;
Vector<Vector3> position = {
{0, 0, 0}, {0, 0, 1}, {0, 0, 2},
{1, 0, 0}, {1, 0, 1}, {1, 0, 2},
{2, 0, 0}, {2, 0, 1}, {2, 0, 2},
};
PODVector<unsigned short> indices{3, 1, 0, 3, 4, 1, 4, 2, 1, 4, 5, 2, 6, 4, 3, 6, 7, 4, 7, 5, 4, 7, 8, 5};
vertexBuffer_->SetSize(position.Size(), MASK_POSITION);
auto *dest = (float *) vertexBuffer_->Lock(0, position.Size(), true);
for (int i = 0; i < position.Size(); ++i) {
*dest++ = position[i].x_;
*dest++ = position[i].y_;
*dest++ = position[i].z_;
}
SharedPtr<IndexBuffer> indexBuffer_(new IndexBuffer(context_));
indexBuffer_->SetSize(indices.Size(), false);
indexBuffer_->SetData(&indices[0]);
geometries_[0]->SetIndexBuffer(indexBuffer_);
geometries_[0]->SetVertexBuffer(0, vertexBuffer_);
geometries_[0]->SetDrawRange(PrimitiveType::TRIANGLE_LIST,
0,
indices.Size(),
0,
position.Size());
vertexBuffer_->Unlock();
vertexBuffer_->ClearDataLost();
}
However, this function draws nothing!
When I just simply change the TRIANGLE_LIST to TRIANGLE_STRIPE, the drawing is what I want.
geometries_[0]->SetDrawRange(PrimitiveType:: TRIANGLE_STRIP,
0,
indices.Size(),
0,
position.Size());
But this does not make any sense to me!
The TRIANGLE_LIST should draw from the IndexBuffer
while TRIANGLE_STRIP should have a specific order to draw the vertices.
What’s wrong?