How to define a Triangle Mesh Shape by Callback?

How to define a Triangle Mesh Shape by Callback?

Hi !

Is there a way to define a user defined shape without giving the whole geometry up front to havok?

As far as I understand, I have to copy the data for havok or give a reference to the triangles I created in memory.

Now my problem is, I have a kind of runlength encoded voxel geometry which is a much more compressed description of the geometry than having it as a vertices/indices data. To be able to collide with it in havok, I'ld have to describe it as vertices/index data. It would be much more efficient if havok asked me about the vertices/index data within an AABB when it needs it by a callback. Is that or something similar possible in havok?



8 posts / novo 0
Último post
Para obter mais informações sobre otimizações de compiladores, consulte Aviso sobre otimizações.

Hi intripoon-
This is sort of a difficult question, so I need some more information to provide a good answer.

There is a way to define a user defined shape. It's a nontrivial task, though, so let's step back a bit.

There are many ways to supply physics objects to Havok without using triangles directly. The most common way is to use shape primitives like spheres and boxes to represent your collision geometry rather than trying to use the graphics mesh representation of the object. More complex physics objects (like a car) can be represented as a collection of simple objects (one box and four cylinders). Would this work for your use case?
If you do want to use triangles, there are a couple of different ways to do this. You can use the hkpExtendedMeshShape or the hkpBvCompressedMeshShape. The former is I think what you were referring to when you said "give a reference to the triangles I created". The latter is an optimized shape that can store a large set of triangles with a minimal memory footprint. For this shape, subcomponents may be turned on or off (ie deactivated from the simulation), but not removed or edited.

When people use mesh shapes it is usually for unchanging geometry (like terrain). People often use voxels for destructible terrain (best example: Minecraft) where the triangle mesh would be constantly changing as objects are destroyed. Is this your intended use?

In general, Havok doesn't like a rigid body's shape to change. Havok makes lots of optimizations because it knows objects stay the same from timestep to step and handling lots of changing bodies would be slow.
More information regarding your intended use would be very helpful here. Are things being created and destroyed? Are objects changing shape? This information can help me provide you with more directed advice.

In the meantime, let me direct you to some documentation describing the different mesh and shape types. Go to "Havok_Physics_Animation_2011-3-0_Pc_Xs_User_Guide" in the Docs folder. Take a look at the start of Chapter Two which describes in some detail the different shape and mesh types. After that the following demo is useful:

Physics > Api > Collide > Shapes > Bv Compressed Mesh (this will show you how parts can get turned on
and off)

I hope that helps!

Developer Support Engineer

Hi Josh,

thx for your answer.

My intended use could be described Minecraft-like from a technical point of view regarding this problem. I have some special encoded volume data which represents geometry in a compact way. Kind of what minecraft does I guess. The changing part is not the issue, like it is in minecraft though. So my problem is probably a subproblem of minecraft.

So, if that helps,if you could tell me how to do something Minecraft-like, I could apply that to my case.


Hi intripoon,

From what you've described I'm not
entirely sure if you need Havok physics for your voxel-based simulation. You
might be better off writing a simplified physics engine using your encoded
volume data, and wrapping dynamic bodies in AABBs. This should give you quick,
Minecraft-like behaviour, and take advantage of your voxel storage algorithms.

Outside of voxel manipulation, how else
do you expect your simulation to behave? How do you intend to have dynamic
bodies interact with one another? Will AABBs alone allow for those



Nick S.
Developer Support Engineer

So, you are telling me, it's not possible to do this with havok?

Besides that, it's not minecraft. There are other objects/bodies in the scene, which have to behave physically.

Hey intripoon,

I apologize if my comments were
misleading; I didn't mean to suggest that this task was impossible to
accomplish with Havok, but that if you only needed voxel based collision
detection, that there were simpler and more straightforward methods.

What you want to accomplish is indeed
possible with Havok, but it is a non-trivial task. What you are going to want
to do is implement your own hkpBvTreeShape. The hkpBvTreeShape is an abstract
class that adds bounding volume tree information to a hkpShapeCollection. An
example of this structure can be seen in hkpMoppBvTreeShape, which implements
hkpBvTreeShape using Havok's MOPP technology.

Unfortunately, there are no demos on
implementing a custom bounding volume shape, so the best I can do is point you
towards the documents:

Havok Physics -> Creating a
Simulation -> Shapes -> Bounding Volume Shapes -> Bounding Volume Tree

You can use your own encoded voxel data
in the hkpBvTreeShape::queryAabb() method by creating triangle shapes on the
fly with shape keys representing the voxel's coordinates. Just be sure to do
the necessary clean up on these "on the fly" triangles.

Sorry again for the confusion, and hope
that helps!


Nick S.
Developer Support Engineer

Hi Nick,

I'm in the similar situation as intripoon. I have some volume based objects in the scene which has to be represented by 'boxes'. These objects represents dynamic rigid bodies and has large number of boxes (e.g. 2500). There's very few of these objects in the scene. We can assume there will be no more than 2 or 3 in collision. I've tried to merge cubes into larger boxes, count of larger boxes was about 300-500 (they were placed into MOPP).

Would it help to create user defined BvShape to improve performance?

Overriding queryAABB would be quite simple, what needs to be done in addition to make this shape work? Does narrow phase require triangles? Or do I have to write my own narrow phase handler for "My" vs. "any other shape"?

Thank you,

Hi Andy,

You'll need to implement queryAabb to return a set of shape keys (uint32s) which overlap that AABB. You'll also need to implement an hkpShapeContainer interface, which would turn those shape keys into real shapes (boxes in your case).

Amy Developer Support Engineer Havok

Deixar um comentário

Faça login para adicionar um comentário. Não é membro? Inscreva-se hoje mesmo!