How to rotate the model in the model j3o

There is model tank j3o - in him model body and tower. I load model:

Spatial tank = assetManager.loadModel(“Models/tank1/model.j3o”);
tank.scale(0.30f, 0.30f, 0.30f);
tank.setLocalTranslation(2.0f,-2.5f,0.0f);

tank.tower.rotate(0.0f, -3.0f, 0.0f); // not work

rootNode.attachChild(tank);

How to apply to the tower and rotate it?

Sorry for my English.

Open your .j3o and in the editor, you can manually select the tower geo and apply translation, rotation and scale to the model. This way, when you load the model to a node, the scale, rotation and translation is already defined.

To get the tower model, you must first cast the tank to a Node. Assuming the name of your tower model is Tower:

((Node)tank).getChild("Tower");

Lastly, rotation is in radians, not degrees. If you want to rotate using degrees, do:

tank.rotate(0.0f, FastMath.DEG_TO_RAD * -3.0f, 0.0f);

Now, after reading this, do all of the tutorials and read Math and Scenegraph for Dummies.

1 Like

Thank you! Rewrite code.

    Node modelTank = (Node)assetManager.loadModel("Models/tank1/model.j3o");

    Node tankBody = (Node) modelTank.getChild("Tank main");
    Node tankTower = (Node) modelTank.getChild("Tower");
    
    rootNode.attachChild(tankBody); 
    rootNode.attachChild(tankTower); 
    
    tankTower.rotate(0f,1.2f,0f);

It works!

1 Like

You don’t have to do this. Just attach the modelTank itself.

STRONGLY recommend you read:
http://wiki.jmonkeyengine.org/doku.php/jme3:scenegraph_for_dummies

2 Likes

Thank you! I will read it.