Changing Asset Material to Unshaded Without Losing Texture

Hi there!

I’ve been making android applications recently and one of my biggest time consumers is properly texturing models on android to have unshaded materials but the proper textures

My current method involves making a material for each different material used in the model, then creating a texture key for it, then applying it to the correct area on the model via this method

[java] private void initHouse(){
building = new Node(“House”);
building = (Node) assetManager.loadModel(“Models/cg_house_A.j3o”);

Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
TextureKey key1 = new TextureKey("Textures/mortar_brick/D.png", false);
Texture tex1 = assetManager.loadTexture(key1);
mat1.setTexture("ColorMap", tex1);

Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
TextureKey key2 = new TextureKey("Textures/floor/D.png", false);
Texture tex2 = assetManager.loadTexture(key2);
mat2.setTexture("ColorMap", tex2);

Material mat3 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
TextureKey key3 = new TextureKey("Textures/roof_shale/D.png", false);
Texture tex3 = assetManager.loadTexture(key3);
mat3.setTexture("ColorMap", tex3);

Material mat4 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
TextureKey key4 = new TextureKey("Textures/roof_straw/D.png", false);
Texture tex4 = assetManager.loadTexture(key4);
mat4.setTexture("ColorMap", tex4);

building.getChild("house").setMaterial(mat1);
building.getChild("floor").setMaterial(mat2);
building.getChild("shale_roof").setMaterial(mat3);
building.getChild("straw_roof").setMaterial(mat4);
building.scale(1f);
RigidBodyControl buildPhys = new RigidBodyControl(0f);
building.addControl(buildPhys);
physics.getPhysicsSpace().add(buildPhys);
rootNode.attachChild(building);
buildPhys.setPhysicsLocation(new Vector3f(0, 0, 0));
}[/java] 

Something tells me that there may be an easier way than what Im doing. Perhaps just being to set the material to unshaded rather than recreating each material and texturing properly!

Thanks for reading and I hope I’ve communicated my issue properly

Anyone?

I could really use some help here as the models often have 5-6 different materials. And it would be nice to just get the materials and change them from lighted to unshaded!

Thanks for reading!

It would be smarter to make a method that reads the previous texture name and applies an unshaded material with it instead of naming every texture in code… Just use the SceneGraphVisitor interface to get all geometry, check the material and apply a new one.

Put another way…

Which parts are you having trouble with:

  1. Finding all relevant geometry?

  2. Getting the material?

  3. Getting the texture from that material?

  4. Or setting that texture to a new material?

@pspeed

Pretty much all of those things. I have a node and am able to get the geometry via the getChild() method and casting it to geometry, but that defeats what I’m trying to do.

I guess an answer to all of them, because I wouldn’t know how to tell the difference between the nodes children, and whether they are geometry or a node containing more geometries.

I’m not super good with programming yet, but I’m sure theres a way to say like

thisNode.getAllGeometries()

and get a list and iterate over those, getting the texture, creating a new unshaded material, and assigning that texture to the new unshaded material.

How to do this, Im unsure…

http://hub.jmonkeyengine.org/javadoc/com/jme3/scene/SceneGraphVisitorAdapter.html