Closed Anjlo closed 7 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:
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.
CANNON.js gives much more detail into support for various shapes in the collision matrix.
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:
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.
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
@wizgrav yeah, sounds feasible but a bit painful. raycasting at some sampling ratio would work too, but slower. 😐
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.
@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.
@donmccurdy Hi, the #player
is getting stick to the ground and after few moves it’s falling down:
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:
Here is how is rendered:
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>
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.
@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>
☹️ 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?
@donmccurdy Here’s a simple pen, just try to remove an HTML comment to use your library.
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.
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.
Hi, the main problem of collisions with Cannon, isn't resolved yet, even with such a primitive 3D models like monu9.obj
:
@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)
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.
Moving this discussion over to https://github.com/donmccurdy/aframe-physics-system/issues/9, and I've added a brief summary there.
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