[2.3] possible to createItem with SubMesh?

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
bjf
Gnoblar
Posts: 7
Joined: Mon Sep 21, 2020 4:14 am

[2.3] possible to createItem with SubMesh?

Post by bjf »

I can create an Item with an Ogre::Mesh object using createItem() and using HlmsUnlit, I set the material.

Code: Select all

    
    Ogre::HlmsUnlitDatablock *block;
    Ogre::MeshPtr mp;
    // ...
    Ogre::Item *item = sceneManager->createItem(mp, Ogre::SCENE_DYNAMIC);
    item->setDatablock(block);
Is it possible to create an Item of a specific Ogre::SubMesh object somehow? I would like to be able to call setDatablock() on the submesh item to only change the material for one of several SubMeshes within a Mesh.
Hilarius86
Halfling
Posts: 51
Joined: Thu Feb 14, 2019 11:27 am
x 8

Re: [2.3] possible to createItem with SubMesh?

Post by Hilarius86 »

Have a look at SubItems and see if it solves your usecase:
https://ogrecave.github.io/ogre-next/ap ... _item.html
bjf
Gnoblar
Posts: 7
Joined: Mon Sep 21, 2020 4:14 am

Re: [2.3] possible to createItem with SubMesh?

Post by bjf »

This is almost what I need. It seems to have the functions I'm looking for (setDatablock()). The only issue seems to be this line in the docs ...
SubItem instances are never created manually. They are created at the same time as their parent Item by the SceneManager method createItem.
My problem is I don't create the second SubMesh till after the first Mesh/SubMesh has been created. So after the Mesh has been created, I later create another Ogre::SubMesh object and attach it to the same Ogre::Mesh object, (so I guess you could say I am creating the SubMesh manually).

Update:
One problem seems to be that, after creating a new Mesh object ...

Code: Select all

    Ogre::MeshPtr mp = meshManager->createManual(...);
    mp->createSubMesh();
    // ...
    Ogre::Item *item = sceneManager->createItem(mp, Ogre::SCENE_DYNAMIC);

... then calling item->getNumSubItems(), the SubItem count will be 1. Then creating another SubMesh on the same MeshPtr object ...

Code: Select all

    Ogre::SubMesh *subMesh = mp->createSubMesh();
    // ...

... and calling item->getNumSubItems(), the count is still 1. In both cases of creating the Mesh or adding the SubMesh, they both call Mesh::createSubMesh() so not sure what's different here; hence the doc quote above. Otherwise if this worked, I could probably figure out a solution.

This really makes me question SubMeshes. If they can't be manipulated, why do they exist? I'm doing a most basic thing for a Mesh, assigning materials via setDatablock() to each SubMesh, or at least that's the intention.
Hilarius86
Halfling
Posts: 51
Joined: Thu Feb 14, 2019 11:27 am
x 8

Re: [2.3] possible to createItem with SubMesh?

Post by Hilarius86 »

Your Mesh is changed with the SubMeshes. It's just the Item that is not reacting to the change. Guess the reason is some optimisation in the Item. As a temp. workaround just destroy the Item and recreate it from the Mesh. Maybe someone else can help here with a real solition?
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5433
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1341

Re: [2.3] possible to createItem with SubMesh?

Post by dark_sylinc »

Modifying a mesh while there are live instances using it is dangerous.

White there are safe operations that can be performed (like modifying the name of the default material for each submesh), generally speaking the mesh should be treated as immutable while items/entities are using it