donmccurdy / three-to-cannon

Convert a THREE.Mesh to a CANNON.Shape.
337 stars 32 forks source link

Support CANNON.Heightfield #1

Open donmccurdy opened 7 years ago

donmccurdy commented 7 years ago

Relevant to this thread: http://www.html5gamedevs.com/topic/24944-cannonjs-heightfield-from-imported-mesh/

Some discussion here: https://github.com/schteppe/cannon.js/issues/221

And several github issues:

Also, docs could be improved per cannon issue 222.

vincentfretin commented 6 years ago

@donmccurdy I created a Heightfield shape for the environment component https://github.com/feiss/aframe-environment-component/pull/24 The environment component uses a THREE.PlaneGeometry where we modify the z of all vertices. I don't think we can generalize the work I did to put in three-to-cannon, but anyway it can inspire others.

donmccurdy commented 6 years ago

@vincentfretin that's great!

I agree it probably doesn't generalize to support any Mesh (I'm not planning to solve that case, at this point) but it would be helpful if three-to-cannon was able to do:

var shape = mesh2shape(object3D, {type: mesh2shape.Type.HEIGHTFIELD});
// succeeds if object3D contains exactly 1 PlaneGeometry, else returns null and logs error

I'd be glad for a PR doing just that, if you're interested. 🙂

vincentfretin commented 6 years ago

Hey, you're right, I'll probably do that. This way I won't put lots of changes in the environment component and I'll probably do an option to enable the heightfield, disabled by default.