Blender model have two materials,uv maps and textures, how switch texture?

Blender model have:
two materials
two uv maps
and two textures
->material->uv map->texture
->material->uv map->texture

If i click in blender assign material - texture change.

I convert model to j3o.
How i can change texture with material an uv map in source code?

1 Like

Maybe you are looking for something like this
https://jmonkeyengine.github.io/wiki/jme3/beginner/hello_asset.html
or
this
https://jmonkeyengine.github.io/wiki/jme3/beginner/hello_material.html

1 Like

I have blender model.

With uv map for texture.

Okay.
How to make some code like this.

  1. Load j3o model.
  2. Create material
  3. Attach uv map in j3o model to material
  4. Attach texture to material an uv map

j3o object already have 2 two material two maps and two textures.
I just need to switch

1 Like

I think:

  1. get geometry from model
  2. get material from geometry
  3. set texture

But how i can: get geometry and material from model?

This is node:
assetManager.loadModel(mesh);

1 Like
Spatial   spatial = assetManager.loadModel(mesh);
    Geometry myGeo = (Geometry)((Node)spatial).getChild("base.obj");

java.lang.ClassCastException: com.jme3.scene.Node cannot be cast to com.jme3.scene.Geometry

1 Like

You did not try to use the search?

1 Like

When applicable:

player = new Node("player");
rootNode.attachChild(player);

Then:

Spatial linkPlayer = rootNode.getChild("player");

1 Like

Make this:
moveSpatial.setMaterial(assetManager.loadMaterial(“Materials/Soldier.j3m”));
and add texture.

  1. Not use uv map
  2. Animations stop work

Load model
private String mesh = “Models/player.j3o”;

    characterModel = (Node) assetManager.loadModel(mesh);

Each root node:
factory-scene_node
Models/player-test-fix.blend

Spatial linkPlayer = rootNode.getChild(“Models/player-test-fix.blend”);
Geometry geo = (Geometry)linkPlayer;

Error
java.lang.ClassCastException: com.jme3.scene.Node cannot be cast to com.jme3.scene.Geometry

1 Like

When i open model in scene composer:
Base object have geometry. and we can change material

Maybe can get base object get geometry get materials and switch

1 Like

I will say briefly:

Geometry cube = new Geometry("Box", new Box(1, 1, 1));
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setName("My material");
cube.setMaterial(mat);
rootNode.attachChild(cube);

Spatial linkBox = rootNode.getChild("Box");
System.out.println(((Geometry) linkBox).getMaterial());
1 Like

And it is better for you to drop the test file for verification.

1 Like

I see but i load j3o and when i load - manager return Node.

When i each rootNode - returns:
main scene
blender object

I try

Spatial node = (Spatial) assetManager.loadModel(mesh);
//Node base = (Node) node.getChild(“base.obj”);

   Geometry myGeo = (Geometry)((Node)node).getChild("base.obj");

returns
java.lang.ClassCastException: com.jme3.scene.Node cannot be cast to com.jme3.scene.Geometry

1 Like

I kind of gave an example when it’s applicable? is not it? You persistently do it wrong.

You have enough:

node.getMaterial()

1 Like

Yes. Than’s i get geometry:

Node node      = (Node) assetManager.loadModel(mesh);
Geometry myGeo = (Geometry)node.getChild("base.obj1");

Now i need:

  1. Get materials from geometry.
  2. Get textures from materials
  3. Change texture

Or question on top:
Blender model have two material.
How i can get second (not used material)?

1 Like

Node node = (Node) assetManager.loadModel(mesh);
Geometry myGeo = (Geometry)node.getChild(“base.obj1”);

    Material material = myGeo.getMaterial();
    
    System.out.println(material.getName());

Returns: army
Used material army.

And model have second texture “Spec”.

I need get material Spec and set to geometry

1 Like

I again say to create a test model and throw off the link. I can not guess what you call materials.

1 Like

Model:
https://drive.google.com/open?id=0B-zv3i43GFAhQVdrN2xDbGVBcFE

Two materials
Two UV maps
Two Textures

Spec and army

1 Like

http://javadoc.jmonkeyengine.org/com/jme3/scene/Node.html#getChild-java.lang.String-

1 Like

Get child from geometry?

Question how to switch materials with textures.

I can:

  1. switch in blender
  2. extract in app
  3. save materials (Serializable)
  4. and load serialized materials
1 Like

If i use this code:

Node node = (Node) assetManager.loadModel(mesh);
Geometry myGeo = (Geometry)node.getChild(“base.obj2”);

    Material material = myGeo.getMaterial();
    
    myGeo.setMaterial(material);
    
    
    System.out.println(material.getName());





    myGeo.setMaterial(material);

Material in node will be changed?

1 Like