I have a lot of custom geoemtries that are rebuild quite-often (voxel chunks). When I’ve recreated the geometry I do the following to re-create the model. Is this the correct way of doing this in Urho3d or am I doing something that gives me overhead performance wise? (Note the “isBuilt” check first where I for the first time create the object otherwise just updates the index/vertex buffers)
if(!iisBuilt) {
vb->SetShadowed(true);
ib->SetShadowed(true);
int bb = 0;
if(size_x > size_y && size_x > size_z) {
bb = size_x;
} else if(size_y > size_x && size_y > size_z) {
bb = size_y;
} else {
bb = size_z;
}
model->SetBoundingBox(BoundingBox(0, (float)bb));
model->SetNumGeometries(1);
elements.Push(VertexElement(TYPE_VECTOR3, SEM_POSITION));
elements.Push(VertexElement(TYPE_VECTOR3, SEM_NORMAL));
elements.Push(VertexElement(TYPE_VECTOR3, SEM_COLOR));
geom->SetVertexBuffer(0, vb);
geom->SetIndexBuffer(ib);
model->SetGeometry(0, 0, geom);
node->SetPosition(Vector3(from_x, from_y, from_z));
object = node->CreateComponent<StaticModel>();
object->SetOccluder(true);
} else {
vb->Release();
ib->Release();
}
vb->SetSize(vertices.Size(), elements);
vb->SetData(&vertexData[0]);
ib->SetSize(vertices.Size(), false);
ib->SetData(&indexData[0]);
geom->SetDrawRange(TRIANGLE_LIST, 0, vertices.Size());
Vector<SharedPtr<VertexBuffer> > vertexBuffers;
Vector<SharedPtr<IndexBuffer> > indexBuffers;
vertexBuffers.Push(vb);
indexBuffers.Push(ib);
PODVector<unsigned> morphRangeStarts;
PODVector<unsigned> morphRangeCounts;
morphRangeStarts.Push(0);
morphRangeCounts.Push(0);
model->SetVertexBuffers(vertexBuffers, morphRangeStarts, morphRangeCounts);
model->SetIndexBuffers(indexBuffers);
object->SetModel(model);
ResourceCache* cache=GetSubsystem<ResourceCache>();
object->SetMaterial(cache->GetResource<Material>("Materials/vcolors.xml"));
object->SetCastShadows(true);
Any input would be helpful! Thanks