1 |
- var TourPlayer=function(){"use strict";var t=function(){this.panos=null};t.prototype.getPointForPano=function(t){return{id:t,G:0,position:this.panos[t].position,contact:this.panos[t].neighbourUUIDs}},t.prototype.getNeighbourUUIDs=function(t){return t.neighbourUUIDs},t.prototype.searchRoad=function(t,e,a){try{if(this.panos=t,e==a)return console.log("点击的点和当前点是同一个点"),null;var o=this.getPointForPano(e);if(o.contact.indexOf(a)>-1)return[a];var r,n,i=this.getPointForPano(a),s=[],p=[],l=[];s.push({id:e,G:0,position:o.position,contact:o.contact});do{var u=s.pop();if(p.push(u),p.length>1e4)return console.log("错误过渡路径:",p.length),null;var d;d=this.getPointForPano(u.id).contact;for(var h=0;h<d.length;++h){var c=d[h],f=this.getPointForPano(c);if(-1==this.existList(f,p)){f.id=c;var m=u.G+this.getDistance(u.position,f.position);if(-1==this.existList(f,s))f.H=this.getDistance(i.position,f.position),f.G=m,f.F=f.H+f.G,f.parent=u,s.push(f);else{var g=this.existList(f,s);m<s[g].G&&(s[g].parent=u,s[g].G=m,s[g].F=m+s[g].H)}}}if(0==s.length)break;s.sort(this.sortF)}while(-1==(r=this.existList(i,s)));if(void 0===r||-1==r)l=[];else{n=s[r];do{if(l.unshift(n.id),!(n=n.parent))break}while(l.length<50&&n.contact.indexOf(e)<0)}return l.length>50?(console.log("错误过渡路径:"+l),null):(n&&l.unshift(n.id),console.log("path-end"+l),l)}catch(t){return console.error("searchRoad",t),[]}},t.prototype.sortF=function(t,e){return e.F-t.F},t.prototype.existList=function(t,e){for(var a=0;a<e.length;++a)if(t.id==e[a].id)return a;return-1},t.prototype.getDistance=function(t,e){return Math.sqrt((t.x-e.x)*(t.x-e.x)+(t.y-e.y)*(t.y-e.y)+(t.z-e.z)*(t.z-e.z))};var e=new t,a=KanKan.Animate.transitions,o="panorama",r="floorplan",n={flydown:{movementEasing:"easeInOutQuad",movementDelay:.001,rotationEasing:"easeInOutQuad",rotationDelay:.5,modelTextureDelay:.75,skyboxDelay:.75}};n.freeze=Object.freeze({FlyToPano:a.getUniqueId(),FlyToNewMode:a.getUniqueId(),FlyToSameMode:a.getUniqueId(),FlyToViewFloor:a.getUniqueId(),LookTransition:a.getUniqueId(),ZoomTransition:a.getUniqueId(),LookRotationForPlay:a.getUniqueId(),wallLineShine:a.getUniqueId(),spotShine:a.getUniqueId(),rulerShine:a.getUniqueId(),outsideFocus:a.getUniqueId(),shopCircle:a.getUniqueId()});var i=function(t){function i(e,a){t.call(this),this.app=e,this._wait_queue=[],this._anit_queue=[],this._is_play_frame=!1,this._is_end=!1,this._is_transing=!1,this.lastTagId=null,this.speed={rotate:{maxSlow:5,maxFast:35},translate:{maxSlow:1e-4,maxFast:.01}},this.cachePanosTaskList={}}t&&(i.__proto__=t),i.prototype=Object.create(t&&t.prototype),i.prototype.constructor=i;var s={tours:{configurable:!0},partId:{configurable:!0},frameId:{configurable:!0},playing:{configurable:!0},isEnd:{configurable:!0}};return s.tours.get=function(){return this.app.TourManager.tours},s.partId.get=function(){return this.app.TourManager.partId},s.partId.set=function(t){this.app.TourManager.partId=t},s.frameId.get=function(){return this.app.TourManager.frameId},s.frameId.set=function(t){this.app.TourManager.frameId=t},s.playing.get=function(){return this.app.TourManager.playing},s.playing.set=function(t){this.app.TourManager.playing=t},s.isEnd.get=function(){return this._is_end},i.prototype.initRoleAnimation=function(){this.roleAnimation.load()},i.prototype.play=function(t,e,a){var r=this;if(void 0===a&&(a=!0),this.tours.length){if(this._is_transing)return setTimeout((function(){r.play(t,e,a)}),100);if(null!=t&&null!=e?(this.partId=t,this.frameId=e,this._is_play_frame=!a):null!=t?(this.partId=t,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(){r.play(t,e)}),200));var n=this.tours[this.partId],i=n.list[this.frameId];if(!i)return this.emit("end");i._end&&(this.frameId=0,i=n.list[this.frameId]),this.playing=!0,this.clearCachePanosTaskList();var s=this.app.core.get("Player");i.pausePanoId&&i.pausePanoId!=i.enter.panoId&&s.mode==o&&s.currentPano.id==i.pausePanoId?this.playNextFrame():this.flyToFirst(i,(function(){r.playing&&(r.emit("play",{partId:r.partId,frameId:r.frameId}),r.playNextFrame())})),this.emit("play2",{partId:this.partId,frameId:this.frameId})}},i.prototype.pause=function(t){this.tours.length&&(this._anit_queue.forEach((function(t){return t&&a.cancel(t)})),this._wait_queue.forEach((function(t){return t&&clearTimeout(t)})),this._anit_queue=[],this._wait_queue=[],this.playing=!1,this._is_play_frame=!1,a.cancelById(n.freeze.LookRotationForPlay),a.cancelById(n.freeze.LookTransition),this.pauseForFlyToPano(),t||this.emit("pause",{partId:this.partId,frameId:this.frameId}),this.tours[this.partId].audio&&this.tours[this.partId].audio.stop())},i.prototype.end=function(){var t=this;if(this._anit_queue=[],this._wait_queue=[],this.playing=!1,this.tours[this.partId].audio){var e=this.partId;setTimeout((function(){t.tours[e].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()},i.prototype.selectPart=function(t){var e=this;return new Promise((function(a){if(isNaN(t))return a();var o=e.tours[t];o?e.playing?(e.pause(!0),setTimeout((function(){e.partId=t,e.frameId=0,e._is_end=!1,e.selectFrame(e.frameId).then((function(){return a(o)}))}),500)):(e.partId=t,e.frameId=0,e._is_end=!1,e.selectFrame(e.frameId).then((function(){return a(o)}))):a()}))},i.prototype.getFrame=function(){var t=this.tours[this.partId];if(t)return t.list[this.frameId]},i.prototype.selectFrame=function(t,e){var a=this;if(e||(e=KanKan.Deferred()),isNaN(t))return e.resolve(),e;t=parseInt(t);var r=this.tours[this.partId].list[t];if(!r)return e.resolve(),e;if(this.playing)return this.pause(!0),setTimeout((function(){a.selectFrame(t,e)}),500),e;this._is_end=!1,this._is_transing=!0,this.frameId=t;var n=this.app.core.get("Player");if(n.mode==o&&r.enter.mode==o){var i=new THREE.Vector3(0,0,-1).applyQuaternion(r.enter.qua).add(r.enter.pos),s=n.model.panos.get(r.enter.panoId);n.flyToPano({pano:s,lookAtPoint:i},(function(){return e.resolve(r)}))}else if(n.mode!=r.enter.mode)if(r.enter.mode==o){var p=n.model.panos.get(r.enter.panoId);n.flyToNewMode({pano:p,quaternion:this.parseVector4(r.enter.qua),mode:r.enter.mode,callback:function(){return e.resolve(r)}})}else n.flyToNewMode({position:this.parseVector3(r.enter.pos),target:this.parseVector3(r.enter.target),quaternion:this.parseVector4(r.enter.qua),mode:r.enter.mode,currentScale:r.enter.currentScale,callback:function(){r.enter.hasOwnProperty("floor")&&a.app.Scene.gotoFloor(r.enter.floor),e.resolve(r)}});else{var l=this.parseVector3(r.enter.pos),u=this.parseVector3(r.enter.target),d=r.enter.currentScale;this.playForRotateForDollAndFloor(l,u,d,r.enter.mode,null,(function(){return e.resolve(r)}),1e3),r.enter.hasOwnProperty("floor")&&this.app.Scene.gotoFloor(r.enter.floor),e.resolve(r)}return e.then((function(t){return a._is_transing=!1,r.tagId?(a.app.TagManager.open(r.tagId),a.lastTagId=r.tagId):a.lastTagId&&(a.app.TagManager.close(a.lastTagId),a.lastTagId=null),t})),e},i.prototype.getRotateTime=function(t){return t||(t=5),15/9+t*(this.speed.rotate.maxFast-this.speed.rotate.maxSlow)/9},i.prototype.getFlySpeed=function(t){return t||(t=5),t*(this.speed.translate.maxFast-this.speed.translate.maxSlow)/9-.001},i.prototype.flyToFirst=function(t,e){var a=this,r=this.app.core.get("Player");if(r.mode==o&&t.enter.mode==o){var n=new THREE.Vector3(0,0,-1).applyQuaternion(t.enter.qua).add(t.enter.pos),i=r.model.panos.get(t.enter.panoId);r.flyToPano({pano:i,lookAtPoint:n},e)}else if(t.enter.mode==o){var s=r.model.panos.get(t.enter.panoId);r.flyToNewMode({pano:s,quaternion:this.parseVector4(t.enter.qua),mode:t.enter.mode,callback:e})}else r.flyToNewMode({position:this.parseVector3(t.enter.pos),target:this.parseVector3(t.enter.target),quaternion:this.parseVector4(t.enter.qua),mode:t.enter.mode,currentScale:t.enter.currentScale,callback:function(){t.enter.hasOwnProperty("floor")&&a.app.Scene.gotoFloor(t.enter.floor),e()}})},i.prototype.playForRotateForPano=function(t,e,o){var r=this.app.core.get("Player"),i=r.cameraControls.activeControl.camera.quaternion,s=i.angleTo(t);console.log("停留角度:"+s),a.start(KanKan.Animate.lerp.quaternion(i,t,function(t,e){if(r.cameraControls.activeControl){var a=new THREE.Vector3(0,0,-1).applyQuaternion(t).add(r.position);r.cameraControls.activeControl.lookAt(a)}}.bind(this)),e,(function(){o()}),0,null,null,n.freeze.LookRotationForPlay)},i.prototype.stayForPano=function(t,e){var o=this,r=t.time,i=t.rotateRange*Math.PI/180,s=this.app.core.get("Player");if(0!=i&&0!=r){var p=s.cameraControls.activeControl.camera.quaternion,l=new THREE.Quaternion;l.setFromAxisAngle(new THREE.Vector3(0,1,0),i).multiply(p),a.start(KanKan.Animate.lerp.quaternion(p,l,function(t,e){if(s.cameraControls.activeControl){var a=new THREE.Vector3(0,0,-1).applyQuaternion(t).add(s.position);s.cameraControls.activeControl.lookAt(a)}this.emit("progress",{partId:this.partId,frameId:this.frameId,progress:e})}.bind(this)),r,(function(){t.tagId&&(o.app.TagManager.close(t.tagId),o.lastTagId=null),e()}),0,null,null,n.freeze.LookRotationForPlay)}else this._anit_queue.push(a.start((function(a){1==a&&(t.tagId&&(o.app.TagManager.close(t.tagId),o.lastTagId=null),e()),o.emit("progress",{partId:o.partId,frameId:o.frameId,progress:a})}),r))},i.prototype.playForRotateForDollAndFloor=function(t,e,o,i,s,p,l){var u=this.app.core.get("Player");a.start(KanKan.Animate.lerp.vector(u.cameraControls.activeControl.target,new THREE.Vector3(e.x,e.y,e.z),s),l,null,0,KanKan.Animate.easing[n.flydown.rotationEasing],null,n.freeze.LookRotationForPlay),a.start(KanKan.Animate.lerp.vector(u.cameraControls.activeControl.camera.position,t),l,p,0,KanKan.Animate.easing[n.flydown.rotationEasing],null,n.freeze.LookRotationForPlay),i==r&&u.cameraControls.activeControl.absoluteScale!=o&&a.start(KanKan.Animate.lerp.property(u.cameraControls.activeControl,"absoluteScale",o,function(t){u.cameraControls.activeControl&&(u.cameraControls.activeControl.currentScale=t,"PerspectiveCamera"!=u.cameraControls.activeControl.camera.type&&u.cameraControls.activeControl.updateZoom())}.bind(this)),l,null,0,KanKan.Animate.easing[n.flydown.rotationEasing],null,n.freeze.LookRotationForPlay)},i.prototype.playForFlyToPano=function(t,e,a){var r=this.app.core.get("Player"),n=e.transitType;if(r.mode==o&&t.enter.mode==o){var i=r.model.panos.get(t.enter.panoId);if("fast"==n)r.fastToPano({pano:i,quaternion:this.parseVector4(t.enter.qua),callback:a});else if(e.enter.panoId==t.enter.panoId){var s=this.parseVector4(t.enter.qua),p=this.parseVector4(e.enter.qua).angleTo(s)/Math.PI*180/this.getRotateTime(e.speed)*1e3;this.playForRotateForPano(s,p,a)}else{var l=this.getFlySpeed(e.speed),u=e.enter.panoId,d=null!=e.pausePanoId;if(d&&(u=e.pausePanoId,delete e.pausePanoId),this.cachePanosTaskList[u])delete this.cachePanosTaskList[u];else{var h=this.createPanoList(u,t)[u];r.setTourPanoTask({panoList:h,flySpeed:l,callback:a},d),this.outputPanosId("当前",u)}this.createNextPanoList(t),this.addToPanosTaskList(t.enter.panoId,l,a),this.outputPanosId("下一段",t.enter.panoId)}}},i.prototype.pauseForFlyToPano=function(){var t=this.app.core.get("Player");if(t.panosTaskList&&t.panosTaskList.length>0){var e=t.panosTaskList[0],a=this.tours[this.partId].list[this.frameId],r=this.getNextFrame();r&&a.enter.mode==o&&r.enter.mode==o&&a.enter.panoId!=e.pano.id&&r.enter.panoId!=e.pano.id&&(a.pausePanoId=e.pano.id),t.stopTourPanoTask()}},i.prototype.playForFlyToNewMode=function(t,e){var a=this.app.core.get("Player");if(a.mode==t.enter.mode&&a.mode==o);else if(a.mode!=t.enter.mode)if(t.enter.mode==o){var r=a.model.panos.get(t.enter.panoId);a.flyToNewMode({pano:r,quaternion:t.enter.qua,mode:t.enter.mode,callback:e})}else a.flyToNewMode({position:t.enter.pos,target:t.enter.target,quaternion:t.enter.qua,mode:t.enter.mode,currentScale:t.enter.currentScale,floor:t.enter.floor,callback:function(){e()}})},i.prototype.createPanoList=function(t,a){var o=this.app.core.get("Player"),r=e.searchRoad(o.model.panos.index,t,a.enter.panoId);0==r.length&&(r[0]=a.enter.panoId);for(var n=[],i=0;i<r.length;++i){var s=void 0;if(i==r.length-1)s=new THREE.Vector3(0,0,-1).applyQuaternion(a.enter.qua).add(a.enter.pos);else s=o.model.panos.index[r[i+1]].position;n.push({pano:o.model.panos.index[r[i]],lookAtPoint:s})}var p={};return p[t]=n,p},i.prototype.getNextFrame=function(){return this.tours[this.partId].list[this.frameId+1]},i.prototype.createNextPanoList=function(t){var e=this.tours[this.partId].list[this.frameId+2];!e||e.enter.mode!=o||e.tagId||0!=t.time||t.enter.panoId==e.enter.panoId||(this.cachePanosTaskList=this.createPanoList(t.enter.panoId,e))},i.prototype.clearCachePanosTaskList=function(){this.cachePanosTaskList={}},i.prototype.addToPanosTaskList=function(t,e,a){if(this.cachePanosTaskList[t]){var o=this.app.core.get("Player"),r=this.cachePanosTaskList[t];o.addTourPanoTask({panoList:r,flySpeed:e,callback:a})}},i.prototype.outputPanosId=function(t,e){for(var a=this.app.core.get("Player"),o="",r=0;r<a.panosTaskList.length;++r)o+=a.panosTaskList[r].pano.id+",";console.log(t+"---\x3e"+e+","+o)},i.prototype.playFrame=function(t,e){var r=this;if(e){if(this.app.core.get("Player"),t.enter.mode==o){if(t.tagId&&(this.app.TagManager.open(t.tagId),this.lastTagId=t.tagId),e.enter.mode==o)t.pausePanoId&&t.pausePanoId!=t.enter.panoId?this.playForFlyToPano(e,t,(function(){r.playNextFrame(!0)})):this.stayForPano(t,(function(){return r.playForFlyToPano(e,t,(function(){r.playNextFrame(!0)}))}));else if(e.enter.mode!=o)return this._wait_queue.push(setTimeout((function(){return r.playForFlyToNewMode(e,(function(){return r.playNextFrame(!0)}))}),t.time)),void this._anit_queue.push(a.start((function(t){r.emit("progress",{partId:r.partId,frameId:r.frameId,progress:t})}),t.time))}else if(t.enter.mode!=o){if(this.lastTagId&&(this.app.TagManager.close(this.lastTagId),this.lastTagId=null),t.enter.mode!=e.enter.mode)return this._wait_queue.push(setTimeout((function(){return r.playForFlyToNewMode(e,(function(){return r.playNextFrame(!0)}))}),t.time)),void this._anit_queue.push(a.start((function(t){r.emit("progress",{partId:r.partId,frameId:r.frameId,progress:t})}),t.time));this.playForRotateForDollAndFloor(new THREE.Vector3(e.enter.pos.x,e.enter.pos.y,e.enter.pos.z),new THREE.Vector3(e.enter.target.x,e.enter.target.y,e.enter.target.z),e.enter.currentScale,t.enter.mode,(function(t,e){return r.emit("progress",{partId:r.partId,frameId:r.frameId,progress:e})}),(function(){e.enter.hasOwnProperty("floor")&&r.app.Scene.gotoFloor(e.enter.floor),r.playNextFrame(!0)}),t.time)}}else this.playNextFrame(!0)},i.prototype.playNextFrame=function(t){if(this.playing){if(t){if(this._is_play_frame)return this.end();this.frameId++}var e=this.tours[this.partId].list[this.frameId];if(e)t||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 a=this.tours[this.partId+1];if(!(a&&a.list&&a.list.length))return this.end();this.partId++,this.frameId=0,e=this.tours[this.partId].list[this.frameId],this.tours[this.partId].audio&&this.tours[this.partId].audio.play()}var o=this.getNextFrame();if(!o){var r=this.partId+1;if(!this.tours[r]||!this.tours[r].list||!this.tours[r].list.length)return this.end();if(!(o=this.tours[r].list[0]))return this.end()}this.playFrame(e,o)}},i.prototype.parseVector4=function(t){return new THREE.Quaternion(t.x,t.y,t.z,t.w)},i.prototype.parseVector3=function(t){return new THREE.Vector3(t.x,t.y,t.z)},Object.defineProperties(i.prototype,s),i}(KanKan.MITT.Emiter);return function(t,e){void 0===e&&(e={});var a=KanKan.Deferred(),o=function(){var o=new i(t,e);o.$name="TourPlayer",o.$load=function(){t.TourManager.install("player",o)},a.resolve(o)};return t.Scene.loaded?o():t.Scene.on("loaded",o),a}}();
|