1 |
- var TourPlayer=function(){"use strict";var e=KanKan.Animate.transitions,t="panorama",r="floorplan",o={flydown:{movementEasing:"easeInOutQuad",movementDelay:.001,rotationEasing:"easeInOutQuad",rotationDelay:.5,modelTextureDelay:.75,skyboxDelay:.75}};o.freeze=Object.freeze({FlyToPano:e.getUniqueId(),FlyToNewMode:e.getUniqueId(),FlyToSameMode:e.getUniqueId(),FlyToViewFloor:e.getUniqueId(),LookTransition:e.getUniqueId(),ZoomTransition:e.getUniqueId(),LookRotationForPlay:e.getUniqueId(),wallLineShine:e.getUniqueId(),spotShine:e.getUniqueId(),rulerShine:e.getUniqueId(),outsideFocus:e.getUniqueId(),shopCircle:e.getUniqueId()});var a=function(a){function n(e,t){a.call(this),this.app=e,this._wait_queue=[],this._anit_queue=[],this._is_play_frame=!1,this._is_end=!1,this._is_transing=!1}a&&(n.__proto__=a),n.prototype=Object.create(a&&a.prototype),n.prototype.constructor=n;var i={tours:{configurable:!0},partId:{configurable:!0},frameId:{configurable:!0},playing:{configurable:!0},isEnd:{configurable:!0}};return i.tours.get=function(){return this.app.TourManager.tours},i.partId.get=function(){return this.app.TourManager.partId},i.partId.set=function(e){this.app.TourManager.partId=e},i.frameId.get=function(){return this.app.TourManager.frameId},i.frameId.set=function(e){this.app.TourManager.frameId=e},i.playing.get=function(){return this.app.TourManager.playing},i.playing.set=function(e){this.app.TourManager.playing=e},i.isEnd.get=function(){return this._is_end},n.prototype.play=function(e,t,r){var o=this;if(void 0===r&&(r=!0),this.tours.length){if(this._is_transing)return setTimeout((function(){o.play(e,t,r)}),100);if(null!=e&&null!=t?(this.partId=e,this.frameId=t,this._is_play_frame=!r):null!=e?(this.partId=e,this.frameId=0):this.frameId=0,this._is_end&&(this._is_end=!1,this.partId=0,this.frameId=0),this.playing)return this.pause(!0),this._start_timer&&clearTimeout(this._start_timer),void(this._start_timer=setTimeout((function(){o.play(e,t)}),200));var a=this.tours[this.partId],n=a.list[this.frameId];if(!n)return this.emit("end");n._end&&(this.frameId=0,n=a.list[this.frameId]),this.playing=!0,this.flyToFirst(n,(function(){o.playing&&(o.emit("play",{partId:o.partId,frameId:o.frameId}),o.playNextFrame())}))}},n.prototype.pause=function(t){this.tours.length&&(this._anit_queue.forEach((function(t){return t&&e.cancel(t)})),this._wait_queue.forEach((function(e){return e&&clearTimeout(e)})),this._anit_queue=[],this._wait_queue=[],this.playing=!1,this._is_play_frame=!1,e.cancelById(o.freeze.LookRotationForPlay),e.cancelById(o.freeze.LookTransition),t||this.emit("pause",{partId:this.partId,frameId:this.frameId}),this.tours[this.partId].audio&&this.tours[this.partId].audio.stop())},n.prototype.end=function(){var e=this;if(this._anit_queue=[],this._wait_queue=[],this.playing=!1,this.tours[this.partId].audio){var t=this.partId;setTimeout((function(){e.tours[t].audio.stop()}),50)}this._is_play_frame||(this._is_end=!0,this.partId=this.tours.length-1,this.frameId=this.tours[this.partId].list.length-1),this.emit("progress",{partId:this.partId,frameId:this.frameId,progress:1}),this.emit("end"),this._is_play_frame=!1,this.tours[this.partId].audio&&this.tours[this.partId].audio.stop()},n.prototype.selectPart=function(e){var t=this;return new Promise((function(r){if(isNaN(e))return r();var o=t.tours[e];o?(t.partId=e,t.frameId=0,t._is_end=!1,t.selectFrame(t.frameId).then((function(){return r(o)}))):r()}))},n.prototype.getFrame=function(){var e=this.tours[this.partId];if(e)return e.list[this.frameId]},n.prototype.selectFrame=function(e,r){var o=this;if(r||(r=KanKan.Deferred()),isNaN(e))return r.resolve(),r;e=parseInt(e);var a=this.tours[this.partId].list[e];if(!a)return r.resolve(),r;if(this.playing)return this.pause(!0),setTimeout((function(){o.selectFrame(e,r)}),500),r;this._is_end=!1,this._is_transing=!0,this.frameId=e;var n=this.app.core.get("Player");if(n.mode==t&&a.enter.mode==t){var i=new THREE.Vector3(0,0,-1).applyQuaternion(a.enter.qua).add(a.enter.pos),s=n.model.panos.get(a.enter.panoId);n.flyToPano({pano:s,lookAtPoint:i},(function(){return r.resolve(a)}))}else if(n.mode!=a.enter.mode)if(a.enter.mode==t){var p=n.model.panos.get(a.enter.panoId);n.flyToNewMode({pano:p,quaternion:this.parseVector4(a.enter.qua),mode:a.enter.mode,callback:function(){return r.resolve(a)}})}else n.flyToNewMode({position:this.parseVector3(a.enter.pos),target:this.parseVector3(a.enter.target),quaternion:this.parseVector4(a.enter.qua),mode:a.enter.mode,currentScale:a.enter.currentScale,callback:function(){a.enter.hasOwnProperty("floor")&&o.app.Scene.gotoFloor(a.enter.floor),r.resolve(a)}});else{var u=this.parseVector3(a.enter.pos),l=this.parseVector3(a.enter.target),d=a.enter.currentScale;this.playForRotateForDollAndFloor(u,l,d,a.enter.mode,null,(function(){return r.resolve(a)}),1e3),a.enter.hasOwnProperty("floor")&&this.app.Scene.gotoFloor(a.enter.floor),r.resolve(a)}return r.then((function(e){return o._is_transing=!1,e})),r},n.prototype.flyToFirst=function(e,r){var o=this,a=this.app.core.get("Player");if(a.mode==t&&e.enter.mode==t){var n=new THREE.Vector3(0,0,-1).applyQuaternion(e.enter.qua).add(e.enter.pos),i=a.model.panos.get(e.enter.panoId);a.flyToPano({pano:i,lookAtPoint:n},r)}else if(e.enter.mode==t){var s=a.model.panos.get(e.enter.panoId);a.flyToNewMode({pano:s,quaternion:this.parseVector4(e.enter.qua),mode:e.enter.mode,callback:r})}else a.flyToNewMode({position:this.parseVector3(e.enter.pos),target:this.parseVector3(e.enter.target),quaternion:this.parseVector4(e.enter.qua),mode:e.enter.mode,currentScale:e.enter.currentScale,callback:function(){e.enter.hasOwnProperty("floor")&&o.app.Scene.gotoFloor(e.enter.floor),r()}})},n.prototype.playForRotateForPano=function(t,r,a){var n=this.app.core.get("Player"),i=n.cameraControls.activeControl.camera.quaternion;e.start(KanKan.Animate.lerp.quaternion(i,t,function(e,t){if(n.cameraControls.activeControl){var r=new THREE.Vector3(0,0,-1).applyQuaternion(e).add(n.position);n.cameraControls.activeControl.lookAt(r)}this.emit("progress",{partId:this.partId,frameId:this.frameId,progress:t})}.bind(this)),r,(function(){a()}),0,KanKan.Animate.easing[o.flydown.rotationEasing],null,o.freeze.LookRotationForPlay)},n.prototype.playForRotateForDollAndFloor=function(t,a,n,i,s,p,u){var l=this.app.core.get("Player");e.start(KanKan.Animate.lerp.vector(l.cameraControls.activeControl.target,new THREE.Vector3(a.x,a.y,a.z),s),u,null,0,KanKan.Animate.easing[o.flydown.rotationEasing],null,o.freeze.LookRotationForPlay),e.start(KanKan.Animate.lerp.vector(l.cameraControls.activeControl.camera.position,t),u,p,0,KanKan.Animate.easing[o.flydown.rotationEasing],null,o.freeze.LookRotationForPlay),i==r&&l.cameraControls.activeControl.absoluteScale!=n&&e.start(KanKan.Animate.lerp.property(l.cameraControls.activeControl,"absoluteScale",n,function(e){l.cameraControls.activeControl&&(l.cameraControls.activeControl.currentScale=e,"PerspectiveCamera"!=l.cameraControls.activeControl.camera.type&&l.cameraControls.activeControl.updateZoom())}.bind(this)),u,null,0,KanKan.Animate.easing[o.flydown.rotationEasing],null,o.freeze.LookRotationForPlay)},n.prototype.playForFlyToPano=function(e,r,o){var a=this.app.core.get("Player");if(a.mode==t&&e.enter.mode==t){var n=a.model.panos.get(e.enter.panoId);if("fast"==r)a.fastToPano({pano:n,quaternion:this.parseVector4(e.enter.qua),callback:o});else{var i=new THREE.Vector3(0,0,-1).applyQuaternion(e.enter.qua).add(e.enter.pos);a.flyToPano({pano:n,lookAtPoint:i},o)}}},n.prototype.playForFlyToNewMode=function(e,r){var o=this,a=this.app.core.get("Player");if(a.mode==e.enter.mode&&a.mode==t);else if(a.mode!=e.enter.mode)if(e.enter.mode==t){var n=a.model.panos.get(e.enter.panoId);a.flyToNewMode({pano:n,quaternion:e.enter.qua,mode:e.enter.mode,callback:r})}else a.flyToNewMode({position:e.enter.pos,target:e.enter.target,quaternion:e.enter.qua,mode:e.enter.mode,currentScale:e.enter.currentScale,callback:function(){e.enter.hasOwnProperty("floor")&&o.app.Scene.gotoFloor(e.enter.floor),r()}})},n.prototype.playFrame=function(r,o){var a=this;if(o){this.app.core.get("Player").cameraControls.activeControl.camera.quaternion.clone();var n=this.parseVector4(o.enter.qua);if(r.enter.mode==t){if(o.enter.mode==t){if(r.enter.panoId!=o.enter.panoId)return this._wait_queue.push(setTimeout((function(){return a.playForFlyToPano(o,r.transitType,(function(){return a.playNextFrame(!0)}))}),r.time)),void this._anit_queue.push(e.start((function(e){a.emit("progress",{partId:a.partId,frameId:a.frameId,progress:e})}),r.time));this.playForRotateForPano(n,r.time,(function(){return a.playNextFrame(!0)}))}else if(o.enter.mode!=t)return this._wait_queue.push(setTimeout((function(){return a.playForFlyToNewMode(o,(function(){return a.playNextFrame(!0)}))}),r.time)),void this._anit_queue.push(e.start((function(e){a.emit("progress",{partId:a.partId,frameId:a.frameId,progress:e})}),r.time))}else if(r.enter.mode!=t){if(r.enter.mode!=o.enter.mode)return this._wait_queue.push(setTimeout((function(){return a.playForFlyToNewMode(o,(function(){return a.playNextFrame(!0)}))}),r.time)),void this._anit_queue.push(e.start((function(e){a.emit("progress",{partId:a.partId,frameId:a.frameId,progress:e})}),r.time));this.playForRotateForDollAndFloor(new THREE.Vector3(o.enter.pos.x,o.enter.pos.y,o.enter.pos.z),new THREE.Vector3(o.enter.target.x,o.enter.target.y,o.enter.target.z),o.enter.currentScale,r.enter.mode,(function(e,t){return a.emit("progress",{partId:a.partId,frameId:a.frameId,progress:t})}),(function(){o.enter.hasOwnProperty("floor")&&a.app.Scene.gotoFloor(o.enter.floor),a.playNextFrame(!0)}),r.time)}}else this.playNextFrame(!0)},n.prototype.playNextFrame=function(e){if(this.playing){if(e){if(this._is_play_frame)return this.end();this.frameId++}var t=this.tours[this.partId].list[this.frameId];if(t)e||this._is_play_frame||this.tours[this.partId].audio&&this.tours[this.partId].audio.play();else{this.tours[this.partId].audio&&this.tours[this.partId].audio.stop();var r=this.tours[this.partId+1];if(!(r&&r.list&&r.list.length))return this.end();this.partId++,this.frameId=0,t=this.tours[this.partId].list[this.frameId],this.tours[this.partId].audio&&this.tours[this.partId].audio.play()}var o=this.tours[this.partId].list[this.frameId+1];if(!o){var a=this.partId+1;if(!this.tours[a]||!this.tours[a].list||!this.tours[a].list.length)return this.end();if(!(o=this.tours[a].list[0]))return this.end()}this.playFrame(t,o)}},n.prototype.parseVector4=function(e){return new THREE.Quaternion(e.x,e.y,e.z,e.w)},n.prototype.parseVector3=function(e){return new THREE.Vector3(e.x,e.y,e.z)},Object.defineProperties(n.prototype,i),n}(KanKan.MITT.Emiter);return function(e,t){void 0===t&&(t={});var r=KanKan.Deferred();return e.Scene.on("loaded",(function(){var o=new a(e,t);o.$name="TourPlayer",o.$load=function(){e.TourManager.install("player",o)},r.resolve(o)})),r}}();
|