AdiDOS
June 8, 2017, 2:55pm
21
Since you forgot the texture, then an example without textures.
Spatial Model = assetManager.loadModel("player-test-fix.j3o");
rootNode.attachChild(Model);
SceneGraphVisitor searchGeomMat = new SceneGraphVisitor() {
public void visit(Spatial spatial) {
System.out.println("Geometry =" + spatial);
if (spatial instanceof Geometry) {
Geometry geom = (Geometry) spatial;
System.out.println("Material =" + geom.getMaterial());
}
}
};
Model.depthFirstTraversal(searchGeomMat);
1 Like
nnpa
June 8, 2017, 3:20pm
22
Geometry =base.obj1 (Geometry)
Material =Army
Geometry =base.obj2 (Geometry)
Material =null
Geometry =base.obj3 (Geometry)
Material =null
Geometry =base.obj4 (Geometry)
Material =null
Geometry =base.obj (Node)
Geometry =Armature (Node)
Geometry =Lamp (LightNode)
Geometry =Camera (CameraNode)
Thank’s.
model have only assigned in blender material.
I think need:
assign material
save (serialize) material
load needed material
1 Like
AdiDOS
June 8, 2017, 4:02pm
23
Here’s an example of replacing a material, if you want to do it later, just assign it a variable.
Spatial Model = assetManager.loadModel("player-test-fix.j3o");
rootNode.attachChild(Model);
SceneGraphVisitor searchGeomMat = new SceneGraphVisitor() {
public void visit(Spatial spatial) {
if (spatial instanceof Geometry) {
Geometry geom = (Geometry) spatial;
if (geom.getMaterial().getName().equals("Spec")) {
Material mat = geom.getMaterial();
Model.setMaterial(mat);
}
}
}
};
Model.depthFirstTraversal(searchGeomMat);
EDIT: This can be interesting.
https://jmonkeyengine.github.io/wiki/jme3/advanced/save_and_load.html
1 Like
nnpa
June 8, 2017, 4:11pm
24
Thanks. Have null and army:
Think use this:
get material
serialize
load material
/*
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
*/
package custom;
import com.jme3.material.Material;
import java.io.Serializable;
/**
*
@author nn
*/
public class MaterisalSerializable extends Material implements Serializable {
}
/*
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
*/
package custom;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Base64;
/**
*
@author nn
*/
public class Serialize {
private static Object fromString( String s ) throws IOException, ClassNotFoundException {
byte data = Base64.getDecoder().decode( s );
ObjectInputStream ois = new ObjectInputStream(
new ByteArrayInputStream( data ) );
Object o = ois.readObject();
ois.close();
return o;
}
/** Write the object to a Base64 string. */
private static String toString( Serializable o ) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream( baos );
oos.writeObject( o );
oos.close();
return Base64.getEncoder().encodeToString(baos.toByteArray());
}
}
1 Like
AdiDOS
June 8, 2017, 4:19pm
25
I do not think it’s right, it’s better to get all the parameters of the material and make the file readable in text form. You can edit it later with your hands. And it’s better to create it manually at once.
1 Like
nnpa
June 8, 2017, 4:23pm
26
Material file contains big lists and hash maps.
Write material with hands - big work.
Simple serialize object to string
1 Like
nnpa
June 8, 2017, 4:39pm
27
Node node = (Node) assetManager.loadModel(modelPath);
Geometry myGeo = (Geometry)node.getChild(“base.obj1”);
Material material = myGeo.getMaterial();
MaterisalSerializable materialSerializ = (MaterisalSerializable) material;
java.lang.RuntimeException: Uncompilable source code - incompatible types: com.jme3.material.Material cannot be converted to custom.MaterisalSerializable
But MaterisalSerializable extends Material
1 Like
AdiDOS
June 8, 2017, 4:52pm
29
System.out.println(mat.getParams());
Based on them, create a material file: j3m
Material My shiny custom material : Common/MatDefs/Light/Lighting.j3md {
MaterialParameters {
DiffuseMap : Textures/Terrain/Pond/Pond.jpg
NormalMap : Textures/Terrain/Pond/Pond_normal.png
UseMaterialColors : true
Specular : 1.0 1.0 1.0 1.0
Diffuse : 1.0 1.0 1.0 1.0
Shininess : 64.0
}
}
The problem can arise with obtaining all the parameters.
1 Like
nnpa
June 8, 2017, 5:23pm
30
Maybe i get all parameters from material.
Add to class for save (serrialize).
Add set when it need?
1 Like
nnpa
June 8, 2017, 5:37pm
32
Thank’s i believe i solve this problem. I post answer later
1 Like
nnpa
June 9, 2017, 6:04pm
34
I try to:
create material
add map
add change in scene composer
material switch but uv coordinates no asinged
1 Like
nnpa
June 9, 2017, 6:32pm
36
I generate tangents change texture position on model
not by uv in blender
1 Like