three.jscollada

Why does THREE.BoundingBoxHelper not display?


enter image description here

I have previously managed to display the box, but here, where I have stripped everything down in order to experiment with expanding boxes by positioning collada models, the box won't show.

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

Solution

  • First of all, BoundingBoxHelper is now BoxHelper. It seems you are using a very old release of three.js.

    Besides, your collada() function is not synchronous. After executing collada("14",pobj); and collada("7",pobj); the assets are not yet loaded which means you are computing the bounding box for an empty group object.

    I suggest you wait until the Collada models have been loaded via THREE.LoadingManager and then add the helper to your scene.

    Alternatively, ensure to call helper.update() in your animation loop. This approach is wasteful however if the object is static and does not change. So it's probably better to use the onLoad() callback of a loading manager.