Applying color to a MESH. What am I doing wrong?

eddy

06-08-2011 21:34:15

Hello to all!

First of all I hope I won't get banned for opening topics with this rate, but I couldn't fix this (this is one of my first problems when I took up MOGRE, but I chose to fix this later), even after reading some stuff on the wiki and the forums. I am exporting with ogremax, today I have tried the neoaxis exporter as well.
As always pictures tell a thousand words, and lets say that till this step i am OK with the result:

I keep my model files in \Media\models\ and my mesh files in \Media\materials\scripts\
The upper setup gives me the following:
from the log:

Mesh: Loading torsoMesh5.mesh.
22:10:27: Mesh: Loading Glava4.mesh.
22:10:27: Mesh: Loading prviZglob5.mesh.
22:10:27: Can't assign material 01-Default to SubEntity of prviZglob because this Material does not exist. Have you forgotten to define it in a .material script?
22:10:27: Mesh: Loading drugiZglob6.mesh.
22:10:27: Can't assign material 01-Default to SubEntity of drugiZglob because this Material does not exist. Have you forgotten to define it in a .material script?
22:10:27: Mesh: Loading treciZglob3.mesh.
22:10:27: Can't assign material 01-Default to SubEntity of treciZglob because this Material does not exist. Have you forgotten to define it in a .material script?
22:10:27: Mesh: Loading prviZglobDesni1.mesh.
22:10:27: Can't assign material 01-Default to SubEntity of prviZglobDesni because this Material does not exist. Have you forgotten to define it in a .material script?
22:10:27: Mesh: Loading drugiZglobDesni2.mesh.
22:10:27: Can't assign material 07-Default to SubEntity of drugiZglobDesni because this Material does not exist. Have you forgotten to define it in a .material script?
22:10:27: Mesh: Loading treciZglobDesni3.mesh.
22:10:27: Can't assign material 01-Default to SubEntity of treciZglobDesni because this Material does not exist. Have you forgotten to define it in a .material script?
22:10:27: Mesh: Loading CoordMeshManji2.mesh.
22:10:27: Can't assign material 07-Default to SubEntity of Koordinatni sistem because this Material does not exist. Have you forgotten to define it in a .material script?
22:10:27: Can't assign material 07-Default to SubEntity of Koordinatni sistem because this Material does not exist. Have you forgotten to define it in a .material script?
22:10:27: Can't assign material 02-Default to SubEntity of Koordinatni sistem because this Material does not exist. Have you forgotten to define it in a .material script?
22:10:27: Can't assign material 01-Default to SubEntity of Koordinatni sistem because this Material does not exist. Have you forgotten to define it in a .material script?
22:10:27: Can't assign material 01-Default to SubEntity of Koordinatni sistem because this Material does not exist. Have you forgotten to define it in a .material script?
22:10:27: Can't assign material 02-Default to SubEntity of Koordinatni sistem because this Material does not exist. Have you forgotten to define it in a .material script?

Which is ok, since I didn't copy the missing material files over to \Media\materials\scripts\
Then I add prviZglobDesni1.material or prviZglob5.material and nothing happens.
I found out, that when I open them i Total Commander, they are almost empty (i.e. pass is empty):

material 01-Default
{
technique
{
pass
{
}

}

}

Again understandable (more on this later).
Then I add, for example, drugiZglob6.material:

material 01-Default
{
technique
{
pass
{
ambient 0.211765 1 0.266667 1
diffuse 0.211765 1 0.266667 1
specular 0 0 0 1 10
}

}

}

and this happens:

I have tried replacing the code in the scripts according to http://www.ogre3d.org/tikiwiki/Materials, but the end result is the same, or no change at all.
The funny part, from the log file:

22:20:38: Mesh: Loading torsoMesh5.mesh.
22:20:38: Mesh: Loading Glava4.mesh.
22:20:38: Mesh: Loading prviZglob5.mesh.
22:20:38: Mesh: Loading drugiZglob6.mesh.
22:20:38: Mesh: Loading treciZglob3.mesh.
22:20:38: Mesh: Loading prviZglobDesni1.mesh.
22:20:38: Mesh: Loading drugiZglobDesni2.mesh.
22:20:38: Can't assign material 07-Default to SubEntity of drugiZglobDesni because this Material does not exist. Have you forgotten to define it in a .material script?
22:20:38: Mesh: Loading treciZglobDesni3.mesh.
22:20:38: Mesh: Loading CoordMeshManji2.mesh.
22:20:38: Can't assign material 07-Default to SubEntity of Koordinatni sistem because this Material does not exist. Have you forgotten to define it in a .material script?
22:20:38: Can't assign material 07-Default to SubEntity of Koordinatni sistem because this Material does not exist. Have you forgotten to define it in a .material script?
22:20:38: Can't assign material 02-Default to SubEntity of Koordinatni sistem because this Material does not exist. Have you forgotten to define it in a .material script?
22:20:38: Can't assign material 02-Default to SubEntity of Koordinatni sistem because this Material does not exist. Have you forgotten to define it in a .material script?

As it can be seen, the materials are loaded even though I haven't copied their respective *.material files over to \Media\materials\scripts\

or when I have only the prviZglobDesni1.material or prviZglob5.material AND the material file for the coordinate system at the head:


What could be the procedure to correct this?

for example I have tried to replace some of the script files with this (for example the "almost empty" script files, and nothing happens):
material Red
{
technique
{
pass
{
lighting off
scene_blend alpha_blend
depth_check off

texture_unit
{
texture red.png
alpha_op_ex source1 src_manual src_current 0.5
}
}
}
}

or this:

material Template/Red
{
technique
{
pass
{
texture_unit
{
colour_op_ex source1 src_manual src_current 1 0 0
}
}
}
}

or even with the script content with the above torsoMesh5 file.

smiley80

07-08-2011 02:31:42

The filename of a material script doesn't matter. The name of a material is the string after 'material' (e.g. '01-Default'). When entities have the same material name and resource group they share the same material.

eddy

07-08-2011 09:26:56

Thank you!

So does this mean that I can chose material in code with the mogre equivalent of MaterialManager::getSingleton().getByName()? Or how to point to a specific material name/material script ?

smiley80

07-08-2011 11:46:57

Entity.SetMaterialName
If you already have a MaterialPtr:
Entity.SetMaterial

eddy

07-08-2011 12:19:21

Yes, that did the trick:


Your first post really cleared it up for me. Thanks.

Beauty

19-08-2011 20:58:49

Side note:
You don't need a material file for each colour.
If you like you can create materials by source code.

You also can define a "default" material with specific settings.
Later you can create clones by source code and modify them (e.g. colour values or transparency).

Basic material informations are in the wiki. At the bottom I added many related links.
http://www.ogre3d.org/tikiwiki/-material

Here I is a tiny example how to create material by code:

MaterialPtr matPtr = MaterialManager.Singleton.Create("line_material", "debugger");
matPtr.ReceiveShadows = false;
matPtr.GetTechnique(0).SetLightingEnabled(true);
matPtr.GetTechnique(0).GetPass(0).SetDiffuse(0, 0, 1, 0);
matPtr.GetTechnique(0).GetPass(0).SetAmbient(0, 0, 1);
matPtr.GetTechnique(0).GetPass(0).SetSelfIllumination(0, 0, 1);
matPtr.Dispose(); // dispose pointer, not the material