-
Notifications
You must be signed in to change notification settings - Fork 565
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
Please expose btTriangleIndexVertexArray #398
Comments
Yeah, PlayCanvas calls |
You don't want to do this... A heightmap is essentially a Plane so much easier on the memory. See: You should try and use the smallest, most efficient method for the collision detection. For many player objects, they use their own raycasters and dont rely on the physics engine for all sorts of reasons: If you cant do this, use a subdivision method like quad trees or better yet use BVH. This would let you do a smaller pass and maybe do a test against the specific triangles if you need to.. Something like VHCAD would work https://github.com/kmammou/v-hacd BTW Rapier has a JS version and we're working on getting the VHCAD WASM wired up as well (not in rapier JS yet) Will be over at https://github.com/pmndrs/react-three-rapier The docs for Ammo and bullet really surprise me with how popular they are |
This is awesome. Thank you so much!
This looks really exciting and I'd love to get a sense of performance benchmarks against ammo.js. Ultimately I would love to be able to use a babylon.js integration with rapier once the WASM api is up and running or if the performance gains against ammo.js are already there and it makes sense for me to start making the switch.
It's been a nightmare for me. But it's paid off more or less. |
@DennisSmolek Can we revisit this
Even if I don't want to do this for the world terrain mesh, exposing this interface would still speedup adding smaller but still detailed meshes into the ammo js physics world. Having to instantiate an instance of btPoint three times for each triangle still produces an incredible amount of overhead. In fact, I think it's this method of adding points to Ammo js that causes of a lot of the memory issues I've seen. Correct me if I'm wrong, but adding large amounts of vertices in one function call momentarily raises the memory usage of ammo by a significant amount, but once the object has been fully passed in, the memory is released. If this is the case, then JS developers really could be getting more use out of Ammo js since it's the initial overhead that causes the OOM error in most cases, not the actual large count of vertices once it's been loaded. |
you mean implementing the whole class btTriangleIndexVertexArray I dunno about this one cause i dont know for sure how to implement all the constructor properties in ammo.idl and more importantly how to pass them from javascript. |
So it's not a matter of just exposing it in the idl? |
Mainly it is just exposing it the in ammo.idl but how you pass the pointers to the data is the thing. I am going play with this for a bit... lets at least get the idl setup then we can fart around with how to wrap the pointers to the data for Ammo.js |
Sounds good - I'll reference to one your prs that made similar changes to the ammo.idl file |
So this makes sense and I’m honestly not sure regarding the function call itself, but I’ve made INSANE calls with things over the years so I’m not worried there. my concern and warning was against your ultimate use case with using a mesh with that many faces as a collidable object.. (AFAIK) The standard way to run the test is at least one ray per face scanning the universe, and as this is JS it’s sequential, and if it’s a standard loop object and not a ground plane, it’s going to blow stuff up. I’ll use rapiers docs because they explain an alternative a bit better: https://rapier.rs/docs/user_guides/rust/colliders/#compound-shapes |
I figured we'd just copy what's being done with the btHeightfieldTerrainShape:
This might mean making slight modifications to the btTriangleIndexVertexArray class. I'll take a look in a few days. |
Okay that's awesome. I tried to use the VHACD algo as a plugin with blender and had no success. I gave up after reading that people were not getting any sort of stable results from the VHACD algo. At least with the implementation they were using. Recently I went into blender just to split apart a model into a bunch of individual convex hulls, because creating a convexhull with the original monolith model would not result in the correct shape. Its a tree, and each branch and each twig had to be split into its own set of vertices. Does Rapiers Would using this on a large terrain mesh produce an approximate shrink-wrapped mesh as well? I don't think I would use it this way, but I'm wondering what are the limits of it's usage? |
Something has changed in the Ammo.js build that Babylon.js uses, for whatever reason now I can load in a triangle mesh shape with over 500k vertices no problem, just takes |
try may be anoter methode (Bvh include) for all mesh: |
For dynamic concave meshes, you can use the technique of creating using convex triangles (btTriangleMesh) and then adding them to btConvexTriangleMeshShape then if you want add to a btCompoundShape how children shape. For static shape - btBvhTriangleMeshShape. |
Is your suggestion supposed to address loading many vertices faster? Or just building out large mesh shapes in general? |
I wanted to find an approach so that a concave mesh could work correctly with other concave meshes, as well as with destruction and soft bodies. So that collisions were and were detected. And this approach also works if the objects are dynamic. As for performance in large meshes, I believe you can first create several separate forms, directly from the buffer geometry, or pre-cut them in a 3D editor. Then add them to 1 compound, as children |
If I'm understanding everything correctly, this would allow us to pass in massive buffers that are filled with vertex data. This would unlock using massive open world maps with ammo js! As of now, I run out of memory well before all the the individual calls to
btTriangleMesh.addTriangle(triPoints[0], triPoints[1], triPoints[2]);
ever finishes for a model with 200k + vertices; and yet at the same time I'm allowed to load in a heightmap with 1480 x 1480 subdivisions passing in the data viaAmmo._malloc
? It seems to me ammo js would be perfectly capable of handling this if only it were exposed.The text was updated successfully, but these errors were encountered: