three.js - 为什么 THREE.BoundingBoxHelper 不显示?

标签 three.js collada

enter image description here

我之前曾设法显示该框,但在这里,我剥离了所有内容以便通过定位 collada 模型来尝试扩展框,但该框不会显示。

function loadObjects(){
  cobj = new THREE.Group();
  cobj.name = "5";
  scene.add(cobj);
  pobj = cobj;
  collada("14",pobj);
  collada("7",pobj);
  function collada(key,pobj){
    var nn,file,path,loader,dae,s;
    ns = nset[key].shared;
    model = ns.Product;
    source = ns.Source;
    ext = ns.Extension;
    path = source +model +ext;
    loader = new THREE.ColladaLoader();
    loader.load(path,function (collada) {
      dae = collada.scene;
      dae.name = key;
      sc = 25.4;
      dae.scale.set(sc,sc,sc);
      pobj.add(dae);
    });
  }
  obj = scene.getObjectByName("5");
  console.log(obj);
  helper = new THREE.BoundingBoxHelper(obj,0xff0000);
  helper.update();
  scene.add(helper);
  sc = 0.1;
  scene.scale.set(sc,sc,sc);
  requestAnimationFrame( animate );
  renderer.render( scene, camera );
  $("canvas").show();
}

最佳答案

首先,BoundingBoxHelper 现在是 BoxHelper。您似乎使用的是非常旧的 third.js 版本。

此外,您的 collada() 函数不是同步的。执行 collada("14",pobj);collada("7",pobj); 后,资源尚未加载,这意味着您正在计算以下对象的边界框一个空的组对象。

我建议您等待 Collada 模型通过 THREE.LoadingManager 加载完毕。然后将助手添加到场景中。

或者,确保在动画循环中调用 helper.update()。然而,如果对象是静态的并且不会改变,那么这种方法是浪费的。因此,最好使用加载管理器的 onLoad() 回调。

关于three.js - 为什么 THREE.BoundingBoxHelper 不显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67957274/

相关文章:

three.js - 将粒子推离glsl和三个js中的mouseposition

java - 从 Java Web 应用程序导出 WebGL 3D 模型的推荐格式

xml - 写入 dae 时,Scenekit 会自动在节点名称中的空格处插入下划线

collada - 加载 Collada (dae) 模型时如何在 THREE.js 中设置 Material ?

javascript - ColladaLoader 无法加载两个不同的模型

json - JSON 中位置 0 的意外标记 < - Three.js 和 Vue 应用程序中的 glTFLoader

javascript - three.js 的新手,如何在 three.js 中为这个球制作动画

javascript - 验证和运行 javascript (html5 canvas) 的问题

animation - 具有多个骨骼的 collada 动画

javascript - 从 A-Frame 或 JS 更新 Collada (.dae ) 文件代码