[2.1] Equivelant of setDatablock() for a submesh?

Problems building or running the engine, queries about how to use features etc.
Post Reply
rrl
Halfling
Posts: 78
Joined: Sun Jun 04, 2017 12:33 am

[2.1] Equivelant of setDatablock() for a submesh?

Post by rrl »

I have a VB with indexes which are not showing up and I'm wondering if it's because I don't have a material assigned.

How does one assign a material to a submesh. If it were an item, I'd call item->setDatablock(block), and this renders my model according to the macroblock I have.

But for a VB, all I see is setMaterial(), yet I'm avoiding this call because I was unable to get JSON support into Ogre using ogredeps, therefore, I'm creating macroblocks programmatically. So instead of an item, I have a submesh that I'm trying to assign a material to.

Thoughts?
Last edited by rrl on Fri Oct 20, 2017 2:29 am, edited 1 time in total.
dermont
Bugbear
Posts: 812
Joined: Thu Dec 09, 2004 2:51 am
x 42

Re: Equivelant of setDatablock() for a submesh?

Post by dermont »

subitem->setDatablock(block)
rrl
Halfling
Posts: 78
Joined: Sun Jun 04, 2017 12:33 am

Re: Equivelant of setDatablock() for a submesh?

Post by rrl »

Sorry, I should have mentioned, this is for 2.1 (changed the title accordingly). I looked at the docs for Ogre::SubMesh and found no such call (for 2.1).
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: [2.1] Equivelant of setDatablock() for a submesh?

Post by xrgo »

mesh/submesh can't have datablocks, they don't hold rendering information, just geometry, you have to use items..
whats a VB?
rrl
Halfling
Posts: 78
Joined: Sun Jun 04, 2017 12:33 am

Re: [2.1] Equivelant of setDatablock() for a submesh?

Post by rrl »

By VB, I meant vertex buffer. I've been learning to create vertex buffers in 2.1 by creating a mesh, then a submesh, then filled in the data and add index buffers. Problem is, my mesh is not showing up and I think I have it correct (I have it like the DynamicGeometry sample), and so I'm hoping it's because I don't have a material assigned. I'm trying to get it to show up as a wireframe.

Update: I think your reply may have helped. If I'm understanding this correctly, and I missed it in the samples, this somehow needs to translate to an item. So I'll go down that path.
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: [2.1] Equivelant of setDatablock() for a submesh?

Post by xrgo »

rrl wrote:By VB, I meant vertex buffer.
oh right :D
rrl wrote:Update: I think your reply may have helped. If I'm understanding this correctly, and I missed it in the samples, this somehow needs to translate to an item. So I'll go down that path.
yes! when creating an item you specify the mesh it will use, then you have to attach it to a scenenode, Items hold rendering information but no transform information, that's the sceneNode's job, you need it also so it can appear in the world space.
in code:

Code: Select all

    Ogre::Item* myItem = mSceneManager->createItem( myMesh );    
    Ogre::SceneNode* myNode = mSceneManager->getRootSceneNode()->createChildSceneNode();
    myNode->attachObject( myItem );
    myItem->setDatablock( myDatablock );
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: [2.1] Equivelant of setDatablock() for a submesh?

Post by dark_sylinc »

SubMeshes don't hold the pointer of the datablock, but rather the name of the datablock so that it's looked up on instantiation as a SubItem.

Thus you can do:

Code: Select all

const String *datablockName = datablock->getNameStr();
if( datablockName )
    subMesh->setMaterialName( *datablockName );
else
{
    //Datablock is not visible to HlmsManager (probably it was created in a special way by calling directly Hlms::createDatablock)
    //You'll have to set the datablock by pointer once the subItem is instantiated, or make the datablock visible to the HlmsManager
}
Post Reply