c-frame / aframe-extras

Add-ons and helpers for A-Frame VR.
https://c-frame.github.io/aframe-extras/examples/
MIT License
970 stars 308 forks source link

Obj/Collada models fall through with dynamic/static-body #41

Closed Anjlo closed 7 years ago

Anjlo commented 8 years ago

Test at http://anj.fyi/mountains

The manatee falls through the floor, and the mountain mesh isn't walkable.

Link to models: http://anj.fyi/images/manatee.obj http://anj.fyi/images/mountains.dae

donmccurdy commented 8 years ago

Alright, two issues –

The first is general trimesh support, mentioned in schteppe/cannon.js#231 and schteppe/cannon.js#191. In summary, collisions on a trimesh are not as fully supported as other shapes. I've got a demo working that uses a trimesh as the ground, and the player (a sphere) can sort of walk across it, buggily, but cubes can't collide with a trimesh yet. Similarly, the (trimesh) manatee will fall through the (cube-ish) floor.

My ideas are:

  1. Provide an option to wrap a bounding box around the model, in case that's enough for your use case (for a manatee, that seems fine).
  2. Add support (in my components) for CANNON.Heightfield shapes, which might take care of the terrain examples, if I can reasonably convert a BufferGeometry to a heightmap.
  3. Later, provide some declarative API for creating compound shapes – of multiple cubes/spheres/etc – which is the preferred method of doing collisions on a complex shape, anyway.
  4. Also later, see about sending a PR to Cannon.js with additional trimesh collision support.

I can add 1 pretty soon. 2-4 are more difficult, so no promises on timeline there. PRs welcome!

/cc @bnolan and @h0r0man, since we've discussed issues with trimesh collision a bit.


EDIT –

CANNON.js gives much more detail into support for various shapes in the collision matrix.

donmccurdy commented 8 years ago

Second issue, that mountain mesh is pretty complex to just throw at a JS physics engine. Here's the wireframe coming out of it all:

screen shot 2016-05-04 at 10 46 07 pm

Clearly that's not, eh, working quite as expected. Maybe best not to have the whole scene in one big model – much easier for the physics engine if each tree can just be modeled as a box, and terrain as a heightmap, than one massive mesh.

So 1-4 above will give you some options to work with, but it won't be able to magically physics-ify any arbitrary model, I don't think.

wizgrav commented 8 years ago

maybe I'm way off here but maybe you could ortho render the terrain from above at low resolution and take it's depth as the heightmap

donmccurdy commented 8 years ago

@wizgrav yeah, sounds feasible but a bit painful. raycasting at some sampling ratio would work too, but slower. 😐

donmccurdy commented 8 years ago

Well here's a start on (1), in v1.13.0. Not documented yet because various bugs, but –

<a-entity obj-model="obj: url(...)" dynamic-body="shape: box"></a-entity>

Which will ignore the actual shape of the mesh and just put a box around it. You can see the bounding box by adding physics="debug: true" to the <a-scene/>.

Also, CANNON.js gives quite a bit more detail into what's supported in its collision matrix.

wizgrav commented 8 years ago

@donmccurdy yeah raycasting is much more practical and the overhead is not necessarily prohibitive, maybe an octree could be generated to speed up the process and could also be useful for generic intersection testing later.

h0r0m4n commented 8 years ago

@donmccurdy Hi, the #player is getting stick to the ground and after few moves it’s falling down: qui-vid

I’m trying to use simple ground .obj with .mtl. here’s a preview of 3d model, it’ a basic plane subdivided by ~256 cuts:

screen shot 2016-05-08 at 10 00 37

Here is how is rendered:

screen shot 2016-05-08 at 10 11 58

Here’s a html:

<!-- aframe v0.2.0 & aframe-extras v1.14.0 -->
<a-scene physics="debug:true">
  <a-entity
    id="player"
    camera
    universal-controls
    kinematic-body="enableSlopes: false"
    position="0 4 2"></a-entity>
  <a-entity
    id="scene"
    static-body
    obj-model="obj: url(object/ground.obj); mtl: url(object/ground.mtl);"></a-entity>
</a-scene>
donmccurdy commented 8 years ago

Oh nice documentation on that! Thanks. Working on this a bit, it (gradually falling through the floor) should be mostly solved with v1.14.1 now.

h0r0m4n commented 8 years ago

@donmccurdy After v1.13.0 if use collada-model it’s basically freezes the browser!

<a-entity collada-model="url(/path/to/tree.dae)"></a-entity>
donmccurdy commented 8 years ago

☹️ hm. @h0r0man did it work with your OBJ example but start locking up on a DAE? could you post a demo or link to that DAE model?

h0r0m4n commented 8 years ago

@donmccurdy Here’s a simple pen, just try to remove an HTML comment to use your library.

donmccurdy commented 8 years ago

Great thanks. Hoping I can get to this tomorrow, the most likely issue is mesh -> physics body conversion. There's a case where it can enter an infinite loop.

donmccurdy commented 8 years ago

Some progress in 9df3943a4cae721057fa846435946171406fae3b (not released yet). I think the main issue with that Collada model is solved, but there's an issue that causes the physics body to not scale to match the model. Still working on that.

h0r0m4n commented 8 years ago

Hi, the main problem of collisions with Cannon, isn't resolved yet, even with such a primitive 3D models like monu9.obj:

bug-falling

donmccurdy commented 8 years ago

@h0r0man ah yeah, no I just fixed the collada freezing issue so far. using an arbitrary mesh as ground is likely to have issues for a while, not least because lots of shapes can't collide with a trimesh in cannonjs (or oimojs for that matter). i'd like to focus on roomscale tbh.

i think next on my list though is (3) above, to let you define compound shapes around a model using multiple cubes/cylinders. that way even if your model isn't supported you can at least put a custom frame around it (e.g. to pick it up or toss it around)

donmccurdy commented 8 years ago

Added shape: hull, and better support for the (much faster) shape: box option. Documentation here. Those should be helpful for props and obstacles, but probably not terrain.

donmccurdy commented 7 years ago

Moving this discussion over to https://github.com/donmccurdy/aframe-physics-system/issues/9, and I've added a brief summary there.