How to reuse models & How to set Spatial angle correctly?

Hello there,

is there a faster way than reloading the same model all the time like:

 tree[0] = assetManager.loadModel("Models/tree/tree.mesh.j3o"); ?

My second problem is that I cannot change the angle of my models, no matter which values I use inside “poster.setLocalRotation(getPosterAngle(0)):” Do you have any idea what I’m doing wrong?

public static Quaternion getPosterAngle(int i){
        Quaternion q = new Quaternion();
        if(i == 0){
            float[] angles = {0f,0f,90f};
        q.fromAngles(190.0068030576f, -190.11012821f, 190.9938941f);
        return q;

tree[0].clone(); to clone the model, rather than reloading it. (assuming tree[0] is already the model you want to reload)

I rotate models by using spatial.rotate(0,FastMath.PI,0);

  1. First you use the assetManager.load mode as you typed;
tree[0] = assetManager.loadModel("Models/tree/tree.mesh.j3o");

then you can call the clone method to retrieve a fresh copy

tree[1] = tree[0].clone();


tree[i] = tree[0].clone();
  1. Are you calling

after you retrieve the quaternion from the angles? If you just make a random quaternion then the game engine will have no idea what to do with it.

At first thanks for answering me :slight_smile:

would this be correct? The loadingtime is still pretty long sadly

public void spawnEnvironment(){       

    Spatial tree[] = new Spatial[11];
    Spatial bush[] = new Spatial[17];
    tree[0] = assetManager.loadModel("Models/tree/tree.mesh.j3o"); 
     for(int i = 1;i < 11;i++){             
        //tree[i] = assetManager.loadModel("Models/tree/tree.mesh.j3o"); 
        tree[i] = tree[0].clone();

and yes Im doing:


which returns the quaternion


seems to create a copy of the model which becomes invisible and visible again in a loop // called in simpleUpdate

Quaternion q = new Quaternion(new float[]{0, FastMath.PI,0});

A second call to assetManager.loadModel() is already just cloning the original… and it’s smartly doing it without any of your local updates.

Anywhere the API takes angles will always be in radians… which makes something like 190 a ridiculously high value.

…and no matter what i is, this method will always return the same value:
q.fromAngles(190.0068030576f, -190.11012821f, 190.9938941f);

Okay thank you, it looks like changing the angle works fine.
Is there a way to easily get the correct angle? When I print the camera rotation, it has 4 values instead of 3?

      System.out.println("Position: " + player.getPhysicsLocation());
      System.out.println("Angle: " + cam.getRotation());
      System.out.println("Direction: " + cam.getDirection());

Rotation is represented as a quaternion. These values are magic 4 dimensional values.

To get angles out, use toAngles(). Note: that you may not get the angles you expect out of it because euler angles are ambiguous… but they will be accurate angles.

in Radians.

Oh okay thank you. Could u explain the toAngles cmd a lil bit more? I wonder which parameter I should use instead of null since I dont have an angle float yet?

 Quaternion q = cam.getRotation();
 float[] f = q.toAngles(null);
  f[0] = f[0] * FastMath.RAD_TO_DEG;
   f[1] = f[1] * FastMath.RAD_TO_DEG;
  f[2] = f[2] * FastMath.RAD_TO_DEG;
 System.out.println("Angle: " + Arrays.toString(f));

…note: if you don’t have the JME javadocs one click away then go ahead and quit right now, I guess.

If you have a specific question about that javadoc then ask it else I’m not sure what to say. Your code should work fine as written.