更新版本,修复镜像槽问题
This commit is contained in:
@@ -1,21 +1,20 @@
|
||||
import * as THREE from 'three';
|
||||
import { Vector3 } from 'three';
|
||||
import { Box3, Camera, MathUtils, OrthographicCamera, PerspectiveCamera, Vector3 } from 'three';
|
||||
import { Orbit } from './Orbit';
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* 相机的控制.
|
||||
* ->切换相机
|
||||
* ->设置视口大小
|
||||
* ->旋转和移动相机.
|
||||
*
|
||||
*
|
||||
* @export
|
||||
* @class ViewCameraManage
|
||||
*/
|
||||
export class CameraUpdate
|
||||
{
|
||||
private m_CurCamera: THREE.Camera;
|
||||
private m_CameraArray: Map<any, THREE.Camera> = new Map<any, THREE.Camera>();
|
||||
private m_CurCamera: Camera;
|
||||
private m_CameraArray: Map<any, Camera> = new Map<any, Camera>();
|
||||
|
||||
//视口的画布大小
|
||||
private m_Width: number;
|
||||
@@ -24,9 +23,9 @@ export class CameraUpdate
|
||||
private m_ViewHeight: number = 10;
|
||||
|
||||
//观察的位置
|
||||
private m_Target: THREE.Vector3 = new THREE.Vector3();
|
||||
private m_Target: Vector3 = new Vector3();
|
||||
//观察向量
|
||||
private m_Direction: THREE.Vector3 = new THREE.Vector3(0, 0, -1);
|
||||
private m_Direction: Vector3 = new Vector3(0, 0, -1);
|
||||
//观察的轨道.
|
||||
private m_Orbit: Orbit = new Orbit();
|
||||
|
||||
@@ -35,12 +34,12 @@ export class CameraUpdate
|
||||
|
||||
constructor()
|
||||
{
|
||||
this.m_CameraArray.set(THREE.OrthographicCamera, new THREE.OrthographicCamera(-2, 2, 2, -2,
|
||||
this.m_CameraArray.set(OrthographicCamera, new OrthographicCamera(-2, 2, 2, -2,
|
||||
-1e6, 1e6));
|
||||
|
||||
this.m_CameraArray.set(THREE.PerspectiveCamera, new THREE.PerspectiveCamera(50, 1, 0.01, 10000));
|
||||
this.m_CameraArray.set(PerspectiveCamera, new PerspectiveCamera(50, 1, 0.01, 10000));
|
||||
|
||||
this.m_CurCamera = this.m_CameraArray.get(THREE.OrthographicCamera);
|
||||
this.m_CurCamera = this.m_CameraArray.get(OrthographicCamera);
|
||||
|
||||
this.m_Orbit.UpdateRoValue(this.m_Direction);
|
||||
|
||||
@@ -53,7 +52,7 @@ export class CameraUpdate
|
||||
return this.m_Width / this.m_Height;
|
||||
}
|
||||
|
||||
get Camera(): THREE.Camera
|
||||
get Camera(): Camera
|
||||
{
|
||||
return this.m_CurCamera;
|
||||
}
|
||||
@@ -63,7 +62,7 @@ export class CameraUpdate
|
||||
}
|
||||
set ViewHeight(height)
|
||||
{
|
||||
this.m_ViewHeight = THREE.Math.clamp(height, this.m_MinViewHeight, this.m_MaxViewHeight);
|
||||
this.m_ViewHeight = MathUtils.clamp(height, this.m_MinViewHeight, this.m_MaxViewHeight);
|
||||
}
|
||||
|
||||
SetSize(width: number, height: number)
|
||||
@@ -74,11 +73,11 @@ export class CameraUpdate
|
||||
|
||||
/**
|
||||
* 平移相机.
|
||||
*
|
||||
* @param {THREE.Vector3} mouseMove
|
||||
*
|
||||
* @param {Vector3} mouseMove
|
||||
* @memberof CameraControl
|
||||
*/
|
||||
Pan(mouseMove: THREE.Vector3)
|
||||
Pan(mouseMove: Vector3)
|
||||
{
|
||||
mouseMove.y *= -1;
|
||||
mouseMove.multiplyScalar(-this.m_ViewHeight / this.m_Height);
|
||||
@@ -86,7 +85,7 @@ export class CameraUpdate
|
||||
this.m_Target.add(mouseMove);
|
||||
this.Update();
|
||||
}
|
||||
Rotate(mouseMove: THREE.Vector3, target: THREE.Vector3)
|
||||
Rotate(mouseMove: Vector3, target: Vector3)
|
||||
{
|
||||
this.m_Orbit.RoX -= mouseMove.y * 0.003;
|
||||
this.m_Orbit.RoZ -= mouseMove.x * 0.003;
|
||||
@@ -112,9 +111,9 @@ export class CameraUpdate
|
||||
|
||||
this.Update();
|
||||
}
|
||||
Zoom(scale: number, scaleCenter?: THREE.Vector3)
|
||||
Zoom(scale: number, scaleCenter?: Vector3)
|
||||
{
|
||||
if (this.Camera instanceof THREE.OrthographicCamera)
|
||||
if (this.Camera instanceof OrthographicCamera)
|
||||
{
|
||||
this.ViewHeight *= scale;
|
||||
if (scaleCenter && this.m_ViewHeight < this.m_MaxViewHeight)
|
||||
@@ -124,7 +123,7 @@ export class CameraUpdate
|
||||
this.m_Target.add(scaleCenter);
|
||||
}
|
||||
}
|
||||
else if (this.Camera instanceof THREE.PerspectiveCamera)
|
||||
else if (this.Camera instanceof PerspectiveCamera)
|
||||
{
|
||||
let add = scale > 1 ? 1 : -1;
|
||||
add *= this.Camera.position.distanceTo(this.m_Target) / 10;
|
||||
@@ -132,7 +131,7 @@ export class CameraUpdate
|
||||
}
|
||||
this.Update();
|
||||
}
|
||||
ZoomExtensBox3(box3: THREE.Box3)
|
||||
ZoomExtensBox3(box3: Box3)
|
||||
{
|
||||
if (!box3 || box3.isEmpty()) return;
|
||||
this.Camera.updateMatrixWorld(false);
|
||||
@@ -159,7 +158,7 @@ export class CameraUpdate
|
||||
}
|
||||
this.Update();
|
||||
}
|
||||
LookAt(dir: THREE.Vector3)
|
||||
LookAt(dir: Vector3)
|
||||
{
|
||||
this.m_Orbit.UpdateRoValue(dir);
|
||||
this.m_Direction.copy(dir);
|
||||
@@ -173,15 +172,15 @@ export class CameraUpdate
|
||||
}
|
||||
/**
|
||||
* 根据视口大小,设置相机视口范围.
|
||||
*
|
||||
* @returns
|
||||
*
|
||||
* @returns
|
||||
* @memberof CameraControl
|
||||
*/
|
||||
Update()
|
||||
{
|
||||
this.Camera.position.copy(this.m_Target);
|
||||
|
||||
if (this.Camera instanceof THREE.OrthographicCamera)
|
||||
if (this.Camera instanceof OrthographicCamera)
|
||||
{
|
||||
this.Camera.left = this.Aspect * this.m_ViewHeight / -2;
|
||||
this.Camera.right = this.Aspect * this.m_ViewHeight / 2;
|
||||
@@ -190,10 +189,10 @@ export class CameraUpdate
|
||||
|
||||
this.Camera.position.sub(this.m_Direction);
|
||||
}
|
||||
else if (this.Camera instanceof THREE.PerspectiveCamera)
|
||||
else if (this.Camera instanceof PerspectiveCamera)
|
||||
{
|
||||
this.Camera.aspect = this.Aspect;
|
||||
let distens = (this.m_ViewHeight / 2) / (Math.tan(THREE.Math.degToRad(this.Camera.fov) / 2));
|
||||
let distens = (this.m_ViewHeight / 2) / (Math.tan(MathUtils.degToRad(this.Camera.fov) / 2));
|
||||
|
||||
this.Camera.position.sub(this.m_Direction.clone().multiplyScalar(distens));
|
||||
}
|
||||
@@ -209,13 +208,13 @@ export class CameraUpdate
|
||||
|
||||
SwitchCamera()
|
||||
{
|
||||
if (this.Camera instanceof THREE.OrthographicCamera)
|
||||
if (this.Camera instanceof OrthographicCamera)
|
||||
{
|
||||
this.m_CurCamera = this.m_CameraArray.get(THREE.PerspectiveCamera);
|
||||
this.m_CurCamera = this.m_CameraArray.get(PerspectiveCamera);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.m_CurCamera = this.m_CameraArray.get(THREE.OrthographicCamera);
|
||||
this.m_CurCamera = this.m_CameraArray.get(OrthographicCamera);
|
||||
}
|
||||
this.UpdateUp();
|
||||
this.Update();
|
||||
|
Reference in New Issue
Block a user