Loaded road mesh collide with AWPBoxShape

Software: Away3D 4.x

lior_hai, Newbie
Posted: 18 July 2013 11:58 AM   Total Posts: 10

I am having a hard time solving a problem, I hope someone could point me to the right direction. My goal is to enable physics in my scene and have a box shape collide with loaded road mesh.

- I have created a road mesh in 3DMax and loaded it using away3dx4 with no problem.

- I created a spaceship mesh in 3DMax, imported and wrapped it with AWPBoxShape with the dimensions of the ship.

Now, how do I get the ship box shape to collide with the loaded road? I read all posts related in this forum, I checked all relevant examples and still I have no answer.

The collision worked fine with 2 box shapes when I tested it.

This is my code now:

//load assets
_loader  = new Loader3D();
   
_loader.load(new URLRequest('embeds/Ships/spaceship.3DS'),nullnull, new Max3DSParser());
   
_loader.addEventListener(LoaderEvent.RESOURCE_COMPLETEonSceneResourceComplete);
   
   
_loader2  = new Loader3D();
   
_loader2.load(new URLRequest('embeds/Terrains/lvl1.3DS'),nullnull, new Max3DSParser());
   
_loader2.addEventListener(LoaderEvent.RESOURCE_COMPLETEonSceneResourceComplete2);

//handle spaceship load
private function onSceneResourceComplete(e:LoaderEvent):void{   
     
   chas 
ObjectContainer3D(e.target);
   
view.scene.addChild(chas);
   
   var 
mesh:Mesh;
   
mesh Mesh(chas.getChildAt(0));
   
mesh.moveTo(0,150,0);
   
mesh.geometry.scale(2);
   
mesh.material.lightPicker lightPicker;  
   
            var 
cubeShape:AWPBoxShape=new AWPBoxShape(mesh.maxX*2,mesh.maxY*2,mesh.maxZ*2);
            var 
cubeRigidBody:AWPRigidBody=new AWPRigidBody(cubeShape,mesh,1); 
            
physicsWorld.addRigidBody(cubeRigidBody);
            
cubeRigidBody.friction=1;
            
cubeRigidBody.position=new Vector3D(0,0,0);
   
  
}


//handle road load

private function onSceneResourceComplete2(e:LoaderEvent):void{   
   
   
var container ObjectContainer3D ObjectContainer3D(e.target);
   
view.scene.addChild(container);
   

   var 
materia ColorMaterial = new ColorMaterial(0xfa6c16);
   
materia.lightPicker lightPicker;
   var 
sceneMesh Mesh Mesh(container.getChildAt(0));
   
sceneMesh.material materia;

   var 
sceneShape AWPBvhTriangleMeshShape = new AWPBvhTriangleMeshShape(sceneMesh.geometry);
   var 
sceneBody AWPRigidBody = new AWPRigidBody(sceneShapesceneMesh0);
   
physicsWorld.addRigidBody(sceneBody);   
   
   
   
this.addEventListener(Event.ENTER_FRAMEonFrame);
  
}


//enter frame

private function onFrame(evt:Event):void{
   
   physicsWorld
.step(1/3011/30);
   
view.render();
  

The current output of the code is the spaceship falls through the road.

Any help would be greatly appreciated!

   

John Brookes, Moderator
Posted: 18 July 2013 12:41 PM   Total Posts: 732   [ # 1 ]

Probably you have some position data on either the container or child.

AWPBvhTriangleMeshShape(sceneMesh.geometry)
will use the local vertice positions to create a physics mesh. Its postion is the origin. Unless you set it.

So the road mesh may be another position than the road physics mesh.

I would say turn on debugdraw to check. But its broken at the momment :(

OR
Lots of other stuff.
smile

   

lior_hai, Newbie
Posted: 18 July 2013 12:55 PM   Total Posts: 10   [ # 2 ]

Thank you for your response!

But if I didn’t move the body or the mesh after loading it they should both be at 0,0,0, am I right? also the road was exported at 0,0,0 position in 3dmax.

How do I position both of them to the same location?

   

John Brookes, Moderator
Posted: 19 July 2013 08:49 AM   Total Posts: 732   [ # 3 ]

Yes the positions will be the same, but the geometry vertices could be higher than your box.

But looking again you probably just need to set the position of your cube.
mesh.moveTo(0,150,0);
That wont position rigidbody, you need to set the rigidbody.position so its higher than the road.
Or lower your road rigidBody.position.


If not that.
Things to try.

Bullet doesnt like very small objects, so make sure your box shape is large enough.
Increase the physics step to the default 1/60

Road mesh may have too many vertices.
BVHTriangle only uses 1 subgeometry, so if your mesh uses more it ignores the other subgeoms.

   

lior_hai, Newbie
Posted: 19 July 2013 09:30 AM   Total Posts: 10   [ # 4 ]

After massing abit with the geometry position it worked just fine!
Changing the timeStep helped making the collision more accurate.

If I was able to debug draw the physics bodies it would have saved me ALOT of time…

Thank you for your help!

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X