Hi everyone
I try to create an animation with an 3ds model. For this purpose I wrote my own class. Worked fine until i tried to set up my skeleton.
I cannot use setSkin() with the 3ds model node. Any ideas?
Thx
package game.bin.importer;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import com.jme.animation.SkinNode;
import com.jme.bounding.BoundingBox;
import com.jme.image.Texture;
import com.jme.math.FastMath;
import com.jme.math.Quaternion;
import com.jme.math.Vector3f;
import com.jme.scene.Node;
import com.jme.scene.shape.Box;
import com.jme.scene.state.TextureState;
import com.jme.system.DisplaySystem;
import com.jme.util.TextureManager;
import com.jme.util.export.binary.BinaryImporter;
import com.jmex.model.converters.MaxToJme;
public class Mesh extends Node{
private DisplaySystem display = null;
private URL model_path = null;
private URL texture_path = null;
private Node model = null;
private TextureState ts = null;
private SkinNode model_skin;
public Mesh(DisplaySystem display, String meshpath, String texturepath){
this.display = display;
texture_path = Mesh.class.getClassLoader().getResource(texturepath);
model_path = Mesh.class.getClassLoader().getResource(meshpath);
model_skin = new SkinNode("test skin");
model_skin.setSkin(loadMesh(model_path)); ////!!!!!!
this.attachChild(model_skin);
//this.attachChild(loadMesh(model_path));
}
public Node loadMesh(URL modelToLoad){
try {
MaxToJme C1 = new MaxToJme();
ByteArrayOutputStream BO = new ByteArrayOutputStream();
C1.convert(new BufferedInputStream(modelToLoad.openStream()), BO);
model = (Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
model.setLocalScale(1.0f);
model.setLocalTranslation(new Vector3f(0,0,0));
model.setModelBound(new BoundingBox());
model.updateModelBound();
model.setRenderState(loadTexture(texture_path));
Quaternion temp = new Quaternion();
temp.fromAngleAxis(FastMath.PI / 2, new Vector3f(-1, 0, 0));
model.setLocalRotation(temp);
return model;
} catch (IOException e) {
//logger.log(Level.SEVERE, "Failed to load Max file", e);
}
return null;
}
public TextureState loadTexture(URL textureToLoad){
TextureState ts=display.getRenderer().createTextureState();
ts.setTexture(TextureManager.loadTexture(texture_path ,Texture.MM_LINEAR,Texture.FM_LINEAR));
ts.setEnabled(true);
return ts;
}
public void rotate(float x, float y, float z){
Quaternion temp = new Quaternion();
temp.fromAngleAxis(x, new Vector3f(1, 0, 0));
model.setLocalRotation(temp);
}
}