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 ?