[SOLVED] updateGeometricState change LocalTranslation of child

Hi all,



I have a problem with updateGeometricState, I don't know if it's a bug or if I don't understand how it works.



I have a model stocked in a Node with 3 children. I do a localTranslation on a child in the addBloc function :



public void addBloc() {
      Node objets = ((Node)modelNode.getChild(0));
                // modelNode is a Node with the used model

      ...
      
      // translate on X
      Spatial movedPart = objets.getChild(MOVED_PART);
      Vector3f position = movedPart.getLocalTranslation();
      movedPart.setLocalTranslation(new Vector3f(position.x + _widthCopiedMesh,
                             position.y, position.z));
      movedPart.updateGeometricState(0, true);
   }



this works correctly, but when I call the scaleSize function to scale all the model node (parent of translated object) it change the local translation with the original values.


protected void scaleSize(float widthScale, float heightScale) {
      Node objets = ((Node)modelNode.getChild(0));
      System.out.println(objets.getChild(MOVED_PART).getLocalTranslation());

      Vector3f scale = new Vector3f(1f, widthScale, heightScale);
      scale = _originScale.mult(scale); // _originScale is the saved values of scale (Vector3f)
      modelNode.setLocalScale(scale);
      modelNode.updateGeometricState(0, true);
      
      System.out.println(objets.getChild(MOVED_PART).getLocalTranslation());
   }



console shows :
com.jme.math.Vector3f [X=174.7964, Y=7.304E-5, Z=0.0]
com.jme.math.Vector3f [X=0.0, Y=7.304E-5, Z=0.0]

Scale works on the model but the translated object move to its original position, so updateGeometricState seems to initialize translation values of child and I don't understand why. Or maybe it's another problem.

Any ideas ?
Thanks

updateGS does not by itself affect local transform values, so something else must be going on there… for example, if you have an animation controller in action or something of that nature.

thanks for your answer but I am not sure because as you can see in the code, I print the values of localTranslation before updateGS and after:


System.out.println(objets.getChild(MOVED_PART).getLocalTranslation());

Vector3f scale = new Vector3f(1f, widthScale, heightScale);
scale = _originScale.mult(scale); // _originScale is the saved values of scale (Vector3f)
modelNode.setLocalScale(scale);
modelNode.updateGeometricState(0, true);
      
System.out.println(objets.getChild(MOVED_PART).getLocalTranslation());



and as you can see this is the only one line which can modify it (or maybe an other thread but I don't have animation in my program).

So I decided to trace in Debug all the calls in updateGS and in fact I found where the values are changed, it's in the function applyToSpatial of TransformQuaternion.
The stack trace is:

Vector3f.set(Vector3f) line: 151
TransformQuaternion.applyToSpatial(Spatial) line: 177
SpatialTransformer.update(float) line: 140
Node(Spatial).updateWorldData(float) line: 376
Node.updateWorldData(float) line: 383
Node(Spatial).updateGeometricState(float, boolean) line: 351
Node.updateWorldData(float) line: 395
Node(Spatial).updateGeometricState(float, boolean) line: 351
SasAbriExtensible.scaleSize(float, float) line: 215

So the updateWorldData seems to modify the localTranslation. I don't know if it's normal but the result is that translation is changed.
Any solution ?

The only time I have seen something like this happening is when someone accidentally overwrote the localTranslation vector of a node with the worldTranslation, and since updateGS does change the worldTranslation, then it would also change the local (because they are the same reference/object). Try to print your vectors as follows:


System.out.println( "Same ref? " + (objets.getChild(MOVED_PART).getLocalTranslation() == objets.getChild(MOVED_PART).getWorldTranslation() ) );

The result is "Same ref? false" so unfortunatly it's not the problem. :frowning:

updateGeometricState() triggers SpatialTransformer.update() which is attached to your Spatial.

And this transformer probably moves your object.

Well, I found the problem, indeed there was SpatialTransformer on the model, you were right. These SpatialTransformers was created in a conversion beetween 3DS file and Jme file so I never saw them, especially besause there is no animation on the model.

So I removed them and now it works so good.



Thanks a lot for your help

Maxime