Changing an existing mesh (created by myself)

Problems building or running the engine, queries about how to use features etc.
andrecaldas
Halfling
Posts: 54
Joined: Mon May 06, 2024 1:06 am
x 3

Changing an existing mesh (created by myself)

Post by andrecaldas »

Ogre Version: 14 from github.
Operating System: Debian GNU/Linux
Render System: OpenGL Rendering Subsystem

After creating a mesh using "MeshManager::getSingleton().createManual", I have populate it like this:

Code: Select all

    mesh->createVertexData();
    mesh->sharedVertexData->vertexCount = vertexEntriesPerPoint();
    auto* decl = mesh->sharedVertexData->vertexDeclaration;
    auto* bind = mesh->sharedVertexData->vertexBufferBinding;

size_t offset = 0;
offset += decl->addElement(0, offset, VET_FLOAT3, VES_POSITION).getSize();

auto vbuf =
  HardwareBufferManager::getSingleton().createVertexBuffer(
    offset, vertex.size()/vertexEntriesPerPoint(), HBU_GPU_ONLY);
vbuf->writeData(0, vbuf->getSizeInBytes(), vertex.data(), true);
bind->setBinding(0, vbuf);

auto ibuf =
  HardwareBufferManager::getSingleton().createIndexBuffer(
    HardwareIndexBuffer::IT_16BIT, indexes.size(), HBU_GPU_ONLY);
ibuf->writeData(0, ibuf->getSizeInBytes(), indexes.data(), true);

SubMesh* sub = mesh->createSubMesh();
sub->operationType = RenderOperation::OT_LINE_STRIP;
//    sub->useSharedVertices = true;
    sub->indexData->indexBuffer = ibuf;
    sub->indexData->indexStart = 0;
    sub->indexData->indexCount = indexes.size();

Everything works. Now, I want to use the same mesh object, but I want to change the mesh. I suspect I have the options of:

  1. Doing everything again, from scratch: recreate the VertexData, recreate the buffers and repopulate them.
  2. Re-use buffers and change the data.

How do I do number 1 properly?

And how do I do number 2? :mrgreen:

Also... any recommendations? :D

rpgplayerrobin
Gnoll
Posts: 677
Joined: Wed Mar 18, 2009 3:03 am
x 379

Re: Changing an existing mesh (created by myself)

Post by rpgplayerrobin »

I suggest you to look at my own manual object code, it should show you everything you will need:
viewtopic.php?p=547857#p547857

andrecaldas
Halfling
Posts: 54
Joined: Mon May 06, 2024 1:06 am
x 3

Re: Changing an existing mesh (created by myself)

Post by andrecaldas »

rpgplayerrobin wrote: Tue Nov 05, 2024 4:24 am

I suggest you to look at my own manual object code [...]

Thank you. But I could not find "your code". :(

paroj
OGRE Team Member
OGRE Team Member
Posts: 2106
Joined: Sun Mar 30, 2014 2:51 pm
x 1132

Re: Changing an existing mesh (created by myself)

Post by paroj »

just call writeData with the new data to update the mesh.

andrecaldas
Halfling
Posts: 54
Joined: Mon May 06, 2024 1:06 am
x 3

Re: Changing an existing mesh (created by myself)

Post by andrecaldas »

paroj wrote: Tue Nov 05, 2024 1:50 pm

just call writeData with the new data to update the mesh.

Good to know. :-)

I wish I was a little more clear... what if the number of vertexes is much greater?

I am writing a software where the user can edit the geometric object. The object can get much more complex during its life. What can I do in this case?

paroj
OGRE Team Member
OGRE Team Member
Posts: 2106
Joined: Sun Mar 30, 2014 2:51 pm
x 1132

Re: Changing an existing mesh (created by myself)

Post by paroj »

  1. overwrite sub->indexData->indexBuffer and bind->setBinding(0, vbuf) with the new larger buffers
  2. create "large enough" buffers initially and only use a part of them
rpgplayerrobin
Gnoll
Posts: 677
Joined: Wed Mar 18, 2009 3:03 am
x 379

Re: Changing an existing mesh (created by myself)

Post by rpgplayerrobin »

andrecaldas wrote: Tue Nov 05, 2024 12:47 pm
rpgplayerrobin wrote: Tue Nov 05, 2024 4:24 am

I suggest you to look at my own manual object code [...]

Thank you. But I could not find "your code". :(

I linked it to you. Just check that post and the full code regarding this is there.
Just search for "CManual_Object.cpp" in that post if you don't find it.

That code takes care of all the issues and questions you are talking about in this topic.