注释
合作者作者
更新: |
合作者作者
Todo:将 3D 可视化器中的旋转轴心点设置为铣刀的当前位置。 更新:在 0.9.x 中修复 |
合作者作者
来源:http ://stackoverflow.com/questions/14614252/how-to-fit-camera-to-object 要使对象高度与可见高度相匹配: fov = 2 * Math.atan(height / (2 * dist)) * ( 180 / Math.PI); // in degrees
要使对象宽度与可见宽度匹配: fov = 2 * Math.atan((width / aspect) / (2 * dist)) * (180 / Math.PI); // in degrees
该算法已在v0.10.4中实现。 const CAMERA_DEFAULT_FOV = 50;
// Fits camera to object
// @param {number} width The object width
// @param {number} height The object height
// @param {THREE.Vector3} [lookTarget] The object's top position which is nearest to the camera
fitCameraToObject(width, height, lookTarget) {
console.assert(_.isNumber(width));
console.assert(_.isNumber(height));
console.assert(lookTarget instanceof THREE.Vector3);
let v1 = (lookTarget instanceof THREE.Vector3) ? lookTarget : new THREE.Vector3(0, 0, 0);
let v2 = new THREE.Vector3(
this.camera.position.x,
this.camera.position.y,
this.camera.position.z
);
let dist = v1.distanceTo(v2); // the distance from the camera to the closest face of the object
let aspect = this.camera.aspect; // the aspect ratio of the canvas (width / height)
width = Number(width) || 0;
height = Number(height) || 0;
// Pick the largest camera field-of-view
let fov = Math.max(
2 * Math.atan(height / (2 * dist)) * (180 / Math.PI),
2 * Math.atan((width / aspect) / (2 * dist)) * (180 / Math.PI)
);
fov = fov || CAMERA_DEFAULT_FOV;
this.camera.fov = fov;
this.camera.updateProjectionMatrix();
}
使用示例可能如下所示: let objectWidth = dimension.delta.x;
let objectHeight = dimension.delta.y;
let lookTarget = new THREE.Vector3(0, 0, dimension.max.z);
this.fitCameraToObject(objectWidth, objectHeight, lookTarget);
|
参考
http://stackoverflow.com/questions/14614252/how-to-fit-camera-to-object
https://scottbyrns.atlassian.net/wiki/display/THREEJS/How+to+Fit+Camera+to +对象