I’m using Perlin noise to create a terrain automatically in three.js. I then create a physics body with that mesh using Trimesh and get vertices and indices from the geometry. However for some reason when I drop a sphere on it then it just falls right through it. The body shape exists because I create another mesh with the vertices found in the body to make sure that it is made properly. Here is my tri mesh code:
var platShape = CreateTrimesh(platformGeometry, platform)
var platBody = new CANNON.Body({ mass: 0, shape: platShape });
copy(platform, platBody)
world.addBody(platBody)
//createThree(platBody)
function buffer(geo) {
const bufferedGeo = new THREE.BufferGeometry().fromGeometry(geo);
return bufferedGeo;
}
function CreateTrimesh(geometry) {
const vertices = buffer(geometry).attributes.position.array;
// Each triangle is defined by three consecutive vertices
const numTriangles = vertices.length / 9; // Each triangle has 3 vertices (3 components each)
const triangleIndices = [];
for (let i = 0; i < numTriangles; i++) {
triangleIndices.push([i * 3, i * 3 + 1, i * 3 + 2]);
}
return new CANNON.Trimesh(vertices, triangleIndices);
}
Also it works sometimes depending on a bunch of weird factors like where the sphere is, and if its moving horizontally and stuff.
If anyone needs more info then feel free to ask
platBody.collisionResponse = 0;
looks suspicious…
Sorry that was left there from a previous test. Forgot to remove it.
1 Like
hey im having the same issue did you figure out hoe to fix it
1 Like
Physics sims can be really hard… and easy to break… and once you break them, tricky to Unbreak.
The main ways that physics sims break is when you violate the constraints somehow… like starting things out with dynamic objects intersecting…
The other way they break is by using units that are out of the “safe” range for the engine… Making masses too high or too small… making objects too big or too small. Especially making both too big and too small at the same time.
Another way they break is by objects moving too fast relative to the thickness of other objects… so that they “tunnel” through each other, and end up interpenetrating.
1 Like
-
value of noise sample at edge/repeat may be misaligned (self-intersection, hole, NaN)
-
async/await the terrain algo result
-
MergeVertices to make mesh topology robust
-
test terrain trimesh by CSG subtraction from a box… Is outcome inconsistently reversed or upside-down?
-
…if so, this may explain why “sideways” force contacts other bodies
-
increase mass/area, and geometry should have depth
-
include a generic floor in collision group to avert complete failure
-
test terrain collision by augmenting faces with primitives
It’s complicated,
Ambassk8r Truckstop
2 Likes
have we solve the trimesh passing through other body like plane, box and trimesh alike, is there an update on the Cannon Es?
I tried to shift to other physics but Cannon is by far the fastest, lightest and more advance that other physics libs, we need to revive Cannon
I have evaluated other JavaScript physics and cannon is still the most reliable one.
CANNON-ES Demo
PhysX, Havok, Ammo, Rapier, and Jolt all perform better and are far more fully featured than cannon. Cannons main benefit is that it’s easy to get something working. It achieves this by not being very complex, and not supporting a lot of features that the other engines do. For instance… box->trimesh collision.
If you want to see some comparisons of the different engines, you can take a look at this project: phy docs
As far as I know, cannon isn’t included because it simply doesn’t support enough features to compare it to the other engines.
( I want to insert a caveat here, because there are plenty of scenarios where cannon is a fine choice. Sphere->heightmap collision is really fast, so if you can restructure your sim to capitalize on that… you can probably simulate a Lot of objects in a constrained setting. Everything is tradeoffs. Every engine is beautiful. Also I heard that Havok actually does its rigidbodies as collections of spheres… but don’t quote me on that. )
Here is a page of different physics demos that allows you to switch between the different engines and see how they perform: PHY
3 Likes
Cannon is still the best physics, if we can only solved the timesh issue, then we don’t need other js physics.
yes cannon.js or cannon-es, either one depending on the application, I prepare to use the cannon.js this allow me to use it globally.
Cannonjs powers these threeverse game engines
- Lake Track
- Sneak Peak
- Edge Apartment
- Apartment
- Speed Way
- Galleria
- Facility Bunker
- Outpost
- Trench Terrain
- White Round Art Gallery
- The Greens Villa
- Island
- Tsukoba Cirtcuit