how to update a hkpshape??

how to update a hkpshape??

hi all, its me again

how can i update a rigids body shape??

right now i create a rigid body with a shape as one of the input parameters as usual. Keep the hkpshape alive in a pointer

my problem is when i try to update that shape. I do all the update to my shape pointer. Then to make the changes available for the rigid body i do a "rigid_body->SetShape(shape)". shape its a pointer to the same shape rigid body was created from and it works, buuuutttt i get a very nice memory leak

then i tried shape->removeReference() after the SetShape call, but now the shape is gone and i have no collisions

i guess there is an easy method to make the shape updates available for the rigid body without memory leaks

any ideas???


10 帖子 / 0 全新

Hello again a24710 :-)

It sounds like this is a design problem on your end. Make sure that when you decide to keep a pointer around you don't removeReference() and when you make a new pointer you addReference().

Most of the sample code creates a shape, creates a rigid body, then does removeReference() on the shape, but if you plan to keep a pointer to that shape in your code, don't call removeReference().

When your world is being destroyed, it will automatically clean up all the shapes it has, but if you're keeping a shape around that's not part of your world, remember to call removeReference() on it when you destroy your world.

1. For example, you have cubeShape and sphereShape and you have pointers to both. Their reference counts are 1 each.
2. You set your rigid body to cubeShape when you create it. Its reference count becomes 2.
3. Then change it to sphereShape: cubeShape is back to 1 and sphereShape is up to 2.
4. You close your game and the world is destroyed. The world knows about sphereShape and calls removeReference(): now both are 1 again. You need to call removeReference() in your destructor/cleanup function on both of these.

By the way, are you using Debug Memory to track your memory leaks? It sounds like you're already on top of your leaks and know where they're coming from, but it's a useful tool to know about if you don't know about it already.


Hi Daniel.... again :)

So, whats the correct method for updating a rigid bodys shape and make that modification to be reflected in the rigid body??? (im working mainly with hkpExtendedMeshShape right now)

example, im calling this method for scaling

((hkpExtendedMeshShape *) mesh_shape)->setScaling( hkVector4(scale.GetX(), scale.GetY(), scale.GetZ()) );

mesh_shape is the shape i used to create the rigid body. i called removeReference after the RB creation.

and to make the scale be reflected on the body, then i call rigid_bod->SetShape(mesh_shape) which is something that is not recomended in the documentation, but dont know other way to make the rigid body to get actually scaled

ill take a look at the memory stuff

thanks again and again and again :)

maybe i did not explain myself very well

my main purpose is to get the rigid body transformed, and transforming the shape is the only way i know right now

Well, you're right about that... the docs do say that you shouldn't do it. The problem is that if you're colliding two boxes and a box-box agent is created for the collision, then you change one of them to a sphere, suddenly your agent is incorrect and you might see a crash or other bad/strange behavior. That being said, in the demos the crouch behavior of the character proxy is done by swapping out the shape in realtime.

Is hkpExtendedMeshShape->setScale() not working for you? Do you mind if I ask what exactly you're trying to do? What is it in your game that you need to scale? Maybe if I understand exactly what your goal is I can be a bit more helpful :-)


By transforming the rigid body, do you just mean changing the position and rotation of it?

no, dont want to change the shape

my purpose is really simple

for example, i have an object A which i want to scale because is too small. I can scale it by using a matrix, but that only would scale the object to be rendered

i just want that scale to be reflected in the rigid phyisc body, so the collisions are computed against the new size

So is your object changing shape in real-time while the game runs? Or is it a matter of your asset being too small and you need to scale it up at load-time?


at the moment is that its too small and i would like to scale it at load time. If its not going to changle the scale i guess i could pass the geometry data already scaled to the extended shape

but i would like to know if its possible to change the scale of the geometry of a rigid bodys shape at run time in a "cheap" way.

sorry if sometimes i dont express myself 100% correctly, but english is not my mother language

Don't worry, your English is great :-)

It sounds like you have a matrix by which you want to scale your object, so have you considered scaling at export time? This will save you time when loading too, as you won't have to calculate the scaling after loading.

To scale when exporting, just add the Transform Scene filter to your filter list in the Havok Content Tools, choose "CUSTOM" for your matrix, fill in the values, and you should see a properly scaled mesh when you load your asset.

As far as changing scale at run-time, I think that setScale's just about your only option. If you have access to vertex data maybe you could always manually scale each vertex by multiplying it by your rotation matrix to create a scaled shape? I haven't experimented with this in Havok myself but feel free to experiment yourself :-) If you can avoid it, not changing scale/shape during runtime will help stability so if you can think of another way of doing what you want to do...