BvhTriangleMeshShape only works properly on meshes with 1 subgeometry

Software: Away3D 4.x

Somokon, Member
Posted: 16 September 2011 07:10 PM   Total Posts: 75


In my project I have static scene objects that are dynamically created and merged into a single mesh at runtime.  To add physics collision, I am using a BvhTriangleMeshShape.  The merged mesh has multiple different materials, thus multiple subgeometries.

However, BvhTriangleMeshShape ignores all but the first subgeometry

var indexData Vector.<uint> = mesh.geometry.subGeometries[0].indexData;

vertexData Vector.<Number> = mesh.geometry.subGeometries[0].vertexData

I tried to fix this but it seems it is more complicated than it looks and my meagre efforts have failed smile

It would be great to have this fixed as my current workaround is to merge the scene objects into a temporary second mesh without a texture (thus only 1 subgeometry), and use this temporary mesh to create the shape.  Obviously not a very efficient way of doing things.


Alejandro Santander, Administrator
Posted: 16 September 2011 08:00 PM   Total Posts: 414   [ # 1 ]

We discussed this here a bit:

It is not a but, rather an approach AWP takes.

I personally like the current 1 on 1 approach and think it should be the responsibility of the user’s 3d design and parsing methods to assign the meshes to the shapes correctly, but if you feel otherwise I’d say please put this in a feature request.


John Brookes, Moderator
Posted: 16 September 2011 10:26 PM   Total Posts: 732   [ # 2 ]

Alejandro think your missing the point. (or maybe me wink)

BvhTriangleMeshShape can only use the first subg.
So if you have a mesh with more than 1 subg (maybe afetr a merge) all the verices in the next subg wont get used.

What you can do is modify Bvhtrainglemesh to accept subg index.

public function AWPBvhTriangleMeshShape(mesh : Mesh, subgIndex:uint=0, useQuantizedAabbCompression : Boolean = true) {

replace the two

Then you can do something like

for (var i:int = 0; i < buildings.geometry.subGeometries.length; i++)
var buildingsShape:AWPBvhTriangleMeshShape = new AWPBvhTriangleMeshShape(buildings,i);
var buildingsRb:AWPRigidBody = new AWPRigidBody(buildingsShape, buildings, 0);


Yang Li, Administrator
Posted: 17 September 2011 01:29 AM   Total Posts: 80   [ # 3 ]

Thanks John, I will add this to awayphysics.


Alejandro Santander, Administrator
Posted: 17 September 2011 02:34 AM   Total Posts: 414   [ # 4 ]

I don’t think this is a good idea. Seems like a hack to me that will confuse users in the future.

If you do wish to go this way, then why not study the hierarchy of the mesh being passed to AWPBvhTriangleMeshShape and create a triangle mesh shape for each valid sub geometry found? The shapes created could yield rigid bodies grouped within a non colliding group, like a compound object.

This way, passing a compound mesh to AWPBvhTriangleMeshShape would yield a compound set of shapes, without the user having to know the hierarchy of the involved mesh.


Somokon, Member
Posted: 20 September 2011 12:23 AM   Total Posts: 75   [ # 5 ]

Hi Alejandro,

I understand your point.  However I wanted a single rigid body for my entire static scene as I understand that this is more efficient for the physics engine.

This code snippet will properly merge all the vertex and index data from a compound mesh into single vectors that you can pass to the alchemy function

var indexData:Vector.<uint> = new Vector.<uint>();
vertexData:Vector.<Number> = new Vector.<Number>();
for (var 
i:int 0mesh.geometry.subGeometries.lengthi++) {
indexData.concat(mesh.geometry.subGeometries[i]*, b:*):uint {
return + (vertexData.length 3);
vertexData vertexData.concat(mesh.geometry.subGeometries[i].vertexData);

But the beauty of open source and git is that I can keep this change and you don’t have to include it in the official repository if you don’t want to! smile


Alejandro Santander, Administrator
Posted: 20 September 2011 12:42 AM   Total Posts: 414   [ # 6 ]

Interesting point Somokon.

@Yang Li: Perhaps AWP could have a helper class to produce multiple AWPBvhTriangleMeshShape’s from a Mesh with nested children OR one combined AWPBvhTriangleMeshShape from all the children of the Mesh?



Away3D Forum

Member Login