Create a cannon Body with a BufferGeometry from GLTF Model

I am a beginner on ThreeJS.

I import my gltf blender model in threeJs. I have a bufferGeometry. I want to convert it in a cannon Body.

All example I see use THREE.Geometry. I see the THREE.Geometry have be remove of threeJs (THREE.Geometry will be removed from core with r125).

See this exemple : How to add a collision body to a model · Issue #444 · schteppe/cannon.js · GitHub

let shape, rigidBody, mesh, geometry;
geometry = new THREE.Geometry().fromBufferGeometry(mesh.geometry);
let scale = mesh.scale;
let vertices = [], faces = [];

// Add vertices
for (let i = 0; i < geometry.vertices.length; i++) {
let x = scale.x * geometry.vertices[i].x;
let y = scale.y * geometry.vertices[i].y;
let z = scale.z * geometry.vertices[i].z;
vertices.push(new CANNON.Vec3(x, y, z));
}

for (let i = 0; i < geometry.faces.length; i++) {
let a = geometry.faces[i].a;
let b = geometry.faces[i].b;
let c = geometry.faces[i].c;
faces.push([a, b, c]);
}

console.log(vertices, faces);
shape = new CANNON.ConvexPolyhedron(vertices, faces);
rigidBody = new CANNON.Body({
mass: 0,
shape: shape
});

// rigidBody.position.copy(mesh.position);

With bufferGeomtry (no indexed), I dont have face attributes.

If I want to create a `CANNON.ConvexPolyhedron, what I could use without Geometry ?

Hey , if the issue was solved plz if you never mind to share with us

I never solve this :disappointed_relieved: :disappointed_relieved:
When I see example with cannonJS, always they use plane floor.

Geometry now in deprecated folder, you can still use it.

See these two ( similar ) r135 examples for convex bufferGeometry, maybe helpful:
with modified cannon-es utils
self-written based on pure cannon

For arbitrary ( concave ) geometry, you may need this tool to turn them to convex parts first:
lib, demo.

Hey, if this issue solved without using deprecated folder plz share.