好的,经过多次尝试,我找到了一个近似的方法来获得结果。我意外地发现,如果远截面值设置为25,它将完美地工作...所以我制定了一个方程来补偿如果值不同。虽然不是完美的,但也足够接近了,也许有人可以看出它在哪里可以改进?
我在combinedcamera.js中进行了替换。
halfHeight /= this.zoom;
halfWidth /= this.zoom;
带有。
halfHeight /= ((this.cameraP.far/25)*this.zoom)
halfWidth /= ((this.cameraP.far/25)*this.zoom)
我在combinedcamera.js中添加了这一行代码。
this.cameraO.far = this.cameraP.far+((this.cameraP.far/25)*this.zoom)-0.5
在此之前
this.cameraO.updateProjectionMatrix()
这是完整的部分。
THREE.CombinedCamera.prototype.toOrthographic = function () {
var fov = this.fov;
var aspect = this.cameraP.aspect;
var near = this.cameraP.near;
var far = this.cameraP.far;
var hyperfocus = ( near + far ) / 2;
var halfHeight = Math.tan( fov * Math.PI / 180 / 2 ) * hyperfocus;
var planeHeight = 2 * halfHeight;
var planeWidth = planeHeight * aspect;
var halfWidth = planeWidth / 2;
halfHeight /= ((this.cameraP.far/25)*this.zoom);
halfWidth /= ((this.cameraP.far/25)*this.zoom);
this.cameraO.left = -halfWidth;
this.cameraO.right = halfWidth;
this.cameraO.top = halfHeight;
this.cameraO.bottom = -halfHeight;
this.cameraO.far = this.cameraP.far+((this.cameraP.far/25)*this.zoom)-0.5;
this.cameraO.updateProjectionMatrix();
this.near = this.cameraO.near;
this.far = this.cameraO.far;
this.projectionMatrix = this.cameraO.projectionMatrix;
this.inPerspectiveMode = false;
this.inOrthographicMode = true;
};
我将this.zoom更改为透视相机的1。
THREE.CombinedCamera.prototype.toPerspective = function () {
// Switches to the Perspective Camera
this.near = this.cameraP.near
this.far = this.cameraP.far
this.cameraP.fov = this.fov / 1
this.cameraP.updateProjectionMatrix()
this.projectionMatrix = this.cameraP.projectionMatrix
this.inPerspectiveMode = true
this.inOrthographicMode = false
}
另外,我不得不调整orbitcontrols。
this.dollyIn = function ( dollyScale ) {
if ( dollyScale === undefined ) {
dollyScale = getZoomScale();
}
scale /= dollyScale;
scope.object.zoom = Math.max( this.minZoom, Math.min( this.maxZoom, this.object.zoom * dollyScale ) );
};
this.dollyOut = function ( dollyScale ) {
if ( dollyScale === undefined ) {
dollyScale = getZoomScale();
}
scale *= dollyScale;
scope.object.zoom = Math.max( this.minZoom, Math.min( this.maxZoom, this.object.zoom / dollyScale ) );
};