1

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);
})
ceshi
  • 31
  • 2
  • I got it! objLoader.load('xxx.obj',function(object){ var model = object; for (let x in model.children){ let material = Physijs.createMaterial(model.children[x].material, 1, 0); let mesh = new Physijs.BoxMesh(model.children[x].geometry, material, 0); mesh.castShadow = true; mesh.receiveShadow = true; scene.add(mesh); } },onProgress,onError); – ceshi Sep 26 '20 at 02:21

1 Answers1

1

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);
})
M -
  • 26,908
  • 11
  • 49
  • 81
  • The physical effect generated by boxmesh is not correct. Sometimes there is nothing around, but the result shows collision effect, and sometimes there are objects around but they pass through – ceshi Oct 09 '20 at 10:26
  • I think someone said concavemesh. But the browser reported an error. – ceshi Oct 09 '20 at 10:27
  • TypeError: Cannot read property 'length' of undefined at new window.Physijs.Physijs.ConcaveMesh (physi.js:1259) – ceshi Oct 09 '20 at 10:27