123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120 |
- 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 QualityManager from './tile/QualityManager.js'
- import TileDownloader from './tile/TileDownloader.js'
- import PanoRenderer from './tile/PanoRenderer.js'
- import TilePrioritizer from './tile/TilePrioritizer.js'
- import { PanoSizeClass,Vectors,GLCubeFaces, PanoramaEvents} from '../../defines.js'
-
- import {transitions, easing, lerp} from "../../utils/transitions.js";
- import DepthImageSampler from './DepthImageSampler.js'
-
- 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 sm = new THREE.MeshBasicMaterial({side: THREE.BackSide});
- 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.selectingEnabled = true;
- this.panos = [];
- this.neighbourMap = {}
-
-
- this.node = new THREE.Object3D();
- this.node.name = 'ImagesNode'
- //this.node2 = new THREE.Object3D();
-
- this.cubePanos = [];
-
-
-
- this.cube = new THREE.Mesh(new THREE.BoxBufferGeometry(1,1,1,1),new ModelTextureMaterial());
- viewer.updateVisible(this.cube,'showSkybox', false )
-
-
- this.cube.layers.set(Potree.config.renderLayers.skybox)
- this.cube.name = 'skyboxCube'
- viewer.scene.scene.add(this.cube)
-
-
- this._visible = true;
-
- this.currentPano = null;
- this.mouseLastMoveTime = Date.now()
- this.scrollZoomSpeed = 0.06
- this.zoomLevel = 1
-
- this.tileDownloader = new TileDownloader;
- this.qualityManager = new QualityManager
- this.panoRenderer = new PanoRenderer(viewer, this.tileDownloader, this.qualityManager)
-
- this.basePanoSize = this.qualityManager.getPanoSize(PanoSizeClass.BASE);
- this.standardPanoSize = this.qualityManager.getPanoSize(PanoSizeClass.STANDARD);
- this.highPanoSize = this.qualityManager.getPanoSize(PanoSizeClass.HIGH);
- this.ultraHighPanoSize = this.qualityManager.getPanoSize(PanoSizeClass.ULTRAHIGH);
- this.tileDownloader.processPriorityQueue = !1;
- this.tileDownloader.tilePrioritizer = new TilePrioritizer(this.qualityManager, this.basePanoSize, this.standardPanoSize, this.highPanoSize, this.ultraHighPanoSize);
- this.flying_ = false
-
- {//高分辨率cube 放大
- this.addHighMapCube()
- viewer.addEventListener(PanoramaEvents.Enter,(e)=>{
- this.setHighMap(e.newPano)
- })
- viewer.addEventListener('panoSetZoom',(e)=>{
- if(Potree.settings.displayMode == 'showPanos'){
- e.zoomed ? this.showHighMap() : this.hideHighMap() //add
- }
- })
-
- }
-
-
-
- this.depthSampler = new DepthImageSampler();
- this.addEventListener('loadedDepthImg',(e)=>{
- e.loaded && this.updateDepthTex(e.pano)
- })
-
-
-
- let scroll = (e)=>{
- if(e.hoverViewport != viewer.mainViewport)return
-
- /* if(Potree.settings.displayMode == 'showPanos' && Potree.settings.zoom.enabled){
-
- } */
- }
-
- 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(Potree.settings.editType != 'pano' && Potree.settings.editType != 'merge'){
- if( e.hoverViewport == viewer.mapViewer.viewports[0]){
- return viewer.mapViewer.dispatchEvent(e/* {type:'global_click',e } */)
- }else if(e.hoverViewport != viewer.mainViewport){ //如数据集校准其他viewport
- return
- }
- }
-
-
- /* if(currentlyHovered && currentlyHovered.pano){
- this.focusPano(currentlyHovered.pano);
- }else{//add */
- 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 = viewer.getObjVisiByReason(viewer.scene.pointclouds[0], 'force')
- viewer.scene.pointclouds.forEach(e=>{
- viewer.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 = '';
- let latestRequestMode = '';//因为可能延迟,所以记录下每次的请求模式,延迟后判断这个
- Object.defineProperty(Potree.settings , "displayMode",{
- get: function() {
- return displayMode
- },
- set: (mode)=> {
- latestRequestMode = mode
- //console.warn('Request setMode: ' + mode)
-
- if(mode != displayMode){
- let config = Potree.config.displayMode[mode]
- let config2
- let camera = viewer.scene.getActiveCamera()
- if(mode == 'showPanos' && viewer.mainViewport.view.isFlying()){//飞完才能切换全景
- let f = ()=>{
- if(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.currentPano
- if(this.flying)config2 = config.transition
- else config2 = config.atPano
- }else{
- config2 = config.atPano
- if(mode == 'showPanos'){//自动飞入一个pano
- //要改成飞进最近的。。。
- if(this.panos.length == 0)return
- //this.modeChanging = true //主要是因为到全景图不会立刻成功
- let wait = (e)=>{
- this.removeEventListener('flyToPanoDone',wait)
- setTimeout(()=>{
- if(latestRequestMode == mode ){
- Potree.settings.displayMode = mode
- }
- },e.makeIt ? 1 : 50)
- }
- this.flyToPano({
- pano: this.findNearestPano(),
- //dealDoneWhenCancel:true,
- /* callback: ()=>{
- setTimeout(()=>{ //防止循环,所以延迟
- if(latestRequestMode == mode ){
- Potree.settings.displayMode = mode
- }
- },1)
- } */
- })
- this.addEventListener('flyToPanoDone',wait) //等待飞行完毕。flyToPano的callback可能不执行所以换这个。但也可能被cancel
-
- return;
- }else{
-
- }
- }
-
-
- if(config2.showSkybox || config2.showPoint && config2.pointUsePanoTex){
- this.tileDownloader.start()
- }else{
- this.tileDownloader.stop()
- }
-
-
-
- if(config2.showSkybox || config2.pointUsePanoTex){
- let wait = ()=> {
- setTimeout( ()=>{
- if(latestRequestMode == mode ){
- Potree.settings.displayMode = mode
- }
- },1)
- this.removeEventListener('loadedDepthImg', wait)
- }
- if(!this.currentPano.depthTex && this.currentPano.pointcloud.hasDepthTex){
- this.addEventListener('loadedDepthImg', wait)
- return this.currentPano.loadDepthImg()
- }
- //this.updateDepthTex()
- if(this.checkAndWaitForPanoLoad(this.currentPano, this.basePanoSize, wait)){
- return
- }
- }
-
-
-
- viewer.scene.pointclouds.forEach(e=>{
- viewer.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()
- })
- }
-
- viewer.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)
- this.resetHighMap()
- this.hideHighMap()
- }
-
-
-
- /* 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=>{
- viewer.updateVisible(e, 'modeIsShowPanos', mode == 'showPanos', 1, mode == 'showPanos' ? 'add':'cancel') //
- }) */
-
-
- this.dispatchEvent({type:'endChangeMode',mode})
- //console.log('setModeSuccess: ' + mode)
- }else{
-
- //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){
-
- 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=>{
- viewer.updateVisible(pano, 'ifShowMarker', show, 1 )
- })
- //this.emit('markersDisplayChange', show)
- ifShowMarker = show
- }
-
- }
- })
- }
-
-
-
-
- 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 && 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)
- }
- getDirection(e) {
- if(!e){
- return viewer.scene.view.direction
- }else{
- return e = e ? e : (new THREE.Vector3).copy(Vectors.FORWARD),
- e.applyQuaternion(viewer.scene.getActiveCamera().quaternion)
- }
-
- }
- get position(){
- return this.viewer.scene.view.position.clone()
- }
-
-
- get visible(){
- return this._visible;
- }
- set visible(visible){
- if(this._visible === visible){
- return;
- }
- /* for(const image of this.panos){
- image.mesh.visible = visible && (this.currentPano == null);
- } */
- //this.sphere.visible = visible && (this.currentPano != null);
- this._visible = visible;
- this.dispatchEvent({
- type: "visibility_changed",
- panos: this,
- });
- }
-
-
-
- isAtPano(){//是否在某个漫游点上
- 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(){//取消当前已有的飞行准备,前提是相机还未移动
- Potree.Log('cancelFlyToPano')
- if(viewer.mainViewport.view.isFlying())return
- this.nextPano = null
- this.latestToPano = null
- //this.flying = false
- }
- flyToPano(toPano) { //飞向漫游点
- if(!toPano)return
- if(toPano instanceof Panorama){
- toPano = {pano: toPano}
- }
-
- if(!toPano.pano.enabled)return
-
- /* if(!this.currentPano){
- return this.focusPano(toPano)
- } */
-
- let done = (makeIt, disturb)=>{
- //console.log('flyToPano done ', toPano.pano.id, makeIt )
- if(makeIt || disturb) { // disturb已经开始飞行但中途取消
- toPano.callback && toPano.callback(makeIt)
- //this.flying = false
- this.cancelFlyToPano()
- this.updateClosestPano(this.closestPano,false) //飞行结束后取消点击漫游点时得到的closestPano
- }else{
- console.log('makeit fail')
- }
-
- this.dispatchEvent({type:'flyToPanoDone', makeIt})
- //this.dispatchEvent('cameraMoveDone')
- toPano.deferred && toPano.deferred.resolve(makeIt) //测量线截图时发现,resolve需要写在flying=false 后才行。
- }
- if(this.currentPano == toPano.pano && this.isAtPano() && !toPano.target && !toPano.quaternion ){
- this.dispatchEvent({type:'flyToPano', toPano})
- return done(true);
- }
- if(this.latestToPano && this.latestToPano != toPano){
- return done(false)
- }
-
- let target = toPano.target
- let easeName = toPano.easeName || 'easeInOutQuad' // 'easeInOutSine'//'easeOutSine'
-
- let config = Potree.config.displayMode[Potree.settings.displayMode]
- var pointcloudVisi = config.atPano.showPoint //viewer.scene.pointclouds[0].visible
-
-
- var pano = toPano.pano
- let T = Potree.config.transitionsTime
- let maxTime = this.isAtPano() ? T.panoToPanoMax : T.flyIn
- var duration = toPano.duration == void 0 ? (T.flyMinTime+Math.min(T.flytimeDistanceMultiplier * this.position.distanceTo(pano.position), maxTime)) : toPano.duration
- toPano.duration = duration
- //console.warn("flyto "+pano.id + ' duration: ' + duration )
-
- this.nextPano = pano
- this.latestToPano = toPano
- //this.flying = true //防止新的请求
- Potree.Log('flyToPano:'+pano.id + ' , duration:'+toPano.duration)
-
-
- {//不飞的话是否不要执行这段?
-
- let wait = ()=> {
- if(this.latestToPano != toPano)return Potree.Log('已经取消')//如果取消了
- setTimeout(()=>{
- if(this.latestToPano != toPano)return
- this.flyToPano(toPano)
- },1)
- this.removeEventListener('loadedDepthImg', wait)
- }
- if(!pano.depthTex && pano.pointcloud.hasDepthTex){ //需要用到depthTex计算neighbour
- this.addEventListener('loadedDepthImg', wait)
- return pano.loadDepthImg()
- }
-
- if(config.atPano.showSkybox || config.atPano.pointUsePanoTex){
-
- this.updateCube(this.currentPano, toPano.pano)
-
- if(this.checkAndWaitForPanoLoad(pano, toPano.basePanoSize || this.basePanoSize, wait)){
- return
- }
- }
- }
- viewer.updateVisible(this.cube,'showSkybox', config.atPano.showSkybox ) // this.cube.visible = config.atPano.showSkybox
- /* this.cube.visible && this.cube.material.setProjectedPanos(this.currentPano, pano, 0)
-
- if(config.transition.showPoint){
- viewer.scene.pointclouds.forEach(e=>{
- viewer.updateVisible(e, 'displayMode', true)
- })
-
- if(config.transition.pointUsePanoTex){
- let easeInOutRatio = pointcloudVisi ? 0.3 : 0
- viewer.scene.pointclouds.forEach(e=>{
- e.material.setProjectedPanos(this.currentPano, pano, 0, easeInOutRatio)
- })
- }
-
- } */
- if(config.transition.showPoint){
- viewer.scene.pointclouds.forEach(e=>{
- viewer.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()
- {
- toPano.duration = duration
- toPano.easeName = easeName
- this.beforeFlyToPano(toPano)
- }
-
-
-
-
- let fly = ()=>{
-
- this.dispatchEvent({type:'flyToPano', toPano})
- viewer.scene.view.setView({position:endPosition, target, quaternion:toPano.quaternion , duration,
- callback:()=>{
-
- if(!config.atPano.pointUsePanoTex){
- viewer.scene.pointclouds.forEach(e=>{
- e.material.stopProjectedPanos()
- })
- }
- //this.currentPano.exit()
- //pano.enter()
- this.currentPano = pano;
-
- this.nextPano = null;
- if(Potree.settings.displayMode == 'showPanos'){
- viewer.scene.pointclouds.forEach(e=>{
- viewer.updateVisible(e, 'displayMode',pointcloudVisi)
- })
- }
- done(true);
- //this.updateCube(this.currentPano)
- this.updateDepthTex(this.currentPano)
-
-
-
- }, onUpdate:(progress)=>{
- this.cube.material.uniforms.progress.value = progress
-
- viewer.scene.pointclouds.forEach(e=>{
- e.material.uniforms.progress.value = progress
- })
- },
- cancelFun:()=>{ done(false, true) },
- Easing:easeName
- })
-
- //duration > 0 && (this.flying = true) //再写一遍 防止cancel其他项目导致flying为false
-
-
- }
-
- if(Potree.settings.displayMode == 'showPanos'){
- setTimeout(fly, 40); //更新geo后缓冲
- }else{
- fly()
- }
-
- //console.log('flyToPano:', toPano.pano.id)
- }
- beforeFlyToPano(toPano){
- if(this.currentPano != toPano.pano) {
- if(Potree.settings.displayMode == 'showPanos'){
- this.resetHighMap()
- }
-
- this.smoothZoomTo(1, toPano.duration / 2);
- }
-
-
-
- }
- /* focusPano(toPano ){
- if(this.currentPano !== null){
- return this.flyToPano(toPano);
- }
- if(toPano instanceof Panorama){
- toPano = {pano: toPano}
- }
- let done = (makeIt)=>{
- toPano.deferred && toPano.deferred.resolve(makeIt)
- makeIt && toPano.callback && toPano.callback()
- }
-
- var pano = toPano.pano
- let config = Potree.config.displayMode[Potree.settings.displayMode]
- previousView = {
- //controls: this.viewer.controls,
- position: this.position,
- target: viewer.scene.view.getPivot(),
- };
- //this.viewer.setControls(this.viewer.orbitControls);
- this.viewer.orbitControls.doubleClockZoomEnabled = false;
- for(let image of this.panos){
- image.mesh.visible = false;
- }
- this.selectingEnabled = false;
-
- //console.warn("flyto "+pano.file.split('/').pop() )
- var dur = toPano.duration == void 0 ? 700 : toPano.duration
-
- if(config.atPano.showSkybox){
- if ( this.checkAndWaitForPanoLoad(pano, this.basePanoSize, ()=> {
- setTimeout( ()=>{
- this.focusPano(toPano)
- },1)
- })
- ) {
- return ;
- }
- }
-
-
-
- this.cube.visible = config.atPano.showSkybox
-
- //if(config.transition.showSkybox || config.transition.pointUsePanoTex){
- this.setProjectedPanos({
- progress:0,
- ifSkybox: this.cube.visible,
- ifPointcloud : config.atPano.pointUsePanoTex,
- pano0:pano,
- pano1:pano
- })
- //}
-
- let newCamPos = pano.position.clone()
- let target = newCamPos.clone().add(viewer.scene.view.direction)
-
-
- viewer.scene.view.setView( {position:newCamPos, target, duration:dur ,
- callback:()=>{//done
- //pano.enter()
- this.flying = false
-
- this.currentPano = pano;
- this.updateCube(this.currentPano)
- done(true)
- },onUpdate:(progress)=>{
-
- },
- cancelFun:()=>{this.flying = false}
- })
- this.flying = true
- this.elUnfocus && (this.elUnfocus[0].style.display = "");
- }
- unfocus(o={}){
- this.selectingEnabled = true;
- Potree.settings.displayMode = 'showPointCloud'
-
- if(!this.currentPano && !o.position){
- return;
- }
-
- this.cube.visible = false
-
- viewer.orbitControls.doubleClockZoomEnabled = true;
-
-
- viewer.scene.view.setView($.extend({
- position: previousView.position,
- target:previousView.target,
- duration:500
- },o,{
- callback:()=>{ //done
- for(let pano of this.panos){
- pano.mesh.visible = true;
- //pano.marker.material.depthTest = true
- }
- o.callback && o.callback()
- }
- ,
- cancelFun:()=>{this.flying = false},
- }))
- //this.currentPano.exit()
- this.currentPano = null;
- this.elUnfocus && (this.elUnfocus[0].style.display = "none");
- } */
- updateCube(pano0, pano1){
-
- if(Potree.settings.displayMode != 'showPanos')return
- if(!viewer.scene.pointclouds.some(e=>!e.hasDepthTex)) return this.updateCube2(pano0, pano1) //都hasDepthTex的话
-
-
- let f = (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.scale.copy(size)
- this.cube.position.copy(center)
-
- }
-
- let getDis = (bound1, bound2)=>{ //获取bound1边界到bound2边界距离
- if(bound1.intersectsBox(bound2))return 0
- let center1 = bound1.getCenter(new THREE.Vector3)
- let center2 = bound2.getCenter(new THREE.Vector3)
- let dis = center1.distanceTo(center2)
- let dis1 = bound1.distanceToPoint(center2)
- let dis2 = bound2.distanceToPoint(center1)
- return dis1 + dis2 - dis
- }
-
- if(pano1){//过渡
- if(pano0.pointcloud == pano1.pointcloud){//同一个数据集内的过渡
- f(pano0.pointcloud.bound)
- //console.log('updateCube1' )
- }else{//非同一个数据集内的过渡
- let bound = pano0.pointcloud.bound.clone().union(pano1.pointcloud.bound)
- if(getDis(pano0.pointcloud.bound, pano1.pointcloud.bound) < 100){
- f(bound)
- }else{//如果两个数据集boundingbox距离大于这个距离,扩大一下,防止精度问题导致失真//对很远的数据集似乎没有什么用
- let size = bound.getSize(new THREE.Vector3)
- let max = Math.max(size.x, size.y, size.z)
- size.set(max,max,max)
- f(bound, size)
- //console.log('updateCube2', size)
- //far可能要修改下
- }
- }
- }else{
- f(pano0.pointcloud.bound) //假定一个数据集不会太大,否则会造成失真,且bump时移动距离看起来很小。或者可以考虑用固定大小
- //console.log('updateCube3' )
- }
-
- }
-
-
- /* updateCube(pano0, pano1){ //垂直上不分段、 每个pano只有5个方向的版本
- if(Potree.settings.displayMode != 'showPanos')return
- console.log('updateCube',pano0.id, pano1&&pano1.id)
-
- let f = (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.scale.copy(size)
- this.cube.position.copy(center)
-
- }
-
-
- this.cube.geometry.dispose();
-
- if(pano1){//过渡
-
- let add = (pano, dir, )=>{
-
- let minZ, maxZ
- minZ = pano.floorPosition.z
-
- {//天花板高度值
- //用三个间隔120度散开,和中心垂直线成一定夹角的三个向量去求 最高高度 (不求平均的原因:万一是0不好算)
- let rotMat = new THREE.Matrix4().makeRotationX(THREE.Math.degToRad(40))// 角度不能小于天花板中空的半径,大概就是0.2*Math.PI=36度
- let dir1 = new THREE.Vector3(0,0,1).applyMatrix4(rotMat)
- let rotMat1 = new THREE.Matrix4().makeRotationZ(Math.PI*2 / 3);
- let rotMat2 = new THREE.Matrix4().makeRotationZ(-Math.PI*2 / 3);
-
- let dir2 = dir1.clone().applyMatrix4(rotMat1)
- let dir3 = dir1.clone().applyMatrix4(rotMat2)
-
- let zs = [dir1,dir2,dir3].map(dir_=>{
- let intersect = this.depthSampler.sample( {dir: dir_}, pano, true )
- let z = intersect ? intersect.location.z : pano.position.z
- return z
- })
- zs.sort((a,b)=>{return b-a});//得最大值
- maxZ = zs[0]
-
- }
-
-
- const angle = Math.PI/6 //每次转30度
-
- let getDir = (angle_)=>{
- let rotMat = new THREE.Matrix4().makeRotationZ(angle_)
- return dir.clone().applyMatrix4(rotMat)
- }
-
- let dirs = [getDir(angle*2), getDir(angle),getDir(angle), dir.clone(), getDir(-angle), getDir(-angle*2)]; //总共五个方向,夹角总和180度
- dirs.forEach(dir=>{//获取在这个方向上和墙体intersect的最远距离,使用中、上、下三个方向
- //上下分别45度 刚好就是
- let dir0 = dir.clone();// 水平方向
- let dir1 = dir.clone().setZ(1).normalize() //上45度方向
- let dir2 = dir.clone().setZ(-1).normalize() // 下45度方向
-
- let disArr = [dir0,dir1,dir2].map(dir_ =>{
- let intersect = this.depthSampler.sample( {dir: dir_}, pano, true )
-
- let projectLen = intersect.distance ? dir_.dot(dir)*intersect.distance : 0 //得到project在dir的长度
-
- return projectLen
- })
-
- disArr.sort((a,b)=>{return b-a});//得最大值
- dir.multiplyScalar( disArr[0] );//得到水平方向上的最远向量
-
- [minZ,maxZ].forEach(z=>{ //0-9
-
- posArr.push(pano.position.clone().setZ(z).add(dir))
-
- })
-
- });
- [minZ,maxZ].forEach(z=>{ // 10,11
- posArr.push(pano.position.clone().setZ(z))
- })
-
- }
-
-
-
- let posArr = [];
- let faceArr = [[0,1,2],[1,2,3], [2,3,4],[3,4,5], [4,5,6],[5,6,7], [6,7,8],[7,8,9], //外侧四个面
- [0,2,10],[2,4,10],[4,6,10],[6,8,10],//底部扇形
- [1,3,11],[3,5,11],[5,7,11],[7,9,11],//顶部扇形
- ]
-
-
-
-
- //两点连线的水平向量
- let vec = new THREE.Vector3().subVectors(pano0.position, pano1.position).setZ(0).normalize()
-
- add(pano0, vec)
- add(pano1, vec.negate())
-
-
- let faceArr2 = faceArr.map(face=>face.map(i=>i+12))//加上pano2的部分
- faceArr.push(...faceArr2)
- //加上连接的部分,四个面
- faceArr.push([0,1, 8+12],[1, 9+12, 8+12], [8,9,0+12],[9,1+12,0+12],
- [0,8,0+12],[0,0+12,8+12], [1,9,1+12],[1,1+12,9+12],
- )
-
- let geo = MeshDraw.createGeometry(posArr, faceArr)
- this.cube.geometry = geo
- this.cube.scale.set(1,1,1);
- this.cube.position.set(0,0,0)
-
-
- }else{
- if(this.hasUpdateOnePano)return
- this.hasUpdateOnePano = true
- this.cube.geometry = new THREE.BoxBufferGeometry(1,1,1,1)
- f(pano0.pointcloud.bound)
- }
- } */
-
-
- /* updateCube(pano0, pano1){//增加细分的版本,且垂直方向上也分多个
- if(Potree.settings.displayMode != 'showPanos')return
- console.log('updateCube',pano0.id, pano1&&pano1.id)
-
- let f = (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.scale.copy(size)
- this.cube.position.copy(center)
-
- }
-
-
- this.cube.geometry.dispose();
-
- if(pano1){//过渡
- let count1, count2;
-
-
- let panoIndex = 0
- let add = (pano, dir )=>{
- let getPI = function(index, panoIndex_){
- if(panoIndex_ == void 0) panoIndex_ = panoIndex
- return (count1 * count2 + 2 ) * panoIndex_ + index + 2
- }
- let minZ, maxZ
- minZ = pano.floorPosition.z
-
- {//天花板高度值
- //用三个间隔120度散开,和中心垂直线成一定夹角的三个向量去求 最高高度 (不求平均的原因:万一是0不好算)
- let rotMat = new THREE.Matrix4().makeRotationX(THREE.Math.degToRad(40))// 角度不能小于天花板中空的半径,大概就是0.2*Math.PI=36度
- let dir1 = new THREE.Vector3(0,0,1).applyMatrix4(rotMat)
- let rotMat1 = new THREE.Matrix4().makeRotationZ(Math.PI*2 / 3);
- let rotMat2 = new THREE.Matrix4().makeRotationZ(-Math.PI*2 / 3);
-
- let dir2 = dir1.clone().applyMatrix4(rotMat1)
- let dir3 = dir1.clone().applyMatrix4(rotMat2)
-
- let zs = [dir1,dir2,dir3].map(dir_=>{
- let intersect = this.depthSampler.sample( {dir: dir_}, pano, true )
- let z = intersect ? intersect.location.z : pano.position.z
- return z
- })
- zs.sort((a,b)=>{return b-a});//得最大值
- maxZ = zs[0]
-
- let min = pano.position.z + 1
- if(maxZ < pano.position.z + 0.04){//户外
- maxZ = pano.position.z + 50
- }
- maxZ = Math.max(min,maxZ)
- console.log(pano.id, 'maxZ:',maxZ )
- console.log(pano.id, 'minZ:',minZ )
- }
- [maxZ, minZ ].forEach(z=>{
- posArr.push(pano.position.clone().setZ(z))
- })
-
- const angle = Math.PI/8
-
- let getDir = (angle_)=>{
- let rotMat = new THREE.Matrix4().makeRotationZ(angle_)
- return dir.clone().applyMatrix4(rotMat)
- }
-
- let dirs = [ getDir(angle*4), getDir(angle*3), getDir(angle*2), getDir(angle), dir.clone(), getDir(-angle) , getDir(-angle*2), getDir(-angle*3), getDir(-angle*4) ]; // 夹角总和180度
- count1 = dirs.length
- dirs.forEach((dir, index)=>{//获取在这个方向上和墙体intersect的最远距离,使用中、上、下三个方向
-
- let dirs_ = [
-
- dir.clone().setZ(Math.tan(THREE.Math.degToRad(30))).normalize(),
- dir.clone().setZ(Math.tan(THREE.Math.degToRad(15))).normalize(),
- dir.clone(), // 水平方向
- dir.clone().setZ(-Math.tan(THREE.Math.degToRad(15))).normalize(),
- dir.clone().setZ(-Math.tan(THREE.Math.degToRad(30))).normalize(),
-
-
- ];
- count2 = dirs_.length
- dirs_.forEach((dir_, i) =>{
- let intersect = this.depthSampler.sample( {dir: dir_}, pano, true )
- let location
- if(!intersect){ //超级远
- let distance = 100
- location = dir_.clone().multiplyScalar(distance).add(pano.position)
- intersect = {distance,location}
- }
- //intersect.distance
- location = intersect.location.clone()
- let shouldZ// = THREE.Math.clamp(intersect.location.z, minZ, maxZ);
- let needShrink = false
-
- if(i == 0){//最上方的点高度直接等于天花板
- shouldZ = maxZ
- if(location.z<maxZ)location.z = maxZ
- else needShrink = true
- }else if(i == count2-1){//最下方的点高度直接等于地板
- shouldZ = minZ
- if(location.z>minZ)location.z = minZ
- else needShrink = true
- }
- if(needShrink ){//需要在保持dir_不变的情况下修改z
- let len = (shouldZ - pano.position.z) / (intersect.location.z - pano.position.z) * intersect.distance
- location = dir_.clone().multiplyScalar(len).add(pano.position)
- }
-
- posArr.push(location)
-
- if(index!=0 && i!=0){//加入一块四方面
- let curIndex = getPI(count2 * index + i);
-
- faceArr.push([curIndex-1, curIndex-count2-1, curIndex-count2],
- [curIndex-1, curIndex, curIndex-count2])
- }
-
- })
-
- if(index!=0){
- let top = -2;
- let btm = -1
- faceArr.push([getPI(count2*(index-1) ), getPI(count2*index ), getPI(top) ])//天花板扇形
- faceArr.push([getPI(count2*index-1), getPI(count2*(index+1)-1), getPI(btm) ] )//地板扇形
- }else{
- //加入和另一个pano连接的其中一个侧边
- let panoIndex2 = (panoIndex + 1) % 2;
- for(let i=1;i<count2;i++){
- faceArr.push([getPI(i-1), getPI(i), getPI((count1-1)*count2 +i, panoIndex2)],
- [getPI(i-1), getPI((count1-1)*count2+i , panoIndex2) , getPI((count1-1)*count2+i-1 ,panoIndex2)])
- }
- faceArr.push([getPI(0), getPI((count1-1)*count2), getPI(0, panoIndex2)])//加入顶部的一半
- faceArr.push([getPI(count2-1), getPI(count1*count2-1), getPI(count2-1, panoIndex2)])//加入底部的一半
-
-
- }
-
- });
- panoIndex ++
-
- }
-
-
-
- let posArr = [];
- let faceArr = []
-
-
-
- //两点连线的水平向量
- let vec = new THREE.Vector3().subVectors(pano0.position, pano1.position).setZ(0).normalize()
-
- add(pano0, vec)
- add(pano1, vec.negate())
-
-
-
- let geo = MeshDraw.createGeometry(posArr, faceArr)
- this.cube.geometry = geo
- this.cube.scale.set(1,1,1);
- this.cube.position.set(0,0,0)
-
-
- }else{
- this.cube.geometry = new THREE.BoxBufferGeometry(1,1,1,1)
- f(pano0.pointcloud.bound)
- }
- } */
-
-
-
- updateCube3(pano0, pano1){//增加细分的版本,且垂直方向上取中位数... 侧边只有一条
- if(Potree.settings.displayMode != 'showPanos' || pano0 == pano1
- || this.cubePanos.includes(pano0) && this.cubePanos.includes(pano1)
- ) return
-
- this.cubePanos = [pano0, pano1]
-
- //console.log('updateCube',pano0.id, pano1&&pano1.id)
-
- let f = (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.scale.copy(size)
- this.cube.position.copy(center)
-
- }
-
-
- this.cube.geometry.dispose();
-
- if(pano1){//过渡
-
-
- const half = pano0.pointcloud.hasDepthTex && pano0.pointcloud.hasDepthTex ? ( browser.isMobile() ? 3 : 6 ) : (browser.isMobile() ? 2 : 3) //自行输入 (点云计算的慢,还不准)
- let count1 = 2*half//偶数个 dir 个数
-
- //奇数个的好处:在窄空间内能探测到最远距离,坏处是前方有尖角。偶数个的坏处就是可能检测距离太近。
- let panoIndex = 0
-
- let 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
- })
- }
- }
- let getDir = (angle_, vec)=>{ //旋转获得水平向量
- let rotMat = new THREE.Matrix4().makeRotationZ(angle_)
- return vec.clone().applyMatrix4(rotMat)
- }
- let getFar = (dir, pano, origin)=>{//获取在这个方向上和墙体intersect的最远距离
- let r = (pano.ceilZ - pano.floorPosition.z) * 0.14 // 高度约小,角度越小
- let getAngle = (deg)=>{
- deg *= r
- deg = THREE.Math.clamp(deg, 1, 80);
- return deg
- }
- let dirs_ = [
- //注意:角度太大会碰到天花板或地板,越远越容易碰到, 在地下停车场就会伸展不开。 户外时需要更多向上的方向,所以上方向多一个
- dir.clone().setZ(Math.tan(getAngle(30))).normalize(),
- dir.clone().setZ(Math.tan(getAngle(7))).normalize(),
- dir.clone(), // 水平方向
- dir.clone().setZ(-Math.tan(getAngle(5))).normalize(),
- //dir.clone().setZ(-Math.tan(THREE.Math.degToRad(30))).normalize(),
- ];
-
- let max = 50
- let count2 = dirs_.length
- let disArr = dirs_.map((dir_, i) =>{
- let intersect = getIntersect(pano, dir_, origin)
-
- let projectLen = intersect && intersect.distance ? dir_.dot(dir)*intersect.distance : max //得到project在dir的长度
-
- return projectLen
- })
- 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 add = (pano, vec )=>{
- let getPI = function(index, panoIndex_){
- if(panoIndex_ == void 0) panoIndex_ = panoIndex
- return (count1*2 + 2 ) * panoIndex_ + index + 2
- }
- let minZ, maxZ
- minZ = pano.floorPosition.z
-
- if(pano.ceilZ != void 0){
- maxZ = pano.ceilZ
- }else{//天花板高度值
- //用三个间隔120度散开,和中心垂直线成一定夹角的三个向量去求 最高高度 (不求平均的原因:万一是0不好算)
- let rotMat = new THREE.Matrix4().makeRotationX(THREE.Math.degToRad(40))// 角度不能小于天花板中空的半径,大概就是0.2*Math.PI=36度
- let dir1 = new THREE.Vector3(0,0,1).applyMatrix4(rotMat)
- let rotMat1 = new THREE.Matrix4().makeRotationZ(Math.PI*2 / 3);
- let rotMat2 = new THREE.Matrix4().makeRotationZ(-Math.PI*2 / 3);
-
- let dir2 = dir1.clone().applyMatrix4(rotMat1)
- let dir3 = dir1.clone().applyMatrix4(rotMat2)
-
- let zs = [dir1,dir2,dir3].map(dir_=>{
- let intersect = getIntersect(pano, dir_)
-
- let z = intersect ? intersect.location.z : pano.position.z+50
- return z
- })
- zs.sort((a,b)=>{return b-a});//得最大值
- maxZ = zs[0]
-
- let min = pano.position.z + 1
- maxZ = Math.max(min,maxZ)
- pano.ceilZ = maxZ
- //console.log(pano.id, 'maxZ:',maxZ )
- //console.log(pano.id, 'minZ:',minZ )
- }
- [maxZ, minZ ].forEach(z=>{
- posArr.push(pano.position.clone().setZ(z))
- })
-
- const angle = Math.PI/(count1-1)
-
-
- //在画面上线条从左往右数
- let dirs = [];
- for(let i=0;i<count1;i++){
- dirs.push(getDir(Math.PI/2-i*angle, vec))//正的在左边
- }
-
-
-
- let sideDis = []
- dirs.forEach((dir, index)=>{
- let dis = getFar(dir, pano);
- if(index == 0 || index == count1-1){
- sideDis.push(dis)
- }
- dir.multiplyScalar( dis );
-
- [maxZ,minZ].forEach(z=>{
- posArr.push(pano.position.clone().setZ(z).add(dir))
- })
-
- if(index!=0){//加入一块四方面
- let m = index*2
- faceArr.push([getPI(m), getPI(m-1), getPI(m-2)],
- [getPI(m), getPI(m+1), getPI(m-1)])
-
- let top = -2;
- let btm = -1
- faceArr.push([getPI(m), getPI(m-2), getPI(top) ])//天花板扇形
- faceArr.push([getPI(btm), getPI(m-1), getPI(m+1) ] )//地板扇形
-
- }
- });
-
-
-
-
- let panoIndex2 = (panoIndex + 1) % 2;
- //let m = (count1-1)*2
- /* faceArr.push([getPI(0), getPI(1), getPI(count1*2-1, panoIndex2)],
- [getPI(0), getPI(count1*2-1,panoIndex2) , getPI(count1*2-2,panoIndex2)])
-
- faceArr.push([getPI(0, panoIndex2), getPI(count1*2-2), getPI(0)])//加入顶部的一半
- faceArr.push([getPI(1), getPI(count1*2-1), getPI(1, panoIndex2)])//加入底部的一半 */
-
-
-
- //加入和另一个pano连接
- let sideMid = count1*4+4; //侧边点start
- //侧边的一半
- faceArr.push([getPI(0), getPI(1), sideMid+panoIndex*2],
- [sideMid+panoIndex*2, getPI(1) , sideMid+panoIndex*2+1 ],
- [getPI(count1*2-2), sideMid+panoIndex2*2+1, getPI(count1*2-1)],
- [getPI(count1*2-2), sideMid+panoIndex2*2, sideMid+panoIndex2*2+1 ]
- )
-
- faceArr.push([getPI(0), sideMid+panoIndex2*2, getPI(count1*2-2)],
- [getPI(0),sideMid+panoIndex*2, sideMid+panoIndex2*2]
- )//加入顶部的一半
- faceArr.push([getPI(count1*2-1), sideMid+panoIndex2*2+1, getPI(1)],
- [sideMid+panoIndex2*2+1, sideMid+panoIndex*2+1, getPI(1)]
- )//加入底部的一半
-
-
-
- panoIndex ++
- return sideDis;
- }
-
- let addSide = ()=>{//两个漫游点间两边各加一条侧线,为了适应四方形房间漫游点在对角方向的那种情况
- //侧边为了取中点,没办法用全景图获取了,用点云
- let sideMaxZ = (pano0.ceilZ + pano1.ceilZ)/2
- let sideMinZ = (pano0.floorPosition.z+pano1.floorPosition.z)/2;
-
- let sideDis_ = [(sideDis0[0] + sideDis1[1])/2, (sideDis0[1] + sideDis1[0])/2];
- let sideDis = [Math.min(sideDis0[0] , sideDis1[1]), Math.min(sideDis0[1] , sideDis1[0])]//
-
- let mid = new THREE.Vector3().addVectors(pano0.position, pano1.position).multiplyScalar(0.5)
- let sideDirs = [getDir(-Math.PI/2, vec), getDir(Math.PI/2, vec)]
-
- if(pano0.pointcloud.hasDepthTex && pano0.pointcloud.hasDepthTex){
- let panos = [pano0,pano1]
- let vecs = [vec.negate(), vec]
- let axis = [[-1,1],[1,-1]]
- let dis2d = new THREE.Vector2().subVectors(pano0.position, pano1.position).length()//水平上的距离
- let angles = [THREE.Math.degToRad(45), THREE.Math.degToRad(60)]
- sideDirs.forEach((dir, index0)=>{
- let disToSides = []
- panos.forEach((pano,index)=>{
- let dirs = [getDir(axis[index0][index]*angles[0], vecs[index]), getDir(axis[index0][index]*angles[1], vecs[index])];//一侧的若干角度
- dirs.forEach((dir_,i)=>{
- let dis1 = getFar(dir_, pano);
- //dir_.multiplyScalar( dis1 );
- let disToPano2d = dis1 * Math.cos(angles[i])
- if(disToPano2d<dis2d){//超过的话都到另一半pano的半圆了,不计入
- let disToSide = dis1 * Math.sin(angles[i])
- disToSides.push(disToSide)
- }
- })
- })
- let disToSide
- if(disToSides.length){
- disToSides.sort((a,b)=>{return b-a});//从大到小
- disToSide = disToSides[0]
- console.log('disToSides', index0, disToSides)
- }else{
- disToSide = sideDis[index0]
- }
- dir.multiplyScalar( disToSide );
-
- [sideMaxZ,sideMinZ].forEach(z=>{
- posArr.push(mid.clone().setZ(z).add(dir)) //是直接使用最长dis的那个intersect点好还是mid
- })
- })
-
- }else{
-
- sideDirs.forEach((dir_ ,index)=>{
- let dis = getFar(dir_, null, mid);
- dir_.multiplyScalar( /* sideDis_[index] */ Math.max(dis, sideDis[index]) );
-
-
- [sideMaxZ,sideMinZ].forEach(z=>{
- posArr.push(mid.clone().setZ(z).add(dir_))
- })
- })
- }
- }
-
- let posArr = [];
- let faceArr = []
-
-
-
- //两点连线的水平向量
- let vec = new THREE.Vector3().subVectors(pano0.position, pano1.position).setZ(0).normalize()
- let sideDis0 = add(pano0, vec)
- let sideDis1 = add(pano1, vec.negate())
- addSide()
-
-
- //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)
-
-
- //this.cube.scale.set(100,100,100);
- //this.cube.position.copy(pano1.position).multiplyScalar(-100)
- }else{
- this.cube.geometry = new THREE.BoxBufferGeometry(1,1,1,1)
- f(pano0.pointcloud.bound)
- }
- }
-
-
-
-
- updateCube2(pano0, pano1){//增加细分的版本,且垂直方向上取中位数 侧边多条
- if(Potree.settings.displayMode != 'showPanos' || pano0 == pano1
- || this.cubePanos.includes(pano0) && this.cubePanos.includes(pano1)
- ) return
-
- this.cubePanos = [pano0, pano1]
-
- //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)
- }
-
-
- 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){//过渡
-
- if(pano0.pointcloud != pano1.pointcloud){ //距离太远的数据集,过渡会畸变。所以扩大skybox
- let dis = pano0.position.distanceTo(pano1.position)
- if(dis > 100){
- 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)
- return useBound(bound, size)
- }
- }
-
-
- const half = pano0.pointcloud.hasDepthTex && pano0.pointcloud.hasDepthTex ? 6 : (browser.isMobile() ? 2 : 3) //自行输入 (点云计算的慢,还不准)
- let count1 = 2*half//偶数个 每个pano向 外dir 个数
- //奇数个的好处:在窄空间内能探测到最远距离,坏处是前方有尖角。偶数个的坏处就是可能检测距离太近。
-
- //let panoIndex = 0
-
- let 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
- })
- }
- }
- let getDir = (angle_, vec)=>{ //旋转获得水平向量
- let rotMat = new THREE.Matrix4().makeRotationZ(angle_)
- return vec.clone().applyMatrix4(rotMat)
- }
- let getFar = (dir, pano, origin)=>{//获取在这个方向上和墙体intersect的距离
- //在垂直方向上分出多个方向,取一个最可能的接近真实的距离
- let maxH = 40, minH = 2, height = pano.ceilZ - pano.floorPosition.z, minR = 0.5, maxR = 2
- //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 getZ = (deg)=>{
- deg *= r
- deg = THREE.Math.clamp(deg, 1, 80);
- return Math.tan(THREE.Math.degToRad(deg))
- }
- let dirs_ = [
- //注意:角度太大会碰到天花板或地板,越远越容易碰到, 在地下停车场就会伸展不开。 户外时需要更多向上的方向,所以上方向多一个
- dir.clone().setZ(getZ(30)).normalize(),
- dir.clone().setZ(getZ(15)).normalize(),
- dir.clone().setZ(getZ(7)).normalize(),
- dir.clone(), // 水平方向
- dir.clone().setZ(-getZ(5)).normalize(),
- //dir.clone().setZ(-Math.tan(THREE.Math.degToRad(30))).normalize(),
- ];
-
- let max = 50
- let count2 = dirs_.length
- let disArr = dirs_.map((dir_, i) =>{
- let intersect = 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 = []
-
- let addPos = (pano, vec )=>{//添加这个pano这一侧向外半圆的顶点
- //添加pano位置对应的最高点最低点:
- let minZ, maxZ
- minZ = pano.floorPosition.z
-
- if(pano.ceilZ != void 0){
- maxZ = pano.ceilZ
- }else{//天花板高度值
- //用三个间隔120度散开,和中心垂直线成一定夹角的三个向量去求 最高高度 (不求平均的原因:万一是0不好算)
- let rotMat = new THREE.Matrix4().makeRotationX(THREE.Math.degToRad(40))// 角度不能小于天花板中空的半径,大概就是0.2*Math.PI=36度
- let dir1 = new THREE.Vector3(0,0,1).applyMatrix4(rotMat)
- let rotMat1 = new THREE.Matrix4().makeRotationZ(Math.PI*2 / 3);
- let rotMat2 = new THREE.Matrix4().makeRotationZ(-Math.PI*2 / 3);
-
- let dir2 = dir1.clone().applyMatrix4(rotMat1)
- let dir3 = dir1.clone().applyMatrix4(rotMat2)
- let skyHeight = 50
- let zs = [dir1,dir2,dir3].map(dir_=>{
- let intersect = getIntersect(pano, dir_)
- let z = intersect ? intersect.location.z : pano.position.z+skyHeight //没有intersect代表可能是天空
- return z
- })
- zs.sort((a,b)=>{return b-a});//得最大值 (不用中位数的原因:在屋檐处,如果仅有一个intersect是天空,因到了室外所以也用天空高度)
- maxZ = zs[0]
-
- let min = pano.position.z + 1 // 防止意外太低
- maxZ = Math.max(min,maxZ)
- pano.ceilZ = maxZ
- //console.log(pano.id, 'maxZ:',maxZ )
- //console.log(pano.id, 'minZ:',minZ )
- }
- [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。有可能是拍摄的人、或者杆子、树
- const maxRatio = 8
- /* 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 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
- while(j>start && dirs2[i].dis / dirs2[j].dis > maxRatio){
- j--
- }
- let count = i-j
- if(count > 1 && (count == 2 || computeWidth(j,i)<minWidth)){//若只有一个不用判断宽度直接修改,count == 2 即只有一个
- 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 midMaxZ = (pano0.ceilZ + pano1.ceilZ)/2
- let midMinZ = (pano0.floorPosition.z+pano1.floorPosition.z)/2;
- let mid = new THREE.Vector3().addVectors(pano0.position, pano1.position).multiplyScalar(0.5)
-
- /* let sideDis_ = [(sideDis0[0] + sideDis1[1])/2, (sideDis0[1] + sideDis1[0])/2];
- let sideDis = [Math.min(sideDis0[0] , sideDis1[1]), Math.min(sideDis0[1] , sideDis1[0])]//
- */
-
-
- 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 angles = [THREE.Math.degToRad(40), THREE.Math.degToRad(70)] //正的在左边 尽量能够平分中间这段墙体
- axis.forEach((axis_, index0)=>{
- let disToSides = []
- let accordingPano = index0 == 0 ? pano0 : pano1; //根据离该点在vec方向上的距离顺序来存顶点
- panos.forEach((pano,index)=>{
- let dirs = [getDir(axis_[index]*angles[0], vecs[index]), getDir(axis_[index]*angles[1], 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_})
- }
- })
- })
-
-
- sideCount[index0] = disToSides.length //记录侧边个数
-
- 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)
-
-
- disToSides.forEach(e=>{//求z
- let ratio = e.disToPano2d / dis2d
- let r = accordingPano == pano0 ? (1-ratio) : ratio
- let sideMaxZ_ = pano0.ceilZ * r + pano1.ceilZ * (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
- })
-
- })
-
- }
- })
-
- }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); //直接从中点求两侧的距离
- 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)
-
-
- //this.cube.scale.set(100,100,100);
- //this.cube.position.copy(pano1.position).multiplyScalar(-100)
- }else{
-
- useBound(getPanoBound(pano0))
- }
- }
-
- /*
- 注: 修改skybox,若不准的话,会遮住其他mesh,比如marker。尤其在没有深度贴图时。
-
-
- */
- /* updateCube(params){
- let size = params.boundSize
- this.cube.scale.set(Math.max(size.x, HighMapCubeWidth), Math.max(size.y, HighMapCubeWidth), Math.max(size.z, HighMapCubeWidth) )
- this.cube.position.copy(params.center)
-
- } */
- 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、左右方向移动镜头’ 都改为移动镜头。 因为这里无法判断左右离壁距离。
-
- }
- /* load(pano, ){
- return new Promise(resolve => {
- let texture = texLoader.load(pano.file, resolve);
- texture.wrapS = THREE.RepeatWrapping;
- texture.repeat.x = -1;
- texture.flipY = false//add
- pano.texture = texture;
-
- //add
- texture.wrapS = texture.wrapT = THREE.ClampToEdgeWrapping;
- texture.minFilter = THREE.LinearFilter;
- texture.magFilter = THREE.LinearFilter;
- texture.generateMipmaps = true;
-
- });
- } */
- flyToPanoClosestToMouse() {
- /* if (Date.now() - this.mouseLastMoveTime > 50) {
- //this.intersect = this.getMouseIntersect();
- this.intersect && this.updateClosestPano(this.intersect);
- } */
-
- 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
- });
-
- }
- var direction = this.viewer.inputHandler.getMouseDirection().direction;
- this.flyDirection(direction)
- }
- flyDirection(direction, option1, option2) {
- var deferred = $.Deferred();
- //this.history.invalidate();
- var panoSet = this.closestPanoInDirection(direction, option1, option2);
- 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) {
- return this.rankedPanoInDirection(0, direction, option1, option2)
- }
- rankedPanoInDirection(t, direction, option1, option2){
- //此direction为mouseDirection,是否需要加上相机角度的权重
-
- var panoSet = {
- pano: null,
- candidates: [] //缓存顺序--如果需要打印的话
- };
- t || (t = 0);
- option1 = void 0 !== option1 ? option1 : .75;
- var o = option2 ? "angle" : "direction";
-
- var floor = viewer.modules.SiteModel.currentFloor;
- var entity = viewer.modules.SiteModel.inEntity;
- var getHeightDis = (pano)=>{
- if(floor && !floor.panos.includes(pano) && pano.position.z < this.position.z){ //若是上方的漫游点,就正常走。因为一般不会点击天花板。
- return this.position.z - pano.position.z
- }else{
- return 0
- }
- }
-
-
-
- var request = [//必要条件
- Images360.filters.inPanoDirection( this.position, direction, option1),
- //Images360.filters.isNeighbourPanoTo(this.currentPano),
- Images360.filters.not(this.currentPano),
- Images360.filters.isEnabled(),
-
- /* (pano)=>{ //防止不小心穿越地板到下一层, 尽量走楼梯,实在没有楼梯或楼梯漫游点稀疏的话就通过楼层按钮。
- let dis = getHeightDis(pano)
- //console.log('getHeightDis',pano.id,dis)
- if(dis < 3){//不能超过最大高度差( 最大高度差暂定为接近一层楼的高度。)(最好的解决方案是设置漫游可行)
- return true
- }else{
- return this.isNeighbour(this.currentPano, pano)
- }
- } */
- ]
-
-
- var list = [//决胜项目
- Images360.scoreFunctions.distanceSquared(this.position, 1 ),
-
- Images360.scoreFunctions[o]( this.position, direction,true),
-
- (pano)=>{
- let neighbour = this.isNeighbour(this.currentPano, pano)
- return neighbour ? directionFactor : 0;
- }
-
- /* (pano)=>{//尽量不穿越地板到下一层
- let dis = getHeightDis(pano)
- return -dis * directionFactor * 0.1;
- }, */
-
- /* (pano)=>{ //尽量在一个建筑内行走,这样不易穿墙
- if(entity && !entity.panos.includes(pano) ){
- return - directionFactor * 0.05; //- directionFactor * 0.2;
- }else{ //不能设置太高,否则会走不进大房间的小房间中,因为容易穿过小房间的一个门到另一个门外
- return 0
- }
- } */
- ];
- if(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);
-
- 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)
- }
-
- isNeighbour(pano0, pano1){//是否之间没有遮挡(在加载visibles之前,自己算) 最好pano0是currentPano
-
- if(!pano0 || !pano1)return
-
- let margin = 0.1;
-
- let map0 = this.neighbourMap[pano0.id];
- if(!map0){
- map0 = {}
- this.neighbourMap[pano0.id] = map0
- }
- let map1 = this.neighbourMap[pano1.id];
- if(!map1){
- map1 = {}
- this.neighbourMap[pano1.id] = map1
- }
- //三个方向 : position0到position1, position0到floorPosition1, position1到floorPosition0。 只要有一个满足ifNeighbour就为true
- //0能看到1不代表1能看到0; 但只要有一方能完全看到另一方,无论是position还是floorPosition都算是neighbor
-
- let ifNeighbour = map0[pano1.id] || map1[pano0.id]
-
- let getNeighbour = (mainPano, subPano, jumpStep1)=>{
- //暂时只判断到pano,不判断到marker的方向
- let dir = new THREE.Vector3().subVectors(subPano.position, mainPano.position).normalize();
-
- let dirPoints = []
- if(!jumpStep1){//跳过此步骤,因为之前算过不成功(虽然用另一个漫游点算的可能拍摄时间不同所以有概率不一样,如人走动)
- dirPoints.push([subPano.position, mainPano.position])
- }
- 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
- }
- }
-
- }
-
- //let usePointcloud = pano0.depthTex
-
- if(!ifNeighbour) {
- if(pano0.depthTex || pano1.depthTex){
-
- if(map0[pano1.id] == void 0 || map1[pano0.id] == void 0 ){
-
- let mainPano = pano0.depthTex ? pano0 : pano1;
- let subPano = pano0.depthTex ? pano1 : pano0;
- //let notPosNeighbor = false
- if(map0[pano1.id] == void 0 && pano0.depthTex){
- let is = getNeighbour(pano0, pano1)
- if(is){
- ifNeighbour = true
- }
- map0[pano1.id] = !!is
- }
-
- if(!ifNeighbour && map1[pano0.id] == void 0 && pano1.depthTex){
- let is = getNeighbour(pano1, pano0, !ifNeighbour)
- if(is){
- ifNeighbour = true
- }
- map1[pano0.id] = !!is
- }
-
- /* if(ifNeighbour){ //需要标记成全部true吗,不标记也能get到,但标记了更直观,不标记保留信息更多
- map0[pano1.id] = map1[pano0.id] = true
- } */
- }
- }else{
- //使用点云判断(有深度贴图时不会执行到这)
- ifNeighbour = !viewer.inputHandler.ifBlockedByIntersect(pano1.position, margin, true, pano0.position)
- console.log('使用点云判断')
- if(ifNeighbour){//点云模式下未加载的点云会判断为true
- 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/* THREE.Math.degToRad(40) */) * dis / 10, min, max )){//距离越远要求和视线角度越接近
- ifNeighbour = undefined //不确定
- }
- }
- map0[pano1.id] = map1[pano0.id] = ifNeighbour //写简单点
- }
- }
-
- return ifNeighbour
- }
- updateClosestPano(intersect, state) {//hover到的pano 大多数时候是null
-
- /*
- var pano
- if(this.isAtPano() ){ //为什么之前Panorama要加这个限制?
- if(intersect instanceof Panorama){
- pano = state ? intersect : null
- }else{
- return
- }
- }else{
- if(this.flying)return;
- 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);
- }
- */
-
-
- var pano
-
- if(intersect instanceof Panorama){
- pano = state ? intersect : null
- }else{
- if(this.isAtPano()){
- return
- }else{
- if(this.flying)return;
- 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
- }
-
-
- }
-
-
-
- update(){
- let {viewer} = this;
- /* if(currentlyHovered){
- currentlyHovered.material = sm;
- currentlyHovered = null;
- }
- if(this.selectingEnabled){
- this.handleHovering();
- } */
- if(this.tileDownloader.started){
-
- var vectorForwards = this.getTileDirection()
-
- //vectorForwards = vectorForwards[0].direction
-
- this.updateTileDownloader(tileArr, vectorForwards);
- this.updatePanoRenderer(vectorForwards)
- }
-
- this.updateZoomPano();
-
- }
-
-
-
-
-
-
- updateTileDownloader(t, vectorForward) {
- var i = this.nextPano || this.currentPano;
- if(i){
- this.tileDownloader.tilePrioritizer.updateCriteria(i, viewer.scene.view.position.clone() , vectorForward, t.length > 0 ? t : null),
- this.tileDownloader.processPriorityQueue = !0
- }
- }
-
-
- updatePanoRenderer(vectorForward) {
- var i = this.nextPano || this.currentPano;
- if(i){
- if (this.panoRenderer.hasQueuedTiles() && i) {
- this.panoRenderer.updateDirection(vectorForward);
- }
- }
-
- }
-
-
-
-
-
-
- //等待部分加载完
- checkAndWaitForTiledPanoLoad(pano, basePanoSize, callback1, callback2, progressCallback, iswait, isclear, l) {
-
- if (!pano) {
- console.error("Player.checkAndWaitForTiledPanoLoad() -> Cannot load texture for null pano.");
- }
-
- var vectorForward = this.getTileDirection()
-
-
- if (!pano.isLoaded(basePanoSize)) {
- iswait && viewer.waitForLoad(pano, function() {//发送loading
- return pano.isLoaded(basePanoSize)
- });
-
-
-
- /* var fov = {//test for direction 预加载的边缘有一丢丢不准确,尤其在相机倾斜时(4dkk也是)。
- hFov: cameraLight.getHFOVForCamera(viewer.scene.getActiveCamera() ),
- vFov: viewer.scene.getActiveCamera().fov
- }//原先是null,不要求方向 */
- var fov = null //若不为null的话,因为可能可见范围的tile下载过了从而无法触发下载,然后得不到下载成功的消息,怎么办
-
-
-
- pano.loadTiledPano(/* 1024 */ basePanoSize , vectorForward, fov, isclear, l, null).done(function(e, t) {
- callback1 && callback1(e, t)
- }
- .bind(this)).fail(function(msg) {
- callback2 && callback2(msg)
- }
- .bind(this)).progress(function(e, t, i) {
- progressCallback && progressCallback(e, t, i)
- }
- .bind(this));
- return !0;
- }
-
- }
- /* load(){//quickstart里的
-
- var lowSize = this.qualityManager.getPanoSize(PanoSizeClass.BASE),
- highSize = this.qualityManager.getPanoSize(PanoSizeClass.STANDARD),
- d = cameraLight.getHFOVForCamera(this.quickStartcamera, $('#player').width(), $('#player').height()),
- p = this.quickStartcamera.fov,
- r = Vectors.FORWARD.clone().applyQuaternion(this.view.quaternion)
-
- var promise1 = this.view.pano.loadTiledPano(highSize, r, {
- hFov: d,
- vFov: p
- }, !1, !1 , !0 )
- var promise2 = this.view.pano.loadTiledPano(lowSize, r.clone().negate(), null, !1, !1, !0)
-
- this.loadPromise = this.pano.hasVideo ? promise2 : promise1;
- //this.loadPromise = promise1;
-
- }
- */
- fitPanoTowardPoint(o){ //寻找最适合的点位
- var point = o.point, //相机最佳位置
- target = o.target, //实际要看的位置
- require = o.require || [],
- rank = o.rank || [],
- force = o.force,
- getAll = o.getAll,
- bestDistance = o.bestDistance || 0
- let camera = viewer.scene.getActiveCamera()
- if(target){
- var vec = new THREE.Vector3().subVectors(target,point).normalize()
- }
-
-
- //if(o.floor)require.push(Panorama.filters.atFloor(o.floor))
-
-
- 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 bestDisSquared = bestDistance * bestDistance
- rank.push((pano)=>{
- let dis1 = Math.abs(pano.position.distanceToSquared(point) - bestDisSquared); //距离最佳位置
- if(!target){
- return -dis1
- }else{
- let dis2 = pano.position.distanceToSquared(target); //距离目标点
- let vec2 = new THREE.Vector3().subVectors(target,pano.position).normalize()
- let cos = vec.dot(vec2)
- let result = (- dis1 - Math.pow(dis2 , 1.5)) / (cos + 2) // cos+2是为了调整到1-3, 尽量贴近最佳位置的角度;
- //console.log(pano.id, dis1,dis2, cos, result)
- return result
- }
- },(pano)=>{
- if(pano.depthTex && o.checkIntersect){ //没加载好的话,不管了
- let intersect = viewer.inputHandler.ifBlockedByIntersect(target, 0.1 , null, null, null, pano)
- if(intersect){
- //console.log('intersected', pano.id )
- return -10000
- }else return 0
- }else return 0
- })
-
- /* var temp = {position:point}
- rank.push(Panorama.scoreFunctions.distanceSquared(temp, -2)); */
-
- var g = Common.sortByScore(this.panos, require, rank);
-
- if(getAll)return g;
- return g && g.length > 0 && g[0].item
-
- }
- //---------------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 = 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'] )
- }
-
-
- /* zoomDefault{
- this.zoomTo(1, !0)
- }
- smoothZoomToDefault(e, t) {
- var i, n = this.zoomLevel,
- r = function(e) {
- e > 1 && (e = 1),
- i = n * (1 - e) + e,
- this.zoomTo(i, !0)
- }
- .bind(this),
- o = function() {
- this.zoomDefault(),
- t && window.setTimeout(t, 50)
- }
- .bind(this);
- transitions.start(r, e, o, null, 0, easing[settings.transition.blendEasing])
- } */
-
- updateZoomPano() {
- if (!this.panoRenderer.zoomPanoRenderingDisabled && Potree.settings.displayMode == 'showPanos') {
- var currentPano = this.currentPano;
- if (currentPano) {
- var activationThreshold = Potree.settings.navTileClass == '2k' && Potree.settings.tileClass == '4k' ? 1.7 : Potree.settings.zoom.activationThreshold//1.1
- var t = this.zoomLevel > activationThreshold,
- n = !(this.flying && this.nextPano && this.nextPano !== this.currentPano),
- r = t && n;
- this.tileDownloader.tilePrioritizer.setZoomingActive(r);
- this.panoRenderer.setZoomingActive(r, currentPano, !0);
-
- var o = (pano, zoomedFlag)=>{
- this.panoRenderer.resetRenderStatus(pano.id, !1, !0, this.qualityManager.getMaxNavPanoSize());
- this.panoRenderer.clearAllQueuedUploadsForPano(pano.id);
- this.panoRenderer.renderPanoTiles(pano.id, null, !1, !1);
- pano.setZoomed(zoomedFlag);
- }
-
-
- if (r && (!currentPano.zoomed || this.qualityManager.zoomLevelResolution && this.qualityManager.zoomLevelResolution != '4k')) {
- currentPano.zoomed || o(currentPano, !0);
-
- if(Potree.settings.navTileClass == '1k' && Potree.settings.tileClass != '1k' && this.zoomLevel < 2){
- this.panoRenderer.enableHighQuality( function() {//开启2k
- if(Potree.settings.tileClass != '4k') o(currentPano, !0);
- }.bind(this));
- }else{
- this.panoRenderer.enableUltraHighQualityMode(function() {//开启4k getMaxZoomPanoSize
- this.qualityManager.useUltraHighResolutionPanos && (Potree.settings.zoom.max = Potree.config.ultraHighQualityMaxZoom);
- o(currentPano, !0)
- }.bind(this));
- }
- } else {
- !t && currentPano.zoomed && o(currentPano, !1);
- }
-
-
-
- if(r && Potree.settings.navTileClass == '1k' && Potree.settings.tileClass == '4k' ){ //目前只有手机端navTileClass == '1k'
- var change = (zoomedFlag)=>{
- this.qualityManager.updateMaximums()//更新maxZoomPanoSize
- this.panoRenderer.setupZoomRenderTarget() //更新renderTarget
- //currentPano.setZoomed(t);//更新uniforms贴图
- }
- this.qualityManager.zoomLevelResolution = this.zoomLevel >= 2 ? '4k' : this.zoomLevel > 1.1 ? '2k' : '1k'
-
- if(this.oldZoomLevel < 2 && this.zoomLevel >= 2){//1k/2k-4k
- change()
- o(currentPano, t)
- }else if(this.oldZoomLevel <= Potree.settings.zoom.activationThreshold && this.zoomLevel > Potree.settings.zoom.activationThreshold){//1k-2k
- change()
- }else if(this.oldZoomLevel > 2 && this.zoomLevel <= 2){//4k-2k/1k
- change()
- o(currentPano, t)
- }else if(this.oldZoomLevel > Potree.settings.zoom.activationThreshold && this.zoomLevel <= Potree.settings.zoom.activationThreshold){//2k-1k
- change()
- }
- this.oldZoomLevel = this.zoomLevel
- }
- }
- }
- }
- //--------------------
- addHighMapCube(){//创建8*8的tile cube 主要因手机版崩溃 要在电脑端测试得设置maxRenderTargetSize
-
- if( Potree.settings.tileClass == '4k' && this.qualityManager.maxRenderTargetSize == 2048){
-
- var geo = new THREE.PlaneGeometry(1, 1, 1, 1)
- var cube = new THREE.Object3D;
- for(var cubeIndex=0; cubeIndex<6; cubeIndex++){
- var face = new THREE.Object3D;
- for(var i=0;i<8;i++){
- for(var j=0;j<8;j++){
- var tile = new THREE.Mesh(geo, new THREE.MeshBasicMaterial({
- //side:THREE.DoubleSide
- }))
- tile.position.set(i-3.5, j-3.5, -4);
-
- tile.material.opacity = 0.4;
- tile.material.transparent = true
-
-
- if(Potree.settings.isTest){
- var colorHue = Math.random();
- tile.material.color = (new THREE.Color()).setHSL(colorHue, 0.5, 0.9)
- }
-
- tile.visible = false
- face.add(tile)
- }
- }
- switch(cubeIndex){
- case GLCubeFaces.GL_TEXTURE_CUBE_MAP_POSITIVE_X:
- face.rotation.set(0,Math.PI/2,0);
- break;
- case GLCubeFaces.GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
- face.rotation.set(0,-Math.PI/2,0);
- break;
- case GLCubeFaces.GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
- var rot1 = new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0,1,0),Math.PI)
- var rot2 = new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(1,0,0),Math.PI/2)
-
- face.quaternion.copy(rot1).multiply(rot2)
- //face.rotation.set(Math.PI/2,0,0);
- break;
- case GLCubeFaces.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
- //face.rotation.set(-Math.PI/2,0,0);
- var rot1 = new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0,1,0),Math.PI)
- var rot2 = new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(1,0,0),-Math.PI/2)
-
- face.quaternion.copy(rot1).multiply(rot2)
- break;
- case GLCubeFaces.GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
- face.rotation.set(0,Math.PI,0);
- break;
- case GLCubeFaces.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
- face.rotation.set(0,0,0);
-
- }
- face.scale.set(1,-1,1)
- cube.add(face)
- }
- cube.name = 'highMapCube'
- this.highMapCube = cube
- viewer.scene.scene.add(cube)
- //cube.scale.set(0.01,0.01,0.01)
-
- this.highMapCube.visible = false;
- viewer.setObjectLayers(this.highMapCube, 'sceneObjects'/* 'skybox' */) //如果是skybox层,点云可见时会被遮住,depthTest为false呢? 但不会遮住场景物体
- //console.warn('addHighMapCube')
-
- }
-
- }
-
-
- isHighMapLoaded( cubeFace, tileX, tileY){
- var tile = this.highMapCube.children[cubeFace].children[tileX*8+tileY];
- return !!tile.material.map
- }
-
-
- updateHighMap(tex, cubeFace, tileX, tileY){
- //console.warn('updateHighMap')
- var tile = this.highMapCube.children[cubeFace].children[tileX*8+tileY];
-
- tile.material.map = tex;
-
- tile.material.opacity = 1;
- tile.material.transparent = false
-
-
- tile.visible = true
- tile.material.needsUpdate = true //发现每次开始放大但还未放大到4k时也会把之前加载过的4k加载
- }
-
-
-
- resetHighMap(){
-
- if(!this.highMapCube) return
- //console.warn('resetHighMap')
- this.highMapCube.children.forEach(e=>e.children.forEach(tile=>{
- if(tile.material.map){
- tile.material.map.dispose()
- tile.material.map.loaded = !1
- tile.material.map.version = 0
-
- var h = viewer.renderer.properties.get(tile.material.map)
- viewer.renderer.getContext().deleteTexture(h.__webglTexture)
- //类似app.sceneRenderer.deallocateCubeTexture(tile.material.map)
-
- tile.material.map = null
- /* tile.material.opacity = 0.4;
- tile.material.transparent = true */
- tile.material.needsUpdate = true
- tile.visible = false
- }
- }))
- this.highMapCube.visible = false;
- }
-
- setHighMap(pano){
- if(!this.highMapCube) return
- this.highMapCube.position.copy(pano.position)
-
- //可以利用第0个pano查看,其 rotation4dkk是(_x: 0, _y: -1.5707963267948966, _z: 0 )而手动旋转至(_x:1.5707963, _y: -1.57079, _z: 0)时才正确,说明要在4dkk的旋转基础上,绕x轴转90度,(也就是转成navvis坐标系), 然后得到YupToZup的函数写法的
-
- this.highMapCube.quaternion.copy( math.convertQuaternion.YupToZup( pano.quaternion4dkk ) )
-
-
- //乘上数据集整体的旋转:
- let modelRotQua = new THREE.Quaternion().setFromRotationMatrix(pano.pointcloud.rotateMatrix)
- this.highMapCube.quaternion.premultiply(modelRotQua)
-
-
- }
-
- showHighMap(){
- if(!this.highMapCube) return
- //console.warn('showHighMap')
- this.highMapCube.visible = true;
- }
- hideHighMap(){
- if(!this.highMapCube) return
- //console.warn('hideHighMap')
- this.highMapCube.visible = false;
- }
- //缩小后继续显示cube呢还是不显示? 不显示的话,就要把cube上的复制到renderTarget上……会不会又崩溃,or没加载的显示???
-
-
- addPanoData(data, datasetId ){
- //data[0].file_id = '00019'
-
- if(data.data) data = data.data
- if(data.length == 0)console.error(datasetId + ' 没有漫游点')
- //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.mesh.layers.set(Potree.config.renderLayers.marker)
- pano.marker.layers.set(Potree.config.renderLayers.marker) */
-
-
- pano.addEventListener('dispose',(e)=>{
- if(this.closestPano == pano) this.closestPano = null
- })
-
- this.panos.push(pano);
- if(Potree.settings.editType == 'pano'){
- Potree.settings.datasetsPanos[datasetId].panos.push(pano);
- }
- })
-
-
- }
-
-
- loadDone(){
- viewer.setObjectLayers(this.node, 'sceneObjects')
- //this.updateCube(/* viewer.bound */)
-
- this.panos.forEach(e=>{
- e.label && viewer.setObjectLayers(e.label, 'bothMapAndScene')
- })
-
- this.tileDownloader.setPanoData(this.panos, [] /* , Potree.settings.number */);
- {
- /* var panosBound = new THREE.Box3
- this.panos.forEach(pano=>{
- panosBound.expandByPoint(pano.position)
- })
- let center = panosBound.getCenter(new THREE.Vector3)
- let minBound = (new THREE.Box3()).setFromCenterAndSize(center, new THREE.Vector3(1,1,1))
- panosBound.union(minBound)
-
- this.bound = {
- bounding:panosBound,
- size: panosBound.getSize(new THREE.Vector3),
- center,
- } */
-
- 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)
- }
- };
-
- //判断当前点是否加载了全景图
- Images360.prototype.checkAndWaitForPanoLoad = function() {
- var isLoadedPanos = {},
- LoadedTimePanos = {},
- loadedCallback = {}, //add
- maxTime = 5e3;
- var withinTime = function() {
- for (var panoId in isLoadedPanos)
- if (isLoadedPanos.hasOwnProperty(panoId) && isLoadedPanos[panoId]) {
- var differTime = performance.now() - LoadedTimePanos[panoId];
- if (differTime < maxTime)
- return !0
- }
- return !1
- }
-
- return function(pano, basePanoSize, doneFun1, doneFun2, progressCallback, iswait, isclear, p ) {
- loadedCallback[pano.id] = doneFun1//add 因为有可能之前请求的没加doneFun1, 如果加载好就执行最新的doneFun1
-
- if (withinTime()){//距离上次请求时间很近
-
- return !0; //这里感觉应该是!1
- }
-
-
-
- var callback1 = (param1, param2)=>{
- setTimeout(()=>{
- isLoadedPanos[pano.id] = !1;
- loadedCallback[pano.id] && loadedCallback[pano.id](param1, param2);
- },1)
- }
- var callback2 = (param)=>{//没有看到有传doneFun2的
- setTimeout(()=>{
- isLoadedPanos[pano.id] = !1;
- doneFun2 && doneFun2(param);
- },1)
- }
- try {
- null !== iswait && void 0 !== iswait || (iswait = !0);
-
- isLoadedPanos[pano.id] = this.checkAndWaitForTiledPanoLoad(pano, basePanoSize, callback1, callback2, progressCallback, iswait, isclear, p );
- //true代表没加载好
- isLoadedPanos[pano.id] && (LoadedTimePanos[pano.id] = performance.now());
- return isLoadedPanos[pano.id];
- } catch (msg) {
- isLoadedPanos[pano.id] = !1;
- LoadedTimePanos[pano.id] = performance.now() - maxTime;
- throw msg;
- }
- }
- }()
- Images360.filters = {
- inPanoDirection : function(pos, dir, i) {
- return function(pano) {
- var r = pano.floorPosition.clone().sub(pos).normalize()
- var o = pano.position.clone().sub(pos).normalize()
- return r.dot(dir) > i || o.dot(dir) > i
-
-
- }
- },
- inFloorDirection: function(pos, e, o) {//许钟文 改 for鱼眼
- return function(n) {
- var i = n.floorPosition.clone().sub(pos).setZ(0).normalize();//改成在xz方向上,否则点击墙面不会移动
- return i.dot(e) > o
- }
- },
- 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, ifLog) {
- if(pos1.position)pos1 = pos1.position
- return function(pano) {//许钟文 改
- var pos2 = pano.position.clone()
- //ifLog && console.log('distanceSquared', pano.id, pos1.distanceToSquared(pos2) * -1 )
- return pos1.distanceTo(pos2) * -1 * r;
- }
- },
- distanceSquared: function(pos1, r ) {
- 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)
- }
- },
-
- }
-
|