Archive 17/01/2023.

Resizing Drawable batches

sabotage3d

I have a component that inherits from Drawable. I have added methods to resize the batch count, but it doesn’t seem to work correctly. For example if I create two components and resize the batches accordingly and set the index of the first to 0 and the second to 1 if I apply a different material on both the second overwrites the first. What would be the correct way of doing this?

batches_.Resize(batchCount_);
batches_[batchIndex_].geometry_ = geometry_;
batches_[batchIndex_].material_ = material;
Eugene

That’s pretty strange… StaticModel works just fine with multiple materials.
More code?

sabotage3d

My code is almost the same as the RibbonTrail, with the difference I am trying to change the batches.

Pencheff

I had the same problem with the RichText3D component…and it took me a week to work around.

The only place you can modify the Drawable::batches_ without getting exceptions is in Drawable::GetUpdateGeometryType(), although it doesn’t seem to be the right place. If you follow View.cpp line 1112 you’ll see :

Drawable* drawable = *k;
// If drawable is not in actual view frustum, mark it in view here and check its geometry update type
if (!drawable->IsInView(frame_, true))
{
    drawable->MarkInView(frame_.frameNumber_);
    UpdateGeometryType type = drawable->GetUpdateGeometryType();
    if (type == UPDATE_MAIN_THREAD)
        nonThreadedGeometries_.Push(drawable);
    else if (type == UPDATE_WORKER_THREAD)
        threadedGeometries_.Push(drawable);
}

const Vector<SourceBatch>& batches = drawable->GetBatches();
...

If you modify the batch count after Drawable::GetUpdateGeometryType() you’ll end up with a big mess.

sabotage3d

Thanks ,but I am confused. Does it mean I cannot resize batches in the constructor of component? Are these batches global for all the instances of the component inheriting from Drawable.

Pencheff

You can resize the batches in the constructor. Batches are not global and shared between instances, every instance has its own list of batches. Maybe you are facing another problem.

sabotage3d

I just noticed that if I create new instance of a component even if the batch was set to batches_[0] it still creates a new batch. Is the batch index only local to the class? Can we share batches between components?