限制用户的相机活动范围,避免用户在坐标过大的地方绘制图形, 添加双击鼠标缩放整体图纸的功能.

pull/68/head
ChenX 6 years ago
parent 4e2841054a
commit dfef0ce3d9

@ -141,6 +141,9 @@ export class CameraControls
this.m_State = CameraControlState.Rotate;
this.m_Viewer.UpdateLockTarget();
}
//最后一次按中键的时间
lastMiddleClickTime = 0;
//鼠标
onMouseDown = (event: MouseEvent) =>
{
@ -161,6 +164,15 @@ export class CameraControls
}
case MouseKey.Middle:
{
let curTime = Date.now();
let t = curTime - this.lastMiddleClickTime;
this.lastMiddleClickTime = curTime;
if (t < 350)
{
this.m_Viewer.ZoomAll();
return;
}
if (this.m_KeyDown.get(KeyBoard.Control))
{
this.beginRotate();

@ -2,6 +2,11 @@ import * as THREE from 'three';
import { Vector3 } from 'three';
import { Orbit } from '../Geometry/Orbit';
const ViewScopeSize = 4e4;
//相机活动范围
const ViewScopeMin = new Vector3(-ViewScopeSize, -ViewScopeSize * 0.7, -ViewScopeSize);
const ViewScopeMax = ViewScopeMin.clone().negate();
/**
*
* .
@ -30,12 +35,16 @@ export class CameraControl
//观察的轨道.
private m_Orbit: Orbit = new Orbit();
//最大最小视口高度
m_MinViewHeight = 1e-3;
m_MaxViewHeight = 3e4;
constructor()
{
this.m_CameraArray.set(THREE.OrthographicCamera, new THREE.OrthographicCamera(-2, 2, 2, -2,
-10000, 10000));
-ViewScopeSize, ViewScopeSize));
this.m_CameraArray.set(THREE.PerspectiveCamera, new THREE.PerspectiveCamera(50, 1, 0.01, 10000));
this.m_CameraArray.set(THREE.PerspectiveCamera, new THREE.PerspectiveCamera(50, 1, 0.01, ViewScopeSize));
this.m_CurCamera = this.m_CameraArray.get(THREE.OrthographicCamera);
@ -60,7 +69,7 @@ export class CameraControl
}
set ViewHeight(height)
{
this.m_ViewHeight = THREE.Math.clamp(height, 1e-8, 1e8);
this.m_ViewHeight = THREE.Math.clamp(height, this.m_MinViewHeight, this.m_MaxViewHeight);
}
SetSize(width: number, height: number)
@ -81,6 +90,7 @@ export class CameraControl
mouseMove.multiplyScalar(-this.m_ViewHeight / this.m_Height);
mouseMove.applyQuaternion(this.Camera.quaternion);
this.m_Target.add(mouseMove);
this.m_Target.clamp(ViewScopeMin, ViewScopeMax);
this.Update();
}
Rotate(mouseMove: THREE.Vector3, target: THREE.Vector3)
@ -114,7 +124,7 @@ export class CameraControl
if (this.Camera instanceof THREE.OrthographicCamera)
{
this.ViewHeight *= scale;
if (scaleCenter)
if (scaleCenter && this.m_ViewHeight < this.m_MaxViewHeight)
{
this.m_Target.sub(scaleCenter);
this.m_Target.multiplyScalar(scale);
@ -131,7 +141,7 @@ export class CameraControl
}
ZoomExtensBox3(box3: THREE.Box3)
{
if (!box3) return;
if (!box3 || box3.isEmpty()) return;
this.Camera.updateMatrixWorld(false);
//变换到相机坐标系
box3.applyMatrix4(this.Camera.matrixWorldInverse);
@ -148,11 +158,11 @@ export class CameraControl
//
if (aspectRatio > viewAspectRatio)
{
this.m_ViewHeight = size.x / viewAspectRatio;
this.ViewHeight = size.x / viewAspectRatio;
}
else
{
this.m_ViewHeight = size.y;
this.ViewHeight = size.y;
}
this.Update();
}

Loading…
Cancel
Save