Hi,
I would like to change the color of my mesh during the game.
What is the most efficient way to do it??
I think I have to play with the material of the entity but I don't know if it's the must.
Thanks
Charlie
Modify the color of a mesh
-
- Kobold
- Posts: 26
- Joined: Sun Sep 16, 2007 2:38 pm
- Location: France
-
- OGRE Team Member
- Posts: 4308
- Joined: Mon Feb 04, 2008 2:02 pm
- Location: Germany
- x 137
Re: Modify the color of a mesh
Yes, the visual appearance of a mesh is defined by its material script. Those can be modified at runtime.
Code: Select all
m_pMat = m_pEntity->getSubEntity(0)->getMaterial();
m_pMat->getTechnique(0)->getPass(0)->setAmbient(1, 0, 0);
m_pMat->getTechnique(0)->getPass(0)->setDiffuse(1, 0, 0, 0);
m_pEntity->setMaterialName(m_pMat->getName());
Ogre Admin [Admin, Dev, PR, Finance, Wiki, etc.] | BasicOgreFramework | AdvancedOgreFramework
Don't know what to do in your spare time? Help the Ogre wiki grow! Or squash a bug...
Don't know what to do in your spare time? Help the Ogre wiki grow! Or squash a bug...
-
- Kobold
- Posts: 26
- Joined: Sun Sep 16, 2007 2:38 pm
- Location: France
Re: Modify the color of a mesh
Ok thanks for your answer.
Is it time consuming??
Is it time consuming??
-
- OGRE Team Member
- Posts: 4308
- Joined: Mon Feb 04, 2008 2:02 pm
- Location: Germany
- x 137
Re: Modify the color of a mesh
I assume you mean the performance: I never had any problems with it. I even used to make this call once per frame in order to constantly change the alpha value so that my objects fade in and out all the time.
Ogre Admin [Admin, Dev, PR, Finance, Wiki, etc.] | BasicOgreFramework | AdvancedOgreFramework
Don't know what to do in your spare time? Help the Ogre wiki grow! Or squash a bug...
Don't know what to do in your spare time? Help the Ogre wiki grow! Or squash a bug...
-
- Kobold
- Posts: 26
- Joined: Sun Sep 16, 2007 2:38 pm
- Location: France
Re: Modify the color of a mesh
Yeah that's what I meant, sorry for my english 

-
- Gnome
- Posts: 350
- Joined: Sun Feb 10, 2008 2:07 pm
Re: Modify the color of a mesh
Be aware that changing an entity's material changes all entities which share this material.
-
- Kobold
- Posts: 26
- Joined: Sun Sep 16, 2007 2:38 pm
- Location: France
Re: Modify the color of a mesh
Ok so I have to create a new material each time... but I will quickly have some memory issues... any advice?
I want each entity to be independant from all the others.
Anyway I have a problem... I've changed the color but nothing happen on screen (I checked in debug).
I want each entity to be independant from all the others.
Anyway I have a problem... I've changed the color but nothing happen on screen (I checked in debug).
-
- OGRE Team Member
- Posts: 4308
- Joined: Mon Feb 04, 2008 2:02 pm
- Location: Germany
- x 137
Re: Modify the color of a mesh
Did you stick to the example I posted above, meaning that you also applied the altered material to the Ogre::Entity? Just chaning it in the code without reapplying won't make anything happen visually.
Yes, you will need an own material for each Ogre::Entity if you want them to look different. As the materials are nothing big, I would not bother about the RAM.
You can therefore clone one exisiting materal, if you only have to change small things (of course you can also define new ones everytime).
Yes, you will need an own material for each Ogre::Entity if you want them to look different. As the materials are nothing big, I would not bother about the RAM.
You can therefore clone one exisiting materal, if you only have to change small things (of course you can also define new ones everytime).
Code: Select all
Ogre::MaterialPtr* m_pMat = m_pExistingMat->clone("NewMatName");
Ogre Admin [Admin, Dev, PR, Finance, Wiki, etc.] | BasicOgreFramework | AdvancedOgreFramework
Don't know what to do in your spare time? Help the Ogre wiki grow! Or squash a bug...
Don't know what to do in your spare time? Help the Ogre wiki grow! Or squash a bug...
-
- Gremlin
- Posts: 150
- Joined: Thu Apr 01, 2004 5:55 pm
- x 5