Ingame changing material

Hi clever people :slight_smile:

Is there any tutorial to get material from loaded ogre mesh object and change it diffuse/specular/etc?

i can set material but it delete texture and texture parameters from old material

I look at all methods and variables and never seen spatial/node material to get ;/ (maybe im just blind)

If someone know such tutorial like editing material intime, then thanks :slight_smile:

the material can only be set/get on a Geometry object.

The Node.setMaterial() method just recurse through the children and set the material to any found geometries.



So if you want to change some parameters in a material, you have to do the same : find a geom and get its material.



There are several ways of doing this but the easiest is to use the node.getChild(“nameOfTheGeometry”). But you have to know the name of the geom. You can see how they are named in the Scene explorer window in jmp when you load a j3o or mesh.xml file.

Also you can get the geom getChild(indexof the geom), but the geom has to be a direct child of the node.

1 Like

thank u, i will try do somethin with it

will it be somethin like it?:

[java]

public void updateMaterial(Spatial spatial) {

try {

if (spatial instanceof Node) {

Node node = (Node) spatial;

for (int i = 0; i < node.getQuantity(); i++) {

Spatial child = node.getChild(i);

updateMaterial(child);

}

} else if (spatial instanceof Geometry) {

Geometry geo = (Geometry) spatial;

geo.getMaterial(); // YEA

}

} catch (Exception err) {

System.out.println("Exception ExtNode::updateMaterial() err: " + err + " | " + err.getLocalizedMessage() + " | " + err.getMessage() + " | " + err.toString());

}

}[/java]

Yeah that’s it :wink: