Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Anjlo opened this issue May 4, 2016 · 17 comments
Closed

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

Anjlo opened this issue May 4, 2016 · 17 comments
Labels

Comments

@Anjlo
Copy link

Anjlo commented May 4, 2016

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 donmccurdy added the bug label May 4, 2016
@donmccurdy
Copy link
Collaborator

donmccurdy commented May 5, 2016

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
Copy link
Collaborator

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
Copy link
Contributor

wizgrav commented May 5, 2016

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 added a commit that referenced this issue May 6, 2016
@donmccurdy
Copy link
Collaborator

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

@donmccurdy
Copy link
Collaborator

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
Copy link
Contributor

wizgrav commented May 6, 2016

@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
Copy link

h0r0m4n commented May 8, 2016

@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
Copy link
Collaborator

donmccurdy commented May 8, 2016

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
Copy link

h0r0m4n commented May 10, 2016

@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
Copy link
Collaborator

☹️ 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
Copy link

h0r0m4n commented May 10, 2016

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

@donmccurdy
Copy link
Collaborator

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
Copy link
Collaborator

Some progress in 9df3943 (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.

@donmccurdy donmccurdy self-assigned this May 13, 2016
@h0r0m4n
Copy link

h0r0m4n commented May 13, 2016

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
Copy link
Collaborator

@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
Copy link
Collaborator

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
Copy link
Collaborator

Moving this discussion over to n5ro/aframe-physics-system#9, and I've added a brief summary there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants