-
Notifications
You must be signed in to change notification settings - Fork 2
/
THREE.TargetCamera.min.js
8 lines (8 loc) · 2.65 KB
/
THREE.TargetCamera.min.js
1
2
3
4
5
6
7
8
/**
* THREE.TargetCamera.js 1.1.0
* (c) 2013 Luke Moody (http://www.github.com/squarefeet)
*
* THREE.TargetCamera may be freely distributed under the MIT license
* (See the LICENSE file at root of this repository.)
*/
THREE.TargetCamera=function(a,b,c,d){THREE.PerspectiveCamera.call(this),this.fov=void 0!==a?a:50,this.aspect=void 0!==b?b:1,this.near=void 0!==c?c:.1,this.far=void 0!==d?d:2e3,this.targets={},this.targetOrder=[],this.currentTargetName=null,this._idealObject=new THREE.Object3D,this._isTransitioning=!1,this._defaults={name:null,targetObject:new THREE.Object3D,cameraPosition:new THREE.Vector3(0,30,50),cameraRotation:void 0,fixed:!1,stiffness:.4,matchRotation:!0},this.updateProjectionMatrix()},THREE.TargetCamera.prototype=Object.create(THREE.PerspectiveCamera.prototype),THREE.TargetCamera.prototype._translateIdealObject=function(a){var b=this._idealObject;0!==a.x&&b.translateX(a.x),0!==a.y&&b.translateY(a.y),0!==a.z&&b.translateZ(a.z)},THREE.TargetCamera.prototype._createNewTarget=function(){var a=this._defaults;return{name:a.name,targetObject:a.targetObject,cameraPosition:a.cameraPosition,cameraRotation:a.cameraRotation,fixed:a.fixed,stiffness:a.stiffness,matchRotation:a.matchRotation}},THREE.TargetCamera.prototype._determineCameraRotation=function(a){return a instanceof THREE.Euler?(new THREE.Quaternion).setFromEuler(a):a instanceof THREE.Quaternion?a:void 0},THREE.TargetCamera.prototype.addTarget=function(a){var b=this._createNewTarget();if("object"==typeof a)for(var c in a)b.hasOwnProperty(c)&&("cameraRotation"===c?b[c]=this._determineCameraRotation(a[c]):b[c]=a[c]);this.targets[a.name]=b,this.targetOrder.push(a.name)},THREE.TargetCamera.prototype.setTarget=function(a){this.targets.hasOwnProperty(a)?this.currentTargetName=a:console.warn("THREE.TargetCamera.setTarget: No target with name "+a)},THREE.TargetCamera.prototype.removeTarget=function(a,b){var c=this.targets,d=this.targetOrder;return 1===d.length?void console.warn("THREE.TargetCamera: Will not remove only existing camera target."):(c.hasOwnProperty(a)&&(d.splice(d.indexOf(a),1),c[a]=null),void this.setTarget(b&&c.hasOwnProperty(b)?b:d[d.length-1]))},THREE.TargetCamera.prototype.update=function(a){var b=this.targets[this.currentTargetName],c=this._idealObject;b&&(b.fixed?(this.position.copy(b.cameraPosition),this.lookAt(b.targetObject.position)):(c.position.copy(b.targetObject.position),c.quaternion.copy(b.targetObject.quaternion),void 0!==b.cameraRotation&&c.quaternion.multiply(b.cameraRotation),this._translateIdealObject(b.cameraPosition),this.position.lerp(c.position,b.stiffness),b.matchRotation?this.quaternion.slerp(c.quaternion,b.stiffness):this.lookAt(b.targetObject.position)))};