Loading meshes from AWD file to create rigid bodies

Software: Away3D 4.x

antEater, Newbie
Posted: 28 February 2014 07:56 PM   Total Posts: 5


    I have been trying to use rigid bodies for terrains. I have been trying to use simple shapes to learn how to implement rigid bodies correctly but I have been having some problems.
    I have noticed there is a scaling issue. When I use a mesh’s geometry to create a rigid body with AWPBvhTriangleMeshShape the rigid body is much much smaller than the mesh. I tried trouble shooting the scaling factor or looking online for help but I haven’t been able to get it right.

I found some great code to look at here http://flashdaily.net/post/28546902414/away3d-gold-awayphysics-vectormap
I noticed this code also scales the geometries before setting the rigid bodies BUT the code initializes the _scale variable with 1 and I can’t see when it is changed. I tried building this game to trace the scale factor when it runs but there is a class collision with my libraries I am using for awayphysics and away3d (yes I am having lots of issues) so I can’t build it.

Any insight into rigid bodies would be fantastic

Also I am using
The class collision happens for texture materials…they both contain a away3d.materials.texturematerial


John Brookes, Moderator
Posted: 01 March 2014 02:14 AM   Total Posts: 732   [ # 1 ]

bvh works from the meshes geometry (its vertices).
So if the mesh transform has any scaling bvh will not know about it.

You can either scale the geometry and leave the mesh unscaled
then create your bvh shape

scale the bvh shape
MyAWPBvhTriangleMeshShape.localScaling = new Vector3D(2,2,2)


antEater, Newbie
Posted: 03 March 2014 03:45 AM   Total Posts: 5   [ # 2 ]

Thanks for the heads up! I have been scaling the mesh itself not the geometry.

The only other thing I am struggling with is loading in an irregular shape to be used as a rigid body. I listen for a mesh to be completed then this code is ran

if (e.asset.assetType == "mesh")
var m:Mesh e.asset as Mesh;
sceneShape:AWPBvhTriangleMeshShape = new AWPBvhTriangleMeshShape(m.geometry);
sceneBody:AWPRigidBody = new AWPRigidBody(sceneShapem0);

antEater, Newbie
Posted: 03 March 2014 03:46 AM   Total Posts: 5   [ # 3 ]

I’ve seen examples use similar code. The meshes I am loading in are irregular shapes but they are simple and not complicated. From what I know about awayphysics (and Bullet) I feel like it should work, but its not.

I have been trying to simply get a ball to roll down a ramp. The ramp object is the mesh that is loaded in from an external awd file. Unfortunatley the ball falls right through when it hits the slope. I’m not sure why.


antEater, Newbie
Posted: 03 March 2014 04:26 AM   Total Posts: 5   [ # 4 ]

Quick update just in case anybody else is struggling like I am. So the original mesh I was using for the ramp had over 326 faces….which I thought was simple enough (probably a newbie assumption). Then I created a ramp with only 60 faces and used that one for a rigid body and it worked, the ball rolled right down the ramp.

So I think that solves my problems for now, so to sum it up for anyone else (please correct me if I am wrong)
1. For AWPBvhTriangleMeshShape the mesh’s geometry used to create the shape needs to be simple.
2. If you want to scale the rigidbody, either scale the mesh’s geometry or use the shape’s local scaling method


John Brookes, Moderator
Posted: 03 March 2014 12:18 PM   Total Posts: 732   [ # 5 ]

For AWPBvhTriangleMeshShape the mesh’s geometry used to create the shape needs to be simple.

Not true. Simple is better/faster yes, but bvh can handle quite large meshes.

The usual issue with things falling through a mesh are
The falling object is…
moving too fast
is too small

the bvh mesh…
has holes
normals pointing wrong way

world scaling is set wrong for the distances your using
and possibly lots of other things smile


antEater, Newbie
Posted: 07 March 2014 06:28 PM   Total Posts: 5   [ # 6 ]

Ah Ha! Thanks for the help JohnBrookes! I can’t believe I didn’t think to check the normal’s orientation on the objects I was using. That ended up solving problems I was having with other models I was loading in.

It seems the last hurdle to get over is the world scaling. I can now collide with the terrain, but the rigidbody’s shape is not aligned or scaled with the terrain mesh.



Away3D Forum

Member Login