ceshi
ceshi

Reputation: 31

three.js After importing the model through objloader, how to make the model have physical effect through physijs?

I know through Physijs.BoxMesh Can let three.js The model has a physical effect

new Physijs.BoxMesh(Geometry, material, 1)

But now my model is imported through objloader. How can I make it have physical effect

var objLoader = new THREE.OBJLoader();
objLoader.load(baseUrl+"sofa/1/file.obj", function(mesh){
    mesh.scale.set(0.115, 0.115, 0.115);
    mesh.rotateY(-Math.PI/2);
    mesh.position.set(-105, 0, 80);
    scene.add(mesh);
})

Upvotes: 1

Views: 47

Answers (1)

M -
M -

Reputation: 28482

You could extract the geometry from the loaded mesh and use it to create your own Physijs.BoxMesh:

var objLoader = new THREE.OBJLoader();
var boxMesh;
objLoader.load(baseUrl+"sofa/1/file.obj", function(mesh){
    boxMesh = new Physijs.BoxMesh(mesh.geometry, mesh.material);
    boxMesh.scale.set(0.115, 0.115, 0.115);
    boxMesh.rotateY(-Math.PI/2);
    boxMesh.position.set(-105, 0, 80);
    scene.add(boxMesh);
})

Upvotes: 1

Related Questions