In my project I generate geometry programmatically, and I simply fill the VertexBuffer and IndexBuffer, then supply them to the Model and it works.
I read this https://urho3d.github.io/documentation/1.7.1/_vertex_buffers.html and sometime ago I seen code from somewhere on how to create Model manually… It ended up something like this in my code (unnecessary details are omitted):
SharedPtr<Model> model (new Model(pContext));
model->SetNumGeometries(2);
Vector<SharedPtr<IndexBuffer>> model_index_buffers;
Vector<SharedPtr<VertexBuffer>> model_vertex_buffers;
//// first pair of buffers goes to geom1
SharedPtr<Geometry> geom1(new Geometry(pContext));
SharedPtr<VertexBuffer> vb1(new VertexBuffer(pContext, false));
SharedPtr<IndexBuffer> ib1(new IndexBuffer(pContext, false));
// pass your generated data
vb1->SetShadowed(true);
vb1->SetSize(...);
vb1->SetData(...);
ib1->SetShadowed(true);
ib1->SetSize(...);
ib1->SetData(...);
geom1->SetVertexBuffer(0, vb1);
geom1->SetIndexBuffer(ib1);
geom1->SetDrawRange(Urho3D::TRIANGLE_LIST, 0, ...);
model->SetGeometry(/*0th Geometry*/0, /*0th LOD*/0, geom1);
model_vertex_buffers.Push(vb1);
model_index_buffers.Push(ib1);
// I don't know why, but afaik this part is required?
Vector<unsigned> morphRangeStarts;
Vector<unsigned> morphRangeCounts;
morphRangeStarts.push_back(0);
morphRangeCounts.push_back(0);
//// repeat everything with second geometry ...
// Questionable part: this two calls are not necessery to render the model,
// but are required for Model::SaveFile to work
model->SetIndexBuffers(model_index_buffers);
model->SetVertexBuffers(model_vertexRangeStarts, morphRangeCounts);
It’s pretty dense and elaborate, but the essense is that we set up multiple Geometry classes each containing vertex/index buffers pair, and then pass them into Model then again we pass all of the vertex/index buffers to the Model.
Structure roughly looks like this:
Model {
Vector<IndexBuffer>;
Vector<VertexBuffer>;
Geometry1 {
IndexBuffer;
VertexBuffer;
}
Geometry2 {
IndexBuffer;
VertexBuffer;
}
}
So, is it only me not totally understanding the logic here, or do we have an inconsistency in the engine? What I see as illogical is having 2 ways to contain the Vertex/Index buffers (through Model and through containing Geometries).
The thing is, I can get away with passing vertex/index buffers through Geometries only, but then Model::SaveFile saves nothing.
Thanks for reading it to the end Will be thankful for any leads on this.