Hi all,
I'm pretty new to threeJs and AmmoJs (porting of bullet) world and I don't know if I'm moving totally wrong or I miss something.
I created a hollow cylinder with threeJs using custom shape (CODE) and created the physic with ammoJS using btConvexHullShape and btCompoundShape (CODE), but something went wrong and I don't know how to make it work.
Here is a demo.
https://hollow-cylinder.web.app/home
Anybody can help me?
Problem to add physic in a hollow cylinder (threeJS, AmmoJS)
-
- Posts: 2
- Joined: Thu Dec 31, 2020 9:37 am
-
- Posts: 2
- Joined: Thu Dec 31, 2020 9:37 am
Re: Problem to add physic in a hollow cylinder (threeJS, AmmoJS)
UPDATE (05/01/2021)
I update the ammoJS code part like this
I found this code from this question, but this solution does not seem to work well, the cylinders fall to one side without standing.
I update the ammoJS code part like this
Code: Select all
const vec31 = new Ammo.btVector3(0, 0, 0);
const vec32 = new Ammo.btVector3(0, 0, 0);
const vec33 = new Ammo.btVector3(0, 0, 0);
const vertices = geometry.vertices;
geometry.faces.forEach(face => {
triangles.push([
{ x: vertices[face.a].x, y: vertices[face.a].y, z: vertices[face.a].z },
{ x: vertices[face.b].x, y: vertices[face.b].y, z: vertices[face.b].z },
{ x: vertices[face.c].x, y: vertices[face.c].y, z: vertices[face.c].z }
]);
});
const shape = new Ammo.btConvexHullShape();
triangles.forEach(triangle => {
vec31.setX(triangle[0].x);
vec31.setY(triangle[0].y);
vec31.setZ(triangle[0].z);
shape.addPoint(vec31, true);
vec32.setX(triangle[1].x);
vec32.setY(triangle[1].y);
vec32.setZ(triangle[1].z);
shape.addPoint(vec31, true);
vec33.setX(triangle[2].x);
vec33.setY(triangle[2].y);
vec33.setZ(triangle[2].z);
shape.addPoint(vec31, true);
});