【问题标题】:three.js After importing the model through objloader, how to make the model have physical effect through physijs?三.js 通过objloader导入模型后,如何通过physijs让模型有物理效果?
【发布时间】:2020-09-26 01:49:01
【问题描述】:

我知道通过 Physijs.BoxMesh 可以让三个.js 模型产生物理效果

new Physijs.BoxMesh(Geometry, material, 1)

但是现在我的模型是通过 objloader 导入的。怎样才能让它有物理效果

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);
})

【问题讨论】:

  • 我明白了! 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) ; 让 mesh = new Physijs.BoxMesh(model.children[x].geometry, material, 0); mesh.castShadow = true; mesh.receiveShadow = true; scene.add(mesh); } },onProgress,onError);

标签: three.js physijs


【解决方案1】:

您可以从加载的mesh 中提取几何图形并使用它来创建您自己的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);
})

【讨论】:

  • boxmesh产生的物理效果不正确。有时周围什么都没有,但结果显示碰撞效果,有时周围有物体但穿过
  • 我想有人说凹网。但是浏览器报错了。
  • TypeError: Cannot read property 'length' of undefined at new window.Physijs.Physijs.ConcaveMesh (physi.js:1259)
猜你喜欢
  • 2019-03-14
  • 2013-12-11
  • 1970-01-01
  • 2014-08-19
  • 1970-01-01
  • 1970-01-01
  • 2016-01-20
  • 2015-05-23
  • 1970-01-01
相关资源
最近更新 更多