Hey,
I've been looking around, and I can't seem to find anything which deals with making models dynamic, I can't even find an example of an exported 3ds model with animation which has been loaded into jme and animated.
Basically, I how do I edit models or terrains made in 3ds with jME, or is it not possible. Say I have a 3ds model of a man who walks. Is there a way to start and stop the animation? Or add child nodes, for example a sword to his hand, then make that sword swing as he runs, in effect you are editing the .jme file temporarily, so will the entire animation need to be loaded again?
I'm finding it kind of hard to describe, sorry if you don't understand
Basically can I access and edit different aspects of my model, like the wheel of a car, through jme, and how?
Thanks
Sword in hand I don't know how to do.
This loads models of all files supported in JME 1.0's CVS.
public static Node loadModel (String modelFile){
Node loadedModel = null;
FormatConverter formatConverter = null;
ByteArrayOutputStream BO = new ByteArrayOutputStream();
String modelFormat = modelFile.substring(modelFile.lastIndexOf(".") + 1, modelFile.length());
String modelBinary = modelFile.substring(0, modelFile.lastIndexOf(".") + 1) + "jbin";
URL modelURL = Fyrestone.class.getClassLoader().getResource(modelBinary);
//verify the presence of the jbin model
if (modelURL == null){
modelURL = ModelLoader.class.getClassLoader().getResource(modelFile);
//evaluate the format
if (modelFormat.equals("3ds")){
formatConverter = new MaxToJme();
} else if (modelFormat.equals("md2")){
formatConverter = new Md2ToJme();
} else if (modelFormat.equals("md3")){
formatConverter = new Md3ToJme();
} else if (modelFormat.equals("ms3d")){
formatConverter = new MilkToJme();
} else if (modelFormat.equals("ase")){
formatConverter = new AseToJme();
} else if (modelFormat.equals("obj")){
formatConverter = new ObjToJme();
}
formatConverter.setProperty("mtllib", modelURL);
try {
formatConverter.convert(modelURL.openStream(), BO);
loadedModel = (Node) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
//save the jbin format
BinaryExporter.getInstance().save((Savable)loadedModel, new File(modelBinary));
} catch (IOException e) {
e.printStackTrace();
return null;
}
}else{
try {
//load the jbin format
loadedModel = (Node) BinaryImporter.getInstance().load(modelURL.openStream());
} catch (IOException e) {
return null;
}
}
return loadedModel;
}
This is an example of animation of a model (playing frames 206 to 250 repeatedly):
JointController char_controller;
char_controller = (JointController) charNode.getChild(0).getController(0);
char_controller.setTimes(206, 250);
char_controller.setRepeatType(JointController.RT_WRAP);
char_controller.setActive(true);
char_controller.setSpeed(.8f);
Trussell said:
Sword in hand I don't know how to do.
This loads models of all files supported in JME 1.0's CVS.
This is an example of animation of a model (playing frames 206 to 250 repeatedly):
JointController char_controller;
char_controller = (JointController) charNode.getChild(0).getController(0);
char_controller.setTimes(206, 250);
char_controller.setRepeatType(JointController.RT_WRAP);
char_controller.setActive(true);
char_controller.setSpeed(.8f);
Thanks, that helped me understand it a bit better :)
One more question (actually a few but I'l save them for later) ... How do you set the child node in the 3d modeling program - "charNode.getChild(0).getController(0);" - what is child 0? and how can you access different parts of a body or 3d character from this?
To attach somthing else could you not just simply find the child of the body which is the hand, and litterally attach a new spatial model of the sword.
Is there a way to edit the angle of limbs through that method? So that the model of the body can run with it's arm higher when it is holding the sword.
I'll have a look at the docs :)
And also, can I just save a .3ds model, convert it to .jme and do this, or do I need a specific type of model?
I think the child in this instance is the geometry (which is what a modeller creates), where the model loader has it attached to a node.
Stopping, or manipulating the animation can be done with the same commands already posted.
Attaching a weapon is not always quite as simple as attaching, as bones are not usually represented by nodes. But you can do essentially the same thing by just applying the bone's transforms to the weapon. Or you can add the weapon in the modeller as a seperate item and delete or switch it out in code.
You don't need to have a new animation, or edit the animation, unless the sword is animated itself in some way. If the sword simply follows the movement of the hand, then you don't need any extra animation data. That is, you might have an animation of the character swinging a sword, but really that's just an animation of the character. Whether they are really holding a sword or not is immaterial.
The code you see above actually converts the model from 3ds, but then it saves a .jbin which is JME's model format, and if that's available it decodes that instead.
If you make any changes to a model, you'll need to open the "models" folder that it creates and delete the .jbin, since it'll only import the .jbin if it finds it.
Greetings! I hope this information isn't coming too late! I haven't done this in jME yet but I have in other engines so the process should be very similar. To mount a Sword or other weapon is fairly simple. When you create your model you need to create a mount point. Usually a hand. In the specific modeling software this will be done many different ways so I suggest you look at the documentation for you specific one to see how. What you want to do is name the new mount point as "RightHand" or some such. When you load the model you can access this mount point by using the Node::getChild(String name) function. Attach your sword to that node and you now have a mounted sword!
As far as the animation is concerned you shouldn't access the bones through the code to make those changes! You should be making a specific animation for running with a weapon and call that when you have one equipped.
I hope this helps!