three.js导入模型自适应居中展示

用于导入模型后,自动调整模型的缩放比例

//适合模型观察的缩放比例
  setScaleToFitSize(obj) {
    const boxHelper = new THREE.BoxHelper(obj);
    boxHelper.geometry.computeBoundingBox();
    const box = boxHelper.geometry.boundingBox;
    const maxDiameter = Math.max((box.max.x - box.min.x), (box.max.y - box.min.y), (box.max.z - box.min.z));
    const scaleValue = this.camera.position.z / maxDiameter;
    obj.scale.set(scaleValue, scaleValue, scaleValue);
  }

 

上一篇:python中requests发送POST请求—破解百度翻译案例


下一篇:XOR to All