|
@@ -50,7 +50,7 @@ class ExtendView extends View {
|
|
|
}
|
|
|
|
|
|
set quaternion(q){
|
|
|
- this.direction = new THREE.Vector3(0,0,-1).applyQuaternion(q)
|
|
|
+ this.direction = new THREE.Vector3(0,0,-1).applyQuaternion(q) //注意如果得到的dir.x==dir.y==0, yaw不会变为0, 导致算的quaternion和q不一致
|
|
|
}
|
|
|
|
|
|
copy(a){
|
|
@@ -180,7 +180,7 @@ class ExtendView extends View {
|
|
|
setView( info = {}){
|
|
|
// position, target, duration = 0, callback = null, onUpdate = null, Easing='', cancelFun
|
|
|
this.cancelFlying()
|
|
|
- let posWaitDone, rotWaitDone
|
|
|
+ let posWaitDone, rotWaitDone , dir
|
|
|
|
|
|
let posDone = ()=>{
|
|
|
rotWaitDone || done()
|
|
@@ -188,10 +188,14 @@ class ExtendView extends View {
|
|
|
}
|
|
|
let rotDone = ()=>{
|
|
|
if(endTarget){
|
|
|
- this.lookAt(endTarget); //compute radius for orbitcontrol
|
|
|
+ this.lookAt(endTarget); //compute radius for orbitcontrol
|
|
|
}else if(endQuaternion){
|
|
|
this.rotation = new THREE.Euler().setFromQuaternion(endQuaternion)
|
|
|
+ }else if(endYaw != void 0){
|
|
|
+ this.yaw = endYaw, this.pitch = endPitch
|
|
|
}
|
|
|
+ //if(dir.x == 0 && dir.y == 0)this.yaw = 0 //统一一下 朝上的话是正的。朝下的一般不是0,会保留一个接近0的小数所以不用管
|
|
|
+
|
|
|
posWaitDone || done()
|
|
|
rotWaitDone = false
|
|
|
}
|
|
@@ -212,24 +216,27 @@ class ExtendView extends View {
|
|
|
|
|
|
let endPosition = new THREE.Vector3().copy(info.position)
|
|
|
let startPosition = this.position.clone();
|
|
|
- let startQuaternion, endQuaternion, endTarget = null ;
|
|
|
+ let startQuaternion, endQuaternion, endTarget = null,
|
|
|
+ endYaw = info.endYaw, startYaw, endPitch = info.endPitch, startPitch ;
|
|
|
+
|
|
|
+
|
|
|
this.restrictPos(endPosition)
|
|
|
|
|
|
- if(info.target ){
|
|
|
+
|
|
|
+ if(endYaw != void 0) {
|
|
|
+ startYaw = this.yaw
|
|
|
+ startPitch = this.pitch
|
|
|
+ }else if(info.target ){
|
|
|
endTarget = new THREE.Vector3().copy(info.target)
|
|
|
- endQuaternion = math.getQuaFromPosAim(endPosition,endTarget)
|
|
|
- let dir = new THREE.Vector3().subVectors(endTarget, endPosition).normalize()
|
|
|
-
|
|
|
- let view = this.clone();
|
|
|
- view.direction = dir;
|
|
|
-
|
|
|
+ endQuaternion = math.getQuaFromPosAim(endPosition,endTarget) //若为垂直,会自动偏向x负的方向
|
|
|
+ dir = new THREE.Vector3().subVectors(endTarget, endPosition).normalize()
|
|
|
+ //console.log(dir, this.direction)
|
|
|
}else if(info.quaternion){
|
|
|
endQuaternion = info.quaternion.clone()
|
|
|
}
|
|
|
|
|
|
if(endQuaternion){
|
|
|
- startQuaternion = this.quaternion//new THREE.Quaternion().setFromEuler(this.rotation)
|
|
|
-
|
|
|
+ startQuaternion = this.quaternion
|
|
|
}
|
|
|
|
|
|
|
|
@@ -264,16 +271,19 @@ class ExtendView extends View {
|
|
|
}, info.ignoreFirstFrame);
|
|
|
}
|
|
|
|
|
|
- if(endQuaternion){
|
|
|
+ if(endQuaternion || endYaw != void 0){
|
|
|
rotWaitDone = true
|
|
|
transitions.start( (progress, delta )=>{
|
|
|
-
|
|
|
- let quaternion = (new THREE.Quaternion()).copy(startQuaternion)
|
|
|
- lerp.quaternion(quaternion, endQuaternion)(progress) //在垂直的视角下的角度突变的厉害,这时候可能渐变yaw比较好
|
|
|
-
|
|
|
- //this.rotation = new THREE.Euler().setFromQuaternion(quaternion)
|
|
|
- this.quaternion = quaternion
|
|
|
-
|
|
|
+ if(endYaw != void 0){
|
|
|
+ this.yaw = startYaw * (1-progress) + endYaw * progress
|
|
|
+ this.pitch = startPitch * (1-progress) + endPitch * progress
|
|
|
+ }else{
|
|
|
+ let quaternion = (new THREE.Quaternion()).copy(startQuaternion)
|
|
|
+ lerp.quaternion(quaternion, endQuaternion)(progress) //在垂直的视角下的角度突变的厉害,这时候可能渐变yaw比较好
|
|
|
+ //console.log(quaternion)
|
|
|
+ //this.rotation = new THREE.Euler().setFromQuaternion(quaternion)
|
|
|
+ this.quaternion = quaternion
|
|
|
+ }
|
|
|
posChange || info.onUpdate && info.onUpdate(progress, delta)
|
|
|
|
|
|
}, info.duration, rotDone , 0, info.Easing ? easing[info.Easing] : easing.easeInOutSine ,null, this.LookTransition, ()=>{
|
|
@@ -308,13 +318,16 @@ class ExtendView extends View {
|
|
|
|
|
|
//平移Ortho相机
|
|
|
moveOrthoCamera(viewport, info, duration, easeName){//boundSize优先于endZoom。
|
|
|
- let camera = viewport.camera
|
|
|
+ let camera = info.camera || viewport.camera
|
|
|
|
|
|
let startZoom = camera.zoom
|
|
|
let endPosition = info.endPosition
|
|
|
let boundSize = info.boundSize
|
|
|
let endZoom = info.endZoom
|
|
|
let margin = info.margin || {x:0,y:0}/* 200 */ //像素
|
|
|
+ let onUpdate = info.onUpdate
|
|
|
+
|
|
|
+
|
|
|
|
|
|
if(info.bound){//需要修改boundSize以适应相机的旋转,当相机不在xy水平面上朝向z时
|
|
|
endPosition = endPosition || info.bound.getCenter(new THREE.Vector3())
|
|
@@ -329,9 +342,12 @@ class ExtendView extends View {
|
|
|
boundSize.set(1,1) //避免infinity
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
this.setView( Object.assign(info, { position:endPosition, duration,
|
|
|
|
|
|
- onUpdate:(progress)=>{
|
|
|
+ onUpdate:(progress, delta)=>{
|
|
|
if(boundSize || endZoom){
|
|
|
if(boundSize){
|
|
|
let aspect = boundSize.x / boundSize.y
|
|
@@ -349,6 +365,7 @@ class ExtendView extends View {
|
|
|
|
|
|
camera.zoom = endZoom * progress + startZoom * (1 - progress)
|
|
|
camera.updateProjectionMatrix()
|
|
|
+ onUpdate && onUpdate(progress, delta)
|
|
|
}
|
|
|
},
|
|
|
|
|
@@ -391,6 +408,42 @@ class ExtendView extends View {
|
|
|
|
|
|
|
|
|
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ tranCamera(viewport, info, duration, easeName){
|
|
|
+ viewport.camera = info.midCamera
|
|
|
+ //viewport.camera.matrixWorld = info.endCamera.matrixWorld
|
|
|
+
|
|
|
+
|
|
|
+ //viewer.setCameraMode(CameraMode.ORTHOGRAPHIC)
|
|
|
+ info.midCamera.projectionMatrix.copy(info.startCamera.projectionMatrix)
|
|
|
+
|
|
|
+ let onUpdate = info.onUpdate
|
|
|
+ info.onUpdate = (progress, delta)=>{
|
|
|
+ lerp.matrix4(info.midCamera.projectionMatrix, info.endCamera.projectionMatrix)(progress)
|
|
|
+
|
|
|
+ /* console.log('matrixWorld', viewport.camera.position.toArray(), viewport.camera.matrixWorld.toArray())
|
|
|
+ console.log('projectionMatrix', info.endCamera.zoom, viewport.camera.projectionMatrix.toArray())
|
|
|
+ */
|
|
|
+ onUpdate && onUpdate(progress, delta)
|
|
|
+ }
|
|
|
+
|
|
|
+ let callback = info.callback
|
|
|
+ info.callback = ()=>{
|
|
|
+ viewport.camera = info.endCamera
|
|
|
+ callback && callback()
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ info.camera = info.endCamera
|
|
|
+
|
|
|
+ if(info.camera.type == "OrthographicCamera"){
|
|
|
+ this.moveOrthoCamera(viewport, info, duration, easeName)
|
|
|
+ }else{
|
|
|
+ this.setView( Object.assign(info, { duration}) )
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|