How to re-size a hkpBvTreeShape?

How to re-size a hkpBvTreeShape?

Hi,

I'm reading data from a .mesh file in Ogre. And convert the data into a hkpBVTreeShape. I'd like to scale up or down a hkpBvTreeShape or it's assigned rigid body according to the user input. Is there a way to change the shape size with simple code without using the content tool?

Thanks!

publicaciones de 2 / 0 nuevos
Último envío
Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.

Hi Kevin,

Generally speaking, changing the scale of an object at runtime is very expensive, so we don't recommend it.  If you must change the scale of a shape at runtime there are a few ways you can do it, but keep in mind that Havok shapes are not designed to support this, and performance could suffer.

The first thing I recommend is to become familiar with the hkpStaticCompoundShape.  This shape type is designed to have one or more subshapes, and each subshape will have multiple instances, each with its own position, orientation, and scale.  If you have a lot of identical shapes that appear at different scales but don't move or resize - such as trees in a landscape - you will want to use a hkpStaticCompoundShape with the individual tree shape as a subshape. Take a look at the demo Physics/Api/Collide/Shapes/Static Compound/Construction for an example.

Individual instances of a subshape inside a hkpStaticCompoundShape can be enabled and disabled, so one way to simulate runtime scaling would be to create a series of instances all in the same place but at different scales, and then only enable one at a time.  This is probably the most efficient way to achieve some measure of runtime scaling, but you will be limited to the specific scale choices you create up front.  Take a look at the demo Physics\Api\Collide\Shapes\StaticCompound\DisablingKeys for an example of enabling and disabling individual instances inside an hkpStaticCompoundShape.

It is possible to create hkpStaticCompoundShapes at runtime, so another option would be to create an individual hkpStaticCompoundShape for each object that can be resized and have it contain only that object.  Then whenever the object needs to be resized, remove the old shape and create a new one with the updated scale.  After adding the new object, it's a good idea to call m_world->reintegrateAndRecollideEntities() for the new rigid body, otherwise collision detection may not work properly in the next few frames.  Removing and recreating shapes can be very expensive, though, especially if you are doing this for many shapes at a time.

  Let me know if you have other questions on shape scaling. 

Cheers,

Josh

Josh S. Havok Developer Support Engineer www.havok.com

Deje un comentario

Por favor inicie sesión para agregar un comentario. ¿No es socio? Únase ya