nnpa
June 8, 2017, 10:54am
1
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
nnpa
June 8, 2017, 11:23am
3
I have blender model.
With uv map for texture.
Okay.
How to make some code like this.
Load j3o model.
Create material
Attach uv map in j3o model to material
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
nnpa
June 8, 2017, 12:16pm
4
I think:
get geometry from model
get material from geometry
set texture
But how i can: get geometry and material from model?
This is node:
assetManager.loadModel(mesh);
1 Like
nnpa
June 8, 2017, 12:22pm
5
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
AdiDOS
June 8, 2017, 12:58pm
6
You did not try to use the search?
Is it possible to get the material of a loaded model?
I’m loading a model from blender as .obj. It works all fine and it is correctly textured and colored. And i can set the material to for example another SolidColor with setMatrial and the definition. But how can i reverse it back to its original texture/color? Must i somehow export the texture from blender and load it as a material? Or is there a reset method that i didn’t discover yet?
1 Like
nnpa:
.getChild()
When applicable:
player = new Node("player");
rootNode.attachChild(player);
Then:
Spatial linkPlayer = rootNode.getChild("player");
1 Like
nnpa
June 8, 2017, 1:31pm
8
Make this:
moveSpatial.setMaterial(assetManager.loadMaterial(“Materials/Soldier.j3m”));
and add texture.
Not use uv map
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
nnpa
June 8, 2017, 1:57pm
9
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
AdiDOS
June 8, 2017, 1:59pm
10
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
AdiDOS
June 8, 2017, 2:04pm
11
And it is better for you to drop the test file for verification.
1 Like
nnpa
June 8, 2017, 2:06pm
12
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
AdiDOS
June 8, 2017, 2:08pm
13
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
nnpa
June 8, 2017, 2:13pm
14
Yes. Than’s i get geometry:
Node node = (Node) assetManager.loadModel(mesh);
Geometry myGeo = (Geometry)node.getChild("base.obj1");
Now i need:
Get materials from geometry.
Get textures from materials
Change texture
Or question on top:
Blender model have two material.
How i can get second (not used material)?
1 Like
nnpa
June 8, 2017, 2:19pm
15
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
AdiDOS
June 8, 2017, 2:21pm
16
I again say to create a test model and throw off the link. I can not guess what you call materials.
1 Like
nnpa
June 8, 2017, 2:28pm
17
1 Like
pspeed
June 8, 2017, 2:38pm
18
1 Like
nnpa
June 8, 2017, 2:46pm
19
Get child from geometry?
Question how to switch materials with textures.
I can:
switch in blender
extract in app
save materials (Serializable)
and load serialized materials
1 Like
nnpa
June 8, 2017, 2:51pm
20
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