Hi all!
How can move my model's parts separate? Is there any geneal solution in jme?
For example:
I have a tank model in my game.
How can i do that the tank's tower rotate separate from the tank's body?
I want to turn the tower around tank'a axle.
Should i load the tank's body and tower model in a separate .obj file?
Or it can be solvable using jme?
Thanks and sorry for my English!
Yes, you should have a separate object for each moving part of a larger model.
So for a tank - separate body, turret, wheels and tracks.
JOC said:
Yes, you should have a separate object for each moving part of a larger model.
So for a tank - separate body, turret, wheels and tracks.
I see.
Btw, is there any accepted solution for this in JME?
But you don't need multiple models. You can do with a single model too.
If your export format can represent groups, you can walk the node graph and retrieve a reference to your turret. Then you can rotate that node separately from the body.
It can be organised in different ways. I use this after loading the model:
hull = ((Node)((Node)spatial).getChild("Tank")).getChild("Hull");
canon = ((Node)((Node)spatial).getChild("Tank")).getChild("Canon");
My model has a Tank object which contains Hull and Canon objects. So I keep a reference to the hull and canon and I rotate them separately. When I need to translate the tank I move the node that contains everything.
Hi
I tried it with a .obj model, exported from 3dstudio.
The tank has seperate groups for the tank body and the canon.
Try to import it:
private void createTankPlayer() {
URL loc = TankGame.class.getClassLoader().getResource("tank/res/tank.obj");
FormatConverter converter = new ObjToJme();
converter.setProperty("mtllib", loc);
ByteOutputStream out = new ByteOutputStream();
TriMesh tankModel = null;
try {
converter.convert(loc.openStream(), out);
tankModel = (TriMesh)BinaryImporter.getInstance().load(out.toByteArray());
} catch (IOException ioe) {
ioe.printStackTrace();
}
if (tankModel != null) {
tankModel.setLocalScale(.30f);
tankModel.setModelBound(new BoundingBox());
tankModel.updateModelBound();
playerNode = new Tank("TankModel", tankModel);
((Vehicle)playerNode).setAcceleration(15);
((Vehicle)playerNode).setBreaking(25);
((Vehicle)playerNode).setWeight(50);
((Vehicle)playerNode).setTurnSpeed(0.3f);
playerNode.updateWorldBound();
playerNode.attachChild(tankModel);
tankModel.updateRenderState();
rootNode.attachChild(playerNode);
rootNode.updateGeometricState(0, true);
playerNode.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
}
}
After that i tried to list it's children.
((Node)((Node)playerNode).getChild("temp0")).getChildren()
But the playerNode.getChild("temp0") is a TriMesh.
So when i try to cast it to Node to get it's children i get a ClassCastException.
I see that the TriMesh is not subclass of Node.
Should i load the object an other way?
Here is a ready-to-run app where you can use the properties window to move the different nodes of the robot. http://pub.admc.com/misc/articulated-robot.jnlp. Click the iconified tree node viewer to use it. I created this model before I committed to a scale, so you need to back up with the s key to see the whole thing (or you could use the properties window to rescale it).
I recently improved Ogreloader to load nested objects. So, you can create nested objects in just about any modeling tool, including Blender, export, them load them into jME. You can use the Modeler app above to test and manipulate these exports if you wish.