Create CANNON.RigidBody from THREE.Mesh or THREE.Geometry

前端 未结 2 1732
孤独总比滥情好
孤独总比滥情好 2021-01-18 21:11

I am creating a THREE.Mesh object using a THREE.JSONLoader object like so:

// Create castle.
loader.load(\'/Meshes/CastleTower.js\'         


        
2条回答
  •  情深已故
    2021-01-18 22:06

    Well it depends on how exact the physical representatin of your model should be. I'm not very familiar with cannon.js, but here are some options I know:

    • use "computeBoundingBox" and on your tower and create a cannon.js box with those bounds
    • use "computeBoundingSphere" in a similar way
    • use physics for a concave (i.e. arbitrary) mesh. This is the most performance consuming way. Cannon.js has an example here: http://schteppe.github.io/cannon.js/demos/bunny.html

    A non cannon.js related approach would be to e.g. use Recast. Recast would load your .obj file for you and create a navigation mesh for you according to your settings. Then you could walk around there (absolutely great if you have a RTS birdview like game, or bots running around). A recast javascript port can be found here: https://github.com/vincent/recast.js

    Hope this helps!

提交回复
热议问题