Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top