1

Everytime I try to add a resized ModelInstance of a Model (made in 3ds max) to a Bullet world, I keep getting the same model, with no modified scale. This is my current code:

Objeto objmat = mapaactu.nameAndPutObjetos(obj.getMaterias().get(0).nombreasoci,(int)obj.getMaterias().get(0).cantidad);
world.addConstructor(objmat.nombreinterno, objmat.constructor);

Vector3 objmatpos = new Vector3(obj.entidadbody.getWorldTransform().getTranslation(Vector3.Zero));
Vector3 scala = new Vector3(obj.getMaterias().get(0).cantidad / 100f, obj.getMaterias().get(0).cantidad / 100f, obj.getMaterias().get(0).cantidad / 100f);
Quaternion rotacion = new Quaternion();
objmat.instancia.transform.getRotation(rotacion);

objmat.instancia.transform.set(objmatpos, rotacion, scala);

objmat.setEntidad(world.add(objmat.nombreinterno, objmat.instancia.transform));

However, the position component of the transform I get is always correct (it spawns where "obj" is)! I have debugged it and "scala" = (0.5f,0.5f,0.5f) What should I do to scale a model correctly before adding it to Bullet world?

Daahrien
  • 10,190
  • 6
  • 39
  • 71
LosTChG
  • 77
  • 2
  • 7

1 Answers1

4

Although it depends on the type of body, in general scaling and physics should be avoided. Normally scaling a body does change its volume and therefor affects its physics properties. So the correct answer would be to "bake" the scaling in your modeling application (depending on the application it might be called "freeze transformation" or alike) or take the scaling into account when creating the btCollisionShape (e.g. multiply the half extents with the scaling when creating a btBoxShape).

That being said, it is possible to scale collision shapes. For example a btCompoundShape has a method called setLocalScaling to apply a scale to its child shapes. See also: http://www.continuousphysics.com/Bullet/BulletFull/classbtCompoundShape.html#a1059971dd35c0b5dc2b4d5db070b9fb0.

Note that if you are using the built-in method to create a static shape from a model (https://github.com/libgdx/libgdx/blob/master/extensions/gdx-bullet/src/com/badlogic/gdx/physics/bullet/Bullet.java#L124), that the scale components will be ignored.

Also note that the scaling component in the matrix used by the motion state is ignored. See also: https://github.com/libgdx/libgdx/wiki/Bullet-physics#wiki-common-classes

Xoppa
  • 7,983
  • 1
  • 23
  • 34
  • Thanks for the answer, Xoppa, but I am trying to resize a model in game (creating a couple of modelinstances of it) before adding them to the Bullet world as dynamic objects, so apparently there is no problem in scaling them, isn't it? However, I can't manage to do it. – LosTChG Feb 24 '14 at 18:09
  • 2
    Scaling a ModelInstance can be done using `instance.transform.scale(x, y, z);` regardless whether the ModelInstance is a visual representation of a physics body or not. Of course if you update the transformation matrix in the MotionState, you'll have to reapply the scale. You can avoid this by scaling the root node (assuming you have one root node): `instance.nodes.get(0).scale.set(x, y, z); instance.calculateTransforms();` – Xoppa Feb 24 '14 at 18:28
  • Ok, doing what you said in the last comment worked perfectly. You just have to apply that scale to the BulletEntity.modelInstance's root node after you add it to the Bullet world. How do I set the comment to be the accepted answer? – LosTChG Feb 28 '14 at 12:52