Any way to get a bounding box from a three.js Object3D?

前端 未结 4 1120
情话喂你
情话喂你 2020-11-28 06:42

I\'m loading an OBJ file using Three.js and OBJLoader.js. This returns a Three.Object3D object, which has what you\'d expect from a 3D model (position vector, up vector...)

4条回答
  •  佛祖请我去吃肉
    2020-11-28 07:39

    If you want the bounding box position and size as the object appears in the scene, try the BoundingBoxHelper:

    var helper = new THREE.BoundingBoxHelper(someObject3D, 0xff0000);
    helper.update();
    // If you want a visible bounding box
    scene.add(helper);
    // If you just want the numbers
    console.log(helper.box.min);
    console.log(helper.box.max);
    

    The .boundingBox on the geometry doesn't account for translations, rotations, or scaling that may be applied to the parent mesh and etc. and I found it very difficult to adjust for that manually, but the helper does it for you.

提交回复
热议问题