12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114 |
- import * as THREE from "../../../../libs/three.js/build/three.module.js";
- import {TextSprite} from "../../objects/TextSprite.js";
- import ModelTextureMaterial from "../../materials/ModelTextureMaterial.js";
- import Common from "../../utils/Common.js";
- import math from "../../utils/math.js";
- import cameraLight from "../../utils/cameraLight.js";
- import {MeshDraw } from '../../utils/DrawUtil.js'
- import Panorama from "./Panorama.js";
- import browser from '../../utils/browser.js'
-
- import {transitions, easing, lerp} from "../../utils/transitions.js";
- import DepthImageSampler from './DepthImageSampler.js'
- let {PanoSizeClass,Vectors,GLCubeFaces, PanoramaEvents} = Potree.defines
-
-
- var rot90 = new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0,0,1), Math.PI/2 ); //使用的是刚好适合全景图的,给cube贴图需要转90°
-
- let raycaster = new THREE.Raycaster();
- //let currentlyHovered = null;
- let texLoader = new THREE.TextureLoader()
-
- let tileArr = []
- let previousView = {
- controls: null,
- position: null,
- target: null,
- };
- const HighMapCubeWidth = 1
-
-
- const directionFactor = 400 //原先10,几乎只往距离近的走了;设置太大容易略过近处漫游点走向下坡,因为鼠标一般在地面,下坡的漫游点更有利
-
-
-
-
-
-
-
- export class Images360 extends THREE.EventDispatcher{
- constructor(viewer ){
- super();
- this.viewer = viewer;
-
- this.panos = [];
- this.neighbourMap = {}
-
-
- this.node = new THREE.Object3D();
- this.node.name = 'ImagesNode'
-
- this.cubePanos = [];
-
-
- {
- this.cube = new THREE.Mesh(new THREE.BoxBufferGeometry(1,1,1,1),new ModelTextureMaterial());
- Potree.Utils.updateVisible(this.cube,'showSkybox', false )
-
- this.cube.layers.set(Potree.config.renderLayers.skybox)
- this.cube.name = 'skyboxCube'
- viewer.scene.scene.add(this.cube)
- }
- if(Potree.settings.testCube){
- this.cubeTest = this.cube.clone()
- this.cubeTest.material = new THREE.MeshBasicMaterial({
- wireframe:true,
- color:'#FF3377',
- transparent:true,
- opacity:0.7,
- depthWrite:false,
- depthTest:false,
- })
- viewer.scene.scene.add(this.cubeTest)
- this.cubeTest.visible = true
- }
-
-
- this.flying_ = false
-
-
- this.currentPano = null;
- this.mouseLastMoveTime = Date.now()
- this.scrollZoomSpeed = 0.06
- this.zoomLevel = 1
-
-
-
-
-
-
- this.depthSampler = new DepthImageSampler();
-
-
-
-
-
-
- viewer.fpControls.addEventListener('dollyStopCauseUnable',(e)=>{
- if(/* e.hoverViewport != viewer.mainViewport || */!Potree.settings.zoom.enabled)return
-
- if(e.scale != void 0){//触屏
- this.zoomBy(e.scale, e.pointer)
- }else{//滚轮
- let zoom;
- if(e.delta > 0){
- zoom = 1 + this.scrollZoomSpeed
- }else{
- zoom = 1 - this.scrollZoomSpeed
- }
- e.delta != 0 && this.zoomBy(zoom)
- }
- })
-
-
- let click = (e) => {//不用"mouseup" 是因为 mouseup有drag object时也会触发
- if(e.clickElement ||
- Potree.settings.unableNavigate || this.flying || !e.isTouch && e.button != THREE.MOUSE.LEFT || e.drag && e.drag.object //拖拽结束时不算
- || Potree.settings.editType == 'pano' && viewer.modules.PanoEditor.activeViewName != 'mainView'
- || Potree.settings.editType == 'merge' && !e.intersectPoint || viewer.inputHandler.hoveredElements[0] && viewer.inputHandler.hoveredElements[0].isModel && e.intersectPoint.distance > viewer.inputHandler.hoveredElements[0].distance
- ) return
-
- if(e.hoverViewport != viewer.mainViewport){ //如数据集校准其他viewport
- return
- }
-
- if(!Potree.settings.dblToFocusPoint/* && this.currentPano */){//双击不会focus点云 或者 已经focusPano了
- this.flyToPanoClosestToMouse()
- }
-
- }
- viewer.addEventListener('global_click' , click)
-
- viewer.addEventListener("global_mousemove", (e) => {
- if(!Potree.settings.unableNavigate && Potree.settings.ifShowMarker && e.hoverViewport == viewer.mainViewport){//如果不显示marker,就在点击时再更新
- this.updateClosestPano(e.intersect)
- }
- });
-
-
- this.addEventListener('markerHover',(e)=>{
- this.updateClosestPano(e.pano, e.hovered)
- })
-
- if(!Potree.settings.isOfficial){
- this.domRoot = viewer.renderer.domElement.parentElement;
- let elUnfocus = $("<input type='button' value='unfocus'></input>");
- elUnfocus.css({
- position : "absolute",
- right : '25%',
- bottom: '20px',
- zIndex: "10000",
- fontSize:'1em', color:"black",
- display:'none',
- background:'rgba(255,255,255,0.8)',
- })
- elUnfocus.on("click", () => this.unfocus());
- this.elUnfocus = elUnfocus;
- this.domRoot.appendChild(elUnfocus[0]);
-
- if(Potree.settings.editType != 'merge'){
-
- let elHide = $("<input type='button' value='隐藏点云'></input>")
- elHide.css({
- position : "absolute",
- right : '40%',
- bottom: '20px',
- zIndex: "10000",
- fontSize:'1em' ,color:"black",
- width : '100px',
- background:'rgba(255,255,255,0.8)',
- })
- this.domRoot.appendChild(elHide[0]);
- elHide.on("click", (e) => {
- let visi = Potree.Utils.getObjVisiByReason(viewer.scene.pointclouds[0], 'force')
- viewer.scene.pointclouds.forEach(e=>{
- Potree.Utils.updateVisible(e, 'force', !visi)
- })
- elHide.val(!visi ? "隐藏点云" : "显示点云")
- });
-
- }
-
- let elDisplayModel = $("<input type='button' value='>>全景'></input>")
- elDisplayModel.css({
- position : "absolute",
- right : '65%',
- bottom: '20px',
- zIndex: "10000",
- fontSize:'1em',color:"black",
- width : '100px',
- background:'rgba(255,255,255,0.8)',
- })
-
- this.domRoot.appendChild(elDisplayModel[0]);
- elDisplayModel.on("click", (e) => {
- if(Potree.settings.displayMode == 'showPointCloud' && this.panos.length == 0)return
- Potree.settings.displayMode = Potree.settings.displayMode == 'showPointCloud' ? 'showPanos' : 'showPointCloud'
- });
-
- this.elDisplayModel = elDisplayModel
- }
-
-
-
- {//切换模式
- let displayMode = '';
- this.latestRequestMode = '';//因为可能延迟,所以记录下每次的请求模式,延迟后判断这个
- Object.defineProperty(Potree.settings , "displayMode",{
- get: function() {
- return displayMode
- },
- set: (mode)=> {
- this.latestRequestMode = mode
- console.warn('Request setMode: ' + mode)
- let config2
- let config = Potree.config.displayMode[mode]
- if(this.isAtPano() && !this.latestToPano){
- config2 = config.atPano
- }else{
- config2 = config.transition
- }
- let changeTileDownload = ()=>{
- if(config2.showSkybox || config2.showPoint && config2.pointUsePanoTex){
- //this.tileDownloader.start()
- this.currentPano && this.currentPano.enter()
- }else{
- //this.tileDownloader.stop()
- this.currentPano && this.currentPano.exit()
- }
- }
-
- if(mode != displayMode){
-
-
- let camera = viewer.scene.getActiveCamera()
- if(mode == 'showPanos' && viewer.mainViewport.view.isFlying()){//飞完才能切换全景
- let f = ()=>{
- if(this.latestRequestMode == mode){//如果ui还是停在这个模式的话
- Potree.settings.displayMode = mode
- }
- viewer.mainViewport.view.removeEventListener('flyingDone', f)
- }
- viewer.mainViewport.view.addEventListener('flyingDone', f) //once
- return
- }
-
- if(this.isAtPano() && !this.latestToPano){
- config2 = config.atPano
- }else{
- config2 = config.transition
- if(mode == 'showPanos'){//自动飞入一个pano
- //要改成飞进最近的。。。
- if(this.panos.length == 0)return
- //this.modeChanging = true //主要是因为到全景图不会立刻成功
- let wait = (e)=>{
- this.removeEventListener('flyToPanoDone',wait)
- setTimeout(()=>{
- if(this.latestRequestMode == mode ){
- Potree.settings.displayMode = mode
- }
- },e.makeIt ? 1 : 50)
- }
- this.addEventListener('flyToPanoDone',wait) //等待飞行完毕。flyToPano的callback可能不执行所以换这个。但也可能被cancel
- this.flyToPano({
- pano: this.findNearestPano(),
-
- })
-
- return;
- }else{
-
- }
- }
-
-
-
- changeTileDownload()
-
- if(config2.showSkybox || config2.pointUsePanoTex){
- let wait = (e)=> {
- viewer.ifAllLoaded()
- //if(e.pano && e.pano != this.currentPano)return//loadedDepthImg
- setTimeout( ()=>{
- if(this.latestRequestMode == mode ){
- Potree.settings.displayMode = mode
- }
- },1)
- }
- /*
- //this.updateDepthTex()
- if(this.checkAndWaitForPanoLoad(this.currentPano, this.basePanoSize, wait)){
- return
- } */
- if(!this.currentPano.skyboxTex){
- this.currentPano.waitForLoad()
- this.currentPano.addEventListener('loadedTex', wait, {once:true})
- return this.currentPano.loadTex()
- }
- }
-
-
-
- viewer.scene.pointclouds.forEach(e=>{
- Potree.Utils.updateVisible(e, 'displayMode', config2.showPoint, 2 )
- })
-
- if(config2.pointUsePanoTex){
- viewer.scene.pointclouds.forEach(e=>{
- e.material.setProjectedPanos(this.currentPano,this.currentPano, 1)
- })
- }else{
- viewer.scene.pointclouds.forEach(e=>{
- e.material.stopProjectedPanos()
- })
- }
-
- Potree.Utils.updateVisible(this.cube,'showSkybox',config2.showSkybox )// this.cube.visible = config2.showSkybox
-
- //this.cube.visible = config.atPano.showSkybox
- if(this.cube.visible){
- //this.cube.material.setProjectedPanos(this.currentPano, this.currentPano, 1)
-
- this.setProjectedPanos({
- progress:1,
- ifSkybox: true,
- ifPointcloud : false,
- easeInOutRatio : 0,
- pano0:this.currentPano,
- pano1:this.currentPano
- })
-
- }else{
- this.smoothZoomTo(1)
-
-
- }
-
-
-
- /* viewer.dispatchEvent({
- type: "enableChangePos",
- canLeavePano : config.canLeavePano ,
- viewport:
- }) */
-
- //viewer.mainViewport.unableChangePos = !config.canLeavePano
-
-
- displayMode = mode
-
-
-
-
- if(mode == 'showPanos'){
- camera.far = viewer.farWhenShowPano //修改far
- Potree.settings.pointDensity = 'panorama'
- if(Potree.config.displayMode.showPanos.transition.pointUsePanoTex){
- viewer.scene.pointclouds.forEach(e=>{
- e.material.pointSizeType = 'FIXED'
- })
- }
- this.updateCube(this.currentPano)
-
- }else{
- if(camera.limitFar) camera.far = Potree.settings.cameraFar;//修改far
- Potree.settings.pointDensity = Potree.settings.UserPointDensity
- //Potree.sdk && Potree.sdk.scene.changePointOpacity()
- if(Potree.config.displayMode.showPanos.transition.pointUsePanoTex){
- viewer.scene.pointclouds.forEach(e=>{
- e.material.pointSizeType = Potree.config.material.pointSizeType
- })
- }
- }
- camera.updateProjectionMatrix()
-
-
-
-
- if(this.elDisplayModel){
- this.elDisplayModel.val( mode == 'showPointCloud' ? ">>全景" : '>>点云')
- }
-
- /* this.panos.forEach(e=>{
- Potree.Utils.updateVisible(e, 'modeIsShowPanos', mode == 'showPanos', 1, mode == 'showPanos' ? 'add':'cancel') //
- }) */
-
-
- this.dispatchEvent({type:'endChangeMode',mode})
- console.log('setModeSuccess: ' + mode)
- }else{
- changeTileDownload()
- //this.dispatchEvent({type:'endChangeMode',mode})
- }
-
-
- }
- })
- Potree.settings.displayMode = 'showPointCloud'
- }// 切换模式 end
-
- {//
- let currentPano = null;
- Object.defineProperty(this , "currentPano",{
- get: function() {
- return currentPano
- },
- set: function(e) {
- if(e != currentPano){
- //console.log('set currentPano ', e.id)
- currentPano && currentPano.exit()
- e && e.enter()
- currentPano = e
- }
-
- }
- })
- }
-
- {//是否显示marker
- let ifShowMarker = true;
- Object.defineProperty(Potree.settings, "ifShowMarker",{
- get: function() {
- return ifShowMarker
- },
- set: (show)=>{
- show = !!show
- if(show != ifShowMarker){
- this.panos.forEach(pano=>{
- Potree.Utils.updateVisible(pano, 'ifShowMarker', show, 1 )
- })
- //this.emit('markersDisplayChange', show)
- ifShowMarker = show
- viewer.dispatchEvent('showMarkerChanged')
- viewer.dispatchEvent('content_changed')
- }
-
- }
- })
- }
-
-
-
-
- viewer.addEventListener("update", () => {
- this.update(viewer);
- });
- //viewer.inputHandler.addInputListener(this);
-
-
-
- var keys = {
- FORWARD: ['W'.charCodeAt(0), 38],
- BACKWARD: ['S'.charCodeAt(0), 40],
- LEFT: ['A'.charCodeAt(0), 37],
- RIGHT: ['D'.charCodeAt(0), 39],
- }
- viewer.inputHandler.addEventListener('keydown',(e)=>{
- if(Potree.settings.displayMode == 'showPanos'){
- for(let i in keys){
- if(keys[i].some(a => a == e.keyCode)){
- switch(i){
- case 'FORWARD':
- this.flyLocalDirection(Vectors.FORWARD.clone());
- break;
- case 'BACKWARD':
- this.flyLocalDirection(Vectors.BACK.clone());
- break;
- case 'LEFT':
- this.flyLocalDirection(Vectors.LEFT.clone());
- break;
- case 'RIGHT':
- this.flyLocalDirection(Vectors.RIGHT.clone());
- break;
-
- }
-
- break;
- }
- }
- }
- })
-
- };
-
-
- updateDepthTex(pano){
- if(this.currentPano != pano || !pano.depthTex)return
- //this.depthSampler.changeImg(pano.depthTex.image); //pick sampler要飞到了才能切换图,而skybox贴图是随着全景图切换而切换的
- this.cube.material.updateDepthTex(pano) //确保一下
-
-
- }
-
- findNearestPano(pos){
- pos = pos ? new THREE.Vector3().copy(pos) : this.position
- let result = Common.sortByScore(this.panos,[Images360.filters.isEnabled()],[e=>-e.position.distanceTo(pos)])
- let pano = result[0] && result[0].item
- return pano
-
- }
-
- /* set flying(v){//正在飞向pano
- this.flying_ = !!v
- //console.log('this.flying_ ', !!v )
- //this.emit('flying', this.flying_)
- let config = Potree.config.displayMode[Potree.settings.displayMode]
- viewer.mainViewport.unableChangePos = !config.canLeavePano || !!v
-
- }
- get flying(){
- return this.flying_
- } */
-
-
-
-
-
-
- flyLocalDirection(dir) {
- var direction = this.getDirection(dir),
- option1 = 1 === dir.y ? .4 : .75,
- option2 = 1 === Math.abs(dir.x);
- return this.flyDirection(direction, option1, option2, true)
- }
- getDirection(e) {
- if(!e){
- return viewer.scene.view.direction
- }else{
- return e = e ? e : (new THREE.Vector3).copy(Vectors.FORWARD),
- e.applyQuaternion(viewer.mainViewport.camera.quaternion)
- }
-
- }
- get position(){
- return this.viewer.scene.view.position.clone()
- }
-
-
-
-
- isAtPano(precision){//是否在某个漫游点上
- if(precision){
- return this.currentPano && math.closeTo(viewer.scene.view.position, this.currentPano.position, precision)
- }
- return this.currentPano && viewer.scene.view.position.equals(this.currentPano.position)
- }
-
-
-
-
- updateProjectedPanos(){//更新材质贴图
- //console.warn('updateProjectedPanos')
- this.projectedPano0 && this.projectedPano1 && this.setProjectedPanos({pano0:this.projectedPano0, pano1:this.projectedPano1})
- }
-
- setProjectedPanos(o={}){//设置cube和点云的材质贴图
- this.cube.material.setProjectedPanos(o.pano0, o.pano1, o.progress)
- if(o.ifPointcloud){
- viewer.scene.pointclouds.forEach(e=>{
- e.material.setProjectedPanos(o.pano0, o.pano1, o.progress, o.easeInOutRatio)
- })
- }
-
- //console.warn('setProjectedPanos ', o.pano0.id , o.pano1.id)
- this.projectedPano0 = o.pano0
- this.projectedPano1 = o.pano1
-
- }
- cancelFlyToPano(toPano){//取消当前已有的飞行准备,前提是相机还未移动
- if(viewer.mainViewport.view.isFlying() || toPano && this.latestToPano != toPano)return
- //Potree.Log('cancelFlyToPano', this.latestToPano && this.latestToPano.pano.id)
- this.nextPano = null
- this.latestToPano = null
- }
- flyToPano(toPano) { //飞向漫游点
- if(!toPano)return
- if(toPano instanceof Panorama){
- toPano = {pano: toPano}
- }
-
-
- let done = (makeIt, disturb)=>{
- //console.log('flyToPano done ', toPano.pano.id, makeIt, disturb )
- if(makeIt || disturb) { // disturb已经开始飞行但中途取消
- toPano.callback && toPano.callback(makeIt)
- //this.flying = false
- this.cancelFlyToPano(toPano)
- this.updateClosestPano(this.closestPano,false) //飞行结束后取消点击漫游点时得到的closestPano
- }else{
- }
-
- this.dispatchEvent({type:'flyToPanoDone', makeIt})
-
- toPano.deferred && toPano.deferred.resolve(makeIt) //测量线截图时发现,resolve需要写在flying=false 后才行。
- }
-
- if(!toPano.pano.enabled)return done(false,true);
- //Potree.Log('hope flyToPano: '+toPano.pano.id )
-
-
- if(this.latestToPano && this.latestToPano != toPano && this.latestToPano.pano != this.currentPano){//还在飞//如果旧的toPano只是旋转镜头,就直接取消旧的
- return done(false)
- }
- //Potree.Log('flyToPano: '+toPano.pano.id, this.latestToPano && this.latestToPano.pano.id )
- if(this.currentPano == toPano.pano && this.isAtPano() && !toPano.target && !toPano.quaternion ){
- this.dispatchEvent({type:'flyToPano', toPano})
- return done(true);
- }
-
- let target = toPano.target
- let config = Potree.config.displayMode[Potree.settings.displayMode]
- let pointcloudVisi = config.atPano.showPoint //viewer.scene.pointclouds[0].visible
-
-
- let pano = toPano.pano
- let dis = pano.position.distanceTo(this.position)
-
- this.nextPano = pano
- this.latestToPano = toPano
- //this.flying = true //防止新的请求
- //Potree.Log('flyToPano:'+pano.id + ' , duration:'+toPano.duration, null, 12)
-
-
- {//不飞的话是否不要执行这段?
-
- let wait = ( )=> {
- viewer.ifAllLoaded()
- if( this.latestToPano && pano != this.latestToPano.pano)return//loadedDepthImg
- if(this.latestToPano != toPano)return /* Potree.Log('已经取消') *///如果取消了
- setTimeout(()=>{
- if(this.latestToPano != toPano)return
- this.flyToPano(toPano)
- },1)
- }
- if(!pano.depthTex && pano.pointcloud.hasDepthTex){ //点云模式也要加载depthTex,因获取neighbour需要用到
- //console.log('等待加载depthtex')
- pano.addEventListener('loadedDepthImg', wait, {once:true})
- pano.waitForLoad()
- return pano.loadDepthImg()
- }
-
- if(config.atPano.showSkybox || config.atPano.pointUsePanoTex){
- let a = this.updateCube(this.currentPano, toPano.pano)
- if(a == 'useBound'){
- toPano.useBound = true
- }
-
- if(!pano.skyboxTex){
- pano.waitForLoad()
- pano.addEventListener('loadedTex', wait, {once:true})
- return pano.loadTex()
- }
- /* if(this.checkAndWaitForPanoLoad(pano, toPano.basePanoSize || this.basePanoSize, wait )){
- return
- } */
- }
- }
- Potree.Utils.updateVisible(this.cube,'showSkybox', config.atPano.showSkybox ) // this.cube.visible = config.atPano.showSkybox
- //console.log('开始飞1')
-
- if(config.transition.showPoint){
- viewer.scene.pointclouds.forEach(e=>{
- Potree.Utils.updateVisible(e, 'displayMode', true)
- })
- }
-
-
- if(config.transition.showSkybox || config.transition.pointUsePanoTex){
- this.setProjectedPanos({
- progress:0,
- ifSkybox: this.cube.visible,
- ifPointcloud : config.transition.pointUsePanoTex,
- easeInOutRatio : pointcloudVisi ? 0.3 : 0,
- pano0:this.currentPano,
- pano1:pano
- })
- }
-
- const endPosition = pano.position.clone()
- let T = Potree.config.transitionsTime
- let maxTime = this.isAtPano() ? T.panoToPanoMax : T.flyIn
- let duration = toPano.duration == void 0 ? (T.flyMinTime+Math.min(T.flytimeDistanceMultiplier * dis, maxTime)) : toPano.duration
- if(toPano.useBound){
- duration = Math.min(1500, duration)
- toPano.easeName = 'easeInOutQuad'
- }else{
- if(endPosition.equals(this.position))toPano.easeName = 'easeOutSine'
- }
-
- {
- toPano.easeName = toPano.easeName || 'linearTween'
- toPano.duration = duration
- this.beforeFlyToPano(toPano)
- }
-
-
- let onUpdate = (progress)=>{
-
- this.cube.material.uniforms.progress.value = progress
-
- viewer.scene.pointclouds.forEach(e=>{
- e.material.uniforms.progress.value = progress
- })
-
- }
-
-
- let fly = ()=>{
- let startProgress = toPano.progress = toPano.progress || 0
- let loadNextProgress = THREE.MathUtils.clamp(1 - 2.5 / dis, 0.3, 0.8)
- //console.log(loadNextProgress, (1-loadNextProgress) * dis )
- this.dispatchEvent({type:'flyToPano', toPano})
-
-
- viewer.scene.view.setView({position:endPosition, target, quaternion:toPano.quaternion , duration:toPano.duration,
- onUpdate:(progress_, delta)=>{
-
- let progress = startProgress + progress_ * (1 - startProgress)
-
-
- let currentSpeed
- if (progress_ != 1 && progress_ != 0) { // 1的时候不准,往往偏小, 0的时候速度为0,也不记录
- currentSpeed = ((progress - toPano.progress) * dis) / delta //记录下当前速度,当变为匀速时可以过渡到flySpeed
-
- } else {
- currentSpeed = toPano.currentSpeed || 0
- }
- toPano.currentSpeed = currentSpeed
- toPano.progress = progress
-
- //console.log('progress_', progress_, 'delta',delta , 'progress', progress/*, 'currentSpeed', currentSpeed, */ )
-
- if (progress > loadNextProgress && toPano.easeName == 'linearTween' && currentSpeed){// 减速. 如果仅旋转就不停止
- //console.log('减速', currentSpeed)
- toPano.easeName = 'easeOutSine'
- let restDis = (1 - progress) * dis
- toPano.duration = (Math.PI / 2 * restDis) / currentSpeed // 这样能保证初始速度为currentSpeed
- viewer.scene.view.cancelFlying('all',false) //为了防止执行cancelFun先主动cancel
- toPano.flyCount = 2
-
- fly(toPano)
- }
- onUpdate(progress)
- },
-
- callback:()=>{
-
- if(!config.atPano.pointUsePanoTex){
- viewer.scene.pointclouds.forEach(e=>{
- e.material.stopProjectedPanos()
- })
- }
-
- this.currentPano = pano;
-
- this.nextPano = null;
- if(Potree.settings.displayMode == 'showPanos'){
- viewer.scene.pointclouds.forEach(e=>{
- Potree.Utils.updateVisible(e, 'displayMode',pointcloudVisi)
- })
- }
- done(true);
-
- this.updateDepthTex(this.currentPano)
-
-
-
- },
- cancelFun:()=>{ done(false, true) },
- Easing:toPano.easeName,
- ignoreFirstFrame : toPano.flyCount != 2 //变换transition时不停一帧
- })
-
-
- }
- if(Potree.settings.displayMode == 'showPanos'){
- setTimeout(fly, 40); //更新geo后缓冲
- }else{
- fly()
- }
-
- //console.log('flyToPano:', toPano.pano.id)
- }
-
- beforeFlyToPano(toPano){
- if(this.currentPano != toPano.pano) {
- this.smoothZoomTo(toPano.zoomLevel || 1, toPano.duration / 2);
- }
- }
-
- isNeighbour(pano0, pano1, dontCompute, onlyUseTex, computeDirFirst){//是否之间没有遮挡(在加载visibles之前,自己算) 最好pano0是currentPano
-
- if(!pano0 || !pano1 )return
-
- let margin = 0.1;
-
- let map0 = this.neighbourMap[pano0.id]; //主
- let map1 = this.neighbourMap[pano1.id]; //副
-
- //三个方向 : position0到position1, position0到floorPosition1, position1到floorPosition0。 只要有一个满足ifNeighbour就为true。 不过为了不使sampler总换图,先只考虑从主pano到副pano的方向
- //0能看到1不代表1能看到0; 但只要有一方能完全看到另一方,无论是position还是floorPosition都算是neighbor
- //也正因此,全部计算完两两之间的neighbour后,neighbourMap也看起来有缺的样子,必须得通过isNeighbour函数来判断是否是邻居
-
- let ifNeighbour
- if(map0[pano1.id] != void 0){
- ifNeighbour = map0[pano1.id]
- }
- if(!ifNeighbour && map1[pano0.id] != void 0){
- ifNeighbour = map1[pano0.id]
- }
-
-
- if(dontCompute) return ifNeighbour
-
- let getNeighbour = (mainPano, subPano, jumpStep1, simpleJudge)=>{
- //暂时只判断到pano,不判断到marker的方向
-
- let dirPoints = []
- if(!jumpStep1){//跳过此步骤,因为之前算过不成功(虽然用另一个漫游点算的可能拍摄时间不同所以有概率不一样,如人走动)
- dirPoints.push([subPano.position, mainPano.position])
- }
- if(!simpleJudge){
- dirPoints.push([subPano.floorPosition.clone().add(new THREE.Vector3(0,0,0.1)), mainPano.position])
- }
- for(let i=0; i<dirPoints.length; i++){
- let dir = new THREE.Vector3().subVectors(dirPoints[i][0], dirPoints[i][1]).normalize();
- let intersectPoint = viewer.images360.depthSampler.sample({dir}, mainPano, true)
- if(!intersectPoint || intersectPoint.distance+margin > pano0.position.distanceTo(pano1.position)){
- return true
- }
- }
- }
-
- if( map0[pano1.id] == void 0 && !ifNeighbour ) {//主方向为空且不为邻居
- let simpleJudge = pano0.position.distanceToSquared(pano1.position) > 300 //在远处去掉对floorPosition的判断
- if(pano0.depthTex || pano1.depthTex){
-
- if(map0[pano1.id] == void 0 && pano0.depthTex){
- let is = getNeighbour(pano0, pano1, null, simpleJudge)
- if(is){
- ifNeighbour = true
- }else if(simpleJudge){
- ifNeighbour = false
- }
- map0[pano1.id] = !!is
- }
-
- if( ifNeighbour == void 0 && /* map1[pano0.id] == void 0 && */ pano1.depthTex){ //若正向为false,反向暂且不算,等到pano0为主时再算
- let is = getNeighbour(pano1, pano0, !ifNeighbour, simpleJudge)
- if(is){
- ifNeighbour = true
- }else if(simpleJudge){
- ifNeighbour = false
- }
- map1[pano0.id] = !!is
- }
- ifNeighbour = !!ifNeighbour
-
- //console.log('isNeighbour', pano0, pano1, ifNeighbour)
- /* if(ifNeighbour){ //需要标记成全部true吗,不标记也能get到,但标记了更直观,不标记保留信息更多
- map0[pano1.id] = map1[pano0.id] = true
- } */
-
- }else if(!onlyUseTex){//使用点云判断(有深度贴图时不会执行到这)
-
- let inDirection = ()=>{
- let dir = new THREE.Vector3().subVectors(pano1.position,pano0.position).normalize()
- let dis = pano1.position.distanceTo(pano0.position)
- let hfov = cameraLight.getHFOVForCamera(viewer.mainViewport.camera , true );
- let max = Math.cos(THREE.Math.degToRad(10))
- let min = Math.cos(THREE.Math.degToRad(80))
- if(this.getDirection().dot(dir) > THREE.Math.clamp(Math.cos(hfov/2 ) * dis / 10, min, max )){//距离越远要求和视线角度越接近
- return true
- }
- }
- if(computeDirFirst){//先计算方向,防止重复计算ifBlockedByIntersect
- if(inDirection()){
- ifNeighbour = !viewer.inputHandler.ifBlockedByIntersect({pos3d:pano1.position, margin, cameraPos:pano0.position})
- }
- }else{
- ifNeighbour = !viewer.inputHandler.ifBlockedByIntersect({pos3d:pano1.position, margin, cameraPos:pano0.position})
- if(ifNeighbour && !inDirection()){
- ifNeighbour = undefined //不确定
- }
- }
-
- //}
- map0[pano1.id] = map1[pano0.id] = ifNeighbour ? 'byCloud' : ifNeighbour//写简单点
-
- }
-
-
- }
-
- if(ifNeighbour){
- pano0.neighbours.includes(pano1) || pano0.neighbours.push(pano1)
- pano1.neighbours.includes(pano0) || pano1.neighbours.push(pano0)
- }
-
- return ifNeighbour
- }
-
-
- bump(direction) {//撞墙弹回效果
- if (!this.bumping && !this.latestToPano) {
- let distance = Potree.settings.displayMode == 'showPanos' ? 0.3 : 0.2;//感觉点云模式比全景模式更明显,所以降低
- let currentPos = this.position.clone()
- let endPosition = new THREE.Vector3().addVectors(this.position, direction.clone().multiplyScalar(distance))
-
- let duration = 150
- viewer.scene.view.setView({position:endPosition, duration,
- callback:()=>{
- viewer.scene.view.setView({position:currentPos, duration: duration*5,
- callback: ()=>{
- this.bumping = false
- //this.dispatchEvent('cameraMoveDone')
- },
- Easing:'easeInOutSine',
- cancelFun:()=>{this.bumping = false}
- })
- this.bumping = true
- },
-
- cancelFun:()=>{this.bumping = false},
- Easing:'easeInOutSine'
- })
- this.bumping = true
- }
- //备注:将4dkk中的‘前后方向变化fov、左右方向移动镜头’ 都改为移动镜头。 因为这里无法判断左右离壁距离。
-
- }
-
- flyToPanoClosestToMouse() {
-
- if(!Potree.settings.ifShowMarker){//不显示marker的时候mousemove没更新鼠标最近点所以更新
- this.updateClosestPano(viewer.inputHandler.intersect)
- }
- //console.log('flyToPanoClosestToMouse',this.closestPano)
-
- if (this.closestPano) {
- let pano = this.closestPano
- return this.flyToPano({
- pano, easeName: this.isAtPano() ? 'linearTween' : 'easeInOutQuad'
- });
-
- }
- var direction = this.viewer.inputHandler.getMouseDirection().direction;
- this.flyDirection(direction)
- }
- flyDirection(direction, option1, option2, byKey) {
- if(viewer.mainViewport.view.isFlying()){// closestPanoInDirection函数耗时长,飞行时运行会卡顿(如果以后加无缝过渡再说)
- return
- }
-
- var deferred = $.Deferred();
- //this.history.invalidate();
- var panoSet = this.closestPanoInDirection(direction, option1, option2, byKey);
- if (panoSet) {
- this.flyToPano({
- pano: panoSet,
- callback: deferred.resolve.bind(deferred, !0)
- } );
- } else {
- this.bump(direction);
- deferred.resolve(!1);
- }
- return deferred.promise();
- }
-
- closestPanoInDirection(direction, option1, option2, byKey) {
- return this.rankedPanoInDirection(0, direction, option1, option2, byKey)
- }
-
-
- rankedPanoInDirection(t, direction, option1, option2, byKey){
- //此direction为mouseDirection,是否需要加上相机角度的权重
- //let startTime = Date.now()
- var panoSet = {
- pano: null,
- candidates: [] //缓存顺序--如果需要打印的话
- };
- t || (t = 0);
- option1 = void 0 !== option1 ? option1 : .75;
- var o = option2 ? "angle" : "direction";
-
- let disSquareMap = new Map()
- this.panos.forEach(pano=>{
- let dis2 = pano.position.distanceToSquared(this.position); //距离目标点
- disSquareMap.set(pano, dis2)
- })
-
- let changeTexCount = 0, maxWaitDur = 300
-
-
- var request = [//必要条件
- Images360.filters.not(this.currentPano),
- Images360.filters.isEnabled(),
- Images360.filters.inFloorDirection( this.position, direction, option1 ), //原先用inPanoDirection,但容易穿楼层,当mouse较低或较高
- Images360.filters.inPanoDirection( this.position, this.getDirection(), option1/* , true */), //垂直方向上再稍微限制一下, 要接近视线方向,避免点击前方时因无路而到下一楼。但不能太高,否则楼梯上稍微朝下点击都到不了上方。之所以使用视线方向是因为镜头方向比鼠标方向目的性更强。
- (pano)=>{
- let isNeighbour = this.isNeighbour(this.currentPano, pano, false, true); // 注: 不会再changeTex了
-
- if(isNeighbour || pano.noNeighbour && disSquareMap.get(pano) < 200){//在靠近孤立点时可以通行。但是不好把握这个距离,太远的话很多地方都会不小心到孤立点,太近的话可能永远到不了。
- return true
- }
- },
-
- ]
-
- var list = [//决胜项目
- (pano)=>{
- return -disSquareMap.get(pano)
- },
-
- Images360.scoreFunctions[o]( this.position, direction, true),
-
- (pano)=>{
- let neighbour = this.isNeighbour(this.currentPano, pano, true, true) //不计算的
-
- return neighbour ? directionFactor : 0;
- } ,
-
- ];
- if(!byKey && viewer.inputHandler.intersect && this.currentPano ){//方便上下楼, 考虑panos之间的角度差
- let pos1 = this.currentPano.floorPosition
- let vec1 = new THREE.Vector3().subVectors(viewer.inputHandler.intersect.location, pos1 ).normalize()//应该只有atPano时才会执行到这吧?
- list.push( function(pano) {
- var pos2 = pano.floorPosition;
- var vec2 = pos2.clone().sub(pos1).normalize();
-
- return vec2.dot(vec1) * directionFactor * 4
- })
- }
-
- this.findRankedByScore(t,request,list,panoSet);
-
- //console.log( 'costTime:',Date.now() - startTime)
-
- return panoSet.pano;
-
- }
- findRankedByScore(e, t, i, n) {
- n && (n.candidates = null, //candidates 缓存顺序--如果需要打印的话
- n.pano = null),
- e || (e = 0);
- var r = Common.sortByScore(this.panos, t, i);
- //console.log('findRankedByScore', r && r.map(u=>u.item.id + '| ' + math.toPrecision(u.score,4) + " | " + math.toPrecision(u.scores,4)))
-
-
- return !r || 0 === r.length || e >= r.length ? null : (n && (n.candidates = r,
- n.pano = r[e].item),
- r[e].item)
- }
-
- updateClosestPano(intersect, state) {//hover到的pano 大多数时候是null
-
- var pano
-
- if(intersect instanceof Panorama){ //漫游模式
- pano = state ? intersect : null
- }else{
- if(this.isAtPano() || this.bumping){
- return
- }else{
- var filterFuncs = [];
- intersect = intersect && intersect.location
- if(!intersect)return
- let sortFuncs = Potree.settings.editType != 'pano'? [Images360.sortFunctions.floorDisSquaredToPoint(intersect)] : [Images360.sortFunctions.disSquaredToPoint(intersect)]
- pano = Common.find(this.panos, filterFuncs, sortFuncs);
- }
- }
-
- if (pano != this.closestPano) {
- pano && (this.isPanoHover = !0);
-
- this.closestPanoChanging(this.closestPano, pano) // 高亮marker
- //console.log('closestPano '+ (pano ? pano.id : 'null' ))
- this.closestPano = pano;
- } else {
- this.isPanoHover = !1;
- }
- }
- closestPanoChanging(oldPano, newPano){
- if(!Potree.settings.ifShowMarker)return
-
- oldPano && oldPano.hoverOff({byImages360:true})
- newPano && newPano.hoverOn({byImages360:true})
-
-
- }
-
- /*
- getTileDirection(){//根据不同dataset的来存储
- var vectorForward = viewer.scene.view.direction.clone()
-
- var vectorForwards = viewer.scene.pointclouds.map(e=>{
- var inv = new THREE.Matrix4().copy(e.rotateMatrix).invert()//乘上dataset的旋转的反转
- var direction = vectorForward.clone().applyMatrix4(inv)
- return {
- datasetId: e.dataset_id,
- direction: math.convertVector.ZupToYup(direction)
- }
- })
- //return vectorForwards[0].direction
-
-
- return {
- datasetsLocal: vectorForwards,
- vectorForward
- }
-
-
- }
- */
-
-
-
-
-
-
-
-
-
- fitPanoTowardPoint(o){ //寻找最适合的点位
- var point = o.point, //相机最佳位置
- target = o.target || o.point, //实际要看的位置
- require = o.require || [],
- rank = o.rank || [],
- force = o.force,
- getAll = o.getAll,
- bestDistance = o.bestDistance || 0,
- sameFloor = o.sameFloor,
- maxDis = o.maxDis,
- dir = o.dir
-
- let camera = viewer.scene.getActiveCamera()
- if(target && !dir){
- dir = new THREE.Vector3().subVectors(target,point).normalize()
- }
- let atFloor = sameFloor && viewer.modules.SiteModel.pointInWhichEntity(point, 'floor')
-
- //if(o.floor)require.push(Panorama.filters.atFloor(o.floor))
-
- let checkIntersect = o.checkIntersect
- let base = Math.max(300, viewer.bound.boundSize.length()*3);
-
-
- if(o.boundSphere){//只接受boundSphere
- let aspect = 1//size.x / size.y
- let dis
- if(camera.aspect > aspect){//视野更宽则用bound的纵向来决定
- dis = /* size.y */o.boundSphere.radius/* / 2 *// THREE.Math.degToRad(camera.fov / 2)
- }else{
- let hfov = cameraLight.getHFOVForCamera(camera , true );
- dis = /* size.x */ o.boundSphere.radius /* / 2 */ / (hfov / 2)
- }
- bestDistance = dis//*0.8
-
- }
- let disSquareMap = new Map()
-
- let bestDisSquared = bestDistance * bestDistance
- let maxDisSquared = maxDis && (maxDis * maxDis)
- this.panos.forEach(pano=>{
- let dis2 = pano.position.distanceToSquared(target); //距离目标点
- disSquareMap.set(pano, dis2)
- })
- let panos = this.panos.sort((p1,p2)=>{return disSquareMap.get(p1)-disSquareMap.get(p2)})
-
-
- if(maxDisSquared){//热点超过最大距离不可见的
- let panos2 = [], pano, i=0
- while(pano = panos[i], disSquareMap.get(pano) < maxDisSquared){
- panos2.push(pano)
- i++;
- }
- if(panos2.length == 0)return {pano, msg:'tooFar'} //全部都大于maxDis, 就返回最近的
- panos = panos2
- }
-
-
-
- rank.push((pano)=>{
- let dis1 = Math.abs(pano.position.distanceToSquared(point) - bestDisSquared); //距离最佳位置
- disSquareMap.set(pano, dis1)
- if(!target){
- return -dis1
- }else{
- let dis2 = disSquareMap.get(pano)
- let vec2 = new THREE.Vector3().subVectors(target,pano.position).normalize()
- let cos = dir.dot(vec2)
- //let result = (- dis1 - Math.pow(dis2 , 1.5)) / (cos + 2) // cos+2是为了调整到1-3,
-
- let result = (dis1 + dis2*0.3) * ( -1 + cos*0.9 ) //尽量贴近最佳位置的角度, 或贴近相机原来的角度 。尽量靠近最佳观测点,并且优先选择靠近目标点的位置.(注意cos的乘数不能太接近1,否则容易只考虑角度)
- //Potree.Log(pano.id, dis1, dis2, cos, result,{font:{toFixed:2,fontSize:10}})
-
- return result
- }
-
- //注:热点最好加上法线信息,这样可以多加一个限制,尽量顺着热点像展示的方向。
- },
- (pano)=>{
- let score = 0
- if(pano.depthTex && checkIntersect){
- let intersect = !!viewer.ifPointBlockedByIntersect(target, pano.id, true) //viewer.inputHandler.ifBlockedByIntersect({pos3d:target, margin:0.1, cameraPos:pano})
- if(intersect){
- score = 0
- }else {
- score = base * 2
- }
- }else{
- score = base * 1.5 //没加载好的话,不管了 , 几乎当做无遮挡,否则容易到不了最近点
- }
- return score
- }
-
- )
-
-
- var g = Common.sortByScore(panos, require, rank);
- console.log(g)
-
-
- let pano = g && g.length > 0 && g[0].item
- if(pano && checkIntersect){
- let intersect = !!viewer.ifPointBlockedByIntersect(target, pano.id, true)
-
- if(intersect){
- return {pano, msg : 'sheltered'}
- }
- }
-
- //if(getAll)return g;
- return pano
-
- //注:深度图有的位置会不准确,以至于会算出错误的遮挡、选择错误的pano,解决办法只能是移动下热点到更好的位置
- }
- //---------------scroll zoom ------------------------------------------
-
-
- /* zoomIn = function() { //放大
- this.zoomBy(1 + this.zoomSpeed);
- }
- zoomOut = function() {//缩小
- this.zoomBy(1 - this.zoomSpeed);
- } */
- zoomBy(e, pointer) {//以倍数
- this.zoomTo(this.zoomLevel * e, pointer);
- }
- zoomTo(zoomLevel, pointer) {//缩放到某绝对zoomLevel
- let zoom = Potree.settings.zoom
- if (zoom.enabled) {
-
-
- zoomLevel = THREE.Math.clamp(zoomLevel, zoom.min, zoom.max)
- //console.log(zoomLevel)
-
- if(zoomLevel == this.zoomLevel) return;
-
- /* if (zoomLevel > this.zoomLevel) {
- this.emit(ZoomEvents.ZoomIn);
- zoomLevel === settings.zoom.max && this.emit(ZoomEvents.ZoomMax);
- } else if (zoomLevel < this.zoomLevel) {
- this.emit(ZoomEvents.ZoomOut);
- zoomLevel === settings.zoom.min && this.emit(ZoomEvents.ZoomMin);
- } */
-
- this.zoomLevel = zoomLevel;
- //定点缩放:使当前鼠标所在的位置缩放后不变
- let view = viewer.scene.view
- let originDir = viewer.scene.view.direction;
- let oldPointerDir = viewer.inputHandler.getMouseDirection(pointer).direction
- viewer.setFOV(Potree.config.view.fov * (1 / this.zoomLevel))
- let newPointerDir = viewer.inputHandler.getMouseDirection(pointer).direction
-
- view.direction = oldPointerDir; //获取一下鼠标所在位置的yaw 和 pitch
- let oldPitch = view.pitch, oldYaw = view.yaw;
- view.direction = newPointerDir;
- let newPitch = view.pitch, newYaw = view.yaw;
-
- view.direction = originDir //还原
- viewer.scene.view.pitch -= newPitch - oldPitch
- viewer.scene.view.yaw -= newYaw - oldYaw
- }
- }
-
-
-
-
- zoomFovTo( fov ) { //通过fov来算zoomLevel
- let zoomLevel = Potree.config.view.fov /* this.baseFov */ / fov;
- this.zoomTo( zoomLevel );
- }
- smoothZoomTo(aimLevel, dur=0) {
- var currentLevel = this.zoomLevel
- if(currentLevel == aimLevel)return;
-
- var fun = (progress)=>{
- //progress > 1 && (progress = 1)
- let level = currentLevel * (1 - progress) + aimLevel * progress
- this.zoomTo(level, !0)
- }
-
-
- transitions.start(fun, dur, null, null, 0 , easing['easeInOutQuad'] )
- }
-
-
-
-
-
-
- getIntersect(pano, dir, origin){
- if(pano && pano.pointcloud.hasDepthTex ){
- return this.depthSampler.sample( {dir }, pano, true )
- }else{
- origin = origin || pano.position
- return viewer.inputHandler.getIntersect(viewer.inputHandler.hoverViewport, true, null, null, true, {
- point: origin.clone().add(dir),
- cameraPos: origin
- })
- }
- }
-
-
-
-
-
-
-
-
- addPanoData(data ){//加载漫游点
- //data[0].file_id = '00019'
-
- data = data.sweepLocations
- if(data.length == 0)console.error( '没有漫游点')
- //data = data.sort(function(a,b){return a.id-b.id})
-
- data.forEach((info)=>{
- //if(Potree.fileServer){
- info.id = this.panos.length //把info的id的一长串数字改简单点
- //}
- let pano = new Panorama( info, this );
-
- pano.addEventListener('dispose',(e)=>{
- if(this.closestPano == pano) this.closestPano = null
- })
-
- this.panos.push(pano);
-
- })
- }
-
-
- loadDone(){
- Potree.Utils.setObjectLayers(this.node, 'sceneObjects')
-
- this.panos.forEach(e=>{
- this.neighbourMap[e.id] = {}
- e.label && Potree.Utils.setObjectLayers(e.label, 'bothMapAndScene')
- })
-
-
- {
- let minSize = new THREE.Vector3(1,1,1)
- this.bound = math.getBoundByPoints(this.panos.map(e=>e.position), minSize)
- viewer.scene.pointclouds.forEach(pointcloud=>pointcloud.getPanosBound())
-
- }
-
- if(viewer.scene.pointclouds.some(e=>e.panos.length == 0)){
- //console.warn('存在数据集没有pano');
- viewer.hasNoPanoDataset = true
- }
- }
-
-
-
- getPano(value, typeName='id'){ //默认找的是id,也可以是sid、uuid
- return this.panos.find(p=>p[typeName] == value)
- }
- update(){
-
-
- if(!this.currentPano)return
-
- Potree.Common.intervalTool.isWaiting('filterDepthTex', ()=>{
-
- var s = [Images360.filters.not(this.currentPano )],
- l = [Images360.scoreFunctions.distanceSquared(this.currentPano ), Images360.scoreFunctions.direction(this.position, this.getDirection())]
- this.nearPanos = Common.sortByScore(this.panos, s, l).map(e=>e.item);
-
- //下载深度图
- let depTexDlCount = browser.isMobile() ? 1 : 2;
- let loadingCount = this.nearPanos.filter(p=>p.depthTexLoading).length;
- if(loadingCount<depTexDlCount){
- this.nearPanos.filter(p=>!p.depthTex).slice(0, depTexDlCount-loadingCount).forEach(p=>p.loadDepthImg());
- }
-
- }, 77)
-
- this.getNeighbours(this.nearPanos)
-
- }
-
- };
-
-
- Images360.prototype.getNeighbours = function(){ //逐渐自动获取neighbours。 200个点差不多在半分钟内算完
- let lastIndex //标记上次查询到哪,防止重新sortByScore
- return function(nearPanos){
- if(!this.currentPano || viewer.mainViewport.view.isFlying() || viewer.lastFrameChanged || viewer.inputHandler.drag /* interacted */){ //拖拽时不更新,否则移动端卡
- return lastIndex = 0;
- }
- if(!nearPanos)return;
- //let startTime = Date.now()
-
- let panos = [this.currentPano, ...nearPanos ]
- this.depthSampler.updateNearPanos(panos)
-
- let maxWaitDur = browser.isMobile() ? 40 : 60
- let changeCount = 0, getCount = 0
- let changeTexCount = ()=>{
- changeCount ++;
- }
- let median = Math.max(10, Potree.timeCollect.depthSampler.median)
- let ifOverTime = ()=>{
- let is = changeCount * median + getCount * 0.01 > maxWaitDur//不换贴图也要一丢丢计算时间
- /* if(is){
- console.log(1)
- } */
- return is
- }
- this.depthSampler.addEventListener('changeImg', changeTexCount)
-
- outer: for(let i=lastIndex,j=panos.length; i<j; i++){
- let pano = panos[i];
- let others = panos.slice(i+1, j)
- lastIndex = i
-
- var g = Common.sortByScore(others, [ ], [
- Images360.scoreFunctions.distanceSquared(pano.position)
- ]);
-
- for(let a=0, b=g.length; a<b; a++){
- let item = g[a]
- if(this.isNeighbour(pano, item.item, true) != void 0) continue
-
- let byCloud = !pano.pointcloud.hasDepthTex
- let result = this.isNeighbour(pano, item.item, false, !byCloud, true)//计算
-
- if(result != void 0){//计算了
- //console.log('提前计算neighbor', pano.id, item.item.id)
- this.dispatchEvent({type:'getNeighbourAuto', panos:[pano,item.item]})
-
- if(byCloud){ //只计算一次
- //console.log('提前计算neighbor byCloud', result, pano.id, item.item.id)
- break outer;
- }
- getCount ++
- if(ifOverTime()){
- break outer
- }
- }
-
-
- }
-
- lastIndex = i+1 //这轮结束
- }
-
-
- this.depthSampler.removeEventListener('changeImg', changeTexCount)
-
- /* let costTime = Date.now() - startTime
- costTime > maxWaitDur && console.log( 'costTime:',costTime) */
- }
- }()
- Images360.filters = {
- inPanoDirection : function(pos, dir, i, log) { //pano在mouse的方向上
- return function(pano) {
- var r = pano.floorPosition.clone().sub(pos).normalize()
- var o = pano.position.clone().sub(pos).normalize()
- log && console.log('dire',pano.id, r.dot(dir), o.dot(dir) )
- return r.dot(dir) > i || o.dot(dir) > i
- }
- },
- inFloorDirection: function(pos, dir, min, log) { //pano在mouse的水平方向上
- return function(pano) {
- var vec = new THREE.Vector2().subVectors(pano.floorPosition, pos).normalize()
- var dir_ = new THREE.Vector2().copy(dir).normalize()
- log && console.log('dire', pano.id, vec.dot(dir_) )
- return vec.dot(dir_) > min
-
- /* var i = pano.floorPosition.clone().sub(pos).setZ(0).normalize();//改成在xz方向上,否则点击墙面不会移动
- return i.dot(dir.clone().setZ(0)) > min */
- }
- },
- isNotBehindNormal: function(e, t) {
- var i = new THREE.Vector3;
- return t = t.clone(),
- function(n) {
- var r = i.copy(n.position).sub(e).normalize();
- return r.dot(t) > 0
- }
- },
- isCloseEnoughTo: function(e, t) {
- return function(i) {//因为marker可能比地面高,所以识别范围要比marker看起来更近一些。(因为投影到地板的位置比marker更近)
- return e.distanceTo(i.floorPosition) < t //许钟文
- }
- },
-
- not: function(e) {
- return function(t) {
- return t !== e
- }
- } ,
- isEnabled:function() {
- return function(t) {
- return t.enabled
- }
- },
- isVisible:function() {
- return function(t) {
- return t.visible
- }
- }
- }
- Images360.scoreFunctions = {
- direction: function(curPos, dir, ifLog) {
- return function(pano) {
- var pos1 = /* pano.floorPosition */ pano.position //旧:改为权重放在marker上,这样对有斜坡的更准确,如上楼, 但这样近距离的pano角度就会向下了,以致于走不到
- var n = pos1.clone().sub(curPos).normalize();
- //ifLog && console.log('direction', pano.id, n.dot(dir) * directionFactor )
- return n.dot(dir) * directionFactor
- }
-
- },
-
- distance: function(pos1, r=1, ifLog) {
- if(pos1.position)pos1 = pos1.position
- return function(pano) {//许钟文 改
- var pos2 = pano.position.clone()
- //ifLog && console.log('distance', pano.id, pos1.distance(pos2) * -1 )
- return pos1.distanceTo(pos2) * -1 * r;
- }
- },
- distanceSquared: function(pos1, r=1 ) {
- if(pos1.position)pos1 = pos1.position
- return function(pano) {//许钟文 改
- var pos2 = pano.position.clone()
- return pos1.distanceToSquared(pos2) * -1 * r;
- }
- },
-
- angle: function(e, t) {
- return function(i) {
- var n = i.position.clone().sub(e).normalize();
- return n.angleTo(t) * Potree.config.navigation.angleFactor
- }
- },
- }
- Images360.sortFunctions = {//排序函数,涉及到两个item相减
- floorDisSquaredToPoint: function(e) {
- return function(t, i) {
- return t.floorPosition.distanceToSquared(e) - i.floorPosition.distanceToSquared(e)
- }
- },
- disSquaredToPoint: function(e) {
- return function(t, i) {
- return t.position.distanceToSquared(e) - i.position.distanceToSquared(e)
- }
- },
-
- }
-
- Images360.prototype.updateCube = (function(){//增加细分的版本,且垂直方向上取中位数 侧边多条
-
- const minDis = 0.2; //pano和墙距离不能小于相机的near
- const height = 1 //准确计算的话要分别计算两个pano的地面、天花板之间的俯仰角,和pano之间的还不一样。这里统一假设一个比较小的高度,因高度越大 maxSinAlpha 越大
- let minTanBeta = minDis / height /* (pano0.position.z - pano0.floorPosition.z) */
- let minBeta = Math.atan(minTanBeta)
- const maxSinAlpha = Math.cos(minBeta) // 注:beta = Math/2 - alpha
- const skyHeight = 50
- return function(pano0, pano1){
-
- if(Potree.settings.displayMode != 'showPanos' || pano0 == pano1
- || this.cubePanos.includes(pano0) && this.cubePanos.includes(pano1)
- ) return
-
- this.cubePanos = [pano0, pano1]
-
- viewer.addTimeMark('updateCube','start')
-
- //console.log('updateCube',pano0.id, pano1&&pano1.id)
-
- let useBound = (bound, size)=>{
-
- size = size || bound.getSize(new THREE.Vector3)
- let center = bound.getCenter(new THREE.Vector3)
- size.max(new THREE.Vector3(HighMapCubeWidth,HighMapCubeWidth,HighMapCubeWidth))
- this.cube.geometry = new THREE.BoxBufferGeometry(1,1,1,1)
- this.cube.scale.copy(size)
- this.cube.position.copy(center)
- if(Potree.settings.testCube){
- this.cubeTest.geometry = this.cube.geometry
- this.cubeTest.scale.copy(size)
- this.cubeTest.position.copy(center)
- }
-
- return 'useBound'
- }
-
-
- let getPanoBound = (pano)=>{//因漫游点可能在点云外部,如室外平地,所以需要union进漫游点
- let panoBound = new THREE.Box3
- panoBound.expandByPoint(pano.position)
- panoBound.expandByVector(new THREE.Vector3(10,10,10));//give pano a margin
- return pano.pointcloud.bound.clone().union(panoBound)
- }
-
- this.cube.geometry.dispose();
-
- if(pano1){//过渡
- let dontAddSides
- let dis = pano0.position.distanceTo(pano1.position)
-
- let sinAlpha = Math.abs(pano0.position.z - pano1.position.z) / dis //俯仰角的sin,随角度增大而增大 0-1
- let score = (1+sinAlpha*20) * dis //score越大创建的mesh越不适合
- let isNeighbour = this.isNeighbour(pano0, pano1)
- //console.log(pano0.id, pano1.id, maxSinAlpha.toFixed(2), sinAlpha.toFixed(2), score.toFixed(2), isNeighbour)
-
- //let depthTiming = Potree.timeCollect.depthSampler.median //pc firefox达到4. chrome为0.01
-
- if(sinAlpha>maxSinAlpha || !pano0.pointcloud.hasDepthTex || !pano1.pointcloud.hasDepthTex || (isNeighbour ? score > 100 : score > 50 ) ){
- let bound = getPanoBound(pano0).union(getPanoBound(pano1))
- let size = bound.getSize(new THREE.Vector3)
- let max = Math.max(size.x, size.y, size.z)
- size.set(max,max,max) //距离太远的数据集,过渡会畸变。所以扩大skybox,且为立方体
- return useBound(bound, size)
- }else if(/* depthTiming > 1 || */ (isNeighbour ? score > 70 : score > 15)){
- dontAddSides = true //pano间有阻挡时得到的side点可能使通道变窄,所以去掉。
- }
- //俯仰角增大时可能不在同一楼层,算出来的mesh不太好,所以更倾向直接使用cube,或去除side。
-
-
-
- let half //6 : (browser.isMobile() ? 2 : 3) //自行输入 (点云计算的慢,还不准)
- {
- let min = 3,max = 6, minTime = 0, maxTime = 3
- /* half = math.linearClamp(depthTiming, minTime,maxTime, max,min)
- half = Math.round(half) */
- half = max
- }
- let count1 = 2*half//偶数个 每个pano向 外dir 个数
- //奇数个的好处:在窄空间内能探测到最远距离,坏处是前方有尖角。偶数个的坏处就是可能检测距离太近。
-
- //let panoIndex = 0
-
-
- let getDir = (angle_, vec)=>{ //旋转获得水平向量
- let rotMat = new THREE.Matrix4().makeRotationZ(angle_)
- return vec.clone().applyMatrix4(rotMat)
- }
- let getFar = (dir, pano, origin, height)=>{//获取在这个方向上和墙体intersect的距离
- //在垂直方向上分出多个方向,取一个最可能的接近真实的距离
- let maxH = 40, minH = 2, minR = 0.5, maxR = 2
- height = height == void 0 ? (Math.min(skyHeight,pano.ceilZ) - pano.floorPosition.z) : height
- //let r = height (maxH - minH)* 0.14 // 高度越小,角度越小
- //let r = minR + ( maxR - minR) * THREE.Math.clamp((height - minH) / (maxH - minH),0,1) //THREE.Math.smoothstep(currentDis, op.nearBound, op.farBound);
- let r = math.linearClamp(height, minH,maxH, minR, maxR)
-
-
- let getZ = (deg)=>{
- deg *= r
- deg = THREE.Math.clamp(deg, 1, 80);
- return Math.tan(THREE.Math.degToRad(deg))
- }
- let dirs_ //注意:角度太大会碰到天花板或地板,越远越容易碰到, 在地下停车场就会伸展不开。 户外时需要更多向上的方向,所以上方向多一个
- /* if(depthTiming > 2) dirs_ = [35,0,-5]
- else if(depthTiming > 0.5) dirs_ = [35,10,0,-5]
- else */dirs_ = [35,20,7, 0,-5]
- dirs_ = dirs_.map(deg=> dir.clone().setZ(getZ(deg)).normalize() )
-
-
- let max = 50
- let count2 = dirs_.length
- let disArr = dirs_.map((dir_, i) =>{
- let intersect = this.getIntersect(pano, dir_, origin)
- let projectLen = intersect && intersect.distance ? dir_.dot(dir)*intersect.distance : max; //得到project在dir的长度
- return projectLen //得水平距离
- })
- //console.log(pano ? pano.id : 'side','disArr', disArr.slice(0))
- disArr.sort((a,b)=>{return b-a}); //从大到小
- //console.log(pano ? pano.id : 'side','disArr', disArr)
- let dis = disArr[Math.floor(count2/2-0.5)] //对半、取前(中位数)
- return dis
- }
- let sideCount = [0,0]
-
- let addPos = (pano, vec )=>{//添加这个pano这一侧向外半圆的顶点
- //添加pano位置对应的最高点最低点:
- let minZ, maxZ
- minZ = pano.floorPosition.z
-
- maxZ = pano.getCeilHeight()
-
- if(maxZ == Infinity) maxZ = skyHeight; //maxZ = Math.max(skyHeight, maxZ)
-
-
-
- [maxZ, minZ ].forEach(z=>{
- posArr.push(pano.position.clone().setZ(z))
- })
-
-
-
- //在画面上线条从左往右数
- const angle = Math.PI/(count1-1)
- const dirs = []; //平分这半边180度
- for(let i=0;i<count1;i++){
- dirs.push(getDir(Math.PI/2-i*angle, vec))//正的在左边
- }
-
-
- let dirs2 = dirs.map((dir)=>{
- return {
- dir,
- dis: getFar(dir, pano)
- }
- })
-
- //剔除那些突然间离相机很近的dir。有可能是拍摄的人、或者杆子、树
-
- /* dirs2.forEach((e,i)=>{
- console.log(i, e.dis)
- let smallThanBefore = ()=>{
- return dirs2[i-1].dis / e.dis > maxRatio
- }
- let smallThanAfter = ()=>{
- return dirs2[i+1].dis / e.dis > maxRatio
- }
-
- if(i>0 && i<count1-1 && smallThanBefore() && smallThanAfter()){//比左右两边都小很多
- e.disB = (dirs2[i-1].dis + dirs2[i+1].dis) / 2 //平均数
- console.log('两者之间',i,e.disB)
- }else if(i==count1-1 && smallThanBefore() ) {//比前者小很多
- e.disB = dirs2[i-1].dis * 0.8
- console.log('smallThanBefore', i, e.disB)
- }else if(i==0 && smallThanAfter() ){//比后者小很多
- e.disB = dirs2[i+1].dis * 0.8
- console.log('smallThanAftere', i, e.disB)
- }
-
- }) */
- const maxRatio1 = 3 , maxRatio2 = 8 //超过maxRatio1就要加入判断,而最终结果的设限其实是maxRatio2
- const minWidth = 0.5
- let computeWidth = (start,end)=>{
- start+=1 //不包含start和end
- let count = end - start ;
- let dis = 0
- for(let m=start;m<end;m++){//得平均数
- dis += dirs2[m].dis
- }
- dis /= count
- let angle = Math.PI / (count1-1) * count / 2
- let width = dis * Math.tan(angle) //得到block的半宽度
- return width
- }
- let changeDis = (start,end )=>{ //不包含start
- start+=1 //不包含start和end
- for(let m=start;m<end;m++){
- dirs2[m].disB = dirs2[end].dis * 0.8
- //console.log('changeDis', m, dirs2[m].disB)
- }
- }
- let start = -1
- for(let i=0;i<count1;i++){//遍历时将左边dis比之小很多且宽度较小的改大
- //console.log(i, dirs2[i].dis)
- let j = i-1
- let ratios = 0
- while(j>start && dirs2[i].dis / dirs2[j].dis > maxRatio1){
- ratios += dirs2[i].dis / dirs2[j].dis
- j--
- }
- let count = i-j-1
- ratios /= count
- if(count > 0 && computeWidth(j,i)< minWidth * ratios / maxRatio2 ){ //怎么感觉好像改成了视觉宽度小于某个值即可,那直接用count好了?
- changeDis(j,i)
- start = i //在此之前的修改过,之后不用再判断
- }
- /* if(count > 0 && (count == 1 || computeWidth(j,i)<minWidth)){//若只有一个不用判断宽度直接修改
- changeDis(j,i)
- start = i //在此之前的修改过,之后不用再判断
- } */
- }
-
-
- dirs2.forEach((e, index)=>{
- let dir = e.dir.clone().multiplyScalar(e.disB || e.dis);
- [maxZ,minZ].forEach(z=>{
- posArr.push(pano.position.clone().setZ(z).add(dir)) //获取到外墙点
- })
- });
- }
-
-
-
- let addSide = ()=>{//两个漫游点间两边各加一些侧线
- //中点处的
- let top0 = pano0.ceilZ == Infinity ? skyHeight : pano0.ceilZ
- let top1 = pano1.ceilZ == Infinity ? skyHeight : pano1.ceilZ
- let midMaxZ = (top0 + top1)/2
- let midMinZ = (pano0.floorPosition.z+pano1.floorPosition.z)/2;
- let mid = new THREE.Vector3().addVectors(pano0.position, pano1.position).multiplyScalar(0.5)
-
- if(!dontAddSides){
- if( pano0.pointcloud.hasDepthTex && pano0.pointcloud.hasDepthTex){
- let panos = [pano0,pano1]
- let vecs = [vec.clone().negate(), vec]
- let axis = [[-1,1],[1,-1]]
- let dis2d = new THREE.Vector2().subVectors(pano0.position, pano1.position).length()//水平上的距离
-
- let maxDis = 50, minDis = 0.5, minR = 0.2, maxR = 1.2
- //let r = maxR - ( maxR - minR) * THREE.Math.clamp((dis2d - minDis) / (maxDis - minDis),0,1) //dis2d越大,角度要越小 //THREE.Math.smoothstep(currentDis, op.nearBound, op.farBound);
- let r = math.linearClamp(dis2d, minDis,maxDis, maxR, minR)
- //console.log('dis2d',dis2d,'r',r)
-
-
- let angles = (browser.isMobile ? [50] : [35,65]).map(deg=>{ //正的在左边 尽量能够平分中间这段墙体。 (角度为从中心向外)
- let angle = THREE.Math.clamp(deg * r, 5, 80);
- //console.log('angle',angle)
- return THREE.Math.degToRad(angle)
- })
-
- axis.forEach((axis_, index0)=>{
- let disToSides = []
- let accordingPano = index0 == 0 ? pano0 : pano1; //根据离该点在vec方向上的距离顺序来存顶点
- panos.forEach((pano,index)=>{
- let dirs = angles.map(angle=>getDir(axis_[index]*angle, vecs[index]))//一侧的若干角度
-
- dirs.forEach((dir_,i)=>{
- let dis1 = getFar(dir_, pano);
-
- let disToPano2d = dis1 * Math.cos(angles[i])
- if(disToPano2d<dis2d){//超过的话都到另一半pano的半圆了,不计入
- let disToSide = dis1 * Math.sin(angles[i])
-
- if(pano != accordingPano){
- disToPano2d = dis2d - disToPano2d //反一下
- }
-
- dir_.multiplyScalar( dis1 );
- disToSides.push({disToSide,disToPano2d, pano, dir_})
- }
- })
- })
-
- if(disToSides.length){
- //disToSides.sort((a,b)=>{return b-a});//从大到小
- //由距离accordingPano的近到远:
- disToSides.sort((a,b)=>{return a.disToPano2d-b.disToPano2d})
-
- //console.log('disToSides', index0, disToSides)
- if(disToSides.length == 1 && disToSides[0].disToSide < 0.5){
- disToSides = [] //如果太近直接去除
- }
-
- disToSides.forEach(e=>{//求z
- let ratio = e.disToPano2d / dis2d
- let r = accordingPano == pano0 ? (1-ratio) : ratio
- let sideMaxZ_ = top0 * r + top1 * (1-r);
- let sideMinZ_ = pano0.floorPosition.z * r + pano1.floorPosition.z * (1-r);
- [sideMaxZ_,sideMinZ_].forEach(z=>{
- posArr.push(e.pano.position.clone().setZ(z).add(e.dir_)) //是直接使用最长dis的那个intersect点好还是mid
- })
-
- })
-
- }
- sideCount[index0] = disToSides.length //记录侧边个数
- })
-
- }else{
- //这段针对点云时,仅测试才会执行到
- sideCount = [1,1]
- let sideDirs = [getDir(Math.PI/2, vec), getDir(-Math.PI/2, vec)]
- sideDirs.forEach((dir_ ,index)=>{
- let dis = getFar(dir_, null, mid, midMaxZ-midMinZ); //直接从中点求两侧的距离
- dir_.multiplyScalar( /* Math.max( */dis/* , sideDis[index]) */ );
- [midMaxZ,midMinZ].forEach(z=>{
- posArr.push(mid.clone().setZ(z).add(dir_))
- })
- })
- }
- }
-
- //中心:
- [midMaxZ,midMinZ].forEach(z=>{
- posArr.push(mid.clone().setZ(z))
- })
- }
-
-
-
-
- //positions存放顺序:pano的每边的 zMax和zMin 、count1个dir的点 ;侧边的点 ;连接处顶底的中点
- let addFaces = ()=>{
-
- let getPI = function(index, posType, panoIndex){//获取顶点序号
- return 2 + (count1*2 + 2 ) * panoIndex + index*2 + (posType == 'top' ? 0 : 1)
- }
- let getSidePI = function(index, posType, panoIndex){//获取侧边顶点序号
- if(panoIndex == 1) index += sideCount[0]
- return getPI(index, posType, 2)-2
- }
- let getPanoPI = function(posType, panoIndex){//获取pano处对应的点序号
- return getPI(-1, posType, panoIndex)
- }
- let topCenter = posArr.length-2; //最后添加的两个中心点
- let btmCenter = posArr.length-1;
-
- for(let i=0;i<2;i++){
- for(let index=1; index<count1; index++){
- //pano外侧半圆围墙
- faceArr.push([getPI(index,'top',i), getPI(index-1,'btm',i), getPI(index-1,'top',i)],//加入一块四方面
- [getPI(index,'top',i), getPI(index,'btm',i), getPI(index-1,'btm',i)])
-
- faceArr.push([getPI(index,'top',i), getPI(index-1,'top',i), getPanoPI('top',i)])//天花板扇形
- faceArr.push([getPI(index,'btm',i), getPI(index-1,'btm',i), getPanoPI('btm',i)])//地板扇形
-
- }
-
- let j = (i + 1) % 2; //另一个pano
-
-
- //侧边
-
- for(let u=0; u<=sideCount[i]; u++){
- //侧边每个四方的左上右上左下右下四个点
- let pLT = u == 0 ? getPI(0,'top',i) : getSidePI(u-1, 'top',i)
- let pRT = u == sideCount[i] ? getPI(count1-1,'top',j) : getSidePI(u, 'top',i)
- let pLB = u == 0 ? getPI(0,'btm',i) : getSidePI(u-1, 'btm',i)
- let pRB = u == sideCount[i] ? getPI(count1-1,'btm',j) : getSidePI(u, 'btm',i)
-
- faceArr.push([pLT,pLB,pRB],[pLT,pRB,pRT])//外侧四方面
- faceArr.push([pLT,topCenter,pRT] ,[pLB,btmCenter,pRB] )//顶部和底部到整体中心的扇形(由于点的顺序是根据和两个pano的距离,因此到中心的夹角并没按顺序排列,所以可能会重叠)
-
- if(i==0){//只需要算一次
- //顶部和底部中心与两个pano边构成的三角形
- if(u == 0){
- faceArr.push([pLT,getPI(count1-1,'top',i),topCenter],
- [pLB,getPI(count1-1,'btm',i),btmCenter],
- )
- }
- //不能用else 因为当length==0时u==0也==sideCount[i],此时就是要两个面
- if(u == sideCount[i]){
- faceArr.push([pRT,getPI(0,'top',j),topCenter],
- [pRB,getPI(0,'btm',j),btmCenter],
- )
- }
- }
-
- }
-
- }
-
- }
-
-
-
-
- let posArr = [];
- let faceArr = []
-
-
-
- //两点连线的水平向量
- let vec = new THREE.Vector3().subVectors(pano0.position, pano1.position).setZ(0).normalize()
-
- /* let sideDis0 = */addPos(pano0, vec)
- /* let sideDis1 = */addPos(pano1, vec.clone().negate())
- addSide()
- addFaces()
-
- //MeshDraw.updateGeometry(this.cube.geometry, posArr, faceArr)
- let geo = MeshDraw.createGeometry(posArr, faceArr)
- this.cube.geometry = geo
- this.cube.scale.set(1,1,1);
- this.cube.position.set(0,0,0)
-
- if(Potree.settings.testCube){
- this.cubeTest.geometry = geo
- this.cubeTest.scale.set(1,1,1);
- this.cubeTest.position.set(0,0,0)
- }
-
- }else{
-
- useBound(getPanoBound(pano0))
-
- }
-
- viewer.addTimeMark('updateCube','end')
- return true
-
- /*
- 关于卡顿:
- 即使使用cube,若scale设置为只容纳两个pano,也会卡顿。但也是有的卡有的不卡。
- 若按照原先的复杂geo,一般在平直的街道上行走流畅,经过拐弯或者复杂区域较卡。减小geo复杂度没有什么作用。
-
-
- 注: 修改skybox,若不准的话,会遮住其他mesh,比如marker。尤其在没有深度贴图时。
-
-
- 耗时: chrome: 20+ ,但是firefox:500+ 咋回事 ? iphonex safari: 40+
-
-
- */
- }
- })()
-
|