Two independernt textures in a single geometry

I have an asset(turtle), and is has two parts(but one geometry, with tow different texture, with their independent 0-1 coordinate) with different materials(from Maya, lambert for turtle’s skin and blinn for its shell).

When I import this model and use it without any material overwriting, things are fine



But, now i want the turtle to glow sometime, when player pick any weapon, so, it stands out from the environment.



Problem starts when I try the following code:



[java] geo_turtle = assetManager.loadModel(“Models/turtle/turtle.j3o”);

mat_turtle = new Material(assetManager, “Common/MatDefs/Light/Lighting.j3md”);

mat_turtle.setTexture(“m_DiffuseMap”, assetManager.loadTexture(“Models/turtle/turtle_shell2.jpg”));

mat_turtle.setTexture(“m_DiffuseMap”, assetManager.loadTexture(“Models/turtle/turtle_body2.jpg”));

geo_turtle.setMaterial(mat_turtle);

[/java]



The body texture is covering the whole geometry.2nd assignment to m_DiffuseMap is overwriting the first one.

So, how do i set two different texture in a single geometry?



or, is there any way to put on another material without overwriting the default(the one that comes from Maya) one.I just need to control the glow parameter, nothing else.

Lighting mat def supports 7 kinds of texture : m_GlowMap, M_SpecularMap, m_NormalMap, m_DiffuseMap, m_AlphaMap, m_Color_Ramp and m_ParallaxMap. So you just can assign one texture for each.

here is the issue, I have 2 textures that I need to assign on one object, which is actually comprised to two parts, which has their independent texture coordinate.



but, here inside of jMonkey, I am accessing the model as a whole and I have only one m_DiffuseMap channel to plug in, only one texture.But, I need to two m_DiffuseMap channel to set two different texture on one model.

iamcreasy said:
[java] geo_turtle = assetManager.loadModel("Models/turtle/turtle.j3o");
mat_turtle = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
mat_turtle.setTexture("m_DiffuseMap", assetManager.loadTexture("Models/turtle/turtle_shell2.jpg"));
mat_turtle.setTexture("m_DiffuseMap", assetManager.loadTexture("Models/turtle/turtle_body2.jpg"));
geo_turtle.setMaterial(mat_turtle);
[/java]


Hmm! "geo_turtle" isn't a geometry, it's a node. Nodes has no materials. Geometries that has materials. Despite nodes has the "setMaterial" method, They has no materials. Then you must to do so:

[java]
...
Node turtleNode = (Node) assetManager.loadModel("Models/turtle/turtle.j3o");
Geometry geo1 = findGeom(turtleNode, "geo1");
Geometry geo2 = findGeom(turtleNode, "geo2");
mat_turtle = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
mat_turtle.setTexture("m_DiffuseMap", assetManager.loadTexture("Models/turtle/turtle_shell2.jpg"));
mat_turtle.setTexture("m_DiffuseMap", assetManager.loadTexture("Models/turtle/turtle_body2.jpg"));
geo1.setMaterial(mat_turtle);
geo2.setMaterial(mat_turtle);
}

private Geometry findGeom(Spatial spatial, String name){
if (spatial instanceof Node){
Node node = (Node) spatial;
for (int i = 0; i < node.getQuantity(); i++){
Spatial child = node.getChild(i);
Geometry result = findGeom(child, name);
if (result != null)
return result;
}
}else if (spatial instanceof Geometry){
if (spatial.getName().startsWith(name))
return (Geometry) spatial;
}
return null;
}
}
[/java]

@iamcreazy the lighting material supports only one diffuse texture it won’t work like this.

I guess you have 2 sub geometries, aren’t you ?

If so, you have to create 2 materials one for each geometry (you’ll have to set the glowColors for both materials).

to know the names of sub geometries, open your model in the scene composer, and look at the scene explorer view (bottom left), you’ll see the tree representation of the node.



@glaucomardano turtleNode.getChild(“geo1”) does exactly what your findGeom does, you know?

1 Like
nehon said:@glaucomardano turtleNode.getChild("geo1") does exactly what your findGeom does, you know?


Humm! Really! I didn't know that the "getChild" method was so effective :D. Because i saw the "findGeo" method at the TestFancyCar.java.

Yep that test is pretty old, now getChild is recursive through all the children of a node.

it worked, with two different materials, :slight_smile: