Sign in to follow this  
Metalx1000

Adding cannonJS physics to imported mesh ThreeJS

Recommended Posts

I'm using ThreeJS and I've created a basic scene in which I've imported some objects from a dae file.
Everything is going great except when I try to apply a basic box body to an imported mesh with CannonJS.

If I create a cube with code and apply Physics to it, it works fine.
But, if I try and added Physics to an imported model it seems that the bound box shape for the Physics is to big (I'm guessing that's what it happening).

Here is the scene:
http://filmsbykris.com/tmp/cannonjs/

You will see that the smaller boxes and the large ground box, seem to work just fine.
But, the larger box seems to be floating.  I've set it to flip every 2 seconds just so you can see how it's moving.

The function I've put together this function to apply the physics.  (I'm guessing that this is where the problem is)

      function addBoxPhy(obj){        var mesh = obj.children[0];        if(mesh.type == "Mesh"){          var halfExtents = new CANNON.Vec3(.5,.5,.5);          var boxShape = new CANNON.Box(halfExtents);          var boxBody = new CANNON.Body({ mass: 5 });          boxBody.addShape(boxShape);          world.add(boxBody);          boxBody.position.copy(mesh.position);           boxMeshes.push(mesh);          boxes.push(boxBody);          daeBox = boxBody;        }      }

I've been trying to figure this out for a day or two now.
Any help would be great.
Thanks

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.