[solved] changing submaterial

Problems building or running the engine, queries about how to use features etc.
Post Reply
User avatar
sphinkie
Greenskin
Posts: 114
Joined: Wed Jul 07, 2004 11:08 am
Location: Paris
x 1
Contact:

[solved] changing submaterial

Post by sphinkie »

Hi,
I have a small problem with materials, in my game.

I have a class "computer" with its entity and its behaviour.
In the room, I have 8 computers.

In the 3D object, I have a material called "computer/screen".

And I want to change this material, for only one computer, for writting a red large "ALARM" (for instance).

I was using the following code, to find the material:

Code: Select all

int NumSubEntities = mEntity->getNumSubEntities();
for (int i=0; i<NumSubEntities; i++) 
	{
	String MatName = mEntity->getSubEntity(i)->getMaterialName();
	if (MatName == "computer/screen")  mScreenEntity=i;
	}
and this code to change the material:

Code: Select all

mEntity->getSubEntity(mScreenEntity)->setMaterialName("computer/alarm");
But the material change for the whole scene, so for all the 8 computer, and not only 1.

Do you know if there is a way to change a material, for only one instance of several entities ?
thanks
Last edited by sphinkie on Mon Nov 28, 2005 3:36 pm, edited 2 times in total.
Magefire
Gnoblar
Posts: 11
Joined: Sat Feb 19, 2005 10:52 pm

Post by Magefire »

I'm not very good at using OGRE but I read the documentation and it says that you can just set the entire material of the entity using

Code: Select all

mEntity->setMaterialName("computer/screen").
Also, to retrieven subentities, the only two options for parameters I saw were a string for the name or an integer for the index but you seem to be passing the parent entity as a parameter and I couldn't find an option for passing an entity as a parameter to getSubEntity().

I hope this helped.
User avatar
Cyberdigitus
Halfling
Posts: 55
Joined: Thu Mar 04, 2004 7:08 pm
Location: Belgium
Contact:

Post by Cyberdigitus »

You can set names to subentities, independent of the subentity material name, so you can easily get the subobject in question:

void Mesh::nameSubMesh (const String &name, ushort index) // Gives a name to a SubMesh.
SubEntity * Entity::getSubEntity (const String &name) // Gets a pointer to a SubEntity by name.

Setting a material to the entity will set the same to all subentities, maybe some utility function to deal with multimaterials and above mentioned subEntity naming would be nice?

Is it possible to define those names in addition or instead of material names in the mesh.xml actually? That would be nice.
. . .
User avatar
sphinkie
Greenskin
Posts: 114
Joined: Wed Jul 07, 2004 11:08 am
Location: Paris
x 1
Contact:

Post by sphinkie »

Thanks guys.

well Mage, you were right, but it was only a cut/paste error in my post.
and cyberdigitus, you way is maybe cleaner than mine, and I will use it.

but strangely, I made few more testing this afternoon, and it seems to work without touching anything... strange.... I will carry on anyway.
Post Reply