potree.js 4.9 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998489994900049001490024900349004490054900649007490084900949010490114901249013490144901549016490174901849019490204902149022490234902449025490264902749028490294903049031490324903349034490354903649037490384903949040490414904249043490444904549046490474904849049490504905149052490534905449055490564905749058490594906049061490624906349064490654906649067490684906949070490714907249073490744907549076490774907849079490804908149082490834908449085490864908749088490894909049091490924909349094490954909649097490984909949100491014910249103491044910549106491074910849109491104911149112491134911449115491164911749118491194912049121491224912349124491254912649127491284912949130491314913249133491344913549136491374913849139491404914149142491434914449145491464914749148491494915049151491524915349154491554915649157491584915949160491614916249163491644916549166491674916849169491704917149172491734917449175491764917749178491794918049181491824918349184491854918649187491884918949190491914919249193491944919549196491974919849199492004920149202492034920449205492064920749208492094921049211492124921349214492154921649217492184921949220492214922249223492244922549226492274922849229492304923149232492334923449235492364923749238492394924049241492424924349244492454924649247492484924949250492514925249253492544925549256492574925849259492604926149262492634926449265492664926749268492694927049271492724927349274492754927649277492784927949280492814928249283492844928549286492874928849289492904929149292492934929449295492964929749298492994930049301493024930349304493054930649307493084930949310493114931249313493144931549316493174931849319493204932149322493234932449325493264932749328493294933049331493324933349334493354933649337493384933949340493414934249343493444934549346493474934849349493504935149352493534935449355493564935749358493594936049361493624936349364493654936649367493684936949370493714937249373493744937549376493774937849379493804938149382493834938449385493864938749388493894939049391493924939349394493954939649397493984939949400494014940249403494044940549406494074940849409494104941149412494134941449415494164941749418494194942049421494224942349424494254942649427494284942949430494314943249433494344943549436494374943849439494404944149442494434944449445494464944749448494494945049451494524945349454494554945649457494584945949460494614946249463494644946549466494674946849469494704947149472494734947449475494764947749478494794948049481494824948349484494854948649487494884948949490494914949249493494944949549496494974949849499495004950149502495034950449505495064950749508495094951049511495124951349514495154951649517495184951949520495214952249523495244952549526495274952849529495304953149532495334953449535495364953749538495394954049541495424954349544495454954649547495484954949550495514955249553495544955549556495574955849559495604956149562495634956449565495664956749568495694957049571495724957349574495754957649577495784957949580495814958249583495844958549586495874958849589495904959149592495934959449595495964959749598495994960049601496024960349604496054960649607496084960949610496114961249613496144961549616496174961849619496204962149622496234962449625496264962749628496294963049631496324963349634496354963649637496384963949640496414964249643496444964549646496474964849649496504965149652496534965449655496564965749658496594966049661496624966349664496654966649667496684966949670496714967249673496744967549676496774967849679496804968149682496834968449685496864968749688496894969049691496924969349694496954969649697496984969949700497014970249703497044970549706497074970849709497104971149712497134971449715497164971749718497194972049721497224972349724497254972649727497284972949730497314973249733497344973549736497374973849739497404974149742497434974449745497464974749748497494975049751497524975349754497554975649757497584975949760497614976249763497644976549766497674976849769497704977149772497734977449775497764977749778497794978049781497824978349784497854978649787497884978949790497914979249793497944979549796497974979849799498004980149802498034980449805498064980749808498094981049811498124981349814498154981649817498184981949820498214982249823498244982549826498274982849829498304983149832498334983449835498364983749838498394984049841498424984349844498454984649847498484984949850498514985249853498544985549856498574985849859498604986149862498634986449865498664986749868498694987049871498724987349874498754987649877498784987949880498814988249883498844988549886498874988849889498904989149892498934989449895498964989749898498994990049901499024990349904499054990649907499084990949910499114991249913499144991549916499174991849919499204992149922499234992449925499264992749928499294993049931499324993349934499354993649937499384993949940499414994249943499444994549946499474994849949499504995149952499534995449955499564995749958499594996049961499624996349964499654996649967499684996949970499714997249973499744997549976499774997849979499804998149982499834998449985499864998749988499894999049991499924999349994499954999649997499984999950000500015000250003500045000550006500075000850009500105001150012500135001450015500165001750018500195002050021500225002350024500255002650027500285002950030500315003250033500345003550036500375003850039500405004150042500435004450045500465004750048500495005050051500525005350054500555005650057500585005950060500615006250063500645006550066500675006850069500705007150072500735007450075500765007750078500795008050081500825008350084500855008650087500885008950090500915009250093500945009550096500975009850099501005010150102501035010450105501065010750108501095011050111501125011350114501155011650117501185011950120501215012250123501245012550126501275012850129501305013150132501335013450135501365013750138501395014050141501425014350144501455014650147501485014950150501515015250153501545015550156501575015850159501605016150162501635016450165501665016750168501695017050171501725017350174501755017650177501785017950180501815018250183501845018550186501875018850189501905019150192501935019450195501965019750198501995020050201502025020350204502055020650207502085020950210502115021250213502145021550216502175021850219502205022150222502235022450225502265022750228502295023050231502325023350234502355023650237502385023950240502415024250243502445024550246502475024850249502505025150252502535025450255502565025750258502595026050261502625026350264502655026650267502685026950270502715027250273502745027550276502775027850279502805028150282502835028450285502865028750288502895029050291502925029350294502955029650297502985029950300503015030250303503045030550306503075030850309503105031150312503135031450315503165031750318503195032050321503225032350324503255032650327503285032950330503315033250333503345033550336503375033850339503405034150342503435034450345503465034750348503495035050351503525035350354503555035650357503585035950360503615036250363503645036550366503675036850369503705037150372503735037450375503765037750378503795038050381503825038350384503855038650387503885038950390503915039250393503945039550396503975039850399504005040150402504035040450405504065040750408504095041050411504125041350414504155041650417504185041950420504215042250423504245042550426504275042850429504305043150432504335043450435504365043750438504395044050441504425044350444504455044650447504485044950450504515045250453504545045550456504575045850459504605046150462504635046450465504665046750468504695047050471504725047350474504755047650477504785047950480504815048250483504845048550486504875048850489504905049150492504935049450495504965049750498504995050050501505025050350504505055050650507505085050950510505115051250513505145051550516505175051850519505205052150522505235052450525505265052750528505295053050531505325053350534505355053650537505385053950540505415054250543505445054550546505475054850549505505055150552505535055450555505565055750558505595056050561505625056350564505655056650567505685056950570505715057250573505745057550576505775057850579505805058150582505835058450585505865058750588505895059050591505925059350594505955059650597505985059950600506015060250603506045060550606506075060850609506105061150612506135061450615506165061750618506195062050621506225062350624506255062650627506285062950630506315063250633506345063550636506375063850639506405064150642506435064450645506465064750648506495065050651506525065350654506555065650657506585065950660506615066250663506645066550666506675066850669506705067150672506735067450675506765067750678506795068050681506825068350684506855068650687506885068950690506915069250693506945069550696506975069850699507005070150702507035070450705507065070750708507095071050711507125071350714507155071650717507185071950720507215072250723507245072550726507275072850729507305073150732507335073450735507365073750738507395074050741507425074350744507455074650747507485074950750507515075250753507545075550756507575075850759507605076150762507635076450765507665076750768507695077050771507725077350774507755077650777507785077950780507815078250783507845078550786507875078850789507905079150792507935079450795507965079750798507995080050801508025080350804508055080650807508085080950810508115081250813508145081550816508175081850819508205082150822508235082450825508265082750828508295083050831508325083350834508355083650837508385083950840508415084250843508445084550846508475084850849508505085150852508535085450855508565085750858508595086050861508625086350864508655086650867508685086950870508715087250873508745087550876508775087850879508805088150882508835088450885508865088750888508895089050891508925089350894508955089650897508985089950900509015090250903509045090550906509075090850909509105091150912509135091450915509165091750918509195092050921509225092350924509255092650927509285092950930509315093250933509345093550936509375093850939509405094150942509435094450945509465094750948509495095050951509525095350954509555095650957509585095950960509615096250963509645096550966509675096850969509705097150972509735097450975509765097750978509795098050981509825098350984509855098650987509885098950990509915099250993509945099550996509975099850999510005100151002510035100451005510065100751008510095101051011510125101351014510155101651017510185101951020510215102251023510245102551026510275102851029510305103151032510335103451035510365103751038510395104051041510425104351044510455104651047510485104951050510515105251053510545105551056510575105851059510605106151062510635106451065510665106751068510695107051071510725107351074510755107651077510785107951080510815108251083510845108551086510875108851089510905109151092510935109451095510965109751098510995110051101511025110351104511055110651107511085110951110511115111251113511145111551116511175111851119511205112151122511235112451125511265112751128511295113051131511325113351134511355113651137511385113951140511415114251143511445114551146511475114851149511505115151152511535115451155511565115751158511595116051161511625116351164511655116651167511685116951170511715117251173511745117551176511775117851179511805118151182511835118451185511865118751188511895119051191511925119351194511955119651197511985119951200512015120251203512045120551206512075120851209512105121151212512135121451215512165121751218512195122051221512225122351224512255122651227512285122951230512315123251233512345123551236512375123851239512405124151242512435124451245512465124751248512495125051251512525125351254512555125651257512585125951260512615126251263512645126551266512675126851269512705127151272512735127451275512765127751278512795128051281512825128351284512855128651287512885128951290512915129251293512945129551296512975129851299513005130151302513035130451305513065130751308513095131051311513125131351314513155131651317513185131951320513215132251323513245132551326513275132851329513305133151332513335133451335513365133751338513395134051341513425134351344513455134651347513485134951350513515135251353513545135551356513575135851359513605136151362513635136451365513665136751368513695137051371513725137351374513755137651377513785137951380513815138251383513845138551386513875138851389513905139151392513935139451395513965139751398513995140051401514025140351404514055140651407514085140951410514115141251413514145141551416514175141851419514205142151422514235142451425514265142751428514295143051431514325143351434514355143651437514385143951440514415144251443514445144551446514475144851449514505145151452514535145451455514565145751458514595146051461514625146351464514655146651467514685146951470514715147251473514745147551476514775147851479514805148151482514835148451485514865148751488514895149051491514925149351494514955149651497514985149951500515015150251503515045150551506515075150851509515105151151512515135151451515515165151751518515195152051521515225152351524515255152651527515285152951530515315153251533515345153551536515375153851539515405154151542515435154451545515465154751548515495155051551515525155351554515555155651557515585155951560515615156251563515645156551566515675156851569515705157151572515735157451575515765157751578515795158051581515825158351584515855158651587515885158951590515915159251593515945159551596515975159851599516005160151602516035160451605516065160751608516095161051611516125161351614516155161651617516185161951620516215162251623516245162551626516275162851629516305163151632516335163451635516365163751638516395164051641516425164351644516455164651647516485164951650516515165251653516545165551656516575165851659516605166151662516635166451665516665166751668516695167051671516725167351674516755167651677516785167951680516815168251683516845168551686516875168851689516905169151692516935169451695516965169751698516995170051701517025170351704517055170651707517085170951710517115171251713517145171551716517175171851719517205172151722517235172451725517265172751728517295173051731517325173351734517355173651737517385173951740517415174251743517445174551746517475174851749517505175151752517535175451755517565175751758517595176051761517625176351764517655176651767517685176951770517715177251773517745177551776517775177851779517805178151782517835178451785517865178751788517895179051791517925179351794517955179651797517985179951800518015180251803518045180551806518075180851809518105181151812518135181451815518165181751818518195182051821518225182351824518255182651827518285182951830518315183251833518345183551836518375183851839518405184151842518435184451845518465184751848518495185051851518525185351854518555185651857518585185951860518615186251863518645186551866518675186851869518705187151872518735187451875518765187751878518795188051881518825188351884518855188651887518885188951890518915189251893518945189551896518975189851899519005190151902519035190451905519065190751908519095191051911519125191351914519155191651917519185191951920519215192251923519245192551926519275192851929519305193151932519335193451935519365193751938519395194051941519425194351944519455194651947519485194951950519515195251953519545195551956519575195851959519605196151962519635196451965519665196751968519695197051971519725197351974519755197651977519785197951980519815198251983519845198551986519875198851989519905199151992519935199451995519965199751998519995200052001520025200352004520055200652007520085200952010520115201252013520145201552016520175201852019520205202152022520235202452025520265202752028520295203052031520325203352034520355203652037520385203952040520415204252043520445204552046520475204852049520505205152052520535205452055520565205752058520595206052061520625206352064520655206652067520685206952070520715207252073520745207552076520775207852079520805208152082520835208452085520865208752088520895209052091520925209352094520955209652097520985209952100521015210252103521045210552106521075210852109521105211152112521135211452115521165211752118521195212052121521225212352124521255212652127521285212952130521315213252133521345213552136521375213852139521405214152142521435214452145521465214752148521495215052151521525215352154521555215652157521585215952160521615216252163521645216552166521675216852169521705217152172521735217452175521765217752178521795218052181521825218352184521855218652187521885218952190521915219252193521945219552196521975219852199522005220152202522035220452205522065220752208522095221052211522125221352214522155221652217522185221952220522215222252223522245222552226522275222852229522305223152232522335223452235522365223752238522395224052241522425224352244522455224652247522485224952250522515225252253522545225552256522575225852259522605226152262522635226452265522665226752268522695227052271522725227352274522755227652277522785227952280522815228252283522845228552286522875228852289522905229152292522935229452295522965229752298522995230052301523025230352304523055230652307523085230952310523115231252313523145231552316523175231852319523205232152322523235232452325523265232752328523295233052331523325233352334523355233652337523385233952340523415234252343523445234552346523475234852349523505235152352523535235452355523565235752358523595236052361523625236352364523655236652367523685236952370523715237252373523745237552376523775237852379523805238152382523835238452385523865238752388523895239052391523925239352394523955239652397523985239952400524015240252403524045240552406524075240852409524105241152412524135241452415524165241752418524195242052421524225242352424524255242652427524285242952430524315243252433524345243552436524375243852439524405244152442524435244452445524465244752448524495245052451524525245352454524555245652457524585245952460524615246252463524645246552466524675246852469524705247152472524735247452475524765247752478524795248052481524825248352484524855248652487524885248952490524915249252493524945249552496524975249852499525005250152502525035250452505525065250752508525095251052511525125251352514525155251652517525185251952520525215252252523525245252552526525275252852529525305253152532525335253452535525365253752538525395254052541525425254352544525455254652547525485254952550525515255252553525545255552556525575255852559525605256152562525635256452565525665256752568525695257052571525725257352574525755257652577525785257952580525815258252583525845258552586525875258852589525905259152592525935259452595525965259752598525995260052601526025260352604526055260652607526085260952610526115261252613526145261552616526175261852619526205262152622526235262452625526265262752628526295263052631526325263352634526355263652637526385263952640526415264252643526445264552646526475264852649526505265152652526535265452655526565265752658526595266052661526625266352664526655266652667526685266952670526715267252673526745267552676526775267852679526805268152682526835268452685526865268752688526895269052691526925269352694526955269652697526985269952700527015270252703527045270552706527075270852709527105271152712527135271452715527165271752718527195272052721527225272352724527255272652727527285272952730527315273252733527345273552736527375273852739527405274152742527435274452745527465274752748527495275052751527525275352754527555275652757527585275952760527615276252763527645276552766527675276852769527705277152772527735277452775527765277752778527795278052781527825278352784527855278652787527885278952790527915279252793527945279552796527975279852799528005280152802528035280452805528065280752808528095281052811528125281352814528155281652817528185281952820528215282252823528245282552826528275282852829528305283152832528335283452835528365283752838528395284052841528425284352844528455284652847528485284952850528515285252853528545285552856528575285852859528605286152862528635286452865528665286752868528695287052871528725287352874528755287652877528785287952880528815288252883528845288552886528875288852889528905289152892528935289452895528965289752898528995290052901529025290352904529055290652907529085290952910529115291252913529145291552916529175291852919529205292152922529235292452925529265292752928529295293052931529325293352934529355293652937529385293952940529415294252943529445294552946529475294852949529505295152952529535295452955529565295752958529595296052961529625296352964529655296652967529685296952970529715297252973529745297552976529775297852979529805298152982529835298452985529865298752988529895299052991529925299352994529955299652997529985299953000530015300253003530045300553006530075300853009530105301153012530135301453015530165301753018530195302053021530225302353024530255302653027530285302953030530315303253033530345303553036530375303853039530405304153042530435304453045530465304753048530495305053051530525305353054530555305653057530585305953060530615306253063530645306553066530675306853069530705307153072530735307453075530765307753078530795308053081530825308353084530855308653087530885308953090530915309253093530945309553096530975309853099531005310153102531035310453105531065310753108531095311053111531125311353114531155311653117531185311953120531215312253123531245312553126531275312853129531305313153132531335313453135531365313753138531395314053141531425314353144531455314653147531485314953150531515315253153531545315553156531575315853159531605316153162531635316453165531665316753168531695317053171531725317353174531755317653177531785317953180531815318253183531845318553186531875318853189531905319153192531935319453195531965319753198531995320053201532025320353204532055320653207532085320953210532115321253213532145321553216532175321853219532205322153222532235322453225532265322753228532295323053231532325323353234532355323653237532385323953240532415324253243532445324553246532475324853249532505325153252532535325453255532565325753258532595326053261532625326353264532655326653267532685326953270532715327253273532745327553276532775327853279532805328153282532835328453285532865328753288532895329053291532925329353294532955329653297532985329953300533015330253303533045330553306533075330853309533105331153312533135331453315533165331753318533195332053321533225332353324533255332653327533285332953330533315333253333533345333553336533375333853339533405334153342533435334453345533465334753348533495335053351533525335353354533555335653357533585335953360533615336253363533645336553366533675336853369533705337153372533735337453375533765337753378533795338053381533825338353384533855338653387533885338953390533915339253393533945339553396533975339853399534005340153402534035340453405534065340753408534095341053411534125341353414534155341653417534185341953420534215342253423534245342553426534275342853429534305343153432534335343453435534365343753438534395344053441534425344353444534455344653447534485344953450534515345253453534545345553456534575345853459534605346153462534635346453465534665346753468534695347053471534725347353474534755347653477534785347953480534815348253483534845348553486534875348853489534905349153492534935349453495534965349753498534995350053501535025350353504535055350653507535085350953510535115351253513535145351553516535175351853519535205352153522535235352453525535265352753528535295353053531535325353353534535355353653537535385353953540535415354253543535445354553546535475354853549535505355153552535535355453555535565355753558535595356053561535625356353564535655356653567535685356953570535715357253573535745357553576535775357853579535805358153582535835358453585535865358753588535895359053591535925359353594535955359653597535985359953600536015360253603536045360553606536075360853609536105361153612536135361453615536165361753618536195362053621536225362353624536255362653627536285362953630536315363253633536345363553636536375363853639536405364153642536435364453645536465364753648536495365053651536525365353654536555365653657536585365953660536615366253663536645366553666536675366853669536705367153672536735367453675536765367753678536795368053681536825368353684536855368653687536885368953690536915369253693536945369553696536975369853699537005370153702537035370453705537065370753708537095371053711537125371353714537155371653717537185371953720537215372253723537245372553726537275372853729537305373153732537335373453735537365373753738537395374053741537425374353744537455374653747537485374953750537515375253753537545375553756537575375853759537605376153762537635376453765537665376753768537695377053771537725377353774537755377653777537785377953780537815378253783537845378553786537875378853789537905379153792537935379453795537965379753798537995380053801538025380353804538055380653807538085380953810538115381253813538145381553816538175381853819538205382153822538235382453825538265382753828538295383053831538325383353834538355383653837538385383953840538415384253843538445384553846538475384853849538505385153852538535385453855538565385753858538595386053861538625386353864538655386653867538685386953870538715387253873538745387553876538775387853879538805388153882538835388453885538865388753888538895389053891538925389353894538955389653897538985389953900539015390253903539045390553906539075390853909539105391153912539135391453915539165391753918539195392053921539225392353924539255392653927539285392953930539315393253933539345393553936539375393853939539405394153942539435394453945539465394753948539495395053951539525395353954539555395653957539585395953960539615396253963539645396553966539675396853969539705397153972539735397453975539765397753978539795398053981539825398353984539855398653987539885398953990539915399253993539945399553996539975399853999540005400154002540035400454005540065400754008540095401054011540125401354014540155401654017540185401954020540215402254023540245402554026540275402854029540305403154032540335403454035540365403754038540395404054041540425404354044540455404654047540485404954050540515405254053540545405554056540575405854059540605406154062540635406454065540665406754068540695407054071540725407354074540755407654077540785407954080540815408254083540845408554086540875408854089540905409154092540935409454095540965409754098540995410054101541025410354104541055410654107541085410954110541115411254113541145411554116541175411854119541205412154122541235412454125541265412754128541295413054131541325413354134541355413654137541385413954140541415414254143541445414554146541475414854149541505415154152541535415454155541565415754158541595416054161541625416354164541655416654167541685416954170541715417254173541745417554176541775417854179541805418154182541835418454185541865418754188541895419054191541925419354194541955419654197541985419954200542015420254203542045420554206542075420854209542105421154212542135421454215542165421754218542195422054221542225422354224542255422654227542285422954230542315423254233542345423554236542375423854239542405424154242542435424454245542465424754248542495425054251542525425354254542555425654257542585425954260542615426254263542645426554266542675426854269542705427154272542735427454275542765427754278542795428054281542825428354284542855428654287542885428954290542915429254293542945429554296542975429854299543005430154302543035430454305543065430754308543095431054311543125431354314543155431654317543185431954320543215432254323543245432554326543275432854329543305433154332543335433454335543365433754338543395434054341543425434354344543455434654347543485434954350543515435254353543545435554356543575435854359543605436154362543635436454365543665436754368543695437054371543725437354374543755437654377543785437954380543815438254383543845438554386543875438854389543905439154392543935439454395543965439754398543995440054401544025440354404544055440654407544085440954410544115441254413544145441554416544175441854419544205442154422544235442454425544265442754428544295443054431544325443354434544355443654437544385443954440544415444254443544445444554446544475444854449544505445154452544535445454455544565445754458544595446054461544625446354464544655446654467544685446954470544715447254473544745447554476544775447854479544805448154482544835448454485544865448754488544895449054491544925449354494544955449654497544985449954500545015450254503545045450554506545075450854509545105451154512545135451454515545165451754518545195452054521545225452354524545255452654527545285452954530545315453254533545345453554536545375453854539545405454154542545435454454545545465454754548545495455054551545525455354554545555455654557545585455954560545615456254563545645456554566545675456854569545705457154572545735457454575545765457754578545795458054581545825458354584545855458654587545885458954590545915459254593545945459554596545975459854599546005460154602546035460454605546065460754608546095461054611546125461354614546155461654617546185461954620546215462254623546245462554626546275462854629546305463154632546335463454635546365463754638546395464054641546425464354644546455464654647546485464954650546515465254653546545465554656546575465854659546605466154662546635466454665546665466754668546695467054671546725467354674546755467654677546785467954680546815468254683546845468554686546875468854689546905469154692546935469454695546965469754698546995470054701547025470354704547055470654707547085470954710547115471254713547145471554716547175471854719547205472154722547235472454725547265472754728547295473054731547325473354734547355473654737547385473954740547415474254743547445474554746547475474854749547505475154752547535475454755547565475754758547595476054761547625476354764547655476654767547685476954770547715477254773547745477554776547775477854779547805478154782547835478454785547865478754788547895479054791547925479354794547955479654797547985479954800548015480254803548045480554806548075480854809548105481154812548135481454815548165481754818548195482054821548225482354824548255482654827548285482954830548315483254833548345483554836548375483854839548405484154842548435484454845548465484754848548495485054851548525485354854548555485654857548585485954860548615486254863548645486554866548675486854869548705487154872548735487454875548765487754878548795488054881548825488354884548855488654887548885488954890548915489254893548945489554896548975489854899549005490154902549035490454905549065490754908549095491054911549125491354914549155491654917549185491954920549215492254923549245492554926549275492854929549305493154932549335493454935549365493754938549395494054941549425494354944549455494654947549485494954950549515495254953549545495554956549575495854959549605496154962549635496454965549665496754968549695497054971549725497354974549755497654977549785497954980549815498254983549845498554986549875498854989549905499154992549935499454995549965499754998549995500055001550025500355004550055500655007550085500955010550115501255013550145501555016550175501855019550205502155022550235502455025550265502755028550295503055031550325503355034550355503655037550385503955040550415504255043550445504555046550475504855049550505505155052550535505455055550565505755058550595506055061550625506355064550655506655067550685506955070550715507255073550745507555076550775507855079550805508155082550835508455085550865508755088550895509055091550925509355094550955509655097550985509955100551015510255103551045510555106551075510855109551105511155112551135511455115551165511755118551195512055121551225512355124551255512655127551285512955130551315513255133551345513555136551375513855139551405514155142551435514455145551465514755148551495515055151551525515355154551555515655157551585515955160551615516255163551645516555166551675516855169551705517155172551735517455175551765517755178551795518055181551825518355184551855518655187551885518955190551915519255193551945519555196551975519855199552005520155202552035520455205552065520755208552095521055211552125521355214552155521655217552185521955220552215522255223552245522555226552275522855229552305523155232552335523455235552365523755238552395524055241552425524355244552455524655247552485524955250552515525255253552545525555256552575525855259552605526155262552635526455265552665526755268552695527055271552725527355274552755527655277552785527955280552815528255283552845528555286552875528855289552905529155292552935529455295552965529755298552995530055301553025530355304553055530655307553085530955310553115531255313553145531555316553175531855319553205532155322553235532455325553265532755328553295533055331553325533355334553355533655337553385533955340553415534255343553445534555346553475534855349553505535155352553535535455355553565535755358553595536055361553625536355364553655536655367553685536955370553715537255373553745537555376553775537855379553805538155382553835538455385553865538755388553895539055391553925539355394553955539655397553985539955400554015540255403554045540555406554075540855409554105541155412554135541455415554165541755418554195542055421554225542355424554255542655427554285542955430554315543255433554345543555436554375543855439554405544155442554435544455445554465544755448554495545055451554525545355454554555545655457554585545955460554615546255463554645546555466554675546855469554705547155472554735547455475554765547755478554795548055481554825548355484554855548655487554885548955490554915549255493554945549555496554975549855499555005550155502555035550455505555065550755508555095551055511555125551355514555155551655517555185551955520555215552255523555245552555526555275552855529555305553155532555335553455535555365553755538555395554055541555425554355544555455554655547555485554955550555515555255553555545555555556555575555855559555605556155562555635556455565555665556755568555695557055571555725557355574555755557655577555785557955580555815558255583555845558555586555875558855589555905559155592555935559455595555965559755598555995560055601556025560355604556055560655607556085560955610556115561255613556145561555616556175561855619556205562155622556235562455625556265562755628556295563055631556325563355634556355563655637556385563955640556415564255643556445564555646556475564855649556505565155652556535565455655556565565755658556595566055661556625566355664556655566655667556685566955670556715567255673556745567555676556775567855679556805568155682556835568455685556865568755688556895569055691556925569355694556955569655697556985569955700557015570255703557045570555706557075570855709557105571155712557135571455715557165571755718557195572055721557225572355724557255572655727557285572955730557315573255733557345573555736557375573855739557405574155742557435574455745557465574755748557495575055751557525575355754557555575655757557585575955760557615576255763557645576555766557675576855769557705577155772557735577455775557765577755778557795578055781557825578355784557855578655787557885578955790557915579255793557945579555796557975579855799558005580155802558035580455805558065580755808558095581055811558125581355814558155581655817558185581955820558215582255823558245582555826558275582855829558305583155832558335583455835558365583755838558395584055841558425584355844558455584655847558485584955850558515585255853558545585555856558575585855859558605586155862558635586455865558665586755868558695587055871558725587355874558755587655877558785587955880558815588255883558845588555886558875588855889558905589155892558935589455895558965589755898558995590055901559025590355904559055590655907559085590955910559115591255913559145591555916559175591855919559205592155922559235592455925559265592755928559295593055931559325593355934559355593655937559385593955940559415594255943559445594555946559475594855949559505595155952559535595455955559565595755958559595596055961559625596355964559655596655967559685596955970559715597255973559745597555976559775597855979559805598155982559835598455985559865598755988559895599055991559925599355994559955599655997559985599956000560015600256003560045600556006560075600856009560105601156012560135601456015560165601756018560195602056021560225602356024560255602656027560285602956030560315603256033560345603556036560375603856039560405604156042560435604456045560465604756048560495605056051560525605356054560555605656057560585605956060560615606256063560645606556066560675606856069560705607156072560735607456075560765607756078560795608056081560825608356084560855608656087560885608956090560915609256093560945609556096560975609856099561005610156102561035610456105561065610756108561095611056111561125611356114561155611656117561185611956120561215612256123561245612556126561275612856129561305613156132561335613456135561365613756138561395614056141561425614356144561455614656147561485614956150561515615256153561545615556156561575615856159561605616156162561635616456165561665616756168561695617056171561725617356174561755617656177561785617956180561815618256183561845618556186561875618856189561905619156192561935619456195561965619756198561995620056201562025620356204562055620656207562085620956210562115621256213562145621556216562175621856219562205622156222562235622456225562265622756228562295623056231562325623356234562355623656237562385623956240562415624256243562445624556246562475624856249562505625156252562535625456255562565625756258562595626056261562625626356264562655626656267562685626956270562715627256273562745627556276562775627856279562805628156282562835628456285562865628756288562895629056291562925629356294562955629656297562985629956300563015630256303563045630556306563075630856309563105631156312563135631456315563165631756318563195632056321563225632356324563255632656327563285632956330563315633256333563345633556336563375633856339563405634156342563435634456345563465634756348563495635056351563525635356354563555635656357563585635956360563615636256363563645636556366563675636856369563705637156372563735637456375563765637756378563795638056381563825638356384563855638656387563885638956390563915639256393563945639556396563975639856399564005640156402564035640456405564065640756408564095641056411564125641356414564155641656417564185641956420564215642256423564245642556426564275642856429564305643156432564335643456435564365643756438564395644056441564425644356444564455644656447564485644956450564515645256453564545645556456564575645856459564605646156462564635646456465564665646756468564695647056471564725647356474564755647656477564785647956480564815648256483564845648556486564875648856489564905649156492564935649456495564965649756498564995650056501565025650356504565055650656507565085650956510565115651256513565145651556516565175651856519565205652156522565235652456525565265652756528565295653056531565325653356534565355653656537565385653956540565415654256543565445654556546565475654856549565505655156552565535655456555565565655756558565595656056561565625656356564565655656656567565685656956570565715657256573565745657556576565775657856579565805658156582565835658456585565865658756588565895659056591565925659356594565955659656597565985659956600566015660256603566045660556606566075660856609566105661156612566135661456615566165661756618566195662056621566225662356624566255662656627566285662956630566315663256633566345663556636566375663856639566405664156642566435664456645566465664756648566495665056651566525665356654566555665656657566585665956660566615666256663566645666556666566675666856669566705667156672566735667456675566765667756678566795668056681566825668356684566855668656687566885668956690566915669256693566945669556696566975669856699567005670156702567035670456705567065670756708567095671056711567125671356714567155671656717567185671956720567215672256723567245672556726567275672856729567305673156732567335673456735567365673756738567395674056741567425674356744567455674656747567485674956750567515675256753567545675556756567575675856759567605676156762567635676456765567665676756768567695677056771567725677356774567755677656777567785677956780567815678256783567845678556786567875678856789567905679156792567935679456795567965679756798567995680056801568025680356804568055680656807568085680956810568115681256813568145681556816568175681856819568205682156822568235682456825568265682756828568295683056831568325683356834568355683656837568385683956840568415684256843568445684556846568475684856849568505685156852568535685456855568565685756858568595686056861568625686356864568655686656867568685686956870568715687256873568745687556876568775687856879568805688156882568835688456885568865688756888568895689056891568925689356894568955689656897568985689956900569015690256903569045690556906569075690856909569105691156912569135691456915569165691756918569195692056921569225692356924569255692656927569285692956930569315693256933569345693556936569375693856939569405694156942569435694456945569465694756948569495695056951569525695356954569555695656957569585695956960569615696256963569645696556966569675696856969569705697156972569735697456975569765697756978569795698056981569825698356984569855698656987569885698956990569915699256993569945699556996569975699856999570005700157002570035700457005570065700757008570095701057011570125701357014570155701657017570185701957020570215702257023570245702557026570275702857029570305703157032570335703457035570365703757038570395704057041570425704357044570455704657047570485704957050570515705257053570545705557056570575705857059570605706157062570635706457065570665706757068570695707057071570725707357074570755707657077570785707957080570815708257083570845708557086570875708857089570905709157092570935709457095570965709757098570995710057101571025710357104571055710657107571085710957110571115711257113571145711557116571175711857119571205712157122571235712457125571265712757128571295713057131571325713357134571355713657137571385713957140571415714257143571445714557146571475714857149571505715157152571535715457155571565715757158571595716057161571625716357164571655716657167571685716957170571715717257173571745717557176571775717857179571805718157182571835718457185571865718757188571895719057191571925719357194571955719657197571985719957200572015720257203572045720557206572075720857209572105721157212572135721457215572165721757218572195722057221572225722357224572255722657227572285722957230572315723257233572345723557236572375723857239572405724157242572435724457245572465724757248572495725057251572525725357254572555725657257572585725957260572615726257263572645726557266572675726857269572705727157272572735727457275572765727757278572795728057281572825728357284572855728657287572885728957290572915729257293572945729557296572975729857299573005730157302573035730457305573065730757308573095731057311573125731357314573155731657317573185731957320573215732257323573245732557326573275732857329573305733157332573335733457335573365733757338573395734057341573425734357344573455734657347573485734957350573515735257353573545735557356573575735857359573605736157362573635736457365573665736757368573695737057371573725737357374573755737657377573785737957380573815738257383573845738557386573875738857389573905739157392573935739457395573965739757398573995740057401574025740357404574055740657407574085740957410574115741257413574145741557416574175741857419574205742157422574235742457425574265742757428574295743057431574325743357434574355743657437574385743957440574415744257443574445744557446574475744857449574505745157452574535745457455574565745757458574595746057461574625746357464574655746657467574685746957470574715747257473574745747557476574775747857479574805748157482574835748457485574865748757488574895749057491574925749357494574955749657497574985749957500575015750257503575045750557506575075750857509575105751157512575135751457515575165751757518575195752057521575225752357524575255752657527575285752957530575315753257533575345753557536575375753857539575405754157542575435754457545575465754757548575495755057551575525755357554575555755657557575585755957560575615756257563575645756557566575675756857569575705757157572575735757457575575765757757578575795758057581575825758357584575855758657587575885758957590575915759257593575945759557596575975759857599576005760157602576035760457605576065760757608576095761057611576125761357614576155761657617576185761957620576215762257623576245762557626576275762857629576305763157632576335763457635576365763757638576395764057641576425764357644576455764657647576485764957650576515765257653576545765557656576575765857659576605766157662576635766457665576665766757668576695767057671576725767357674576755767657677576785767957680576815768257683576845768557686576875768857689576905769157692576935769457695576965769757698576995770057701577025770357704577055770657707577085770957710577115771257713577145771557716577175771857719577205772157722577235772457725577265772757728577295773057731577325773357734577355773657737577385773957740577415774257743577445774557746577475774857749577505775157752577535775457755577565775757758577595776057761577625776357764577655776657767577685776957770577715777257773577745777557776577775777857779577805778157782577835778457785577865778757788577895779057791577925779357794577955779657797577985779957800578015780257803578045780557806578075780857809578105781157812578135781457815578165781757818578195782057821578225782357824578255782657827578285782957830578315783257833578345783557836578375783857839578405784157842578435784457845578465784757848578495785057851578525785357854578555785657857578585785957860578615786257863578645786557866578675786857869578705787157872578735787457875578765787757878578795788057881578825788357884578855788657887578885788957890578915789257893578945789557896578975789857899579005790157902579035790457905579065790757908579095791057911579125791357914579155791657917579185791957920579215792257923579245792557926579275792857929579305793157932579335793457935579365793757938579395794057941579425794357944579455794657947579485794957950579515795257953579545795557956579575795857959579605796157962579635796457965579665796757968579695797057971579725797357974579755797657977579785797957980579815798257983579845798557986579875798857989579905799157992579935799457995579965799757998579995800058001580025800358004580055800658007580085800958010580115801258013580145801558016580175801858019580205802158022580235802458025580265802758028580295803058031580325803358034580355803658037580385803958040580415804258043580445804558046580475804858049580505805158052580535805458055580565805758058580595806058061580625806358064580655806658067580685806958070580715807258073580745807558076580775807858079580805808158082580835808458085580865808758088580895809058091580925809358094580955809658097580985809958100581015810258103581045810558106581075810858109581105811158112581135811458115581165811758118581195812058121581225812358124581255812658127581285812958130581315813258133581345813558136581375813858139581405814158142581435814458145581465814758148581495815058151581525815358154581555815658157581585815958160581615816258163581645816558166581675816858169581705817158172581735817458175581765817758178581795818058181581825818358184581855818658187581885818958190581915819258193581945819558196581975819858199582005820158202582035820458205582065820758208582095821058211582125821358214582155821658217582185821958220582215822258223582245822558226582275822858229582305823158232582335823458235582365823758238582395824058241582425824358244582455824658247582485824958250582515825258253582545825558256582575825858259582605826158262582635826458265582665826758268582695827058271582725827358274582755827658277582785827958280582815828258283582845828558286582875828858289582905829158292582935829458295582965829758298582995830058301583025830358304583055830658307583085830958310583115831258313583145831558316583175831858319583205832158322583235832458325583265832758328583295833058331583325833358334583355833658337583385833958340583415834258343583445834558346583475834858349583505835158352583535835458355583565835758358583595836058361583625836358364583655836658367583685836958370583715837258373583745837558376583775837858379583805838158382583835838458385583865838758388583895839058391583925839358394583955839658397583985839958400584015840258403584045840558406584075840858409584105841158412584135841458415584165841758418584195842058421584225842358424584255842658427584285842958430584315843258433584345843558436584375843858439584405844158442584435844458445584465844758448584495845058451584525845358454584555845658457584585845958460584615846258463584645846558466584675846858469584705847158472584735847458475584765847758478584795848058481584825848358484584855848658487584885848958490584915849258493584945849558496584975849858499585005850158502585035850458505585065850758508585095851058511585125851358514585155851658517585185851958520585215852258523585245852558526585275852858529585305853158532585335853458535585365853758538585395854058541585425854358544585455854658547585485854958550585515855258553585545855558556585575855858559585605856158562585635856458565585665856758568585695857058571585725857358574585755857658577585785857958580585815858258583585845858558586585875858858589585905859158592585935859458595585965859758598585995860058601586025860358604586055860658607586085860958610586115861258613586145861558616586175861858619586205862158622586235862458625586265862758628586295863058631586325863358634586355863658637586385863958640586415864258643586445864558646586475864858649586505865158652586535865458655586565865758658586595866058661586625866358664586655866658667586685866958670586715867258673586745867558676586775867858679586805868158682586835868458685586865868758688586895869058691586925869358694586955869658697586985869958700587015870258703587045870558706587075870858709587105871158712587135871458715587165871758718587195872058721587225872358724587255872658727587285872958730587315873258733587345873558736587375873858739587405874158742587435874458745587465874758748587495875058751587525875358754587555875658757587585875958760587615876258763587645876558766587675876858769587705877158772587735877458775587765877758778587795878058781587825878358784587855878658787587885878958790587915879258793587945879558796587975879858799588005880158802588035880458805588065880758808588095881058811588125881358814588155881658817588185881958820588215882258823588245882558826588275882858829588305883158832588335883458835588365883758838588395884058841588425884358844588455884658847588485884958850588515885258853588545885558856588575885858859588605886158862588635886458865588665886758868588695887058871588725887358874588755887658877588785887958880588815888258883588845888558886588875888858889588905889158892588935889458895588965889758898588995890058901589025890358904589055890658907589085890958910589115891258913589145891558916589175891858919589205892158922589235892458925589265892758928589295893058931589325893358934589355893658937589385893958940589415894258943589445894558946589475894858949589505895158952589535895458955589565895758958589595896058961589625896358964589655896658967589685896958970589715897258973589745897558976589775897858979589805898158982589835898458985589865898758988589895899058991589925899358994589955899658997589985899959000590015900259003590045900559006590075900859009590105901159012590135901459015590165901759018590195902059021590225902359024590255902659027590285902959030590315903259033590345903559036590375903859039590405904159042590435904459045590465904759048590495905059051590525905359054590555905659057590585905959060590615906259063590645906559066590675906859069590705907159072590735907459075590765907759078590795908059081590825908359084590855908659087590885908959090590915909259093590945909559096590975909859099591005910159102591035910459105591065910759108591095911059111591125911359114591155911659117591185911959120591215912259123591245912559126591275912859129591305913159132591335913459135591365913759138591395914059141591425914359144591455914659147591485914959150591515915259153591545915559156591575915859159591605916159162591635916459165591665916759168591695917059171591725917359174591755917659177591785917959180591815918259183591845918559186591875918859189591905919159192591935919459195591965919759198591995920059201592025920359204592055920659207592085920959210592115921259213592145921559216592175921859219592205922159222592235922459225592265922759228592295923059231592325923359234592355923659237592385923959240592415924259243592445924559246592475924859249592505925159252592535925459255592565925759258592595926059261592625926359264592655926659267592685926959270592715927259273592745927559276592775927859279592805928159282592835928459285592865928759288592895929059291592925929359294592955929659297592985929959300593015930259303593045930559306593075930859309593105931159312593135931459315593165931759318593195932059321593225932359324593255932659327593285932959330593315933259333593345933559336593375933859339593405934159342593435934459345593465934759348593495935059351593525935359354593555935659357593585935959360593615936259363593645936559366593675936859369593705937159372593735937459375593765937759378593795938059381593825938359384593855938659387593885938959390593915939259393593945939559396593975939859399594005940159402594035940459405594065940759408594095941059411594125941359414594155941659417594185941959420594215942259423594245942559426594275942859429594305943159432594335943459435594365943759438594395944059441594425944359444594455944659447594485944959450594515945259453594545945559456594575945859459594605946159462594635946459465594665946759468594695947059471594725947359474594755947659477594785947959480594815948259483594845948559486594875948859489594905949159492594935949459495594965949759498594995950059501595025950359504595055950659507595085950959510595115951259513595145951559516595175951859519595205952159522595235952459525595265952759528595295953059531595325953359534595355953659537595385953959540595415954259543595445954559546595475954859549595505955159552595535955459555595565955759558595595956059561595625956359564595655956659567595685956959570595715957259573595745957559576595775957859579595805958159582595835958459585595865958759588595895959059591595925959359594595955959659597595985959959600596015960259603596045960559606596075960859609596105961159612596135961459615596165961759618596195962059621596225962359624596255962659627596285962959630596315963259633596345963559636596375963859639596405964159642596435964459645596465964759648596495965059651596525965359654596555965659657596585965959660596615966259663596645966559666596675966859669596705967159672596735967459675596765967759678596795968059681596825968359684596855968659687596885968959690596915969259693596945969559696596975969859699597005970159702597035970459705597065970759708597095971059711597125971359714597155971659717597185971959720597215972259723597245972559726597275972859729597305973159732597335973459735597365973759738597395974059741597425974359744597455974659747597485974959750597515975259753597545975559756597575975859759597605976159762597635976459765597665976759768597695977059771597725977359774597755977659777597785977959780597815978259783597845978559786597875978859789597905979159792597935979459795597965979759798597995980059801598025980359804598055980659807598085980959810598115981259813598145981559816598175981859819598205982159822598235982459825598265982759828598295983059831598325983359834598355983659837598385983959840598415984259843598445984559846598475984859849598505985159852598535985459855598565985759858598595986059861598625986359864598655986659867598685986959870598715987259873598745987559876598775987859879598805988159882598835988459885598865988759888598895989059891598925989359894598955989659897598985989959900599015990259903599045990559906599075990859909599105991159912599135991459915599165991759918599195992059921599225992359924599255992659927599285992959930599315993259933599345993559936599375993859939599405994159942599435994459945599465994759948599495995059951599525995359954599555995659957599585995959960599615996259963599645996559966599675996859969599705997159972599735997459975599765997759978599795998059981599825998359984599855998659987599885998959990599915999259993599945999559996599975999859999600006000160002600036000460005600066000760008600096001060011600126001360014600156001660017600186001960020600216002260023600246002560026600276002860029600306003160032600336003460035600366003760038600396004060041600426004360044600456004660047600486004960050600516005260053600546005560056600576005860059600606006160062600636006460065600666006760068600696007060071600726007360074600756007660077600786007960080600816008260083600846008560086600876008860089600906009160092600936009460095600966009760098600996010060101601026010360104601056010660107601086010960110601116011260113601146011560116601176011860119601206012160122601236012460125601266012760128601296013060131601326013360134601356013660137601386013960140601416014260143601446014560146601476014860149601506015160152601536015460155601566015760158601596016060161601626016360164601656016660167601686016960170601716017260173601746017560176601776017860179601806018160182601836018460185601866018760188601896019060191601926019360194601956019660197601986019960200602016020260203602046020560206602076020860209602106021160212602136021460215602166021760218602196022060221602226022360224602256022660227602286022960230602316023260233602346023560236602376023860239602406024160242602436024460245602466024760248602496025060251602526025360254602556025660257602586025960260602616026260263602646026560266602676026860269602706027160272602736027460275602766027760278602796028060281602826028360284602856028660287602886028960290602916029260293602946029560296602976029860299603006030160302603036030460305603066030760308603096031060311603126031360314603156031660317603186031960320603216032260323603246032560326603276032860329603306033160332603336033460335603366033760338603396034060341603426034360344603456034660347603486034960350603516035260353603546035560356603576035860359603606036160362603636036460365603666036760368603696037060371603726037360374603756037660377603786037960380603816038260383603846038560386603876038860389603906039160392603936039460395603966039760398603996040060401604026040360404604056040660407604086040960410604116041260413604146041560416604176041860419604206042160422604236042460425604266042760428604296043060431604326043360434604356043660437604386043960440604416044260443604446044560446604476044860449604506045160452604536045460455604566045760458604596046060461604626046360464604656046660467604686046960470604716047260473604746047560476604776047860479604806048160482604836048460485604866048760488604896049060491604926049360494604956049660497604986049960500605016050260503605046050560506605076050860509605106051160512605136051460515605166051760518605196052060521605226052360524605256052660527605286052960530605316053260533605346053560536605376053860539605406054160542605436054460545605466054760548605496055060551605526055360554605556055660557605586055960560605616056260563605646056560566605676056860569605706057160572605736057460575605766057760578605796058060581605826058360584605856058660587605886058960590605916059260593605946059560596605976059860599606006060160602606036060460605606066060760608606096061060611606126061360614606156061660617606186061960620606216062260623606246062560626606276062860629606306063160632606336063460635606366063760638606396064060641606426064360644606456064660647606486064960650606516065260653606546065560656606576065860659606606066160662606636066460665606666066760668606696067060671606726067360674606756067660677606786067960680606816068260683606846068560686606876068860689606906069160692606936069460695606966069760698606996070060701607026070360704607056070660707607086070960710607116071260713607146071560716607176071860719607206072160722607236072460725607266072760728607296073060731607326073360734607356073660737607386073960740607416074260743607446074560746607476074860749607506075160752607536075460755607566075760758607596076060761607626076360764607656076660767607686076960770607716077260773607746077560776607776077860779607806078160782607836078460785607866078760788607896079060791607926079360794607956079660797607986079960800608016080260803608046080560806608076080860809608106081160812608136081460815608166081760818608196082060821608226082360824608256082660827608286082960830608316083260833608346083560836608376083860839608406084160842608436084460845608466084760848608496085060851608526085360854608556085660857608586085960860608616086260863608646086560866608676086860869608706087160872608736087460875608766087760878608796088060881608826088360884608856088660887608886088960890608916089260893608946089560896608976089860899609006090160902609036090460905609066090760908609096091060911609126091360914609156091660917609186091960920609216092260923609246092560926609276092860929609306093160932609336093460935609366093760938609396094060941609426094360944609456094660947609486094960950609516095260953609546095560956609576095860959609606096160962609636096460965609666096760968609696097060971609726097360974609756097660977609786097960980609816098260983609846098560986609876098860989609906099160992609936099460995609966099760998609996100061001610026100361004610056100661007610086100961010610116101261013610146101561016610176101861019610206102161022610236102461025610266102761028610296103061031610326103361034610356103661037610386103961040610416104261043610446104561046610476104861049610506105161052610536105461055610566105761058610596106061061610626106361064610656106661067610686106961070610716107261073610746107561076610776107861079610806108161082610836108461085610866108761088610896109061091610926109361094610956109661097610986109961100611016110261103611046110561106611076110861109611106111161112611136111461115611166111761118611196112061121611226112361124611256112661127611286112961130611316113261133611346113561136611376113861139611406114161142611436114461145611466114761148611496115061151611526115361154611556115661157611586115961160611616116261163611646116561166611676116861169611706117161172611736117461175611766117761178611796118061181611826118361184611856118661187611886118961190611916119261193611946119561196611976119861199612006120161202612036120461205612066120761208612096121061211612126121361214612156121661217612186121961220612216122261223612246122561226612276122861229612306123161232612336123461235612366123761238612396124061241612426124361244612456124661247612486124961250612516125261253612546125561256612576125861259612606126161262612636126461265612666126761268612696127061271612726127361274612756127661277612786127961280612816128261283612846128561286612876128861289612906129161292612936129461295612966129761298612996130061301613026130361304613056130661307613086130961310613116131261313613146131561316613176131861319613206132161322613236132461325613266132761328613296133061331613326133361334613356133661337613386133961340613416134261343613446134561346613476134861349613506135161352613536135461355613566135761358613596136061361613626136361364613656136661367613686136961370613716137261373613746137561376613776137861379613806138161382613836138461385613866138761388613896139061391613926139361394613956139661397613986139961400614016140261403614046140561406614076140861409614106141161412614136141461415614166141761418614196142061421614226142361424614256142661427614286142961430614316143261433614346143561436614376143861439614406144161442614436144461445614466144761448614496145061451614526145361454614556145661457614586145961460614616146261463614646146561466614676146861469614706147161472614736147461475614766147761478614796148061481614826148361484614856148661487614886148961490614916149261493614946149561496614976149861499615006150161502615036150461505615066150761508615096151061511615126151361514615156151661517615186151961520615216152261523615246152561526615276152861529615306153161532615336153461535615366153761538615396154061541615426154361544615456154661547615486154961550615516155261553615546155561556615576155861559615606156161562615636156461565615666156761568615696157061571615726157361574615756157661577615786157961580615816158261583615846158561586615876158861589615906159161592615936159461595615966159761598615996160061601616026160361604616056160661607616086160961610616116161261613616146161561616616176161861619616206162161622616236162461625616266162761628616296163061631616326163361634616356163661637616386163961640616416164261643616446164561646616476164861649616506165161652616536165461655616566165761658616596166061661616626166361664616656166661667616686166961670616716167261673616746167561676616776167861679616806168161682616836168461685616866168761688616896169061691616926169361694616956169661697616986169961700617016170261703617046170561706617076170861709617106171161712617136171461715617166171761718617196172061721617226172361724617256172661727617286172961730617316173261733617346173561736617376173861739617406174161742617436174461745617466174761748617496175061751617526175361754617556175661757617586175961760617616176261763617646176561766617676176861769617706177161772617736177461775617766177761778617796178061781617826178361784617856178661787617886178961790617916179261793617946179561796617976179861799618006180161802618036180461805618066180761808618096181061811618126181361814618156181661817618186181961820618216182261823618246182561826618276182861829618306183161832618336183461835618366183761838618396184061841618426184361844618456184661847618486184961850618516185261853618546185561856618576185861859618606186161862618636186461865618666186761868618696187061871618726187361874618756187661877618786187961880618816188261883618846188561886618876188861889618906189161892618936189461895618966189761898618996190061901619026190361904619056190661907619086190961910619116191261913619146191561916619176191861919619206192161922619236192461925619266192761928619296193061931619326193361934619356193661937619386193961940619416194261943619446194561946619476194861949619506195161952619536195461955619566195761958619596196061961619626196361964619656196661967619686196961970619716197261973619746197561976619776197861979619806198161982619836198461985619866198761988619896199061991619926199361994619956199661997619986199962000620016200262003620046200562006620076200862009620106201162012620136201462015620166201762018620196202062021620226202362024620256202662027620286202962030620316203262033620346203562036620376203862039620406204162042620436204462045620466204762048620496205062051620526205362054620556205662057620586205962060620616206262063620646206562066620676206862069620706207162072620736207462075620766207762078620796208062081620826208362084620856208662087620886208962090620916209262093620946209562096620976209862099621006210162102621036210462105621066210762108621096211062111621126211362114621156211662117621186211962120621216212262123621246212562126621276212862129621306213162132621336213462135621366213762138621396214062141621426214362144621456214662147621486214962150621516215262153621546215562156621576215862159621606216162162621636216462165621666216762168621696217062171621726217362174621756217662177621786217962180621816218262183621846218562186621876218862189621906219162192621936219462195621966219762198621996220062201622026220362204622056220662207622086220962210622116221262213622146221562216622176221862219622206222162222622236222462225622266222762228622296223062231622326223362234622356223662237622386223962240622416224262243622446224562246622476224862249622506225162252622536225462255622566225762258622596226062261622626226362264622656226662267622686226962270622716227262273622746227562276622776227862279622806228162282622836228462285622866228762288622896229062291622926229362294622956229662297622986229962300623016230262303623046230562306623076230862309623106231162312623136231462315623166231762318623196232062321623226232362324623256232662327623286232962330623316233262333623346233562336623376233862339623406234162342623436234462345623466234762348623496235062351623526235362354623556235662357623586235962360623616236262363623646236562366623676236862369623706237162372623736237462375623766237762378623796238062381623826238362384623856238662387623886238962390623916239262393623946239562396623976239862399624006240162402624036240462405624066240762408624096241062411624126241362414624156241662417624186241962420624216242262423624246242562426624276242862429624306243162432624336243462435624366243762438624396244062441624426244362444624456244662447624486244962450624516245262453624546245562456624576245862459624606246162462624636246462465624666246762468624696247062471624726247362474624756247662477624786247962480624816248262483624846248562486624876248862489624906249162492624936249462495624966249762498624996250062501625026250362504625056250662507625086250962510625116251262513625146251562516625176251862519625206252162522625236252462525625266252762528625296253062531625326253362534625356253662537625386253962540625416254262543625446254562546625476254862549625506255162552625536255462555625566255762558625596256062561625626256362564625656256662567625686256962570625716257262573625746257562576625776257862579625806258162582625836258462585625866258762588625896259062591625926259362594625956259662597625986259962600626016260262603626046260562606626076260862609626106261162612626136261462615626166261762618626196262062621626226262362624626256262662627626286262962630626316263262633626346263562636626376263862639626406264162642626436264462645626466264762648626496265062651626526265362654626556265662657626586265962660626616266262663626646266562666626676266862669626706267162672626736267462675626766267762678626796268062681626826268362684626856268662687626886268962690626916269262693626946269562696626976269862699627006270162702627036270462705627066270762708627096271062711627126271362714627156271662717627186271962720627216272262723627246272562726627276272862729627306273162732627336273462735627366273762738627396274062741627426274362744627456274662747627486274962750627516275262753627546275562756627576275862759627606276162762627636276462765627666276762768627696277062771627726277362774627756277662777627786277962780627816278262783627846278562786627876278862789627906279162792627936279462795627966279762798627996280062801628026280362804628056280662807628086280962810628116281262813628146281562816628176281862819628206282162822628236282462825628266282762828628296283062831628326283362834628356283662837628386283962840628416284262843628446284562846628476284862849628506285162852628536285462855628566285762858628596286062861628626286362864628656286662867628686286962870628716287262873628746287562876628776287862879628806288162882628836288462885628866288762888628896289062891628926289362894628956289662897628986289962900629016290262903629046290562906629076290862909629106291162912629136291462915629166291762918629196292062921629226292362924629256292662927629286292962930629316293262933629346293562936629376293862939629406294162942629436294462945629466294762948629496295062951629526295362954629556295662957629586295962960629616296262963629646296562966629676296862969629706297162972629736297462975629766297762978629796298062981629826298362984629856298662987629886298962990629916299262993629946299562996629976299862999630006300163002630036300463005630066300763008630096301063011630126301363014630156301663017630186301963020630216302263023630246302563026630276302863029630306303163032630336303463035630366303763038630396304063041630426304363044630456304663047630486304963050630516305263053630546305563056630576305863059630606306163062630636306463065630666306763068630696307063071630726307363074630756307663077630786307963080630816308263083630846308563086630876308863089630906309163092630936309463095630966309763098630996310063101631026310363104631056310663107631086310963110631116311263113631146311563116631176311863119631206312163122631236312463125631266312763128631296313063131631326313363134631356313663137631386313963140631416314263143631446314563146631476314863149631506315163152631536315463155631566315763158631596316063161631626316363164631656316663167631686316963170631716317263173631746317563176631776317863179631806318163182631836318463185631866318763188631896319063191631926319363194631956319663197631986319963200632016320263203632046320563206632076320863209632106321163212632136321463215632166321763218632196322063221632226322363224632256322663227632286322963230632316323263233632346323563236632376323863239632406324163242632436324463245632466324763248632496325063251632526325363254632556325663257632586325963260632616326263263632646326563266632676326863269632706327163272632736327463275632766327763278632796328063281632826328363284632856328663287632886328963290632916329263293632946329563296632976329863299633006330163302633036330463305633066330763308633096331063311633126331363314633156331663317633186331963320633216332263323633246332563326633276332863329633306333163332633336333463335633366333763338633396334063341633426334363344633456334663347633486334963350633516335263353633546335563356633576335863359633606336163362633636336463365633666336763368633696337063371633726337363374633756337663377633786337963380633816338263383633846338563386633876338863389633906339163392633936339463395633966339763398633996340063401634026340363404634056340663407634086340963410634116341263413634146341563416634176341863419634206342163422634236342463425634266342763428634296343063431634326343363434634356343663437634386343963440634416344263443634446344563446634476344863449634506345163452634536345463455634566345763458634596346063461634626346363464634656346663467634686346963470634716347263473634746347563476634776347863479634806348163482634836348463485634866348763488634896349063491634926349363494634956349663497634986349963500635016350263503635046350563506635076350863509635106351163512635136351463515635166351763518635196352063521635226352363524635256352663527635286352963530635316353263533635346353563536635376353863539635406354163542635436354463545635466354763548635496355063551635526355363554635556355663557635586355963560635616356263563635646356563566635676356863569635706357163572635736357463575635766357763578635796358063581635826358363584635856358663587635886358963590635916359263593635946359563596635976359863599636006360163602636036360463605636066360763608636096361063611636126361363614636156361663617636186361963620636216362263623636246362563626636276362863629636306363163632636336363463635636366363763638636396364063641636426364363644636456364663647636486364963650636516365263653636546365563656636576365863659636606366163662636636366463665636666366763668636696367063671636726367363674636756367663677636786367963680636816368263683636846368563686636876368863689636906369163692636936369463695636966369763698636996370063701637026370363704637056370663707637086370963710637116371263713637146371563716637176371863719637206372163722637236372463725637266372763728637296373063731637326373363734637356373663737637386373963740637416374263743637446374563746637476374863749637506375163752637536375463755637566375763758637596376063761637626376363764637656376663767637686376963770637716377263773637746377563776637776377863779637806378163782637836378463785637866378763788637896379063791637926379363794637956379663797637986379963800638016380263803638046380563806638076380863809638106381163812638136381463815638166381763818638196382063821638226382363824638256382663827638286382963830638316383263833638346383563836638376383863839638406384163842638436384463845638466384763848638496385063851638526385363854638556385663857638586385963860638616386263863638646386563866638676386863869638706387163872638736387463875638766387763878638796388063881638826388363884638856388663887638886388963890638916389263893638946389563896638976389863899639006390163902639036390463905639066390763908639096391063911639126391363914639156391663917639186391963920639216392263923639246392563926639276392863929639306393163932639336393463935639366393763938639396394063941639426394363944639456394663947639486394963950639516395263953639546395563956639576395863959639606396163962639636396463965639666396763968639696397063971639726397363974639756397663977639786397963980639816398263983639846398563986639876398863989639906399163992639936399463995639966399763998639996400064001640026400364004640056400664007640086400964010640116401264013640146401564016640176401864019640206402164022640236402464025640266402764028640296403064031640326403364034640356403664037640386403964040640416404264043640446404564046640476404864049640506405164052640536405464055640566405764058640596406064061640626406364064640656406664067640686406964070640716407264073640746407564076640776407864079640806408164082640836408464085640866408764088640896409064091640926409364094640956409664097640986409964100641016410264103641046410564106641076410864109641106411164112641136411464115641166411764118641196412064121641226412364124641256412664127641286412964130641316413264133641346413564136641376413864139641406414164142641436414464145641466414764148641496415064151641526415364154641556415664157641586415964160641616416264163641646416564166641676416864169641706417164172641736417464175641766417764178641796418064181641826418364184641856418664187641886418964190641916419264193641946419564196641976419864199642006420164202642036420464205642066420764208642096421064211642126421364214642156421664217642186421964220642216422264223642246422564226642276422864229642306423164232642336423464235642366423764238642396424064241642426424364244642456424664247642486424964250642516425264253642546425564256642576425864259642606426164262642636426464265642666426764268642696427064271642726427364274642756427664277642786427964280642816428264283642846428564286642876428864289642906429164292642936429464295642966429764298642996430064301643026430364304643056430664307643086430964310643116431264313643146431564316643176431864319643206432164322643236432464325643266432764328643296433064331643326433364334643356433664337643386433964340643416434264343643446434564346643476434864349643506435164352643536435464355643566435764358643596436064361643626436364364643656436664367643686436964370643716437264373643746437564376643776437864379643806438164382643836438464385643866438764388643896439064391643926439364394643956439664397643986439964400644016440264403644046440564406644076440864409644106441164412644136441464415644166441764418644196442064421644226442364424644256442664427644286442964430644316443264433644346443564436644376443864439644406444164442644436444464445644466444764448644496445064451644526445364454644556445664457644586445964460644616446264463644646446564466644676446864469644706447164472644736447464475644766447764478644796448064481644826448364484644856448664487644886448964490644916449264493644946449564496644976449864499645006450164502645036450464505645066450764508645096451064511645126451364514645156451664517645186451964520645216452264523645246452564526645276452864529645306453164532645336453464535645366453764538645396454064541645426454364544645456454664547645486454964550645516455264553645546455564556645576455864559645606456164562645636456464565645666456764568645696457064571645726457364574645756457664577645786457964580645816458264583645846458564586645876458864589645906459164592645936459464595645966459764598645996460064601646026460364604646056460664607646086460964610646116461264613646146461564616646176461864619646206462164622646236462464625646266462764628646296463064631646326463364634646356463664637646386463964640646416464264643646446464564646646476464864649646506465164652646536465464655646566465764658646596466064661646626466364664646656466664667646686466964670646716467264673646746467564676646776467864679646806468164682646836468464685646866468764688646896469064691646926469364694646956469664697646986469964700647016470264703647046470564706647076470864709647106471164712647136471464715647166471764718647196472064721647226472364724647256472664727647286472964730647316473264733647346473564736647376473864739647406474164742647436474464745647466474764748647496475064751647526475364754647556475664757647586475964760647616476264763647646476564766647676476864769647706477164772647736477464775647766477764778647796478064781647826478364784647856478664787647886478964790647916479264793647946479564796647976479864799648006480164802648036480464805648066480764808648096481064811648126481364814648156481664817648186481964820648216482264823648246482564826648276482864829648306483164832648336483464835648366483764838648396484064841648426484364844648456484664847648486484964850648516485264853648546485564856648576485864859648606486164862648636486464865648666486764868648696487064871648726487364874648756487664877648786487964880648816488264883648846488564886648876488864889648906489164892648936489464895648966489764898648996490064901649026490364904649056490664907649086490964910649116491264913649146491564916649176491864919649206492164922649236492464925649266492764928649296493064931649326493364934649356493664937649386493964940649416494264943649446494564946649476494864949649506495164952649536495464955649566495764958649596496064961649626496364964649656496664967649686496964970649716497264973649746497564976649776497864979649806498164982649836498464985649866498764988649896499064991649926499364994649956499664997649986499965000650016500265003650046500565006650076500865009650106501165012650136501465015650166501765018650196502065021650226502365024650256502665027650286502965030650316503265033650346503565036650376503865039650406504165042650436504465045650466504765048650496505065051650526505365054650556505665057650586505965060650616506265063650646506565066650676506865069650706507165072650736507465075650766507765078650796508065081650826508365084650856508665087650886508965090650916509265093650946509565096650976509865099651006510165102651036510465105651066510765108651096511065111651126511365114651156511665117651186511965120651216512265123651246512565126651276512865129651306513165132651336513465135651366513765138651396514065141651426514365144651456514665147651486514965150651516515265153651546515565156651576515865159651606516165162651636516465165651666516765168651696517065171651726517365174651756517665177651786517965180651816518265183651846518565186651876518865189651906519165192651936519465195651966519765198651996520065201652026520365204652056520665207652086520965210652116521265213652146521565216652176521865219652206522165222652236522465225652266522765228652296523065231652326523365234652356523665237652386523965240652416524265243652446524565246652476524865249652506525165252652536525465255652566525765258652596526065261652626526365264652656526665267652686526965270652716527265273652746527565276652776527865279652806528165282652836528465285652866528765288652896529065291652926529365294652956529665297652986529965300653016530265303653046530565306653076530865309653106531165312653136531465315653166531765318653196532065321653226532365324653256532665327653286532965330653316533265333653346533565336653376533865339653406534165342653436534465345653466534765348653496535065351653526535365354653556535665357653586535965360653616536265363653646536565366653676536865369653706537165372653736537465375653766537765378653796538065381653826538365384653856538665387653886538965390653916539265393653946539565396653976539865399654006540165402654036540465405654066540765408654096541065411654126541365414654156541665417654186541965420654216542265423654246542565426654276542865429654306543165432654336543465435654366543765438654396544065441654426544365444654456544665447654486544965450654516545265453654546545565456654576545865459654606546165462654636546465465654666546765468654696547065471654726547365474654756547665477654786547965480654816548265483654846548565486654876548865489654906549165492654936549465495654966549765498654996550065501655026550365504655056550665507655086550965510655116551265513655146551565516655176551865519655206552165522655236552465525655266552765528655296553065531655326553365534655356553665537655386553965540655416554265543655446554565546655476554865549655506555165552655536555465555655566555765558655596556065561655626556365564655656556665567655686556965570655716557265573655746557565576655776557865579655806558165582655836558465585655866558765588655896559065591655926559365594655956559665597655986559965600656016560265603656046560565606656076560865609656106561165612656136561465615656166561765618656196562065621656226562365624656256562665627656286562965630656316563265633656346563565636656376563865639656406564165642656436564465645656466564765648656496565065651656526565365654656556565665657656586565965660656616566265663656646566565666656676566865669656706567165672656736567465675656766567765678656796568065681656826568365684656856568665687656886568965690656916569265693656946569565696656976569865699657006570165702657036570465705657066570765708657096571065711657126571365714657156571665717657186571965720657216572265723657246572565726657276572865729657306573165732657336573465735657366573765738657396574065741657426574365744657456574665747657486574965750657516575265753657546575565756657576575865759657606576165762657636576465765657666576765768657696577065771657726577365774657756577665777657786577965780657816578265783657846578565786657876578865789657906579165792657936579465795657966579765798657996580065801658026580365804658056580665807658086580965810658116581265813658146581565816658176581865819658206582165822658236582465825658266582765828658296583065831658326583365834658356583665837658386583965840658416584265843658446584565846658476584865849658506585165852658536585465855658566585765858658596586065861658626586365864658656586665867658686586965870658716587265873658746587565876658776587865879658806588165882658836588465885658866588765888658896589065891658926589365894658956589665897658986589965900659016590265903659046590565906659076590865909659106591165912659136591465915659166591765918659196592065921659226592365924659256592665927659286592965930659316593265933659346593565936659376593865939659406594165942659436594465945659466594765948659496595065951659526595365954659556595665957659586595965960659616596265963659646596565966659676596865969659706597165972659736597465975659766597765978659796598065981659826598365984659856598665987659886598965990659916599265993659946599565996659976599865999660006600166002660036600466005660066600766008660096601066011660126601366014660156601666017660186601966020660216602266023660246602566026660276602866029660306603166032660336603466035660366603766038660396604066041660426604366044660456604666047660486604966050660516605266053660546605566056660576605866059660606606166062660636606466065660666606766068660696607066071660726607366074660756607666077660786607966080660816608266083660846608566086660876608866089660906609166092660936609466095660966609766098660996610066101661026610366104661056610666107661086610966110661116611266113661146611566116661176611866119661206612166122661236612466125661266612766128661296613066131661326613366134661356613666137661386613966140661416614266143661446614566146661476614866149661506615166152661536615466155661566615766158661596616066161661626616366164661656616666167661686616966170661716617266173661746617566176661776617866179661806618166182661836618466185661866618766188661896619066191661926619366194661956619666197661986619966200662016620266203662046620566206662076620866209662106621166212662136621466215662166621766218662196622066221662226622366224662256622666227662286622966230662316623266233662346623566236662376623866239662406624166242662436624466245662466624766248662496625066251662526625366254662556625666257662586625966260662616626266263662646626566266662676626866269662706627166272662736627466275662766627766278662796628066281662826628366284662856628666287662886628966290662916629266293662946629566296662976629866299663006630166302663036630466305663066630766308663096631066311663126631366314663156631666317663186631966320663216632266323663246632566326663276632866329663306633166332663336633466335663366633766338663396634066341663426634366344663456634666347663486634966350663516635266353663546635566356663576635866359663606636166362663636636466365663666636766368663696637066371663726637366374663756637666377663786637966380663816638266383663846638566386663876638866389663906639166392663936639466395663966639766398663996640066401664026640366404664056640666407664086640966410664116641266413664146641566416664176641866419664206642166422664236642466425664266642766428664296643066431664326643366434664356643666437664386643966440664416644266443664446644566446664476644866449664506645166452664536645466455664566645766458664596646066461664626646366464664656646666467664686646966470664716647266473664746647566476664776647866479664806648166482664836648466485664866648766488664896649066491664926649366494664956649666497664986649966500665016650266503665046650566506665076650866509665106651166512665136651466515665166651766518665196652066521665226652366524665256652666527665286652966530665316653266533665346653566536665376653866539665406654166542665436654466545665466654766548665496655066551665526655366554665556655666557665586655966560665616656266563665646656566566665676656866569665706657166572665736657466575665766657766578665796658066581665826658366584665856658666587665886658966590665916659266593665946659566596665976659866599666006660166602666036660466605666066660766608666096661066611666126661366614666156661666617666186661966620666216662266623666246662566626666276662866629666306663166632666336663466635666366663766638666396664066641666426664366644666456664666647666486664966650666516665266653666546665566656666576665866659666606666166662666636666466665666666666766668666696667066671666726667366674666756667666677666786667966680666816668266683666846668566686666876668866689666906669166692666936669466695666966669766698666996670066701667026670366704667056670666707667086670966710667116671266713667146671566716667176671866719667206672166722667236672466725667266672766728667296673066731667326673366734667356673666737667386673966740667416674266743667446674566746667476674866749667506675166752667536675466755667566675766758667596676066761667626676366764667656676666767667686676966770667716677266773667746677566776667776677866779667806678166782667836678466785667866678766788667896679066791667926679366794667956679666797667986679966800668016680266803668046680566806668076680866809668106681166812668136681466815668166681766818668196682066821668226682366824668256682666827668286682966830668316683266833668346683566836668376683866839668406684166842668436684466845668466684766848668496685066851668526685366854668556685666857668586685966860668616686266863668646686566866668676686866869668706687166872668736687466875668766687766878668796688066881668826688366884668856688666887668886688966890668916689266893668946689566896668976689866899669006690166902669036690466905669066690766908669096691066911669126691366914669156691666917669186691966920669216692266923669246692566926669276692866929669306693166932669336693466935669366693766938669396694066941669426694366944669456694666947669486694966950669516695266953669546695566956669576695866959669606696166962669636696466965669666696766968669696697066971669726697366974669756697666977669786697966980669816698266983669846698566986669876698866989669906699166992669936699466995669966699766998669996700067001670026700367004670056700667007670086700967010670116701267013670146701567016670176701867019670206702167022670236702467025670266702767028670296703067031670326703367034670356703667037670386703967040670416704267043670446704567046670476704867049670506705167052670536705467055670566705767058670596706067061670626706367064670656706667067670686706967070670716707267073670746707567076670776707867079670806708167082670836708467085670866708767088670896709067091670926709367094670956709667097670986709967100671016710267103671046710567106671076710867109671106711167112671136711467115671166711767118671196712067121671226712367124671256712667127671286712967130671316713267133671346713567136671376713867139671406714167142671436714467145671466714767148671496715067151671526715367154671556715667157671586715967160671616716267163671646716567166671676716867169671706717167172671736717467175671766717767178671796718067181671826718367184671856718667187671886718967190671916719267193671946719567196671976719867199672006720167202672036720467205672066720767208672096721067211672126721367214672156721667217672186721967220672216722267223672246722567226672276722867229672306723167232672336723467235672366723767238672396724067241672426724367244672456724667247672486724967250672516725267253672546725567256672576725867259672606726167262672636726467265672666726767268672696727067271672726727367274672756727667277672786727967280672816728267283672846728567286672876728867289672906729167292672936729467295672966729767298672996730067301673026730367304673056730667307673086730967310673116731267313673146731567316673176731867319673206732167322673236732467325673266732767328673296733067331673326733367334673356733667337673386733967340673416734267343673446734567346673476734867349673506735167352673536735467355673566735767358673596736067361673626736367364673656736667367673686736967370673716737267373673746737567376673776737867379673806738167382673836738467385673866738767388673896739067391673926739367394673956739667397673986739967400674016740267403674046740567406674076740867409674106741167412674136741467415674166741767418674196742067421674226742367424674256742667427674286742967430674316743267433674346743567436674376743867439674406744167442674436744467445674466744767448674496745067451674526745367454674556745667457674586745967460674616746267463674646746567466674676746867469674706747167472674736747467475674766747767478674796748067481674826748367484674856748667487674886748967490674916749267493674946749567496674976749867499675006750167502675036750467505675066750767508675096751067511675126751367514675156751667517675186751967520675216752267523675246752567526675276752867529675306753167532675336753467535675366753767538675396754067541675426754367544675456754667547675486754967550675516755267553675546755567556675576755867559675606756167562675636756467565675666756767568675696757067571675726757367574675756757667577675786757967580675816758267583675846758567586675876758867589675906759167592675936759467595675966759767598675996760067601676026760367604676056760667607676086760967610676116761267613676146761567616676176761867619676206762167622676236762467625676266762767628676296763067631676326763367634676356763667637676386763967640676416764267643676446764567646676476764867649676506765167652676536765467655676566765767658676596766067661676626766367664676656766667667676686766967670676716767267673676746767567676676776767867679676806768167682676836768467685676866768767688676896769067691676926769367694676956769667697676986769967700677016770267703677046770567706677076770867709677106771167712677136771467715677166771767718677196772067721677226772367724677256772667727677286772967730677316773267733677346773567736677376773867739677406774167742677436774467745677466774767748677496775067751677526775367754677556775667757677586775967760677616776267763677646776567766677676776867769677706777167772677736777467775677766777767778677796778067781677826778367784677856778667787677886778967790677916779267793677946779567796677976779867799678006780167802678036780467805678066780767808678096781067811678126781367814678156781667817678186781967820678216782267823678246782567826678276782867829678306783167832678336783467835678366783767838678396784067841678426784367844678456784667847678486784967850678516785267853678546785567856678576785867859678606786167862678636786467865678666786767868678696787067871678726787367874678756787667877678786787967880678816788267883678846788567886678876788867889678906789167892678936789467895678966789767898678996790067901679026790367904679056790667907679086790967910679116791267913679146791567916679176791867919679206792167922679236792467925679266792767928679296793067931679326793367934679356793667937679386793967940679416794267943679446794567946679476794867949679506795167952679536795467955679566795767958679596796067961679626796367964679656796667967679686796967970679716797267973679746797567976679776797867979679806798167982679836798467985679866798767988679896799067991679926799367994679956799667997679986799968000680016800268003680046800568006680076800868009680106801168012680136801468015680166801768018680196802068021680226802368024680256802668027680286802968030680316803268033680346803568036680376803868039680406804168042680436804468045680466804768048680496805068051680526805368054680556805668057680586805968060680616806268063680646806568066680676806868069680706807168072680736807468075680766807768078680796808068081680826808368084680856808668087680886808968090680916809268093680946809568096680976809868099681006810168102681036810468105681066810768108681096811068111681126811368114681156811668117681186811968120681216812268123681246812568126681276812868129681306813168132681336813468135681366813768138681396814068141681426814368144681456814668147681486814968150681516815268153681546815568156681576815868159681606816168162681636816468165681666816768168681696817068171681726817368174681756817668177681786817968180681816818268183681846818568186681876818868189681906819168192681936819468195681966819768198681996820068201682026820368204682056820668207682086820968210682116821268213682146821568216682176821868219682206822168222682236822468225682266822768228682296823068231682326823368234682356823668237682386823968240682416824268243682446824568246682476824868249682506825168252682536825468255682566825768258682596826068261682626826368264682656826668267682686826968270682716827268273682746827568276682776827868279682806828168282682836828468285682866828768288682896829068291682926829368294682956829668297682986829968300683016830268303683046830568306683076830868309683106831168312683136831468315683166831768318683196832068321683226832368324683256832668327683286832968330683316833268333683346833568336683376833868339683406834168342683436834468345683466834768348683496835068351683526835368354683556835668357683586835968360683616836268363683646836568366683676836868369683706837168372683736837468375683766837768378683796838068381683826838368384683856838668387683886838968390683916839268393683946839568396683976839868399684006840168402684036840468405684066840768408684096841068411684126841368414684156841668417684186841968420684216842268423684246842568426684276842868429684306843168432684336843468435684366843768438684396844068441684426844368444684456844668447684486844968450684516845268453684546845568456684576845868459684606846168462684636846468465684666846768468684696847068471684726847368474684756847668477684786847968480684816848268483684846848568486684876848868489684906849168492684936849468495684966849768498684996850068501685026850368504685056850668507685086850968510685116851268513685146851568516685176851868519685206852168522685236852468525685266852768528685296853068531685326853368534685356853668537685386853968540685416854268543685446854568546685476854868549685506855168552685536855468555685566855768558685596856068561685626856368564685656856668567685686856968570685716857268573685746857568576685776857868579685806858168582685836858468585685866858768588685896859068591685926859368594685956859668597685986859968600686016860268603686046860568606686076860868609686106861168612686136861468615686166861768618686196862068621686226862368624686256862668627686286862968630686316863268633686346863568636686376863868639686406864168642686436864468645686466864768648686496865068651686526865368654686556865668657686586865968660686616866268663686646866568666686676866868669686706867168672686736867468675686766867768678686796868068681686826868368684686856868668687686886868968690686916869268693686946869568696686976869868699687006870168702687036870468705687066870768708687096871068711687126871368714687156871668717687186871968720687216872268723687246872568726687276872868729687306873168732687336873468735687366873768738687396874068741687426874368744687456874668747687486874968750687516875268753687546875568756687576875868759687606876168762687636876468765687666876768768687696877068771687726877368774687756877668777687786877968780687816878268783687846878568786687876878868789687906879168792687936879468795687966879768798687996880068801688026880368804688056880668807688086880968810688116881268813688146881568816688176881868819688206882168822688236882468825688266882768828688296883068831688326883368834688356883668837688386883968840688416884268843688446884568846688476884868849688506885168852688536885468855688566885768858688596886068861688626886368864688656886668867688686886968870688716887268873688746887568876688776887868879688806888168882688836888468885688866888768888688896889068891688926889368894688956889668897688986889968900689016890268903689046890568906689076890868909689106891168912689136891468915689166891768918689196892068921689226892368924689256892668927689286892968930689316893268933689346893568936689376893868939689406894168942689436894468945689466894768948689496895068951689526895368954689556895668957689586895968960689616896268963689646896568966689676896868969689706897168972689736897468975689766897768978689796898068981689826898368984689856898668987689886898968990689916899268993689946899568996689976899868999690006900169002690036900469005690066900769008690096901069011690126901369014690156901669017690186901969020690216902269023690246902569026690276902869029690306903169032690336903469035690366903769038690396904069041690426904369044690456904669047690486904969050690516905269053690546905569056690576905869059690606906169062690636906469065690666906769068690696907069071690726907369074690756907669077690786907969080690816908269083690846908569086690876908869089690906909169092690936909469095690966909769098690996910069101691026910369104691056910669107691086910969110691116911269113691146911569116691176911869119691206912169122691236912469125691266912769128691296913069131691326913369134691356913669137691386913969140691416914269143691446914569146691476914869149691506915169152691536915469155691566915769158691596916069161691626916369164691656916669167691686916969170691716917269173691746917569176691776917869179691806918169182691836918469185691866918769188691896919069191691926919369194691956919669197691986919969200692016920269203692046920569206692076920869209692106921169212692136921469215692166921769218692196922069221692226922369224692256922669227692286922969230692316923269233692346923569236692376923869239692406924169242692436924469245692466924769248692496925069251692526925369254692556925669257692586925969260692616926269263692646926569266692676926869269692706927169272692736927469275692766927769278692796928069281692826928369284692856928669287692886928969290692916929269293692946929569296692976929869299693006930169302693036930469305693066930769308693096931069311693126931369314693156931669317693186931969320693216932269323693246932569326693276932869329693306933169332693336933469335693366933769338693396934069341693426934369344693456934669347693486934969350693516935269353693546935569356693576935869359693606936169362693636936469365693666936769368693696937069371693726937369374693756937669377693786937969380693816938269383693846938569386693876938869389693906939169392693936939469395693966939769398693996940069401694026940369404694056940669407694086940969410694116941269413694146941569416694176941869419694206942169422694236942469425694266942769428694296943069431694326943369434694356943669437694386943969440694416944269443694446944569446694476944869449694506945169452694536945469455694566945769458694596946069461694626946369464694656946669467694686946969470694716947269473694746947569476694776947869479694806948169482694836948469485694866948769488694896949069491694926949369494694956949669497694986949969500695016950269503695046950569506695076950869509695106951169512695136951469515695166951769518695196952069521695226952369524695256952669527695286952969530695316953269533695346953569536695376953869539695406954169542695436954469545695466954769548695496955069551695526955369554695556955669557695586955969560695616956269563695646956569566695676956869569695706957169572695736957469575695766957769578695796958069581695826958369584695856958669587695886958969590695916959269593695946959569596695976959869599696006960169602696036960469605696066960769608696096961069611696126961369614696156961669617696186961969620696216962269623696246962569626696276962869629696306963169632696336963469635696366963769638696396964069641696426964369644696456964669647696486964969650696516965269653696546965569656696576965869659696606966169662696636966469665696666966769668696696967069671696726967369674696756967669677696786967969680696816968269683696846968569686696876968869689696906969169692696936969469695696966969769698696996970069701697026970369704697056970669707697086970969710697116971269713697146971569716697176971869719697206972169722697236972469725697266972769728697296973069731697326973369734697356973669737697386973969740697416974269743697446974569746697476974869749697506975169752697536975469755697566975769758697596976069761697626976369764697656976669767697686976969770697716977269773697746977569776697776977869779697806978169782697836978469785697866978769788697896979069791697926979369794697956979669797697986979969800698016980269803698046980569806698076980869809698106981169812698136981469815698166981769818698196982069821698226982369824698256982669827698286982969830698316983269833698346983569836698376983869839698406984169842698436984469845698466984769848698496985069851698526985369854698556985669857698586985969860698616986269863698646986569866698676986869869698706987169872698736987469875698766987769878698796988069881698826988369884698856988669887698886988969890698916989269893698946989569896698976989869899699006990169902699036990469905699066990769908699096991069911699126991369914699156991669917699186991969920699216992269923699246992569926699276992869929699306993169932699336993469935699366993769938699396994069941699426994369944699456994669947699486994969950699516995269953699546995569956699576995869959699606996169962699636996469965699666996769968699696997069971699726997369974699756997669977699786997969980699816998269983699846998569986699876998869989699906999169992699936999469995699966999769998699997000070001700027000370004700057000670007700087000970010700117001270013700147001570016700177001870019700207002170022700237002470025700267002770028700297003070031700327003370034700357003670037700387003970040700417004270043700447004570046700477004870049700507005170052700537005470055700567005770058700597006070061700627006370064700657006670067700687006970070700717007270073700747007570076700777007870079700807008170082700837008470085700867008770088700897009070091700927009370094700957009670097700987009970100701017010270103701047010570106701077010870109701107011170112701137011470115701167011770118701197012070121701227012370124701257012670127701287012970130701317013270133701347013570136701377013870139701407014170142701437014470145701467014770148701497015070151701527015370154701557015670157701587015970160701617016270163701647016570166701677016870169701707017170172701737017470175701767017770178701797018070181701827018370184701857018670187701887018970190701917019270193701947019570196701977019870199702007020170202702037020470205702067020770208702097021070211702127021370214702157021670217702187021970220702217022270223702247022570226702277022870229702307023170232702337023470235702367023770238702397024070241702427024370244702457024670247702487024970250702517025270253702547025570256702577025870259702607026170262702637026470265702667026770268702697027070271702727027370274702757027670277702787027970280702817028270283702847028570286702877028870289702907029170292702937029470295702967029770298702997030070301703027030370304703057030670307703087030970310703117031270313703147031570316703177031870319703207032170322703237032470325703267032770328703297033070331703327033370334703357033670337703387033970340703417034270343703447034570346703477034870349703507035170352703537035470355703567035770358703597036070361703627036370364703657036670367703687036970370703717037270373703747037570376703777037870379703807038170382703837038470385703867038770388703897039070391703927039370394703957039670397703987039970400704017040270403704047040570406704077040870409704107041170412704137041470415704167041770418704197042070421704227042370424704257042670427704287042970430704317043270433704347043570436704377043870439704407044170442704437044470445704467044770448704497045070451704527045370454704557045670457704587045970460704617046270463704647046570466704677046870469704707047170472704737047470475704767047770478704797048070481704827048370484704857048670487704887048970490704917049270493704947049570496704977049870499705007050170502705037050470505705067050770508705097051070511705127051370514705157051670517705187051970520705217052270523705247052570526705277052870529705307053170532705337053470535705367053770538705397054070541705427054370544705457054670547705487054970550705517055270553705547055570556705577055870559705607056170562705637056470565705667056770568705697057070571705727057370574705757057670577705787057970580705817058270583705847058570586705877058870589705907059170592705937059470595705967059770598705997060070601706027060370604706057060670607706087060970610706117061270613706147061570616706177061870619706207062170622706237062470625706267062770628706297063070631706327063370634706357063670637706387063970640706417064270643706447064570646706477064870649706507065170652706537065470655706567065770658706597066070661706627066370664706657066670667706687066970670706717067270673706747067570676706777067870679706807068170682706837068470685706867068770688706897069070691706927069370694706957069670697706987069970700707017070270703707047070570706707077070870709707107071170712707137071470715707167071770718707197072070721707227072370724707257072670727707287072970730707317073270733707347073570736707377073870739707407074170742707437074470745707467074770748707497075070751707527075370754707557075670757707587075970760707617076270763707647076570766707677076870769707707077170772707737077470775707767077770778707797078070781707827078370784707857078670787707887078970790707917079270793707947079570796707977079870799708007080170802708037080470805708067080770808708097081070811708127081370814708157081670817708187081970820708217082270823708247082570826708277082870829708307083170832708337083470835708367083770838708397084070841708427084370844708457084670847708487084970850708517085270853708547085570856708577085870859708607086170862708637086470865708667086770868708697087070871708727087370874708757087670877708787087970880708817088270883708847088570886708877088870889708907089170892708937089470895708967089770898708997090070901709027090370904709057090670907709087090970910709117091270913709147091570916709177091870919709207092170922709237092470925709267092770928709297093070931709327093370934709357093670937709387093970940709417094270943709447094570946709477094870949709507095170952709537095470955709567095770958709597096070961709627096370964709657096670967709687096970970709717097270973709747097570976709777097870979709807098170982709837098470985709867098770988709897099070991709927099370994709957099670997709987099971000710017100271003710047100571006710077100871009710107101171012710137101471015710167101771018710197102071021710227102371024710257102671027710287102971030710317103271033710347103571036710377103871039710407104171042710437104471045710467104771048710497105071051710527105371054710557105671057710587105971060710617106271063710647106571066710677106871069710707107171072710737107471075710767107771078710797108071081710827108371084710857108671087710887108971090710917109271093710947109571096710977109871099711007110171102711037110471105711067110771108711097111071111711127111371114711157111671117711187111971120711217112271123711247112571126711277112871129711307113171132711337113471135711367113771138711397114071141711427114371144711457114671147711487114971150711517115271153711547115571156711577115871159711607116171162711637116471165711667116771168711697117071171711727117371174711757117671177711787117971180711817118271183711847118571186711877118871189711907119171192711937119471195711967119771198711997120071201712027120371204712057120671207712087120971210712117121271213712147121571216712177121871219712207122171222712237122471225712267122771228712297123071231712327123371234712357123671237712387123971240712417124271243712447124571246712477124871249712507125171252712537125471255712567125771258712597126071261712627126371264712657126671267712687126971270712717127271273712747127571276712777127871279712807128171282712837128471285712867128771288712897129071291712927129371294712957129671297712987129971300713017130271303713047130571306713077130871309713107131171312713137131471315713167131771318713197132071321713227132371324713257132671327713287132971330713317133271333713347133571336713377133871339713407134171342713437134471345713467134771348713497135071351713527135371354713557135671357713587135971360713617136271363713647136571366713677136871369713707137171372713737137471375713767137771378713797138071381713827138371384713857138671387713887138971390713917139271393713947139571396713977139871399714007140171402714037140471405714067140771408714097141071411714127141371414714157141671417714187141971420714217142271423714247142571426714277142871429714307143171432714337143471435714367143771438714397144071441714427144371444714457144671447714487144971450714517145271453714547145571456714577145871459714607146171462714637146471465714667146771468714697147071471714727147371474714757147671477714787147971480714817148271483714847148571486714877148871489714907149171492714937149471495714967149771498714997150071501715027150371504715057150671507715087150971510715117151271513715147151571516715177151871519715207152171522715237152471525715267152771528715297153071531715327153371534715357153671537715387153971540715417154271543715447154571546715477154871549715507155171552715537155471555715567155771558715597156071561715627156371564715657156671567715687156971570715717157271573715747157571576715777157871579715807158171582715837158471585715867158771588715897159071591715927159371594715957159671597715987159971600716017160271603716047160571606716077160871609716107161171612716137161471615716167161771618716197162071621716227162371624716257162671627716287162971630716317163271633716347163571636716377163871639716407164171642716437164471645716467164771648716497165071651716527165371654716557165671657716587165971660716617166271663716647166571666716677166871669716707167171672716737167471675716767167771678716797168071681716827168371684716857168671687716887168971690716917169271693716947169571696716977169871699717007170171702717037170471705717067170771708717097171071711717127171371714717157171671717717187171971720717217172271723717247172571726717277172871729717307173171732717337173471735717367173771738717397174071741717427174371744717457174671747717487174971750717517175271753717547175571756717577175871759717607176171762717637176471765717667176771768717697177071771717727177371774717757177671777717787177971780717817178271783717847178571786717877178871789717907179171792717937179471795717967179771798717997180071801718027180371804718057180671807718087180971810718117181271813718147181571816718177181871819718207182171822718237182471825718267182771828718297183071831718327183371834718357183671837718387183971840718417184271843718447184571846718477184871849718507185171852718537185471855718567185771858718597186071861718627186371864718657186671867718687186971870718717187271873718747187571876718777187871879718807188171882718837188471885718867188771888718897189071891718927189371894718957189671897718987189971900719017190271903719047190571906719077190871909719107191171912719137191471915719167191771918719197192071921719227192371924719257192671927719287192971930719317193271933719347193571936719377193871939719407194171942719437194471945719467194771948719497195071951719527195371954719557195671957719587195971960719617196271963719647196571966719677196871969719707197171972719737197471975719767197771978719797198071981719827198371984719857198671987719887198971990719917199271993719947199571996719977199871999720007200172002720037200472005720067200772008720097201072011720127201372014720157201672017720187201972020720217202272023720247202572026720277202872029720307203172032720337203472035720367203772038720397204072041720427204372044720457204672047720487204972050720517205272053720547205572056720577205872059720607206172062720637206472065720667206772068720697207072071720727207372074720757207672077720787207972080720817208272083720847208572086720877208872089720907209172092720937209472095720967209772098720997210072101721027210372104721057210672107721087210972110721117211272113721147211572116721177211872119721207212172122721237212472125721267212772128721297213072131721327213372134721357213672137721387213972140721417214272143721447214572146721477214872149721507215172152721537215472155721567215772158721597216072161721627216372164721657216672167721687216972170721717217272173721747217572176721777217872179721807218172182721837218472185721867218772188721897219072191721927219372194721957219672197721987219972200722017220272203722047220572206722077220872209722107221172212722137221472215722167221772218722197222072221722227222372224722257222672227722287222972230722317223272233722347223572236722377223872239722407224172242722437224472245722467224772248722497225072251722527225372254722557225672257722587225972260722617226272263722647226572266722677226872269722707227172272722737227472275722767227772278722797228072281722827228372284722857228672287722887228972290722917229272293722947229572296722977229872299723007230172302723037230472305723067230772308723097231072311723127231372314723157231672317723187231972320723217232272323723247232572326723277232872329723307233172332723337233472335723367233772338723397234072341723427234372344723457234672347723487234972350723517235272353723547235572356723577235872359723607236172362723637236472365723667236772368723697237072371723727237372374723757237672377723787237972380723817238272383723847238572386723877238872389723907239172392723937239472395723967239772398723997240072401724027240372404724057240672407724087240972410724117241272413724147241572416724177241872419724207242172422724237242472425724267242772428724297243072431724327243372434724357243672437724387243972440724417244272443724447244572446724477244872449724507245172452724537245472455724567245772458724597246072461724627246372464724657246672467724687246972470724717247272473724747247572476724777247872479724807248172482724837248472485724867248772488724897249072491724927249372494724957249672497724987249972500725017250272503725047250572506725077250872509725107251172512725137251472515725167251772518725197252072521725227252372524725257252672527725287252972530725317253272533725347253572536725377253872539725407254172542725437254472545725467254772548725497255072551725527255372554725557255672557725587255972560725617256272563725647256572566725677256872569725707257172572725737257472575725767257772578725797258072581725827258372584725857258672587725887258972590725917259272593725947259572596725977259872599726007260172602726037260472605726067260772608726097261072611726127261372614726157261672617726187261972620726217262272623726247262572626726277262872629726307263172632726337263472635726367263772638726397264072641726427264372644726457264672647726487264972650726517265272653726547265572656726577265872659726607266172662726637266472665726667266772668726697267072671726727267372674726757267672677726787267972680726817268272683726847268572686726877268872689726907269172692726937269472695726967269772698726997270072701727027270372704727057270672707727087270972710727117271272713727147271572716727177271872719727207272172722727237272472725727267272772728727297273072731727327273372734727357273672737727387273972740727417274272743727447274572746727477274872749727507275172752727537275472755727567275772758727597276072761727627276372764727657276672767727687276972770727717277272773727747277572776727777277872779727807278172782727837278472785727867278772788727897279072791727927279372794727957279672797727987279972800728017280272803728047280572806728077280872809728107281172812728137281472815728167281772818728197282072821728227282372824728257282672827728287282972830728317283272833728347283572836728377283872839728407284172842728437284472845728467284772848728497285072851728527285372854728557285672857728587285972860728617286272863728647286572866728677286872869728707287172872728737287472875728767287772878728797288072881728827288372884728857288672887728887288972890728917289272893728947289572896728977289872899729007290172902729037290472905729067290772908729097291072911729127291372914729157291672917729187291972920729217292272923729247292572926729277292872929729307293172932729337293472935729367293772938729397294072941729427294372944729457294672947729487294972950729517295272953729547295572956729577295872959729607296172962729637296472965729667296772968729697297072971729727297372974729757297672977729787297972980729817298272983729847298572986729877298872989729907299172992729937299472995729967299772998729997300073001730027300373004730057300673007730087300973010730117301273013730147301573016730177301873019730207302173022730237302473025730267302773028730297303073031730327303373034730357303673037730387303973040730417304273043730447304573046730477304873049730507305173052730537305473055730567305773058730597306073061730627306373064730657306673067730687306973070730717307273073730747307573076730777307873079730807308173082730837308473085730867308773088730897309073091730927309373094730957309673097730987309973100731017310273103731047310573106731077310873109731107311173112731137311473115731167311773118731197312073121731227312373124731257312673127731287312973130731317313273133731347313573136731377313873139731407314173142731437314473145731467314773148731497315073151731527315373154731557315673157731587315973160731617316273163731647316573166731677316873169731707317173172731737317473175731767317773178731797318073181731827318373184731857318673187731887318973190731917319273193731947319573196731977319873199732007320173202732037320473205732067320773208732097321073211732127321373214732157321673217732187321973220732217322273223732247322573226732277322873229732307323173232732337323473235732367323773238732397324073241732427324373244732457324673247732487324973250732517325273253732547325573256732577325873259732607326173262732637326473265732667326773268732697327073271732727327373274732757327673277732787327973280732817328273283732847328573286732877328873289732907329173292732937329473295732967329773298732997330073301733027330373304733057330673307733087330973310733117331273313733147331573316733177331873319733207332173322733237332473325733267332773328733297333073331733327333373334733357333673337733387333973340733417334273343733447334573346733477334873349733507335173352733537335473355733567335773358733597336073361733627336373364733657336673367733687336973370733717337273373733747337573376733777337873379733807338173382733837338473385733867338773388733897339073391733927339373394733957339673397733987339973400734017340273403734047340573406734077340873409734107341173412734137341473415734167341773418734197342073421734227342373424734257342673427734287342973430734317343273433734347343573436734377343873439734407344173442734437344473445734467344773448734497345073451734527345373454734557345673457734587345973460734617346273463734647346573466734677346873469734707347173472734737347473475734767347773478734797348073481734827348373484734857348673487734887348973490734917349273493734947349573496734977349873499735007350173502735037350473505735067350773508735097351073511735127351373514735157351673517735187351973520735217352273523735247352573526735277352873529735307353173532735337353473535735367353773538735397354073541735427354373544735457354673547735487354973550735517355273553735547355573556735577355873559735607356173562735637356473565735667356773568735697357073571735727357373574735757357673577735787357973580735817358273583735847358573586735877358873589735907359173592735937359473595735967359773598735997360073601736027360373604736057360673607736087360973610736117361273613736147361573616736177361873619736207362173622736237362473625736267362773628736297363073631736327363373634736357363673637736387363973640736417364273643736447364573646736477364873649736507365173652736537365473655736567365773658736597366073661736627366373664736657366673667736687366973670736717367273673736747367573676736777367873679736807368173682736837368473685736867368773688736897369073691736927369373694736957369673697736987369973700737017370273703737047370573706737077370873709737107371173712737137371473715737167371773718737197372073721737227372373724737257372673727737287372973730737317373273733737347373573736737377373873739737407374173742737437374473745737467374773748737497375073751737527375373754737557375673757737587375973760737617376273763737647376573766737677376873769737707377173772737737377473775737767377773778737797378073781737827378373784737857378673787737887378973790737917379273793737947379573796737977379873799738007380173802738037380473805738067380773808738097381073811738127381373814738157381673817738187381973820738217382273823738247382573826738277382873829738307383173832738337383473835738367383773838738397384073841738427384373844738457384673847738487384973850738517385273853738547385573856738577385873859738607386173862738637386473865738667386773868738697387073871738727387373874738757387673877738787387973880738817388273883738847388573886738877388873889738907389173892738937389473895738967389773898738997390073901739027390373904739057390673907739087390973910739117391273913739147391573916739177391873919739207392173922739237392473925739267392773928739297393073931739327393373934739357393673937739387393973940739417394273943739447394573946739477394873949739507395173952739537395473955739567395773958739597396073961739627396373964739657396673967739687396973970739717397273973739747397573976739777397873979739807398173982739837398473985739867398773988739897399073991739927399373994739957399673997739987399974000740017400274003740047400574006740077400874009740107401174012740137401474015740167401774018740197402074021740227402374024740257402674027740287402974030740317403274033740347403574036740377403874039740407404174042740437404474045740467404774048740497405074051740527405374054740557405674057740587405974060740617406274063740647406574066740677406874069740707407174072740737407474075740767407774078740797408074081740827408374084740857408674087740887408974090740917409274093740947409574096740977409874099741007410174102741037410474105741067410774108741097411074111741127411374114741157411674117741187411974120741217412274123741247412574126741277412874129741307413174132741337413474135741367413774138741397414074141741427414374144741457414674147741487414974150741517415274153741547415574156741577415874159741607416174162741637416474165741667416774168741697417074171741727417374174741757417674177741787417974180741817418274183741847418574186741877418874189741907419174192741937419474195741967419774198741997420074201742027420374204742057420674207742087420974210742117421274213742147421574216742177421874219742207422174222742237422474225742267422774228742297423074231742327423374234742357423674237742387423974240742417424274243742447424574246742477424874249742507425174252742537425474255742567425774258742597426074261742627426374264742657426674267742687426974270742717427274273742747427574276742777427874279742807428174282742837428474285742867428774288742897429074291742927429374294742957429674297742987429974300743017430274303743047430574306743077430874309743107431174312743137431474315743167431774318743197432074321743227432374324743257432674327743287432974330743317433274333743347433574336743377433874339743407434174342743437434474345743467434774348743497435074351743527435374354743557435674357743587435974360743617436274363743647436574366743677436874369743707437174372743737437474375743767437774378743797438074381743827438374384743857438674387743887438974390743917439274393743947439574396743977439874399744007440174402744037440474405744067440774408744097441074411744127441374414744157441674417744187441974420744217442274423744247442574426744277442874429744307443174432744337443474435744367443774438744397444074441744427444374444744457444674447744487444974450744517445274453744547445574456744577445874459744607446174462744637446474465744667446774468744697447074471744727447374474744757447674477744787447974480744817448274483744847448574486744877448874489744907449174492744937449474495744967449774498744997450074501745027450374504745057450674507745087450974510745117451274513745147451574516745177451874519745207452174522745237452474525745267452774528745297453074531745327453374534745357453674537745387453974540745417454274543745447454574546745477454874549745507455174552745537455474555745567455774558745597456074561745627456374564745657456674567745687456974570745717457274573745747457574576745777457874579745807458174582745837458474585745867458774588745897459074591745927459374594745957459674597745987459974600746017460274603746047460574606746077460874609746107461174612746137461474615746167461774618746197462074621746227462374624746257462674627746287462974630746317463274633746347463574636746377463874639746407464174642746437464474645746467464774648746497465074651746527465374654746557465674657746587465974660746617466274663746647466574666746677466874669746707467174672746737467474675746767467774678746797468074681746827468374684746857468674687746887468974690746917469274693746947469574696746977469874699747007470174702747037470474705747067470774708747097471074711747127471374714747157471674717747187471974720747217472274723747247472574726747277472874729747307473174732747337473474735747367473774738747397474074741747427474374744747457474674747747487474974750747517475274753747547475574756747577475874759747607476174762747637476474765747667476774768747697477074771747727477374774747757477674777747787477974780747817478274783747847478574786747877478874789747907479174792747937479474795747967479774798747997480074801748027480374804748057480674807748087480974810748117481274813748147481574816748177481874819748207482174822748237482474825748267482774828748297483074831748327483374834748357483674837748387483974840748417484274843748447484574846748477484874849748507485174852748537485474855748567485774858748597486074861748627486374864748657486674867748687486974870748717487274873748747487574876748777487874879748807488174882748837488474885748867488774888748897489074891748927489374894748957489674897748987489974900749017490274903749047490574906749077490874909749107491174912749137491474915749167491774918749197492074921749227492374924749257492674927749287492974930749317493274933749347493574936749377493874939749407494174942749437494474945749467494774948749497495074951749527495374954749557495674957749587495974960749617496274963749647496574966749677496874969749707497174972749737497474975749767497774978749797498074981749827498374984749857498674987749887498974990749917499274993749947499574996749977499874999750007500175002750037500475005750067500775008750097501075011750127501375014750157501675017750187501975020750217502275023750247502575026750277502875029750307503175032750337503475035750367503775038750397504075041750427504375044750457504675047750487504975050750517505275053750547505575056750577505875059750607506175062750637506475065750667506775068750697507075071750727507375074750757507675077750787507975080750817508275083750847508575086750877508875089750907509175092750937509475095750967509775098750997510075101751027510375104751057510675107751087510975110751117511275113751147511575116751177511875119751207512175122751237512475125751267512775128751297513075131751327513375134751357513675137751387513975140751417514275143751447514575146751477514875149751507515175152751537515475155751567515775158751597516075161751627516375164751657516675167751687516975170751717517275173751747517575176751777517875179751807518175182751837518475185751867518775188751897519075191751927519375194751957519675197751987519975200752017520275203752047520575206752077520875209752107521175212752137521475215752167521775218752197522075221752227522375224752257522675227752287522975230752317523275233752347523575236752377523875239752407524175242752437524475245752467524775248752497525075251752527525375254752557525675257752587525975260752617526275263752647526575266752677526875269752707527175272752737527475275752767527775278752797528075281752827528375284752857528675287752887528975290752917529275293752947529575296752977529875299753007530175302753037530475305753067530775308753097531075311753127531375314753157531675317753187531975320753217532275323753247532575326753277532875329753307533175332753337533475335753367533775338753397534075341753427534375344753457534675347753487534975350753517535275353753547535575356753577535875359753607536175362753637536475365753667536775368753697537075371753727537375374753757537675377753787537975380753817538275383753847538575386753877538875389753907539175392753937539475395753967539775398753997540075401754027540375404754057540675407754087540975410754117541275413754147541575416754177541875419754207542175422754237542475425754267542775428754297543075431754327543375434754357543675437754387543975440754417544275443754447544575446754477544875449754507545175452754537545475455754567545775458754597546075461754627546375464754657546675467754687546975470754717547275473754747547575476754777547875479754807548175482754837548475485754867548775488754897549075491754927549375494754957549675497754987549975500755017550275503755047550575506755077550875509755107551175512755137551475515755167551775518755197552075521755227552375524755257552675527755287552975530755317553275533755347553575536755377553875539755407554175542755437554475545755467554775548755497555075551755527555375554755557555675557755587555975560755617556275563755647556575566755677556875569755707557175572755737557475575755767557775578755797558075581755827558375584755857558675587755887558975590755917559275593755947559575596755977559875599756007560175602756037560475605756067560775608756097561075611756127561375614756157561675617756187561975620756217562275623756247562575626756277562875629756307563175632756337563475635756367563775638756397564075641756427564375644756457564675647756487564975650756517565275653756547565575656756577565875659756607566175662756637566475665756667566775668756697567075671756727567375674756757567675677756787567975680756817568275683756847568575686756877568875689756907569175692756937569475695756967569775698756997570075701757027570375704757057570675707757087570975710757117571275713757147571575716757177571875719757207572175722757237572475725757267572775728757297573075731757327573375734757357573675737757387573975740757417574275743757447574575746757477574875749757507575175752757537575475755757567575775758757597576075761757627576375764757657576675767757687576975770757717577275773757747577575776757777577875779757807578175782757837578475785757867578775788757897579075791757927579375794757957579675797757987579975800758017580275803758047580575806758077580875809758107581175812758137581475815758167581775818758197582075821758227582375824758257582675827758287582975830758317583275833758347583575836758377583875839758407584175842758437584475845758467584775848758497585075851758527585375854758557585675857758587585975860758617586275863758647586575866758677586875869758707587175872758737587475875758767587775878758797588075881758827588375884758857588675887758887588975890758917589275893758947589575896758977589875899759007590175902759037590475905759067590775908759097591075911759127591375914759157591675917759187591975920759217592275923759247592575926759277592875929759307593175932759337593475935759367593775938759397594075941759427594375944759457594675947759487594975950759517595275953759547595575956759577595875959759607596175962759637596475965759667596775968759697597075971759727597375974759757597675977759787597975980759817598275983759847598575986759877598875989759907599175992759937599475995759967599775998759997600076001760027600376004760057600676007760087600976010760117601276013760147601576016760177601876019760207602176022760237602476025760267602776028760297603076031760327603376034760357603676037760387603976040760417604276043760447604576046760477604876049760507605176052760537605476055760567605776058760597606076061760627606376064760657606676067760687606976070760717607276073760747607576076760777607876079760807608176082760837608476085760867608776088760897609076091760927609376094760957609676097760987609976100761017610276103761047610576106761077610876109761107611176112761137611476115761167611776118761197612076121761227612376124761257612676127761287612976130761317613276133761347613576136761377613876139761407614176142761437614476145761467614776148761497615076151761527615376154761557615676157761587615976160761617616276163761647616576166761677616876169761707617176172761737617476175761767617776178761797618076181761827618376184761857618676187761887618976190761917619276193761947619576196761977619876199762007620176202762037620476205762067620776208762097621076211762127621376214762157621676217762187621976220762217622276223762247622576226762277622876229762307623176232762337623476235762367623776238762397624076241762427624376244762457624676247762487624976250762517625276253762547625576256762577625876259762607626176262762637626476265762667626776268762697627076271762727627376274762757627676277762787627976280762817628276283762847628576286762877628876289762907629176292762937629476295762967629776298762997630076301763027630376304763057630676307763087630976310763117631276313763147631576316763177631876319763207632176322763237632476325763267632776328763297633076331763327633376334763357633676337763387633976340763417634276343763447634576346763477634876349763507635176352763537635476355763567635776358763597636076361763627636376364763657636676367763687636976370763717637276373763747637576376763777637876379763807638176382763837638476385763867638776388763897639076391763927639376394763957639676397763987639976400764017640276403764047640576406764077640876409764107641176412764137641476415764167641776418764197642076421764227642376424764257642676427764287642976430764317643276433764347643576436764377643876439764407644176442764437644476445764467644776448764497645076451764527645376454764557645676457764587645976460764617646276463764647646576466764677646876469764707647176472764737647476475764767647776478764797648076481764827648376484764857648676487764887648976490764917649276493764947649576496764977649876499765007650176502765037650476505765067650776508765097651076511765127651376514765157651676517765187651976520765217652276523765247652576526765277652876529765307653176532765337653476535765367653776538765397654076541765427654376544765457654676547765487654976550765517655276553765547655576556765577655876559765607656176562765637656476565765667656776568765697657076571765727657376574765757657676577765787657976580765817658276583765847658576586765877658876589765907659176592765937659476595765967659776598765997660076601766027660376604766057660676607766087660976610766117661276613766147661576616766177661876619766207662176622766237662476625766267662776628766297663076631766327663376634766357663676637766387663976640766417664276643766447664576646766477664876649766507665176652766537665476655766567665776658766597666076661766627666376664766657666676667766687666976670766717667276673766747667576676766777667876679766807668176682766837668476685766867668776688766897669076691766927669376694766957669676697766987669976700767017670276703767047670576706767077670876709767107671176712767137671476715767167671776718767197672076721767227672376724767257672676727767287672976730767317673276733767347673576736767377673876739767407674176742767437674476745767467674776748767497675076751767527675376754767557675676757767587675976760767617676276763767647676576766767677676876769767707677176772767737677476775767767677776778767797678076781767827678376784767857678676787767887678976790767917679276793767947679576796767977679876799768007680176802768037680476805768067680776808768097681076811768127681376814768157681676817768187681976820768217682276823768247682576826768277682876829768307683176832768337683476835768367683776838768397684076841768427684376844768457684676847768487684976850768517685276853768547685576856768577685876859768607686176862768637686476865768667686776868768697687076871768727687376874768757687676877768787687976880768817688276883768847688576886768877688876889768907689176892768937689476895768967689776898768997690076901769027690376904769057690676907769087690976910769117691276913769147691576916769177691876919769207692176922769237692476925769267692776928769297693076931769327693376934769357693676937769387693976940769417694276943769447694576946769477694876949769507695176952769537695476955769567695776958769597696076961769627696376964769657696676967769687696976970769717697276973769747697576976769777697876979769807698176982769837698476985769867698776988769897699076991769927699376994769957699676997769987699977000770017700277003770047700577006770077700877009770107701177012770137701477015770167701777018770197702077021770227702377024770257702677027770287702977030770317703277033770347703577036770377703877039770407704177042770437704477045770467704777048770497705077051770527705377054770557705677057770587705977060770617706277063770647706577066770677706877069770707707177072770737707477075770767707777078770797708077081770827708377084770857708677087770887708977090770917709277093770947709577096770977709877099771007710177102771037710477105771067710777108771097711077111771127711377114771157711677117771187711977120771217712277123771247712577126771277712877129771307713177132771337713477135771367713777138771397714077141771427714377144771457714677147771487714977150771517715277153771547715577156771577715877159771607716177162771637716477165771667716777168771697717077171771727717377174771757717677177771787717977180771817718277183771847718577186771877718877189771907719177192771937719477195771967719777198771997720077201772027720377204772057720677207772087720977210772117721277213772147721577216772177721877219772207722177222772237722477225772267722777228772297723077231772327723377234772357723677237772387723977240772417724277243772447724577246772477724877249772507725177252772537725477255772567725777258772597726077261772627726377264772657726677267772687726977270772717727277273772747727577276772777727877279772807728177282772837728477285772867728777288772897729077291772927729377294772957729677297772987729977300773017730277303773047730577306773077730877309773107731177312773137731477315773167731777318773197732077321773227732377324773257732677327773287732977330773317733277333773347733577336773377733877339773407734177342773437734477345773467734777348773497735077351773527735377354773557735677357773587735977360773617736277363773647736577366773677736877369773707737177372773737737477375773767737777378773797738077381773827738377384773857738677387773887738977390773917739277393773947739577396773977739877399774007740177402774037740477405774067740777408774097741077411774127741377414774157741677417774187741977420774217742277423774247742577426774277742877429774307743177432774337743477435774367743777438774397744077441774427744377444774457744677447774487744977450774517745277453774547745577456774577745877459774607746177462774637746477465774667746777468774697747077471774727747377474774757747677477774787747977480774817748277483774847748577486774877748877489774907749177492774937749477495774967749777498774997750077501775027750377504775057750677507775087750977510775117751277513775147751577516775177751877519775207752177522775237752477525775267752777528775297753077531775327753377534775357753677537775387753977540775417754277543775447754577546775477754877549775507755177552775537755477555775567755777558775597756077561775627756377564775657756677567775687756977570775717757277573775747757577576775777757877579775807758177582775837758477585775867758777588775897759077591775927759377594775957759677597775987759977600776017760277603776047760577606776077760877609776107761177612776137761477615776167761777618776197762077621776227762377624776257762677627776287762977630776317763277633776347763577636776377763877639776407764177642776437764477645776467764777648776497765077651776527765377654776557765677657776587765977660776617766277663776647766577666776677766877669776707767177672776737767477675776767767777678776797768077681776827768377684776857768677687776887768977690776917769277693776947769577696776977769877699777007770177702777037770477705777067770777708777097771077711777127771377714777157771677717777187771977720777217772277723777247772577726777277772877729777307773177732777337773477735777367773777738777397774077741777427774377744777457774677747777487774977750777517775277753777547775577756777577775877759777607776177762777637776477765777667776777768777697777077771777727777377774777757777677777777787777977780777817778277783777847778577786777877778877789777907779177792777937779477795777967779777798777997780077801778027780377804778057780677807778087780977810778117781277813778147781577816778177781877819778207782177822778237782477825778267782777828778297783077831778327783377834778357783677837778387783977840778417784277843778447784577846778477784877849778507785177852778537785477855778567785777858778597786077861778627786377864778657786677867778687786977870778717787277873778747787577876778777787877879778807788177882778837788477885778867788777888778897789077891778927789377894778957789677897778987789977900779017790277903779047790577906779077790877909779107791177912779137791477915779167791777918779197792077921779227792377924779257792677927779287792977930779317793277933779347793577936779377793877939779407794177942779437794477945779467794777948779497795077951779527795377954779557795677957779587795977960779617796277963779647796577966779677796877969779707797177972779737797477975779767797777978779797798077981779827798377984779857798677987779887798977990779917799277993779947799577996779977799877999780007800178002780037800478005780067800778008780097801078011780127801378014780157801678017780187801978020780217802278023780247802578026780277802878029780307803178032780337803478035780367803778038780397804078041780427804378044780457804678047780487804978050780517805278053780547805578056780577805878059780607806178062780637806478065780667806778068780697807078071780727807378074780757807678077780787807978080780817808278083780847808578086780877808878089780907809178092780937809478095780967809778098780997810078101781027810378104781057810678107781087810978110781117811278113781147811578116781177811878119781207812178122781237812478125781267812778128781297813078131781327813378134781357813678137781387813978140781417814278143781447814578146781477814878149781507815178152781537815478155781567815778158781597816078161781627816378164781657816678167781687816978170781717817278173781747817578176781777817878179781807818178182781837818478185781867818778188781897819078191781927819378194781957819678197781987819978200782017820278203782047820578206782077820878209782107821178212782137821478215782167821778218782197822078221782227822378224782257822678227782287822978230782317823278233782347823578236782377823878239782407824178242782437824478245782467824778248782497825078251782527825378254782557825678257782587825978260782617826278263782647826578266782677826878269782707827178272782737827478275782767827778278782797828078281782827828378284782857828678287782887828978290782917829278293782947829578296782977829878299783007830178302783037830478305783067830778308783097831078311783127831378314783157831678317783187831978320783217832278323783247832578326783277832878329783307833178332783337833478335783367833778338783397834078341783427834378344783457834678347783487834978350783517835278353783547835578356783577835878359783607836178362783637836478365783667836778368783697837078371783727837378374783757837678377783787837978380783817838278383783847838578386783877838878389783907839178392783937839478395783967839778398783997840078401784027840378404784057840678407784087840978410784117841278413784147841578416784177841878419784207842178422784237842478425784267842778428784297843078431784327843378434784357843678437784387843978440784417844278443784447844578446784477844878449784507845178452784537845478455784567845778458784597846078461784627846378464784657846678467784687846978470784717847278473784747847578476784777847878479784807848178482784837848478485784867848778488784897849078491784927849378494784957849678497784987849978500785017850278503785047850578506785077850878509785107851178512785137851478515785167851778518785197852078521785227852378524785257852678527785287852978530785317853278533785347853578536785377853878539785407854178542785437854478545785467854778548785497855078551785527855378554785557855678557785587855978560785617856278563785647856578566785677856878569785707857178572785737857478575785767857778578785797858078581785827858378584785857858678587785887858978590785917859278593785947859578596785977859878599786007860178602786037860478605786067860778608786097861078611786127861378614786157861678617786187861978620786217862278623786247862578626786277862878629786307863178632786337863478635786367863778638786397864078641786427864378644786457864678647786487864978650786517865278653786547865578656786577865878659786607866178662786637866478665786667866778668786697867078671786727867378674786757867678677786787867978680786817868278683786847868578686786877868878689786907869178692786937869478695786967869778698786997870078701787027870378704787057870678707787087870978710787117871278713787147871578716787177871878719787207872178722787237872478725787267872778728787297873078731787327873378734787357873678737787387873978740787417874278743787447874578746787477874878749787507875178752787537875478755787567875778758787597876078761787627876378764787657876678767787687876978770787717877278773787747877578776787777877878779787807878178782787837878478785787867878778788787897879078791787927879378794787957879678797787987879978800788017880278803788047880578806788077880878809788107881178812788137881478815788167881778818788197882078821788227882378824788257882678827788287882978830788317883278833788347883578836788377883878839788407884178842788437884478845788467884778848788497885078851788527885378854788557885678857788587885978860788617886278863788647886578866788677886878869788707887178872788737887478875788767887778878788797888078881788827888378884788857888678887788887888978890788917889278893788947889578896788977889878899789007890178902789037890478905789067890778908789097891078911789127891378914789157891678917789187891978920789217892278923789247892578926789277892878929789307893178932789337893478935789367893778938789397894078941789427894378944789457894678947789487894978950789517895278953789547895578956789577895878959789607896178962789637896478965789667896778968789697897078971789727897378974789757897678977789787897978980789817898278983789847898578986789877898878989789907899178992789937899478995789967899778998789997900079001790027900379004790057900679007790087900979010790117901279013790147901579016790177901879019790207902179022790237902479025790267902779028790297903079031790327903379034790357903679037790387903979040790417904279043790447904579046790477904879049790507905179052790537905479055790567905779058790597906079061790627906379064790657906679067790687906979070790717907279073790747907579076790777907879079790807908179082790837908479085790867908779088790897909079091790927909379094790957909679097790987909979100791017910279103791047910579106791077910879109791107911179112791137911479115791167911779118791197912079121791227912379124791257912679127791287912979130791317913279133791347913579136791377913879139791407914179142791437914479145791467914779148791497915079151791527915379154791557915679157791587915979160791617916279163791647916579166791677916879169791707917179172791737917479175791767917779178791797918079181791827918379184791857918679187791887918979190791917919279193791947919579196791977919879199792007920179202792037920479205792067920779208792097921079211792127921379214792157921679217792187921979220792217922279223792247922579226792277922879229792307923179232792337923479235792367923779238792397924079241792427924379244792457924679247792487924979250792517925279253792547925579256792577925879259792607926179262792637926479265792667926779268792697927079271792727927379274792757927679277792787927979280792817928279283792847928579286792877928879289792907929179292792937929479295792967929779298792997930079301793027930379304793057930679307793087930979310793117931279313793147931579316793177931879319793207932179322793237932479325793267932779328793297933079331793327933379334793357933679337793387933979340793417934279343793447934579346793477934879349793507935179352793537935479355793567935779358793597936079361793627936379364793657936679367793687936979370793717937279373793747937579376793777937879379793807938179382793837938479385793867938779388793897939079391793927939379394793957939679397793987939979400794017940279403794047940579406794077940879409794107941179412794137941479415794167941779418794197942079421794227942379424794257942679427794287942979430794317943279433794347943579436794377943879439794407944179442794437944479445794467944779448794497945079451794527945379454794557945679457794587945979460794617946279463794647946579466794677946879469794707947179472794737947479475794767947779478794797948079481794827948379484794857948679487794887948979490794917949279493794947949579496794977949879499795007950179502795037950479505795067950779508795097951079511795127951379514795157951679517795187951979520795217952279523795247952579526795277952879529795307953179532795337953479535795367953779538795397954079541795427954379544795457954679547795487954979550795517955279553795547955579556795577955879559795607956179562795637956479565795667956779568795697957079571795727957379574795757957679577795787957979580795817958279583795847958579586795877958879589795907959179592795937959479595795967959779598795997960079601796027960379604796057960679607796087960979610796117961279613796147961579616796177961879619796207962179622796237962479625796267962779628796297963079631796327963379634796357963679637796387963979640796417964279643796447964579646796477964879649796507965179652796537965479655796567965779658796597966079661796627966379664796657966679667796687966979670796717967279673796747967579676796777967879679796807968179682796837968479685796867968779688796897969079691796927969379694796957969679697796987969979700797017970279703797047970579706797077970879709797107971179712797137971479715797167971779718797197972079721797227972379724797257972679727797287972979730797317973279733797347973579736797377973879739797407974179742797437974479745797467974779748797497975079751797527975379754797557975679757797587975979760797617976279763797647976579766797677976879769797707977179772797737977479775797767977779778797797978079781797827978379784797857978679787797887978979790797917979279793797947979579796797977979879799798007980179802798037980479805798067980779808798097981079811798127981379814798157981679817798187981979820798217982279823798247982579826798277982879829798307983179832798337983479835798367983779838798397984079841798427984379844798457984679847798487984979850798517985279853798547985579856798577985879859798607986179862798637986479865798667986779868798697987079871798727987379874798757987679877798787987979880798817988279883798847988579886798877988879889798907989179892798937989479895798967989779898798997990079901799027990379904799057990679907799087990979910799117991279913799147991579916799177991879919799207992179922799237992479925799267992779928799297993079931799327993379934799357993679937799387993979940799417994279943799447994579946799477994879949799507995179952799537995479955799567995779958799597996079961799627996379964799657996679967799687996979970799717997279973799747997579976799777997879979799807998179982799837998479985799867998779988799897999079991799927999379994799957999679997799987999980000800018000280003800048000580006800078000880009800108001180012800138001480015800168001780018800198002080021800228002380024800258002680027800288002980030800318003280033800348003580036800378003880039800408004180042800438004480045800468004780048800498005080051800528005380054800558005680057800588005980060800618006280063800648006580066800678006880069800708007180072800738007480075800768007780078800798008080081800828008380084800858008680087800888008980090800918009280093800948009580096800978009880099801008010180102801038010480105801068010780108801098011080111801128011380114801158011680117801188011980120801218012280123801248012580126801278012880129801308013180132801338013480135801368013780138801398014080141801428014380144801458014680147801488014980150801518015280153801548015580156801578015880159801608016180162801638016480165801668016780168801698017080171801728017380174801758017680177801788017980180801818018280183801848018580186801878018880189801908019180192801938019480195801968019780198801998020080201802028020380204802058020680207802088020980210802118021280213802148021580216802178021880219802208022180222802238022480225802268022780228802298023080231802328023380234802358023680237802388023980240802418024280243802448024580246802478024880249802508025180252802538025480255802568025780258802598026080261802628026380264802658026680267802688026980270802718027280273802748027580276802778027880279802808028180282802838028480285802868028780288802898029080291802928029380294802958029680297802988029980300803018030280303803048030580306803078030880309803108031180312803138031480315803168031780318803198032080321803228032380324803258032680327803288032980330803318033280333803348033580336803378033880339803408034180342803438034480345803468034780348803498035080351803528035380354803558035680357803588035980360803618036280363803648036580366803678036880369803708037180372803738037480375803768037780378803798038080381803828038380384803858038680387803888038980390803918039280393803948039580396803978039880399804008040180402804038040480405804068040780408804098041080411804128041380414804158041680417804188041980420804218042280423804248042580426804278042880429804308043180432804338043480435804368043780438804398044080441804428044380444804458044680447804488044980450804518045280453804548045580456804578045880459804608046180462804638046480465804668046780468804698047080471804728047380474804758047680477804788047980480804818048280483804848048580486804878048880489804908049180492804938049480495804968049780498804998050080501805028050380504805058050680507805088050980510805118051280513805148051580516805178051880519805208052180522805238052480525805268052780528805298053080531805328053380534805358053680537805388053980540805418054280543805448054580546805478054880549805508055180552805538055480555805568055780558805598056080561805628056380564805658056680567805688056980570805718057280573805748057580576805778057880579805808058180582805838058480585805868058780588805898059080591805928059380594805958059680597805988059980600806018060280603806048060580606806078060880609806108061180612806138061480615806168061780618806198062080621806228062380624806258062680627806288062980630806318063280633806348063580636806378063880639806408064180642806438064480645806468064780648806498065080651806528065380654806558065680657806588065980660806618066280663806648066580666806678066880669806708067180672806738067480675806768067780678806798068080681806828068380684806858068680687806888068980690806918069280693806948069580696806978069880699807008070180702807038070480705807068070780708807098071080711807128071380714807158071680717807188071980720807218072280723807248072580726807278072880729807308073180732807338073480735807368073780738807398074080741807428074380744807458074680747807488074980750807518075280753807548075580756807578075880759807608076180762807638076480765807668076780768807698077080771807728077380774807758077680777807788077980780807818078280783807848078580786807878078880789807908079180792807938079480795807968079780798807998080080801808028080380804808058080680807808088080980810808118081280813808148081580816808178081880819808208082180822808238082480825808268082780828808298083080831808328083380834808358083680837808388083980840808418084280843808448084580846808478084880849808508085180852808538085480855808568085780858808598086080861808628086380864808658086680867808688086980870808718087280873808748087580876808778087880879808808088180882808838088480885808868088780888808898089080891808928089380894808958089680897808988089980900809018090280903809048090580906809078090880909809108091180912809138091480915809168091780918809198092080921809228092380924809258092680927809288092980930809318093280933809348093580936809378093880939809408094180942809438094480945809468094780948809498095080951809528095380954809558095680957809588095980960809618096280963809648096580966809678096880969809708097180972809738097480975809768097780978809798098080981809828098380984809858098680987809888098980990809918099280993809948099580996809978099880999810008100181002810038100481005810068100781008810098101081011810128101381014810158101681017810188101981020810218102281023810248102581026810278102881029810308103181032810338103481035810368103781038810398104081041810428104381044810458104681047810488104981050810518105281053810548105581056810578105881059810608106181062810638106481065810668106781068810698107081071810728107381074810758107681077810788107981080810818108281083810848108581086810878108881089810908109181092810938109481095810968109781098810998110081101811028110381104811058110681107811088110981110811118111281113811148111581116811178111881119811208112181122811238112481125811268112781128811298113081131811328113381134811358113681137811388113981140811418114281143811448114581146811478114881149811508115181152811538115481155811568115781158811598116081161811628116381164811658116681167811688116981170811718117281173811748117581176811778117881179811808118181182811838118481185811868118781188811898119081191811928119381194811958119681197811988119981200812018120281203812048120581206812078120881209812108121181212812138121481215812168121781218812198122081221812228122381224812258122681227812288122981230812318123281233812348123581236812378123881239812408124181242812438124481245812468124781248812498125081251812528125381254812558125681257812588125981260812618126281263812648126581266812678126881269812708127181272812738127481275812768127781278812798128081281812828128381284812858128681287812888128981290812918129281293812948129581296812978129881299813008130181302813038130481305813068130781308813098131081311813128131381314813158131681317813188131981320813218132281323813248132581326813278132881329813308133181332813338133481335813368133781338813398134081341813428134381344813458134681347813488134981350813518135281353813548135581356813578135881359813608136181362813638136481365813668136781368813698137081371813728137381374813758137681377813788137981380813818138281383813848138581386813878138881389813908139181392813938139481395813968139781398813998140081401814028140381404814058140681407814088140981410814118141281413814148141581416814178141881419814208142181422814238142481425814268142781428814298143081431814328143381434814358143681437814388143981440814418144281443814448144581446814478144881449814508145181452814538145481455814568145781458814598146081461814628146381464814658146681467814688146981470814718147281473814748147581476814778147881479814808148181482814838148481485814868148781488814898149081491814928149381494814958149681497814988149981500815018150281503815048150581506815078150881509815108151181512815138151481515815168151781518815198152081521815228152381524815258152681527815288152981530815318153281533815348153581536815378153881539815408154181542815438154481545815468154781548815498155081551815528155381554815558155681557815588155981560815618156281563815648156581566815678156881569815708157181572815738157481575815768157781578815798158081581815828158381584815858158681587815888158981590815918159281593815948159581596815978159881599816008160181602816038160481605816068160781608816098161081611816128161381614816158161681617816188161981620816218162281623816248162581626816278162881629816308163181632816338163481635816368163781638816398164081641816428164381644816458164681647816488164981650816518165281653816548165581656816578165881659816608166181662816638166481665816668166781668816698167081671816728167381674816758167681677816788167981680816818168281683816848168581686816878168881689816908169181692816938169481695816968169781698816998170081701817028170381704817058170681707817088170981710817118171281713817148171581716817178171881719817208172181722817238172481725817268172781728817298173081731817328173381734817358173681737817388173981740817418174281743817448174581746817478174881749817508175181752817538175481755817568175781758817598176081761817628176381764817658176681767817688176981770817718177281773817748177581776817778177881779817808178181782817838178481785817868178781788817898179081791817928179381794817958179681797817988179981800818018180281803818048180581806818078180881809818108181181812818138181481815818168181781818818198182081821818228182381824818258182681827818288182981830818318183281833818348183581836818378183881839818408184181842818438184481845818468184781848818498185081851818528185381854818558185681857818588185981860818618186281863818648186581866818678186881869818708187181872818738187481875818768187781878818798188081881818828188381884818858188681887818888188981890818918189281893818948189581896818978189881899819008190181902819038190481905819068190781908819098191081911819128191381914819158191681917819188191981920819218192281923819248192581926819278192881929819308193181932819338193481935819368193781938819398194081941819428194381944819458194681947819488194981950819518195281953819548195581956819578195881959819608196181962819638196481965819668196781968819698197081971819728197381974819758197681977819788197981980819818198281983819848198581986819878198881989819908199181992819938199481995819968199781998819998200082001820028200382004820058200682007820088200982010820118201282013820148201582016820178201882019820208202182022820238202482025820268202782028820298203082031820328203382034820358203682037820388203982040820418204282043820448204582046820478204882049820508205182052820538205482055820568205782058820598206082061820628206382064820658206682067820688206982070820718207282073820748207582076820778207882079820808208182082820838208482085820868208782088820898209082091820928209382094820958209682097820988209982100821018210282103821048210582106821078210882109821108211182112821138211482115821168211782118821198212082121821228212382124821258212682127821288212982130821318213282133821348213582136821378213882139821408214182142821438214482145821468214782148821498215082151821528215382154821558215682157821588215982160821618216282163821648216582166821678216882169821708217182172821738217482175821768217782178821798218082181821828218382184821858218682187821888218982190821918219282193821948219582196821978219882199822008220182202822038220482205822068220782208822098221082211822128221382214822158221682217822188221982220822218222282223822248222582226822278222882229822308223182232822338223482235822368223782238822398224082241822428224382244822458224682247822488224982250822518225282253822548225582256822578225882259822608226182262822638226482265822668226782268822698227082271822728227382274822758227682277822788227982280822818228282283822848228582286822878228882289822908229182292822938229482295822968229782298822998230082301823028230382304823058230682307823088230982310823118231282313823148231582316823178231882319823208232182322823238232482325823268232782328823298233082331823328233382334823358233682337823388233982340823418234282343823448234582346823478234882349823508235182352823538235482355823568235782358823598236082361823628236382364823658236682367823688236982370823718237282373823748237582376823778237882379823808238182382823838238482385823868238782388823898239082391823928239382394823958239682397823988239982400824018240282403824048240582406824078240882409824108241182412824138241482415824168241782418824198242082421824228242382424824258242682427824288242982430824318243282433824348243582436824378243882439824408244182442824438244482445824468244782448824498245082451824528245382454824558245682457824588245982460824618246282463824648246582466824678246882469824708247182472824738247482475824768247782478824798248082481824828248382484824858248682487824888248982490824918249282493824948249582496824978249882499825008250182502825038250482505825068250782508825098251082511825128251382514825158251682517825188251982520825218252282523825248252582526825278252882529825308253182532825338253482535825368253782538825398254082541825428254382544825458254682547825488254982550825518255282553825548255582556825578255882559825608256182562825638256482565825668256782568825698257082571825728257382574825758257682577825788257982580825818258282583825848258582586825878258882589825908259182592825938259482595825968259782598825998260082601826028260382604826058260682607826088260982610826118261282613826148261582616826178261882619826208262182622826238262482625826268262782628826298263082631826328263382634826358263682637826388263982640826418264282643826448264582646826478264882649826508265182652826538265482655826568265782658826598266082661826628266382664826658266682667826688266982670826718267282673826748267582676826778267882679826808268182682826838268482685826868268782688826898269082691826928269382694826958269682697826988269982700827018270282703827048270582706827078270882709827108271182712827138271482715827168271782718827198272082721827228272382724827258272682727827288272982730827318273282733827348273582736827378273882739827408274182742827438274482745827468274782748827498275082751827528275382754827558275682757827588275982760827618276282763827648276582766827678276882769827708277182772827738277482775827768277782778827798278082781827828278382784827858278682787827888278982790827918279282793827948279582796827978279882799828008280182802828038280482805828068280782808828098281082811828128281382814828158281682817828188281982820828218282282823828248282582826828278282882829828308283182832828338283482835828368283782838828398284082841828428284382844828458284682847828488284982850828518285282853828548285582856828578285882859828608286182862828638286482865828668286782868828698287082871828728287382874828758287682877828788287982880828818288282883828848288582886828878288882889828908289182892828938289482895828968289782898828998290082901829028290382904829058290682907829088290982910829118291282913829148291582916829178291882919829208292182922829238292482925829268292782928829298293082931829328293382934829358293682937829388293982940829418294282943829448294582946829478294882949829508295182952829538295482955829568295782958829598296082961829628296382964829658296682967829688296982970829718297282973829748297582976829778297882979829808298182982829838298482985829868298782988829898299082991829928299382994829958299682997829988299983000830018300283003830048300583006830078300883009830108301183012830138301483015830168301783018830198302083021830228302383024830258302683027830288302983030830318303283033830348303583036830378303883039830408304183042830438304483045830468304783048830498305083051830528305383054830558305683057830588305983060830618306283063830648306583066830678306883069830708307183072830738307483075830768307783078830798308083081830828308383084830858308683087830888308983090830918309283093830948309583096830978309883099831008310183102831038310483105831068310783108831098311083111831128311383114831158311683117831188311983120831218312283123831248312583126831278312883129831308313183132831338313483135831368313783138831398314083141831428314383144831458314683147831488314983150831518315283153831548315583156831578315883159831608316183162831638316483165831668316783168831698317083171831728317383174831758317683177831788317983180831818318283183831848318583186831878318883189831908319183192831938319483195831968319783198831998320083201832028320383204832058320683207832088320983210832118321283213832148321583216832178321883219832208322183222832238322483225832268322783228832298323083231832328323383234832358323683237832388323983240832418324283243832448324583246832478324883249832508325183252832538325483255832568325783258832598326083261832628326383264832658326683267832688326983270832718327283273832748327583276832778327883279832808328183282832838328483285832868328783288832898329083291832928329383294832958329683297832988329983300833018330283303833048330583306833078330883309833108331183312833138331483315833168331783318833198332083321833228332383324833258332683327833288332983330833318333283333833348333583336833378333883339833408334183342833438334483345833468334783348833498335083351833528335383354833558335683357833588335983360833618336283363833648336583366833678336883369833708337183372833738337483375833768337783378833798338083381833828338383384833858338683387833888338983390833918339283393833948339583396833978339883399834008340183402834038340483405834068340783408834098341083411834128341383414834158341683417834188341983420834218342283423834248342583426834278342883429834308343183432834338343483435834368343783438834398344083441834428344383444834458344683447834488344983450834518345283453834548345583456834578345883459834608346183462834638346483465834668346783468834698347083471834728347383474834758347683477834788347983480834818348283483834848348583486834878348883489834908349183492834938349483495834968349783498834998350083501835028350383504835058350683507835088350983510835118351283513835148351583516835178351883519835208352183522835238352483525835268352783528835298353083531835328353383534835358353683537835388353983540835418354283543835448354583546835478354883549835508355183552835538355483555835568355783558835598356083561835628356383564835658356683567835688356983570835718357283573835748357583576835778357883579835808358183582835838358483585835868358783588835898359083591835928359383594835958359683597835988359983600836018360283603836048360583606836078360883609836108361183612836138361483615836168361783618836198362083621836228362383624836258362683627836288362983630836318363283633836348363583636836378363883639836408364183642836438364483645836468364783648836498365083651836528365383654836558365683657836588365983660836618366283663836648366583666836678366883669836708367183672836738367483675836768367783678836798368083681836828368383684836858368683687836888368983690836918369283693836948369583696836978369883699837008370183702837038370483705837068370783708837098371083711837128371383714837158371683717837188371983720837218372283723837248372583726837278372883729837308373183732837338373483735837368373783738837398374083741837428374383744837458374683747837488374983750837518375283753837548375583756837578375883759837608376183762837638376483765837668376783768837698377083771837728377383774837758377683777837788377983780837818378283783837848378583786837878378883789837908379183792837938379483795837968379783798837998380083801838028380383804838058380683807838088380983810838118381283813838148381583816838178381883819838208382183822838238382483825838268382783828838298383083831838328383383834838358383683837838388383983840838418384283843838448384583846838478384883849838508385183852838538385483855838568385783858838598386083861838628386383864838658386683867838688386983870838718387283873838748387583876838778387883879838808388183882838838388483885838868388783888838898389083891838928389383894838958389683897838988389983900839018390283903839048390583906839078390883909839108391183912839138391483915839168391783918839198392083921839228392383924839258392683927839288392983930839318393283933839348393583936839378393883939839408394183942839438394483945839468394783948839498395083951839528395383954839558395683957839588395983960839618396283963839648396583966839678396883969839708397183972839738397483975839768397783978839798398083981839828398383984839858398683987839888398983990839918399283993839948399583996839978399883999840008400184002840038400484005840068400784008840098401084011840128401384014840158401684017840188401984020840218402284023840248402584026840278402884029840308403184032840338403484035840368403784038840398404084041840428404384044840458404684047840488404984050840518405284053840548405584056840578405884059840608406184062840638406484065840668406784068840698407084071840728407384074840758407684077840788407984080840818408284083840848408584086840878408884089840908409184092840938409484095840968409784098840998410084101841028410384104841058410684107841088410984110841118411284113841148411584116841178411884119841208412184122841238412484125841268412784128841298413084131841328413384134841358413684137841388413984140841418414284143841448414584146841478414884149841508415184152841538415484155841568415784158841598416084161841628416384164841658416684167841688416984170841718417284173841748417584176841778417884179841808418184182841838418484185841868418784188841898419084191841928419384194841958419684197841988419984200842018420284203842048420584206842078420884209842108421184212842138421484215842168421784218842198422084221842228422384224842258422684227842288422984230842318423284233842348423584236842378423884239842408424184242842438424484245842468424784248842498425084251842528425384254842558425684257842588425984260842618426284263842648426584266842678426884269842708427184272842738427484275842768427784278842798428084281842828428384284842858428684287842888428984290842918429284293842948429584296842978429884299843008430184302843038430484305843068430784308843098431084311843128431384314843158431684317843188431984320843218432284323843248432584326843278432884329843308433184332843338433484335843368433784338843398434084341843428434384344843458434684347843488434984350843518435284353843548435584356843578435884359843608436184362843638436484365843668436784368843698437084371843728437384374843758437684377843788437984380843818438284383843848438584386843878438884389843908439184392843938439484395843968439784398843998440084401844028440384404844058440684407844088440984410844118441284413844148441584416844178441884419844208442184422844238442484425844268442784428844298443084431844328443384434844358443684437844388443984440844418444284443844448444584446844478444884449844508445184452844538445484455844568445784458844598446084461844628446384464844658446684467844688446984470844718447284473844748447584476844778447884479844808448184482844838448484485844868448784488844898449084491844928449384494844958449684497844988449984500845018450284503845048450584506845078450884509845108451184512845138451484515845168451784518845198452084521845228452384524845258452684527845288452984530845318453284533845348453584536845378453884539845408454184542845438454484545845468454784548845498455084551845528455384554845558455684557845588455984560845618456284563845648456584566845678456884569845708457184572845738457484575845768457784578845798458084581845828458384584845858458684587845888458984590845918459284593845948459584596845978459884599846008460184602846038460484605846068460784608846098461084611846128461384614846158461684617846188461984620846218462284623846248462584626846278462884629846308463184632846338463484635846368463784638846398464084641846428464384644846458464684647846488464984650846518465284653846548465584656846578465884659846608466184662846638466484665846668466784668846698467084671846728467384674846758467684677846788467984680846818468284683846848468584686846878468884689846908469184692846938469484695846968469784698846998470084701847028470384704847058470684707847088470984710847118471284713847148471584716847178471884719847208472184722847238472484725847268472784728847298473084731847328473384734847358473684737847388473984740847418474284743847448474584746847478474884749847508475184752847538475484755847568475784758847598476084761847628476384764847658476684767847688476984770847718477284773847748477584776847778477884779847808478184782847838478484785847868478784788847898479084791847928479384794847958479684797847988479984800848018480284803848048480584806848078480884809848108481184812848138481484815848168481784818848198482084821848228482384824848258482684827848288482984830848318483284833848348483584836848378483884839848408484184842848438484484845848468484784848848498485084851848528485384854848558485684857848588485984860848618486284863848648486584866848678486884869848708487184872848738487484875848768487784878848798488084881848828488384884848858488684887848888488984890848918489284893848948489584896848978489884899849008490184902849038490484905849068490784908849098491084911849128491384914849158491684917849188491984920849218492284923849248492584926849278492884929849308493184932849338493484935849368493784938849398494084941849428494384944849458494684947849488494984950849518495284953849548495584956849578495884959849608496184962849638496484965849668496784968849698497084971849728497384974849758497684977849788497984980849818498284983849848498584986849878498884989849908499184992849938499484995849968499784998849998500085001850028500385004850058500685007850088500985010850118501285013850148501585016850178501885019850208502185022850238502485025850268502785028850298503085031850328503385034850358503685037850388503985040850418504285043850448504585046850478504885049850508505185052850538505485055850568505785058850598506085061850628506385064850658506685067850688506985070850718507285073850748507585076850778507885079850808508185082850838508485085850868508785088850898509085091850928509385094850958509685097850988509985100851018510285103851048510585106851078510885109851108511185112851138511485115851168511785118851198512085121851228512385124851258512685127851288512985130851318513285133851348513585136851378513885139851408514185142851438514485145851468514785148851498515085151851528515385154851558515685157851588515985160851618516285163851648516585166851678516885169851708517185172851738517485175851768517785178851798518085181851828518385184851858518685187851888518985190851918519285193851948519585196851978519885199852008520185202852038520485205852068520785208852098521085211852128521385214852158521685217852188521985220852218522285223852248522585226852278522885229852308523185232852338523485235852368523785238852398524085241852428524385244852458524685247852488524985250852518525285253852548525585256852578525885259852608526185262852638526485265852668526785268852698527085271852728527385274852758527685277852788527985280852818528285283852848528585286852878528885289852908529185292852938529485295852968529785298852998530085301853028530385304853058530685307853088530985310853118531285313853148531585316853178531885319853208532185322853238532485325853268532785328853298533085331853328533385334853358533685337853388533985340853418534285343853448534585346853478534885349853508535185352853538535485355853568535785358853598536085361853628536385364853658536685367853688536985370853718537285373853748537585376853778537885379853808538185382853838538485385853868538785388853898539085391853928539385394853958539685397853988539985400854018540285403854048540585406854078540885409854108541185412854138541485415854168541785418854198542085421854228542385424854258542685427854288542985430854318543285433854348543585436854378543885439854408544185442854438544485445854468544785448854498545085451854528545385454854558545685457854588545985460854618546285463854648546585466854678546885469854708547185472854738547485475854768547785478854798548085481854828548385484854858548685487854888548985490854918549285493854948549585496854978549885499855008550185502855038550485505855068550785508855098551085511855128551385514855158551685517855188551985520855218552285523855248552585526855278552885529855308553185532855338553485535855368553785538855398554085541855428554385544855458554685547855488554985550855518555285553855548555585556855578555885559855608556185562855638556485565855668556785568855698557085571855728557385574855758557685577855788557985580855818558285583855848558585586855878558885589855908559185592855938559485595855968559785598855998560085601856028560385604856058560685607856088560985610856118561285613856148561585616856178561885619856208562185622856238562485625856268562785628856298563085631856328563385634856358563685637856388563985640856418564285643856448564585646856478564885649856508565185652856538565485655856568565785658856598566085661856628566385664856658566685667856688566985670856718567285673856748567585676856778567885679856808568185682856838568485685856868568785688856898569085691856928569385694856958569685697856988569985700857018570285703857048570585706857078570885709857108571185712857138571485715857168571785718857198572085721857228572385724857258572685727857288572985730857318573285733857348573585736857378573885739857408574185742857438574485745857468574785748857498575085751857528575385754857558575685757857588575985760857618576285763857648576585766857678576885769857708577185772857738577485775857768577785778857798578085781857828578385784857858578685787857888578985790857918579285793857948579585796857978579885799858008580185802858038580485805858068580785808858098581085811858128581385814858158581685817858188581985820858218582285823858248582585826858278582885829858308583185832858338583485835858368583785838858398584085841858428584385844858458584685847858488584985850858518585285853858548585585856858578585885859858608586185862858638586485865858668586785868858698587085871858728587385874858758587685877858788587985880858818588285883858848588585886858878588885889858908589185892858938589485895858968589785898858998590085901859028590385904859058590685907859088590985910859118591285913859148591585916859178591885919859208592185922859238592485925859268592785928859298593085931859328593385934859358593685937859388593985940859418594285943859448594585946859478594885949859508595185952859538595485955859568595785958859598596085961859628596385964859658596685967859688596985970859718597285973859748597585976859778597885979859808598185982859838598485985859868598785988859898599085991859928599385994859958599685997859988599986000860018600286003860048600586006860078600886009860108601186012860138601486015860168601786018860198602086021860228602386024860258602686027860288602986030860318603286033860348603586036860378603886039860408604186042860438604486045860468604786048860498605086051860528605386054860558605686057860588605986060860618606286063860648606586066860678606886069860708607186072860738607486075860768607786078860798608086081860828608386084860858608686087860888608986090860918609286093860948609586096860978609886099861008610186102861038610486105861068610786108861098611086111861128611386114861158611686117861188611986120861218612286123861248612586126861278612886129861308613186132861338613486135861368613786138861398614086141861428614386144861458614686147861488614986150861518615286153861548615586156861578615886159861608616186162861638616486165861668616786168861698617086171861728617386174861758617686177861788617986180861818618286183861848618586186861878618886189861908619186192861938619486195861968619786198861998620086201862028620386204862058620686207862088620986210862118621286213862148621586216862178621886219862208622186222862238622486225862268622786228862298623086231862328623386234862358623686237862388623986240862418624286243862448624586246862478624886249862508625186252862538625486255862568625786258862598626086261862628626386264862658626686267862688626986270862718627286273862748627586276862778627886279862808628186282862838628486285862868628786288862898629086291862928629386294862958629686297862988629986300863018630286303863048630586306863078630886309863108631186312863138631486315863168631786318863198632086321863228632386324863258632686327863288632986330863318633286333863348633586336863378633886339863408634186342863438634486345863468634786348863498635086351863528635386354863558635686357863588635986360863618636286363863648636586366863678636886369863708637186372863738637486375863768637786378863798638086381863828638386384863858638686387863888638986390863918639286393863948639586396863978639886399864008640186402864038640486405864068640786408864098641086411864128641386414864158641686417864188641986420864218642286423864248642586426864278642886429864308643186432864338643486435864368643786438864398644086441864428644386444864458644686447864488644986450864518645286453864548645586456864578645886459864608646186462864638646486465864668646786468864698647086471864728647386474864758647686477864788647986480864818648286483864848648586486864878648886489864908649186492864938649486495864968649786498864998650086501865028650386504865058650686507865088650986510865118651286513865148651586516865178651886519865208652186522865238652486525865268652786528865298653086531865328653386534865358653686537865388653986540865418654286543865448654586546865478654886549865508655186552865538655486555865568655786558865598656086561865628656386564865658656686567865688656986570865718657286573865748657586576865778657886579865808658186582865838658486585865868658786588865898659086591865928659386594865958659686597865988659986600866018660286603866048660586606866078660886609866108661186612866138661486615866168661786618866198662086621866228662386624866258662686627866288662986630866318663286633866348663586636866378663886639866408664186642866438664486645866468664786648866498665086651866528665386654866558665686657866588665986660866618666286663866648666586666866678666886669866708667186672866738667486675866768667786678866798668086681866828668386684866858668686687866888668986690866918669286693866948669586696866978669886699867008670186702867038670486705867068670786708867098671086711867128671386714867158671686717867188671986720867218672286723867248672586726867278672886729867308673186732867338673486735867368673786738867398674086741867428674386744867458674686747867488674986750867518675286753867548675586756867578675886759867608676186762867638676486765867668676786768867698677086771867728677386774867758677686777867788677986780867818678286783867848678586786867878678886789867908679186792867938679486795867968679786798867998680086801868028680386804868058680686807868088680986810868118681286813868148681586816868178681886819868208682186822868238682486825868268682786828868298683086831868328683386834868358683686837868388683986840868418684286843868448684586846868478684886849868508685186852868538685486855868568685786858868598686086861868628686386864868658686686867868688686986870868718687286873868748687586876868778687886879868808688186882868838688486885868868688786888868898689086891868928689386894868958689686897868988689986900869018690286903869048690586906869078690886909869108691186912869138691486915869168691786918869198692086921869228692386924869258692686927869288692986930869318693286933869348693586936869378693886939869408694186942869438694486945869468694786948869498695086951869528695386954869558695686957869588695986960869618696286963869648696586966869678696886969869708697186972869738697486975869768697786978869798698086981869828698386984869858698686987869888698986990869918699286993869948699586996869978699886999870008700187002870038700487005870068700787008870098701087011870128701387014870158701687017870188701987020870218702287023870248702587026870278702887029870308703187032870338703487035870368703787038870398704087041870428704387044870458704687047870488704987050870518705287053870548705587056870578705887059870608706187062870638706487065870668706787068870698707087071870728707387074870758707687077870788707987080870818708287083870848708587086870878708887089870908709187092870938709487095870968709787098870998710087101871028710387104871058710687107871088710987110871118711287113871148711587116871178711887119871208712187122871238712487125871268712787128871298713087131871328713387134871358713687137871388713987140871418714287143871448714587146871478714887149871508715187152871538715487155871568715787158871598716087161871628716387164871658716687167871688716987170871718717287173871748717587176871778717887179871808718187182871838718487185871868718787188871898719087191871928719387194871958719687197871988719987200872018720287203872048720587206872078720887209872108721187212872138721487215872168721787218872198722087221872228722387224872258722687227872288722987230872318723287233872348723587236872378723887239872408724187242872438724487245872468724787248872498725087251872528725387254872558725687257872588725987260872618726287263872648726587266872678726887269872708727187272872738727487275872768727787278872798728087281872828728387284872858728687287872888728987290872918729287293872948729587296872978729887299873008730187302873038730487305873068730787308873098731087311873128731387314873158731687317873188731987320873218732287323873248732587326873278732887329873308733187332873338733487335873368733787338873398734087341873428734387344873458734687347873488734987350873518735287353873548735587356873578735887359873608736187362873638736487365873668736787368873698737087371873728737387374873758737687377873788737987380873818738287383873848738587386873878738887389873908739187392873938739487395873968739787398873998740087401874028740387404874058740687407874088740987410874118741287413874148741587416874178741887419874208742187422874238742487425874268742787428874298743087431874328743387434874358743687437874388743987440874418744287443874448744587446874478744887449874508745187452874538745487455874568745787458874598746087461874628746387464874658746687467874688746987470874718747287473874748747587476874778747887479874808748187482874838748487485874868748787488874898749087491874928749387494874958749687497874988749987500875018750287503875048750587506875078750887509875108751187512875138751487515875168751787518875198752087521875228752387524875258752687527875288752987530875318753287533875348753587536875378753887539875408754187542875438754487545875468754787548875498755087551875528755387554875558755687557875588755987560875618756287563875648756587566875678756887569875708757187572875738757487575875768757787578875798758087581875828758387584875858758687587875888758987590875918759287593875948759587596875978759887599876008760187602876038760487605876068760787608876098761087611876128761387614876158761687617876188761987620876218762287623876248762587626876278762887629876308763187632876338763487635876368763787638876398764087641876428764387644876458764687647876488764987650876518765287653876548765587656876578765887659876608766187662876638766487665876668766787668876698767087671876728767387674876758767687677876788767987680876818768287683876848768587686876878768887689876908769187692876938769487695876968769787698876998770087701877028770387704877058770687707877088770987710877118771287713877148771587716877178771887719877208772187722877238772487725877268772787728877298773087731877328773387734877358773687737877388773987740877418774287743877448774587746877478774887749877508775187752877538775487755877568775787758877598776087761877628776387764877658776687767877688776987770877718777287773877748777587776877778777887779877808778187782877838778487785877868778787788877898779087791877928779387794877958779687797877988779987800878018780287803878048780587806878078780887809878108781187812878138781487815878168781787818878198782087821878228782387824878258782687827878288782987830878318783287833878348783587836878378783887839878408784187842878438784487845878468784787848878498785087851878528785387854878558785687857878588785987860878618786287863878648786587866878678786887869878708787187872878738787487875878768787787878878798788087881878828788387884878858788687887878888788987890878918789287893878948789587896878978789887899879008790187902879038790487905879068790787908879098791087911879128791387914879158791687917879188791987920879218792287923879248792587926879278792887929879308793187932879338793487935879368793787938879398794087941879428794387944879458794687947879488794987950879518795287953879548795587956879578795887959879608796187962879638796487965879668796787968879698797087971879728797387974879758797687977879788797987980879818798287983879848798587986879878798887989879908799187992879938799487995879968799787998879998800088001880028800388004880058800688007880088800988010880118801288013880148801588016880178801888019880208802188022880238802488025880268802788028880298803088031880328803388034880358803688037880388803988040880418804288043880448804588046880478804888049880508805188052880538805488055880568805788058880598806088061880628806388064880658806688067880688806988070880718807288073880748807588076880778807888079880808808188082880838808488085880868808788088880898809088091880928809388094880958809688097880988809988100881018810288103881048810588106881078810888109881108811188112881138811488115881168811788118881198812088121881228812388124881258812688127881288812988130881318813288133881348813588136881378813888139881408814188142881438814488145881468814788148881498815088151881528815388154881558815688157881588815988160881618816288163881648816588166881678816888169881708817188172881738817488175881768817788178881798818088181881828818388184881858818688187881888818988190881918819288193881948819588196881978819888199882008820188202882038820488205882068820788208882098821088211882128821388214882158821688217882188821988220882218822288223882248822588226882278822888229882308823188232882338823488235882368823788238882398824088241882428824388244882458824688247882488824988250882518825288253882548825588256882578825888259882608826188262882638826488265882668826788268882698827088271882728827388274882758827688277882788827988280882818828288283882848828588286882878828888289882908829188292882938829488295882968829788298882998830088301883028830388304883058830688307883088830988310883118831288313883148831588316883178831888319883208832188322883238832488325883268832788328883298833088331883328833388334883358833688337883388833988340883418834288343883448834588346883478834888349883508835188352883538835488355883568835788358883598836088361883628836388364883658836688367883688836988370883718837288373883748837588376883778837888379883808838188382883838838488385883868838788388883898839088391883928839388394883958839688397883988839988400884018840288403884048840588406884078840888409884108841188412884138841488415884168841788418884198842088421884228842388424884258842688427884288842988430884318843288433884348843588436884378843888439884408844188442884438844488445884468844788448884498845088451884528845388454884558845688457884588845988460884618846288463884648846588466884678846888469884708847188472884738847488475884768847788478884798848088481884828848388484884858848688487884888848988490884918849288493884948849588496884978849888499885008850188502885038850488505885068850788508885098851088511885128851388514885158851688517885188851988520885218852288523885248852588526885278852888529885308853188532885338853488535885368853788538885398854088541885428854388544885458854688547885488854988550885518855288553885548855588556885578855888559885608856188562885638856488565885668856788568885698857088571885728857388574885758857688577885788857988580885818858288583885848858588586885878858888589885908859188592885938859488595885968859788598885998860088601886028860388604886058860688607886088860988610886118861288613886148861588616886178861888619886208862188622886238862488625886268862788628886298863088631886328863388634886358863688637886388863988640886418864288643886448864588646886478864888649886508865188652886538865488655886568865788658886598866088661886628866388664886658866688667886688866988670886718867288673886748867588676886778867888679886808868188682886838868488685886868868788688886898869088691886928869388694886958869688697886988869988700887018870288703887048870588706887078870888709887108871188712887138871488715887168871788718887198872088721887228872388724887258872688727887288872988730887318873288733887348873588736887378873888739887408874188742887438874488745887468874788748887498875088751887528875388754887558875688757887588875988760887618876288763887648876588766887678876888769887708877188772887738877488775887768877788778887798878088781887828878388784887858878688787887888878988790887918879288793887948879588796887978879888799888008880188802888038880488805888068880788808888098881088811888128881388814888158881688817888188881988820888218882288823888248882588826888278882888829888308883188832888338883488835888368883788838888398884088841888428884388844888458884688847888488884988850888518885288853888548885588856888578885888859888608886188862888638886488865888668886788868888698887088871888728887388874888758887688877888788887988880888818888288883888848888588886888878888888889888908889188892888938889488895888968889788898888998890088901889028890388904889058890688907889088890988910889118891288913889148891588916889178891888919889208892188922889238892488925889268892788928889298893088931889328893388934889358893688937889388893988940889418894288943889448894588946889478894888949889508895188952889538895488955889568895788958889598896088961889628896388964889658896688967889688896988970889718897288973889748897588976889778897888979889808898188982889838898488985889868898788988889898899088991889928899388994889958899688997889988899989000890018900289003890048900589006890078900889009890108901189012890138901489015890168901789018890198902089021890228902389024890258902689027890288902989030890318903289033890348903589036890378903889039890408904189042890438904489045890468904789048890498905089051890528905389054890558905689057890588905989060890618906289063890648906589066890678906889069890708907189072890738907489075890768907789078890798908089081890828908389084890858908689087890888908989090890918909289093890948909589096890978909889099891008910189102891038910489105891068910789108891098911089111891128911389114891158911689117891188911989120891218912289123891248912589126891278912889129891308913189132891338913489135891368913789138891398914089141891428914389144891458914689147891488914989150891518915289153891548915589156891578915889159891608916189162891638916489165891668916789168891698917089171891728917389174891758917689177891788917989180891818918289183891848918589186891878918889189891908919189192891938919489195891968919789198891998920089201892028920389204892058920689207892088920989210892118921289213892148921589216892178921889219892208922189222892238922489225892268922789228892298923089231892328923389234892358923689237892388923989240892418924289243892448924589246892478924889249892508925189252892538925489255892568925789258892598926089261892628926389264892658926689267892688926989270892718927289273892748927589276892778927889279892808928189282892838928489285892868928789288892898929089291892928929389294892958929689297892988929989300893018930289303893048930589306893078930889309893108931189312893138931489315893168931789318893198932089321893228932389324893258932689327893288932989330893318933289333893348933589336893378933889339893408934189342893438934489345893468934789348893498935089351893528935389354893558935689357893588935989360893618936289363893648936589366893678936889369893708937189372893738937489375893768937789378893798938089381893828938389384893858938689387893888938989390893918939289393893948939589396893978939889399894008940189402894038940489405894068940789408894098941089411894128941389414894158941689417894188941989420894218942289423894248942589426894278942889429894308943189432894338943489435894368943789438894398944089441894428944389444894458944689447894488944989450894518945289453894548945589456894578945889459894608946189462894638946489465894668946789468894698947089471894728947389474894758947689477894788947989480894818948289483894848948589486894878948889489894908949189492894938949489495894968949789498894998950089501895028950389504895058950689507895088950989510895118951289513895148951589516895178951889519895208952189522895238952489525895268952789528895298953089531895328953389534895358953689537895388953989540895418954289543895448954589546895478954889549895508955189552895538955489555895568955789558895598956089561895628956389564895658956689567895688956989570895718957289573895748957589576895778957889579895808958189582895838958489585895868958789588895898959089591895928959389594895958959689597895988959989600896018960289603896048960589606896078960889609896108961189612896138961489615896168961789618896198962089621896228962389624896258962689627896288962989630896318963289633896348963589636896378963889639896408964189642896438964489645896468964789648896498965089651896528965389654896558965689657896588965989660896618966289663896648966589666896678966889669896708967189672896738967489675896768967789678896798968089681896828968389684896858968689687896888968989690896918969289693896948969589696896978969889699897008970189702897038970489705897068970789708897098971089711897128971389714897158971689717897188971989720897218972289723897248972589726897278972889729897308973189732897338973489735897368973789738897398974089741897428974389744897458974689747897488974989750897518975289753897548975589756897578975889759897608976189762897638976489765897668976789768897698977089771897728977389774897758977689777897788977989780897818978289783897848978589786897878978889789897908979189792897938979489795897968979789798897998980089801898028980389804898058980689807898088980989810898118981289813898148981589816898178981889819898208982189822898238982489825898268982789828898298983089831898328983389834898358983689837898388983989840898418984289843898448984589846898478984889849898508985189852898538985489855898568985789858898598986089861898628986389864898658986689867898688986989870898718987289873898748987589876898778987889879898808988189882898838988489885898868988789888898898989089891898928989389894898958989689897898988989989900899018990289903899048990589906899078990889909899108991189912899138991489915899168991789918899198992089921899228992389924899258992689927899288992989930899318993289933899348993589936899378993889939899408994189942899438994489945899468994789948899498995089951899528995389954899558995689957899588995989960899618996289963899648996589966899678996889969899708997189972899738997489975899768997789978899798998089981899828998389984899858998689987899888998989990899918999289993899948999589996899978999889999900009000190002900039000490005900069000790008900099001090011900129001390014900159001690017900189001990020900219002290023900249002590026900279002890029900309003190032900339003490035900369003790038900399004090041900429004390044900459004690047900489004990050900519005290053900549005590056900579005890059900609006190062900639006490065900669006790068900699007090071900729007390074900759007690077900789007990080900819008290083900849008590086900879008890089900909009190092900939009490095900969009790098900999010090101901029010390104901059010690107901089010990110901119011290113901149011590116901179011890119901209012190122901239012490125901269012790128901299013090131901329013390134901359013690137901389013990140901419014290143901449014590146901479014890149901509015190152901539015490155901569015790158901599016090161901629016390164901659016690167901689016990170901719017290173901749017590176901779017890179901809018190182901839018490185901869018790188901899019090191901929019390194901959019690197901989019990200902019020290203902049020590206902079020890209902109021190212902139021490215902169021790218902199022090221902229022390224902259022690227902289022990230902319023290233902349023590236902379023890239902409024190242902439024490245902469024790248902499025090251902529025390254902559025690257902589025990260902619026290263902649026590266902679026890269902709027190272902739027490275902769027790278902799028090281902829028390284902859028690287902889028990290902919029290293902949029590296902979029890299903009030190302903039030490305903069030790308903099031090311903129031390314903159031690317903189031990320903219032290323903249032590326903279032890329903309033190332903339033490335903369033790338903399034090341903429034390344903459034690347903489034990350903519035290353903549035590356903579035890359903609036190362903639036490365903669036790368903699037090371903729037390374903759037690377903789037990380903819038290383903849038590386903879038890389903909039190392903939039490395903969039790398903999040090401904029040390404904059040690407904089040990410904119041290413904149041590416904179041890419904209042190422904239042490425904269042790428904299043090431904329043390434904359043690437904389043990440904419044290443904449044590446904479044890449904509045190452904539045490455904569045790458904599046090461904629046390464904659046690467904689046990470904719047290473904749047590476904779047890479904809048190482904839048490485904869048790488904899049090491904929049390494904959049690497904989049990500905019050290503905049050590506905079050890509905109051190512905139051490515905169051790518905199052090521905229052390524905259052690527905289052990530905319053290533905349053590536905379053890539905409054190542905439054490545905469054790548905499055090551905529055390554905559055690557905589055990560905619056290563905649056590566905679056890569905709057190572905739057490575905769057790578905799058090581905829058390584905859058690587905889058990590905919059290593905949059590596905979059890599906009060190602906039060490605906069060790608906099061090611906129061390614906159061690617906189061990620906219062290623906249062590626906279062890629906309063190632906339063490635906369063790638906399064090641906429064390644906459064690647906489064990650906519065290653906549065590656906579065890659906609066190662906639066490665906669066790668906699067090671906729067390674906759067690677906789067990680906819068290683906849068590686906879068890689906909069190692906939069490695906969069790698906999070090701907029070390704907059070690707907089070990710907119071290713907149071590716907179071890719907209072190722907239072490725907269072790728907299073090731907329073390734907359073690737907389073990740907419074290743907449074590746907479074890749907509075190752907539075490755907569075790758907599076090761907629076390764907659076690767907689076990770907719077290773907749077590776907779077890779907809078190782907839078490785907869078790788907899079090791907929079390794907959079690797907989079990800908019080290803908049080590806908079080890809908109081190812908139081490815908169081790818908199082090821908229082390824908259082690827908289082990830908319083290833908349083590836908379083890839908409084190842908439084490845908469084790848908499085090851908529085390854908559085690857908589085990860908619086290863908649086590866908679086890869908709087190872908739087490875908769087790878908799088090881908829088390884908859088690887908889088990890908919089290893908949089590896908979089890899909009090190902909039090490905909069090790908909099091090911909129091390914909159091690917909189091990920909219092290923909249092590926909279092890929909309093190932909339093490935909369093790938909399094090941909429094390944909459094690947909489094990950909519095290953909549095590956909579095890959909609096190962909639096490965909669096790968909699097090971909729097390974909759097690977909789097990980909819098290983909849098590986909879098890989909909099190992909939099490995909969099790998909999100091001910029100391004910059100691007910089100991010910119101291013910149101591016910179101891019910209102191022910239102491025910269102791028910299103091031910329103391034910359103691037910389103991040910419104291043910449104591046910479104891049910509105191052910539105491055910569105791058910599106091061910629106391064910659106691067910689106991070910719107291073910749107591076910779107891079910809108191082910839108491085910869108791088910899109091091910929109391094910959109691097910989109991100911019110291103911049110591106911079110891109911109111191112911139111491115911169111791118911199112091121911229112391124911259112691127911289112991130911319113291133911349113591136911379113891139911409114191142911439114491145911469114791148911499115091151911529115391154911559115691157911589115991160911619116291163911649116591166911679116891169911709117191172911739117491175911769117791178911799118091181911829118391184911859118691187911889118991190911919119291193911949119591196911979119891199912009120191202912039120491205912069120791208912099121091211912129121391214912159121691217912189121991220912219122291223912249122591226912279122891229912309123191232912339123491235912369123791238912399124091241912429124391244912459124691247912489124991250912519125291253912549125591256912579125891259912609126191262912639126491265912669126791268912699127091271912729127391274912759127691277912789127991280912819128291283912849128591286912879128891289912909129191292912939129491295912969129791298912999130091301913029130391304913059130691307913089130991310913119131291313913149131591316913179131891319913209132191322913239132491325913269132791328913299133091331913329133391334913359133691337913389133991340913419134291343913449134591346913479134891349913509135191352913539135491355913569135791358913599136091361913629136391364913659136691367913689136991370913719137291373913749137591376913779137891379913809138191382913839138491385913869138791388913899139091391913929139391394913959139691397913989139991400914019140291403914049140591406914079140891409914109141191412914139141491415914169141791418914199142091421914229142391424914259142691427914289142991430914319143291433914349143591436914379143891439914409144191442914439144491445914469144791448914499145091451914529145391454914559145691457914589145991460914619146291463914649146591466914679146891469914709147191472914739147491475914769147791478914799148091481914829148391484914859148691487914889148991490914919149291493914949149591496914979149891499915009150191502915039150491505915069150791508915099151091511915129151391514915159151691517915189151991520915219152291523915249152591526915279152891529915309153191532915339153491535915369153791538915399154091541915429154391544915459154691547915489154991550915519155291553915549155591556915579155891559915609156191562915639156491565915669156791568915699157091571915729157391574915759157691577915789157991580915819158291583915849158591586915879158891589915909159191592915939159491595915969159791598915999160091601916029160391604916059160691607916089160991610916119161291613916149161591616916179161891619916209162191622916239162491625916269162791628916299163091631916329163391634916359163691637916389163991640916419164291643916449164591646916479164891649916509165191652916539165491655916569165791658916599166091661916629166391664916659166691667916689166991670916719167291673916749167591676916779167891679916809168191682916839168491685916869168791688916899169091691916929169391694916959169691697916989169991700917019170291703917049170591706917079170891709917109171191712917139171491715917169171791718917199172091721917229172391724917259172691727917289172991730917319173291733917349173591736917379173891739917409174191742917439174491745917469174791748917499175091751917529175391754917559175691757917589175991760917619176291763917649176591766917679176891769917709177191772917739177491775917769177791778917799178091781917829178391784917859178691787917889178991790917919179291793917949179591796917979179891799918009180191802918039180491805918069180791808918099181091811918129181391814918159181691817918189181991820918219182291823918249182591826918279182891829918309183191832918339183491835918369183791838918399184091841918429184391844918459184691847918489184991850918519185291853918549185591856918579185891859918609186191862918639186491865918669186791868918699187091871918729187391874918759187691877918789187991880918819188291883918849188591886918879188891889918909189191892918939189491895918969189791898918999190091901919029190391904919059190691907919089190991910919119191291913919149191591916919179191891919919209192191922919239192491925919269192791928919299193091931919329193391934919359193691937919389193991940919419194291943919449194591946919479194891949919509195191952919539195491955919569195791958919599196091961919629196391964919659196691967919689196991970919719197291973919749197591976919779197891979919809198191982919839198491985919869198791988919899199091991919929199391994919959199691997919989199992000920019200292003920049200592006920079200892009920109201192012920139201492015920169201792018920199202092021920229202392024920259202692027920289202992030920319203292033920349203592036920379203892039920409204192042920439204492045920469204792048920499205092051920529205392054920559205692057920589205992060920619206292063920649206592066920679206892069920709207192072920739207492075920769207792078920799208092081920829208392084920859208692087920889208992090920919209292093920949209592096920979209892099921009210192102921039210492105921069210792108921099211092111921129211392114921159211692117921189211992120921219212292123921249212592126921279212892129921309213192132921339213492135921369213792138921399214092141921429214392144921459214692147921489214992150921519215292153921549215592156921579215892159921609216192162921639216492165921669216792168921699217092171921729217392174921759217692177921789217992180921819218292183921849218592186921879218892189921909219192192921939219492195921969219792198921999220092201922029220392204922059220692207922089220992210922119221292213922149221592216922179221892219922209222192222922239222492225922269222792228922299223092231922329223392234922359223692237922389223992240922419224292243922449224592246922479224892249922509225192252922539225492255922569225792258922599226092261922629226392264922659226692267922689226992270922719227292273922749227592276922779227892279922809228192282922839228492285922869228792288922899229092291922929229392294922959229692297922989229992300923019230292303923049230592306923079230892309923109231192312923139231492315923169231792318923199232092321923229232392324923259232692327923289232992330923319233292333923349233592336923379233892339923409234192342923439234492345923469234792348923499235092351923529235392354923559235692357923589235992360923619236292363923649236592366923679236892369923709237192372923739237492375923769237792378923799238092381923829238392384923859238692387923889238992390923919239292393923949239592396923979239892399924009240192402924039240492405924069240792408924099241092411924129241392414924159241692417924189241992420924219242292423924249242592426924279242892429924309243192432924339243492435924369243792438924399244092441924429244392444924459244692447924489244992450924519245292453924549245592456924579245892459924609246192462924639246492465924669246792468924699247092471924729247392474924759247692477924789247992480924819248292483924849248592486924879248892489924909249192492924939249492495924969249792498924999250092501925029250392504925059250692507925089250992510925119251292513925149251592516925179251892519925209252192522925239252492525925269252792528925299253092531925329253392534925359253692537925389253992540925419254292543925449254592546925479254892549925509255192552925539255492555925569255792558925599256092561925629256392564925659256692567925689256992570925719257292573925749257592576925779257892579925809258192582925839258492585925869258792588925899259092591925929259392594925959259692597925989259992600926019260292603926049260592606926079260892609926109261192612926139261492615926169261792618926199262092621926229262392624926259262692627926289262992630926319263292633926349263592636926379263892639926409264192642926439264492645926469264792648926499265092651926529265392654926559265692657926589265992660926619266292663926649266592666926679266892669926709267192672926739267492675926769267792678926799268092681926829268392684926859268692687926889268992690926919269292693926949269592696926979269892699927009270192702927039270492705927069270792708927099271092711927129271392714927159271692717927189271992720927219272292723927249272592726927279272892729927309273192732927339273492735927369273792738927399274092741927429274392744927459274692747927489274992750927519275292753927549275592756927579275892759927609276192762927639276492765927669276792768927699277092771927729277392774927759277692777927789277992780927819278292783927849278592786927879278892789927909279192792927939279492795927969279792798927999280092801928029280392804928059280692807928089280992810928119281292813928149281592816928179281892819928209282192822928239282492825928269282792828928299283092831928329283392834928359283692837928389283992840928419284292843928449284592846928479284892849928509285192852928539285492855928569285792858928599286092861928629286392864928659286692867928689286992870928719287292873928749287592876928779287892879928809288192882928839288492885928869288792888928899289092891928929289392894928959289692897928989289992900929019290292903929049290592906929079290892909929109291192912929139291492915929169291792918929199292092921929229292392924929259292692927929289292992930929319293292933929349293592936
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  3. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  4. (global = global || self, factory(global.Potree = {}));
  5. }(this, (function (exports) { 'use strict';
  6. // threejs.org/license
  7. var REVISION='124';var MOUSE={LEFT:0,MIDDLE:1,RIGHT:2,ROTATE:0,DOLLY:1,PAN:2};var TOUCH={ROTATE:0,PAN:1,DOLLY_PAN:2,DOLLY_ROTATE:3};var CullFaceNone=0;var CullFaceBack=1;var CullFaceFront=2;var CullFaceFrontBack=3;var BasicShadowMap=0;var PCFShadowMap=1;var PCFSoftShadowMap=2;var VSMShadowMap=3;var FrontSide=0;var BackSide=1;var DoubleSide=2;var FlatShading$1=1;var SmoothShading=2;var NoBlending=0;var NormalBlending=1;var AdditiveBlending=2;var SubtractiveBlending=3;var MultiplyBlending=4;var CustomBlending=5;var AddEquation=100;var SubtractEquation=101;var ReverseSubtractEquation=102;var MinEquation=103;var MaxEquation=104;var ZeroFactor=200;var OneFactor=201;var SrcColorFactor=202;var OneMinusSrcColorFactor=203;var SrcAlphaFactor=204;var OneMinusSrcAlphaFactor=205;var DstAlphaFactor=206;var OneMinusDstAlphaFactor=207;var DstColorFactor=208;var OneMinusDstColorFactor=209;var SrcAlphaSaturateFactor=210;var NeverDepth=0;var AlwaysDepth=1;var LessDepth=2;var LessEqualDepth=3;var EqualDepth=4;var GreaterEqualDepth=5;var GreaterDepth=6;var NotEqualDepth=7;var MultiplyOperation=0;var MixOperation=1;var AddOperation=2;var NoToneMapping=0;var LinearToneMapping=1;var ReinhardToneMapping=2;var CineonToneMapping=3;var ACESFilmicToneMapping=4;var CustomToneMapping=5;var UVMapping=300;var CubeReflectionMapping=301;var CubeRefractionMapping=302;var EquirectangularReflectionMapping=303;var EquirectangularRefractionMapping=304;var CubeUVReflectionMapping=306;var CubeUVRefractionMapping=307;var RepeatWrapping=1000;var ClampToEdgeWrapping=1001;var MirroredRepeatWrapping=1002;var NearestFilter=1003;var NearestMipmapNearestFilter=1004;var NearestMipMapNearestFilter=1004;var NearestMipmapLinearFilter=1005;var NearestMipMapLinearFilter=1005;var LinearFilter=1006;var LinearMipmapNearestFilter=1007;var LinearMipMapNearestFilter=1007;var LinearMipmapLinearFilter=1008;var LinearMipMapLinearFilter=1008;var UnsignedByteType=1009;var ByteType=1010;var ShortType=1011;var UnsignedShortType=1012;var IntType=1013;var UnsignedIntType=1014;var FloatType=1015;var HalfFloatType=1016;var UnsignedShort4444Type=1017;var UnsignedShort5551Type=1018;var UnsignedShort565Type=1019;var UnsignedInt248Type$1=1020;var AlphaFormat=1021;var RGBFormat=1022;var RGBAFormat=1023;var LuminanceFormat=1024;var LuminanceAlphaFormat=1025;var RGBEFormat=RGBAFormat;var DepthFormat=1026;var DepthStencilFormat=1027;var RedFormat=1028;var RedIntegerFormat=1029;var RGFormat=1030;var RGIntegerFormat=1031;var RGBIntegerFormat=1032;var RGBAIntegerFormat=1033;var RGB_S3TC_DXT1_Format=33776;var RGBA_S3TC_DXT1_Format$1=33777;var RGBA_S3TC_DXT3_Format=33778;var RGBA_S3TC_DXT5_Format$1=33779;var RGB_PVRTC_4BPPV1_Format=35840;var RGB_PVRTC_2BPPV1_Format=35841;var RGBA_PVRTC_4BPPV1_Format=35842;var RGBA_PVRTC_2BPPV1_Format=35843;var RGB_ETC1_Format=36196;var RGB_ETC2_Format=37492;var RGBA_ETC2_EAC_Format=37496;var RGBA_ASTC_4x4_Format=37808;var RGBA_ASTC_5x4_Format=37809;var RGBA_ASTC_5x5_Format=37810;var RGBA_ASTC_6x5_Format=37811;var RGBA_ASTC_6x6_Format=37812;var RGBA_ASTC_8x5_Format=37813;var RGBA_ASTC_8x6_Format=37814;var RGBA_ASTC_8x8_Format=37815;var RGBA_ASTC_10x5_Format=37816;var RGBA_ASTC_10x6_Format=37817;var RGBA_ASTC_10x8_Format=37818;var RGBA_ASTC_10x10_Format=37819;var RGBA_ASTC_12x10_Format=37820;var RGBA_ASTC_12x12_Format=37821;var RGBA_BPTC_Format=36492;var SRGB8_ALPHA8_ASTC_4x4_Format=37840;var SRGB8_ALPHA8_ASTC_5x4_Format=37841;var SRGB8_ALPHA8_ASTC_5x5_Format=37842;var SRGB8_ALPHA8_ASTC_6x5_Format=37843;var SRGB8_ALPHA8_ASTC_6x6_Format=37844;var SRGB8_ALPHA8_ASTC_8x5_Format=37845;var SRGB8_ALPHA8_ASTC_8x6_Format=37846;var SRGB8_ALPHA8_ASTC_8x8_Format=37847;var SRGB8_ALPHA8_ASTC_10x5_Format=37848;var SRGB8_ALPHA8_ASTC_10x6_Format=37849;var SRGB8_ALPHA8_ASTC_10x8_Format=37850;var SRGB8_ALPHA8_ASTC_10x10_Format=37851;var SRGB8_ALPHA8_ASTC_12x10_Format=37852;var SRGB8_ALPHA8_ASTC_12x12_Format=37853;var LoopOnce=2200;var LoopRepeat=2201;var LoopPingPong=2202;var InterpolateDiscrete=2300;var InterpolateLinear=2301;var InterpolateSmooth=2302;var ZeroCurvatureEnding=2400;var ZeroSlopeEnding=2401;var WrapAroundEnding=2402;var NormalAnimationBlendMode=2500;var AdditiveAnimationBlendMode=2501;var TrianglesDrawMode=0;var TriangleStripDrawMode=1;var TriangleFanDrawMode=2;var LinearEncoding=3000;var sRGBEncoding=3001;var GammaEncoding=3007;var RGBEEncoding=3002;var LogLuvEncoding=3003;var RGBM7Encoding=3004;var RGBM16Encoding=3005;var RGBDEncoding=3006;var BasicDepthPacking=3200;var RGBADepthPacking=3201;var TangentSpaceNormalMap=0;var ObjectSpaceNormalMap=1;var ZeroStencilOp=0;var KeepStencilOp=7680;var ReplaceStencilOp=7681;var IncrementStencilOp=7682;var DecrementStencilOp=7683;var IncrementWrapStencilOp=34055;var DecrementWrapStencilOp=34056;var InvertStencilOp=5386;var NeverStencilFunc=512;var LessStencilFunc=513;var EqualStencilFunc=514;var LessEqualStencilFunc=515;var GreaterStencilFunc=516;var NotEqualStencilFunc=517;var GreaterEqualStencilFunc=518;var AlwaysStencilFunc=519;var StaticDrawUsage=35044;var DynamicDrawUsage=35048;var StreamDrawUsage=35040;var StaticReadUsage=35045;var DynamicReadUsage=35049;var StreamReadUsage=35041;var StaticCopyUsage=35046;var DynamicCopyUsage=35050;var StreamCopyUsage=35042;var GLSL1='100';var GLSL3='300 es';/**
  8. * https://github.com/mrdoob/eventdispatcher.js/
  9. */function EventDispatcher(){}Object.assign(EventDispatcher.prototype,{addEventListener:function addEventListener(type,listener){if(this._listeners===undefined)this._listeners={};var listeners=this._listeners;if(listeners[type]===undefined){listeners[type]=[];}if(listeners[type].indexOf(listener)===-1){listeners[type].push(listener);}},hasEventListener:function hasEventListener(type,listener){if(this._listeners===undefined)return false;var listeners=this._listeners;return listeners[type]!==undefined&&listeners[type].indexOf(listener)!==-1;},dispatchEvent:function dispatchEvent(event){if(this._listeners===undefined)return;var listeners=this._listeners;var listenerArray=listeners[event.type];if(listenerArray!==undefined){event.target=this;// Make a copy, in case listeners are removed while iterating.
  10. var array=listenerArray.slice(0);for(var i=0,l=array.length;i<l;i++){array[i].call(this,event);}}}});var _lut=[];for(var i=0;i<256;i++){_lut[i]=(i<16?'0':'')+i.toString(16);}var _seed=1234567;var MathUtils={DEG2RAD:Math.PI/180,RAD2DEG:180/Math.PI,generateUUID:function generateUUID(){// http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  11. var d0=Math.random()*0xffffffff|0;var d1=Math.random()*0xffffffff|0;var d2=Math.random()*0xffffffff|0;var d3=Math.random()*0xffffffff|0;var uuid=_lut[d0&0xff]+_lut[d0>>8&0xff]+_lut[d0>>16&0xff]+_lut[d0>>24&0xff]+'-'+_lut[d1&0xff]+_lut[d1>>8&0xff]+'-'+_lut[d1>>16&0x0f|0x40]+_lut[d1>>24&0xff]+'-'+_lut[d2&0x3f|0x80]+_lut[d2>>8&0xff]+'-'+_lut[d2>>16&0xff]+_lut[d2>>24&0xff]+_lut[d3&0xff]+_lut[d3>>8&0xff]+_lut[d3>>16&0xff]+_lut[d3>>24&0xff];// .toUpperCase() here flattens concatenated strings to save heap memory space.
  12. return uuid.toUpperCase();},clamp:function clamp(value,min,max){return Math.max(min,Math.min(max,value));},// compute euclidian modulo of m % n
  13. // https://en.wikipedia.org/wiki/Modulo_operation
  14. euclideanModulo:function euclideanModulo(n,m){return (n%m+m)%m;},// Linear mapping from range <a1, a2> to range <b1, b2>
  15. mapLinear:function mapLinear(x,a1,a2,b1,b2){return b1+(x-a1)*(b2-b1)/(a2-a1);},// https://en.wikipedia.org/wiki/Linear_interpolation
  16. lerp:function lerp(x,y,t){return (1-t)*x+t*y;},// http://en.wikipedia.org/wiki/Smoothstep
  17. smoothstep:function smoothstep(x,min,max){if(x<=min)return 0;if(x>=max)return 1;x=(x-min)/(max-min);return x*x*(3-2*x);},smootherstep:function smootherstep(x,min,max){if(x<=min)return 0;if(x>=max)return 1;x=(x-min)/(max-min);return x*x*x*(x*(x*6-15)+10);},// Random integer from <low, high> interval
  18. randInt:function randInt(low,high){return low+Math.floor(Math.random()*(high-low+1));},// Random float from <low, high> interval
  19. randFloat:function randFloat(low,high){return low+Math.random()*(high-low);},// Random float from <-range/2, range/2> interval
  20. randFloatSpread:function randFloatSpread(range){return range*(0.5-Math.random());},// Deterministic pseudo-random float in the interval [ 0, 1 ]
  21. seededRandom:function seededRandom(s){if(s!==undefined)_seed=s%2147483647;// Park-Miller algorithm
  22. _seed=_seed*16807%2147483647;return (_seed-1)/2147483646;},degToRad:function degToRad(degrees){return degrees*MathUtils.DEG2RAD;},radToDeg:function radToDeg(radians){return radians*MathUtils.RAD2DEG;},isPowerOfTwo:function isPowerOfTwo(value){return (value&value-1)===0&&value!==0;},ceilPowerOfTwo:function ceilPowerOfTwo(value){return Math.pow(2,Math.ceil(Math.log(value)/Math.LN2));},floorPowerOfTwo:function floorPowerOfTwo(value){return Math.pow(2,Math.floor(Math.log(value)/Math.LN2));},setQuaternionFromProperEuler:function setQuaternionFromProperEuler(q,a,b,c,order){// Intrinsic Proper Euler Angles - see https://en.wikipedia.org/wiki/Euler_angles
  23. // rotations are applied to the axes in the order specified by 'order'
  24. // rotation by angle 'a' is applied first, then by angle 'b', then by angle 'c'
  25. // angles are in radians
  26. var cos=Math.cos;var sin=Math.sin;var c2=cos(b/2);var s2=sin(b/2);var c13=cos((a+c)/2);var s13=sin((a+c)/2);var c1_3=cos((a-c)/2);var s1_3=sin((a-c)/2);var c3_1=cos((c-a)/2);var s3_1=sin((c-a)/2);switch(order){case'XYX':q.set(c2*s13,s2*c1_3,s2*s1_3,c2*c13);break;case'YZY':q.set(s2*s1_3,c2*s13,s2*c1_3,c2*c13);break;case'ZXZ':q.set(s2*c1_3,s2*s1_3,c2*s13,c2*c13);break;case'XZX':q.set(c2*s13,s2*s3_1,s2*c3_1,c2*c13);break;case'YXY':q.set(s2*c3_1,c2*s13,s2*s3_1,c2*c13);break;case'ZYZ':q.set(s2*s3_1,s2*c3_1,c2*s13,c2*c13);break;default:console.warn('THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: '+order);}}};class Vector2{constructor(){var x=arguments.length>0&&arguments[0]!==undefined?arguments[0]:0;var y=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;Object.defineProperty(this,'isVector2',{value:true});this.x=x;this.y=y;}get width(){return this.x;}set width(value){this.x=value;}get height(){return this.y;}set height(value){this.y=value;}set(x,y){this.x=x;this.y=y;return this;}setScalar(scalar){this.x=scalar;this.y=scalar;return this;}setX(x){this.x=x;return this;}setY(y){this.y=y;return this;}setComponent(index,value){switch(index){case 0:this.x=value;break;case 1:this.y=value;break;default:throw new Error('index is out of range: '+index);}return this;}getComponent(index){switch(index){case 0:return this.x;case 1:return this.y;default:throw new Error('index is out of range: '+index);}}clone(){return new this.constructor(this.x,this.y);}copy(v){this.x=v.x;this.y=v.y;return this;}add(v,w){if(w!==undefined){console.warn('THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');return this.addVectors(v,w);}this.x+=v.x;this.y+=v.y;return this;}addScalar(s){this.x+=s;this.y+=s;return this;}addVectors(a,b){this.x=a.x+b.x;this.y=a.y+b.y;return this;}addScaledVector(v,s){this.x+=v.x*s;this.y+=v.y*s;return this;}sub(v,w){if(w!==undefined){console.warn('THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');return this.subVectors(v,w);}this.x-=v.x;this.y-=v.y;return this;}subScalar(s){this.x-=s;this.y-=s;return this;}subVectors(a,b){this.x=a.x-b.x;this.y=a.y-b.y;return this;}multiply(v){this.x*=v.x;this.y*=v.y;return this;}multiplyScalar(scalar){this.x*=scalar;this.y*=scalar;return this;}divide(v){this.x/=v.x;this.y/=v.y;return this;}divideScalar(scalar){return this.multiplyScalar(1/scalar);}applyMatrix3(m){var x=this.x,y=this.y;var e=m.elements;this.x=e[0]*x+e[3]*y+e[6];this.y=e[1]*x+e[4]*y+e[7];return this;}min(v){this.x=Math.min(this.x,v.x);this.y=Math.min(this.y,v.y);return this;}max(v){this.x=Math.max(this.x,v.x);this.y=Math.max(this.y,v.y);return this;}clamp(min,max){// assumes min < max, componentwise
  27. this.x=Math.max(min.x,Math.min(max.x,this.x));this.y=Math.max(min.y,Math.min(max.y,this.y));return this;}clampScalar(minVal,maxVal){this.x=Math.max(minVal,Math.min(maxVal,this.x));this.y=Math.max(minVal,Math.min(maxVal,this.y));return this;}clampLength(min,max){var length=this.length();return this.divideScalar(length||1).multiplyScalar(Math.max(min,Math.min(max,length)));}floor(){this.x=Math.floor(this.x);this.y=Math.floor(this.y);return this;}ceil(){this.x=Math.ceil(this.x);this.y=Math.ceil(this.y);return this;}round(){this.x=Math.round(this.x);this.y=Math.round(this.y);return this;}roundToZero(){this.x=this.x<0?Math.ceil(this.x):Math.floor(this.x);this.y=this.y<0?Math.ceil(this.y):Math.floor(this.y);return this;}negate(){this.x=-this.x;this.y=-this.y;return this;}dot(v){return this.x*v.x+this.y*v.y;}cross(v){return this.x*v.y-this.y*v.x;}lengthSq(){return this.x*this.x+this.y*this.y;}length(){return Math.sqrt(this.x*this.x+this.y*this.y);}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y);}normalize(){return this.divideScalar(this.length()||1);}angle(){// computes the angle in radians with respect to the positive x-axis
  28. var angle=Math.atan2(-this.y,-this.x)+Math.PI;return angle;}distanceTo(v){return Math.sqrt(this.distanceToSquared(v));}distanceToSquared(v){var dx=this.x-v.x,dy=this.y-v.y;return dx*dx+dy*dy;}manhattanDistanceTo(v){return Math.abs(this.x-v.x)+Math.abs(this.y-v.y);}setLength(length){return this.normalize().multiplyScalar(length);}lerp(v,alpha){this.x+=(v.x-this.x)*alpha;this.y+=(v.y-this.y)*alpha;return this;}lerpVectors(v1,v2,alpha){this.x=v1.x+(v2.x-v1.x)*alpha;this.y=v1.y+(v2.y-v1.y)*alpha;return this;}equals(v){return v.x===this.x&&v.y===this.y;}fromArray(array){var offset=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;this.x=array[offset];this.y=array[offset+1];return this;}toArray(){var array=arguments.length>0&&arguments[0]!==undefined?arguments[0]:[];var offset=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;array[offset]=this.x;array[offset+1]=this.y;return array;}fromBufferAttribute(attribute,index,offset){if(offset!==undefined){console.warn('THREE.Vector2: offset has been removed from .fromBufferAttribute().');}this.x=attribute.getX(index);this.y=attribute.getY(index);return this;}rotateAround(center,angle){var c=Math.cos(angle),s=Math.sin(angle);var x=this.x-center.x;var y=this.y-center.y;this.x=x*c-y*s+center.x;this.y=x*s+y*c+center.y;return this;}random(){this.x=Math.random();this.y=Math.random();return this;}}class Matrix3{constructor(){Object.defineProperty(this,'isMatrix3',{value:true});this.elements=[1,0,0,0,1,0,0,0,1];if(arguments.length>0){console.error('THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.');}}set(n11,n12,n13,n21,n22,n23,n31,n32,n33){var te=this.elements;te[0]=n11;te[1]=n21;te[2]=n31;te[3]=n12;te[4]=n22;te[5]=n32;te[6]=n13;te[7]=n23;te[8]=n33;return this;}identity(){this.set(1,0,0,0,1,0,0,0,1);return this;}clone(){return new this.constructor().fromArray(this.elements);}copy(m){var te=this.elements;var me=m.elements;te[0]=me[0];te[1]=me[1];te[2]=me[2];te[3]=me[3];te[4]=me[4];te[5]=me[5];te[6]=me[6];te[7]=me[7];te[8]=me[8];return this;}extractBasis(xAxis,yAxis,zAxis){xAxis.setFromMatrix3Column(this,0);yAxis.setFromMatrix3Column(this,1);zAxis.setFromMatrix3Column(this,2);return this;}setFromMatrix4(m){var me=m.elements;this.set(me[0],me[4],me[8],me[1],me[5],me[9],me[2],me[6],me[10]);return this;}multiply(m){return this.multiplyMatrices(this,m);}premultiply(m){return this.multiplyMatrices(m,this);}multiplyMatrices(a,b){var ae=a.elements;var be=b.elements;var te=this.elements;var a11=ae[0],a12=ae[3],a13=ae[6];var a21=ae[1],a22=ae[4],a23=ae[7];var a31=ae[2],a32=ae[5],a33=ae[8];var b11=be[0],b12=be[3],b13=be[6];var b21=be[1],b22=be[4],b23=be[7];var b31=be[2],b32=be[5],b33=be[8];te[0]=a11*b11+a12*b21+a13*b31;te[3]=a11*b12+a12*b22+a13*b32;te[6]=a11*b13+a12*b23+a13*b33;te[1]=a21*b11+a22*b21+a23*b31;te[4]=a21*b12+a22*b22+a23*b32;te[7]=a21*b13+a22*b23+a23*b33;te[2]=a31*b11+a32*b21+a33*b31;te[5]=a31*b12+a32*b22+a33*b32;te[8]=a31*b13+a32*b23+a33*b33;return this;}multiplyScalar(s){var te=this.elements;te[0]*=s;te[3]*=s;te[6]*=s;te[1]*=s;te[4]*=s;te[7]*=s;te[2]*=s;te[5]*=s;te[8]*=s;return this;}determinant(){var te=this.elements;var a=te[0],b=te[1],c=te[2],d=te[3],e=te[4],f=te[5],g=te[6],h=te[7],i=te[8];return a*e*i-a*f*h-b*d*i+b*f*g+c*d*h-c*e*g;}invert(){var te=this.elements,n11=te[0],n21=te[1],n31=te[2],n12=te[3],n22=te[4],n32=te[5],n13=te[6],n23=te[7],n33=te[8],t11=n33*n22-n32*n23,t12=n32*n13-n33*n12,t13=n23*n12-n22*n13,det=n11*t11+n21*t12+n31*t13;if(det===0)return this.set(0,0,0,0,0,0,0,0,0);var detInv=1/det;te[0]=t11*detInv;te[1]=(n31*n23-n33*n21)*detInv;te[2]=(n32*n21-n31*n22)*detInv;te[3]=t12*detInv;te[4]=(n33*n11-n31*n13)*detInv;te[5]=(n31*n12-n32*n11)*detInv;te[6]=t13*detInv;te[7]=(n21*n13-n23*n11)*detInv;te[8]=(n22*n11-n21*n12)*detInv;return this;}transpose(){var tmp;var m=this.elements;tmp=m[1];m[1]=m[3];m[3]=tmp;tmp=m[2];m[2]=m[6];m[6]=tmp;tmp=m[5];m[5]=m[7];m[7]=tmp;return this;}getNormalMatrix(matrix4){return this.setFromMatrix4(matrix4).copy(this).invert().transpose();}transposeIntoArray(r){var m=this.elements;r[0]=m[0];r[1]=m[3];r[2]=m[6];r[3]=m[1];r[4]=m[4];r[5]=m[7];r[6]=m[2];r[7]=m[5];r[8]=m[8];return this;}setUvTransform(tx,ty,sx,sy,rotation,cx,cy){var c=Math.cos(rotation);var s=Math.sin(rotation);this.set(sx*c,sx*s,-sx*(c*cx+s*cy)+cx+tx,-sy*s,sy*c,-sy*(-s*cx+c*cy)+cy+ty,0,0,1);return this;}scale(sx,sy){var te=this.elements;te[0]*=sx;te[3]*=sx;te[6]*=sx;te[1]*=sy;te[4]*=sy;te[7]*=sy;return this;}rotate(theta){var c=Math.cos(theta);var s=Math.sin(theta);var te=this.elements;var a11=te[0],a12=te[3],a13=te[6];var a21=te[1],a22=te[4],a23=te[7];te[0]=c*a11+s*a21;te[3]=c*a12+s*a22;te[6]=c*a13+s*a23;te[1]=-s*a11+c*a21;te[4]=-s*a12+c*a22;te[7]=-s*a13+c*a23;return this;}translate(tx,ty){var te=this.elements;te[0]+=tx*te[2];te[3]+=tx*te[5];te[6]+=tx*te[8];te[1]+=ty*te[2];te[4]+=ty*te[5];te[7]+=ty*te[8];return this;}equals(matrix){var te=this.elements;var me=matrix.elements;for(var _i=0;_i<9;_i++){if(te[_i]!==me[_i])return false;}return true;}fromArray(array){var offset=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;for(var _i2=0;_i2<9;_i2++){this.elements[_i2]=array[_i2+offset];}return this;}toArray(){var array=arguments.length>0&&arguments[0]!==undefined?arguments[0]:[];var offset=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var te=this.elements;array[offset]=te[0];array[offset+1]=te[1];array[offset+2]=te[2];array[offset+3]=te[3];array[offset+4]=te[4];array[offset+5]=te[5];array[offset+6]=te[6];array[offset+7]=te[7];array[offset+8]=te[8];return array;}}var _canvas;var ImageUtils={getDataURL:function getDataURL(image){if(/^data:/i.test(image.src)){return image.src;}if(typeof HTMLCanvasElement=='undefined'){return image.src;}var canvas;if(image instanceof HTMLCanvasElement){canvas=image;}else {if(_canvas===undefined)_canvas=document.createElementNS('http://www.w3.org/1999/xhtml','canvas');_canvas.width=image.width;_canvas.height=image.height;var context=_canvas.getContext('2d');if(image instanceof ImageData){context.putImageData(image,0,0);}else {context.drawImage(image,0,0,image.width,image.height);}canvas=_canvas;}if(canvas.width>2048||canvas.height>2048){return canvas.toDataURL('image/jpeg',0.6);}else {return canvas.toDataURL('image/png');}}};var textureId=0;function Texture(){var image=arguments.length>0&&arguments[0]!==undefined?arguments[0]:Texture.DEFAULT_IMAGE;var mapping=arguments.length>1&&arguments[1]!==undefined?arguments[1]:Texture.DEFAULT_MAPPING;var wrapS=arguments.length>2&&arguments[2]!==undefined?arguments[2]:ClampToEdgeWrapping;var wrapT=arguments.length>3&&arguments[3]!==undefined?arguments[3]:ClampToEdgeWrapping;var magFilter=arguments.length>4&&arguments[4]!==undefined?arguments[4]:LinearFilter;var minFilter=arguments.length>5&&arguments[5]!==undefined?arguments[5]:LinearMipmapLinearFilter;var format=arguments.length>6&&arguments[6]!==undefined?arguments[6]:RGBAFormat;var type=arguments.length>7&&arguments[7]!==undefined?arguments[7]:UnsignedByteType;var anisotropy=arguments.length>8&&arguments[8]!==undefined?arguments[8]:1;var encoding=arguments.length>9&&arguments[9]!==undefined?arguments[9]:LinearEncoding;Object.defineProperty(this,'id',{value:textureId++});this.uuid=MathUtils.generateUUID();this.name='';this.image=image;this.mipmaps=[];this.mapping=mapping;this.wrapS=wrapS;this.wrapT=wrapT;this.magFilter=magFilter;this.minFilter=minFilter;this.anisotropy=anisotropy;this.format=format;this.internalFormat=null;this.type=type;this.offset=new Vector2(0,0);this.repeat=new Vector2(1,1);this.center=new Vector2(0,0);this.rotation=0;this.matrixAutoUpdate=true;this.matrix=new Matrix3();this.generateMipmaps=true;this.premultiplyAlpha=false;this.flipY=true;this.unpackAlignment=4;// valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  29. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  30. //
  31. // Also changing the encoding after already used by a Material will not automatically make the Material
  32. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  33. this.encoding=encoding;this.version=0;this.onUpdate=null;}Texture.DEFAULT_IMAGE=undefined;Texture.DEFAULT_MAPPING=UVMapping;Texture.prototype=Object.assign(Object.create(EventDispatcher.prototype),{constructor:Texture,isTexture:true,updateMatrix:function updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y);},clone:function clone(){return new this.constructor().copy(this);},copy:function copy(source){this.name=source.name;this.image=source.image;this.mipmaps=source.mipmaps.slice(0);this.mapping=source.mapping;this.wrapS=source.wrapS;this.wrapT=source.wrapT;this.magFilter=source.magFilter;this.minFilter=source.minFilter;this.anisotropy=source.anisotropy;this.format=source.format;this.internalFormat=source.internalFormat;this.type=source.type;this.offset.copy(source.offset);this.repeat.copy(source.repeat);this.center.copy(source.center);this.rotation=source.rotation;this.matrixAutoUpdate=source.matrixAutoUpdate;this.matrix.copy(source.matrix);this.generateMipmaps=source.generateMipmaps;this.premultiplyAlpha=source.premultiplyAlpha;this.flipY=source.flipY;this.unpackAlignment=source.unpackAlignment;this.encoding=source.encoding;return this;},toJSON:function toJSON(meta){var isRootObject=meta===undefined||typeof meta==='string';if(!isRootObject&&meta.textures[this.uuid]!==undefined){return meta.textures[this.uuid];}var output={metadata:{version:4.5,type:'Texture',generator:'Texture.toJSON'},uuid:this.uuid,name:this.name,mapping:this.mapping,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,type:this.type,encoding:this.encoding,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};if(this.image!==undefined){// TODO: Move to THREE.Image
  34. var image=this.image;if(image.uuid===undefined){image.uuid=MathUtils.generateUUID();// UGH
  35. }if(!isRootObject&&meta.images[image.uuid]===undefined){var url;if(Array.isArray(image)){// process array of images e.g. CubeTexture
  36. url=[];for(var _i3=0,l=image.length;_i3<l;_i3++){// check cube texture with data textures
  37. if(image[_i3].isDataTexture){url.push(serializeImage(image[_i3].image));}else {url.push(serializeImage(image[_i3]));}}}else {// process single image
  38. url=serializeImage(image);}meta.images[image.uuid]={uuid:image.uuid,url:url};}output.image=image.uuid;}if(!isRootObject){meta.textures[this.uuid]=output;}return output;},dispose:function dispose(){this.dispatchEvent({type:'dispose'});},transformUv:function transformUv(uv){if(this.mapping!==UVMapping)return uv;uv.applyMatrix3(this.matrix);if(uv.x<0||uv.x>1){switch(this.wrapS){case RepeatWrapping:uv.x=uv.x-Math.floor(uv.x);break;case ClampToEdgeWrapping:uv.x=uv.x<0?0:1;break;case MirroredRepeatWrapping:if(Math.abs(Math.floor(uv.x)%2)===1){uv.x=Math.ceil(uv.x)-uv.x;}else {uv.x=uv.x-Math.floor(uv.x);}break;}}if(uv.y<0||uv.y>1){switch(this.wrapT){case RepeatWrapping:uv.y=uv.y-Math.floor(uv.y);break;case ClampToEdgeWrapping:uv.y=uv.y<0?0:1;break;case MirroredRepeatWrapping:if(Math.abs(Math.floor(uv.y)%2)===1){uv.y=Math.ceil(uv.y)-uv.y;}else {uv.y=uv.y-Math.floor(uv.y);}break;}}if(this.flipY){uv.y=1-uv.y;}return uv;}});Object.defineProperty(Texture.prototype,'needsUpdate',{set:function set(value){if(value===true)this.version++;}});function serializeImage(image){if(typeof HTMLImageElement!=='undefined'&&image instanceof HTMLImageElement||typeof HTMLCanvasElement!=='undefined'&&image instanceof HTMLCanvasElement||typeof ImageBitmap!=='undefined'&&image instanceof ImageBitmap){// default images
  39. return ImageUtils.getDataURL(image);}else {if(image.data){// images of DataTexture
  40. return {data:Array.prototype.slice.call(image.data),width:image.width,height:image.height,type:image.data.constructor.name};}else {console.warn('THREE.Texture: Unable to serialize Texture.');return {};}}}class Vector4{constructor(){var x=arguments.length>0&&arguments[0]!==undefined?arguments[0]:0;var y=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var z=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0;var w=arguments.length>3&&arguments[3]!==undefined?arguments[3]:1;Object.defineProperty(this,'isVector4',{value:true});this.x=x;this.y=y;this.z=z;this.w=w;}get width(){return this.z;}set width(value){this.z=value;}get height(){return this.w;}set height(value){this.w=value;}set(x,y,z,w){this.x=x;this.y=y;this.z=z;this.w=w;return this;}setScalar(scalar){this.x=scalar;this.y=scalar;this.z=scalar;this.w=scalar;return this;}setX(x){this.x=x;return this;}setY(y){this.y=y;return this;}setZ(z){this.z=z;return this;}setW(w){this.w=w;return this;}setComponent(index,value){switch(index){case 0:this.x=value;break;case 1:this.y=value;break;case 2:this.z=value;break;case 3:this.w=value;break;default:throw new Error('index is out of range: '+index);}return this;}getComponent(index){switch(index){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error('index is out of range: '+index);}}clone(){return new this.constructor(this.x,this.y,this.z,this.w);}copy(v){this.x=v.x;this.y=v.y;this.z=v.z;this.w=v.w!==undefined?v.w:1;return this;}add(v,w){if(w!==undefined){console.warn('THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');return this.addVectors(v,w);}this.x+=v.x;this.y+=v.y;this.z+=v.z;this.w+=v.w;return this;}addScalar(s){this.x+=s;this.y+=s;this.z+=s;this.w+=s;return this;}addVectors(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;this.w=a.w+b.w;return this;}addScaledVector(v,s){this.x+=v.x*s;this.y+=v.y*s;this.z+=v.z*s;this.w+=v.w*s;return this;}sub(v,w){if(w!==undefined){console.warn('THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');return this.subVectors(v,w);}this.x-=v.x;this.y-=v.y;this.z-=v.z;this.w-=v.w;return this;}subScalar(s){this.x-=s;this.y-=s;this.z-=s;this.w-=s;return this;}subVectors(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;this.w=a.w-b.w;return this;}multiplyScalar(scalar){this.x*=scalar;this.y*=scalar;this.z*=scalar;this.w*=scalar;return this;}applyMatrix4(m){var x=this.x,y=this.y,z=this.z,w=this.w;var e=m.elements;this.x=e[0]*x+e[4]*y+e[8]*z+e[12]*w;this.y=e[1]*x+e[5]*y+e[9]*z+e[13]*w;this.z=e[2]*x+e[6]*y+e[10]*z+e[14]*w;this.w=e[3]*x+e[7]*y+e[11]*z+e[15]*w;return this;}divideScalar(scalar){return this.multiplyScalar(1/scalar);}setAxisAngleFromQuaternion(q){// http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  41. // q is assumed to be normalized
  42. this.w=2*Math.acos(q.w);var s=Math.sqrt(1-q.w*q.w);if(s<0.0001){this.x=1;this.y=0;this.z=0;}else {this.x=q.x/s;this.y=q.y/s;this.z=q.z/s;}return this;}setAxisAngleFromRotationMatrix(m){// http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  43. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  44. var angle,x,y,z;// variables for result
  45. var epsilon=0.01,// margin to allow for rounding errors
  46. epsilon2=0.1,// margin to distinguish between 0 and 180 degrees
  47. te=m.elements,m11=te[0],m12=te[4],m13=te[8],m21=te[1],m22=te[5],m23=te[9],m31=te[2],m32=te[6],m33=te[10];if(Math.abs(m12-m21)<epsilon&&Math.abs(m13-m31)<epsilon&&Math.abs(m23-m32)<epsilon){// singularity found
  48. // first check for identity matrix which must have +1 for all terms
  49. // in leading diagonal and zero in other terms
  50. if(Math.abs(m12+m21)<epsilon2&&Math.abs(m13+m31)<epsilon2&&Math.abs(m23+m32)<epsilon2&&Math.abs(m11+m22+m33-3)<epsilon2){// this singularity is identity matrix so angle = 0
  51. this.set(1,0,0,0);return this;// zero angle, arbitrary axis
  52. }// otherwise this singularity is angle = 180
  53. angle=Math.PI;var xx=(m11+1)/2;var yy=(m22+1)/2;var zz=(m33+1)/2;var xy=(m12+m21)/4;var xz=(m13+m31)/4;var yz=(m23+m32)/4;if(xx>yy&&xx>zz){// m11 is the largest diagonal term
  54. if(xx<epsilon){x=0;y=0.707106781;z=0.707106781;}else {x=Math.sqrt(xx);y=xy/x;z=xz/x;}}else if(yy>zz){// m22 is the largest diagonal term
  55. if(yy<epsilon){x=0.707106781;y=0;z=0.707106781;}else {y=Math.sqrt(yy);x=xy/y;z=yz/y;}}else {// m33 is the largest diagonal term so base result on this
  56. if(zz<epsilon){x=0.707106781;y=0.707106781;z=0;}else {z=Math.sqrt(zz);x=xz/z;y=yz/z;}}this.set(x,y,z,angle);return this;// return 180 deg rotation
  57. }// as we have reached here there are no singularities so we can handle normally
  58. var s=Math.sqrt((m32-m23)*(m32-m23)+(m13-m31)*(m13-m31)+(m21-m12)*(m21-m12));// used to normalize
  59. if(Math.abs(s)<0.001)s=1;// prevent divide by zero, should not happen if matrix is orthogonal and should be
  60. // caught by singularity test above, but I've left it in just in case
  61. this.x=(m32-m23)/s;this.y=(m13-m31)/s;this.z=(m21-m12)/s;this.w=Math.acos((m11+m22+m33-1)/2);return this;}min(v){this.x=Math.min(this.x,v.x);this.y=Math.min(this.y,v.y);this.z=Math.min(this.z,v.z);this.w=Math.min(this.w,v.w);return this;}max(v){this.x=Math.max(this.x,v.x);this.y=Math.max(this.y,v.y);this.z=Math.max(this.z,v.z);this.w=Math.max(this.w,v.w);return this;}clamp(min,max){// assumes min < max, componentwise
  62. this.x=Math.max(min.x,Math.min(max.x,this.x));this.y=Math.max(min.y,Math.min(max.y,this.y));this.z=Math.max(min.z,Math.min(max.z,this.z));this.w=Math.max(min.w,Math.min(max.w,this.w));return this;}clampScalar(minVal,maxVal){this.x=Math.max(minVal,Math.min(maxVal,this.x));this.y=Math.max(minVal,Math.min(maxVal,this.y));this.z=Math.max(minVal,Math.min(maxVal,this.z));this.w=Math.max(minVal,Math.min(maxVal,this.w));return this;}clampLength(min,max){var length=this.length();return this.divideScalar(length||1).multiplyScalar(Math.max(min,Math.min(max,length)));}floor(){this.x=Math.floor(this.x);this.y=Math.floor(this.y);this.z=Math.floor(this.z);this.w=Math.floor(this.w);return this;}ceil(){this.x=Math.ceil(this.x);this.y=Math.ceil(this.y);this.z=Math.ceil(this.z);this.w=Math.ceil(this.w);return this;}round(){this.x=Math.round(this.x);this.y=Math.round(this.y);this.z=Math.round(this.z);this.w=Math.round(this.w);return this;}roundToZero(){this.x=this.x<0?Math.ceil(this.x):Math.floor(this.x);this.y=this.y<0?Math.ceil(this.y):Math.floor(this.y);this.z=this.z<0?Math.ceil(this.z):Math.floor(this.z);this.w=this.w<0?Math.ceil(this.w):Math.floor(this.w);return this;}negate(){this.x=-this.x;this.y=-this.y;this.z=-this.z;this.w=-this.w;return this;}dot(v){return this.x*v.x+this.y*v.y+this.z*v.z+this.w*v.w;}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w;}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w);}normalize(){return this.divideScalar(this.length()||1);}setLength(length){return this.normalize().multiplyScalar(length);}lerp(v,alpha){this.x+=(v.x-this.x)*alpha;this.y+=(v.y-this.y)*alpha;this.z+=(v.z-this.z)*alpha;this.w+=(v.w-this.w)*alpha;return this;}lerpVectors(v1,v2,alpha){this.x=v1.x+(v2.x-v1.x)*alpha;this.y=v1.y+(v2.y-v1.y)*alpha;this.z=v1.z+(v2.z-v1.z)*alpha;this.w=v1.w+(v2.w-v1.w)*alpha;return this;}equals(v){return v.x===this.x&&v.y===this.y&&v.z===this.z&&v.w===this.w;}fromArray(array){var offset=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;this.x=array[offset];this.y=array[offset+1];this.z=array[offset+2];this.w=array[offset+3];return this;}toArray(){var array=arguments.length>0&&arguments[0]!==undefined?arguments[0]:[];var offset=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;array[offset]=this.x;array[offset+1]=this.y;array[offset+2]=this.z;array[offset+3]=this.w;return array;}fromBufferAttribute(attribute,index,offset){if(offset!==undefined){console.warn('THREE.Vector4: offset has been removed from .fromBufferAttribute().');}this.x=attribute.getX(index);this.y=attribute.getY(index);this.z=attribute.getZ(index);this.w=attribute.getW(index);return this;}random(){this.x=Math.random();this.y=Math.random();this.z=Math.random();this.w=Math.random();return this;}}/*
  63. In options, we can specify:
  64. * Texture parameters for an auto-generated target texture
  65. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  66. */function WebGLRenderTarget(width,height,options){this.width=width;this.height=height;this.scissor=new Vector4(0,0,width,height);this.scissorTest=false;this.viewport=new Vector4(0,0,width,height);options=options||{};this.texture=new Texture(undefined,options.mapping,options.wrapS,options.wrapT,options.magFilter,options.minFilter,options.format,options.type,options.anisotropy,options.encoding);this.texture.image={};this.texture.image.width=width;this.texture.image.height=height;this.texture.generateMipmaps=options.generateMipmaps!==undefined?options.generateMipmaps:false;this.texture.minFilter=options.minFilter!==undefined?options.minFilter:LinearFilter;this.depthBuffer=options.depthBuffer!==undefined?options.depthBuffer:true;this.stencilBuffer=options.stencilBuffer!==undefined?options.stencilBuffer:false;this.depthTexture=options.depthTexture!==undefined?options.depthTexture:null;}WebGLRenderTarget.prototype=Object.assign(Object.create(EventDispatcher.prototype),{constructor:WebGLRenderTarget,isWebGLRenderTarget:true,setSize:function setSize(width,height){if(this.width!==width||this.height!==height){this.width=width;this.height=height;this.texture.image.width=width;this.texture.image.height=height;this.dispose();}this.viewport.set(0,0,width,height);this.scissor.set(0,0,width,height);},clone:function clone(){return new this.constructor().copy(this);},copy:function copy(source){this.width=source.width;this.height=source.height;this.viewport.copy(source.viewport);this.texture=source.texture.clone();this.depthBuffer=source.depthBuffer;this.stencilBuffer=source.stencilBuffer;this.depthTexture=source.depthTexture;return this;},dispose:function dispose(){this.dispatchEvent({type:'dispose'});}});function WebGLMultisampleRenderTarget(width,height,options){WebGLRenderTarget.call(this,width,height,options);this.samples=4;}WebGLMultisampleRenderTarget.prototype=Object.assign(Object.create(WebGLRenderTarget.prototype),{constructor:WebGLMultisampleRenderTarget,isWebGLMultisampleRenderTarget:true,copy:function copy(source){WebGLRenderTarget.prototype.copy.call(this,source);this.samples=source.samples;return this;}});class Quaternion{constructor(){var x=arguments.length>0&&arguments[0]!==undefined?arguments[0]:0;var y=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var z=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0;var w=arguments.length>3&&arguments[3]!==undefined?arguments[3]:1;Object.defineProperty(this,'isQuaternion',{value:true});this._x=x;this._y=y;this._z=z;this._w=w;}static slerp(qa,qb,qm,t){return qm.copy(qa).slerp(qb,t);}static slerpFlat(dst,dstOffset,src0,srcOffset0,src1,srcOffset1,t){// fuzz-free, array-based Quaternion SLERP operation
  67. var x0=src0[srcOffset0+0],y0=src0[srcOffset0+1],z0=src0[srcOffset0+2],w0=src0[srcOffset0+3];var x1=src1[srcOffset1+0],y1=src1[srcOffset1+1],z1=src1[srcOffset1+2],w1=src1[srcOffset1+3];if(w0!==w1||x0!==x1||y0!==y1||z0!==z1){var s=1-t;var cos=x0*x1+y0*y1+z0*z1+w0*w1,dir=cos>=0?1:-1,sqrSin=1-cos*cos;// Skip the Slerp for tiny steps to avoid numeric problems:
  68. if(sqrSin>Number.EPSILON){var sin=Math.sqrt(sqrSin),len=Math.atan2(sin,cos*dir);s=Math.sin(s*len)/sin;t=Math.sin(t*len)/sin;}var tDir=t*dir;x0=x0*s+x1*tDir;y0=y0*s+y1*tDir;z0=z0*s+z1*tDir;w0=w0*s+w1*tDir;// Normalize in case we just did a lerp:
  69. if(s===1-t){var f=1/Math.sqrt(x0*x0+y0*y0+z0*z0+w0*w0);x0*=f;y0*=f;z0*=f;w0*=f;}}dst[dstOffset]=x0;dst[dstOffset+1]=y0;dst[dstOffset+2]=z0;dst[dstOffset+3]=w0;}static multiplyQuaternionsFlat(dst,dstOffset,src0,srcOffset0,src1,srcOffset1){var x0=src0[srcOffset0];var y0=src0[srcOffset0+1];var z0=src0[srcOffset0+2];var w0=src0[srcOffset0+3];var x1=src1[srcOffset1];var y1=src1[srcOffset1+1];var z1=src1[srcOffset1+2];var w1=src1[srcOffset1+3];dst[dstOffset]=x0*w1+w0*x1+y0*z1-z0*y1;dst[dstOffset+1]=y0*w1+w0*y1+z0*x1-x0*z1;dst[dstOffset+2]=z0*w1+w0*z1+x0*y1-y0*x1;dst[dstOffset+3]=w0*w1-x0*x1-y0*y1-z0*z1;return dst;}get x(){return this._x;}set x(value){this._x=value;this._onChangeCallback();}get y(){return this._y;}set y(value){this._y=value;this._onChangeCallback();}get z(){return this._z;}set z(value){this._z=value;this._onChangeCallback();}get w(){return this._w;}set w(value){this._w=value;this._onChangeCallback();}set(x,y,z,w){this._x=x;this._y=y;this._z=z;this._w=w;this._onChangeCallback();return this;}clone(){return new this.constructor(this._x,this._y,this._z,this._w);}copy(quaternion){this._x=quaternion.x;this._y=quaternion.y;this._z=quaternion.z;this._w=quaternion.w;this._onChangeCallback();return this;}setFromEuler(euler,update){if(!(euler&&euler.isEuler)){throw new Error('THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.');}var x=euler._x,y=euler._y,z=euler._z,order=euler._order;// http://www.mathworks.com/matlabcentral/fileexchange/
  70. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  71. // content/SpinCalc.m
  72. var cos=Math.cos;var sin=Math.sin;var c1=cos(x/2);var c2=cos(y/2);var c3=cos(z/2);var s1=sin(x/2);var s2=sin(y/2);var s3=sin(z/2);switch(order){case'XYZ':this._x=s1*c2*c3+c1*s2*s3;this._y=c1*s2*c3-s1*c2*s3;this._z=c1*c2*s3+s1*s2*c3;this._w=c1*c2*c3-s1*s2*s3;break;case'YXZ':this._x=s1*c2*c3+c1*s2*s3;this._y=c1*s2*c3-s1*c2*s3;this._z=c1*c2*s3-s1*s2*c3;this._w=c1*c2*c3+s1*s2*s3;break;case'ZXY':this._x=s1*c2*c3-c1*s2*s3;this._y=c1*s2*c3+s1*c2*s3;this._z=c1*c2*s3+s1*s2*c3;this._w=c1*c2*c3-s1*s2*s3;break;case'ZYX':this._x=s1*c2*c3-c1*s2*s3;this._y=c1*s2*c3+s1*c2*s3;this._z=c1*c2*s3-s1*s2*c3;this._w=c1*c2*c3+s1*s2*s3;break;case'YZX':this._x=s1*c2*c3+c1*s2*s3;this._y=c1*s2*c3+s1*c2*s3;this._z=c1*c2*s3-s1*s2*c3;this._w=c1*c2*c3-s1*s2*s3;break;case'XZY':this._x=s1*c2*c3-c1*s2*s3;this._y=c1*s2*c3-s1*c2*s3;this._z=c1*c2*s3+s1*s2*c3;this._w=c1*c2*c3+s1*s2*s3;break;default:console.warn('THREE.Quaternion: .setFromEuler() encountered an unknown order: '+order);}if(update!==false)this._onChangeCallback();return this;}setFromAxisAngle(axis,angle){// http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  73. // assumes axis is normalized
  74. var halfAngle=angle/2,s=Math.sin(halfAngle);this._x=axis.x*s;this._y=axis.y*s;this._z=axis.z*s;this._w=Math.cos(halfAngle);this._onChangeCallback();return this;}setFromRotationMatrix(m){// http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  75. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  76. var te=m.elements,m11=te[0],m12=te[4],m13=te[8],m21=te[1],m22=te[5],m23=te[9],m31=te[2],m32=te[6],m33=te[10],trace=m11+m22+m33;if(trace>0){var s=0.5/Math.sqrt(trace+1.0);this._w=0.25/s;this._x=(m32-m23)*s;this._y=(m13-m31)*s;this._z=(m21-m12)*s;}else if(m11>m22&&m11>m33){var _s=2.0*Math.sqrt(1.0+m11-m22-m33);this._w=(m32-m23)/_s;this._x=0.25*_s;this._y=(m12+m21)/_s;this._z=(m13+m31)/_s;}else if(m22>m33){var _s2=2.0*Math.sqrt(1.0+m22-m11-m33);this._w=(m13-m31)/_s2;this._x=(m12+m21)/_s2;this._y=0.25*_s2;this._z=(m23+m32)/_s2;}else {var _s3=2.0*Math.sqrt(1.0+m33-m11-m22);this._w=(m21-m12)/_s3;this._x=(m13+m31)/_s3;this._y=(m23+m32)/_s3;this._z=0.25*_s3;}this._onChangeCallback();return this;}setFromUnitVectors(vFrom,vTo){// assumes direction vectors vFrom and vTo are normalized
  77. var EPS=0.000001;var r=vFrom.dot(vTo)+1;if(r<EPS){r=0;if(Math.abs(vFrom.x)>Math.abs(vFrom.z)){this._x=-vFrom.y;this._y=vFrom.x;this._z=0;this._w=r;}else {this._x=0;this._y=-vFrom.z;this._z=vFrom.y;this._w=r;}}else {// crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  78. this._x=vFrom.y*vTo.z-vFrom.z*vTo.y;this._y=vFrom.z*vTo.x-vFrom.x*vTo.z;this._z=vFrom.x*vTo.y-vFrom.y*vTo.x;this._w=r;}return this.normalize();}angleTo(q){return 2*Math.acos(Math.abs(MathUtils.clamp(this.dot(q),-1,1)));}rotateTowards(q,step){var angle=this.angleTo(q);if(angle===0)return this;var t=Math.min(1,step/angle);this.slerp(q,t);return this;}identity(){return this.set(0,0,0,1);}invert(){// quaternion is assumed to have unit length
  79. return this.conjugate();}conjugate(){this._x*=-1;this._y*=-1;this._z*=-1;this._onChangeCallback();return this;}dot(v){return this._x*v._x+this._y*v._y+this._z*v._z+this._w*v._w;}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w;}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w);}normalize(){var l=this.length();if(l===0){this._x=0;this._y=0;this._z=0;this._w=1;}else {l=1/l;this._x=this._x*l;this._y=this._y*l;this._z=this._z*l;this._w=this._w*l;}this._onChangeCallback();return this;}multiply(q,p){if(p!==undefined){console.warn('THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.');return this.multiplyQuaternions(q,p);}return this.multiplyQuaternions(this,q);}premultiply(q){return this.multiplyQuaternions(q,this);}multiplyQuaternions(a,b){// from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  80. var qax=a._x,qay=a._y,qaz=a._z,qaw=a._w;var qbx=b._x,qby=b._y,qbz=b._z,qbw=b._w;this._x=qax*qbw+qaw*qbx+qay*qbz-qaz*qby;this._y=qay*qbw+qaw*qby+qaz*qbx-qax*qbz;this._z=qaz*qbw+qaw*qbz+qax*qby-qay*qbx;this._w=qaw*qbw-qax*qbx-qay*qby-qaz*qbz;this._onChangeCallback();return this;}slerp(qb,t){if(t===0)return this;if(t===1)return this.copy(qb);var x=this._x,y=this._y,z=this._z,w=this._w;// http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  81. var cosHalfTheta=w*qb._w+x*qb._x+y*qb._y+z*qb._z;if(cosHalfTheta<0){this._w=-qb._w;this._x=-qb._x;this._y=-qb._y;this._z=-qb._z;cosHalfTheta=-cosHalfTheta;}else {this.copy(qb);}if(cosHalfTheta>=1.0){this._w=w;this._x=x;this._y=y;this._z=z;return this;}var sqrSinHalfTheta=1.0-cosHalfTheta*cosHalfTheta;if(sqrSinHalfTheta<=Number.EPSILON){var s=1-t;this._w=s*w+t*this._w;this._x=s*x+t*this._x;this._y=s*y+t*this._y;this._z=s*z+t*this._z;this.normalize();this._onChangeCallback();return this;}var sinHalfTheta=Math.sqrt(sqrSinHalfTheta);var halfTheta=Math.atan2(sinHalfTheta,cosHalfTheta);var ratioA=Math.sin((1-t)*halfTheta)/sinHalfTheta,ratioB=Math.sin(t*halfTheta)/sinHalfTheta;this._w=w*ratioA+this._w*ratioB;this._x=x*ratioA+this._x*ratioB;this._y=y*ratioA+this._y*ratioB;this._z=z*ratioA+this._z*ratioB;this._onChangeCallback();return this;}equals(quaternion){return quaternion._x===this._x&&quaternion._y===this._y&&quaternion._z===this._z&&quaternion._w===this._w;}fromArray(array){var offset=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;this._x=array[offset];this._y=array[offset+1];this._z=array[offset+2];this._w=array[offset+3];this._onChangeCallback();return this;}toArray(){var array=arguments.length>0&&arguments[0]!==undefined?arguments[0]:[];var offset=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;array[offset]=this._x;array[offset+1]=this._y;array[offset+2]=this._z;array[offset+3]=this._w;return array;}fromBufferAttribute(attribute,index){this._x=attribute.getX(index);this._y=attribute.getY(index);this._z=attribute.getZ(index);this._w=attribute.getW(index);return this;}_onChange(callback){this._onChangeCallback=callback;return this;}_onChangeCallback(){}}class Vector3{constructor(){var x=arguments.length>0&&arguments[0]!==undefined?arguments[0]:0;var y=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var z=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0;Object.defineProperty(this,'isVector3',{value:true});this.x=x;this.y=y;this.z=z;}set(x,y,z){if(z===undefined)z=this.z;// sprite.scale.set(x,y)
  82. this.x=x;this.y=y;this.z=z;return this;}setScalar(scalar){this.x=scalar;this.y=scalar;this.z=scalar;return this;}setX(x){this.x=x;return this;}setY(y){this.y=y;return this;}setZ(z){this.z=z;return this;}setComponent(index,value){switch(index){case 0:this.x=value;break;case 1:this.y=value;break;case 2:this.z=value;break;default:throw new Error('index is out of range: '+index);}return this;}getComponent(index){switch(index){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error('index is out of range: '+index);}}clone(){return new this.constructor(this.x,this.y,this.z);}copy(v){this.x=v.x;this.y=v.y;this.z=v.z;return this;}add(v,w){if(w!==undefined){console.warn('THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');return this.addVectors(v,w);}this.x+=v.x;this.y+=v.y;this.z+=v.z;return this;}addScalar(s){this.x+=s;this.y+=s;this.z+=s;return this;}addVectors(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;return this;}addScaledVector(v,s){this.x+=v.x*s;this.y+=v.y*s;this.z+=v.z*s;return this;}sub(v,w){if(w!==undefined){console.warn('THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');return this.subVectors(v,w);}this.x-=v.x;this.y-=v.y;this.z-=v.z;return this;}subScalar(s){this.x-=s;this.y-=s;this.z-=s;return this;}subVectors(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;return this;}multiply(v,w){if(w!==undefined){console.warn('THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.');return this.multiplyVectors(v,w);}this.x*=v.x;this.y*=v.y;this.z*=v.z;return this;}multiplyScalar(scalar){this.x*=scalar;this.y*=scalar;this.z*=scalar;return this;}multiplyVectors(a,b){this.x=a.x*b.x;this.y=a.y*b.y;this.z=a.z*b.z;return this;}applyEuler(euler){if(!(euler&&euler.isEuler)){console.error('THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.');}return this.applyQuaternion(_quaternion.setFromEuler(euler));}applyAxisAngle(axis,angle){return this.applyQuaternion(_quaternion.setFromAxisAngle(axis,angle));}applyMatrix3(m){var x=this.x,y=this.y,z=this.z;var e=m.elements;this.x=e[0]*x+e[3]*y+e[6]*z;this.y=e[1]*x+e[4]*y+e[7]*z;this.z=e[2]*x+e[5]*y+e[8]*z;return this;}applyNormalMatrix(m){return this.applyMatrix3(m).normalize();}applyMatrix4(m){var x=this.x,y=this.y,z=this.z;var e=m.elements;var w=1/(e[3]*x+e[7]*y+e[11]*z+e[15]);this.x=(e[0]*x+e[4]*y+e[8]*z+e[12])*w;this.y=(e[1]*x+e[5]*y+e[9]*z+e[13])*w;this.z=(e[2]*x+e[6]*y+e[10]*z+e[14])*w;return this;}applyQuaternion(q){var x=this.x,y=this.y,z=this.z;var qx=q.x,qy=q.y,qz=q.z,qw=q.w;// calculate quat * vector
  83. var ix=qw*x+qy*z-qz*y;var iy=qw*y+qz*x-qx*z;var iz=qw*z+qx*y-qy*x;var iw=-qx*x-qy*y-qz*z;// calculate result * inverse quat
  84. this.x=ix*qw+iw*-qx+iy*-qz-iz*-qy;this.y=iy*qw+iw*-qy+iz*-qx-ix*-qz;this.z=iz*qw+iw*-qz+ix*-qy-iy*-qx;return this;}project(camera){return this.applyMatrix4(camera.matrixWorldInverse).applyMatrix4(camera.projectionMatrix);}unproject(camera){return this.applyMatrix4(camera.projectionMatrixInverse).applyMatrix4(camera.matrixWorld);}transformDirection(m){// input: THREE.Matrix4 affine matrix
  85. // vector interpreted as a direction
  86. var x=this.x,y=this.y,z=this.z;var e=m.elements;this.x=e[0]*x+e[4]*y+e[8]*z;this.y=e[1]*x+e[5]*y+e[9]*z;this.z=e[2]*x+e[6]*y+e[10]*z;return this.normalize();}divide(v){this.x/=v.x;this.y/=v.y;this.z/=v.z;return this;}divideScalar(scalar){return this.multiplyScalar(1/scalar);}min(v){this.x=Math.min(this.x,v.x);this.y=Math.min(this.y,v.y);this.z=Math.min(this.z,v.z);return this;}max(v){this.x=Math.max(this.x,v.x);this.y=Math.max(this.y,v.y);this.z=Math.max(this.z,v.z);return this;}clamp(min,max){// assumes min < max, componentwise
  87. this.x=Math.max(min.x,Math.min(max.x,this.x));this.y=Math.max(min.y,Math.min(max.y,this.y));this.z=Math.max(min.z,Math.min(max.z,this.z));return this;}clampScalar(minVal,maxVal){this.x=Math.max(minVal,Math.min(maxVal,this.x));this.y=Math.max(minVal,Math.min(maxVal,this.y));this.z=Math.max(minVal,Math.min(maxVal,this.z));return this;}clampLength(min,max){var length=this.length();return this.divideScalar(length||1).multiplyScalar(Math.max(min,Math.min(max,length)));}floor(){this.x=Math.floor(this.x);this.y=Math.floor(this.y);this.z=Math.floor(this.z);return this;}ceil(){this.x=Math.ceil(this.x);this.y=Math.ceil(this.y);this.z=Math.ceil(this.z);return this;}round(){this.x=Math.round(this.x);this.y=Math.round(this.y);this.z=Math.round(this.z);return this;}roundToZero(){this.x=this.x<0?Math.ceil(this.x):Math.floor(this.x);this.y=this.y<0?Math.ceil(this.y):Math.floor(this.y);this.z=this.z<0?Math.ceil(this.z):Math.floor(this.z);return this;}negate(){this.x=-this.x;this.y=-this.y;this.z=-this.z;return this;}dot(v){return this.x*v.x+this.y*v.y+this.z*v.z;}// TODO lengthSquared?
  88. lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z;}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z);}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z);}normalize(){return this.divideScalar(this.length()||1);}setLength(length){return this.normalize().multiplyScalar(length);}lerp(v,alpha){this.x+=(v.x-this.x)*alpha;this.y+=(v.y-this.y)*alpha;this.z+=(v.z-this.z)*alpha;return this;}lerpVectors(v1,v2,alpha){this.x=v1.x+(v2.x-v1.x)*alpha;this.y=v1.y+(v2.y-v1.y)*alpha;this.z=v1.z+(v2.z-v1.z)*alpha;return this;}cross(v,w){if(w!==undefined){console.warn('THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.');return this.crossVectors(v,w);}return this.crossVectors(this,v);}crossVectors(a,b){var ax=a.x,ay=a.y,az=a.z;var bx=b.x,by=b.y,bz=b.z;this.x=ay*bz-az*by;this.y=az*bx-ax*bz;this.z=ax*by-ay*bx;return this;}projectOnVector(v){var denominator=v.lengthSq();if(denominator===0)return this.set(0,0,0);var scalar=v.dot(this)/denominator;return this.copy(v).multiplyScalar(scalar);}projectOnPlane(planeNormal){_vector.copy(this).projectOnVector(planeNormal);return this.sub(_vector);}reflect(normal){// reflect incident vector off plane orthogonal to normal
  89. // normal is assumed to have unit length
  90. return this.sub(_vector.copy(normal).multiplyScalar(2*this.dot(normal)));}angleTo(v){var denominator=Math.sqrt(this.lengthSq()*v.lengthSq());if(denominator===0)return Math.PI/2;var theta=this.dot(v)/denominator;// clamp, to handle numerical problems
  91. return Math.acos(MathUtils.clamp(theta,-1,1));}distanceTo(v){return Math.sqrt(this.distanceToSquared(v));}distanceToSquared(v){var dx=this.x-v.x,dy=this.y-v.y,dz=this.z-v.z;return dx*dx+dy*dy+dz*dz;}manhattanDistanceTo(v){return Math.abs(this.x-v.x)+Math.abs(this.y-v.y)+Math.abs(this.z-v.z);}setFromSpherical(s){return this.setFromSphericalCoords(s.radius,s.phi,s.theta);}setFromSphericalCoords(radius,phi,theta){var sinPhiRadius=Math.sin(phi)*radius;this.x=sinPhiRadius*Math.sin(theta);this.y=Math.cos(phi)*radius;this.z=sinPhiRadius*Math.cos(theta);return this;}setFromCylindrical(c){return this.setFromCylindricalCoords(c.radius,c.theta,c.y);}setFromCylindricalCoords(radius,theta,y){this.x=radius*Math.sin(theta);this.y=y;this.z=radius*Math.cos(theta);return this;}setFromMatrixPosition(m){var e=m.elements;this.x=e[12];this.y=e[13];this.z=e[14];return this;}setFromMatrixScale(m){var sx=this.setFromMatrixColumn(m,0).length();var sy=this.setFromMatrixColumn(m,1).length();var sz=this.setFromMatrixColumn(m,2).length();this.x=sx;this.y=sy;this.z=sz;return this;}setFromMatrixColumn(m,index){return this.fromArray(m.elements,index*4);}setFromMatrix3Column(m,index){return this.fromArray(m.elements,index*3);}equals(v){return v.x===this.x&&v.y===this.y&&v.z===this.z;}fromArray(array){var offset=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;this.x=array[offset];this.y=array[offset+1];this.z=array[offset+2];return this;}toArray(){var array=arguments.length>0&&arguments[0]!==undefined?arguments[0]:[];var offset=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;array[offset]=this.x;array[offset+1]=this.y;array[offset+2]=this.z;return array;}fromBufferAttribute(attribute,index,offset){if(offset!==undefined){console.warn('THREE.Vector3: offset has been removed from .fromBufferAttribute().');}this.x=attribute.getX(index);this.y=attribute.getY(index);this.z=attribute.getZ(index);return this;}random(){this.x=Math.random();this.y=Math.random();this.z=Math.random();return this;}}var _vector=/*@__PURE__*/new Vector3();var _quaternion=/*@__PURE__*/new Quaternion();class Box3{constructor(min,max){Object.defineProperty(this,'isBox3',{value:true});this.min=min!==undefined?min:new Vector3(+Infinity,+Infinity,+Infinity);this.max=max!==undefined?max:new Vector3(-Infinity,-Infinity,-Infinity);}set(min,max){this.min.copy(min);this.max.copy(max);return this;}setFromArray(array){var minX=+Infinity;var minY=+Infinity;var minZ=+Infinity;var maxX=-Infinity;var maxY=-Infinity;var maxZ=-Infinity;for(var _i4=0,l=array.length;_i4<l;_i4+=3){var x=array[_i4];var y=array[_i4+1];var z=array[_i4+2];if(x<minX)minX=x;if(y<minY)minY=y;if(z<minZ)minZ=z;if(x>maxX)maxX=x;if(y>maxY)maxY=y;if(z>maxZ)maxZ=z;}this.min.set(minX,minY,minZ);this.max.set(maxX,maxY,maxZ);return this;}setFromBufferAttribute(attribute){var minX=+Infinity;var minY=+Infinity;var minZ=+Infinity;var maxX=-Infinity;var maxY=-Infinity;var maxZ=-Infinity;for(var _i5=0,l=attribute.count;_i5<l;_i5++){var x=attribute.getX(_i5);var y=attribute.getY(_i5);var z=attribute.getZ(_i5);if(x<minX)minX=x;if(y<minY)minY=y;if(z<minZ)minZ=z;if(x>maxX)maxX=x;if(y>maxY)maxY=y;if(z>maxZ)maxZ=z;}this.min.set(minX,minY,minZ);this.max.set(maxX,maxY,maxZ);return this;}setFromPoints(points){this.makeEmpty();for(var _i6=0,il=points.length;_i6<il;_i6++){this.expandByPoint(points[_i6]);}return this;}setFromCenterAndSize(center,size){var halfSize=_vector$1.copy(size).multiplyScalar(0.5);this.min.copy(center).sub(halfSize);this.max.copy(center).add(halfSize);return this;}setFromObject(object){this.makeEmpty();return this.expandByObject(object);}clone(){return new this.constructor().copy(this);}copy(box){this.min.copy(box.min);this.max.copy(box.max);return this;}makeEmpty(){this.min.x=this.min.y=this.min.z=+Infinity;this.max.x=this.max.y=this.max.z=-Infinity;return this;}isEmpty(){// this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  92. return this.max.x<this.min.x||this.max.y<this.min.y||this.max.z<this.min.z;}getCenter(target){if(target===undefined){console.warn('THREE.Box3: .getCenter() target is now required');target=new Vector3();}return this.isEmpty()?target.set(0,0,0):target.addVectors(this.min,this.max).multiplyScalar(0.5);}getSize(target){if(target===undefined){console.warn('THREE.Box3: .getSize() target is now required');target=new Vector3();}return this.isEmpty()?target.set(0,0,0):target.subVectors(this.max,this.min);}expandByPoint(point){this.min.min(point);this.max.max(point);return this;}expandByVector(vector){this.min.sub(vector);this.max.add(vector);return this;}expandByScalar(scalar){this.min.addScalar(-scalar);this.max.addScalar(scalar);return this;}expandByObject(object){// Computes the world-axis-aligned bounding box of an object (including its children),
  93. // accounting for both the object's, and children's, world transforms
  94. object.updateWorldMatrix(false,false);var geometry=object.geometry;if(geometry!==undefined){if(geometry.boundingBox===null){geometry.computeBoundingBox();}_box.copy(geometry.boundingBox);_box.applyMatrix4(object.matrixWorld);this.union(_box);}var children=object.children;for(var _i7=0,l=children.length;_i7<l;_i7++){this.expandByObject(children[_i7]);}return this;}containsPoint(point){return point.x<this.min.x||point.x>this.max.x||point.y<this.min.y||point.y>this.max.y||point.z<this.min.z||point.z>this.max.z?false:true;}containsBox(box){return this.min.x<=box.min.x&&box.max.x<=this.max.x&&this.min.y<=box.min.y&&box.max.y<=this.max.y&&this.min.z<=box.min.z&&box.max.z<=this.max.z;}getParameter(point,target){// This can potentially have a divide by zero if the box
  95. // has a size dimension of 0.
  96. if(target===undefined){console.warn('THREE.Box3: .getParameter() target is now required');target=new Vector3();}return target.set((point.x-this.min.x)/(this.max.x-this.min.x),(point.y-this.min.y)/(this.max.y-this.min.y),(point.z-this.min.z)/(this.max.z-this.min.z));}intersectsBox(box){// using 6 splitting planes to rule out intersections.
  97. return box.max.x<this.min.x||box.min.x>this.max.x||box.max.y<this.min.y||box.min.y>this.max.y||box.max.z<this.min.z||box.min.z>this.max.z?false:true;}intersectsSphere(sphere){// Find the point on the AABB closest to the sphere center.
  98. this.clampPoint(sphere.center,_vector$1);// If that point is inside the sphere, the AABB and sphere intersect.
  99. return _vector$1.distanceToSquared(sphere.center)<=sphere.radius*sphere.radius;}intersectsPlane(plane){// We compute the minimum and maximum dot product values. If those values
  100. // are on the same side (back or front) of the plane, then there is no intersection.
  101. var min,max;if(plane.normal.x>0){min=plane.normal.x*this.min.x;max=plane.normal.x*this.max.x;}else {min=plane.normal.x*this.max.x;max=plane.normal.x*this.min.x;}if(plane.normal.y>0){min+=plane.normal.y*this.min.y;max+=plane.normal.y*this.max.y;}else {min+=plane.normal.y*this.max.y;max+=plane.normal.y*this.min.y;}if(plane.normal.z>0){min+=plane.normal.z*this.min.z;max+=plane.normal.z*this.max.z;}else {min+=plane.normal.z*this.max.z;max+=plane.normal.z*this.min.z;}return min<=-plane.constant&&max>=-plane.constant;}intersectsTriangle(triangle){if(this.isEmpty()){return false;}// compute box center and extents
  102. this.getCenter(_center);_extents.subVectors(this.max,_center);// translate triangle to aabb origin
  103. _v0.subVectors(triangle.a,_center);_v1.subVectors(triangle.b,_center);_v2.subVectors(triangle.c,_center);// compute edge vectors for triangle
  104. _f0.subVectors(_v1,_v0);_f1.subVectors(_v2,_v1);_f2.subVectors(_v0,_v2);// test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
  105. // make an axis testing of each of the 3 sides of the aabb against each of the 3 sides of the triangle = 9 axis of separation
  106. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  107. var axes=[0,-_f0.z,_f0.y,0,-_f1.z,_f1.y,0,-_f2.z,_f2.y,_f0.z,0,-_f0.x,_f1.z,0,-_f1.x,_f2.z,0,-_f2.x,-_f0.y,_f0.x,0,-_f1.y,_f1.x,0,-_f2.y,_f2.x,0];if(!satForAxes(axes,_v0,_v1,_v2,_extents)){return false;}// test 3 face normals from the aabb
  108. axes=[1,0,0,0,1,0,0,0,1];if(!satForAxes(axes,_v0,_v1,_v2,_extents)){return false;}// finally testing the face normal of the triangle
  109. // use already existing triangle edge vectors here
  110. _triangleNormal.crossVectors(_f0,_f1);axes=[_triangleNormal.x,_triangleNormal.y,_triangleNormal.z];return satForAxes(axes,_v0,_v1,_v2,_extents);}clampPoint(point,target){if(target===undefined){console.warn('THREE.Box3: .clampPoint() target is now required');target=new Vector3();}return target.copy(point).clamp(this.min,this.max);}distanceToPoint(point){var clampedPoint=_vector$1.copy(point).clamp(this.min,this.max);return clampedPoint.sub(point).length();}getBoundingSphere(target){if(target===undefined){console.error('THREE.Box3: .getBoundingSphere() target is now required');//target = new Sphere(); // removed to avoid cyclic dependency
  111. }this.getCenter(target.center);target.radius=this.getSize(_vector$1).length()*0.5;return target;}intersect(box){this.min.max(box.min);this.max.min(box.max);// ensure that if there is no overlap, the result is fully empty, not slightly empty with non-inf/+inf values that will cause subsequence intersects to erroneously return valid values.
  112. if(this.isEmpty())this.makeEmpty();return this;}union(box){this.min.min(box.min);this.max.max(box.max);return this;}applyMatrix4(matrix){// transform of empty box is an empty box.
  113. if(this.isEmpty())return this;// NOTE: I am using a binary pattern to specify all 2^3 combinations below
  114. _points[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(matrix);// 000
  115. _points[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(matrix);// 001
  116. _points[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(matrix);// 010
  117. _points[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(matrix);// 011
  118. _points[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(matrix);// 100
  119. _points[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(matrix);// 101
  120. _points[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(matrix);// 110
  121. _points[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(matrix);// 111
  122. this.setFromPoints(_points);return this;}translate(offset){this.min.add(offset);this.max.add(offset);return this;}equals(box){return box.min.equals(this.min)&&box.max.equals(this.max);}}function satForAxes(axes,v0,v1,v2,extents){for(var _i8=0,j=axes.length-3;_i8<=j;_i8+=3){_testAxis.fromArray(axes,_i8);// project the aabb onto the seperating axis
  123. var r=extents.x*Math.abs(_testAxis.x)+extents.y*Math.abs(_testAxis.y)+extents.z*Math.abs(_testAxis.z);// project all 3 vertices of the triangle onto the seperating axis
  124. var p0=v0.dot(_testAxis);var p1=v1.dot(_testAxis);var p2=v2.dot(_testAxis);// actual test, basically see if either of the most extreme of the triangle points intersects r
  125. if(Math.max(-Math.max(p0,p1,p2),Math.min(p0,p1,p2))>r){// points of the projected triangle are outside the projected half-length of the aabb
  126. // the axis is seperating and we can exit
  127. return false;}}return true;}var _points=[/*@__PURE__*/new Vector3(),/*@__PURE__*/new Vector3(),/*@__PURE__*/new Vector3(),/*@__PURE__*/new Vector3(),/*@__PURE__*/new Vector3(),/*@__PURE__*/new Vector3(),/*@__PURE__*/new Vector3(),/*@__PURE__*/new Vector3()];var _vector$1=/*@__PURE__*/new Vector3();var _box=/*@__PURE__*/new Box3();// triangle centered vertices
  128. var _v0=/*@__PURE__*/new Vector3();var _v1=/*@__PURE__*/new Vector3();var _v2=/*@__PURE__*/new Vector3();// triangle edge vectors
  129. var _f0=/*@__PURE__*/new Vector3();var _f1=/*@__PURE__*/new Vector3();var _f2=/*@__PURE__*/new Vector3();var _center=/*@__PURE__*/new Vector3();var _extents=/*@__PURE__*/new Vector3();var _triangleNormal=/*@__PURE__*/new Vector3();var _testAxis=/*@__PURE__*/new Vector3();var _box$1=/*@__PURE__*/new Box3();class Sphere{constructor(center,radius){this.center=center!==undefined?center:new Vector3();this.radius=radius!==undefined?radius:-1;}set(center,radius){this.center.copy(center);this.radius=radius;return this;}setFromPoints(points,optionalCenter){var center=this.center;if(optionalCenter!==undefined){center.copy(optionalCenter);}else {_box$1.setFromPoints(points).getCenter(center);}var maxRadiusSq=0;for(var _i9=0,il=points.length;_i9<il;_i9++){maxRadiusSq=Math.max(maxRadiusSq,center.distanceToSquared(points[_i9]));}this.radius=Math.sqrt(maxRadiusSq);return this;}clone(){return new this.constructor().copy(this);}copy(sphere){this.center.copy(sphere.center);this.radius=sphere.radius;return this;}isEmpty(){return this.radius<0;}makeEmpty(){this.center.set(0,0,0);this.radius=-1;return this;}containsPoint(point){return point.distanceToSquared(this.center)<=this.radius*this.radius;}distanceToPoint(point){return point.distanceTo(this.center)-this.radius;}intersectsSphere(sphere){var radiusSum=this.radius+sphere.radius;return sphere.center.distanceToSquared(this.center)<=radiusSum*radiusSum;}intersectsBox(box){return box.intersectsSphere(this);}intersectsPlane(plane){return Math.abs(plane.distanceToPoint(this.center))<=this.radius;}clampPoint(point,target){var deltaLengthSq=this.center.distanceToSquared(point);if(target===undefined){console.warn('THREE.Sphere: .clampPoint() target is now required');target=new Vector3();}target.copy(point);if(deltaLengthSq>this.radius*this.radius){target.sub(this.center).normalize();target.multiplyScalar(this.radius).add(this.center);}return target;}getBoundingBox(target){if(target===undefined){console.warn('THREE.Sphere: .getBoundingBox() target is now required');target=new Box3();}if(this.isEmpty()){// Empty sphere produces empty bounding box
  130. target.makeEmpty();return target;}target.set(this.center,this.center);target.expandByScalar(this.radius);return target;}applyMatrix4(matrix){this.center.applyMatrix4(matrix);this.radius=this.radius*matrix.getMaxScaleOnAxis();return this;}translate(offset){this.center.add(offset);return this;}equals(sphere){return sphere.center.equals(this.center)&&sphere.radius===this.radius;}}var _vector$2=/*@__PURE__*/new Vector3();var _segCenter=/*@__PURE__*/new Vector3();var _segDir=/*@__PURE__*/new Vector3();var _diff=/*@__PURE__*/new Vector3();var _edge1=/*@__PURE__*/new Vector3();var _edge2=/*@__PURE__*/new Vector3();var _normal=/*@__PURE__*/new Vector3();class Ray{constructor(origin,direction){this.origin=origin!==undefined?origin:new Vector3();this.direction=direction!==undefined?direction:new Vector3(0,0,-1);}set(origin,direction){this.origin.copy(origin);this.direction.copy(direction);return this;}clone(){return new this.constructor().copy(this);}copy(ray){this.origin.copy(ray.origin);this.direction.copy(ray.direction);return this;}at(t,target){if(target===undefined){console.warn('THREE.Ray: .at() target is now required');target=new Vector3();}return target.copy(this.direction).multiplyScalar(t).add(this.origin);}lookAt(v){this.direction.copy(v).sub(this.origin).normalize();return this;}recast(t){this.origin.copy(this.at(t,_vector$2));return this;}closestPointToPoint(point,target){if(target===undefined){console.warn('THREE.Ray: .closestPointToPoint() target is now required');target=new Vector3();}target.subVectors(point,this.origin);var directionDistance=target.dot(this.direction);if(directionDistance<0){return target.copy(this.origin);}return target.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);}distanceToPoint(point){return Math.sqrt(this.distanceSqToPoint(point));}distanceSqToPoint(point){var directionDistance=_vector$2.subVectors(point,this.origin).dot(this.direction);// point behind the ray
  131. if(directionDistance<0){return this.origin.distanceToSquared(point);}_vector$2.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);return _vector$2.distanceToSquared(point);}distanceSqToSegment(v0,v1,optionalPointOnRay,optionalPointOnSegment){// from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  132. // It returns the min distance between the ray and the segment
  133. // defined by v0 and v1
  134. // It can also set two optional targets :
  135. // - The closest point on the ray
  136. // - The closest point on the segment
  137. _segCenter.copy(v0).add(v1).multiplyScalar(0.5);_segDir.copy(v1).sub(v0).normalize();_diff.copy(this.origin).sub(_segCenter);var segExtent=v0.distanceTo(v1)*0.5;var a01=-this.direction.dot(_segDir);var b0=_diff.dot(this.direction);var b1=-_diff.dot(_segDir);var c=_diff.lengthSq();var det=Math.abs(1-a01*a01);var s0,s1,sqrDist,extDet;if(det>0){// The ray and segment are not parallel.
  138. s0=a01*b1-b0;s1=a01*b0-b1;extDet=segExtent*det;if(s0>=0){if(s1>=-extDet){if(s1<=extDet){// region 0
  139. // Minimum at interior points of ray and segment.
  140. var invDet=1/det;s0*=invDet;s1*=invDet;sqrDist=s0*(s0+a01*s1+2*b0)+s1*(a01*s0+s1+2*b1)+c;}else {// region 1
  141. s1=segExtent;s0=Math.max(0,-(a01*s1+b0));sqrDist=-s0*s0+s1*(s1+2*b1)+c;}}else {// region 5
  142. s1=-segExtent;s0=Math.max(0,-(a01*s1+b0));sqrDist=-s0*s0+s1*(s1+2*b1)+c;}}else {if(s1<=-extDet){// region 4
  143. s0=Math.max(0,-(-a01*segExtent+b0));s1=s0>0?-segExtent:Math.min(Math.max(-segExtent,-b1),segExtent);sqrDist=-s0*s0+s1*(s1+2*b1)+c;}else if(s1<=extDet){// region 3
  144. s0=0;s1=Math.min(Math.max(-segExtent,-b1),segExtent);sqrDist=s1*(s1+2*b1)+c;}else {// region 2
  145. s0=Math.max(0,-(a01*segExtent+b0));s1=s0>0?segExtent:Math.min(Math.max(-segExtent,-b1),segExtent);sqrDist=-s0*s0+s1*(s1+2*b1)+c;}}}else {// Ray and segment are parallel.
  146. s1=a01>0?-segExtent:segExtent;s0=Math.max(0,-(a01*s1+b0));sqrDist=-s0*s0+s1*(s1+2*b1)+c;}if(optionalPointOnRay){optionalPointOnRay.copy(this.direction).multiplyScalar(s0).add(this.origin);}if(optionalPointOnSegment){optionalPointOnSegment.copy(_segDir).multiplyScalar(s1).add(_segCenter);}return sqrDist;}intersectSphere(sphere,target){_vector$2.subVectors(sphere.center,this.origin);var tca=_vector$2.dot(this.direction);var d2=_vector$2.dot(_vector$2)-tca*tca;var radius2=sphere.radius*sphere.radius;if(d2>radius2)return null;var thc=Math.sqrt(radius2-d2);// t0 = first intersect point - entrance on front of sphere
  147. var t0=tca-thc;// t1 = second intersect point - exit point on back of sphere
  148. var t1=tca+thc;// test to see if both t0 and t1 are behind the ray - if so, return null
  149. if(t0<0&&t1<0)return null;// test to see if t0 is behind the ray:
  150. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  151. // in order to always return an intersect point that is in front of the ray.
  152. if(t0<0)return this.at(t1,target);// else t0 is in front of the ray, so return the first collision point scaled by t0
  153. return this.at(t0,target);}intersectsSphere(sphere){return this.distanceSqToPoint(sphere.center)<=sphere.radius*sphere.radius;}distanceToPlane(plane){var denominator=plane.normal.dot(this.direction);if(denominator===0){// line is coplanar, return origin
  154. if(plane.distanceToPoint(this.origin)===0){return 0;}// Null is preferable to undefined since undefined means.... it is undefined
  155. return null;}var t=-(this.origin.dot(plane.normal)+plane.constant)/denominator;// Return if the ray never intersects the plane
  156. return t>=0?t:null;}intersectPlane(plane,target){var t=this.distanceToPlane(plane);if(t===null){return null;}return this.at(t,target);}intersectsPlane(plane){// check if the ray lies on the plane first
  157. var distToPoint=plane.distanceToPoint(this.origin);if(distToPoint===0){return true;}var denominator=plane.normal.dot(this.direction);if(denominator*distToPoint<0){return true;}// ray origin is behind the plane (and is pointing behind it)
  158. return false;}intersectBox(box,target){var tmin,tmax,tymin,tymax,tzmin,tzmax;var invdirx=1/this.direction.x,invdiry=1/this.direction.y,invdirz=1/this.direction.z;var origin=this.origin;if(invdirx>=0){tmin=(box.min.x-origin.x)*invdirx;tmax=(box.max.x-origin.x)*invdirx;}else {tmin=(box.max.x-origin.x)*invdirx;tmax=(box.min.x-origin.x)*invdirx;}if(invdiry>=0){tymin=(box.min.y-origin.y)*invdiry;tymax=(box.max.y-origin.y)*invdiry;}else {tymin=(box.max.y-origin.y)*invdiry;tymax=(box.min.y-origin.y)*invdiry;}if(tmin>tymax||tymin>tmax)return null;// These lines also handle the case where tmin or tmax is NaN
  159. // (result of 0 * Infinity). x !== x returns true if x is NaN
  160. if(tymin>tmin||tmin!==tmin)tmin=tymin;if(tymax<tmax||tmax!==tmax)tmax=tymax;if(invdirz>=0){tzmin=(box.min.z-origin.z)*invdirz;tzmax=(box.max.z-origin.z)*invdirz;}else {tzmin=(box.max.z-origin.z)*invdirz;tzmax=(box.min.z-origin.z)*invdirz;}if(tmin>tzmax||tzmin>tmax)return null;if(tzmin>tmin||tmin!==tmin)tmin=tzmin;if(tzmax<tmax||tmax!==tmax)tmax=tzmax;//return point closest to the ray (positive side)
  161. if(tmax<0)return null;return this.at(tmin>=0?tmin:tmax,target);}intersectsBox(box){return this.intersectBox(box,_vector$2)!==null;}intersectTriangle(a,b,c,backfaceCulling,target){// Compute the offset origin, edges, and normal.
  162. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  163. _edge1.subVectors(b,a);_edge2.subVectors(c,a);_normal.crossVectors(_edge1,_edge2);// Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  164. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  165. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  166. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  167. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  168. var DdN=this.direction.dot(_normal);var sign;if(DdN>0){if(backfaceCulling)return null;sign=1;}else if(DdN<0){sign=-1;DdN=-DdN;}else {return null;}_diff.subVectors(this.origin,a);var DdQxE2=sign*this.direction.dot(_edge2.crossVectors(_diff,_edge2));// b1 < 0, no intersection
  169. if(DdQxE2<0){return null;}var DdE1xQ=sign*this.direction.dot(_edge1.cross(_diff));// b2 < 0, no intersection
  170. if(DdE1xQ<0){return null;}// b1+b2 > 1, no intersection
  171. if(DdQxE2+DdE1xQ>DdN){return null;}// Line intersects triangle, check if ray does.
  172. var QdN=-sign*_diff.dot(_normal);// t < 0, no intersection
  173. if(QdN<0){return null;}// Ray intersects triangle.
  174. return this.at(QdN/DdN,target);}applyMatrix4(matrix4){this.origin.applyMatrix4(matrix4);this.direction.transformDirection(matrix4);return this;}equals(ray){return ray.origin.equals(this.origin)&&ray.direction.equals(this.direction);}}class Matrix4{constructor(){Object.defineProperty(this,'isMatrix4',{value:true});this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];if(arguments.length>0){console.error('THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.');}}set(n11,n12,n13,n14,n21,n22,n23,n24,n31,n32,n33,n34,n41,n42,n43,n44){var te=this.elements;te[0]=n11;te[4]=n12;te[8]=n13;te[12]=n14;te[1]=n21;te[5]=n22;te[9]=n23;te[13]=n24;te[2]=n31;te[6]=n32;te[10]=n33;te[14]=n34;te[3]=n41;te[7]=n42;te[11]=n43;te[15]=n44;return this;}identity(){this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1);return this;}clone(){return new Matrix4().fromArray(this.elements);}copy(m){var te=this.elements;var me=m.elements;te[0]=me[0];te[1]=me[1];te[2]=me[2];te[3]=me[3];te[4]=me[4];te[5]=me[5];te[6]=me[6];te[7]=me[7];te[8]=me[8];te[9]=me[9];te[10]=me[10];te[11]=me[11];te[12]=me[12];te[13]=me[13];te[14]=me[14];te[15]=me[15];return this;}copyPosition(m){var te=this.elements,me=m.elements;te[12]=me[12];te[13]=me[13];te[14]=me[14];return this;}extractBasis(xAxis,yAxis,zAxis){xAxis.setFromMatrixColumn(this,0);yAxis.setFromMatrixColumn(this,1);zAxis.setFromMatrixColumn(this,2);return this;}makeBasis(xAxis,yAxis,zAxis){this.set(xAxis.x,yAxis.x,zAxis.x,0,xAxis.y,yAxis.y,zAxis.y,0,xAxis.z,yAxis.z,zAxis.z,0,0,0,0,1);return this;}extractRotation(m){// this method does not support reflection matrices
  175. var te=this.elements;var me=m.elements;var scaleX=1/_v1$1.setFromMatrixColumn(m,0).length();var scaleY=1/_v1$1.setFromMatrixColumn(m,1).length();var scaleZ=1/_v1$1.setFromMatrixColumn(m,2).length();te[0]=me[0]*scaleX;te[1]=me[1]*scaleX;te[2]=me[2]*scaleX;te[3]=0;te[4]=me[4]*scaleY;te[5]=me[5]*scaleY;te[6]=me[6]*scaleY;te[7]=0;te[8]=me[8]*scaleZ;te[9]=me[9]*scaleZ;te[10]=me[10]*scaleZ;te[11]=0;te[12]=0;te[13]=0;te[14]=0;te[15]=1;return this;}makeRotationFromEuler(euler){if(!(euler&&euler.isEuler)){console.error('THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.');}var te=this.elements;var x=euler.x,y=euler.y,z=euler.z;var a=Math.cos(x),b=Math.sin(x);var c=Math.cos(y),d=Math.sin(y);var e=Math.cos(z),f=Math.sin(z);if(euler.order==='XYZ'){var ae=a*e,af=a*f,be=b*e,bf=b*f;te[0]=c*e;te[4]=-c*f;te[8]=d;te[1]=af+be*d;te[5]=ae-bf*d;te[9]=-b*c;te[2]=bf-ae*d;te[6]=be+af*d;te[10]=a*c;}else if(euler.order==='YXZ'){var ce=c*e,cf=c*f,de=d*e,df=d*f;te[0]=ce+df*b;te[4]=de*b-cf;te[8]=a*d;te[1]=a*f;te[5]=a*e;te[9]=-b;te[2]=cf*b-de;te[6]=df+ce*b;te[10]=a*c;}else if(euler.order==='ZXY'){var _ce=c*e,_cf=c*f,_de=d*e,_df=d*f;te[0]=_ce-_df*b;te[4]=-a*f;te[8]=_de+_cf*b;te[1]=_cf+_de*b;te[5]=a*e;te[9]=_df-_ce*b;te[2]=-a*d;te[6]=b;te[10]=a*c;}else if(euler.order==='ZYX'){var _ae=a*e,_af=a*f,_be=b*e,_bf=b*f;te[0]=c*e;te[4]=_be*d-_af;te[8]=_ae*d+_bf;te[1]=c*f;te[5]=_bf*d+_ae;te[9]=_af*d-_be;te[2]=-d;te[6]=b*c;te[10]=a*c;}else if(euler.order==='YZX'){var ac=a*c,ad=a*d,bc=b*c,bd=b*d;te[0]=c*e;te[4]=bd-ac*f;te[8]=bc*f+ad;te[1]=f;te[5]=a*e;te[9]=-b*e;te[2]=-d*e;te[6]=ad*f+bc;te[10]=ac-bd*f;}else if(euler.order==='XZY'){var _ac=a*c,_ad=a*d,_bc=b*c,_bd=b*d;te[0]=c*e;te[4]=-f;te[8]=d*e;te[1]=_ac*f+_bd;te[5]=a*e;te[9]=_ad*f-_bc;te[2]=_bc*f-_ad;te[6]=b*e;te[10]=_bd*f+_ac;}// bottom row
  176. te[3]=0;te[7]=0;te[11]=0;// last column
  177. te[12]=0;te[13]=0;te[14]=0;te[15]=1;return this;}makeRotationFromQuaternion(q){return this.compose(_zero,q,_one);}lookAt(eye,target,up){var te=this.elements;_z.subVectors(eye,target);if(_z.lengthSq()===0){// eye and target are in the same position
  178. _z.z=1;}_z.normalize();_x.crossVectors(up,_z);if(_x.lengthSq()===0){// up and z are parallel
  179. if(Math.abs(up.z)===1){_z.x+=0.0001;}else {_z.z+=0.0001;}_z.normalize();_x.crossVectors(up,_z);}_x.normalize();_y.crossVectors(_z,_x);te[0]=_x.x;te[4]=_y.x;te[8]=_z.x;te[1]=_x.y;te[5]=_y.y;te[9]=_z.y;te[2]=_x.z;te[6]=_y.z;te[10]=_z.z;return this;}multiply(m,n){if(n!==undefined){console.warn('THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.');return this.multiplyMatrices(m,n);}return this.multiplyMatrices(this,m);}premultiply(m){return this.multiplyMatrices(m,this);}multiplyMatrices(a,b){var ae=a.elements;var be=b.elements;var te=this.elements;var a11=ae[0],a12=ae[4],a13=ae[8],a14=ae[12];var a21=ae[1],a22=ae[5],a23=ae[9],a24=ae[13];var a31=ae[2],a32=ae[6],a33=ae[10],a34=ae[14];var a41=ae[3],a42=ae[7],a43=ae[11],a44=ae[15];var b11=be[0],b12=be[4],b13=be[8],b14=be[12];var b21=be[1],b22=be[5],b23=be[9],b24=be[13];var b31=be[2],b32=be[6],b33=be[10],b34=be[14];var b41=be[3],b42=be[7],b43=be[11],b44=be[15];te[0]=a11*b11+a12*b21+a13*b31+a14*b41;te[4]=a11*b12+a12*b22+a13*b32+a14*b42;te[8]=a11*b13+a12*b23+a13*b33+a14*b43;te[12]=a11*b14+a12*b24+a13*b34+a14*b44;te[1]=a21*b11+a22*b21+a23*b31+a24*b41;te[5]=a21*b12+a22*b22+a23*b32+a24*b42;te[9]=a21*b13+a22*b23+a23*b33+a24*b43;te[13]=a21*b14+a22*b24+a23*b34+a24*b44;te[2]=a31*b11+a32*b21+a33*b31+a34*b41;te[6]=a31*b12+a32*b22+a33*b32+a34*b42;te[10]=a31*b13+a32*b23+a33*b33+a34*b43;te[14]=a31*b14+a32*b24+a33*b34+a34*b44;te[3]=a41*b11+a42*b21+a43*b31+a44*b41;te[7]=a41*b12+a42*b22+a43*b32+a44*b42;te[11]=a41*b13+a42*b23+a43*b33+a44*b43;te[15]=a41*b14+a42*b24+a43*b34+a44*b44;return this;}multiplyScalar(s){var te=this.elements;te[0]*=s;te[4]*=s;te[8]*=s;te[12]*=s;te[1]*=s;te[5]*=s;te[9]*=s;te[13]*=s;te[2]*=s;te[6]*=s;te[10]*=s;te[14]*=s;te[3]*=s;te[7]*=s;te[11]*=s;te[15]*=s;return this;}determinant(){var te=this.elements;var n11=te[0],n12=te[4],n13=te[8],n14=te[12];var n21=te[1],n22=te[5],n23=te[9],n24=te[13];var n31=te[2],n32=te[6],n33=te[10],n34=te[14];var n41=te[3],n42=te[7],n43=te[11],n44=te[15];//TODO: make this more efficient
  180. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  181. return n41*(+n14*n23*n32-n13*n24*n32-n14*n22*n33+n12*n24*n33+n13*n22*n34-n12*n23*n34)+n42*(+n11*n23*n34-n11*n24*n33+n14*n21*n33-n13*n21*n34+n13*n24*n31-n14*n23*n31)+n43*(+n11*n24*n32-n11*n22*n34-n14*n21*n32+n12*n21*n34+n14*n22*n31-n12*n24*n31)+n44*(-n13*n22*n31-n11*n23*n32+n11*n22*n33+n13*n21*n32-n12*n21*n33+n12*n23*n31);}transpose(){var te=this.elements;var tmp;tmp=te[1];te[1]=te[4];te[4]=tmp;tmp=te[2];te[2]=te[8];te[8]=tmp;tmp=te[6];te[6]=te[9];te[9]=tmp;tmp=te[3];te[3]=te[12];te[12]=tmp;tmp=te[7];te[7]=te[13];te[13]=tmp;tmp=te[11];te[11]=te[14];te[14]=tmp;return this;}setPosition(x,y,z){var te=this.elements;if(x.isVector3){te[12]=x.x;te[13]=x.y;te[14]=x.z;}else {te[12]=x;te[13]=y;te[14]=z;}return this;}invert(){// based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  182. var te=this.elements,n11=te[0],n21=te[1],n31=te[2],n41=te[3],n12=te[4],n22=te[5],n32=te[6],n42=te[7],n13=te[8],n23=te[9],n33=te[10],n43=te[11],n14=te[12],n24=te[13],n34=te[14],n44=te[15],t11=n23*n34*n42-n24*n33*n42+n24*n32*n43-n22*n34*n43-n23*n32*n44+n22*n33*n44,t12=n14*n33*n42-n13*n34*n42-n14*n32*n43+n12*n34*n43+n13*n32*n44-n12*n33*n44,t13=n13*n24*n42-n14*n23*n42+n14*n22*n43-n12*n24*n43-n13*n22*n44+n12*n23*n44,t14=n14*n23*n32-n13*n24*n32-n14*n22*n33+n12*n24*n33+n13*n22*n34-n12*n23*n34;var det=n11*t11+n21*t12+n31*t13+n41*t14;if(det===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);var detInv=1/det;te[0]=t11*detInv;te[1]=(n24*n33*n41-n23*n34*n41-n24*n31*n43+n21*n34*n43+n23*n31*n44-n21*n33*n44)*detInv;te[2]=(n22*n34*n41-n24*n32*n41+n24*n31*n42-n21*n34*n42-n22*n31*n44+n21*n32*n44)*detInv;te[3]=(n23*n32*n41-n22*n33*n41-n23*n31*n42+n21*n33*n42+n22*n31*n43-n21*n32*n43)*detInv;te[4]=t12*detInv;te[5]=(n13*n34*n41-n14*n33*n41+n14*n31*n43-n11*n34*n43-n13*n31*n44+n11*n33*n44)*detInv;te[6]=(n14*n32*n41-n12*n34*n41-n14*n31*n42+n11*n34*n42+n12*n31*n44-n11*n32*n44)*detInv;te[7]=(n12*n33*n41-n13*n32*n41+n13*n31*n42-n11*n33*n42-n12*n31*n43+n11*n32*n43)*detInv;te[8]=t13*detInv;te[9]=(n14*n23*n41-n13*n24*n41-n14*n21*n43+n11*n24*n43+n13*n21*n44-n11*n23*n44)*detInv;te[10]=(n12*n24*n41-n14*n22*n41+n14*n21*n42-n11*n24*n42-n12*n21*n44+n11*n22*n44)*detInv;te[11]=(n13*n22*n41-n12*n23*n41-n13*n21*n42+n11*n23*n42+n12*n21*n43-n11*n22*n43)*detInv;te[12]=t14*detInv;te[13]=(n13*n24*n31-n14*n23*n31+n14*n21*n33-n11*n24*n33-n13*n21*n34+n11*n23*n34)*detInv;te[14]=(n14*n22*n31-n12*n24*n31-n14*n21*n32+n11*n24*n32+n12*n21*n34-n11*n22*n34)*detInv;te[15]=(n12*n23*n31-n13*n22*n31+n13*n21*n32-n11*n23*n32-n12*n21*n33+n11*n22*n33)*detInv;return this;}scale(v){var te=this.elements;var x=v.x,y=v.y,z=v.z;te[0]*=x;te[4]*=y;te[8]*=z;te[1]*=x;te[5]*=y;te[9]*=z;te[2]*=x;te[6]*=y;te[10]*=z;te[3]*=x;te[7]*=y;te[11]*=z;return this;}getMaxScaleOnAxis(){var te=this.elements;var scaleXSq=te[0]*te[0]+te[1]*te[1]+te[2]*te[2];var scaleYSq=te[4]*te[4]+te[5]*te[5]+te[6]*te[6];var scaleZSq=te[8]*te[8]+te[9]*te[9]+te[10]*te[10];return Math.sqrt(Math.max(scaleXSq,scaleYSq,scaleZSq));}makeTranslation(x,y,z){this.set(1,0,0,x,0,1,0,y,0,0,1,z,0,0,0,1);return this;}makeRotationX(theta){var c=Math.cos(theta),s=Math.sin(theta);this.set(1,0,0,0,0,c,-s,0,0,s,c,0,0,0,0,1);return this;}makeRotationY(theta){var c=Math.cos(theta),s=Math.sin(theta);this.set(c,0,s,0,0,1,0,0,-s,0,c,0,0,0,0,1);return this;}makeRotationZ(theta){var c=Math.cos(theta),s=Math.sin(theta);this.set(c,-s,0,0,s,c,0,0,0,0,1,0,0,0,0,1);return this;}makeRotationAxis(axis,angle){// Based on http://www.gamedev.net/reference/articles/article1199.asp
  183. var c=Math.cos(angle);var s=Math.sin(angle);var t=1-c;var x=axis.x,y=axis.y,z=axis.z;var tx=t*x,ty=t*y;this.set(tx*x+c,tx*y-s*z,tx*z+s*y,0,tx*y+s*z,ty*y+c,ty*z-s*x,0,tx*z-s*y,ty*z+s*x,t*z*z+c,0,0,0,0,1);return this;}makeScale(x,y,z){this.set(x,0,0,0,0,y,0,0,0,0,z,0,0,0,0,1);return this;}makeShear(x,y,z){this.set(1,y,z,0,x,1,z,0,x,y,1,0,0,0,0,1);return this;}compose(position,quaternion,scale){var te=this.elements;var x=quaternion._x,y=quaternion._y,z=quaternion._z,w=quaternion._w;var x2=x+x,y2=y+y,z2=z+z;var xx=x*x2,xy=x*y2,xz=x*z2;var yy=y*y2,yz=y*z2,zz=z*z2;var wx=w*x2,wy=w*y2,wz=w*z2;var sx=scale.x,sy=scale.y,sz=scale.z;te[0]=(1-(yy+zz))*sx;te[1]=(xy+wz)*sx;te[2]=(xz-wy)*sx;te[3]=0;te[4]=(xy-wz)*sy;te[5]=(1-(xx+zz))*sy;te[6]=(yz+wx)*sy;te[7]=0;te[8]=(xz+wy)*sz;te[9]=(yz-wx)*sz;te[10]=(1-(xx+yy))*sz;te[11]=0;te[12]=position.x;te[13]=position.y;te[14]=position.z;te[15]=1;return this;}decompose(position,quaternion,scale){var te=this.elements;var sx=_v1$1.set(te[0],te[1],te[2]).length();var sy=_v1$1.set(te[4],te[5],te[6]).length();var sz=_v1$1.set(te[8],te[9],te[10]).length();// if determine is negative, we need to invert one scale
  184. var det=this.determinant();if(det<0)sx=-sx;position.x=te[12];position.y=te[13];position.z=te[14];// scale the rotation part
  185. _m1.copy(this);var invSX=1/sx;var invSY=1/sy;var invSZ=1/sz;_m1.elements[0]*=invSX;_m1.elements[1]*=invSX;_m1.elements[2]*=invSX;_m1.elements[4]*=invSY;_m1.elements[5]*=invSY;_m1.elements[6]*=invSY;_m1.elements[8]*=invSZ;_m1.elements[9]*=invSZ;_m1.elements[10]*=invSZ;quaternion.setFromRotationMatrix(_m1);scale.x=sx;scale.y=sy;scale.z=sz;return this;}makePerspective(left,right,top,bottom,near,far){if(far===undefined){console.warn('THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.');}var te=this.elements;var x=2*near/(right-left);var y=2*near/(top-bottom);var a=(right+left)/(right-left);var b=(top+bottom)/(top-bottom);var c=-(far+near)/(far-near);var d=-2*far*near/(far-near);te[0]=x;te[4]=0;te[8]=a;te[12]=0;te[1]=0;te[5]=y;te[9]=b;te[13]=0;te[2]=0;te[6]=0;te[10]=c;te[14]=d;te[3]=0;te[7]=0;te[11]=-1;te[15]=0;return this;}makeOrthographic(left,right,top,bottom,near,far){var te=this.elements;var w=1.0/(right-left);var h=1.0/(top-bottom);var p=1.0/(far-near);var x=(right+left)*w;var y=(top+bottom)*h;var z=(far+near)*p;te[0]=2*w;te[4]=0;te[8]=0;te[12]=-x;te[1]=0;te[5]=2*h;te[9]=0;te[13]=-y;te[2]=0;te[6]=0;te[10]=-2*p;te[14]=-z;te[3]=0;te[7]=0;te[11]=0;te[15]=1;return this;}equals(matrix){var te=this.elements;var me=matrix.elements;for(var _i10=0;_i10<16;_i10++){if(te[_i10]!==me[_i10])return false;}return true;}fromArray(array){var offset=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;for(var _i11=0;_i11<16;_i11++){this.elements[_i11]=array[_i11+offset];}return this;}toArray(){var array=arguments.length>0&&arguments[0]!==undefined?arguments[0]:[];var offset=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var te=this.elements;array[offset]=te[0];array[offset+1]=te[1];array[offset+2]=te[2];array[offset+3]=te[3];array[offset+4]=te[4];array[offset+5]=te[5];array[offset+6]=te[6];array[offset+7]=te[7];array[offset+8]=te[8];array[offset+9]=te[9];array[offset+10]=te[10];array[offset+11]=te[11];array[offset+12]=te[12];array[offset+13]=te[13];array[offset+14]=te[14];array[offset+15]=te[15];return array;}}var _v1$1=/*@__PURE__*/new Vector3();var _m1=/*@__PURE__*/new Matrix4();var _zero=/*@__PURE__*/new Vector3(0,0,0);var _one=/*@__PURE__*/new Vector3(1,1,1);var _x=/*@__PURE__*/new Vector3();var _y=/*@__PURE__*/new Vector3();var _z=/*@__PURE__*/new Vector3();class Euler{constructor(){var x=arguments.length>0&&arguments[0]!==undefined?arguments[0]:0;var y=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var z=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0;var order=arguments.length>3&&arguments[3]!==undefined?arguments[3]:Euler.DefaultOrder;Object.defineProperty(this,'isEuler',{value:true});this._x=x;this._y=y;this._z=z;this._order=order;}get x(){return this._x;}set x(value){this._x=value;this._onChangeCallback();}get y(){return this._y;}set y(value){this._y=value;this._onChangeCallback();}get z(){return this._z;}set z(value){this._z=value;this._onChangeCallback();}get order(){return this._order;}set order(value){this._order=value;this._onChangeCallback();}set(x,y,z,order){this._x=x;this._y=y;this._z=z;this._order=order||this._order;this._onChangeCallback();return this;}clone(){return new this.constructor(this._x,this._y,this._z,this._order);}copy(euler){this._x=euler._x;this._y=euler._y;this._z=euler._z;this._order=euler._order;this._onChangeCallback();return this;}setFromRotationMatrix(m,order,update){var clamp=MathUtils.clamp;// assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  186. var te=m.elements;var m11=te[0],m12=te[4],m13=te[8];var m21=te[1],m22=te[5],m23=te[9];var m31=te[2],m32=te[6],m33=te[10];order=order||this._order;switch(order){case'XYZ':this._y=Math.asin(clamp(m13,-1,1));if(Math.abs(m13)<0.9999999){this._x=Math.atan2(-m23,m33);this._z=Math.atan2(-m12,m11);}else {this._x=Math.atan2(m32,m22);this._z=0;}break;case'YXZ':this._x=Math.asin(-clamp(m23,-1,1));if(Math.abs(m23)<0.9999999){this._y=Math.atan2(m13,m33);this._z=Math.atan2(m21,m22);}else {this._y=Math.atan2(-m31,m11);this._z=0;}break;case'ZXY':this._x=Math.asin(clamp(m32,-1,1));if(Math.abs(m32)<0.9999999){this._y=Math.atan2(-m31,m33);this._z=Math.atan2(-m12,m22);}else {this._y=0;this._z=Math.atan2(m21,m11);}break;case'ZYX':this._y=Math.asin(-clamp(m31,-1,1));if(Math.abs(m31)<0.9999999){this._x=Math.atan2(m32,m33);this._z=Math.atan2(m21,m11);}else {this._x=0;this._z=Math.atan2(-m12,m22);}break;case'YZX':this._z=Math.asin(clamp(m21,-1,1));if(Math.abs(m21)<0.9999999){this._x=Math.atan2(-m23,m22);this._y=Math.atan2(-m31,m11);}else {this._x=0;this._y=Math.atan2(m13,m33);}break;case'XZY':this._z=Math.asin(-clamp(m12,-1,1));if(Math.abs(m12)<0.9999999){this._x=Math.atan2(m32,m22);this._y=Math.atan2(m13,m11);}else {this._x=Math.atan2(-m23,m33);this._y=0;}break;default:console.warn('THREE.Euler: .setFromRotationMatrix() encountered an unknown order: '+order);}this._order=order;if(update!==false)this._onChangeCallback();return this;}setFromQuaternion(q,order,update){_matrix.makeRotationFromQuaternion(q);return this.setFromRotationMatrix(_matrix,order,update);}setFromVector3(v,order){return this.set(v.x,v.y,v.z,order||this._order);}reorder(newOrder){// WARNING: this discards revolution information -bhouston
  187. _quaternion$1.setFromEuler(this);return this.setFromQuaternion(_quaternion$1,newOrder);}equals(euler){return euler._x===this._x&&euler._y===this._y&&euler._z===this._z&&euler._order===this._order;}fromArray(array){this._x=array[0];this._y=array[1];this._z=array[2];if(array[3]!==undefined)this._order=array[3];this._onChangeCallback();return this;}toArray(){var array=arguments.length>0&&arguments[0]!==undefined?arguments[0]:[];var offset=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;array[offset]=this._x;array[offset+1]=this._y;array[offset+2]=this._z;array[offset+3]=this._order;return array;}toVector3(optionalResult){if(optionalResult){return optionalResult.set(this._x,this._y,this._z);}else {return new Vector3(this._x,this._y,this._z);}}_onChange(callback){this._onChangeCallback=callback;return this;}_onChangeCallback(){}}Euler.DefaultOrder='XYZ';Euler.RotationOrders=['XYZ','YZX','ZXY','XZY','YXZ','ZYX'];var _matrix=/*@__PURE__*/new Matrix4();var _quaternion$1=/*@__PURE__*/new Quaternion();class Layers{constructor(){this.mask=1|0;}set(channel){this.mask=1<<channel|0;}enable(channel){this.mask|=1<<channel|0;}enableAll(){this.mask=0xffffffff|0;}toggle(channel){this.mask^=1<<channel|0;}disable(channel){this.mask&=~(1<<channel|0);}disableAll(){this.mask=0;}test(layers){return (this.mask&layers.mask)!==0;}}var _object3DId=0;var _v1$2=new Vector3();var _q1=new Quaternion();var _m1$1=new Matrix4();var _target=new Vector3();var _position=new Vector3();var _scale=new Vector3();var _quaternion$2=new Quaternion();var _xAxis=new Vector3(1,0,0);var _yAxis=new Vector3(0,1,0);var _zAxis=new Vector3(0,0,1);var _addedEvent={type:'added'};var _removedEvent={type:'removed'};function Object3D(){Object.defineProperty(this,'id',{value:_object3DId++});this.uuid=MathUtils.generateUUID();this.name='';this.type='Object3D';this.parent=null;this.children=[];this.up=Object3D.DefaultUp.clone();var position=new Vector3();var rotation=new Euler();var quaternion=new Quaternion();var scale=new Vector3(1,1,1);function onRotationChange(){quaternion.setFromEuler(rotation,false);}function onQuaternionChange(){rotation.setFromQuaternion(quaternion,undefined,false);}rotation._onChange(onRotationChange);quaternion._onChange(onQuaternionChange);Object.defineProperties(this,{position:{configurable:true,enumerable:true,value:position},rotation:{configurable:true,enumerable:true,value:rotation},quaternion:{configurable:true,enumerable:true,value:quaternion},scale:{configurable:true,enumerable:true,value:scale},modelViewMatrix:{value:new Matrix4()},normalMatrix:{value:new Matrix3()}});this.matrix=new Matrix4();this.matrixWorld=new Matrix4();this.matrixAutoUpdate=Object3D.DefaultMatrixAutoUpdate;this.matrixWorldNeedsUpdate=false;this.layers=new Layers();this.visible=true;this.castShadow=false;this.receiveShadow=false;this.frustumCulled=true;this.renderOrder=0;this.animations=[];this.userData={};}Object3D.DefaultUp=new Vector3(0,1,0);Object3D.DefaultMatrixAutoUpdate=true;Object3D.prototype=Object.assign(Object.create(EventDispatcher.prototype),{constructor:Object3D,isObject3D:true,onBeforeRender:function onBeforeRender(){},onAfterRender:function onAfterRender(){},applyMatrix4:function applyMatrix4(matrix){if(this.matrixAutoUpdate)this.updateMatrix();this.matrix.premultiply(matrix);this.matrix.decompose(this.position,this.quaternion,this.scale);},applyQuaternion:function applyQuaternion(q){this.quaternion.premultiply(q);return this;},setRotationFromAxisAngle:function setRotationFromAxisAngle(axis,angle){// assumes axis is normalized
  188. this.quaternion.setFromAxisAngle(axis,angle);},setRotationFromEuler:function setRotationFromEuler(euler){this.quaternion.setFromEuler(euler,true);},setRotationFromMatrix:function setRotationFromMatrix(m){// assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  189. this.quaternion.setFromRotationMatrix(m);},setRotationFromQuaternion:function setRotationFromQuaternion(q){// assumes q is normalized
  190. this.quaternion.copy(q);},rotateOnAxis:function rotateOnAxis(axis,angle){// rotate object on axis in object space
  191. // axis is assumed to be normalized
  192. _q1.setFromAxisAngle(axis,angle);this.quaternion.multiply(_q1);return this;},rotateOnWorldAxis:function rotateOnWorldAxis(axis,angle){// rotate object on axis in world space
  193. // axis is assumed to be normalized
  194. // method assumes no rotated parent
  195. _q1.setFromAxisAngle(axis,angle);this.quaternion.premultiply(_q1);return this;},rotateX:function rotateX(angle){return this.rotateOnAxis(_xAxis,angle);},rotateY:function rotateY(angle){return this.rotateOnAxis(_yAxis,angle);},rotateZ:function rotateZ(angle){return this.rotateOnAxis(_zAxis,angle);},translateOnAxis:function translateOnAxis(axis,distance){// translate object by distance along axis in object space
  196. // axis is assumed to be normalized
  197. _v1$2.copy(axis).applyQuaternion(this.quaternion);this.position.add(_v1$2.multiplyScalar(distance));return this;},translateX:function translateX(distance){return this.translateOnAxis(_xAxis,distance);},translateY:function translateY(distance){return this.translateOnAxis(_yAxis,distance);},translateZ:function translateZ(distance){return this.translateOnAxis(_zAxis,distance);},localToWorld:function localToWorld(vector){return vector.applyMatrix4(this.matrixWorld);},worldToLocal:function worldToLocal(vector){return vector.applyMatrix4(_m1$1.copy(this.matrixWorld).invert());},lookAt:function lookAt(x,y,z){// This method does not support objects having non-uniformly-scaled parent(s)
  198. if(x.isVector3){_target.copy(x);}else {_target.set(x,y,z);}var parent=this.parent;this.updateWorldMatrix(true,false);_position.setFromMatrixPosition(this.matrixWorld);if(this.isCamera||this.isLight){_m1$1.lookAt(_position,_target,this.up);}else {_m1$1.lookAt(_target,_position,this.up);}this.quaternion.setFromRotationMatrix(_m1$1);if(parent){_m1$1.extractRotation(parent.matrixWorld);_q1.setFromRotationMatrix(_m1$1);this.quaternion.premultiply(_q1.invert());}},add:function add(object){if(arguments.length>1){for(var _i12=0;_i12<arguments.length;_i12++){this.add(arguments[_i12]);}return this;}if(object===this){console.error('THREE.Object3D.add: object can\'t be added as a child of itself.',object);return this;}if(object&&object.isObject3D){if(object.parent!==null){object.parent.remove(object);}object.parent=this;this.children.push(object);object.dispatchEvent(_addedEvent);}else {console.error('THREE.Object3D.add: object not an instance of THREE.Object3D.',object);}return this;},remove:function remove(object){if(arguments.length>1){for(var _i13=0;_i13<arguments.length;_i13++){this.remove(arguments[_i13]);}return this;}var index=this.children.indexOf(object);if(index!==-1){object.parent=null;this.children.splice(index,1);object.dispatchEvent(_removedEvent);}return this;},clear:function clear(){for(var _i14=0;_i14<this.children.length;_i14++){var object=this.children[_i14];object.parent=null;object.dispatchEvent(_removedEvent);}this.children.length=0;return this;},attach:function attach(object){// adds object as a child of this, while maintaining the object's world transform
  199. this.updateWorldMatrix(true,false);_m1$1.copy(this.matrixWorld).invert();if(object.parent!==null){object.parent.updateWorldMatrix(true,false);_m1$1.multiply(object.parent.matrixWorld);}object.applyMatrix4(_m1$1);object.updateWorldMatrix(false,false);this.add(object);return this;},getObjectById:function getObjectById(id){return this.getObjectByProperty('id',id);},getObjectByName:function getObjectByName(name){return this.getObjectByProperty('name',name);},getObjectByProperty:function getObjectByProperty(name,value){if(this[name]===value)return this;for(var _i15=0,l=this.children.length;_i15<l;_i15++){var child=this.children[_i15];var object=child.getObjectByProperty(name,value);if(object!==undefined){return object;}}return undefined;},getWorldPosition:function getWorldPosition(target){if(target===undefined){console.warn('THREE.Object3D: .getWorldPosition() target is now required');target=new Vector3();}this.updateWorldMatrix(true,false);return target.setFromMatrixPosition(this.matrixWorld);},getWorldQuaternion:function getWorldQuaternion(target){if(target===undefined){console.warn('THREE.Object3D: .getWorldQuaternion() target is now required');target=new Quaternion();}this.updateWorldMatrix(true,false);this.matrixWorld.decompose(_position,target,_scale);return target;},getWorldScale:function getWorldScale(target){if(target===undefined){console.warn('THREE.Object3D: .getWorldScale() target is now required');target=new Vector3();}this.updateWorldMatrix(true,false);this.matrixWorld.decompose(_position,_quaternion$2,target);return target;},getWorldDirection:function getWorldDirection(target){if(target===undefined){console.warn('THREE.Object3D: .getWorldDirection() target is now required');target=new Vector3();}this.updateWorldMatrix(true,false);var e=this.matrixWorld.elements;return target.set(e[8],e[9],e[10]).normalize();},raycast:function raycast(){},traverse:function traverse(callback){callback(this);var children=this.children;for(var _i16=0,l=children.length;_i16<l;_i16++){children[_i16].traverse(callback);}},traverseVisible:function traverseVisible(callback){if(this.visible===false)return;callback(this);var children=this.children;for(var _i17=0,l=children.length;_i17<l;_i17++){children[_i17].traverseVisible(callback);}},traverseAncestors:function traverseAncestors(callback){var parent=this.parent;if(parent!==null){callback(parent);parent.traverseAncestors(callback);}},updateMatrix:function updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale);this.matrixWorldNeedsUpdate=true;},updateMatrixWorld:function updateMatrixWorld(force){if(this.matrixAutoUpdate)this.updateMatrix();if(this.matrixWorldNeedsUpdate||force){if(this.parent===null){this.matrixWorld.copy(this.matrix);}else {this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix);}this.matrixWorldNeedsUpdate=false;force=true;}// update children
  200. var children=this.children;for(var _i18=0,l=children.length;_i18<l;_i18++){children[_i18].updateMatrixWorld(force);}},updateWorldMatrix:function updateWorldMatrix(updateParents,updateChildren){var parent=this.parent;if(updateParents===true&&parent!==null){parent.updateWorldMatrix(true,false);}if(this.matrixAutoUpdate)this.updateMatrix();if(this.parent===null){this.matrixWorld.copy(this.matrix);}else {this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix);}// update children
  201. if(updateChildren===true){var children=this.children;for(var _i19=0,l=children.length;_i19<l;_i19++){children[_i19].updateWorldMatrix(false,true);}}},toJSON:function toJSON(meta){// meta is a string when called from JSON.stringify
  202. var isRootObject=meta===undefined||typeof meta==='string';var output={};// meta is a hash used to collect geometries, materials.
  203. // not providing it implies that this is the root object
  204. // being serialized.
  205. if(isRootObject){// initialize meta obj
  206. meta={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{}};output.metadata={version:4.5,type:'Object',generator:'Object3D.toJSON'};}// standard Object3D serialization
  207. var object={};object.uuid=this.uuid;object.type=this.type;if(this.name!=='')object.name=this.name;if(this.castShadow===true)object.castShadow=true;if(this.receiveShadow===true)object.receiveShadow=true;if(this.visible===false)object.visible=false;if(this.frustumCulled===false)object.frustumCulled=false;if(this.renderOrder!==0)object.renderOrder=this.renderOrder;if(JSON.stringify(this.userData)!=='{}')object.userData=this.userData;object.layers=this.layers.mask;object.matrix=this.matrix.toArray();if(this.matrixAutoUpdate===false)object.matrixAutoUpdate=false;// object specific properties
  208. if(this.isInstancedMesh){object.type='InstancedMesh';object.count=this.count;object.instanceMatrix=this.instanceMatrix.toJSON();}//
  209. function serialize(library,element){if(library[element.uuid]===undefined){library[element.uuid]=element.toJSON(meta);}return element.uuid;}if(this.isMesh||this.isLine||this.isPoints){object.geometry=serialize(meta.geometries,this.geometry);var parameters=this.geometry.parameters;if(parameters!==undefined&&parameters.shapes!==undefined){var shapes=parameters.shapes;if(Array.isArray(shapes)){for(var _i20=0,l=shapes.length;_i20<l;_i20++){var shape=shapes[_i20];serialize(meta.shapes,shape);}}else {serialize(meta.shapes,shapes);}}}if(this.isSkinnedMesh){object.bindMode=this.bindMode;object.bindMatrix=this.bindMatrix.toArray();if(this.skeleton!==undefined){serialize(meta.skeletons,this.skeleton);object.skeleton=this.skeleton.uuid;}}if(this.material!==undefined){if(Array.isArray(this.material)){var uuids=[];for(var _i21=0,_l=this.material.length;_i21<_l;_i21++){uuids.push(serialize(meta.materials,this.material[_i21]));}object.material=uuids;}else {object.material=serialize(meta.materials,this.material);}}//
  210. if(this.children.length>0){object.children=[];for(var _i22=0;_i22<this.children.length;_i22++){object.children.push(this.children[_i22].toJSON(meta).object);}}//
  211. if(this.animations.length>0){object.animations=[];for(var _i23=0;_i23<this.animations.length;_i23++){var animation=this.animations[_i23];object.animations.push(serialize(meta.animations,animation));}}if(isRootObject){var geometries=extractFromCache(meta.geometries);var materials=extractFromCache(meta.materials);var textures=extractFromCache(meta.textures);var images=extractFromCache(meta.images);var _shapes=extractFromCache(meta.shapes);var skeletons=extractFromCache(meta.skeletons);var animations=extractFromCache(meta.animations);if(geometries.length>0)output.geometries=geometries;if(materials.length>0)output.materials=materials;if(textures.length>0)output.textures=textures;if(images.length>0)output.images=images;if(_shapes.length>0)output.shapes=_shapes;if(skeletons.length>0)output.skeletons=skeletons;if(animations.length>0)output.animations=animations;}output.object=object;return output;// extract data from the cache hash
  212. // remove metadata on each item
  213. // and return as array
  214. function extractFromCache(cache){var values=[];for(var key in cache){var data=cache[key];delete data.metadata;values.push(data);}return values;}},clone:function clone(recursive){return new this.constructor().copy(this,recursive);},copy:function copy(source){var recursive=arguments.length>1&&arguments[1]!==undefined?arguments[1]:true;this.name=source.name;this.up.copy(source.up);this.position.copy(source.position);this.rotation.order=source.rotation.order;this.quaternion.copy(source.quaternion);this.scale.copy(source.scale);this.matrix.copy(source.matrix);this.matrixWorld.copy(source.matrixWorld);this.matrixAutoUpdate=source.matrixAutoUpdate;this.matrixWorldNeedsUpdate=source.matrixWorldNeedsUpdate;this.layers.mask=source.layers.mask;this.visible=source.visible;this.castShadow=source.castShadow;this.receiveShadow=source.receiveShadow;this.frustumCulled=source.frustumCulled;this.renderOrder=source.renderOrder;this.userData=JSON.parse(JSON.stringify(source.userData));if(recursive===true){for(var _i24=0;_i24<source.children.length;_i24++){var child=source.children[_i24];this.add(child.clone());}}return this;}});var _vector1=/*@__PURE__*/new Vector3();var _vector2=/*@__PURE__*/new Vector3();var _normalMatrix=/*@__PURE__*/new Matrix3();class Plane{constructor(normal,constant){Object.defineProperty(this,'isPlane',{value:true});// normal is assumed to be normalized
  215. this.normal=normal!==undefined?normal:new Vector3(1,0,0);this.constant=constant!==undefined?constant:0;}set(normal,constant){this.normal.copy(normal);this.constant=constant;return this;}setComponents(x,y,z,w){this.normal.set(x,y,z);this.constant=w;return this;}setFromNormalAndCoplanarPoint(normal,point){this.normal.copy(normal);this.constant=-point.dot(this.normal);return this;}setFromCoplanarPoints(a,b,c){var normal=_vector1.subVectors(c,b).cross(_vector2.subVectors(a,b)).normalize();// Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  216. this.setFromNormalAndCoplanarPoint(normal,a);return this;}clone(){return new this.constructor().copy(this);}copy(plane){this.normal.copy(plane.normal);this.constant=plane.constant;return this;}normalize(){// Note: will lead to a divide by zero if the plane is invalid.
  217. var inverseNormalLength=1.0/this.normal.length();this.normal.multiplyScalar(inverseNormalLength);this.constant*=inverseNormalLength;return this;}negate(){this.constant*=-1;this.normal.negate();return this;}distanceToPoint(point){return this.normal.dot(point)+this.constant;}distanceToSphere(sphere){return this.distanceToPoint(sphere.center)-sphere.radius;}projectPoint(point,target){if(target===undefined){console.warn('THREE.Plane: .projectPoint() target is now required');target=new Vector3();}return target.copy(this.normal).multiplyScalar(-this.distanceToPoint(point)).add(point);}intersectLine(line,target){if(target===undefined){console.warn('THREE.Plane: .intersectLine() target is now required');target=new Vector3();}var direction=line.delta(_vector1);var denominator=this.normal.dot(direction);if(denominator===0){// line is coplanar, return origin
  218. if(this.distanceToPoint(line.start)===0){return target.copy(line.start);}// Unsure if this is the correct method to handle this case.
  219. return undefined;}var t=-(line.start.dot(this.normal)+this.constant)/denominator;if(t<0||t>1){return undefined;}return target.copy(direction).multiplyScalar(t).add(line.start);}intersectsLine(line){// Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  220. var startSign=this.distanceToPoint(line.start);var endSign=this.distanceToPoint(line.end);return startSign<0&&endSign>0||endSign<0&&startSign>0;}intersectsBox(box){return box.intersectsPlane(this);}intersectsSphere(sphere){return sphere.intersectsPlane(this);}coplanarPoint(target){if(target===undefined){console.warn('THREE.Plane: .coplanarPoint() target is now required');target=new Vector3();}return target.copy(this.normal).multiplyScalar(-this.constant);}applyMatrix4(matrix,optionalNormalMatrix){var normalMatrix=optionalNormalMatrix||_normalMatrix.getNormalMatrix(matrix);var referencePoint=this.coplanarPoint(_vector1).applyMatrix4(matrix);var normal=this.normal.applyMatrix3(normalMatrix).normalize();this.constant=-referencePoint.dot(normal);return this;}translate(offset){this.constant-=offset.dot(this.normal);return this;}equals(plane){return plane.normal.equals(this.normal)&&plane.constant===this.constant;}}var _v0$1=/*@__PURE__*/new Vector3();var _v1$3=/*@__PURE__*/new Vector3();var _v2$1=/*@__PURE__*/new Vector3();var _v3=/*@__PURE__*/new Vector3();var _vab=/*@__PURE__*/new Vector3();var _vac=/*@__PURE__*/new Vector3();var _vbc=/*@__PURE__*/new Vector3();var _vap=/*@__PURE__*/new Vector3();var _vbp=/*@__PURE__*/new Vector3();var _vcp=/*@__PURE__*/new Vector3();class Triangle{constructor(a,b,c){this.a=a!==undefined?a:new Vector3();this.b=b!==undefined?b:new Vector3();this.c=c!==undefined?c:new Vector3();}static getNormal(a,b,c,target){if(target===undefined){console.warn('THREE.Triangle: .getNormal() target is now required');target=new Vector3();}target.subVectors(c,b);_v0$1.subVectors(a,b);target.cross(_v0$1);var targetLengthSq=target.lengthSq();if(targetLengthSq>0){return target.multiplyScalar(1/Math.sqrt(targetLengthSq));}return target.set(0,0,0);}// static/instance method to calculate barycentric coordinates
  221. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  222. static getBarycoord(point,a,b,c,target){_v0$1.subVectors(c,a);_v1$3.subVectors(b,a);_v2$1.subVectors(point,a);var dot00=_v0$1.dot(_v0$1);var dot01=_v0$1.dot(_v1$3);var dot02=_v0$1.dot(_v2$1);var dot11=_v1$3.dot(_v1$3);var dot12=_v1$3.dot(_v2$1);var denom=dot00*dot11-dot01*dot01;if(target===undefined){console.warn('THREE.Triangle: .getBarycoord() target is now required');target=new Vector3();}// collinear or singular triangle
  223. if(denom===0){// arbitrary location outside of triangle?
  224. // not sure if this is the best idea, maybe should be returning undefined
  225. return target.set(-2,-1,-1);}var invDenom=1/denom;var u=(dot11*dot02-dot01*dot12)*invDenom;var v=(dot00*dot12-dot01*dot02)*invDenom;// barycentric coordinates must always sum to 1
  226. return target.set(1-u-v,v,u);}static containsPoint(point,a,b,c){this.getBarycoord(point,a,b,c,_v3);return _v3.x>=0&&_v3.y>=0&&_v3.x+_v3.y<=1;}static getUV(point,p1,p2,p3,uv1,uv2,uv3,target){this.getBarycoord(point,p1,p2,p3,_v3);target.set(0,0);target.addScaledVector(uv1,_v3.x);target.addScaledVector(uv2,_v3.y);target.addScaledVector(uv3,_v3.z);return target;}static isFrontFacing(a,b,c,direction){_v0$1.subVectors(c,b);_v1$3.subVectors(a,b);// strictly front facing
  227. return _v0$1.cross(_v1$3).dot(direction)<0?true:false;}set(a,b,c){this.a.copy(a);this.b.copy(b);this.c.copy(c);return this;}setFromPointsAndIndices(points,i0,i1,i2){this.a.copy(points[i0]);this.b.copy(points[i1]);this.c.copy(points[i2]);return this;}clone(){return new this.constructor().copy(this);}copy(triangle){this.a.copy(triangle.a);this.b.copy(triangle.b);this.c.copy(triangle.c);return this;}getArea(){_v0$1.subVectors(this.c,this.b);_v1$3.subVectors(this.a,this.b);return _v0$1.cross(_v1$3).length()*0.5;}getMidpoint(target){if(target===undefined){console.warn('THREE.Triangle: .getMidpoint() target is now required');target=new Vector3();}return target.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3);}getNormal(target){return Triangle.getNormal(this.a,this.b,this.c,target);}getPlane(target){if(target===undefined){console.warn('THREE.Triangle: .getPlane() target is now required');target=new Plane();}return target.setFromCoplanarPoints(this.a,this.b,this.c);}getBarycoord(point,target){return Triangle.getBarycoord(point,this.a,this.b,this.c,target);}getUV(point,uv1,uv2,uv3,target){return Triangle.getUV(point,this.a,this.b,this.c,uv1,uv2,uv3,target);}containsPoint(point){return Triangle.containsPoint(point,this.a,this.b,this.c);}isFrontFacing(direction){return Triangle.isFrontFacing(this.a,this.b,this.c,direction);}intersectsBox(box){return box.intersectsTriangle(this);}closestPointToPoint(p,target){if(target===undefined){console.warn('THREE.Triangle: .closestPointToPoint() target is now required');target=new Vector3();}var a=this.a,b=this.b,c=this.c;var v,w;// algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  228. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  229. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  230. // basically, we're distinguishing which of the voronoi regions of the triangle
  231. // the point lies in with the minimum amount of redundant computation.
  232. _vab.subVectors(b,a);_vac.subVectors(c,a);_vap.subVectors(p,a);var d1=_vab.dot(_vap);var d2=_vac.dot(_vap);if(d1<=0&&d2<=0){// vertex region of A; barycentric coords (1, 0, 0)
  233. return target.copy(a);}_vbp.subVectors(p,b);var d3=_vab.dot(_vbp);var d4=_vac.dot(_vbp);if(d3>=0&&d4<=d3){// vertex region of B; barycentric coords (0, 1, 0)
  234. return target.copy(b);}var vc=d1*d4-d3*d2;if(vc<=0&&d1>=0&&d3<=0){v=d1/(d1-d3);// edge region of AB; barycentric coords (1-v, v, 0)
  235. return target.copy(a).addScaledVector(_vab,v);}_vcp.subVectors(p,c);var d5=_vab.dot(_vcp);var d6=_vac.dot(_vcp);if(d6>=0&&d5<=d6){// vertex region of C; barycentric coords (0, 0, 1)
  236. return target.copy(c);}var vb=d5*d2-d1*d6;if(vb<=0&&d2>=0&&d6<=0){w=d2/(d2-d6);// edge region of AC; barycentric coords (1-w, 0, w)
  237. return target.copy(a).addScaledVector(_vac,w);}var va=d3*d6-d5*d4;if(va<=0&&d4-d3>=0&&d5-d6>=0){_vbc.subVectors(c,b);w=(d4-d3)/(d4-d3+(d5-d6));// edge region of BC; barycentric coords (0, 1-w, w)
  238. return target.copy(b).addScaledVector(_vbc,w);// edge region of BC
  239. }// face region
  240. var denom=1/(va+vb+vc);// u = va * denom
  241. v=vb*denom;w=vc*denom;return target.copy(a).addScaledVector(_vab,v).addScaledVector(_vac,w);}equals(triangle){return triangle.a.equals(this.a)&&triangle.b.equals(this.b)&&triangle.c.equals(this.c);}}var _colorKeywords={'aliceblue':0xF0F8FF,'antiquewhite':0xFAEBD7,'aqua':0x00FFFF,'aquamarine':0x7FFFD4,'azure':0xF0FFFF,'beige':0xF5F5DC,'bisque':0xFFE4C4,'black':0x000000,'blanchedalmond':0xFFEBCD,'blue':0x0000FF,'blueviolet':0x8A2BE2,'brown':0xA52A2A,'burlywood':0xDEB887,'cadetblue':0x5F9EA0,'chartreuse':0x7FFF00,'chocolate':0xD2691E,'coral':0xFF7F50,'cornflowerblue':0x6495ED,'cornsilk':0xFFF8DC,'crimson':0xDC143C,'cyan':0x00FFFF,'darkblue':0x00008B,'darkcyan':0x008B8B,'darkgoldenrod':0xB8860B,'darkgray':0xA9A9A9,'darkgreen':0x006400,'darkgrey':0xA9A9A9,'darkkhaki':0xBDB76B,'darkmagenta':0x8B008B,'darkolivegreen':0x556B2F,'darkorange':0xFF8C00,'darkorchid':0x9932CC,'darkred':0x8B0000,'darksalmon':0xE9967A,'darkseagreen':0x8FBC8F,'darkslateblue':0x483D8B,'darkslategray':0x2F4F4F,'darkslategrey':0x2F4F4F,'darkturquoise':0x00CED1,'darkviolet':0x9400D3,'deeppink':0xFF1493,'deepskyblue':0x00BFFF,'dimgray':0x696969,'dimgrey':0x696969,'dodgerblue':0x1E90FF,'firebrick':0xB22222,'floralwhite':0xFFFAF0,'forestgreen':0x228B22,'fuchsia':0xFF00FF,'gainsboro':0xDCDCDC,'ghostwhite':0xF8F8FF,'gold':0xFFD700,'goldenrod':0xDAA520,'gray':0x808080,'green':0x008000,'greenyellow':0xADFF2F,'grey':0x808080,'honeydew':0xF0FFF0,'hotpink':0xFF69B4,'indianred':0xCD5C5C,'indigo':0x4B0082,'ivory':0xFFFFF0,'khaki':0xF0E68C,'lavender':0xE6E6FA,'lavenderblush':0xFFF0F5,'lawngreen':0x7CFC00,'lemonchiffon':0xFFFACD,'lightblue':0xADD8E6,'lightcoral':0xF08080,'lightcyan':0xE0FFFF,'lightgoldenrodyellow':0xFAFAD2,'lightgray':0xD3D3D3,'lightgreen':0x90EE90,'lightgrey':0xD3D3D3,'lightpink':0xFFB6C1,'lightsalmon':0xFFA07A,'lightseagreen':0x20B2AA,'lightskyblue':0x87CEFA,'lightslategray':0x778899,'lightslategrey':0x778899,'lightsteelblue':0xB0C4DE,'lightyellow':0xFFFFE0,'lime':0x00FF00,'limegreen':0x32CD32,'linen':0xFAF0E6,'magenta':0xFF00FF,'maroon':0x800000,'mediumaquamarine':0x66CDAA,'mediumblue':0x0000CD,'mediumorchid':0xBA55D3,'mediumpurple':0x9370DB,'mediumseagreen':0x3CB371,'mediumslateblue':0x7B68EE,'mediumspringgreen':0x00FA9A,'mediumturquoise':0x48D1CC,'mediumvioletred':0xC71585,'midnightblue':0x191970,'mintcream':0xF5FFFA,'mistyrose':0xFFE4E1,'moccasin':0xFFE4B5,'navajowhite':0xFFDEAD,'navy':0x000080,'oldlace':0xFDF5E6,'olive':0x808000,'olivedrab':0x6B8E23,'orange':0xFFA500,'orangered':0xFF4500,'orchid':0xDA70D6,'palegoldenrod':0xEEE8AA,'palegreen':0x98FB98,'paleturquoise':0xAFEEEE,'palevioletred':0xDB7093,'papayawhip':0xFFEFD5,'peachpuff':0xFFDAB9,'peru':0xCD853F,'pink':0xFFC0CB,'plum':0xDDA0DD,'powderblue':0xB0E0E6,'purple':0x800080,'rebeccapurple':0x663399,'red':0xFF0000,'rosybrown':0xBC8F8F,'royalblue':0x4169E1,'saddlebrown':0x8B4513,'salmon':0xFA8072,'sandybrown':0xF4A460,'seagreen':0x2E8B57,'seashell':0xFFF5EE,'sienna':0xA0522D,'silver':0xC0C0C0,'skyblue':0x87CEEB,'slateblue':0x6A5ACD,'slategray':0x708090,'slategrey':0x708090,'snow':0xFFFAFA,'springgreen':0x00FF7F,'steelblue':0x4682B4,'tan':0xD2B48C,'teal':0x008080,'thistle':0xD8BFD8,'tomato':0xFF6347,'turquoise':0x40E0D0,'violet':0xEE82EE,'wheat':0xF5DEB3,'white':0xFFFFFF,'whitesmoke':0xF5F5F5,'yellow':0xFFFF00,'yellowgreen':0x9ACD32};var _hslA={h:0,s:0,l:0};var _hslB={h:0,s:0,l:0};function hue2rgb(p,q,t){if(t<0)t+=1;if(t>1)t-=1;if(t<1/6)return p+(q-p)*6*t;if(t<1/2)return q;if(t<2/3)return p+(q-p)*6*(2/3-t);return p;}function SRGBToLinear(c){return c<0.04045?c*0.0773993808:Math.pow(c*0.9478672986+0.0521327014,2.4);}function LinearToSRGB(c){return c<0.0031308?c*12.92:1.055*Math.pow(c,0.41666)-0.055;}class Color{constructor(r,g,b){Object.defineProperty(this,'isColor',{value:true});if(g===undefined&&b===undefined){// r is THREE.Color, hex or string
  242. return this.set(r);}return this.setRGB(r,g,b);}set(value){if(value&&value.isColor){this.copy(value);}else if(typeof value==='number'){this.setHex(value);}else if(typeof value==='string'){this.setStyle(value);}return this;}setScalar(scalar){this.r=scalar;this.g=scalar;this.b=scalar;return this;}setHex(hex){hex=Math.floor(hex);this.r=(hex>>16&255)/255;this.g=(hex>>8&255)/255;this.b=(hex&255)/255;return this;}setRGB(r,g,b){this.r=r;this.g=g;this.b=b;return this;}setHSL(h,s,l){// h,s,l ranges are in 0.0 - 1.0
  243. h=MathUtils.euclideanModulo(h,1);s=MathUtils.clamp(s,0,1);l=MathUtils.clamp(l,0,1);if(s===0){this.r=this.g=this.b=l;}else {var p=l<=0.5?l*(1+s):l+s-l*s;var q=2*l-p;this.r=hue2rgb(q,p,h+1/3);this.g=hue2rgb(q,p,h);this.b=hue2rgb(q,p,h-1/3);}return this;}setStyle(style){function handleAlpha(string){if(string===undefined)return;if(parseFloat(string)<1){console.warn('THREE.Color: Alpha component of '+style+' will be ignored.');}}var m;if(m=/^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec(style)){// rgb / hsl
  244. var color;var name=m[1];var components=m[2];switch(name){case'rgb':case'rgba':if(color=/^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)){// rgb(255,0,0) rgba(255,0,0,0.5)
  245. this.r=Math.min(255,parseInt(color[1],10))/255;this.g=Math.min(255,parseInt(color[2],10))/255;this.b=Math.min(255,parseInt(color[3],10))/255;handleAlpha(color[4]);return this;}if(color=/^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)){// rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  246. this.r=Math.min(100,parseInt(color[1],10))/100;this.g=Math.min(100,parseInt(color[2],10))/100;this.b=Math.min(100,parseInt(color[3],10))/100;handleAlpha(color[4]);return this;}break;case'hsl':case'hsla':if(color=/^(\d*\.?\d+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)){// hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  247. var h=parseFloat(color[1])/360;var s=parseInt(color[2],10)/100;var l=parseInt(color[3],10)/100;handleAlpha(color[4]);return this.setHSL(h,s,l);}break;}}else if(m=/^\#([A-Fa-f\d]+)$/.exec(style)){// hex color
  248. var hex=m[1];var size=hex.length;if(size===3){// #ff0
  249. this.r=parseInt(hex.charAt(0)+hex.charAt(0),16)/255;this.g=parseInt(hex.charAt(1)+hex.charAt(1),16)/255;this.b=parseInt(hex.charAt(2)+hex.charAt(2),16)/255;return this;}else if(size===6){// #ff0000
  250. this.r=parseInt(hex.charAt(0)+hex.charAt(1),16)/255;this.g=parseInt(hex.charAt(2)+hex.charAt(3),16)/255;this.b=parseInt(hex.charAt(4)+hex.charAt(5),16)/255;return this;}}if(style&&style.length>0){return this.setColorName(style);}return this;}setColorName(style){// color keywords
  251. var hex=_colorKeywords[style];if(hex!==undefined){// red
  252. this.setHex(hex);}else {// unknown color
  253. console.warn('THREE.Color: Unknown color '+style);}return this;}clone(){return new this.constructor(this.r,this.g,this.b);}copy(color){this.r=color.r;this.g=color.g;this.b=color.b;return this;}copyGammaToLinear(color){var gammaFactor=arguments.length>1&&arguments[1]!==undefined?arguments[1]:2.0;this.r=Math.pow(color.r,gammaFactor);this.g=Math.pow(color.g,gammaFactor);this.b=Math.pow(color.b,gammaFactor);return this;}copyLinearToGamma(color){var gammaFactor=arguments.length>1&&arguments[1]!==undefined?arguments[1]:2.0;var safeInverse=gammaFactor>0?1.0/gammaFactor:1.0;this.r=Math.pow(color.r,safeInverse);this.g=Math.pow(color.g,safeInverse);this.b=Math.pow(color.b,safeInverse);return this;}convertGammaToLinear(gammaFactor){this.copyGammaToLinear(this,gammaFactor);return this;}convertLinearToGamma(gammaFactor){this.copyLinearToGamma(this,gammaFactor);return this;}copySRGBToLinear(color){this.r=SRGBToLinear(color.r);this.g=SRGBToLinear(color.g);this.b=SRGBToLinear(color.b);return this;}copyLinearToSRGB(color){this.r=LinearToSRGB(color.r);this.g=LinearToSRGB(color.g);this.b=LinearToSRGB(color.b);return this;}convertSRGBToLinear(){this.copySRGBToLinear(this);return this;}convertLinearToSRGB(){this.copyLinearToSRGB(this);return this;}getHex(){return this.r*255<<16^this.g*255<<8^this.b*255<<0;}getHexString(){return ('000000'+this.getHex().toString(16)).slice(-6);}getHSL(target){// h,s,l ranges are in 0.0 - 1.0
  254. if(target===undefined){console.warn('THREE.Color: .getHSL() target is now required');target={h:0,s:0,l:0};}var r=this.r,g=this.g,b=this.b;var max=Math.max(r,g,b);var min=Math.min(r,g,b);var hue,saturation;var lightness=(min+max)/2.0;if(min===max){hue=0;saturation=0;}else {var delta=max-min;saturation=lightness<=0.5?delta/(max+min):delta/(2-max-min);switch(max){case r:hue=(g-b)/delta+(g<b?6:0);break;case g:hue=(b-r)/delta+2;break;case b:hue=(r-g)/delta+4;break;}hue/=6;}target.h=hue;target.s=saturation;target.l=lightness;return target;}getStyle(){return 'rgb('+(this.r*255|0)+','+(this.g*255|0)+','+(this.b*255|0)+')';}offsetHSL(h,s,l){this.getHSL(_hslA);_hslA.h+=h;_hslA.s+=s;_hslA.l+=l;this.setHSL(_hslA.h,_hslA.s,_hslA.l);return this;}add(color){this.r+=color.r;this.g+=color.g;this.b+=color.b;return this;}addColors(color1,color2){this.r=color1.r+color2.r;this.g=color1.g+color2.g;this.b=color1.b+color2.b;return this;}addScalar(s){this.r+=s;this.g+=s;this.b+=s;return this;}sub(color){this.r=Math.max(0,this.r-color.r);this.g=Math.max(0,this.g-color.g);this.b=Math.max(0,this.b-color.b);return this;}multiply(color){this.r*=color.r;this.g*=color.g;this.b*=color.b;return this;}multiplyScalar(s){this.r*=s;this.g*=s;this.b*=s;return this;}lerp(color,alpha){this.r+=(color.r-this.r)*alpha;this.g+=(color.g-this.g)*alpha;this.b+=(color.b-this.b)*alpha;return this;}lerpHSL(color,alpha){this.getHSL(_hslA);color.getHSL(_hslB);var h=MathUtils.lerp(_hslA.h,_hslB.h,alpha);var s=MathUtils.lerp(_hslA.s,_hslB.s,alpha);var l=MathUtils.lerp(_hslA.l,_hslB.l,alpha);this.setHSL(h,s,l);return this;}equals(c){return c.r===this.r&&c.g===this.g&&c.b===this.b;}fromArray(array){var offset=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;this.r=array[offset];this.g=array[offset+1];this.b=array[offset+2];return this;}toArray(){var array=arguments.length>0&&arguments[0]!==undefined?arguments[0]:[];var offset=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;array[offset]=this.r;array[offset+1]=this.g;array[offset+2]=this.b;return array;}fromBufferAttribute(attribute,index){this.r=attribute.getX(index);this.g=attribute.getY(index);this.b=attribute.getZ(index);if(attribute.normalized===true){// assuming Uint8Array
  255. this.r/=255;this.g/=255;this.b/=255;}return this;}toJSON(){return this.getHex();}}Color.NAMES=_colorKeywords;Color.prototype.r=1;Color.prototype.g=1;Color.prototype.b=1;class Face3{constructor(a,b,c,normal,color){var materialIndex=arguments.length>5&&arguments[5]!==undefined?arguments[5]:0;this.a=a;this.b=b;this.c=c;this.normal=normal&&normal.isVector3?normal:new Vector3();this.vertexNormals=Array.isArray(normal)?normal:[];this.color=color&&color.isColor?color:new Color();this.vertexColors=Array.isArray(color)?color:[];this.materialIndex=materialIndex;}clone(){return new this.constructor().copy(this);}copy(source){this.a=source.a;this.b=source.b;this.c=source.c;this.normal.copy(source.normal);this.color.copy(source.color);this.materialIndex=source.materialIndex;for(var _i25=0,il=source.vertexNormals.length;_i25<il;_i25++){this.vertexNormals[_i25]=source.vertexNormals[_i25].clone();}for(var _i26=0,_il=source.vertexColors.length;_i26<_il;_i26++){this.vertexColors[_i26]=source.vertexColors[_i26].clone();}return this;}}var materialId=0;function Material(){Object.defineProperty(this,'id',{value:materialId++});this.uuid=MathUtils.generateUUID();this.name='';this.type='Material';this.fog=true;this.blending=NormalBlending;this.side=FrontSide;this.flatShading=false;this.vertexColors=false;this.opacity=1;this.transparent=false;this.blendSrc=SrcAlphaFactor;this.blendDst=OneMinusSrcAlphaFactor;this.blendEquation=AddEquation;this.blendSrcAlpha=null;this.blendDstAlpha=null;this.blendEquationAlpha=null;this.depthFunc=LessEqualDepth;this.depthTest=true;this.depthWrite=true;this.stencilWriteMask=0xff;this.stencilFunc=AlwaysStencilFunc;this.stencilRef=0;this.stencilFuncMask=0xff;this.stencilFail=KeepStencilOp;this.stencilZFail=KeepStencilOp;this.stencilZPass=KeepStencilOp;this.stencilWrite=false;this.clippingPlanes=null;this.clipIntersection=false;this.clipShadows=false;this.shadowSide=null;this.colorWrite=true;this.precision=null;// override the renderer's default precision for this material
  256. this.polygonOffset=false;this.polygonOffsetFactor=0;this.polygonOffsetUnits=0;this.dithering=false;this.alphaTest=0;this.premultipliedAlpha=false;this.visible=true;this.toneMapped=true;this.userData={};this.version=0;}Material.prototype=Object.assign(Object.create(EventDispatcher.prototype),{constructor:Material,isMaterial:true,onBeforeCompile:function onBeforeCompile(/* shaderobject, renderer */){},customProgramCacheKey:function customProgramCacheKey(){return this.onBeforeCompile.toString();},setValues:function setValues(values){if(values===undefined)return;for(var key in values){var newValue=values[key];if(newValue===undefined){console.warn('THREE.Material: \''+key+'\' parameter is undefined.');continue;}// for backward compatability if shading is set in the constructor
  257. if(key==='shading'){console.warn('THREE.'+this.type+': .shading has been removed. Use the boolean .flatShading instead.');this.flatShading=newValue===FlatShading$1?true:false;continue;}var currentValue=this[key];if(currentValue===undefined){//console.warn( 'THREE.' + this.type + ': \'' + key + '\' is not a property of this material.' );
  258. continue;}if(currentValue&&currentValue.isColor){currentValue.set(newValue);}else if(currentValue&&currentValue.isVector3&&newValue&&newValue.isVector3){currentValue.copy(newValue);}else {this[key]=newValue;}}},toJSON:function toJSON(meta){var isRoot=meta===undefined||typeof meta==='string';if(isRoot){meta={textures:{},images:{}};}var data={metadata:{version:4.5,type:'Material',generator:'Material.toJSON'}};// standard Material serialization
  259. data.uuid=this.uuid;data.type=this.type;if(this.name!=='')data.name=this.name;if(this.color&&this.color.isColor)data.color=this.color.getHex();if(this.roughness!==undefined)data.roughness=this.roughness;if(this.metalness!==undefined)data.metalness=this.metalness;if(this.sheen&&this.sheen.isColor)data.sheen=this.sheen.getHex();if(this.emissive&&this.emissive.isColor)data.emissive=this.emissive.getHex();if(this.emissiveIntensity&&this.emissiveIntensity!==1)data.emissiveIntensity=this.emissiveIntensity;if(this.specular&&this.specular.isColor)data.specular=this.specular.getHex();if(this.shininess!==undefined)data.shininess=this.shininess;if(this.clearcoat!==undefined)data.clearcoat=this.clearcoat;if(this.clearcoatRoughness!==undefined)data.clearcoatRoughness=this.clearcoatRoughness;if(this.clearcoatMap&&this.clearcoatMap.isTexture){data.clearcoatMap=this.clearcoatMap.toJSON(meta).uuid;}if(this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture){data.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(meta).uuid;}if(this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture){data.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(meta).uuid;data.clearcoatNormalScale=this.clearcoatNormalScale.toArray();}if(this.map&&this.map.isTexture)data.map=this.map.toJSON(meta).uuid;if(this.matcap&&this.matcap.isTexture)data.matcap=this.matcap.toJSON(meta).uuid;if(this.alphaMap&&this.alphaMap.isTexture)data.alphaMap=this.alphaMap.toJSON(meta).uuid;if(this.lightMap&&this.lightMap.isTexture)data.lightMap=this.lightMap.toJSON(meta).uuid;if(this.aoMap&&this.aoMap.isTexture){data.aoMap=this.aoMap.toJSON(meta).uuid;data.aoMapIntensity=this.aoMapIntensity;}if(this.bumpMap&&this.bumpMap.isTexture){data.bumpMap=this.bumpMap.toJSON(meta).uuid;data.bumpScale=this.bumpScale;}if(this.normalMap&&this.normalMap.isTexture){data.normalMap=this.normalMap.toJSON(meta).uuid;data.normalMapType=this.normalMapType;data.normalScale=this.normalScale.toArray();}if(this.displacementMap&&this.displacementMap.isTexture){data.displacementMap=this.displacementMap.toJSON(meta).uuid;data.displacementScale=this.displacementScale;data.displacementBias=this.displacementBias;}if(this.roughnessMap&&this.roughnessMap.isTexture)data.roughnessMap=this.roughnessMap.toJSON(meta).uuid;if(this.metalnessMap&&this.metalnessMap.isTexture)data.metalnessMap=this.metalnessMap.toJSON(meta).uuid;if(this.emissiveMap&&this.emissiveMap.isTexture)data.emissiveMap=this.emissiveMap.toJSON(meta).uuid;if(this.specularMap&&this.specularMap.isTexture)data.specularMap=this.specularMap.toJSON(meta).uuid;if(this.envMap&&this.envMap.isTexture){data.envMap=this.envMap.toJSON(meta).uuid;data.reflectivity=this.reflectivity;// Scale behind envMap
  260. data.refractionRatio=this.refractionRatio;if(this.combine!==undefined)data.combine=this.combine;if(this.envMapIntensity!==undefined)data.envMapIntensity=this.envMapIntensity;}if(this.gradientMap&&this.gradientMap.isTexture){data.gradientMap=this.gradientMap.toJSON(meta).uuid;}if(this.size!==undefined)data.size=this.size;if(this.sizeAttenuation!==undefined)data.sizeAttenuation=this.sizeAttenuation;if(this.blending!==NormalBlending)data.blending=this.blending;if(this.flatShading===true)data.flatShading=this.flatShading;if(this.side!==FrontSide)data.side=this.side;if(this.vertexColors)data.vertexColors=true;if(this.opacity<1)data.opacity=this.opacity;if(this.transparent===true)data.transparent=this.transparent;data.depthFunc=this.depthFunc;data.depthTest=this.depthTest;data.depthWrite=this.depthWrite;data.stencilWrite=this.stencilWrite;data.stencilWriteMask=this.stencilWriteMask;data.stencilFunc=this.stencilFunc;data.stencilRef=this.stencilRef;data.stencilFuncMask=this.stencilFuncMask;data.stencilFail=this.stencilFail;data.stencilZFail=this.stencilZFail;data.stencilZPass=this.stencilZPass;// rotation (SpriteMaterial)
  261. if(this.rotation&&this.rotation!==0)data.rotation=this.rotation;if(this.polygonOffset===true)data.polygonOffset=true;if(this.polygonOffsetFactor!==0)data.polygonOffsetFactor=this.polygonOffsetFactor;if(this.polygonOffsetUnits!==0)data.polygonOffsetUnits=this.polygonOffsetUnits;if(this.linewidth&&this.linewidth!==1)data.linewidth=this.linewidth;if(this.dashSize!==undefined)data.dashSize=this.dashSize;if(this.gapSize!==undefined)data.gapSize=this.gapSize;if(this.scale!==undefined)data.scale=this.scale;if(this.dithering===true)data.dithering=true;if(this.alphaTest>0)data.alphaTest=this.alphaTest;if(this.premultipliedAlpha===true)data.premultipliedAlpha=this.premultipliedAlpha;if(this.wireframe===true)data.wireframe=this.wireframe;if(this.wireframeLinewidth>1)data.wireframeLinewidth=this.wireframeLinewidth;if(this.wireframeLinecap!=='round')data.wireframeLinecap=this.wireframeLinecap;if(this.wireframeLinejoin!=='round')data.wireframeLinejoin=this.wireframeLinejoin;if(this.morphTargets===true)data.morphTargets=true;if(this.morphNormals===true)data.morphNormals=true;if(this.skinning===true)data.skinning=true;if(this.visible===false)data.visible=false;if(this.toneMapped===false)data.toneMapped=false;if(JSON.stringify(this.userData)!=='{}')data.userData=this.userData;// TODO: Copied from Object3D.toJSON
  262. function extractFromCache(cache){var values=[];for(var key in cache){var _data=cache[key];delete _data.metadata;values.push(_data);}return values;}if(isRoot){var textures=extractFromCache(meta.textures);var images=extractFromCache(meta.images);if(textures.length>0)data.textures=textures;if(images.length>0)data.images=images;}return data;},clone:function clone(){return new this.constructor().copy(this);},copy:function copy(source){this.name=source.name;this.fog=source.fog;this.blending=source.blending;this.side=source.side;this.flatShading=source.flatShading;this.vertexColors=source.vertexColors;this.opacity=source.opacity;this.transparent=source.transparent;this.blendSrc=source.blendSrc;this.blendDst=source.blendDst;this.blendEquation=source.blendEquation;this.blendSrcAlpha=source.blendSrcAlpha;this.blendDstAlpha=source.blendDstAlpha;this.blendEquationAlpha=source.blendEquationAlpha;this.depthFunc=source.depthFunc;this.depthTest=source.depthTest;this.depthWrite=source.depthWrite;this.stencilWriteMask=source.stencilWriteMask;this.stencilFunc=source.stencilFunc;this.stencilRef=source.stencilRef;this.stencilFuncMask=source.stencilFuncMask;this.stencilFail=source.stencilFail;this.stencilZFail=source.stencilZFail;this.stencilZPass=source.stencilZPass;this.stencilWrite=source.stencilWrite;var srcPlanes=source.clippingPlanes;var dstPlanes=null;if(srcPlanes!==null){var n=srcPlanes.length;dstPlanes=new Array(n);for(var _i27=0;_i27!==n;++_i27){dstPlanes[_i27]=srcPlanes[_i27].clone();}}this.clippingPlanes=dstPlanes;this.clipIntersection=source.clipIntersection;this.clipShadows=source.clipShadows;this.shadowSide=source.shadowSide;this.colorWrite=source.colorWrite;this.precision=source.precision;this.polygonOffset=source.polygonOffset;this.polygonOffsetFactor=source.polygonOffsetFactor;this.polygonOffsetUnits=source.polygonOffsetUnits;this.dithering=source.dithering;this.alphaTest=source.alphaTest;this.premultipliedAlpha=source.premultipliedAlpha;this.visible=source.visible;this.toneMapped=source.toneMapped;this.userData=JSON.parse(JSON.stringify(source.userData));return this;},dispose:function dispose(){this.dispatchEvent({type:'dispose'});}});Object.defineProperty(Material.prototype,'needsUpdate',{set:function set(value){if(value===true)this.version++;}});/**
  263. * parameters = {
  264. * color: <hex>,
  265. * opacity: <float>,
  266. * map: new THREE.Texture( <Image> ),
  267. *
  268. * lightMap: new THREE.Texture( <Image> ),
  269. * lightMapIntensity: <float>
  270. *
  271. * aoMap: new THREE.Texture( <Image> ),
  272. * aoMapIntensity: <float>
  273. *
  274. * specularMap: new THREE.Texture( <Image> ),
  275. *
  276. * alphaMap: new THREE.Texture( <Image> ),
  277. *
  278. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  279. * combine: THREE.Multiply,
  280. * reflectivity: <float>,
  281. * refractionRatio: <float>,
  282. *
  283. * depthTest: <bool>,
  284. * depthWrite: <bool>,
  285. *
  286. * wireframe: <boolean>,
  287. * wireframeLinewidth: <float>,
  288. *
  289. * skinning: <bool>,
  290. * morphTargets: <bool>
  291. * }
  292. */function MeshBasicMaterial(parameters){Material.call(this);this.type='MeshBasicMaterial';this.color=new Color(0xffffff);// emissive
  293. this.map=null;this.lightMap=null;this.lightMapIntensity=1.0;this.aoMap=null;this.aoMapIntensity=1.0;this.specularMap=null;this.alphaMap=null;this.envMap=null;this.combine=MultiplyOperation;this.reflectivity=1;this.refractionRatio=0.98;this.wireframe=false;this.wireframeLinewidth=1;this.wireframeLinecap='round';this.wireframeLinejoin='round';this.skinning=false;this.morphTargets=false;this.setValues(parameters);}MeshBasicMaterial.prototype=Object.create(Material.prototype);MeshBasicMaterial.prototype.constructor=MeshBasicMaterial;MeshBasicMaterial.prototype.isMeshBasicMaterial=true;MeshBasicMaterial.prototype.copy=function(source){Material.prototype.copy.call(this,source);this.color.copy(source.color);this.map=source.map;this.lightMap=source.lightMap;this.lightMapIntensity=source.lightMapIntensity;this.aoMap=source.aoMap;this.aoMapIntensity=source.aoMapIntensity;this.specularMap=source.specularMap;this.alphaMap=source.alphaMap;this.envMap=source.envMap;this.combine=source.combine;this.reflectivity=source.reflectivity;this.refractionRatio=source.refractionRatio;this.wireframe=source.wireframe;this.wireframeLinewidth=source.wireframeLinewidth;this.wireframeLinecap=source.wireframeLinecap;this.wireframeLinejoin=source.wireframeLinejoin;this.skinning=source.skinning;this.morphTargets=source.morphTargets;return this;};var _vector$3=new Vector3();var _vector2$1=new Vector2();function BufferAttribute(array,itemSize,normalized){if(Array.isArray(array)){throw new TypeError('THREE.BufferAttribute: array should be a Typed Array.');}this.name='';this.array=array;this.itemSize=itemSize;this.count=array!==undefined?array.length/itemSize:0;this.normalized=normalized===true;this.usage=StaticDrawUsage;this.updateRange={offset:0,count:-1};this.version=0;}Object.defineProperty(BufferAttribute.prototype,'needsUpdate',{set:function set(value){if(value===true)this.version++;}});Object.assign(BufferAttribute.prototype,{isBufferAttribute:true,onUploadCallback:function onUploadCallback(){},setUsage:function setUsage(value){this.usage=value;return this;},copy:function copy(source){this.name=source.name;this.array=new source.array.constructor(source.array);this.itemSize=source.itemSize;this.count=source.count;this.normalized=source.normalized;this.usage=source.usage;return this;},copyAt:function copyAt(index1,attribute,index2){index1*=this.itemSize;index2*=attribute.itemSize;for(var _i28=0,l=this.itemSize;_i28<l;_i28++){this.array[index1+_i28]=attribute.array[index2+_i28];}return this;},copyArray:function copyArray(array){this.array.set(array);return this;},copyColorsArray:function copyColorsArray(colors){var array=this.array;var offset=0;for(var _i29=0,l=colors.length;_i29<l;_i29++){var color=colors[_i29];if(color===undefined){console.warn('THREE.BufferAttribute.copyColorsArray(): color is undefined',_i29);color=new Color();}array[offset++]=color.r;array[offset++]=color.g;array[offset++]=color.b;}return this;},copyVector2sArray:function copyVector2sArray(vectors){var array=this.array;var offset=0;for(var _i30=0,l=vectors.length;_i30<l;_i30++){var vector=vectors[_i30];if(vector===undefined){console.warn('THREE.BufferAttribute.copyVector2sArray(): vector is undefined',_i30);vector=new Vector2();}array[offset++]=vector.x;array[offset++]=vector.y;}return this;},copyVector3sArray:function copyVector3sArray(vectors){var array=this.array;var offset=0;for(var _i31=0,l=vectors.length;_i31<l;_i31++){var vector=vectors[_i31];if(vector===undefined){console.warn('THREE.BufferAttribute.copyVector3sArray(): vector is undefined',_i31);vector=new Vector3();}array[offset++]=vector.x;array[offset++]=vector.y;array[offset++]=vector.z;}return this;},copyVector4sArray:function copyVector4sArray(vectors){var array=this.array;var offset=0;for(var _i32=0,l=vectors.length;_i32<l;_i32++){var vector=vectors[_i32];if(vector===undefined){console.warn('THREE.BufferAttribute.copyVector4sArray(): vector is undefined',_i32);vector=new Vector4();}array[offset++]=vector.x;array[offset++]=vector.y;array[offset++]=vector.z;array[offset++]=vector.w;}return this;},applyMatrix3:function applyMatrix3(m){if(this.itemSize===2){for(var _i33=0,l=this.count;_i33<l;_i33++){_vector2$1.fromBufferAttribute(this,_i33);_vector2$1.applyMatrix3(m);this.setXY(_i33,_vector2$1.x,_vector2$1.y);}}else if(this.itemSize===3){for(var _i34=0,_l2=this.count;_i34<_l2;_i34++){_vector$3.fromBufferAttribute(this,_i34);_vector$3.applyMatrix3(m);this.setXYZ(_i34,_vector$3.x,_vector$3.y,_vector$3.z);}}return this;},applyMatrix4:function applyMatrix4(m){for(var _i35=0,l=this.count;_i35<l;_i35++){_vector$3.x=this.getX(_i35);_vector$3.y=this.getY(_i35);_vector$3.z=this.getZ(_i35);_vector$3.applyMatrix4(m);this.setXYZ(_i35,_vector$3.x,_vector$3.y,_vector$3.z);}return this;},applyNormalMatrix:function applyNormalMatrix(m){for(var _i36=0,l=this.count;_i36<l;_i36++){_vector$3.x=this.getX(_i36);_vector$3.y=this.getY(_i36);_vector$3.z=this.getZ(_i36);_vector$3.applyNormalMatrix(m);this.setXYZ(_i36,_vector$3.x,_vector$3.y,_vector$3.z);}return this;},transformDirection:function transformDirection(m){for(var _i37=0,l=this.count;_i37<l;_i37++){_vector$3.x=this.getX(_i37);_vector$3.y=this.getY(_i37);_vector$3.z=this.getZ(_i37);_vector$3.transformDirection(m);this.setXYZ(_i37,_vector$3.x,_vector$3.y,_vector$3.z);}return this;},set:function set(value){var offset=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;this.array.set(value,offset);return this;},getX:function getX(index){return this.array[index*this.itemSize];},setX:function setX(index,x){this.array[index*this.itemSize]=x;return this;},getY:function getY(index){return this.array[index*this.itemSize+1];},setY:function setY(index,y){this.array[index*this.itemSize+1]=y;return this;},getZ:function getZ(index){return this.array[index*this.itemSize+2];},setZ:function setZ(index,z){this.array[index*this.itemSize+2]=z;return this;},getW:function getW(index){return this.array[index*this.itemSize+3];},setW:function setW(index,w){this.array[index*this.itemSize+3]=w;return this;},setXY:function setXY(index,x,y){index*=this.itemSize;this.array[index+0]=x;this.array[index+1]=y;return this;},setXYZ:function setXYZ(index,x,y,z){index*=this.itemSize;this.array[index+0]=x;this.array[index+1]=y;this.array[index+2]=z;return this;},setXYZW:function setXYZW(index,x,y,z,w){index*=this.itemSize;this.array[index+0]=x;this.array[index+1]=y;this.array[index+2]=z;this.array[index+3]=w;return this;},onUpload:function onUpload(callback){this.onUploadCallback=callback;return this;},clone:function clone(){return new this.constructor(this.array,this.itemSize).copy(this);},toJSON:function toJSON(){return {itemSize:this.itemSize,type:this.array.constructor.name,array:Array.prototype.slice.call(this.array),normalized:this.normalized};}});//
  294. function Int8BufferAttribute(array,itemSize,normalized){BufferAttribute.call(this,new Int8Array(array),itemSize,normalized);}Int8BufferAttribute.prototype=Object.create(BufferAttribute.prototype);Int8BufferAttribute.prototype.constructor=Int8BufferAttribute;function Uint8BufferAttribute(array,itemSize,normalized){BufferAttribute.call(this,new Uint8Array(array),itemSize,normalized);}Uint8BufferAttribute.prototype=Object.create(BufferAttribute.prototype);Uint8BufferAttribute.prototype.constructor=Uint8BufferAttribute;function Uint8ClampedBufferAttribute(array,itemSize,normalized){BufferAttribute.call(this,new Uint8ClampedArray(array),itemSize,normalized);}Uint8ClampedBufferAttribute.prototype=Object.create(BufferAttribute.prototype);Uint8ClampedBufferAttribute.prototype.constructor=Uint8ClampedBufferAttribute;function Int16BufferAttribute(array,itemSize,normalized){BufferAttribute.call(this,new Int16Array(array),itemSize,normalized);}Int16BufferAttribute.prototype=Object.create(BufferAttribute.prototype);Int16BufferAttribute.prototype.constructor=Int16BufferAttribute;function Uint16BufferAttribute(array,itemSize,normalized){BufferAttribute.call(this,new Uint16Array(array),itemSize,normalized);}Uint16BufferAttribute.prototype=Object.create(BufferAttribute.prototype);Uint16BufferAttribute.prototype.constructor=Uint16BufferAttribute;function Int32BufferAttribute(array,itemSize,normalized){BufferAttribute.call(this,new Int32Array(array),itemSize,normalized);}Int32BufferAttribute.prototype=Object.create(BufferAttribute.prototype);Int32BufferAttribute.prototype.constructor=Int32BufferAttribute;function Uint32BufferAttribute(array,itemSize,normalized){BufferAttribute.call(this,new Uint32Array(array),itemSize,normalized);}Uint32BufferAttribute.prototype=Object.create(BufferAttribute.prototype);Uint32BufferAttribute.prototype.constructor=Uint32BufferAttribute;function Float16BufferAttribute(array,itemSize,normalized){BufferAttribute.call(this,new Uint16Array(array),itemSize,normalized);}Float16BufferAttribute.prototype=Object.create(BufferAttribute.prototype);Float16BufferAttribute.prototype.constructor=Float16BufferAttribute;Float16BufferAttribute.prototype.isFloat16BufferAttribute=true;function Float32BufferAttribute(array,itemSize,normalized){BufferAttribute.call(this,new Float32Array(array),itemSize,normalized);}Float32BufferAttribute.prototype=Object.create(BufferAttribute.prototype);Float32BufferAttribute.prototype.constructor=Float32BufferAttribute;function Float64BufferAttribute(array,itemSize,normalized){BufferAttribute.call(this,new Float64Array(array),itemSize,normalized);}Float64BufferAttribute.prototype=Object.create(BufferAttribute.prototype);Float64BufferAttribute.prototype.constructor=Float64BufferAttribute;class DirectGeometry{constructor(){this.vertices=[];this.normals=[];this.colors=[];this.uvs=[];this.uvs2=[];this.groups=[];this.morphTargets={};this.skinWeights=[];this.skinIndices=[];// this.lineDistances = [];
  295. this.boundingBox=null;this.boundingSphere=null;// update flags
  296. this.verticesNeedUpdate=false;this.normalsNeedUpdate=false;this.colorsNeedUpdate=false;this.uvsNeedUpdate=false;this.groupsNeedUpdate=false;}computeGroups(geometry){var groups=[];var group,i;var materialIndex=undefined;var faces=geometry.faces;for(i=0;i<faces.length;i++){var face=faces[i];// materials
  297. if(face.materialIndex!==materialIndex){materialIndex=face.materialIndex;if(group!==undefined){group.count=i*3-group.start;groups.push(group);}group={start:i*3,materialIndex:materialIndex};}}if(group!==undefined){group.count=i*3-group.start;groups.push(group);}this.groups=groups;}fromGeometry(geometry){var faces=geometry.faces;var vertices=geometry.vertices;var faceVertexUvs=geometry.faceVertexUvs;var hasFaceVertexUv=faceVertexUvs[0]&&faceVertexUvs[0].length>0;var hasFaceVertexUv2=faceVertexUvs[1]&&faceVertexUvs[1].length>0;// morphs
  298. var morphTargets=geometry.morphTargets;var morphTargetsLength=morphTargets.length;var morphTargetsPosition;if(morphTargetsLength>0){morphTargetsPosition=[];for(var _i38=0;_i38<morphTargetsLength;_i38++){morphTargetsPosition[_i38]={name:morphTargets[_i38].name,data:[]};}this.morphTargets.position=morphTargetsPosition;}var morphNormals=geometry.morphNormals;var morphNormalsLength=morphNormals.length;var morphTargetsNormal;if(morphNormalsLength>0){morphTargetsNormal=[];for(var _i39=0;_i39<morphNormalsLength;_i39++){morphTargetsNormal[_i39]={name:morphNormals[_i39].name,data:[]};}this.morphTargets.normal=morphTargetsNormal;}// skins
  299. var skinIndices=geometry.skinIndices;var skinWeights=geometry.skinWeights;var hasSkinIndices=skinIndices.length===vertices.length;var hasSkinWeights=skinWeights.length===vertices.length;//
  300. if(vertices.length>0&&faces.length===0){console.error('THREE.DirectGeometry: Faceless geometries are not supported.');}for(var _i40=0;_i40<faces.length;_i40++){var face=faces[_i40];this.vertices.push(vertices[face.a],vertices[face.b],vertices[face.c]);var vertexNormals=face.vertexNormals;if(vertexNormals.length===3){this.normals.push(vertexNormals[0],vertexNormals[1],vertexNormals[2]);}else {var normal=face.normal;this.normals.push(normal,normal,normal);}var vertexColors=face.vertexColors;if(vertexColors.length===3){this.colors.push(vertexColors[0],vertexColors[1],vertexColors[2]);}else {var color=face.color;this.colors.push(color,color,color);}if(hasFaceVertexUv===true){var vertexUvs=faceVertexUvs[0][_i40];if(vertexUvs!==undefined){this.uvs.push(vertexUvs[0],vertexUvs[1],vertexUvs[2]);}else {console.warn('THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ',_i40);this.uvs.push(new Vector2(),new Vector2(),new Vector2());}}if(hasFaceVertexUv2===true){var _vertexUvs=faceVertexUvs[1][_i40];if(_vertexUvs!==undefined){this.uvs2.push(_vertexUvs[0],_vertexUvs[1],_vertexUvs[2]);}else {console.warn('THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ',_i40);this.uvs2.push(new Vector2(),new Vector2(),new Vector2());}}// morphs
  301. for(var j=0;j<morphTargetsLength;j++){var morphTarget=morphTargets[j].vertices;morphTargetsPosition[j].data.push(morphTarget[face.a],morphTarget[face.b],morphTarget[face.c]);}for(var _j=0;_j<morphNormalsLength;_j++){var morphNormal=morphNormals[_j].vertexNormals[_i40];morphTargetsNormal[_j].data.push(morphNormal.a,morphNormal.b,morphNormal.c);}// skins
  302. if(hasSkinIndices){this.skinIndices.push(skinIndices[face.a],skinIndices[face.b],skinIndices[face.c]);}if(hasSkinWeights){this.skinWeights.push(skinWeights[face.a],skinWeights[face.b],skinWeights[face.c]);}}this.computeGroups(geometry);this.verticesNeedUpdate=geometry.verticesNeedUpdate;this.normalsNeedUpdate=geometry.normalsNeedUpdate;this.colorsNeedUpdate=geometry.colorsNeedUpdate;this.uvsNeedUpdate=geometry.uvsNeedUpdate;this.groupsNeedUpdate=geometry.groupsNeedUpdate;if(geometry.boundingSphere!==null){this.boundingSphere=geometry.boundingSphere.clone();}if(geometry.boundingBox!==null){this.boundingBox=geometry.boundingBox.clone();}return this;}}function arrayMax(array){if(array.length===0)return -Infinity;var max=array[0];for(var _i41=1,l=array.length;_i41<l;++_i41){if(array[_i41]>max)max=array[_i41];}return max;}var TYPED_ARRAYS={Int8Array:Int8Array,Uint8Array:Uint8Array,// Workaround for IE11 pre KB2929437. See #11440
  303. Uint8ClampedArray:typeof Uint8ClampedArray!=='undefined'?Uint8ClampedArray:Uint8Array,Int16Array:Int16Array,Uint16Array:Uint16Array,Int32Array:Int32Array,Uint32Array:Uint32Array,Float32Array:Float32Array,Float64Array:Float64Array};function getTypedArray(type,buffer){return new TYPED_ARRAYS[type](buffer);}var _bufferGeometryId=1;// BufferGeometry uses odd numbers as Id
  304. var _m1$2=new Matrix4();var _obj=new Object3D();var _offset=new Vector3();var _box$2=new Box3();var _boxMorphTargets=new Box3();var _vector$4=new Vector3();function BufferGeometry(){Object.defineProperty(this,'id',{value:_bufferGeometryId+=2});this.uuid=MathUtils.generateUUID();this.name='';this.type='BufferGeometry';this.index=null;this.attributes={};this.morphAttributes={};this.morphTargetsRelative=false;this.groups=[];this.boundingBox=null;this.boundingSphere=null;this.drawRange={start:0,count:Infinity};this.userData={};}BufferGeometry.prototype=Object.assign(Object.create(EventDispatcher.prototype),{constructor:BufferGeometry,isBufferGeometry:true,getIndex:function getIndex(){return this.index;},setIndex:function setIndex(index){if(Array.isArray(index)){this.index=new(arrayMax(index)>65535?Uint32BufferAttribute:Uint16BufferAttribute)(index,1);}else {this.index=index;}return this;},getAttribute:function getAttribute(name){return this.attributes[name];},setAttribute:function setAttribute(name,attribute){this.attributes[name]=attribute;return this;},deleteAttribute:function deleteAttribute(name){delete this.attributes[name];return this;},hasAttribute:function hasAttribute(name){return this.attributes[name]!==undefined;},addGroup:function addGroup(start,count){var materialIndex=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0;this.groups.push({start:start,count:count,materialIndex:materialIndex});},clearGroups:function clearGroups(){this.groups=[];},setDrawRange:function setDrawRange(start,count){this.drawRange.start=start;this.drawRange.count=count;},applyMatrix4:function applyMatrix4(matrix){var position=this.attributes.position;if(position!==undefined){position.applyMatrix4(matrix);position.needsUpdate=true;}var normal=this.attributes.normal;if(normal!==undefined){var normalMatrix=new Matrix3().getNormalMatrix(matrix);normal.applyNormalMatrix(normalMatrix);normal.needsUpdate=true;}var tangent=this.attributes.tangent;if(tangent!==undefined){tangent.transformDirection(matrix);tangent.needsUpdate=true;}if(this.boundingBox!==null){this.computeBoundingBox();}if(this.boundingSphere!==null){this.computeBoundingSphere();}return this;},rotateX:function rotateX(angle){// rotate geometry around world x-axis
  305. _m1$2.makeRotationX(angle);this.applyMatrix4(_m1$2);return this;},rotateY:function rotateY(angle){// rotate geometry around world y-axis
  306. _m1$2.makeRotationY(angle);this.applyMatrix4(_m1$2);return this;},rotateZ:function rotateZ(angle){// rotate geometry around world z-axis
  307. _m1$2.makeRotationZ(angle);this.applyMatrix4(_m1$2);return this;},translate:function translate(x,y,z){// translate geometry
  308. _m1$2.makeTranslation(x,y,z);this.applyMatrix4(_m1$2);return this;},scale:function scale(x,y,z){// scale geometry
  309. _m1$2.makeScale(x,y,z);this.applyMatrix4(_m1$2);return this;},lookAt:function lookAt(vector){_obj.lookAt(vector);_obj.updateMatrix();this.applyMatrix4(_obj.matrix);return this;},center:function center(){this.computeBoundingBox();this.boundingBox.getCenter(_offset).negate();this.translate(_offset.x,_offset.y,_offset.z);return this;},setFromObject:function setFromObject(object){// console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  310. var geometry=object.geometry;if(object.isPoints||object.isLine){var positions=new Float32BufferAttribute(geometry.vertices.length*3,3);var colors=new Float32BufferAttribute(geometry.colors.length*3,3);this.setAttribute('position',positions.copyVector3sArray(geometry.vertices));this.setAttribute('color',colors.copyColorsArray(geometry.colors));if(geometry.lineDistances&&geometry.lineDistances.length===geometry.vertices.length){var lineDistances=new Float32BufferAttribute(geometry.lineDistances.length,1);this.setAttribute('lineDistance',lineDistances.copyArray(geometry.lineDistances));}if(geometry.boundingSphere!==null){this.boundingSphere=geometry.boundingSphere.clone();}if(geometry.boundingBox!==null){this.boundingBox=geometry.boundingBox.clone();}}else if(object.isMesh){if(geometry&&geometry.isGeometry){this.fromGeometry(geometry);}}return this;},setFromPoints:function setFromPoints(points){var position=[];for(var _i42=0,l=points.length;_i42<l;_i42++){var point=points[_i42];position.push(point.x,point.y,point.z||0);}this.setAttribute('position',new Float32BufferAttribute(position,3));return this;},updateFromObject:function updateFromObject(object){var geometry=object.geometry;if(object.isMesh){var direct=geometry.__directGeometry;if(geometry.elementsNeedUpdate===true){direct=undefined;geometry.elementsNeedUpdate=false;}if(direct===undefined){return this.fromGeometry(geometry);}direct.verticesNeedUpdate=geometry.verticesNeedUpdate;direct.normalsNeedUpdate=geometry.normalsNeedUpdate;direct.colorsNeedUpdate=geometry.colorsNeedUpdate;direct.uvsNeedUpdate=geometry.uvsNeedUpdate;direct.groupsNeedUpdate=geometry.groupsNeedUpdate;geometry.verticesNeedUpdate=false;geometry.normalsNeedUpdate=false;geometry.colorsNeedUpdate=false;geometry.uvsNeedUpdate=false;geometry.groupsNeedUpdate=false;geometry=direct;}if(geometry.verticesNeedUpdate===true){var attribute=this.attributes.position;if(attribute!==undefined){attribute.copyVector3sArray(geometry.vertices);attribute.needsUpdate=true;}geometry.verticesNeedUpdate=false;}if(geometry.normalsNeedUpdate===true){var _attribute=this.attributes.normal;if(_attribute!==undefined){_attribute.copyVector3sArray(geometry.normals);_attribute.needsUpdate=true;}geometry.normalsNeedUpdate=false;}if(geometry.colorsNeedUpdate===true){var _attribute2=this.attributes.color;if(_attribute2!==undefined){_attribute2.copyColorsArray(geometry.colors);_attribute2.needsUpdate=true;}geometry.colorsNeedUpdate=false;}if(geometry.uvsNeedUpdate){var _attribute3=this.attributes.uv;if(_attribute3!==undefined){_attribute3.copyVector2sArray(geometry.uvs);_attribute3.needsUpdate=true;}geometry.uvsNeedUpdate=false;}if(geometry.lineDistancesNeedUpdate){var _attribute4=this.attributes.lineDistance;if(_attribute4!==undefined){_attribute4.copyArray(geometry.lineDistances);_attribute4.needsUpdate=true;}geometry.lineDistancesNeedUpdate=false;}if(geometry.groupsNeedUpdate){geometry.computeGroups(object.geometry);this.groups=geometry.groups;geometry.groupsNeedUpdate=false;}return this;},fromGeometry:function fromGeometry(geometry){geometry.__directGeometry=new DirectGeometry().fromGeometry(geometry);return this.fromDirectGeometry(geometry.__directGeometry);},fromDirectGeometry:function fromDirectGeometry(geometry){var positions=new Float32Array(geometry.vertices.length*3);this.setAttribute('position',new BufferAttribute(positions,3).copyVector3sArray(geometry.vertices));if(geometry.normals.length>0){var normals=new Float32Array(geometry.normals.length*3);this.setAttribute('normal',new BufferAttribute(normals,3).copyVector3sArray(geometry.normals));}if(geometry.colors.length>0){var colors=new Float32Array(geometry.colors.length*3);this.setAttribute('color',new BufferAttribute(colors,3).copyColorsArray(geometry.colors));}if(geometry.uvs.length>0){var uvs=new Float32Array(geometry.uvs.length*2);this.setAttribute('uv',new BufferAttribute(uvs,2).copyVector2sArray(geometry.uvs));}if(geometry.uvs2.length>0){var uvs2=new Float32Array(geometry.uvs2.length*2);this.setAttribute('uv2',new BufferAttribute(uvs2,2).copyVector2sArray(geometry.uvs2));}// groups
  311. this.groups=geometry.groups;// morphs
  312. for(var name in geometry.morphTargets){var array=[];var morphTargets=geometry.morphTargets[name];for(var _i43=0,l=morphTargets.length;_i43<l;_i43++){var morphTarget=morphTargets[_i43];var attribute=new Float32BufferAttribute(morphTarget.data.length*3,3);attribute.name=morphTarget.name;array.push(attribute.copyVector3sArray(morphTarget.data));}this.morphAttributes[name]=array;}// skinning
  313. if(geometry.skinIndices.length>0){var skinIndices=new Float32BufferAttribute(geometry.skinIndices.length*4,4);this.setAttribute('skinIndex',skinIndices.copyVector4sArray(geometry.skinIndices));}if(geometry.skinWeights.length>0){var skinWeights=new Float32BufferAttribute(geometry.skinWeights.length*4,4);this.setAttribute('skinWeight',skinWeights.copyVector4sArray(geometry.skinWeights));}//
  314. if(geometry.boundingSphere!==null){this.boundingSphere=geometry.boundingSphere.clone();}if(geometry.boundingBox!==null){this.boundingBox=geometry.boundingBox.clone();}return this;},computeBoundingBox:function computeBoundingBox(){if(this.boundingBox===null){this.boundingBox=new Box3();}var position=this.attributes.position;var morphAttributesPosition=this.morphAttributes.position;if(position&&position.isGLBufferAttribute){console.error('THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box. Alternatively set "mesh.frustumCulled" to "false".',this);this.boundingBox.set(new Vector3(-Infinity,-Infinity,-Infinity),new Vector3(+Infinity,+Infinity,+Infinity));return;}if(position!==undefined){this.boundingBox.setFromBufferAttribute(position);// process morph attributes if present
  315. if(morphAttributesPosition){for(var _i44=0,il=morphAttributesPosition.length;_i44<il;_i44++){var morphAttribute=morphAttributesPosition[_i44];_box$2.setFromBufferAttribute(morphAttribute);if(this.morphTargetsRelative){_vector$4.addVectors(this.boundingBox.min,_box$2.min);this.boundingBox.expandByPoint(_vector$4);_vector$4.addVectors(this.boundingBox.max,_box$2.max);this.boundingBox.expandByPoint(_vector$4);}else {this.boundingBox.expandByPoint(_box$2.min);this.boundingBox.expandByPoint(_box$2.max);}}}}else {this.boundingBox.makeEmpty();}if(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z)){console.error('THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.',this);}},computeBoundingSphere:function computeBoundingSphere(){if(this.boundingSphere===null){this.boundingSphere=new Sphere();}var position=this.attributes.position;var morphAttributesPosition=this.morphAttributes.position;if(position&&position.isGLBufferAttribute){console.error('THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere. Alternatively set "mesh.frustumCulled" to "false".',this);this.boundingSphere.set(new Vector3(),Infinity);return;}if(position){// first, find the center of the bounding sphere
  316. var center=this.boundingSphere.center;_box$2.setFromBufferAttribute(position);// process morph attributes if present
  317. if(morphAttributesPosition){for(var _i45=0,il=morphAttributesPosition.length;_i45<il;_i45++){var morphAttribute=morphAttributesPosition[_i45];_boxMorphTargets.setFromBufferAttribute(morphAttribute);if(this.morphTargetsRelative){_vector$4.addVectors(_box$2.min,_boxMorphTargets.min);_box$2.expandByPoint(_vector$4);_vector$4.addVectors(_box$2.max,_boxMorphTargets.max);_box$2.expandByPoint(_vector$4);}else {_box$2.expandByPoint(_boxMorphTargets.min);_box$2.expandByPoint(_boxMorphTargets.max);}}}_box$2.getCenter(center);// second, try to find a boundingSphere with a radius smaller than the
  318. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  319. var maxRadiusSq=0;for(var _i46=0,_il2=position.count;_i46<_il2;_i46++){_vector$4.fromBufferAttribute(position,_i46);maxRadiusSq=Math.max(maxRadiusSq,center.distanceToSquared(_vector$4));}// process morph attributes if present
  320. if(morphAttributesPosition){for(var _i47=0,_il3=morphAttributesPosition.length;_i47<_il3;_i47++){var _morphAttribute=morphAttributesPosition[_i47];var morphTargetsRelative=this.morphTargetsRelative;for(var j=0,jl=_morphAttribute.count;j<jl;j++){_vector$4.fromBufferAttribute(_morphAttribute,j);if(morphTargetsRelative){_offset.fromBufferAttribute(position,j);_vector$4.add(_offset);}maxRadiusSq=Math.max(maxRadiusSq,center.distanceToSquared(_vector$4));}}}this.boundingSphere.radius=Math.sqrt(maxRadiusSq);if(isNaN(this.boundingSphere.radius)){console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this);}}},computeFaceNormals:function computeFaceNormals(){// backwards compatibility
  321. },computeVertexNormals:function computeVertexNormals(){var index=this.index;var positionAttribute=this.getAttribute('position');if(positionAttribute!==undefined){var normalAttribute=this.getAttribute('normal');if(normalAttribute===undefined){normalAttribute=new BufferAttribute(new Float32Array(positionAttribute.count*3),3);this.setAttribute('normal',normalAttribute);}else {// reset existing normals to zero
  322. for(var _i48=0,il=normalAttribute.count;_i48<il;_i48++){normalAttribute.setXYZ(_i48,0,0,0);}}var pA=new Vector3(),pB=new Vector3(),pC=new Vector3();var nA=new Vector3(),nB=new Vector3(),nC=new Vector3();var cb=new Vector3(),ab=new Vector3();// indexed elements
  323. if(index){for(var _i49=0,_il4=index.count;_i49<_il4;_i49+=3){var vA=index.getX(_i49+0);var vB=index.getX(_i49+1);var vC=index.getX(_i49+2);pA.fromBufferAttribute(positionAttribute,vA);pB.fromBufferAttribute(positionAttribute,vB);pC.fromBufferAttribute(positionAttribute,vC);cb.subVectors(pC,pB);ab.subVectors(pA,pB);cb.cross(ab);nA.fromBufferAttribute(normalAttribute,vA);nB.fromBufferAttribute(normalAttribute,vB);nC.fromBufferAttribute(normalAttribute,vC);nA.add(cb);nB.add(cb);nC.add(cb);normalAttribute.setXYZ(vA,nA.x,nA.y,nA.z);normalAttribute.setXYZ(vB,nB.x,nB.y,nB.z);normalAttribute.setXYZ(vC,nC.x,nC.y,nC.z);}}else {// non-indexed elements (unconnected triangle soup)
  324. for(var _i50=0,_il5=positionAttribute.count;_i50<_il5;_i50+=3){pA.fromBufferAttribute(positionAttribute,_i50+0);pB.fromBufferAttribute(positionAttribute,_i50+1);pC.fromBufferAttribute(positionAttribute,_i50+2);cb.subVectors(pC,pB);ab.subVectors(pA,pB);cb.cross(ab);normalAttribute.setXYZ(_i50+0,cb.x,cb.y,cb.z);normalAttribute.setXYZ(_i50+1,cb.x,cb.y,cb.z);normalAttribute.setXYZ(_i50+2,cb.x,cb.y,cb.z);}}this.normalizeNormals();normalAttribute.needsUpdate=true;}},merge:function merge(geometry,offset){if(!(geometry&&geometry.isBufferGeometry)){console.error('THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.',geometry);return;}if(offset===undefined){offset=0;console.warn('THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. '+'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.');}var attributes=this.attributes;for(var key in attributes){if(geometry.attributes[key]===undefined)continue;var attribute1=attributes[key];var attributeArray1=attribute1.array;var attribute2=geometry.attributes[key];var attributeArray2=attribute2.array;var attributeOffset=attribute2.itemSize*offset;var length=Math.min(attributeArray2.length,attributeArray1.length-attributeOffset);for(var _i51=0,j=attributeOffset;_i51<length;_i51++,j++){attributeArray1[j]=attributeArray2[_i51];}}return this;},normalizeNormals:function normalizeNormals(){var normals=this.attributes.normal;for(var _i52=0,il=normals.count;_i52<il;_i52++){_vector$4.fromBufferAttribute(normals,_i52);_vector$4.normalize();normals.setXYZ(_i52,_vector$4.x,_vector$4.y,_vector$4.z);}},toNonIndexed:function toNonIndexed(){function convertBufferAttribute(attribute,indices){var array=attribute.array;var itemSize=attribute.itemSize;var normalized=attribute.normalized;var array2=new array.constructor(indices.length*itemSize);var index=0,index2=0;for(var _i53=0,l=indices.length;_i53<l;_i53++){index=indices[_i53]*itemSize;for(var j=0;j<itemSize;j++){array2[index2++]=array[index++];}}return new BufferAttribute(array2,itemSize,normalized);}//
  325. if(this.index===null){console.warn('THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.');return this;}var geometry2=new BufferGeometry();var indices=this.index.array;var attributes=this.attributes;// attributes
  326. for(var name in attributes){var attribute=attributes[name];var newAttribute=convertBufferAttribute(attribute,indices);geometry2.setAttribute(name,newAttribute);}// morph attributes
  327. var morphAttributes=this.morphAttributes;for(var _name in morphAttributes){var morphArray=[];var morphAttribute=morphAttributes[_name];// morphAttribute: array of Float32BufferAttributes
  328. for(var _i54=0,il=morphAttribute.length;_i54<il;_i54++){var _attribute5=morphAttribute[_i54];var _newAttribute=convertBufferAttribute(_attribute5,indices);morphArray.push(_newAttribute);}geometry2.morphAttributes[_name]=morphArray;}geometry2.morphTargetsRelative=this.morphTargetsRelative;// groups
  329. var groups=this.groups;for(var _i55=0,l=groups.length;_i55<l;_i55++){var group=groups[_i55];geometry2.addGroup(group.start,group.count,group.materialIndex);}return geometry2;},toJSON:function toJSON(){var data={metadata:{version:4.5,type:'BufferGeometry',generator:'BufferGeometry.toJSON'}};// standard BufferGeometry serialization
  330. data.uuid=this.uuid;data.type=this.type;if(this.name!=='')data.name=this.name;if(Object.keys(this.userData).length>0)data.userData=this.userData;if(this.parameters!==undefined){var parameters=this.parameters;for(var key in parameters){if(parameters[key]!==undefined)data[key]=parameters[key];}return data;}data.data={attributes:{}};var index=this.index;if(index!==null){data.data.index={type:index.array.constructor.name,array:Array.prototype.slice.call(index.array)};}var attributes=this.attributes;for(var _key in attributes){var attribute=attributes[_key];var attributeData=attribute.toJSON(data.data);if(attribute.name!=='')attributeData.name=attribute.name;data.data.attributes[_key]=attributeData;}var morphAttributes={};var hasMorphAttributes=false;for(var _key2 in this.morphAttributes){var attributeArray=this.morphAttributes[_key2];var array=[];for(var _i56=0,il=attributeArray.length;_i56<il;_i56++){var _attribute6=attributeArray[_i56];var _attributeData=_attribute6.toJSON(data.data);if(_attribute6.name!=='')_attributeData.name=_attribute6.name;array.push(_attributeData);}if(array.length>0){morphAttributes[_key2]=array;hasMorphAttributes=true;}}if(hasMorphAttributes){data.data.morphAttributes=morphAttributes;data.data.morphTargetsRelative=this.morphTargetsRelative;}var groups=this.groups;if(groups.length>0){data.data.groups=JSON.parse(JSON.stringify(groups));}var boundingSphere=this.boundingSphere;if(boundingSphere!==null){data.data.boundingSphere={center:boundingSphere.center.toArray(),radius:boundingSphere.radius};}return data;},clone:function clone(){/*
  331. // Handle primitives
  332. const parameters = this.parameters;
  333. if ( parameters !== undefined ) {
  334. const values = [];
  335. for ( const key in parameters ) {
  336. values.push( parameters[ key ] );
  337. }
  338. const geometry = Object.create( this.constructor.prototype );
  339. this.constructor.apply( geometry, values );
  340. return geometry;
  341. }
  342. return new this.constructor().copy( this );
  343. */return new BufferGeometry().copy(this);},copy:function copy(source){// reset
  344. this.index=null;this.attributes={};this.morphAttributes={};this.groups=[];this.boundingBox=null;this.boundingSphere=null;// used for storing cloned, shared data
  345. var data={};// name
  346. this.name=source.name;// index
  347. var index=source.index;if(index!==null){this.setIndex(index.clone(data));}// attributes
  348. var attributes=source.attributes;for(var name in attributes){var attribute=attributes[name];this.setAttribute(name,attribute.clone(data));}// morph attributes
  349. var morphAttributes=source.morphAttributes;for(var _name2 in morphAttributes){var array=[];var morphAttribute=morphAttributes[_name2];// morphAttribute: array of Float32BufferAttributes
  350. for(var _i57=0,l=morphAttribute.length;_i57<l;_i57++){array.push(morphAttribute[_i57].clone(data));}this.morphAttributes[_name2]=array;}this.morphTargetsRelative=source.morphTargetsRelative;// groups
  351. var groups=source.groups;for(var _i58=0,_l3=groups.length;_i58<_l3;_i58++){var group=groups[_i58];this.addGroup(group.start,group.count,group.materialIndex);}// bounding box
  352. var boundingBox=source.boundingBox;if(boundingBox!==null){this.boundingBox=boundingBox.clone();}// bounding sphere
  353. var boundingSphere=source.boundingSphere;if(boundingSphere!==null){this.boundingSphere=boundingSphere.clone();}// draw range
  354. this.drawRange.start=source.drawRange.start;this.drawRange.count=source.drawRange.count;// user data
  355. this.userData=source.userData;return this;},dispose:function dispose(){this.dispatchEvent({type:'dispose'});}});var _inverseMatrix=new Matrix4();var _ray=new Ray();var _sphere=new Sphere();var _vA=new Vector3();var _vB=new Vector3();var _vC=new Vector3();var _tempA=new Vector3();var _tempB=new Vector3();var _tempC=new Vector3();var _morphA=new Vector3();var _morphB=new Vector3();var _morphC=new Vector3();var _uvA=new Vector2();var _uvB=new Vector2();var _uvC=new Vector2();var _intersectionPoint=new Vector3();var _intersectionPointWorld=new Vector3();function Mesh(){var geometry=arguments.length>0&&arguments[0]!==undefined?arguments[0]:new BufferGeometry();var material=arguments.length>1&&arguments[1]!==undefined?arguments[1]:new MeshBasicMaterial();Object3D.call(this);this.type='Mesh';this.geometry=geometry;this.material=material;this.updateMorphTargets();}Mesh.prototype=Object.assign(Object.create(Object3D.prototype),{constructor:Mesh,isMesh:true,copy:function copy(source){Object3D.prototype.copy.call(this,source);if(source.morphTargetInfluences!==undefined){this.morphTargetInfluences=source.morphTargetInfluences.slice();}if(source.morphTargetDictionary!==undefined){this.morphTargetDictionary=Object.assign({},source.morphTargetDictionary);}this.material=source.material;this.geometry=source.geometry;return this;},updateMorphTargets:function updateMorphTargets(){var geometry=this.geometry;if(geometry.isBufferGeometry){var morphAttributes=geometry.morphAttributes;var keys=Object.keys(morphAttributes);if(keys.length>0){var morphAttribute=morphAttributes[keys[0]];if(morphAttribute!==undefined){this.morphTargetInfluences=[];this.morphTargetDictionary={};for(var m=0,ml=morphAttribute.length;m<ml;m++){var name=morphAttribute[m].name||String(m);this.morphTargetInfluences.push(0);this.morphTargetDictionary[name]=m;}}}}else {var morphTargets=geometry.morphTargets;if(morphTargets!==undefined&&morphTargets.length>0){console.error('THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');}}},raycast:function raycast(raycaster,intersects){var geometry=this.geometry;var material=this.material;var matrixWorld=this.matrixWorld;if(material===undefined)return;// Checking boundingSphere distance to ray
  356. if(geometry.boundingSphere===null)geometry.computeBoundingSphere();_sphere.copy(geometry.boundingSphere);_sphere.applyMatrix4(matrixWorld);if(raycaster.ray.intersectsSphere(_sphere)===false)return;//
  357. _inverseMatrix.copy(matrixWorld).invert();_ray.copy(raycaster.ray).applyMatrix4(_inverseMatrix);// Check boundingBox before continuing
  358. if(geometry.boundingBox!==null){if(_ray.intersectsBox(geometry.boundingBox)===false)return;}var intersection;if(geometry.isBufferGeometry){var index=geometry.index;var position=geometry.attributes.position;var morphPosition=geometry.morphAttributes.position;var morphTargetsRelative=geometry.morphTargetsRelative;var uv=geometry.attributes.uv;var uv2=geometry.attributes.uv2;var groups=geometry.groups;var drawRange=geometry.drawRange;if(index!==null){// indexed buffer geometry
  359. if(Array.isArray(material)){for(var _i59=0,il=groups.length;_i59<il;_i59++){var group=groups[_i59];var groupMaterial=material[group.materialIndex];var start=Math.max(group.start,drawRange.start);var end=Math.min(group.start+group.count,drawRange.start+drawRange.count);for(var j=start,jl=end;j<jl;j+=3){var a=index.getX(j);var b=index.getX(j+1);var c=index.getX(j+2);intersection=checkBufferGeometryIntersection(this,groupMaterial,raycaster,_ray,position,morphPosition,morphTargetsRelative,uv,uv2,a,b,c);if(intersection){intersection.faceIndex=Math.floor(j/3);// triangle number in indexed buffer semantics
  360. intersection.face.materialIndex=group.materialIndex;intersects.push(intersection);}}}}else {var _start2=Math.max(0,drawRange.start);var _end2=Math.min(index.count,drawRange.start+drawRange.count);for(var _i60=_start2,_il6=_end2;_i60<_il6;_i60+=3){var _a=index.getX(_i60);var _b=index.getX(_i60+1);var _c=index.getX(_i60+2);intersection=checkBufferGeometryIntersection(this,material,raycaster,_ray,position,morphPosition,morphTargetsRelative,uv,uv2,_a,_b,_c);if(intersection){intersection.faceIndex=Math.floor(_i60/3);// triangle number in indexed buffer semantics
  361. intersects.push(intersection);}}}}else if(position!==undefined){// non-indexed buffer geometry
  362. if(Array.isArray(material)){for(var _i61=0,_il7=groups.length;_i61<_il7;_i61++){var _group=groups[_i61];var _groupMaterial=material[_group.materialIndex];var _start3=Math.max(_group.start,drawRange.start);var _end3=Math.min(_group.start+_group.count,drawRange.start+drawRange.count);for(var _j2=_start3,_jl=_end3;_j2<_jl;_j2+=3){var _a2=_j2;var _b2=_j2+1;var _c2=_j2+2;intersection=checkBufferGeometryIntersection(this,_groupMaterial,raycaster,_ray,position,morphPosition,morphTargetsRelative,uv,uv2,_a2,_b2,_c2);if(intersection){intersection.faceIndex=Math.floor(_j2/3);// triangle number in non-indexed buffer semantics
  363. intersection.face.materialIndex=_group.materialIndex;intersects.push(intersection);}}}}else {var _start4=Math.max(0,drawRange.start);var _end4=Math.min(position.count,drawRange.start+drawRange.count);for(var _i62=_start4,_il8=_end4;_i62<_il8;_i62+=3){var _a3=_i62;var _b3=_i62+1;var _c3=_i62+2;intersection=checkBufferGeometryIntersection(this,material,raycaster,_ray,position,morphPosition,morphTargetsRelative,uv,uv2,_a3,_b3,_c3);if(intersection){intersection.faceIndex=Math.floor(_i62/3);// triangle number in non-indexed buffer semantics
  364. intersects.push(intersection);}}}}}else if(geometry.isGeometry){var isMultiMaterial=Array.isArray(material);var vertices=geometry.vertices;var faces=geometry.faces;var uvs;var faceVertexUvs=geometry.faceVertexUvs[0];if(faceVertexUvs.length>0)uvs=faceVertexUvs;for(var f=0,fl=faces.length;f<fl;f++){var face=faces[f];var faceMaterial=isMultiMaterial?material[face.materialIndex]:material;if(faceMaterial===undefined)continue;var fvA=vertices[face.a];var fvB=vertices[face.b];var fvC=vertices[face.c];intersection=checkIntersection(this,faceMaterial,raycaster,_ray,fvA,fvB,fvC,_intersectionPoint);if(intersection){if(uvs&&uvs[f]){var uvs_f=uvs[f];_uvA.copy(uvs_f[0]);_uvB.copy(uvs_f[1]);_uvC.copy(uvs_f[2]);intersection.uv=Triangle.getUV(_intersectionPoint,fvA,fvB,fvC,_uvA,_uvB,_uvC,new Vector2());}intersection.face=face;intersection.faceIndex=f;intersects.push(intersection);}}}}});function checkIntersection(object,material,raycaster,ray,pA,pB,pC,point){var intersect;if(material.side===BackSide){intersect=ray.intersectTriangle(pC,pB,pA,true,point);}else {intersect=ray.intersectTriangle(pA,pB,pC,material.side!==DoubleSide,point);}if(intersect===null)return null;_intersectionPointWorld.copy(point);_intersectionPointWorld.applyMatrix4(object.matrixWorld);var distance=raycaster.ray.origin.distanceTo(_intersectionPointWorld);if(distance<raycaster.near||distance>raycaster.far)return null;return {distance:distance,point:_intersectionPointWorld.clone(),object:object};}function checkBufferGeometryIntersection(object,material,raycaster,ray,position,morphPosition,morphTargetsRelative,uv,uv2,a,b,c){_vA.fromBufferAttribute(position,a);_vB.fromBufferAttribute(position,b);_vC.fromBufferAttribute(position,c);var morphInfluences=object.morphTargetInfluences;if(material.morphTargets&&morphPosition&&morphInfluences){_morphA.set(0,0,0);_morphB.set(0,0,0);_morphC.set(0,0,0);for(var _i63=0,il=morphPosition.length;_i63<il;_i63++){var influence=morphInfluences[_i63];var morphAttribute=morphPosition[_i63];if(influence===0)continue;_tempA.fromBufferAttribute(morphAttribute,a);_tempB.fromBufferAttribute(morphAttribute,b);_tempC.fromBufferAttribute(morphAttribute,c);if(morphTargetsRelative){_morphA.addScaledVector(_tempA,influence);_morphB.addScaledVector(_tempB,influence);_morphC.addScaledVector(_tempC,influence);}else {_morphA.addScaledVector(_tempA.sub(_vA),influence);_morphB.addScaledVector(_tempB.sub(_vB),influence);_morphC.addScaledVector(_tempC.sub(_vC),influence);}}_vA.add(_morphA);_vB.add(_morphB);_vC.add(_morphC);}if(object.isSkinnedMesh){object.boneTransform(a,_vA);object.boneTransform(b,_vB);object.boneTransform(c,_vC);}var intersection=checkIntersection(object,material,raycaster,ray,_vA,_vB,_vC,_intersectionPoint);if(intersection){if(uv){_uvA.fromBufferAttribute(uv,a);_uvB.fromBufferAttribute(uv,b);_uvC.fromBufferAttribute(uv,c);intersection.uv=Triangle.getUV(_intersectionPoint,_vA,_vB,_vC,_uvA,_uvB,_uvC,new Vector2());}if(uv2){_uvA.fromBufferAttribute(uv2,a);_uvB.fromBufferAttribute(uv2,b);_uvC.fromBufferAttribute(uv2,c);intersection.uv2=Triangle.getUV(_intersectionPoint,_vA,_vB,_vC,_uvA,_uvB,_uvC,new Vector2());}var face=new Face3(a,b,c);Triangle.getNormal(_vA,_vB,_vC,face.normal);intersection.face=face;}return intersection;}class BoxBufferGeometry extends BufferGeometry{constructor(){var width=arguments.length>0&&arguments[0]!==undefined?arguments[0]:1;var height=arguments.length>1&&arguments[1]!==undefined?arguments[1]:1;var depth=arguments.length>2&&arguments[2]!==undefined?arguments[2]:1;var widthSegments=arguments.length>3&&arguments[3]!==undefined?arguments[3]:1;var heightSegments=arguments.length>4&&arguments[4]!==undefined?arguments[4]:1;var depthSegments=arguments.length>5&&arguments[5]!==undefined?arguments[5]:1;super();this.type='BoxBufferGeometry';this.parameters={width:width,height:height,depth:depth,widthSegments:widthSegments,heightSegments:heightSegments,depthSegments:depthSegments};var scope=this;// segments
  365. widthSegments=Math.floor(widthSegments);heightSegments=Math.floor(heightSegments);depthSegments=Math.floor(depthSegments);// buffers
  366. var indices=[];var vertices=[];var normals=[];var uvs=[];// helper variables
  367. var numberOfVertices=0;var groupStart=0;// build each side of the box geometry
  368. buildPlane('z','y','x',-1,-1,depth,height,width,depthSegments,heightSegments,0);// px
  369. buildPlane('z','y','x',1,-1,depth,height,-width,depthSegments,heightSegments,1);// nx
  370. buildPlane('x','z','y',1,1,width,depth,height,widthSegments,depthSegments,2);// py
  371. buildPlane('x','z','y',1,-1,width,depth,-height,widthSegments,depthSegments,3);// ny
  372. buildPlane('x','y','z',1,-1,width,height,depth,widthSegments,heightSegments,4);// pz
  373. buildPlane('x','y','z',-1,-1,width,height,-depth,widthSegments,heightSegments,5);// nz
  374. // build geometry
  375. this.setIndex(indices);this.setAttribute('position',new Float32BufferAttribute(vertices,3));this.setAttribute('normal',new Float32BufferAttribute(normals,3));this.setAttribute('uv',new Float32BufferAttribute(uvs,2));function buildPlane(u,v,w,udir,vdir,width,height,depth,gridX,gridY,materialIndex){var segmentWidth=width/gridX;var segmentHeight=height/gridY;var widthHalf=width/2;var heightHalf=height/2;var depthHalf=depth/2;var gridX1=gridX+1;var gridY1=gridY+1;var vertexCounter=0;var groupCount=0;var vector=new Vector3();// generate vertices, normals and uvs
  376. for(var iy=0;iy<gridY1;iy++){var y=iy*segmentHeight-heightHalf;for(var ix=0;ix<gridX1;ix++){var x=ix*segmentWidth-widthHalf;// set values to correct vector component
  377. vector[u]=x*udir;vector[v]=y*vdir;vector[w]=depthHalf;// now apply vector to vertex buffer
  378. vertices.push(vector.x,vector.y,vector.z);// set values to correct vector component
  379. vector[u]=0;vector[v]=0;vector[w]=depth>0?1:-1;// now apply vector to normal buffer
  380. normals.push(vector.x,vector.y,vector.z);// uvs
  381. uvs.push(ix/gridX);uvs.push(1-iy/gridY);// counters
  382. vertexCounter+=1;}}// indices
  383. // 1. you need three indices to draw a single face
  384. // 2. a single segment consists of two faces
  385. // 3. so we need to generate six (2*3) indices per segment
  386. for(var _iy=0;_iy<gridY;_iy++){for(var _ix=0;_ix<gridX;_ix++){var a=numberOfVertices+_ix+gridX1*_iy;var b=numberOfVertices+_ix+gridX1*(_iy+1);var c=numberOfVertices+(_ix+1)+gridX1*(_iy+1);var d=numberOfVertices+(_ix+1)+gridX1*_iy;// faces
  387. indices.push(a,b,d);indices.push(b,c,d);// increase counter
  388. groupCount+=6;}}// add a group to the geometry. this will ensure multi material support
  389. scope.addGroup(groupStart,groupCount,materialIndex);// calculate new start value for groups
  390. groupStart+=groupCount;// update total number of vertices
  391. numberOfVertices+=vertexCounter;}}}/**
  392. * Uniform Utilities
  393. */function cloneUniforms(src){var dst={};for(var u in src){dst[u]={};for(var p in src[u]){var property=src[u][p];if(property&&(property.isColor||property.isMatrix3||property.isMatrix4||property.isVector2||property.isVector3||property.isVector4||property.isTexture)){dst[u][p]=property.clone();}else if(Array.isArray(property)){dst[u][p]=property.slice();}else {dst[u][p]=property;}}}return dst;}function mergeUniforms(uniforms){var merged={};for(var u=0;u<uniforms.length;u++){var _tmp=cloneUniforms(uniforms[u]);for(var p in _tmp){merged[p]=_tmp[p];}}return merged;}// Legacy
  394. var UniformsUtils={clone:cloneUniforms,merge:mergeUniforms};var default_vertex="void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";var default_fragment="void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";/**
  395. * parameters = {
  396. * defines: { "label" : "value" },
  397. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  398. *
  399. * fragmentShader: <string>,
  400. * vertexShader: <string>,
  401. *
  402. * wireframe: <boolean>,
  403. * wireframeLinewidth: <float>,
  404. *
  405. * lights: <bool>,
  406. *
  407. * skinning: <bool>,
  408. * morphTargets: <bool>,
  409. * morphNormals: <bool>
  410. * }
  411. */function ShaderMaterial(parameters){Material.call(this);this.type='ShaderMaterial';this.defines={};this.uniforms={};this.vertexShader=default_vertex;this.fragmentShader=default_fragment;this.linewidth=1;this.wireframe=false;this.wireframeLinewidth=1;this.fog=false;// set to use scene fog
  412. this.lights=false;// set to use scene lights
  413. this.clipping=false;// set to use user-defined clipping planes
  414. this.skinning=false;// set to use skinning attribute streams
  415. this.morphTargets=false;// set to use morph targets
  416. this.morphNormals=false;// set to use morph normals
  417. this.extensions={derivatives:false,// set to use derivatives
  418. fragDepth:false,// set to use fragment depth values
  419. drawBuffers:false,// set to use draw buffers
  420. shaderTextureLOD:false// set to use shader texture LOD
  421. };// When rendered geometry doesn't include these attributes but the material does,
  422. // use these default values in WebGL. This avoids errors when buffer data is missing.
  423. this.defaultAttributeValues={'color':[1,1,1],'uv':[0,0],'uv2':[0,0]};this.index0AttributeName=undefined;this.uniformsNeedUpdate=false;this.glslVersion=null;if(parameters!==undefined){if(parameters.attributes!==undefined){console.error('THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.');}this.setValues(parameters);}}ShaderMaterial.prototype=Object.create(Material.prototype);ShaderMaterial.prototype.constructor=ShaderMaterial;ShaderMaterial.prototype.isShaderMaterial=true;ShaderMaterial.prototype.copy=function(source){Material.prototype.copy.call(this,source);this.fragmentShader=source.fragmentShader;this.vertexShader=source.vertexShader;this.uniforms=cloneUniforms(source.uniforms);this.defines=Object.assign({},source.defines);this.wireframe=source.wireframe;this.wireframeLinewidth=source.wireframeLinewidth;this.lights=source.lights;this.clipping=source.clipping;this.skinning=source.skinning;this.morphTargets=source.morphTargets;this.morphNormals=source.morphNormals;this.extensions=Object.assign({},source.extensions);this.glslVersion=source.glslVersion;return this;};ShaderMaterial.prototype.toJSON=function(meta){var data=Material.prototype.toJSON.call(this,meta);data.glslVersion=this.glslVersion;data.uniforms={};for(var name in this.uniforms){var uniform=this.uniforms[name];var value=uniform.value;if(value&&value.isTexture){data.uniforms[name]={type:'t',value:value.toJSON(meta).uuid};}else if(value&&value.isColor){data.uniforms[name]={type:'c',value:value.getHex()};}else if(value&&value.isVector2){data.uniforms[name]={type:'v2',value:value.toArray()};}else if(value&&value.isVector3){data.uniforms[name]={type:'v3',value:value.toArray()};}else if(value&&value.isVector4){data.uniforms[name]={type:'v4',value:value.toArray()};}else if(value&&value.isMatrix3){data.uniforms[name]={type:'m3',value:value.toArray()};}else if(value&&value.isMatrix4){data.uniforms[name]={type:'m4',value:value.toArray()};}else {data.uniforms[name]={value:value};// note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  424. }}if(Object.keys(this.defines).length>0)data.defines=this.defines;data.vertexShader=this.vertexShader;data.fragmentShader=this.fragmentShader;var extensions={};for(var key in this.extensions){if(this.extensions[key]===true)extensions[key]=true;}if(Object.keys(extensions).length>0)data.extensions=extensions;return data;};function Camera(){Object3D.call(this);this.type='Camera';this.matrixWorldInverse=new Matrix4();this.projectionMatrix=new Matrix4();this.projectionMatrixInverse=new Matrix4();}Camera.prototype=Object.assign(Object.create(Object3D.prototype),{constructor:Camera,isCamera:true,copy:function copy(source,recursive){Object3D.prototype.copy.call(this,source,recursive);this.matrixWorldInverse.copy(source.matrixWorldInverse);this.projectionMatrix.copy(source.projectionMatrix);this.projectionMatrixInverse.copy(source.projectionMatrixInverse);return this;},getWorldDirection:function getWorldDirection(target){if(target===undefined){console.warn('THREE.Camera: .getWorldDirection() target is now required');target=new Vector3();}this.updateWorldMatrix(true,false);var e=this.matrixWorld.elements;return target.set(-e[8],-e[9],-e[10]).normalize();},updateMatrixWorld:function updateMatrixWorld(force){Object3D.prototype.updateMatrixWorld.call(this,force);this.matrixWorldInverse.copy(this.matrixWorld).invert();},updateWorldMatrix:function updateWorldMatrix(updateParents,updateChildren){Object3D.prototype.updateWorldMatrix.call(this,updateParents,updateChildren);this.matrixWorldInverse.copy(this.matrixWorld).invert();},clone:function clone(){return new this.constructor().copy(this);}});function PerspectiveCamera(){var fov=arguments.length>0&&arguments[0]!==undefined?arguments[0]:50;var aspect=arguments.length>1&&arguments[1]!==undefined?arguments[1]:1;var near=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0.1;var far=arguments.length>3&&arguments[3]!==undefined?arguments[3]:2000;Camera.call(this);this.type='PerspectiveCamera';this.fov=fov;this.zoom=1;this.near=near;this.far=far;this.focus=10;this.aspect=aspect;this.view=null;this.filmGauge=35;// width of the film (default in millimeters)
  425. this.filmOffset=0;// horizontal film offset (same unit as gauge)
  426. this.updateProjectionMatrix();}PerspectiveCamera.prototype=Object.assign(Object.create(Camera.prototype),{constructor:PerspectiveCamera,isPerspectiveCamera:true,copy:function copy(source,recursive){Camera.prototype.copy.call(this,source,recursive);this.fov=source.fov;this.zoom=source.zoom;this.near=source.near;this.far=source.far;this.focus=source.focus;this.aspect=source.aspect;this.view=source.view===null?null:Object.assign({},source.view);this.filmGauge=source.filmGauge;this.filmOffset=source.filmOffset;return this;},/**
  427. * Sets the FOV by focal length in respect to the current .filmGauge.
  428. *
  429. * The default film gauge is 35, so that the focal length can be specified for
  430. * a 35mm (full frame) camera.
  431. *
  432. * Values for focal length and film gauge must have the same unit.
  433. */setFocalLength:function setFocalLength(focalLength){// see http://www.bobatkins.com/photography/technical/field_of_view.html
  434. var vExtentSlope=0.5*this.getFilmHeight()/focalLength;this.fov=MathUtils.RAD2DEG*2*Math.atan(vExtentSlope);this.updateProjectionMatrix();},/**
  435. * Calculates the focal length from the current .fov and .filmGauge.
  436. */getFocalLength:function getFocalLength(){var vExtentSlope=Math.tan(MathUtils.DEG2RAD*0.5*this.fov);return 0.5*this.getFilmHeight()/vExtentSlope;},getEffectiveFOV:function getEffectiveFOV(){return MathUtils.RAD2DEG*2*Math.atan(Math.tan(MathUtils.DEG2RAD*0.5*this.fov)/this.zoom);},getFilmWidth:function getFilmWidth(){// film not completely covered in portrait format (aspect < 1)
  437. return this.filmGauge*Math.min(this.aspect,1);},getFilmHeight:function getFilmHeight(){// film not completely covered in landscape format (aspect > 1)
  438. return this.filmGauge/Math.max(this.aspect,1);},/**
  439. * Sets an offset in a larger frustum. This is useful for multi-window or
  440. * multi-monitor/multi-machine setups.
  441. *
  442. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  443. * the monitors are in grid like this
  444. *
  445. * +---+---+---+
  446. * | A | B | C |
  447. * +---+---+---+
  448. * | D | E | F |
  449. * +---+---+---+
  450. *
  451. * then for each monitor you would call it like this
  452. *
  453. * const w = 1920;
  454. * const h = 1080;
  455. * const fullWidth = w * 3;
  456. * const fullHeight = h * 2;
  457. *
  458. * --A--
  459. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  460. * --B--
  461. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  462. * --C--
  463. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  464. * --D--
  465. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  466. * --E--
  467. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  468. * --F--
  469. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  470. *
  471. * Note there is no reason monitors have to be the same size or in a grid.
  472. */setViewOffset:function setViewOffset(fullWidth,fullHeight,x,y,width,height){this.aspect=fullWidth/fullHeight;if(this.view===null){this.view={enabled:true,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1};}this.view.enabled=true;this.view.fullWidth=fullWidth;this.view.fullHeight=fullHeight;this.view.offsetX=x;this.view.offsetY=y;this.view.width=width;this.view.height=height;this.updateProjectionMatrix();},clearViewOffset:function clearViewOffset(){if(this.view!==null){this.view.enabled=false;}this.updateProjectionMatrix();},updateProjectionMatrix:function updateProjectionMatrix(){var near=this.near;var top=near*Math.tan(MathUtils.DEG2RAD*0.5*this.fov)/this.zoom;var height=2*top;var width=this.aspect*height;var left=-0.5*width;var view=this.view;if(this.view!==null&&this.view.enabled){var fullWidth=view.fullWidth,fullHeight=view.fullHeight;left+=view.offsetX*width/fullWidth;top-=view.offsetY*height/fullHeight;width*=view.width/fullWidth;height*=view.height/fullHeight;}var skew=this.filmOffset;if(skew!==0)left+=near*skew/this.getFilmWidth();this.projectionMatrix.makePerspective(left,left+width,top,top-height,near,this.far);this.projectionMatrixInverse.copy(this.projectionMatrix).invert();},toJSON:function toJSON(meta){var data=Object3D.prototype.toJSON.call(this,meta);data.object.fov=this.fov;data.object.zoom=this.zoom;data.object.near=this.near;data.object.far=this.far;data.object.focus=this.focus;data.object.aspect=this.aspect;if(this.view!==null)data.object.view=Object.assign({},this.view);data.object.filmGauge=this.filmGauge;data.object.filmOffset=this.filmOffset;return data;}});var fov=90,aspect=1;function CubeCamera(near,far,renderTarget){Object3D.call(this);this.type='CubeCamera';if(renderTarget.isWebGLCubeRenderTarget!==true){console.error('THREE.CubeCamera: The constructor now expects an instance of WebGLCubeRenderTarget as third parameter.');return;}this.renderTarget=renderTarget;var cameraPX=new PerspectiveCamera(fov,aspect,near,far);cameraPX.layers=this.layers;cameraPX.up.set(0,-1,0);cameraPX.lookAt(new Vector3(1,0,0));this.add(cameraPX);var cameraNX=new PerspectiveCamera(fov,aspect,near,far);cameraNX.layers=this.layers;cameraNX.up.set(0,-1,0);cameraNX.lookAt(new Vector3(-1,0,0));this.add(cameraNX);var cameraPY=new PerspectiveCamera(fov,aspect,near,far);cameraPY.layers=this.layers;cameraPY.up.set(0,0,1);cameraPY.lookAt(new Vector3(0,1,0));this.add(cameraPY);var cameraNY=new PerspectiveCamera(fov,aspect,near,far);cameraNY.layers=this.layers;cameraNY.up.set(0,0,-1);cameraNY.lookAt(new Vector3(0,-1,0));this.add(cameraNY);var cameraPZ=new PerspectiveCamera(fov,aspect,near,far);cameraPZ.layers=this.layers;cameraPZ.up.set(0,-1,0);cameraPZ.lookAt(new Vector3(0,0,1));this.add(cameraPZ);var cameraNZ=new PerspectiveCamera(fov,aspect,near,far);cameraNZ.layers=this.layers;cameraNZ.up.set(0,-1,0);cameraNZ.lookAt(new Vector3(0,0,-1));this.add(cameraNZ);this.update=function(renderer,scene){if(this.parent===null)this.updateMatrixWorld();var currentXrEnabled=renderer.xr.enabled;var currentRenderTarget=renderer.getRenderTarget();renderer.xr.enabled=false;var generateMipmaps=renderTarget.texture.generateMipmaps;renderTarget.texture.generateMipmaps=false;renderer.setRenderTarget(renderTarget,0);renderer.render(scene,cameraPX);renderer.setRenderTarget(renderTarget,1);renderer.render(scene,cameraNX);renderer.setRenderTarget(renderTarget,2);renderer.render(scene,cameraPY);renderer.setRenderTarget(renderTarget,3);renderer.render(scene,cameraNY);renderer.setRenderTarget(renderTarget,4);renderer.render(scene,cameraPZ);renderTarget.texture.generateMipmaps=generateMipmaps;renderer.setRenderTarget(renderTarget,5);renderer.render(scene,cameraNZ);renderer.setRenderTarget(currentRenderTarget);renderer.xr.enabled=currentXrEnabled;};}CubeCamera.prototype=Object.create(Object3D.prototype);CubeCamera.prototype.constructor=CubeCamera;function CubeTexture(images,mapping,wrapS,wrapT,magFilter,minFilter,format,type,anisotropy,encoding){images=images!==undefined?images:[];mapping=mapping!==undefined?mapping:CubeReflectionMapping;format=format!==undefined?format:RGBFormat;Texture.call(this,images,mapping,wrapS,wrapT,magFilter,minFilter,format,type,anisotropy,encoding);this.flipY=false;// Why CubeTexture._needsFlipEnvMap is necessary:
  473. //
  474. // By convention -- likely based on the RenderMan spec from the 1990's -- cube maps are specified by WebGL (and three.js)
  475. // in a coordinate system in which positive-x is to the right when looking up the positive-z axis -- in other words,
  476. // in a left-handed coordinate system. By continuing this convention, preexisting cube maps continued to render correctly.
  477. // three.js uses a right-handed coordinate system. So environment maps used in three.js appear to have px and nx swapped
  478. // and the flag _needsFlipEnvMap controls this conversion. The flip is not required (and thus _needsFlipEnvMap is set to false)
  479. // when using WebGLCubeRenderTarget.texture as a cube texture.
  480. this._needsFlipEnvMap=true;}CubeTexture.prototype=Object.create(Texture.prototype);CubeTexture.prototype.constructor=CubeTexture;CubeTexture.prototype.isCubeTexture=true;Object.defineProperty(CubeTexture.prototype,'images',{get:function get(){return this.image;},set:function set(value){this.image=value;}});function WebGLCubeRenderTarget(size,options,dummy){if(Number.isInteger(options)){console.warn('THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )');options=dummy;}WebGLRenderTarget.call(this,size,size,options);options=options||{};this.texture=new CubeTexture(undefined,options.mapping,options.wrapS,options.wrapT,options.magFilter,options.minFilter,options.format,options.type,options.anisotropy,options.encoding);this.texture._needsFlipEnvMap=false;}WebGLCubeRenderTarget.prototype=Object.create(WebGLRenderTarget.prototype);WebGLCubeRenderTarget.prototype.constructor=WebGLCubeRenderTarget;WebGLCubeRenderTarget.prototype.isWebGLCubeRenderTarget=true;WebGLCubeRenderTarget.prototype.fromEquirectangularTexture=function(renderer,texture){this.texture.type=texture.type;this.texture.format=RGBAFormat;// see #18859
  481. this.texture.encoding=texture.encoding;this.texture.generateMipmaps=texture.generateMipmaps;this.texture.minFilter=texture.minFilter;this.texture.magFilter=texture.magFilter;var shader={uniforms:{tEquirect:{value:null}},vertexShader:/* glsl */"\n\n\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\tvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\n\t\t\t\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n\n\t\t\t}\n\n\t\t\tvoid main() {\n\n\t\t\t\tvWorldDirection = transformDirection( position, modelMatrix );\n\n\t\t\t\t#include <begin_vertex>\n\t\t\t\t#include <project_vertex>\n\n\t\t\t}\n\t\t",fragmentShader:/* glsl */"\n\n\t\t\tuniform sampler2D tEquirect;\n\n\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\t#include <common>\n\n\t\t\tvoid main() {\n\n\t\t\t\tvec3 direction = normalize( vWorldDirection );\n\n\t\t\t\tvec2 sampleUV = equirectUv( direction );\n\n\t\t\t\tgl_FragColor = texture2D( tEquirect, sampleUV );\n\n\t\t\t}\n\t\t"};var geometry=new BoxBufferGeometry(5,5,5);var material=new ShaderMaterial({name:'CubemapFromEquirect',uniforms:cloneUniforms(shader.uniforms),vertexShader:shader.vertexShader,fragmentShader:shader.fragmentShader,side:BackSide,blending:NoBlending});material.uniforms.tEquirect.value=texture;var mesh=new Mesh(geometry,material);var currentMinFilter=texture.minFilter;// Avoid blurred poles
  482. if(texture.minFilter===LinearMipmapLinearFilter)texture.minFilter=LinearFilter;var camera=new CubeCamera(1,10,this);camera.update(renderer,mesh);texture.minFilter=currentMinFilter;mesh.geometry.dispose();mesh.material.dispose();return this;};WebGLCubeRenderTarget.prototype.clear=function(renderer,color,depth,stencil){var currentRenderTarget=renderer.getRenderTarget();for(var _i64=0;_i64<6;_i64++){renderer.setRenderTarget(this,_i64);renderer.clear(color,depth,stencil);}renderer.setRenderTarget(currentRenderTarget);};function DataTexture(data,width,height,format,type,mapping,wrapS,wrapT,magFilter,minFilter,anisotropy,encoding){Texture.call(this,null,mapping,wrapS,wrapT,magFilter,minFilter,format,type,anisotropy,encoding);this.image={data:data||null,width:width||1,height:height||1};this.magFilter=magFilter!==undefined?magFilter:NearestFilter;this.minFilter=minFilter!==undefined?minFilter:NearestFilter;this.generateMipmaps=false;this.flipY=false;this.unpackAlignment=1;this.needsUpdate=true;}DataTexture.prototype=Object.create(Texture.prototype);DataTexture.prototype.constructor=DataTexture;DataTexture.prototype.isDataTexture=true;var _sphere$1=/*@__PURE__*/new Sphere();var _vector$5=/*@__PURE__*/new Vector3();class Frustum{constructor(p0,p1,p2,p3,p4,p5){this.planes=[p0!==undefined?p0:new Plane(),p1!==undefined?p1:new Plane(),p2!==undefined?p2:new Plane(),p3!==undefined?p3:new Plane(),p4!==undefined?p4:new Plane(),p5!==undefined?p5:new Plane()];}set(p0,p1,p2,p3,p4,p5){var planes=this.planes;planes[0].copy(p0);planes[1].copy(p1);planes[2].copy(p2);planes[3].copy(p3);planes[4].copy(p4);planes[5].copy(p5);return this;}clone(){return new this.constructor().copy(this);}copy(frustum){var planes=this.planes;for(var _i65=0;_i65<6;_i65++){planes[_i65].copy(frustum.planes[_i65]);}return this;}setFromProjectionMatrix(m){var planes=this.planes;var me=m.elements;var me0=me[0],me1=me[1],me2=me[2],me3=me[3];var me4=me[4],me5=me[5],me6=me[6],me7=me[7];var me8=me[8],me9=me[9],me10=me[10],me11=me[11];var me12=me[12],me13=me[13],me14=me[14],me15=me[15];planes[0].setComponents(me3-me0,me7-me4,me11-me8,me15-me12).normalize();planes[1].setComponents(me3+me0,me7+me4,me11+me8,me15+me12).normalize();planes[2].setComponents(me3+me1,me7+me5,me11+me9,me15+me13).normalize();planes[3].setComponents(me3-me1,me7-me5,me11-me9,me15-me13).normalize();planes[4].setComponents(me3-me2,me7-me6,me11-me10,me15-me14).normalize();planes[5].setComponents(me3+me2,me7+me6,me11+me10,me15+me14).normalize();return this;}intersectsObject(object){var geometry=object.geometry;if(geometry.boundingSphere===null)geometry.computeBoundingSphere();_sphere$1.copy(geometry.boundingSphere).applyMatrix4(object.matrixWorld);return this.intersectsSphere(_sphere$1);}intersectsSprite(sprite){_sphere$1.center.set(0,0,0);_sphere$1.radius=0.7071067811865476;_sphere$1.applyMatrix4(sprite.matrixWorld);return this.intersectsSphere(_sphere$1);}intersectsSphere(sphere){var planes=this.planes;var center=sphere.center;var negRadius=-sphere.radius;for(var _i66=0;_i66<6;_i66++){var distance=planes[_i66].distanceToPoint(center);if(distance<negRadius){return false;}}return true;}intersectsBox(box){var planes=this.planes;for(var _i67=0;_i67<6;_i67++){var plane=planes[_i67];// corner at max distance
  483. _vector$5.x=plane.normal.x>0?box.max.x:box.min.x;_vector$5.y=plane.normal.y>0?box.max.y:box.min.y;_vector$5.z=plane.normal.z>0?box.max.z:box.min.z;if(plane.distanceToPoint(_vector$5)<0){return false;}}return true;}containsPoint(point){var planes=this.planes;for(var _i68=0;_i68<6;_i68++){if(planes[_i68].distanceToPoint(point)<0){return false;}}return true;}}function WebGLAnimation(){var context=null;var isAnimating=false;var animationLoop=null;var requestId=null;function onAnimationFrame(time,frame){animationLoop(time,frame);requestId=context.requestAnimationFrame(onAnimationFrame);}return {start:function start(){if(isAnimating===true)return;if(animationLoop===null)return;requestId=context.requestAnimationFrame(onAnimationFrame);isAnimating=true;},stop:function stop(){context.cancelAnimationFrame(requestId);isAnimating=false;},setAnimationLoop:function setAnimationLoop(callback){animationLoop=callback;},setContext:function setContext(value){context=value;}};}function WebGLAttributes(gl,capabilities){var isWebGL2=capabilities.isWebGL2;var buffers=new WeakMap();function createBuffer(attribute,bufferType){var array=attribute.array;var usage=attribute.usage;var buffer=gl.createBuffer();gl.bindBuffer(bufferType,buffer);gl.bufferData(bufferType,array,usage);attribute.onUploadCallback();var type=5126;if(array instanceof Float32Array){type=5126;}else if(array instanceof Float64Array){console.warn('THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.');}else if(array instanceof Uint16Array){if(attribute.isFloat16BufferAttribute){if(isWebGL2){type=5131;}else {console.warn('THREE.WebGLAttributes: Usage of Float16BufferAttribute requires WebGL2.');}}else {type=5123;}}else if(array instanceof Int16Array){type=5122;}else if(array instanceof Uint32Array){type=5125;}else if(array instanceof Int32Array){type=5124;}else if(array instanceof Int8Array){type=5120;}else if(array instanceof Uint8Array){type=5121;}return {buffer:buffer,type:type,bytesPerElement:array.BYTES_PER_ELEMENT,version:attribute.version};}function updateBuffer(buffer,attribute,bufferType){var array=attribute.array;var updateRange=attribute.updateRange;gl.bindBuffer(bufferType,buffer);if(updateRange.count===-1){// Not using update ranges
  484. gl.bufferSubData(bufferType,0,array);}else {if(isWebGL2){gl.bufferSubData(bufferType,updateRange.offset*array.BYTES_PER_ELEMENT,array,updateRange.offset,updateRange.count);}else {gl.bufferSubData(bufferType,updateRange.offset*array.BYTES_PER_ELEMENT,array.subarray(updateRange.offset,updateRange.offset+updateRange.count));}updateRange.count=-1;// reset range
  485. }}//
  486. function get(attribute){if(attribute.isInterleavedBufferAttribute)attribute=attribute.data;return buffers.get(attribute);}function remove(attribute){if(attribute.isInterleavedBufferAttribute)attribute=attribute.data;var data=buffers.get(attribute);if(data){gl.deleteBuffer(data.buffer);buffers.delete(attribute);}}function update(attribute,bufferType){if(attribute.isGLBufferAttribute){var cached=buffers.get(attribute);if(!cached||cached.version<attribute.version){buffers.set(attribute,{buffer:attribute.buffer,type:attribute.type,bytesPerElement:attribute.elementSize,version:attribute.version});}return;}if(attribute.isInterleavedBufferAttribute)attribute=attribute.data;var data=buffers.get(attribute);if(data===undefined){buffers.set(attribute,createBuffer(attribute,bufferType));}else if(data.version<attribute.version){updateBuffer(data.buffer,attribute,bufferType);data.version=attribute.version;}}return {get:get,remove:remove,update:update};}class PlaneBufferGeometry extends BufferGeometry{constructor(){var width=arguments.length>0&&arguments[0]!==undefined?arguments[0]:1;var height=arguments.length>1&&arguments[1]!==undefined?arguments[1]:1;var widthSegments=arguments.length>2&&arguments[2]!==undefined?arguments[2]:1;var heightSegments=arguments.length>3&&arguments[3]!==undefined?arguments[3]:1;super();this.type='PlaneBufferGeometry';this.parameters={width:width,height:height,widthSegments:widthSegments,heightSegments:heightSegments};var width_half=width/2;var height_half=height/2;var gridX=Math.floor(widthSegments);var gridY=Math.floor(heightSegments);var gridX1=gridX+1;var gridY1=gridY+1;var segment_width=width/gridX;var segment_height=height/gridY;//
  487. var indices=[];var vertices=[];var normals=[];var uvs=[];for(var iy=0;iy<gridY1;iy++){var y=iy*segment_height-height_half;for(var ix=0;ix<gridX1;ix++){var x=ix*segment_width-width_half;vertices.push(x,-y,0);normals.push(0,0,1);uvs.push(ix/gridX);uvs.push(1-iy/gridY);}}for(var _iy2=0;_iy2<gridY;_iy2++){for(var _ix2=0;_ix2<gridX;_ix2++){var a=_ix2+gridX1*_iy2;var b=_ix2+gridX1*(_iy2+1);var c=_ix2+1+gridX1*(_iy2+1);var d=_ix2+1+gridX1*_iy2;indices.push(a,b,d);indices.push(b,c,d);}}this.setIndex(indices);this.setAttribute('position',new Float32BufferAttribute(vertices,3));this.setAttribute('normal',new Float32BufferAttribute(normals,3));this.setAttribute('uv',new Float32BufferAttribute(uvs,2));}}var alphamap_fragment="#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";var alphamap_pars_fragment="#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";var alphatest_fragment="#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";var aomap_fragment="#ifdef USE_AOMAP\n\tfloat ambientOcclusion = ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;\n\treflectedLight.indirectDiffuse *= ambientOcclusion;\n\t#if defined( USE_ENVMAP ) && defined( STANDARD )\n\t\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\t\treflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.specularRoughness );\n\t#endif\n#endif";var aomap_pars_fragment="#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";var begin_vertex="vec3 transformed = vec3( position );";var beginnormal_vertex="vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";var bsdfs="vec2 integrateSpecularBRDF( const in float dotNV, const in float roughness ) {\n\tconst vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n\tconst vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n\tvec4 r = roughness * c0 + c1;\n\tfloat a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n\treturn vec2( -1.04, 1.04 ) * a004 + r.zw;\n}\nfloat punctualLightIntensityToIrradianceFactor( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n#if defined ( PHYSICALLY_CORRECT_LIGHTS )\n\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\tif( cutoffDistance > 0.0 ) {\n\t\tdistanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t}\n\treturn distanceFalloff;\n#else\n\tif( cutoffDistance > 0.0 && decayExponent > 0.0 ) {\n\t\treturn pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\n\t}\n\treturn 1.0;\n#endif\n}\nvec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) {\n\treturn RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {\n\tfloat fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );\n\treturn ( 1.0 - specularColor ) * fresnel + specularColor;\n}\nvec3 F_Schlick_RoughnessDependent( const in vec3 F0, const in float dotNV, const in float roughness ) {\n\tfloat fresnel = exp2( ( -5.55473 * dotNV - 6.98316 ) * dotNV );\n\tvec3 Fr = max( vec3( 1.0 - roughness ), F0 ) - F0;\n\treturn Fr * fresnel + F0;\n}\nfloat G_GGX_Smith( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\tfloat gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\treturn 1.0 / ( gl * gv );\n}\nfloat G_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\tfloat gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\treturn 0.5 / max( gv + gl, EPSILON );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n\tfloat a2 = pow2( alpha );\n\tfloat denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;\n\treturn RECIPROCAL_PI * a2 / pow2( denom );\n}\nvec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float roughness ) {\n\tfloat alpha = pow2( roughness );\n\tvec3 halfDir = normalize( incidentLight.direction + viewDir );\n\tfloat dotNL = saturate( dot( normal, incidentLight.direction ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\tfloat D = D_GGX( alpha, dotNH );\n\treturn F * ( G * D );\n}\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\n\tconst float LUT_SIZE = 64.0;\n\tconst float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n\tconst float LUT_BIAS = 0.5 / LUT_SIZE;\n\tfloat dotNV = saturate( dot( N, V ) );\n\tvec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );\n\tuv = uv * LUT_SCALE + LUT_BIAS;\n\treturn uv;\n}\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\n\tfloat l = length( f );\n\treturn max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\n}\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\n\tfloat x = dot( v1, v2 );\n\tfloat y = abs( x );\n\tfloat a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;\n\tfloat b = 3.4175940 + ( 4.1616724 + y ) * y;\n\tfloat v = a / b;\n\tfloat theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;\n\treturn cross( v1, v2 ) * theta_sintheta;\n}\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\n\tvec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\n\tvec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\n\tvec3 lightNormal = cross( v1, v2 );\n\tif( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\n\tvec3 T1, T2;\n\tT1 = normalize( V - N * dot( V, N ) );\n\tT2 = - cross( N, T1 );\n\tmat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );\n\tvec3 coords[ 4 ];\n\tcoords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\n\tcoords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\n\tcoords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\n\tcoords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\n\tcoords[ 0 ] = normalize( coords[ 0 ] );\n\tcoords[ 1 ] = normalize( coords[ 1 ] );\n\tcoords[ 2 ] = normalize( coords[ 2 ] );\n\tcoords[ 3 ] = normalize( coords[ 3 ] );\n\tvec3 vectorFormFactor = vec3( 0.0 );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\n\tfloat result = LTC_ClippedSphereFormFactor( vectorFormFactor );\n\treturn vec3( result );\n}\nvec3 BRDF_Specular_GGX_Environment( const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float roughness ) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tvec2 brdf = integrateSpecularBRDF( dotNV, roughness );\n\treturn specularColor * brdf.x + brdf.y;\n}\nvoid BRDF_Specular_Multiscattering_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\tvec3 F = F_Schlick_RoughnessDependent( specularColor, dotNV, roughness );\n\tvec2 brdf = integrateSpecularBRDF( dotNV, roughness );\n\tvec3 FssEss = F * brdf.x + brdf.y;\n\tfloat Ess = brdf.x + brdf.y;\n\tfloat Ems = 1.0 - Ess;\n\tvec3 Favg = specularColor + ( 1.0 - specularColor ) * 0.047619;\tvec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );\n\tsingleScatter += FssEss;\n\tmultiScatter += Fms * Ems;\n}\nfloat G_BlinnPhong_Implicit( ) {\n\treturn 0.25;\n}\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\n\treturn RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n}\nvec3 BRDF_Specular_BlinnPhong( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float shininess ) {\n\tvec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n\tfloat dotNH = saturate( dot( geometry.normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_BlinnPhong_Implicit( );\n\tfloat D = D_BlinnPhong( shininess, dotNH );\n\treturn F * ( G * D );\n}\nfloat GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {\n\treturn ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 );\n}\nfloat BlinnExponentToGGXRoughness( const in float blinnExponent ) {\n\treturn sqrt( 2.0 / ( blinnExponent + 2.0 ) );\n}\n#if defined( USE_SHEEN )\nfloat D_Charlie(float roughness, float NoH) {\n\tfloat invAlpha = 1.0 / roughness;\n\tfloat cos2h = NoH * NoH;\n\tfloat sin2h = max(1.0 - cos2h, 0.0078125);\treturn (2.0 + invAlpha) * pow(sin2h, invAlpha * 0.5) / (2.0 * PI);\n}\nfloat V_Neubelt(float NoV, float NoL) {\n\treturn saturate(1.0 / (4.0 * (NoL + NoV - NoL * NoV)));\n}\nvec3 BRDF_Specular_Sheen( const in float roughness, const in vec3 L, const in GeometricContext geometry, vec3 specularColor ) {\n\tvec3 N = geometry.normal;\n\tvec3 V = geometry.viewDir;\n\tvec3 H = normalize( V + L );\n\tfloat dotNH = saturate( dot( N, H ) );\n\treturn specularColor * D_Charlie( roughness, dotNH ) * V_Neubelt( dot(N, V), dot(N, L) );\n}\n#endif";var bumpmap_pars_fragment="#ifdef USE_BUMPMAP\n\tuniform sampler2D bumpMap;\n\tuniform float bumpScale;\n\tvec2 dHdxy_fwd() {\n\t\tvec2 dSTdx = dFdx( vUv );\n\t\tvec2 dSTdy = dFdy( vUv );\n\t\tfloat Hll = bumpScale * texture2D( bumpMap, vUv ).x;\n\t\tfloat dBx = bumpScale * texture2D( bumpMap, vUv + dSTdx ).x - Hll;\n\t\tfloat dBy = bumpScale * texture2D( bumpMap, vUv + dSTdy ).x - Hll;\n\t\treturn vec2( dBx, dBy );\n\t}\n\tvec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy ) {\n\t\tvec3 vSigmaX = vec3( dFdx( surf_pos.x ), dFdx( surf_pos.y ), dFdx( surf_pos.z ) );\n\t\tvec3 vSigmaY = vec3( dFdy( surf_pos.x ), dFdy( surf_pos.y ), dFdy( surf_pos.z ) );\n\t\tvec3 vN = surf_norm;\n\t\tvec3 R1 = cross( vSigmaY, vN );\n\t\tvec3 R2 = cross( vN, vSigmaX );\n\t\tfloat fDet = dot( vSigmaX, R1 );\n\t\tfDet *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\tvec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n\t\treturn normalize( abs( fDet ) * surf_norm - vGrad );\n\t}\n#endif";var clipping_planes_fragment="#if NUM_CLIPPING_PLANES > 0\n\tvec4 plane;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\n\t\tplane = clippingPlanes[ i ];\n\t\tif ( dot( vClipPosition, plane.xyz ) > plane.w ) discard;\n\t}\n\t#pragma unroll_loop_end\n\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n\t\tbool clipped = true;\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n\t\t\tplane = clippingPlanes[ i ];\n\t\t\tclipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t\tif ( clipped ) discard;\n\t#endif\n#endif";var clipping_planes_pars_fragment="#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif";var clipping_planes_pars_vertex="#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif";var clipping_planes_vertex="#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif";var color_fragment="#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";var color_pars_fragment="#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";var color_pars_vertex="#if defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvarying vec3 vColor;\n#endif";var color_vertex="#if defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvColor = vec3( 1.0 );\n#endif\n#ifdef USE_COLOR\n\tvColor.xyz *= color.xyz;\n#endif\n#ifdef USE_INSTANCING_COLOR\n\tvColor.xyz *= instanceColor.xyz;\n#endif";var common="#define PI 3.141592653589793\n#define PI2 6.283185307179586\n#define PI_HALF 1.5707963267948966\n#define RECIPROCAL_PI 0.3183098861837907\n#define RECIPROCAL_PI2 0.15915494309189535\n#define EPSILON 1e-6\n#ifndef saturate\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#endif\n#define whiteComplement(a) ( 1.0 - saturate( a ) )\nfloat pow2( const in float x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }\nhighp float rand( const in vec2 uv ) {\n\tconst highp float a = 12.9898, b = 78.233, c = 43758.5453;\n\thighp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n\treturn fract(sin(sn) * c);\n}\n#ifdef HIGH_PRECISION\n\tfloat precisionSafeLength( vec3 v ) { return length( v ); }\n#else\n\tfloat max3( vec3 v ) { return max( max( v.x, v.y ), v.z ); }\n\tfloat precisionSafeLength( vec3 v ) {\n\t\tfloat maxComponent = max3( abs( v ) );\n\t\treturn length( v / maxComponent ) * maxComponent;\n\t}\n#endif\nstruct IncidentLight {\n\tvec3 color;\n\tvec3 direction;\n\tbool visible;\n};\nstruct ReflectedLight {\n\tvec3 directDiffuse;\n\tvec3 directSpecular;\n\tvec3 indirectDiffuse;\n\tvec3 indirectSpecular;\n};\nstruct GeometricContext {\n\tvec3 position;\n\tvec3 normal;\n\tvec3 viewDir;\n#ifdef CLEARCOAT\n\tvec3 clearcoatNormal;\n#endif\n};\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n}\nvec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\tfloat distance = dot( planeNormal, point - pointOnPlane );\n\treturn - distance * planeNormal + point;\n}\nfloat sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\treturn sign( dot( point - pointOnPlane, planeNormal ) );\n}\nvec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\treturn lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;\n}\nmat3 transposeMat3( const in mat3 m ) {\n\tmat3 tmp;\n\ttmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );\n\ttmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );\n\ttmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );\n\treturn tmp;\n}\nfloat linearToRelativeLuminance( const in vec3 color ) {\n\tvec3 weights = vec3( 0.2126, 0.7152, 0.0722 );\n\treturn dot( weights, color.rgb );\n}\nbool isPerspectiveMatrix( mat4 m ) {\n\treturn m[ 2 ][ 3 ] == - 1.0;\n}\nvec2 equirectUv( in vec3 dir ) {\n\tfloat u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5;\n\tfloat v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\treturn vec2( u, v );\n}";var cube_uv_reflection_fragment="#ifdef ENVMAP_TYPE_CUBE_UV\n\t#define cubeUV_maxMipLevel 8.0\n\t#define cubeUV_minMipLevel 4.0\n\t#define cubeUV_maxTileSize 256.0\n\t#define cubeUV_minTileSize 16.0\n\tfloat getFace( vec3 direction ) {\n\t\tvec3 absDirection = abs( direction );\n\t\tfloat face = - 1.0;\n\t\tif ( absDirection.x > absDirection.z ) {\n\t\t\tif ( absDirection.x > absDirection.y )\n\t\t\t\tface = direction.x > 0.0 ? 0.0 : 3.0;\n\t\t\telse\n\t\t\t\tface = direction.y > 0.0 ? 1.0 : 4.0;\n\t\t} else {\n\t\t\tif ( absDirection.z > absDirection.y )\n\t\t\t\tface = direction.z > 0.0 ? 2.0 : 5.0;\n\t\t\telse\n\t\t\t\tface = direction.y > 0.0 ? 1.0 : 4.0;\n\t\t}\n\t\treturn face;\n\t}\n\tvec2 getUV( vec3 direction, float face ) {\n\t\tvec2 uv;\n\t\tif ( face == 0.0 ) {\n\t\t\tuv = vec2( direction.z, direction.y ) / abs( direction.x );\n\t\t} else if ( face == 1.0 ) {\n\t\t\tuv = vec2( - direction.x, - direction.z ) / abs( direction.y );\n\t\t} else if ( face == 2.0 ) {\n\t\t\tuv = vec2( - direction.x, direction.y ) / abs( direction.z );\n\t\t} else if ( face == 3.0 ) {\n\t\t\tuv = vec2( - direction.z, direction.y ) / abs( direction.x );\n\t\t} else if ( face == 4.0 ) {\n\t\t\tuv = vec2( - direction.x, direction.z ) / abs( direction.y );\n\t\t} else {\n\t\t\tuv = vec2( direction.x, direction.y ) / abs( direction.z );\n\t\t}\n\t\treturn 0.5 * ( uv + 1.0 );\n\t}\n\tvec3 bilinearCubeUV( sampler2D envMap, vec3 direction, float mipInt ) {\n\t\tfloat face = getFace( direction );\n\t\tfloat filterInt = max( cubeUV_minMipLevel - mipInt, 0.0 );\n\t\tmipInt = max( mipInt, cubeUV_minMipLevel );\n\t\tfloat faceSize = exp2( mipInt );\n\t\tfloat texelSize = 1.0 / ( 3.0 * cubeUV_maxTileSize );\n\t\tvec2 uv = getUV( direction, face ) * ( faceSize - 1.0 );\n\t\tvec2 f = fract( uv );\n\t\tuv += 0.5 - f;\n\t\tif ( face > 2.0 ) {\n\t\t\tuv.y += faceSize;\n\t\t\tface -= 3.0;\n\t\t}\n\t\tuv.x += face * faceSize;\n\t\tif ( mipInt < cubeUV_maxMipLevel ) {\n\t\t\tuv.y += 2.0 * cubeUV_maxTileSize;\n\t\t}\n\t\tuv.y += filterInt * 2.0 * cubeUV_minTileSize;\n\t\tuv.x += 3.0 * max( 0.0, cubeUV_maxTileSize - 2.0 * faceSize );\n\t\tuv *= texelSize;\n\t\tvec3 tl = envMapTexelToLinear( texture2D( envMap, uv ) ).rgb;\n\t\tuv.x += texelSize;\n\t\tvec3 tr = envMapTexelToLinear( texture2D( envMap, uv ) ).rgb;\n\t\tuv.y += texelSize;\n\t\tvec3 br = envMapTexelToLinear( texture2D( envMap, uv ) ).rgb;\n\t\tuv.x -= texelSize;\n\t\tvec3 bl = envMapTexelToLinear( texture2D( envMap, uv ) ).rgb;\n\t\tvec3 tm = mix( tl, tr, f.x );\n\t\tvec3 bm = mix( bl, br, f.x );\n\t\treturn mix( tm, bm, f.y );\n\t}\n\t#define r0 1.0\n\t#define v0 0.339\n\t#define m0 - 2.0\n\t#define r1 0.8\n\t#define v1 0.276\n\t#define m1 - 1.0\n\t#define r4 0.4\n\t#define v4 0.046\n\t#define m4 2.0\n\t#define r5 0.305\n\t#define v5 0.016\n\t#define m5 3.0\n\t#define r6 0.21\n\t#define v6 0.0038\n\t#define m6 4.0\n\tfloat roughnessToMip( float roughness ) {\n\t\tfloat mip = 0.0;\n\t\tif ( roughness >= r1 ) {\n\t\t\tmip = ( r0 - roughness ) * ( m1 - m0 ) / ( r0 - r1 ) + m0;\n\t\t} else if ( roughness >= r4 ) {\n\t\t\tmip = ( r1 - roughness ) * ( m4 - m1 ) / ( r1 - r4 ) + m1;\n\t\t} else if ( roughness >= r5 ) {\n\t\t\tmip = ( r4 - roughness ) * ( m5 - m4 ) / ( r4 - r5 ) + m4;\n\t\t} else if ( roughness >= r6 ) {\n\t\t\tmip = ( r5 - roughness ) * ( m6 - m5 ) / ( r5 - r6 ) + m5;\n\t\t} else {\n\t\t\tmip = - 2.0 * log2( 1.16 * roughness );\t\t}\n\t\treturn mip;\n\t}\n\tvec4 textureCubeUV( sampler2D envMap, vec3 sampleDir, float roughness ) {\n\t\tfloat mip = clamp( roughnessToMip( roughness ), m0, cubeUV_maxMipLevel );\n\t\tfloat mipF = fract( mip );\n\t\tfloat mipInt = floor( mip );\n\t\tvec3 color0 = bilinearCubeUV( envMap, sampleDir, mipInt );\n\t\tif ( mipF == 0.0 ) {\n\t\t\treturn vec4( color0, 1.0 );\n\t\t} else {\n\t\t\tvec3 color1 = bilinearCubeUV( envMap, sampleDir, mipInt + 1.0 );\n\t\t\treturn vec4( mix( color0, color1, mipF ), 1.0 );\n\t\t}\n\t}\n#endif";var defaultnormal_vertex="vec3 transformedNormal = objectNormal;\n#ifdef USE_INSTANCING\n\tmat3 m = mat3( instanceMatrix );\n\ttransformedNormal /= vec3( dot( m[ 0 ], m[ 0 ] ), dot( m[ 1 ], m[ 1 ] ), dot( m[ 2 ], m[ 2 ] ) );\n\ttransformedNormal = m * transformedNormal;\n#endif\ntransformedNormal = normalMatrix * transformedNormal;\n#ifdef FLIP_SIDED\n\ttransformedNormal = - transformedNormal;\n#endif\n#ifdef USE_TANGENT\n\tvec3 transformedTangent = ( modelViewMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n\t#ifdef FLIP_SIDED\n\t\ttransformedTangent = - transformedTangent;\n\t#endif\n#endif";var displacementmap_pars_vertex="#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";var displacementmap_vertex="#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );\n#endif";var emissivemap_fragment="#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";var emissivemap_pars_fragment="#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";var encodings_fragment="gl_FragColor = linearToOutputTexel( gl_FragColor );";var encodings_pars_fragment="\nvec4 LinearToLinear( in vec4 value ) {\n\treturn value;\n}\nvec4 GammaToLinear( in vec4 value, in float gammaFactor ) {\n\treturn vec4( pow( value.rgb, vec3( gammaFactor ) ), value.a );\n}\nvec4 LinearToGamma( in vec4 value, in float gammaFactor ) {\n\treturn vec4( pow( value.rgb, vec3( 1.0 / gammaFactor ) ), value.a );\n}\nvec4 sRGBToLinear( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.a );\n}\nvec4 LinearTosRGB( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a );\n}\nvec4 RGBEToLinear( in vec4 value ) {\n\treturn vec4( value.rgb * exp2( value.a * 255.0 - 128.0 ), 1.0 );\n}\nvec4 LinearToRGBE( in vec4 value ) {\n\tfloat maxComponent = max( max( value.r, value.g ), value.b );\n\tfloat fExp = clamp( ceil( log2( maxComponent ) ), -128.0, 127.0 );\n\treturn vec4( value.rgb / exp2( fExp ), ( fExp + 128.0 ) / 255.0 );\n}\nvec4 RGBMToLinear( in vec4 value, in float maxRange ) {\n\treturn vec4( value.rgb * value.a * maxRange, 1.0 );\n}\nvec4 LinearToRGBM( in vec4 value, in float maxRange ) {\n\tfloat maxRGB = max( value.r, max( value.g, value.b ) );\n\tfloat M = clamp( maxRGB / maxRange, 0.0, 1.0 );\n\tM = ceil( M * 255.0 ) / 255.0;\n\treturn vec4( value.rgb / ( M * maxRange ), M );\n}\nvec4 RGBDToLinear( in vec4 value, in float maxRange ) {\n\treturn vec4( value.rgb * ( ( maxRange / 255.0 ) / value.a ), 1.0 );\n}\nvec4 LinearToRGBD( in vec4 value, in float maxRange ) {\n\tfloat maxRGB = max( value.r, max( value.g, value.b ) );\n\tfloat D = max( maxRange / maxRGB, 1.0 );\n\tD = clamp( floor( D ) / 255.0, 0.0, 1.0 );\n\treturn vec4( value.rgb * ( D * ( 255.0 / maxRange ) ), D );\n}\nconst mat3 cLogLuvM = mat3( 0.2209, 0.3390, 0.4184, 0.1138, 0.6780, 0.7319, 0.0102, 0.1130, 0.2969 );\nvec4 LinearToLogLuv( in vec4 value ) {\n\tvec3 Xp_Y_XYZp = cLogLuvM * value.rgb;\n\tXp_Y_XYZp = max( Xp_Y_XYZp, vec3( 1e-6, 1e-6, 1e-6 ) );\n\tvec4 vResult;\n\tvResult.xy = Xp_Y_XYZp.xy / Xp_Y_XYZp.z;\n\tfloat Le = 2.0 * log2(Xp_Y_XYZp.y) + 127.0;\n\tvResult.w = fract( Le );\n\tvResult.z = ( Le - ( floor( vResult.w * 255.0 ) ) / 255.0 ) / 255.0;\n\treturn vResult;\n}\nconst mat3 cLogLuvInverseM = mat3( 6.0014, -2.7008, -1.7996, -1.3320, 3.1029, -5.7721, 0.3008, -1.0882, 5.6268 );\nvec4 LogLuvToLinear( in vec4 value ) {\n\tfloat Le = value.z * 255.0 + value.w;\n\tvec3 Xp_Y_XYZp;\n\tXp_Y_XYZp.y = exp2( ( Le - 127.0 ) / 2.0 );\n\tXp_Y_XYZp.z = Xp_Y_XYZp.y / value.y;\n\tXp_Y_XYZp.x = value.x * Xp_Y_XYZp.z;\n\tvec3 vRGB = cLogLuvInverseM * Xp_Y_XYZp.rgb;\n\treturn vec4( max( vRGB, 0.0 ), 1.0 );\n}";var envmap_fragment="#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvec3 cameraToFrag;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToFrag = normalize( vWorldPosition - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( cameraToFrag, worldNormal );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );\n\t\t#endif\n\t#else\n\t\tvec3 reflectVec = vReflect;\n\t#endif\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 envColor = textureCube( envMap, vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\tvec4 envColor = textureCubeUV( envMap, reflectVec, 0.0 );\n\t#else\n\t\tvec4 envColor = vec4( 0.0 );\n\t#endif\n\t#ifndef ENVMAP_TYPE_CUBE_UV\n\t\tenvColor = envMapTexelToLinear( envColor );\n\t#endif\n\t#ifdef ENVMAP_BLENDING_MULTIPLY\n\t\toutgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_MIX )\n\t\toutgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_ADD )\n\t\toutgoingLight += envColor.xyz * specularStrength * reflectivity;\n\t#endif\n#endif";var envmap_common_pars_fragment="#ifdef USE_ENVMAP\n\tuniform float envMapIntensity;\n\tuniform float flipEnvMap;\n\tuniform int maxMipLevel;\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tuniform samplerCube envMap;\n\t#else\n\t\tuniform sampler2D envMap;\n\t#endif\n\t\n#endif";var envmap_pars_fragment="#ifdef USE_ENVMAP\n\tuniform float reflectivity;\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\t\t#define ENV_WORLDPOS\n\t#endif\n\t#ifdef ENV_WORLDPOS\n\t\tvarying vec3 vWorldPosition;\n\t\tuniform float refractionRatio;\n\t#else\n\t\tvarying vec3 vReflect;\n\t#endif\n#endif";var envmap_pars_vertex="#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) ||defined( PHONG )\n\t\t#define ENV_WORLDPOS\n\t#endif\n\t#ifdef ENV_WORLDPOS\n\t\t\n\t\tvarying vec3 vWorldPosition;\n\t#else\n\t\tvarying vec3 vReflect;\n\t\tuniform float refractionRatio;\n\t#endif\n#endif";var envmap_vertex="#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvWorldPosition = worldPosition.xyz;\n\t#else\n\t\tvec3 cameraToVertex;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToVertex = normalize( worldPosition.xyz - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvReflect = reflect( cameraToVertex, worldNormal );\n\t\t#else\n\t\t\tvReflect = refract( cameraToVertex, worldNormal, refractionRatio );\n\t\t#endif\n\t#endif\n#endif";var fog_vertex="#ifdef USE_FOG\n\tfogDepth = - mvPosition.z;\n#endif";var fog_pars_vertex="#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";var fog_fragment="#ifdef USE_FOG\n\t#ifdef FOG_EXP2\n\t\tfloat fogFactor = 1.0 - exp( - fogDensity * fogDensity * fogDepth * fogDepth );\n\t#else\n\t\tfloat fogFactor = smoothstep( fogNear, fogFar, fogDepth );\n\t#endif\n\tgl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );\n#endif";var fog_pars_fragment="#ifdef USE_FOG\n\tuniform vec3 fogColor;\n\tvarying float fogDepth;\n\t#ifdef FOG_EXP2\n\t\tuniform float fogDensity;\n\t#else\n\t\tuniform float fogNear;\n\t\tuniform float fogFar;\n\t#endif\n#endif";var gradientmap_pars_fragment="#ifdef USE_GRADIENTMAP\n\tuniform sampler2D gradientMap;\n#endif\nvec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {\n\tfloat dotNL = dot( normal, lightDirection );\n\tvec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );\n\t#ifdef USE_GRADIENTMAP\n\t\treturn texture2D( gradientMap, coord ).rgb;\n\t#else\n\t\treturn ( coord.x < 0.7 ) ? vec3( 0.7 ) : vec3( 1.0 );\n\t#endif\n}";var lightmap_fragment="#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\treflectedLight.indirectDiffuse += PI * lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n#endif";var lightmap_pars_fragment="#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";var lights_lambert_vertex="vec3 diffuse = vec3( 1.0 );\nGeometricContext geometry;\ngeometry.position = mvPosition.xyz;\ngeometry.normal = normalize( transformedNormal );\ngeometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( -mvPosition.xyz );\nGeometricContext backGeometry;\nbackGeometry.position = geometry.position;\nbackGeometry.normal = -geometry.normal;\nbackGeometry.viewDir = geometry.viewDir;\nvLightFront = vec3( 0.0 );\nvIndirectFront = vec3( 0.0 );\n#ifdef DOUBLE_SIDED\n\tvLightBack = vec3( 0.0 );\n\tvIndirectBack = vec3( 0.0 );\n#endif\nIncidentLight directLight;\nfloat dotNL;\nvec3 directLightColor_Diffuse;\nvIndirectFront += getAmbientLightIrradiance( ambientLightColor );\nvIndirectFront += getLightProbeIrradiance( lightProbe, geometry );\n#ifdef DOUBLE_SIDED\n\tvIndirectBack += getAmbientLightIrradiance( ambientLightColor );\n\tvIndirectBack += getLightProbeIrradiance( lightProbe, backGeometry );\n#endif\n#if NUM_POINT_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tgetPointDirectLightIrradiance( pointLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tgetSpotDirectLightIrradiance( spotLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if NUM_DIR_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tgetDirectionalDirectLightIrradiance( directionalLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\tvIndirectFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvIndirectBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry );\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif";var lights_pars_begin="uniform bool receiveShadow;\nuniform vec3 ambientLightColor;\nuniform vec3 lightProbe[ 9 ];\nvec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {\n\tfloat x = normal.x, y = normal.y, z = normal.z;\n\tvec3 result = shCoefficients[ 0 ] * 0.886227;\n\tresult += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;\n\tresult += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;\n\tresult += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;\n\tresult += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;\n\tresult += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;\n\tresult += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );\n\tresult += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;\n\tresult += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );\n\treturn result;\n}\nvec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in GeometricContext geometry ) {\n\tvec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );\n\tvec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );\n\treturn irradiance;\n}\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n\tvec3 irradiance = ambientLightColor;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\treturn irradiance;\n}\n#if NUM_DIR_LIGHTS > 0\n\tstruct DirectionalLight {\n\t\tvec3 direction;\n\t\tvec3 color;\n\t};\n\tuniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n\tvoid getDirectionalDirectLightIrradiance( const in DirectionalLight directionalLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tdirectLight.color = directionalLight.color;\n\t\tdirectLight.direction = directionalLight.direction;\n\t\tdirectLight.visible = true;\n\t}\n#endif\n#if NUM_POINT_LIGHTS > 0\n\tstruct PointLight {\n\t\tvec3 position;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t};\n\tuniform PointLight pointLights[ NUM_POINT_LIGHTS ];\n\tvoid getPointDirectLightIrradiance( const in PointLight pointLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tvec3 lVector = pointLight.position - geometry.position;\n\t\tdirectLight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tdirectLight.color = pointLight.color;\n\t\tdirectLight.color *= punctualLightIntensityToIrradianceFactor( lightDistance, pointLight.distance, pointLight.decay );\n\t\tdirectLight.visible = ( directLight.color != vec3( 0.0 ) );\n\t}\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\tstruct SpotLight {\n\t\tvec3 position;\n\t\tvec3 direction;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t\tfloat coneCos;\n\t\tfloat penumbraCos;\n\t};\n\tuniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\n\tvoid getSpotDirectLightIrradiance( const in SpotLight spotLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tvec3 lVector = spotLight.position - geometry.position;\n\t\tdirectLight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tfloat angleCos = dot( directLight.direction, spotLight.direction );\n\t\tif ( angleCos > spotLight.coneCos ) {\n\t\t\tfloat spotEffect = smoothstep( spotLight.coneCos, spotLight.penumbraCos, angleCos );\n\t\t\tdirectLight.color = spotLight.color;\n\t\t\tdirectLight.color *= spotEffect * punctualLightIntensityToIrradianceFactor( lightDistance, spotLight.distance, spotLight.decay );\n\t\t\tdirectLight.visible = true;\n\t\t} else {\n\t\t\tdirectLight.color = vec3( 0.0 );\n\t\t\tdirectLight.visible = false;\n\t\t}\n\t}\n#endif\n#if NUM_RECT_AREA_LIGHTS > 0\n\tstruct RectAreaLight {\n\t\tvec3 color;\n\t\tvec3 position;\n\t\tvec3 halfWidth;\n\t\tvec3 halfHeight;\n\t};\n\tuniform sampler2D ltc_1;\tuniform sampler2D ltc_2;\n\tuniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\tstruct HemisphereLight {\n\t\tvec3 direction;\n\t\tvec3 skyColor;\n\t\tvec3 groundColor;\n\t};\n\tuniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\n\tvec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in GeometricContext geometry ) {\n\t\tfloat dotNL = dot( geometry.normal, hemiLight.direction );\n\t\tfloat hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n\t\tvec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tirradiance *= PI;\n\t\t#endif\n\t\treturn irradiance;\n\t}\n#endif";var envmap_physical_pars_fragment="#if defined( USE_ENVMAP )\n\t#ifdef ENVMAP_MODE_REFRACTION\n\t\tuniform float refractionRatio;\n\t#endif\n\tvec3 getLightProbeIndirectIrradiance( const in GeometricContext geometry, const in int maxMIPLevel ) {\n\t\tvec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );\n\t\t#ifdef ENVMAP_TYPE_CUBE\n\t\t\tvec3 queryVec = vec3( flipEnvMap * worldNormal.x, worldNormal.yz );\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = textureCubeLodEXT( envMap, queryVec, float( maxMIPLevel ) );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = textureCube( envMap, queryVec, float( maxMIPLevel ) );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, worldNormal, 1.0 );\n\t\t#else\n\t\t\tvec4 envMapColor = vec4( 0.0 );\n\t\t#endif\n\t\treturn PI * envMapColor.rgb * envMapIntensity;\n\t}\n\tfloat getSpecularMIPLevel( const in float roughness, const in int maxMIPLevel ) {\n\t\tfloat maxMIPLevelScalar = float( maxMIPLevel );\n\t\tfloat sigma = PI * roughness * roughness / ( 1.0 + roughness );\n\t\tfloat desiredMIPLevel = maxMIPLevelScalar + log2( sigma );\n\t\treturn clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );\n\t}\n\tvec3 getLightProbeIndirectRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in int maxMIPLevel ) {\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( -viewDir, normal );\n\t\t\treflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( -viewDir, normal, refractionRatio );\n\t\t#endif\n\t\treflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n\t\tfloat specularMIPLevel = getSpecularMIPLevel( roughness, maxMIPLevel );\n\t\t#ifdef ENVMAP_TYPE_CUBE\n\t\t\tvec3 queryReflectVec = vec3( flipEnvMap * reflectVec.x, reflectVec.yz );\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = textureCubeLodEXT( envMap, queryReflectVec, specularMIPLevel );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = textureCube( envMap, queryReflectVec, specularMIPLevel );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, reflectVec, roughness );\n\t\t#endif\n\t\treturn envMapColor.rgb * envMapIntensity;\n\t}\n#endif";var lights_toon_fragment="ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;";var lights_toon_pars_fragment="varying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\nstruct ToonMaterial {\n\tvec3 diffuseColor;\n};\nvoid RE_Direct_Toon( const in IncidentLight directLight, const in GeometricContext geometry, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n\tvec3 irradiance = getGradientIrradiance( geometry.normal, directLight.direction ) * directLight.color;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\treflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in GeometricContext geometry, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_Toon\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Toon\n#define Material_LightProbeLOD( material )\t(0)";var lights_phong_fragment="BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";var lights_phong_pars_fragment="varying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\nstruct BlinnPhongMaterial {\n\tvec3 diffuseColor;\n\tvec3 specularColor;\n\tfloat specularShininess;\n\tfloat specularStrength;\n};\nvoid RE_Direct_BlinnPhong( const in IncidentLight directLight, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\treflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n\treflectedLight.directSpecular += irradiance * BRDF_Specular_BlinnPhong( directLight, geometry, material.specularColor, material.specularShininess ) * material.specularStrength;\n}\nvoid RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_BlinnPhong\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_BlinnPhong\n#define Material_LightProbeLOD( material )\t(0)";var lights_physical_fragment="PhysicalMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nvec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );\nfloat geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );\nmaterial.specularRoughness = max( roughnessFactor, 0.0525 );material.specularRoughness += geometryRoughness;\nmaterial.specularRoughness = min( material.specularRoughness, 1.0 );\n#ifdef REFLECTIVITY\n\tmaterial.specularColor = mix( vec3( MAXIMUM_SPECULAR_COEFFICIENT * pow2( reflectivity ) ), diffuseColor.rgb, metalnessFactor );\n#else\n\tmaterial.specularColor = mix( vec3( DEFAULT_SPECULAR_COEFFICIENT ), diffuseColor.rgb, metalnessFactor );\n#endif\n#ifdef CLEARCOAT\n\tmaterial.clearcoat = clearcoat;\n\tmaterial.clearcoatRoughness = clearcoatRoughness;\n\t#ifdef USE_CLEARCOATMAP\n\t\tmaterial.clearcoat *= texture2D( clearcoatMap, vUv ).x;\n\t#endif\n\t#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\t\tmaterial.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vUv ).y;\n\t#endif\n\tmaterial.clearcoat = saturate( material.clearcoat );\tmaterial.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 );\n\tmaterial.clearcoatRoughness += geometryRoughness;\n\tmaterial.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );\n#endif\n#ifdef USE_SHEEN\n\tmaterial.sheenColor = sheen;\n#endif";var lights_physical_pars_fragment="struct PhysicalMaterial {\n\tvec3 diffuseColor;\n\tfloat specularRoughness;\n\tvec3 specularColor;\n#ifdef CLEARCOAT\n\tfloat clearcoat;\n\tfloat clearcoatRoughness;\n#endif\n#ifdef USE_SHEEN\n\tvec3 sheenColor;\n#endif\n};\n#define MAXIMUM_SPECULAR_COEFFICIENT 0.16\n#define DEFAULT_SPECULAR_COEFFICIENT 0.04\nfloat clearcoatDHRApprox( const in float roughness, const in float dotNL ) {\n\treturn DEFAULT_SPECULAR_COEFFICIENT + ( 1.0 - DEFAULT_SPECULAR_COEFFICIENT ) * ( pow( 1.0 - dotNL, 5.0 ) * pow( 1.0 - roughness, 2.0 ) );\n}\n#if NUM_RECT_AREA_LIGHTS > 0\n\tvoid RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\t\tvec3 normal = geometry.normal;\n\t\tvec3 viewDir = geometry.viewDir;\n\t\tvec3 position = geometry.position;\n\t\tvec3 lightPos = rectAreaLight.position;\n\t\tvec3 halfWidth = rectAreaLight.halfWidth;\n\t\tvec3 halfHeight = rectAreaLight.halfHeight;\n\t\tvec3 lightColor = rectAreaLight.color;\n\t\tfloat roughness = material.specularRoughness;\n\t\tvec3 rectCoords[ 4 ];\n\t\trectCoords[ 0 ] = lightPos + halfWidth - halfHeight;\t\trectCoords[ 1 ] = lightPos - halfWidth - halfHeight;\n\t\trectCoords[ 2 ] = lightPos - halfWidth + halfHeight;\n\t\trectCoords[ 3 ] = lightPos + halfWidth + halfHeight;\n\t\tvec2 uv = LTC_Uv( normal, viewDir, roughness );\n\t\tvec4 t1 = texture2D( ltc_1, uv );\n\t\tvec4 t2 = texture2D( ltc_2, uv );\n\t\tmat3 mInv = mat3(\n\t\t\tvec3( t1.x, 0, t1.y ),\n\t\t\tvec3( 0, 1, 0 ),\n\t\t\tvec3( t1.z, 0, t1.w )\n\t\t);\n\t\tvec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y );\n\t\treflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );\n\t\treflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );\n\t}\n#endif\nvoid RE_Direct_Physical( const in IncidentLight directLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\t#ifdef CLEARCOAT\n\t\tfloat ccDotNL = saturate( dot( geometry.clearcoatNormal, directLight.direction ) );\n\t\tvec3 ccIrradiance = ccDotNL * directLight.color;\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tccIrradiance *= PI;\n\t\t#endif\n\t\tfloat clearcoatDHR = material.clearcoat * clearcoatDHRApprox( material.clearcoatRoughness, ccDotNL );\n\t\treflectedLight.directSpecular += ccIrradiance * material.clearcoat * BRDF_Specular_GGX( directLight, geometry.viewDir, geometry.clearcoatNormal, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearcoatRoughness );\n\t#else\n\t\tfloat clearcoatDHR = 0.0;\n\t#endif\n\t#ifdef USE_SHEEN\n\t\treflectedLight.directSpecular += ( 1.0 - clearcoatDHR ) * irradiance * BRDF_Specular_Sheen(\n\t\t\tmaterial.specularRoughness,\n\t\t\tdirectLight.direction,\n\t\t\tgeometry,\n\t\t\tmaterial.sheenColor\n\t\t);\n\t#else\n\t\treflectedLight.directSpecular += ( 1.0 - clearcoatDHR ) * irradiance * BRDF_Specular_GGX( directLight, geometry.viewDir, geometry.normal, material.specularColor, material.specularRoughness);\n\t#endif\n\treflectedLight.directDiffuse += ( 1.0 - clearcoatDHR ) * irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {\n\t#ifdef CLEARCOAT\n\t\tfloat ccDotNV = saturate( dot( geometry.clearcoatNormal, geometry.viewDir ) );\n\t\treflectedLight.indirectSpecular += clearcoatRadiance * material.clearcoat * BRDF_Specular_GGX_Environment( geometry.viewDir, geometry.clearcoatNormal, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearcoatRoughness );\n\t\tfloat ccDotNL = ccDotNV;\n\t\tfloat clearcoatDHR = material.clearcoat * clearcoatDHRApprox( material.clearcoatRoughness, ccDotNL );\n\t#else\n\t\tfloat clearcoatDHR = 0.0;\n\t#endif\n\tfloat clearcoatInv = 1.0 - clearcoatDHR;\n\tvec3 singleScattering = vec3( 0.0 );\n\tvec3 multiScattering = vec3( 0.0 );\n\tvec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;\n\tBRDF_Specular_Multiscattering_Environment( geometry, material.specularColor, material.specularRoughness, singleScattering, multiScattering );\n\tvec3 diffuse = material.diffuseColor * ( 1.0 - ( singleScattering + multiScattering ) );\n\treflectedLight.indirectSpecular += clearcoatInv * radiance * singleScattering;\n\treflectedLight.indirectSpecular += multiScattering * cosineWeightedIrradiance;\n\treflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance;\n}\n#define RE_Direct\t\t\t\tRE_Direct_Physical\n#define RE_Direct_RectArea\t\tRE_Direct_RectArea_Physical\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Physical\n#define RE_IndirectSpecular\t\tRE_IndirectSpecular_Physical\nfloat computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {\n\treturn saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\n}";var lights_fragment_begin="\nGeometricContext geometry;\ngeometry.position = - vViewPosition;\ngeometry.normal = normal;\ngeometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );\n#ifdef CLEARCOAT\n\tgeometry.clearcoatNormal = clearcoatNormal;\n#endif\nIncidentLight directLight;\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\tPointLight pointLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tpointLight = pointLights[ i ];\n\t\tgetPointDirectLightIrradiance( pointLight, geometry, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )\n\t\tpointLightShadow = pointLightShadows[ i ];\n\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n\tSpotLight spotLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tspotLight = spotLights[ i ];\n\t\tgetSpotDirectLightIrradiance( spotLight, geometry, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\tspotLightShadow = spotLightShadows[ i ];\n\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n\tDirectionalLight directionalLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tgetDirectionalDirectLightIrradiance( directionalLight, geometry, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n\tRectAreaLight rectAreaLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n\t\trectAreaLight = rectAreaLights[ i ];\n\t\tRE_Direct_RectArea( rectAreaLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if defined( RE_IndirectDiffuse )\n\tvec3 iblIrradiance = vec3( 0.0 );\n\tvec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\tirradiance += getLightProbeIrradiance( lightProbe, geometry );\n\t#if ( NUM_HEMI_LIGHTS > 0 )\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\t\tirradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n#endif\n#if defined( RE_IndirectSpecular )\n\tvec3 radiance = vec3( 0.0 );\n\tvec3 clearcoatRadiance = vec3( 0.0 );\n#endif";var lights_fragment_maps="#if defined( RE_IndirectDiffuse )\n\t#ifdef USE_LIGHTMAP\n\t\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\t\tvec3 lightMapIrradiance = lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tlightMapIrradiance *= PI;\n\t\t#endif\n\t\tirradiance += lightMapIrradiance;\n\t#endif\n\t#if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )\n\t\tiblIrradiance += getLightProbeIndirectIrradiance( geometry, maxMipLevel );\n\t#endif\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n\tradiance += getLightProbeIndirectRadiance( geometry.viewDir, geometry.normal, material.specularRoughness, maxMipLevel );\n\t#ifdef CLEARCOAT\n\t\tclearcoatRadiance += getLightProbeIndirectRadiance( geometry.viewDir, geometry.clearcoatNormal, material.clearcoatRoughness, maxMipLevel );\n\t#endif\n#endif";var lights_fragment_end="#if defined( RE_IndirectDiffuse )\n\tRE_IndirectDiffuse( irradiance, geometry, material, reflectedLight );\n#endif\n#if defined( RE_IndirectSpecular )\n\tRE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometry, material, reflectedLight );\n#endif";var logdepthbuf_fragment="#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tgl_FragDepthEXT = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif";var logdepthbuf_pars_fragment="#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tuniform float logDepthBufFC;\n\tvarying float vFragDepth;\n\tvarying float vIsPerspective;\n#endif";var logdepthbuf_pars_vertex="#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvarying float vFragDepth;\n\t\tvarying float vIsPerspective;\n\t#else\n\t\tuniform float logDepthBufFC;\n\t#endif\n#endif";var logdepthbuf_vertex="#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvFragDepth = 1.0 + gl_Position.w;\n\t\tvIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );\n\t#else\n\t\tif ( isPerspectiveMatrix( projectionMatrix ) ) {\n\t\t\tgl_Position.z = log2( max( EPSILON, gl_Position.w + 1.0 ) ) * logDepthBufFC - 1.0;\n\t\t\tgl_Position.z *= gl_Position.w;\n\t\t}\n\t#endif\n#endif";var map_fragment="#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";var map_pars_fragment="#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";var map_particle_fragment="#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\tvec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;\n#endif\n#ifdef USE_MAP\n\tvec4 mapTexel = texture2D( map, uv );\n\tdiffuseColor *= mapTexelToLinear( mapTexel );\n#endif\n#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, uv ).g;\n#endif";var map_particle_pars_fragment="#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\tuniform mat3 uvTransform;\n#endif\n#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif\n#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";var metalnessmap_fragment="float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";var metalnessmap_pars_fragment="#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";var morphnormal_vertex="#ifdef USE_MORPHNORMALS\n\tobjectNormal *= morphTargetBaseInfluence;\n\tobjectNormal += morphNormal0 * morphTargetInfluences[ 0 ];\n\tobjectNormal += morphNormal1 * morphTargetInfluences[ 1 ];\n\tobjectNormal += morphNormal2 * morphTargetInfluences[ 2 ];\n\tobjectNormal += morphNormal3 * morphTargetInfluences[ 3 ];\n#endif";var morphtarget_pars_vertex="#ifdef USE_MORPHTARGETS\n\tuniform float morphTargetBaseInfluence;\n\t#ifndef USE_MORPHNORMALS\n\t\tuniform float morphTargetInfluences[ 8 ];\n\t#else\n\t\tuniform float morphTargetInfluences[ 4 ];\n\t#endif\n#endif";var morphtarget_vertex="#ifdef USE_MORPHTARGETS\n\ttransformed *= morphTargetBaseInfluence;\n\ttransformed += morphTarget0 * morphTargetInfluences[ 0 ];\n\ttransformed += morphTarget1 * morphTargetInfluences[ 1 ];\n\ttransformed += morphTarget2 * morphTargetInfluences[ 2 ];\n\ttransformed += morphTarget3 * morphTargetInfluences[ 3 ];\n\t#ifndef USE_MORPHNORMALS\n\t\ttransformed += morphTarget4 * morphTargetInfluences[ 4 ];\n\t\ttransformed += morphTarget5 * morphTargetInfluences[ 5 ];\n\t\ttransformed += morphTarget6 * morphTargetInfluences[ 6 ];\n\t\ttransformed += morphTarget7 * morphTargetInfluences[ 7 ];\n\t#endif\n#endif";var normal_fragment_begin="#ifdef FLAT_SHADED\n\tvec3 fdx = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );\n\tvec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );\n\tvec3 normal = normalize( cross( fdx, fdy ) );\n#else\n\tvec3 normal = normalize( vNormal );\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t#endif\n\t#ifdef USE_TANGENT\n\t\tvec3 tangent = normalize( vTangent );\n\t\tvec3 bitangent = normalize( vBitangent );\n\t\t#ifdef DOUBLE_SIDED\n\t\t\ttangent = tangent * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\t\tbitangent = bitangent * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\t#endif\n\t\t#if defined( TANGENTSPACE_NORMALMAP ) || defined( USE_CLEARCOAT_NORMALMAP )\n\t\t\tmat3 vTBN = mat3( tangent, bitangent, normal );\n\t\t#endif\n\t#endif\n#endif\nvec3 geometryNormal = normal;";var normal_fragment_maps="#ifdef OBJECTSPACE_NORMALMAP\n\tnormal = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t#ifdef FLIP_SIDED\n\t\tnormal = - normal;\n\t#endif\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t#endif\n\tnormal = normalize( normalMatrix * normal );\n#elif defined( TANGENTSPACE_NORMALMAP )\n\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\tmapN.xy *= normalScale;\n\t#ifdef USE_TANGENT\n\t\tnormal = normalize( vTBN * mapN );\n\t#else\n\t\tnormal = perturbNormal2Arb( -vViewPosition, normal, mapN );\n\t#endif\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\n#endif";var normalmap_pars_fragment="#ifdef USE_NORMALMAP\n\tuniform sampler2D normalMap;\n\tuniform vec2 normalScale;\n#endif\n#ifdef OBJECTSPACE_NORMALMAP\n\tuniform mat3 normalMatrix;\n#endif\n#if ! defined ( USE_TANGENT ) && ( defined ( TANGENTSPACE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP ) )\n\tvec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec3 mapN ) {\n\t\tvec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );\n\t\tvec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );\n\t\tvec2 st0 = dFdx( vUv.st );\n\t\tvec2 st1 = dFdy( vUv.st );\n\t\tfloat scale = sign( st1.t * st0.s - st0.t * st1.s );\n\t\tvec3 S = normalize( ( q0 * st1.t - q1 * st0.t ) * scale );\n\t\tvec3 T = normalize( ( - q0 * st1.s + q1 * st0.s ) * scale );\n\t\tvec3 N = normalize( surf_norm );\n\t\tmat3 tsn = mat3( S, T, N );\n\t\tmapN.xy *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\treturn normalize( tsn * mapN );\n\t}\n#endif";var clearcoat_normal_fragment_begin="#ifdef CLEARCOAT\n\tvec3 clearcoatNormal = geometryNormal;\n#endif";var clearcoat_normal_fragment_maps="#ifdef USE_CLEARCOAT_NORMALMAP\n\tvec3 clearcoatMapN = texture2D( clearcoatNormalMap, vUv ).xyz * 2.0 - 1.0;\n\tclearcoatMapN.xy *= clearcoatNormalScale;\n\t#ifdef USE_TANGENT\n\t\tclearcoatNormal = normalize( vTBN * clearcoatMapN );\n\t#else\n\t\tclearcoatNormal = perturbNormal2Arb( - vViewPosition, clearcoatNormal, clearcoatMapN );\n\t#endif\n#endif";var clearcoat_pars_fragment="#ifdef USE_CLEARCOATMAP\n\tuniform sampler2D clearcoatMap;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tuniform sampler2D clearcoatRoughnessMap;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tuniform sampler2D clearcoatNormalMap;\n\tuniform vec2 clearcoatNormalScale;\n#endif";var packing="vec3 packNormalToRGB( const in vec3 normal ) {\n\treturn normalize( normal ) * 0.5 + 0.5;\n}\nvec3 unpackRGBToNormal( const in vec3 rgb ) {\n\treturn 2.0 * rgb.xyz - 1.0;\n}\nconst float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;\nconst vec3 PackFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\nconst vec4 UnpackFactors = UnpackDownscale / vec4( PackFactors, 1. );\nconst float ShiftRight8 = 1. / 256.;\nvec4 packDepthToRGBA( const in float v ) {\n\tvec4 r = vec4( fract( v * PackFactors ), v );\n\tr.yzw -= r.xyz * ShiftRight8;\treturn r * PackUpscale;\n}\nfloat unpackRGBAToDepth( const in vec4 v ) {\n\treturn dot( v, UnpackFactors );\n}\nvec4 pack2HalfToRGBA( vec2 v ) {\n\tvec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ));\n\treturn vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w);\n}\nvec2 unpackRGBATo2Half( vec4 v ) {\n\treturn vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );\n}\nfloat viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( viewZ + near ) / ( near - far );\n}\nfloat orthographicDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) {\n\treturn linearClipZ * ( near - far ) - near;\n}\nfloat viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn (( near + viewZ ) * far ) / (( far - near ) * viewZ );\n}\nfloat perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {\n\treturn ( near * far ) / ( ( far - near ) * invClipZ - far );\n}";var premultiplied_alpha_fragment="#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";var project_vertex="vec4 mvPosition = vec4( transformed, 1.0 );\n#ifdef USE_INSTANCING\n\tmvPosition = instanceMatrix * mvPosition;\n#endif\nmvPosition = modelViewMatrix * mvPosition;\ngl_Position = projectionMatrix * mvPosition;";var dithering_fragment="#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";var dithering_pars_fragment="#ifdef DITHERING\n\tvec3 dithering( vec3 color ) {\n\t\tfloat grid_position = rand( gl_FragCoord.xy );\n\t\tvec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );\n\t\tdither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );\n\t\treturn color + dither_shift_RGB;\n\t}\n#endif";var roughnessmap_fragment="float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";var roughnessmap_pars_fragment="#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";var shadowmap_pars_fragment="#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n\tfloat texture2DCompare( sampler2D depths, vec2 uv, float compare ) {\n\t\treturn step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );\n\t}\n\tvec2 texture2DDistribution( sampler2D shadow, vec2 uv ) {\n\t\treturn unpackRGBATo2Half( texture2D( shadow, uv ) );\n\t}\n\tfloat VSMShadow (sampler2D shadow, vec2 uv, float compare ){\n\t\tfloat occlusion = 1.0;\n\t\tvec2 distribution = texture2DDistribution( shadow, uv );\n\t\tfloat hard_shadow = step( compare , distribution.x );\n\t\tif (hard_shadow != 1.0 ) {\n\t\t\tfloat distance = compare - distribution.x ;\n\t\t\tfloat variance = max( 0.00000, distribution.y * distribution.y );\n\t\t\tfloat softness_probability = variance / (variance + distance * distance );\t\t\tsoftness_probability = clamp( ( softness_probability - 0.3 ) / ( 0.95 - 0.3 ), 0.0, 1.0 );\t\t\tocclusion = clamp( max( hard_shadow, softness_probability ), 0.0, 1.0 );\n\t\t}\n\t\treturn occlusion;\n\t}\n\tfloat getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n\t\tfloat shadow = 1.0;\n\t\tshadowCoord.xyz /= shadowCoord.w;\n\t\tshadowCoord.z += shadowBias;\n\t\tbvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );\n\t\tbool inFrustum = all( inFrustumVec );\n\t\tbvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\n\t\tbool frustumTest = all( frustumTestVec );\n\t\tif ( frustumTest ) {\n\t\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx0 = - texelSize.x * shadowRadius;\n\t\t\tfloat dy0 = - texelSize.y * shadowRadius;\n\t\t\tfloat dx1 = + texelSize.x * shadowRadius;\n\t\t\tfloat dy1 = + texelSize.y * shadowRadius;\n\t\t\tfloat dx2 = dx0 / 2.0;\n\t\t\tfloat dy2 = dy0 / 2.0;\n\t\t\tfloat dx3 = dx1 / 2.0;\n\t\t\tfloat dy3 = dy1 / 2.0;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n\t\t\t) * ( 1.0 / 17.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx = texelSize.x;\n\t\t\tfloat dy = texelSize.y;\n\t\t\tvec2 uv = shadowCoord.xy;\n\t\t\tvec2 f = fract( uv * shadowMapSize + 0.5 );\n\t\t\tuv -= f * texelSize;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, uv, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + texelSize, shadowCoord.z ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ), \n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ),\n\t\t\t\t\t f.x ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ), \n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ),\n\t\t\t\t\t f.x ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ), \n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t f.y ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ), \n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t f.y ) +\n\t\t\t\tmix( mix( texture2DCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ), \n\t\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ),\n\t\t\t\t\t\t f.x ),\n\t\t\t\t\t mix( texture2DCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ), \n\t\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t\t f.x ),\n\t\t\t\t\t f.y )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_VSM )\n\t\t\tshadow = VSMShadow( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#else\n\t\t\tshadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#endif\n\t\t}\n\t\treturn shadow;\n\t}\n\tvec2 cubeToUV( vec3 v, float texelSizeY ) {\n\t\tvec3 absV = abs( v );\n\t\tfloat scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n\t\tabsV *= scaleToCube;\n\t\tv *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\n\t\tvec2 planar = v.xy;\n\t\tfloat almostATexel = 1.5 * texelSizeY;\n\t\tfloat almostOne = 1.0 - almostATexel;\n\t\tif ( absV.z >= almostOne ) {\n\t\t\tif ( v.z > 0.0 )\n\t\t\t\tplanar.x = 4.0 - v.x;\n\t\t} else if ( absV.x >= almostOne ) {\n\t\t\tfloat signX = sign( v.x );\n\t\t\tplanar.x = v.z * signX + 2.0 * signX;\n\t\t} else if ( absV.y >= almostOne ) {\n\t\t\tfloat signY = sign( v.y );\n\t\t\tplanar.x = v.x + 2.0 * signY + 2.0;\n\t\t\tplanar.y = v.z * signY - 2.0;\n\t\t}\n\t\treturn vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n\t}\n\tfloat getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {\n\t\tvec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );\n\t\tvec3 lightToPosition = shadowCoord.xyz;\n\t\tfloat dp = ( length( lightToPosition ) - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear );\t\tdp += shadowBias;\n\t\tvec3 bd3D = normalize( lightToPosition );\n\t\t#if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM )\n\t\t\tvec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;\n\t\t\treturn (\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#else\n\t\t\treturn texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );\n\t\t#endif\n\t}\n#endif";var shadowmap_pars_vertex="#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\tuniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tuniform mat4 spotShadowMatrix[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\tuniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n#endif";var shadowmap_vertex="#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0 || NUM_SPOT_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0\n\t\tvec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\t\tvec4 shadowWorldPosition;\n\t#endif\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 );\n\t\tvDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias, 0 );\n\t\tvSpotShadowCoord[ i ] = spotShadowMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 );\n\t\tvPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n#endif";var shadowmask_pars_fragment="float getShadowMask() {\n\tfloat shadow = 1.0;\n\t#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\tdirectionalLight = directionalLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n\t\tspotLight = spotLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\tpointLight = pointLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#endif\n\treturn shadow;\n}";var skinbase_vertex="#ifdef USE_SKINNING\n\tmat4 boneMatX = getBoneMatrix( skinIndex.x );\n\tmat4 boneMatY = getBoneMatrix( skinIndex.y );\n\tmat4 boneMatZ = getBoneMatrix( skinIndex.z );\n\tmat4 boneMatW = getBoneMatrix( skinIndex.w );\n#endif";var skinning_pars_vertex="#ifdef USE_SKINNING\n\tuniform mat4 bindMatrix;\n\tuniform mat4 bindMatrixInverse;\n\t#ifdef BONE_TEXTURE\n\t\tuniform highp sampler2D boneTexture;\n\t\tuniform int boneTextureSize;\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tfloat j = i * 4.0;\n\t\t\tfloat x = mod( j, float( boneTextureSize ) );\n\t\t\tfloat y = floor( j / float( boneTextureSize ) );\n\t\t\tfloat dx = 1.0 / float( boneTextureSize );\n\t\t\tfloat dy = 1.0 / float( boneTextureSize );\n\t\t\ty = dy * ( y + 0.5 );\n\t\t\tvec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );\n\t\t\tvec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );\n\t\t\tvec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );\n\t\t\tvec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );\n\t\t\tmat4 bone = mat4( v1, v2, v3, v4 );\n\t\t\treturn bone;\n\t\t}\n\t#else\n\t\tuniform mat4 boneMatrices[ MAX_BONES ];\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tmat4 bone = boneMatrices[ int(i) ];\n\t\t\treturn bone;\n\t\t}\n\t#endif\n#endif";var skinning_vertex="#ifdef USE_SKINNING\n\tvec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );\n\tvec4 skinned = vec4( 0.0 );\n\tskinned += boneMatX * skinVertex * skinWeight.x;\n\tskinned += boneMatY * skinVertex * skinWeight.y;\n\tskinned += boneMatZ * skinVertex * skinWeight.z;\n\tskinned += boneMatW * skinVertex * skinWeight.w;\n\ttransformed = ( bindMatrixInverse * skinned ).xyz;\n#endif";var skinnormal_vertex="#ifdef USE_SKINNING\n\tmat4 skinMatrix = mat4( 0.0 );\n\tskinMatrix += skinWeight.x * boneMatX;\n\tskinMatrix += skinWeight.y * boneMatY;\n\tskinMatrix += skinWeight.z * boneMatZ;\n\tskinMatrix += skinWeight.w * boneMatW;\n\tskinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;\n\tobjectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n\t#ifdef USE_TANGENT\n\t\tobjectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n\t#endif\n#endif";var specularmap_fragment="float specularStrength;\n#ifdef USE_SPECULARMAP\n\tvec4 texelSpecular = texture2D( specularMap, vUv );\n\tspecularStrength = texelSpecular.r;\n#else\n\tspecularStrength = 1.0;\n#endif";var specularmap_pars_fragment="#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";var tonemapping_fragment="#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";var tonemapping_pars_fragment="#ifndef saturate\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#endif\nuniform float toneMappingExposure;\nvec3 LinearToneMapping( vec3 color ) {\n\treturn toneMappingExposure * color;\n}\nvec3 ReinhardToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( color / ( vec3( 1.0 ) + color ) );\n}\nvec3 OptimizedCineonToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\tcolor = max( vec3( 0.0 ), color - 0.004 );\n\treturn pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\n}\nvec3 RRTAndODTFit( vec3 v ) {\n\tvec3 a = v * ( v + 0.0245786 ) - 0.000090537;\n\tvec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081;\n\treturn a / b;\n}\nvec3 ACESFilmicToneMapping( vec3 color ) {\n\tconst mat3 ACESInputMat = mat3(\n\t\tvec3( 0.59719, 0.07600, 0.02840 ),\t\tvec3( 0.35458, 0.90834, 0.13383 ),\n\t\tvec3( 0.04823, 0.01566, 0.83777 )\n\t);\n\tconst mat3 ACESOutputMat = mat3(\n\t\tvec3( 1.60475, -0.10208, -0.00327 ),\t\tvec3( -0.53108, 1.10813, -0.07276 ),\n\t\tvec3( -0.07367, -0.00605, 1.07602 )\n\t);\n\tcolor *= toneMappingExposure / 0.6;\n\tcolor = ACESInputMat * color;\n\tcolor = RRTAndODTFit( color );\n\tcolor = ACESOutputMat * color;\n\treturn saturate( color );\n}\nvec3 CustomToneMapping( vec3 color ) { return color; }";var transmissionmap_fragment="#ifdef USE_TRANSMISSIONMAP\n\ttotalTransmission *= texture2D( transmissionMap, vUv ).r;\n#endif";var transmissionmap_pars_fragment="#ifdef USE_TRANSMISSIONMAP\n\tuniform sampler2D transmissionMap;\n#endif";var uv_pars_fragment="#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n\tvarying vec2 vUv;\n#endif";var uv_pars_vertex="#ifdef USE_UV\n\t#ifdef UVS_VERTEX_ONLY\n\t\tvec2 vUv;\n\t#else\n\t\tvarying vec2 vUv;\n\t#endif\n\tuniform mat3 uvTransform;\n#endif";var uv_vertex="#ifdef USE_UV\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";var uv2_pars_fragment="#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";var uv2_pars_vertex="#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tattribute vec2 uv2;\n\tvarying vec2 vUv2;\n\tuniform mat3 uv2Transform;\n#endif";var uv2_vertex="#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;\n#endif";var worldpos_vertex="#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP )\n\tvec4 worldPosition = vec4( transformed, 1.0 );\n\t#ifdef USE_INSTANCING\n\t\tworldPosition = instanceMatrix * worldPosition;\n\t#endif\n\tworldPosition = modelMatrix * worldPosition;\n#endif";var background_frag="uniform sampler2D t2D;\nvarying vec2 vUv;\nvoid main() {\n\tvec4 texColor = texture2D( t2D, vUv );\n\tgl_FragColor = mapTexelToLinear( texColor );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}";var background_vert="varying vec2 vUv;\nuniform mat3 uvTransform;\nvoid main() {\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n\tgl_Position = vec4( position.xy, 1.0, 1.0 );\n}";var cube_frag="#include <envmap_common_pars_fragment>\nuniform float opacity;\nvarying vec3 vWorldDirection;\n#include <cube_uv_reflection_fragment>\nvoid main() {\n\tvec3 vReflect = vWorldDirection;\n\t#include <envmap_fragment>\n\tgl_FragColor = envColor;\n\tgl_FragColor.a *= opacity;\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}";var cube_vert="varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\tgl_Position.z = gl_Position.w;\n}";var depth_frag="#if DEPTH_PACKING == 3200\n\tuniform float opacity;\n#endif\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#if DEPTH_PACKING == 3200\n\t\tdiffuseColor.a = opacity;\n\t#endif\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <logdepthbuf_fragment>\n\tfloat fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;\n\t#if DEPTH_PACKING == 3200\n\t\tgl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );\n\t#elif DEPTH_PACKING == 3201\n\t\tgl_FragColor = packDepthToRGBA( fragCoordZ );\n\t#endif\n}";var depth_vert="#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\t#include <uv_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvHighPrecisionZW = gl_Position.zw;\n}";var distanceRGBA_frag="#define DISTANCE\nuniform vec3 referencePosition;\nuniform float nearDistance;\nuniform float farDistance;\nvarying vec3 vWorldPosition;\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main () {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\tfloat dist = length( vWorldPosition - referencePosition );\n\tdist = ( dist - nearDistance ) / ( farDistance - nearDistance );\n\tdist = saturate( dist );\n\tgl_FragColor = packDepthToRGBA( dist );\n}";var distanceRGBA_vert="#define DISTANCE\nvarying vec3 vWorldPosition;\n#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <worldpos_vertex>\n\t#include <clipping_planes_vertex>\n\tvWorldPosition = worldPosition.xyz;\n}";var equirect_frag="uniform sampler2D tEquirect;\nvarying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvec3 direction = normalize( vWorldDirection );\n\tvec2 sampleUV = equirectUv( direction );\n\tvec4 texColor = texture2D( tEquirect, sampleUV );\n\tgl_FragColor = mapTexelToLinear( texColor );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}";var equirect_vert="varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n}";var linedashed_frag="uniform vec3 diffuse;\nuniform float opacity;\nuniform float dashSize;\nuniform float totalSize;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tif ( mod( vLineDistance, totalSize ) > dashSize ) {\n\t\tdiscard;\n\t}\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <color_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n}";var linedashed_vert="uniform float scale;\nattribute float lineDistance;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\tvLineDistance = scale * lineDistance;\n\t#include <color_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}";var meshbasic_frag="uniform vec3 diffuse;\nuniform float opacity;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <cube_uv_reflection_fragment>\n#include <fog_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\t#ifdef USE_LIGHTMAP\n\t\n\t\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\t\treflectedLight.indirectDiffuse += lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n\t#else\n\t\treflectedLight.indirectDiffuse += vec3( 1.0 );\n\t#endif\n\t#include <aomap_fragment>\n\treflectedLight.indirectDiffuse *= diffuseColor.rgb;\n\tvec3 outgoingLight = reflectedLight.indirectDiffuse;\n\t#include <envmap_fragment>\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";var meshbasic_vert="#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_ENVMAP\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <worldpos_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <envmap_vertex>\n\t#include <fog_vertex>\n}";var meshlambert_frag="uniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\nvarying vec3 vLightFront;\nvarying vec3 vIndirectFront;\n#ifdef DOUBLE_SIDED\n\tvarying vec3 vLightBack;\n\tvarying vec3 vIndirectBack;\n#endif\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <cube_uv_reflection_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <fog_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\t#include <emissivemap_fragment>\n\t#ifdef DOUBLE_SIDED\n\t\treflectedLight.indirectDiffuse += ( gl_FrontFacing ) ? vIndirectFront : vIndirectBack;\n\t#else\n\t\treflectedLight.indirectDiffuse += vIndirectFront;\n\t#endif\n\t#include <lightmap_fragment>\n\treflectedLight.indirectDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb );\n\t#ifdef DOUBLE_SIDED\n\t\treflectedLight.directDiffuse = ( gl_FrontFacing ) ? vLightFront : vLightBack;\n\t#else\n\t\treflectedLight.directDiffuse = vLightFront;\n\t#endif\n\treflectedLight.directDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb ) * getShadowMask();\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";var meshlambert_vert="#define LAMBERT\nvarying vec3 vLightFront;\nvarying vec3 vIndirectFront;\n#ifdef DOUBLE_SIDED\n\tvarying vec3 vLightBack;\n\tvarying vec3 vIndirectBack;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <envmap_pars_vertex>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <lights_lambert_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";var meshmatcap_frag="#define MATCAP\nuniform vec3 diffuse;\nuniform float opacity;\nuniform sampler2D matcap;\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tvec3 viewDir = normalize( vViewPosition );\n\tvec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) );\n\tvec3 y = cross( viewDir, x );\n\tvec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5;\n\t#ifdef USE_MATCAP\n\t\tvec4 matcapColor = texture2D( matcap, uv );\n\t\tmatcapColor = matcapTexelToLinear( matcapColor );\n\t#else\n\t\tvec4 matcapColor = vec4( 1.0 );\n\t#endif\n\tvec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";var meshmatcap_vert="#define MATCAP\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <color_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#ifndef FLAT_SHADED\n\t\tvNormal = normalize( transformedNormal );\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n\tvViewPosition = - mvPosition.xyz;\n}";var meshtoon_frag="#define TOON\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <gradientmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <lights_toon_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_toon_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";var meshtoon_vert="#define TOON\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";var meshphong_frag="#define PHONG\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 specular;\nuniform float shininess;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <cube_uv_reflection_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <lights_phong_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_phong_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";var meshphong_vert="#define PHONG\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";var meshphysical_frag="#define STANDARD\n#ifdef PHYSICAL\n\t#define REFLECTIVITY\n\t#define CLEARCOAT\n\t#define TRANSMISSION\n#endif\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifdef TRANSMISSION\n\tuniform float transmission;\n#endif\n#ifdef REFLECTIVITY\n\tuniform float reflectivity;\n#endif\n#ifdef CLEARCOAT\n\tuniform float clearcoat;\n\tuniform float clearcoatRoughness;\n#endif\n#ifdef USE_SHEEN\n\tuniform vec3 sheen;\n#endif\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <transmissionmap_pars_fragment>\n#include <bsdfs>\n#include <cube_uv_reflection_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_physical_pars_fragment>\n#include <fog_pars_fragment>\n#include <lights_pars_begin>\n#include <lights_physical_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <clearcoat_pars_fragment>\n#include <roughnessmap_pars_fragment>\n#include <metalnessmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#ifdef TRANSMISSION\n\t\tfloat totalTransmission = transmission;\n\t#endif\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <roughnessmap_fragment>\n\t#include <metalnessmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <clearcoat_normal_fragment_begin>\n\t#include <clearcoat_normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <transmissionmap_fragment>\n\t#include <lights_physical_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\t#ifdef TRANSMISSION\n\t\tdiffuseColor.a *= mix( saturate( 1. - totalTransmission + linearToRelativeLuminance( reflectedLight.directSpecular + reflectedLight.indirectSpecular ) ), 1.0, metalness );\n\t#endif\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";var meshphysical_vert="#define STANDARD\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n\t#ifdef USE_TANGENT\n\t\tvTangent = normalize( transformedTangent );\n\t\tvBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );\n\t#endif\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";var normal_frag="#define NORMAL\nuniform float opacity;\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )\n\tvarying vec3 vViewPosition;\n#endif\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif\n#include <packing>\n#include <uv_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\t#include <logdepthbuf_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tgl_FragColor = vec4( packNormalToRGB( normal ), opacity );\n}";var normal_vert="#define NORMAL\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )\n\tvarying vec3 vViewPosition;\n#endif\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n\t#ifdef USE_TANGENT\n\t\tvTangent = normalize( transformedTangent );\n\t\tvBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );\n\t#endif\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n}";var points_frag="uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <color_pars_fragment>\n#include <map_particle_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_particle_fragment>\n\t#include <color_fragment>\n\t#include <alphatest_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n}";var points_vert="uniform float size;\nuniform float scale;\n#include <common>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <color_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <project_vertex>\n\tgl_PointSize = size;\n\t#ifdef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z );\n\t#endif\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <fog_vertex>\n}";var shadow_frag="uniform vec3 color;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\nvoid main() {\n\tgl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}";var shadow_vert="#include <common>\n#include <fog_pars_vertex>\n#include <shadowmap_pars_vertex>\nvoid main() {\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\t#include <worldpos_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";var sprite_frag="uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}";var sprite_vert="uniform float rotation;\nuniform vec2 center;\n#include <common>\n#include <uv_pars_vertex>\n#include <fog_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\tvec4 mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );\n\tvec2 scale;\n\tscale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) );\n\tscale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) );\n\t#ifndef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) scale *= - mvPosition.z;\n\t#endif\n\tvec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale;\n\tvec2 rotatedPosition;\n\trotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n\trotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n\tmvPosition.xy += rotatedPosition;\n\tgl_Position = projectionMatrix * mvPosition;\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}";var ShaderChunk={alphamap_fragment:alphamap_fragment,alphamap_pars_fragment:alphamap_pars_fragment,alphatest_fragment:alphatest_fragment,aomap_fragment:aomap_fragment,aomap_pars_fragment:aomap_pars_fragment,begin_vertex:begin_vertex,beginnormal_vertex:beginnormal_vertex,bsdfs:bsdfs,bumpmap_pars_fragment:bumpmap_pars_fragment,clipping_planes_fragment:clipping_planes_fragment,clipping_planes_pars_fragment:clipping_planes_pars_fragment,clipping_planes_pars_vertex:clipping_planes_pars_vertex,clipping_planes_vertex:clipping_planes_vertex,color_fragment:color_fragment,color_pars_fragment:color_pars_fragment,color_pars_vertex:color_pars_vertex,color_vertex:color_vertex,common:common,cube_uv_reflection_fragment:cube_uv_reflection_fragment,defaultnormal_vertex:defaultnormal_vertex,displacementmap_pars_vertex:displacementmap_pars_vertex,displacementmap_vertex:displacementmap_vertex,emissivemap_fragment:emissivemap_fragment,emissivemap_pars_fragment:emissivemap_pars_fragment,encodings_fragment:encodings_fragment,encodings_pars_fragment:encodings_pars_fragment,envmap_fragment:envmap_fragment,envmap_common_pars_fragment:envmap_common_pars_fragment,envmap_pars_fragment:envmap_pars_fragment,envmap_pars_vertex:envmap_pars_vertex,envmap_physical_pars_fragment:envmap_physical_pars_fragment,envmap_vertex:envmap_vertex,fog_vertex:fog_vertex,fog_pars_vertex:fog_pars_vertex,fog_fragment:fog_fragment,fog_pars_fragment:fog_pars_fragment,gradientmap_pars_fragment:gradientmap_pars_fragment,lightmap_fragment:lightmap_fragment,lightmap_pars_fragment:lightmap_pars_fragment,lights_lambert_vertex:lights_lambert_vertex,lights_pars_begin:lights_pars_begin,lights_toon_fragment:lights_toon_fragment,lights_toon_pars_fragment:lights_toon_pars_fragment,lights_phong_fragment:lights_phong_fragment,lights_phong_pars_fragment:lights_phong_pars_fragment,lights_physical_fragment:lights_physical_fragment,lights_physical_pars_fragment:lights_physical_pars_fragment,lights_fragment_begin:lights_fragment_begin,lights_fragment_maps:lights_fragment_maps,lights_fragment_end:lights_fragment_end,logdepthbuf_fragment:logdepthbuf_fragment,logdepthbuf_pars_fragment:logdepthbuf_pars_fragment,logdepthbuf_pars_vertex:logdepthbuf_pars_vertex,logdepthbuf_vertex:logdepthbuf_vertex,map_fragment:map_fragment,map_pars_fragment:map_pars_fragment,map_particle_fragment:map_particle_fragment,map_particle_pars_fragment:map_particle_pars_fragment,metalnessmap_fragment:metalnessmap_fragment,metalnessmap_pars_fragment:metalnessmap_pars_fragment,morphnormal_vertex:morphnormal_vertex,morphtarget_pars_vertex:morphtarget_pars_vertex,morphtarget_vertex:morphtarget_vertex,normal_fragment_begin:normal_fragment_begin,normal_fragment_maps:normal_fragment_maps,normalmap_pars_fragment:normalmap_pars_fragment,clearcoat_normal_fragment_begin:clearcoat_normal_fragment_begin,clearcoat_normal_fragment_maps:clearcoat_normal_fragment_maps,clearcoat_pars_fragment:clearcoat_pars_fragment,packing:packing,premultiplied_alpha_fragment:premultiplied_alpha_fragment,project_vertex:project_vertex,dithering_fragment:dithering_fragment,dithering_pars_fragment:dithering_pars_fragment,roughnessmap_fragment:roughnessmap_fragment,roughnessmap_pars_fragment:roughnessmap_pars_fragment,shadowmap_pars_fragment:shadowmap_pars_fragment,shadowmap_pars_vertex:shadowmap_pars_vertex,shadowmap_vertex:shadowmap_vertex,shadowmask_pars_fragment:shadowmask_pars_fragment,skinbase_vertex:skinbase_vertex,skinning_pars_vertex:skinning_pars_vertex,skinning_vertex:skinning_vertex,skinnormal_vertex:skinnormal_vertex,specularmap_fragment:specularmap_fragment,specularmap_pars_fragment:specularmap_pars_fragment,tonemapping_fragment:tonemapping_fragment,tonemapping_pars_fragment:tonemapping_pars_fragment,transmissionmap_fragment:transmissionmap_fragment,transmissionmap_pars_fragment:transmissionmap_pars_fragment,uv_pars_fragment:uv_pars_fragment,uv_pars_vertex:uv_pars_vertex,uv_vertex:uv_vertex,uv2_pars_fragment:uv2_pars_fragment,uv2_pars_vertex:uv2_pars_vertex,uv2_vertex:uv2_vertex,worldpos_vertex:worldpos_vertex,background_frag:background_frag,background_vert:background_vert,cube_frag:cube_frag,cube_vert:cube_vert,depth_frag:depth_frag,depth_vert:depth_vert,distanceRGBA_frag:distanceRGBA_frag,distanceRGBA_vert:distanceRGBA_vert,equirect_frag:equirect_frag,equirect_vert:equirect_vert,linedashed_frag:linedashed_frag,linedashed_vert:linedashed_vert,meshbasic_frag:meshbasic_frag,meshbasic_vert:meshbasic_vert,meshlambert_frag:meshlambert_frag,meshlambert_vert:meshlambert_vert,meshmatcap_frag:meshmatcap_frag,meshmatcap_vert:meshmatcap_vert,meshtoon_frag:meshtoon_frag,meshtoon_vert:meshtoon_vert,meshphong_frag:meshphong_frag,meshphong_vert:meshphong_vert,meshphysical_frag:meshphysical_frag,meshphysical_vert:meshphysical_vert,normal_frag:normal_frag,normal_vert:normal_vert,points_frag:points_frag,points_vert:points_vert,shadow_frag:shadow_frag,shadow_vert:shadow_vert,sprite_frag:sprite_frag,sprite_vert:sprite_vert};/**
  488. * Uniforms library for shared webgl shaders
  489. */var UniformsLib={common:{diffuse:{value:new Color(0xeeeeee)},opacity:{value:1.0},map:{value:null},uvTransform:{value:new Matrix3()},uv2Transform:{value:new Matrix3()},alphaMap:{value:null}},specularmap:{specularMap:{value:null}},envmap:{envMap:{value:null},flipEnvMap:{value:-1},reflectivity:{value:1.0},refractionRatio:{value:0.98},maxMipLevel:{value:0}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1}},emissivemap:{emissiveMap:{value:null}},bumpmap:{bumpMap:{value:null},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalScale:{value:new Vector2(1,1)}},displacementmap:{displacementMap:{value:null},displacementScale:{value:1},displacementBias:{value:0}},roughnessmap:{roughnessMap:{value:null}},metalnessmap:{metalnessMap:{value:null}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:0.00025},fogNear:{value:1},fogFar:{value:2000},fogColor:{value:new Color(0xffffff)}},lights:{ambientLightColor:{value:[]},lightProbe:{value:[]},directionalLights:{value:[],properties:{direction:{},color:{}}},directionalLightShadows:{value:[],properties:{shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},directionalShadowMap:{value:[]},directionalShadowMatrix:{value:[]},spotLights:{value:[],properties:{color:{},position:{},direction:{},distance:{},coneCos:{},penumbraCos:{},decay:{}}},spotLightShadows:{value:[],properties:{shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},spotShadowMap:{value:[]},spotShadowMatrix:{value:[]},pointLights:{value:[],properties:{color:{},position:{},decay:{},distance:{}}},pointLightShadows:{value:[],properties:{shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{},shadowCameraNear:{},shadowCameraFar:{}}},pointShadowMap:{value:[]},pointShadowMatrix:{value:[]},hemisphereLights:{value:[],properties:{direction:{},skyColor:{},groundColor:{}}},// TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  490. rectAreaLights:{value:[],properties:{color:{},position:{},width:{},height:{}}},ltc_1:{value:null},ltc_2:{value:null}},points:{diffuse:{value:new Color(0xeeeeee)},opacity:{value:1.0},size:{value:1.0},scale:{value:1.0},map:{value:null},alphaMap:{value:null},uvTransform:{value:new Matrix3()}},sprite:{diffuse:{value:new Color(0xeeeeee)},opacity:{value:1.0},center:{value:new Vector2(0.5,0.5)},rotation:{value:0.0},map:{value:null},alphaMap:{value:null},uvTransform:{value:new Matrix3()}}};var ShaderLib={basic:{uniforms:mergeUniforms([UniformsLib.common,UniformsLib.specularmap,UniformsLib.envmap,UniformsLib.aomap,UniformsLib.lightmap,UniformsLib.fog]),vertexShader:ShaderChunk.meshbasic_vert,fragmentShader:ShaderChunk.meshbasic_frag},lambert:{uniforms:mergeUniforms([UniformsLib.common,UniformsLib.specularmap,UniformsLib.envmap,UniformsLib.aomap,UniformsLib.lightmap,UniformsLib.emissivemap,UniformsLib.fog,UniformsLib.lights,{emissive:{value:new Color(0x000000)}}]),vertexShader:ShaderChunk.meshlambert_vert,fragmentShader:ShaderChunk.meshlambert_frag},phong:{uniforms:mergeUniforms([UniformsLib.common,UniformsLib.specularmap,UniformsLib.envmap,UniformsLib.aomap,UniformsLib.lightmap,UniformsLib.emissivemap,UniformsLib.bumpmap,UniformsLib.normalmap,UniformsLib.displacementmap,UniformsLib.fog,UniformsLib.lights,{emissive:{value:new Color(0x000000)},specular:{value:new Color(0x111111)},shininess:{value:30}}]),vertexShader:ShaderChunk.meshphong_vert,fragmentShader:ShaderChunk.meshphong_frag},standard:{uniforms:mergeUniforms([UniformsLib.common,UniformsLib.envmap,UniformsLib.aomap,UniformsLib.lightmap,UniformsLib.emissivemap,UniformsLib.bumpmap,UniformsLib.normalmap,UniformsLib.displacementmap,UniformsLib.roughnessmap,UniformsLib.metalnessmap,UniformsLib.fog,UniformsLib.lights,{emissive:{value:new Color(0x000000)},roughness:{value:1.0},metalness:{value:0.0},envMapIntensity:{value:1}// temporary
  491. }]),vertexShader:ShaderChunk.meshphysical_vert,fragmentShader:ShaderChunk.meshphysical_frag},toon:{uniforms:mergeUniforms([UniformsLib.common,UniformsLib.aomap,UniformsLib.lightmap,UniformsLib.emissivemap,UniformsLib.bumpmap,UniformsLib.normalmap,UniformsLib.displacementmap,UniformsLib.gradientmap,UniformsLib.fog,UniformsLib.lights,{emissive:{value:new Color(0x000000)}}]),vertexShader:ShaderChunk.meshtoon_vert,fragmentShader:ShaderChunk.meshtoon_frag},matcap:{uniforms:mergeUniforms([UniformsLib.common,UniformsLib.bumpmap,UniformsLib.normalmap,UniformsLib.displacementmap,UniformsLib.fog,{matcap:{value:null}}]),vertexShader:ShaderChunk.meshmatcap_vert,fragmentShader:ShaderChunk.meshmatcap_frag},points:{uniforms:mergeUniforms([UniformsLib.points,UniformsLib.fog]),vertexShader:ShaderChunk.points_vert,fragmentShader:ShaderChunk.points_frag},dashed:{uniforms:mergeUniforms([UniformsLib.common,UniformsLib.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:ShaderChunk.linedashed_vert,fragmentShader:ShaderChunk.linedashed_frag},depth:{uniforms:mergeUniforms([UniformsLib.common,UniformsLib.displacementmap]),vertexShader:ShaderChunk.depth_vert,fragmentShader:ShaderChunk.depth_frag},normal:{uniforms:mergeUniforms([UniformsLib.common,UniformsLib.bumpmap,UniformsLib.normalmap,UniformsLib.displacementmap,{opacity:{value:1.0}}]),vertexShader:ShaderChunk.normal_vert,fragmentShader:ShaderChunk.normal_frag},sprite:{uniforms:mergeUniforms([UniformsLib.sprite,UniformsLib.fog]),vertexShader:ShaderChunk.sprite_vert,fragmentShader:ShaderChunk.sprite_frag},background:{uniforms:{uvTransform:{value:new Matrix3()},t2D:{value:null}},vertexShader:ShaderChunk.background_vert,fragmentShader:ShaderChunk.background_frag},/* -------------------------------------------------------------------------
  492. // Cube map shader
  493. ------------------------------------------------------------------------- */cube:{uniforms:mergeUniforms([UniformsLib.envmap,{opacity:{value:1.0}}]),vertexShader:ShaderChunk.cube_vert,fragmentShader:ShaderChunk.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:ShaderChunk.equirect_vert,fragmentShader:ShaderChunk.equirect_frag},distanceRGBA:{uniforms:mergeUniforms([UniformsLib.common,UniformsLib.displacementmap,{referencePosition:{value:new Vector3()},nearDistance:{value:1},farDistance:{value:1000}}]),vertexShader:ShaderChunk.distanceRGBA_vert,fragmentShader:ShaderChunk.distanceRGBA_frag},shadow:{uniforms:mergeUniforms([UniformsLib.lights,UniformsLib.fog,{color:{value:new Color(0x00000)},opacity:{value:1.0}}]),vertexShader:ShaderChunk.shadow_vert,fragmentShader:ShaderChunk.shadow_frag}};ShaderLib.physical={uniforms:mergeUniforms([ShaderLib.standard.uniforms,{clearcoat:{value:0},clearcoatMap:{value:null},clearcoatRoughness:{value:0},clearcoatRoughnessMap:{value:null},clearcoatNormalScale:{value:new Vector2(1,1)},clearcoatNormalMap:{value:null},sheen:{value:new Color(0x000000)},transmission:{value:0},transmissionMap:{value:null}}]),vertexShader:ShaderChunk.meshphysical_vert,fragmentShader:ShaderChunk.meshphysical_frag};function WebGLBackground(renderer,cubemaps,state,objects,premultipliedAlpha){var clearColor=new Color(0x000000);var clearAlpha=0;var planeMesh;var boxMesh;var currentBackground=null;var currentBackgroundVersion=0;var currentTonemapping=null;function render(renderList,scene,camera,forceClear){var background=scene.isScene===true?scene.background:null;if(background&&background.isTexture){background=cubemaps.get(background);}// Ignore background in AR
  494. // TODO: Reconsider this.
  495. var xr=renderer.xr;var session=xr.getSession&&xr.getSession();if(session&&session.environmentBlendMode==='additive'){background=null;}if(background===null){setClear(clearColor,clearAlpha);}else if(background&&background.isColor){setClear(background,1);forceClear=true;}if(renderer.autoClear||forceClear){renderer.clear(renderer.autoClearColor,renderer.autoClearDepth,renderer.autoClearStencil);}if(background&&(background.isCubeTexture||background.isWebGLCubeRenderTarget||background.mapping===CubeUVReflectionMapping)){if(boxMesh===undefined){boxMesh=new Mesh(new BoxBufferGeometry(1,1,1),new ShaderMaterial({name:'BackgroundCubeMaterial',uniforms:cloneUniforms(ShaderLib.cube.uniforms),vertexShader:ShaderLib.cube.vertexShader,fragmentShader:ShaderLib.cube.fragmentShader,side:BackSide,depthTest:false,depthWrite:false,fog:false}));boxMesh.geometry.deleteAttribute('normal');boxMesh.geometry.deleteAttribute('uv');boxMesh.onBeforeRender=function(renderer,scene,camera){this.matrixWorld.copyPosition(camera.matrixWorld);};// enable code injection for non-built-in material
  496. Object.defineProperty(boxMesh.material,'envMap',{get:function get(){return this.uniforms.envMap.value;}});objects.update(boxMesh);}if(background.isWebGLCubeRenderTarget){// TODO Deprecate
  497. background=background.texture;}boxMesh.material.uniforms.envMap.value=background;boxMesh.material.uniforms.flipEnvMap.value=background.isCubeTexture&&background._needsFlipEnvMap?-1:1;if(currentBackground!==background||currentBackgroundVersion!==background.version||currentTonemapping!==renderer.toneMapping){boxMesh.material.needsUpdate=true;currentBackground=background;currentBackgroundVersion=background.version;currentTonemapping=renderer.toneMapping;}// push to the pre-sorted opaque render list
  498. renderList.unshift(boxMesh,boxMesh.geometry,boxMesh.material,0,0,null);}else if(background&&background.isTexture){if(planeMesh===undefined){planeMesh=new Mesh(new PlaneBufferGeometry(2,2),new ShaderMaterial({name:'BackgroundMaterial',uniforms:cloneUniforms(ShaderLib.background.uniforms),vertexShader:ShaderLib.background.vertexShader,fragmentShader:ShaderLib.background.fragmentShader,side:FrontSide,depthTest:false,depthWrite:false,fog:false}));planeMesh.geometry.deleteAttribute('normal');// enable code injection for non-built-in material
  499. Object.defineProperty(planeMesh.material,'map',{get:function get(){return this.uniforms.t2D.value;}});objects.update(planeMesh);}planeMesh.material.uniforms.t2D.value=background;if(background.matrixAutoUpdate===true){background.updateMatrix();}planeMesh.material.uniforms.uvTransform.value.copy(background.matrix);if(currentBackground!==background||currentBackgroundVersion!==background.version||currentTonemapping!==renderer.toneMapping){planeMesh.material.needsUpdate=true;currentBackground=background;currentBackgroundVersion=background.version;currentTonemapping=renderer.toneMapping;}// push to the pre-sorted opaque render list
  500. renderList.unshift(planeMesh,planeMesh.geometry,planeMesh.material,0,0,null);}}function setClear(color,alpha){state.buffers.color.setClear(color.r,color.g,color.b,alpha,premultipliedAlpha);}return {getClearColor:function getClearColor(){return clearColor;},setClearColor:function setClearColor(color){var alpha=arguments.length>1&&arguments[1]!==undefined?arguments[1]:1;clearColor.set(color);clearAlpha=alpha;setClear(clearColor,clearAlpha);},getClearAlpha:function getClearAlpha(){return clearAlpha;},setClearAlpha:function setClearAlpha(alpha){clearAlpha=alpha;setClear(clearColor,clearAlpha);},render:render};}function WebGLBindingStates(gl,extensions,attributes,capabilities){var maxVertexAttributes=gl.getParameter(34921);var extension=capabilities.isWebGL2?null:extensions.get('OES_vertex_array_object');var vaoAvailable=capabilities.isWebGL2||extension!==null;var bindingStates={};var defaultState=createBindingState(null);var currentState=defaultState;function setup(object,material,program,geometry,index){var updateBuffers=false;if(vaoAvailable){var state=getBindingState(geometry,program,material);if(currentState!==state){currentState=state;bindVertexArrayObject(currentState.object);}updateBuffers=needsUpdate(geometry,index);if(updateBuffers)saveCache(geometry,index);}else {var wireframe=material.wireframe===true;if(currentState.geometry!==geometry.id||currentState.program!==program.id||currentState.wireframe!==wireframe){currentState.geometry=geometry.id;currentState.program=program.id;currentState.wireframe=wireframe;updateBuffers=true;}}if(object.isInstancedMesh===true){updateBuffers=true;}if(index!==null){attributes.update(index,34963);}if(updateBuffers){setupVertexAttributes(object,material,program,geometry);if(index!==null){gl.bindBuffer(34963,attributes.get(index).buffer);}}}function createVertexArrayObject(){if(capabilities.isWebGL2)return gl.createVertexArray();return extension.createVertexArrayOES();}function bindVertexArrayObject(vao){if(capabilities.isWebGL2)return gl.bindVertexArray(vao);return extension.bindVertexArrayOES(vao);}function deleteVertexArrayObject(vao){if(capabilities.isWebGL2)return gl.deleteVertexArray(vao);return extension.deleteVertexArrayOES(vao);}function getBindingState(geometry,program,material){var wireframe=material.wireframe===true;var programMap=bindingStates[geometry.id];if(programMap===undefined){programMap={};bindingStates[geometry.id]=programMap;}var stateMap=programMap[program.id];if(stateMap===undefined){stateMap={};programMap[program.id]=stateMap;}var state=stateMap[wireframe];if(state===undefined){state=createBindingState(createVertexArrayObject());stateMap[wireframe]=state;}return state;}function createBindingState(vao){var newAttributes=[];var enabledAttributes=[];var attributeDivisors=[];for(var _i69=0;_i69<maxVertexAttributes;_i69++){newAttributes[_i69]=0;enabledAttributes[_i69]=0;attributeDivisors[_i69]=0;}return {// for backward compatibility on non-VAO support browser
  501. geometry:null,program:null,wireframe:false,newAttributes:newAttributes,enabledAttributes:enabledAttributes,attributeDivisors:attributeDivisors,object:vao,attributes:{},index:null};}function needsUpdate(geometry,index){var cachedAttributes=currentState.attributes;var geometryAttributes=geometry.attributes;var attributesNum=0;for(var key in geometryAttributes){var cachedAttribute=cachedAttributes[key];var geometryAttribute=geometryAttributes[key];if(cachedAttribute===undefined)return true;if(cachedAttribute.attribute!==geometryAttribute)return true;if(cachedAttribute.data!==geometryAttribute.data)return true;attributesNum++;}if(currentState.attributesNum!==attributesNum)return true;if(currentState.index!==index)return true;return false;}function saveCache(geometry,index){var cache={};var attributes=geometry.attributes;var attributesNum=0;for(var key in attributes){var attribute=attributes[key];var data={};data.attribute=attribute;if(attribute.data){data.data=attribute.data;}cache[key]=data;attributesNum++;}currentState.attributes=cache;currentState.attributesNum=attributesNum;currentState.index=index;}function initAttributes(){var newAttributes=currentState.newAttributes;for(var _i70=0,il=newAttributes.length;_i70<il;_i70++){newAttributes[_i70]=0;}}function enableAttribute(attribute){enableAttributeAndDivisor(attribute,0);}function enableAttributeAndDivisor(attribute,meshPerAttribute){var newAttributes=currentState.newAttributes;var enabledAttributes=currentState.enabledAttributes;var attributeDivisors=currentState.attributeDivisors;newAttributes[attribute]=1;if(enabledAttributes[attribute]===0){gl.enableVertexAttribArray(attribute);enabledAttributes[attribute]=1;}if(attributeDivisors[attribute]!==meshPerAttribute){var _extension=capabilities.isWebGL2?gl:extensions.get('ANGLE_instanced_arrays');_extension[capabilities.isWebGL2?'vertexAttribDivisor':'vertexAttribDivisorANGLE'](attribute,meshPerAttribute);attributeDivisors[attribute]=meshPerAttribute;}}function disableUnusedAttributes(){var newAttributes=currentState.newAttributes;var enabledAttributes=currentState.enabledAttributes;for(var _i71=0,il=enabledAttributes.length;_i71<il;_i71++){if(enabledAttributes[_i71]!==newAttributes[_i71]){gl.disableVertexAttribArray(_i71);enabledAttributes[_i71]=0;}}}function vertexAttribPointer(index,size,type,normalized,stride,offset){if(capabilities.isWebGL2===true&&(type===5124||type===5125)){gl.vertexAttribIPointer(index,size,type,stride,offset);}else {gl.vertexAttribPointer(index,size,type,normalized,stride,offset);}}function setupVertexAttributes(object,material,program,geometry){if(capabilities.isWebGL2===false&&(object.isInstancedMesh||geometry.isInstancedBufferGeometry)){if(extensions.get('ANGLE_instanced_arrays')===null)return;}initAttributes();var geometryAttributes=geometry.attributes;var programAttributes=program.getAttributes();var materialDefaultAttributeValues=material.defaultAttributeValues;for(var name in programAttributes){var programAttribute=programAttributes[name];if(programAttribute>=0){var geometryAttribute=geometryAttributes[name];if(geometryAttribute!==undefined){var normalized=geometryAttribute.normalized;var size=geometryAttribute.itemSize;var attribute=attributes.get(geometryAttribute);// TODO Attribute may not be available on context restore
  502. if(attribute===undefined)continue;var buffer=attribute.buffer;var type=attribute.type;var bytesPerElement=attribute.bytesPerElement;if(geometryAttribute.isInterleavedBufferAttribute){var data=geometryAttribute.data;var stride=data.stride;var offset=geometryAttribute.offset;if(data&&data.isInstancedInterleavedBuffer){enableAttributeAndDivisor(programAttribute,data.meshPerAttribute);if(geometry._maxInstanceCount===undefined){geometry._maxInstanceCount=data.meshPerAttribute*data.count;}}else {enableAttribute(programAttribute);}gl.bindBuffer(34962,buffer);vertexAttribPointer(programAttribute,size,type,normalized,stride*bytesPerElement,offset*bytesPerElement);}else {if(geometryAttribute.isInstancedBufferAttribute){enableAttributeAndDivisor(programAttribute,geometryAttribute.meshPerAttribute);if(geometry._maxInstanceCount===undefined){geometry._maxInstanceCount=geometryAttribute.meshPerAttribute*geometryAttribute.count;}}else {enableAttribute(programAttribute);}gl.bindBuffer(34962,buffer);vertexAttribPointer(programAttribute,size,type,normalized,0,0);}}else if(name==='instanceMatrix'){var _attribute7=attributes.get(object.instanceMatrix);// TODO Attribute may not be available on context restore
  503. if(_attribute7===undefined)continue;var _buffer=_attribute7.buffer;var _type=_attribute7.type;enableAttributeAndDivisor(programAttribute+0,1);enableAttributeAndDivisor(programAttribute+1,1);enableAttributeAndDivisor(programAttribute+2,1);enableAttributeAndDivisor(programAttribute+3,1);gl.bindBuffer(34962,_buffer);gl.vertexAttribPointer(programAttribute+0,4,_type,false,64,0);gl.vertexAttribPointer(programAttribute+1,4,_type,false,64,16);gl.vertexAttribPointer(programAttribute+2,4,_type,false,64,32);gl.vertexAttribPointer(programAttribute+3,4,_type,false,64,48);}else if(name==='instanceColor'){var _attribute8=attributes.get(object.instanceColor);// TODO Attribute may not be available on context restore
  504. if(_attribute8===undefined)continue;var _buffer2=_attribute8.buffer;var _type2=_attribute8.type;enableAttributeAndDivisor(programAttribute,1);gl.bindBuffer(34962,_buffer2);gl.vertexAttribPointer(programAttribute,3,_type2,false,12,0);}else if(materialDefaultAttributeValues!==undefined){var value=materialDefaultAttributeValues[name];if(value!==undefined){switch(value.length){case 2:gl.vertexAttrib2fv(programAttribute,value);break;case 3:gl.vertexAttrib3fv(programAttribute,value);break;case 4:gl.vertexAttrib4fv(programAttribute,value);break;default:gl.vertexAttrib1fv(programAttribute,value);}}}}}disableUnusedAttributes();}function dispose(){reset();for(var geometryId in bindingStates){var programMap=bindingStates[geometryId];for(var programId in programMap){var stateMap=programMap[programId];for(var wireframe in stateMap){deleteVertexArrayObject(stateMap[wireframe].object);delete stateMap[wireframe];}delete programMap[programId];}delete bindingStates[geometryId];}}function releaseStatesOfGeometry(geometry){if(bindingStates[geometry.id]===undefined)return;var programMap=bindingStates[geometry.id];for(var programId in programMap){var stateMap=programMap[programId];for(var wireframe in stateMap){deleteVertexArrayObject(stateMap[wireframe].object);delete stateMap[wireframe];}delete programMap[programId];}delete bindingStates[geometry.id];}function releaseStatesOfProgram(program){for(var geometryId in bindingStates){var programMap=bindingStates[geometryId];if(programMap[program.id]===undefined)continue;var stateMap=programMap[program.id];for(var wireframe in stateMap){deleteVertexArrayObject(stateMap[wireframe].object);delete stateMap[wireframe];}delete programMap[program.id];}}function reset(){resetDefaultState();if(currentState===defaultState)return;currentState=defaultState;bindVertexArrayObject(currentState.object);}// for backward-compatilibity
  505. function resetDefaultState(){defaultState.geometry=null;defaultState.program=null;defaultState.wireframe=false;}return {setup:setup,reset:reset,resetDefaultState:resetDefaultState,dispose:dispose,releaseStatesOfGeometry:releaseStatesOfGeometry,releaseStatesOfProgram:releaseStatesOfProgram,initAttributes:initAttributes,enableAttribute:enableAttribute,disableUnusedAttributes:disableUnusedAttributes};}function WebGLBufferRenderer(gl,extensions,info,capabilities){var isWebGL2=capabilities.isWebGL2;var mode;function setMode(value){mode=value;}function render(start,count){gl.drawArrays(mode,start,count);info.update(count,mode,1);}function renderInstances(start,count,primcount){if(primcount===0)return;var extension,methodName;if(isWebGL2){extension=gl;methodName='drawArraysInstanced';}else {extension=extensions.get('ANGLE_instanced_arrays');methodName='drawArraysInstancedANGLE';if(extension===null){console.error('THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');return;}}extension[methodName](mode,start,count,primcount);info.update(count,mode,primcount);}//
  506. this.setMode=setMode;this.render=render;this.renderInstances=renderInstances;}function WebGLCapabilities(gl,extensions,parameters){var maxAnisotropy;function getMaxAnisotropy(){if(maxAnisotropy!==undefined)return maxAnisotropy;var extension=extensions.get('EXT_texture_filter_anisotropic');if(extension!==null){maxAnisotropy=gl.getParameter(extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT);}else {maxAnisotropy=0;}return maxAnisotropy;}function getMaxPrecision(precision){if(precision==='highp'){if(gl.getShaderPrecisionFormat(35633,36338).precision>0&&gl.getShaderPrecisionFormat(35632,36338).precision>0){return 'highp';}precision='mediump';}if(precision==='mediump'){if(gl.getShaderPrecisionFormat(35633,36337).precision>0&&gl.getShaderPrecisionFormat(35632,36337).precision>0){return 'mediump';}}return 'lowp';}/* eslint-disable no-undef */var isWebGL2=typeof WebGL2RenderingContext!=='undefined'&&gl instanceof WebGL2RenderingContext||typeof WebGL2ComputeRenderingContext!=='undefined'&&gl instanceof WebGL2ComputeRenderingContext;/* eslint-enable no-undef */var precision=parameters.precision!==undefined?parameters.precision:'highp';var maxPrecision=getMaxPrecision(precision);if(maxPrecision!==precision){console.warn('THREE.WebGLRenderer:',precision,'not supported, using',maxPrecision,'instead.');precision=maxPrecision;}var logarithmicDepthBuffer=parameters.logarithmicDepthBuffer===true;var maxTextures=gl.getParameter(34930);var maxVertexTextures=gl.getParameter(35660);var maxTextureSize=gl.getParameter(3379);var maxCubemapSize=gl.getParameter(34076);var maxAttributes=gl.getParameter(34921);var maxVertexUniforms=gl.getParameter(36347);var maxVaryings=gl.getParameter(36348);var maxFragmentUniforms=gl.getParameter(36349);var vertexTextures=maxVertexTextures>0;var floatFragmentTextures=isWebGL2||!!extensions.get('OES_texture_float');var floatVertexTextures=vertexTextures&&floatFragmentTextures;var maxSamples=isWebGL2?gl.getParameter(36183):0;return {isWebGL2:isWebGL2,getMaxAnisotropy:getMaxAnisotropy,getMaxPrecision:getMaxPrecision,precision:precision,logarithmicDepthBuffer:logarithmicDepthBuffer,maxTextures:maxTextures,maxVertexTextures:maxVertexTextures,maxTextureSize:maxTextureSize,maxCubemapSize:maxCubemapSize,maxAttributes:maxAttributes,maxVertexUniforms:maxVertexUniforms,maxVaryings:maxVaryings,maxFragmentUniforms:maxFragmentUniforms,vertexTextures:vertexTextures,floatFragmentTextures:floatFragmentTextures,floatVertexTextures:floatVertexTextures,maxSamples:maxSamples};}function WebGLClipping(properties){var scope=this;var globalState=null,numGlobalPlanes=0,localClippingEnabled=false,renderingShadows=false;var plane=new Plane(),viewNormalMatrix=new Matrix3(),uniform={value:null,needsUpdate:false};this.uniform=uniform;this.numPlanes=0;this.numIntersection=0;this.init=function(planes,enableLocalClipping,camera){var enabled=planes.length!==0||enableLocalClipping||// enable state of previous frame - the clipping code has to
  507. // run another frame in order to reset the state:
  508. numGlobalPlanes!==0||localClippingEnabled;localClippingEnabled=enableLocalClipping;globalState=projectPlanes(planes,camera,0);numGlobalPlanes=planes.length;return enabled;};this.beginShadows=function(){renderingShadows=true;projectPlanes(null);};this.endShadows=function(){renderingShadows=false;resetGlobalState();};this.setState=function(material,camera,useCache){var planes=material.clippingPlanes,clipIntersection=material.clipIntersection,clipShadows=material.clipShadows;var materialProperties=properties.get(material);if(!localClippingEnabled||planes===null||planes.length===0||renderingShadows&&!clipShadows){// there's no local clipping
  509. if(renderingShadows){// there's no global clipping
  510. projectPlanes(null);}else {resetGlobalState();}}else {var nGlobal=renderingShadows?0:numGlobalPlanes,lGlobal=nGlobal*4;var dstArray=materialProperties.clippingState||null;uniform.value=dstArray;// ensure unique state
  511. dstArray=projectPlanes(planes,camera,lGlobal,useCache);for(var _i72=0;_i72!==lGlobal;++_i72){dstArray[_i72]=globalState[_i72];}materialProperties.clippingState=dstArray;this.numIntersection=clipIntersection?this.numPlanes:0;this.numPlanes+=nGlobal;}};function resetGlobalState(){if(uniform.value!==globalState){uniform.value=globalState;uniform.needsUpdate=numGlobalPlanes>0;}scope.numPlanes=numGlobalPlanes;scope.numIntersection=0;}function projectPlanes(planes,camera,dstOffset,skipTransform){var nPlanes=planes!==null?planes.length:0;var dstArray=null;if(nPlanes!==0){dstArray=uniform.value;if(skipTransform!==true||dstArray===null){var flatSize=dstOffset+nPlanes*4,viewMatrix=camera.matrixWorldInverse;viewNormalMatrix.getNormalMatrix(viewMatrix);if(dstArray===null||dstArray.length<flatSize){dstArray=new Float32Array(flatSize);}for(var _i73=0,i4=dstOffset;_i73!==nPlanes;++_i73,i4+=4){plane.copy(planes[_i73]).applyMatrix4(viewMatrix,viewNormalMatrix);plane.normal.toArray(dstArray,i4);dstArray[i4+3]=plane.constant;}}uniform.value=dstArray;uniform.needsUpdate=true;}scope.numPlanes=nPlanes;scope.numIntersection=0;return dstArray;}}function WebGLCubeMaps(renderer){var cubemaps=new WeakMap();function mapTextureMapping(texture,mapping){if(mapping===EquirectangularReflectionMapping){texture.mapping=CubeReflectionMapping;}else if(mapping===EquirectangularRefractionMapping){texture.mapping=CubeRefractionMapping;}return texture;}function get(texture){if(texture&&texture.isTexture){var mapping=texture.mapping;if(mapping===EquirectangularReflectionMapping||mapping===EquirectangularRefractionMapping){if(cubemaps.has(texture)){var cubemap=cubemaps.get(texture).texture;return mapTextureMapping(cubemap,texture.mapping);}else {var image=texture.image;if(image&&image.height>0){var currentRenderList=renderer.getRenderList();var currentRenderTarget=renderer.getRenderTarget();var renderTarget=new WebGLCubeRenderTarget(image.height/2);renderTarget.fromEquirectangularTexture(renderer,texture);cubemaps.set(texture,renderTarget);renderer.setRenderTarget(currentRenderTarget);renderer.setRenderList(currentRenderList);texture.addEventListener('dispose',onTextureDispose);return mapTextureMapping(renderTarget.texture,texture.mapping);}else {// image not yet ready. try the conversion next frame
  512. return null;}}}}return texture;}function onTextureDispose(event){var texture=event.target;texture.removeEventListener('dispose',onTextureDispose);var cubemap=cubemaps.get(texture);if(cubemap!==undefined){cubemaps.delete(texture);cubemap.dispose();}}function dispose(){cubemaps=new WeakMap();}return {get:get,dispose:dispose};}function WebGLExtensions(gl){var extensions={};return {has:function has(name){if(extensions[name]!==undefined){return extensions[name]!==null;}var extension;switch(name){case'WEBGL_depth_texture':extension=gl.getExtension('WEBGL_depth_texture')||gl.getExtension('MOZ_WEBGL_depth_texture')||gl.getExtension('WEBKIT_WEBGL_depth_texture');break;case'EXT_texture_filter_anisotropic':extension=gl.getExtension('EXT_texture_filter_anisotropic')||gl.getExtension('MOZ_EXT_texture_filter_anisotropic')||gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic');break;case'WEBGL_compressed_texture_s3tc':extension=gl.getExtension('WEBGL_compressed_texture_s3tc')||gl.getExtension('MOZ_WEBGL_compressed_texture_s3tc')||gl.getExtension('WEBKIT_WEBGL_compressed_texture_s3tc');break;case'WEBGL_compressed_texture_pvrtc':extension=gl.getExtension('WEBGL_compressed_texture_pvrtc')||gl.getExtension('WEBKIT_WEBGL_compressed_texture_pvrtc');break;default:extension=gl.getExtension(name);}extensions[name]=extension;return extension!==null;},get:function get(name){if(!this.has(name)){console.warn('THREE.WebGLRenderer: '+name+' extension not supported.');}return extensions[name];}};}function WebGLGeometries(gl,attributes,info,bindingStates){var geometries=new WeakMap();var wireframeAttributes=new WeakMap();function onGeometryDispose(event){var geometry=event.target;var buffergeometry=geometries.get(geometry);if(buffergeometry.index!==null){attributes.remove(buffergeometry.index);}for(var name in buffergeometry.attributes){attributes.remove(buffergeometry.attributes[name]);}geometry.removeEventListener('dispose',onGeometryDispose);geometries.delete(geometry);var attribute=wireframeAttributes.get(buffergeometry);if(attribute){attributes.remove(attribute);wireframeAttributes.delete(buffergeometry);}bindingStates.releaseStatesOfGeometry(buffergeometry);if(geometry.isInstancedBufferGeometry===true){delete geometry._maxInstanceCount;}//
  513. info.memory.geometries--;}function get(object,geometry){var buffergeometry=geometries.get(geometry);if(buffergeometry)return buffergeometry;geometry.addEventListener('dispose',onGeometryDispose);if(geometry.isBufferGeometry){buffergeometry=geometry;}else if(geometry.isGeometry){if(geometry._bufferGeometry===undefined){geometry._bufferGeometry=new BufferGeometry().setFromObject(object);}buffergeometry=geometry._bufferGeometry;}geometries.set(geometry,buffergeometry);info.memory.geometries++;return buffergeometry;}function update(geometry){var geometryAttributes=geometry.attributes;// Updating index buffer in VAO now. See WebGLBindingStates.
  514. for(var name in geometryAttributes){attributes.update(geometryAttributes[name],34962);}// morph targets
  515. var morphAttributes=geometry.morphAttributes;for(var _name3 in morphAttributes){var array=morphAttributes[_name3];for(var _i74=0,l=array.length;_i74<l;_i74++){attributes.update(array[_i74],34962);}}}function updateWireframeAttribute(geometry){var indices=[];var geometryIndex=geometry.index;var geometryPosition=geometry.attributes.position;var version=0;if(geometryIndex!==null){var array=geometryIndex.array;version=geometryIndex.version;for(var _i75=0,l=array.length;_i75<l;_i75+=3){var a=array[_i75+0];var b=array[_i75+1];var c=array[_i75+2];indices.push(a,b,b,c,c,a);}}else {var _array=geometryPosition.array;version=geometryPosition.version;for(var _i76=0,_l4=_array.length/3-1;_i76<_l4;_i76+=3){var _a4=_i76+0;var _b4=_i76+1;var _c4=_i76+2;indices.push(_a4,_b4,_b4,_c4,_c4,_a4);}}var attribute=new(arrayMax(indices)>65535?Uint32BufferAttribute:Uint16BufferAttribute)(indices,1);attribute.version=version;// Updating index buffer in VAO now. See WebGLBindingStates
  516. //
  517. var previousAttribute=wireframeAttributes.get(geometry);if(previousAttribute)attributes.remove(previousAttribute);//
  518. wireframeAttributes.set(geometry,attribute);}function getWireframeAttribute(geometry){var currentAttribute=wireframeAttributes.get(geometry);if(currentAttribute){var geometryIndex=geometry.index;if(geometryIndex!==null){// if the attribute is obsolete, create a new one
  519. if(currentAttribute.version<geometryIndex.version){updateWireframeAttribute(geometry);}}}else {updateWireframeAttribute(geometry);}return wireframeAttributes.get(geometry);}return {get:get,update:update,getWireframeAttribute:getWireframeAttribute};}function WebGLIndexedBufferRenderer(gl,extensions,info,capabilities){var isWebGL2=capabilities.isWebGL2;var mode;function setMode(value){mode=value;}var type,bytesPerElement;function setIndex(value){type=value.type;bytesPerElement=value.bytesPerElement;}function render(start,count){gl.drawElements(mode,count,type,start*bytesPerElement);info.update(count,mode,1);}function renderInstances(start,count,primcount){if(primcount===0)return;var extension,methodName;if(isWebGL2){extension=gl;methodName='drawElementsInstanced';}else {extension=extensions.get('ANGLE_instanced_arrays');methodName='drawElementsInstancedANGLE';if(extension===null){console.error('THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');return;}}extension[methodName](mode,count,type,start*bytesPerElement,primcount);info.update(count,mode,primcount);}//
  520. this.setMode=setMode;this.setIndex=setIndex;this.render=render;this.renderInstances=renderInstances;}function WebGLInfo(gl){var memory={geometries:0,textures:0};var render={frame:0,calls:0,triangles:0,points:0,lines:0};function update(count,mode,instanceCount){render.calls++;switch(mode){case 4:render.triangles+=instanceCount*(count/3);break;case 1:render.lines+=instanceCount*(count/2);break;case 3:render.lines+=instanceCount*(count-1);break;case 2:render.lines+=instanceCount*count;break;case 0:render.points+=instanceCount*count;break;default:console.error('THREE.WebGLInfo: Unknown draw mode:',mode);break;}}function reset(){render.frame++;render.calls=0;render.triangles=0;render.points=0;render.lines=0;}return {memory:memory,render:render,programs:null,autoReset:true,reset:reset,update:update};}function numericalSort(a,b){return a[0]-b[0];}function absNumericalSort(a,b){return Math.abs(b[1])-Math.abs(a[1]);}function WebGLMorphtargets(gl){var influencesList={};var morphInfluences=new Float32Array(8);var workInfluences=[];for(var _i77=0;_i77<8;_i77++){workInfluences[_i77]=[_i77,0];}function update(object,geometry,material,program){var objectInfluences=object.morphTargetInfluences;// When object doesn't have morph target influences defined, we treat it as a 0-length array
  521. // This is important to make sure we set up morphTargetBaseInfluence / morphTargetInfluences
  522. var length=objectInfluences===undefined?0:objectInfluences.length;var influences=influencesList[geometry.id];if(influences===undefined){// initialise list
  523. influences=[];for(var _i78=0;_i78<length;_i78++){influences[_i78]=[_i78,0];}influencesList[geometry.id]=influences;}// Collect influences
  524. for(var _i79=0;_i79<length;_i79++){var influence=influences[_i79];influence[0]=_i79;influence[1]=objectInfluences[_i79];}influences.sort(absNumericalSort);for(var _i80=0;_i80<8;_i80++){if(_i80<length&&influences[_i80][1]){workInfluences[_i80][0]=influences[_i80][0];workInfluences[_i80][1]=influences[_i80][1];}else {workInfluences[_i80][0]=Number.MAX_SAFE_INTEGER;workInfluences[_i80][1]=0;}}workInfluences.sort(numericalSort);var morphTargets=material.morphTargets&&geometry.morphAttributes.position;var morphNormals=material.morphNormals&&geometry.morphAttributes.normal;var morphInfluencesSum=0;for(var _i81=0;_i81<8;_i81++){var _influence=workInfluences[_i81];var index=_influence[0];var value=_influence[1];if(index!==Number.MAX_SAFE_INTEGER&&value){if(morphTargets&&geometry.getAttribute('morphTarget'+_i81)!==morphTargets[index]){geometry.setAttribute('morphTarget'+_i81,morphTargets[index]);}if(morphNormals&&geometry.getAttribute('morphNormal'+_i81)!==morphNormals[index]){geometry.setAttribute('morphNormal'+_i81,morphNormals[index]);}morphInfluences[_i81]=value;morphInfluencesSum+=value;}else {if(morphTargets&&geometry.hasAttribute('morphTarget'+_i81)===true){geometry.deleteAttribute('morphTarget'+_i81);}if(morphNormals&&geometry.hasAttribute('morphNormal'+_i81)===true){geometry.deleteAttribute('morphNormal'+_i81);}morphInfluences[_i81]=0;}}// GLSL shader uses formula baseinfluence * base + sum(target * influence)
  525. // This allows us to switch between absolute morphs and relative morphs without changing shader code
  526. // When baseinfluence = 1 - sum(influence), the above is equivalent to sum((target - base) * influence)
  527. var morphBaseInfluence=geometry.morphTargetsRelative?1:1-morphInfluencesSum;program.getUniforms().setValue(gl,'morphTargetBaseInfluence',morphBaseInfluence);program.getUniforms().setValue(gl,'morphTargetInfluences',morphInfluences);}return {update:update};}function WebGLObjects(gl,geometries,attributes,info){var updateMap=new WeakMap();function update(object){var frame=info.render.frame;var geometry=object.geometry;var buffergeometry=geometries.get(object,geometry);// Update once per frame
  528. if(updateMap.get(buffergeometry)!==frame){if(geometry.isGeometry){buffergeometry.updateFromObject(object);}geometries.update(buffergeometry);updateMap.set(buffergeometry,frame);}if(object.isInstancedMesh){if(object.hasEventListener('dispose',onInstancedMeshDispose)===false){object.addEventListener('dispose',onInstancedMeshDispose);}attributes.update(object.instanceMatrix,34962);if(object.instanceColor!==null){attributes.update(object.instanceColor,34962);}}return buffergeometry;}function dispose(){updateMap=new WeakMap();}function onInstancedMeshDispose(event){var instancedMesh=event.target;instancedMesh.removeEventListener('dispose',onInstancedMeshDispose);attributes.remove(instancedMesh.instanceMatrix);if(instancedMesh.instanceColor!==null)attributes.remove(instancedMesh.instanceColor);}return {update:update,dispose:dispose};}function DataTexture2DArray(){var data=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;var width=arguments.length>1&&arguments[1]!==undefined?arguments[1]:1;var height=arguments.length>2&&arguments[2]!==undefined?arguments[2]:1;var depth=arguments.length>3&&arguments[3]!==undefined?arguments[3]:1;Texture.call(this,null);this.image={data,width,height,depth};this.magFilter=NearestFilter;this.minFilter=NearestFilter;this.wrapR=ClampToEdgeWrapping;this.generateMipmaps=false;this.flipY=false;this.needsUpdate=true;}DataTexture2DArray.prototype=Object.create(Texture.prototype);DataTexture2DArray.prototype.constructor=DataTexture2DArray;DataTexture2DArray.prototype.isDataTexture2DArray=true;function DataTexture3D(){var data=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;var width=arguments.length>1&&arguments[1]!==undefined?arguments[1]:1;var height=arguments.length>2&&arguments[2]!==undefined?arguments[2]:1;var depth=arguments.length>3&&arguments[3]!==undefined?arguments[3]:1;// We're going to add .setXXX() methods for setting properties later.
  529. // Users can still set in DataTexture3D directly.
  530. //
  531. // const texture = new THREE.DataTexture3D( data, width, height, depth );
  532. // texture.anisotropy = 16;
  533. //
  534. // See #14839
  535. Texture.call(this,null);this.image={data,width,height,depth};this.magFilter=NearestFilter;this.minFilter=NearestFilter;this.wrapR=ClampToEdgeWrapping;this.generateMipmaps=false;this.flipY=false;this.needsUpdate=true;}DataTexture3D.prototype=Object.create(Texture.prototype);DataTexture3D.prototype.constructor=DataTexture3D;DataTexture3D.prototype.isDataTexture3D=true;/**
  536. * Uniforms of a program.
  537. * Those form a tree structure with a special top-level container for the root,
  538. * which you get by calling 'new WebGLUniforms( gl, program )'.
  539. *
  540. *
  541. * Properties of inner nodes including the top-level container:
  542. *
  543. * .seq - array of nested uniforms
  544. * .map - nested uniforms by name
  545. *
  546. *
  547. * Methods of all nodes except the top-level container:
  548. *
  549. * .setValue( gl, value, [textures] )
  550. *
  551. * uploads a uniform value(s)
  552. * the 'textures' parameter is needed for sampler uniforms
  553. *
  554. *
  555. * Static methods of the top-level container (textures factorizations):
  556. *
  557. * .upload( gl, seq, values, textures )
  558. *
  559. * sets uniforms in 'seq' to 'values[id].value'
  560. *
  561. * .seqWithValue( seq, values ) : filteredSeq
  562. *
  563. * filters 'seq' entries with corresponding entry in values
  564. *
  565. *
  566. * Methods of the top-level container (textures factorizations):
  567. *
  568. * .setValue( gl, name, value, textures )
  569. *
  570. * sets uniform with name 'name' to 'value'
  571. *
  572. * .setOptional( gl, obj, prop )
  573. *
  574. * like .set for an optional property of the object
  575. *
  576. */var emptyTexture=new Texture();var emptyTexture2dArray=new DataTexture2DArray();var emptyTexture3d=new DataTexture3D();var emptyCubeTexture=new CubeTexture();// --- Utilities ---
  577. // Array Caches (provide typed arrays for temporary by size)
  578. var arrayCacheF32=[];var arrayCacheI32=[];// Float32Array caches used for uploading Matrix uniforms
  579. var mat4array=new Float32Array(16);var mat3array=new Float32Array(9);var mat2array=new Float32Array(4);// Flattening for arrays of vectors and matrices
  580. function flatten(array,nBlocks,blockSize){var firstElem=array[0];if(firstElem<=0||firstElem>0)return array;// unoptimized: ! isNaN( firstElem )
  581. // see http://jacksondunstan.com/articles/983
  582. var n=nBlocks*blockSize;var r=arrayCacheF32[n];if(r===undefined){r=new Float32Array(n);arrayCacheF32[n]=r;}if(nBlocks!==0){firstElem.toArray(r,0);for(var _i82=1,offset=0;_i82!==nBlocks;++_i82){offset+=blockSize;array[_i82].toArray(r,offset);}}return r;}function arraysEqual(a,b){if(a.length!==b.length)return false;for(var _i83=0,l=a.length;_i83<l;_i83++){if(a[_i83]!==b[_i83])return false;}return true;}function copyArray(a,b){for(var _i84=0,l=b.length;_i84<l;_i84++){a[_i84]=b[_i84];}}// Texture unit allocation
  583. function allocTexUnits(textures,n){var r=arrayCacheI32[n];if(r===undefined){r=new Int32Array(n);arrayCacheI32[n]=r;}for(var _i85=0;_i85!==n;++_i85){r[_i85]=textures.allocateTextureUnit();}return r;}// --- Setters ---
  584. // Note: Defining these methods externally, because they come in a bunch
  585. // and this way their names minify.
  586. // Single scalar
  587. function setValueV1f(gl,v){var cache=this.cache;if(cache[0]===v)return;gl.uniform1f(this.addr,v);cache[0]=v;}// Single float vector (from flat array or THREE.VectorN)
  588. function setValueV2f(gl,v){var cache=this.cache;if(v.x!==undefined){if(cache[0]!==v.x||cache[1]!==v.y){gl.uniform2f(this.addr,v.x,v.y);cache[0]=v.x;cache[1]=v.y;}}else {if(arraysEqual(cache,v))return;gl.uniform2fv(this.addr,v);copyArray(cache,v);}}function setValueV3f(gl,v){var cache=this.cache;if(v.x!==undefined){if(cache[0]!==v.x||cache[1]!==v.y||cache[2]!==v.z){gl.uniform3f(this.addr,v.x,v.y,v.z);cache[0]=v.x;cache[1]=v.y;cache[2]=v.z;}}else if(v.r!==undefined){if(cache[0]!==v.r||cache[1]!==v.g||cache[2]!==v.b){gl.uniform3f(this.addr,v.r,v.g,v.b);cache[0]=v.r;cache[1]=v.g;cache[2]=v.b;}}else {if(arraysEqual(cache,v))return;gl.uniform3fv(this.addr,v);copyArray(cache,v);}}function setValueV4f(gl,v){var cache=this.cache;if(v.x!==undefined){if(cache[0]!==v.x||cache[1]!==v.y||cache[2]!==v.z||cache[3]!==v.w){gl.uniform4f(this.addr,v.x,v.y,v.z,v.w);cache[0]=v.x;cache[1]=v.y;cache[2]=v.z;cache[3]=v.w;}}else {if(arraysEqual(cache,v))return;gl.uniform4fv(this.addr,v);copyArray(cache,v);}}// Single matrix (from flat array or MatrixN)
  589. function setValueM2(gl,v){var cache=this.cache;var elements=v.elements;if(elements===undefined){if(arraysEqual(cache,v))return;gl.uniformMatrix2fv(this.addr,false,v);copyArray(cache,v);}else {if(arraysEqual(cache,elements))return;mat2array.set(elements);gl.uniformMatrix2fv(this.addr,false,mat2array);copyArray(cache,elements);}}function setValueM3(gl,v){var cache=this.cache;var elements=v.elements;if(elements===undefined){if(arraysEqual(cache,v))return;gl.uniformMatrix3fv(this.addr,false,v);copyArray(cache,v);}else {if(arraysEqual(cache,elements))return;mat3array.set(elements);gl.uniformMatrix3fv(this.addr,false,mat3array);copyArray(cache,elements);}}function setValueM4(gl,v){var cache=this.cache;var elements=v.elements;if(elements===undefined){if(arraysEqual(cache,v))return;gl.uniformMatrix4fv(this.addr,false,v);copyArray(cache,v);}else {if(arraysEqual(cache,elements))return;mat4array.set(elements);gl.uniformMatrix4fv(this.addr,false,mat4array);copyArray(cache,elements);}}// Single texture (2D / Cube)
  590. function setValueT1(gl,v,textures){var cache=this.cache;var unit=textures.allocateTextureUnit();if(cache[0]!==unit){gl.uniform1i(this.addr,unit);cache[0]=unit;}textures.safeSetTexture2D(v||emptyTexture,unit);}function setValueT2DArray1(gl,v,textures){var cache=this.cache;var unit=textures.allocateTextureUnit();if(cache[0]!==unit){gl.uniform1i(this.addr,unit);cache[0]=unit;}textures.setTexture2DArray(v||emptyTexture2dArray,unit);}function setValueT3D1(gl,v,textures){var cache=this.cache;var unit=textures.allocateTextureUnit();if(cache[0]!==unit){gl.uniform1i(this.addr,unit);cache[0]=unit;}textures.setTexture3D(v||emptyTexture3d,unit);}function setValueT6(gl,v,textures){var cache=this.cache;var unit=textures.allocateTextureUnit();if(cache[0]!==unit){gl.uniform1i(this.addr,unit);cache[0]=unit;}textures.safeSetTextureCube(v||emptyCubeTexture,unit);}// Integer / Boolean vectors or arrays thereof (always flat arrays)
  591. function setValueV1i(gl,v){var cache=this.cache;if(cache[0]===v)return;gl.uniform1i(this.addr,v);cache[0]=v;}function setValueV2i(gl,v){var cache=this.cache;if(arraysEqual(cache,v))return;gl.uniform2iv(this.addr,v);copyArray(cache,v);}function setValueV3i(gl,v){var cache=this.cache;if(arraysEqual(cache,v))return;gl.uniform3iv(this.addr,v);copyArray(cache,v);}function setValueV4i(gl,v){var cache=this.cache;if(arraysEqual(cache,v))return;gl.uniform4iv(this.addr,v);copyArray(cache,v);}// uint
  592. function setValueV1ui(gl,v){var cache=this.cache;if(cache[0]===v)return;gl.uniform1ui(this.addr,v);cache[0]=v;}// Helper to pick the right setter for the singular case
  593. function getSingularSetter(type){switch(type){case 0x1406:return setValueV1f;// FLOAT
  594. case 0x8b50:return setValueV2f;// _VEC2
  595. case 0x8b51:return setValueV3f;// _VEC3
  596. case 0x8b52:return setValueV4f;// _VEC4
  597. case 0x8b5a:return setValueM2;// _MAT2
  598. case 0x8b5b:return setValueM3;// _MAT3
  599. case 0x8b5c:return setValueM4;// _MAT4
  600. case 0x1404:case 0x8b56:return setValueV1i;// INT, BOOL
  601. case 0x8b53:case 0x8b57:return setValueV2i;// _VEC2
  602. case 0x8b54:case 0x8b58:return setValueV3i;// _VEC3
  603. case 0x8b55:case 0x8b59:return setValueV4i;// _VEC4
  604. case 0x1405:return setValueV1ui;// UINT
  605. case 0x8b5e:// SAMPLER_2D
  606. case 0x8d66:// SAMPLER_EXTERNAL_OES
  607. case 0x8dca:// INT_SAMPLER_2D
  608. case 0x8dd2:// UNSIGNED_INT_SAMPLER_2D
  609. case 0x8b62:// SAMPLER_2D_SHADOW
  610. return setValueT1;case 0x8b5f:// SAMPLER_3D
  611. case 0x8dcb:// INT_SAMPLER_3D
  612. case 0x8dd3:// UNSIGNED_INT_SAMPLER_3D
  613. return setValueT3D1;case 0x8b60:// SAMPLER_CUBE
  614. case 0x8dcc:// INT_SAMPLER_CUBE
  615. case 0x8dd4:// UNSIGNED_INT_SAMPLER_CUBE
  616. case 0x8dc5:// SAMPLER_CUBE_SHADOW
  617. return setValueT6;case 0x8dc1:// SAMPLER_2D_ARRAY
  618. case 0x8dcf:// INT_SAMPLER_2D_ARRAY
  619. case 0x8dd7:// UNSIGNED_INT_SAMPLER_2D_ARRAY
  620. case 0x8dc4:// SAMPLER_2D_ARRAY_SHADOW
  621. return setValueT2DArray1;}}// Array of scalars
  622. function setValueV1fArray(gl,v){gl.uniform1fv(this.addr,v);}// Integer / Boolean vectors or arrays thereof (always flat arrays)
  623. function setValueV1iArray(gl,v){gl.uniform1iv(this.addr,v);}function setValueV2iArray(gl,v){gl.uniform2iv(this.addr,v);}function setValueV3iArray(gl,v){gl.uniform3iv(this.addr,v);}function setValueV4iArray(gl,v){gl.uniform4iv(this.addr,v);}// Array of vectors (flat or from THREE classes)
  624. function setValueV2fArray(gl,v){var data=flatten(v,this.size,2);gl.uniform2fv(this.addr,data);}function setValueV3fArray(gl,v){var data=flatten(v,this.size,3);gl.uniform3fv(this.addr,data);}function setValueV4fArray(gl,v){var data=flatten(v,this.size,4);gl.uniform4fv(this.addr,data);}// Array of matrices (flat or from THREE clases)
  625. function setValueM2Array(gl,v){var data=flatten(v,this.size,4);gl.uniformMatrix2fv(this.addr,false,data);}function setValueM3Array(gl,v){var data=flatten(v,this.size,9);gl.uniformMatrix3fv(this.addr,false,data);}function setValueM4Array(gl,v){var data=flatten(v,this.size,16);gl.uniformMatrix4fv(this.addr,false,data);}// Array of textures (2D / Cube)
  626. function setValueT1Array(gl,v,textures){var n=v.length;var units=allocTexUnits(textures,n);gl.uniform1iv(this.addr,units);for(var _i86=0;_i86!==n;++_i86){textures.safeSetTexture2D(v[_i86]||emptyTexture,units[_i86]);}}function setValueT6Array(gl,v,textures){var n=v.length;var units=allocTexUnits(textures,n);gl.uniform1iv(this.addr,units);for(var _i87=0;_i87!==n;++_i87){textures.safeSetTextureCube(v[_i87]||emptyCubeTexture,units[_i87]);}}// Helper to pick the right setter for a pure (bottom-level) array
  627. function getPureArraySetter(type){switch(type){case 0x1406:return setValueV1fArray;// FLOAT
  628. case 0x8b50:return setValueV2fArray;// _VEC2
  629. case 0x8b51:return setValueV3fArray;// _VEC3
  630. case 0x8b52:return setValueV4fArray;// _VEC4
  631. case 0x8b5a:return setValueM2Array;// _MAT2
  632. case 0x8b5b:return setValueM3Array;// _MAT3
  633. case 0x8b5c:return setValueM4Array;// _MAT4
  634. case 0x1404:case 0x8b56:return setValueV1iArray;// INT, BOOL
  635. case 0x8b53:case 0x8b57:return setValueV2iArray;// _VEC2
  636. case 0x8b54:case 0x8b58:return setValueV3iArray;// _VEC3
  637. case 0x8b55:case 0x8b59:return setValueV4iArray;// _VEC4
  638. case 0x8b5e:// SAMPLER_2D
  639. case 0x8d66:// SAMPLER_EXTERNAL_OES
  640. case 0x8dca:// INT_SAMPLER_2D
  641. case 0x8dd2:// UNSIGNED_INT_SAMPLER_2D
  642. case 0x8b62:// SAMPLER_2D_SHADOW
  643. return setValueT1Array;case 0x8b60:// SAMPLER_CUBE
  644. case 0x8dcc:// INT_SAMPLER_CUBE
  645. case 0x8dd4:// UNSIGNED_INT_SAMPLER_CUBE
  646. case 0x8dc5:// SAMPLER_CUBE_SHADOW
  647. return setValueT6Array;}}// --- Uniform Classes ---
  648. function SingleUniform(id,activeInfo,addr){this.id=id;this.addr=addr;this.cache=[];this.setValue=getSingularSetter(activeInfo.type);// this.path = activeInfo.name; // DEBUG
  649. }function PureArrayUniform(id,activeInfo,addr){this.id=id;this.addr=addr;this.cache=[];this.size=activeInfo.size;this.setValue=getPureArraySetter(activeInfo.type);// this.path = activeInfo.name; // DEBUG
  650. }PureArrayUniform.prototype.updateCache=function(data){var cache=this.cache;if(data instanceof Float32Array&&cache.length!==data.length){this.cache=new Float32Array(data.length);}copyArray(cache,data);};function StructuredUniform(id){this.id=id;this.seq=[];this.map={};}StructuredUniform.prototype.setValue=function(gl,value,textures){var seq=this.seq;for(var _i88=0,n=seq.length;_i88!==n;++_i88){var u=seq[_i88];u.setValue(gl,value[u.id],textures);}};// --- Top-level ---
  651. // Parser - builds up the property tree from the path strings
  652. var RePathPart=/(\w+)(\])?(\[|\.)?/g;// extracts
  653. // - the identifier (member name or array index)
  654. // - followed by an optional right bracket (found when array index)
  655. // - followed by an optional left bracket or dot (type of subscript)
  656. //
  657. // Note: These portions can be read in a non-overlapping fashion and
  658. // allow straightforward parsing of the hierarchy that WebGL encodes
  659. // in the uniform names.
  660. function addUniform(container,uniformObject){container.seq.push(uniformObject);container.map[uniformObject.id]=uniformObject;}function parseUniform(activeInfo,addr,container){var path=activeInfo.name,pathLength=path.length;// reset RegExp object, because of the early exit of a previous run
  661. RePathPart.lastIndex=0;while(true){var match=RePathPart.exec(path),matchEnd=RePathPart.lastIndex;var id=match[1];var idIsIndex=match[2]===']',subscript=match[3];if(idIsIndex)id=id|0;// convert to integer
  662. if(subscript===undefined||subscript==='['&&matchEnd+2===pathLength){// bare name or "pure" bottom-level array "[0]" suffix
  663. addUniform(container,subscript===undefined?new SingleUniform(id,activeInfo,addr):new PureArrayUniform(id,activeInfo,addr));break;}else {// step into inner node / create it in case it doesn't exist
  664. var map=container.map;var next=map[id];if(next===undefined){next=new StructuredUniform(id);addUniform(container,next);}container=next;}}}// Root Container
  665. function WebGLUniforms(gl,program){this.seq=[];this.map={};var n=gl.getProgramParameter(program,35718);for(var _i89=0;_i89<n;++_i89){var info=gl.getActiveUniform(program,_i89),addr=gl.getUniformLocation(program,info.name);parseUniform(info,addr,this);}}WebGLUniforms.prototype.setValue=function(gl,name,value,textures){var u=this.map[name];if(u!==undefined)u.setValue(gl,value,textures);};WebGLUniforms.prototype.setOptional=function(gl,object,name){var v=object[name];if(v!==undefined)this.setValue(gl,name,v);};// Static interface
  666. WebGLUniforms.upload=function(gl,seq,values,textures){for(var _i90=0,n=seq.length;_i90!==n;++_i90){var u=seq[_i90],v=values[u.id];if(v.needsUpdate!==false){// note: always updating when .needsUpdate is undefined
  667. u.setValue(gl,v.value,textures);}}};WebGLUniforms.seqWithValue=function(seq,values){var r=[];for(var _i91=0,n=seq.length;_i91!==n;++_i91){var u=seq[_i91];if(u.id in values)r.push(u);}return r;};function WebGLShader(gl,type,string){var shader=gl.createShader(type);gl.shaderSource(shader,string);gl.compileShader(shader);return shader;}var programIdCount=0;function addLineNumbers(string){var lines=string.split('\n');for(var _i92=0;_i92<lines.length;_i92++){lines[_i92]=_i92+1+': '+lines[_i92];}return lines.join('\n');}function getEncodingComponents(encoding){switch(encoding){case LinearEncoding:return ['Linear','( value )'];case sRGBEncoding:return ['sRGB','( value )'];case RGBEEncoding:return ['RGBE','( value )'];case RGBM7Encoding:return ['RGBM','( value, 7.0 )'];case RGBM16Encoding:return ['RGBM','( value, 16.0 )'];case RGBDEncoding:return ['RGBD','( value, 256.0 )'];case GammaEncoding:return ['Gamma','( value, float( GAMMA_FACTOR ) )'];case LogLuvEncoding:return ['LogLuv','( value )'];default:console.warn('THREE.WebGLProgram: Unsupported encoding:',encoding);return ['Linear','( value )'];}}function getShaderErrors(gl,shader,type){var status=gl.getShaderParameter(shader,35713);var log=gl.getShaderInfoLog(shader).trim();if(status&&log==='')return '';// --enable-privileged-webgl-extension
  668. // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  669. var source=gl.getShaderSource(shader);return 'THREE.WebGLShader: gl.getShaderInfoLog() '+type+'\n'+log+addLineNumbers(source);}function getTexelDecodingFunction(functionName,encoding){var components=getEncodingComponents(encoding);return 'vec4 '+functionName+'( vec4 value ) { return '+components[0]+'ToLinear'+components[1]+'; }';}function getTexelEncodingFunction(functionName,encoding){var components=getEncodingComponents(encoding);return 'vec4 '+functionName+'( vec4 value ) { return LinearTo'+components[0]+components[1]+'; }';}function getToneMappingFunction(functionName,toneMapping){var toneMappingName;switch(toneMapping){case LinearToneMapping:toneMappingName='Linear';break;case ReinhardToneMapping:toneMappingName='Reinhard';break;case CineonToneMapping:toneMappingName='OptimizedCineon';break;case ACESFilmicToneMapping:toneMappingName='ACESFilmic';break;case CustomToneMapping:toneMappingName='Custom';break;default:console.warn('THREE.WebGLProgram: Unsupported toneMapping:',toneMapping);toneMappingName='Linear';}return 'vec3 '+functionName+'( vec3 color ) { return '+toneMappingName+'ToneMapping( color ); }';}function generateExtensions(parameters){var chunks=[parameters.extensionDerivatives||parameters.envMapCubeUV||parameters.bumpMap||parameters.tangentSpaceNormalMap||parameters.clearcoatNormalMap||parameters.flatShading||parameters.shaderID==='physical'?'#extension GL_OES_standard_derivatives : enable':'',(parameters.extensionFragDepth||parameters.logarithmicDepthBuffer)&&parameters.rendererExtensionFragDepth?'#extension GL_EXT_frag_depth : enable':'',parameters.extensionDrawBuffers&&parameters.rendererExtensionDrawBuffers?'#extension GL_EXT_draw_buffers : require':'',(parameters.extensionShaderTextureLOD||parameters.envMap)&&parameters.rendererExtensionShaderTextureLod?'#extension GL_EXT_shader_texture_lod : enable':''];return chunks.filter(filterEmptyLine).join('\n');}function generateDefines(defines){var chunks=[];for(var name in defines){var value=defines[name];if(value===false)continue;chunks.push('#define '+name+' '+value);}return chunks.join('\n');}function fetchAttributeLocations(gl,program){var attributes={};var n=gl.getProgramParameter(program,35721);for(var _i93=0;_i93<n;_i93++){var info=gl.getActiveAttrib(program,_i93);var name=info.name;// console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  670. attributes[name]=gl.getAttribLocation(program,name);}return attributes;}function filterEmptyLine(string){return string!=='';}function replaceLightNums(string,parameters){return string.replace(/NUM_DIR_LIGHTS/g,parameters.numDirLights).replace(/NUM_SPOT_LIGHTS/g,parameters.numSpotLights).replace(/NUM_RECT_AREA_LIGHTS/g,parameters.numRectAreaLights).replace(/NUM_POINT_LIGHTS/g,parameters.numPointLights).replace(/NUM_HEMI_LIGHTS/g,parameters.numHemiLights).replace(/NUM_DIR_LIGHT_SHADOWS/g,parameters.numDirLightShadows).replace(/NUM_SPOT_LIGHT_SHADOWS/g,parameters.numSpotLightShadows).replace(/NUM_POINT_LIGHT_SHADOWS/g,parameters.numPointLightShadows);}function replaceClippingPlaneNums(string,parameters){return string.replace(/NUM_CLIPPING_PLANES/g,parameters.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g,parameters.numClippingPlanes-parameters.numClipIntersection);}// Resolve Includes
  671. var includePattern=/^[ \t]*#include +<([\w\d./]+)>/gm;function resolveIncludes(string){return string.replace(includePattern,includeReplacer);}function includeReplacer(match,include){var string=ShaderChunk[include];if(string===undefined){throw new Error('Can not resolve #include <'+include+'>');}return resolveIncludes(string);}// Unroll Loops
  672. var deprecatedUnrollLoopPattern=/#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;var unrollLoopPattern=/#pragma unroll_loop_start\s+for\s*\(\s*int\s+i\s*=\s*(\d+)\s*;\s*i\s*<\s*(\d+)\s*;\s*i\s*\+\+\s*\)\s*{([\s\S]+?)}\s+#pragma unroll_loop_end/g;function unrollLoops(string){return string.replace(unrollLoopPattern,loopReplacer).replace(deprecatedUnrollLoopPattern,deprecatedLoopReplacer);}function deprecatedLoopReplacer(match,start,end,snippet){console.warn('WebGLProgram: #pragma unroll_loop shader syntax is deprecated. Please use #pragma unroll_loop_start syntax instead.');return loopReplacer(match,start,end,snippet);}function loopReplacer(match,start,end,snippet){var string='';for(var _i94=parseInt(start);_i94<parseInt(end);_i94++){string+=snippet.replace(/\[\s*i\s*\]/g,'[ '+_i94+' ]').replace(/UNROLLED_LOOP_INDEX/g,_i94);}return string;}//
  673. function generatePrecision(parameters){var precisionstring='precision '+parameters.precision+' float;\nprecision '+parameters.precision+' int;';if(parameters.precision==='highp'){precisionstring+='\n#define HIGH_PRECISION';}else if(parameters.precision==='mediump'){precisionstring+='\n#define MEDIUM_PRECISION';}else if(parameters.precision==='lowp'){precisionstring+='\n#define LOW_PRECISION';}return precisionstring;}function generateShadowMapTypeDefine(parameters){var shadowMapTypeDefine='SHADOWMAP_TYPE_BASIC';if(parameters.shadowMapType===PCFShadowMap){shadowMapTypeDefine='SHADOWMAP_TYPE_PCF';}else if(parameters.shadowMapType===PCFSoftShadowMap){shadowMapTypeDefine='SHADOWMAP_TYPE_PCF_SOFT';}else if(parameters.shadowMapType===VSMShadowMap){shadowMapTypeDefine='SHADOWMAP_TYPE_VSM';}return shadowMapTypeDefine;}function generateEnvMapTypeDefine(parameters){var envMapTypeDefine='ENVMAP_TYPE_CUBE';if(parameters.envMap){switch(parameters.envMapMode){case CubeReflectionMapping:case CubeRefractionMapping:envMapTypeDefine='ENVMAP_TYPE_CUBE';break;case CubeUVReflectionMapping:case CubeUVRefractionMapping:envMapTypeDefine='ENVMAP_TYPE_CUBE_UV';break;}}return envMapTypeDefine;}function generateEnvMapModeDefine(parameters){var envMapModeDefine='ENVMAP_MODE_REFLECTION';if(parameters.envMap){switch(parameters.envMapMode){case CubeRefractionMapping:case CubeUVRefractionMapping:envMapModeDefine='ENVMAP_MODE_REFRACTION';break;}}return envMapModeDefine;}function generateEnvMapBlendingDefine(parameters){var envMapBlendingDefine='ENVMAP_BLENDING_NONE';if(parameters.envMap){switch(parameters.combine){case MultiplyOperation:envMapBlendingDefine='ENVMAP_BLENDING_MULTIPLY';break;case MixOperation:envMapBlendingDefine='ENVMAP_BLENDING_MIX';break;case AddOperation:envMapBlendingDefine='ENVMAP_BLENDING_ADD';break;}}return envMapBlendingDefine;}function WebGLProgram(renderer,cacheKey,parameters,bindingStates){var gl=renderer.getContext();var defines=parameters.defines;var vertexShader=parameters.vertexShader;var fragmentShader=parameters.fragmentShader;var shadowMapTypeDefine=generateShadowMapTypeDefine(parameters);var envMapTypeDefine=generateEnvMapTypeDefine(parameters);var envMapModeDefine=generateEnvMapModeDefine(parameters);var envMapBlendingDefine=generateEnvMapBlendingDefine(parameters);var gammaFactorDefine=renderer.gammaFactor>0?renderer.gammaFactor:1.0;var customExtensions=parameters.isWebGL2?'':generateExtensions(parameters);var customDefines=generateDefines(defines);var program=gl.createProgram();var prefixVertex,prefixFragment;var versionString=parameters.glslVersion?'#version '+parameters.glslVersion+'\n':'';if(parameters.isRawShaderMaterial){prefixVertex=[customDefines].filter(filterEmptyLine).join('\n');if(prefixVertex.length>0){prefixVertex+='\n';}prefixFragment=[customExtensions,customDefines].filter(filterEmptyLine).join('\n');if(prefixFragment.length>0){prefixFragment+='\n';}}else {prefixVertex=[generatePrecision(parameters),'#define SHADER_NAME '+parameters.shaderName,customDefines,parameters.instancing?'#define USE_INSTANCING':'',parameters.instancingColor?'#define USE_INSTANCING_COLOR':'',parameters.supportsVertexTextures?'#define VERTEX_TEXTURES':'','#define GAMMA_FACTOR '+gammaFactorDefine,'#define MAX_BONES '+parameters.maxBones,parameters.useFog&&parameters.fog?'#define USE_FOG':'',parameters.useFog&&parameters.fogExp2?'#define FOG_EXP2':'',parameters.map?'#define USE_MAP':'',parameters.envMap?'#define USE_ENVMAP':'',parameters.envMap?'#define '+envMapModeDefine:'',parameters.lightMap?'#define USE_LIGHTMAP':'',parameters.aoMap?'#define USE_AOMAP':'',parameters.emissiveMap?'#define USE_EMISSIVEMAP':'',parameters.bumpMap?'#define USE_BUMPMAP':'',parameters.normalMap?'#define USE_NORMALMAP':'',parameters.normalMap&&parameters.objectSpaceNormalMap?'#define OBJECTSPACE_NORMALMAP':'',parameters.normalMap&&parameters.tangentSpaceNormalMap?'#define TANGENTSPACE_NORMALMAP':'',parameters.clearcoatMap?'#define USE_CLEARCOATMAP':'',parameters.clearcoatRoughnessMap?'#define USE_CLEARCOAT_ROUGHNESSMAP':'',parameters.clearcoatNormalMap?'#define USE_CLEARCOAT_NORMALMAP':'',parameters.displacementMap&&parameters.supportsVertexTextures?'#define USE_DISPLACEMENTMAP':'',parameters.specularMap?'#define USE_SPECULARMAP':'',parameters.roughnessMap?'#define USE_ROUGHNESSMAP':'',parameters.metalnessMap?'#define USE_METALNESSMAP':'',parameters.alphaMap?'#define USE_ALPHAMAP':'',parameters.transmissionMap?'#define USE_TRANSMISSIONMAP':'',parameters.vertexTangents?'#define USE_TANGENT':'',parameters.vertexColors?'#define USE_COLOR':'',parameters.vertexUvs?'#define USE_UV':'',parameters.uvsVertexOnly?'#define UVS_VERTEX_ONLY':'',parameters.flatShading?'#define FLAT_SHADED':'',parameters.skinning?'#define USE_SKINNING':'',parameters.useVertexTexture?'#define BONE_TEXTURE':'',parameters.morphTargets?'#define USE_MORPHTARGETS':'',parameters.morphNormals&&parameters.flatShading===false?'#define USE_MORPHNORMALS':'',parameters.doubleSided?'#define DOUBLE_SIDED':'',parameters.flipSided?'#define FLIP_SIDED':'',parameters.shadowMapEnabled?'#define USE_SHADOWMAP':'',parameters.shadowMapEnabled?'#define '+shadowMapTypeDefine:'',parameters.sizeAttenuation?'#define USE_SIZEATTENUATION':'',parameters.logarithmicDepthBuffer?'#define USE_LOGDEPTHBUF':'',parameters.logarithmicDepthBuffer&&parameters.rendererExtensionFragDepth?'#define USE_LOGDEPTHBUF_EXT':'','uniform mat4 modelMatrix;','uniform mat4 modelViewMatrix;','uniform mat4 projectionMatrix;','uniform mat4 viewMatrix;','uniform mat3 normalMatrix;','uniform vec3 cameraPosition;','uniform bool isOrthographic;','#ifdef USE_INSTANCING',' attribute mat4 instanceMatrix;','#endif','#ifdef USE_INSTANCING_COLOR',' attribute vec3 instanceColor;','#endif','attribute vec3 position;','attribute vec3 normal;','attribute vec2 uv;','#ifdef USE_TANGENT',' attribute vec4 tangent;','#endif','#ifdef USE_COLOR',' attribute vec3 color;','#endif','#ifdef USE_MORPHTARGETS',' attribute vec3 morphTarget0;',' attribute vec3 morphTarget1;',' attribute vec3 morphTarget2;',' attribute vec3 morphTarget3;',' #ifdef USE_MORPHNORMALS',' attribute vec3 morphNormal0;',' attribute vec3 morphNormal1;',' attribute vec3 morphNormal2;',' attribute vec3 morphNormal3;',' #else',' attribute vec3 morphTarget4;',' attribute vec3 morphTarget5;',' attribute vec3 morphTarget6;',' attribute vec3 morphTarget7;',' #endif','#endif','#ifdef USE_SKINNING',' attribute vec4 skinIndex;',' attribute vec4 skinWeight;','#endif','\n'].filter(filterEmptyLine).join('\n');prefixFragment=[customExtensions,generatePrecision(parameters),'#define SHADER_NAME '+parameters.shaderName,customDefines,parameters.alphaTest?'#define ALPHATEST '+parameters.alphaTest+(parameters.alphaTest%1?'':'.0'):'',// add '.0' if integer
  674. '#define GAMMA_FACTOR '+gammaFactorDefine,parameters.useFog&&parameters.fog?'#define USE_FOG':'',parameters.useFog&&parameters.fogExp2?'#define FOG_EXP2':'',parameters.map?'#define USE_MAP':'',parameters.matcap?'#define USE_MATCAP':'',parameters.envMap?'#define USE_ENVMAP':'',parameters.envMap?'#define '+envMapTypeDefine:'',parameters.envMap?'#define '+envMapModeDefine:'',parameters.envMap?'#define '+envMapBlendingDefine:'',parameters.lightMap?'#define USE_LIGHTMAP':'',parameters.aoMap?'#define USE_AOMAP':'',parameters.emissiveMap?'#define USE_EMISSIVEMAP':'',parameters.bumpMap?'#define USE_BUMPMAP':'',parameters.normalMap?'#define USE_NORMALMAP':'',parameters.normalMap&&parameters.objectSpaceNormalMap?'#define OBJECTSPACE_NORMALMAP':'',parameters.normalMap&&parameters.tangentSpaceNormalMap?'#define TANGENTSPACE_NORMALMAP':'',parameters.clearcoatMap?'#define USE_CLEARCOATMAP':'',parameters.clearcoatRoughnessMap?'#define USE_CLEARCOAT_ROUGHNESSMAP':'',parameters.clearcoatNormalMap?'#define USE_CLEARCOAT_NORMALMAP':'',parameters.specularMap?'#define USE_SPECULARMAP':'',parameters.roughnessMap?'#define USE_ROUGHNESSMAP':'',parameters.metalnessMap?'#define USE_METALNESSMAP':'',parameters.alphaMap?'#define USE_ALPHAMAP':'',parameters.sheen?'#define USE_SHEEN':'',parameters.transmissionMap?'#define USE_TRANSMISSIONMAP':'',parameters.vertexTangents?'#define USE_TANGENT':'',parameters.vertexColors||parameters.instancingColor?'#define USE_COLOR':'',parameters.vertexUvs?'#define USE_UV':'',parameters.uvsVertexOnly?'#define UVS_VERTEX_ONLY':'',parameters.gradientMap?'#define USE_GRADIENTMAP':'',parameters.flatShading?'#define FLAT_SHADED':'',parameters.doubleSided?'#define DOUBLE_SIDED':'',parameters.flipSided?'#define FLIP_SIDED':'',parameters.shadowMapEnabled?'#define USE_SHADOWMAP':'',parameters.shadowMapEnabled?'#define '+shadowMapTypeDefine:'',parameters.premultipliedAlpha?'#define PREMULTIPLIED_ALPHA':'',parameters.physicallyCorrectLights?'#define PHYSICALLY_CORRECT_LIGHTS':'',parameters.logarithmicDepthBuffer?'#define USE_LOGDEPTHBUF':'',parameters.logarithmicDepthBuffer&&parameters.rendererExtensionFragDepth?'#define USE_LOGDEPTHBUF_EXT':'',(parameters.extensionShaderTextureLOD||parameters.envMap)&&parameters.rendererExtensionShaderTextureLod?'#define TEXTURE_LOD_EXT':'','uniform mat4 viewMatrix;','uniform vec3 cameraPosition;','uniform bool isOrthographic;',parameters.toneMapping!==NoToneMapping?'#define TONE_MAPPING':'',parameters.toneMapping!==NoToneMapping?ShaderChunk['tonemapping_pars_fragment']:'',// this code is required here because it is used by the toneMapping() function defined below
  675. parameters.toneMapping!==NoToneMapping?getToneMappingFunction('toneMapping',parameters.toneMapping):'',parameters.dithering?'#define DITHERING':'',ShaderChunk['encodings_pars_fragment'],// this code is required here because it is used by the various encoding/decoding function defined below
  676. parameters.map?getTexelDecodingFunction('mapTexelToLinear',parameters.mapEncoding):'',parameters.matcap?getTexelDecodingFunction('matcapTexelToLinear',parameters.matcapEncoding):'',parameters.envMap?getTexelDecodingFunction('envMapTexelToLinear',parameters.envMapEncoding):'',parameters.emissiveMap?getTexelDecodingFunction('emissiveMapTexelToLinear',parameters.emissiveMapEncoding):'',parameters.lightMap?getTexelDecodingFunction('lightMapTexelToLinear',parameters.lightMapEncoding):'',getTexelEncodingFunction('linearToOutputTexel',parameters.outputEncoding),parameters.depthPacking?'#define DEPTH_PACKING '+parameters.depthPacking:'','\n'].filter(filterEmptyLine).join('\n');}vertexShader=resolveIncludes(vertexShader);vertexShader=replaceLightNums(vertexShader,parameters);vertexShader=replaceClippingPlaneNums(vertexShader,parameters);fragmentShader=resolveIncludes(fragmentShader);fragmentShader=replaceLightNums(fragmentShader,parameters);fragmentShader=replaceClippingPlaneNums(fragmentShader,parameters);vertexShader=unrollLoops(vertexShader);fragmentShader=unrollLoops(fragmentShader);if(parameters.isWebGL2&&parameters.isRawShaderMaterial!==true){// GLSL 3.0 conversion for built-in materials and ShaderMaterial
  677. versionString='#version 300 es\n';prefixVertex=['#define attribute in','#define varying out','#define texture2D texture'].join('\n')+'\n'+prefixVertex;prefixFragment=['#define varying in',parameters.glslVersion===GLSL3?'':'out highp vec4 pc_fragColor;',parameters.glslVersion===GLSL3?'':'#define gl_FragColor pc_fragColor','#define gl_FragDepthEXT gl_FragDepth','#define texture2D texture','#define textureCube texture','#define texture2DProj textureProj','#define texture2DLodEXT textureLod','#define texture2DProjLodEXT textureProjLod','#define textureCubeLodEXT textureLod','#define texture2DGradEXT textureGrad','#define texture2DProjGradEXT textureProjGrad','#define textureCubeGradEXT textureGrad'].join('\n')+'\n'+prefixFragment;}var vertexGlsl=versionString+prefixVertex+vertexShader;var fragmentGlsl=versionString+prefixFragment+fragmentShader;// console.log( '*VERTEX*', vertexGlsl );
  678. // console.log( '*FRAGMENT*', fragmentGlsl );
  679. var glVertexShader=WebGLShader(gl,35633,vertexGlsl);var glFragmentShader=WebGLShader(gl,35632,fragmentGlsl);gl.attachShader(program,glVertexShader);gl.attachShader(program,glFragmentShader);// Force a particular attribute to index 0.
  680. if(parameters.index0AttributeName!==undefined){gl.bindAttribLocation(program,0,parameters.index0AttributeName);}else if(parameters.morphTargets===true){// programs with morphTargets displace position out of attribute 0
  681. gl.bindAttribLocation(program,0,'position');}gl.linkProgram(program);// check for link errors
  682. if(renderer.debug.checkShaderErrors){var programLog=gl.getProgramInfoLog(program).trim();var vertexLog=gl.getShaderInfoLog(glVertexShader).trim();var fragmentLog=gl.getShaderInfoLog(glFragmentShader).trim();var runnable=true;var haveDiagnostics=true;if(gl.getProgramParameter(program,35714)===false){runnable=false;var vertexErrors=getShaderErrors(gl,glVertexShader,'vertex');var fragmentErrors=getShaderErrors(gl,glFragmentShader,'fragment');console.error('THREE.WebGLProgram: shader error: ',gl.getError(),'35715',gl.getProgramParameter(program,35715),'gl.getProgramInfoLog',programLog,vertexErrors,fragmentErrors);//add:
  683. if(fragmentErrors){console.log(fragmentGlsl.split("\n").map((a,i)=>"".concat(i+1).padEnd(5)+a).join("\n"));}else {console.log(vertexGlsl.split("\n").map((a,i)=>"".concat(i+1).padEnd(5)+a).join("\n"));}}else if(programLog!==''){console.warn('THREE.WebGLProgram: gl.getProgramInfoLog()',programLog);}else if(vertexLog===''||fragmentLog===''){haveDiagnostics=false;}if(haveDiagnostics){this.diagnostics={runnable:runnable,programLog:programLog,vertexShader:{log:vertexLog,prefix:prefixVertex},fragmentShader:{log:fragmentLog,prefix:prefixFragment}};}}// Clean up
  684. // Crashes in iOS9 and iOS10. #18402
  685. // gl.detachShader( program, glVertexShader );
  686. // gl.detachShader( program, glFragmentShader );
  687. gl.deleteShader(glVertexShader);gl.deleteShader(glFragmentShader);// set up caching for uniform locations
  688. var cachedUniforms;this.getUniforms=function(){if(cachedUniforms===undefined){cachedUniforms=new WebGLUniforms(gl,program);}return cachedUniforms;};// set up caching for attribute locations
  689. var cachedAttributes;this.getAttributes=function(){if(cachedAttributes===undefined){cachedAttributes=fetchAttributeLocations(gl,program);}return cachedAttributes;};// free resource
  690. this.destroy=function(){bindingStates.releaseStatesOfProgram(this);gl.deleteProgram(program);this.program=undefined;};//
  691. this.name=parameters.shaderName;this.id=programIdCount++;this.cacheKey=cacheKey;this.usedTimes=1;this.program=program;this.vertexShader=glVertexShader;this.fragmentShader=glFragmentShader;return this;}function WebGLPrograms(renderer,cubemaps,extensions,capabilities,bindingStates,clipping){var programs=[];var isWebGL2=capabilities.isWebGL2;var logarithmicDepthBuffer=capabilities.logarithmicDepthBuffer;var floatVertexTextures=capabilities.floatVertexTextures;var maxVertexUniforms=capabilities.maxVertexUniforms;var vertexTextures=capabilities.vertexTextures;var precision=capabilities.precision;var shaderIDs={MeshDepthMaterial:'depth',MeshDistanceMaterial:'distanceRGBA',MeshNormalMaterial:'normal',MeshBasicMaterial:'basic',MeshLambertMaterial:'lambert',MeshPhongMaterial:'phong',MeshToonMaterial:'toon',MeshStandardMaterial:'physical',MeshPhysicalMaterial:'physical',MeshMatcapMaterial:'matcap',LineBasicMaterial:'basic',LineDashedMaterial:'dashed',PointsMaterial:'points',ShadowMaterial:'shadow',SpriteMaterial:'sprite'};var parameterNames=['precision','isWebGL2','supportsVertexTextures','outputEncoding','instancing','instancingColor','map','mapEncoding','matcap','matcapEncoding','envMap','envMapMode','envMapEncoding','envMapCubeUV','lightMap','lightMapEncoding','aoMap','emissiveMap','emissiveMapEncoding','bumpMap','normalMap','objectSpaceNormalMap','tangentSpaceNormalMap','clearcoatMap','clearcoatRoughnessMap','clearcoatNormalMap','displacementMap','specularMap','roughnessMap','metalnessMap','gradientMap','alphaMap','combine','vertexColors','vertexTangents','vertexUvs','uvsVertexOnly','fog','useFog','fogExp2','flatShading','sizeAttenuation','logarithmicDepthBuffer','skinning','maxBones','useVertexTexture','morphTargets','morphNormals','maxMorphTargets','maxMorphNormals','premultipliedAlpha','numDirLights','numPointLights','numSpotLights','numHemiLights','numRectAreaLights','numDirLightShadows','numPointLightShadows','numSpotLightShadows','shadowMapEnabled','shadowMapType','toneMapping','physicallyCorrectLights','alphaTest','doubleSided','flipSided','numClippingPlanes','numClipIntersection','depthPacking','dithering','sheen','transmissionMap'];function getMaxBones(object){var skeleton=object.skeleton;var bones=skeleton.bones;if(floatVertexTextures){return 1024;}else {// default for when object is not specified
  692. // ( for example when prebuilding shader to be used with multiple objects )
  693. //
  694. // - leave some extra space for other uniforms
  695. // - limit here is ANGLE's 254 max uniform vectors
  696. // (up to 54 should be safe)
  697. var nVertexUniforms=maxVertexUniforms;var nVertexMatrices=Math.floor((nVertexUniforms-20)/4);var maxBones=Math.min(nVertexMatrices,bones.length);if(maxBones<bones.length){console.warn('THREE.WebGLRenderer: Skeleton has '+bones.length+' bones. This GPU supports '+maxBones+'.');return 0;}return maxBones;}}function getTextureEncodingFromMap(map){var encoding;if(map&&map.isTexture){encoding=map.encoding;}else if(map&&map.isWebGLRenderTarget){console.warn('THREE.WebGLPrograms.getTextureEncodingFromMap: don\'t use render targets as textures. Use their .texture property instead.');encoding=map.texture.encoding;}else {encoding=LinearEncoding;}return encoding;}function getParameters(material,lights,shadows,scene,object){var fog=scene.fog;var environment=material.isMeshStandardMaterial?scene.environment:null;var envMap=cubemaps.get(material.envMap||environment);var shaderID=shaderIDs[material.type];// heuristics to create shader parameters according to lights in the scene
  698. // (not to blow over maxLights budget)
  699. var maxBones=object.isSkinnedMesh?getMaxBones(object):0;if(material.precision!==null){precision=capabilities.getMaxPrecision(material.precision);if(precision!==material.precision){console.warn('THREE.WebGLProgram.getParameters:',material.precision,'not supported, using',precision,'instead.');}}var vertexShader,fragmentShader;if(shaderID){var shader=ShaderLib[shaderID];vertexShader=shader.vertexShader;fragmentShader=shader.fragmentShader;}else {vertexShader=material.vertexShader;fragmentShader=material.fragmentShader;}var currentRenderTarget=renderer.getRenderTarget();var parameters={isWebGL2:isWebGL2,shaderID:shaderID,shaderName:material.type,vertexShader:vertexShader,fragmentShader:fragmentShader,defines:material.defines,isRawShaderMaterial:material.isRawShaderMaterial===true,glslVersion:material.glslVersion,precision:precision,instancing:object.isInstancedMesh===true,instancingColor:object.isInstancedMesh===true&&object.instanceColor!==null,supportsVertexTextures:vertexTextures,outputEncoding:currentRenderTarget!==null?getTextureEncodingFromMap(currentRenderTarget.texture):renderer.outputEncoding,map:!!material.map,mapEncoding:getTextureEncodingFromMap(material.map),matcap:!!material.matcap,matcapEncoding:getTextureEncodingFromMap(material.matcap),envMap:!!envMap,envMapMode:envMap&&envMap.mapping,envMapEncoding:getTextureEncodingFromMap(envMap),envMapCubeUV:!!envMap&&(envMap.mapping===CubeUVReflectionMapping||envMap.mapping===CubeUVRefractionMapping),lightMap:!!material.lightMap,lightMapEncoding:getTextureEncodingFromMap(material.lightMap),aoMap:!!material.aoMap,emissiveMap:!!material.emissiveMap,emissiveMapEncoding:getTextureEncodingFromMap(material.emissiveMap),bumpMap:!!material.bumpMap,normalMap:!!material.normalMap,objectSpaceNormalMap:material.normalMapType===ObjectSpaceNormalMap,tangentSpaceNormalMap:material.normalMapType===TangentSpaceNormalMap,clearcoatMap:!!material.clearcoatMap,clearcoatRoughnessMap:!!material.clearcoatRoughnessMap,clearcoatNormalMap:!!material.clearcoatNormalMap,displacementMap:!!material.displacementMap,roughnessMap:!!material.roughnessMap,metalnessMap:!!material.metalnessMap,specularMap:!!material.specularMap,alphaMap:!!material.alphaMap,gradientMap:!!material.gradientMap,sheen:!!material.sheen,transmissionMap:!!material.transmissionMap,combine:material.combine,vertexTangents:material.normalMap&&material.vertexTangents,vertexColors:material.vertexColors,vertexUvs:!!material.map||!!material.bumpMap||!!material.normalMap||!!material.specularMap||!!material.alphaMap||!!material.emissiveMap||!!material.roughnessMap||!!material.metalnessMap||!!material.clearcoatMap||!!material.clearcoatRoughnessMap||!!material.clearcoatNormalMap||!!material.displacementMap||!!material.transmissionMap,uvsVertexOnly:!(!!material.map||!!material.bumpMap||!!material.normalMap||!!material.specularMap||!!material.alphaMap||!!material.emissiveMap||!!material.roughnessMap||!!material.metalnessMap||!!material.clearcoatNormalMap||!!material.transmissionMap)&&!!material.displacementMap,fog:!!fog,useFog:material.fog,fogExp2:fog&&fog.isFogExp2,flatShading:material.flatShading,sizeAttenuation:material.sizeAttenuation,logarithmicDepthBuffer:logarithmicDepthBuffer,skinning:material.skinning&&maxBones>0,maxBones:maxBones,useVertexTexture:floatVertexTextures,morphTargets:material.morphTargets,morphNormals:material.morphNormals,maxMorphTargets:renderer.maxMorphTargets,maxMorphNormals:renderer.maxMorphNormals,numDirLights:lights.directional.length,numPointLights:lights.point.length,numSpotLights:lights.spot.length,numRectAreaLights:lights.rectArea.length,numHemiLights:lights.hemi.length,numDirLightShadows:lights.directionalShadowMap.length,numPointLightShadows:lights.pointShadowMap.length,numSpotLightShadows:lights.spotShadowMap.length,numClippingPlanes:clipping.numPlanes,numClipIntersection:clipping.numIntersection,dithering:material.dithering,shadowMapEnabled:renderer.shadowMap.enabled&&shadows.length>0,shadowMapType:renderer.shadowMap.type,toneMapping:material.toneMapped?renderer.toneMapping:NoToneMapping,physicallyCorrectLights:renderer.physicallyCorrectLights,premultipliedAlpha:material.premultipliedAlpha,alphaTest:material.alphaTest,doubleSided:material.side===DoubleSide,flipSided:material.side===BackSide,depthPacking:material.depthPacking!==undefined?material.depthPacking:false,index0AttributeName:material.index0AttributeName,extensionDerivatives:material.extensions&&material.extensions.derivatives,extensionFragDepth:material.extensions&&material.extensions.fragDepth,extensionDrawBuffers:material.extensions&&material.extensions.drawBuffers,extensionShaderTextureLOD:material.extensions&&material.extensions.shaderTextureLOD,rendererExtensionFragDepth:isWebGL2||extensions.has('EXT_frag_depth'),rendererExtensionDrawBuffers:isWebGL2||extensions.has('WEBGL_draw_buffers'),rendererExtensionShaderTextureLod:isWebGL2||extensions.has('EXT_shader_texture_lod'),customProgramCacheKey:material.customProgramCacheKey()};return parameters;}function getProgramCacheKey(parameters){var array=[];if(parameters.shaderID){array.push(parameters.shaderID);}else {array.push(parameters.fragmentShader);array.push(parameters.vertexShader);}if(parameters.defines!==undefined){for(var name in parameters.defines){array.push(name);array.push(parameters.defines[name]);}}if(parameters.isRawShaderMaterial===false){for(var _i95=0;_i95<parameterNames.length;_i95++){array.push(parameters[parameterNames[_i95]]);}array.push(renderer.outputEncoding);array.push(renderer.gammaFactor);}array.push(parameters.customProgramCacheKey);return array.join();}function getUniforms(material){var shaderID=shaderIDs[material.type];var uniforms;if(shaderID){var shader=ShaderLib[shaderID];uniforms=UniformsUtils.clone(shader.uniforms);}else {uniforms=material.uniforms;}return uniforms;}function acquireProgram(parameters,cacheKey){var program;// Check if code has been already compiled
  700. for(var p=0,pl=programs.length;p<pl;p++){var preexistingProgram=programs[p];if(preexistingProgram.cacheKey===cacheKey){program=preexistingProgram;++program.usedTimes;break;}}if(program===undefined){program=new WebGLProgram(renderer,cacheKey,parameters,bindingStates);programs.push(program);}return program;}function releaseProgram(program){if(--program.usedTimes===0){// Remove from unordered set
  701. var _i96=programs.indexOf(program);programs[_i96]=programs[programs.length-1];programs.pop();// Free WebGL resources
  702. program.destroy();}}return {getParameters:getParameters,getProgramCacheKey:getProgramCacheKey,getUniforms:getUniforms,acquireProgram:acquireProgram,releaseProgram:releaseProgram,// Exposed for resource monitoring & error feedback via renderer.info:
  703. programs:programs};}function WebGLProperties(){var properties=new WeakMap();function get(object){var map=properties.get(object);if(map===undefined){map={};properties.set(object,map);}return map;}function remove(object){properties.delete(object);}function update(object,key,value){properties.get(object)[key]=value;}function dispose(){properties=new WeakMap();}return {get:get,remove:remove,update:update,dispose:dispose};}function painterSortStable(a,b){if(a.groupOrder!==b.groupOrder){return a.groupOrder-b.groupOrder;}else if(a.renderOrder!==b.renderOrder){return a.renderOrder-b.renderOrder;}else if(a.program!==b.program){return a.program.id-b.program.id;}else if(a.material.id!==b.material.id){return a.material.id-b.material.id;}else if(a.z!==b.z){return a.z-b.z;}else {return a.id-b.id;}}function reversePainterSortStable(a,b){if(a.groupOrder!==b.groupOrder){return a.groupOrder-b.groupOrder;}else if(a.renderOrder!==b.renderOrder){return a.renderOrder-b.renderOrder;}else if(a.z!==b.z){return b.z-a.z;}else {return a.id-b.id;}}function WebGLRenderList(properties){var renderItems=[];var renderItemsIndex=0;var opaque=[];var transparent=[];var defaultProgram={id:-1};function init(){renderItemsIndex=0;opaque.length=0;transparent.length=0;}function getNextRenderItem(object,geometry,material,groupOrder,z,group){var renderItem=renderItems[renderItemsIndex];var materialProperties=properties.get(material);if(renderItem===undefined){renderItem={id:object.id,object:object,geometry:geometry,material:material,program:materialProperties.program||defaultProgram,groupOrder:groupOrder,renderOrder:object.renderOrder,z:z,group:group};renderItems[renderItemsIndex]=renderItem;}else {renderItem.id=object.id;renderItem.object=object;renderItem.geometry=geometry;renderItem.material=material;renderItem.program=materialProperties.program||defaultProgram;renderItem.groupOrder=groupOrder;renderItem.renderOrder=object.renderOrder;renderItem.z=z;renderItem.group=group;}renderItemsIndex++;return renderItem;}function push(object,geometry,material,groupOrder,z,group){var renderItem=getNextRenderItem(object,geometry,material,groupOrder,z,group);(material.transparent===true?transparent:opaque).push(renderItem);}function unshift(object,geometry,material,groupOrder,z,group){var renderItem=getNextRenderItem(object,geometry,material,groupOrder,z,group);(material.transparent===true?transparent:opaque).unshift(renderItem);}function sort(customOpaqueSort,customTransparentSort){if(opaque.length>1)opaque.sort(customOpaqueSort||painterSortStable);if(transparent.length>1)transparent.sort(customTransparentSort||reversePainterSortStable);}function finish(){// Clear references from inactive renderItems in the list
  704. for(var _i97=renderItemsIndex,il=renderItems.length;_i97<il;_i97++){var renderItem=renderItems[_i97];if(renderItem.id===null)break;renderItem.id=null;renderItem.object=null;renderItem.geometry=null;renderItem.material=null;renderItem.program=null;renderItem.group=null;}}return {opaque:opaque,transparent:transparent,init:init,push:push,unshift:unshift,finish:finish,sort:sort};}function WebGLRenderLists(properties){var lists=new WeakMap();function get(scene,camera){var cameras=lists.get(scene);var list;if(cameras===undefined){list=new WebGLRenderList(properties);lists.set(scene,new WeakMap());lists.get(scene).set(camera,list);}else {list=cameras.get(camera);if(list===undefined){list=new WebGLRenderList(properties);cameras.set(camera,list);}}return list;}function dispose(){lists=new WeakMap();}return {get:get,dispose:dispose};}function UniformsCache(){var lights={};return {get:function get(light){if(lights[light.id]!==undefined){return lights[light.id];}var uniforms;switch(light.type){case'DirectionalLight':uniforms={direction:new Vector3(),color:new Color()};break;case'SpotLight':uniforms={position:new Vector3(),direction:new Vector3(),color:new Color(),distance:0,coneCos:0,penumbraCos:0,decay:0};break;case'PointLight':uniforms={position:new Vector3(),color:new Color(),distance:0,decay:0};break;case'HemisphereLight':uniforms={direction:new Vector3(),skyColor:new Color(),groundColor:new Color()};break;case'RectAreaLight':uniforms={color:new Color(),position:new Vector3(),halfWidth:new Vector3(),halfHeight:new Vector3()};break;}lights[light.id]=uniforms;return uniforms;}};}function ShadowUniformsCache(){var lights={};return {get:function get(light){if(lights[light.id]!==undefined){return lights[light.id];}var uniforms;switch(light.type){case'DirectionalLight':uniforms={shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new Vector2()};break;case'SpotLight':uniforms={shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new Vector2()};break;case'PointLight':uniforms={shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new Vector2(),shadowCameraNear:1,shadowCameraFar:1000};break;// TODO (abelnation): set RectAreaLight shadow uniforms
  705. }lights[light.id]=uniforms;return uniforms;}};}var nextVersion=0;function shadowCastingLightsFirst(lightA,lightB){return (lightB.castShadow?1:0)-(lightA.castShadow?1:0);}function WebGLLights(extensions,capabilities){var cache=new UniformsCache();var shadowCache=ShadowUniformsCache();var state={version:0,hash:{directionalLength:-1,pointLength:-1,spotLength:-1,rectAreaLength:-1,hemiLength:-1,numDirectionalShadows:-1,numPointShadows:-1,numSpotShadows:-1},ambient:[0,0,0],probe:[],directional:[],directionalShadow:[],directionalShadowMap:[],directionalShadowMatrix:[],spot:[],spotShadow:[],spotShadowMap:[],spotShadowMatrix:[],rectArea:[],rectAreaLTC1:null,rectAreaLTC2:null,point:[],pointShadow:[],pointShadowMap:[],pointShadowMatrix:[],hemi:[]};for(var _i98=0;_i98<9;_i98++)state.probe.push(new Vector3());var vector3=new Vector3();var matrix4=new Matrix4();var matrix42=new Matrix4();function setup(lights){var r=0,g=0,b=0;for(var _i99=0;_i99<9;_i99++)state.probe[_i99].set(0,0,0);var directionalLength=0;var pointLength=0;var spotLength=0;var rectAreaLength=0;var hemiLength=0;var numDirectionalShadows=0;var numPointShadows=0;var numSpotShadows=0;lights.sort(shadowCastingLightsFirst);for(var _i100=0,l=lights.length;_i100<l;_i100++){var light=lights[_i100];var color=light.color;var intensity=light.intensity;var distance=light.distance;var shadowMap=light.shadow&&light.shadow.map?light.shadow.map.texture:null;if(light.isAmbientLight){r+=color.r*intensity;g+=color.g*intensity;b+=color.b*intensity;}else if(light.isLightProbe){for(var j=0;j<9;j++){state.probe[j].addScaledVector(light.sh.coefficients[j],intensity);}}else if(light.isDirectionalLight){var uniforms=cache.get(light);uniforms.color.copy(light.color).multiplyScalar(light.intensity);if(light.castShadow){var shadow=light.shadow;var shadowUniforms=shadowCache.get(light);shadowUniforms.shadowBias=shadow.bias;shadowUniforms.shadowNormalBias=shadow.normalBias;shadowUniforms.shadowRadius=shadow.radius;shadowUniforms.shadowMapSize=shadow.mapSize;state.directionalShadow[directionalLength]=shadowUniforms;state.directionalShadowMap[directionalLength]=shadowMap;state.directionalShadowMatrix[directionalLength]=light.shadow.matrix;numDirectionalShadows++;}state.directional[directionalLength]=uniforms;directionalLength++;}else if(light.isSpotLight){var _uniforms=cache.get(light);_uniforms.position.setFromMatrixPosition(light.matrixWorld);_uniforms.color.copy(color).multiplyScalar(intensity);_uniforms.distance=distance;_uniforms.coneCos=Math.cos(light.angle);_uniforms.penumbraCos=Math.cos(light.angle*(1-light.penumbra));_uniforms.decay=light.decay;if(light.castShadow){var _shadow=light.shadow;var _shadowUniforms=shadowCache.get(light);_shadowUniforms.shadowBias=_shadow.bias;_shadowUniforms.shadowNormalBias=_shadow.normalBias;_shadowUniforms.shadowRadius=_shadow.radius;_shadowUniforms.shadowMapSize=_shadow.mapSize;state.spotShadow[spotLength]=_shadowUniforms;state.spotShadowMap[spotLength]=shadowMap;state.spotShadowMatrix[spotLength]=light.shadow.matrix;numSpotShadows++;}state.spot[spotLength]=_uniforms;spotLength++;}else if(light.isRectAreaLight){var _uniforms2=cache.get(light);// (a) intensity is the total visible light emitted
  706. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  707. // (b) intensity is the brightness of the light
  708. _uniforms2.color.copy(color).multiplyScalar(intensity);_uniforms2.halfWidth.set(light.width*0.5,0.0,0.0);_uniforms2.halfHeight.set(0.0,light.height*0.5,0.0);state.rectArea[rectAreaLength]=_uniforms2;rectAreaLength++;}else if(light.isPointLight){var _uniforms3=cache.get(light);_uniforms3.color.copy(light.color).multiplyScalar(light.intensity);_uniforms3.distance=light.distance;_uniforms3.decay=light.decay;if(light.castShadow){var _shadow2=light.shadow;var _shadowUniforms2=shadowCache.get(light);_shadowUniforms2.shadowBias=_shadow2.bias;_shadowUniforms2.shadowNormalBias=_shadow2.normalBias;_shadowUniforms2.shadowRadius=_shadow2.radius;_shadowUniforms2.shadowMapSize=_shadow2.mapSize;_shadowUniforms2.shadowCameraNear=_shadow2.camera.near;_shadowUniforms2.shadowCameraFar=_shadow2.camera.far;state.pointShadow[pointLength]=_shadowUniforms2;state.pointShadowMap[pointLength]=shadowMap;state.pointShadowMatrix[pointLength]=light.shadow.matrix;numPointShadows++;}state.point[pointLength]=_uniforms3;pointLength++;}else if(light.isHemisphereLight){var _uniforms4=cache.get(light);_uniforms4.skyColor.copy(light.color).multiplyScalar(intensity);_uniforms4.groundColor.copy(light.groundColor).multiplyScalar(intensity);state.hemi[hemiLength]=_uniforms4;hemiLength++;}}if(rectAreaLength>0){if(capabilities.isWebGL2){// WebGL 2
  709. state.rectAreaLTC1=UniformsLib.LTC_FLOAT_1;state.rectAreaLTC2=UniformsLib.LTC_FLOAT_2;}else {// WebGL 1
  710. if(extensions.has('OES_texture_float_linear')===true){state.rectAreaLTC1=UniformsLib.LTC_FLOAT_1;state.rectAreaLTC2=UniformsLib.LTC_FLOAT_2;}else if(extensions.has('OES_texture_half_float_linear')===true){state.rectAreaLTC1=UniformsLib.LTC_HALF_1;state.rectAreaLTC2=UniformsLib.LTC_HALF_2;}else {console.error('THREE.WebGLRenderer: Unable to use RectAreaLight. Missing WebGL extensions.');}}}state.ambient[0]=r;state.ambient[1]=g;state.ambient[2]=b;var hash=state.hash;if(hash.directionalLength!==directionalLength||hash.pointLength!==pointLength||hash.spotLength!==spotLength||hash.rectAreaLength!==rectAreaLength||hash.hemiLength!==hemiLength||hash.numDirectionalShadows!==numDirectionalShadows||hash.numPointShadows!==numPointShadows||hash.numSpotShadows!==numSpotShadows){state.directional.length=directionalLength;state.spot.length=spotLength;state.rectArea.length=rectAreaLength;state.point.length=pointLength;state.hemi.length=hemiLength;state.directionalShadow.length=numDirectionalShadows;state.directionalShadowMap.length=numDirectionalShadows;state.pointShadow.length=numPointShadows;state.pointShadowMap.length=numPointShadows;state.spotShadow.length=numSpotShadows;state.spotShadowMap.length=numSpotShadows;state.directionalShadowMatrix.length=numDirectionalShadows;state.pointShadowMatrix.length=numPointShadows;state.spotShadowMatrix.length=numSpotShadows;hash.directionalLength=directionalLength;hash.pointLength=pointLength;hash.spotLength=spotLength;hash.rectAreaLength=rectAreaLength;hash.hemiLength=hemiLength;hash.numDirectionalShadows=numDirectionalShadows;hash.numPointShadows=numPointShadows;hash.numSpotShadows=numSpotShadows;state.version=nextVersion++;}}function setupView(lights,camera){var directionalLength=0;var pointLength=0;var spotLength=0;var rectAreaLength=0;var hemiLength=0;var viewMatrix=camera.matrixWorldInverse;for(var _i101=0,l=lights.length;_i101<l;_i101++){var light=lights[_i101];if(light.isDirectionalLight){var uniforms=state.directional[directionalLength];uniforms.direction.setFromMatrixPosition(light.matrixWorld);vector3.setFromMatrixPosition(light.target.matrixWorld);uniforms.direction.sub(vector3);uniforms.direction.transformDirection(viewMatrix);directionalLength++;}else if(light.isSpotLight){var _uniforms5=state.spot[spotLength];_uniforms5.position.setFromMatrixPosition(light.matrixWorld);_uniforms5.position.applyMatrix4(viewMatrix);_uniforms5.direction.setFromMatrixPosition(light.matrixWorld);vector3.setFromMatrixPosition(light.target.matrixWorld);_uniforms5.direction.sub(vector3);_uniforms5.direction.transformDirection(viewMatrix);spotLength++;}else if(light.isRectAreaLight){var _uniforms6=state.rectArea[rectAreaLength];_uniforms6.position.setFromMatrixPosition(light.matrixWorld);_uniforms6.position.applyMatrix4(viewMatrix);// extract local rotation of light to derive width/height half vectors
  711. matrix42.identity();matrix4.copy(light.matrixWorld);matrix4.premultiply(viewMatrix);matrix42.extractRotation(matrix4);_uniforms6.halfWidth.set(light.width*0.5,0.0,0.0);_uniforms6.halfHeight.set(0.0,light.height*0.5,0.0);_uniforms6.halfWidth.applyMatrix4(matrix42);_uniforms6.halfHeight.applyMatrix4(matrix42);rectAreaLength++;}else if(light.isPointLight){var _uniforms7=state.point[pointLength];_uniforms7.position.setFromMatrixPosition(light.matrixWorld);_uniforms7.position.applyMatrix4(viewMatrix);pointLength++;}else if(light.isHemisphereLight){var _uniforms8=state.hemi[hemiLength];_uniforms8.direction.setFromMatrixPosition(light.matrixWorld);_uniforms8.direction.transformDirection(viewMatrix);_uniforms8.direction.normalize();hemiLength++;}}}return {setup:setup,setupView:setupView,state:state};}function WebGLRenderState(extensions,capabilities){var lights=new WebGLLights(extensions,capabilities);var lightsArray=[];var shadowsArray=[];function init(){lightsArray.length=0;shadowsArray.length=0;}function pushLight(light){lightsArray.push(light);}function pushShadow(shadowLight){shadowsArray.push(shadowLight);}function setupLights(){lights.setup(lightsArray);}function setupLightsView(camera){lights.setupView(lightsArray,camera);}var state={lightsArray:lightsArray,shadowsArray:shadowsArray,lights:lights};return {init:init,state:state,setupLights:setupLights,setupLightsView:setupLightsView,pushLight:pushLight,pushShadow:pushShadow};}function WebGLRenderStates(extensions,capabilities){var renderStates=new WeakMap();function get(scene){var renderCallDepth=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var renderState;if(renderStates.has(scene)===false){renderState=new WebGLRenderState(extensions,capabilities);renderStates.set(scene,[]);renderStates.get(scene).push(renderState);}else {if(renderCallDepth>=renderStates.get(scene).length){renderState=new WebGLRenderState(extensions,capabilities);renderStates.get(scene).push(renderState);}else {renderState=renderStates.get(scene)[renderCallDepth];}}return renderState;}function dispose(){renderStates=new WeakMap();}return {get:get,dispose:dispose};}/**
  712. * parameters = {
  713. *
  714. * opacity: <float>,
  715. *
  716. * map: new THREE.Texture( <Image> ),
  717. *
  718. * alphaMap: new THREE.Texture( <Image> ),
  719. *
  720. * displacementMap: new THREE.Texture( <Image> ),
  721. * displacementScale: <float>,
  722. * displacementBias: <float>,
  723. *
  724. * wireframe: <boolean>,
  725. * wireframeLinewidth: <float>
  726. * }
  727. */function MeshDepthMaterial(parameters){Material.call(this);this.type='MeshDepthMaterial';this.depthPacking=BasicDepthPacking;this.skinning=false;this.morphTargets=false;this.map=null;this.alphaMap=null;this.displacementMap=null;this.displacementScale=1;this.displacementBias=0;this.wireframe=false;this.wireframeLinewidth=1;this.fog=false;this.setValues(parameters);}MeshDepthMaterial.prototype=Object.create(Material.prototype);MeshDepthMaterial.prototype.constructor=MeshDepthMaterial;MeshDepthMaterial.prototype.isMeshDepthMaterial=true;MeshDepthMaterial.prototype.copy=function(source){Material.prototype.copy.call(this,source);this.depthPacking=source.depthPacking;this.skinning=source.skinning;this.morphTargets=source.morphTargets;this.map=source.map;this.alphaMap=source.alphaMap;this.displacementMap=source.displacementMap;this.displacementScale=source.displacementScale;this.displacementBias=source.displacementBias;this.wireframe=source.wireframe;this.wireframeLinewidth=source.wireframeLinewidth;return this;};/**
  728. * parameters = {
  729. *
  730. * referencePosition: <float>,
  731. * nearDistance: <float>,
  732. * farDistance: <float>,
  733. *
  734. * skinning: <bool>,
  735. * morphTargets: <bool>,
  736. *
  737. * map: new THREE.Texture( <Image> ),
  738. *
  739. * alphaMap: new THREE.Texture( <Image> ),
  740. *
  741. * displacementMap: new THREE.Texture( <Image> ),
  742. * displacementScale: <float>,
  743. * displacementBias: <float>
  744. *
  745. * }
  746. */function MeshDistanceMaterial(parameters){Material.call(this);this.type='MeshDistanceMaterial';this.referencePosition=new Vector3();this.nearDistance=1;this.farDistance=1000;this.skinning=false;this.morphTargets=false;this.map=null;this.alphaMap=null;this.displacementMap=null;this.displacementScale=1;this.displacementBias=0;this.fog=false;this.setValues(parameters);}MeshDistanceMaterial.prototype=Object.create(Material.prototype);MeshDistanceMaterial.prototype.constructor=MeshDistanceMaterial;MeshDistanceMaterial.prototype.isMeshDistanceMaterial=true;MeshDistanceMaterial.prototype.copy=function(source){Material.prototype.copy.call(this,source);this.referencePosition.copy(source.referencePosition);this.nearDistance=source.nearDistance;this.farDistance=source.farDistance;this.skinning=source.skinning;this.morphTargets=source.morphTargets;this.map=source.map;this.alphaMap=source.alphaMap;this.displacementMap=source.displacementMap;this.displacementScale=source.displacementScale;this.displacementBias=source.displacementBias;return this;};var vsm_frag="uniform sampler2D shadow_pass;\nuniform vec2 resolution;\nuniform float radius;\n#include <packing>\nvoid main() {\n\tfloat mean = 0.0;\n\tfloat squared_mean = 0.0;\n\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy ) / resolution ) );\n\tfor ( float i = -1.0; i < 1.0 ; i += SAMPLE_RATE) {\n\t\t#ifdef HORIZONTAL_PASS\n\t\t\tvec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( i, 0.0 ) * radius ) / resolution ) );\n\t\t\tmean += distribution.x;\n\t\t\tsquared_mean += distribution.y * distribution.y + distribution.x * distribution.x;\n\t\t#else\n\t\t\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, i ) * radius ) / resolution ) );\n\t\t\tmean += depth;\n\t\t\tsquared_mean += depth * depth;\n\t\t#endif\n\t}\n\tmean = mean * HALF_SAMPLE_RATE;\n\tsquared_mean = squared_mean * HALF_SAMPLE_RATE;\n\tfloat std_dev = sqrt( squared_mean - mean * mean );\n\tgl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) );\n}";var vsm_vert="void main() {\n\tgl_Position = vec4( position, 1.0 );\n}";function WebGLShadowMap(_renderer,_objects,maxTextureSize){var _frustum=new Frustum();var _shadowMapSize=new Vector2(),_viewportSize=new Vector2(),_viewport=new Vector4(),_depthMaterials=[],_distanceMaterials=[],_materialCache={};var shadowSide={0:BackSide,1:FrontSide,2:DoubleSide};var shadowMaterialVertical=new ShaderMaterial({defines:{SAMPLE_RATE:2.0/8.0,HALF_SAMPLE_RATE:1.0/8.0},uniforms:{shadow_pass:{value:null},resolution:{value:new Vector2()},radius:{value:4.0}},vertexShader:vsm_vert,fragmentShader:vsm_frag});var shadowMaterialHorizontal=shadowMaterialVertical.clone();shadowMaterialHorizontal.defines.HORIZONTAL_PASS=1;var fullScreenTri=new BufferGeometry();fullScreenTri.setAttribute('position',new BufferAttribute(new Float32Array([-1,-1,0.5,3,-1,0.5,-1,3,0.5]),3));var fullScreenMesh=new Mesh(fullScreenTri,shadowMaterialVertical);var scope=this;this.enabled=false;this.autoUpdate=true;this.needsUpdate=false;this.type=PCFShadowMap;this.render=function(lights,scene,camera){if(scope.enabled===false)return;if(scope.autoUpdate===false&&scope.needsUpdate===false)return;if(lights.length===0)return;var currentRenderTarget=_renderer.getRenderTarget();var activeCubeFace=_renderer.getActiveCubeFace();var activeMipmapLevel=_renderer.getActiveMipmapLevel();var _state=_renderer.state;// Set GL state for depth map.
  747. _state.setBlending(NoBlending);_state.buffers.color.setClear(1,1,1,1);_state.buffers.depth.setTest(true);_state.setScissorTest(false);// render depth map
  748. for(var _i102=0,il=lights.length;_i102<il;_i102++){var light=lights[_i102];var shadow=light.shadow;if(shadow===undefined){console.warn('THREE.WebGLShadowMap:',light,'has no shadow.');continue;}if(shadow.autoUpdate===false&&shadow.needsUpdate===false)continue;_shadowMapSize.copy(shadow.mapSize);var shadowFrameExtents=shadow.getFrameExtents();_shadowMapSize.multiply(shadowFrameExtents);_viewportSize.copy(shadow.mapSize);if(_shadowMapSize.x>maxTextureSize||_shadowMapSize.y>maxTextureSize){if(_shadowMapSize.x>maxTextureSize){_viewportSize.x=Math.floor(maxTextureSize/shadowFrameExtents.x);_shadowMapSize.x=_viewportSize.x*shadowFrameExtents.x;shadow.mapSize.x=_viewportSize.x;}if(_shadowMapSize.y>maxTextureSize){_viewportSize.y=Math.floor(maxTextureSize/shadowFrameExtents.y);_shadowMapSize.y=_viewportSize.y*shadowFrameExtents.y;shadow.mapSize.y=_viewportSize.y;}}if(shadow.map===null&&!shadow.isPointLightShadow&&this.type===VSMShadowMap){var pars={minFilter:LinearFilter,magFilter:LinearFilter,format:RGBAFormat};shadow.map=new WebGLRenderTarget(_shadowMapSize.x,_shadowMapSize.y,pars);shadow.map.texture.name=light.name+'.shadowMap';shadow.mapPass=new WebGLRenderTarget(_shadowMapSize.x,_shadowMapSize.y,pars);shadow.camera.updateProjectionMatrix();}if(shadow.map===null){var _pars={minFilter:NearestFilter,magFilter:NearestFilter,format:RGBAFormat};shadow.map=new WebGLRenderTarget(_shadowMapSize.x,_shadowMapSize.y,_pars);shadow.map.texture.name=light.name+'.shadowMap';shadow.camera.updateProjectionMatrix();}_renderer.setRenderTarget(shadow.map);_renderer.clear();var viewportCount=shadow.getViewportCount();for(var vp=0;vp<viewportCount;vp++){var viewport=shadow.getViewport(vp);_viewport.set(_viewportSize.x*viewport.x,_viewportSize.y*viewport.y,_viewportSize.x*viewport.z,_viewportSize.y*viewport.w);_state.viewport(_viewport);shadow.updateMatrices(light,vp);_frustum=shadow.getFrustum();renderObject(scene,camera,shadow.camera,light,this.type);}// do blur pass for VSM
  749. if(!shadow.isPointLightShadow&&this.type===VSMShadowMap){VSMPass(shadow,camera);}shadow.needsUpdate=false;}scope.needsUpdate=false;_renderer.setRenderTarget(currentRenderTarget,activeCubeFace,activeMipmapLevel);};function VSMPass(shadow,camera){var geometry=_objects.update(fullScreenMesh);// vertical pass
  750. shadowMaterialVertical.uniforms.shadow_pass.value=shadow.map.texture;shadowMaterialVertical.uniforms.resolution.value=shadow.mapSize;shadowMaterialVertical.uniforms.radius.value=shadow.radius;_renderer.setRenderTarget(shadow.mapPass);_renderer.clear();_renderer.renderBufferDirect(camera,null,geometry,shadowMaterialVertical,fullScreenMesh,null);// horizontal pass
  751. shadowMaterialHorizontal.uniforms.shadow_pass.value=shadow.mapPass.texture;shadowMaterialHorizontal.uniforms.resolution.value=shadow.mapSize;shadowMaterialHorizontal.uniforms.radius.value=shadow.radius;_renderer.setRenderTarget(shadow.map);_renderer.clear();_renderer.renderBufferDirect(camera,null,geometry,shadowMaterialHorizontal,fullScreenMesh,null);}function getDepthMaterialVariant(useMorphing,useSkinning,useInstancing){var index=useMorphing<<0|useSkinning<<1|useInstancing<<2;var material=_depthMaterials[index];if(material===undefined){material=new MeshDepthMaterial({depthPacking:RGBADepthPacking,morphTargets:useMorphing,skinning:useSkinning});_depthMaterials[index]=material;}return material;}function getDistanceMaterialVariant(useMorphing,useSkinning,useInstancing){var index=useMorphing<<0|useSkinning<<1|useInstancing<<2;var material=_distanceMaterials[index];if(material===undefined){material=new MeshDistanceMaterial({morphTargets:useMorphing,skinning:useSkinning});_distanceMaterials[index]=material;}return material;}function getDepthMaterial(object,geometry,material,light,shadowCameraNear,shadowCameraFar,type){var result=null;var getMaterialVariant=getDepthMaterialVariant;var customMaterial=object.customDepthMaterial;if(light.isPointLight===true){getMaterialVariant=getDistanceMaterialVariant;customMaterial=object.customDistanceMaterial;}if(customMaterial===undefined){var useMorphing=false;if(material.morphTargets===true){useMorphing=geometry.morphAttributes&&geometry.morphAttributes.position&&geometry.morphAttributes.position.length>0;}var useSkinning=false;if(object.isSkinnedMesh===true){if(material.skinning===true){useSkinning=true;}else {console.warn('THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:',object);}}var useInstancing=object.isInstancedMesh===true;result=getMaterialVariant(useMorphing,useSkinning,useInstancing);}else {result=customMaterial;}if(_renderer.localClippingEnabled&&material.clipShadows===true&&material.clippingPlanes.length!==0){// in this case we need a unique material instance reflecting the
  752. // appropriate state
  753. var keyA=result.uuid,keyB=material.uuid;var materialsForVariant=_materialCache[keyA];if(materialsForVariant===undefined){materialsForVariant={};_materialCache[keyA]=materialsForVariant;}var cachedMaterial=materialsForVariant[keyB];if(cachedMaterial===undefined){cachedMaterial=result.clone();materialsForVariant[keyB]=cachedMaterial;}result=cachedMaterial;}result.visible=material.visible;result.wireframe=material.wireframe;if(type===VSMShadowMap){result.side=material.shadowSide!==null?material.shadowSide:material.side;}else {result.side=material.shadowSide!==null?material.shadowSide:shadowSide[material.side];}result.clipShadows=material.clipShadows;result.clippingPlanes=material.clippingPlanes;result.clipIntersection=material.clipIntersection;result.wireframeLinewidth=material.wireframeLinewidth;result.linewidth=material.linewidth;if(light.isPointLight===true&&result.isMeshDistanceMaterial===true){result.referencePosition.setFromMatrixPosition(light.matrixWorld);result.nearDistance=shadowCameraNear;result.farDistance=shadowCameraFar;}return result;}function renderObject(object,camera,shadowCamera,light,type){if(object.visible===false)return;var visible=object.layers.test(camera.layers);if(visible&&(object.isMesh||object.isLine||object.isPoints)){if((object.castShadow||object.receiveShadow&&type===VSMShadowMap)&&(!object.frustumCulled||_frustum.intersectsObject(object))){object.modelViewMatrix.multiplyMatrices(shadowCamera.matrixWorldInverse,object.matrixWorld);var geometry=_objects.update(object);var material=object.material;if(Array.isArray(material)){var groups=geometry.groups;for(var k=0,kl=groups.length;k<kl;k++){var group=groups[k];var groupMaterial=material[group.materialIndex];if(groupMaterial&&groupMaterial.visible){var depthMaterial=getDepthMaterial(object,geometry,groupMaterial,light,shadowCamera.near,shadowCamera.far,type);_renderer.renderBufferDirect(shadowCamera,null,geometry,depthMaterial,object,group);}}}else if(material.visible){var _depthMaterial=getDepthMaterial(object,geometry,material,light,shadowCamera.near,shadowCamera.far,type);_renderer.renderBufferDirect(shadowCamera,null,geometry,_depthMaterial,object,null);}}}var children=object.children;for(var _i103=0,l=children.length;_i103<l;_i103++){renderObject(children[_i103],camera,shadowCamera,light,type);}}}function WebGLState(gl,extensions,capabilities){var isWebGL2=capabilities.isWebGL2;function ColorBuffer(){var locked=false;var color=new Vector4();var currentColorMask=null;var currentColorClear=new Vector4(0,0,0,0);return {setMask:function setMask(colorMask){if(currentColorMask!==colorMask&&!locked){gl.colorMask(colorMask,colorMask,colorMask,colorMask);currentColorMask=colorMask;}},setLocked:function setLocked(lock){locked=lock;},setClear:function setClear(r,g,b,a,premultipliedAlpha){if(premultipliedAlpha===true){r*=a;g*=a;b*=a;}color.set(r,g,b,a);if(currentColorClear.equals(color)===false){gl.clearColor(r,g,b,a);currentColorClear.copy(color);}},reset:function reset(){locked=false;currentColorMask=null;currentColorClear.set(-1,0,0,0);// set to invalid state
  754. }};}function DepthBuffer(){var locked=false;var currentDepthMask=null;var currentDepthFunc=null;var currentDepthClear=null;return {setTest:function setTest(depthTest){if(depthTest){enable(2929);}else {disable(2929);}},setMask:function setMask(depthMask){if(currentDepthMask!==depthMask&&!locked){gl.depthMask(depthMask);currentDepthMask=depthMask;}},setFunc:function setFunc(depthFunc){if(currentDepthFunc!==depthFunc){if(depthFunc){switch(depthFunc){case NeverDepth:gl.depthFunc(512);break;case AlwaysDepth:gl.depthFunc(519);break;case LessDepth:gl.depthFunc(513);break;case LessEqualDepth:gl.depthFunc(515);break;case EqualDepth:gl.depthFunc(514);break;case GreaterEqualDepth:gl.depthFunc(518);break;case GreaterDepth:gl.depthFunc(516);break;case NotEqualDepth:gl.depthFunc(517);break;default:gl.depthFunc(515);}}else {gl.depthFunc(515);}currentDepthFunc=depthFunc;}},setLocked:function setLocked(lock){locked=lock;},setClear:function setClear(depth){if(currentDepthClear!==depth){gl.clearDepth(depth);currentDepthClear=depth;}},reset:function reset(){locked=false;currentDepthMask=null;currentDepthFunc=null;currentDepthClear=null;}};}function StencilBuffer(){var locked=false;var currentStencilMask=null;var currentStencilFunc=null;var currentStencilRef=null;var currentStencilFuncMask=null;var currentStencilFail=null;var currentStencilZFail=null;var currentStencilZPass=null;var currentStencilClear=null;return {setTest:function setTest(stencilTest){if(!locked){if(stencilTest){enable(2960);}else {disable(2960);}}},setMask:function setMask(stencilMask){if(currentStencilMask!==stencilMask&&!locked){gl.stencilMask(stencilMask);currentStencilMask=stencilMask;}},setFunc:function setFunc(stencilFunc,stencilRef,stencilMask){if(currentStencilFunc!==stencilFunc||currentStencilRef!==stencilRef||currentStencilFuncMask!==stencilMask){gl.stencilFunc(stencilFunc,stencilRef,stencilMask);currentStencilFunc=stencilFunc;currentStencilRef=stencilRef;currentStencilFuncMask=stencilMask;}},setOp:function setOp(stencilFail,stencilZFail,stencilZPass){if(currentStencilFail!==stencilFail||currentStencilZFail!==stencilZFail||currentStencilZPass!==stencilZPass){gl.stencilOp(stencilFail,stencilZFail,stencilZPass);currentStencilFail=stencilFail;currentStencilZFail=stencilZFail;currentStencilZPass=stencilZPass;}},setLocked:function setLocked(lock){locked=lock;},setClear:function setClear(stencil){if(currentStencilClear!==stencil){gl.clearStencil(stencil);currentStencilClear=stencil;}},reset:function reset(){locked=false;currentStencilMask=null;currentStencilFunc=null;currentStencilRef=null;currentStencilFuncMask=null;currentStencilFail=null;currentStencilZFail=null;currentStencilZPass=null;currentStencilClear=null;}};}//
  755. var colorBuffer=new ColorBuffer();var depthBuffer=new DepthBuffer();var stencilBuffer=new StencilBuffer();var enabledCapabilities={};var currentProgram=null;var currentBlendingEnabled=null;var currentBlending=null;var currentBlendEquation=null;var currentBlendSrc=null;var currentBlendDst=null;var currentBlendEquationAlpha=null;var currentBlendSrcAlpha=null;var currentBlendDstAlpha=null;var currentPremultipledAlpha=false;var currentFlipSided=null;var currentCullFace=null;var currentLineWidth=null;var currentPolygonOffsetFactor=null;var currentPolygonOffsetUnits=null;var maxTextures=gl.getParameter(35661);var lineWidthAvailable=false;var version=0;var glVersion=gl.getParameter(7938);if(glVersion.indexOf('WebGL')!==-1){version=parseFloat(/^WebGL (\d)/.exec(glVersion)[1]);lineWidthAvailable=version>=1.0;}else if(glVersion.indexOf('OpenGL ES')!==-1){version=parseFloat(/^OpenGL ES (\d)/.exec(glVersion)[1]);lineWidthAvailable=version>=2.0;}var currentTextureSlot=null;var currentBoundTextures={};var currentScissor=new Vector4();var currentViewport=new Vector4();function createTexture(type,target,count){var data=new Uint8Array(4);// 4 is required to match default unpack alignment of 4.
  756. var texture=gl.createTexture();gl.bindTexture(type,texture);gl.texParameteri(type,10241,9728);gl.texParameteri(type,10240,9728);for(var _i104=0;_i104<count;_i104++){gl.texImage2D(target+_i104,0,6408,1,1,0,6408,5121,data);}return texture;}var emptyTextures={};emptyTextures[3553]=createTexture(3553,3553,1);emptyTextures[34067]=createTexture(34067,34069,6);// init
  757. colorBuffer.setClear(0,0,0,1);depthBuffer.setClear(1);stencilBuffer.setClear(0);enable(2929);depthBuffer.setFunc(LessEqualDepth);setFlipSided(false);setCullFace(CullFaceBack);enable(2884);setBlending(NoBlending);//
  758. function enable(id){if(enabledCapabilities[id]!==true){gl.enable(id);enabledCapabilities[id]=true;}}function disable(id){if(enabledCapabilities[id]!==false){gl.disable(id);enabledCapabilities[id]=false;}}function useProgram(program){if(currentProgram!==program){gl.useProgram(program);currentProgram=program;return true;}return false;}var equationToGL={[AddEquation]:32774,[SubtractEquation]:32778,[ReverseSubtractEquation]:32779};if(isWebGL2){equationToGL[MinEquation]=32775;equationToGL[MaxEquation]=32776;}else {var extension=extensions.get('EXT_blend_minmax');if(extension!==null){equationToGL[MinEquation]=extension.MIN_EXT;equationToGL[MaxEquation]=extension.MAX_EXT;}}var factorToGL={[ZeroFactor]:0,[OneFactor]:1,[SrcColorFactor]:768,[SrcAlphaFactor]:770,[SrcAlphaSaturateFactor]:776,[DstColorFactor]:774,[DstAlphaFactor]:772,[OneMinusSrcColorFactor]:769,[OneMinusSrcAlphaFactor]:771,[OneMinusDstColorFactor]:775,[OneMinusDstAlphaFactor]:773};function setBlending(blending,blendEquation,blendSrc,blendDst,blendEquationAlpha,blendSrcAlpha,blendDstAlpha,premultipliedAlpha){if(blending===NoBlending){if(currentBlendingEnabled){disable(3042);currentBlendingEnabled=false;}return;}if(!currentBlendingEnabled){enable(3042);currentBlendingEnabled=true;}if(blending!==CustomBlending){if(blending!==currentBlending||premultipliedAlpha!==currentPremultipledAlpha){if(currentBlendEquation!==AddEquation||currentBlendEquationAlpha!==AddEquation){gl.blendEquation(32774);currentBlendEquation=AddEquation;currentBlendEquationAlpha=AddEquation;}if(premultipliedAlpha){switch(blending){case NormalBlending:gl.blendFuncSeparate(1,771,1,771);break;case AdditiveBlending:gl.blendFunc(1,1);break;case SubtractiveBlending:gl.blendFuncSeparate(0,0,769,771);break;case MultiplyBlending:gl.blendFuncSeparate(0,768,0,770);break;default:console.error('THREE.WebGLState: Invalid blending: ',blending);break;}}else {switch(blending){case NormalBlending:gl.blendFuncSeparate(770,771,1,771);break;case AdditiveBlending:gl.blendFunc(770,1);break;case SubtractiveBlending:gl.blendFunc(0,769);break;case MultiplyBlending:gl.blendFunc(0,768);break;default:console.error('THREE.WebGLState: Invalid blending: ',blending);break;}}currentBlendSrc=null;currentBlendDst=null;currentBlendSrcAlpha=null;currentBlendDstAlpha=null;currentBlending=blending;currentPremultipledAlpha=premultipliedAlpha;}return;}// custom blending
  759. blendEquationAlpha=blendEquationAlpha||blendEquation;blendSrcAlpha=blendSrcAlpha||blendSrc;blendDstAlpha=blendDstAlpha||blendDst;if(blendEquation!==currentBlendEquation||blendEquationAlpha!==currentBlendEquationAlpha){gl.blendEquationSeparate(equationToGL[blendEquation],equationToGL[blendEquationAlpha]);currentBlendEquation=blendEquation;currentBlendEquationAlpha=blendEquationAlpha;}if(blendSrc!==currentBlendSrc||blendDst!==currentBlendDst||blendSrcAlpha!==currentBlendSrcAlpha||blendDstAlpha!==currentBlendDstAlpha){gl.blendFuncSeparate(factorToGL[blendSrc],factorToGL[blendDst],factorToGL[blendSrcAlpha],factorToGL[blendDstAlpha]);currentBlendSrc=blendSrc;currentBlendDst=blendDst;currentBlendSrcAlpha=blendSrcAlpha;currentBlendDstAlpha=blendDstAlpha;}currentBlending=blending;currentPremultipledAlpha=null;}function setMaterial(material,frontFaceCW){material.side===DoubleSide?disable(2884):enable(2884);var flipSided=material.side===BackSide;if(frontFaceCW)flipSided=!flipSided;setFlipSided(flipSided);material.blending===NormalBlending&&material.transparent===false?setBlending(NoBlending):setBlending(material.blending,material.blendEquation,material.blendSrc,material.blendDst,material.blendEquationAlpha,material.blendSrcAlpha,material.blendDstAlpha,material.premultipliedAlpha);depthBuffer.setFunc(material.depthFunc);depthBuffer.setTest(material.depthTest);depthBuffer.setMask(material.depthWrite);colorBuffer.setMask(material.colorWrite);var stencilWrite=material.stencilWrite;stencilBuffer.setTest(stencilWrite);if(stencilWrite){stencilBuffer.setMask(material.stencilWriteMask);stencilBuffer.setFunc(material.stencilFunc,material.stencilRef,material.stencilFuncMask);stencilBuffer.setOp(material.stencilFail,material.stencilZFail,material.stencilZPass);}setPolygonOffset(material.polygonOffset,material.polygonOffsetFactor,material.polygonOffsetUnits);}//
  760. function setFlipSided(flipSided){if(currentFlipSided!==flipSided){if(flipSided){gl.frontFace(2304);}else {gl.frontFace(2305);}currentFlipSided=flipSided;}}function setCullFace(cullFace){if(cullFace!==CullFaceNone){enable(2884);if(cullFace!==currentCullFace){if(cullFace===CullFaceBack){gl.cullFace(1029);}else if(cullFace===CullFaceFront){gl.cullFace(1028);}else {gl.cullFace(1032);}}}else {disable(2884);}currentCullFace=cullFace;}function setLineWidth(width){if(width!==currentLineWidth){if(lineWidthAvailable)gl.lineWidth(width);currentLineWidth=width;}}function setPolygonOffset(polygonOffset,factor,units){if(polygonOffset){enable(32823);if(currentPolygonOffsetFactor!==factor||currentPolygonOffsetUnits!==units){gl.polygonOffset(factor,units);currentPolygonOffsetFactor=factor;currentPolygonOffsetUnits=units;}}else {disable(32823);}}function setScissorTest(scissorTest){if(scissorTest){enable(3089);}else {disable(3089);}}// texture
  761. function activeTexture(webglSlot){if(webglSlot===undefined)webglSlot=33984+maxTextures-1;if(currentTextureSlot!==webglSlot){gl.activeTexture(webglSlot);currentTextureSlot=webglSlot;}}function bindTexture(webglType,webglTexture){if(currentTextureSlot===null){activeTexture();}var boundTexture=currentBoundTextures[currentTextureSlot];if(boundTexture===undefined){boundTexture={type:undefined,texture:undefined};currentBoundTextures[currentTextureSlot]=boundTexture;}if(boundTexture.type!==webglType||boundTexture.texture!==webglTexture){gl.bindTexture(webglType,webglTexture||emptyTextures[webglType]);boundTexture.type=webglType;boundTexture.texture=webglTexture;}}function unbindTexture(){var boundTexture=currentBoundTextures[currentTextureSlot];if(boundTexture!==undefined&&boundTexture.type!==undefined){gl.bindTexture(boundTexture.type,null);boundTexture.type=undefined;boundTexture.texture=undefined;}}function compressedTexImage2D(){try{gl.compressedTexImage2D.apply(gl,arguments);}catch(error){console.error('THREE.WebGLState:',error);}}function texImage2D(){try{gl.texImage2D.apply(gl,arguments);}catch(error){console.error('THREE.WebGLState:',error);}}function texImage3D(){try{gl.texImage3D.apply(gl,arguments);}catch(error){console.error('THREE.WebGLState:',error);}}//
  762. function scissor(scissor){if(currentScissor.equals(scissor)===false){gl.scissor(scissor.x,scissor.y,scissor.z,scissor.w);currentScissor.copy(scissor);}}function viewport(viewport){if(currentViewport.equals(viewport)===false){gl.viewport(viewport.x,viewport.y,viewport.z,viewport.w);currentViewport.copy(viewport);}}//
  763. function reset(){enabledCapabilities={};currentTextureSlot=null;currentBoundTextures={};currentProgram=null;currentBlendingEnabled=null;currentBlending=null;currentBlendEquation=null;currentBlendSrc=null;currentBlendDst=null;currentBlendEquationAlpha=null;currentBlendSrcAlpha=null;currentBlendDstAlpha=null;currentPremultipledAlpha=false;currentFlipSided=null;currentCullFace=null;currentLineWidth=null;currentPolygonOffsetFactor=null;currentPolygonOffsetUnits=null;colorBuffer.reset();depthBuffer.reset();stencilBuffer.reset();}return {buffers:{color:colorBuffer,depth:depthBuffer,stencil:stencilBuffer},enable:enable,disable:disable,useProgram:useProgram,setBlending:setBlending,setMaterial:setMaterial,setFlipSided:setFlipSided,setCullFace:setCullFace,setLineWidth:setLineWidth,setPolygonOffset:setPolygonOffset,setScissorTest:setScissorTest,activeTexture:activeTexture,bindTexture:bindTexture,unbindTexture:unbindTexture,compressedTexImage2D:compressedTexImage2D,texImage2D:texImage2D,texImage3D:texImage3D,scissor:scissor,viewport:viewport,reset:reset};}function WebGLTextures(_gl,extensions,state,properties,capabilities,utils,info){var isWebGL2=capabilities.isWebGL2;var maxTextures=capabilities.maxTextures;var maxCubemapSize=capabilities.maxCubemapSize;var maxTextureSize=capabilities.maxTextureSize;var maxSamples=capabilities.maxSamples;var _videoTextures=new WeakMap();var _canvas;// cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
  764. // also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
  765. // Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d).
  766. var useOffscreenCanvas=false;try{useOffscreenCanvas=typeof OffscreenCanvas!=='undefined'&&new OffscreenCanvas(1,1).getContext('2d')!==null;}catch(err){// Ignore any errors
  767. }function createCanvas(width,height){// Use OffscreenCanvas when available. Specially needed in web workers
  768. return useOffscreenCanvas?new OffscreenCanvas(width,height):document.createElementNS('http://www.w3.org/1999/xhtml','canvas');}function resizeImage(image,needsPowerOfTwo,needsNewCanvas,maxSize){var scale=1;// handle case if texture exceeds max size
  769. if(image.width>maxSize||image.height>maxSize){scale=maxSize/Math.max(image.width,image.height);}// only perform resize if necessary
  770. if(scale<1||needsPowerOfTwo===true){// only perform resize for certain image types
  771. if(typeof HTMLImageElement!=='undefined'&&image instanceof HTMLImageElement||typeof HTMLCanvasElement!=='undefined'&&image instanceof HTMLCanvasElement||typeof ImageBitmap!=='undefined'&&image instanceof ImageBitmap){var floor=needsPowerOfTwo?MathUtils.floorPowerOfTwo:Math.floor;var width=floor(scale*image.width);var height=floor(scale*image.height);if(_canvas===undefined)_canvas=createCanvas(width,height);// cube textures can't reuse the same canvas
  772. var canvas=needsNewCanvas?createCanvas(width,height):_canvas;canvas.width=width;canvas.height=height;var context=canvas.getContext('2d');context.drawImage(image,0,0,width,height);console.warn('THREE.WebGLRenderer: Texture has been resized from ('+image.width+'x'+image.height+') to ('+width+'x'+height+').');return canvas;}else {if('data'in image){console.warn('THREE.WebGLRenderer: Image in DataTexture is too big ('+image.width+'x'+image.height+').');}return image;}}return image;}function isPowerOfTwo(image){return MathUtils.isPowerOfTwo(image.width)&&MathUtils.isPowerOfTwo(image.height);}function textureNeedsPowerOfTwo(texture){if(isWebGL2)return false;return texture.wrapS!==ClampToEdgeWrapping||texture.wrapT!==ClampToEdgeWrapping||texture.minFilter!==NearestFilter&&texture.minFilter!==LinearFilter;}function textureNeedsGenerateMipmaps(texture,supportsMips){return texture.generateMipmaps&&supportsMips&&texture.minFilter!==NearestFilter&&texture.minFilter!==LinearFilter;}function generateMipmap(target,texture,width,height){_gl.generateMipmap(target);var textureProperties=properties.get(texture);// Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  773. textureProperties.__maxMipLevel=Math.log(Math.max(width,height))*Math.LOG2E;}function getInternalFormat(internalFormatName,glFormat,glType){if(isWebGL2===false)return glFormat;if(internalFormatName!==null){if(_gl[internalFormatName]!==undefined)return _gl[internalFormatName];console.warn('THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format \''+internalFormatName+'\'');}var internalFormat=glFormat;if(glFormat===6403){if(glType===5126)internalFormat=33326;if(glType===5131)internalFormat=33325;if(glType===5121)internalFormat=33321;}if(glFormat===6407){if(glType===5126)internalFormat=34837;if(glType===5131)internalFormat=34843;if(glType===5121)internalFormat=32849;}if(glFormat===6408){if(glType===5126)internalFormat=34836;if(glType===5131)internalFormat=34842;if(glType===5121)internalFormat=32856;}if(internalFormat===33325||internalFormat===33326||internalFormat===34842||internalFormat===34836){extensions.get('EXT_color_buffer_float');}return internalFormat;}// Fallback filters for non-power-of-2 textures
  774. function filterFallback(f){if(f===NearestFilter||f===NearestMipmapNearestFilter||f===NearestMipmapLinearFilter){return 9728;}return 9729;}//
  775. function onTextureDispose(event){var texture=event.target;texture.removeEventListener('dispose',onTextureDispose);deallocateTexture(texture);if(texture.isVideoTexture){_videoTextures.delete(texture);}info.memory.textures--;}function onRenderTargetDispose(event){var renderTarget=event.target;renderTarget.removeEventListener('dispose',onRenderTargetDispose);deallocateRenderTarget(renderTarget);info.memory.textures--;}//
  776. function deallocateTexture(texture){var textureProperties=properties.get(texture);if(textureProperties.__webglInit===undefined)return;_gl.deleteTexture(textureProperties.__webglTexture);properties.remove(texture);}function deallocateRenderTarget(renderTarget){var renderTargetProperties=properties.get(renderTarget);var textureProperties=properties.get(renderTarget.texture);if(!renderTarget)return;if(textureProperties.__webglTexture!==undefined){_gl.deleteTexture(textureProperties.__webglTexture);}if(renderTarget.depthTexture){renderTarget.depthTexture.dispose();}if(renderTarget.isWebGLCubeRenderTarget){for(var _i105=0;_i105<6;_i105++){_gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer[_i105]);if(renderTargetProperties.__webglDepthbuffer)_gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer[_i105]);}}else {_gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer);if(renderTargetProperties.__webglDepthbuffer)_gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer);if(renderTargetProperties.__webglMultisampledFramebuffer)_gl.deleteFramebuffer(renderTargetProperties.__webglMultisampledFramebuffer);if(renderTargetProperties.__webglColorRenderbuffer)_gl.deleteRenderbuffer(renderTargetProperties.__webglColorRenderbuffer);if(renderTargetProperties.__webglDepthRenderbuffer)_gl.deleteRenderbuffer(renderTargetProperties.__webglDepthRenderbuffer);}properties.remove(renderTarget.texture);properties.remove(renderTarget);}//
  777. var textureUnits=0;function resetTextureUnits(){textureUnits=0;}function allocateTextureUnit(){var textureUnit=textureUnits;if(textureUnit>=maxTextures){console.warn('THREE.WebGLTextures: Trying to use '+textureUnit+' texture units while this GPU supports only '+maxTextures);}textureUnits+=1;return textureUnit;}//
  778. function setTexture2D(texture,slot){var textureProperties=properties.get(texture);if(texture.isVideoTexture)updateVideoTexture(texture);if(texture.version>0&&textureProperties.__version!==texture.version){var image=texture.image;if(image===undefined){console.warn('THREE.WebGLRenderer: Texture marked for update but image is undefined');}else if(image.complete===false){console.warn('THREE.WebGLRenderer: Texture marked for update but image is incomplete');}else {uploadTexture(textureProperties,texture,slot);return;}}state.activeTexture(33984+slot);state.bindTexture(3553,textureProperties.__webglTexture);}function setTexture2DArray(texture,slot){var textureProperties=properties.get(texture);if(texture.version>0&&textureProperties.__version!==texture.version){uploadTexture(textureProperties,texture,slot);return;}state.activeTexture(33984+slot);state.bindTexture(35866,textureProperties.__webglTexture);}function setTexture3D(texture,slot){var textureProperties=properties.get(texture);if(texture.version>0&&textureProperties.__version!==texture.version){uploadTexture(textureProperties,texture,slot);return;}state.activeTexture(33984+slot);state.bindTexture(32879,textureProperties.__webglTexture);}function setTextureCube(texture,slot){var textureProperties=properties.get(texture);if(texture.version>0&&textureProperties.__version!==texture.version){uploadCubeTexture(textureProperties,texture,slot);return;}state.activeTexture(33984+slot);state.bindTexture(34067,textureProperties.__webglTexture);}var wrappingToGL={[RepeatWrapping]:10497,[ClampToEdgeWrapping]:33071,[MirroredRepeatWrapping]:33648};var filterToGL={[NearestFilter]:9728,[NearestMipmapNearestFilter]:9984,[NearestMipmapLinearFilter]:9986,[LinearFilter]:9729,[LinearMipmapNearestFilter]:9985,[LinearMipmapLinearFilter]:9987};function setTextureParameters(textureType,texture,supportsMips){if(supportsMips){_gl.texParameteri(textureType,10242,wrappingToGL[texture.wrapS]);_gl.texParameteri(textureType,10243,wrappingToGL[texture.wrapT]);if(textureType===32879||textureType===35866){_gl.texParameteri(textureType,32882,wrappingToGL[texture.wrapR]);}_gl.texParameteri(textureType,10240,filterToGL[texture.magFilter]);_gl.texParameteri(textureType,10241,filterToGL[texture.minFilter]);}else {_gl.texParameteri(textureType,10242,33071);_gl.texParameteri(textureType,10243,33071);if(textureType===32879||textureType===35866){_gl.texParameteri(textureType,32882,33071);}if(texture.wrapS!==ClampToEdgeWrapping||texture.wrapT!==ClampToEdgeWrapping){console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.');}_gl.texParameteri(textureType,10240,filterFallback(texture.magFilter));_gl.texParameteri(textureType,10241,filterFallback(texture.minFilter));if(texture.minFilter!==NearestFilter&&texture.minFilter!==LinearFilter){console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.');}}var extension=extensions.get('EXT_texture_filter_anisotropic');if(extension){if(texture.type===FloatType&&extensions.get('OES_texture_float_linear')===null)return;if(texture.type===HalfFloatType&&(isWebGL2||extensions.get('OES_texture_half_float_linear'))===null)return;if(texture.anisotropy>1||properties.get(texture).__currentAnisotropy){_gl.texParameterf(textureType,extension.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(texture.anisotropy,capabilities.getMaxAnisotropy()));properties.get(texture).__currentAnisotropy=texture.anisotropy;}}}function initTexture(textureProperties,texture){if(textureProperties.__webglInit===undefined){textureProperties.__webglInit=true;texture.addEventListener('dispose',onTextureDispose);textureProperties.__webglTexture=_gl.createTexture();info.memory.textures++;}}function uploadTexture(textureProperties,texture,slot){var textureType=3553;if(texture.isDataTexture2DArray)textureType=35866;if(texture.isDataTexture3D)textureType=32879;initTexture(textureProperties,texture);state.activeTexture(33984+slot);state.bindTexture(textureType,textureProperties.__webglTexture);_gl.pixelStorei(37440,texture.flipY);_gl.pixelStorei(37441,texture.premultiplyAlpha);_gl.pixelStorei(3317,texture.unpackAlignment);var needsPowerOfTwo=textureNeedsPowerOfTwo(texture)&&isPowerOfTwo(texture.image)===false;var image=resizeImage(texture.image,needsPowerOfTwo,false,maxTextureSize);var supportsMips=isPowerOfTwo(image)||isWebGL2,glFormat=utils.convert(texture.format);var glType=utils.convert(texture.type),glInternalFormat=getInternalFormat(texture.internalFormat,glFormat,glType);setTextureParameters(textureType,texture,supportsMips);var mipmap;var mipmaps=texture.mipmaps;if(texture.isDepthTexture){// populate depth texture with dummy data
  779. glInternalFormat=6402;if(isWebGL2){if(texture.type===FloatType){glInternalFormat=36012;}else if(texture.type===UnsignedIntType){glInternalFormat=33190;}else if(texture.type===UnsignedInt248Type$1){glInternalFormat=35056;}else {glInternalFormat=33189;// WebGL2 requires sized internalformat for glTexImage2D
  780. }}else {if(texture.type===FloatType){console.error('WebGLRenderer: Floating point depth texture requires WebGL2.');}}// validation checks for WebGL 1
  781. if(texture.format===DepthFormat&&glInternalFormat===6402){// The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  782. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  783. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  784. if(texture.type!==UnsignedShortType&&texture.type!==UnsignedIntType){console.warn('THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.');texture.type=UnsignedShortType;glType=utils.convert(texture.type);}}if(texture.format===DepthStencilFormat&&glInternalFormat===6402){// Depth stencil textures need the DEPTH_STENCIL internal format
  785. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  786. glInternalFormat=34041;// The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  787. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  788. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  789. if(texture.type!==UnsignedInt248Type$1){console.warn('THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.');texture.type=UnsignedInt248Type$1;glType=utils.convert(texture.type);}}//
  790. state.texImage2D(3553,0,glInternalFormat,image.width,image.height,0,glFormat,glType,null);}else if(texture.isDataTexture){// use manually created mipmaps if available
  791. // if there are no manual mipmaps
  792. // set 0 level mipmap and then use GL to generate other mipmap levels
  793. if(mipmaps.length>0&&supportsMips){for(var _i106=0,il=mipmaps.length;_i106<il;_i106++){mipmap=mipmaps[_i106];state.texImage2D(3553,_i106,glInternalFormat,mipmap.width,mipmap.height,0,glFormat,glType,mipmap.data);}texture.generateMipmaps=false;textureProperties.__maxMipLevel=mipmaps.length-1;}else {state.texImage2D(3553,0,glInternalFormat,image.width,image.height,0,glFormat,glType,image.data);textureProperties.__maxMipLevel=0;}}else if(texture.isCompressedTexture){for(var _i107=0,_il9=mipmaps.length;_i107<_il9;_i107++){mipmap=mipmaps[_i107];if(texture.format!==RGBAFormat&&texture.format!==RGBFormat){if(glFormat!==null){state.compressedTexImage2D(3553,_i107,glInternalFormat,mipmap.width,mipmap.height,0,mipmap.data);}else {console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()');}}else {state.texImage2D(3553,_i107,glInternalFormat,mipmap.width,mipmap.height,0,glFormat,glType,mipmap.data);}}textureProperties.__maxMipLevel=mipmaps.length-1;}else if(texture.isDataTexture2DArray){state.texImage3D(35866,0,glInternalFormat,image.width,image.height,image.depth,0,glFormat,glType,image.data);textureProperties.__maxMipLevel=0;}else if(texture.isDataTexture3D){state.texImage3D(32879,0,glInternalFormat,image.width,image.height,image.depth,0,glFormat,glType,image.data);textureProperties.__maxMipLevel=0;}else {// regular Texture (image, video, canvas)
  794. // use manually created mipmaps if available
  795. // if there are no manual mipmaps
  796. // set 0 level mipmap and then use GL to generate other mipmap levels
  797. if(mipmaps.length>0&&supportsMips){for(var _i108=0,_il10=mipmaps.length;_i108<_il10;_i108++){mipmap=mipmaps[_i108];state.texImage2D(3553,_i108,glInternalFormat,glFormat,glType,mipmap);}texture.generateMipmaps=false;textureProperties.__maxMipLevel=mipmaps.length-1;}else {state.texImage2D(3553,0,glInternalFormat,glFormat,glType,image);textureProperties.__maxMipLevel=0;}}if(textureNeedsGenerateMipmaps(texture,supportsMips)){generateMipmap(textureType,texture,image.width,image.height);}textureProperties.__version=texture.version;if(texture.onUpdate)texture.onUpdate(texture);}function uploadCubeTexture(textureProperties,texture,slot){if(texture.image.length!==6)return;initTexture(textureProperties,texture);state.activeTexture(33984+slot);state.bindTexture(34067,textureProperties.__webglTexture);_gl.pixelStorei(37440,texture.flipY);var isCompressed=texture&&(texture.isCompressedTexture||texture.image[0].isCompressedTexture);var isDataTexture=texture.image[0]&&texture.image[0].isDataTexture;var cubeImage=[];for(var _i109=0;_i109<6;_i109++){if(!isCompressed&&!isDataTexture){cubeImage[_i109]=resizeImage(texture.image[_i109],false,true,maxCubemapSize);}else {cubeImage[_i109]=isDataTexture?texture.image[_i109].image:texture.image[_i109];}}var image=cubeImage[0],supportsMips=isPowerOfTwo(image)||isWebGL2,glFormat=utils.convert(texture.format),glType=utils.convert(texture.type),glInternalFormat=getInternalFormat(texture.internalFormat,glFormat,glType);setTextureParameters(34067,texture,supportsMips);var mipmaps;if(isCompressed){for(var _i110=0;_i110<6;_i110++){mipmaps=cubeImage[_i110].mipmaps;for(var j=0;j<mipmaps.length;j++){var mipmap=mipmaps[j];if(texture.format!==RGBAFormat&&texture.format!==RGBFormat){if(glFormat!==null){state.compressedTexImage2D(34069+_i110,j,glInternalFormat,mipmap.width,mipmap.height,0,mipmap.data);}else {console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()');}}else {state.texImage2D(34069+_i110,j,glInternalFormat,mipmap.width,mipmap.height,0,glFormat,glType,mipmap.data);}}}textureProperties.__maxMipLevel=mipmaps.length-1;}else {mipmaps=texture.mipmaps;for(var _i111=0;_i111<6;_i111++){if(isDataTexture){state.texImage2D(34069+_i111,0,glInternalFormat,cubeImage[_i111].width,cubeImage[_i111].height,0,glFormat,glType,cubeImage[_i111].data);for(var _j3=0;_j3<mipmaps.length;_j3++){var _mipmap=mipmaps[_j3];var mipmapImage=_mipmap.image[_i111].image;state.texImage2D(34069+_i111,_j3+1,glInternalFormat,mipmapImage.width,mipmapImage.height,0,glFormat,glType,mipmapImage.data);}}else {state.texImage2D(34069+_i111,0,glInternalFormat,glFormat,glType,cubeImage[_i111]);for(var _j4=0;_j4<mipmaps.length;_j4++){var _mipmap2=mipmaps[_j4];state.texImage2D(34069+_i111,_j4+1,glInternalFormat,glFormat,glType,_mipmap2.image[_i111]);}}}textureProperties.__maxMipLevel=mipmaps.length;}if(textureNeedsGenerateMipmaps(texture,supportsMips)){// We assume images for cube map have the same size.
  798. generateMipmap(34067,texture,image.width,image.height);}textureProperties.__version=texture.version;if(texture.onUpdate)texture.onUpdate(texture);}// Render targets
  799. // Setup storage for target texture and bind it to correct framebuffer
  800. function setupFrameBufferTexture(framebuffer,renderTarget,attachment,textureTarget){var glFormat=utils.convert(renderTarget.texture.format);var glType=utils.convert(renderTarget.texture.type);var glInternalFormat=getInternalFormat(renderTarget.texture.internalFormat,glFormat,glType);state.texImage2D(textureTarget,0,glInternalFormat,renderTarget.width,renderTarget.height,0,glFormat,glType,null);_gl.bindFramebuffer(36160,framebuffer);_gl.framebufferTexture2D(36160,attachment,textureTarget,properties.get(renderTarget.texture).__webglTexture,0);_gl.bindFramebuffer(36160,null);}// Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  801. function setupRenderBufferStorage(renderbuffer,renderTarget,isMultisample){_gl.bindRenderbuffer(36161,renderbuffer);if(renderTarget.depthBuffer&&!renderTarget.stencilBuffer){var glInternalFormat=33189;if(isMultisample){var depthTexture=renderTarget.depthTexture;if(depthTexture&&depthTexture.isDepthTexture){if(depthTexture.type===FloatType){glInternalFormat=36012;}else if(depthTexture.type===UnsignedIntType){glInternalFormat=33190;}}var samples=getRenderTargetSamples(renderTarget);_gl.renderbufferStorageMultisample(36161,samples,glInternalFormat,renderTarget.width,renderTarget.height);}else {_gl.renderbufferStorage(36161,glInternalFormat,renderTarget.width,renderTarget.height);}_gl.framebufferRenderbuffer(36160,36096,36161,renderbuffer);}else if(renderTarget.depthBuffer&&renderTarget.stencilBuffer){if(isMultisample){var _samples=getRenderTargetSamples(renderTarget);_gl.renderbufferStorageMultisample(36161,_samples,35056,renderTarget.width,renderTarget.height);}else {_gl.renderbufferStorage(36161,34041,renderTarget.width,renderTarget.height);}_gl.framebufferRenderbuffer(36160,33306,36161,renderbuffer);}else {var glFormat=utils.convert(renderTarget.texture.format);var glType=utils.convert(renderTarget.texture.type);var _glInternalFormat=getInternalFormat(renderTarget.texture.internalFormat,glFormat,glType);if(isMultisample){var _samples2=getRenderTargetSamples(renderTarget);_gl.renderbufferStorageMultisample(36161,_samples2,_glInternalFormat,renderTarget.width,renderTarget.height);}else {_gl.renderbufferStorage(36161,_glInternalFormat,renderTarget.width,renderTarget.height);}}_gl.bindRenderbuffer(36161,null);}// Setup resources for a Depth Texture for a FBO (needs an extension)
  802. function setupDepthTexture(framebuffer,renderTarget){var isCube=renderTarget&&renderTarget.isWebGLCubeRenderTarget;if(isCube)throw new Error('Depth Texture with cube render targets is not supported');_gl.bindFramebuffer(36160,framebuffer);if(!(renderTarget.depthTexture&&renderTarget.depthTexture.isDepthTexture)){throw new Error('renderTarget.depthTexture must be an instance of THREE.DepthTexture');}// upload an empty depth texture with framebuffer size
  803. if(!properties.get(renderTarget.depthTexture).__webglTexture||renderTarget.depthTexture.image.width!==renderTarget.width||renderTarget.depthTexture.image.height!==renderTarget.height){renderTarget.depthTexture.image.width=renderTarget.width;renderTarget.depthTexture.image.height=renderTarget.height;renderTarget.depthTexture.needsUpdate=true;}setTexture2D(renderTarget.depthTexture,0);var webglDepthTexture=properties.get(renderTarget.depthTexture).__webglTexture;if(renderTarget.depthTexture.format===DepthFormat){_gl.framebufferTexture2D(36160,36096,3553,webglDepthTexture,0);}else if(renderTarget.depthTexture.format===DepthStencilFormat){_gl.framebufferTexture2D(36160,33306,3553,webglDepthTexture,0);}else {throw new Error('Unknown depthTexture format');}}// Setup GL resources for a non-texture depth buffer
  804. function setupDepthRenderbuffer(renderTarget){var renderTargetProperties=properties.get(renderTarget);var isCube=renderTarget.isWebGLCubeRenderTarget===true;if(renderTarget.depthTexture){if(isCube)throw new Error('target.depthTexture not supported in Cube render targets');setupDepthTexture(renderTargetProperties.__webglFramebuffer,renderTarget);}else {if(isCube){renderTargetProperties.__webglDepthbuffer=[];for(var _i112=0;_i112<6;_i112++){_gl.bindFramebuffer(36160,renderTargetProperties.__webglFramebuffer[_i112]);renderTargetProperties.__webglDepthbuffer[_i112]=_gl.createRenderbuffer();setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer[_i112],renderTarget,false);}}else {_gl.bindFramebuffer(36160,renderTargetProperties.__webglFramebuffer);renderTargetProperties.__webglDepthbuffer=_gl.createRenderbuffer();setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer,renderTarget,false);}}_gl.bindFramebuffer(36160,null);}// Set up GL resources for the render target
  805. function setupRenderTarget(renderTarget){var renderTargetProperties=properties.get(renderTarget);var textureProperties=properties.get(renderTarget.texture);renderTarget.addEventListener('dispose',onRenderTargetDispose);textureProperties.__webglTexture=_gl.createTexture();info.memory.textures++;var isCube=renderTarget.isWebGLCubeRenderTarget===true;var isMultisample=renderTarget.isWebGLMultisampleRenderTarget===true;var supportsMips=isPowerOfTwo(renderTarget)||isWebGL2;// Handles WebGL2 RGBFormat fallback - #18858
  806. if(isWebGL2&&renderTarget.texture.format===RGBFormat&&(renderTarget.texture.type===FloatType||renderTarget.texture.type===HalfFloatType)){renderTarget.texture.format=RGBAFormat;console.warn('THREE.WebGLRenderer: Rendering to textures with RGB format is not supported. Using RGBA format instead.');}// Setup framebuffer
  807. if(isCube){renderTargetProperties.__webglFramebuffer=[];for(var _i113=0;_i113<6;_i113++){renderTargetProperties.__webglFramebuffer[_i113]=_gl.createFramebuffer();}}else {renderTargetProperties.__webglFramebuffer=_gl.createFramebuffer();if(isMultisample){if(isWebGL2){renderTargetProperties.__webglMultisampledFramebuffer=_gl.createFramebuffer();renderTargetProperties.__webglColorRenderbuffer=_gl.createRenderbuffer();_gl.bindRenderbuffer(36161,renderTargetProperties.__webglColorRenderbuffer);var glFormat=utils.convert(renderTarget.texture.format);var glType=utils.convert(renderTarget.texture.type);var glInternalFormat=getInternalFormat(renderTarget.texture.internalFormat,glFormat,glType);var samples=getRenderTargetSamples(renderTarget);_gl.renderbufferStorageMultisample(36161,samples,glInternalFormat,renderTarget.width,renderTarget.height);_gl.bindFramebuffer(36160,renderTargetProperties.__webglMultisampledFramebuffer);_gl.framebufferRenderbuffer(36160,36064,36161,renderTargetProperties.__webglColorRenderbuffer);_gl.bindRenderbuffer(36161,null);if(renderTarget.depthBuffer){renderTargetProperties.__webglDepthRenderbuffer=_gl.createRenderbuffer();setupRenderBufferStorage(renderTargetProperties.__webglDepthRenderbuffer,renderTarget,true);}_gl.bindFramebuffer(36160,null);}else {console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');}}}// Setup color buffer
  808. if(isCube){state.bindTexture(34067,textureProperties.__webglTexture);setTextureParameters(34067,renderTarget.texture,supportsMips);for(var _i114=0;_i114<6;_i114++){setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer[_i114],renderTarget,36064,34069+_i114);}if(textureNeedsGenerateMipmaps(renderTarget.texture,supportsMips)){generateMipmap(34067,renderTarget.texture,renderTarget.width,renderTarget.height);}state.bindTexture(34067,null);}else {state.bindTexture(3553,textureProperties.__webglTexture);setTextureParameters(3553,renderTarget.texture,supportsMips);setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer,renderTarget,36064,3553);if(textureNeedsGenerateMipmaps(renderTarget.texture,supportsMips)){generateMipmap(3553,renderTarget.texture,renderTarget.width,renderTarget.height);}state.bindTexture(3553,null);}// Setup depth and stencil buffers
  809. if(renderTarget.depthBuffer){setupDepthRenderbuffer(renderTarget);}}function updateRenderTargetMipmap(renderTarget){var texture=renderTarget.texture;var supportsMips=isPowerOfTwo(renderTarget)||isWebGL2;if(textureNeedsGenerateMipmaps(texture,supportsMips)){var target=renderTarget.isWebGLCubeRenderTarget?34067:3553;var webglTexture=properties.get(texture).__webglTexture;state.bindTexture(target,webglTexture);generateMipmap(target,texture,renderTarget.width,renderTarget.height);state.bindTexture(target,null);}}function updateMultisampleRenderTarget(renderTarget){if(renderTarget.isWebGLMultisampleRenderTarget){if(isWebGL2){var renderTargetProperties=properties.get(renderTarget);_gl.bindFramebuffer(36008,renderTargetProperties.__webglMultisampledFramebuffer);_gl.bindFramebuffer(36009,renderTargetProperties.__webglFramebuffer);var width=renderTarget.width;var height=renderTarget.height;var mask=16384;if(renderTarget.depthBuffer)mask|=256;if(renderTarget.stencilBuffer)mask|=1024;_gl.blitFramebuffer(0,0,width,height,0,0,width,height,mask,9728);_gl.bindFramebuffer(36160,renderTargetProperties.__webglMultisampledFramebuffer);// see #18905
  810. }else {console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');}}}function getRenderTargetSamples(renderTarget){return isWebGL2&&renderTarget.isWebGLMultisampleRenderTarget?Math.min(maxSamples,renderTarget.samples):0;}function updateVideoTexture(texture){var frame=info.render.frame;// Check the last frame we updated the VideoTexture
  811. if(_videoTextures.get(texture)!==frame){_videoTextures.set(texture,frame);texture.update();}}// backwards compatibility
  812. var warnedTexture2D=false;var warnedTextureCube=false;function safeSetTexture2D(texture,slot){if(texture&&texture.isWebGLRenderTarget){if(warnedTexture2D===false){console.warn('THREE.WebGLTextures.safeSetTexture2D: don\'t use render targets as textures. Use their .texture property instead.');warnedTexture2D=true;}texture=texture.texture;}setTexture2D(texture,slot);}function safeSetTextureCube(texture,slot){if(texture&&texture.isWebGLCubeRenderTarget){if(warnedTextureCube===false){console.warn('THREE.WebGLTextures.safeSetTextureCube: don\'t use cube render targets as textures. Use their .texture property instead.');warnedTextureCube=true;}texture=texture.texture;}setTextureCube(texture,slot);}//
  813. this.allocateTextureUnit=allocateTextureUnit;this.resetTextureUnits=resetTextureUnits;this.setTexture2D=setTexture2D;this.setTexture2DArray=setTexture2DArray;this.setTexture3D=setTexture3D;this.setTextureCube=setTextureCube;this.setupRenderTarget=setupRenderTarget;this.updateRenderTargetMipmap=updateRenderTargetMipmap;this.updateMultisampleRenderTarget=updateMultisampleRenderTarget;this.safeSetTexture2D=safeSetTexture2D;this.safeSetTextureCube=safeSetTextureCube;}function WebGLUtils(gl,extensions,capabilities){var isWebGL2=capabilities.isWebGL2;function convert(p){var extension;if(p===UnsignedByteType)return 5121;if(p===UnsignedShort4444Type)return 32819;if(p===UnsignedShort5551Type)return 32820;if(p===UnsignedShort565Type)return 33635;if(p===ByteType)return 5120;if(p===ShortType)return 5122;if(p===UnsignedShortType)return 5123;if(p===IntType)return 5124;if(p===UnsignedIntType)return 5125;if(p===FloatType)return 5126;if(p===HalfFloatType){if(isWebGL2)return 5131;extension=extensions.get('OES_texture_half_float');if(extension!==null){return extension.HALF_FLOAT_OES;}else {return null;}}if(p===AlphaFormat)return 6406;if(p===RGBFormat)return 6407;if(p===RGBAFormat)return 6408;if(p===LuminanceFormat)return 6409;if(p===LuminanceAlphaFormat)return 6410;if(p===DepthFormat)return 6402;if(p===DepthStencilFormat)return 34041;if(p===RedFormat)return 6403;// WebGL2 formats.
  814. if(p===RedIntegerFormat)return 36244;if(p===RGFormat)return 33319;if(p===RGIntegerFormat)return 33320;if(p===RGBIntegerFormat)return 36248;if(p===RGBAIntegerFormat)return 36249;if(p===RGB_S3TC_DXT1_Format||p===RGBA_S3TC_DXT1_Format$1||p===RGBA_S3TC_DXT3_Format||p===RGBA_S3TC_DXT5_Format$1){extension=extensions.get('WEBGL_compressed_texture_s3tc');if(extension!==null){if(p===RGB_S3TC_DXT1_Format)return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;if(p===RGBA_S3TC_DXT1_Format$1)return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(p===RGBA_S3TC_DXT3_Format)return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(p===RGBA_S3TC_DXT5_Format$1)return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;}else {return null;}}if(p===RGB_PVRTC_4BPPV1_Format||p===RGB_PVRTC_2BPPV1_Format||p===RGBA_PVRTC_4BPPV1_Format||p===RGBA_PVRTC_2BPPV1_Format){extension=extensions.get('WEBGL_compressed_texture_pvrtc');if(extension!==null){if(p===RGB_PVRTC_4BPPV1_Format)return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(p===RGB_PVRTC_2BPPV1_Format)return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(p===RGBA_PVRTC_4BPPV1_Format)return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(p===RGBA_PVRTC_2BPPV1_Format)return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;}else {return null;}}if(p===RGB_ETC1_Format){extension=extensions.get('WEBGL_compressed_texture_etc1');if(extension!==null){return extension.COMPRESSED_RGB_ETC1_WEBGL;}else {return null;}}if(p===RGB_ETC2_Format||p===RGBA_ETC2_EAC_Format){extension=extensions.get('WEBGL_compressed_texture_etc');if(extension!==null){if(p===RGB_ETC2_Format)return extension.COMPRESSED_RGB8_ETC2;if(p===RGBA_ETC2_EAC_Format)return extension.COMPRESSED_RGBA8_ETC2_EAC;}}if(p===RGBA_ASTC_4x4_Format||p===RGBA_ASTC_5x4_Format||p===RGBA_ASTC_5x5_Format||p===RGBA_ASTC_6x5_Format||p===RGBA_ASTC_6x6_Format||p===RGBA_ASTC_8x5_Format||p===RGBA_ASTC_8x6_Format||p===RGBA_ASTC_8x8_Format||p===RGBA_ASTC_10x5_Format||p===RGBA_ASTC_10x6_Format||p===RGBA_ASTC_10x8_Format||p===RGBA_ASTC_10x10_Format||p===RGBA_ASTC_12x10_Format||p===RGBA_ASTC_12x12_Format||p===SRGB8_ALPHA8_ASTC_4x4_Format||p===SRGB8_ALPHA8_ASTC_5x4_Format||p===SRGB8_ALPHA8_ASTC_5x5_Format||p===SRGB8_ALPHA8_ASTC_6x5_Format||p===SRGB8_ALPHA8_ASTC_6x6_Format||p===SRGB8_ALPHA8_ASTC_8x5_Format||p===SRGB8_ALPHA8_ASTC_8x6_Format||p===SRGB8_ALPHA8_ASTC_8x8_Format||p===SRGB8_ALPHA8_ASTC_10x5_Format||p===SRGB8_ALPHA8_ASTC_10x6_Format||p===SRGB8_ALPHA8_ASTC_10x8_Format||p===SRGB8_ALPHA8_ASTC_10x10_Format||p===SRGB8_ALPHA8_ASTC_12x10_Format||p===SRGB8_ALPHA8_ASTC_12x12_Format){extension=extensions.get('WEBGL_compressed_texture_astc');if(extension!==null){// TODO Complete?
  815. return p;}else {return null;}}if(p===RGBA_BPTC_Format){extension=extensions.get('EXT_texture_compression_bptc');if(extension!==null){// TODO Complete?
  816. return p;}else {return null;}}if(p===UnsignedInt248Type$1){if(isWebGL2)return 34042;extension=extensions.get('WEBGL_depth_texture');if(extension!==null){return extension.UNSIGNED_INT_24_8_WEBGL;}else {return null;}}}return {convert:convert};}function ArrayCamera(){var array=arguments.length>0&&arguments[0]!==undefined?arguments[0]:[];PerspectiveCamera.call(this);this.cameras=array;}ArrayCamera.prototype=Object.assign(Object.create(PerspectiveCamera.prototype),{constructor:ArrayCamera,isArrayCamera:true});function Group(){Object3D.call(this);this.type='Group';}Group.prototype=Object.assign(Object.create(Object3D.prototype),{constructor:Group,isGroup:true});function WebXRController(){this._targetRay=null;this._grip=null;this._hand=null;}Object.assign(WebXRController.prototype,{constructor:WebXRController,getHandSpace:function getHandSpace(){if(this._hand===null){this._hand=new Group();this._hand.matrixAutoUpdate=false;this._hand.visible=false;this._hand.joints=[];this._hand.inputState={pinching:false};if(window.XRHand){for(var _i115=0;_i115<=window.XRHand.LITTLE_PHALANX_TIP;_i115++){// The transform of this joint will be updated with the joint pose on each frame
  817. var joint=new Group();joint.matrixAutoUpdate=false;joint.visible=false;this._hand.joints.push(joint);// ??
  818. this._hand.add(joint);}}}return this._hand;},getTargetRaySpace:function getTargetRaySpace(){if(this._targetRay===null){this._targetRay=new Group();this._targetRay.matrixAutoUpdate=false;this._targetRay.visible=false;}return this._targetRay;},getGripSpace:function getGripSpace(){if(this._grip===null){this._grip=new Group();this._grip.matrixAutoUpdate=false;this._grip.visible=false;}return this._grip;},dispatchEvent:function dispatchEvent(event){if(this._targetRay!==null){this._targetRay.dispatchEvent(event);}if(this._grip!==null){this._grip.dispatchEvent(event);}if(this._hand!==null){this._hand.dispatchEvent(event);}return this;},disconnect:function disconnect(inputSource){this.dispatchEvent({type:'disconnected',data:inputSource});if(this._targetRay!==null){this._targetRay.visible=false;}if(this._grip!==null){this._grip.visible=false;}if(this._hand!==null){this._hand.visible=false;}return this;},update:function update(inputSource,frame,referenceSpace){var inputPose=null;var gripPose=null;var handPose=null;var targetRay=this._targetRay;var grip=this._grip;var hand=this._hand;if(inputSource&&frame.session.visibilityState!=='visible-blurred'){if(hand&&inputSource.hand){handPose=true;for(var _i116=0;_i116<=window.XRHand.LITTLE_PHALANX_TIP;_i116++){if(inputSource.hand[_i116]){// Update the joints groups with the XRJoint poses
  819. var jointPose=frame.getJointPose(inputSource.hand[_i116],referenceSpace);var joint=hand.joints[_i116];if(jointPose!==null){joint.matrix.fromArray(jointPose.transform.matrix);joint.matrix.decompose(joint.position,joint.rotation,joint.scale);joint.jointRadius=jointPose.radius;}joint.visible=jointPose!==null;// Custom events
  820. // Check pinch
  821. var indexTip=hand.joints[window.XRHand.INDEX_PHALANX_TIP];var thumbTip=hand.joints[window.XRHand.THUMB_PHALANX_TIP];var distance=indexTip.position.distanceTo(thumbTip.position);var distanceToPinch=0.02;var threshold=0.005;if(hand.inputState.pinching&&distance>distanceToPinch+threshold){hand.inputState.pinching=false;this.dispatchEvent({type:'pinchend',handedness:inputSource.handedness,target:this});}else if(!hand.inputState.pinching&&distance<=distanceToPinch-threshold){hand.inputState.pinching=true;this.dispatchEvent({type:'pinchstart',handedness:inputSource.handedness,target:this});}}}}else {if(targetRay!==null){inputPose=frame.getPose(inputSource.targetRaySpace,referenceSpace);if(inputPose!==null){targetRay.matrix.fromArray(inputPose.transform.matrix);targetRay.matrix.decompose(targetRay.position,targetRay.rotation,targetRay.scale);}}if(grip!==null&&inputSource.gripSpace){gripPose=frame.getPose(inputSource.gripSpace,referenceSpace);if(gripPose!==null){grip.matrix.fromArray(gripPose.transform.matrix);grip.matrix.decompose(grip.position,grip.rotation,grip.scale);}}}}if(targetRay!==null){targetRay.visible=inputPose!==null;}if(grip!==null){grip.visible=gripPose!==null;}if(hand!==null){hand.visible=handPose!==null;}return this;}});function WebXRManager(renderer,gl){var scope=this;var session=null;var framebufferScaleFactor=1.0;var referenceSpace=null;var referenceSpaceType='local-floor';var pose=null;var controllers=[];var inputSourcesMap=new Map();//
  822. var cameraL=new PerspectiveCamera();cameraL.layers.enable(1);cameraL.viewport=new Vector4();var cameraR=new PerspectiveCamera();cameraR.layers.enable(2);cameraR.viewport=new Vector4();var cameras=[cameraL,cameraR];var cameraVR=new ArrayCamera();cameraVR.layers.enable(1);cameraVR.layers.enable(2);var _currentDepthNear=null;var _currentDepthFar=null;//
  823. this.enabled=false;this.isPresenting=false;this.getController=function(index){var controller=controllers[index];if(controller===undefined){controller=new WebXRController();controllers[index]=controller;}return controller.getTargetRaySpace();};this.getControllerGrip=function(index){var controller=controllers[index];if(controller===undefined){controller=new WebXRController();controllers[index]=controller;}return controller.getGripSpace();};this.getHand=function(index){var controller=controllers[index];if(controller===undefined){controller=new WebXRController();controllers[index]=controller;}return controller.getHandSpace();};//
  824. function onSessionEvent(event){var controller=inputSourcesMap.get(event.inputSource);if(controller){controller.dispatchEvent({type:event.type,data:event.inputSource});}}function onSessionEnd(){inputSourcesMap.forEach(function(controller,inputSource){controller.disconnect(inputSource);});inputSourcesMap.clear();//
  825. renderer.setFramebuffer(null);renderer.setRenderTarget(renderer.getRenderTarget());// Hack #15830
  826. animation.stop();scope.isPresenting=false;scope.dispatchEvent({type:'sessionend'});}function onRequestReferenceSpace(value){referenceSpace=value;animation.setContext(session);animation.start();scope.isPresenting=true;scope.dispatchEvent({type:'sessionstart'});}this.setFramebufferScaleFactor=function(value){framebufferScaleFactor=value;if(scope.isPresenting===true){console.warn('THREE.WebXRManager: Cannot change framebuffer scale while presenting.');}};this.setReferenceSpaceType=function(value){referenceSpaceType=value;if(scope.isPresenting===true){console.warn('THREE.WebXRManager: Cannot change reference space type while presenting.');}};this.getReferenceSpace=function(){return referenceSpace;};this.getSession=function(){return session;};this.setSession=function(value){session=value;if(session!==null){session.addEventListener('select',onSessionEvent);session.addEventListener('selectstart',onSessionEvent);session.addEventListener('selectend',onSessionEvent);session.addEventListener('squeeze',onSessionEvent);session.addEventListener('squeezestart',onSessionEvent);session.addEventListener('squeezeend',onSessionEvent);session.addEventListener('end',onSessionEnd);var attributes=gl.getContextAttributes();if(attributes.xrCompatible!==true){gl.makeXRCompatible();}var layerInit={antialias:attributes.antialias,alpha:attributes.alpha,depth:attributes.depth,stencil:attributes.stencil,framebufferScaleFactor:framebufferScaleFactor};// eslint-disable-next-line no-undef
  827. var baseLayer=new XRWebGLLayer(session,gl,layerInit);session.updateRenderState({baseLayer:baseLayer});session.requestReferenceSpace(referenceSpaceType).then(onRequestReferenceSpace);//
  828. session.addEventListener('inputsourceschange',updateInputSources);}};function updateInputSources(event){var inputSources=session.inputSources;// Assign inputSources to available controllers
  829. for(var _i117=0;_i117<controllers.length;_i117++){inputSourcesMap.set(inputSources[_i117],controllers[_i117]);}// Notify disconnected
  830. for(var _i118=0;_i118<event.removed.length;_i118++){var inputSource=event.removed[_i118];var controller=inputSourcesMap.get(inputSource);if(controller){controller.dispatchEvent({type:'disconnected',data:inputSource});inputSourcesMap.delete(inputSource);}}// Notify connected
  831. for(var _i119=0;_i119<event.added.length;_i119++){var _inputSource=event.added[_i119];var _controller=inputSourcesMap.get(_inputSource);if(_controller){_controller.dispatchEvent({type:'connected',data:_inputSource});}}}//
  832. var cameraLPos=new Vector3();var cameraRPos=new Vector3();/**
  833. * Assumes 2 cameras that are parallel and share an X-axis, and that
  834. * the cameras' projection and world matrices have already been set.
  835. * And that near and far planes are identical for both cameras.
  836. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  837. */function setProjectionFromUnion(camera,cameraL,cameraR){cameraLPos.setFromMatrixPosition(cameraL.matrixWorld);cameraRPos.setFromMatrixPosition(cameraR.matrixWorld);var ipd=cameraLPos.distanceTo(cameraRPos);var projL=cameraL.projectionMatrix.elements;var projR=cameraR.projectionMatrix.elements;// VR systems will have identical far and near planes, and
  838. // most likely identical top and bottom frustum extents.
  839. // Use the left camera for these values.
  840. var near=projL[14]/(projL[10]-1);var far=projL[14]/(projL[10]+1);var topFov=(projL[9]+1)/projL[5];var bottomFov=(projL[9]-1)/projL[5];var leftFov=(projL[8]-1)/projL[0];var rightFov=(projR[8]+1)/projR[0];var left=near*leftFov;var right=near*rightFov;// Calculate the new camera's position offset from the
  841. // left camera. xOffset should be roughly half `ipd`.
  842. var zOffset=ipd/(-leftFov+rightFov);var xOffset=zOffset*-leftFov;// TODO: Better way to apply this offset?
  843. cameraL.matrixWorld.decompose(camera.position,camera.quaternion,camera.scale);camera.translateX(xOffset);camera.translateZ(zOffset);camera.matrixWorld.compose(camera.position,camera.quaternion,camera.scale);camera.matrixWorldInverse.copy(camera.matrixWorld).invert();// Find the union of the frustum values of the cameras and scale
  844. // the values so that the near plane's position does not change in world space,
  845. // although must now be relative to the new union camera.
  846. var near2=near+zOffset;var far2=far+zOffset;var left2=left-xOffset;var right2=right+(ipd-xOffset);var top2=topFov*far/far2*near2;var bottom2=bottomFov*far/far2*near2;camera.projectionMatrix.makePerspective(left2,right2,top2,bottom2,near2,far2);}function updateCamera(camera,parent){if(parent===null){camera.matrixWorld.copy(camera.matrix);}else {camera.matrixWorld.multiplyMatrices(parent.matrixWorld,camera.matrix);}camera.matrixWorldInverse.copy(camera.matrixWorld).invert();}this.getCamera=function(camera){cameraVR.near=cameraR.near=cameraL.near=camera.near;cameraVR.far=cameraR.far=cameraL.far=camera.far;if(_currentDepthNear!==cameraVR.near||_currentDepthFar!==cameraVR.far){// Note that the new renderState won't apply until the next frame. See #18320
  847. session.updateRenderState({depthNear:cameraVR.near,depthFar:cameraVR.far});_currentDepthNear=cameraVR.near;_currentDepthFar=cameraVR.far;}var parent=camera.parent;var cameras=cameraVR.cameras;updateCamera(cameraVR,parent);for(var _i120=0;_i120<cameras.length;_i120++){updateCamera(cameras[_i120],parent);}// update camera and its children
  848. camera.matrixWorld.copy(cameraVR.matrixWorld);var children=camera.children;for(var _i121=0,l=children.length;_i121<l;_i121++){children[_i121].updateMatrixWorld(true);}// update projection matrix for proper view frustum culling
  849. if(cameras.length===2){setProjectionFromUnion(cameraVR,cameraL,cameraR);}else {// assume single camera setup (AR)
  850. cameraVR.projectionMatrix.copy(cameraL.projectionMatrix);}return cameraVR;};// Animation Loop
  851. var onAnimationFrameCallback=null;function onAnimationFrame(time,frame){pose=frame.getViewerPose(referenceSpace);if(pose!==null){var views=pose.views;var baseLayer=session.renderState.baseLayer;renderer.setFramebuffer(baseLayer.framebuffer);var cameraVRNeedsUpdate=false;// check if it's necessary to rebuild cameraVR's camera list
  852. if(views.length!==cameraVR.cameras.length){cameraVR.cameras.length=0;cameraVRNeedsUpdate=true;}for(var _i122=0;_i122<views.length;_i122++){var view=views[_i122];var viewport=baseLayer.getViewport(view);var camera=cameras[_i122];camera.matrix.fromArray(view.transform.matrix);camera.projectionMatrix.fromArray(view.projectionMatrix);camera.viewport.set(viewport.x,viewport.y,viewport.width,viewport.height);if(_i122===0){cameraVR.matrix.copy(camera.matrix);}if(cameraVRNeedsUpdate===true){cameraVR.cameras.push(camera);}}}//
  853. var inputSources=session.inputSources;for(var _i123=0;_i123<controllers.length;_i123++){var controller=controllers[_i123];var inputSource=inputSources[_i123];controller.update(inputSource,frame,referenceSpace);}if(onAnimationFrameCallback)onAnimationFrameCallback(time,frame);}var animation=new WebGLAnimation();animation.setAnimationLoop(onAnimationFrame);this.setAnimationLoop=function(callback){onAnimationFrameCallback=callback;};this.dispose=function(){};}Object.assign(WebXRManager.prototype,EventDispatcher.prototype);function WebGLMaterials(properties){function refreshFogUniforms(uniforms,fog){uniforms.fogColor.value.copy(fog.color);if(fog.isFog){uniforms.fogNear.value=fog.near;uniforms.fogFar.value=fog.far;}else if(fog.isFogExp2){uniforms.fogDensity.value=fog.density;}}function refreshMaterialUniforms(uniforms,material,pixelRatio,height){if(material.isMeshBasicMaterial){refreshUniformsCommon(uniforms,material);}else if(material.isMeshLambertMaterial){refreshUniformsCommon(uniforms,material);refreshUniformsLambert(uniforms,material);}else if(material.isMeshToonMaterial){refreshUniformsCommon(uniforms,material);refreshUniformsToon(uniforms,material);}else if(material.isMeshPhongMaterial){refreshUniformsCommon(uniforms,material);refreshUniformsPhong(uniforms,material);}else if(material.isMeshStandardMaterial){refreshUniformsCommon(uniforms,material);if(material.isMeshPhysicalMaterial){refreshUniformsPhysical(uniforms,material);}else {refreshUniformsStandard(uniforms,material);}}else if(material.isMeshMatcapMaterial){refreshUniformsCommon(uniforms,material);refreshUniformsMatcap(uniforms,material);}else if(material.isMeshDepthMaterial){refreshUniformsCommon(uniforms,material);refreshUniformsDepth(uniforms,material);}else if(material.isMeshDistanceMaterial){refreshUniformsCommon(uniforms,material);refreshUniformsDistance(uniforms,material);}else if(material.isMeshNormalMaterial){refreshUniformsCommon(uniforms,material);refreshUniformsNormal(uniforms,material);}else if(material.isLineBasicMaterial){refreshUniformsLine(uniforms,material);if(material.isLineDashedMaterial){refreshUniformsDash(uniforms,material);}}else if(material.isPointsMaterial){refreshUniformsPoints(uniforms,material,pixelRatio,height);}else if(material.isSpriteMaterial){refreshUniformsSprites(uniforms,material);}else if(material.isShadowMaterial){uniforms.color.value.copy(material.color);uniforms.opacity.value=material.opacity;}else if(material.isShaderMaterial){material.uniformsNeedUpdate=false;// #15581
  854. }}function refreshUniformsCommon(uniforms,material){uniforms.opacity.value=material.opacity;if(material.color){uniforms.diffuse.value.copy(material.color);}if(material.emissive){uniforms.emissive.value.copy(material.emissive).multiplyScalar(material.emissiveIntensity);}if(material.map){uniforms.map.value=material.map;}if(material.alphaMap){uniforms.alphaMap.value=material.alphaMap;}if(material.specularMap){uniforms.specularMap.value=material.specularMap;}var envMap=properties.get(material).envMap;if(envMap){uniforms.envMap.value=envMap;uniforms.flipEnvMap.value=envMap.isCubeTexture&&envMap._needsFlipEnvMap?-1:1;uniforms.reflectivity.value=material.reflectivity;uniforms.refractionRatio.value=material.refractionRatio;var maxMipLevel=properties.get(envMap).__maxMipLevel;if(maxMipLevel!==undefined){uniforms.maxMipLevel.value=maxMipLevel;}}if(material.lightMap){uniforms.lightMap.value=material.lightMap;uniforms.lightMapIntensity.value=material.lightMapIntensity;}if(material.aoMap){uniforms.aoMap.value=material.aoMap;uniforms.aoMapIntensity.value=material.aoMapIntensity;}// uv repeat and offset setting priorities
  855. // 1. color map
  856. // 2. specular map
  857. // 3. displacementMap map
  858. // 4. normal map
  859. // 5. bump map
  860. // 6. roughnessMap map
  861. // 7. metalnessMap map
  862. // 8. alphaMap map
  863. // 9. emissiveMap map
  864. // 10. clearcoat map
  865. // 11. clearcoat normal map
  866. // 12. clearcoat roughnessMap map
  867. var uvScaleMap;if(material.map){uvScaleMap=material.map;}else if(material.specularMap){uvScaleMap=material.specularMap;}else if(material.displacementMap){uvScaleMap=material.displacementMap;}else if(material.normalMap){uvScaleMap=material.normalMap;}else if(material.bumpMap){uvScaleMap=material.bumpMap;}else if(material.roughnessMap){uvScaleMap=material.roughnessMap;}else if(material.metalnessMap){uvScaleMap=material.metalnessMap;}else if(material.alphaMap){uvScaleMap=material.alphaMap;}else if(material.emissiveMap){uvScaleMap=material.emissiveMap;}else if(material.clearcoatMap){uvScaleMap=material.clearcoatMap;}else if(material.clearcoatNormalMap){uvScaleMap=material.clearcoatNormalMap;}else if(material.clearcoatRoughnessMap){uvScaleMap=material.clearcoatRoughnessMap;}if(uvScaleMap!==undefined){// backwards compatibility
  868. if(uvScaleMap.isWebGLRenderTarget){uvScaleMap=uvScaleMap.texture;}if(uvScaleMap.matrixAutoUpdate===true){uvScaleMap.updateMatrix();}uniforms.uvTransform.value.copy(uvScaleMap.matrix);}// uv repeat and offset setting priorities for uv2
  869. // 1. ao map
  870. // 2. light map
  871. var uv2ScaleMap;if(material.aoMap){uv2ScaleMap=material.aoMap;}else if(material.lightMap){uv2ScaleMap=material.lightMap;}if(uv2ScaleMap!==undefined){// backwards compatibility
  872. if(uv2ScaleMap.isWebGLRenderTarget){uv2ScaleMap=uv2ScaleMap.texture;}if(uv2ScaleMap.matrixAutoUpdate===true){uv2ScaleMap.updateMatrix();}uniforms.uv2Transform.value.copy(uv2ScaleMap.matrix);}}function refreshUniformsLine(uniforms,material){uniforms.diffuse.value.copy(material.color);uniforms.opacity.value=material.opacity;}function refreshUniformsDash(uniforms,material){uniforms.dashSize.value=material.dashSize;uniforms.totalSize.value=material.dashSize+material.gapSize;uniforms.scale.value=material.scale;}function refreshUniformsPoints(uniforms,material,pixelRatio,height){uniforms.diffuse.value.copy(material.color);uniforms.opacity.value=material.opacity;uniforms.size.value=material.size*pixelRatio;uniforms.scale.value=height*0.5;if(material.map){uniforms.map.value=material.map;}if(material.alphaMap){uniforms.alphaMap.value=material.alphaMap;}// uv repeat and offset setting priorities
  873. // 1. color map
  874. // 2. alpha map
  875. var uvScaleMap;if(material.map){uvScaleMap=material.map;}else if(material.alphaMap){uvScaleMap=material.alphaMap;}if(uvScaleMap!==undefined){if(uvScaleMap.matrixAutoUpdate===true){uvScaleMap.updateMatrix();}uniforms.uvTransform.value.copy(uvScaleMap.matrix);}}function refreshUniformsSprites(uniforms,material){uniforms.diffuse.value.copy(material.color);uniforms.opacity.value=material.opacity;uniforms.rotation.value=material.rotation;if(material.map){uniforms.map.value=material.map;}if(material.alphaMap){uniforms.alphaMap.value=material.alphaMap;}// uv repeat and offset setting priorities
  876. // 1. color map
  877. // 2. alpha map
  878. var uvScaleMap;if(material.map){uvScaleMap=material.map;}else if(material.alphaMap){uvScaleMap=material.alphaMap;}if(uvScaleMap!==undefined){if(uvScaleMap.matrixAutoUpdate===true){uvScaleMap.updateMatrix();}uniforms.uvTransform.value.copy(uvScaleMap.matrix);}}function refreshUniformsLambert(uniforms,material){if(material.emissiveMap){uniforms.emissiveMap.value=material.emissiveMap;}}function refreshUniformsPhong(uniforms,material){uniforms.specular.value.copy(material.specular);uniforms.shininess.value=Math.max(material.shininess,1e-4);// to prevent pow( 0.0, 0.0 )
  879. if(material.emissiveMap){uniforms.emissiveMap.value=material.emissiveMap;}if(material.bumpMap){uniforms.bumpMap.value=material.bumpMap;uniforms.bumpScale.value=material.bumpScale;if(material.side===BackSide)uniforms.bumpScale.value*=-1;}if(material.normalMap){uniforms.normalMap.value=material.normalMap;uniforms.normalScale.value.copy(material.normalScale);if(material.side===BackSide)uniforms.normalScale.value.negate();}if(material.displacementMap){uniforms.displacementMap.value=material.displacementMap;uniforms.displacementScale.value=material.displacementScale;uniforms.displacementBias.value=material.displacementBias;}}function refreshUniformsToon(uniforms,material){if(material.gradientMap){uniforms.gradientMap.value=material.gradientMap;}if(material.emissiveMap){uniforms.emissiveMap.value=material.emissiveMap;}if(material.bumpMap){uniforms.bumpMap.value=material.bumpMap;uniforms.bumpScale.value=material.bumpScale;if(material.side===BackSide)uniforms.bumpScale.value*=-1;}if(material.normalMap){uniforms.normalMap.value=material.normalMap;uniforms.normalScale.value.copy(material.normalScale);if(material.side===BackSide)uniforms.normalScale.value.negate();}if(material.displacementMap){uniforms.displacementMap.value=material.displacementMap;uniforms.displacementScale.value=material.displacementScale;uniforms.displacementBias.value=material.displacementBias;}}function refreshUniformsStandard(uniforms,material){uniforms.roughness.value=material.roughness;uniforms.metalness.value=material.metalness;if(material.roughnessMap){uniforms.roughnessMap.value=material.roughnessMap;}if(material.metalnessMap){uniforms.metalnessMap.value=material.metalnessMap;}if(material.emissiveMap){uniforms.emissiveMap.value=material.emissiveMap;}if(material.bumpMap){uniforms.bumpMap.value=material.bumpMap;uniforms.bumpScale.value=material.bumpScale;if(material.side===BackSide)uniforms.bumpScale.value*=-1;}if(material.normalMap){uniforms.normalMap.value=material.normalMap;uniforms.normalScale.value.copy(material.normalScale);if(material.side===BackSide)uniforms.normalScale.value.negate();}if(material.displacementMap){uniforms.displacementMap.value=material.displacementMap;uniforms.displacementScale.value=material.displacementScale;uniforms.displacementBias.value=material.displacementBias;}var envMap=properties.get(material).envMap;if(envMap){//uniforms.envMap.value = material.envMap; // part of uniforms common
  880. uniforms.envMapIntensity.value=material.envMapIntensity;}}function refreshUniformsPhysical(uniforms,material){refreshUniformsStandard(uniforms,material);uniforms.reflectivity.value=material.reflectivity;// also part of uniforms common
  881. uniforms.clearcoat.value=material.clearcoat;uniforms.clearcoatRoughness.value=material.clearcoatRoughness;if(material.sheen)uniforms.sheen.value.copy(material.sheen);if(material.clearcoatMap){uniforms.clearcoatMap.value=material.clearcoatMap;}if(material.clearcoatRoughnessMap){uniforms.clearcoatRoughnessMap.value=material.clearcoatRoughnessMap;}if(material.clearcoatNormalMap){uniforms.clearcoatNormalScale.value.copy(material.clearcoatNormalScale);uniforms.clearcoatNormalMap.value=material.clearcoatNormalMap;if(material.side===BackSide){uniforms.clearcoatNormalScale.value.negate();}}uniforms.transmission.value=material.transmission;if(material.transmissionMap){uniforms.transmissionMap.value=material.transmissionMap;}}function refreshUniformsMatcap(uniforms,material){if(material.matcap){uniforms.matcap.value=material.matcap;}if(material.bumpMap){uniforms.bumpMap.value=material.bumpMap;uniforms.bumpScale.value=material.bumpScale;if(material.side===BackSide)uniforms.bumpScale.value*=-1;}if(material.normalMap){uniforms.normalMap.value=material.normalMap;uniforms.normalScale.value.copy(material.normalScale);if(material.side===BackSide)uniforms.normalScale.value.negate();}if(material.displacementMap){uniforms.displacementMap.value=material.displacementMap;uniforms.displacementScale.value=material.displacementScale;uniforms.displacementBias.value=material.displacementBias;}}function refreshUniformsDepth(uniforms,material){if(material.displacementMap){uniforms.displacementMap.value=material.displacementMap;uniforms.displacementScale.value=material.displacementScale;uniforms.displacementBias.value=material.displacementBias;}}function refreshUniformsDistance(uniforms,material){if(material.displacementMap){uniforms.displacementMap.value=material.displacementMap;uniforms.displacementScale.value=material.displacementScale;uniforms.displacementBias.value=material.displacementBias;}uniforms.referencePosition.value.copy(material.referencePosition);uniforms.nearDistance.value=material.nearDistance;uniforms.farDistance.value=material.farDistance;}function refreshUniformsNormal(uniforms,material){if(material.bumpMap){uniforms.bumpMap.value=material.bumpMap;uniforms.bumpScale.value=material.bumpScale;if(material.side===BackSide)uniforms.bumpScale.value*=-1;}if(material.normalMap){uniforms.normalMap.value=material.normalMap;uniforms.normalScale.value.copy(material.normalScale);if(material.side===BackSide)uniforms.normalScale.value.negate();}if(material.displacementMap){uniforms.displacementMap.value=material.displacementMap;uniforms.displacementScale.value=material.displacementScale;uniforms.displacementBias.value=material.displacementBias;}}return {refreshFogUniforms:refreshFogUniforms,refreshMaterialUniforms:refreshMaterialUniforms};}function createCanvasElement(){var canvas=document.createElementNS('http://www.w3.org/1999/xhtml','canvas');canvas.style.display='block';return canvas;}function WebGLRenderer(parameters){parameters=parameters||{};var _canvas=parameters.canvas!==undefined?parameters.canvas:createCanvasElement(),_context=parameters.context!==undefined?parameters.context:null,_alpha=parameters.alpha!==undefined?parameters.alpha:false,_depth=parameters.depth!==undefined?parameters.depth:true,_stencil=parameters.stencil!==undefined?parameters.stencil:true,_antialias=parameters.antialias!==undefined?parameters.antialias:false,_premultipliedAlpha=parameters.premultipliedAlpha!==undefined?parameters.premultipliedAlpha:true,_preserveDrawingBuffer=parameters.preserveDrawingBuffer!==undefined?parameters.preserveDrawingBuffer:false,_powerPreference=parameters.powerPreference!==undefined?parameters.powerPreference:'default',_failIfMajorPerformanceCaveat=parameters.failIfMajorPerformanceCaveat!==undefined?parameters.failIfMajorPerformanceCaveat:false;var currentRenderList=null;var currentRenderState=null;// render() can be called from within a callback triggered by another render.
  882. // We track this so that the nested render call gets its state isolated from the parent render call.
  883. var renderStateStack=[];// public properties
  884. this.domElement=_canvas;// Debug configuration container
  885. this.debug={/**
  886. * Enables error checking and reporting when shader programs are being compiled
  887. * @type {boolean}
  888. */checkShaderErrors:true};// clearing
  889. this.autoClear=true;this.autoClearColor=true;this.autoClearDepth=true;this.autoClearStencil=true;// scene graph
  890. this.sortObjects=true;// user-defined clipping
  891. this.clippingPlanes=[];this.localClippingEnabled=false;// physically based shading
  892. this.gammaFactor=2.0;// for backwards compatibility
  893. this.outputEncoding=LinearEncoding;// physical lights
  894. this.physicallyCorrectLights=false;// tone mapping
  895. this.toneMapping=NoToneMapping;this.toneMappingExposure=1.0;// morphs
  896. this.maxMorphTargets=8;this.maxMorphNormals=4;// internal properties
  897. var _this=this;var _isContextLost=false;// internal state cache
  898. var _framebuffer=null;var _currentActiveCubeFace=0;var _currentActiveMipmapLevel=0;var _currentRenderTarget=null;var _currentFramebuffer=null;var _currentMaterialId=-1;var _currentCamera=null;var _currentViewport=new Vector4();var _currentScissor=new Vector4();var _currentScissorTest=null;//
  899. var _width=_canvas.width;var _height=_canvas.height;var _pixelRatio=1;var _opaqueSort=null;var _transparentSort=null;var _viewport=new Vector4(0,0,_width,_height);var _scissor=new Vector4(0,0,_width,_height);var _scissorTest=false;// frustum
  900. var _frustum=new Frustum();// clipping
  901. var _clippingEnabled=false;var _localClippingEnabled=false;// camera matrices cache
  902. var _projScreenMatrix=new Matrix4();var _vector3=new Vector3();var _emptyScene={background:null,fog:null,environment:null,overrideMaterial:null,isScene:true};function getTargetPixelRatio(){return _currentRenderTarget===null?_pixelRatio:1;}// initialize
  903. var _gl=_context;function getContext(contextNames,contextAttributes){for(var _i124=0;_i124<contextNames.length;_i124++){var contextName=contextNames[_i124];var context=_canvas.getContext(contextName,contextAttributes);if(context!==null)return context;}return null;}try{var contextAttributes={alpha:_alpha,depth:_depth,stencil:_stencil,antialias:_antialias,premultipliedAlpha:_premultipliedAlpha,preserveDrawingBuffer:_preserveDrawingBuffer,powerPreference:_powerPreference,failIfMajorPerformanceCaveat:_failIfMajorPerformanceCaveat};// event listeners must be registered before WebGL context is created, see #12753
  904. _canvas.addEventListener('webglcontextlost',onContextLost,false);_canvas.addEventListener('webglcontextrestored',onContextRestore,false);if(_gl===null){var contextNames=['webgl2','webgl','experimental-webgl'];if(_this.isWebGL1Renderer===true){contextNames.shift();}_gl=getContext(contextNames,contextAttributes);if(_gl===null){if(getContext(contextNames)){throw new Error('Error creating WebGL context with your selected attributes.');}else {throw new Error('Error creating WebGL context.');}}}// Some experimental-webgl implementations do not have getShaderPrecisionFormat
  905. if(_gl.getShaderPrecisionFormat===undefined){_gl.getShaderPrecisionFormat=function(){return {'rangeMin':1,'rangeMax':1,'precision':1};};}}catch(error){console.error('THREE.WebGLRenderer: '+error.message);throw error;}var extensions,capabilities,state,info;var properties,textures,cubemaps,attributes,geometries,objects;var programCache,materials,renderLists,renderStates,clipping;var background,morphtargets,bufferRenderer,indexedBufferRenderer;var utils,bindingStates;function initGLContext(){extensions=new WebGLExtensions(_gl);capabilities=new WebGLCapabilities(_gl,extensions,parameters);if(capabilities.isWebGL2===false){extensions.get('WEBGL_depth_texture');extensions.get('OES_texture_float');extensions.get('OES_texture_half_float');extensions.get('OES_texture_half_float_linear');extensions.get('OES_standard_derivatives');extensions.get('OES_element_index_uint');extensions.get('OES_vertex_array_object');extensions.get('ANGLE_instanced_arrays');}extensions.get('OES_texture_float_linear');utils=new WebGLUtils(_gl,extensions,capabilities);state=new WebGLState(_gl,extensions,capabilities);state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());info=new WebGLInfo(_gl);properties=new WebGLProperties();textures=new WebGLTextures(_gl,extensions,state,properties,capabilities,utils,info);cubemaps=new WebGLCubeMaps(_this);attributes=new WebGLAttributes(_gl,capabilities);bindingStates=new WebGLBindingStates(_gl,extensions,attributes,capabilities);geometries=new WebGLGeometries(_gl,attributes,info,bindingStates);objects=new WebGLObjects(_gl,geometries,attributes,info);morphtargets=new WebGLMorphtargets(_gl);clipping=new WebGLClipping(properties);programCache=new WebGLPrograms(_this,cubemaps,extensions,capabilities,bindingStates,clipping);materials=new WebGLMaterials(properties);renderLists=new WebGLRenderLists(properties);renderStates=new WebGLRenderStates(extensions,capabilities);background=new WebGLBackground(_this,cubemaps,state,objects,_premultipliedAlpha);bufferRenderer=new WebGLBufferRenderer(_gl,extensions,info,capabilities);indexedBufferRenderer=new WebGLIndexedBufferRenderer(_gl,extensions,info,capabilities);info.programs=programCache.programs;_this.capabilities=capabilities;_this.extensions=extensions;_this.properties=properties;_this.renderLists=renderLists;_this.state=state;_this.info=info;_this._textures=textures;//add
  906. }initGLContext();// xr
  907. var xr=new WebXRManager(_this,_gl);this.xr=xr;// shadow map
  908. var shadowMap=new WebGLShadowMap(_this,objects,capabilities.maxTextureSize);this.shadowMap=shadowMap;// API
  909. this.getContext=function(){return _gl;};this.getContextAttributes=function(){return _gl.getContextAttributes();};this.forceContextLoss=function(){var extension=extensions.get('WEBGL_lose_context');if(extension)extension.loseContext();};this.forceContextRestore=function(){var extension=extensions.get('WEBGL_lose_context');if(extension)extension.restoreContext();};this.getPixelRatio=function(){return _pixelRatio;};this.setPixelRatio=function(value){if(value===undefined)return;_pixelRatio=value;this.setSize(_width,_height,false);};this.getSize=function(target){if(target===undefined){console.warn('WebGLRenderer: .getsize() now requires a Vector2 as an argument');target=new Vector2();}return target.set(_width,_height);};this.setSize=function(width,height,updateStyle){if(xr.isPresenting){console.warn('THREE.WebGLRenderer: Can\'t change size while VR device is presenting.');return;}_width=width;_height=height;_canvas.width=Math.floor(width*_pixelRatio);_canvas.height=Math.floor(height*_pixelRatio);if(updateStyle!==false){_canvas.style.width=width+'px';_canvas.style.height=height+'px';}this.setViewport(0,0,width,height);};this.getDrawingBufferSize=function(target){if(target===undefined){console.warn('WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument');target=new Vector2();}return target.set(_width*_pixelRatio,_height*_pixelRatio).floor();};this.setDrawingBufferSize=function(width,height,pixelRatio){_width=width;_height=height;_pixelRatio=pixelRatio;_canvas.width=Math.floor(width*pixelRatio);_canvas.height=Math.floor(height*pixelRatio);this.setViewport(0,0,width,height);};this.getCurrentViewport=function(target){if(target===undefined){console.warn('WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument');target=new Vector4();}return target.copy(_currentViewport);};this.getViewport=function(target){return target.copy(_viewport);};this.setViewport=function(x,y,width,height){if(x.isVector4){_viewport.set(x.x,x.y,x.z,x.w);}else {_viewport.set(x,y,width,height);}state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());};this.getScissor=function(target){return target.copy(_scissor);};this.setScissor=function(x,y,width,height){if(x.isVector4){_scissor.set(x.x,x.y,x.z,x.w);}else {_scissor.set(x,y,width,height);}state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());};this.getScissorTest=function(){return _scissorTest;};this.setScissorTest=function(boolean){state.setScissorTest(_scissorTest=boolean);};this.setOpaqueSort=function(method){_opaqueSort=method;};this.setTransparentSort=function(method){_transparentSort=method;};// Clearing
  910. this.getClearColor=function(target){if(target===undefined){console.warn('WebGLRenderer: .getClearColor() now requires a Color as an argument');target=new Color();}return target.copy(background.getClearColor());};this.setClearColor=function(){background.setClearColor.apply(background,arguments);};this.getClearAlpha=function(){return background.getClearAlpha();};this.setClearAlpha=function(){background.setClearAlpha.apply(background,arguments);};this.clear=function(color,depth,stencil){var bits=0;if(color===undefined||color)bits|=16384;if(depth===undefined||depth)bits|=256;if(stencil===undefined||stencil)bits|=1024;_gl.clear(bits);};this.clearColor=function(){this.clear(true,false,false);};this.clearDepth=function(){this.clear(false,true,false);};this.clearStencil=function(){this.clear(false,false,true);};//
  911. this.dispose=function(){_canvas.removeEventListener('webglcontextlost',onContextLost,false);_canvas.removeEventListener('webglcontextrestored',onContextRestore,false);renderLists.dispose();renderStates.dispose();properties.dispose();cubemaps.dispose();objects.dispose();bindingStates.dispose();xr.dispose();animation.stop();};// Events
  912. function onContextLost(event){event.preventDefault();console.log('THREE.WebGLRenderer: Context Lost.');_isContextLost=true;}function onContextRestore(/* event */){console.log('THREE.WebGLRenderer: Context Restored.');_isContextLost=false;initGLContext();}function onMaterialDispose(event){var material=event.target;material.removeEventListener('dispose',onMaterialDispose);deallocateMaterial(material);}// Buffer deallocation
  913. function deallocateMaterial(material){releaseMaterialProgramReference(material);properties.remove(material);}function releaseMaterialProgramReference(material){var programInfo=properties.get(material).program;if(programInfo!==undefined){programCache.releaseProgram(programInfo);}}// Buffer rendering
  914. function renderObjectImmediate(object,program){object.render(function(object){_this.renderBufferImmediate(object,program);});}this.renderBufferImmediate=function(object,program){bindingStates.initAttributes();var buffers=properties.get(object);if(object.hasPositions&&!buffers.position)buffers.position=_gl.createBuffer();if(object.hasNormals&&!buffers.normal)buffers.normal=_gl.createBuffer();if(object.hasUvs&&!buffers.uv)buffers.uv=_gl.createBuffer();if(object.hasColors&&!buffers.color)buffers.color=_gl.createBuffer();var programAttributes=program.getAttributes();if(object.hasPositions){_gl.bindBuffer(34962,buffers.position);_gl.bufferData(34962,object.positionArray,35048);bindingStates.enableAttribute(programAttributes.position);_gl.vertexAttribPointer(programAttributes.position,3,5126,false,0,0);}if(object.hasNormals){_gl.bindBuffer(34962,buffers.normal);_gl.bufferData(34962,object.normalArray,35048);bindingStates.enableAttribute(programAttributes.normal);_gl.vertexAttribPointer(programAttributes.normal,3,5126,false,0,0);}if(object.hasUvs){_gl.bindBuffer(34962,buffers.uv);_gl.bufferData(34962,object.uvArray,35048);bindingStates.enableAttribute(programAttributes.uv);_gl.vertexAttribPointer(programAttributes.uv,2,5126,false,0,0);}if(object.hasColors){_gl.bindBuffer(34962,buffers.color);_gl.bufferData(34962,object.colorArray,35048);bindingStates.enableAttribute(programAttributes.color);_gl.vertexAttribPointer(programAttributes.color,3,5126,false,0,0);}bindingStates.disableUnusedAttributes();_gl.drawArrays(4,0,object.count);object.count=0;};this.renderBufferDirect=function(camera,scene,geometry,material,object,group){if(scene===null)scene=_emptyScene;// renderBufferDirect second parameter used to be fog (could be null)
  915. var frontFaceCW=object.isMesh&&object.matrixWorld.determinant()<0;var program=setProgram(camera,scene,material,object);state.setMaterial(material,frontFaceCW);//
  916. var index=geometry.index;var position=geometry.attributes.position;//
  917. if(index===null){if(position===undefined||position.count===0)return;}else if(index.count===0){return;}//
  918. var rangeFactor=1;if(material.wireframe===true){index=geometries.getWireframeAttribute(geometry);rangeFactor=2;}if(material.morphTargets||material.morphNormals){morphtargets.update(object,geometry,material,program);}bindingStates.setup(object,material,program,geometry,index);var attribute;var renderer=bufferRenderer;if(index!==null){attribute=attributes.get(index);renderer=indexedBufferRenderer;renderer.setIndex(attribute);}//
  919. var dataCount=index!==null?index.count:position.count;var rangeStart=geometry.drawRange.start*rangeFactor;var rangeCount=geometry.drawRange.count*rangeFactor;var groupStart=group!==null?group.start*rangeFactor:0;var groupCount=group!==null?group.count*rangeFactor:Infinity;var drawStart=Math.max(rangeStart,groupStart);var drawEnd=Math.min(dataCount,rangeStart+rangeCount,groupStart+groupCount)-1;var drawCount=Math.max(0,drawEnd-drawStart+1);if(drawCount===0)return;//
  920. if(object.isMesh){if(material.wireframe===true){state.setLineWidth(material.wireframeLinewidth*getTargetPixelRatio());renderer.setMode(1);}else {renderer.setMode(4);}}else if(object.isLine){var lineWidth=material.linewidth;if(lineWidth===undefined)lineWidth=1;// Not using Line*Material
  921. state.setLineWidth(lineWidth*getTargetPixelRatio());if(object.isLineSegments){renderer.setMode(1);}else if(object.isLineLoop){renderer.setMode(2);}else {renderer.setMode(3);}}else if(object.isPoints){renderer.setMode(0);}else if(object.isSprite){renderer.setMode(4);}if(object.isInstancedMesh){renderer.renderInstances(drawStart,drawCount,object.count);}else if(geometry.isInstancedBufferGeometry){var instanceCount=Math.min(geometry.instanceCount,geometry._maxInstanceCount);renderer.renderInstances(drawStart,drawCount,instanceCount);}else {renderer.render(drawStart,drawCount);}};// Compile
  922. this.compile=function(scene,camera){currentRenderState=renderStates.get(scene);currentRenderState.init();scene.traverseVisible(function(object){if(object.isLight&&object.layers.test(camera.layers)){currentRenderState.pushLight(object);if(object.castShadow){currentRenderState.pushShadow(object);}}});currentRenderState.setupLights();var compiled=new WeakMap();scene.traverse(function(object){var material=object.material;if(material){if(Array.isArray(material)){for(var _i125=0;_i125<material.length;_i125++){var material2=material[_i125];if(compiled.has(material2)===false){initMaterial(material2,scene,object);compiled.set(material2);}}}else if(compiled.has(material)===false){initMaterial(material,scene,object);compiled.set(material);}}});};// Animation Loop
  923. var onAnimationFrameCallback=null;function onAnimationFrame(time){if(xr.isPresenting)return;if(onAnimationFrameCallback)onAnimationFrameCallback(time);}var animation=new WebGLAnimation();animation.setAnimationLoop(onAnimationFrame);if(typeof window!=='undefined')animation.setContext(window);this.setAnimationLoop=function(callback){onAnimationFrameCallback=callback;xr.setAnimationLoop(callback);callback===null?animation.stop():animation.start();};// Rendering
  924. this.render=function(scene,camera){var renderTarget,forceClear;if(arguments[2]!==undefined){console.warn('THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.');renderTarget=arguments[2];}if(arguments[3]!==undefined){console.warn('THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.');forceClear=arguments[3];}if(camera!==undefined&&camera.isCamera!==true){console.error('THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.');return;}if(_isContextLost===true)return;// reset caching for this frame
  925. bindingStates.resetDefaultState();_currentMaterialId=-1;_currentCamera=null;// update scene graph
  926. if(scene.autoUpdate===true)scene.updateMatrixWorld();// update camera matrices and frustum
  927. if(camera.parent===null)camera.updateMatrixWorld();if(xr.enabled===true&&xr.isPresenting===true){camera=xr.getCamera(camera);}//
  928. if(scene.isScene===true)scene.onBeforeRender(_this,scene,camera,renderTarget||_currentRenderTarget);currentRenderState=renderStates.get(scene,renderStateStack.length);currentRenderState.init();renderStateStack.push(currentRenderState);_projScreenMatrix.multiplyMatrices(camera.projectionMatrix,camera.matrixWorldInverse);_frustum.setFromProjectionMatrix(_projScreenMatrix);_localClippingEnabled=this.localClippingEnabled;_clippingEnabled=clipping.init(this.clippingPlanes,_localClippingEnabled,camera);currentRenderList=renderLists.get(scene,camera);currentRenderList.init();projectObject(scene,camera,0,_this.sortObjects);currentRenderList.finish();if(_this.sortObjects===true){currentRenderList.sort(_opaqueSort,_transparentSort);}//
  929. if(_clippingEnabled===true)clipping.beginShadows();var shadowsArray=currentRenderState.state.shadowsArray;shadowMap.render(shadowsArray,scene,camera);currentRenderState.setupLights();currentRenderState.setupLightsView(camera);if(_clippingEnabled===true)clipping.endShadows();//
  930. if(this.info.autoReset===true)this.info.reset();if(renderTarget!==undefined){this.setRenderTarget(renderTarget);}//
  931. background.render(currentRenderList,scene,camera,forceClear);// render scene
  932. var opaqueObjects=currentRenderList.opaque;var transparentObjects=currentRenderList.transparent;if(opaqueObjects.length>0)renderObjects(opaqueObjects,scene,camera);if(transparentObjects.length>0)renderObjects(transparentObjects,scene,camera);//
  933. if(scene.isScene===true)scene.onAfterRender(_this,scene,camera);//
  934. if(_currentRenderTarget!==null){// Generate mipmap if we're using any kind of mipmap filtering
  935. textures.updateRenderTargetMipmap(_currentRenderTarget);// resolve multisample renderbuffers to a single-sample texture if necessary
  936. textures.updateMultisampleRenderTarget(_currentRenderTarget);}// Ensure depth buffer writing is enabled so it can be cleared on next render
  937. state.buffers.depth.setTest(true);state.buffers.depth.setMask(true);state.buffers.color.setMask(true);state.setPolygonOffset(false);// _gl.finish();
  938. renderStateStack.pop();if(renderStateStack.length>0){currentRenderState=renderStateStack[renderStateStack.length-1];}else {currentRenderState=null;}currentRenderList=null;};function projectObject(object,camera,groupOrder,sortObjects){if(object.visible===false)return;var visible=object.layers.test(camera.layers);if(visible){if(object.isGroup){groupOrder=object.renderOrder;}else if(object.isLOD){if(object.autoUpdate===true)object.update(camera);}else if(object.isLight){currentRenderState.pushLight(object);if(object.castShadow){currentRenderState.pushShadow(object);}}else if(object.isSprite){if(!object.frustumCulled||_frustum.intersectsSprite(object)){if(sortObjects){_vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);}var geometry=objects.update(object);var material=object.material;if(material.visible){currentRenderList.push(object,geometry,material,groupOrder,_vector3.z,null);}}}else if(object.isImmediateRenderObject){if(sortObjects){_vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);}currentRenderList.push(object,null,object.material,groupOrder,_vector3.z,null);}else if(object.isMesh||object.isLine||object.isPoints){if(object.isSkinnedMesh){// update skeleton only once in a frame
  939. if(object.skeleton.frame!==info.render.frame){object.skeleton.update();object.skeleton.frame=info.render.frame;}}if(!object.frustumCulled||_frustum.intersectsObject(object)){if(sortObjects){_vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);}var _geometry2=objects.update(object);var _material=object.material;if(Array.isArray(_material)){var groups=_geometry2.groups;for(var _i126=0,l=groups.length;_i126<l;_i126++){var group=groups[_i126];var groupMaterial=_material[group.materialIndex];if(groupMaterial&&groupMaterial.visible){currentRenderList.push(object,_geometry2,groupMaterial,groupOrder,_vector3.z,group);}}}else if(_material.visible){currentRenderList.push(object,_geometry2,_material,groupOrder,_vector3.z,null);}}}}var children=object.children;for(var _i127=0,_l5=children.length;_i127<_l5;_i127++){projectObject(children[_i127],camera,groupOrder,sortObjects);}}function renderObjects(renderList,scene,camera){var overrideMaterial=scene.isScene===true?scene.overrideMaterial:null;for(var _i128=0,l=renderList.length;_i128<l;_i128++){var renderItem=renderList[_i128];var object=renderItem.object;var geometry=renderItem.geometry;var material=overrideMaterial===null?renderItem.material:overrideMaterial;var group=renderItem.group;if(camera.isArrayCamera){var cameras=camera.cameras;for(var j=0,jl=cameras.length;j<jl;j++){var camera2=cameras[j];if(object.layers.test(camera2.layers)){state.viewport(_currentViewport.copy(camera2.viewport));currentRenderState.setupLightsView(camera2);renderObject(object,scene,camera2,geometry,material,group);}}}else {renderObject(object,scene,camera,geometry,material,group);}}}function renderObject(object,scene,camera,geometry,material,group){object.onBeforeRender(_this,scene,camera,geometry,material,group);object.modelViewMatrix.multiplyMatrices(camera.matrixWorldInverse,object.matrixWorld);object.normalMatrix.getNormalMatrix(object.modelViewMatrix);if(object.isImmediateRenderObject){var program=setProgram(camera,scene,material,object);state.setMaterial(material);bindingStates.reset();renderObjectImmediate(object,program);}else {_this.renderBufferDirect(camera,scene,geometry,material,object,group);}object.onAfterRender(_this,scene,camera,geometry,material,group);}function initMaterial(material,scene,object){if(scene.isScene!==true)scene=_emptyScene;// scene could be a Mesh, Line, Points, ...
  940. var materialProperties=properties.get(material);var lights=currentRenderState.state.lights;var shadowsArray=currentRenderState.state.shadowsArray;var lightsStateVersion=lights.state.version;var parameters=programCache.getParameters(material,lights.state,shadowsArray,scene,object);var programCacheKey=programCache.getProgramCacheKey(parameters);var program=materialProperties.program;var programChange=true;if(program===undefined){// new material
  941. material.addEventListener('dispose',onMaterialDispose);}else if(program.cacheKey!==programCacheKey){// changed glsl or parameters
  942. releaseMaterialProgramReference(material);}else if(materialProperties.lightsStateVersion!==lightsStateVersion){programChange=false;}else if(parameters.shaderID!==undefined){// same glsl and uniform list, envMap still needs the update here to avoid a frame-late effect
  943. var environment=material.isMeshStandardMaterial?scene.environment:null;materialProperties.envMap=cubemaps.get(material.envMap||environment);return;}else {// only rebuild uniform list
  944. programChange=false;}if(programChange){parameters.uniforms=programCache.getUniforms(material);material.onBeforeCompile(parameters,_this);program=programCache.acquireProgram(parameters,programCacheKey);materialProperties.program=program;materialProperties.uniforms=parameters.uniforms;materialProperties.outputEncoding=parameters.outputEncoding;}var uniforms=materialProperties.uniforms;if(!material.isShaderMaterial&&!material.isRawShaderMaterial||material.clipping===true){materialProperties.numClippingPlanes=clipping.numPlanes;materialProperties.numIntersection=clipping.numIntersection;uniforms.clippingPlanes=clipping.uniform;}materialProperties.environment=material.isMeshStandardMaterial?scene.environment:null;materialProperties.fog=scene.fog;materialProperties.envMap=cubemaps.get(material.envMap||materialProperties.environment);// store the light setup it was created for
  945. materialProperties.needsLights=materialNeedsLights(material);materialProperties.lightsStateVersion=lightsStateVersion;if(materialProperties.needsLights){// wire up the material to this renderer's lighting state
  946. uniforms.ambientLightColor.value=lights.state.ambient;uniforms.lightProbe.value=lights.state.probe;uniforms.directionalLights.value=lights.state.directional;uniforms.directionalLightShadows.value=lights.state.directionalShadow;uniforms.spotLights.value=lights.state.spot;uniforms.spotLightShadows.value=lights.state.spotShadow;uniforms.rectAreaLights.value=lights.state.rectArea;uniforms.ltc_1.value=lights.state.rectAreaLTC1;uniforms.ltc_2.value=lights.state.rectAreaLTC2;uniforms.pointLights.value=lights.state.point;uniforms.pointLightShadows.value=lights.state.pointShadow;uniforms.hemisphereLights.value=lights.state.hemi;uniforms.directionalShadowMap.value=lights.state.directionalShadowMap;uniforms.directionalShadowMatrix.value=lights.state.directionalShadowMatrix;uniforms.spotShadowMap.value=lights.state.spotShadowMap;uniforms.spotShadowMatrix.value=lights.state.spotShadowMatrix;uniforms.pointShadowMap.value=lights.state.pointShadowMap;uniforms.pointShadowMatrix.value=lights.state.pointShadowMatrix;// TODO (abelnation): add area lights shadow info to uniforms
  947. }var progUniforms=materialProperties.program.getUniforms();var uniformsList=WebGLUniforms.seqWithValue(progUniforms.seq,uniforms);materialProperties.uniformsList=uniformsList;}function setProgram(camera,scene,material,object){if(scene.isScene!==true)scene=_emptyScene;// scene could be a Mesh, Line, Points, ...
  948. textures.resetTextureUnits();var fog=scene.fog;var environment=material.isMeshStandardMaterial?scene.environment:null;var encoding=_currentRenderTarget===null?_this.outputEncoding:_currentRenderTarget.texture.encoding;var envMap=cubemaps.get(material.envMap||environment);var materialProperties=properties.get(material);var lights=currentRenderState.state.lights;if(_clippingEnabled===true){if(_localClippingEnabled===true||camera!==_currentCamera){var useCache=camera===_currentCamera&&material.id===_currentMaterialId;// we might want to call this function with some ClippingGroup
  949. // object instead of the material, once it becomes feasible
  950. // (#8465, #8379)
  951. clipping.setState(material,camera,useCache);}}if(material.version===materialProperties.__version){if(material.fog&&materialProperties.fog!==fog){initMaterial(material,scene,object);}else if(materialProperties.environment!==environment){initMaterial(material,scene,object);}else if(materialProperties.needsLights&&materialProperties.lightsStateVersion!==lights.state.version){initMaterial(material,scene,object);}else if(materialProperties.numClippingPlanes!==undefined&&(materialProperties.numClippingPlanes!==clipping.numPlanes||materialProperties.numIntersection!==clipping.numIntersection)){initMaterial(material,scene,object);}else if(materialProperties.outputEncoding!==encoding){initMaterial(material,scene,object);}else if(materialProperties.envMap!==envMap){initMaterial(material,scene,object);}}else {initMaterial(material,scene,object);materialProperties.__version=material.version;}var refreshProgram=false;var refreshMaterial=false;var refreshLights=false;var program=materialProperties.program,p_uniforms=program.getUniforms(),m_uniforms=materialProperties.uniforms;if(state.useProgram(program.program)){refreshProgram=true;refreshMaterial=true;refreshLights=true;}if(material.id!==_currentMaterialId){_currentMaterialId=material.id;refreshMaterial=true;}if(refreshProgram||_currentCamera!==camera){p_uniforms.setValue(_gl,'projectionMatrix',camera.projectionMatrix);if(capabilities.logarithmicDepthBuffer){p_uniforms.setValue(_gl,'logDepthBufFC',2.0/(Math.log(camera.far+1.0)/Math.LN2));}if(_currentCamera!==camera){_currentCamera=camera;// lighting uniforms depend on the camera so enforce an update
  952. // now, in case this material supports lights - or later, when
  953. // the next material that does gets activated:
  954. refreshMaterial=true;// set to true on material change
  955. refreshLights=true;// remains set until update done
  956. }// load material specific uniforms
  957. // (shader material also gets them for the sake of genericity)
  958. if(material.isShaderMaterial||material.isMeshPhongMaterial||material.isMeshToonMaterial||material.isMeshStandardMaterial||material.envMap){var uCamPos=p_uniforms.map.cameraPosition;if(uCamPos!==undefined){uCamPos.setValue(_gl,_vector3.setFromMatrixPosition(camera.matrixWorld));}}if(material.isMeshPhongMaterial||material.isMeshToonMaterial||material.isMeshLambertMaterial||material.isMeshBasicMaterial||material.isMeshStandardMaterial||material.isShaderMaterial){p_uniforms.setValue(_gl,'isOrthographic',camera.isOrthographicCamera===true);}if(material.isMeshPhongMaterial||material.isMeshToonMaterial||material.isMeshLambertMaterial||material.isMeshBasicMaterial||material.isMeshStandardMaterial||material.isShaderMaterial||material.isShadowMaterial||material.skinning){p_uniforms.setValue(_gl,'viewMatrix',camera.matrixWorldInverse);}}// skinning uniforms must be set even if material didn't change
  959. // auto-setting of texture unit for bone texture must go before other textures
  960. // otherwise textures used for skinning can take over texture units reserved for other material textures
  961. if(material.skinning){p_uniforms.setOptional(_gl,object,'bindMatrix');p_uniforms.setOptional(_gl,object,'bindMatrixInverse');var skeleton=object.skeleton;if(skeleton){var bones=skeleton.bones;if(capabilities.floatVertexTextures){if(skeleton.boneTexture===null){// layout (1 matrix = 4 pixels)
  962. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  963. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  964. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  965. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  966. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  967. var size=Math.sqrt(bones.length*4);// 4 pixels needed for 1 matrix
  968. size=MathUtils.ceilPowerOfTwo(size);size=Math.max(size,4);var boneMatrices=new Float32Array(size*size*4);// 4 floats per RGBA pixel
  969. boneMatrices.set(skeleton.boneMatrices);// copy current values
  970. var boneTexture=new DataTexture(boneMatrices,size,size,RGBAFormat,FloatType);skeleton.boneMatrices=boneMatrices;skeleton.boneTexture=boneTexture;skeleton.boneTextureSize=size;}p_uniforms.setValue(_gl,'boneTexture',skeleton.boneTexture,textures);p_uniforms.setValue(_gl,'boneTextureSize',skeleton.boneTextureSize);}else {p_uniforms.setOptional(_gl,skeleton,'boneMatrices');}}}if(refreshMaterial||materialProperties.receiveShadow!==object.receiveShadow){materialProperties.receiveShadow=object.receiveShadow;p_uniforms.setValue(_gl,'receiveShadow',object.receiveShadow);}if(refreshMaterial){p_uniforms.setValue(_gl,'toneMappingExposure',_this.toneMappingExposure);if(materialProperties.needsLights){// the current material requires lighting info
  971. // note: all lighting uniforms are always set correctly
  972. // they simply reference the renderer's state for their
  973. // values
  974. //
  975. // use the current material's .needsUpdate flags to set
  976. // the GL state when required
  977. markUniformsLightsNeedsUpdate(m_uniforms,refreshLights);}// refresh uniforms common to several materials
  978. if(fog&&material.fog){materials.refreshFogUniforms(m_uniforms,fog);}materials.refreshMaterialUniforms(m_uniforms,material,_pixelRatio,_height);WebGLUniforms.upload(_gl,materialProperties.uniformsList,m_uniforms,textures);}if(material.isShaderMaterial&&material.uniformsNeedUpdate===true){WebGLUniforms.upload(_gl,materialProperties.uniformsList,m_uniforms,textures);material.uniformsNeedUpdate=false;}if(material.isSpriteMaterial){p_uniforms.setValue(_gl,'center',object.center);}// common matrices
  979. p_uniforms.setValue(_gl,'modelViewMatrix',object.modelViewMatrix);p_uniforms.setValue(_gl,'normalMatrix',object.normalMatrix);p_uniforms.setValue(_gl,'modelMatrix',object.matrixWorld);return program;}// If uniforms are marked as clean, they don't need to be loaded to the GPU.
  980. function markUniformsLightsNeedsUpdate(uniforms,value){uniforms.ambientLightColor.needsUpdate=value;uniforms.lightProbe.needsUpdate=value;uniforms.directionalLights.needsUpdate=value;uniforms.directionalLightShadows.needsUpdate=value;uniforms.pointLights.needsUpdate=value;uniforms.pointLightShadows.needsUpdate=value;uniforms.spotLights.needsUpdate=value;uniforms.spotLightShadows.needsUpdate=value;uniforms.rectAreaLights.needsUpdate=value;uniforms.hemisphereLights.needsUpdate=value;}function materialNeedsLights(material){return material.isMeshLambertMaterial||material.isMeshToonMaterial||material.isMeshPhongMaterial||material.isMeshStandardMaterial||material.isShadowMaterial||material.isShaderMaterial&&material.lights===true;}//
  981. this.setFramebuffer=function(value){if(_framebuffer!==value&&_currentRenderTarget===null)_gl.bindFramebuffer(36160,value);_framebuffer=value;};this.getActiveCubeFace=function(){return _currentActiveCubeFace;};this.getActiveMipmapLevel=function(){return _currentActiveMipmapLevel;};this.getRenderList=function(){return currentRenderList;};this.setRenderList=function(renderList){currentRenderList=renderList;};this.getRenderTarget=function(){return _currentRenderTarget;};this.setRenderTarget=function(renderTarget){var activeCubeFace=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var activeMipmapLevel=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0;_currentRenderTarget=renderTarget;_currentActiveCubeFace=activeCubeFace;_currentActiveMipmapLevel=activeMipmapLevel;if(renderTarget&&properties.get(renderTarget).__webglFramebuffer===undefined){textures.setupRenderTarget(renderTarget);}var framebuffer=_framebuffer;var isCube=false;if(renderTarget){var __webglFramebuffer=properties.get(renderTarget).__webglFramebuffer;if(renderTarget.isWebGLCubeRenderTarget){framebuffer=__webglFramebuffer[activeCubeFace];isCube=true;}else if(renderTarget.isWebGLMultisampleRenderTarget){framebuffer=properties.get(renderTarget).__webglMultisampledFramebuffer;}else {framebuffer=__webglFramebuffer;}_currentViewport.copy(renderTarget.viewport);_currentScissor.copy(renderTarget.scissor);_currentScissorTest=renderTarget.scissorTest;}else {_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor();_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor();_currentScissorTest=_scissorTest;}if(_currentFramebuffer!==framebuffer){_gl.bindFramebuffer(36160,framebuffer);_currentFramebuffer=framebuffer;}state.viewport(_currentViewport);state.scissor(_currentScissor);state.setScissorTest(_currentScissorTest);if(isCube){var textureProperties=properties.get(renderTarget.texture);_gl.framebufferTexture2D(36160,36064,34069+activeCubeFace,textureProperties.__webglTexture,activeMipmapLevel);}};this.readRenderTargetPixels=function(renderTarget,x,y,width,height,buffer,activeCubeFaceIndex){if(!(renderTarget&&renderTarget.isWebGLRenderTarget)){console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.');return;}var framebuffer=properties.get(renderTarget).__webglFramebuffer;if(renderTarget.isWebGLCubeRenderTarget&&activeCubeFaceIndex!==undefined){framebuffer=framebuffer[activeCubeFaceIndex];}if(framebuffer){var restore=false;if(framebuffer!==_currentFramebuffer){_gl.bindFramebuffer(36160,framebuffer);restore=true;}try{var texture=renderTarget.texture;var textureFormat=texture.format;var textureType=texture.type;if(textureFormat!==RGBAFormat&&utils.convert(textureFormat)!==_gl.getParameter(35739)){console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.');return;}if(textureType!==UnsignedByteType&&utils.convert(textureType)!==_gl.getParameter(35738)&&// IE11, Edge and Chrome Mac < 52 (#9513)
  982. !(textureType===FloatType&&(capabilities.isWebGL2||extensions.get('OES_texture_float')||extensions.get('WEBGL_color_buffer_float')))&&// Chrome Mac >= 52 and Firefox
  983. !(textureType===HalfFloatType&&(capabilities.isWebGL2?extensions.get('EXT_color_buffer_float'):extensions.get('EXT_color_buffer_half_float')))){console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.');return;}if(_gl.checkFramebufferStatus(36160)===36053){// the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  984. if(x>=0&&x<=renderTarget.width-width&&y>=0&&y<=renderTarget.height-height){_gl.readPixels(x,y,width,height,utils.convert(textureFormat),utils.convert(textureType),buffer);}}else {console.error('THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.');}}finally{if(restore){_gl.bindFramebuffer(36160,_currentFramebuffer);}}}};this.copyFramebufferToTexture=function(position,texture){var level=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0;var levelScale=Math.pow(2,-level);var width=Math.floor(texture.image.width*levelScale);var height=Math.floor(texture.image.height*levelScale);var glFormat=utils.convert(texture.format);textures.setTexture2D(texture,0);_gl.copyTexImage2D(3553,level,glFormat,position.x,position.y,width,height,0);state.unbindTexture();};this.copyTextureToTexture=function(position,srcTexture,dstTexture){var level=arguments.length>3&&arguments[3]!==undefined?arguments[3]:0;var width=srcTexture.image.width;var height=srcTexture.image.height;var glFormat=utils.convert(dstTexture.format);var glType=utils.convert(dstTexture.type);textures.setTexture2D(dstTexture,0);// As another texture upload may have changed pixelStorei
  985. // parameters, make sure they are correct for the dstTexture
  986. _gl.pixelStorei(37440,dstTexture.flipY);_gl.pixelStorei(37441,dstTexture.premultiplyAlpha);_gl.pixelStorei(3317,dstTexture.unpackAlignment);if(srcTexture.isDataTexture){_gl.texSubImage2D(3553,level,position.x,position.y,width,height,glFormat,glType,srcTexture.image.data);}else {if(srcTexture.isCompressedTexture){_gl.compressedTexSubImage2D(3553,level,position.x,position.y,srcTexture.mipmaps[0].width,srcTexture.mipmaps[0].height,glFormat,srcTexture.mipmaps[0].data);}else {_gl.texSubImage2D(3553,level,position.x,position.y,glFormat,glType,srcTexture.image);}}// Generate mipmaps only when copying level 0
  987. if(level===0&&dstTexture.generateMipmaps)_gl.generateMipmap(3553);state.unbindTexture();};this.initTexture=function(texture){textures.setTexture2D(texture,0);state.unbindTexture();};this.resetState=function(){state.reset();bindingStates.reset();};if(typeof __THREE_DEVTOOLS__!=='undefined'){__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe',{detail:this}));// eslint-disable-line no-undef
  988. }}function WebGL1Renderer(parameters){WebGLRenderer.call(this,parameters);}WebGL1Renderer.prototype=Object.assign(Object.create(WebGLRenderer.prototype),{constructor:WebGL1Renderer,isWebGL1Renderer:true});class FogExp2{constructor(color,density){Object.defineProperty(this,'isFogExp2',{value:true});this.name='';this.color=new Color(color);this.density=density!==undefined?density:0.00025;}clone(){return new FogExp2(this.color,this.density);}toJSON(/* meta */){return {type:'FogExp2',color:this.color.getHex(),density:this.density};}}class Fog{constructor(color,near,far){Object.defineProperty(this,'isFog',{value:true});this.name='';this.color=new Color(color);this.near=near!==undefined?near:1;this.far=far!==undefined?far:1000;}clone(){return new Fog(this.color,this.near,this.far);}toJSON(/* meta */){return {type:'Fog',color:this.color.getHex(),near:this.near,far:this.far};}}class Scene extends Object3D{constructor(){super();Object.defineProperty(this,'isScene',{value:true});this.type='Scene';this.background=null;this.environment=null;this.fog=null;this.overrideMaterial=null;this.autoUpdate=true;// checked by the renderer
  989. if(typeof __THREE_DEVTOOLS__!=='undefined'){__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe',{detail:this}));// eslint-disable-line no-undef
  990. }}copy(source,recursive){super.copy(source,recursive);if(source.background!==null)this.background=source.background.clone();if(source.environment!==null)this.environment=source.environment.clone();if(source.fog!==null)this.fog=source.fog.clone();if(source.overrideMaterial!==null)this.overrideMaterial=source.overrideMaterial.clone();this.autoUpdate=source.autoUpdate;this.matrixAutoUpdate=source.matrixAutoUpdate;return this;}toJSON(meta){var data=super.toJSON(meta);if(this.background!==null)data.object.background=this.background.toJSON(meta);if(this.environment!==null)data.object.environment=this.environment.toJSON(meta);if(this.fog!==null)data.object.fog=this.fog.toJSON();return data;}}function InterleavedBuffer(array,stride){this.array=array;this.stride=stride;this.count=array!==undefined?array.length/stride:0;this.usage=StaticDrawUsage;this.updateRange={offset:0,count:-1};this.version=0;this.uuid=MathUtils.generateUUID();}Object.defineProperty(InterleavedBuffer.prototype,'needsUpdate',{set:function set(value){if(value===true)this.version++;}});Object.assign(InterleavedBuffer.prototype,{isInterleavedBuffer:true,onUploadCallback:function onUploadCallback(){},setUsage:function setUsage(value){this.usage=value;return this;},copy:function copy(source){this.array=new source.array.constructor(source.array);this.count=source.count;this.stride=source.stride;this.usage=source.usage;return this;},copyAt:function copyAt(index1,attribute,index2){index1*=this.stride;index2*=attribute.stride;for(var _i129=0,l=this.stride;_i129<l;_i129++){this.array[index1+_i129]=attribute.array[index2+_i129];}return this;},set:function set(value){var offset=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;this.array.set(value,offset);return this;},clone:function clone(data){if(data.arrayBuffers===undefined){data.arrayBuffers={};}if(this.array.buffer._uuid===undefined){this.array.buffer._uuid=MathUtils.generateUUID();}if(data.arrayBuffers[this.array.buffer._uuid]===undefined){data.arrayBuffers[this.array.buffer._uuid]=this.array.slice(0).buffer;}var array=new this.array.constructor(data.arrayBuffers[this.array.buffer._uuid]);var ib=new InterleavedBuffer(array,this.stride);ib.setUsage(this.usage);return ib;},onUpload:function onUpload(callback){this.onUploadCallback=callback;return this;},toJSON:function toJSON(data){if(data.arrayBuffers===undefined){data.arrayBuffers={};}// generate UUID for array buffer if necessary
  991. if(this.array.buffer._uuid===undefined){this.array.buffer._uuid=MathUtils.generateUUID();}if(data.arrayBuffers[this.array.buffer._uuid]===undefined){data.arrayBuffers[this.array.buffer._uuid]=Array.prototype.slice.call(new Uint32Array(this.array.buffer));}//
  992. return {uuid:this.uuid,buffer:this.array.buffer._uuid,type:this.array.constructor.name,stride:this.stride};}});var _vector$6=new Vector3();function InterleavedBufferAttribute(interleavedBuffer,itemSize,offset,normalized){this.name='';this.data=interleavedBuffer;this.itemSize=itemSize;this.offset=offset;this.normalized=normalized===true;}Object.defineProperties(InterleavedBufferAttribute.prototype,{count:{get:function get(){return this.data.count;}},array:{get:function get(){return this.data.array;}},needsUpdate:{set:function set(value){this.data.needsUpdate=value;}}});Object.assign(InterleavedBufferAttribute.prototype,{isInterleavedBufferAttribute:true,applyMatrix4:function applyMatrix4(m){for(var _i130=0,l=this.data.count;_i130<l;_i130++){_vector$6.x=this.getX(_i130);_vector$6.y=this.getY(_i130);_vector$6.z=this.getZ(_i130);_vector$6.applyMatrix4(m);this.setXYZ(_i130,_vector$6.x,_vector$6.y,_vector$6.z);}return this;},setX:function setX(index,x){this.data.array[index*this.data.stride+this.offset]=x;return this;},setY:function setY(index,y){this.data.array[index*this.data.stride+this.offset+1]=y;return this;},setZ:function setZ(index,z){this.data.array[index*this.data.stride+this.offset+2]=z;return this;},setW:function setW(index,w){this.data.array[index*this.data.stride+this.offset+3]=w;return this;},getX:function getX(index){return this.data.array[index*this.data.stride+this.offset];},getY:function getY(index){return this.data.array[index*this.data.stride+this.offset+1];},getZ:function getZ(index){return this.data.array[index*this.data.stride+this.offset+2];},getW:function getW(index){return this.data.array[index*this.data.stride+this.offset+3];},setXY:function setXY(index,x,y){index=index*this.data.stride+this.offset;this.data.array[index+0]=x;this.data.array[index+1]=y;return this;},setXYZ:function setXYZ(index,x,y,z){index=index*this.data.stride+this.offset;this.data.array[index+0]=x;this.data.array[index+1]=y;this.data.array[index+2]=z;return this;},setXYZW:function setXYZW(index,x,y,z,w){index=index*this.data.stride+this.offset;this.data.array[index+0]=x;this.data.array[index+1]=y;this.data.array[index+2]=z;this.data.array[index+3]=w;return this;},clone:function clone(data){if(data===undefined){console.log('THREE.InterleavedBufferAttribute.clone(): Cloning an interlaved buffer attribute will deinterleave buffer data.');var array=[];for(var _i131=0;_i131<this.count;_i131++){var index=_i131*this.data.stride+this.offset;for(var j=0;j<this.itemSize;j++){array.push(this.data.array[index+j]);}}return new BufferAttribute(new this.array.constructor(array),this.itemSize,this.normalized);}else {if(data.interleavedBuffers===undefined){data.interleavedBuffers={};}if(data.interleavedBuffers[this.data.uuid]===undefined){data.interleavedBuffers[this.data.uuid]=this.data.clone(data);}return new InterleavedBufferAttribute(data.interleavedBuffers[this.data.uuid],this.itemSize,this.offset,this.normalized);}},toJSON:function toJSON(data){if(data===undefined){console.log('THREE.InterleavedBufferAttribute.toJSON(): Serializing an interlaved buffer attribute will deinterleave buffer data.');var array=[];for(var _i132=0;_i132<this.count;_i132++){var index=_i132*this.data.stride+this.offset;for(var j=0;j<this.itemSize;j++){array.push(this.data.array[index+j]);}}// deinterleave data and save it as an ordinary buffer attribute for now
  993. return {itemSize:this.itemSize,type:this.array.constructor.name,array:array,normalized:this.normalized};}else {// save as true interlaved attribtue
  994. if(data.interleavedBuffers===undefined){data.interleavedBuffers={};}if(data.interleavedBuffers[this.data.uuid]===undefined){data.interleavedBuffers[this.data.uuid]=this.data.toJSON(data);}return {isInterleavedBufferAttribute:true,itemSize:this.itemSize,data:this.data.uuid,offset:this.offset,normalized:this.normalized};}}});/**
  995. * parameters = {
  996. * color: <hex>,
  997. * map: new THREE.Texture( <Image> ),
  998. * alphaMap: new THREE.Texture( <Image> ),
  999. * rotation: <float>,
  1000. * sizeAttenuation: <bool>
  1001. * }
  1002. */function SpriteMaterial(parameters){Material.call(this);this.type='SpriteMaterial';this.color=new Color(0xffffff);this.map=null;this.alphaMap=null;this.rotation=0;this.sizeAttenuation=true;this.transparent=true;this.setValues(parameters);}SpriteMaterial.prototype=Object.create(Material.prototype);SpriteMaterial.prototype.constructor=SpriteMaterial;SpriteMaterial.prototype.isSpriteMaterial=true;SpriteMaterial.prototype.copy=function(source){Material.prototype.copy.call(this,source);this.color.copy(source.color);this.map=source.map;this.alphaMap=source.alphaMap;this.rotation=source.rotation;this.sizeAttenuation=source.sizeAttenuation;return this;};var _geometry;var _intersectPoint=new Vector3();var _worldScale=new Vector3();var _mvPosition=new Vector3();var _alignedPosition=new Vector2();var _rotatedPosition=new Vector2();var _viewWorldMatrix=new Matrix4();var _vA$1=new Vector3();var _vB$1=new Vector3();var _vC$1=new Vector3();var _uvA$1=new Vector2();var _uvB$1=new Vector2();var _uvC$1=new Vector2();function Sprite$1(material){Object3D.call(this);this.type='Sprite';if(_geometry===undefined){_geometry=new BufferGeometry();var float32Array=new Float32Array([-0.5,-0.5,0,0,0,0.5,-0.5,0,1,0,0.5,0.5,0,1,1,-0.5,0.5,0,0,1]);var interleavedBuffer=new InterleavedBuffer(float32Array,5);_geometry.setIndex([0,1,2,0,2,3]);_geometry.setAttribute('position',new InterleavedBufferAttribute(interleavedBuffer,3,0,false));_geometry.setAttribute('uv',new InterleavedBufferAttribute(interleavedBuffer,2,3,false));}this.geometry=_geometry;this.material=material!==undefined?material:new SpriteMaterial();this.center=new Vector2(0.5,0.5);}Sprite$1.prototype=Object.assign(Object.create(Object3D.prototype),{constructor:Sprite$1,isSprite:true,raycast:function raycast(raycaster,intersects){if(raycaster.camera===null){console.error('THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.');}_worldScale.setFromMatrixScale(this.matrixWorld);_viewWorldMatrix.copy(raycaster.camera.matrixWorld);this.modelViewMatrix.multiplyMatrices(raycaster.camera.matrixWorldInverse,this.matrixWorld);_mvPosition.setFromMatrixPosition(this.modelViewMatrix);if(raycaster.camera.isPerspectiveCamera&&this.material.sizeAttenuation===false){_worldScale.multiplyScalar(-_mvPosition.z);}var rotation=this.material.rotation;var sin,cos;if(rotation!==0){cos=Math.cos(rotation);sin=Math.sin(rotation);}var center=this.center;transformVertex(_vA$1.set(-0.5,-0.5,0),_mvPosition,center,_worldScale,sin,cos);transformVertex(_vB$1.set(0.5,-0.5,0),_mvPosition,center,_worldScale,sin,cos);transformVertex(_vC$1.set(0.5,0.5,0),_mvPosition,center,_worldScale,sin,cos);_uvA$1.set(0,0);_uvB$1.set(1,0);_uvC$1.set(1,1);// check first triangle
  1003. var intersect=raycaster.ray.intersectTriangle(_vA$1,_vB$1,_vC$1,false,_intersectPoint);if(intersect===null){// check second triangle
  1004. transformVertex(_vB$1.set(-0.5,0.5,0),_mvPosition,center,_worldScale,sin,cos);_uvB$1.set(0,1);intersect=raycaster.ray.intersectTriangle(_vA$1,_vC$1,_vB$1,false,_intersectPoint);if(intersect===null){return;}}var distance=raycaster.ray.origin.distanceTo(_intersectPoint);if(distance<raycaster.near||distance>raycaster.far)return;intersects.push({distance:distance,point:_intersectPoint.clone(),uv:Triangle.getUV(_intersectPoint,_vA$1,_vB$1,_vC$1,_uvA$1,_uvB$1,_uvC$1,new Vector2()),face:null,object:this});},copy:function copy(source){Object3D.prototype.copy.call(this,source);if(source.center!==undefined)this.center.copy(source.center);this.material=source.material;return this;}});function transformVertex(vertexPosition,mvPosition,center,scale,sin,cos){// compute position in camera space
  1005. _alignedPosition.subVectors(vertexPosition,center).addScalar(0.5).multiply(scale);// to check if rotation is not zero
  1006. if(sin!==undefined){_rotatedPosition.x=cos*_alignedPosition.x-sin*_alignedPosition.y;_rotatedPosition.y=sin*_alignedPosition.x+cos*_alignedPosition.y;}else {_rotatedPosition.copy(_alignedPosition);}vertexPosition.copy(mvPosition);vertexPosition.x+=_rotatedPosition.x;vertexPosition.y+=_rotatedPosition.y;// transform to world space
  1007. vertexPosition.applyMatrix4(_viewWorldMatrix);}var _v1$4=new Vector3();var _v2$2=new Vector3();function LOD(){Object3D.call(this);this._currentLevel=0;this.type='LOD';Object.defineProperties(this,{levels:{enumerable:true,value:[]}});this.autoUpdate=true;}LOD.prototype=Object.assign(Object.create(Object3D.prototype),{constructor:LOD,isLOD:true,copy:function copy(source){Object3D.prototype.copy.call(this,source,false);var levels=source.levels;for(var _i133=0,l=levels.length;_i133<l;_i133++){var level=levels[_i133];this.addLevel(level.object.clone(),level.distance);}this.autoUpdate=source.autoUpdate;return this;},addLevel:function addLevel(object){var distance=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;distance=Math.abs(distance);var levels=this.levels;var l;for(l=0;l<levels.length;l++){if(distance<levels[l].distance){break;}}levels.splice(l,0,{distance:distance,object:object});this.add(object);return this;},getCurrentLevel:function getCurrentLevel(){return this._currentLevel;},getObjectForDistance:function getObjectForDistance(distance){var levels=this.levels;if(levels.length>0){var _i134,l;for(_i134=1,l=levels.length;_i134<l;_i134++){if(distance<levels[_i134].distance){break;}}return levels[_i134-1].object;}return null;},raycast:function raycast(raycaster,intersects){var levels=this.levels;if(levels.length>0){_v1$4.setFromMatrixPosition(this.matrixWorld);var distance=raycaster.ray.origin.distanceTo(_v1$4);this.getObjectForDistance(distance).raycast(raycaster,intersects);}},update:function update(camera){var levels=this.levels;if(levels.length>1){_v1$4.setFromMatrixPosition(camera.matrixWorld);_v2$2.setFromMatrixPosition(this.matrixWorld);var distance=_v1$4.distanceTo(_v2$2)/camera.zoom;levels[0].object.visible=true;var _i135,l;for(_i135=1,l=levels.length;_i135<l;_i135++){if(distance>=levels[_i135].distance){levels[_i135-1].object.visible=false;levels[_i135].object.visible=true;}else {break;}}this._currentLevel=_i135-1;for(;_i135<l;_i135++){levels[_i135].object.visible=false;}}},toJSON:function toJSON(meta){var data=Object3D.prototype.toJSON.call(this,meta);if(this.autoUpdate===false)data.object.autoUpdate=false;data.object.levels=[];var levels=this.levels;for(var _i136=0,l=levels.length;_i136<l;_i136++){var level=levels[_i136];data.object.levels.push({object:level.object.uuid,distance:level.distance});}return data;}});var _basePosition=new Vector3();var _skinIndex=new Vector4();var _skinWeight=new Vector4();var _vector$7=new Vector3();var _matrix$1=new Matrix4();function SkinnedMesh(geometry,material){if(geometry&&geometry.isGeometry){console.error('THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');}Mesh.call(this,geometry,material);this.type='SkinnedMesh';this.bindMode='attached';this.bindMatrix=new Matrix4();this.bindMatrixInverse=new Matrix4();}SkinnedMesh.prototype=Object.assign(Object.create(Mesh.prototype),{constructor:SkinnedMesh,isSkinnedMesh:true,copy:function copy(source){Mesh.prototype.copy.call(this,source);this.bindMode=source.bindMode;this.bindMatrix.copy(source.bindMatrix);this.bindMatrixInverse.copy(source.bindMatrixInverse);this.skeleton=source.skeleton;return this;},bind:function bind(skeleton,bindMatrix){this.skeleton=skeleton;if(bindMatrix===undefined){this.updateMatrixWorld(true);this.skeleton.calculateInverses();bindMatrix=this.matrixWorld;}this.bindMatrix.copy(bindMatrix);this.bindMatrixInverse.copy(bindMatrix).invert();},pose:function pose(){this.skeleton.pose();},normalizeSkinWeights:function normalizeSkinWeights(){var vector=new Vector4();var skinWeight=this.geometry.attributes.skinWeight;for(var _i137=0,l=skinWeight.count;_i137<l;_i137++){vector.x=skinWeight.getX(_i137);vector.y=skinWeight.getY(_i137);vector.z=skinWeight.getZ(_i137);vector.w=skinWeight.getW(_i137);var scale=1.0/vector.manhattanLength();if(scale!==Infinity){vector.multiplyScalar(scale);}else {vector.set(1,0,0,0);// do something reasonable
  1008. }skinWeight.setXYZW(_i137,vector.x,vector.y,vector.z,vector.w);}},updateMatrixWorld:function updateMatrixWorld(force){Mesh.prototype.updateMatrixWorld.call(this,force);if(this.bindMode==='attached'){this.bindMatrixInverse.copy(this.matrixWorld).invert();}else if(this.bindMode==='detached'){this.bindMatrixInverse.copy(this.bindMatrix).invert();}else {console.warn('THREE.SkinnedMesh: Unrecognized bindMode: '+this.bindMode);}},boneTransform:function boneTransform(index,target){var skeleton=this.skeleton;var geometry=this.geometry;_skinIndex.fromBufferAttribute(geometry.attributes.skinIndex,index);_skinWeight.fromBufferAttribute(geometry.attributes.skinWeight,index);_basePosition.fromBufferAttribute(geometry.attributes.position,index).applyMatrix4(this.bindMatrix);target.set(0,0,0);for(var _i138=0;_i138<4;_i138++){var weight=_skinWeight.getComponent(_i138);if(weight!==0){var boneIndex=_skinIndex.getComponent(_i138);_matrix$1.multiplyMatrices(skeleton.bones[boneIndex].matrixWorld,skeleton.boneInverses[boneIndex]);target.addScaledVector(_vector$7.copy(_basePosition).applyMatrix4(_matrix$1),weight);}}return target.applyMatrix4(this.bindMatrixInverse);}});function Bone(){Object3D.call(this);this.type='Bone';}Bone.prototype=Object.assign(Object.create(Object3D.prototype),{constructor:Bone,isBone:true});var _offsetMatrix=new Matrix4();var _identityMatrix=new Matrix4();function Skeleton(){var bones=arguments.length>0&&arguments[0]!==undefined?arguments[0]:[];var boneInverses=arguments.length>1&&arguments[1]!==undefined?arguments[1]:[];this.uuid=MathUtils.generateUUID();this.bones=bones.slice(0);this.boneInverses=boneInverses;this.boneMatrices=null;this.boneTexture=null;this.boneTextureSize=0;this.frame=-1;this.init();}Object.assign(Skeleton.prototype,{init:function init(){var bones=this.bones;var boneInverses=this.boneInverses;this.boneMatrices=new Float32Array(bones.length*16);// calculate inverse bone matrices if necessary
  1009. if(boneInverses.length===0){this.calculateInverses();}else {// handle special case
  1010. if(bones.length!==boneInverses.length){console.warn('THREE.Skeleton: Number of inverse bone matrices does not match amount of bones.');this.boneInverses=[];for(var _i139=0,il=this.bones.length;_i139<il;_i139++){this.boneInverses.push(new Matrix4());}}}},calculateInverses:function calculateInverses(){this.boneInverses.length=0;for(var _i140=0,il=this.bones.length;_i140<il;_i140++){var inverse=new Matrix4();if(this.bones[_i140]){inverse.copy(this.bones[_i140].matrixWorld).invert();}this.boneInverses.push(inverse);}},pose:function pose(){// recover the bind-time world matrices
  1011. for(var _i141=0,il=this.bones.length;_i141<il;_i141++){var bone=this.bones[_i141];if(bone){bone.matrixWorld.copy(this.boneInverses[_i141]).invert();}}// compute the local matrices, positions, rotations and scales
  1012. for(var _i142=0,_il11=this.bones.length;_i142<_il11;_i142++){var _bone=this.bones[_i142];if(_bone){if(_bone.parent&&_bone.parent.isBone){_bone.matrix.copy(_bone.parent.matrixWorld).invert();_bone.matrix.multiply(_bone.matrixWorld);}else {_bone.matrix.copy(_bone.matrixWorld);}_bone.matrix.decompose(_bone.position,_bone.quaternion,_bone.scale);}}},update:function update(){var bones=this.bones;var boneInverses=this.boneInverses;var boneMatrices=this.boneMatrices;var boneTexture=this.boneTexture;// flatten bone matrices to array
  1013. for(var _i143=0,il=bones.length;_i143<il;_i143++){// compute the offset between the current and the original transform
  1014. var matrix=bones[_i143]?bones[_i143].matrixWorld:_identityMatrix;_offsetMatrix.multiplyMatrices(matrix,boneInverses[_i143]);_offsetMatrix.toArray(boneMatrices,_i143*16);}if(boneTexture!==null){boneTexture.needsUpdate=true;}},clone:function clone(){return new Skeleton(this.bones,this.boneInverses);},getBoneByName:function getBoneByName(name){for(var _i144=0,il=this.bones.length;_i144<il;_i144++){var bone=this.bones[_i144];if(bone.name===name){return bone;}}return undefined;},dispose:function dispose(){if(this.boneTexture!==null){this.boneTexture.dispose();this.boneTexture=null;}},fromJSON:function fromJSON(json,bones){this.uuid=json.uuid;for(var _i145=0,l=json.bones.length;_i145<l;_i145++){var uuid=json.bones[_i145];var bone=bones[uuid];if(bone===undefined){console.warn('THREE.Skeleton: No bone found with UUID:',uuid);bone=new Bone();}this.bones.push(bone);this.boneInverses.push(new Matrix4().fromArray(json.boneInverses[_i145]));}this.init();return this;},toJSON:function toJSON(){var data={metadata:{version:4.5,type:'Skeleton',generator:'Skeleton.toJSON'},bones:[],boneInverses:[]};data.uuid=this.uuid;var bones=this.bones;var boneInverses=this.boneInverses;for(var _i146=0,l=bones.length;_i146<l;_i146++){var bone=bones[_i146];data.bones.push(bone.uuid);var boneInverse=boneInverses[_i146];data.boneInverses.push(boneInverse.toArray());}return data;}});var _instanceLocalMatrix=new Matrix4();var _instanceWorldMatrix=new Matrix4();var _instanceIntersects=[];var _mesh=new Mesh();function InstancedMesh(geometry,material,count){Mesh.call(this,geometry,material);this.instanceMatrix=new BufferAttribute(new Float32Array(count*16),16);this.instanceColor=null;this.count=count;this.frustumCulled=false;}InstancedMesh.prototype=Object.assign(Object.create(Mesh.prototype),{constructor:InstancedMesh,isInstancedMesh:true,copy:function copy(source){Mesh.prototype.copy.call(this,source);this.instanceMatrix.copy(source.instanceMatrix);this.count=source.count;return this;},getColorAt:function getColorAt(index,color){color.fromArray(this.instanceColor.array,index*3);},getMatrixAt:function getMatrixAt(index,matrix){matrix.fromArray(this.instanceMatrix.array,index*16);},raycast:function raycast(raycaster,intersects){var matrixWorld=this.matrixWorld;var raycastTimes=this.count;_mesh.geometry=this.geometry;_mesh.material=this.material;if(_mesh.material===undefined)return;for(var instanceId=0;instanceId<raycastTimes;instanceId++){// calculate the world matrix for each instance
  1015. this.getMatrixAt(instanceId,_instanceLocalMatrix);_instanceWorldMatrix.multiplyMatrices(matrixWorld,_instanceLocalMatrix);// the mesh represents this single instance
  1016. _mesh.matrixWorld=_instanceWorldMatrix;_mesh.raycast(raycaster,_instanceIntersects);// process the result of raycast
  1017. for(var _i147=0,l=_instanceIntersects.length;_i147<l;_i147++){var intersect=_instanceIntersects[_i147];intersect.instanceId=instanceId;intersect.object=this;intersects.push(intersect);}_instanceIntersects.length=0;}},setColorAt:function setColorAt(index,color){if(this.instanceColor===null){this.instanceColor=new BufferAttribute(new Float32Array(this.count*3),3);}color.toArray(this.instanceColor.array,index*3);},setMatrixAt:function setMatrixAt(index,matrix){matrix.toArray(this.instanceMatrix.array,index*16);},updateMorphTargets:function updateMorphTargets(){},dispose:function dispose(){this.dispatchEvent({type:'dispose'});}});/**
  1018. * parameters = {
  1019. * color: <hex>,
  1020. * opacity: <float>,
  1021. *
  1022. * linewidth: <float>,
  1023. * linecap: "round",
  1024. * linejoin: "round"
  1025. * }
  1026. */function LineBasicMaterial(parameters){Material.call(this);this.type='LineBasicMaterial';this.color=new Color(0xffffff);this.linewidth=1;this.linecap='round';this.linejoin='round';this.morphTargets=false;this.setValues(parameters);}LineBasicMaterial.prototype=Object.create(Material.prototype);LineBasicMaterial.prototype.constructor=LineBasicMaterial;LineBasicMaterial.prototype.isLineBasicMaterial=true;LineBasicMaterial.prototype.copy=function(source){Material.prototype.copy.call(this,source);this.color.copy(source.color);this.linewidth=source.linewidth;this.linecap=source.linecap;this.linejoin=source.linejoin;this.morphTargets=source.morphTargets;return this;};var _start=new Vector3();var _end=new Vector3();var _inverseMatrix$1=new Matrix4();var _ray$1=new Ray();var _sphere$2=new Sphere();function Line(){var geometry=arguments.length>0&&arguments[0]!==undefined?arguments[0]:new BufferGeometry();var material=arguments.length>1&&arguments[1]!==undefined?arguments[1]:new LineBasicMaterial();Object3D.call(this);this.type='Line';this.geometry=geometry;this.material=material;this.updateMorphTargets();}Line.prototype=Object.assign(Object.create(Object3D.prototype),{constructor:Line,isLine:true,copy:function copy(source){Object3D.prototype.copy.call(this,source);this.material=source.material;this.geometry=source.geometry;return this;},computeLineDistances:function computeLineDistances(){var geometry=this.geometry;if(geometry.isBufferGeometry){// we assume non-indexed geometry
  1027. if(geometry.index===null){var positionAttribute=geometry.attributes.position;var lineDistances=[0];for(var _i148=1,l=positionAttribute.count;_i148<l;_i148++){_start.fromBufferAttribute(positionAttribute,_i148-1);_end.fromBufferAttribute(positionAttribute,_i148);lineDistances[_i148]=lineDistances[_i148-1];lineDistances[_i148]+=_start.distanceTo(_end);}geometry.setAttribute('lineDistance',new Float32BufferAttribute(lineDistances,1));}else {console.warn('THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');}}else if(geometry.isGeometry){var vertices=geometry.vertices;var _lineDistances=geometry.lineDistances;_lineDistances[0]=0;for(var _i149=1,_l6=vertices.length;_i149<_l6;_i149++){_lineDistances[_i149]=_lineDistances[_i149-1];_lineDistances[_i149]+=vertices[_i149-1].distanceTo(vertices[_i149]);}}return this;},raycast:function raycast(raycaster,intersects){var geometry=this.geometry;var matrixWorld=this.matrixWorld;var threshold=raycaster.params.Line.threshold;// Checking boundingSphere distance to ray
  1028. if(geometry.boundingSphere===null)geometry.computeBoundingSphere();_sphere$2.copy(geometry.boundingSphere);_sphere$2.applyMatrix4(matrixWorld);_sphere$2.radius+=threshold;if(raycaster.ray.intersectsSphere(_sphere$2)===false)return;//
  1029. _inverseMatrix$1.copy(matrixWorld).invert();_ray$1.copy(raycaster.ray).applyMatrix4(_inverseMatrix$1);var localThreshold=threshold/((this.scale.x+this.scale.y+this.scale.z)/3);var localThresholdSq=localThreshold*localThreshold;var vStart=new Vector3();var vEnd=new Vector3();var interSegment=new Vector3();var interRay=new Vector3();var step=this.isLineSegments?2:1;if(geometry.isBufferGeometry){var index=geometry.index;var attributes=geometry.attributes;var positionAttribute=attributes.position;if(index!==null){var indices=index.array;for(var _i150=0,l=indices.length-1;_i150<l;_i150+=step){var a=indices[_i150];var b=indices[_i150+1];vStart.fromBufferAttribute(positionAttribute,a);vEnd.fromBufferAttribute(positionAttribute,b);var distSq=_ray$1.distanceSqToSegment(vStart,vEnd,interRay,interSegment);if(distSq>localThresholdSq)continue;interRay.applyMatrix4(this.matrixWorld);//Move back to world space for distance calculation
  1030. var distance=raycaster.ray.origin.distanceTo(interRay);if(distance<raycaster.near||distance>raycaster.far)continue;intersects.push({distance:distance,// What do we want? intersection point on the ray or on the segment??
  1031. // point: raycaster.ray.at( distance ),
  1032. point:interSegment.clone().applyMatrix4(this.matrixWorld),index:_i150,face:null,faceIndex:null,object:this});}}else {for(var _i151=0,_l7=positionAttribute.count-1;_i151<_l7;_i151+=step){vStart.fromBufferAttribute(positionAttribute,_i151);vEnd.fromBufferAttribute(positionAttribute,_i151+1);var _distSq=_ray$1.distanceSqToSegment(vStart,vEnd,interRay,interSegment);if(_distSq>localThresholdSq)continue;interRay.applyMatrix4(this.matrixWorld);//Move back to world space for distance calculation
  1033. var _distance=raycaster.ray.origin.distanceTo(interRay);if(_distance<raycaster.near||_distance>raycaster.far)continue;intersects.push({distance:_distance,// What do we want? intersection point on the ray or on the segment??
  1034. // point: raycaster.ray.at( distance ),
  1035. point:interSegment.clone().applyMatrix4(this.matrixWorld),index:_i151,face:null,faceIndex:null,object:this});}}}else if(geometry.isGeometry){var vertices=geometry.vertices;var nbVertices=vertices.length;for(var _i152=0;_i152<nbVertices-1;_i152+=step){var _distSq2=_ray$1.distanceSqToSegment(vertices[_i152],vertices[_i152+1],interRay,interSegment);if(_distSq2>localThresholdSq)continue;interRay.applyMatrix4(this.matrixWorld);//Move back to world space for distance calculation
  1036. var _distance2=raycaster.ray.origin.distanceTo(interRay);if(_distance2<raycaster.near||_distance2>raycaster.far)continue;intersects.push({distance:_distance2,// What do we want? intersection point on the ray or on the segment??
  1037. // point: raycaster.ray.at( distance ),
  1038. point:interSegment.clone().applyMatrix4(this.matrixWorld),index:_i152,face:null,faceIndex:null,object:this});}}},updateMorphTargets:function updateMorphTargets(){var geometry=this.geometry;if(geometry.isBufferGeometry){var morphAttributes=geometry.morphAttributes;var keys=Object.keys(morphAttributes);if(keys.length>0){var morphAttribute=morphAttributes[keys[0]];if(morphAttribute!==undefined){this.morphTargetInfluences=[];this.morphTargetDictionary={};for(var m=0,ml=morphAttribute.length;m<ml;m++){var name=morphAttribute[m].name||String(m);this.morphTargetInfluences.push(0);this.morphTargetDictionary[name]=m;}}}}else {var morphTargets=geometry.morphTargets;if(morphTargets!==undefined&&morphTargets.length>0){console.error('THREE.Line.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');}}}});var _start$1=new Vector3();var _end$1=new Vector3();function LineSegments(geometry,material){Line.call(this,geometry,material);this.type='LineSegments';}LineSegments.prototype=Object.assign(Object.create(Line.prototype),{constructor:LineSegments,isLineSegments:true,computeLineDistances:function computeLineDistances(){var geometry=this.geometry;if(geometry.isBufferGeometry){// we assume non-indexed geometry
  1039. if(geometry.index===null){var positionAttribute=geometry.attributes.position;var lineDistances=[];for(var _i153=0,l=positionAttribute.count;_i153<l;_i153+=2){_start$1.fromBufferAttribute(positionAttribute,_i153);_end$1.fromBufferAttribute(positionAttribute,_i153+1);lineDistances[_i153]=_i153===0?0:lineDistances[_i153-1];lineDistances[_i153+1]=lineDistances[_i153]+_start$1.distanceTo(_end$1);}geometry.setAttribute('lineDistance',new Float32BufferAttribute(lineDistances,1));}else {console.warn('THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');}}else if(geometry.isGeometry){var vertices=geometry.vertices;var _lineDistances2=geometry.lineDistances;for(var _i154=0,_l8=vertices.length;_i154<_l8;_i154+=2){_start$1.copy(vertices[_i154]);_end$1.copy(vertices[_i154+1]);_lineDistances2[_i154]=_i154===0?0:_lineDistances2[_i154-1];_lineDistances2[_i154+1]=_lineDistances2[_i154]+_start$1.distanceTo(_end$1);}}return this;}});function LineLoop(geometry,material){Line.call(this,geometry,material);this.type='LineLoop';}LineLoop.prototype=Object.assign(Object.create(Line.prototype),{constructor:LineLoop,isLineLoop:true});/**
  1040. * parameters = {
  1041. * color: <hex>,
  1042. * opacity: <float>,
  1043. * map: new THREE.Texture( <Image> ),
  1044. * alphaMap: new THREE.Texture( <Image> ),
  1045. *
  1046. * size: <float>,
  1047. * sizeAttenuation: <bool>
  1048. *
  1049. * morphTargets: <bool>
  1050. * }
  1051. */function PointsMaterial(parameters){Material.call(this);this.type='PointsMaterial';this.color=new Color(0xffffff);this.map=null;this.alphaMap=null;this.size=1;this.sizeAttenuation=true;this.morphTargets=false;this.setValues(parameters);}PointsMaterial.prototype=Object.create(Material.prototype);PointsMaterial.prototype.constructor=PointsMaterial;PointsMaterial.prototype.isPointsMaterial=true;PointsMaterial.prototype.copy=function(source){Material.prototype.copy.call(this,source);this.color.copy(source.color);this.map=source.map;this.alphaMap=source.alphaMap;this.size=source.size;this.sizeAttenuation=source.sizeAttenuation;this.morphTargets=source.morphTargets;return this;};var _inverseMatrix$2=new Matrix4();var _ray$2=new Ray();var _sphere$3=new Sphere();var _position$1=new Vector3();function Points(){var geometry=arguments.length>0&&arguments[0]!==undefined?arguments[0]:new BufferGeometry();var material=arguments.length>1&&arguments[1]!==undefined?arguments[1]:new PointsMaterial();Object3D.call(this);this.type='Points';this.geometry=geometry;this.material=material;this.updateMorphTargets();}Points.prototype=Object.assign(Object.create(Object3D.prototype),{constructor:Points,isPoints:true,copy:function copy(source){Object3D.prototype.copy.call(this,source);this.material=source.material;this.geometry=source.geometry;return this;},raycast:function raycast(raycaster,intersects){var geometry=this.geometry;var matrixWorld=this.matrixWorld;var threshold=raycaster.params.Points.threshold;// Checking boundingSphere distance to ray
  1052. if(geometry.boundingSphere===null)geometry.computeBoundingSphere();_sphere$3.copy(geometry.boundingSphere);_sphere$3.applyMatrix4(matrixWorld);_sphere$3.radius+=threshold;if(raycaster.ray.intersectsSphere(_sphere$3)===false)return;//
  1053. _inverseMatrix$2.copy(matrixWorld).invert();_ray$2.copy(raycaster.ray).applyMatrix4(_inverseMatrix$2);var localThreshold=threshold/((this.scale.x+this.scale.y+this.scale.z)/3);var localThresholdSq=localThreshold*localThreshold;if(geometry.isBufferGeometry){var index=geometry.index;var attributes=geometry.attributes;var positionAttribute=attributes.position;if(index!==null){var indices=index.array;for(var _i155=0,il=indices.length;_i155<il;_i155++){var a=indices[_i155];_position$1.fromBufferAttribute(positionAttribute,a);testPoint(_position$1,a,localThresholdSq,matrixWorld,raycaster,intersects,this);}}else {for(var _i156=0,l=positionAttribute.count;_i156<l;_i156++){_position$1.fromBufferAttribute(positionAttribute,_i156);testPoint(_position$1,_i156,localThresholdSq,matrixWorld,raycaster,intersects,this);}}}else {var vertices=geometry.vertices;for(var _i157=0,_l9=vertices.length;_i157<_l9;_i157++){testPoint(vertices[_i157],_i157,localThresholdSq,matrixWorld,raycaster,intersects,this);}}},updateMorphTargets:function updateMorphTargets(){var geometry=this.geometry;if(geometry.isBufferGeometry){var morphAttributes=geometry.morphAttributes;var keys=Object.keys(morphAttributes);if(keys.length>0){var morphAttribute=morphAttributes[keys[0]];if(morphAttribute!==undefined){this.morphTargetInfluences=[];this.morphTargetDictionary={};for(var m=0,ml=morphAttribute.length;m<ml;m++){var name=morphAttribute[m].name||String(m);this.morphTargetInfluences.push(0);this.morphTargetDictionary[name]=m;}}}}else {var morphTargets=geometry.morphTargets;if(morphTargets!==undefined&&morphTargets.length>0){console.error('THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');}}}});function testPoint(point,index,localThresholdSq,matrixWorld,raycaster,intersects,object){var rayPointDistanceSq=_ray$2.distanceSqToPoint(point);if(rayPointDistanceSq<localThresholdSq){var intersectPoint=new Vector3();_ray$2.closestPointToPoint(point,intersectPoint);intersectPoint.applyMatrix4(matrixWorld);var distance=raycaster.ray.origin.distanceTo(intersectPoint);if(distance<raycaster.near||distance>raycaster.far)return;intersects.push({distance:distance,distanceToRay:Math.sqrt(rayPointDistanceSq),point:intersectPoint,index:index,face:null,object:object});}}function VideoTexture(video,mapping,wrapS,wrapT,magFilter,minFilter,format,type,anisotropy){Texture.call(this,video,mapping,wrapS,wrapT,magFilter,minFilter,format,type,anisotropy);this.format=format!==undefined?format:RGBFormat;this.minFilter=minFilter!==undefined?minFilter:LinearFilter;this.magFilter=magFilter!==undefined?magFilter:LinearFilter;this.generateMipmaps=false;var scope=this;function updateVideo(){scope.needsUpdate=true;video.requestVideoFrameCallback(updateVideo);}if('requestVideoFrameCallback'in video){video.requestVideoFrameCallback(updateVideo);}}VideoTexture.prototype=Object.assign(Object.create(Texture.prototype),{constructor:VideoTexture,clone:function clone(){return new this.constructor(this.image).copy(this);},isVideoTexture:true,update:function update(){var video=this.image;var hasVideoFrameCallback='requestVideoFrameCallback'in video;if(hasVideoFrameCallback===false&&video.readyState>=video.HAVE_CURRENT_DATA){this.needsUpdate=true;}}});function CompressedTexture(mipmaps,width,height,format,type,mapping,wrapS,wrapT,magFilter,minFilter,anisotropy,encoding){Texture.call(this,null,mapping,wrapS,wrapT,magFilter,minFilter,format,type,anisotropy,encoding);this.image={width:width,height:height};this.mipmaps=mipmaps;// no flipping for cube textures
  1054. // (also flipping doesn't work for compressed textures )
  1055. this.flipY=false;// can't generate mipmaps for compressed textures
  1056. // mips must be embedded in DDS files
  1057. this.generateMipmaps=false;}CompressedTexture.prototype=Object.create(Texture.prototype);CompressedTexture.prototype.constructor=CompressedTexture;CompressedTexture.prototype.isCompressedTexture=true;function CanvasTexture(canvas,mapping,wrapS,wrapT,magFilter,minFilter,format,type,anisotropy){Texture.call(this,canvas,mapping,wrapS,wrapT,magFilter,minFilter,format,type,anisotropy);this.needsUpdate=true;}CanvasTexture.prototype=Object.create(Texture.prototype);CanvasTexture.prototype.constructor=CanvasTexture;CanvasTexture.prototype.isCanvasTexture=true;function DepthTexture(width,height,type,mapping,wrapS,wrapT,magFilter,minFilter,anisotropy,format){format=format!==undefined?format:DepthFormat;if(format!==DepthFormat&&format!==DepthStencilFormat){throw new Error('DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat');}if(type===undefined&&format===DepthFormat)type=UnsignedShortType;if(type===undefined&&format===DepthStencilFormat)type=UnsignedInt248Type$1;Texture.call(this,null,mapping,wrapS,wrapT,magFilter,minFilter,format,type,anisotropy);this.image={width:width,height:height};this.magFilter=magFilter!==undefined?magFilter:NearestFilter;this.minFilter=minFilter!==undefined?minFilter:NearestFilter;this.flipY=false;this.generateMipmaps=false;}DepthTexture.prototype=Object.create(Texture.prototype);DepthTexture.prototype.constructor=DepthTexture;DepthTexture.prototype.isDepthTexture=true;var _geometryId=0;// Geometry uses even numbers as Id
  1058. var _m1$3=new Matrix4();var _obj$1=new Object3D();var _offset$1=new Vector3();function Geometry(){Object.defineProperty(this,'id',{value:_geometryId+=2});this.uuid=MathUtils.generateUUID();this.name='';this.type='Geometry';this.vertices=[];this.colors=[];this.faces=[];this.faceVertexUvs=[[]];this.morphTargets=[];this.morphNormals=[];this.skinWeights=[];this.skinIndices=[];this.lineDistances=[];this.boundingBox=null;this.boundingSphere=null;// update flags
  1059. this.elementsNeedUpdate=false;this.verticesNeedUpdate=false;this.uvsNeedUpdate=false;this.normalsNeedUpdate=false;this.colorsNeedUpdate=false;this.lineDistancesNeedUpdate=false;this.groupsNeedUpdate=false;}Geometry.prototype=Object.assign(Object.create(EventDispatcher.prototype),{constructor:Geometry,isGeometry:true,applyMatrix4:function applyMatrix4(matrix){var normalMatrix=new Matrix3().getNormalMatrix(matrix);for(var _i158=0,il=this.vertices.length;_i158<il;_i158++){var vertex=this.vertices[_i158];vertex.applyMatrix4(matrix);}for(var _i159=0,_il12=this.faces.length;_i159<_il12;_i159++){var face=this.faces[_i159];face.normal.applyMatrix3(normalMatrix).normalize();for(var j=0,jl=face.vertexNormals.length;j<jl;j++){face.vertexNormals[j].applyMatrix3(normalMatrix).normalize();}}if(this.boundingBox!==null){this.computeBoundingBox();}if(this.boundingSphere!==null){this.computeBoundingSphere();}this.verticesNeedUpdate=true;this.normalsNeedUpdate=true;return this;},rotateX:function rotateX(angle){// rotate geometry around world x-axis
  1060. _m1$3.makeRotationX(angle);this.applyMatrix4(_m1$3);return this;},rotateY:function rotateY(angle){// rotate geometry around world y-axis
  1061. _m1$3.makeRotationY(angle);this.applyMatrix4(_m1$3);return this;},rotateZ:function rotateZ(angle){// rotate geometry around world z-axis
  1062. _m1$3.makeRotationZ(angle);this.applyMatrix4(_m1$3);return this;},translate:function translate(x,y,z){// translate geometry
  1063. _m1$3.makeTranslation(x,y,z);this.applyMatrix4(_m1$3);return this;},scale:function scale(x,y,z){// scale geometry
  1064. _m1$3.makeScale(x,y,z);this.applyMatrix4(_m1$3);return this;},lookAt:function lookAt(vector){_obj$1.lookAt(vector);_obj$1.updateMatrix();this.applyMatrix4(_obj$1.matrix);return this;},fromBufferGeometry:function fromBufferGeometry(geometry){var scope=this;var index=geometry.index!==null?geometry.index:undefined;var attributes=geometry.attributes;if(attributes.position===undefined){console.error('THREE.Geometry.fromBufferGeometry(): Position attribute required for conversion.');return this;}var position=attributes.position;var normal=attributes.normal;var color=attributes.color;var uv=attributes.uv;var uv2=attributes.uv2;if(uv2!==undefined)this.faceVertexUvs[1]=[];for(var _i160=0;_i160<position.count;_i160++){scope.vertices.push(new Vector3().fromBufferAttribute(position,_i160));if(color!==undefined){scope.colors.push(new Color().fromBufferAttribute(color,_i160));}}function addFace(a,b,c,materialIndex){var vertexColors=color===undefined?[]:[scope.colors[a].clone(),scope.colors[b].clone(),scope.colors[c].clone()];var vertexNormals=normal===undefined?[]:[new Vector3().fromBufferAttribute(normal,a),new Vector3().fromBufferAttribute(normal,b),new Vector3().fromBufferAttribute(normal,c)];var face=new Face3(a,b,c,vertexNormals,vertexColors,materialIndex);scope.faces.push(face);if(uv!==undefined){scope.faceVertexUvs[0].push([new Vector2().fromBufferAttribute(uv,a),new Vector2().fromBufferAttribute(uv,b),new Vector2().fromBufferAttribute(uv,c)]);}if(uv2!==undefined){scope.faceVertexUvs[1].push([new Vector2().fromBufferAttribute(uv2,a),new Vector2().fromBufferAttribute(uv2,b),new Vector2().fromBufferAttribute(uv2,c)]);}}var groups=geometry.groups;if(groups.length>0){for(var _i161=0;_i161<groups.length;_i161++){var group=groups[_i161];var start=group.start;var count=group.count;for(var j=start,jl=start+count;j<jl;j+=3){if(index!==undefined){addFace(index.getX(j),index.getX(j+1),index.getX(j+2),group.materialIndex);}else {addFace(j,j+1,j+2,group.materialIndex);}}}}else {if(index!==undefined){for(var _i162=0;_i162<index.count;_i162+=3){addFace(index.getX(_i162),index.getX(_i162+1),index.getX(_i162+2));}}else {for(var _i163=0;_i163<position.count;_i163+=3){addFace(_i163,_i163+1,_i163+2);}}}this.computeFaceNormals();if(geometry.boundingBox!==null){this.boundingBox=geometry.boundingBox.clone();}if(geometry.boundingSphere!==null){this.boundingSphere=geometry.boundingSphere.clone();}return this;},center:function center(){this.computeBoundingBox();this.boundingBox.getCenter(_offset$1).negate();this.translate(_offset$1.x,_offset$1.y,_offset$1.z);return this;},normalize:function normalize(){this.computeBoundingSphere();var center=this.boundingSphere.center;var radius=this.boundingSphere.radius;var s=radius===0?1:1.0/radius;var matrix=new Matrix4();matrix.set(s,0,0,-s*center.x,0,s,0,-s*center.y,0,0,s,-s*center.z,0,0,0,1);this.applyMatrix4(matrix);return this;},computeFaceNormals:function computeFaceNormals(){var cb=new Vector3(),ab=new Vector3();for(var f=0,fl=this.faces.length;f<fl;f++){var face=this.faces[f];var vA=this.vertices[face.a];var vB=this.vertices[face.b];var vC=this.vertices[face.c];cb.subVectors(vC,vB);ab.subVectors(vA,vB);cb.cross(ab);cb.normalize();face.normal.copy(cb);}},computeVertexNormals:function computeVertexNormals(){var areaWeighted=arguments.length>0&&arguments[0]!==undefined?arguments[0]:true;var vertices=new Array(this.vertices.length);for(var v=0,vl=this.vertices.length;v<vl;v++){vertices[v]=new Vector3();}if(areaWeighted){// vertex normals weighted by triangle areas
  1065. // http://www.iquilezles.org/www/articles/normals/normals.htm
  1066. var cb=new Vector3(),ab=new Vector3();for(var f=0,fl=this.faces.length;f<fl;f++){var face=this.faces[f];var vA=this.vertices[face.a];var vB=this.vertices[face.b];var vC=this.vertices[face.c];cb.subVectors(vC,vB);ab.subVectors(vA,vB);cb.cross(ab);vertices[face.a].add(cb);vertices[face.b].add(cb);vertices[face.c].add(cb);}}else {this.computeFaceNormals();for(var _f=0,_fl=this.faces.length;_f<_fl;_f++){var _face=this.faces[_f];vertices[_face.a].add(_face.normal);vertices[_face.b].add(_face.normal);vertices[_face.c].add(_face.normal);}}for(var _v=0,_vl=this.vertices.length;_v<_vl;_v++){vertices[_v].normalize();}for(var _f3=0,_fl2=this.faces.length;_f3<_fl2;_f3++){var _face2=this.faces[_f3];var vertexNormals=_face2.vertexNormals;if(vertexNormals.length===3){vertexNormals[0].copy(vertices[_face2.a]);vertexNormals[1].copy(vertices[_face2.b]);vertexNormals[2].copy(vertices[_face2.c]);}else {vertexNormals[0]=vertices[_face2.a].clone();vertexNormals[1]=vertices[_face2.b].clone();vertexNormals[2]=vertices[_face2.c].clone();}}if(this.faces.length>0){this.normalsNeedUpdate=true;}},computeFlatVertexNormals:function computeFlatVertexNormals(){this.computeFaceNormals();for(var f=0,fl=this.faces.length;f<fl;f++){var face=this.faces[f];var vertexNormals=face.vertexNormals;if(vertexNormals.length===3){vertexNormals[0].copy(face.normal);vertexNormals[1].copy(face.normal);vertexNormals[2].copy(face.normal);}else {vertexNormals[0]=face.normal.clone();vertexNormals[1]=face.normal.clone();vertexNormals[2]=face.normal.clone();}}if(this.faces.length>0){this.normalsNeedUpdate=true;}},computeMorphNormals:function computeMorphNormals(){// save original normals
  1067. // - create temp variables on first access
  1068. // otherwise just copy (for faster repeated calls)
  1069. for(var f=0,fl=this.faces.length;f<fl;f++){var face=this.faces[f];if(!face.__originalFaceNormal){face.__originalFaceNormal=face.normal.clone();}else {face.__originalFaceNormal.copy(face.normal);}if(!face.__originalVertexNormals)face.__originalVertexNormals=[];for(var _i164=0,il=face.vertexNormals.length;_i164<il;_i164++){if(!face.__originalVertexNormals[_i164]){face.__originalVertexNormals[_i164]=face.vertexNormals[_i164].clone();}else {face.__originalVertexNormals[_i164].copy(face.vertexNormals[_i164]);}}}// use temp geometry to compute face and vertex normals for each morph
  1070. var tmpGeo=new Geometry();tmpGeo.faces=this.faces;for(var _i165=0,_il13=this.morphTargets.length;_i165<_il13;_i165++){// create on first access
  1071. if(!this.morphNormals[_i165]){this.morphNormals[_i165]={};this.morphNormals[_i165].faceNormals=[];this.morphNormals[_i165].vertexNormals=[];var dstNormalsFace=this.morphNormals[_i165].faceNormals;var dstNormalsVertex=this.morphNormals[_i165].vertexNormals;for(var _f4=0,_fl3=this.faces.length;_f4<_fl3;_f4++){var faceNormal=new Vector3();var vertexNormals={a:new Vector3(),b:new Vector3(),c:new Vector3()};dstNormalsFace.push(faceNormal);dstNormalsVertex.push(vertexNormals);}}var morphNormals=this.morphNormals[_i165];// set vertices to morph target
  1072. tmpGeo.vertices=this.morphTargets[_i165].vertices;// compute morph normals
  1073. tmpGeo.computeFaceNormals();tmpGeo.computeVertexNormals();// store morph normals
  1074. for(var _f5=0,_fl4=this.faces.length;_f5<_fl4;_f5++){var _face3=this.faces[_f5];var _faceNormal=morphNormals.faceNormals[_f5];var _vertexNormals=morphNormals.vertexNormals[_f5];_faceNormal.copy(_face3.normal);_vertexNormals.a.copy(_face3.vertexNormals[0]);_vertexNormals.b.copy(_face3.vertexNormals[1]);_vertexNormals.c.copy(_face3.vertexNormals[2]);}}// restore original normals
  1075. for(var _f6=0,_fl5=this.faces.length;_f6<_fl5;_f6++){var _face4=this.faces[_f6];_face4.normal=_face4.__originalFaceNormal;_face4.vertexNormals=_face4.__originalVertexNormals;}},computeBoundingBox:function computeBoundingBox(){if(this.boundingBox===null){this.boundingBox=new Box3();}this.boundingBox.setFromPoints(this.vertices);},computeBoundingSphere:function computeBoundingSphere(){if(this.boundingSphere===null){this.boundingSphere=new Sphere();}this.boundingSphere.setFromPoints(this.vertices);},merge:function merge(geometry,matrix){var materialIndexOffset=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0;if(!(geometry&&geometry.isGeometry)){console.error('THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.',geometry);return;}var normalMatrix;var vertexOffset=this.vertices.length,vertices1=this.vertices,vertices2=geometry.vertices,faces1=this.faces,faces2=geometry.faces,colors1=this.colors,colors2=geometry.colors;if(matrix!==undefined){normalMatrix=new Matrix3().getNormalMatrix(matrix);}// vertices
  1076. for(var _i166=0,il=vertices2.length;_i166<il;_i166++){var vertex=vertices2[_i166];var vertexCopy=vertex.clone();if(matrix!==undefined)vertexCopy.applyMatrix4(matrix);vertices1.push(vertexCopy);}// colors
  1077. for(var _i167=0,_il14=colors2.length;_i167<_il14;_i167++){colors1.push(colors2[_i167].clone());}// faces
  1078. for(var _i168=0,_il15=faces2.length;_i168<_il15;_i168++){var face=faces2[_i168];var normal=void 0,color=void 0;var faceVertexNormals=face.vertexNormals,faceVertexColors=face.vertexColors;var faceCopy=new Face3(face.a+vertexOffset,face.b+vertexOffset,face.c+vertexOffset);faceCopy.normal.copy(face.normal);if(normalMatrix!==undefined){faceCopy.normal.applyMatrix3(normalMatrix).normalize();}for(var j=0,jl=faceVertexNormals.length;j<jl;j++){normal=faceVertexNormals[j].clone();if(normalMatrix!==undefined){normal.applyMatrix3(normalMatrix).normalize();}faceCopy.vertexNormals.push(normal);}faceCopy.color.copy(face.color);for(var _j5=0,_jl2=faceVertexColors.length;_j5<_jl2;_j5++){color=faceVertexColors[_j5];faceCopy.vertexColors.push(color.clone());}faceCopy.materialIndex=face.materialIndex+materialIndexOffset;faces1.push(faceCopy);}// uvs
  1079. for(var _i169=0,_il16=geometry.faceVertexUvs.length;_i169<_il16;_i169++){var faceVertexUvs2=geometry.faceVertexUvs[_i169];if(this.faceVertexUvs[_i169]===undefined)this.faceVertexUvs[_i169]=[];for(var _j6=0,_jl3=faceVertexUvs2.length;_j6<_jl3;_j6++){var uvs2=faceVertexUvs2[_j6],uvsCopy=[];for(var k=0,kl=uvs2.length;k<kl;k++){uvsCopy.push(uvs2[k].clone());}this.faceVertexUvs[_i169].push(uvsCopy);}}},mergeMesh:function mergeMesh(mesh){if(!(mesh&&mesh.isMesh)){console.error('THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.',mesh);return;}if(mesh.matrixAutoUpdate)mesh.updateMatrix();this.merge(mesh.geometry,mesh.matrix);},/*
  1080. * Checks for duplicate vertices with hashmap.
  1081. * Duplicated vertices are removed
  1082. * and faces' vertices are updated.
  1083. */mergeVertices:function mergeVertices(){var precisionPoints=arguments.length>0&&arguments[0]!==undefined?arguments[0]:4;var verticesMap={};// Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  1084. var unique=[],changes=[];var precision=Math.pow(10,precisionPoints);for(var _i170=0,il=this.vertices.length;_i170<il;_i170++){var v=this.vertices[_i170];var key=Math.round(v.x*precision)+'_'+Math.round(v.y*precision)+'_'+Math.round(v.z*precision);if(verticesMap[key]===undefined){verticesMap[key]=_i170;unique.push(this.vertices[_i170]);changes[_i170]=unique.length-1;}else {//console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  1085. changes[_i170]=changes[verticesMap[key]];}}// if faces are completely degenerate after merging vertices, we
  1086. // have to remove them from the geometry.
  1087. var faceIndicesToRemove=[];for(var _i171=0,_il17=this.faces.length;_i171<_il17;_i171++){var face=this.faces[_i171];face.a=changes[face.a];face.b=changes[face.b];face.c=changes[face.c];var indices=[face.a,face.b,face.c];// if any duplicate vertices are found in a Face3
  1088. // we have to remove the face as nothing can be saved
  1089. for(var n=0;n<3;n++){if(indices[n]===indices[(n+1)%3]){faceIndicesToRemove.push(_i171);break;}}}for(var _i172=faceIndicesToRemove.length-1;_i172>=0;_i172--){var idx=faceIndicesToRemove[_i172];this.faces.splice(idx,1);for(var j=0,jl=this.faceVertexUvs.length;j<jl;j++){this.faceVertexUvs[j].splice(idx,1);}}// Use unique set of vertices
  1090. var diff=this.vertices.length-unique.length;this.vertices=unique;return diff;},setFromPoints:function setFromPoints(points){this.vertices=[];for(var _i173=0,l=points.length;_i173<l;_i173++){var point=points[_i173];this.vertices.push(new Vector3(point.x,point.y,point.z||0));}return this;},sortFacesByMaterialIndex:function sortFacesByMaterialIndex(){var faces=this.faces;var length=faces.length;// tag faces
  1091. for(var _i174=0;_i174<length;_i174++){faces[_i174]._id=_i174;}// sort faces
  1092. function materialIndexSort(a,b){return a.materialIndex-b.materialIndex;}faces.sort(materialIndexSort);// sort uvs
  1093. var uvs1=this.faceVertexUvs[0];var uvs2=this.faceVertexUvs[1];var newUvs1,newUvs2;if(uvs1&&uvs1.length===length)newUvs1=[];if(uvs2&&uvs2.length===length)newUvs2=[];for(var _i175=0;_i175<length;_i175++){var id=faces[_i175]._id;if(newUvs1)newUvs1.push(uvs1[id]);if(newUvs2)newUvs2.push(uvs2[id]);}if(newUvs1)this.faceVertexUvs[0]=newUvs1;if(newUvs2)this.faceVertexUvs[1]=newUvs2;},toJSON:function toJSON(){var data={metadata:{version:4.5,type:'Geometry',generator:'Geometry.toJSON'}};// standard Geometry serialization
  1094. data.uuid=this.uuid;data.type=this.type;if(this.name!=='')data.name=this.name;if(this.parameters!==undefined){var parameters=this.parameters;for(var key in parameters){if(parameters[key]!==undefined)data[key]=parameters[key];}return data;}var vertices=[];for(var _i176=0;_i176<this.vertices.length;_i176++){var vertex=this.vertices[_i176];vertices.push(vertex.x,vertex.y,vertex.z);}var faces=[];var normals=[];var normalsHash={};var colors=[];var colorsHash={};var uvs=[];var uvsHash={};for(var _i177=0;_i177<this.faces.length;_i177++){var face=this.faces[_i177];var hasMaterial=true;var hasFaceUv=false;// deprecated
  1095. var hasFaceVertexUv=this.faceVertexUvs[0][_i177]!==undefined;var hasFaceNormal=face.normal.length()>0;var hasFaceVertexNormal=face.vertexNormals.length>0;var hasFaceColor=face.color.r!==1||face.color.g!==1||face.color.b!==1;var hasFaceVertexColor=face.vertexColors.length>0;var faceType=0;faceType=setBit(faceType,0,0);// isQuad
  1096. faceType=setBit(faceType,1,hasMaterial);faceType=setBit(faceType,2,hasFaceUv);faceType=setBit(faceType,3,hasFaceVertexUv);faceType=setBit(faceType,4,hasFaceNormal);faceType=setBit(faceType,5,hasFaceVertexNormal);faceType=setBit(faceType,6,hasFaceColor);faceType=setBit(faceType,7,hasFaceVertexColor);faces.push(faceType);faces.push(face.a,face.b,face.c);faces.push(face.materialIndex);if(hasFaceVertexUv){var faceVertexUvs=this.faceVertexUvs[0][_i177];faces.push(getUvIndex(faceVertexUvs[0]),getUvIndex(faceVertexUvs[1]),getUvIndex(faceVertexUvs[2]));}if(hasFaceNormal){faces.push(getNormalIndex(face.normal));}if(hasFaceVertexNormal){var vertexNormals=face.vertexNormals;faces.push(getNormalIndex(vertexNormals[0]),getNormalIndex(vertexNormals[1]),getNormalIndex(vertexNormals[2]));}if(hasFaceColor){faces.push(getColorIndex(face.color));}if(hasFaceVertexColor){var vertexColors=face.vertexColors;faces.push(getColorIndex(vertexColors[0]),getColorIndex(vertexColors[1]),getColorIndex(vertexColors[2]));}}function setBit(value,position,enabled){return enabled?value|1<<position:value&~(1<<position);}function getNormalIndex(normal){var hash=normal.x.toString()+normal.y.toString()+normal.z.toString();if(normalsHash[hash]!==undefined){return normalsHash[hash];}normalsHash[hash]=normals.length/3;normals.push(normal.x,normal.y,normal.z);return normalsHash[hash];}function getColorIndex(color){var hash=color.r.toString()+color.g.toString()+color.b.toString();if(colorsHash[hash]!==undefined){return colorsHash[hash];}colorsHash[hash]=colors.length;colors.push(color.getHex());return colorsHash[hash];}function getUvIndex(uv){var hash=uv.x.toString()+uv.y.toString();if(uvsHash[hash]!==undefined){return uvsHash[hash];}uvsHash[hash]=uvs.length/2;uvs.push(uv.x,uv.y);return uvsHash[hash];}data.data={};data.data.vertices=vertices;data.data.normals=normals;if(colors.length>0)data.data.colors=colors;if(uvs.length>0)data.data.uvs=[uvs];// temporal backward compatibility
  1097. data.data.faces=faces;return data;},clone:function clone(){/*
  1098. // Handle primitives
  1099. const parameters = this.parameters;
  1100. if ( parameters !== undefined ) {
  1101. const values = [];
  1102. for ( const key in parameters ) {
  1103. values.push( parameters[ key ] );
  1104. }
  1105. const geometry = Object.create( this.constructor.prototype );
  1106. this.constructor.apply( geometry, values );
  1107. return geometry;
  1108. }
  1109. return new this.constructor().copy( this );
  1110. */return new Geometry().copy(this);},copy:function copy(source){// reset
  1111. this.vertices=[];this.colors=[];this.faces=[];this.faceVertexUvs=[[]];this.morphTargets=[];this.morphNormals=[];this.skinWeights=[];this.skinIndices=[];this.lineDistances=[];this.boundingBox=null;this.boundingSphere=null;// name
  1112. this.name=source.name;// vertices
  1113. var vertices=source.vertices;for(var _i178=0,il=vertices.length;_i178<il;_i178++){this.vertices.push(vertices[_i178].clone());}// colors
  1114. var colors=source.colors;for(var _i179=0,_il18=colors.length;_i179<_il18;_i179++){this.colors.push(colors[_i179].clone());}// faces
  1115. var faces=source.faces;for(var _i180=0,_il19=faces.length;_i180<_il19;_i180++){this.faces.push(faces[_i180].clone());}// face vertex uvs
  1116. for(var _i181=0,_il20=source.faceVertexUvs.length;_i181<_il20;_i181++){var faceVertexUvs=source.faceVertexUvs[_i181];if(this.faceVertexUvs[_i181]===undefined){this.faceVertexUvs[_i181]=[];}for(var j=0,jl=faceVertexUvs.length;j<jl;j++){var uvs=faceVertexUvs[j],uvsCopy=[];for(var k=0,kl=uvs.length;k<kl;k++){var uv=uvs[k];uvsCopy.push(uv.clone());}this.faceVertexUvs[_i181].push(uvsCopy);}}// morph targets
  1117. var morphTargets=source.morphTargets;for(var _i182=0,_il21=morphTargets.length;_i182<_il21;_i182++){var morphTarget={};morphTarget.name=morphTargets[_i182].name;// vertices
  1118. if(morphTargets[_i182].vertices!==undefined){morphTarget.vertices=[];for(var _j7=0,_jl4=morphTargets[_i182].vertices.length;_j7<_jl4;_j7++){morphTarget.vertices.push(morphTargets[_i182].vertices[_j7].clone());}}// normals
  1119. if(morphTargets[_i182].normals!==undefined){morphTarget.normals=[];for(var _j8=0,_jl5=morphTargets[_i182].normals.length;_j8<_jl5;_j8++){morphTarget.normals.push(morphTargets[_i182].normals[_j8].clone());}}this.morphTargets.push(morphTarget);}// morph normals
  1120. var morphNormals=source.morphNormals;for(var _i183=0,_il22=morphNormals.length;_i183<_il22;_i183++){var morphNormal={};// vertex normals
  1121. if(morphNormals[_i183].vertexNormals!==undefined){morphNormal.vertexNormals=[];for(var _j9=0,_jl6=morphNormals[_i183].vertexNormals.length;_j9<_jl6;_j9++){var srcVertexNormal=morphNormals[_i183].vertexNormals[_j9];var destVertexNormal={};destVertexNormal.a=srcVertexNormal.a.clone();destVertexNormal.b=srcVertexNormal.b.clone();destVertexNormal.c=srcVertexNormal.c.clone();morphNormal.vertexNormals.push(destVertexNormal);}}// face normals
  1122. if(morphNormals[_i183].faceNormals!==undefined){morphNormal.faceNormals=[];for(var _j10=0,_jl7=morphNormals[_i183].faceNormals.length;_j10<_jl7;_j10++){morphNormal.faceNormals.push(morphNormals[_i183].faceNormals[_j10].clone());}}this.morphNormals.push(morphNormal);}// skin weights
  1123. var skinWeights=source.skinWeights;for(var _i184=0,_il23=skinWeights.length;_i184<_il23;_i184++){this.skinWeights.push(skinWeights[_i184].clone());}// skin indices
  1124. var skinIndices=source.skinIndices;for(var _i185=0,_il24=skinIndices.length;_i185<_il24;_i185++){this.skinIndices.push(skinIndices[_i185].clone());}// line distances
  1125. var lineDistances=source.lineDistances;for(var _i186=0,_il25=lineDistances.length;_i186<_il25;_i186++){this.lineDistances.push(lineDistances[_i186]);}// bounding box
  1126. var boundingBox=source.boundingBox;if(boundingBox!==null){this.boundingBox=boundingBox.clone();}// bounding sphere
  1127. var boundingSphere=source.boundingSphere;if(boundingSphere!==null){this.boundingSphere=boundingSphere.clone();}// update flags
  1128. this.elementsNeedUpdate=source.elementsNeedUpdate;this.verticesNeedUpdate=source.verticesNeedUpdate;this.uvsNeedUpdate=source.uvsNeedUpdate;this.normalsNeedUpdate=source.normalsNeedUpdate;this.colorsNeedUpdate=source.colorsNeedUpdate;this.lineDistancesNeedUpdate=source.lineDistancesNeedUpdate;this.groupsNeedUpdate=source.groupsNeedUpdate;return this;},dispose:function dispose(){this.dispatchEvent({type:'dispose'});}});class BoxGeometry extends Geometry{constructor(width,height,depth,widthSegments,heightSegments,depthSegments){super();this.type='BoxGeometry';this.parameters={width:width,height:height,depth:depth,widthSegments:widthSegments,heightSegments:heightSegments,depthSegments:depthSegments};this.fromBufferGeometry(new BoxBufferGeometry(width,height,depth,widthSegments,heightSegments,depthSegments));this.mergeVertices();}}class CircleBufferGeometry extends BufferGeometry{constructor(){var radius=arguments.length>0&&arguments[0]!==undefined?arguments[0]:1;var segments=arguments.length>1&&arguments[1]!==undefined?arguments[1]:8;var thetaStart=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0;var thetaLength=arguments.length>3&&arguments[3]!==undefined?arguments[3]:Math.PI*2;super();this.type='CircleBufferGeometry';this.parameters={radius:radius,segments:segments,thetaStart:thetaStart,thetaLength:thetaLength};segments=Math.max(3,segments);// buffers
  1129. var indices=[];var vertices=[];var normals=[];var uvs=[];// helper variables
  1130. var vertex=new Vector3();var uv=new Vector2();// center point
  1131. vertices.push(0,0,0);normals.push(0,0,1);uvs.push(0.5,0.5);for(var s=0,_i187=3;s<=segments;s++,_i187+=3){var segment=thetaStart+s/segments*thetaLength;// vertex
  1132. vertex.x=radius*Math.cos(segment);vertex.y=radius*Math.sin(segment);vertices.push(vertex.x,vertex.y,vertex.z);// normal
  1133. normals.push(0,0,1);// uvs
  1134. uv.x=(vertices[_i187]/radius+1)/2;uv.y=(vertices[_i187+1]/radius+1)/2;uvs.push(uv.x,uv.y);}// indices
  1135. for(var _i188=1;_i188<=segments;_i188++){indices.push(_i188,_i188+1,0);}// build geometry
  1136. this.setIndex(indices);this.setAttribute('position',new Float32BufferAttribute(vertices,3));this.setAttribute('normal',new Float32BufferAttribute(normals,3));this.setAttribute('uv',new Float32BufferAttribute(uvs,2));}}class CircleGeometry extends Geometry{constructor(radius,segments,thetaStart,thetaLength){super();this.type='CircleGeometry';this.parameters={radius:radius,segments:segments,thetaStart:thetaStart,thetaLength:thetaLength};this.fromBufferGeometry(new CircleBufferGeometry(radius,segments,thetaStart,thetaLength));this.mergeVertices();}}class CylinderBufferGeometry extends BufferGeometry{constructor(){var radiusTop=arguments.length>0&&arguments[0]!==undefined?arguments[0]:1;var radiusBottom=arguments.length>1&&arguments[1]!==undefined?arguments[1]:1;var height=arguments.length>2&&arguments[2]!==undefined?arguments[2]:1;var radialSegments=arguments.length>3&&arguments[3]!==undefined?arguments[3]:8;var heightSegments=arguments.length>4&&arguments[4]!==undefined?arguments[4]:1;var openEnded=arguments.length>5&&arguments[5]!==undefined?arguments[5]:false;var thetaStart=arguments.length>6&&arguments[6]!==undefined?arguments[6]:0;var thetaLength=arguments.length>7&&arguments[7]!==undefined?arguments[7]:Math.PI*2;super();this.type='CylinderBufferGeometry';this.parameters={radiusTop:radiusTop,radiusBottom:radiusBottom,height:height,radialSegments:radialSegments,heightSegments:heightSegments,openEnded:openEnded,thetaStart:thetaStart,thetaLength:thetaLength};var scope=this;radialSegments=Math.floor(radialSegments);heightSegments=Math.floor(heightSegments);// buffers
  1137. var indices=[];var vertices=[];var normals=[];var uvs=[];// helper variables
  1138. var index=0;var indexArray=[];var halfHeight=height/2;var groupStart=0;// generate geometry
  1139. generateTorso();if(openEnded===false){if(radiusTop>0)generateCap(true);if(radiusBottom>0)generateCap(false);}// build geometry
  1140. this.setIndex(indices);this.setAttribute('position',new Float32BufferAttribute(vertices,3));this.setAttribute('normal',new Float32BufferAttribute(normals,3));this.setAttribute('uv',new Float32BufferAttribute(uvs,2));function generateTorso(){var normal=new Vector3();var vertex=new Vector3();var groupCount=0;// this will be used to calculate the normal
  1141. var slope=(radiusBottom-radiusTop)/height;// generate vertices, normals and uvs
  1142. for(var y=0;y<=heightSegments;y++){var indexRow=[];var v=y/heightSegments;// calculate the radius of the current row
  1143. var radius=v*(radiusBottom-radiusTop)+radiusTop;for(var x=0;x<=radialSegments;x++){var u=x/radialSegments;var theta=u*thetaLength+thetaStart;var sinTheta=Math.sin(theta);var cosTheta=Math.cos(theta);// vertex
  1144. vertex.x=radius*sinTheta;vertex.y=-v*height+halfHeight;vertex.z=radius*cosTheta;vertices.push(vertex.x,vertex.y,vertex.z);// normal
  1145. normal.set(sinTheta,slope,cosTheta).normalize();normals.push(normal.x,normal.y,normal.z);// uv
  1146. uvs.push(u,1-v);// save index of vertex in respective row
  1147. indexRow.push(index++);}// now save vertices of the row in our index array
  1148. indexArray.push(indexRow);}// generate indices
  1149. for(var _x2=0;_x2<radialSegments;_x2++){for(var _y2=0;_y2<heightSegments;_y2++){// we use the index array to access the correct indices
  1150. var a=indexArray[_y2][_x2];var b=indexArray[_y2+1][_x2];var c=indexArray[_y2+1][_x2+1];var d=indexArray[_y2][_x2+1];// faces
  1151. indices.push(a,b,d);indices.push(b,c,d);// update group counter
  1152. groupCount+=6;}}// add a group to the geometry. this will ensure multi material support
  1153. scope.addGroup(groupStart,groupCount,0);// calculate new start value for groups
  1154. groupStart+=groupCount;}function generateCap(top){// save the index of the first center vertex
  1155. var centerIndexStart=index;var uv=new Vector2();var vertex=new Vector3();var groupCount=0;var radius=top===true?radiusTop:radiusBottom;var sign=top===true?1:-1;// first we generate the center vertex data of the cap.
  1156. // because the geometry needs one set of uvs per face,
  1157. // we must generate a center vertex per face/segment
  1158. for(var x=1;x<=radialSegments;x++){// vertex
  1159. vertices.push(0,halfHeight*sign,0);// normal
  1160. normals.push(0,sign,0);// uv
  1161. uvs.push(0.5,0.5);// increase index
  1162. index++;}// save the index of the last center vertex
  1163. var centerIndexEnd=index;// now we generate the surrounding vertices, normals and uvs
  1164. for(var _x3=0;_x3<=radialSegments;_x3++){var u=_x3/radialSegments;var theta=u*thetaLength+thetaStart;var cosTheta=Math.cos(theta);var sinTheta=Math.sin(theta);// vertex
  1165. vertex.x=radius*sinTheta;vertex.y=halfHeight*sign;vertex.z=radius*cosTheta;vertices.push(vertex.x,vertex.y,vertex.z);// normal
  1166. normals.push(0,sign,0);// uv
  1167. uv.x=cosTheta*0.5+0.5;uv.y=sinTheta*0.5*sign+0.5;uvs.push(uv.x,uv.y);// increase index
  1168. index++;}// generate indices
  1169. for(var _x4=0;_x4<radialSegments;_x4++){var c=centerIndexStart+_x4;var _i189=centerIndexEnd+_x4;if(top===true){// face top
  1170. indices.push(_i189,_i189+1,c);}else {// face bottom
  1171. indices.push(_i189+1,_i189,c);}groupCount+=3;}// add a group to the geometry. this will ensure multi material support
  1172. scope.addGroup(groupStart,groupCount,top===true?1:2);// calculate new start value for groups
  1173. groupStart+=groupCount;}}}class CylinderGeometry extends Geometry{constructor(radiusTop,radiusBottom,height,radialSegments,heightSegments,openEnded,thetaStart,thetaLength){super();this.type='CylinderGeometry';this.parameters={radiusTop:radiusTop,radiusBottom:radiusBottom,height:height,radialSegments:radialSegments,heightSegments:heightSegments,openEnded:openEnded,thetaStart:thetaStart,thetaLength:thetaLength};this.fromBufferGeometry(new CylinderBufferGeometry(radiusTop,radiusBottom,height,radialSegments,heightSegments,openEnded,thetaStart,thetaLength));this.mergeVertices();}}class ConeGeometry extends CylinderGeometry{constructor(radius,height,radialSegments,heightSegments,openEnded,thetaStart,thetaLength){super(0,radius,height,radialSegments,heightSegments,openEnded,thetaStart,thetaLength);this.type='ConeGeometry';this.parameters={radius:radius,height:height,radialSegments:radialSegments,heightSegments:heightSegments,openEnded:openEnded,thetaStart:thetaStart,thetaLength:thetaLength};}}class ConeBufferGeometry extends CylinderBufferGeometry{constructor(){var radius=arguments.length>0&&arguments[0]!==undefined?arguments[0]:1;var height=arguments.length>1&&arguments[1]!==undefined?arguments[1]:1;var radialSegments=arguments.length>2&&arguments[2]!==undefined?arguments[2]:8;var heightSegments=arguments.length>3&&arguments[3]!==undefined?arguments[3]:1;var openEnded=arguments.length>4&&arguments[4]!==undefined?arguments[4]:false;var thetaStart=arguments.length>5&&arguments[5]!==undefined?arguments[5]:0;var thetaLength=arguments.length>6&&arguments[6]!==undefined?arguments[6]:Math.PI*2;super(0,radius,height,radialSegments,heightSegments,openEnded,thetaStart,thetaLength);this.type='ConeBufferGeometry';this.parameters={radius:radius,height:height,radialSegments:radialSegments,heightSegments:heightSegments,openEnded:openEnded,thetaStart:thetaStart,thetaLength:thetaLength};}}class PolyhedronBufferGeometry extends BufferGeometry{constructor(vertices,indices){var radius=arguments.length>2&&arguments[2]!==undefined?arguments[2]:1;var detail=arguments.length>3&&arguments[3]!==undefined?arguments[3]:0;super();this.type='PolyhedronBufferGeometry';this.parameters={vertices:vertices,indices:indices,radius:radius,detail:detail};// default buffer data
  1174. var vertexBuffer=[];var uvBuffer=[];// the subdivision creates the vertex buffer data
  1175. subdivide(detail);// all vertices should lie on a conceptual sphere with a given radius
  1176. applyRadius(radius);// finally, create the uv data
  1177. generateUVs();// build non-indexed geometry
  1178. this.setAttribute('position',new Float32BufferAttribute(vertexBuffer,3));this.setAttribute('normal',new Float32BufferAttribute(vertexBuffer.slice(),3));this.setAttribute('uv',new Float32BufferAttribute(uvBuffer,2));if(detail===0){this.computeVertexNormals();// flat normals
  1179. }else {this.normalizeNormals();// smooth normals
  1180. }// helper functions
  1181. function subdivide(detail){var a=new Vector3();var b=new Vector3();var c=new Vector3();// iterate over all faces and apply a subdivison with the given detail value
  1182. for(var _i190=0;_i190<indices.length;_i190+=3){// get the vertices of the face
  1183. getVertexByIndex(indices[_i190+0],a);getVertexByIndex(indices[_i190+1],b);getVertexByIndex(indices[_i190+2],c);// perform subdivision
  1184. subdivideFace(a,b,c,detail);}}function subdivideFace(a,b,c,detail){var cols=detail+1;// we use this multidimensional array as a data structure for creating the subdivision
  1185. var v=[];// construct all of the vertices for this subdivision
  1186. for(var _i191=0;_i191<=cols;_i191++){v[_i191]=[];var aj=a.clone().lerp(c,_i191/cols);var bj=b.clone().lerp(c,_i191/cols);var rows=cols-_i191;for(var j=0;j<=rows;j++){if(j===0&&_i191===cols){v[_i191][j]=aj;}else {v[_i191][j]=aj.clone().lerp(bj,j/rows);}}}// construct all of the faces
  1187. for(var _i192=0;_i192<cols;_i192++){for(var _j11=0;_j11<2*(cols-_i192)-1;_j11++){var k=Math.floor(_j11/2);if(_j11%2===0){pushVertex(v[_i192][k+1]);pushVertex(v[_i192+1][k]);pushVertex(v[_i192][k]);}else {pushVertex(v[_i192][k+1]);pushVertex(v[_i192+1][k+1]);pushVertex(v[_i192+1][k]);}}}}function applyRadius(radius){var vertex=new Vector3();// iterate over the entire buffer and apply the radius to each vertex
  1188. for(var _i193=0;_i193<vertexBuffer.length;_i193+=3){vertex.x=vertexBuffer[_i193+0];vertex.y=vertexBuffer[_i193+1];vertex.z=vertexBuffer[_i193+2];vertex.normalize().multiplyScalar(radius);vertexBuffer[_i193+0]=vertex.x;vertexBuffer[_i193+1]=vertex.y;vertexBuffer[_i193+2]=vertex.z;}}function generateUVs(){var vertex=new Vector3();for(var _i194=0;_i194<vertexBuffer.length;_i194+=3){vertex.x=vertexBuffer[_i194+0];vertex.y=vertexBuffer[_i194+1];vertex.z=vertexBuffer[_i194+2];var u=azimuth(vertex)/2/Math.PI+0.5;var v=inclination(vertex)/Math.PI+0.5;uvBuffer.push(u,1-v);}correctUVs();correctSeam();}function correctSeam(){// handle case when face straddles the seam, see #3269
  1189. for(var _i195=0;_i195<uvBuffer.length;_i195+=6){// uv data of a single face
  1190. var x0=uvBuffer[_i195+0];var x1=uvBuffer[_i195+2];var x2=uvBuffer[_i195+4];var max=Math.max(x0,x1,x2);var min=Math.min(x0,x1,x2);// 0.9 is somewhat arbitrary
  1191. if(max>0.9&&min<0.1){if(x0<0.2)uvBuffer[_i195+0]+=1;if(x1<0.2)uvBuffer[_i195+2]+=1;if(x2<0.2)uvBuffer[_i195+4]+=1;}}}function pushVertex(vertex){vertexBuffer.push(vertex.x,vertex.y,vertex.z);}function getVertexByIndex(index,vertex){var stride=index*3;vertex.x=vertices[stride+0];vertex.y=vertices[stride+1];vertex.z=vertices[stride+2];}function correctUVs(){var a=new Vector3();var b=new Vector3();var c=new Vector3();var centroid=new Vector3();var uvA=new Vector2();var uvB=new Vector2();var uvC=new Vector2();for(var _i196=0,j=0;_i196<vertexBuffer.length;_i196+=9,j+=6){a.set(vertexBuffer[_i196+0],vertexBuffer[_i196+1],vertexBuffer[_i196+2]);b.set(vertexBuffer[_i196+3],vertexBuffer[_i196+4],vertexBuffer[_i196+5]);c.set(vertexBuffer[_i196+6],vertexBuffer[_i196+7],vertexBuffer[_i196+8]);uvA.set(uvBuffer[j+0],uvBuffer[j+1]);uvB.set(uvBuffer[j+2],uvBuffer[j+3]);uvC.set(uvBuffer[j+4],uvBuffer[j+5]);centroid.copy(a).add(b).add(c).divideScalar(3);var azi=azimuth(centroid);correctUV(uvA,j+0,a,azi);correctUV(uvB,j+2,b,azi);correctUV(uvC,j+4,c,azi);}}function correctUV(uv,stride,vector,azimuth){if(azimuth<0&&uv.x===1){uvBuffer[stride]=uv.x-1;}if(vector.x===0&&vector.z===0){uvBuffer[stride]=azimuth/2/Math.PI+0.5;}}// Angle around the Y axis, counter-clockwise when looking from above.
  1192. function azimuth(vector){return Math.atan2(vector.z,-vector.x);}// Angle above the XZ plane.
  1193. function inclination(vector){return Math.atan2(-vector.y,Math.sqrt(vector.x*vector.x+vector.z*vector.z));}}}class DodecahedronBufferGeometry extends PolyhedronBufferGeometry{constructor(){var radius=arguments.length>0&&arguments[0]!==undefined?arguments[0]:1;var detail=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var t=(1+Math.sqrt(5))/2;var r=1/t;var vertices=[// (±1, ±1, ±1)
  1194. -1,-1,-1,-1,-1,1,-1,1,-1,-1,1,1,1,-1,-1,1,-1,1,1,1,-1,1,1,1,// (0, ±1/φ, ±φ)
  1195. 0,-r,-t,0,-r,t,0,r,-t,0,r,t,// (±1/φ, ±φ, 0)
  1196. -r,-t,0,-r,t,0,r,-t,0,r,t,0,// (±φ, 0, ±1/φ)
  1197. -t,0,-r,t,0,-r,-t,0,r,t,0,r];var indices=[3,11,7,3,7,15,3,15,13,7,19,17,7,17,6,7,6,15,17,4,8,17,8,10,17,10,6,8,0,16,8,16,2,8,2,10,0,12,1,0,1,18,0,18,16,6,10,2,6,2,13,6,13,15,2,16,18,2,18,3,2,3,13,18,1,9,18,9,11,18,11,3,4,14,12,4,12,0,4,0,8,11,9,5,11,5,19,11,19,7,19,5,14,19,14,4,19,4,17,1,12,14,1,14,5,1,5,9];super(vertices,indices,radius,detail);this.type='DodecahedronBufferGeometry';this.parameters={radius:radius,detail:detail};}}class DodecahedronGeometry extends Geometry{constructor(radius,detail){super();this.type='DodecahedronGeometry';this.parameters={radius:radius,detail:detail};this.fromBufferGeometry(new DodecahedronBufferGeometry(radius,detail));this.mergeVertices();}}var _v0$2=new Vector3();var _v1$5=new Vector3();var _normal$1=new Vector3();var _triangle=new Triangle();class EdgesGeometry extends BufferGeometry{constructor(geometry,thresholdAngle){super();this.type='EdgesGeometry';this.parameters={thresholdAngle:thresholdAngle};thresholdAngle=thresholdAngle!==undefined?thresholdAngle:1;if(geometry.isGeometry){geometry=new BufferGeometry().fromGeometry(geometry);}var precisionPoints=4;var precision=Math.pow(10,precisionPoints);var thresholdDot=Math.cos(MathUtils.DEG2RAD*thresholdAngle);var indexAttr=geometry.getIndex();var positionAttr=geometry.getAttribute('position');var indexCount=indexAttr?indexAttr.count:positionAttr.count;var indexArr=[0,0,0];var vertKeys=['a','b','c'];var hashes=new Array(3);var edgeData={};var vertices=[];for(var _i197=0;_i197<indexCount;_i197+=3){if(indexAttr){indexArr[0]=indexAttr.getX(_i197);indexArr[1]=indexAttr.getX(_i197+1);indexArr[2]=indexAttr.getX(_i197+2);}else {indexArr[0]=_i197;indexArr[1]=_i197+1;indexArr[2]=_i197+2;}var{a,b,c}=_triangle;a.fromBufferAttribute(positionAttr,indexArr[0]);b.fromBufferAttribute(positionAttr,indexArr[1]);c.fromBufferAttribute(positionAttr,indexArr[2]);_triangle.getNormal(_normal$1);// create hashes for the edge from the vertices
  1198. hashes[0]="".concat(Math.round(a.x*precision),",").concat(Math.round(a.y*precision),",").concat(Math.round(a.z*precision));hashes[1]="".concat(Math.round(b.x*precision),",").concat(Math.round(b.y*precision),",").concat(Math.round(b.z*precision));hashes[2]="".concat(Math.round(c.x*precision),",").concat(Math.round(c.y*precision),",").concat(Math.round(c.z*precision));// skip degenerate triangles
  1199. if(hashes[0]===hashes[1]||hashes[1]===hashes[2]||hashes[2]===hashes[0]){continue;}// iterate over every edge
  1200. for(var j=0;j<3;j++){// get the first and next vertex making up the edge
  1201. var jNext=(j+1)%3;var vecHash0=hashes[j];var vecHash1=hashes[jNext];var v0=_triangle[vertKeys[j]];var v1=_triangle[vertKeys[jNext]];var hash="".concat(vecHash0,"_").concat(vecHash1);var reverseHash="".concat(vecHash1,"_").concat(vecHash0);if(reverseHash in edgeData&&edgeData[reverseHash]){// if we found a sibling edge add it into the vertex array if
  1202. // it meets the angle threshold and delete the edge from the map.
  1203. if(_normal$1.dot(edgeData[reverseHash].normal)<=thresholdDot){vertices.push(v0.x,v0.y,v0.z);vertices.push(v1.x,v1.y,v1.z);}edgeData[reverseHash]=null;}else if(!(hash in edgeData)){// if we've already got an edge here then skip adding a new one
  1204. edgeData[hash]={index0:indexArr[j],index1:indexArr[jNext],normal:_normal$1.clone()};}}}// iterate over all remaining, unmatched edges and add them to the vertex array
  1205. for(var key in edgeData){if(edgeData[key]){var{index0,index1}=edgeData[key];_v0$2.fromBufferAttribute(positionAttr,index0);_v1$5.fromBufferAttribute(positionAttr,index1);vertices.push(_v0$2.x,_v0$2.y,_v0$2.z);vertices.push(_v1$5.x,_v1$5.y,_v1$5.z);}}this.setAttribute('position',new Float32BufferAttribute(vertices,3));}}/**
  1206. * Port from https://github.com/mapbox/earcut (v2.2.2)
  1207. */var Earcut={triangulate:function triangulate(data,holeIndices,dim){dim=dim||2;var hasHoles=holeIndices&&holeIndices.length;var outerLen=hasHoles?holeIndices[0]*dim:data.length;var outerNode=linkedList(data,0,outerLen,dim,true);var triangles=[];if(!outerNode||outerNode.next===outerNode.prev)return triangles;var minX,minY,maxX,maxY,x,y,invSize;if(hasHoles)outerNode=eliminateHoles(data,holeIndices,outerNode,dim);// if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  1208. if(data.length>80*dim){minX=maxX=data[0];minY=maxY=data[1];for(var _i198=dim;_i198<outerLen;_i198+=dim){x=data[_i198];y=data[_i198+1];if(x<minX)minX=x;if(y<minY)minY=y;if(x>maxX)maxX=x;if(y>maxY)maxY=y;}// minX, minY and invSize are later used to transform coords into integers for z-order calculation
  1209. invSize=Math.max(maxX-minX,maxY-minY);invSize=invSize!==0?1/invSize:0;}earcutLinked(outerNode,triangles,dim,minX,minY,invSize);return triangles;}};// create a circular doubly linked list from polygon points in the specified winding order
  1210. function linkedList(data,start,end,dim,clockwise){var i,last;if(clockwise===signedArea(data,start,end,dim)>0){for(i=start;i<end;i+=dim)last=insertNode(i,data[i],data[i+1],last);}else {for(i=end-dim;i>=start;i-=dim)last=insertNode(i,data[i],data[i+1],last);}if(last&&equals(last,last.next)){removeNode(last);last=last.next;}return last;}// eliminate colinear or duplicate points
  1211. function filterPoints(start,end){if(!start)return start;if(!end)end=start;var p=start,again;do{again=false;if(!p.steiner&&(equals(p,p.next)||area(p.prev,p,p.next)===0)){removeNode(p);p=end=p.prev;if(p===p.next)break;again=true;}else {p=p.next;}}while(again||p!==end);return end;}// main ear slicing loop which triangulates a polygon (given as a linked list)
  1212. function earcutLinked(ear,triangles,dim,minX,minY,invSize,pass){if(!ear)return;// interlink polygon nodes in z-order
  1213. if(!pass&&invSize)indexCurve(ear,minX,minY,invSize);var stop=ear,prev,next;// iterate through ears, slicing them one by one
  1214. while(ear.prev!==ear.next){prev=ear.prev;next=ear.next;if(invSize?isEarHashed(ear,minX,minY,invSize):isEar(ear)){// cut off the triangle
  1215. triangles.push(prev.i/dim);triangles.push(ear.i/dim);triangles.push(next.i/dim);removeNode(ear);// skipping the next vertex leads to less sliver triangles
  1216. ear=next.next;stop=next.next;continue;}ear=next;// if we looped through the whole remaining polygon and can't find any more ears
  1217. if(ear===stop){// try filtering points and slicing again
  1218. if(!pass){earcutLinked(filterPoints(ear),triangles,dim,minX,minY,invSize,1);// if this didn't work, try curing all small self-intersections locally
  1219. }else if(pass===1){ear=cureLocalIntersections(filterPoints(ear),triangles,dim);earcutLinked(ear,triangles,dim,minX,minY,invSize,2);// as a last resort, try splitting the remaining polygon into two
  1220. }else if(pass===2){splitEarcut(ear,triangles,dim,minX,minY,invSize);}break;}}}// check whether a polygon node forms a valid ear with adjacent nodes
  1221. function isEar(ear){var a=ear.prev,b=ear,c=ear.next;if(area(a,b,c)>=0)return false;// reflex, can't be an ear
  1222. // now make sure we don't have other points inside the potential ear
  1223. var p=ear.next.next;while(p!==ear.prev){if(pointInTriangle(a.x,a.y,b.x,b.y,c.x,c.y,p.x,p.y)&&area(p.prev,p,p.next)>=0)return false;p=p.next;}return true;}function isEarHashed(ear,minX,minY,invSize){var a=ear.prev,b=ear,c=ear.next;if(area(a,b,c)>=0)return false;// reflex, can't be an ear
  1224. // triangle bbox; min & max are calculated like this for speed
  1225. var minTX=a.x<b.x?a.x<c.x?a.x:c.x:b.x<c.x?b.x:c.x,minTY=a.y<b.y?a.y<c.y?a.y:c.y:b.y<c.y?b.y:c.y,maxTX=a.x>b.x?a.x>c.x?a.x:c.x:b.x>c.x?b.x:c.x,maxTY=a.y>b.y?a.y>c.y?a.y:c.y:b.y>c.y?b.y:c.y;// z-order range for the current triangle bbox;
  1226. var minZ=zOrder(minTX,minTY,minX,minY,invSize),maxZ=zOrder(maxTX,maxTY,minX,minY,invSize);var p=ear.prevZ,n=ear.nextZ;// look for points inside the triangle in both directions
  1227. while(p&&p.z>=minZ&&n&&n.z<=maxZ){if(p!==ear.prev&&p!==ear.next&&pointInTriangle(a.x,a.y,b.x,b.y,c.x,c.y,p.x,p.y)&&area(p.prev,p,p.next)>=0)return false;p=p.prevZ;if(n!==ear.prev&&n!==ear.next&&pointInTriangle(a.x,a.y,b.x,b.y,c.x,c.y,n.x,n.y)&&area(n.prev,n,n.next)>=0)return false;n=n.nextZ;}// look for remaining points in decreasing z-order
  1228. while(p&&p.z>=minZ){if(p!==ear.prev&&p!==ear.next&&pointInTriangle(a.x,a.y,b.x,b.y,c.x,c.y,p.x,p.y)&&area(p.prev,p,p.next)>=0)return false;p=p.prevZ;}// look for remaining points in increasing z-order
  1229. while(n&&n.z<=maxZ){if(n!==ear.prev&&n!==ear.next&&pointInTriangle(a.x,a.y,b.x,b.y,c.x,c.y,n.x,n.y)&&area(n.prev,n,n.next)>=0)return false;n=n.nextZ;}return true;}// go through all polygon nodes and cure small local self-intersections
  1230. function cureLocalIntersections(start,triangles,dim){var p=start;do{var a=p.prev,b=p.next.next;if(!equals(a,b)&&intersects(a,p,p.next,b)&&locallyInside(a,b)&&locallyInside(b,a)){triangles.push(a.i/dim);triangles.push(p.i/dim);triangles.push(b.i/dim);// remove two nodes involved
  1231. removeNode(p);removeNode(p.next);p=start=b;}p=p.next;}while(p!==start);return filterPoints(p);}// try splitting polygon into two and triangulate them independently
  1232. function splitEarcut(start,triangles,dim,minX,minY,invSize){// look for a valid diagonal that divides the polygon into two
  1233. var a=start;do{var b=a.next.next;while(b!==a.prev){if(a.i!==b.i&&isValidDiagonal(a,b)){// split the polygon in two by the diagonal
  1234. var c=splitPolygon(a,b);// filter colinear points around the cuts
  1235. a=filterPoints(a,a.next);c=filterPoints(c,c.next);// run earcut on each half
  1236. earcutLinked(a,triangles,dim,minX,minY,invSize);earcutLinked(c,triangles,dim,minX,minY,invSize);return;}b=b.next;}a=a.next;}while(a!==start);}// link every hole into the outer loop, producing a single-ring polygon without holes
  1237. function eliminateHoles(data,holeIndices,outerNode,dim){var queue=[];var i,len,start,end,list;for(i=0,len=holeIndices.length;i<len;i++){start=holeIndices[i]*dim;end=i<len-1?holeIndices[i+1]*dim:data.length;list=linkedList(data,start,end,dim,false);if(list===list.next)list.steiner=true;queue.push(getLeftmost(list));}queue.sort(compareX);// process holes from left to right
  1238. for(i=0;i<queue.length;i++){eliminateHole(queue[i],outerNode);outerNode=filterPoints(outerNode,outerNode.next);}return outerNode;}function compareX(a,b){return a.x-b.x;}// find a bridge between vertices that connects hole with an outer ring and and link it
  1239. function eliminateHole(hole,outerNode){outerNode=findHoleBridge(hole,outerNode);if(outerNode){var b=splitPolygon(outerNode,hole);// filter collinear points around the cuts
  1240. filterPoints(outerNode,outerNode.next);filterPoints(b,b.next);}}// David Eberly's algorithm for finding a bridge between hole and outer polygon
  1241. function findHoleBridge(hole,outerNode){var p=outerNode;var hx=hole.x;var hy=hole.y;var qx=-Infinity,m;// find a segment intersected by a ray from the hole's leftmost point to the left;
  1242. // segment's endpoint with lesser x will be potential connection point
  1243. do{if(hy<=p.y&&hy>=p.next.y&&p.next.y!==p.y){var x=p.x+(hy-p.y)*(p.next.x-p.x)/(p.next.y-p.y);if(x<=hx&&x>qx){qx=x;if(x===hx){if(hy===p.y)return p;if(hy===p.next.y)return p.next;}m=p.x<p.next.x?p:p.next;}}p=p.next;}while(p!==outerNode);if(!m)return null;if(hx===qx)return m;// hole touches outer segment; pick leftmost endpoint
  1244. // look for points inside the triangle of hole point, segment intersection and endpoint;
  1245. // if there are no points found, we have a valid connection;
  1246. // otherwise choose the point of the minimum angle with the ray as connection point
  1247. var stop=m,mx=m.x,my=m.y;var tanMin=Infinity,tan;p=m;do{if(hx>=p.x&&p.x>=mx&&hx!==p.x&&pointInTriangle(hy<my?hx:qx,hy,mx,my,hy<my?qx:hx,hy,p.x,p.y)){tan=Math.abs(hy-p.y)/(hx-p.x);// tangential
  1248. if(locallyInside(p,hole)&&(tan<tanMin||tan===tanMin&&(p.x>m.x||p.x===m.x&&sectorContainsSector(m,p)))){m=p;tanMin=tan;}}p=p.next;}while(p!==stop);return m;}// whether sector in vertex m contains sector in vertex p in the same coordinates
  1249. function sectorContainsSector(m,p){return area(m.prev,m,p.prev)<0&&area(p.next,m,m.next)<0;}// interlink polygon nodes in z-order
  1250. function indexCurve(start,minX,minY,invSize){var p=start;do{if(p.z===null)p.z=zOrder(p.x,p.y,minX,minY,invSize);p.prevZ=p.prev;p.nextZ=p.next;p=p.next;}while(p!==start);p.prevZ.nextZ=null;p.prevZ=null;sortLinked(p);}// Simon Tatham's linked list merge sort algorithm
  1251. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  1252. function sortLinked(list){var i,p,q,e,tail,numMerges,pSize,qSize,inSize=1;do{p=list;list=null;tail=null;numMerges=0;while(p){numMerges++;q=p;pSize=0;for(i=0;i<inSize;i++){pSize++;q=q.nextZ;if(!q)break;}qSize=inSize;while(pSize>0||qSize>0&&q){if(pSize!==0&&(qSize===0||!q||p.z<=q.z)){e=p;p=p.nextZ;pSize--;}else {e=q;q=q.nextZ;qSize--;}if(tail)tail.nextZ=e;else list=e;e.prevZ=tail;tail=e;}p=q;}tail.nextZ=null;inSize*=2;}while(numMerges>1);return list;}// z-order of a point given coords and inverse of the longer side of data bbox
  1253. function zOrder(x,y,minX,minY,invSize){// coords are transformed into non-negative 15-bit integer range
  1254. x=32767*(x-minX)*invSize;y=32767*(y-minY)*invSize;x=(x|x<<8)&0x00FF00FF;x=(x|x<<4)&0x0F0F0F0F;x=(x|x<<2)&0x33333333;x=(x|x<<1)&0x55555555;y=(y|y<<8)&0x00FF00FF;y=(y|y<<4)&0x0F0F0F0F;y=(y|y<<2)&0x33333333;y=(y|y<<1)&0x55555555;return x|y<<1;}// find the leftmost node of a polygon ring
  1255. function getLeftmost(start){var p=start,leftmost=start;do{if(p.x<leftmost.x||p.x===leftmost.x&&p.y<leftmost.y)leftmost=p;p=p.next;}while(p!==start);return leftmost;}// check if a point lies within a convex triangle
  1256. function pointInTriangle(ax,ay,bx,by,cx,cy,px,py){return (cx-px)*(ay-py)-(ax-px)*(cy-py)>=0&&(ax-px)*(by-py)-(bx-px)*(ay-py)>=0&&(bx-px)*(cy-py)-(cx-px)*(by-py)>=0;}// check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  1257. function isValidDiagonal(a,b){return a.next.i!==b.i&&a.prev.i!==b.i&&!intersectsPolygon(a,b)&&(// dones't intersect other edges
  1258. locallyInside(a,b)&&locallyInside(b,a)&&middleInside(a,b)&&(// locally visible
  1259. area(a.prev,a,b.prev)||area(a,b.prev,b))||// does not create opposite-facing sectors
  1260. equals(a,b)&&area(a.prev,a,a.next)>0&&area(b.prev,b,b.next)>0);// special zero-length case
  1261. }// signed area of a triangle
  1262. function area(p,q,r){return (q.y-p.y)*(r.x-q.x)-(q.x-p.x)*(r.y-q.y);}// check if two points are equal
  1263. function equals(p1,p2){return p1.x===p2.x&&p1.y===p2.y;}// check if two segments intersect
  1264. function intersects(p1,q1,p2,q2){var o1=sign(area(p1,q1,p2));var o2=sign(area(p1,q1,q2));var o3=sign(area(p2,q2,p1));var o4=sign(area(p2,q2,q1));if(o1!==o2&&o3!==o4)return true;// general case
  1265. if(o1===0&&onSegment(p1,p2,q1))return true;// p1, q1 and p2 are collinear and p2 lies on p1q1
  1266. if(o2===0&&onSegment(p1,q2,q1))return true;// p1, q1 and q2 are collinear and q2 lies on p1q1
  1267. if(o3===0&&onSegment(p2,p1,q2))return true;// p2, q2 and p1 are collinear and p1 lies on p2q2
  1268. if(o4===0&&onSegment(p2,q1,q2))return true;// p2, q2 and q1 are collinear and q1 lies on p2q2
  1269. return false;}// for collinear points p, q, r, check if point q lies on segment pr
  1270. function onSegment(p,q,r){return q.x<=Math.max(p.x,r.x)&&q.x>=Math.min(p.x,r.x)&&q.y<=Math.max(p.y,r.y)&&q.y>=Math.min(p.y,r.y);}function sign(num){return num>0?1:num<0?-1:0;}// check if a polygon diagonal intersects any polygon segments
  1271. function intersectsPolygon(a,b){var p=a;do{if(p.i!==a.i&&p.next.i!==a.i&&p.i!==b.i&&p.next.i!==b.i&&intersects(p,p.next,a,b))return true;p=p.next;}while(p!==a);return false;}// check if a polygon diagonal is locally inside the polygon
  1272. function locallyInside(a,b){return area(a.prev,a,a.next)<0?area(a,b,a.next)>=0&&area(a,a.prev,b)>=0:area(a,b,a.prev)<0||area(a,a.next,b)<0;}// check if the middle point of a polygon diagonal is inside the polygon
  1273. function middleInside(a,b){var p=a,inside=false;var px=(a.x+b.x)/2,py=(a.y+b.y)/2;do{if(p.y>py!==p.next.y>py&&p.next.y!==p.y&&px<(p.next.x-p.x)*(py-p.y)/(p.next.y-p.y)+p.x)inside=!inside;p=p.next;}while(p!==a);return inside;}// link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  1274. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  1275. function splitPolygon(a,b){var a2=new Node(a.i,a.x,a.y),b2=new Node(b.i,b.x,b.y),an=a.next,bp=b.prev;a.next=b;b.prev=a;a2.next=an;an.prev=a2;b2.next=a2;a2.prev=b2;bp.next=b2;b2.prev=bp;return b2;}// create a node and optionally link it with previous one (in a circular doubly linked list)
  1276. function insertNode(i,x,y,last){var p=new Node(i,x,y);if(!last){p.prev=p;p.next=p;}else {p.next=last.next;p.prev=last;last.next.prev=p;last.next=p;}return p;}function removeNode(p){p.next.prev=p.prev;p.prev.next=p.next;if(p.prevZ)p.prevZ.nextZ=p.nextZ;if(p.nextZ)p.nextZ.prevZ=p.prevZ;}function Node(i,x,y){// vertex index in coordinates array
  1277. this.i=i;// vertex coordinates
  1278. this.x=x;this.y=y;// previous and next vertex nodes in a polygon ring
  1279. this.prev=null;this.next=null;// z-order curve value
  1280. this.z=null;// previous and next nodes in z-order
  1281. this.prevZ=null;this.nextZ=null;// indicates whether this is a steiner point
  1282. this.steiner=false;}function signedArea(data,start,end,dim){var sum=0;for(var _i199=start,j=end-dim;_i199<end;_i199+=dim){sum+=(data[j]-data[_i199])*(data[_i199+1]+data[j+1]);j=_i199;}return sum;}var ShapeUtils={// calculate area of the contour polygon
  1283. area:function area(contour){var n=contour.length;var a=0.0;for(var p=n-1,q=0;q<n;p=q++){a+=contour[p].x*contour[q].y-contour[q].x*contour[p].y;}return a*0.5;},isClockWise:function isClockWise(pts){return ShapeUtils.area(pts)<0;},triangulateShape:function triangulateShape(contour,holes){var vertices=[];// flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  1284. var holeIndices=[];// array of hole indices
  1285. var faces=[];// final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  1286. removeDupEndPts(contour);addContour(vertices,contour);//
  1287. var holeIndex=contour.length;holes.forEach(removeDupEndPts);for(var _i200=0;_i200<holes.length;_i200++){holeIndices.push(holeIndex);holeIndex+=holes[_i200].length;addContour(vertices,holes[_i200]);}//
  1288. var triangles=Earcut.triangulate(vertices,holeIndices);//
  1289. for(var _i201=0;_i201<triangles.length;_i201+=3){faces.push(triangles.slice(_i201,_i201+3));}return faces;}};function removeDupEndPts(points){var l=points.length;if(l>2&&points[l-1].equals(points[0])){points.pop();}}function addContour(vertices,contour){for(var _i202=0;_i202<contour.length;_i202++){vertices.push(contour[_i202].x);vertices.push(contour[_i202].y);}}/**
  1290. * Creates extruded geometry from a path shape.
  1291. *
  1292. * parameters = {
  1293. *
  1294. * curveSegments: <int>, // number of points on the curves
  1295. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  1296. * depth: <float>, // Depth to extrude the shape
  1297. *
  1298. * bevelEnabled: <bool>, // turn on bevel
  1299. * bevelThickness: <float>, // how deep into the original shape bevel goes
  1300. * bevelSize: <float>, // how far from shape outline (including bevelOffset) is bevel
  1301. * bevelOffset: <float>, // how far from shape outline does bevel start
  1302. * bevelSegments: <int>, // number of bevel layers
  1303. *
  1304. * extrudePath: <THREE.Curve> // curve to extrude shape along
  1305. *
  1306. * UVGenerator: <Object> // object that provides UV generator functions
  1307. *
  1308. * }
  1309. */class ExtrudeBufferGeometry extends BufferGeometry{constructor(shapes,options){super();this.type='ExtrudeBufferGeometry';this.parameters={shapes:shapes,options:options};shapes=Array.isArray(shapes)?shapes:[shapes];var scope=this;var verticesArray=[];var uvArray=[];for(var _i203=0,l=shapes.length;_i203<l;_i203++){var shape=shapes[_i203];addShape(shape);}// build geometry
  1310. this.setAttribute('position',new Float32BufferAttribute(verticesArray,3));this.setAttribute('uv',new Float32BufferAttribute(uvArray,2));this.computeVertexNormals();// functions
  1311. function addShape(shape){var placeholder=[];// options
  1312. var curveSegments=options.curveSegments!==undefined?options.curveSegments:12;var steps=options.steps!==undefined?options.steps:1;var depth=options.depth!==undefined?options.depth:100;var bevelEnabled=options.bevelEnabled!==undefined?options.bevelEnabled:true;var bevelThickness=options.bevelThickness!==undefined?options.bevelThickness:6;var bevelSize=options.bevelSize!==undefined?options.bevelSize:bevelThickness-2;var bevelOffset=options.bevelOffset!==undefined?options.bevelOffset:0;var bevelSegments=options.bevelSegments!==undefined?options.bevelSegments:3;var extrudePath=options.extrudePath;var uvgen=options.UVGenerator!==undefined?options.UVGenerator:WorldUVGenerator;// deprecated options
  1313. if(options.amount!==undefined){console.warn('THREE.ExtrudeBufferGeometry: amount has been renamed to depth.');depth=options.amount;}//
  1314. var extrudePts,extrudeByPath=false;var splineTube,binormal,normal,position2;if(extrudePath){extrudePts=extrudePath.getSpacedPoints(steps);extrudeByPath=true;bevelEnabled=false;// bevels not supported for path extrusion
  1315. // SETUP TNB variables
  1316. // TODO1 - have a .isClosed in spline?
  1317. splineTube=extrudePath.computeFrenetFrames(steps,false);// console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  1318. binormal=new Vector3();normal=new Vector3();position2=new Vector3();}// Safeguards if bevels are not enabled
  1319. if(!bevelEnabled){bevelSegments=0;bevelThickness=0;bevelSize=0;bevelOffset=0;}// Variables initialization
  1320. var shapePoints=shape.extractPoints(curveSegments);var vertices=shapePoints.shape;var holes=shapePoints.holes;var reverse=!ShapeUtils.isClockWise(vertices);if(reverse){vertices=vertices.reverse();// Maybe we should also check if holes are in the opposite direction, just to be safe ...
  1321. for(var h=0,hl=holes.length;h<hl;h++){var ahole=holes[h];if(ShapeUtils.isClockWise(ahole)){holes[h]=ahole.reverse();}}}var faces=ShapeUtils.triangulateShape(vertices,holes);/* Vertices */var contour=vertices;// vertices has all points but contour has only points of circumference
  1322. for(var _h=0,_hl=holes.length;_h<_hl;_h++){var _ahole=holes[_h];vertices=vertices.concat(_ahole);}function scalePt2(pt,vec,size){if(!vec)console.error('THREE.ExtrudeGeometry: vec does not exist');return vec.clone().multiplyScalar(size).add(pt);}var vlen=vertices.length,flen=faces.length;// Find directions for point movement
  1323. function getBevelVec(inPt,inPrev,inNext){// computes for inPt the corresponding point inPt' on a new contour
  1324. // shifted by 1 unit (length of normalized vector) to the left
  1325. // if we walk along contour clockwise, this new contour is outside the old one
  1326. //
  1327. // inPt' is the intersection of the two lines parallel to the two
  1328. // adjacent edges of inPt at a distance of 1 unit on the left side.
  1329. var v_trans_x,v_trans_y,shrink_by;// resulting translation vector for inPt
  1330. // good reading for geometry algorithms (here: line-line intersection)
  1331. // http://geomalgorithms.com/a05-_intersect-1.html
  1332. var v_prev_x=inPt.x-inPrev.x,v_prev_y=inPt.y-inPrev.y;var v_next_x=inNext.x-inPt.x,v_next_y=inNext.y-inPt.y;var v_prev_lensq=v_prev_x*v_prev_x+v_prev_y*v_prev_y;// check for collinear edges
  1333. var collinear0=v_prev_x*v_next_y-v_prev_y*v_next_x;if(Math.abs(collinear0)>Number.EPSILON){// not collinear
  1334. // length of vectors for normalizing
  1335. var v_prev_len=Math.sqrt(v_prev_lensq);var v_next_len=Math.sqrt(v_next_x*v_next_x+v_next_y*v_next_y);// shift adjacent points by unit vectors to the left
  1336. var ptPrevShift_x=inPrev.x-v_prev_y/v_prev_len;var ptPrevShift_y=inPrev.y+v_prev_x/v_prev_len;var ptNextShift_x=inNext.x-v_next_y/v_next_len;var ptNextShift_y=inNext.y+v_next_x/v_next_len;// scaling factor for v_prev to intersection point
  1337. var sf=((ptNextShift_x-ptPrevShift_x)*v_next_y-(ptNextShift_y-ptPrevShift_y)*v_next_x)/(v_prev_x*v_next_y-v_prev_y*v_next_x);// vector from inPt to intersection point
  1338. v_trans_x=ptPrevShift_x+v_prev_x*sf-inPt.x;v_trans_y=ptPrevShift_y+v_prev_y*sf-inPt.y;// Don't normalize!, otherwise sharp corners become ugly
  1339. // but prevent crazy spikes
  1340. var v_trans_lensq=v_trans_x*v_trans_x+v_trans_y*v_trans_y;if(v_trans_lensq<=2){return new Vector2(v_trans_x,v_trans_y);}else {shrink_by=Math.sqrt(v_trans_lensq/2);}}else {// handle special case of collinear edges
  1341. var direction_eq=false;// assumes: opposite
  1342. if(v_prev_x>Number.EPSILON){if(v_next_x>Number.EPSILON){direction_eq=true;}}else {if(v_prev_x<-Number.EPSILON){if(v_next_x<-Number.EPSILON){direction_eq=true;}}else {if(Math.sign(v_prev_y)===Math.sign(v_next_y)){direction_eq=true;}}}if(direction_eq){// console.log("Warning: lines are a straight sequence");
  1343. v_trans_x=-v_prev_y;v_trans_y=v_prev_x;shrink_by=Math.sqrt(v_prev_lensq);}else {// console.log("Warning: lines are a straight spike");
  1344. v_trans_x=v_prev_x;v_trans_y=v_prev_y;shrink_by=Math.sqrt(v_prev_lensq/2);}}return new Vector2(v_trans_x/shrink_by,v_trans_y/shrink_by);}var contourMovements=[];for(var _i204=0,il=contour.length,j=il-1,k=_i204+1;_i204<il;_i204++,j++,k++){if(j===il)j=0;if(k===il)k=0;// (j)---(i)---(k)
  1345. // console.log('i,j,k', i, j , k)
  1346. contourMovements[_i204]=getBevelVec(contour[_i204],contour[j],contour[k]);}var holesMovements=[];var oneHoleMovements,verticesMovements=contourMovements.concat();for(var _h2=0,_hl2=holes.length;_h2<_hl2;_h2++){var _ahole2=holes[_h2];oneHoleMovements=[];for(var _i205=0,_il26=_ahole2.length,_j12=_il26-1,_k=_i205+1;_i205<_il26;_i205++,_j12++,_k++){if(_j12===_il26)_j12=0;if(_k===_il26)_k=0;// (j)---(i)---(k)
  1347. oneHoleMovements[_i205]=getBevelVec(_ahole2[_i205],_ahole2[_j12],_ahole2[_k]);}holesMovements.push(oneHoleMovements);verticesMovements=verticesMovements.concat(oneHoleMovements);}// Loop bevelSegments, 1 for the front, 1 for the back
  1348. for(var b=0;b<bevelSegments;b++){//for ( b = bevelSegments; b > 0; b -- ) {
  1349. var t=b/bevelSegments;var z=bevelThickness*Math.cos(t*Math.PI/2);var _bs=bevelSize*Math.sin(t*Math.PI/2)+bevelOffset;// contract shape
  1350. for(var _i206=0,_il27=contour.length;_i206<_il27;_i206++){var vert=scalePt2(contour[_i206],contourMovements[_i206],_bs);v(vert.x,vert.y,-z);}// expand holes
  1351. for(var _h3=0,_hl3=holes.length;_h3<_hl3;_h3++){var _ahole3=holes[_h3];oneHoleMovements=holesMovements[_h3];for(var _i207=0,_il28=_ahole3.length;_i207<_il28;_i207++){var _vert=scalePt2(_ahole3[_i207],oneHoleMovements[_i207],_bs);v(_vert.x,_vert.y,-z);}}}var bs=bevelSize+bevelOffset;// Back facing vertices
  1352. for(var _i208=0;_i208<vlen;_i208++){var _vert2=bevelEnabled?scalePt2(vertices[_i208],verticesMovements[_i208],bs):vertices[_i208];if(!extrudeByPath){v(_vert2.x,_vert2.y,0);}else {// v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  1353. normal.copy(splineTube.normals[0]).multiplyScalar(_vert2.x);binormal.copy(splineTube.binormals[0]).multiplyScalar(_vert2.y);position2.copy(extrudePts[0]).add(normal).add(binormal);v(position2.x,position2.y,position2.z);}}// Add stepped vertices...
  1354. // Including front facing vertices
  1355. for(var s=1;s<=steps;s++){for(var _i209=0;_i209<vlen;_i209++){var _vert3=bevelEnabled?scalePt2(vertices[_i209],verticesMovements[_i209],bs):vertices[_i209];if(!extrudeByPath){v(_vert3.x,_vert3.y,depth/steps*s);}else {// v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  1356. normal.copy(splineTube.normals[s]).multiplyScalar(_vert3.x);binormal.copy(splineTube.binormals[s]).multiplyScalar(_vert3.y);position2.copy(extrudePts[s]).add(normal).add(binormal);v(position2.x,position2.y,position2.z);}}}// Add bevel segments planes
  1357. //for ( b = 1; b <= bevelSegments; b ++ ) {
  1358. for(var _b5=bevelSegments-1;_b5>=0;_b5--){var _t=_b5/bevelSegments;var _z2=bevelThickness*Math.cos(_t*Math.PI/2);var _bs2=bevelSize*Math.sin(_t*Math.PI/2)+bevelOffset;// contract shape
  1359. for(var _i210=0,_il29=contour.length;_i210<_il29;_i210++){var _vert4=scalePt2(contour[_i210],contourMovements[_i210],_bs2);v(_vert4.x,_vert4.y,depth+_z2);}// expand holes
  1360. for(var _h4=0,_hl4=holes.length;_h4<_hl4;_h4++){var _ahole4=holes[_h4];oneHoleMovements=holesMovements[_h4];for(var _i211=0,_il30=_ahole4.length;_i211<_il30;_i211++){var _vert5=scalePt2(_ahole4[_i211],oneHoleMovements[_i211],_bs2);if(!extrudeByPath){v(_vert5.x,_vert5.y,depth+_z2);}else {v(_vert5.x,_vert5.y+extrudePts[steps-1].y,extrudePts[steps-1].x+_z2);}}}}/* Faces */ // Top and bottom faces
  1361. if(!options.openEnded){//xzw add 可以选择开口,不创建Top and bottom faces
  1362. buildLidFaces();}// Sides faces
  1363. buildSideFaces();///// Internal functions
  1364. function buildLidFaces(){var start=verticesArray.length/3;if(bevelEnabled){var layer=0;// steps + 1
  1365. var offset=vlen*layer;// Bottom faces
  1366. for(var _i212=0;_i212<flen;_i212++){var face=faces[_i212];f3(face[2]+offset,face[1]+offset,face[0]+offset);}layer=steps+bevelSegments*2;offset=vlen*layer;// Top faces
  1367. for(var _i213=0;_i213<flen;_i213++){var _face5=faces[_i213];f3(_face5[0]+offset,_face5[1]+offset,_face5[2]+offset);}}else {// Bottom faces
  1368. for(var _i214=0;_i214<flen;_i214++){var _face6=faces[_i214];f3(_face6[2],_face6[1],_face6[0]);}// Top faces
  1369. for(var _i215=0;_i215<flen;_i215++){var _face7=faces[_i215];f3(_face7[0]+vlen*steps,_face7[1]+vlen*steps,_face7[2]+vlen*steps);}}scope.addGroup(start,verticesArray.length/3-start,0);}// Create faces for the z-sides of the shape
  1370. function buildSideFaces(){var start=verticesArray.length/3;var layeroffset=0;sidewalls(contour,layeroffset);layeroffset+=contour.length;for(var _h5=0,_hl5=holes.length;_h5<_hl5;_h5++){var _ahole5=holes[_h5];sidewalls(_ahole5,layeroffset);//, true
  1371. layeroffset+=_ahole5.length;}scope.addGroup(start,verticesArray.length/3-start,1);}function sidewalls(contour,layeroffset){var i=contour.length;var shapeDontClose=shape.dontClose;//xzw add不闭合
  1372. while(--i>=0){if(shapeDontClose&&i==0)break;//xzw add
  1373. var _j13=i;var _k2=i-1;if(_k2<0)_k2=contour.length-1;//console.log('b', i,j, i-1, k,vertices.length);
  1374. for(var _s4=0,sl=steps+bevelSegments*2;_s4<sl;_s4++){var slen1=vlen*_s4;var slen2=vlen*(_s4+1);var a=layeroffset+_j13+slen1,_b6=layeroffset+_k2+slen1,c=layeroffset+_k2+slen2,d=layeroffset+_j13+slen2;f4(a,_b6,c,d);}}}function v(x,y,z){placeholder.push(x);placeholder.push(y);placeholder.push(z);}function f3(a,b,c){addVertex(a);addVertex(b);addVertex(c);var nextIndex=verticesArray.length/3;var uvs=uvgen.generateTopUV(scope,verticesArray,nextIndex-3,nextIndex-2,nextIndex-1);addUV(uvs[0]);addUV(uvs[1]);addUV(uvs[2]);}function f4(a,b,c,d){addVertex(a);addVertex(b);addVertex(d);addVertex(b);addVertex(c);addVertex(d);var nextIndex=verticesArray.length/3;var uvs=uvgen.generateSideWallUV(scope,verticesArray,nextIndex-6,nextIndex-3,nextIndex-2,nextIndex-1);addUV(uvs[0]);addUV(uvs[1]);addUV(uvs[3]);addUV(uvs[1]);addUV(uvs[2]);addUV(uvs[3]);}function addVertex(index){verticesArray.push(placeholder[index*3+0]);verticesArray.push(placeholder[index*3+1]);verticesArray.push(placeholder[index*3+2]);}function addUV(vector2){uvArray.push(vector2.x);uvArray.push(vector2.y);}}}toJSON(){var data=BufferGeometry.prototype.toJSON.call(this);var shapes=this.parameters.shapes;var options=this.parameters.options;return toJSON(shapes,options,data);}}var WorldUVGenerator={generateTopUV:function generateTopUV(geometry,vertices,indexA,indexB,indexC){var a_x=vertices[indexA*3];var a_y=vertices[indexA*3+1];var b_x=vertices[indexB*3];var b_y=vertices[indexB*3+1];var c_x=vertices[indexC*3];var c_y=vertices[indexC*3+1];return [new Vector2(a_x,a_y),new Vector2(b_x,b_y),new Vector2(c_x,c_y)];},generateSideWallUV:function generateSideWallUV(geometry,vertices,indexA,indexB,indexC,indexD){var a_x=vertices[indexA*3];var a_y=vertices[indexA*3+1];var a_z=vertices[indexA*3+2];var b_x=vertices[indexB*3];var b_y=vertices[indexB*3+1];var b_z=vertices[indexB*3+2];var c_x=vertices[indexC*3];var c_y=vertices[indexC*3+1];var c_z=vertices[indexC*3+2];var d_x=vertices[indexD*3];var d_y=vertices[indexD*3+1];var d_z=vertices[indexD*3+2];if(Math.abs(a_y-b_y)<0.01){return [new Vector2(a_x,1-a_z),new Vector2(b_x,1-b_z),new Vector2(c_x,1-c_z),new Vector2(d_x,1-d_z)];}else {return [new Vector2(a_y,1-a_z),new Vector2(b_y,1-b_z),new Vector2(c_y,1-c_z),new Vector2(d_y,1-d_z)];}}};function toJSON(shapes,options,data){data.shapes=[];if(Array.isArray(shapes)){for(var _i216=0,l=shapes.length;_i216<l;_i216++){var shape=shapes[_i216];data.shapes.push(shape.uuid);}}else {data.shapes.push(shapes.uuid);}if(options.extrudePath!==undefined)data.options.extrudePath=options.extrudePath.toJSON();return data;}/**
  1375. * Creates extruded geometry from a path shape.
  1376. *
  1377. * parameters = {
  1378. *
  1379. * curveSegments: <int>, // number of points on the curves
  1380. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  1381. * depth: <float>, // Depth to extrude the shape
  1382. *
  1383. * bevelEnabled: <bool>, // turn on bevel
  1384. * bevelThickness: <float>, // how deep into the original shape bevel goes
  1385. * bevelSize: <float>, // how far from shape outline (including bevelOffset) is bevel
  1386. * bevelOffset: <float>, // how far from shape outline does bevel start
  1387. * bevelSegments: <int>, // number of bevel layers
  1388. *
  1389. * extrudePath: <THREE.Curve> // curve to extrude shape along
  1390. *
  1391. * UVGenerator: <Object> // object that provides UV generator functions
  1392. *
  1393. * }
  1394. */class ExtrudeGeometry extends Geometry{constructor(shapes,options){super();this.type='ExtrudeGeometry';this.parameters={shapes:shapes,options:options};this.fromBufferGeometry(new ExtrudeBufferGeometry(shapes,options));this.mergeVertices();}toJSON(){var data=super.toJSON();var shapes=this.parameters.shapes;var options=this.parameters.options;return toJSON$1(shapes,options,data);}}function toJSON$1(shapes,options,data){data.shapes=[];if(Array.isArray(shapes)){for(var _i217=0,l=shapes.length;_i217<l;_i217++){var shape=shapes[_i217];data.shapes.push(shape.uuid);}}else {data.shapes.push(shapes.uuid);}if(options.extrudePath!==undefined)data.options.extrudePath=options.extrudePath.toJSON();return data;}class IcosahedronBufferGeometry extends PolyhedronBufferGeometry{constructor(){var radius=arguments.length>0&&arguments[0]!==undefined?arguments[0]:1;var detail=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var t=(1+Math.sqrt(5))/2;var vertices=[-1,t,0,1,t,0,-1,-t,0,1,-t,0,0,-1,t,0,1,t,0,-1,-t,0,1,-t,t,0,-1,t,0,1,-t,0,-1,-t,0,1];var indices=[0,11,5,0,5,1,0,1,7,0,7,10,0,10,11,1,5,9,5,11,4,11,10,2,10,7,6,7,1,8,3,9,4,3,4,2,3,2,6,3,6,8,3,8,9,4,9,5,2,4,11,6,2,10,8,6,7,9,8,1];super(vertices,indices,radius,detail);this.type='IcosahedronBufferGeometry';this.parameters={radius:radius,detail:detail};}}class IcosahedronGeometry extends Geometry{constructor(radius,detail){super();this.type='IcosahedronGeometry';this.parameters={radius:radius,detail:detail};this.fromBufferGeometry(new IcosahedronBufferGeometry(radius,detail));this.mergeVertices();}}class LatheBufferGeometry extends BufferGeometry{constructor(points){var segments=arguments.length>1&&arguments[1]!==undefined?arguments[1]:12;var phiStart=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0;var phiLength=arguments.length>3&&arguments[3]!==undefined?arguments[3]:Math.PI*2;super();this.type='LatheBufferGeometry';this.parameters={points:points,segments:segments,phiStart:phiStart,phiLength:phiLength};segments=Math.floor(segments);// clamp phiLength so it's in range of [ 0, 2PI ]
  1395. phiLength=MathUtils.clamp(phiLength,0,Math.PI*2);// buffers
  1396. var indices=[];var vertices=[];var uvs=[];// helper variables
  1397. var inverseSegments=1.0/segments;var vertex=new Vector3();var uv=new Vector2();// generate vertices and uvs
  1398. for(var _i218=0;_i218<=segments;_i218++){var phi=phiStart+_i218*inverseSegments*phiLength;var sin=Math.sin(phi);var cos=Math.cos(phi);for(var j=0;j<=points.length-1;j++){// vertex
  1399. vertex.x=points[j].x*sin;vertex.y=points[j].y;vertex.z=points[j].x*cos;vertices.push(vertex.x,vertex.y,vertex.z);// uv
  1400. uv.x=_i218/segments;uv.y=j/(points.length-1);uvs.push(uv.x,uv.y);}}// indices
  1401. for(var _i219=0;_i219<segments;_i219++){for(var _j14=0;_j14<points.length-1;_j14++){var base=_j14+_i219*points.length;var a=base;var b=base+points.length;var c=base+points.length+1;var d=base+1;// faces
  1402. indices.push(a,b,d);indices.push(b,c,d);}}// build geometry
  1403. this.setIndex(indices);this.setAttribute('position',new Float32BufferAttribute(vertices,3));this.setAttribute('uv',new Float32BufferAttribute(uvs,2));// generate normals
  1404. this.computeVertexNormals();// if the geometry is closed, we need to average the normals along the seam.
  1405. // because the corresponding vertices are identical (but still have different UVs).
  1406. if(phiLength===Math.PI*2){var normals=this.attributes.normal.array;var n1=new Vector3();var n2=new Vector3();var n=new Vector3();// this is the buffer offset for the last line of vertices
  1407. var _base=segments*points.length*3;for(var _i220=0,_j15=0;_i220<points.length;_i220++,_j15+=3){// select the normal of the vertex in the first line
  1408. n1.x=normals[_j15+0];n1.y=normals[_j15+1];n1.z=normals[_j15+2];// select the normal of the vertex in the last line
  1409. n2.x=normals[_base+_j15+0];n2.y=normals[_base+_j15+1];n2.z=normals[_base+_j15+2];// average normals
  1410. n.addVectors(n1,n2).normalize();// assign the new values to both normals
  1411. normals[_j15+0]=normals[_base+_j15+0]=n.x;normals[_j15+1]=normals[_base+_j15+1]=n.y;normals[_j15+2]=normals[_base+_j15+2]=n.z;}}}}class LatheGeometry extends Geometry{constructor(points,segments,phiStart,phiLength){super();this.type='LatheGeometry';this.parameters={points:points,segments:segments,phiStart:phiStart,phiLength:phiLength};this.fromBufferGeometry(new LatheBufferGeometry(points,segments,phiStart,phiLength));this.mergeVertices();}}class OctahedronBufferGeometry extends PolyhedronBufferGeometry{constructor(){var radius=arguments.length>0&&arguments[0]!==undefined?arguments[0]:1;var detail=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var vertices=[1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1];var indices=[0,2,4,0,4,3,0,3,5,0,5,2,1,2,5,1,5,3,1,3,4,1,4,2];super(vertices,indices,radius,detail);this.type='OctahedronBufferGeometry';this.parameters={radius:radius,detail:detail};}}class OctahedronGeometry extends Geometry{constructor(radius,detail){super();this.type='OctahedronGeometry';this.parameters={radius:radius,detail:detail};this.fromBufferGeometry(new OctahedronBufferGeometry(radius,detail));this.mergeVertices();}}/**
  1412. * Parametric Surfaces Geometry
  1413. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  1414. */function ParametricBufferGeometry(func,slices,stacks){BufferGeometry.call(this);this.type='ParametricBufferGeometry';this.parameters={func:func,slices:slices,stacks:stacks};// buffers
  1415. var indices=[];var vertices=[];var normals=[];var uvs=[];var EPS=0.00001;var normal=new Vector3();var p0=new Vector3(),p1=new Vector3();var pu=new Vector3(),pv=new Vector3();if(func.length<3){console.error('THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.');}// generate vertices, normals and uvs
  1416. var sliceCount=slices+1;for(var _i221=0;_i221<=stacks;_i221++){var v=_i221/stacks;for(var j=0;j<=slices;j++){var u=j/slices;// vertex
  1417. func(u,v,p0);vertices.push(p0.x,p0.y,p0.z);// normal
  1418. // approximate tangent vectors via finite differences
  1419. if(u-EPS>=0){func(u-EPS,v,p1);pu.subVectors(p0,p1);}else {func(u+EPS,v,p1);pu.subVectors(p1,p0);}if(v-EPS>=0){func(u,v-EPS,p1);pv.subVectors(p0,p1);}else {func(u,v+EPS,p1);pv.subVectors(p1,p0);}// cross product of tangent vectors returns surface normal
  1420. normal.crossVectors(pu,pv).normalize();normals.push(normal.x,normal.y,normal.z);// uv
  1421. uvs.push(u,v);}}// generate indices
  1422. for(var _i222=0;_i222<stacks;_i222++){for(var _j16=0;_j16<slices;_j16++){var a=_i222*sliceCount+_j16;var b=_i222*sliceCount+_j16+1;var c=(_i222+1)*sliceCount+_j16+1;var d=(_i222+1)*sliceCount+_j16;// faces one and two
  1423. indices.push(a,b,d);indices.push(b,c,d);}}// build geometry
  1424. this.setIndex(indices);this.setAttribute('position',new Float32BufferAttribute(vertices,3));this.setAttribute('normal',new Float32BufferAttribute(normals,3));this.setAttribute('uv',new Float32BufferAttribute(uvs,2));}ParametricBufferGeometry.prototype=Object.create(BufferGeometry.prototype);ParametricBufferGeometry.prototype.constructor=ParametricBufferGeometry;/**
  1425. * Parametric Surfaces Geometry
  1426. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  1427. */function ParametricGeometry(func,slices,stacks){Geometry.call(this);this.type='ParametricGeometry';this.parameters={func:func,slices:slices,stacks:stacks};this.fromBufferGeometry(new ParametricBufferGeometry(func,slices,stacks));this.mergeVertices();}ParametricGeometry.prototype=Object.create(Geometry.prototype);ParametricGeometry.prototype.constructor=ParametricGeometry;class PlaneGeometry extends Geometry{constructor(width,height,widthSegments,heightSegments){super();this.type='PlaneGeometry';this.parameters={width:width,height:height,widthSegments:widthSegments,heightSegments:heightSegments};this.fromBufferGeometry(new PlaneBufferGeometry(width,height,widthSegments,heightSegments));this.mergeVertices();}}class PolyhedronGeometry extends Geometry{constructor(vertices,indices,radius,detail){super();this.type='PolyhedronGeometry';this.parameters={vertices:vertices,indices:indices,radius:radius,detail:detail};this.fromBufferGeometry(new PolyhedronBufferGeometry(vertices,indices,radius,detail));this.mergeVertices();}}class RingBufferGeometry extends BufferGeometry{constructor(){var innerRadius=arguments.length>0&&arguments[0]!==undefined?arguments[0]:0.5;var outerRadius=arguments.length>1&&arguments[1]!==undefined?arguments[1]:1;var thetaSegments=arguments.length>2&&arguments[2]!==undefined?arguments[2]:8;var phiSegments=arguments.length>3&&arguments[3]!==undefined?arguments[3]:1;var thetaStart=arguments.length>4&&arguments[4]!==undefined?arguments[4]:0;var thetaLength=arguments.length>5&&arguments[5]!==undefined?arguments[5]:Math.PI*2;super();this.type='RingBufferGeometry';this.parameters={innerRadius:innerRadius,outerRadius:outerRadius,thetaSegments:thetaSegments,phiSegments:phiSegments,thetaStart:thetaStart,thetaLength:thetaLength};thetaSegments=Math.max(3,thetaSegments);phiSegments=Math.max(1,phiSegments);// buffers
  1428. var indices=[];var vertices=[];var normals=[];var uvs=[];// some helper variables
  1429. var radius=innerRadius;var radiusStep=(outerRadius-innerRadius)/phiSegments;var vertex=new Vector3();var uv=new Vector2();// generate vertices, normals and uvs
  1430. for(var j=0;j<=phiSegments;j++){for(var _i223=0;_i223<=thetaSegments;_i223++){// values are generate from the inside of the ring to the outside
  1431. var segment=thetaStart+_i223/thetaSegments*thetaLength;// vertex
  1432. vertex.x=radius*Math.cos(segment);vertex.y=radius*Math.sin(segment);vertices.push(vertex.x,vertex.y,vertex.z);// normal
  1433. normals.push(0,0,1);// uv
  1434. uv.x=(vertex.x/outerRadius+1)/2;uv.y=(vertex.y/outerRadius+1)/2;uvs.push(uv.x,uv.y);}// increase the radius for next row of vertices
  1435. radius+=radiusStep;}// indices
  1436. for(var _j17=0;_j17<phiSegments;_j17++){var thetaSegmentLevel=_j17*(thetaSegments+1);for(var _i224=0;_i224<thetaSegments;_i224++){var _segment=_i224+thetaSegmentLevel;var a=_segment;var b=_segment+thetaSegments+1;var c=_segment+thetaSegments+2;var d=_segment+1;// faces
  1437. indices.push(a,b,d);indices.push(b,c,d);}}// build geometry
  1438. this.setIndex(indices);this.setAttribute('position',new Float32BufferAttribute(vertices,3));this.setAttribute('normal',new Float32BufferAttribute(normals,3));this.setAttribute('uv',new Float32BufferAttribute(uvs,2));}}class RingGeometry extends Geometry{constructor(innerRadius,outerRadius,thetaSegments,phiSegments,thetaStart,thetaLength){super();this.type='RingGeometry';this.parameters={innerRadius:innerRadius,outerRadius:outerRadius,thetaSegments:thetaSegments,phiSegments:phiSegments,thetaStart:thetaStart,thetaLength:thetaLength};this.fromBufferGeometry(new RingBufferGeometry(innerRadius,outerRadius,thetaSegments,phiSegments,thetaStart,thetaLength));this.mergeVertices();}}class ShapeBufferGeometry extends BufferGeometry{constructor(shapes){var curveSegments=arguments.length>1&&arguments[1]!==undefined?arguments[1]:12;super();this.type='ShapeBufferGeometry';this.parameters={shapes:shapes,curveSegments:curveSegments};// buffers
  1439. var indices=[];var vertices=[];var normals=[];var uvs=[];// helper variables
  1440. var groupStart=0;var groupCount=0;// allow single and array values for "shapes" parameter
  1441. if(Array.isArray(shapes)===false){addShape(shapes);}else {for(var _i225=0;_i225<shapes.length;_i225++){addShape(shapes[_i225]);this.addGroup(groupStart,groupCount,_i225);// enables MultiMaterial support
  1442. groupStart+=groupCount;groupCount=0;}}// build geometry
  1443. this.setIndex(indices);this.setAttribute('position',new Float32BufferAttribute(vertices,3));this.setAttribute('normal',new Float32BufferAttribute(normals,3));this.setAttribute('uv',new Float32BufferAttribute(uvs,2));// helper functions
  1444. function addShape(shape){var indexOffset=vertices.length/3;var points=shape.extractPoints(curveSegments);var shapeVertices=points.shape;var shapeHoles=points.holes;// check direction of vertices
  1445. if(ShapeUtils.isClockWise(shapeVertices)===false){shapeVertices=shapeVertices.reverse();}for(var _i226=0,l=shapeHoles.length;_i226<l;_i226++){var shapeHole=shapeHoles[_i226];if(ShapeUtils.isClockWise(shapeHole)===true){shapeHoles[_i226]=shapeHole.reverse();}}var faces=ShapeUtils.triangulateShape(shapeVertices,shapeHoles);// join vertices of inner and outer paths to a single array
  1446. for(var _i227=0,_l10=shapeHoles.length;_i227<_l10;_i227++){var _shapeHole=shapeHoles[_i227];shapeVertices=shapeVertices.concat(_shapeHole);}// vertices, normals, uvs
  1447. for(var _i228=0,_l11=shapeVertices.length;_i228<_l11;_i228++){var vertex=shapeVertices[_i228];vertices.push(vertex.x,vertex.y,0);normals.push(0,0,1);uvs.push(vertex.x,vertex.y);// world uvs
  1448. }// incides
  1449. for(var _i229=0,_l12=faces.length;_i229<_l12;_i229++){var face=faces[_i229];var a=face[0]+indexOffset;var b=face[1]+indexOffset;var c=face[2]+indexOffset;indices.push(a,b,c);groupCount+=3;}}}toJSON(){var data=BufferGeometry.prototype.toJSON.call(this);var shapes=this.parameters.shapes;return toJSON$2(shapes,data);}}function toJSON$2(shapes,data){data.shapes=[];if(Array.isArray(shapes)){for(var _i230=0,l=shapes.length;_i230<l;_i230++){var shape=shapes[_i230];data.shapes.push(shape.uuid);}}else {data.shapes.push(shapes.uuid);}return data;}class ShapeGeometry extends Geometry{constructor(shapes,curveSegments){super();this.type='ShapeGeometry';if(typeof curveSegments==='object'){console.warn('THREE.ShapeGeometry: Options parameter has been removed.');curveSegments=curveSegments.curveSegments;}this.parameters={shapes:shapes,curveSegments:curveSegments};this.fromBufferGeometry(new ShapeBufferGeometry(shapes,curveSegments));this.mergeVertices();}toJSON(){var data=Geometry.prototype.toJSON.call(this);var shapes=this.parameters.shapes;return toJSON$3(shapes,data);}}function toJSON$3(shapes,data){data.shapes=[];if(Array.isArray(shapes)){for(var _i231=0,l=shapes.length;_i231<l;_i231++){var shape=shapes[_i231];data.shapes.push(shape.uuid);}}else {data.shapes.push(shapes.uuid);}return data;}class SphereBufferGeometry extends BufferGeometry{constructor(){var radius=arguments.length>0&&arguments[0]!==undefined?arguments[0]:1;var widthSegments=arguments.length>1&&arguments[1]!==undefined?arguments[1]:8;var heightSegments=arguments.length>2&&arguments[2]!==undefined?arguments[2]:6;var phiStart=arguments.length>3&&arguments[3]!==undefined?arguments[3]:0;var phiLength=arguments.length>4&&arguments[4]!==undefined?arguments[4]:Math.PI*2;var thetaStart=arguments.length>5&&arguments[5]!==undefined?arguments[5]:0;var thetaLength=arguments.length>6&&arguments[6]!==undefined?arguments[6]:Math.PI;super();this.type='SphereBufferGeometry';this.parameters={radius:radius,widthSegments:widthSegments,heightSegments:heightSegments,phiStart:phiStart,phiLength:phiLength,thetaStart:thetaStart,thetaLength:thetaLength};widthSegments=Math.max(3,Math.floor(widthSegments));heightSegments=Math.max(2,Math.floor(heightSegments));var thetaEnd=Math.min(thetaStart+thetaLength,Math.PI);var index=0;var grid=[];var vertex=new Vector3();var normal=new Vector3();// buffers
  1450. var indices=[];var vertices=[];var normals=[];var uvs=[];// generate vertices, normals and uvs
  1451. for(var iy=0;iy<=heightSegments;iy++){var verticesRow=[];var v=iy/heightSegments;// special case for the poles
  1452. var uOffset=0;if(iy==0&&thetaStart==0){uOffset=0.5/widthSegments;}else if(iy==heightSegments&&thetaEnd==Math.PI){uOffset=-0.5/widthSegments;}for(var ix=0;ix<=widthSegments;ix++){var u=ix/widthSegments;// vertex
  1453. vertex.x=-radius*Math.cos(phiStart+u*phiLength)*Math.sin(thetaStart+v*thetaLength);vertex.y=radius*Math.cos(thetaStart+v*thetaLength);vertex.z=radius*Math.sin(phiStart+u*phiLength)*Math.sin(thetaStart+v*thetaLength);vertices.push(vertex.x,vertex.y,vertex.z);// normal
  1454. normal.copy(vertex).normalize();normals.push(normal.x,normal.y,normal.z);// uv
  1455. uvs.push(u+uOffset,1-v);verticesRow.push(index++);}grid.push(verticesRow);}// indices
  1456. for(var _iy3=0;_iy3<heightSegments;_iy3++){for(var _ix3=0;_ix3<widthSegments;_ix3++){var a=grid[_iy3][_ix3+1];var b=grid[_iy3][_ix3];var c=grid[_iy3+1][_ix3];var d=grid[_iy3+1][_ix3+1];if(_iy3!==0||thetaStart>0)indices.push(a,b,d);if(_iy3!==heightSegments-1||thetaEnd<Math.PI)indices.push(b,c,d);}}// build geometry
  1457. this.setIndex(indices);this.setAttribute('position',new Float32BufferAttribute(vertices,3));this.setAttribute('normal',new Float32BufferAttribute(normals,3));this.setAttribute('uv',new Float32BufferAttribute(uvs,2));}}class SphereGeometry extends Geometry{constructor(radius,widthSegments,heightSegments,phiStart,phiLength,thetaStart,thetaLength){super();this.type='SphereGeometry';this.parameters={radius:radius,widthSegments:widthSegments,heightSegments:heightSegments,phiStart:phiStart,phiLength:phiLength,thetaStart:thetaStart,thetaLength:thetaLength};this.fromBufferGeometry(new SphereBufferGeometry(radius,widthSegments,heightSegments,phiStart,phiLength,thetaStart,thetaLength));this.mergeVertices();}}class TetrahedronBufferGeometry extends PolyhedronBufferGeometry{constructor(){var radius=arguments.length>0&&arguments[0]!==undefined?arguments[0]:1;var detail=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var vertices=[1,1,1,-1,-1,1,-1,1,-1,1,-1,-1];var indices=[2,1,0,0,3,2,1,3,0,2,3,1];super(vertices,indices,radius,detail);this.type='TetrahedronBufferGeometry';this.parameters={radius:radius,detail:detail};}}class TetrahedronGeometry extends Geometry{constructor(radius,detail){super();this.type='TetrahedronGeometry';this.parameters={radius:radius,detail:detail};this.fromBufferGeometry(new TetrahedronBufferGeometry(radius,detail));this.mergeVertices();}}/**
  1458. * Text = 3D Text
  1459. *
  1460. * parameters = {
  1461. * font: <THREE.Font>, // font
  1462. *
  1463. * size: <float>, // size of the text
  1464. * height: <float>, // thickness to extrude text
  1465. * curveSegments: <int>, // number of points on the curves
  1466. *
  1467. * bevelEnabled: <bool>, // turn on bevel
  1468. * bevelThickness: <float>, // how deep into text bevel goes
  1469. * bevelSize: <float>, // how far from text outline (including bevelOffset) is bevel
  1470. * bevelOffset: <float> // how far from text outline does bevel start
  1471. * }
  1472. */class TextBufferGeometry extends ExtrudeBufferGeometry{constructor(text){var parameters=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var font=parameters.font;if(!(font&&font.isFont)){console.error('THREE.TextGeometry: font parameter is not an instance of THREE.Font.');return new BufferGeometry();}var shapes=font.generateShapes(text,parameters.size);// translate parameters to ExtrudeGeometry API
  1473. parameters.depth=parameters.height!==undefined?parameters.height:50;// defaults
  1474. if(parameters.bevelThickness===undefined)parameters.bevelThickness=10;if(parameters.bevelSize===undefined)parameters.bevelSize=8;if(parameters.bevelEnabled===undefined)parameters.bevelEnabled=false;super(shapes,parameters);this.type='TextBufferGeometry';}}/**
  1475. * Text = 3D Text
  1476. *
  1477. * parameters = {
  1478. * font: <THREE.Font>, // font
  1479. *
  1480. * size: <float>, // size of the text
  1481. * height: <float>, // thickness to extrude text
  1482. * curveSegments: <int>, // number of points on the curves
  1483. *
  1484. * bevelEnabled: <bool>, // turn on bevel
  1485. * bevelThickness: <float>, // how deep into text bevel goes
  1486. * bevelSize: <float>, // how far from text outline (including bevelOffset) is bevel
  1487. * bevelOffset: <float> // how far from text outline does bevel start
  1488. * }
  1489. */class TextGeometry extends Geometry{constructor(text,parameters){super();this.type='TextGeometry';this.parameters={text:text,parameters:parameters};this.fromBufferGeometry(new TextBufferGeometry(text,parameters));this.mergeVertices();}}class TorusBufferGeometry extends BufferGeometry{constructor(){var radius=arguments.length>0&&arguments[0]!==undefined?arguments[0]:1;var tube=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0.4;var radialSegments=arguments.length>2&&arguments[2]!==undefined?arguments[2]:8;var tubularSegments=arguments.length>3&&arguments[3]!==undefined?arguments[3]:6;var arc=arguments.length>4&&arguments[4]!==undefined?arguments[4]:Math.PI*2;super();this.type='TorusBufferGeometry';this.parameters={radius:radius,tube:tube,radialSegments:radialSegments,tubularSegments:tubularSegments,arc:arc};radialSegments=Math.floor(radialSegments);tubularSegments=Math.floor(tubularSegments);// buffers
  1490. var indices=[];var vertices=[];var normals=[];var uvs=[];// helper variables
  1491. var center=new Vector3();var vertex=new Vector3();var normal=new Vector3();// generate vertices, normals and uvs
  1492. for(var j=0;j<=radialSegments;j++){for(var _i232=0;_i232<=tubularSegments;_i232++){var u=_i232/tubularSegments*arc;var v=j/radialSegments*Math.PI*2;// vertex
  1493. vertex.x=(radius+tube*Math.cos(v))*Math.cos(u);vertex.y=(radius+tube*Math.cos(v))*Math.sin(u);vertex.z=tube*Math.sin(v);vertices.push(vertex.x,vertex.y,vertex.z);// normal
  1494. center.x=radius*Math.cos(u);center.y=radius*Math.sin(u);normal.subVectors(vertex,center).normalize();normals.push(normal.x,normal.y,normal.z);// uv
  1495. uvs.push(_i232/tubularSegments);uvs.push(j/radialSegments);}}// generate indices
  1496. for(var _j18=1;_j18<=radialSegments;_j18++){for(var _i233=1;_i233<=tubularSegments;_i233++){// indices
  1497. var a=(tubularSegments+1)*_j18+_i233-1;var b=(tubularSegments+1)*(_j18-1)+_i233-1;var c=(tubularSegments+1)*(_j18-1)+_i233;var d=(tubularSegments+1)*_j18+_i233;// faces
  1498. indices.push(a,b,d);indices.push(b,c,d);}}// build geometry
  1499. this.setIndex(indices);this.setAttribute('position',new Float32BufferAttribute(vertices,3));this.setAttribute('normal',new Float32BufferAttribute(normals,3));this.setAttribute('uv',new Float32BufferAttribute(uvs,2));}}class TorusGeometry extends Geometry{constructor(radius,tube,radialSegments,tubularSegments,arc){super();this.type='TorusGeometry';this.parameters={radius:radius,tube:tube,radialSegments:radialSegments,tubularSegments:tubularSegments,arc:arc};this.fromBufferGeometry(new TorusBufferGeometry(radius,tube,radialSegments,tubularSegments,arc));this.mergeVertices();}}class TorusKnotBufferGeometry extends BufferGeometry{constructor(){var radius=arguments.length>0&&arguments[0]!==undefined?arguments[0]:1;var tube=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0.4;var tubularSegments=arguments.length>2&&arguments[2]!==undefined?arguments[2]:64;var radialSegments=arguments.length>3&&arguments[3]!==undefined?arguments[3]:8;var p=arguments.length>4&&arguments[4]!==undefined?arguments[4]:2;var q=arguments.length>5&&arguments[5]!==undefined?arguments[5]:3;super();this.type='TorusKnotBufferGeometry';this.parameters={radius:radius,tube:tube,tubularSegments:tubularSegments,radialSegments:radialSegments,p:p,q:q};tubularSegments=Math.floor(tubularSegments);radialSegments=Math.floor(radialSegments);// buffers
  1500. var indices=[];var vertices=[];var normals=[];var uvs=[];// helper variables
  1501. var vertex=new Vector3();var normal=new Vector3();var P1=new Vector3();var P2=new Vector3();var B=new Vector3();var T=new Vector3();var N=new Vector3();// generate vertices, normals and uvs
  1502. for(var _i234=0;_i234<=tubularSegments;++_i234){// the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  1503. var u=_i234/tubularSegments*p*Math.PI*2;// now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  1504. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  1505. calculatePositionOnCurve(u,p,q,radius,P1);calculatePositionOnCurve(u+0.01,p,q,radius,P2);// calculate orthonormal basis
  1506. T.subVectors(P2,P1);N.addVectors(P2,P1);B.crossVectors(T,N);N.crossVectors(B,T);// normalize B, N. T can be ignored, we don't use it
  1507. B.normalize();N.normalize();for(var j=0;j<=radialSegments;++j){// now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  1508. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  1509. var v=j/radialSegments*Math.PI*2;var cx=-tube*Math.cos(v);var cy=tube*Math.sin(v);// now calculate the final vertex position.
  1510. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  1511. vertex.x=P1.x+(cx*N.x+cy*B.x);vertex.y=P1.y+(cx*N.y+cy*B.y);vertex.z=P1.z+(cx*N.z+cy*B.z);vertices.push(vertex.x,vertex.y,vertex.z);// normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  1512. normal.subVectors(vertex,P1).normalize();normals.push(normal.x,normal.y,normal.z);// uv
  1513. uvs.push(_i234/tubularSegments);uvs.push(j/radialSegments);}}// generate indices
  1514. for(var _j19=1;_j19<=tubularSegments;_j19++){for(var _i235=1;_i235<=radialSegments;_i235++){// indices
  1515. var a=(radialSegments+1)*(_j19-1)+(_i235-1);var b=(radialSegments+1)*_j19+(_i235-1);var c=(radialSegments+1)*_j19+_i235;var d=(radialSegments+1)*(_j19-1)+_i235;// faces
  1516. indices.push(a,b,d);indices.push(b,c,d);}}// build geometry
  1517. this.setIndex(indices);this.setAttribute('position',new Float32BufferAttribute(vertices,3));this.setAttribute('normal',new Float32BufferAttribute(normals,3));this.setAttribute('uv',new Float32BufferAttribute(uvs,2));// this function calculates the current position on the torus curve
  1518. function calculatePositionOnCurve(u,p,q,radius,position){var cu=Math.cos(u);var su=Math.sin(u);var quOverP=q/p*u;var cs=Math.cos(quOverP);position.x=radius*(2+cs)*0.5*cu;position.y=radius*(2+cs)*su*0.5;position.z=radius*Math.sin(quOverP)*0.5;}}}class TorusKnotGeometry extends Geometry{constructor(radius,tube,tubularSegments,radialSegments,p,q,heightScale){super();this.type='TorusKnotGeometry';this.parameters={radius:radius,tube:tube,tubularSegments:tubularSegments,radialSegments:radialSegments,p:p,q:q};if(heightScale!==undefined)console.warn('THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.');this.fromBufferGeometry(new TorusKnotBufferGeometry(radius,tube,tubularSegments,radialSegments,p,q));this.mergeVertices();}}class TubeBufferGeometry extends BufferGeometry{constructor(path){var tubularSegments=arguments.length>1&&arguments[1]!==undefined?arguments[1]:64;var radius=arguments.length>2&&arguments[2]!==undefined?arguments[2]:1;var radialSegments=arguments.length>3&&arguments[3]!==undefined?arguments[3]:8;var closed=arguments.length>4&&arguments[4]!==undefined?arguments[4]:false;super();this.type='TubeBufferGeometry';this.parameters={path:path,tubularSegments:tubularSegments,radius:radius,radialSegments:radialSegments,closed:closed};var frames=path.computeFrenetFrames(tubularSegments,closed);// expose internals
  1519. this.tangents=frames.tangents;this.normals=frames.normals;this.binormals=frames.binormals;// helper variables
  1520. var vertex=new Vector3();var normal=new Vector3();var uv=new Vector2();var P=new Vector3();// buffer
  1521. var vertices=[];var normals=[];var uvs=[];var indices=[];// create buffer data
  1522. generateBufferData();// build geometry
  1523. this.setIndex(indices);this.setAttribute('position',new Float32BufferAttribute(vertices,3));this.setAttribute('normal',new Float32BufferAttribute(normals,3));this.setAttribute('uv',new Float32BufferAttribute(uvs,2));// functions
  1524. function generateBufferData(){for(var _i236=0;_i236<tubularSegments;_i236++){generateSegment(_i236);}// if the geometry is not closed, generate the last row of vertices and normals
  1525. // at the regular position on the given path
  1526. //
  1527. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  1528. generateSegment(closed===false?tubularSegments:0);// uvs are generated in a separate function.
  1529. // this makes it easy compute correct values for closed geometries
  1530. generateUVs();// finally create faces
  1531. generateIndices();}function generateSegment(i){// we use getPointAt to sample evenly distributed points from the given path
  1532. P=path.getPointAt(i/tubularSegments,P);// retrieve corresponding normal and binormal
  1533. var N=frames.normals[i];var B=frames.binormals[i];// generate normals and vertices for the current segment
  1534. for(var j=0;j<=radialSegments;j++){var v=j/radialSegments*Math.PI*2;var sin=Math.sin(v);var cos=-Math.cos(v);// normal
  1535. normal.x=cos*N.x+sin*B.x;normal.y=cos*N.y+sin*B.y;normal.z=cos*N.z+sin*B.z;normal.normalize();normals.push(normal.x,normal.y,normal.z);// vertex
  1536. vertex.x=P.x+radius*normal.x;vertex.y=P.y+radius*normal.y;vertex.z=P.z+radius*normal.z;vertices.push(vertex.x,vertex.y,vertex.z);}}function generateIndices(){for(var j=1;j<=tubularSegments;j++){for(var _i237=1;_i237<=radialSegments;_i237++){var a=(radialSegments+1)*(j-1)+(_i237-1);var b=(radialSegments+1)*j+(_i237-1);var c=(radialSegments+1)*j+_i237;var d=(radialSegments+1)*(j-1)+_i237;// faces
  1537. indices.push(a,b,d);indices.push(b,c,d);}}}function generateUVs(){for(var _i238=0;_i238<=tubularSegments;_i238++){for(var j=0;j<=radialSegments;j++){uv.x=_i238/tubularSegments;uv.y=j/radialSegments;uvs.push(uv.x,uv.y);}}}}toJSON(){var data=BufferGeometry.prototype.toJSON.call(this);data.path=this.parameters.path.toJSON();return data;}}class TubeGeometry extends Geometry{constructor(path,tubularSegments,radius,radialSegments,closed,taper){super();this.type='TubeGeometry';this.parameters={path:path,tubularSegments:tubularSegments,radius:radius,radialSegments:radialSegments,closed:closed};if(taper!==undefined)console.warn('THREE.TubeGeometry: taper has been removed.');var bufferGeometry=new TubeBufferGeometry(path,tubularSegments,radius,radialSegments,closed);// expose internals
  1538. this.tangents=bufferGeometry.tangents;this.normals=bufferGeometry.normals;this.binormals=bufferGeometry.binormals;// create geometry
  1539. this.fromBufferGeometry(bufferGeometry);this.mergeVertices();}}class WireframeGeometry extends BufferGeometry{constructor(geometry){super();this.type='WireframeGeometry';// buffer
  1540. var vertices=[];// helper variables
  1541. var edge=[0,0],edges={};var keys=['a','b','c'];// different logic for Geometry and BufferGeometry
  1542. if(geometry&&geometry.isGeometry){// create a data structure that contains all edges without duplicates
  1543. var faces=geometry.faces;for(var _i239=0,l=faces.length;_i239<l;_i239++){var face=faces[_i239];for(var j=0;j<3;j++){var edge1=face[keys[j]];var edge2=face[keys[(j+1)%3]];edge[0]=Math.min(edge1,edge2);// sorting prevents duplicates
  1544. edge[1]=Math.max(edge1,edge2);var key=edge[0]+','+edge[1];if(edges[key]===undefined){edges[key]={index1:edge[0],index2:edge[1]};}}}// generate vertices
  1545. for(var _key3 in edges){var e=edges[_key3];var vertex=geometry.vertices[e.index1];vertices.push(vertex.x,vertex.y,vertex.z);vertex=geometry.vertices[e.index2];vertices.push(vertex.x,vertex.y,vertex.z);}}else if(geometry&&geometry.isBufferGeometry){var _vertex=new Vector3();if(geometry.index!==null){// indexed BufferGeometry
  1546. var position=geometry.attributes.position;var indices=geometry.index;var groups=geometry.groups;if(groups.length===0){groups=[{start:0,count:indices.count,materialIndex:0}];}// create a data structure that contains all eges without duplicates
  1547. for(var o=0,ol=groups.length;o<ol;++o){var group=groups[o];var start=group.start;var count=group.count;for(var _i240=start,_l13=start+count;_i240<_l13;_i240+=3){for(var _j20=0;_j20<3;_j20++){var _edge=indices.getX(_i240+_j20);var _edge3=indices.getX(_i240+(_j20+1)%3);edge[0]=Math.min(_edge,_edge3);// sorting prevents duplicates
  1548. edge[1]=Math.max(_edge,_edge3);var _key4=edge[0]+','+edge[1];if(edges[_key4]===undefined){edges[_key4]={index1:edge[0],index2:edge[1]};}}}}// generate vertices
  1549. for(var _key5 in edges){var _e=edges[_key5];_vertex.fromBufferAttribute(position,_e.index1);vertices.push(_vertex.x,_vertex.y,_vertex.z);_vertex.fromBufferAttribute(position,_e.index2);vertices.push(_vertex.x,_vertex.y,_vertex.z);}}else {// non-indexed BufferGeometry
  1550. var _position2=geometry.attributes.position;for(var _i241=0,_l14=_position2.count/3;_i241<_l14;_i241++){for(var _j21=0;_j21<3;_j21++){// three edges per triangle, an edge is represented as (index1, index2)
  1551. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  1552. var index1=3*_i241+_j21;_vertex.fromBufferAttribute(_position2,index1);vertices.push(_vertex.x,_vertex.y,_vertex.z);var index2=3*_i241+(_j21+1)%3;_vertex.fromBufferAttribute(_position2,index2);vertices.push(_vertex.x,_vertex.y,_vertex.z);}}}}// build geometry
  1553. this.setAttribute('position',new Float32BufferAttribute(vertices,3));}}var Geometries=/*#__PURE__*/Object.freeze({__proto__:null,BoxGeometry:BoxGeometry,BoxBufferGeometry:BoxBufferGeometry,CircleGeometry:CircleGeometry,CircleBufferGeometry:CircleBufferGeometry,ConeGeometry:ConeGeometry,ConeBufferGeometry:ConeBufferGeometry,CylinderGeometry:CylinderGeometry,CylinderBufferGeometry:CylinderBufferGeometry,DodecahedronGeometry:DodecahedronGeometry,DodecahedronBufferGeometry:DodecahedronBufferGeometry,EdgesGeometry:EdgesGeometry,ExtrudeGeometry:ExtrudeGeometry,ExtrudeBufferGeometry:ExtrudeBufferGeometry,IcosahedronGeometry:IcosahedronGeometry,IcosahedronBufferGeometry:IcosahedronBufferGeometry,LatheGeometry:LatheGeometry,LatheBufferGeometry:LatheBufferGeometry,OctahedronGeometry:OctahedronGeometry,OctahedronBufferGeometry:OctahedronBufferGeometry,ParametricGeometry:ParametricGeometry,ParametricBufferGeometry:ParametricBufferGeometry,PlaneGeometry:PlaneGeometry,PlaneBufferGeometry:PlaneBufferGeometry,PolyhedronGeometry:PolyhedronGeometry,PolyhedronBufferGeometry:PolyhedronBufferGeometry,RingGeometry:RingGeometry,RingBufferGeometry:RingBufferGeometry,ShapeGeometry:ShapeGeometry,ShapeBufferGeometry:ShapeBufferGeometry,SphereGeometry:SphereGeometry,SphereBufferGeometry:SphereBufferGeometry,TetrahedronGeometry:TetrahedronGeometry,TetrahedronBufferGeometry:TetrahedronBufferGeometry,TextGeometry:TextGeometry,TextBufferGeometry:TextBufferGeometry,TorusGeometry:TorusGeometry,TorusBufferGeometry:TorusBufferGeometry,TorusKnotGeometry:TorusKnotGeometry,TorusKnotBufferGeometry:TorusKnotBufferGeometry,TubeGeometry:TubeGeometry,TubeBufferGeometry:TubeBufferGeometry,WireframeGeometry:WireframeGeometry});/**
  1554. * parameters = {
  1555. * color: <THREE.Color>
  1556. * }
  1557. */function ShadowMaterial(parameters){Material.call(this);this.type='ShadowMaterial';this.color=new Color(0x000000);this.transparent=true;this.setValues(parameters);}ShadowMaterial.prototype=Object.create(Material.prototype);ShadowMaterial.prototype.constructor=ShadowMaterial;ShadowMaterial.prototype.isShadowMaterial=true;ShadowMaterial.prototype.copy=function(source){Material.prototype.copy.call(this,source);this.color.copy(source.color);return this;};function RawShaderMaterial(parameters){ShaderMaterial.call(this,parameters);this.type='RawShaderMaterial';}RawShaderMaterial.prototype=Object.create(ShaderMaterial.prototype);RawShaderMaterial.prototype.constructor=RawShaderMaterial;RawShaderMaterial.prototype.isRawShaderMaterial=true;/**
  1558. * parameters = {
  1559. * color: <hex>,
  1560. * roughness: <float>,
  1561. * metalness: <float>,
  1562. * opacity: <float>,
  1563. *
  1564. * map: new THREE.Texture( <Image> ),
  1565. *
  1566. * lightMap: new THREE.Texture( <Image> ),
  1567. * lightMapIntensity: <float>
  1568. *
  1569. * aoMap: new THREE.Texture( <Image> ),
  1570. * aoMapIntensity: <float>
  1571. *
  1572. * emissive: <hex>,
  1573. * emissiveIntensity: <float>
  1574. * emissiveMap: new THREE.Texture( <Image> ),
  1575. *
  1576. * bumpMap: new THREE.Texture( <Image> ),
  1577. * bumpScale: <float>,
  1578. *
  1579. * normalMap: new THREE.Texture( <Image> ),
  1580. * normalMapType: THREE.TangentSpaceNormalMap,
  1581. * normalScale: <Vector2>,
  1582. *
  1583. * displacementMap: new THREE.Texture( <Image> ),
  1584. * displacementScale: <float>,
  1585. * displacementBias: <float>,
  1586. *
  1587. * roughnessMap: new THREE.Texture( <Image> ),
  1588. *
  1589. * metalnessMap: new THREE.Texture( <Image> ),
  1590. *
  1591. * alphaMap: new THREE.Texture( <Image> ),
  1592. *
  1593. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  1594. * envMapIntensity: <float>
  1595. *
  1596. * refractionRatio: <float>,
  1597. *
  1598. * wireframe: <boolean>,
  1599. * wireframeLinewidth: <float>,
  1600. *
  1601. * skinning: <bool>,
  1602. * morphTargets: <bool>,
  1603. * morphNormals: <bool>
  1604. * }
  1605. */function MeshStandardMaterial(parameters){Material.call(this);this.defines={'STANDARD':''};this.type='MeshStandardMaterial';this.color=new Color(0xffffff);// diffuse
  1606. this.roughness=1.0;this.metalness=0.0;this.map=null;this.lightMap=null;this.lightMapIntensity=1.0;this.aoMap=null;this.aoMapIntensity=1.0;this.emissive=new Color(0x000000);this.emissiveIntensity=1.0;this.emissiveMap=null;this.bumpMap=null;this.bumpScale=1;this.normalMap=null;this.normalMapType=TangentSpaceNormalMap;this.normalScale=new Vector2(1,1);this.displacementMap=null;this.displacementScale=1;this.displacementBias=0;this.roughnessMap=null;this.metalnessMap=null;this.alphaMap=null;this.envMap=null;this.envMapIntensity=1.0;this.refractionRatio=0.98;this.wireframe=false;this.wireframeLinewidth=1;this.wireframeLinecap='round';this.wireframeLinejoin='round';this.skinning=false;this.morphTargets=false;this.morphNormals=false;this.vertexTangents=false;this.setValues(parameters);}MeshStandardMaterial.prototype=Object.create(Material.prototype);MeshStandardMaterial.prototype.constructor=MeshStandardMaterial;MeshStandardMaterial.prototype.isMeshStandardMaterial=true;MeshStandardMaterial.prototype.copy=function(source){Material.prototype.copy.call(this,source);this.defines={'STANDARD':''};this.color.copy(source.color);this.roughness=source.roughness;this.metalness=source.metalness;this.map=source.map;this.lightMap=source.lightMap;this.lightMapIntensity=source.lightMapIntensity;this.aoMap=source.aoMap;this.aoMapIntensity=source.aoMapIntensity;this.emissive.copy(source.emissive);this.emissiveMap=source.emissiveMap;this.emissiveIntensity=source.emissiveIntensity;this.bumpMap=source.bumpMap;this.bumpScale=source.bumpScale;this.normalMap=source.normalMap;this.normalMapType=source.normalMapType;this.normalScale.copy(source.normalScale);this.displacementMap=source.displacementMap;this.displacementScale=source.displacementScale;this.displacementBias=source.displacementBias;this.roughnessMap=source.roughnessMap;this.metalnessMap=source.metalnessMap;this.alphaMap=source.alphaMap;this.envMap=source.envMap;this.envMapIntensity=source.envMapIntensity;this.refractionRatio=source.refractionRatio;this.wireframe=source.wireframe;this.wireframeLinewidth=source.wireframeLinewidth;this.wireframeLinecap=source.wireframeLinecap;this.wireframeLinejoin=source.wireframeLinejoin;this.skinning=source.skinning;this.morphTargets=source.morphTargets;this.morphNormals=source.morphNormals;this.vertexTangents=source.vertexTangents;return this;};/**
  1607. * parameters = {
  1608. * clearcoat: <float>,
  1609. * clearcoatMap: new THREE.Texture( <Image> ),
  1610. * clearcoatRoughness: <float>,
  1611. * clearcoatRoughnessMap: new THREE.Texture( <Image> ),
  1612. * clearcoatNormalScale: <Vector2>,
  1613. * clearcoatNormalMap: new THREE.Texture( <Image> ),
  1614. *
  1615. * reflectivity: <float>,
  1616. * ior: <float>,
  1617. *
  1618. * sheen: <Color>,
  1619. *
  1620. * transmission: <float>,
  1621. * transmissionMap: new THREE.Texture( <Image> )
  1622. * }
  1623. */function MeshPhysicalMaterial(parameters){MeshStandardMaterial.call(this);this.defines={'STANDARD':'','PHYSICAL':''};this.type='MeshPhysicalMaterial';this.clearcoat=0.0;this.clearcoatMap=null;this.clearcoatRoughness=0.0;this.clearcoatRoughnessMap=null;this.clearcoatNormalScale=new Vector2(1,1);this.clearcoatNormalMap=null;this.reflectivity=0.5;// maps to F0 = 0.04
  1624. Object.defineProperty(this,'ior',{get:function get(){return (1+0.4*this.reflectivity)/(1-0.4*this.reflectivity);},set:function set(ior){this.reflectivity=MathUtils.clamp(2.5*(ior-1)/(ior+1),0,1);}});this.sheen=null;// null will disable sheen bsdf
  1625. this.transmission=0.0;this.transmissionMap=null;this.setValues(parameters);}MeshPhysicalMaterial.prototype=Object.create(MeshStandardMaterial.prototype);MeshPhysicalMaterial.prototype.constructor=MeshPhysicalMaterial;MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial=true;MeshPhysicalMaterial.prototype.copy=function(source){MeshStandardMaterial.prototype.copy.call(this,source);this.defines={'STANDARD':'','PHYSICAL':''};this.clearcoat=source.clearcoat;this.clearcoatMap=source.clearcoatMap;this.clearcoatRoughness=source.clearcoatRoughness;this.clearcoatRoughnessMap=source.clearcoatRoughnessMap;this.clearcoatNormalMap=source.clearcoatNormalMap;this.clearcoatNormalScale.copy(source.clearcoatNormalScale);this.reflectivity=source.reflectivity;if(source.sheen){this.sheen=(this.sheen||new Color()).copy(source.sheen);}else {this.sheen=null;}this.transmission=source.transmission;this.transmissionMap=source.transmissionMap;return this;};/**
  1626. * parameters = {
  1627. * color: <hex>,
  1628. * specular: <hex>,
  1629. * shininess: <float>,
  1630. * opacity: <float>,
  1631. *
  1632. * map: new THREE.Texture( <Image> ),
  1633. *
  1634. * lightMap: new THREE.Texture( <Image> ),
  1635. * lightMapIntensity: <float>
  1636. *
  1637. * aoMap: new THREE.Texture( <Image> ),
  1638. * aoMapIntensity: <float>
  1639. *
  1640. * emissive: <hex>,
  1641. * emissiveIntensity: <float>
  1642. * emissiveMap: new THREE.Texture( <Image> ),
  1643. *
  1644. * bumpMap: new THREE.Texture( <Image> ),
  1645. * bumpScale: <float>,
  1646. *
  1647. * normalMap: new THREE.Texture( <Image> ),
  1648. * normalMapType: THREE.TangentSpaceNormalMap,
  1649. * normalScale: <Vector2>,
  1650. *
  1651. * displacementMap: new THREE.Texture( <Image> ),
  1652. * displacementScale: <float>,
  1653. * displacementBias: <float>,
  1654. *
  1655. * specularMap: new THREE.Texture( <Image> ),
  1656. *
  1657. * alphaMap: new THREE.Texture( <Image> ),
  1658. *
  1659. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  1660. * combine: THREE.MultiplyOperation,
  1661. * reflectivity: <float>,
  1662. * refractionRatio: <float>,
  1663. *
  1664. * wireframe: <boolean>,
  1665. * wireframeLinewidth: <float>,
  1666. *
  1667. * skinning: <bool>,
  1668. * morphTargets: <bool>,
  1669. * morphNormals: <bool>
  1670. * }
  1671. */function MeshPhongMaterial(parameters){Material.call(this);this.type='MeshPhongMaterial';this.color=new Color(0xffffff);// diffuse
  1672. this.specular=new Color(0x111111);this.shininess=30;this.map=null;this.lightMap=null;this.lightMapIntensity=1.0;this.aoMap=null;this.aoMapIntensity=1.0;this.emissive=new Color(0x000000);this.emissiveIntensity=1.0;this.emissiveMap=null;this.bumpMap=null;this.bumpScale=1;this.normalMap=null;this.normalMapType=TangentSpaceNormalMap;this.normalScale=new Vector2(1,1);this.displacementMap=null;this.displacementScale=1;this.displacementBias=0;this.specularMap=null;this.alphaMap=null;this.envMap=null;this.combine=MultiplyOperation;this.reflectivity=1;this.refractionRatio=0.98;this.wireframe=false;this.wireframeLinewidth=1;this.wireframeLinecap='round';this.wireframeLinejoin='round';this.skinning=false;this.morphTargets=false;this.morphNormals=false;this.setValues(parameters);}MeshPhongMaterial.prototype=Object.create(Material.prototype);MeshPhongMaterial.prototype.constructor=MeshPhongMaterial;MeshPhongMaterial.prototype.isMeshPhongMaterial=true;MeshPhongMaterial.prototype.copy=function(source){Material.prototype.copy.call(this,source);this.color.copy(source.color);this.specular.copy(source.specular);this.shininess=source.shininess;this.map=source.map;this.lightMap=source.lightMap;this.lightMapIntensity=source.lightMapIntensity;this.aoMap=source.aoMap;this.aoMapIntensity=source.aoMapIntensity;this.emissive.copy(source.emissive);this.emissiveMap=source.emissiveMap;this.emissiveIntensity=source.emissiveIntensity;this.bumpMap=source.bumpMap;this.bumpScale=source.bumpScale;this.normalMap=source.normalMap;this.normalMapType=source.normalMapType;this.normalScale.copy(source.normalScale);this.displacementMap=source.displacementMap;this.displacementScale=source.displacementScale;this.displacementBias=source.displacementBias;this.specularMap=source.specularMap;this.alphaMap=source.alphaMap;this.envMap=source.envMap;this.combine=source.combine;this.reflectivity=source.reflectivity;this.refractionRatio=source.refractionRatio;this.wireframe=source.wireframe;this.wireframeLinewidth=source.wireframeLinewidth;this.wireframeLinecap=source.wireframeLinecap;this.wireframeLinejoin=source.wireframeLinejoin;this.skinning=source.skinning;this.morphTargets=source.morphTargets;this.morphNormals=source.morphNormals;return this;};/**
  1673. * parameters = {
  1674. * color: <hex>,
  1675. *
  1676. * map: new THREE.Texture( <Image> ),
  1677. * gradientMap: new THREE.Texture( <Image> ),
  1678. *
  1679. * lightMap: new THREE.Texture( <Image> ),
  1680. * lightMapIntensity: <float>
  1681. *
  1682. * aoMap: new THREE.Texture( <Image> ),
  1683. * aoMapIntensity: <float>
  1684. *
  1685. * emissive: <hex>,
  1686. * emissiveIntensity: <float>
  1687. * emissiveMap: new THREE.Texture( <Image> ),
  1688. *
  1689. * bumpMap: new THREE.Texture( <Image> ),
  1690. * bumpScale: <float>,
  1691. *
  1692. * normalMap: new THREE.Texture( <Image> ),
  1693. * normalMapType: THREE.TangentSpaceNormalMap,
  1694. * normalScale: <Vector2>,
  1695. *
  1696. * displacementMap: new THREE.Texture( <Image> ),
  1697. * displacementScale: <float>,
  1698. * displacementBias: <float>,
  1699. *
  1700. * alphaMap: new THREE.Texture( <Image> ),
  1701. *
  1702. * wireframe: <boolean>,
  1703. * wireframeLinewidth: <float>,
  1704. *
  1705. * skinning: <bool>,
  1706. * morphTargets: <bool>,
  1707. * morphNormals: <bool>
  1708. * }
  1709. */function MeshToonMaterial(parameters){Material.call(this);this.defines={'TOON':''};this.type='MeshToonMaterial';this.color=new Color(0xffffff);this.map=null;this.gradientMap=null;this.lightMap=null;this.lightMapIntensity=1.0;this.aoMap=null;this.aoMapIntensity=1.0;this.emissive=new Color(0x000000);this.emissiveIntensity=1.0;this.emissiveMap=null;this.bumpMap=null;this.bumpScale=1;this.normalMap=null;this.normalMapType=TangentSpaceNormalMap;this.normalScale=new Vector2(1,1);this.displacementMap=null;this.displacementScale=1;this.displacementBias=0;this.alphaMap=null;this.wireframe=false;this.wireframeLinewidth=1;this.wireframeLinecap='round';this.wireframeLinejoin='round';this.skinning=false;this.morphTargets=false;this.morphNormals=false;this.setValues(parameters);}MeshToonMaterial.prototype=Object.create(Material.prototype);MeshToonMaterial.prototype.constructor=MeshToonMaterial;MeshToonMaterial.prototype.isMeshToonMaterial=true;MeshToonMaterial.prototype.copy=function(source){Material.prototype.copy.call(this,source);this.color.copy(source.color);this.map=source.map;this.gradientMap=source.gradientMap;this.lightMap=source.lightMap;this.lightMapIntensity=source.lightMapIntensity;this.aoMap=source.aoMap;this.aoMapIntensity=source.aoMapIntensity;this.emissive.copy(source.emissive);this.emissiveMap=source.emissiveMap;this.emissiveIntensity=source.emissiveIntensity;this.bumpMap=source.bumpMap;this.bumpScale=source.bumpScale;this.normalMap=source.normalMap;this.normalMapType=source.normalMapType;this.normalScale.copy(source.normalScale);this.displacementMap=source.displacementMap;this.displacementScale=source.displacementScale;this.displacementBias=source.displacementBias;this.alphaMap=source.alphaMap;this.wireframe=source.wireframe;this.wireframeLinewidth=source.wireframeLinewidth;this.wireframeLinecap=source.wireframeLinecap;this.wireframeLinejoin=source.wireframeLinejoin;this.skinning=source.skinning;this.morphTargets=source.morphTargets;this.morphNormals=source.morphNormals;return this;};/**
  1710. * parameters = {
  1711. * opacity: <float>,
  1712. *
  1713. * bumpMap: new THREE.Texture( <Image> ),
  1714. * bumpScale: <float>,
  1715. *
  1716. * normalMap: new THREE.Texture( <Image> ),
  1717. * normalMapType: THREE.TangentSpaceNormalMap,
  1718. * normalScale: <Vector2>,
  1719. *
  1720. * displacementMap: new THREE.Texture( <Image> ),
  1721. * displacementScale: <float>,
  1722. * displacementBias: <float>,
  1723. *
  1724. * wireframe: <boolean>,
  1725. * wireframeLinewidth: <float>
  1726. *
  1727. * skinning: <bool>,
  1728. * morphTargets: <bool>,
  1729. * morphNormals: <bool>
  1730. * }
  1731. */function MeshNormalMaterial(parameters){Material.call(this);this.type='MeshNormalMaterial';this.bumpMap=null;this.bumpScale=1;this.normalMap=null;this.normalMapType=TangentSpaceNormalMap;this.normalScale=new Vector2(1,1);this.displacementMap=null;this.displacementScale=1;this.displacementBias=0;this.wireframe=false;this.wireframeLinewidth=1;this.fog=false;this.skinning=false;this.morphTargets=false;this.morphNormals=false;this.setValues(parameters);}MeshNormalMaterial.prototype=Object.create(Material.prototype);MeshNormalMaterial.prototype.constructor=MeshNormalMaterial;MeshNormalMaterial.prototype.isMeshNormalMaterial=true;MeshNormalMaterial.prototype.copy=function(source){Material.prototype.copy.call(this,source);this.bumpMap=source.bumpMap;this.bumpScale=source.bumpScale;this.normalMap=source.normalMap;this.normalMapType=source.normalMapType;this.normalScale.copy(source.normalScale);this.displacementMap=source.displacementMap;this.displacementScale=source.displacementScale;this.displacementBias=source.displacementBias;this.wireframe=source.wireframe;this.wireframeLinewidth=source.wireframeLinewidth;this.skinning=source.skinning;this.morphTargets=source.morphTargets;this.morphNormals=source.morphNormals;return this;};/**
  1732. * parameters = {
  1733. * color: <hex>,
  1734. * opacity: <float>,
  1735. *
  1736. * map: new THREE.Texture( <Image> ),
  1737. *
  1738. * lightMap: new THREE.Texture( <Image> ),
  1739. * lightMapIntensity: <float>
  1740. *
  1741. * aoMap: new THREE.Texture( <Image> ),
  1742. * aoMapIntensity: <float>
  1743. *
  1744. * emissive: <hex>,
  1745. * emissiveIntensity: <float>
  1746. * emissiveMap: new THREE.Texture( <Image> ),
  1747. *
  1748. * specularMap: new THREE.Texture( <Image> ),
  1749. *
  1750. * alphaMap: new THREE.Texture( <Image> ),
  1751. *
  1752. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  1753. * combine: THREE.Multiply,
  1754. * reflectivity: <float>,
  1755. * refractionRatio: <float>,
  1756. *
  1757. * wireframe: <boolean>,
  1758. * wireframeLinewidth: <float>,
  1759. *
  1760. * skinning: <bool>,
  1761. * morphTargets: <bool>,
  1762. * morphNormals: <bool>
  1763. * }
  1764. */function MeshLambertMaterial(parameters){Material.call(this);this.type='MeshLambertMaterial';this.color=new Color(0xffffff);// diffuse
  1765. this.map=null;this.lightMap=null;this.lightMapIntensity=1.0;this.aoMap=null;this.aoMapIntensity=1.0;this.emissive=new Color(0x000000);this.emissiveIntensity=1.0;this.emissiveMap=null;this.specularMap=null;this.alphaMap=null;this.envMap=null;this.combine=MultiplyOperation;this.reflectivity=1;this.refractionRatio=0.98;this.wireframe=false;this.wireframeLinewidth=1;this.wireframeLinecap='round';this.wireframeLinejoin='round';this.skinning=false;this.morphTargets=false;this.morphNormals=false;this.setValues(parameters);}MeshLambertMaterial.prototype=Object.create(Material.prototype);MeshLambertMaterial.prototype.constructor=MeshLambertMaterial;MeshLambertMaterial.prototype.isMeshLambertMaterial=true;MeshLambertMaterial.prototype.copy=function(source){Material.prototype.copy.call(this,source);this.color.copy(source.color);this.map=source.map;this.lightMap=source.lightMap;this.lightMapIntensity=source.lightMapIntensity;this.aoMap=source.aoMap;this.aoMapIntensity=source.aoMapIntensity;this.emissive.copy(source.emissive);this.emissiveMap=source.emissiveMap;this.emissiveIntensity=source.emissiveIntensity;this.specularMap=source.specularMap;this.alphaMap=source.alphaMap;this.envMap=source.envMap;this.combine=source.combine;this.reflectivity=source.reflectivity;this.refractionRatio=source.refractionRatio;this.wireframe=source.wireframe;this.wireframeLinewidth=source.wireframeLinewidth;this.wireframeLinecap=source.wireframeLinecap;this.wireframeLinejoin=source.wireframeLinejoin;this.skinning=source.skinning;this.morphTargets=source.morphTargets;this.morphNormals=source.morphNormals;return this;};/**
  1766. * parameters = {
  1767. * color: <hex>,
  1768. * opacity: <float>,
  1769. *
  1770. * matcap: new THREE.Texture( <Image> ),
  1771. *
  1772. * map: new THREE.Texture( <Image> ),
  1773. *
  1774. * bumpMap: new THREE.Texture( <Image> ),
  1775. * bumpScale: <float>,
  1776. *
  1777. * normalMap: new THREE.Texture( <Image> ),
  1778. * normalMapType: THREE.TangentSpaceNormalMap,
  1779. * normalScale: <Vector2>,
  1780. *
  1781. * displacementMap: new THREE.Texture( <Image> ),
  1782. * displacementScale: <float>,
  1783. * displacementBias: <float>,
  1784. *
  1785. * alphaMap: new THREE.Texture( <Image> ),
  1786. *
  1787. * skinning: <bool>,
  1788. * morphTargets: <bool>,
  1789. * morphNormals: <bool>
  1790. * }
  1791. */function MeshMatcapMaterial(parameters){Material.call(this);this.defines={'MATCAP':''};this.type='MeshMatcapMaterial';this.color=new Color(0xffffff);// diffuse
  1792. this.matcap=null;this.map=null;this.bumpMap=null;this.bumpScale=1;this.normalMap=null;this.normalMapType=TangentSpaceNormalMap;this.normalScale=new Vector2(1,1);this.displacementMap=null;this.displacementScale=1;this.displacementBias=0;this.alphaMap=null;this.skinning=false;this.morphTargets=false;this.morphNormals=false;this.setValues(parameters);}MeshMatcapMaterial.prototype=Object.create(Material.prototype);MeshMatcapMaterial.prototype.constructor=MeshMatcapMaterial;MeshMatcapMaterial.prototype.isMeshMatcapMaterial=true;MeshMatcapMaterial.prototype.copy=function(source){Material.prototype.copy.call(this,source);this.defines={'MATCAP':''};this.color.copy(source.color);this.matcap=source.matcap;this.map=source.map;this.bumpMap=source.bumpMap;this.bumpScale=source.bumpScale;this.normalMap=source.normalMap;this.normalMapType=source.normalMapType;this.normalScale.copy(source.normalScale);this.displacementMap=source.displacementMap;this.displacementScale=source.displacementScale;this.displacementBias=source.displacementBias;this.alphaMap=source.alphaMap;this.skinning=source.skinning;this.morphTargets=source.morphTargets;this.morphNormals=source.morphNormals;return this;};/**
  1793. * parameters = {
  1794. * color: <hex>,
  1795. * opacity: <float>,
  1796. *
  1797. * linewidth: <float>,
  1798. *
  1799. * scale: <float>,
  1800. * dashSize: <float>,
  1801. * gapSize: <float>
  1802. * }
  1803. */function LineDashedMaterial(parameters){LineBasicMaterial.call(this);this.type='LineDashedMaterial';this.scale=1;this.dashSize=3;this.gapSize=1;this.setValues(parameters);}LineDashedMaterial.prototype=Object.create(LineBasicMaterial.prototype);LineDashedMaterial.prototype.constructor=LineDashedMaterial;LineDashedMaterial.prototype.isLineDashedMaterial=true;LineDashedMaterial.prototype.copy=function(source){LineBasicMaterial.prototype.copy.call(this,source);this.scale=source.scale;this.dashSize=source.dashSize;this.gapSize=source.gapSize;return this;};var Materials=/*#__PURE__*/Object.freeze({__proto__:null,ShadowMaterial:ShadowMaterial,SpriteMaterial:SpriteMaterial,RawShaderMaterial:RawShaderMaterial,ShaderMaterial:ShaderMaterial,PointsMaterial:PointsMaterial,MeshPhysicalMaterial:MeshPhysicalMaterial,MeshStandardMaterial:MeshStandardMaterial,MeshPhongMaterial:MeshPhongMaterial,MeshToonMaterial:MeshToonMaterial,MeshNormalMaterial:MeshNormalMaterial,MeshLambertMaterial:MeshLambertMaterial,MeshDepthMaterial:MeshDepthMaterial,MeshDistanceMaterial:MeshDistanceMaterial,MeshBasicMaterial:MeshBasicMaterial,MeshMatcapMaterial:MeshMatcapMaterial,LineDashedMaterial:LineDashedMaterial,LineBasicMaterial:LineBasicMaterial,Material:Material});var AnimationUtils={// same as Array.prototype.slice, but also works on typed arrays
  1804. arraySlice:function arraySlice(array,from,to){if(AnimationUtils.isTypedArray(array)){// in ios9 array.subarray(from, undefined) will return empty array
  1805. // but array.subarray(from) or array.subarray(from, len) is correct
  1806. return new array.constructor(array.subarray(from,to!==undefined?to:array.length));}return array.slice(from,to);},// converts an array to a specific type
  1807. convertArray:function convertArray(array,type,forceClone){if(!array||// let 'undefined' and 'null' pass
  1808. !forceClone&&array.constructor===type)return array;if(typeof type.BYTES_PER_ELEMENT==='number'){return new type(array);// create typed array
  1809. }return Array.prototype.slice.call(array);// create Array
  1810. },isTypedArray:function isTypedArray(object){return ArrayBuffer.isView(object)&&!(object instanceof DataView);},// returns an array by which times and values can be sorted
  1811. getKeyframeOrder:function getKeyframeOrder(times){function compareTime(i,j){return times[i]-times[j];}var n=times.length;var result=new Array(n);for(var _i242=0;_i242!==n;++_i242)result[_i242]=_i242;result.sort(compareTime);return result;},// uses the array previously returned by 'getKeyframeOrder' to sort data
  1812. sortedArray:function sortedArray(values,stride,order){var nValues=values.length;var result=new values.constructor(nValues);for(var _i243=0,dstOffset=0;dstOffset!==nValues;++_i243){var srcOffset=order[_i243]*stride;for(var j=0;j!==stride;++j){result[dstOffset++]=values[srcOffset+j];}}return result;},// function for parsing AOS keyframe formats
  1813. flattenJSON:function flattenJSON(jsonKeys,times,values,valuePropertyName){var i=1,key=jsonKeys[0];while(key!==undefined&&key[valuePropertyName]===undefined){key=jsonKeys[i++];}if(key===undefined)return;// no data
  1814. var value=key[valuePropertyName];if(value===undefined)return;// no data
  1815. if(Array.isArray(value)){do{value=key[valuePropertyName];if(value!==undefined){times.push(key.time);values.push.apply(values,value);// push all elements
  1816. }key=jsonKeys[i++];}while(key!==undefined);}else if(value.toArray!==undefined){// ...assume THREE.Math-ish
  1817. do{value=key[valuePropertyName];if(value!==undefined){times.push(key.time);value.toArray(values,values.length);}key=jsonKeys[i++];}while(key!==undefined);}else {// otherwise push as-is
  1818. do{value=key[valuePropertyName];if(value!==undefined){times.push(key.time);values.push(value);}key=jsonKeys[i++];}while(key!==undefined);}},subclip:function subclip(sourceClip,name,startFrame,endFrame){var fps=arguments.length>4&&arguments[4]!==undefined?arguments[4]:30;var clip=sourceClip.clone();clip.name=name;var tracks=[];for(var _i244=0;_i244<clip.tracks.length;++_i244){var track=clip.tracks[_i244];var valueSize=track.getValueSize();var times=[];var values=[];for(var j=0;j<track.times.length;++j){var frame=track.times[j]*fps;if(frame<startFrame||frame>=endFrame)continue;times.push(track.times[j]);for(var k=0;k<valueSize;++k){values.push(track.values[j*valueSize+k]);}}if(times.length===0)continue;track.times=AnimationUtils.convertArray(times,track.times.constructor);track.values=AnimationUtils.convertArray(values,track.values.constructor);tracks.push(track);}clip.tracks=tracks;// find minimum .times value across all tracks in the trimmed clip
  1819. var minStartTime=Infinity;for(var _i245=0;_i245<clip.tracks.length;++_i245){if(minStartTime>clip.tracks[_i245].times[0]){minStartTime=clip.tracks[_i245].times[0];}}// shift all tracks such that clip begins at t=0
  1820. for(var _i246=0;_i246<clip.tracks.length;++_i246){clip.tracks[_i246].shift(-1*minStartTime);}clip.resetDuration();return clip;},makeClipAdditive:function makeClipAdditive(targetClip){var referenceFrame=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var referenceClip=arguments.length>2&&arguments[2]!==undefined?arguments[2]:targetClip;var fps=arguments.length>3&&arguments[3]!==undefined?arguments[3]:30;if(fps<=0)fps=30;var numTracks=referenceClip.tracks.length;var referenceTime=referenceFrame/fps;// Make each track's values relative to the values at the reference frame
  1821. var _loop=function _loop(){var referenceTrack=referenceClip.tracks[_i247];var referenceTrackType=referenceTrack.ValueTypeName;// Skip this track if it's non-numeric
  1822. if(referenceTrackType==='bool'||referenceTrackType==='string')return 0;// continue
  1823. // Find the track in the target clip whose name and type matches the reference track
  1824. var targetTrack=targetClip.tracks.find(function(track){return track.name===referenceTrack.name&&track.ValueTypeName===referenceTrackType;});if(targetTrack===undefined)return 0;// continue
  1825. var referenceOffset=0;var referenceValueSize=referenceTrack.getValueSize();if(referenceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline){referenceOffset=referenceValueSize/3;}var targetOffset=0;var targetValueSize=targetTrack.getValueSize();if(targetTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline){targetOffset=targetValueSize/3;}var lastIndex=referenceTrack.times.length-1;var referenceValue;// Find the value to subtract out of the track
  1826. if(referenceTime<=referenceTrack.times[0]){// Reference frame is earlier than the first keyframe, so just use the first keyframe
  1827. var startIndex=referenceOffset;var endIndex=referenceValueSize-referenceOffset;referenceValue=AnimationUtils.arraySlice(referenceTrack.values,startIndex,endIndex);}else if(referenceTime>=referenceTrack.times[lastIndex]){// Reference frame is after the last keyframe, so just use the last keyframe
  1828. var _startIndex=lastIndex*referenceValueSize+referenceOffset;var _endIndex=_startIndex+referenceValueSize-referenceOffset;referenceValue=AnimationUtils.arraySlice(referenceTrack.values,_startIndex,_endIndex);}else {// Interpolate to the reference value
  1829. var interpolant=referenceTrack.createInterpolant();var _startIndex2=referenceOffset;var _endIndex2=referenceValueSize-referenceOffset;interpolant.evaluate(referenceTime);referenceValue=AnimationUtils.arraySlice(interpolant.resultBuffer,_startIndex2,_endIndex2);}// Conjugate the quaternion
  1830. if(referenceTrackType==='quaternion'){var referenceQuat=new Quaternion().fromArray(referenceValue).normalize().conjugate();referenceQuat.toArray(referenceValue);}// Subtract the reference value from all of the track values
  1831. var numTimes=targetTrack.times.length;for(var j=0;j<numTimes;++j){var valueStart=j*targetValueSize+targetOffset;if(referenceTrackType==='quaternion'){// Multiply the conjugate for quaternion track types
  1832. Quaternion.multiplyQuaternionsFlat(targetTrack.values,valueStart,referenceValue,0,targetTrack.values,valueStart);}else {var valueEnd=targetValueSize-targetOffset*2;// Subtract each value for all other numeric track types
  1833. for(var k=0;k<valueEnd;++k){targetTrack.values[valueStart+k]-=referenceValue[k];}}}},_ret;for(var _i247=0;_i247<numTracks;++_i247){_ret=_loop();if(_ret===0)continue;}targetClip.blendMode=AdditiveAnimationBlendMode;return targetClip;}};/**
  1834. * Abstract base class of interpolants over parametric samples.
  1835. *
  1836. * The parameter domain is one dimensional, typically the time or a path
  1837. * along a curve defined by the data.
  1838. *
  1839. * The sample values can have any dimensionality and derived classes may
  1840. * apply special interpretations to the data.
  1841. *
  1842. * This class provides the interval seek in a Template Method, deferring
  1843. * the actual interpolation to derived classes.
  1844. *
  1845. * Time complexity is O(1) for linear access crossing at most two points
  1846. * and O(log N) for random access, where N is the number of positions.
  1847. *
  1848. * References:
  1849. *
  1850. * http://www.oodesign.com/template-method-pattern.html
  1851. *
  1852. */function Interpolant(parameterPositions,sampleValues,sampleSize,resultBuffer){this.parameterPositions=parameterPositions;this._cachedIndex=0;this.resultBuffer=resultBuffer!==undefined?resultBuffer:new sampleValues.constructor(sampleSize);this.sampleValues=sampleValues;this.valueSize=sampleSize;}Object.assign(Interpolant.prototype,{evaluate:function evaluate(t){var pp=this.parameterPositions;var i1=this._cachedIndex,t1=pp[i1],t0=pp[i1-1];validate_interval:{seek:{var right;linear_scan:{//- See http://jsperf.com/comparison-to-undefined/3
  1853. //- slower code:
  1854. //-
  1855. //- if ( t >= t1 || t1 === undefined ) {
  1856. forward_scan:if(!(t<t1)){for(var giveUpAt=i1+2;;){if(t1===undefined){if(t<t0)break forward_scan;// after end
  1857. i1=pp.length;this._cachedIndex=i1;return this.afterEnd_(i1-1,t,t0);}if(i1===giveUpAt)break;// this loop
  1858. t0=t1;t1=pp[++i1];if(t<t1){// we have arrived at the sought interval
  1859. break seek;}}// prepare binary search on the right side of the index
  1860. right=pp.length;break linear_scan;}//- slower code:
  1861. //- if ( t < t0 || t0 === undefined ) {
  1862. if(!(t>=t0)){// looping?
  1863. var t1global=pp[1];if(t<t1global){i1=2;// + 1, using the scan for the details
  1864. t0=t1global;}// linear reverse scan
  1865. for(var _giveUpAt=i1-2;;){if(t0===undefined){// before start
  1866. this._cachedIndex=0;return this.beforeStart_(0,t,t1);}if(i1===_giveUpAt)break;// this loop
  1867. t1=t0;t0=pp[--i1-1];if(t>=t0){// we have arrived at the sought interval
  1868. break seek;}}// prepare binary search on the left side of the index
  1869. right=i1;i1=0;break linear_scan;}// the interval is valid
  1870. break validate_interval;}// linear scan
  1871. // binary search
  1872. while(i1<right){var mid=i1+right>>>1;if(t<pp[mid]){right=mid;}else {i1=mid+1;}}t1=pp[i1];t0=pp[i1-1];// check boundary cases, again
  1873. if(t0===undefined){this._cachedIndex=0;return this.beforeStart_(0,t,t1);}if(t1===undefined){i1=pp.length;this._cachedIndex=i1;return this.afterEnd_(i1-1,t0,t);}}// seek
  1874. this._cachedIndex=i1;this.intervalChanged_(i1,t0,t1);}// validate_interval
  1875. return this.interpolate_(i1,t0,t,t1);},settings:null,// optional, subclass-specific settings structure
  1876. // Note: The indirection allows central control of many interpolants.
  1877. // --- Protected interface
  1878. DefaultSettings_:{},getSettings_:function getSettings_(){return this.settings||this.DefaultSettings_;},copySampleValue_:function copySampleValue_(index){// copies a sample value to the result buffer
  1879. var result=this.resultBuffer,values=this.sampleValues,stride=this.valueSize,offset=index*stride;for(var _i248=0;_i248!==stride;++_i248){result[_i248]=values[offset+_i248];}return result;},// Template methods for derived classes:
  1880. interpolate_:function interpolate_(/* i1, t0, t, t1 */){throw new Error('call to abstract method');// implementations shall return this.resultBuffer
  1881. },intervalChanged_:function intervalChanged_(/* i1, t0, t1 */){// empty
  1882. }});// DECLARE ALIAS AFTER assign prototype
  1883. Object.assign(Interpolant.prototype,{//( 0, t, t0 ), returns this.resultBuffer
  1884. beforeStart_:Interpolant.prototype.copySampleValue_,//( N-1, tN-1, t ), returns this.resultBuffer
  1885. afterEnd_:Interpolant.prototype.copySampleValue_});/**
  1886. * Fast and simple cubic spline interpolant.
  1887. *
  1888. * It was derived from a Hermitian construction setting the first derivative
  1889. * at each sample position to the linear slope between neighboring positions
  1890. * over their parameter interval.
  1891. */function CubicInterpolant(parameterPositions,sampleValues,sampleSize,resultBuffer){Interpolant.call(this,parameterPositions,sampleValues,sampleSize,resultBuffer);this._weightPrev=-0;this._offsetPrev=-0;this._weightNext=-0;this._offsetNext=-0;}CubicInterpolant.prototype=Object.assign(Object.create(Interpolant.prototype),{constructor:CubicInterpolant,DefaultSettings_:{endingStart:ZeroCurvatureEnding,endingEnd:ZeroCurvatureEnding},intervalChanged_:function intervalChanged_(i1,t0,t1){var pp=this.parameterPositions;var iPrev=i1-2,iNext=i1+1,tPrev=pp[iPrev],tNext=pp[iNext];if(tPrev===undefined){switch(this.getSettings_().endingStart){case ZeroSlopeEnding:// f'(t0) = 0
  1892. iPrev=i1;tPrev=2*t0-t1;break;case WrapAroundEnding:// use the other end of the curve
  1893. iPrev=pp.length-2;tPrev=t0+pp[iPrev]-pp[iPrev+1];break;default:// ZeroCurvatureEnding
  1894. // f''(t0) = 0 a.k.a. Natural Spline
  1895. iPrev=i1;tPrev=t1;}}if(tNext===undefined){switch(this.getSettings_().endingEnd){case ZeroSlopeEnding:// f'(tN) = 0
  1896. iNext=i1;tNext=2*t1-t0;break;case WrapAroundEnding:// use the other end of the curve
  1897. iNext=1;tNext=t1+pp[1]-pp[0];break;default:// ZeroCurvatureEnding
  1898. // f''(tN) = 0, a.k.a. Natural Spline
  1899. iNext=i1-1;tNext=t0;}}var halfDt=(t1-t0)*0.5,stride=this.valueSize;this._weightPrev=halfDt/(t0-tPrev);this._weightNext=halfDt/(tNext-t1);this._offsetPrev=iPrev*stride;this._offsetNext=iNext*stride;},interpolate_:function interpolate_(i1,t0,t,t1){var result=this.resultBuffer,values=this.sampleValues,stride=this.valueSize,o1=i1*stride,o0=o1-stride,oP=this._offsetPrev,oN=this._offsetNext,wP=this._weightPrev,wN=this._weightNext,p=(t-t0)/(t1-t0),pp=p*p,ppp=pp*p;// evaluate polynomials
  1900. var sP=-wP*ppp+2*wP*pp-wP*p;var s0=(1+wP)*ppp+(-1.5-2*wP)*pp+(-0.5+wP)*p+1;var s1=(-1-wN)*ppp+(1.5+wN)*pp+0.5*p;var sN=wN*ppp-wN*pp;// combine data linearly
  1901. for(var _i249=0;_i249!==stride;++_i249){result[_i249]=sP*values[oP+_i249]+s0*values[o0+_i249]+s1*values[o1+_i249]+sN*values[oN+_i249];}return result;}});function LinearInterpolant(parameterPositions,sampleValues,sampleSize,resultBuffer){Interpolant.call(this,parameterPositions,sampleValues,sampleSize,resultBuffer);}LinearInterpolant.prototype=Object.assign(Object.create(Interpolant.prototype),{constructor:LinearInterpolant,interpolate_:function interpolate_(i1,t0,t,t1){var result=this.resultBuffer,values=this.sampleValues,stride=this.valueSize,offset1=i1*stride,offset0=offset1-stride,weight1=(t-t0)/(t1-t0),weight0=1-weight1;for(var _i250=0;_i250!==stride;++_i250){result[_i250]=values[offset0+_i250]*weight0+values[offset1+_i250]*weight1;}return result;}});/**
  1902. *
  1903. * Interpolant that evaluates to the sample value at the position preceeding
  1904. * the parameter.
  1905. */function DiscreteInterpolant(parameterPositions,sampleValues,sampleSize,resultBuffer){Interpolant.call(this,parameterPositions,sampleValues,sampleSize,resultBuffer);}DiscreteInterpolant.prototype=Object.assign(Object.create(Interpolant.prototype),{constructor:DiscreteInterpolant,interpolate_:function interpolate_(i1/*, t0, t, t1 */){return this.copySampleValue_(i1-1);}});function KeyframeTrack(name,times,values,interpolation){if(name===undefined)throw new Error('THREE.KeyframeTrack: track name is undefined');if(times===undefined||times.length===0)throw new Error('THREE.KeyframeTrack: no keyframes in track named '+name);this.name=name;this.times=AnimationUtils.convertArray(times,this.TimeBufferType);this.values=AnimationUtils.convertArray(values,this.ValueBufferType);this.setInterpolation(interpolation||this.DefaultInterpolation);}// Static methods
  1906. Object.assign(KeyframeTrack,{// Serialization (in static context, because of constructor invocation
  1907. // and automatic invocation of .toJSON):
  1908. toJSON:function toJSON(track){var trackType=track.constructor;var json;// derived classes can define a static toJSON method
  1909. if(trackType.toJSON!==undefined){json=trackType.toJSON(track);}else {// by default, we assume the data can be serialized as-is
  1910. json={'name':track.name,'times':AnimationUtils.convertArray(track.times,Array),'values':AnimationUtils.convertArray(track.values,Array)};var interpolation=track.getInterpolation();if(interpolation!==track.DefaultInterpolation){json.interpolation=interpolation;}}json.type=track.ValueTypeName;// mandatory
  1911. return json;}});Object.assign(KeyframeTrack.prototype,{constructor:KeyframeTrack,TimeBufferType:Float32Array,ValueBufferType:Float32Array,DefaultInterpolation:InterpolateLinear,InterpolantFactoryMethodDiscrete:function InterpolantFactoryMethodDiscrete(result){return new DiscreteInterpolant(this.times,this.values,this.getValueSize(),result);},InterpolantFactoryMethodLinear:function InterpolantFactoryMethodLinear(result){return new LinearInterpolant(this.times,this.values,this.getValueSize(),result);},InterpolantFactoryMethodSmooth:function InterpolantFactoryMethodSmooth(result){return new CubicInterpolant(this.times,this.values,this.getValueSize(),result);},setInterpolation:function setInterpolation(interpolation){var factoryMethod;switch(interpolation){case InterpolateDiscrete:factoryMethod=this.InterpolantFactoryMethodDiscrete;break;case InterpolateLinear:factoryMethod=this.InterpolantFactoryMethodLinear;break;case InterpolateSmooth:factoryMethod=this.InterpolantFactoryMethodSmooth;break;}if(factoryMethod===undefined){var message='unsupported interpolation for '+this.ValueTypeName+' keyframe track named '+this.name;if(this.createInterpolant===undefined){// fall back to default, unless the default itself is messed up
  1912. if(interpolation!==this.DefaultInterpolation){this.setInterpolation(this.DefaultInterpolation);}else {throw new Error(message);// fatal, in this case
  1913. }}console.warn('THREE.KeyframeTrack:',message);return this;}this.createInterpolant=factoryMethod;return this;},getInterpolation:function getInterpolation(){switch(this.createInterpolant){case this.InterpolantFactoryMethodDiscrete:return InterpolateDiscrete;case this.InterpolantFactoryMethodLinear:return InterpolateLinear;case this.InterpolantFactoryMethodSmooth:return InterpolateSmooth;}},getValueSize:function getValueSize(){return this.values.length/this.times.length;},// move all keyframes either forwards or backwards in time
  1914. shift:function shift(timeOffset){if(timeOffset!==0.0){var times=this.times;for(var _i251=0,n=times.length;_i251!==n;++_i251){times[_i251]+=timeOffset;}}return this;},// scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  1915. scale:function scale(timeScale){if(timeScale!==1.0){var times=this.times;for(var _i252=0,n=times.length;_i252!==n;++_i252){times[_i252]*=timeScale;}}return this;},// removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  1916. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  1917. trim:function trim(startTime,endTime){var times=this.times,nKeys=times.length;var from=0,to=nKeys-1;while(from!==nKeys&&times[from]<startTime){++from;}while(to!==-1&&times[to]>endTime){--to;}++to;// inclusive -> exclusive bound
  1918. if(from!==0||to!==nKeys){// empty tracks are forbidden, so keep at least one keyframe
  1919. if(from>=to){to=Math.max(to,1);from=to-1;}var stride=this.getValueSize();this.times=AnimationUtils.arraySlice(times,from,to);this.values=AnimationUtils.arraySlice(this.values,from*stride,to*stride);}return this;},// ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  1920. validate:function validate(){var valid=true;var valueSize=this.getValueSize();if(valueSize-Math.floor(valueSize)!==0){console.error('THREE.KeyframeTrack: Invalid value size in track.',this);valid=false;}var times=this.times,values=this.values,nKeys=times.length;if(nKeys===0){console.error('THREE.KeyframeTrack: Track is empty.',this);valid=false;}var prevTime=null;for(var _i253=0;_i253!==nKeys;_i253++){var currTime=times[_i253];if(typeof currTime==='number'&&isNaN(currTime)){console.error('THREE.KeyframeTrack: Time is not a valid number.',this,_i253,currTime);valid=false;break;}if(prevTime!==null&&prevTime>currTime){console.error('THREE.KeyframeTrack: Out of order keys.',this,_i253,currTime,prevTime);valid=false;break;}prevTime=currTime;}if(values!==undefined){if(AnimationUtils.isTypedArray(values)){for(var _i254=0,n=values.length;_i254!==n;++_i254){var value=values[_i254];if(isNaN(value)){console.error('THREE.KeyframeTrack: Value is not a valid number.',this,_i254,value);valid=false;break;}}}}return valid;},// removes equivalent sequential keys as common in morph target sequences
  1921. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  1922. optimize:function optimize(){// times or values may be shared with other tracks, so overwriting is unsafe
  1923. var times=AnimationUtils.arraySlice(this.times),values=AnimationUtils.arraySlice(this.values),stride=this.getValueSize(),smoothInterpolation=this.getInterpolation()===InterpolateSmooth,lastIndex=times.length-1;var writeIndex=1;for(var _i255=1;_i255<lastIndex;++_i255){var keep=false;var time=times[_i255];var timeNext=times[_i255+1];// remove adjacent keyframes scheduled at the same time
  1924. if(time!==timeNext&&(_i255!==1||time!==time[0])){if(!smoothInterpolation){// remove unnecessary keyframes same as their neighbors
  1925. var offset=_i255*stride,offsetP=offset-stride,offsetN=offset+stride;for(var j=0;j!==stride;++j){var value=values[offset+j];if(value!==values[offsetP+j]||value!==values[offsetN+j]){keep=true;break;}}}else {keep=true;}}// in-place compaction
  1926. if(keep){if(_i255!==writeIndex){times[writeIndex]=times[_i255];var readOffset=_i255*stride,writeOffset=writeIndex*stride;for(var _j22=0;_j22!==stride;++_j22){values[writeOffset+_j22]=values[readOffset+_j22];}}++writeIndex;}}// flush last keyframe (compaction looks ahead)
  1927. if(lastIndex>0){times[writeIndex]=times[lastIndex];for(var _readOffset=lastIndex*stride,_writeOffset=writeIndex*stride,_j23=0;_j23!==stride;++_j23){values[_writeOffset+_j23]=values[_readOffset+_j23];}++writeIndex;}if(writeIndex!==times.length){this.times=AnimationUtils.arraySlice(times,0,writeIndex);this.values=AnimationUtils.arraySlice(values,0,writeIndex*stride);}else {this.times=times;this.values=values;}return this;},clone:function clone(){var times=AnimationUtils.arraySlice(this.times,0);var values=AnimationUtils.arraySlice(this.values,0);var TypedKeyframeTrack=this.constructor;var track=new TypedKeyframeTrack(this.name,times,values);// Interpolant argument to constructor is not saved, so copy the factory method directly.
  1928. track.createInterpolant=this.createInterpolant;return track;}});/**
  1929. * A Track of Boolean keyframe values.
  1930. */function BooleanKeyframeTrack(name,times,values){KeyframeTrack.call(this,name,times,values);}BooleanKeyframeTrack.prototype=Object.assign(Object.create(KeyframeTrack.prototype),{constructor:BooleanKeyframeTrack,ValueTypeName:'bool',ValueBufferType:Array,DefaultInterpolation:InterpolateDiscrete,InterpolantFactoryMethodLinear:undefined,InterpolantFactoryMethodSmooth:undefined// Note: Actually this track could have a optimized / compressed
  1931. // representation of a single value and a custom interpolant that
  1932. // computes "firstValue ^ isOdd( index )".
  1933. });/**
  1934. * A Track of keyframe values that represent color.
  1935. */function ColorKeyframeTrack(name,times,values,interpolation){KeyframeTrack.call(this,name,times,values,interpolation);}ColorKeyframeTrack.prototype=Object.assign(Object.create(KeyframeTrack.prototype),{constructor:ColorKeyframeTrack,ValueTypeName:'color'// ValueBufferType is inherited
  1936. // DefaultInterpolation is inherited
  1937. // Note: Very basic implementation and nothing special yet.
  1938. // However, this is the place for color space parameterization.
  1939. });/**
  1940. * A Track of numeric keyframe values.
  1941. */function NumberKeyframeTrack(name,times,values,interpolation){KeyframeTrack.call(this,name,times,values,interpolation);}NumberKeyframeTrack.prototype=Object.assign(Object.create(KeyframeTrack.prototype),{constructor:NumberKeyframeTrack,ValueTypeName:'number'// ValueBufferType is inherited
  1942. // DefaultInterpolation is inherited
  1943. });/**
  1944. * Spherical linear unit quaternion interpolant.
  1945. */function QuaternionLinearInterpolant(parameterPositions,sampleValues,sampleSize,resultBuffer){Interpolant.call(this,parameterPositions,sampleValues,sampleSize,resultBuffer);}QuaternionLinearInterpolant.prototype=Object.assign(Object.create(Interpolant.prototype),{constructor:QuaternionLinearInterpolant,interpolate_:function interpolate_(i1,t0,t,t1){var result=this.resultBuffer,values=this.sampleValues,stride=this.valueSize,alpha=(t-t0)/(t1-t0);var offset=i1*stride;for(var end=offset+stride;offset!==end;offset+=4){Quaternion.slerpFlat(result,0,values,offset-stride,values,offset,alpha);}return result;}});/**
  1946. * A Track of quaternion keyframe values.
  1947. */function QuaternionKeyframeTrack(name,times,values,interpolation){KeyframeTrack.call(this,name,times,values,interpolation);}QuaternionKeyframeTrack.prototype=Object.assign(Object.create(KeyframeTrack.prototype),{constructor:QuaternionKeyframeTrack,ValueTypeName:'quaternion',// ValueBufferType is inherited
  1948. DefaultInterpolation:InterpolateLinear,InterpolantFactoryMethodLinear:function InterpolantFactoryMethodLinear(result){return new QuaternionLinearInterpolant(this.times,this.values,this.getValueSize(),result);},InterpolantFactoryMethodSmooth:undefined// not yet implemented
  1949. });/**
  1950. * A Track that interpolates Strings
  1951. */function StringKeyframeTrack(name,times,values,interpolation){KeyframeTrack.call(this,name,times,values,interpolation);}StringKeyframeTrack.prototype=Object.assign(Object.create(KeyframeTrack.prototype),{constructor:StringKeyframeTrack,ValueTypeName:'string',ValueBufferType:Array,DefaultInterpolation:InterpolateDiscrete,InterpolantFactoryMethodLinear:undefined,InterpolantFactoryMethodSmooth:undefined});/**
  1952. * A Track of vectored keyframe values.
  1953. */function VectorKeyframeTrack(name,times,values,interpolation){KeyframeTrack.call(this,name,times,values,interpolation);}VectorKeyframeTrack.prototype=Object.assign(Object.create(KeyframeTrack.prototype),{constructor:VectorKeyframeTrack,ValueTypeName:'vector'// ValueBufferType is inherited
  1954. // DefaultInterpolation is inherited
  1955. });function AnimationClip(name){var duration=arguments.length>1&&arguments[1]!==undefined?arguments[1]:-1;var tracks=arguments.length>2?arguments[2]:undefined;var blendMode=arguments.length>3&&arguments[3]!==undefined?arguments[3]:NormalAnimationBlendMode;this.name=name;this.tracks=tracks;this.duration=duration;this.blendMode=blendMode;this.uuid=MathUtils.generateUUID();// this means it should figure out its duration by scanning the tracks
  1956. if(this.duration<0){this.resetDuration();}}function getTrackTypeForValueTypeName(typeName){switch(typeName.toLowerCase()){case'scalar':case'double':case'float':case'number':case'integer':return NumberKeyframeTrack;case'vector':case'vector2':case'vector3':case'vector4':return VectorKeyframeTrack;case'color':return ColorKeyframeTrack;case'quaternion':return QuaternionKeyframeTrack;case'bool':case'boolean':return BooleanKeyframeTrack;case'string':return StringKeyframeTrack;}throw new Error('THREE.KeyframeTrack: Unsupported typeName: '+typeName);}function parseKeyframeTrack(json){if(json.type===undefined){throw new Error('THREE.KeyframeTrack: track type undefined, can not parse');}var trackType=getTrackTypeForValueTypeName(json.type);if(json.times===undefined){var times=[],values=[];AnimationUtils.flattenJSON(json.keys,times,values,'value');json.times=times;json.values=values;}// derived classes can define a static parse method
  1957. if(trackType.parse!==undefined){return trackType.parse(json);}else {// by default, we assume a constructor compatible with the base
  1958. return new trackType(json.name,json.times,json.values,json.interpolation);}}Object.assign(AnimationClip,{parse:function parse(json){var tracks=[],jsonTracks=json.tracks,frameTime=1.0/(json.fps||1.0);for(var _i256=0,n=jsonTracks.length;_i256!==n;++_i256){tracks.push(parseKeyframeTrack(jsonTracks[_i256]).scale(frameTime));}var clip=new AnimationClip(json.name,json.duration,tracks,json.blendMode);clip.uuid=json.uuid;return clip;},toJSON:function toJSON(clip){var tracks=[],clipTracks=clip.tracks;var json={'name':clip.name,'duration':clip.duration,'tracks':tracks,'uuid':clip.uuid,'blendMode':clip.blendMode};for(var _i257=0,n=clipTracks.length;_i257!==n;++_i257){tracks.push(KeyframeTrack.toJSON(clipTracks[_i257]));}return json;},CreateFromMorphTargetSequence:function CreateFromMorphTargetSequence(name,morphTargetSequence,fps,noLoop){var numMorphTargets=morphTargetSequence.length;var tracks=[];for(var _i258=0;_i258<numMorphTargets;_i258++){var times=[];var values=[];times.push((_i258+numMorphTargets-1)%numMorphTargets,_i258,(_i258+1)%numMorphTargets);values.push(0,1,0);var order=AnimationUtils.getKeyframeOrder(times);times=AnimationUtils.sortedArray(times,1,order);values=AnimationUtils.sortedArray(values,1,order);// if there is a key at the first frame, duplicate it as the
  1959. // last frame as well for perfect loop.
  1960. if(!noLoop&&times[0]===0){times.push(numMorphTargets);values.push(values[0]);}tracks.push(new NumberKeyframeTrack('.morphTargetInfluences['+morphTargetSequence[_i258].name+']',times,values).scale(1.0/fps));}return new AnimationClip(name,-1,tracks);},findByName:function findByName(objectOrClipArray,name){var clipArray=objectOrClipArray;if(!Array.isArray(objectOrClipArray)){var o=objectOrClipArray;clipArray=o.geometry&&o.geometry.animations||o.animations;}for(var _i259=0;_i259<clipArray.length;_i259++){if(clipArray[_i259].name===name){return clipArray[_i259];}}return null;},CreateClipsFromMorphTargetSequences:function CreateClipsFromMorphTargetSequences(morphTargets,fps,noLoop){var animationToMorphTargets={};// tested with https://regex101.com/ on trick sequences
  1961. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  1962. var pattern=/^([\w-]*?)([\d]+)$/;// sort morph target names into animation groups based
  1963. // patterns like Walk_001, Walk_002, Run_001, Run_002
  1964. for(var _i260=0,il=morphTargets.length;_i260<il;_i260++){var morphTarget=morphTargets[_i260];var parts=morphTarget.name.match(pattern);if(parts&&parts.length>1){var name=parts[1];var animationMorphTargets=animationToMorphTargets[name];if(!animationMorphTargets){animationToMorphTargets[name]=animationMorphTargets=[];}animationMorphTargets.push(morphTarget);}}var clips=[];for(var _name4 in animationToMorphTargets){clips.push(AnimationClip.CreateFromMorphTargetSequence(_name4,animationToMorphTargets[_name4],fps,noLoop));}return clips;},// parse the animation.hierarchy format
  1965. parseAnimation:function parseAnimation(animation,bones){if(!animation){console.error('THREE.AnimationClip: No animation in JSONLoader data.');return null;}var addNonemptyTrack=function addNonemptyTrack(trackType,trackName,animationKeys,propertyName,destTracks){// only return track if there are actually keys.
  1966. if(animationKeys.length!==0){var times=[];var values=[];AnimationUtils.flattenJSON(animationKeys,times,values,propertyName);// empty keys are filtered out, so check again
  1967. if(times.length!==0){destTracks.push(new trackType(trackName,times,values));}}};var tracks=[];var clipName=animation.name||'default';var fps=animation.fps||30;var blendMode=animation.blendMode;// automatic length determination in AnimationClip.
  1968. var duration=animation.length||-1;var hierarchyTracks=animation.hierarchy||[];for(var h=0;h<hierarchyTracks.length;h++){var animationKeys=hierarchyTracks[h].keys;// skip empty tracks
  1969. if(!animationKeys||animationKeys.length===0)continue;// process morph targets
  1970. if(animationKeys[0].morphTargets){// figure out all morph targets used in this track
  1971. var morphTargetNames={};var k=void 0;for(k=0;k<animationKeys.length;k++){if(animationKeys[k].morphTargets){for(var m=0;m<animationKeys[k].morphTargets.length;m++){morphTargetNames[animationKeys[k].morphTargets[m]]=-1;}}}// create a track for each morph target with all zero
  1972. // morphTargetInfluences except for the keys in which
  1973. // the morphTarget is named.
  1974. for(var morphTargetName in morphTargetNames){var times=[];var values=[];for(var _m=0;_m!==animationKeys[k].morphTargets.length;++_m){var animationKey=animationKeys[k];times.push(animationKey.time);values.push(animationKey.morphTarget===morphTargetName?1:0);}tracks.push(new NumberKeyframeTrack('.morphTargetInfluence['+morphTargetName+']',times,values));}duration=morphTargetNames.length*(fps||1.0);}else {// ...assume skeletal animation
  1975. var boneName='.bones['+bones[h].name+']';addNonemptyTrack(VectorKeyframeTrack,boneName+'.position',animationKeys,'pos',tracks);addNonemptyTrack(QuaternionKeyframeTrack,boneName+'.quaternion',animationKeys,'rot',tracks);addNonemptyTrack(VectorKeyframeTrack,boneName+'.scale',animationKeys,'scl',tracks);}}if(tracks.length===0){return null;}var clip=new AnimationClip(clipName,duration,tracks,blendMode);return clip;}});Object.assign(AnimationClip.prototype,{resetDuration:function resetDuration(){var tracks=this.tracks;var duration=0;for(var _i261=0,n=tracks.length;_i261!==n;++_i261){var track=this.tracks[_i261];duration=Math.max(duration,track.times[track.times.length-1]);}this.duration=duration;return this;},trim:function trim(){for(var _i262=0;_i262<this.tracks.length;_i262++){this.tracks[_i262].trim(0,this.duration);}return this;},validate:function validate(){var valid=true;for(var _i263=0;_i263<this.tracks.length;_i263++){valid=valid&&this.tracks[_i263].validate();}return valid;},optimize:function optimize(){for(var _i264=0;_i264<this.tracks.length;_i264++){this.tracks[_i264].optimize();}return this;},clone:function clone(){var tracks=[];for(var _i265=0;_i265<this.tracks.length;_i265++){tracks.push(this.tracks[_i265].clone());}return new AnimationClip(this.name,this.duration,tracks,this.blendMode);},toJSON:function toJSON(){return AnimationClip.toJSON(this);}});var Cache={enabled:false,files:{},add:function add(key,file){if(this.enabled===false)return;// console.log( 'THREE.Cache', 'Adding key:', key );
  1976. this.files[key]=file;},get:function get(key){if(this.enabled===false)return;// console.log( 'THREE.Cache', 'Checking key:', key );
  1977. return this.files[key];},remove:function remove(key){delete this.files[key];},clear:function clear(){this.files={};}};function LoadingManager(onLoad,onProgress,onError){var scope=this;var isLoading=false;var itemsLoaded=0;var itemsTotal=0;var urlModifier=undefined;var handlers=[];// Refer to #5689 for the reason why we don't set .onStart
  1978. // in the constructor
  1979. this.onStart=undefined;this.onLoad=onLoad;this.onProgress=onProgress;this.onError=onError;this.itemStart=function(url){itemsTotal++;if(isLoading===false){if(scope.onStart!==undefined){scope.onStart(url,itemsLoaded,itemsTotal);}}isLoading=true;};this.itemEnd=function(url){itemsLoaded++;if(scope.onProgress!==undefined){scope.onProgress(url,itemsLoaded,itemsTotal);}if(itemsLoaded===itemsTotal){isLoading=false;if(scope.onLoad!==undefined){scope.onLoad();}}};this.itemError=function(url){if(scope.onError!==undefined){scope.onError(url);}};this.resolveURL=function(url){if(urlModifier){return urlModifier(url);}return url;};this.setURLModifier=function(transform){urlModifier=transform;return this;};this.addHandler=function(regex,loader){handlers.push(regex,loader);return this;};this.removeHandler=function(regex){var index=handlers.indexOf(regex);if(index!==-1){handlers.splice(index,2);}return this;};this.getHandler=function(file){for(var _i266=0,l=handlers.length;_i266<l;_i266+=2){var regex=handlers[_i266];var loader=handlers[_i266+1];if(regex.global)regex.lastIndex=0;// see #17920
  1980. if(regex.test(file)){return loader;}}return null;};}var DefaultLoadingManager=new LoadingManager();function Loader(manager){this.manager=manager!==undefined?manager:DefaultLoadingManager;this.crossOrigin='anonymous';this.withCredentials=false;this.path='';this.resourcePath='';this.requestHeader={};}Object.assign(Loader.prototype,{load:function load(/* url, onLoad, onProgress, onError */){},loadAsync:function loadAsync(url,onProgress){var scope=this;return new Promise(function(resolve,reject){scope.load(url,resolve,onProgress,reject);});},parse:function parse(/* data */){},setCrossOrigin:function setCrossOrigin(crossOrigin){this.crossOrigin=crossOrigin;return this;},setWithCredentials:function setWithCredentials(value){this.withCredentials=value;return this;},setPath:function setPath(path){this.path=path;return this;},setResourcePath:function setResourcePath(resourcePath){this.resourcePath=resourcePath;return this;},setRequestHeader:function setRequestHeader(requestHeader){this.requestHeader=requestHeader;return this;}});var loading={};function FileLoader(manager){Loader.call(this,manager);}FileLoader.prototype=Object.assign(Object.create(Loader.prototype),{constructor:FileLoader,load:function load(url,onLoad,onProgress,onError){if(url===undefined)url='';if(this.path!==undefined)url=this.path+url;url=this.manager.resolveURL(url);var scope=this;var cached=Cache.get(url);if(cached!==undefined){scope.manager.itemStart(url);setTimeout(function(){if(onLoad)onLoad(cached);scope.manager.itemEnd(url);},0);return cached;}// Check if request is duplicate
  1981. if(loading[url]!==undefined){loading[url].push({onLoad:onLoad,onProgress:onProgress,onError:onError});return;}// Check for data: URI
  1982. var dataUriRegex=/^data:(.*?)(;base64)?,(.*)$/;var dataUriRegexResult=url.match(dataUriRegex);var request;// Safari can not handle Data URIs through XMLHttpRequest so process manually
  1983. if(dataUriRegexResult){var mimeType=dataUriRegexResult[1];var isBase64=!!dataUriRegexResult[2];var data=dataUriRegexResult[3];data=decodeURIComponent(data);if(isBase64)data=atob(data);try{var response;var responseType=(this.responseType||'').toLowerCase();switch(responseType){case'arraybuffer':case'blob':var view=new Uint8Array(data.length);for(var _i267=0;_i267<data.length;_i267++){view[_i267]=data.charCodeAt(_i267);}if(responseType==='blob'){response=new Blob([view.buffer],{type:mimeType});}else {response=view.buffer;}break;case'document':var parser=new DOMParser();response=parser.parseFromString(data,mimeType);break;case'json':response=JSON.parse(data);break;default:// 'text' or other
  1984. response=data;break;}// Wait for next browser tick like standard XMLHttpRequest event dispatching does
  1985. setTimeout(function(){if(onLoad)onLoad(response);scope.manager.itemEnd(url);},0);}catch(error){// Wait for next browser tick like standard XMLHttpRequest event dispatching does
  1986. setTimeout(function(){if(onError)onError(error);scope.manager.itemError(url);scope.manager.itemEnd(url);},0);}}else {// Initialise array for duplicate requests
  1987. loading[url]=[];loading[url].push({onLoad:onLoad,onProgress:onProgress,onError:onError});request=new XMLHttpRequest();request.open('GET',url,true);request.addEventListener('load',function(event){var response=this.response;var callbacks=loading[url];delete loading[url];if(this.status===200||this.status===0){// Some browsers return HTTP Status 0 when using non-http protocol
  1988. // e.g. 'file://' or 'data://'. Handle as success.
  1989. if(this.status===0)console.warn('THREE.FileLoader: HTTP Status 0 received.');// Add to cache only on HTTP success, so that we do not cache
  1990. // error response bodies as proper responses to requests.
  1991. Cache.add(url,response);for(var _i268=0,il=callbacks.length;_i268<il;_i268++){var callback=callbacks[_i268];if(callback.onLoad)callback.onLoad(response);}scope.manager.itemEnd(url);}else {for(var _i269=0,_il31=callbacks.length;_i269<_il31;_i269++){var _callback=callbacks[_i269];if(_callback.onError)_callback.onError(event);}scope.manager.itemError(url);scope.manager.itemEnd(url);}},false);request.addEventListener('progress',function(event){var callbacks=loading[url];for(var _i270=0,il=callbacks.length;_i270<il;_i270++){var callback=callbacks[_i270];if(callback.onProgress)callback.onProgress(event);}},false);request.addEventListener('error',function(event){var callbacks=loading[url];delete loading[url];for(var _i271=0,il=callbacks.length;_i271<il;_i271++){var callback=callbacks[_i271];if(callback.onError)callback.onError(event);}scope.manager.itemError(url);scope.manager.itemEnd(url);},false);request.addEventListener('abort',function(event){var callbacks=loading[url];delete loading[url];for(var _i272=0,il=callbacks.length;_i272<il;_i272++){var callback=callbacks[_i272];if(callback.onError)callback.onError(event);}scope.manager.itemError(url);scope.manager.itemEnd(url);},false);if(this.responseType!==undefined)request.responseType=this.responseType;if(this.withCredentials!==undefined)request.withCredentials=this.withCredentials;if(request.overrideMimeType)request.overrideMimeType(this.mimeType!==undefined?this.mimeType:'text/plain');for(var header in this.requestHeader){request.setRequestHeader(header,this.requestHeader[header]);}request.send(null);}scope.manager.itemStart(url);return request;},setResponseType:function setResponseType(value){this.responseType=value;return this;},setMimeType:function setMimeType(value){this.mimeType=value;return this;}});function AnimationLoader(manager){Loader.call(this,manager);}AnimationLoader.prototype=Object.assign(Object.create(Loader.prototype),{constructor:AnimationLoader,load:function load(url,onLoad,onProgress,onError){var scope=this;var loader=new FileLoader(scope.manager);loader.setPath(scope.path);loader.setRequestHeader(scope.requestHeader);loader.setWithCredentials(scope.withCredentials);loader.load(url,function(text){try{onLoad(scope.parse(JSON.parse(text)));}catch(e){if(onError){onError(e);}else {console.error(e);}scope.manager.itemError(url);}},onProgress,onError);},parse:function parse(json){var animations=[];for(var _i273=0;_i273<json.length;_i273++){var clip=AnimationClip.parse(json[_i273]);animations.push(clip);}return animations;}});/**
  1992. * Abstract Base class to block based textures loader (dds, pvr, ...)
  1993. *
  1994. * Sub classes have to implement the parse() method which will be used in load().
  1995. */function CompressedTextureLoader(manager){Loader.call(this,manager);}CompressedTextureLoader.prototype=Object.assign(Object.create(Loader.prototype),{constructor:CompressedTextureLoader,load:function load(url,onLoad,onProgress,onError){var scope=this;var images=[];var texture=new CompressedTexture();var loader=new FileLoader(this.manager);loader.setPath(this.path);loader.setResponseType('arraybuffer');loader.setRequestHeader(this.requestHeader);loader.setWithCredentials(scope.withCredentials);var loaded=0;function loadTexture(i){loader.load(url[i],function(buffer){var texDatas=scope.parse(buffer,true);images[i]={width:texDatas.width,height:texDatas.height,format:texDatas.format,mipmaps:texDatas.mipmaps};loaded+=1;if(loaded===6){if(texDatas.mipmapCount===1)texture.minFilter=LinearFilter;texture.image=images;texture.format=texDatas.format;texture.needsUpdate=true;if(onLoad)onLoad(texture);}},onProgress,onError);}if(Array.isArray(url)){for(var _i274=0,il=url.length;_i274<il;++_i274){loadTexture(_i274);}}else {// compressed cubemap texture stored in a single DDS file
  1996. loader.load(url,function(buffer){var texDatas=scope.parse(buffer,true);if(texDatas.isCubemap){var faces=texDatas.mipmaps.length/texDatas.mipmapCount;for(var f=0;f<faces;f++){images[f]={mipmaps:[]};for(var _i275=0;_i275<texDatas.mipmapCount;_i275++){images[f].mipmaps.push(texDatas.mipmaps[f*texDatas.mipmapCount+_i275]);images[f].format=texDatas.format;images[f].width=texDatas.width;images[f].height=texDatas.height;}}texture.image=images;}else {texture.image.width=texDatas.width;texture.image.height=texDatas.height;texture.mipmaps=texDatas.mipmaps;}if(texDatas.mipmapCount===1){texture.minFilter=LinearFilter;}texture.format=texDatas.format;texture.needsUpdate=true;if(onLoad)onLoad(texture);},onProgress,onError);}return texture;}});function ImageLoader(manager){Loader.call(this,manager);}ImageLoader.prototype=Object.assign(Object.create(Loader.prototype),{constructor:ImageLoader,load:function load(url,onLoad,onProgress,onError){if(this.path!==undefined)url=this.path+url;url=this.manager.resolveURL(url);var scope=this;var cached=Cache.get(url);if(cached!==undefined){scope.manager.itemStart(url);setTimeout(function(){if(onLoad)onLoad(cached);scope.manager.itemEnd(url);},0);return cached;}var image=document.createElementNS('http://www.w3.org/1999/xhtml','img');function onImageLoad(){image.removeEventListener('load',onImageLoad,false);image.removeEventListener('error',onImageError,false);Cache.add(url,this);if(onLoad)onLoad(this);scope.manager.itemEnd(url);}function onImageError(event){image.removeEventListener('load',onImageLoad,false);image.removeEventListener('error',onImageError,false);if(onError)onError(event);scope.manager.itemError(url);scope.manager.itemEnd(url);}image.addEventListener('load',onImageLoad,false);image.addEventListener('error',onImageError,false);if(url.substr(0,5)!=='data:'){if(this.crossOrigin!==undefined)image.crossOrigin=this.crossOrigin;}scope.manager.itemStart(url);image.src=url;return image;}});function CubeTextureLoader(manager){Loader.call(this,manager);}CubeTextureLoader.prototype=Object.assign(Object.create(Loader.prototype),{constructor:CubeTextureLoader,load:function load(urls,onLoad,onProgress,onError){var texture=new CubeTexture();var loader=new ImageLoader(this.manager);loader.setCrossOrigin(this.crossOrigin);loader.setPath(this.path);var loaded=0;function loadTexture(i){loader.load(urls[i],function(image){texture.images[i]=image;loaded++;if(loaded===6){texture.needsUpdate=true;if(onLoad)onLoad(texture);}},undefined,onError);}for(var _i276=0;_i276<urls.length;++_i276){loadTexture(_i276);}return texture;}});/**
  1997. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  1998. *
  1999. * Sub classes have to implement the parse() method which will be used in load().
  2000. */function DataTextureLoader(manager){Loader.call(this,manager);}DataTextureLoader.prototype=Object.assign(Object.create(Loader.prototype),{constructor:DataTextureLoader,load:function load(url,onLoad,onProgress,onError){var scope=this;var texture=new DataTexture();var loader=new FileLoader(this.manager);loader.setResponseType('arraybuffer');loader.setRequestHeader(this.requestHeader);loader.setPath(this.path);loader.setWithCredentials(scope.withCredentials);loader.load(url,function(buffer){var texData=scope.parse(buffer);if(!texData)return;if(texData.image!==undefined){texture.image=texData.image;}else if(texData.data!==undefined){texture.image.width=texData.width;texture.image.height=texData.height;texture.image.data=texData.data;}texture.wrapS=texData.wrapS!==undefined?texData.wrapS:ClampToEdgeWrapping;texture.wrapT=texData.wrapT!==undefined?texData.wrapT:ClampToEdgeWrapping;texture.magFilter=texData.magFilter!==undefined?texData.magFilter:LinearFilter;texture.minFilter=texData.minFilter!==undefined?texData.minFilter:LinearFilter;texture.anisotropy=texData.anisotropy!==undefined?texData.anisotropy:1;if(texData.format!==undefined){texture.format=texData.format;}if(texData.type!==undefined){texture.type=texData.type;}if(texData.mipmaps!==undefined){texture.mipmaps=texData.mipmaps;texture.minFilter=LinearMipmapLinearFilter;// presumably...
  2001. }if(texData.mipmapCount===1){texture.minFilter=LinearFilter;}texture.needsUpdate=true;if(onLoad)onLoad(texture,texData);},onProgress,onError);return texture;}});function TextureLoader(manager){Loader.call(this,manager);}TextureLoader.prototype=Object.assign(Object.create(Loader.prototype),{constructor:TextureLoader,load:function load(url,onLoad,onProgress,onError){var texture=new Texture();var loader=new ImageLoader(this.manager);loader.setCrossOrigin(this.crossOrigin);loader.setPath(this.path);loader.load(url,function(image){texture.image=image;// JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  2002. var isJPEG=url.search(/\.jpe?g($|\?)/i)>0||url.search(/^data\:image\/jpeg/)===0;texture.format=isJPEG?RGBFormat:RGBAFormat;texture.needsUpdate=true;if(onLoad!==undefined){onLoad(texture);}},onProgress,onError);return texture;}});/**
  2003. * Extensible curve object.
  2004. *
  2005. * Some common of curve methods:
  2006. * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
  2007. * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
  2008. * .getPoints(), .getSpacedPoints()
  2009. * .getLength()
  2010. * .updateArcLengths()
  2011. *
  2012. * This following curves inherit from THREE.Curve:
  2013. *
  2014. * -- 2D curves --
  2015. * THREE.ArcCurve
  2016. * THREE.CubicBezierCurve
  2017. * THREE.EllipseCurve
  2018. * THREE.LineCurve
  2019. * THREE.QuadraticBezierCurve
  2020. * THREE.SplineCurve
  2021. *
  2022. * -- 3D curves --
  2023. * THREE.CatmullRomCurve3
  2024. * THREE.CubicBezierCurve3
  2025. * THREE.LineCurve3
  2026. * THREE.QuadraticBezierCurve3
  2027. *
  2028. * A series of curves can be represented as a THREE.CurvePath.
  2029. *
  2030. **/function Curve(){this.type='Curve';this.arcLengthDivisions=200;}Object.assign(Curve.prototype,{// Virtual base class method to overwrite and implement in subclasses
  2031. // - t [0 .. 1]
  2032. getPoint:function getPoint(/* t, optionalTarget */){console.warn('THREE.Curve: .getPoint() not implemented.');return null;},// Get point at relative position in curve according to arc length
  2033. // - u [0 .. 1]
  2034. getPointAt:function getPointAt(u,optionalTarget){var t=this.getUtoTmapping(u);return this.getPoint(t,optionalTarget);},// Get sequence of points using getPoint( t )
  2035. getPoints:function getPoints(){var divisions=arguments.length>0&&arguments[0]!==undefined?arguments[0]:5;var points=[];for(var d=0;d<=divisions;d++){points.push(this.getPoint(d/divisions));}return points;},// Get sequence of points using getPointAt( u )
  2036. getSpacedPoints:function getSpacedPoints(){var divisions=arguments.length>0&&arguments[0]!==undefined?arguments[0]:5;var points=[];for(var d=0;d<=divisions;d++){points.push(this.getPointAt(d/divisions));}return points;},// Get total curve arc length
  2037. getLength:function getLength(){var lengths=this.getLengths();return lengths[lengths.length-1];},// Get list of cumulative segment lengths
  2038. getLengths:function getLengths(divisions){if(divisions===undefined)divisions=this.arcLengthDivisions;if(this.cacheArcLengths&&this.cacheArcLengths.length===divisions+1&&!this.needsUpdate){return this.cacheArcLengths;}this.needsUpdate=false;var cache=[];var current,last=this.getPoint(0);var sum=0;cache.push(0);for(var p=1;p<=divisions;p++){current=this.getPoint(p/divisions);sum+=current.distanceTo(last);cache.push(sum);last=current;}this.cacheArcLengths=cache;return cache;// { sums: cache, sum: sum }; Sum is in the last element.
  2039. },updateArcLengths:function updateArcLengths(){this.needsUpdate=true;this.getLengths();},// Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  2040. getUtoTmapping:function getUtoTmapping(u,distance){var arcLengths=this.getLengths();var i=0;var il=arcLengths.length;var targetArcLength;// The targeted u distance value to get
  2041. if(distance){targetArcLength=distance;}else {targetArcLength=u*arcLengths[il-1];}// binary search for the index with largest value smaller than target u distance
  2042. var low=0,high=il-1,comparison;while(low<=high){i=Math.floor(low+(high-low)/2);// less likely to overflow, though probably not issue here, JS doesn't really have integers, all numbers are floats
  2043. comparison=arcLengths[i]-targetArcLength;if(comparison<0){low=i+1;}else if(comparison>0){high=i-1;}else {high=i;break;// DONE
  2044. }}i=high;if(arcLengths[i]===targetArcLength){return i/(il-1);}// we could get finer grain at lengths, or use simple interpolation between two points
  2045. var lengthBefore=arcLengths[i];var lengthAfter=arcLengths[i+1];var segmentLength=lengthAfter-lengthBefore;// determine where we are between the 'before' and 'after' points
  2046. var segmentFraction=(targetArcLength-lengthBefore)/segmentLength;// add that fractional amount to t
  2047. var t=(i+segmentFraction)/(il-1);return t;},// Returns a unit vector tangent at t
  2048. // In case any sub curve does not implement its tangent derivation,
  2049. // 2 points a small delta apart will be used to find its gradient
  2050. // which seems to give a reasonable approximation
  2051. getTangent:function getTangent(t,optionalTarget){var delta=0.0001;var t1=t-delta;var t2=t+delta;// Capping in case of danger
  2052. if(t1<0)t1=0;if(t2>1)t2=1;var pt1=this.getPoint(t1);var pt2=this.getPoint(t2);var tangent=optionalTarget||(pt1.isVector2?new Vector2():new Vector3());tangent.copy(pt2).sub(pt1).normalize();return tangent;},getTangentAt:function getTangentAt(u,optionalTarget){var t=this.getUtoTmapping(u);return this.getTangent(t,optionalTarget);},computeFrenetFrames:function computeFrenetFrames(segments,closed){// see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  2053. var normal=new Vector3();var tangents=[];var normals=[];var binormals=[];var vec=new Vector3();var mat=new Matrix4();// compute the tangent vectors for each segment on the curve
  2054. for(var _i277=0;_i277<=segments;_i277++){var u=_i277/segments;tangents[_i277]=this.getTangentAt(u,new Vector3());tangents[_i277].normalize();}// select an initial normal vector perpendicular to the first tangent vector,
  2055. // and in the direction of the minimum tangent xyz component
  2056. normals[0]=new Vector3();binormals[0]=new Vector3();var min=Number.MAX_VALUE;var tx=Math.abs(tangents[0].x);var ty=Math.abs(tangents[0].y);var tz=Math.abs(tangents[0].z);if(tx<=min){min=tx;normal.set(1,0,0);}if(ty<=min){min=ty;normal.set(0,1,0);}if(tz<=min){normal.set(0,0,1);}vec.crossVectors(tangents[0],normal).normalize();normals[0].crossVectors(tangents[0],vec);binormals[0].crossVectors(tangents[0],normals[0]);// compute the slowly-varying normal and binormal vectors for each segment on the curve
  2057. for(var _i278=1;_i278<=segments;_i278++){normals[_i278]=normals[_i278-1].clone();binormals[_i278]=binormals[_i278-1].clone();vec.crossVectors(tangents[_i278-1],tangents[_i278]);if(vec.length()>Number.EPSILON){vec.normalize();var theta=Math.acos(MathUtils.clamp(tangents[_i278-1].dot(tangents[_i278]),-1,1));// clamp for floating pt errors
  2058. normals[_i278].applyMatrix4(mat.makeRotationAxis(vec,theta));}binormals[_i278].crossVectors(tangents[_i278],normals[_i278]);}// if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  2059. if(closed===true){var _theta=Math.acos(MathUtils.clamp(normals[0].dot(normals[segments]),-1,1));_theta/=segments;if(tangents[0].dot(vec.crossVectors(normals[0],normals[segments]))>0){_theta=-_theta;}for(var _i279=1;_i279<=segments;_i279++){// twist a little...
  2060. normals[_i279].applyMatrix4(mat.makeRotationAxis(tangents[_i279],_theta*_i279));binormals[_i279].crossVectors(tangents[_i279],normals[_i279]);}}return {tangents:tangents,normals:normals,binormals:binormals};},clone:function clone(){return new this.constructor().copy(this);},copy:function copy(source){this.arcLengthDivisions=source.arcLengthDivisions;return this;},toJSON:function toJSON(){var data={metadata:{version:4.5,type:'Curve',generator:'Curve.toJSON'}};data.arcLengthDivisions=this.arcLengthDivisions;data.type=this.type;return data;},fromJSON:function fromJSON(json){this.arcLengthDivisions=json.arcLengthDivisions;return this;}});function EllipseCurve(aX,aY,xRadius,yRadius,aStartAngle,aEndAngle,aClockwise,aRotation){Curve.call(this);this.type='EllipseCurve';this.aX=aX||0;this.aY=aY||0;this.xRadius=xRadius||1;this.yRadius=yRadius||1;this.aStartAngle=aStartAngle||0;this.aEndAngle=aEndAngle||2*Math.PI;this.aClockwise=aClockwise||false;this.aRotation=aRotation||0;}EllipseCurve.prototype=Object.create(Curve.prototype);EllipseCurve.prototype.constructor=EllipseCurve;EllipseCurve.prototype.isEllipseCurve=true;EllipseCurve.prototype.getPoint=function(t,optionalTarget){var point=optionalTarget||new Vector2();var twoPi=Math.PI*2;var deltaAngle=this.aEndAngle-this.aStartAngle;var samePoints=Math.abs(deltaAngle)<Number.EPSILON;// ensures that deltaAngle is 0 .. 2 PI
  2061. while(deltaAngle<0)deltaAngle+=twoPi;while(deltaAngle>twoPi)deltaAngle-=twoPi;if(deltaAngle<Number.EPSILON){if(samePoints){deltaAngle=0;}else {deltaAngle=twoPi;}}if(this.aClockwise===true&&!samePoints){if(deltaAngle===twoPi){deltaAngle=-twoPi;}else {deltaAngle=deltaAngle-twoPi;}}var angle=this.aStartAngle+t*deltaAngle;var x=this.aX+this.xRadius*Math.cos(angle);var y=this.aY+this.yRadius*Math.sin(angle);if(this.aRotation!==0){var cos=Math.cos(this.aRotation);var sin=Math.sin(this.aRotation);var tx=x-this.aX;var ty=y-this.aY;// Rotate the point about the center of the ellipse.
  2062. x=tx*cos-ty*sin+this.aX;y=tx*sin+ty*cos+this.aY;}return point.set(x,y);};EllipseCurve.prototype.copy=function(source){Curve.prototype.copy.call(this,source);this.aX=source.aX;this.aY=source.aY;this.xRadius=source.xRadius;this.yRadius=source.yRadius;this.aStartAngle=source.aStartAngle;this.aEndAngle=source.aEndAngle;this.aClockwise=source.aClockwise;this.aRotation=source.aRotation;return this;};EllipseCurve.prototype.toJSON=function(){var data=Curve.prototype.toJSON.call(this);data.aX=this.aX;data.aY=this.aY;data.xRadius=this.xRadius;data.yRadius=this.yRadius;data.aStartAngle=this.aStartAngle;data.aEndAngle=this.aEndAngle;data.aClockwise=this.aClockwise;data.aRotation=this.aRotation;return data;};EllipseCurve.prototype.fromJSON=function(json){Curve.prototype.fromJSON.call(this,json);this.aX=json.aX;this.aY=json.aY;this.xRadius=json.xRadius;this.yRadius=json.yRadius;this.aStartAngle=json.aStartAngle;this.aEndAngle=json.aEndAngle;this.aClockwise=json.aClockwise;this.aRotation=json.aRotation;return this;};function ArcCurve(aX,aY,aRadius,aStartAngle,aEndAngle,aClockwise){EllipseCurve.call(this,aX,aY,aRadius,aRadius,aStartAngle,aEndAngle,aClockwise);this.type='ArcCurve';}ArcCurve.prototype=Object.create(EllipseCurve.prototype);ArcCurve.prototype.constructor=ArcCurve;ArcCurve.prototype.isArcCurve=true;/**
  2063. * Centripetal CatmullRom Curve - which is useful for avoiding
  2064. * cusps and self-intersections in non-uniform catmull rom curves.
  2065. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  2066. *
  2067. * curve.type accepts centripetal(default), chordal and catmullrom
  2068. * curve.tension is used for catmullrom which defaults to 0.5
  2069. */ /*
  2070. Based on an optimized c++ solution in
  2071. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  2072. - http://ideone.com/NoEbVM
  2073. This CubicPoly class could be used for reusing some variables and calculations,
  2074. but for three.js curve use, it could be possible inlined and flatten into a single function call
  2075. which can be placed in CurveUtils.
  2076. */function CubicPoly(){var c0=0,c1=0,c2=0,c3=0;/*
  2077. * Compute coefficients for a cubic polynomial
  2078. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  2079. * such that
  2080. * p(0) = x0, p(1) = x1
  2081. * and
  2082. * p'(0) = t0, p'(1) = t1.
  2083. */function init(x0,x1,t0,t1){c0=x0;c1=t0;c2=-3*x0+3*x1-2*t0-t1;c3=2*x0-2*x1+t0+t1;}return {initCatmullRom:function initCatmullRom(x0,x1,x2,x3,tension){init(x1,x2,tension*(x2-x0),tension*(x3-x1));},initNonuniformCatmullRom:function initNonuniformCatmullRom(x0,x1,x2,x3,dt0,dt1,dt2){// compute tangents when parameterized in [t1,t2]
  2084. var t1=(x1-x0)/dt0-(x2-x0)/(dt0+dt1)+(x2-x1)/dt1;var t2=(x2-x1)/dt1-(x3-x1)/(dt1+dt2)+(x3-x2)/dt2;// rescale tangents for parametrization in [0,1]
  2085. t1*=dt1;t2*=dt1;init(x1,x2,t1,t2);},calc:function calc(t){var t2=t*t;var t3=t2*t;return c0+c1*t+c2*t2+c3*t3;}};}//
  2086. var tmp=new Vector3();var px=new CubicPoly(),py=new CubicPoly(),pz=new CubicPoly();function CatmullRomCurve3(){var points=arguments.length>0&&arguments[0]!==undefined?arguments[0]:[];var closed=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var curveType=arguments.length>2&&arguments[2]!==undefined?arguments[2]:'centripetal';var tension=arguments.length>3&&arguments[3]!==undefined?arguments[3]:0.5;Curve.call(this);this.type='CatmullRomCurve3';this.points=points;this.closed=closed;this.curveType=curveType;this.tension=tension;}CatmullRomCurve3.prototype=Object.create(Curve.prototype);CatmullRomCurve3.prototype.constructor=CatmullRomCurve3;CatmullRomCurve3.prototype.isCatmullRomCurve3=true;CatmullRomCurve3.prototype.getPoint=function(t){var optionalTarget=arguments.length>1&&arguments[1]!==undefined?arguments[1]:new Vector3();var point=optionalTarget;var points=this.points;var l=points.length;var p=(l-(this.closed?0:1))*t;var intPoint=Math.floor(p);var weight=p-intPoint;if(this.closed){intPoint+=intPoint>0?0:(Math.floor(Math.abs(intPoint)/l)+1)*l;}else if(weight===0&&intPoint===l-1){intPoint=l-2;weight=1;}var p0,p3;// 4 points (p1 & p2 defined below)
  2087. if(this.closed||intPoint>0){p0=points[(intPoint-1)%l];}else {// extrapolate first point
  2088. tmp.subVectors(points[0],points[1]).add(points[0]);p0=tmp;}var p1=points[intPoint%l];var p2=points[(intPoint+1)%l];if(this.closed||intPoint+2<l){p3=points[(intPoint+2)%l];}else {// extrapolate last point
  2089. tmp.subVectors(points[l-1],points[l-2]).add(points[l-1]);p3=tmp;}if(this.curveType==='centripetal'||this.curveType==='chordal'){// init Centripetal / Chordal Catmull-Rom
  2090. var pow=this.curveType==='chordal'?0.5:0.25;var dt0=Math.pow(p0.distanceToSquared(p1),pow);var dt1=Math.pow(p1.distanceToSquared(p2),pow);var dt2=Math.pow(p2.distanceToSquared(p3),pow);// safety check for repeated points
  2091. if(dt1<1e-4)dt1=1.0;if(dt0<1e-4)dt0=dt1;if(dt2<1e-4)dt2=dt1;px.initNonuniformCatmullRom(p0.x,p1.x,p2.x,p3.x,dt0,dt1,dt2);py.initNonuniformCatmullRom(p0.y,p1.y,p2.y,p3.y,dt0,dt1,dt2);pz.initNonuniformCatmullRom(p0.z,p1.z,p2.z,p3.z,dt0,dt1,dt2);}else if(this.curveType==='catmullrom'){px.initCatmullRom(p0.x,p1.x,p2.x,p3.x,this.tension);py.initCatmullRom(p0.y,p1.y,p2.y,p3.y,this.tension);pz.initCatmullRom(p0.z,p1.z,p2.z,p3.z,this.tension);}point.set(px.calc(weight),py.calc(weight),pz.calc(weight));return point;};CatmullRomCurve3.prototype.copy=function(source){Curve.prototype.copy.call(this,source);this.points=[];for(var _i280=0,l=source.points.length;_i280<l;_i280++){var point=source.points[_i280];this.points.push(point.clone());}this.closed=source.closed;this.curveType=source.curveType;this.tension=source.tension;return this;};CatmullRomCurve3.prototype.toJSON=function(){var data=Curve.prototype.toJSON.call(this);data.points=[];for(var _i281=0,l=this.points.length;_i281<l;_i281++){var point=this.points[_i281];data.points.push(point.toArray());}data.closed=this.closed;data.curveType=this.curveType;data.tension=this.tension;return data;};CatmullRomCurve3.prototype.fromJSON=function(json){Curve.prototype.fromJSON.call(this,json);this.points=[];for(var _i282=0,l=json.points.length;_i282<l;_i282++){var point=json.points[_i282];this.points.push(new Vector3().fromArray(point));}this.closed=json.closed;this.curveType=json.curveType;this.tension=json.tension;return this;};/**
  2092. * Bezier Curves formulas obtained from
  2093. * http://en.wikipedia.org/wiki/Bézier_curve
  2094. */function CatmullRom(t,p0,p1,p2,p3){var v0=(p2-p0)*0.5;var v1=(p3-p1)*0.5;var t2=t*t;var t3=t*t2;return (2*p1-2*p2+v0+v1)*t3+(-3*p1+3*p2-2*v0-v1)*t2+v0*t+p1;}//
  2095. function QuadraticBezierP0(t,p){var k=1-t;return k*k*p;}function QuadraticBezierP1(t,p){return 2*(1-t)*t*p;}function QuadraticBezierP2(t,p){return t*t*p;}function QuadraticBezier(t,p0,p1,p2){return QuadraticBezierP0(t,p0)+QuadraticBezierP1(t,p1)+QuadraticBezierP2(t,p2);}//
  2096. function CubicBezierP0(t,p){var k=1-t;return k*k*k*p;}function CubicBezierP1(t,p){var k=1-t;return 3*k*k*t*p;}function CubicBezierP2(t,p){return 3*(1-t)*t*t*p;}function CubicBezierP3(t,p){return t*t*t*p;}function CubicBezier(t,p0,p1,p2,p3){return CubicBezierP0(t,p0)+CubicBezierP1(t,p1)+CubicBezierP2(t,p2)+CubicBezierP3(t,p3);}function CubicBezierCurve(){var v0=arguments.length>0&&arguments[0]!==undefined?arguments[0]:new Vector2();var v1=arguments.length>1&&arguments[1]!==undefined?arguments[1]:new Vector2();var v2=arguments.length>2&&arguments[2]!==undefined?arguments[2]:new Vector2();var v3=arguments.length>3&&arguments[3]!==undefined?arguments[3]:new Vector2();Curve.call(this);this.type='CubicBezierCurve';this.v0=v0;this.v1=v1;this.v2=v2;this.v3=v3;}CubicBezierCurve.prototype=Object.create(Curve.prototype);CubicBezierCurve.prototype.constructor=CubicBezierCurve;CubicBezierCurve.prototype.isCubicBezierCurve=true;CubicBezierCurve.prototype.getPoint=function(t){var optionalTarget=arguments.length>1&&arguments[1]!==undefined?arguments[1]:new Vector2();var point=optionalTarget;var v0=this.v0,v1=this.v1,v2=this.v2,v3=this.v3;point.set(CubicBezier(t,v0.x,v1.x,v2.x,v3.x),CubicBezier(t,v0.y,v1.y,v2.y,v3.y));return point;};CubicBezierCurve.prototype.copy=function(source){Curve.prototype.copy.call(this,source);this.v0.copy(source.v0);this.v1.copy(source.v1);this.v2.copy(source.v2);this.v3.copy(source.v3);return this;};CubicBezierCurve.prototype.toJSON=function(){var data=Curve.prototype.toJSON.call(this);data.v0=this.v0.toArray();data.v1=this.v1.toArray();data.v2=this.v2.toArray();data.v3=this.v3.toArray();return data;};CubicBezierCurve.prototype.fromJSON=function(json){Curve.prototype.fromJSON.call(this,json);this.v0.fromArray(json.v0);this.v1.fromArray(json.v1);this.v2.fromArray(json.v2);this.v3.fromArray(json.v3);return this;};function CubicBezierCurve3(){var v0=arguments.length>0&&arguments[0]!==undefined?arguments[0]:new Vector3();var v1=arguments.length>1&&arguments[1]!==undefined?arguments[1]:new Vector3();var v2=arguments.length>2&&arguments[2]!==undefined?arguments[2]:new Vector3();var v3=arguments.length>3&&arguments[3]!==undefined?arguments[3]:new Vector3();Curve.call(this);this.type='CubicBezierCurve3';this.v0=v0;this.v1=v1;this.v2=v2;this.v3=v3;}CubicBezierCurve3.prototype=Object.create(Curve.prototype);CubicBezierCurve3.prototype.constructor=CubicBezierCurve3;CubicBezierCurve3.prototype.isCubicBezierCurve3=true;CubicBezierCurve3.prototype.getPoint=function(t){var optionalTarget=arguments.length>1&&arguments[1]!==undefined?arguments[1]:new Vector3();var point=optionalTarget;var v0=this.v0,v1=this.v1,v2=this.v2,v3=this.v3;point.set(CubicBezier(t,v0.x,v1.x,v2.x,v3.x),CubicBezier(t,v0.y,v1.y,v2.y,v3.y),CubicBezier(t,v0.z,v1.z,v2.z,v3.z));return point;};CubicBezierCurve3.prototype.copy=function(source){Curve.prototype.copy.call(this,source);this.v0.copy(source.v0);this.v1.copy(source.v1);this.v2.copy(source.v2);this.v3.copy(source.v3);return this;};CubicBezierCurve3.prototype.toJSON=function(){var data=Curve.prototype.toJSON.call(this);data.v0=this.v0.toArray();data.v1=this.v1.toArray();data.v2=this.v2.toArray();data.v3=this.v3.toArray();return data;};CubicBezierCurve3.prototype.fromJSON=function(json){Curve.prototype.fromJSON.call(this,json);this.v0.fromArray(json.v0);this.v1.fromArray(json.v1);this.v2.fromArray(json.v2);this.v3.fromArray(json.v3);return this;};function LineCurve(){var v1=arguments.length>0&&arguments[0]!==undefined?arguments[0]:new Vector2();var v2=arguments.length>1&&arguments[1]!==undefined?arguments[1]:new Vector2();Curve.call(this);this.type='LineCurve';this.v1=v1;this.v2=v2;}LineCurve.prototype=Object.create(Curve.prototype);LineCurve.prototype.constructor=LineCurve;LineCurve.prototype.isLineCurve=true;LineCurve.prototype.getPoint=function(t){var optionalTarget=arguments.length>1&&arguments[1]!==undefined?arguments[1]:new Vector2();var point=optionalTarget;if(t===1){point.copy(this.v2);}else {point.copy(this.v2).sub(this.v1);point.multiplyScalar(t).add(this.v1);}return point;};// Line curve is linear, so we can overwrite default getPointAt
  2097. LineCurve.prototype.getPointAt=function(u,optionalTarget){return this.getPoint(u,optionalTarget);};LineCurve.prototype.getTangent=function(t,optionalTarget){var tangent=optionalTarget||new Vector2();tangent.copy(this.v2).sub(this.v1).normalize();return tangent;};LineCurve.prototype.copy=function(source){Curve.prototype.copy.call(this,source);this.v1.copy(source.v1);this.v2.copy(source.v2);return this;};LineCurve.prototype.toJSON=function(){var data=Curve.prototype.toJSON.call(this);data.v1=this.v1.toArray();data.v2=this.v2.toArray();return data;};LineCurve.prototype.fromJSON=function(json){Curve.prototype.fromJSON.call(this,json);this.v1.fromArray(json.v1);this.v2.fromArray(json.v2);return this;};function LineCurve3(){var v1=arguments.length>0&&arguments[0]!==undefined?arguments[0]:new Vector3();var v2=arguments.length>1&&arguments[1]!==undefined?arguments[1]:new Vector3();Curve.call(this);this.type='LineCurve3';this.v1=v1;this.v2=v2;}LineCurve3.prototype=Object.create(Curve.prototype);LineCurve3.prototype.constructor=LineCurve3;LineCurve3.prototype.isLineCurve3=true;LineCurve3.prototype.getPoint=function(t){var optionalTarget=arguments.length>1&&arguments[1]!==undefined?arguments[1]:new Vector3();var point=optionalTarget;if(t===1){point.copy(this.v2);}else {point.copy(this.v2).sub(this.v1);point.multiplyScalar(t).add(this.v1);}return point;};// Line curve is linear, so we can overwrite default getPointAt
  2098. LineCurve3.prototype.getPointAt=function(u,optionalTarget){return this.getPoint(u,optionalTarget);};LineCurve3.prototype.copy=function(source){Curve.prototype.copy.call(this,source);this.v1.copy(source.v1);this.v2.copy(source.v2);return this;};LineCurve3.prototype.toJSON=function(){var data=Curve.prototype.toJSON.call(this);data.v1=this.v1.toArray();data.v2=this.v2.toArray();return data;};LineCurve3.prototype.fromJSON=function(json){Curve.prototype.fromJSON.call(this,json);this.v1.fromArray(json.v1);this.v2.fromArray(json.v2);return this;};function QuadraticBezierCurve(){var v0=arguments.length>0&&arguments[0]!==undefined?arguments[0]:new Vector2();var v1=arguments.length>1&&arguments[1]!==undefined?arguments[1]:new Vector2();var v2=arguments.length>2&&arguments[2]!==undefined?arguments[2]:new Vector2();Curve.call(this);this.type='QuadraticBezierCurve';this.v0=v0;this.v1=v1;this.v2=v2;}QuadraticBezierCurve.prototype=Object.create(Curve.prototype);QuadraticBezierCurve.prototype.constructor=QuadraticBezierCurve;QuadraticBezierCurve.prototype.isQuadraticBezierCurve=true;QuadraticBezierCurve.prototype.getPoint=function(t){var optionalTarget=arguments.length>1&&arguments[1]!==undefined?arguments[1]:new Vector2();var point=optionalTarget;var v0=this.v0,v1=this.v1,v2=this.v2;point.set(QuadraticBezier(t,v0.x,v1.x,v2.x),QuadraticBezier(t,v0.y,v1.y,v2.y));return point;};QuadraticBezierCurve.prototype.copy=function(source){Curve.prototype.copy.call(this,source);this.v0.copy(source.v0);this.v1.copy(source.v1);this.v2.copy(source.v2);return this;};QuadraticBezierCurve.prototype.toJSON=function(){var data=Curve.prototype.toJSON.call(this);data.v0=this.v0.toArray();data.v1=this.v1.toArray();data.v2=this.v2.toArray();return data;};QuadraticBezierCurve.prototype.fromJSON=function(json){Curve.prototype.fromJSON.call(this,json);this.v0.fromArray(json.v0);this.v1.fromArray(json.v1);this.v2.fromArray(json.v2);return this;};function QuadraticBezierCurve3(){var v0=arguments.length>0&&arguments[0]!==undefined?arguments[0]:new Vector3();var v1=arguments.length>1&&arguments[1]!==undefined?arguments[1]:new Vector3();var v2=arguments.length>2&&arguments[2]!==undefined?arguments[2]:new Vector3();Curve.call(this);this.type='QuadraticBezierCurve3';this.v0=v0;this.v1=v1;this.v2=v2;}QuadraticBezierCurve3.prototype=Object.create(Curve.prototype);QuadraticBezierCurve3.prototype.constructor=QuadraticBezierCurve3;QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3=true;QuadraticBezierCurve3.prototype.getPoint=function(t){var optionalTarget=arguments.length>1&&arguments[1]!==undefined?arguments[1]:new Vector3();var point=optionalTarget;var v0=this.v0,v1=this.v1,v2=this.v2;point.set(QuadraticBezier(t,v0.x,v1.x,v2.x),QuadraticBezier(t,v0.y,v1.y,v2.y),QuadraticBezier(t,v0.z,v1.z,v2.z));return point;};QuadraticBezierCurve3.prototype.copy=function(source){Curve.prototype.copy.call(this,source);this.v0.copy(source.v0);this.v1.copy(source.v1);this.v2.copy(source.v2);return this;};QuadraticBezierCurve3.prototype.toJSON=function(){var data=Curve.prototype.toJSON.call(this);data.v0=this.v0.toArray();data.v1=this.v1.toArray();data.v2=this.v2.toArray();return data;};QuadraticBezierCurve3.prototype.fromJSON=function(json){Curve.prototype.fromJSON.call(this,json);this.v0.fromArray(json.v0);this.v1.fromArray(json.v1);this.v2.fromArray(json.v2);return this;};function SplineCurve(){var points=arguments.length>0&&arguments[0]!==undefined?arguments[0]:[];Curve.call(this);this.type='SplineCurve';this.points=points;}SplineCurve.prototype=Object.create(Curve.prototype);SplineCurve.prototype.constructor=SplineCurve;SplineCurve.prototype.isSplineCurve=true;SplineCurve.prototype.getPoint=function(t){var optionalTarget=arguments.length>1&&arguments[1]!==undefined?arguments[1]:new Vector2();var point=optionalTarget;var points=this.points;var p=(points.length-1)*t;var intPoint=Math.floor(p);var weight=p-intPoint;var p0=points[intPoint===0?intPoint:intPoint-1];var p1=points[intPoint];var p2=points[intPoint>points.length-2?points.length-1:intPoint+1];var p3=points[intPoint>points.length-3?points.length-1:intPoint+2];point.set(CatmullRom(weight,p0.x,p1.x,p2.x,p3.x),CatmullRom(weight,p0.y,p1.y,p2.y,p3.y));return point;};SplineCurve.prototype.copy=function(source){Curve.prototype.copy.call(this,source);this.points=[];for(var _i283=0,l=source.points.length;_i283<l;_i283++){var point=source.points[_i283];this.points.push(point.clone());}return this;};SplineCurve.prototype.toJSON=function(){var data=Curve.prototype.toJSON.call(this);data.points=[];for(var _i284=0,l=this.points.length;_i284<l;_i284++){var point=this.points[_i284];data.points.push(point.toArray());}return data;};SplineCurve.prototype.fromJSON=function(json){Curve.prototype.fromJSON.call(this,json);this.points=[];for(var _i285=0,l=json.points.length;_i285<l;_i285++){var point=json.points[_i285];this.points.push(new Vector2().fromArray(point));}return this;};var Curves=/*#__PURE__*/Object.freeze({__proto__:null,ArcCurve:ArcCurve,CatmullRomCurve3:CatmullRomCurve3,CubicBezierCurve:CubicBezierCurve,CubicBezierCurve3:CubicBezierCurve3,EllipseCurve:EllipseCurve,LineCurve:LineCurve,LineCurve3:LineCurve3,QuadraticBezierCurve:QuadraticBezierCurve,QuadraticBezierCurve3:QuadraticBezierCurve3,SplineCurve:SplineCurve});/**************************************************************
  2099. * Curved Path - a curve path is simply a array of connected
  2100. * curves, but retains the api of a curve
  2101. **************************************************************/function CurvePath(){Curve.call(this);this.type='CurvePath';this.curves=[];this.autoClose=false;// Automatically closes the path
  2102. }CurvePath.prototype=Object.assign(Object.create(Curve.prototype),{constructor:CurvePath,add:function add(curve){this.curves.push(curve);},closePath:function closePath(){// Add a line curve if start and end of lines are not connected
  2103. var startPoint=this.curves[0].getPoint(0);var endPoint=this.curves[this.curves.length-1].getPoint(1);if(!startPoint.equals(endPoint)){this.curves.push(new LineCurve(endPoint,startPoint));}},// To get accurate point with reference to
  2104. // entire path distance at time t,
  2105. // following has to be done:
  2106. // 1. Length of each sub path have to be known
  2107. // 2. Locate and identify type of curve
  2108. // 3. Get t for the curve
  2109. // 4. Return curve.getPointAt(t')
  2110. getPoint:function getPoint(t){var d=t*this.getLength();var curveLengths=this.getCurveLengths();var i=0;// To think about boundaries points.
  2111. while(i<curveLengths.length){if(curveLengths[i]>=d){var diff=curveLengths[i]-d;var curve=this.curves[i];var segmentLength=curve.getLength();var u=segmentLength===0?0:1-diff/segmentLength;return curve.getPointAt(u);}i++;}return null;// loop where sum != 0, sum > d , sum+1 <d
  2112. },// We cannot use the default THREE.Curve getPoint() with getLength() because in
  2113. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  2114. // getPoint() depends on getLength
  2115. getLength:function getLength(){var lens=this.getCurveLengths();return lens[lens.length-1];},// cacheLengths must be recalculated.
  2116. updateArcLengths:function updateArcLengths(){this.needsUpdate=true;this.cacheLengths=null;this.getCurveLengths();},// Compute lengths and cache them
  2117. // We cannot overwrite getLengths() because UtoT mapping uses it.
  2118. getCurveLengths:function getCurveLengths(){// We use cache values if curves and cache array are same length
  2119. if(this.cacheLengths&&this.cacheLengths.length===this.curves.length){return this.cacheLengths;}// Get length of sub-curve
  2120. // Push sums into cached array
  2121. var lengths=[];var sums=0;for(var _i286=0,l=this.curves.length;_i286<l;_i286++){sums+=this.curves[_i286].getLength();lengths.push(sums);}this.cacheLengths=lengths;return lengths;},getSpacedPoints:function getSpacedPoints(){var divisions=arguments.length>0&&arguments[0]!==undefined?arguments[0]:40;var points=[];for(var _i287=0;_i287<=divisions;_i287++){points.push(this.getPoint(_i287/divisions));}if(this.autoClose){points.push(points[0]);}return points;},getPoints:function getPoints(){var divisions=arguments.length>0&&arguments[0]!==undefined?arguments[0]:12;var points=[];var last;for(var _i288=0,curves=this.curves;_i288<curves.length;_i288++){var curve=curves[_i288];var resolution=curve&&curve.isEllipseCurve?divisions*2:curve&&(curve.isLineCurve||curve.isLineCurve3)?1:curve&&curve.isSplineCurve?divisions*curve.points.length:divisions;var pts=curve.getPoints(resolution);for(var j=0;j<pts.length;j++){var point=pts[j];if(last&&last.equals(point))continue;// ensures no consecutive points are duplicates
  2122. points.push(point);last=point;}}if(this.autoClose&&points.length>1&&!points[points.length-1].equals(points[0])){points.push(points[0]);}return points;},copy:function copy(source){Curve.prototype.copy.call(this,source);this.curves=[];for(var _i289=0,l=source.curves.length;_i289<l;_i289++){var curve=source.curves[_i289];this.curves.push(curve.clone());}this.autoClose=source.autoClose;return this;},toJSON:function toJSON(){var data=Curve.prototype.toJSON.call(this);data.autoClose=this.autoClose;data.curves=[];for(var _i290=0,l=this.curves.length;_i290<l;_i290++){var curve=this.curves[_i290];data.curves.push(curve.toJSON());}return data;},fromJSON:function fromJSON(json){Curve.prototype.fromJSON.call(this,json);this.autoClose=json.autoClose;this.curves=[];for(var _i291=0,l=json.curves.length;_i291<l;_i291++){var curve=json.curves[_i291];this.curves.push(new Curves[curve.type]().fromJSON(curve));}return this;}});function Path(points){CurvePath.call(this);this.type='Path';this.currentPoint=new Vector2();if(points){this.setFromPoints(points);}}Path.prototype=Object.assign(Object.create(CurvePath.prototype),{constructor:Path,setFromPoints:function setFromPoints(points){this.moveTo(points[0].x,points[0].y);for(var _i292=1,l=points.length;_i292<l;_i292++){this.lineTo(points[_i292].x,points[_i292].y);}return this;},moveTo:function moveTo(x,y){this.currentPoint.set(x,y);// TODO consider referencing vectors instead of copying?
  2123. return this;},lineTo:function lineTo(x,y){var curve=new LineCurve(this.currentPoint.clone(),new Vector2(x,y));this.curves.push(curve);this.currentPoint.set(x,y);return this;},quadraticCurveTo:function quadraticCurveTo(aCPx,aCPy,aX,aY){var curve=new QuadraticBezierCurve(this.currentPoint.clone(),new Vector2(aCPx,aCPy),new Vector2(aX,aY));this.curves.push(curve);this.currentPoint.set(aX,aY);return this;},bezierCurveTo:function bezierCurveTo(aCP1x,aCP1y,aCP2x,aCP2y,aX,aY){var curve=new CubicBezierCurve(this.currentPoint.clone(),new Vector2(aCP1x,aCP1y),new Vector2(aCP2x,aCP2y),new Vector2(aX,aY));this.curves.push(curve);this.currentPoint.set(aX,aY);return this;},splineThru:function splineThru(pts/*Array of Vector*/){var npts=[this.currentPoint.clone()].concat(pts);var curve=new SplineCurve(npts);this.curves.push(curve);this.currentPoint.copy(pts[pts.length-1]);return this;},arc:function arc(aX,aY,aRadius,aStartAngle,aEndAngle,aClockwise){var x0=this.currentPoint.x;var y0=this.currentPoint.y;this.absarc(aX+x0,aY+y0,aRadius,aStartAngle,aEndAngle,aClockwise);return this;},absarc:function absarc(aX,aY,aRadius,aStartAngle,aEndAngle,aClockwise){this.absellipse(aX,aY,aRadius,aRadius,aStartAngle,aEndAngle,aClockwise);return this;},ellipse:function ellipse(aX,aY,xRadius,yRadius,aStartAngle,aEndAngle,aClockwise,aRotation){var x0=this.currentPoint.x;var y0=this.currentPoint.y;this.absellipse(aX+x0,aY+y0,xRadius,yRadius,aStartAngle,aEndAngle,aClockwise,aRotation);return this;},absellipse:function absellipse(aX,aY,xRadius,yRadius,aStartAngle,aEndAngle,aClockwise,aRotation){var curve=new EllipseCurve(aX,aY,xRadius,yRadius,aStartAngle,aEndAngle,aClockwise,aRotation);if(this.curves.length>0){// if a previous curve is present, attempt to join
  2124. var firstPoint=curve.getPoint(0);if(!firstPoint.equals(this.currentPoint)){this.lineTo(firstPoint.x,firstPoint.y);}}this.curves.push(curve);var lastPoint=curve.getPoint(1);this.currentPoint.copy(lastPoint);return this;},copy:function copy(source){CurvePath.prototype.copy.call(this,source);this.currentPoint.copy(source.currentPoint);return this;},toJSON:function toJSON(){var data=CurvePath.prototype.toJSON.call(this);data.currentPoint=this.currentPoint.toArray();return data;},fromJSON:function fromJSON(json){CurvePath.prototype.fromJSON.call(this,json);this.currentPoint.fromArray(json.currentPoint);return this;}});function Shape(points){Path.call(this,points);this.uuid=MathUtils.generateUUID();this.type='Shape';this.holes=[];}Shape.prototype=Object.assign(Object.create(Path.prototype),{constructor:Shape,getPointsHoles:function getPointsHoles(divisions){var holesPts=[];for(var _i293=0,l=this.holes.length;_i293<l;_i293++){holesPts[_i293]=this.holes[_i293].getPoints(divisions);}return holesPts;},// get points of shape and holes (keypoints based on segments parameter)
  2125. extractPoints:function extractPoints(divisions){return {shape:this.getPoints(divisions),holes:this.getPointsHoles(divisions)};},copy:function copy(source){Path.prototype.copy.call(this,source);this.holes=[];for(var _i294=0,l=source.holes.length;_i294<l;_i294++){var hole=source.holes[_i294];this.holes.push(hole.clone());}return this;},toJSON:function toJSON(){var data=Path.prototype.toJSON.call(this);data.uuid=this.uuid;data.holes=[];for(var _i295=0,l=this.holes.length;_i295<l;_i295++){var hole=this.holes[_i295];data.holes.push(hole.toJSON());}return data;},fromJSON:function fromJSON(json){Path.prototype.fromJSON.call(this,json);this.uuid=json.uuid;this.holes=[];for(var _i296=0,l=json.holes.length;_i296<l;_i296++){var hole=json.holes[_i296];this.holes.push(new Path().fromJSON(hole));}return this;}});function Light(color){var intensity=arguments.length>1&&arguments[1]!==undefined?arguments[1]:1;Object3D.call(this);this.type='Light';this.color=new Color(color);this.intensity=intensity;}Light.prototype=Object.assign(Object.create(Object3D.prototype),{constructor:Light,isLight:true,copy:function copy(source){Object3D.prototype.copy.call(this,source);this.color.copy(source.color);this.intensity=source.intensity;return this;},toJSON:function toJSON(meta){var data=Object3D.prototype.toJSON.call(this,meta);data.object.color=this.color.getHex();data.object.intensity=this.intensity;if(this.groundColor!==undefined)data.object.groundColor=this.groundColor.getHex();if(this.distance!==undefined)data.object.distance=this.distance;if(this.angle!==undefined)data.object.angle=this.angle;if(this.decay!==undefined)data.object.decay=this.decay;if(this.penumbra!==undefined)data.object.penumbra=this.penumbra;if(this.shadow!==undefined)data.object.shadow=this.shadow.toJSON();return data;}});function HemisphereLight(skyColor,groundColor,intensity){Light.call(this,skyColor,intensity);this.type='HemisphereLight';this.position.copy(Object3D.DefaultUp);this.updateMatrix();this.groundColor=new Color(groundColor);}HemisphereLight.prototype=Object.assign(Object.create(Light.prototype),{constructor:HemisphereLight,isHemisphereLight:true,copy:function copy(source){Light.prototype.copy.call(this,source);this.groundColor.copy(source.groundColor);return this;}});function LightShadow(camera){this.camera=camera;this.bias=0;this.normalBias=0;this.radius=1;this.mapSize=new Vector2(512,512);this.map=null;this.mapPass=null;this.matrix=new Matrix4();this.autoUpdate=true;this.needsUpdate=false;this._frustum=new Frustum();this._frameExtents=new Vector2(1,1);this._viewportCount=1;this._viewports=[new Vector4(0,0,1,1)];}Object.assign(LightShadow.prototype,{_projScreenMatrix:new Matrix4(),_lightPositionWorld:new Vector3(),_lookTarget:new Vector3(),getViewportCount:function getViewportCount(){return this._viewportCount;},getFrustum:function getFrustum(){return this._frustum;},updateMatrices:function updateMatrices(light){var shadowCamera=this.camera,shadowMatrix=this.matrix,projScreenMatrix=this._projScreenMatrix,lookTarget=this._lookTarget,lightPositionWorld=this._lightPositionWorld;lightPositionWorld.setFromMatrixPosition(light.matrixWorld);shadowCamera.position.copy(lightPositionWorld);lookTarget.setFromMatrixPosition(light.target.matrixWorld);shadowCamera.lookAt(lookTarget);shadowCamera.updateMatrixWorld();projScreenMatrix.multiplyMatrices(shadowCamera.projectionMatrix,shadowCamera.matrixWorldInverse);this._frustum.setFromProjectionMatrix(projScreenMatrix);shadowMatrix.set(0.5,0.0,0.0,0.5,0.0,0.5,0.0,0.5,0.0,0.0,0.5,0.5,0.0,0.0,0.0,1.0);shadowMatrix.multiply(shadowCamera.projectionMatrix);shadowMatrix.multiply(shadowCamera.matrixWorldInverse);},getViewport:function getViewport(viewportIndex){return this._viewports[viewportIndex];},getFrameExtents:function getFrameExtents(){return this._frameExtents;},copy:function copy(source){this.camera=source.camera.clone();this.bias=source.bias;this.radius=source.radius;this.mapSize.copy(source.mapSize);return this;},clone:function clone(){return new this.constructor().copy(this);},toJSON:function toJSON(){var object={};if(this.bias!==0)object.bias=this.bias;if(this.normalBias!==0)object.normalBias=this.normalBias;if(this.radius!==1)object.radius=this.radius;if(this.mapSize.x!==512||this.mapSize.y!==512)object.mapSize=this.mapSize.toArray();object.camera=this.camera.toJSON(false).object;delete object.camera.matrix;return object;}});function SpotLightShadow(){LightShadow.call(this,new PerspectiveCamera(50,1,0.5,500));this.focus=1;}SpotLightShadow.prototype=Object.assign(Object.create(LightShadow.prototype),{constructor:SpotLightShadow,isSpotLightShadow:true,updateMatrices:function updateMatrices(light){var camera=this.camera;var fov=MathUtils.RAD2DEG*2*light.angle*this.focus;var aspect=this.mapSize.width/this.mapSize.height;var far=light.distance||camera.far;if(fov!==camera.fov||aspect!==camera.aspect||far!==camera.far){camera.fov=fov;camera.aspect=aspect;camera.far=far;camera.updateProjectionMatrix();}LightShadow.prototype.updateMatrices.call(this,light);}});function SpotLight(color,intensity,distance,angle,penumbra,decay){Light.call(this,color,intensity);this.type='SpotLight';this.position.copy(Object3D.DefaultUp);this.updateMatrix();this.target=new Object3D();Object.defineProperty(this,'power',{get:function get(){// intensity = power per solid angle.
  2126. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  2127. return this.intensity*Math.PI;},set:function set(power){// intensity = power per solid angle.
  2128. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  2129. this.intensity=power/Math.PI;}});this.distance=distance!==undefined?distance:0;this.angle=angle!==undefined?angle:Math.PI/3;this.penumbra=penumbra!==undefined?penumbra:0;this.decay=decay!==undefined?decay:1;// for physically correct lights, should be 2.
  2130. this.shadow=new SpotLightShadow();}SpotLight.prototype=Object.assign(Object.create(Light.prototype),{constructor:SpotLight,isSpotLight:true,copy:function copy(source){Light.prototype.copy.call(this,source);this.distance=source.distance;this.angle=source.angle;this.penumbra=source.penumbra;this.decay=source.decay;this.target=source.target.clone();this.shadow=source.shadow.clone();return this;}});function PointLightShadow(){LightShadow.call(this,new PerspectiveCamera(90,1,0.5,500));this._frameExtents=new Vector2(4,2);this._viewportCount=6;this._viewports=[// These viewports map a cube-map onto a 2D texture with the
  2131. // following orientation:
  2132. //
  2133. // xzXZ
  2134. // y Y
  2135. //
  2136. // X - Positive x direction
  2137. // x - Negative x direction
  2138. // Y - Positive y direction
  2139. // y - Negative y direction
  2140. // Z - Positive z direction
  2141. // z - Negative z direction
  2142. // positive X
  2143. new Vector4(2,1,1,1),// negative X
  2144. new Vector4(0,1,1,1),// positive Z
  2145. new Vector4(3,1,1,1),// negative Z
  2146. new Vector4(1,1,1,1),// positive Y
  2147. new Vector4(3,0,1,1),// negative Y
  2148. new Vector4(1,0,1,1)];this._cubeDirections=[new Vector3(1,0,0),new Vector3(-1,0,0),new Vector3(0,0,1),new Vector3(0,0,-1),new Vector3(0,1,0),new Vector3(0,-1,0)];this._cubeUps=[new Vector3(0,1,0),new Vector3(0,1,0),new Vector3(0,1,0),new Vector3(0,1,0),new Vector3(0,0,1),new Vector3(0,0,-1)];}PointLightShadow.prototype=Object.assign(Object.create(LightShadow.prototype),{constructor:PointLightShadow,isPointLightShadow:true,updateMatrices:function updateMatrices(light){var viewportIndex=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var camera=this.camera,shadowMatrix=this.matrix,lightPositionWorld=this._lightPositionWorld,lookTarget=this._lookTarget,projScreenMatrix=this._projScreenMatrix;lightPositionWorld.setFromMatrixPosition(light.matrixWorld);camera.position.copy(lightPositionWorld);lookTarget.copy(camera.position);lookTarget.add(this._cubeDirections[viewportIndex]);camera.up.copy(this._cubeUps[viewportIndex]);camera.lookAt(lookTarget);camera.updateMatrixWorld();shadowMatrix.makeTranslation(-lightPositionWorld.x,-lightPositionWorld.y,-lightPositionWorld.z);projScreenMatrix.multiplyMatrices(camera.projectionMatrix,camera.matrixWorldInverse);this._frustum.setFromProjectionMatrix(projScreenMatrix);}});function PointLight(color,intensity,distance,decay){Light.call(this,color,intensity);this.type='PointLight';Object.defineProperty(this,'power',{get:function get(){// intensity = power per solid angle.
  2149. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  2150. return this.intensity*4*Math.PI;},set:function set(power){// intensity = power per solid angle.
  2151. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  2152. this.intensity=power/(4*Math.PI);}});this.distance=distance!==undefined?distance:0;this.decay=decay!==undefined?decay:1;// for physically correct lights, should be 2.
  2153. this.shadow=new PointLightShadow();}PointLight.prototype=Object.assign(Object.create(Light.prototype),{constructor:PointLight,isPointLight:true,copy:function copy(source){Light.prototype.copy.call(this,source);this.distance=source.distance;this.decay=source.decay;this.shadow=source.shadow.clone();return this;}});function OrthographicCamera(){var left=arguments.length>0&&arguments[0]!==undefined?arguments[0]:-1;var right=arguments.length>1&&arguments[1]!==undefined?arguments[1]:1;var top=arguments.length>2&&arguments[2]!==undefined?arguments[2]:1;var bottom=arguments.length>3&&arguments[3]!==undefined?arguments[3]:-1;var near=arguments.length>4&&arguments[4]!==undefined?arguments[4]:0.1;var far=arguments.length>5&&arguments[5]!==undefined?arguments[5]:2000;Camera.call(this);this.type='OrthographicCamera';this.zoom=1;this.view=null;this.left=left;this.right=right;this.top=top;this.bottom=bottom;this.near=near;this.far=far;this.updateProjectionMatrix();}OrthographicCamera.prototype=Object.assign(Object.create(Camera.prototype),{constructor:OrthographicCamera,isOrthographicCamera:true,copy:function copy(source,recursive){Camera.prototype.copy.call(this,source,recursive);this.left=source.left;this.right=source.right;this.top=source.top;this.bottom=source.bottom;this.near=source.near;this.far=source.far;this.zoom=source.zoom;this.view=source.view===null?null:Object.assign({},source.view);return this;},setViewOffset:function setViewOffset(fullWidth,fullHeight,x,y,width,height){if(this.view===null){this.view={enabled:true,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1};}this.view.enabled=true;this.view.fullWidth=fullWidth;this.view.fullHeight=fullHeight;this.view.offsetX=x;this.view.offsetY=y;this.view.width=width;this.view.height=height;this.updateProjectionMatrix();},clearViewOffset:function clearViewOffset(){if(this.view!==null){this.view.enabled=false;}this.updateProjectionMatrix();},updateProjectionMatrix:function updateProjectionMatrix(){var dx=(this.right-this.left)/(2*this.zoom);var dy=(this.top-this.bottom)/(2*this.zoom);var cx=(this.right+this.left)/2;var cy=(this.top+this.bottom)/2;var left=cx-dx;var right=cx+dx;var top=cy+dy;var bottom=cy-dy;if(this.view!==null&&this.view.enabled){var scaleW=(this.right-this.left)/this.view.fullWidth/this.zoom;var scaleH=(this.top-this.bottom)/this.view.fullHeight/this.zoom;left+=scaleW*this.view.offsetX;right=left+scaleW*this.view.width;top-=scaleH*this.view.offsetY;bottom=top-scaleH*this.view.height;}this.projectionMatrix.makeOrthographic(left,right,top,bottom,this.near,this.far);this.projectionMatrixInverse.copy(this.projectionMatrix).invert();},toJSON:function toJSON(meta){var data=Object3D.prototype.toJSON.call(this,meta);data.object.zoom=this.zoom;data.object.left=this.left;data.object.right=this.right;data.object.top=this.top;data.object.bottom=this.bottom;data.object.near=this.near;data.object.far=this.far;if(this.view!==null)data.object.view=Object.assign({},this.view);return data;}});function DirectionalLightShadow(){LightShadow.call(this,new OrthographicCamera(-5,5,5,-5,0.5,500));}DirectionalLightShadow.prototype=Object.assign(Object.create(LightShadow.prototype),{constructor:DirectionalLightShadow,isDirectionalLightShadow:true,updateMatrices:function updateMatrices(light){LightShadow.prototype.updateMatrices.call(this,light);}});function DirectionalLight(color,intensity){Light.call(this,color,intensity);this.type='DirectionalLight';this.position.copy(Object3D.DefaultUp);this.updateMatrix();this.target=new Object3D();this.shadow=new DirectionalLightShadow();}DirectionalLight.prototype=Object.assign(Object.create(Light.prototype),{constructor:DirectionalLight,isDirectionalLight:true,copy:function copy(source){Light.prototype.copy.call(this,source);this.target=source.target.clone();this.shadow=source.shadow.clone();return this;}});function AmbientLight(color,intensity){Light.call(this,color,intensity);this.type='AmbientLight';}AmbientLight.prototype=Object.assign(Object.create(Light.prototype),{constructor:AmbientLight,isAmbientLight:true});function RectAreaLight(color,intensity,width,height){Light.call(this,color,intensity);this.type='RectAreaLight';this.width=width!==undefined?width:10;this.height=height!==undefined?height:10;}RectAreaLight.prototype=Object.assign(Object.create(Light.prototype),{constructor:RectAreaLight,isRectAreaLight:true,copy:function copy(source){Light.prototype.copy.call(this,source);this.width=source.width;this.height=source.height;return this;},toJSON:function toJSON(meta){var data=Light.prototype.toJSON.call(this,meta);data.object.width=this.width;data.object.height=this.height;return data;}});/**
  2154. * Primary reference:
  2155. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  2156. *
  2157. * Secondary reference:
  2158. * https://www.ppsloan.org/publications/StupidSH36.pdf
  2159. */ // 3-band SH defined by 9 coefficients
  2160. class SphericalHarmonics3{constructor(){Object.defineProperty(this,'isSphericalHarmonics3',{value:true});this.coefficients=[];for(var _i297=0;_i297<9;_i297++){this.coefficients.push(new Vector3());}}set(coefficients){for(var _i298=0;_i298<9;_i298++){this.coefficients[_i298].copy(coefficients[_i298]);}return this;}zero(){for(var _i299=0;_i299<9;_i299++){this.coefficients[_i299].set(0,0,0);}return this;}// get the radiance in the direction of the normal
  2161. // target is a Vector3
  2162. getAt(normal,target){// normal is assumed to be unit length
  2163. var x=normal.x,y=normal.y,z=normal.z;var coeff=this.coefficients;// band 0
  2164. target.copy(coeff[0]).multiplyScalar(0.282095);// band 1
  2165. target.addScaledVector(coeff[1],0.488603*y);target.addScaledVector(coeff[2],0.488603*z);target.addScaledVector(coeff[3],0.488603*x);// band 2
  2166. target.addScaledVector(coeff[4],1.092548*(x*y));target.addScaledVector(coeff[5],1.092548*(y*z));target.addScaledVector(coeff[6],0.315392*(3.0*z*z-1.0));target.addScaledVector(coeff[7],1.092548*(x*z));target.addScaledVector(coeff[8],0.546274*(x*x-y*y));return target;}// get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  2167. // target is a Vector3
  2168. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  2169. getIrradianceAt(normal,target){// normal is assumed to be unit length
  2170. var x=normal.x,y=normal.y,z=normal.z;var coeff=this.coefficients;// band 0
  2171. target.copy(coeff[0]).multiplyScalar(0.886227);// π * 0.282095
  2172. // band 1
  2173. target.addScaledVector(coeff[1],2.0*0.511664*y);// ( 2 * π / 3 ) * 0.488603
  2174. target.addScaledVector(coeff[2],2.0*0.511664*z);target.addScaledVector(coeff[3],2.0*0.511664*x);// band 2
  2175. target.addScaledVector(coeff[4],2.0*0.429043*x*y);// ( π / 4 ) * 1.092548
  2176. target.addScaledVector(coeff[5],2.0*0.429043*y*z);target.addScaledVector(coeff[6],0.743125*z*z-0.247708);// ( π / 4 ) * 0.315392 * 3
  2177. target.addScaledVector(coeff[7],2.0*0.429043*x*z);target.addScaledVector(coeff[8],0.429043*(x*x-y*y));// ( π / 4 ) * 0.546274
  2178. return target;}add(sh){for(var _i300=0;_i300<9;_i300++){this.coefficients[_i300].add(sh.coefficients[_i300]);}return this;}addScaledSH(sh,s){for(var _i301=0;_i301<9;_i301++){this.coefficients[_i301].addScaledVector(sh.coefficients[_i301],s);}return this;}scale(s){for(var _i302=0;_i302<9;_i302++){this.coefficients[_i302].multiplyScalar(s);}return this;}lerp(sh,alpha){for(var _i303=0;_i303<9;_i303++){this.coefficients[_i303].lerp(sh.coefficients[_i303],alpha);}return this;}equals(sh){for(var _i304=0;_i304<9;_i304++){if(!this.coefficients[_i304].equals(sh.coefficients[_i304])){return false;}}return true;}copy(sh){return this.set(sh.coefficients);}clone(){return new this.constructor().copy(this);}fromArray(array){var offset=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var coefficients=this.coefficients;for(var _i305=0;_i305<9;_i305++){coefficients[_i305].fromArray(array,offset+_i305*3);}return this;}toArray(){var array=arguments.length>0&&arguments[0]!==undefined?arguments[0]:[];var offset=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var coefficients=this.coefficients;for(var _i306=0;_i306<9;_i306++){coefficients[_i306].toArray(array,offset+_i306*3);}return array;}// evaluate the basis functions
  2179. // shBasis is an Array[ 9 ]
  2180. static getBasisAt(normal,shBasis){// normal is assumed to be unit length
  2181. var x=normal.x,y=normal.y,z=normal.z;// band 0
  2182. shBasis[0]=0.282095;// band 1
  2183. shBasis[1]=0.488603*y;shBasis[2]=0.488603*z;shBasis[3]=0.488603*x;// band 2
  2184. shBasis[4]=1.092548*x*y;shBasis[5]=1.092548*y*z;shBasis[6]=0.315392*(3*z*z-1);shBasis[7]=1.092548*x*z;shBasis[8]=0.546274*(x*x-y*y);}}function LightProbe(sh,intensity){Light.call(this,undefined,intensity);this.type='LightProbe';this.sh=sh!==undefined?sh:new SphericalHarmonics3();}LightProbe.prototype=Object.assign(Object.create(Light.prototype),{constructor:LightProbe,isLightProbe:true,copy:function copy(source){Light.prototype.copy.call(this,source);this.sh.copy(source.sh);return this;},fromJSON:function fromJSON(json){this.intensity=json.intensity;// TODO: Move this bit to Light.fromJSON();
  2185. this.sh.fromArray(json.sh);return this;},toJSON:function toJSON(meta){var data=Light.prototype.toJSON.call(this,meta);data.object.sh=this.sh.toArray();return data;}});function MaterialLoader(manager){Loader.call(this,manager);this.textures={};}MaterialLoader.prototype=Object.assign(Object.create(Loader.prototype),{constructor:MaterialLoader,load:function load(url,onLoad,onProgress,onError){var scope=this;var loader=new FileLoader(scope.manager);loader.setPath(scope.path);loader.setRequestHeader(scope.requestHeader);loader.setWithCredentials(scope.withCredentials);loader.load(url,function(text){try{onLoad(scope.parse(JSON.parse(text)));}catch(e){if(onError){onError(e);}else {console.error(e);}scope.manager.itemError(url);}},onProgress,onError);},parse:function parse(json){var textures=this.textures;function getTexture(name){if(textures[name]===undefined){console.warn('THREE.MaterialLoader: Undefined texture',name);}return textures[name];}var material=new Materials[json.type]();if(json.uuid!==undefined)material.uuid=json.uuid;if(json.name!==undefined)material.name=json.name;if(json.color!==undefined&&material.color!==undefined)material.color.setHex(json.color);if(json.roughness!==undefined)material.roughness=json.roughness;if(json.metalness!==undefined)material.metalness=json.metalness;if(json.sheen!==undefined)material.sheen=new Color().setHex(json.sheen);if(json.emissive!==undefined&&material.emissive!==undefined)material.emissive.setHex(json.emissive);if(json.specular!==undefined&&material.specular!==undefined)material.specular.setHex(json.specular);if(json.shininess!==undefined)material.shininess=json.shininess;if(json.clearcoat!==undefined)material.clearcoat=json.clearcoat;if(json.clearcoatRoughness!==undefined)material.clearcoatRoughness=json.clearcoatRoughness;if(json.fog!==undefined)material.fog=json.fog;if(json.flatShading!==undefined)material.flatShading=json.flatShading;if(json.blending!==undefined)material.blending=json.blending;if(json.combine!==undefined)material.combine=json.combine;if(json.side!==undefined)material.side=json.side;if(json.opacity!==undefined)material.opacity=json.opacity;if(json.transparent!==undefined)material.transparent=json.transparent;if(json.alphaTest!==undefined)material.alphaTest=json.alphaTest;if(json.depthTest!==undefined)material.depthTest=json.depthTest;if(json.depthWrite!==undefined)material.depthWrite=json.depthWrite;if(json.colorWrite!==undefined)material.colorWrite=json.colorWrite;if(json.stencilWrite!==undefined)material.stencilWrite=json.stencilWrite;if(json.stencilWriteMask!==undefined)material.stencilWriteMask=json.stencilWriteMask;if(json.stencilFunc!==undefined)material.stencilFunc=json.stencilFunc;if(json.stencilRef!==undefined)material.stencilRef=json.stencilRef;if(json.stencilFuncMask!==undefined)material.stencilFuncMask=json.stencilFuncMask;if(json.stencilFail!==undefined)material.stencilFail=json.stencilFail;if(json.stencilZFail!==undefined)material.stencilZFail=json.stencilZFail;if(json.stencilZPass!==undefined)material.stencilZPass=json.stencilZPass;if(json.wireframe!==undefined)material.wireframe=json.wireframe;if(json.wireframeLinewidth!==undefined)material.wireframeLinewidth=json.wireframeLinewidth;if(json.wireframeLinecap!==undefined)material.wireframeLinecap=json.wireframeLinecap;if(json.wireframeLinejoin!==undefined)material.wireframeLinejoin=json.wireframeLinejoin;if(json.rotation!==undefined)material.rotation=json.rotation;if(json.linewidth!==1)material.linewidth=json.linewidth;if(json.dashSize!==undefined)material.dashSize=json.dashSize;if(json.gapSize!==undefined)material.gapSize=json.gapSize;if(json.scale!==undefined)material.scale=json.scale;if(json.polygonOffset!==undefined)material.polygonOffset=json.polygonOffset;if(json.polygonOffsetFactor!==undefined)material.polygonOffsetFactor=json.polygonOffsetFactor;if(json.polygonOffsetUnits!==undefined)material.polygonOffsetUnits=json.polygonOffsetUnits;if(json.skinning!==undefined)material.skinning=json.skinning;if(json.morphTargets!==undefined)material.morphTargets=json.morphTargets;if(json.morphNormals!==undefined)material.morphNormals=json.morphNormals;if(json.dithering!==undefined)material.dithering=json.dithering;if(json.vertexTangents!==undefined)material.vertexTangents=json.vertexTangents;if(json.visible!==undefined)material.visible=json.visible;if(json.toneMapped!==undefined)material.toneMapped=json.toneMapped;if(json.userData!==undefined)material.userData=json.userData;if(json.vertexColors!==undefined){if(typeof json.vertexColors==='number'){material.vertexColors=json.vertexColors>0?true:false;}else {material.vertexColors=json.vertexColors;}}// Shader Material
  2186. if(json.uniforms!==undefined){for(var name in json.uniforms){var uniform=json.uniforms[name];material.uniforms[name]={};switch(uniform.type){case't':material.uniforms[name].value=getTexture(uniform.value);break;case'c':material.uniforms[name].value=new Color().setHex(uniform.value);break;case'v2':material.uniforms[name].value=new Vector2().fromArray(uniform.value);break;case'v3':material.uniforms[name].value=new Vector3().fromArray(uniform.value);break;case'v4':material.uniforms[name].value=new Vector4().fromArray(uniform.value);break;case'm3':material.uniforms[name].value=new Matrix3().fromArray(uniform.value);break;case'm4':material.uniforms[name].value=new Matrix4().fromArray(uniform.value);break;default:material.uniforms[name].value=uniform.value;}}}if(json.defines!==undefined)material.defines=json.defines;if(json.vertexShader!==undefined)material.vertexShader=json.vertexShader;if(json.fragmentShader!==undefined)material.fragmentShader=json.fragmentShader;if(json.extensions!==undefined){for(var key in json.extensions){material.extensions[key]=json.extensions[key];}}// Deprecated
  2187. if(json.shading!==undefined)material.flatShading=json.shading===1;// THREE.FlatShading
  2188. // for PointsMaterial
  2189. if(json.size!==undefined)material.size=json.size;if(json.sizeAttenuation!==undefined)material.sizeAttenuation=json.sizeAttenuation;// maps
  2190. if(json.map!==undefined)material.map=getTexture(json.map);if(json.matcap!==undefined)material.matcap=getTexture(json.matcap);if(json.alphaMap!==undefined)material.alphaMap=getTexture(json.alphaMap);if(json.bumpMap!==undefined)material.bumpMap=getTexture(json.bumpMap);if(json.bumpScale!==undefined)material.bumpScale=json.bumpScale;if(json.normalMap!==undefined)material.normalMap=getTexture(json.normalMap);if(json.normalMapType!==undefined)material.normalMapType=json.normalMapType;if(json.normalScale!==undefined){var normalScale=json.normalScale;if(Array.isArray(normalScale)===false){// Blender exporter used to export a scalar. See #7459
  2191. normalScale=[normalScale,normalScale];}material.normalScale=new Vector2().fromArray(normalScale);}if(json.displacementMap!==undefined)material.displacementMap=getTexture(json.displacementMap);if(json.displacementScale!==undefined)material.displacementScale=json.displacementScale;if(json.displacementBias!==undefined)material.displacementBias=json.displacementBias;if(json.roughnessMap!==undefined)material.roughnessMap=getTexture(json.roughnessMap);if(json.metalnessMap!==undefined)material.metalnessMap=getTexture(json.metalnessMap);if(json.emissiveMap!==undefined)material.emissiveMap=getTexture(json.emissiveMap);if(json.emissiveIntensity!==undefined)material.emissiveIntensity=json.emissiveIntensity;if(json.specularMap!==undefined)material.specularMap=getTexture(json.specularMap);if(json.envMap!==undefined)material.envMap=getTexture(json.envMap);if(json.envMapIntensity!==undefined)material.envMapIntensity=json.envMapIntensity;if(json.reflectivity!==undefined)material.reflectivity=json.reflectivity;if(json.refractionRatio!==undefined)material.refractionRatio=json.refractionRatio;if(json.lightMap!==undefined)material.lightMap=getTexture(json.lightMap);if(json.lightMapIntensity!==undefined)material.lightMapIntensity=json.lightMapIntensity;if(json.aoMap!==undefined)material.aoMap=getTexture(json.aoMap);if(json.aoMapIntensity!==undefined)material.aoMapIntensity=json.aoMapIntensity;if(json.gradientMap!==undefined)material.gradientMap=getTexture(json.gradientMap);if(json.clearcoatMap!==undefined)material.clearcoatMap=getTexture(json.clearcoatMap);if(json.clearcoatRoughnessMap!==undefined)material.clearcoatRoughnessMap=getTexture(json.clearcoatRoughnessMap);if(json.clearcoatNormalMap!==undefined)material.clearcoatNormalMap=getTexture(json.clearcoatNormalMap);if(json.clearcoatNormalScale!==undefined)material.clearcoatNormalScale=new Vector2().fromArray(json.clearcoatNormalScale);if(json.transmission!==undefined)material.transmission=json.transmission;if(json.transmissionMap!==undefined)material.transmissionMap=getTexture(json.transmissionMap);return material;},setTextures:function setTextures(value){this.textures=value;return this;}});var LoaderUtils={decodeText:function decodeText(array){if(typeof TextDecoder!=='undefined'){return new TextDecoder().decode(array);}// Avoid the String.fromCharCode.apply(null, array) shortcut, which
  2192. // throws a "maximum call stack size exceeded" error for large arrays.
  2193. var s='';for(var _i307=0,il=array.length;_i307<il;_i307++){// Implicitly assumes little-endian.
  2194. s+=String.fromCharCode(array[_i307]);}try{// merges multi-byte utf-8 characters.
  2195. return decodeURIComponent(escape(s));}catch(e){// see #16358
  2196. return s;}},extractUrlBase:function extractUrlBase(url){var index=url.lastIndexOf('/');if(index===-1)return './';return url.substr(0,index+1);}};function InstancedBufferGeometry(){BufferGeometry.call(this);this.type='InstancedBufferGeometry';this.instanceCount=Infinity;}InstancedBufferGeometry.prototype=Object.assign(Object.create(BufferGeometry.prototype),{constructor:InstancedBufferGeometry,isInstancedBufferGeometry:true,copy:function copy(source){BufferGeometry.prototype.copy.call(this,source);this.instanceCount=source.instanceCount;return this;},clone:function clone(){return new this.constructor().copy(this);},toJSON:function toJSON(){var data=BufferGeometry.prototype.toJSON.call(this);data.instanceCount=this.instanceCount;data.isInstancedBufferGeometry=true;return data;}});function InstancedBufferAttribute(array,itemSize,normalized,meshPerAttribute){if(typeof normalized==='number'){meshPerAttribute=normalized;normalized=false;console.error('THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.');}BufferAttribute.call(this,array,itemSize,normalized);this.meshPerAttribute=meshPerAttribute||1;}InstancedBufferAttribute.prototype=Object.assign(Object.create(BufferAttribute.prototype),{constructor:InstancedBufferAttribute,isInstancedBufferAttribute:true,copy:function copy(source){BufferAttribute.prototype.copy.call(this,source);this.meshPerAttribute=source.meshPerAttribute;return this;},toJSON:function toJSON(){var data=BufferAttribute.prototype.toJSON.call(this);data.meshPerAttribute=this.meshPerAttribute;data.isInstancedBufferAttribute=true;return data;}});function BufferGeometryLoader(manager){Loader.call(this,manager);}BufferGeometryLoader.prototype=Object.assign(Object.create(Loader.prototype),{constructor:BufferGeometryLoader,load:function load(url,onLoad,onProgress,onError){var scope=this;var loader=new FileLoader(scope.manager);loader.setPath(scope.path);loader.setRequestHeader(scope.requestHeader);loader.setWithCredentials(scope.withCredentials);loader.load(url,function(text){try{onLoad(scope.parse(JSON.parse(text)));}catch(e){if(onError){onError(e);}else {console.error(e);}scope.manager.itemError(url);}},onProgress,onError);},parse:function parse(json){var interleavedBufferMap={};var arrayBufferMap={};function getInterleavedBuffer(json,uuid){if(interleavedBufferMap[uuid]!==undefined)return interleavedBufferMap[uuid];var interleavedBuffers=json.interleavedBuffers;var interleavedBuffer=interleavedBuffers[uuid];var buffer=getArrayBuffer(json,interleavedBuffer.buffer);var array=getTypedArray(interleavedBuffer.type,buffer);var ib=new InterleavedBuffer(array,interleavedBuffer.stride);ib.uuid=interleavedBuffer.uuid;interleavedBufferMap[uuid]=ib;return ib;}function getArrayBuffer(json,uuid){if(arrayBufferMap[uuid]!==undefined)return arrayBufferMap[uuid];var arrayBuffers=json.arrayBuffers;var arrayBuffer=arrayBuffers[uuid];var ab=new Uint32Array(arrayBuffer).buffer;arrayBufferMap[uuid]=ab;return ab;}var geometry=json.isInstancedBufferGeometry?new InstancedBufferGeometry():new BufferGeometry();var index=json.data.index;if(index!==undefined){var typedArray=getTypedArray(index.type,index.array);geometry.setIndex(new BufferAttribute(typedArray,1));}var attributes=json.data.attributes;for(var key in attributes){var attribute=attributes[key];var bufferAttribute=void 0;if(attribute.isInterleavedBufferAttribute){var interleavedBuffer=getInterleavedBuffer(json.data,attribute.data);bufferAttribute=new InterleavedBufferAttribute(interleavedBuffer,attribute.itemSize,attribute.offset,attribute.normalized);}else {var _typedArray=getTypedArray(attribute.type,attribute.array);var bufferAttributeConstr=attribute.isInstancedBufferAttribute?InstancedBufferAttribute:BufferAttribute;bufferAttribute=new bufferAttributeConstr(_typedArray,attribute.itemSize,attribute.normalized);}if(attribute.name!==undefined)bufferAttribute.name=attribute.name;geometry.setAttribute(key,bufferAttribute);}var morphAttributes=json.data.morphAttributes;if(morphAttributes){for(var _key6 in morphAttributes){var attributeArray=morphAttributes[_key6];var array=[];for(var _i308=0,il=attributeArray.length;_i308<il;_i308++){var _attribute9=attributeArray[_i308];var _bufferAttribute=void 0;if(_attribute9.isInterleavedBufferAttribute){var _interleavedBuffer=getInterleavedBuffer(json.data,_attribute9.data);_bufferAttribute=new InterleavedBufferAttribute(_interleavedBuffer,_attribute9.itemSize,_attribute9.offset,_attribute9.normalized);}else {var _typedArray2=getTypedArray(_attribute9.type,_attribute9.array);_bufferAttribute=new BufferAttribute(_typedArray2,_attribute9.itemSize,_attribute9.normalized);}if(_attribute9.name!==undefined)_bufferAttribute.name=_attribute9.name;array.push(_bufferAttribute);}geometry.morphAttributes[_key6]=array;}}var morphTargetsRelative=json.data.morphTargetsRelative;if(morphTargetsRelative){geometry.morphTargetsRelative=true;}var groups=json.data.groups||json.data.drawcalls||json.data.offsets;if(groups!==undefined){for(var _i309=0,n=groups.length;_i309!==n;++_i309){var group=groups[_i309];geometry.addGroup(group.start,group.count,group.materialIndex);}}var boundingSphere=json.data.boundingSphere;if(boundingSphere!==undefined){var center=new Vector3();if(boundingSphere.center!==undefined){center.fromArray(boundingSphere.center);}geometry.boundingSphere=new Sphere(center,boundingSphere.radius);}if(json.name)geometry.name=json.name;if(json.userData)geometry.userData=json.userData;return geometry;}});class ObjectLoader extends Loader{constructor(manager){super(manager);}load(url,onLoad,onProgress,onError){var scope=this;var path=this.path===''?LoaderUtils.extractUrlBase(url):this.path;this.resourcePath=this.resourcePath||path;var loader=new FileLoader(this.manager);loader.setPath(this.path);loader.setRequestHeader(this.requestHeader);loader.setWithCredentials(this.withCredentials);loader.load(url,function(text){var json=null;try{json=JSON.parse(text);}catch(error){if(onError!==undefined)onError(error);console.error('THREE:ObjectLoader: Can\'t parse '+url+'.',error.message);return;}var metadata=json.metadata;if(metadata===undefined||metadata.type===undefined||metadata.type.toLowerCase()==='geometry'){console.error('THREE.ObjectLoader: Can\'t load '+url);return;}scope.parse(json,onLoad);},onProgress,onError);}parse(json,onLoad){var animations=this.parseAnimations(json.animations);var shapes=this.parseShapes(json.shapes);var geometries=this.parseGeometries(json.geometries,shapes);var images=this.parseImages(json.images,function(){if(onLoad!==undefined)onLoad(object);});var textures=this.parseTextures(json.textures,images);var materials=this.parseMaterials(json.materials,textures);var object=this.parseObject(json.object,geometries,materials,animations);var skeletons=this.parseSkeletons(json.skeletons,object);this.bindSkeletons(object,skeletons);//
  2197. if(onLoad!==undefined){var hasImages=false;for(var uuid in images){if(images[uuid]instanceof HTMLImageElement){hasImages=true;break;}}if(hasImages===false)onLoad(object);}return object;}parseShapes(json){var shapes={};if(json!==undefined){for(var _i310=0,l=json.length;_i310<l;_i310++){var shape=new Shape().fromJSON(json[_i310]);shapes[shape.uuid]=shape;}}return shapes;}parseSkeletons(json,object){var skeletons={};var bones={};// generate bone lookup table
  2198. object.traverse(function(child){if(child.isBone)bones[child.uuid]=child;});// create skeletons
  2199. if(json!==undefined){for(var _i311=0,l=json.length;_i311<l;_i311++){var skeleton=new Skeleton().fromJSON(json[_i311],bones);skeletons[skeleton.uuid]=skeleton;}}return skeletons;}parseGeometries(json,shapes){var geometries={};var geometryShapes;if(json!==undefined){var bufferGeometryLoader=new BufferGeometryLoader();for(var _i312=0,l=json.length;_i312<l;_i312++){var geometry=void 0;var data=json[_i312];switch(data.type){case'PlaneGeometry':case'PlaneBufferGeometry':geometry=new Geometries[data.type](data.width,data.height,data.widthSegments,data.heightSegments);break;case'BoxGeometry':case'BoxBufferGeometry':case'CubeGeometry':// backwards compatible
  2200. geometry=new Geometries[data.type](data.width,data.height,data.depth,data.widthSegments,data.heightSegments,data.depthSegments);break;case'CircleGeometry':case'CircleBufferGeometry':geometry=new Geometries[data.type](data.radius,data.segments,data.thetaStart,data.thetaLength);break;case'CylinderGeometry':case'CylinderBufferGeometry':geometry=new Geometries[data.type](data.radiusTop,data.radiusBottom,data.height,data.radialSegments,data.heightSegments,data.openEnded,data.thetaStart,data.thetaLength);break;case'ConeGeometry':case'ConeBufferGeometry':geometry=new Geometries[data.type](data.radius,data.height,data.radialSegments,data.heightSegments,data.openEnded,data.thetaStart,data.thetaLength);break;case'SphereGeometry':case'SphereBufferGeometry':geometry=new Geometries[data.type](data.radius,data.widthSegments,data.heightSegments,data.phiStart,data.phiLength,data.thetaStart,data.thetaLength);break;case'DodecahedronGeometry':case'DodecahedronBufferGeometry':case'IcosahedronGeometry':case'IcosahedronBufferGeometry':case'OctahedronGeometry':case'OctahedronBufferGeometry':case'TetrahedronGeometry':case'TetrahedronBufferGeometry':geometry=new Geometries[data.type](data.radius,data.detail);break;case'RingGeometry':case'RingBufferGeometry':geometry=new Geometries[data.type](data.innerRadius,data.outerRadius,data.thetaSegments,data.phiSegments,data.thetaStart,data.thetaLength);break;case'TorusGeometry':case'TorusBufferGeometry':geometry=new Geometries[data.type](data.radius,data.tube,data.radialSegments,data.tubularSegments,data.arc);break;case'TorusKnotGeometry':case'TorusKnotBufferGeometry':geometry=new Geometries[data.type](data.radius,data.tube,data.tubularSegments,data.radialSegments,data.p,data.q);break;case'TubeGeometry':case'TubeBufferGeometry':// This only works for built-in curves (e.g. CatmullRomCurve3).
  2201. // User defined curves or instances of CurvePath will not be deserialized.
  2202. geometry=new Geometries[data.type](new Curves[data.path.type]().fromJSON(data.path),data.tubularSegments,data.radius,data.radialSegments,data.closed);break;case'LatheGeometry':case'LatheBufferGeometry':geometry=new Geometries[data.type](data.points,data.segments,data.phiStart,data.phiLength);break;case'PolyhedronGeometry':case'PolyhedronBufferGeometry':geometry=new Geometries[data.type](data.vertices,data.indices,data.radius,data.details);break;case'ShapeGeometry':case'ShapeBufferGeometry':geometryShapes=[];for(var j=0,jl=data.shapes.length;j<jl;j++){var shape=shapes[data.shapes[j]];geometryShapes.push(shape);}geometry=new Geometries[data.type](geometryShapes,data.curveSegments);break;case'ExtrudeGeometry':case'ExtrudeBufferGeometry':geometryShapes=[];for(var _j24=0,_jl8=data.shapes.length;_j24<_jl8;_j24++){var _shape=shapes[data.shapes[_j24]];geometryShapes.push(_shape);}var extrudePath=data.options.extrudePath;if(extrudePath!==undefined){data.options.extrudePath=new Curves[extrudePath.type]().fromJSON(extrudePath);}geometry=new Geometries[data.type](geometryShapes,data.options);break;case'BufferGeometry':case'InstancedBufferGeometry':geometry=bufferGeometryLoader.parse(data);break;case'Geometry':console.error('THREE.ObjectLoader: Loading "Geometry" is not supported anymore.');break;default:console.warn('THREE.ObjectLoader: Unsupported geometry type "'+data.type+'"');continue;}geometry.uuid=data.uuid;if(data.name!==undefined)geometry.name=data.name;if(geometry.isBufferGeometry===true&&data.userData!==undefined)geometry.userData=data.userData;geometries[data.uuid]=geometry;}}return geometries;}parseMaterials(json,textures){var cache={};// MultiMaterial
  2203. var materials={};if(json!==undefined){var loader=new MaterialLoader();loader.setTextures(textures);for(var _i313=0,l=json.length;_i313<l;_i313++){var data=json[_i313];if(data.type==='MultiMaterial'){// Deprecated
  2204. var array=[];for(var j=0;j<data.materials.length;j++){var material=data.materials[j];if(cache[material.uuid]===undefined){cache[material.uuid]=loader.parse(material);}array.push(cache[material.uuid]);}materials[data.uuid]=array;}else {if(cache[data.uuid]===undefined){cache[data.uuid]=loader.parse(data);}materials[data.uuid]=cache[data.uuid];}}}return materials;}parseAnimations(json){var animations={};if(json!==undefined){for(var _i314=0;_i314<json.length;_i314++){var data=json[_i314];var clip=AnimationClip.parse(data);animations[clip.uuid]=clip;}}return animations;}parseImages(json,onLoad){var scope=this;var images={};var loader;function loadImage(url){scope.manager.itemStart(url);return loader.load(url,function(){scope.manager.itemEnd(url);},undefined,function(){scope.manager.itemError(url);scope.manager.itemEnd(url);});}function deserializeImage(image){if(typeof image==='string'){var url=image;var path=/^(\/\/)|([a-z]+:(\/\/)?)/i.test(url)?url:scope.resourcePath+url;return loadImage(path);}else {if(image.data){return {data:getTypedArray(image.type,image.data),width:image.width,height:image.height};}else {return null;}}}if(json!==undefined&&json.length>0){var manager=new LoadingManager(onLoad);loader=new ImageLoader(manager);loader.setCrossOrigin(this.crossOrigin);for(var _i315=0,il=json.length;_i315<il;_i315++){var image=json[_i315];var url=image.url;if(Array.isArray(url)){// load array of images e.g CubeTexture
  2205. images[image.uuid]=[];for(var j=0,jl=url.length;j<jl;j++){var currentUrl=url[j];var deserializedImage=deserializeImage(currentUrl);if(deserializedImage!==null){if(deserializedImage instanceof HTMLImageElement){images[image.uuid].push(deserializedImage);}else {// special case: handle array of data textures for cube textures
  2206. images[image.uuid].push(new DataTexture(deserializedImage.data,deserializedImage.width,deserializedImage.height));}}}}else {// load single image
  2207. var _deserializedImage=deserializeImage(image.url);if(_deserializedImage!==null){images[image.uuid]=_deserializedImage;}}}}return images;}parseTextures(json,images){function parseConstant(value,type){if(typeof value==='number')return value;console.warn('THREE.ObjectLoader.parseTexture: Constant should be in numeric form.',value);return type[value];}var textures={};if(json!==undefined){for(var _i316=0,l=json.length;_i316<l;_i316++){var data=json[_i316];if(data.image===undefined){console.warn('THREE.ObjectLoader: No "image" specified for',data.uuid);}if(images[data.image]===undefined){console.warn('THREE.ObjectLoader: Undefined image',data.image);}var texture=void 0;var image=images[data.image];if(Array.isArray(image)){texture=new CubeTexture(image);if(image.length===6)texture.needsUpdate=true;}else {if(image&&image.data){texture=new DataTexture(image.data,image.width,image.height);}else {texture=new Texture(image);}if(image)texture.needsUpdate=true;// textures can have undefined image data
  2208. }texture.uuid=data.uuid;if(data.name!==undefined)texture.name=data.name;if(data.mapping!==undefined)texture.mapping=parseConstant(data.mapping,TEXTURE_MAPPING);if(data.offset!==undefined)texture.offset.fromArray(data.offset);if(data.repeat!==undefined)texture.repeat.fromArray(data.repeat);if(data.center!==undefined)texture.center.fromArray(data.center);if(data.rotation!==undefined)texture.rotation=data.rotation;if(data.wrap!==undefined){texture.wrapS=parseConstant(data.wrap[0],TEXTURE_WRAPPING);texture.wrapT=parseConstant(data.wrap[1],TEXTURE_WRAPPING);}if(data.format!==undefined)texture.format=data.format;if(data.type!==undefined)texture.type=data.type;if(data.encoding!==undefined)texture.encoding=data.encoding;if(data.minFilter!==undefined)texture.minFilter=parseConstant(data.minFilter,TEXTURE_FILTER);if(data.magFilter!==undefined)texture.magFilter=parseConstant(data.magFilter,TEXTURE_FILTER);if(data.anisotropy!==undefined)texture.anisotropy=data.anisotropy;if(data.flipY!==undefined)texture.flipY=data.flipY;if(data.premultiplyAlpha!==undefined)texture.premultiplyAlpha=data.premultiplyAlpha;if(data.unpackAlignment!==undefined)texture.unpackAlignment=data.unpackAlignment;textures[data.uuid]=texture;}}return textures;}parseObject(data,geometries,materials,animations){var object;function getGeometry(name){if(geometries[name]===undefined){console.warn('THREE.ObjectLoader: Undefined geometry',name);}return geometries[name];}function getMaterial(name){if(name===undefined)return undefined;if(Array.isArray(name)){var array=[];for(var _i317=0,l=name.length;_i317<l;_i317++){var uuid=name[_i317];if(materials[uuid]===undefined){console.warn('THREE.ObjectLoader: Undefined material',uuid);}array.push(materials[uuid]);}return array;}if(materials[name]===undefined){console.warn('THREE.ObjectLoader: Undefined material',name);}return materials[name];}var geometry,material;switch(data.type){case'Scene':object=new Scene();if(data.background!==undefined){if(Number.isInteger(data.background)){object.background=new Color(data.background);}}if(data.fog!==undefined){if(data.fog.type==='Fog'){object.fog=new Fog(data.fog.color,data.fog.near,data.fog.far);}else if(data.fog.type==='FogExp2'){object.fog=new FogExp2(data.fog.color,data.fog.density);}}break;case'PerspectiveCamera':object=new PerspectiveCamera(data.fov,data.aspect,data.near,data.far);if(data.focus!==undefined)object.focus=data.focus;if(data.zoom!==undefined)object.zoom=data.zoom;if(data.filmGauge!==undefined)object.filmGauge=data.filmGauge;if(data.filmOffset!==undefined)object.filmOffset=data.filmOffset;if(data.view!==undefined)object.view=Object.assign({},data.view);break;case'OrthographicCamera':object=new OrthographicCamera(data.left,data.right,data.top,data.bottom,data.near,data.far);if(data.zoom!==undefined)object.zoom=data.zoom;if(data.view!==undefined)object.view=Object.assign({},data.view);break;case'AmbientLight':object=new AmbientLight(data.color,data.intensity);break;case'DirectionalLight':object=new DirectionalLight(data.color,data.intensity);break;case'PointLight':object=new PointLight(data.color,data.intensity,data.distance,data.decay);break;case'RectAreaLight':object=new RectAreaLight(data.color,data.intensity,data.width,data.height);break;case'SpotLight':object=new SpotLight(data.color,data.intensity,data.distance,data.angle,data.penumbra,data.decay);break;case'HemisphereLight':object=new HemisphereLight(data.color,data.groundColor,data.intensity);break;case'LightProbe':object=new LightProbe().fromJSON(data);break;case'SkinnedMesh':geometry=getGeometry(data.geometry);material=getMaterial(data.material);object=new SkinnedMesh(geometry,material);if(data.bindMode!==undefined)object.bindMode=data.bindMode;if(data.bindMatrix!==undefined)object.bindMatrix.fromArray(data.bindMatrix);if(data.skeleton!==undefined)object.skeleton=data.skeleton;break;case'Mesh':geometry=getGeometry(data.geometry);material=getMaterial(data.material);object=new Mesh(geometry,material);break;case'InstancedMesh':geometry=getGeometry(data.geometry);material=getMaterial(data.material);var count=data.count;var instanceMatrix=data.instanceMatrix;object=new InstancedMesh(geometry,material,count);object.instanceMatrix=new BufferAttribute(new Float32Array(instanceMatrix.array),16);break;case'LOD':object=new LOD();break;case'Line':object=new Line(getGeometry(data.geometry),getMaterial(data.material));break;case'LineLoop':object=new LineLoop(getGeometry(data.geometry),getMaterial(data.material));break;case'LineSegments':object=new LineSegments(getGeometry(data.geometry),getMaterial(data.material));break;case'PointCloud':case'Points':object=new Points(getGeometry(data.geometry),getMaterial(data.material));break;case'Sprite':object=new Sprite$1(getMaterial(data.material));break;case'Group':object=new Group();break;case'Bone':object=new Bone();break;default:object=new Object3D();}object.uuid=data.uuid;if(data.name!==undefined)object.name=data.name;if(data.matrix!==undefined){object.matrix.fromArray(data.matrix);if(data.matrixAutoUpdate!==undefined)object.matrixAutoUpdate=data.matrixAutoUpdate;if(object.matrixAutoUpdate)object.matrix.decompose(object.position,object.quaternion,object.scale);}else {if(data.position!==undefined)object.position.fromArray(data.position);if(data.rotation!==undefined)object.rotation.fromArray(data.rotation);if(data.quaternion!==undefined)object.quaternion.fromArray(data.quaternion);if(data.scale!==undefined)object.scale.fromArray(data.scale);}if(data.castShadow!==undefined)object.castShadow=data.castShadow;if(data.receiveShadow!==undefined)object.receiveShadow=data.receiveShadow;if(data.shadow){if(data.shadow.bias!==undefined)object.shadow.bias=data.shadow.bias;if(data.shadow.normalBias!==undefined)object.shadow.normalBias=data.shadow.normalBias;if(data.shadow.radius!==undefined)object.shadow.radius=data.shadow.radius;if(data.shadow.mapSize!==undefined)object.shadow.mapSize.fromArray(data.shadow.mapSize);if(data.shadow.camera!==undefined)object.shadow.camera=this.parseObject(data.shadow.camera);}if(data.visible!==undefined)object.visible=data.visible;if(data.frustumCulled!==undefined)object.frustumCulled=data.frustumCulled;if(data.renderOrder!==undefined)object.renderOrder=data.renderOrder;if(data.userData!==undefined)object.userData=data.userData;if(data.layers!==undefined)object.layers.mask=data.layers;if(data.children!==undefined){var children=data.children;for(var _i318=0;_i318<children.length;_i318++){object.add(this.parseObject(children[_i318],geometries,materials,animations));}}if(data.animations!==undefined){var objectAnimations=data.animations;for(var _i319=0;_i319<objectAnimations.length;_i319++){var uuid=objectAnimations[_i319];object.animations.push(animations[uuid]);}}if(data.type==='LOD'){if(data.autoUpdate!==undefined)object.autoUpdate=data.autoUpdate;var levels=data.levels;for(var l=0;l<levels.length;l++){var level=levels[l];var child=object.getObjectByProperty('uuid',level.object);if(child!==undefined){object.addLevel(child,level.distance);}}}return object;}bindSkeletons(object,skeletons){if(Object.keys(skeletons).length===0)return;object.traverse(function(child){if(child.isSkinnedMesh===true&&child.skeleton!==undefined){var skeleton=skeletons[child.skeleton];if(skeleton===undefined){console.warn('THREE.ObjectLoader: No skeleton found with UUID:',child.skeleton);}else {child.bind(skeleton,child.bindMatrix);}}});}/* DEPRECATED */setTexturePath(value){console.warn('THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().');return this.setResourcePath(value);}}var TEXTURE_MAPPING={UVMapping:UVMapping,CubeReflectionMapping:CubeReflectionMapping,CubeRefractionMapping:CubeRefractionMapping,EquirectangularReflectionMapping:EquirectangularReflectionMapping,EquirectangularRefractionMapping:EquirectangularRefractionMapping,CubeUVReflectionMapping:CubeUVReflectionMapping,CubeUVRefractionMapping:CubeUVRefractionMapping};var TEXTURE_WRAPPING={RepeatWrapping:RepeatWrapping,ClampToEdgeWrapping:ClampToEdgeWrapping,MirroredRepeatWrapping:MirroredRepeatWrapping};var TEXTURE_FILTER={NearestFilter:NearestFilter,NearestMipmapNearestFilter:NearestMipmapNearestFilter,NearestMipmapLinearFilter:NearestMipmapLinearFilter,LinearFilter:LinearFilter,LinearMipmapNearestFilter:LinearMipmapNearestFilter,LinearMipmapLinearFilter:LinearMipmapLinearFilter};function ImageBitmapLoader(manager){if(typeof createImageBitmap==='undefined'){console.warn('THREE.ImageBitmapLoader: createImageBitmap() not supported.');}if(typeof fetch==='undefined'){console.warn('THREE.ImageBitmapLoader: fetch() not supported.');}Loader.call(this,manager);this.options={premultiplyAlpha:'none'};}ImageBitmapLoader.prototype=Object.assign(Object.create(Loader.prototype),{constructor:ImageBitmapLoader,isImageBitmapLoader:true,setOptions:function setOptions(options){this.options=options;return this;},load:function load(url,onLoad,onProgress,onError){if(url===undefined)url='';if(this.path!==undefined)url=this.path+url;url=this.manager.resolveURL(url);var scope=this;var cached=Cache.get(url);if(cached!==undefined){scope.manager.itemStart(url);setTimeout(function(){if(onLoad)onLoad(cached);scope.manager.itemEnd(url);},0);return cached;}var fetchOptions={};fetchOptions.credentials=this.crossOrigin==='anonymous'?'same-origin':'include';fetch(url,fetchOptions).then(function(res){return res.blob();}).then(function(blob){//console.log('getBlob', url )
  2209. return createImageBitmap(blob,scope.options);}).then(function(imageBitmap){Cache.add(url,imageBitmap);if(onLoad)onLoad(imageBitmap);scope.manager.itemEnd(url);}).catch(function(e){//console.log('error', url, e)
  2210. if(onError)onError(e,url);scope.manager.itemError(url);scope.manager.itemEnd(url);});scope.manager.itemStart(url);}});function ShapePath(){this.type='ShapePath';this.color=new Color();this.subPaths=[];this.currentPath=null;}Object.assign(ShapePath.prototype,{moveTo:function moveTo(x,y){this.currentPath=new Path();this.subPaths.push(this.currentPath);this.currentPath.moveTo(x,y);return this;},lineTo:function lineTo(x,y){this.currentPath.lineTo(x,y);return this;},quadraticCurveTo:function quadraticCurveTo(aCPx,aCPy,aX,aY){this.currentPath.quadraticCurveTo(aCPx,aCPy,aX,aY);return this;},bezierCurveTo:function bezierCurveTo(aCP1x,aCP1y,aCP2x,aCP2y,aX,aY){this.currentPath.bezierCurveTo(aCP1x,aCP1y,aCP2x,aCP2y,aX,aY);return this;},splineThru:function splineThru(pts){this.currentPath.splineThru(pts);return this;},toShapes:function toShapes(isCCW,noHoles){function toShapesNoHoles(inSubpaths){var shapes=[];for(var _i320=0,l=inSubpaths.length;_i320<l;_i320++){var _tmpPath=inSubpaths[_i320];var _tmpShape=new Shape();_tmpShape.curves=_tmpPath.curves;shapes.push(_tmpShape);}return shapes;}function isPointInsidePolygon(inPt,inPolygon){var polyLen=inPolygon.length;// inPt on polygon contour => immediate success or
  2211. // toggling of inside/outside at every single! intersection point of an edge
  2212. // with the horizontal line through inPt, left of inPt
  2213. // not counting lowerY endpoints of edges and whole edges on that line
  2214. var inside=false;for(var p=polyLen-1,q=0;q<polyLen;p=q++){var edgeLowPt=inPolygon[p];var edgeHighPt=inPolygon[q];var edgeDx=edgeHighPt.x-edgeLowPt.x;var edgeDy=edgeHighPt.y-edgeLowPt.y;if(Math.abs(edgeDy)>Number.EPSILON){// not parallel
  2215. if(edgeDy<0){edgeLowPt=inPolygon[q];edgeDx=-edgeDx;edgeHighPt=inPolygon[p];edgeDy=-edgeDy;}if(inPt.y<edgeLowPt.y||inPt.y>edgeHighPt.y)continue;if(inPt.y===edgeLowPt.y){if(inPt.x===edgeLowPt.x)return true;// inPt is on contour ?
  2216. // continue; // no intersection or edgeLowPt => doesn't count !!!
  2217. }else {var perpEdge=edgeDy*(inPt.x-edgeLowPt.x)-edgeDx*(inPt.y-edgeLowPt.y);if(perpEdge===0)return true;// inPt is on contour ?
  2218. if(perpEdge<0)continue;inside=!inside;// true intersection left of inPt
  2219. }}else {// parallel or collinear
  2220. if(inPt.y!==edgeLowPt.y)continue;// parallel
  2221. // edge lies on the same horizontal line as inPt
  2222. if(edgeHighPt.x<=inPt.x&&inPt.x<=edgeLowPt.x||edgeLowPt.x<=inPt.x&&inPt.x<=edgeHighPt.x)return true;// inPt: Point on contour !
  2223. // continue;
  2224. }}return inside;}var isClockWise=ShapeUtils.isClockWise;var subPaths=this.subPaths;if(subPaths.length===0)return [];if(noHoles===true)return toShapesNoHoles(subPaths);var solid,tmpPath,tmpShape;var shapes=[];if(subPaths.length===1){tmpPath=subPaths[0];tmpShape=new Shape();tmpShape.curves=tmpPath.curves;shapes.push(tmpShape);return shapes;}var holesFirst=!isClockWise(subPaths[0].getPoints());holesFirst=isCCW?!holesFirst:holesFirst;// console.log("Holes first", holesFirst);
  2225. var betterShapeHoles=[];var newShapes=[];var newShapeHoles=[];var mainIdx=0;var tmpPoints;newShapes[mainIdx]=undefined;newShapeHoles[mainIdx]=[];for(var _i321=0,l=subPaths.length;_i321<l;_i321++){tmpPath=subPaths[_i321];tmpPoints=tmpPath.getPoints();solid=isClockWise(tmpPoints);solid=isCCW?!solid:solid;if(solid){if(!holesFirst&&newShapes[mainIdx])mainIdx++;newShapes[mainIdx]={s:new Shape(),p:tmpPoints};newShapes[mainIdx].s.curves=tmpPath.curves;if(holesFirst)mainIdx++;newShapeHoles[mainIdx]=[];//console.log('cw', i);
  2226. }else {newShapeHoles[mainIdx].push({h:tmpPath,p:tmpPoints[0]});//console.log('ccw', i);
  2227. }}// only Holes? -> probably all Shapes with wrong orientation
  2228. if(!newShapes[0])return toShapesNoHoles(subPaths);if(newShapes.length>1){var ambiguous=false;var toChange=[];for(var sIdx=0,sLen=newShapes.length;sIdx<sLen;sIdx++){betterShapeHoles[sIdx]=[];}for(var _sIdx=0,_sLen=newShapes.length;_sIdx<_sLen;_sIdx++){var sho=newShapeHoles[_sIdx];for(var hIdx=0;hIdx<sho.length;hIdx++){var ho=sho[hIdx];var hole_unassigned=true;for(var s2Idx=0;s2Idx<newShapes.length;s2Idx++){if(isPointInsidePolygon(ho.p,newShapes[s2Idx].p)){if(_sIdx!==s2Idx)toChange.push({froms:_sIdx,tos:s2Idx,hole:hIdx});if(hole_unassigned){hole_unassigned=false;betterShapeHoles[s2Idx].push(ho);}else {ambiguous=true;}}}if(hole_unassigned){betterShapeHoles[_sIdx].push(ho);}}}// console.log("ambiguous: ", ambiguous);
  2229. if(toChange.length>0){// console.log("to change: ", toChange);
  2230. if(!ambiguous)newShapeHoles=betterShapeHoles;}}var tmpHoles;for(var _i322=0,il=newShapes.length;_i322<il;_i322++){tmpShape=newShapes[_i322].s;shapes.push(tmpShape);tmpHoles=newShapeHoles[_i322];for(var j=0,jl=tmpHoles.length;j<jl;j++){tmpShape.holes.push(tmpHoles[j].h);}}//console.log("shape", shapes);
  2231. return shapes;}});function Font(data){this.type='Font';this.data=data;}Object.assign(Font.prototype,{isFont:true,generateShapes:function generateShapes(text){var size=arguments.length>1&&arguments[1]!==undefined?arguments[1]:100;var shapes=[];var paths=createPaths(text,size,this.data);for(var p=0,pl=paths.length;p<pl;p++){Array.prototype.push.apply(shapes,paths[p].toShapes());}return shapes;}});function createPaths(text,size,data){var chars=Array.from?Array.from(text):String(text).split('');// workaround for IE11, see #13988
  2232. var scale=size/data.resolution;var line_height=(data.boundingBox.yMax-data.boundingBox.yMin+data.underlineThickness)*scale;var paths=[];var offsetX=0,offsetY=0;for(var _i323=0;_i323<chars.length;_i323++){var char=chars[_i323];if(char==='\n'){offsetX=0;offsetY-=line_height;}else {var ret=createPath(char,scale,offsetX,offsetY,data);offsetX+=ret.offsetX;paths.push(ret.path);}}return paths;}function createPath(char,scale,offsetX,offsetY,data){var glyph=data.glyphs[char]||data.glyphs['?'];if(!glyph){console.error('THREE.Font: character "'+char+'" does not exists in font family '+data.familyName+'.');return;}var path=new ShapePath();var x,y,cpx,cpy,cpx1,cpy1,cpx2,cpy2;if(glyph.o){var outline=glyph._cachedOutline||(glyph._cachedOutline=glyph.o.split(' '));for(var _i324=0,l=outline.length;_i324<l;){var action=outline[_i324++];switch(action){case'm':// moveTo
  2233. x=outline[_i324++]*scale+offsetX;y=outline[_i324++]*scale+offsetY;path.moveTo(x,y);break;case'l':// lineTo
  2234. x=outline[_i324++]*scale+offsetX;y=outline[_i324++]*scale+offsetY;path.lineTo(x,y);break;case'q':// quadraticCurveTo
  2235. cpx=outline[_i324++]*scale+offsetX;cpy=outline[_i324++]*scale+offsetY;cpx1=outline[_i324++]*scale+offsetX;cpy1=outline[_i324++]*scale+offsetY;path.quadraticCurveTo(cpx1,cpy1,cpx,cpy);break;case'b':// bezierCurveTo
  2236. cpx=outline[_i324++]*scale+offsetX;cpy=outline[_i324++]*scale+offsetY;cpx1=outline[_i324++]*scale+offsetX;cpy1=outline[_i324++]*scale+offsetY;cpx2=outline[_i324++]*scale+offsetX;cpy2=outline[_i324++]*scale+offsetY;path.bezierCurveTo(cpx1,cpy1,cpx2,cpy2,cpx,cpy);break;}}}return {offsetX:glyph.ha*scale,path:path};}function FontLoader(manager){Loader.call(this,manager);}FontLoader.prototype=Object.assign(Object.create(Loader.prototype),{constructor:FontLoader,load:function load(url,onLoad,onProgress,onError){var scope=this;var loader=new FileLoader(this.manager);loader.setPath(this.path);loader.setRequestHeader(this.requestHeader);loader.setWithCredentials(scope.withCredentials);loader.load(url,function(text){var json;try{json=JSON.parse(text);}catch(e){console.warn('THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.');json=JSON.parse(text.substring(65,text.length-2));}var font=scope.parse(json);if(onLoad)onLoad(font);},onProgress,onError);},parse:function parse(json){return new Font(json);}});var _context;var AudioContext={getContext:function getContext(){if(_context===undefined){_context=new(window.AudioContext||window.webkitAudioContext)();}return _context;},setContext:function setContext(value){_context=value;}};function AudioLoader(manager){Loader.call(this,manager);}AudioLoader.prototype=Object.assign(Object.create(Loader.prototype),{constructor:AudioLoader,load:function load(url,onLoad,onProgress,onError){var scope=this;var loader=new FileLoader(scope.manager);loader.setResponseType('arraybuffer');loader.setPath(scope.path);loader.setRequestHeader(scope.requestHeader);loader.setWithCredentials(scope.withCredentials);loader.load(url,function(buffer){try{// Create a copy of the buffer. The `decodeAudioData` method
  2237. // detaches the buffer when complete, preventing reuse.
  2238. var bufferCopy=buffer.slice(0);var context=AudioContext.getContext();context.decodeAudioData(bufferCopy,function(audioBuffer){onLoad(audioBuffer);});}catch(e){if(onError){onError(e);}else {console.error(e);}scope.manager.itemError(url);}},onProgress,onError);}});function HemisphereLightProbe(skyColor,groundColor,intensity){LightProbe.call(this,undefined,intensity);var color1=new Color().set(skyColor);var color2=new Color().set(groundColor);var sky=new Vector3(color1.r,color1.g,color1.b);var ground=new Vector3(color2.r,color2.g,color2.b);// without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  2239. var c0=Math.sqrt(Math.PI);var c1=c0*Math.sqrt(0.75);this.sh.coefficients[0].copy(sky).add(ground).multiplyScalar(c0);this.sh.coefficients[1].copy(sky).sub(ground).multiplyScalar(c1);}HemisphereLightProbe.prototype=Object.assign(Object.create(LightProbe.prototype),{constructor:HemisphereLightProbe,isHemisphereLightProbe:true,copy:function copy(source){// modifying colors not currently supported
  2240. LightProbe.prototype.copy.call(this,source);return this;},toJSON:function toJSON(meta){var data=LightProbe.prototype.toJSON.call(this,meta);// data.sh = this.sh.toArray(); // todo
  2241. return data;}});function AmbientLightProbe(color,intensity){LightProbe.call(this,undefined,intensity);var color1=new Color().set(color);// without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
  2242. this.sh.coefficients[0].set(color1.r,color1.g,color1.b).multiplyScalar(2*Math.sqrt(Math.PI));}AmbientLightProbe.prototype=Object.assign(Object.create(LightProbe.prototype),{constructor:AmbientLightProbe,isAmbientLightProbe:true,copy:function copy(source){// modifying color not currently supported
  2243. LightProbe.prototype.copy.call(this,source);return this;},toJSON:function toJSON(meta){var data=LightProbe.prototype.toJSON.call(this,meta);// data.sh = this.sh.toArray(); // todo
  2244. return data;}});var _eyeRight=new Matrix4();var _eyeLeft=new Matrix4();function StereoCamera(){this.type='StereoCamera';this.aspect=1;this.eyeSep=0.064;this.cameraL=new PerspectiveCamera();this.cameraL.layers.enable(1);this.cameraL.matrixAutoUpdate=false;this.cameraR=new PerspectiveCamera();this.cameraR.layers.enable(2);this.cameraR.matrixAutoUpdate=false;this._cache={focus:null,fov:null,aspect:null,near:null,far:null,zoom:null,eyeSep:null};}Object.assign(StereoCamera.prototype,{update:function update(camera){var cache=this._cache;var needsUpdate=cache.focus!==camera.focus||cache.fov!==camera.fov||cache.aspect!==camera.aspect*this.aspect||cache.near!==camera.near||cache.far!==camera.far||cache.zoom!==camera.zoom||cache.eyeSep!==this.eyeSep;if(needsUpdate){cache.focus=camera.focus;cache.fov=camera.fov;cache.aspect=camera.aspect*this.aspect;cache.near=camera.near;cache.far=camera.far;cache.zoom=camera.zoom;cache.eyeSep=this.eyeSep;// Off-axis stereoscopic effect based on
  2245. // http://paulbourke.net/stereographics/stereorender/
  2246. var projectionMatrix=camera.projectionMatrix.clone();var eyeSepHalf=cache.eyeSep/2;var eyeSepOnProjection=eyeSepHalf*cache.near/cache.focus;var ymax=cache.near*Math.tan(MathUtils.DEG2RAD*cache.fov*0.5)/cache.zoom;var xmin,xmax;// translate xOffset
  2247. _eyeLeft.elements[12]=-eyeSepHalf;_eyeRight.elements[12]=eyeSepHalf;// for left eye
  2248. xmin=-ymax*cache.aspect+eyeSepOnProjection;xmax=ymax*cache.aspect+eyeSepOnProjection;projectionMatrix.elements[0]=2*cache.near/(xmax-xmin);projectionMatrix.elements[8]=(xmax+xmin)/(xmax-xmin);this.cameraL.projectionMatrix.copy(projectionMatrix);// for right eye
  2249. xmin=-ymax*cache.aspect-eyeSepOnProjection;xmax=ymax*cache.aspect-eyeSepOnProjection;projectionMatrix.elements[0]=2*cache.near/(xmax-xmin);projectionMatrix.elements[8]=(xmax+xmin)/(xmax-xmin);this.cameraR.projectionMatrix.copy(projectionMatrix);}this.cameraL.matrixWorld.copy(camera.matrixWorld).multiply(_eyeLeft);this.cameraR.matrixWorld.copy(camera.matrixWorld).multiply(_eyeRight);}});class Clock{constructor(autoStart){this.autoStart=autoStart!==undefined?autoStart:true;this.startTime=0;this.oldTime=0;this.elapsedTime=0;this.running=false;}start(){this.startTime=now();this.oldTime=this.startTime;this.elapsedTime=0;this.running=true;}stop(){this.getElapsedTime();this.running=false;this.autoStart=false;}getElapsedTime(){this.getDelta();return this.elapsedTime;}getDelta(){var diff=0;if(this.autoStart&&!this.running){this.start();return 0;}if(this.running){var newTime=now();diff=(newTime-this.oldTime)/1000;this.oldTime=newTime;this.elapsedTime+=diff;}return diff;}}function now(){return (typeof performance==='undefined'?Date:performance).now();// see #10732
  2250. }var _position$2=/*@__PURE__*/new Vector3();var _quaternion$3=/*@__PURE__*/new Quaternion();var _scale$1=/*@__PURE__*/new Vector3();var _orientation=/*@__PURE__*/new Vector3();class AudioListener extends Object3D{constructor(){super();this.type='AudioListener';this.context=AudioContext.getContext();this.gain=this.context.createGain();this.gain.connect(this.context.destination);this.filter=null;this.timeDelta=0;// private
  2251. this._clock=new Clock();}getInput(){return this.gain;}removeFilter(){if(this.filter!==null){this.gain.disconnect(this.filter);this.filter.disconnect(this.context.destination);this.gain.connect(this.context.destination);this.filter=null;}return this;}getFilter(){return this.filter;}setFilter(value){if(this.filter!==null){this.gain.disconnect(this.filter);this.filter.disconnect(this.context.destination);}else {this.gain.disconnect(this.context.destination);}this.filter=value;this.gain.connect(this.filter);this.filter.connect(this.context.destination);return this;}getMasterVolume(){return this.gain.gain.value;}setMasterVolume(value){this.gain.gain.setTargetAtTime(value,this.context.currentTime,0.01);return this;}updateMatrixWorld(force){super.updateMatrixWorld(force);var listener=this.context.listener;var up=this.up;this.timeDelta=this._clock.getDelta();this.matrixWorld.decompose(_position$2,_quaternion$3,_scale$1);_orientation.set(0,0,-1).applyQuaternion(_quaternion$3);if(listener.positionX){// code path for Chrome (see #14393)
  2252. var endTime=this.context.currentTime+this.timeDelta;listener.positionX.linearRampToValueAtTime(_position$2.x,endTime);listener.positionY.linearRampToValueAtTime(_position$2.y,endTime);listener.positionZ.linearRampToValueAtTime(_position$2.z,endTime);listener.forwardX.linearRampToValueAtTime(_orientation.x,endTime);listener.forwardY.linearRampToValueAtTime(_orientation.y,endTime);listener.forwardZ.linearRampToValueAtTime(_orientation.z,endTime);listener.upX.linearRampToValueAtTime(up.x,endTime);listener.upY.linearRampToValueAtTime(up.y,endTime);listener.upZ.linearRampToValueAtTime(up.z,endTime);}else {listener.setPosition(_position$2.x,_position$2.y,_position$2.z);listener.setOrientation(_orientation.x,_orientation.y,_orientation.z,up.x,up.y,up.z);}}}class Audio extends Object3D{constructor(listener){super();this.type='Audio';this.listener=listener;this.context=listener.context;this.gain=this.context.createGain();this.gain.connect(listener.getInput());this.autoplay=false;this.buffer=null;this.detune=0;this.loop=false;this.loopStart=0;this.loopEnd=0;this.offset=0;this.duration=undefined;this.playbackRate=1;this.isPlaying=false;this.hasPlaybackControl=true;this.source=null;this.sourceType='empty';this._startedAt=0;this._progress=0;this._connected=false;this.filters=[];}getOutput(){return this.gain;}setNodeSource(audioNode){this.hasPlaybackControl=false;this.sourceType='audioNode';this.source=audioNode;this.connect();return this;}setMediaElementSource(mediaElement){this.hasPlaybackControl=false;this.sourceType='mediaNode';this.source=this.context.createMediaElementSource(mediaElement);this.connect();return this;}setMediaStreamSource(mediaStream){this.hasPlaybackControl=false;this.sourceType='mediaStreamNode';this.source=this.context.createMediaStreamSource(mediaStream);this.connect();return this;}setBuffer(audioBuffer){this.buffer=audioBuffer;this.sourceType='buffer';if(this.autoplay)this.play();return this;}play(){var delay=arguments.length>0&&arguments[0]!==undefined?arguments[0]:0;if(this.isPlaying===true){console.warn('THREE.Audio: Audio is already playing.');return;}if(this.hasPlaybackControl===false){console.warn('THREE.Audio: this Audio has no playback control.');return;}this._startedAt=this.context.currentTime+delay;var source=this.context.createBufferSource();source.buffer=this.buffer;source.loop=this.loop;source.loopStart=this.loopStart;source.loopEnd=this.loopEnd;source.onended=this.onEnded.bind(this);source.start(this._startedAt,this._progress+this.offset,this.duration);this.isPlaying=true;this.source=source;this.setDetune(this.detune);this.setPlaybackRate(this.playbackRate);return this.connect();}pause(){if(this.hasPlaybackControl===false){console.warn('THREE.Audio: this Audio has no playback control.');return;}if(this.isPlaying===true){// update current progress
  2253. this._progress+=Math.max(this.context.currentTime-this._startedAt,0)*this.playbackRate;if(this.loop===true){// ensure _progress does not exceed duration with looped audios
  2254. this._progress=this._progress%(this.duration||this.buffer.duration);}this.source.stop();this.source.onended=null;this.isPlaying=false;}return this;}stop(){if(this.hasPlaybackControl===false){console.warn('THREE.Audio: this Audio has no playback control.');return;}this._progress=0;this.source.stop();this.source.onended=null;this.isPlaying=false;return this;}connect(){if(this.filters.length>0){this.source.connect(this.filters[0]);for(var _i325=1,l=this.filters.length;_i325<l;_i325++){this.filters[_i325-1].connect(this.filters[_i325]);}this.filters[this.filters.length-1].connect(this.getOutput());}else {this.source.connect(this.getOutput());}this._connected=true;return this;}disconnect(){if(this.filters.length>0){this.source.disconnect(this.filters[0]);for(var _i326=1,l=this.filters.length;_i326<l;_i326++){this.filters[_i326-1].disconnect(this.filters[_i326]);}this.filters[this.filters.length-1].disconnect(this.getOutput());}else {this.source.disconnect(this.getOutput());}this._connected=false;return this;}getFilters(){return this.filters;}setFilters(value){if(!value)value=[];if(this._connected===true){this.disconnect();this.filters=value.slice();this.connect();}else {this.filters=value.slice();}return this;}setDetune(value){this.detune=value;if(this.source.detune===undefined)return;// only set detune when available
  2255. if(this.isPlaying===true){this.source.detune.setTargetAtTime(this.detune,this.context.currentTime,0.01);}return this;}getDetune(){return this.detune;}getFilter(){return this.getFilters()[0];}setFilter(filter){return this.setFilters(filter?[filter]:[]);}setPlaybackRate(value){if(this.hasPlaybackControl===false){console.warn('THREE.Audio: this Audio has no playback control.');return;}this.playbackRate=value;if(this.isPlaying===true){this.source.playbackRate.setTargetAtTime(this.playbackRate,this.context.currentTime,0.01);}return this;}getPlaybackRate(){return this.playbackRate;}onEnded(){this.isPlaying=false;}getLoop(){if(this.hasPlaybackControl===false){console.warn('THREE.Audio: this Audio has no playback control.');return false;}return this.loop;}setLoop(value){if(this.hasPlaybackControl===false){console.warn('THREE.Audio: this Audio has no playback control.');return;}this.loop=value;if(this.isPlaying===true){this.source.loop=this.loop;}return this;}setLoopStart(value){this.loopStart=value;return this;}setLoopEnd(value){this.loopEnd=value;return this;}getVolume(){return this.gain.gain.value;}setVolume(value){this.gain.gain.setTargetAtTime(value,this.context.currentTime,0.01);return this;}}var _position$3=/*@__PURE__*/new Vector3();var _quaternion$4=/*@__PURE__*/new Quaternion();var _scale$2=/*@__PURE__*/new Vector3();var _orientation$1=/*@__PURE__*/new Vector3();class PositionalAudio extends Audio{constructor(listener){super(listener);this.panner=this.context.createPanner();this.panner.panningModel='HRTF';this.panner.connect(this.gain);}getOutput(){return this.panner;}getRefDistance(){return this.panner.refDistance;}setRefDistance(value){this.panner.refDistance=value;return this;}getRolloffFactor(){return this.panner.rolloffFactor;}setRolloffFactor(value){this.panner.rolloffFactor=value;return this;}getDistanceModel(){return this.panner.distanceModel;}setDistanceModel(value){this.panner.distanceModel=value;return this;}getMaxDistance(){return this.panner.maxDistance;}setMaxDistance(value){this.panner.maxDistance=value;return this;}setDirectionalCone(coneInnerAngle,coneOuterAngle,coneOuterGain){this.panner.coneInnerAngle=coneInnerAngle;this.panner.coneOuterAngle=coneOuterAngle;this.panner.coneOuterGain=coneOuterGain;return this;}updateMatrixWorld(force){super.updateMatrixWorld(force);if(this.hasPlaybackControl===true&&this.isPlaying===false)return;this.matrixWorld.decompose(_position$3,_quaternion$4,_scale$2);_orientation$1.set(0,0,1).applyQuaternion(_quaternion$4);var panner=this.panner;if(panner.positionX){// code path for Chrome and Firefox (see #14393)
  2256. var endTime=this.context.currentTime+this.listener.timeDelta;panner.positionX.linearRampToValueAtTime(_position$3.x,endTime);panner.positionY.linearRampToValueAtTime(_position$3.y,endTime);panner.positionZ.linearRampToValueAtTime(_position$3.z,endTime);panner.orientationX.linearRampToValueAtTime(_orientation$1.x,endTime);panner.orientationY.linearRampToValueAtTime(_orientation$1.y,endTime);panner.orientationZ.linearRampToValueAtTime(_orientation$1.z,endTime);}else {panner.setPosition(_position$3.x,_position$3.y,_position$3.z);panner.setOrientation(_orientation$1.x,_orientation$1.y,_orientation$1.z);}}}class AudioAnalyser{constructor(audio){var fftSize=arguments.length>1&&arguments[1]!==undefined?arguments[1]:2048;this.analyser=audio.context.createAnalyser();this.analyser.fftSize=fftSize;this.data=new Uint8Array(this.analyser.frequencyBinCount);audio.getOutput().connect(this.analyser);}getFrequencyData(){this.analyser.getByteFrequencyData(this.data);return this.data;}getAverageFrequency(){var value=0;var data=this.getFrequencyData();for(var _i327=0;_i327<data.length;_i327++){value+=data[_i327];}return value/data.length;}}function PropertyMixer(binding,typeName,valueSize){this.binding=binding;this.valueSize=valueSize;var mixFunction,mixFunctionAdditive,setIdentity;// buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ]
  2257. //
  2258. // interpolators can use .buffer as their .result
  2259. // the data then goes to 'incoming'
  2260. //
  2261. // 'accu0' and 'accu1' are used frame-interleaved for
  2262. // the cumulative result and are compared to detect
  2263. // changes
  2264. //
  2265. // 'orig' stores the original state of the property
  2266. //
  2267. // 'add' is used for additive cumulative results
  2268. //
  2269. // 'work' is optional and is only present for quaternion types. It is used
  2270. // to store intermediate quaternion multiplication results
  2271. switch(typeName){case'quaternion':mixFunction=this._slerp;mixFunctionAdditive=this._slerpAdditive;setIdentity=this._setAdditiveIdentityQuaternion;this.buffer=new Float64Array(valueSize*6);this._workIndex=5;break;case'string':case'bool':mixFunction=this._select;// Use the regular mix function and for additive on these types,
  2272. // additive is not relevant for non-numeric types
  2273. mixFunctionAdditive=this._select;setIdentity=this._setAdditiveIdentityOther;this.buffer=new Array(valueSize*5);break;default:mixFunction=this._lerp;mixFunctionAdditive=this._lerpAdditive;setIdentity=this._setAdditiveIdentityNumeric;this.buffer=new Float64Array(valueSize*5);}this._mixBufferRegion=mixFunction;this._mixBufferRegionAdditive=mixFunctionAdditive;this._setIdentity=setIdentity;this._origIndex=3;this._addIndex=4;this.cumulativeWeight=0;this.cumulativeWeightAdditive=0;this.useCount=0;this.referenceCount=0;}Object.assign(PropertyMixer.prototype,{// accumulate data in the 'incoming' region into 'accu<i>'
  2274. accumulate:function accumulate(accuIndex,weight){// note: happily accumulating nothing when weight = 0, the caller knows
  2275. // the weight and shouldn't have made the call in the first place
  2276. var buffer=this.buffer,stride=this.valueSize,offset=accuIndex*stride+stride;var currentWeight=this.cumulativeWeight;if(currentWeight===0){// accuN := incoming * weight
  2277. for(var _i328=0;_i328!==stride;++_i328){buffer[offset+_i328]=buffer[_i328];}currentWeight=weight;}else {// accuN := accuN + incoming * weight
  2278. currentWeight+=weight;var mix=weight/currentWeight;this._mixBufferRegion(buffer,offset,0,mix,stride);}this.cumulativeWeight=currentWeight;},// accumulate data in the 'incoming' region into 'add'
  2279. accumulateAdditive:function accumulateAdditive(weight){var buffer=this.buffer,stride=this.valueSize,offset=stride*this._addIndex;if(this.cumulativeWeightAdditive===0){// add = identity
  2280. this._setIdentity();}// add := add + incoming * weight
  2281. this._mixBufferRegionAdditive(buffer,offset,0,weight,stride);this.cumulativeWeightAdditive+=weight;},// apply the state of 'accu<i>' to the binding when accus differ
  2282. apply:function apply(accuIndex){var stride=this.valueSize,buffer=this.buffer,offset=accuIndex*stride+stride,weight=this.cumulativeWeight,weightAdditive=this.cumulativeWeightAdditive,binding=this.binding;this.cumulativeWeight=0;this.cumulativeWeightAdditive=0;if(weight<1){// accuN := accuN + original * ( 1 - cumulativeWeight )
  2283. var originalValueOffset=stride*this._origIndex;this._mixBufferRegion(buffer,offset,originalValueOffset,1-weight,stride);}if(weightAdditive>0){// accuN := accuN + additive accuN
  2284. this._mixBufferRegionAdditive(buffer,offset,this._addIndex*stride,1,stride);}for(var _i329=stride,e=stride+stride;_i329!==e;++_i329){if(buffer[_i329]!==buffer[_i329+stride]){// value has changed -> update scene graph
  2285. binding.setValue(buffer,offset);break;}}},// remember the state of the bound property and copy it to both accus
  2286. saveOriginalState:function saveOriginalState(){var binding=this.binding;var buffer=this.buffer,stride=this.valueSize,originalValueOffset=stride*this._origIndex;binding.getValue(buffer,originalValueOffset);// accu[0..1] := orig -- initially detect changes against the original
  2287. for(var _i330=stride,e=originalValueOffset;_i330!==e;++_i330){buffer[_i330]=buffer[originalValueOffset+_i330%stride];}// Add to identity for additive
  2288. this._setIdentity();this.cumulativeWeight=0;this.cumulativeWeightAdditive=0;},// apply the state previously taken via 'saveOriginalState' to the binding
  2289. restoreOriginalState:function restoreOriginalState(){var originalValueOffset=this.valueSize*3;this.binding.setValue(this.buffer,originalValueOffset);},_setAdditiveIdentityNumeric:function _setAdditiveIdentityNumeric(){var startIndex=this._addIndex*this.valueSize;var endIndex=startIndex+this.valueSize;for(var _i331=startIndex;_i331<endIndex;_i331++){this.buffer[_i331]=0;}},_setAdditiveIdentityQuaternion:function _setAdditiveIdentityQuaternion(){this._setAdditiveIdentityNumeric();this.buffer[this._addIndex*this.valueSize+3]=1;},_setAdditiveIdentityOther:function _setAdditiveIdentityOther(){var startIndex=this._origIndex*this.valueSize;var targetIndex=this._addIndex*this.valueSize;for(var _i332=0;_i332<this.valueSize;_i332++){this.buffer[targetIndex+_i332]=this.buffer[startIndex+_i332];}},// mix functions
  2290. _select:function _select(buffer,dstOffset,srcOffset,t,stride){if(t>=0.5){for(var _i333=0;_i333!==stride;++_i333){buffer[dstOffset+_i333]=buffer[srcOffset+_i333];}}},_slerp:function _slerp(buffer,dstOffset,srcOffset,t){Quaternion.slerpFlat(buffer,dstOffset,buffer,dstOffset,buffer,srcOffset,t);},_slerpAdditive:function _slerpAdditive(buffer,dstOffset,srcOffset,t,stride){var workOffset=this._workIndex*stride;// Store result in intermediate buffer offset
  2291. Quaternion.multiplyQuaternionsFlat(buffer,workOffset,buffer,dstOffset,buffer,srcOffset);// Slerp to the intermediate result
  2292. Quaternion.slerpFlat(buffer,dstOffset,buffer,dstOffset,buffer,workOffset,t);},_lerp:function _lerp(buffer,dstOffset,srcOffset,t,stride){var s=1-t;for(var _i334=0;_i334!==stride;++_i334){var j=dstOffset+_i334;buffer[j]=buffer[j]*s+buffer[srcOffset+_i334]*t;}},_lerpAdditive:function _lerpAdditive(buffer,dstOffset,srcOffset,t,stride){for(var _i335=0;_i335!==stride;++_i335){var j=dstOffset+_i335;buffer[j]=buffer[j]+buffer[srcOffset+_i335]*t;}}});// Characters [].:/ are reserved for track binding syntax.
  2293. var _RESERVED_CHARS_RE='\\[\\]\\.:\\/';var _reservedRe=new RegExp('['+_RESERVED_CHARS_RE+']','g');// Attempts to allow node names from any language. ES5's `\w` regexp matches
  2294. // only latin characters, and the unicode \p{L} is not yet supported. So
  2295. // instead, we exclude reserved characters and match everything else.
  2296. var _wordChar='[^'+_RESERVED_CHARS_RE+']';var _wordCharOrDot='[^'+_RESERVED_CHARS_RE.replace('\\.','')+']';// Parent directories, delimited by '/' or ':'. Currently unused, but must
  2297. // be matched to parse the rest of the track name.
  2298. var _directoryRe=/((?:WC+[\/:])*)/.source.replace('WC',_wordChar);// Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  2299. var _nodeRe=/(WCOD+)?/.source.replace('WCOD',_wordCharOrDot);// Object on target node, and accessor. May not contain reserved
  2300. // characters. Accessor may contain any character except closing bracket.
  2301. var _objectRe=/(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace('WC',_wordChar);// Property and accessor. May not contain reserved characters. Accessor may
  2302. // contain any non-bracket characters.
  2303. var _propertyRe=/\.(WC+)(?:\[(.+)\])?/.source.replace('WC',_wordChar);var _trackRe=new RegExp(''+'^'+_directoryRe+_nodeRe+_objectRe+_propertyRe+'$');var _supportedObjectNames=['material','materials','bones'];function Composite(targetGroup,path,optionalParsedPath){var parsedPath=optionalParsedPath||PropertyBinding.parseTrackName(path);this._targetGroup=targetGroup;this._bindings=targetGroup.subscribe_(path,parsedPath);}Object.assign(Composite.prototype,{getValue:function getValue(array,offset){this.bind();// bind all binding
  2304. var firstValidIndex=this._targetGroup.nCachedObjects_,binding=this._bindings[firstValidIndex];// and only call .getValue on the first
  2305. if(binding!==undefined)binding.getValue(array,offset);},setValue:function setValue(array,offset){var bindings=this._bindings;for(var _i336=this._targetGroup.nCachedObjects_,n=bindings.length;_i336!==n;++_i336){bindings[_i336].setValue(array,offset);}},bind:function bind(){var bindings=this._bindings;for(var _i337=this._targetGroup.nCachedObjects_,n=bindings.length;_i337!==n;++_i337){bindings[_i337].bind();}},unbind:function unbind(){var bindings=this._bindings;for(var _i338=this._targetGroup.nCachedObjects_,n=bindings.length;_i338!==n;++_i338){bindings[_i338].unbind();}}});function PropertyBinding(rootNode,path,parsedPath){this.path=path;this.parsedPath=parsedPath||PropertyBinding.parseTrackName(path);this.node=PropertyBinding.findNode(rootNode,this.parsedPath.nodeName)||rootNode;this.rootNode=rootNode;}Object.assign(PropertyBinding,{Composite:Composite,create:function create(root,path,parsedPath){if(!(root&&root.isAnimationObjectGroup)){return new PropertyBinding(root,path,parsedPath);}else {return new PropertyBinding.Composite(root,path,parsedPath);}},/**
  2306. * Replaces spaces with underscores and removes unsupported characters from
  2307. * node names, to ensure compatibility with parseTrackName().
  2308. *
  2309. * @param {string} name Node name to be sanitized.
  2310. * @return {string}
  2311. */sanitizeNodeName:function sanitizeNodeName(name){return name.replace(/\s/g,'_').replace(_reservedRe,'');},parseTrackName:function parseTrackName(trackName){var matches=_trackRe.exec(trackName);if(!matches){throw new Error('PropertyBinding: Cannot parse trackName: '+trackName);}var results={// directoryName: matches[ 1 ], // (tschw) currently unused
  2312. nodeName:matches[2],objectName:matches[3],objectIndex:matches[4],propertyName:matches[5],// required
  2313. propertyIndex:matches[6]};var lastDot=results.nodeName&&results.nodeName.lastIndexOf('.');if(lastDot!==undefined&&lastDot!==-1){var objectName=results.nodeName.substring(lastDot+1);// Object names must be checked against an allowlist. Otherwise, there
  2314. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  2315. // 'bar' could be the objectName, or part of a nodeName (which can
  2316. // include '.' characters).
  2317. if(_supportedObjectNames.indexOf(objectName)!==-1){results.nodeName=results.nodeName.substring(0,lastDot);results.objectName=objectName;}}if(results.propertyName===null||results.propertyName.length===0){throw new Error('PropertyBinding: can not parse propertyName from trackName: '+trackName);}return results;},findNode:function findNode(root,nodeName){if(!nodeName||nodeName===''||nodeName==='.'||nodeName===-1||nodeName===root.name||nodeName===root.uuid){return root;}// search into skeleton bones.
  2318. if(root.skeleton){var bone=root.skeleton.getBoneByName(nodeName);if(bone!==undefined){return bone;}}// search into node subtree.
  2319. if(root.children){var _searchNodeSubtree=function searchNodeSubtree(children){for(var _i339=0;_i339<children.length;_i339++){var childNode=children[_i339];if(childNode.name===nodeName||childNode.uuid===nodeName){return childNode;}var result=_searchNodeSubtree(childNode.children);if(result)return result;}return null;};var subTreeNode=_searchNodeSubtree(root.children);if(subTreeNode){return subTreeNode;}}return null;}});Object.assign(PropertyBinding.prototype,{// prototype, continued
  2320. // these are used to "bind" a nonexistent property
  2321. _getValue_unavailable:function _getValue_unavailable(){},_setValue_unavailable:function _setValue_unavailable(){},BindingType:{Direct:0,EntireArray:1,ArrayElement:2,HasFromToArray:3},Versioning:{None:0,NeedsUpdate:1,MatrixWorldNeedsUpdate:2},GetterByBindingType:[function getValue_direct(buffer,offset){buffer[offset]=this.node[this.propertyName];},function getValue_array(buffer,offset){var source=this.resolvedProperty;for(var _i340=0,n=source.length;_i340!==n;++_i340){buffer[offset++]=source[_i340];}},function getValue_arrayElement(buffer,offset){buffer[offset]=this.resolvedProperty[this.propertyIndex];},function getValue_toArray(buffer,offset){this.resolvedProperty.toArray(buffer,offset);}],SetterByBindingTypeAndVersioning:[[// Direct
  2322. function setValue_direct(buffer,offset){this.targetObject[this.propertyName]=buffer[offset];},function setValue_direct_setNeedsUpdate(buffer,offset){this.targetObject[this.propertyName]=buffer[offset];this.targetObject.needsUpdate=true;},function setValue_direct_setMatrixWorldNeedsUpdate(buffer,offset){this.targetObject[this.propertyName]=buffer[offset];this.targetObject.matrixWorldNeedsUpdate=true;}],[// EntireArray
  2323. function setValue_array(buffer,offset){var dest=this.resolvedProperty;for(var _i341=0,n=dest.length;_i341!==n;++_i341){dest[_i341]=buffer[offset++];}},function setValue_array_setNeedsUpdate(buffer,offset){var dest=this.resolvedProperty;for(var _i342=0,n=dest.length;_i342!==n;++_i342){dest[_i342]=buffer[offset++];}this.targetObject.needsUpdate=true;},function setValue_array_setMatrixWorldNeedsUpdate(buffer,offset){var dest=this.resolvedProperty;for(var _i343=0,n=dest.length;_i343!==n;++_i343){dest[_i343]=buffer[offset++];}this.targetObject.matrixWorldNeedsUpdate=true;}],[// ArrayElement
  2324. function setValue_arrayElement(buffer,offset){this.resolvedProperty[this.propertyIndex]=buffer[offset];},function setValue_arrayElement_setNeedsUpdate(buffer,offset){this.resolvedProperty[this.propertyIndex]=buffer[offset];this.targetObject.needsUpdate=true;},function setValue_arrayElement_setMatrixWorldNeedsUpdate(buffer,offset){this.resolvedProperty[this.propertyIndex]=buffer[offset];this.targetObject.matrixWorldNeedsUpdate=true;}],[// HasToFromArray
  2325. function setValue_fromArray(buffer,offset){this.resolvedProperty.fromArray(buffer,offset);},function setValue_fromArray_setNeedsUpdate(buffer,offset){this.resolvedProperty.fromArray(buffer,offset);this.targetObject.needsUpdate=true;},function setValue_fromArray_setMatrixWorldNeedsUpdate(buffer,offset){this.resolvedProperty.fromArray(buffer,offset);this.targetObject.matrixWorldNeedsUpdate=true;}]],getValue:function getValue_unbound(targetArray,offset){this.bind();this.getValue(targetArray,offset);// Note: This class uses a State pattern on a per-method basis:
  2326. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  2327. // prototype version of these methods with one that represents
  2328. // the bound state. When the property is not found, the methods
  2329. // become no-ops.
  2330. },setValue:function getValue_unbound(sourceArray,offset){this.bind();this.setValue(sourceArray,offset);},// create getter / setter pair for a property in the scene graph
  2331. bind:function bind(){var targetObject=this.node;var parsedPath=this.parsedPath;var objectName=parsedPath.objectName;var propertyName=parsedPath.propertyName;var propertyIndex=parsedPath.propertyIndex;if(!targetObject){targetObject=PropertyBinding.findNode(this.rootNode,parsedPath.nodeName)||this.rootNode;this.node=targetObject;}// set fail state so we can just 'return' on error
  2332. this.getValue=this._getValue_unavailable;this.setValue=this._setValue_unavailable;// ensure there is a value node
  2333. if(!targetObject){console.error('THREE.PropertyBinding: Trying to update node for track: '+this.path+' but it wasn\'t found.');return;}if(objectName){var objectIndex=parsedPath.objectIndex;// special cases were we need to reach deeper into the hierarchy to get the face materials....
  2334. switch(objectName){case'materials':if(!targetObject.material){console.error('THREE.PropertyBinding: Can not bind to material as node does not have a material.',this);return;}if(!targetObject.material.materials){console.error('THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.',this);return;}targetObject=targetObject.material.materials;break;case'bones':if(!targetObject.skeleton){console.error('THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.',this);return;}// potential future optimization: skip this if propertyIndex is already an integer
  2335. // and convert the integer string to a true integer.
  2336. targetObject=targetObject.skeleton.bones;// support resolving morphTarget names into indices.
  2337. for(var _i344=0;_i344<targetObject.length;_i344++){if(targetObject[_i344].name===objectIndex){objectIndex=_i344;break;}}break;default:if(targetObject[objectName]===undefined){console.error('THREE.PropertyBinding: Can not bind to objectName of node undefined.',this);return;}targetObject=targetObject[objectName];}if(objectIndex!==undefined){if(targetObject[objectIndex]===undefined){console.error('THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.',this,targetObject);return;}targetObject=targetObject[objectIndex];}}// resolve property
  2338. var nodeProperty=targetObject[propertyName];if(nodeProperty===undefined){var nodeName=parsedPath.nodeName;console.error('THREE.PropertyBinding: Trying to update property for track: '+nodeName+'.'+propertyName+' but it wasn\'t found.',targetObject);return;}// determine versioning scheme
  2339. var versioning=this.Versioning.None;this.targetObject=targetObject;if(targetObject.needsUpdate!==undefined){// material
  2340. versioning=this.Versioning.NeedsUpdate;}else if(targetObject.matrixWorldNeedsUpdate!==undefined){// node transform
  2341. versioning=this.Versioning.MatrixWorldNeedsUpdate;}// determine how the property gets bound
  2342. var bindingType=this.BindingType.Direct;if(propertyIndex!==undefined){// access a sub element of the property array (only primitives are supported right now)
  2343. if(propertyName==='morphTargetInfluences'){// potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  2344. // support resolving morphTarget names into indices.
  2345. if(!targetObject.geometry){console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.',this);return;}if(targetObject.geometry.isBufferGeometry){if(!targetObject.geometry.morphAttributes){console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.',this);return;}if(targetObject.morphTargetDictionary[propertyIndex]!==undefined){propertyIndex=targetObject.morphTargetDictionary[propertyIndex];}}else {console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences on THREE.Geometry. Use THREE.BufferGeometry instead.',this);return;}}bindingType=this.BindingType.ArrayElement;this.resolvedProperty=nodeProperty;this.propertyIndex=propertyIndex;}else if(nodeProperty.fromArray!==undefined&&nodeProperty.toArray!==undefined){// must use copy for Object3D.Euler/Quaternion
  2346. bindingType=this.BindingType.HasFromToArray;this.resolvedProperty=nodeProperty;}else if(Array.isArray(nodeProperty)){bindingType=this.BindingType.EntireArray;this.resolvedProperty=nodeProperty;}else {this.propertyName=propertyName;}// select getter / setter
  2347. this.getValue=this.GetterByBindingType[bindingType];this.setValue=this.SetterByBindingTypeAndVersioning[bindingType][versioning];},unbind:function unbind(){this.node=null;// back to the prototype version of getValue / setValue
  2348. // note: avoiding to mutate the shape of 'this' via 'delete'
  2349. this.getValue=this._getValue_unbound;this.setValue=this._setValue_unbound;}});// DECLARE ALIAS AFTER assign prototype
  2350. Object.assign(PropertyBinding.prototype,{// initial state of these methods that calls 'bind'
  2351. _getValue_unbound:PropertyBinding.prototype.getValue,_setValue_unbound:PropertyBinding.prototype.setValue});/**
  2352. *
  2353. * A group of objects that receives a shared animation state.
  2354. *
  2355. * Usage:
  2356. *
  2357. * - Add objects you would otherwise pass as 'root' to the
  2358. * constructor or the .clipAction method of AnimationMixer.
  2359. *
  2360. * - Instead pass this object as 'root'.
  2361. *
  2362. * - You can also add and remove objects later when the mixer
  2363. * is running.
  2364. *
  2365. * Note:
  2366. *
  2367. * Objects of this class appear as one object to the mixer,
  2368. * so cache control of the individual objects must be done
  2369. * on the group.
  2370. *
  2371. * Limitation:
  2372. *
  2373. * - The animated properties must be compatible among the
  2374. * all objects in the group.
  2375. *
  2376. * - A single property can either be controlled through a
  2377. * target group or directly, but not both.
  2378. */function AnimationObjectGroup(){this.uuid=MathUtils.generateUUID();// cached objects followed by the active ones
  2379. this._objects=Array.prototype.slice.call(arguments);this.nCachedObjects_=0;// threshold
  2380. // note: read by PropertyBinding.Composite
  2381. var indices={};this._indicesByUUID=indices;// for bookkeeping
  2382. for(var _i345=0,n=arguments.length;_i345!==n;++_i345){indices[arguments[_i345].uuid]=_i345;}this._paths=[];// inside: string
  2383. this._parsedPaths=[];// inside: { we don't care, here }
  2384. this._bindings=[];// inside: Array< PropertyBinding >
  2385. this._bindingsIndicesByPath={};// inside: indices in these arrays
  2386. var scope=this;this.stats={objects:{get total(){return scope._objects.length;},get inUse(){return this.total-scope.nCachedObjects_;}},get bindingsPerObject(){return scope._bindings.length;}};}Object.assign(AnimationObjectGroup.prototype,{isAnimationObjectGroup:true,add:function add(){var objects=this._objects,indicesByUUID=this._indicesByUUID,paths=this._paths,parsedPaths=this._parsedPaths,bindings=this._bindings,nBindings=bindings.length;var knownObject=undefined,nObjects=objects.length,nCachedObjects=this.nCachedObjects_;for(var _i346=0,n=arguments.length;_i346!==n;++_i346){var object=arguments[_i346],uuid=object.uuid;var index=indicesByUUID[uuid];if(index===undefined){// unknown object -> add it to the ACTIVE region
  2387. index=nObjects++;indicesByUUID[uuid]=index;objects.push(object);// accounting is done, now do the same for all bindings
  2388. for(var j=0,m=nBindings;j!==m;++j){bindings[j].push(new PropertyBinding(object,paths[j],parsedPaths[j]));}}else if(index<nCachedObjects){knownObject=objects[index];// move existing object to the ACTIVE region
  2389. var firstActiveIndex=--nCachedObjects,lastCachedObject=objects[firstActiveIndex];indicesByUUID[lastCachedObject.uuid]=index;objects[index]=lastCachedObject;indicesByUUID[uuid]=firstActiveIndex;objects[firstActiveIndex]=object;// accounting is done, now do the same for all bindings
  2390. for(var _j25=0,_m2=nBindings;_j25!==_m2;++_j25){var bindingsForPath=bindings[_j25],lastCached=bindingsForPath[firstActiveIndex];var binding=bindingsForPath[index];bindingsForPath[index]=lastCached;if(binding===undefined){// since we do not bother to create new bindings
  2391. // for objects that are cached, the binding may
  2392. // or may not exist
  2393. binding=new PropertyBinding(object,paths[_j25],parsedPaths[_j25]);}bindingsForPath[firstActiveIndex]=binding;}}else if(objects[index]!==knownObject){console.error('THREE.AnimationObjectGroup: Different objects with the same UUID '+'detected. Clean the caches or recreate your infrastructure when reloading scenes.');}// else the object is already where we want it to be
  2394. }// for arguments
  2395. this.nCachedObjects_=nCachedObjects;},remove:function remove(){var objects=this._objects,indicesByUUID=this._indicesByUUID,bindings=this._bindings,nBindings=bindings.length;var nCachedObjects=this.nCachedObjects_;for(var _i347=0,n=arguments.length;_i347!==n;++_i347){var object=arguments[_i347],uuid=object.uuid,index=indicesByUUID[uuid];if(index!==undefined&&index>=nCachedObjects){// move existing object into the CACHED region
  2396. var lastCachedIndex=nCachedObjects++,firstActiveObject=objects[lastCachedIndex];indicesByUUID[firstActiveObject.uuid]=index;objects[index]=firstActiveObject;indicesByUUID[uuid]=lastCachedIndex;objects[lastCachedIndex]=object;// accounting is done, now do the same for all bindings
  2397. for(var j=0,m=nBindings;j!==m;++j){var bindingsForPath=bindings[j],firstActive=bindingsForPath[lastCachedIndex],binding=bindingsForPath[index];bindingsForPath[index]=firstActive;bindingsForPath[lastCachedIndex]=binding;}}}// for arguments
  2398. this.nCachedObjects_=nCachedObjects;},// remove & forget
  2399. uncache:function uncache(){var objects=this._objects,indicesByUUID=this._indicesByUUID,bindings=this._bindings,nBindings=bindings.length;var nCachedObjects=this.nCachedObjects_,nObjects=objects.length;for(var _i348=0,n=arguments.length;_i348!==n;++_i348){var object=arguments[_i348],uuid=object.uuid,index=indicesByUUID[uuid];if(index!==undefined){delete indicesByUUID[uuid];if(index<nCachedObjects){// object is cached, shrink the CACHED region
  2400. var firstActiveIndex=--nCachedObjects,lastCachedObject=objects[firstActiveIndex],lastIndex=--nObjects,lastObject=objects[lastIndex];// last cached object takes this object's place
  2401. indicesByUUID[lastCachedObject.uuid]=index;objects[index]=lastCachedObject;// last object goes to the activated slot and pop
  2402. indicesByUUID[lastObject.uuid]=firstActiveIndex;objects[firstActiveIndex]=lastObject;objects.pop();// accounting is done, now do the same for all bindings
  2403. for(var j=0,m=nBindings;j!==m;++j){var bindingsForPath=bindings[j],lastCached=bindingsForPath[firstActiveIndex],last=bindingsForPath[lastIndex];bindingsForPath[index]=lastCached;bindingsForPath[firstActiveIndex]=last;bindingsForPath.pop();}}else {// object is active, just swap with the last and pop
  2404. var _lastIndex=--nObjects,_lastObject=objects[_lastIndex];if(_lastIndex>0){indicesByUUID[_lastObject.uuid]=index;}objects[index]=_lastObject;objects.pop();// accounting is done, now do the same for all bindings
  2405. for(var _j26=0,_m3=nBindings;_j26!==_m3;++_j26){var _bindingsForPath=bindings[_j26];_bindingsForPath[index]=_bindingsForPath[_lastIndex];_bindingsForPath.pop();}}// cached or active
  2406. }// if object is known
  2407. }// for arguments
  2408. this.nCachedObjects_=nCachedObjects;},// Internal interface used by befriended PropertyBinding.Composite:
  2409. subscribe_:function subscribe_(path,parsedPath){// returns an array of bindings for the given path that is changed
  2410. // according to the contained objects in the group
  2411. var indicesByPath=this._bindingsIndicesByPath;var index=indicesByPath[path];var bindings=this._bindings;if(index!==undefined)return bindings[index];var paths=this._paths,parsedPaths=this._parsedPaths,objects=this._objects,nObjects=objects.length,nCachedObjects=this.nCachedObjects_,bindingsForPath=new Array(nObjects);index=bindings.length;indicesByPath[path]=index;paths.push(path);parsedPaths.push(parsedPath);bindings.push(bindingsForPath);for(var _i349=nCachedObjects,n=objects.length;_i349!==n;++_i349){var object=objects[_i349];bindingsForPath[_i349]=new PropertyBinding(object,path,parsedPath);}return bindingsForPath;},unsubscribe_:function unsubscribe_(path){// tells the group to forget about a property path and no longer
  2412. // update the array previously obtained with 'subscribe_'
  2413. var indicesByPath=this._bindingsIndicesByPath,index=indicesByPath[path];if(index!==undefined){var paths=this._paths,parsedPaths=this._parsedPaths,bindings=this._bindings,lastBindingsIndex=bindings.length-1,lastBindings=bindings[lastBindingsIndex],lastBindingsPath=path[lastBindingsIndex];indicesByPath[lastBindingsPath]=index;bindings[index]=lastBindings;bindings.pop();parsedPaths[index]=parsedPaths[lastBindingsIndex];parsedPaths.pop();paths[index]=paths[lastBindingsIndex];paths.pop();}}});class AnimationAction{constructor(mixer,clip){var localRoot=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;var blendMode=arguments.length>3&&arguments[3]!==undefined?arguments[3]:clip.blendMode;this._mixer=mixer;this._clip=clip;this._localRoot=localRoot;this.blendMode=blendMode;var tracks=clip.tracks,nTracks=tracks.length,interpolants=new Array(nTracks);var interpolantSettings={endingStart:ZeroCurvatureEnding,endingEnd:ZeroCurvatureEnding};for(var _i350=0;_i350!==nTracks;++_i350){var interpolant=tracks[_i350].createInterpolant(null);interpolants[_i350]=interpolant;interpolant.settings=interpolantSettings;}this._interpolantSettings=interpolantSettings;this._interpolants=interpolants;// bound by the mixer
  2414. // inside: PropertyMixer (managed by the mixer)
  2415. this._propertyBindings=new Array(nTracks);this._cacheIndex=null;// for the memory manager
  2416. this._byClipCacheIndex=null;// for the memory manager
  2417. this._timeScaleInterpolant=null;this._weightInterpolant=null;this.loop=LoopRepeat;this._loopCount=-1;// global mixer time when the action is to be started
  2418. // it's set back to 'null' upon start of the action
  2419. this._startTime=null;// scaled local time of the action
  2420. // gets clamped or wrapped to 0..clip.duration according to loop
  2421. this.time=0;this.timeScale=1;this._effectiveTimeScale=1;this.weight=1;this._effectiveWeight=1;this.repetitions=Infinity;// no. of repetitions when looping
  2422. this.paused=false;// true -> zero effective time scale
  2423. this.enabled=true;// false -> zero effective weight
  2424. this.clampWhenFinished=false;// keep feeding the last frame?
  2425. this.zeroSlopeAtStart=true;// for smooth interpolation w/o separate
  2426. this.zeroSlopeAtEnd=true;// clips for start, loop and end
  2427. }// State & Scheduling
  2428. play(){this._mixer._activateAction(this);return this;}stop(){this._mixer._deactivateAction(this);return this.reset();}reset(){this.paused=false;this.enabled=true;this.time=0;// restart clip
  2429. this._loopCount=-1;// forget previous loops
  2430. this._startTime=null;// forget scheduling
  2431. return this.stopFading().stopWarping();}isRunning(){return this.enabled&&!this.paused&&this.timeScale!==0&&this._startTime===null&&this._mixer._isActiveAction(this);}// return true when play has been called
  2432. isScheduled(){return this._mixer._isActiveAction(this);}startAt(time){this._startTime=time;return this;}setLoop(mode,repetitions){this.loop=mode;this.repetitions=repetitions;return this;}// Weight
  2433. // set the weight stopping any scheduled fading
  2434. // although .enabled = false yields an effective weight of zero, this
  2435. // method does *not* change .enabled, because it would be confusing
  2436. setEffectiveWeight(weight){this.weight=weight;// note: same logic as when updated at runtime
  2437. this._effectiveWeight=this.enabled?weight:0;return this.stopFading();}// return the weight considering fading and .enabled
  2438. getEffectiveWeight(){return this._effectiveWeight;}fadeIn(duration){return this._scheduleFading(duration,0,1);}fadeOut(duration){return this._scheduleFading(duration,1,0);}crossFadeFrom(fadeOutAction,duration,warp){fadeOutAction.fadeOut(duration);this.fadeIn(duration);if(warp){var fadeInDuration=this._clip.duration,fadeOutDuration=fadeOutAction._clip.duration,startEndRatio=fadeOutDuration/fadeInDuration,endStartRatio=fadeInDuration/fadeOutDuration;fadeOutAction.warp(1.0,startEndRatio,duration);this.warp(endStartRatio,1.0,duration);}return this;}crossFadeTo(fadeInAction,duration,warp){return fadeInAction.crossFadeFrom(this,duration,warp);}stopFading(){var weightInterpolant=this._weightInterpolant;if(weightInterpolant!==null){this._weightInterpolant=null;this._mixer._takeBackControlInterpolant(weightInterpolant);}return this;}// Time Scale Control
  2439. // set the time scale stopping any scheduled warping
  2440. // although .paused = true yields an effective time scale of zero, this
  2441. // method does *not* change .paused, because it would be confusing
  2442. setEffectiveTimeScale(timeScale){this.timeScale=timeScale;this._effectiveTimeScale=this.paused?0:timeScale;return this.stopWarping();}// return the time scale considering warping and .paused
  2443. getEffectiveTimeScale(){return this._effectiveTimeScale;}setDuration(duration){this.timeScale=this._clip.duration/duration;return this.stopWarping();}syncWith(action){this.time=action.time;this.timeScale=action.timeScale;return this.stopWarping();}halt(duration){return this.warp(this._effectiveTimeScale,0,duration);}warp(startTimeScale,endTimeScale,duration){var mixer=this._mixer,now=mixer.time,timeScale=this.timeScale;var interpolant=this._timeScaleInterpolant;if(interpolant===null){interpolant=mixer._lendControlInterpolant();this._timeScaleInterpolant=interpolant;}var times=interpolant.parameterPositions,values=interpolant.sampleValues;times[0]=now;times[1]=now+duration;values[0]=startTimeScale/timeScale;values[1]=endTimeScale/timeScale;return this;}stopWarping(){var timeScaleInterpolant=this._timeScaleInterpolant;if(timeScaleInterpolant!==null){this._timeScaleInterpolant=null;this._mixer._takeBackControlInterpolant(timeScaleInterpolant);}return this;}// Object Accessors
  2444. getMixer(){return this._mixer;}getClip(){return this._clip;}getRoot(){return this._localRoot||this._mixer._root;}// Interna
  2445. _update(time,deltaTime,timeDirection,accuIndex){// called by the mixer
  2446. if(!this.enabled){// call ._updateWeight() to update ._effectiveWeight
  2447. this._updateWeight(time);return;}var startTime=this._startTime;if(startTime!==null){// check for scheduled start of action
  2448. var timeRunning=(time-startTime)*timeDirection;if(timeRunning<0||timeDirection===0){return;// yet to come / don't decide when delta = 0
  2449. }// start
  2450. this._startTime=null;// unschedule
  2451. deltaTime=timeDirection*timeRunning;}// apply time scale and advance time
  2452. deltaTime*=this._updateTimeScale(time);var clipTime=this._updateTime(deltaTime);// note: _updateTime may disable the action resulting in
  2453. // an effective weight of 0
  2454. var weight=this._updateWeight(time);if(weight>0){var interpolants=this._interpolants;var propertyMixers=this._propertyBindings;switch(this.blendMode){case AdditiveAnimationBlendMode:for(var j=0,m=interpolants.length;j!==m;++j){interpolants[j].evaluate(clipTime);propertyMixers[j].accumulateAdditive(weight);}break;case NormalAnimationBlendMode:default:for(var _j27=0,_m4=interpolants.length;_j27!==_m4;++_j27){interpolants[_j27].evaluate(clipTime);propertyMixers[_j27].accumulate(accuIndex,weight);}}}}_updateWeight(time){var weight=0;if(this.enabled){weight=this.weight;var interpolant=this._weightInterpolant;if(interpolant!==null){var interpolantValue=interpolant.evaluate(time)[0];weight*=interpolantValue;if(time>interpolant.parameterPositions[1]){this.stopFading();if(interpolantValue===0){// faded out, disable
  2455. this.enabled=false;}}}}this._effectiveWeight=weight;return weight;}_updateTimeScale(time){var timeScale=0;if(!this.paused){timeScale=this.timeScale;var interpolant=this._timeScaleInterpolant;if(interpolant!==null){var interpolantValue=interpolant.evaluate(time)[0];timeScale*=interpolantValue;if(time>interpolant.parameterPositions[1]){this.stopWarping();if(timeScale===0){// motion has halted, pause
  2456. this.paused=true;}else {// warp done - apply final time scale
  2457. this.timeScale=timeScale;}}}}this._effectiveTimeScale=timeScale;return timeScale;}_updateTime(deltaTime){var duration=this._clip.duration;var loop=this.loop;var time=this.time+deltaTime;var loopCount=this._loopCount;var pingPong=loop===LoopPingPong;if(deltaTime===0){if(loopCount===-1)return time;return pingPong&&(loopCount&1)===1?duration-time:time;}if(loop===LoopOnce){if(loopCount===-1){// just started
  2458. this._loopCount=0;this._setEndings(true,true,false);}handle_stop:{if(time>=duration){time=duration;}else if(time<0){time=0;}else {this.time=time;break handle_stop;}if(this.clampWhenFinished)this.paused=true;else this.enabled=false;this.time=time;this._mixer.dispatchEvent({type:'finished',action:this,direction:deltaTime<0?-1:1});}}else {// repetitive Repeat or PingPong
  2459. if(loopCount===-1){// just started
  2460. if(deltaTime>=0){loopCount=0;this._setEndings(true,this.repetitions===0,pingPong);}else {// when looping in reverse direction, the initial
  2461. // transition through zero counts as a repetition,
  2462. // so leave loopCount at -1
  2463. this._setEndings(this.repetitions===0,true,pingPong);}}if(time>=duration||time<0){// wrap around
  2464. var loopDelta=Math.floor(time/duration);// signed
  2465. time-=duration*loopDelta;loopCount+=Math.abs(loopDelta);var pending=this.repetitions-loopCount;if(pending<=0){// have to stop (switch state, clamp time, fire event)
  2466. if(this.clampWhenFinished)this.paused=true;else this.enabled=false;time=deltaTime>0?duration:0;this.time=time;this._mixer.dispatchEvent({type:'finished',action:this,direction:deltaTime>0?1:-1});}else {// keep running
  2467. if(pending===1){// entering the last round
  2468. var atStart=deltaTime<0;this._setEndings(atStart,!atStart,pingPong);}else {this._setEndings(false,false,pingPong);}this._loopCount=loopCount;this.time=time;this._mixer.dispatchEvent({type:'loop',action:this,loopDelta:loopDelta});}}else {this.time=time;}if(pingPong&&(loopCount&1)===1){// invert time for the "pong round"
  2469. return duration-time;}}return time;}_setEndings(atStart,atEnd,pingPong){var settings=this._interpolantSettings;if(pingPong){settings.endingStart=ZeroSlopeEnding;settings.endingEnd=ZeroSlopeEnding;}else {// assuming for LoopOnce atStart == atEnd == true
  2470. if(atStart){settings.endingStart=this.zeroSlopeAtStart?ZeroSlopeEnding:ZeroCurvatureEnding;}else {settings.endingStart=WrapAroundEnding;}if(atEnd){settings.endingEnd=this.zeroSlopeAtEnd?ZeroSlopeEnding:ZeroCurvatureEnding;}else {settings.endingEnd=WrapAroundEnding;}}}_scheduleFading(duration,weightNow,weightThen){var mixer=this._mixer,now=mixer.time;var interpolant=this._weightInterpolant;if(interpolant===null){interpolant=mixer._lendControlInterpolant();this._weightInterpolant=interpolant;}var times=interpolant.parameterPositions,values=interpolant.sampleValues;times[0]=now;values[0]=weightNow;times[1]=now+duration;values[1]=weightThen;return this;}}function AnimationMixer(root){this._root=root;this._initMemoryManager();this._accuIndex=0;this.time=0;this.timeScale=1.0;}AnimationMixer.prototype=Object.assign(Object.create(EventDispatcher.prototype),{constructor:AnimationMixer,_bindAction:function _bindAction(action,prototypeAction){var root=action._localRoot||this._root,tracks=action._clip.tracks,nTracks=tracks.length,bindings=action._propertyBindings,interpolants=action._interpolants,rootUuid=root.uuid,bindingsByRoot=this._bindingsByRootAndName;var bindingsByName=bindingsByRoot[rootUuid];if(bindingsByName===undefined){bindingsByName={};bindingsByRoot[rootUuid]=bindingsByName;}for(var _i351=0;_i351!==nTracks;++_i351){var track=tracks[_i351],trackName=track.name;var binding=bindingsByName[trackName];if(binding!==undefined){bindings[_i351]=binding;}else {binding=bindings[_i351];if(binding!==undefined){// existing binding, make sure the cache knows
  2471. if(binding._cacheIndex===null){++binding.referenceCount;this._addInactiveBinding(binding,rootUuid,trackName);}continue;}var path=prototypeAction&&prototypeAction._propertyBindings[_i351].binding.parsedPath;binding=new PropertyMixer(PropertyBinding.create(root,trackName,path),track.ValueTypeName,track.getValueSize());++binding.referenceCount;this._addInactiveBinding(binding,rootUuid,trackName);bindings[_i351]=binding;}interpolants[_i351].resultBuffer=binding.buffer;}},_activateAction:function _activateAction(action){if(!this._isActiveAction(action)){if(action._cacheIndex===null){// this action has been forgotten by the cache, but the user
  2472. // appears to be still using it -> rebind
  2473. var rootUuid=(action._localRoot||this._root).uuid,clipUuid=action._clip.uuid,actionsForClip=this._actionsByClip[clipUuid];this._bindAction(action,actionsForClip&&actionsForClip.knownActions[0]);this._addInactiveAction(action,clipUuid,rootUuid);}var bindings=action._propertyBindings;// increment reference counts / sort out state
  2474. for(var _i352=0,n=bindings.length;_i352!==n;++_i352){var binding=bindings[_i352];if(binding.useCount++===0){this._lendBinding(binding);binding.saveOriginalState();}}this._lendAction(action);}},_deactivateAction:function _deactivateAction(action){if(this._isActiveAction(action)){var bindings=action._propertyBindings;// decrement reference counts / sort out state
  2475. for(var _i353=0,n=bindings.length;_i353!==n;++_i353){var binding=bindings[_i353];if(--binding.useCount===0){binding.restoreOriginalState();this._takeBackBinding(binding);}}this._takeBackAction(action);}},// Memory manager
  2476. _initMemoryManager:function _initMemoryManager(){this._actions=[];// 'nActiveActions' followed by inactive ones
  2477. this._nActiveActions=0;this._actionsByClip={};// inside:
  2478. // {
  2479. // knownActions: Array< AnimationAction > - used as prototypes
  2480. // actionByRoot: AnimationAction - lookup
  2481. // }
  2482. this._bindings=[];// 'nActiveBindings' followed by inactive ones
  2483. this._nActiveBindings=0;this._bindingsByRootAndName={};// inside: Map< name, PropertyMixer >
  2484. this._controlInterpolants=[];// same game as above
  2485. this._nActiveControlInterpolants=0;var scope=this;this.stats={actions:{get total(){return scope._actions.length;},get inUse(){return scope._nActiveActions;}},bindings:{get total(){return scope._bindings.length;},get inUse(){return scope._nActiveBindings;}},controlInterpolants:{get total(){return scope._controlInterpolants.length;},get inUse(){return scope._nActiveControlInterpolants;}}};},// Memory management for AnimationAction objects
  2486. _isActiveAction:function _isActiveAction(action){var index=action._cacheIndex;return index!==null&&index<this._nActiveActions;},_addInactiveAction:function _addInactiveAction(action,clipUuid,rootUuid){var actions=this._actions,actionsByClip=this._actionsByClip;var actionsForClip=actionsByClip[clipUuid];if(actionsForClip===undefined){actionsForClip={knownActions:[action],actionByRoot:{}};action._byClipCacheIndex=0;actionsByClip[clipUuid]=actionsForClip;}else {var knownActions=actionsForClip.knownActions;action._byClipCacheIndex=knownActions.length;knownActions.push(action);}action._cacheIndex=actions.length;actions.push(action);actionsForClip.actionByRoot[rootUuid]=action;},_removeInactiveAction:function _removeInactiveAction(action){var actions=this._actions,lastInactiveAction=actions[actions.length-1],cacheIndex=action._cacheIndex;lastInactiveAction._cacheIndex=cacheIndex;actions[cacheIndex]=lastInactiveAction;actions.pop();action._cacheIndex=null;var clipUuid=action._clip.uuid,actionsByClip=this._actionsByClip,actionsForClip=actionsByClip[clipUuid],knownActionsForClip=actionsForClip.knownActions,lastKnownAction=knownActionsForClip[knownActionsForClip.length-1],byClipCacheIndex=action._byClipCacheIndex;lastKnownAction._byClipCacheIndex=byClipCacheIndex;knownActionsForClip[byClipCacheIndex]=lastKnownAction;knownActionsForClip.pop();action._byClipCacheIndex=null;var actionByRoot=actionsForClip.actionByRoot,rootUuid=(action._localRoot||this._root).uuid;delete actionByRoot[rootUuid];if(knownActionsForClip.length===0){delete actionsByClip[clipUuid];}this._removeInactiveBindingsForAction(action);},_removeInactiveBindingsForAction:function _removeInactiveBindingsForAction(action){var bindings=action._propertyBindings;for(var _i354=0,n=bindings.length;_i354!==n;++_i354){var binding=bindings[_i354];if(--binding.referenceCount===0){this._removeInactiveBinding(binding);}}},_lendAction:function _lendAction(action){// [ active actions | inactive actions ]
  2487. // [ active actions >| inactive actions ]
  2488. // s a
  2489. // <-swap->
  2490. // a s
  2491. var actions=this._actions,prevIndex=action._cacheIndex,lastActiveIndex=this._nActiveActions++,firstInactiveAction=actions[lastActiveIndex];action._cacheIndex=lastActiveIndex;actions[lastActiveIndex]=action;firstInactiveAction._cacheIndex=prevIndex;actions[prevIndex]=firstInactiveAction;},_takeBackAction:function _takeBackAction(action){// [ active actions | inactive actions ]
  2492. // [ active actions |< inactive actions ]
  2493. // a s
  2494. // <-swap->
  2495. // s a
  2496. var actions=this._actions,prevIndex=action._cacheIndex,firstInactiveIndex=--this._nActiveActions,lastActiveAction=actions[firstInactiveIndex];action._cacheIndex=firstInactiveIndex;actions[firstInactiveIndex]=action;lastActiveAction._cacheIndex=prevIndex;actions[prevIndex]=lastActiveAction;},// Memory management for PropertyMixer objects
  2497. _addInactiveBinding:function _addInactiveBinding(binding,rootUuid,trackName){var bindingsByRoot=this._bindingsByRootAndName,bindings=this._bindings;var bindingByName=bindingsByRoot[rootUuid];if(bindingByName===undefined){bindingByName={};bindingsByRoot[rootUuid]=bindingByName;}bindingByName[trackName]=binding;binding._cacheIndex=bindings.length;bindings.push(binding);},_removeInactiveBinding:function _removeInactiveBinding(binding){var bindings=this._bindings,propBinding=binding.binding,rootUuid=propBinding.rootNode.uuid,trackName=propBinding.path,bindingsByRoot=this._bindingsByRootAndName,bindingByName=bindingsByRoot[rootUuid],lastInactiveBinding=bindings[bindings.length-1],cacheIndex=binding._cacheIndex;lastInactiveBinding._cacheIndex=cacheIndex;bindings[cacheIndex]=lastInactiveBinding;bindings.pop();delete bindingByName[trackName];if(Object.keys(bindingByName).length===0){delete bindingsByRoot[rootUuid];}},_lendBinding:function _lendBinding(binding){var bindings=this._bindings,prevIndex=binding._cacheIndex,lastActiveIndex=this._nActiveBindings++,firstInactiveBinding=bindings[lastActiveIndex];binding._cacheIndex=lastActiveIndex;bindings[lastActiveIndex]=binding;firstInactiveBinding._cacheIndex=prevIndex;bindings[prevIndex]=firstInactiveBinding;},_takeBackBinding:function _takeBackBinding(binding){var bindings=this._bindings,prevIndex=binding._cacheIndex,firstInactiveIndex=--this._nActiveBindings,lastActiveBinding=bindings[firstInactiveIndex];binding._cacheIndex=firstInactiveIndex;bindings[firstInactiveIndex]=binding;lastActiveBinding._cacheIndex=prevIndex;bindings[prevIndex]=lastActiveBinding;},// Memory management of Interpolants for weight and time scale
  2498. _lendControlInterpolant:function _lendControlInterpolant(){var interpolants=this._controlInterpolants,lastActiveIndex=this._nActiveControlInterpolants++;var interpolant=interpolants[lastActiveIndex];if(interpolant===undefined){interpolant=new LinearInterpolant(new Float32Array(2),new Float32Array(2),1,this._controlInterpolantsResultBuffer);interpolant.__cacheIndex=lastActiveIndex;interpolants[lastActiveIndex]=interpolant;}return interpolant;},_takeBackControlInterpolant:function _takeBackControlInterpolant(interpolant){var interpolants=this._controlInterpolants,prevIndex=interpolant.__cacheIndex,firstInactiveIndex=--this._nActiveControlInterpolants,lastActiveInterpolant=interpolants[firstInactiveIndex];interpolant.__cacheIndex=firstInactiveIndex;interpolants[firstInactiveIndex]=interpolant;lastActiveInterpolant.__cacheIndex=prevIndex;interpolants[prevIndex]=lastActiveInterpolant;},_controlInterpolantsResultBuffer:new Float32Array(1),// return an action for a clip optionally using a custom root target
  2499. // object (this method allocates a lot of dynamic memory in case a
  2500. // previously unknown clip/root combination is specified)
  2501. clipAction:function clipAction(clip,optionalRoot,blendMode){var root=optionalRoot||this._root,rootUuid=root.uuid;var clipObject=typeof clip==='string'?AnimationClip.findByName(root,clip):clip;var clipUuid=clipObject!==null?clipObject.uuid:clip;var actionsForClip=this._actionsByClip[clipUuid];var prototypeAction=null;if(blendMode===undefined){if(clipObject!==null){blendMode=clipObject.blendMode;}else {blendMode=NormalAnimationBlendMode;}}if(actionsForClip!==undefined){var existingAction=actionsForClip.actionByRoot[rootUuid];if(existingAction!==undefined&&existingAction.blendMode===blendMode){return existingAction;}// we know the clip, so we don't have to parse all
  2502. // the bindings again but can just copy
  2503. prototypeAction=actionsForClip.knownActions[0];// also, take the clip from the prototype action
  2504. if(clipObject===null)clipObject=prototypeAction._clip;}// clip must be known when specified via string
  2505. if(clipObject===null)return null;// allocate all resources required to run it
  2506. var newAction=new AnimationAction(this,clipObject,optionalRoot,blendMode);this._bindAction(newAction,prototypeAction);// and make the action known to the memory manager
  2507. this._addInactiveAction(newAction,clipUuid,rootUuid);return newAction;},// get an existing action
  2508. existingAction:function existingAction(clip,optionalRoot){var root=optionalRoot||this._root,rootUuid=root.uuid,clipObject=typeof clip==='string'?AnimationClip.findByName(root,clip):clip,clipUuid=clipObject?clipObject.uuid:clip,actionsForClip=this._actionsByClip[clipUuid];if(actionsForClip!==undefined){return actionsForClip.actionByRoot[rootUuid]||null;}return null;},// deactivates all previously scheduled actions
  2509. stopAllAction:function stopAllAction(){var actions=this._actions,nActions=this._nActiveActions;for(var _i355=nActions-1;_i355>=0;--_i355){actions[_i355].stop();}return this;},// advance the time and update apply the animation
  2510. update:function update(deltaTime){deltaTime*=this.timeScale;var actions=this._actions,nActions=this._nActiveActions,time=this.time+=deltaTime,timeDirection=Math.sign(deltaTime),accuIndex=this._accuIndex^=1;// run active actions
  2511. for(var _i356=0;_i356!==nActions;++_i356){var action=actions[_i356];action._update(time,deltaTime,timeDirection,accuIndex);}// update scene graph
  2512. var bindings=this._bindings,nBindings=this._nActiveBindings;for(var _i357=0;_i357!==nBindings;++_i357){bindings[_i357].apply(accuIndex);}return this;},// Allows you to seek to a specific time in an animation.
  2513. setTime:function setTime(timeInSeconds){this.time=0;// Zero out time attribute for AnimationMixer object;
  2514. for(var _i358=0;_i358<this._actions.length;_i358++){this._actions[_i358].time=0;// Zero out time attribute for all associated AnimationAction objects.
  2515. }return this.update(timeInSeconds);// Update used to set exact time. Returns "this" AnimationMixer object.
  2516. },// return this mixer's root target object
  2517. getRoot:function getRoot(){return this._root;},// free all resources specific to a particular clip
  2518. uncacheClip:function uncacheClip(clip){var actions=this._actions,clipUuid=clip.uuid,actionsByClip=this._actionsByClip,actionsForClip=actionsByClip[clipUuid];if(actionsForClip!==undefined){// note: just calling _removeInactiveAction would mess up the
  2519. // iteration state and also require updating the state we can
  2520. // just throw away
  2521. var actionsToRemove=actionsForClip.knownActions;for(var _i359=0,n=actionsToRemove.length;_i359!==n;++_i359){var action=actionsToRemove[_i359];this._deactivateAction(action);var cacheIndex=action._cacheIndex,lastInactiveAction=actions[actions.length-1];action._cacheIndex=null;action._byClipCacheIndex=null;lastInactiveAction._cacheIndex=cacheIndex;actions[cacheIndex]=lastInactiveAction;actions.pop();this._removeInactiveBindingsForAction(action);}delete actionsByClip[clipUuid];}},// free all resources specific to a particular root target object
  2522. uncacheRoot:function uncacheRoot(root){var rootUuid=root.uuid,actionsByClip=this._actionsByClip;for(var clipUuid in actionsByClip){var actionByRoot=actionsByClip[clipUuid].actionByRoot,action=actionByRoot[rootUuid];if(action!==undefined){this._deactivateAction(action);this._removeInactiveAction(action);}}var bindingsByRoot=this._bindingsByRootAndName,bindingByName=bindingsByRoot[rootUuid];if(bindingByName!==undefined){for(var trackName in bindingByName){var binding=bindingByName[trackName];binding.restoreOriginalState();this._removeInactiveBinding(binding);}}},// remove a targeted clip from the cache
  2523. uncacheAction:function uncacheAction(clip,optionalRoot){var action=this.existingAction(clip,optionalRoot);if(action!==null){this._deactivateAction(action);this._removeInactiveAction(action);}}});class Uniform{constructor(value){if(typeof value==='string'){console.warn('THREE.Uniform: Type parameter is no longer needed.');value=arguments[1];}this.value=value;}clone(){return new Uniform(this.value.clone===undefined?this.value:this.value.clone());}}function InstancedInterleavedBuffer(array,stride,meshPerAttribute){InterleavedBuffer.call(this,array,stride);this.meshPerAttribute=meshPerAttribute||1;}InstancedInterleavedBuffer.prototype=Object.assign(Object.create(InterleavedBuffer.prototype),{constructor:InstancedInterleavedBuffer,isInstancedInterleavedBuffer:true,copy:function copy(source){InterleavedBuffer.prototype.copy.call(this,source);this.meshPerAttribute=source.meshPerAttribute;return this;},clone:function clone(data){var ib=InterleavedBuffer.prototype.clone.call(this,data);ib.meshPerAttribute=this.meshPerAttribute;return ib;},toJSON:function toJSON(data){var json=InterleavedBuffer.prototype.toJSON.call(this,data);json.isInstancedInterleavedBuffer=true;json.meshPerAttribute=this.meshPerAttribute;return json;}});function GLBufferAttribute(buffer,type,itemSize,elementSize,count){this.buffer=buffer;this.type=type;this.itemSize=itemSize;this.elementSize=elementSize;this.count=count;this.version=0;}Object.defineProperty(GLBufferAttribute.prototype,'needsUpdate',{set:function set(value){if(value===true)this.version++;}});Object.assign(GLBufferAttribute.prototype,{isGLBufferAttribute:true,setBuffer:function setBuffer(buffer){this.buffer=buffer;return this;},setType:function setType(type,elementSize){this.type=type;this.elementSize=elementSize;return this;},setItemSize:function setItemSize(itemSize){this.itemSize=itemSize;return this;},setCount:function setCount(count){this.count=count;return this;}});function Raycaster(origin,direction,near,far){this.ray=new Ray(origin,direction);// direction is assumed to be normalized (for accurate distance calculations)
  2524. this.near=near||0;this.far=far||Infinity;this.camera=null;this.layers=new Layers();this.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:1},Sprite:{}};Object.defineProperties(this.params,{PointCloud:{get:function get(){console.warn('THREE.Raycaster: params.PointCloud has been renamed to params.Points.');return this.Points;}}});}function ascSort(a,b){return a.distance-b.distance;}function _intersectObject(object,raycaster,intersects,recursive){if(object.layers.test(raycaster.layers)){object.raycast(raycaster,intersects);}if(recursive===true){var children=object.children;for(var _i360=0,l=children.length;_i360<l;_i360++){_intersectObject(children[_i360],raycaster,intersects,true);}}}Object.assign(Raycaster.prototype,{set:function set(origin,direction){// direction is assumed to be normalized (for accurate distance calculations)
  2525. this.ray.set(origin,direction);},setFromCamera:function setFromCamera(coords,camera){if(camera&&camera.isPerspectiveCamera){this.ray.origin.setFromMatrixPosition(camera.matrixWorld);this.ray.direction.set(coords.x,coords.y,0.5).unproject(camera).sub(this.ray.origin).normalize();this.camera=camera;}else if(camera&&camera.isOrthographicCamera){this.ray.origin.set(coords.x,coords.y,(camera.near+camera.far)/(camera.near-camera.far)).unproject(camera);// set origin in plane of camera
  2526. this.ray.direction.set(0,0,-1).transformDirection(camera.matrixWorld);this.camera=camera;}else {console.error('THREE.Raycaster: Unsupported camera type: '+camera.type);}},intersectObject:function intersectObject(object,recursive,optionalTarget){var intersects=optionalTarget||[];_intersectObject(object,this,intersects,recursive);intersects.sort(ascSort);return intersects;},intersectObjects:function intersectObjects(objects,recursive,optionalTarget){var intersects=optionalTarget||[];if(Array.isArray(objects)===false){console.warn('THREE.Raycaster.intersectObjects: objects is not an Array.');return intersects;}for(var _i361=0,l=objects.length;_i361<l;_i361++){_intersectObject(objects[_i361],this,intersects,recursive);}intersects.sort(ascSort);return intersects;}});/**
  2527. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  2528. *
  2529. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  2530. * The azimuthal angle (theta) is measured from the positive z-axis.
  2531. */class Spherical{constructor(){var radius=arguments.length>0&&arguments[0]!==undefined?arguments[0]:1;var phi=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var theta=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0;this.radius=radius;this.phi=phi;// polar angle
  2532. this.theta=theta;// azimuthal angle
  2533. return this;}set(radius,phi,theta){this.radius=radius;this.phi=phi;this.theta=theta;return this;}clone(){return new this.constructor().copy(this);}copy(other){this.radius=other.radius;this.phi=other.phi;this.theta=other.theta;return this;}// restrict phi to be betwee EPS and PI-EPS
  2534. makeSafe(){var EPS=0.000001;this.phi=Math.max(EPS,Math.min(Math.PI-EPS,this.phi));return this;}setFromVector3(v){return this.setFromCartesianCoords(v.x,v.y,v.z);}setFromCartesianCoords(x,y,z){this.radius=Math.sqrt(x*x+y*y+z*z);if(this.radius===0){this.theta=0;this.phi=0;}else {this.theta=Math.atan2(x,z);this.phi=Math.acos(MathUtils.clamp(y/this.radius,-1,1));}return this;}}/**
  2535. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  2536. */class Cylindrical{constructor(radius,theta,y){this.radius=radius!==undefined?radius:1.0;// distance from the origin to a point in the x-z plane
  2537. this.theta=theta!==undefined?theta:0;// counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  2538. this.y=y!==undefined?y:0;// height above the x-z plane
  2539. return this;}set(radius,theta,y){this.radius=radius;this.theta=theta;this.y=y;return this;}clone(){return new this.constructor().copy(this);}copy(other){this.radius=other.radius;this.theta=other.theta;this.y=other.y;return this;}setFromVector3(v){return this.setFromCartesianCoords(v.x,v.y,v.z);}setFromCartesianCoords(x,y,z){this.radius=Math.sqrt(x*x+z*z);this.theta=Math.atan2(x,z);this.y=y;return this;}}var _vector$8=/*@__PURE__*/new Vector2();class Box2{constructor(min,max){Object.defineProperty(this,'isBox2',{value:true});this.min=min!==undefined?min:new Vector2(+Infinity,+Infinity);this.max=max!==undefined?max:new Vector2(-Infinity,-Infinity);}set(min,max){this.min.copy(min);this.max.copy(max);return this;}setFromPoints(points){this.makeEmpty();for(var _i362=0,il=points.length;_i362<il;_i362++){this.expandByPoint(points[_i362]);}return this;}setFromCenterAndSize(center,size){var halfSize=_vector$8.copy(size).multiplyScalar(0.5);this.min.copy(center).sub(halfSize);this.max.copy(center).add(halfSize);return this;}clone(){return new this.constructor().copy(this);}copy(box){this.min.copy(box.min);this.max.copy(box.max);return this;}makeEmpty(){this.min.x=this.min.y=+Infinity;this.max.x=this.max.y=-Infinity;return this;}isEmpty(){// this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2540. return this.max.x<this.min.x||this.max.y<this.min.y;}getCenter(target){if(target===undefined){console.warn('THREE.Box2: .getCenter() target is now required');target=new Vector2();}return this.isEmpty()?target.set(0,0):target.addVectors(this.min,this.max).multiplyScalar(0.5);}getSize(target){if(target===undefined){console.warn('THREE.Box2: .getSize() target is now required');target=new Vector2();}return this.isEmpty()?target.set(0,0):target.subVectors(this.max,this.min);}expandByPoint(point){this.min.min(point);this.max.max(point);return this;}expandByVector(vector){this.min.sub(vector);this.max.add(vector);return this;}expandByScalar(scalar){this.min.addScalar(-scalar);this.max.addScalar(scalar);return this;}containsPoint(point){return point.x<this.min.x||point.x>this.max.x||point.y<this.min.y||point.y>this.max.y?false:true;}containsBox(box){return this.min.x<=box.min.x&&box.max.x<=this.max.x&&this.min.y<=box.min.y&&box.max.y<=this.max.y;}getParameter(point,target){// This can potentially have a divide by zero if the box
  2541. // has a size dimension of 0.
  2542. if(target===undefined){console.warn('THREE.Box2: .getParameter() target is now required');target=new Vector2();}return target.set((point.x-this.min.x)/(this.max.x-this.min.x),(point.y-this.min.y)/(this.max.y-this.min.y));}intersectsBox(box){// using 4 splitting planes to rule out intersections
  2543. return box.max.x<this.min.x||box.min.x>this.max.x||box.max.y<this.min.y||box.min.y>this.max.y?false:true;}clampPoint(point,target){if(target===undefined){console.warn('THREE.Box2: .clampPoint() target is now required');target=new Vector2();}return target.copy(point).clamp(this.min,this.max);}distanceToPoint(point){var clampedPoint=_vector$8.copy(point).clamp(this.min,this.max);return clampedPoint.sub(point).length();}intersect(box){this.min.max(box.min);this.max.min(box.max);return this;}union(box){this.min.min(box.min);this.max.max(box.max);return this;}translate(offset){this.min.add(offset);this.max.add(offset);return this;}equals(box){return box.min.equals(this.min)&&box.max.equals(this.max);}}var _startP=/*@__PURE__*/new Vector3();var _startEnd=/*@__PURE__*/new Vector3();class Line3{constructor(start,end){this.start=start!==undefined?start:new Vector3();this.end=end!==undefined?end:new Vector3();}set(start,end){this.start.copy(start);this.end.copy(end);return this;}clone(){return new this.constructor().copy(this);}copy(line){this.start.copy(line.start);this.end.copy(line.end);return this;}getCenter(target){if(target===undefined){console.warn('THREE.Line3: .getCenter() target is now required');target=new Vector3();}return target.addVectors(this.start,this.end).multiplyScalar(0.5);}delta(target){if(target===undefined){console.warn('THREE.Line3: .delta() target is now required');target=new Vector3();}return target.subVectors(this.end,this.start);}distanceSq(){return this.start.distanceToSquared(this.end);}distance(){return this.start.distanceTo(this.end);}at(t,target){if(target===undefined){console.warn('THREE.Line3: .at() target is now required');target=new Vector3();}return this.delta(target).multiplyScalar(t).add(this.start);}closestPointToPointParameter(point,clampToLine){_startP.subVectors(point,this.start);_startEnd.subVectors(this.end,this.start);var startEnd2=_startEnd.dot(_startEnd);var startEnd_startP=_startEnd.dot(_startP);var t=startEnd_startP/startEnd2;if(clampToLine){t=MathUtils.clamp(t,0,1);}return t;}closestPointToPoint(point,clampToLine,target){var t=this.closestPointToPointParameter(point,clampToLine);if(target===undefined){console.warn('THREE.Line3: .closestPointToPoint() target is now required');target=new Vector3();}return this.delta(target).multiplyScalar(t).add(this.start);}applyMatrix4(matrix){this.start.applyMatrix4(matrix);this.end.applyMatrix4(matrix);return this;}equals(line){return line.start.equals(this.start)&&line.end.equals(this.end);}}function ImmediateRenderObject(material){Object3D.call(this);this.material=material;this.render=function/* renderCallback */(){};this.hasPositions=false;this.hasNormals=false;this.hasColors=false;this.hasUvs=false;this.positionArray=null;this.normalArray=null;this.colorArray=null;this.uvArray=null;this.count=0;}ImmediateRenderObject.prototype=Object.create(Object3D.prototype);ImmediateRenderObject.prototype.constructor=ImmediateRenderObject;ImmediateRenderObject.prototype.isImmediateRenderObject=true;var _vector$9=/*@__PURE__*/new Vector3();class SpotLightHelper extends Object3D{constructor(light,color){super();this.light=light;this.light.updateMatrixWorld();this.matrix=light.matrixWorld;this.matrixAutoUpdate=false;this.color=color;var geometry=new BufferGeometry();var positions=[0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,-1,0,1,0,0,0,0,1,1,0,0,0,0,-1,1];for(var _i363=0,j=1,l=32;_i363<l;_i363++,j++){var p1=_i363/l*Math.PI*2;var p2=j/l*Math.PI*2;positions.push(Math.cos(p1),Math.sin(p1),1,Math.cos(p2),Math.sin(p2),1);}geometry.setAttribute('position',new Float32BufferAttribute(positions,3));var material=new LineBasicMaterial({fog:false,toneMapped:false});this.cone=new LineSegments(geometry,material);this.add(this.cone);this.update();}dispose(){this.cone.geometry.dispose();this.cone.material.dispose();}update(){this.light.updateMatrixWorld();var coneLength=this.light.distance?this.light.distance:1000;var coneWidth=coneLength*Math.tan(this.light.angle);this.cone.scale.set(coneWidth,coneWidth,coneLength);_vector$9.setFromMatrixPosition(this.light.target.matrixWorld);this.cone.lookAt(_vector$9);if(this.color!==undefined){this.cone.material.color.set(this.color);}else {this.cone.material.color.copy(this.light.color);}}}var _vector$a=/*@__PURE__*/new Vector3();var _boneMatrix=/*@__PURE__*/new Matrix4();var _matrixWorldInv=/*@__PURE__*/new Matrix4();class SkeletonHelper extends LineSegments{constructor(object){var bones=getBoneList(object);var geometry=new BufferGeometry();var vertices=[];var colors=[];var color1=new Color(0,0,1);var color2=new Color(0,1,0);for(var _i364=0;_i364<bones.length;_i364++){var bone=bones[_i364];if(bone.parent&&bone.parent.isBone){vertices.push(0,0,0);vertices.push(0,0,0);colors.push(color1.r,color1.g,color1.b);colors.push(color2.r,color2.g,color2.b);}}geometry.setAttribute('position',new Float32BufferAttribute(vertices,3));geometry.setAttribute('color',new Float32BufferAttribute(colors,3));var material=new LineBasicMaterial({vertexColors:true,depthTest:false,depthWrite:false,toneMapped:false,transparent:true});super(geometry,material);this.type='SkeletonHelper';this.isSkeletonHelper=true;this.root=object;this.bones=bones;this.matrix=object.matrixWorld;this.matrixAutoUpdate=false;}updateMatrixWorld(force){var bones=this.bones;var geometry=this.geometry;var position=geometry.getAttribute('position');_matrixWorldInv.copy(this.root.matrixWorld).invert();for(var _i365=0,j=0;_i365<bones.length;_i365++){var bone=bones[_i365];if(bone.parent&&bone.parent.isBone){_boneMatrix.multiplyMatrices(_matrixWorldInv,bone.matrixWorld);_vector$a.setFromMatrixPosition(_boneMatrix);position.setXYZ(j,_vector$a.x,_vector$a.y,_vector$a.z);_boneMatrix.multiplyMatrices(_matrixWorldInv,bone.parent.matrixWorld);_vector$a.setFromMatrixPosition(_boneMatrix);position.setXYZ(j+1,_vector$a.x,_vector$a.y,_vector$a.z);j+=2;}}geometry.getAttribute('position').needsUpdate=true;super.updateMatrixWorld(force);}}function getBoneList(object){var boneList=[];if(object&&object.isBone){boneList.push(object);}for(var _i366=0;_i366<object.children.length;_i366++){boneList.push.apply(boneList,getBoneList(object.children[_i366]));}return boneList;}class PointLightHelper extends Mesh{constructor(light,sphereSize,color){var geometry=new SphereBufferGeometry(sphereSize,4,2);var material=new MeshBasicMaterial({wireframe:true,fog:false,toneMapped:false});super(geometry,material);this.light=light;this.light.updateMatrixWorld();this.color=color;this.type='PointLightHelper';this.matrix=this.light.matrixWorld;this.matrixAutoUpdate=false;this.update();/*
  2544. // TODO: delete this comment?
  2545. const distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  2546. const distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  2547. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  2548. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  2549. const d = light.distance;
  2550. if ( d === 0.0 ) {
  2551. this.lightDistance.visible = false;
  2552. } else {
  2553. this.lightDistance.scale.set( d, d, d );
  2554. }
  2555. this.add( this.lightDistance );
  2556. */}dispose(){this.geometry.dispose();this.material.dispose();}update(){if(this.color!==undefined){this.material.color.set(this.color);}else {this.material.color.copy(this.light.color);}/*
  2557. const d = this.light.distance;
  2558. if ( d === 0.0 ) {
  2559. this.lightDistance.visible = false;
  2560. } else {
  2561. this.lightDistance.visible = true;
  2562. this.lightDistance.scale.set( d, d, d );
  2563. }
  2564. */}}var _vector$b=/*@__PURE__*/new Vector3();var _color1=/*@__PURE__*/new Color();var _color2=/*@__PURE__*/new Color();class HemisphereLightHelper extends Object3D{constructor(light,size,color){super();this.light=light;this.light.updateMatrixWorld();this.matrix=light.matrixWorld;this.matrixAutoUpdate=false;this.color=color;var geometry=new OctahedronBufferGeometry(size);geometry.rotateY(Math.PI*0.5);this.material=new MeshBasicMaterial({wireframe:true,fog:false,toneMapped:false});if(this.color===undefined)this.material.vertexColors=true;var position=geometry.getAttribute('position');var colors=new Float32Array(position.count*3);geometry.setAttribute('color',new BufferAttribute(colors,3));this.add(new Mesh(geometry,this.material));this.update();}dispose(){this.children[0].geometry.dispose();this.children[0].material.dispose();}update(){var mesh=this.children[0];if(this.color!==undefined){this.material.color.set(this.color);}else {var colors=mesh.geometry.getAttribute('color');_color1.copy(this.light.color);_color2.copy(this.light.groundColor);for(var _i367=0,l=colors.count;_i367<l;_i367++){var color=_i367<l/2?_color1:_color2;colors.setXYZ(_i367,color.r,color.g,color.b);}colors.needsUpdate=true;}mesh.lookAt(_vector$b.setFromMatrixPosition(this.light.matrixWorld).negate());}}class GridHelper extends LineSegments{constructor(){var size=arguments.length>0&&arguments[0]!==undefined?arguments[0]:10;var divisions=arguments.length>1&&arguments[1]!==undefined?arguments[1]:10;var color1=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0x444444;var color2=arguments.length>3&&arguments[3]!==undefined?arguments[3]:0x888888;color1=new Color(color1);color2=new Color(color2);var center=divisions/2;var step=size/divisions;var halfSize=size/2;var vertices=[],colors=[];for(var _i368=0,j=0,k=-halfSize;_i368<=divisions;_i368++,k+=step){vertices.push(-halfSize,0,k,halfSize,0,k);vertices.push(k,0,-halfSize,k,0,halfSize);var color=_i368===center?color1:color2;color.toArray(colors,j);j+=3;color.toArray(colors,j);j+=3;color.toArray(colors,j);j+=3;color.toArray(colors,j);j+=3;}var geometry=new BufferGeometry();geometry.setAttribute('position',new Float32BufferAttribute(vertices,3));geometry.setAttribute('color',new Float32BufferAttribute(colors,3));var material=new LineBasicMaterial({vertexColors:true,toneMapped:false});super(geometry,material);this.type='GridHelper';}}class PolarGridHelper extends LineSegments{constructor(){var radius=arguments.length>0&&arguments[0]!==undefined?arguments[0]:10;var radials=arguments.length>1&&arguments[1]!==undefined?arguments[1]:16;var circles=arguments.length>2&&arguments[2]!==undefined?arguments[2]:8;var divisions=arguments.length>3&&arguments[3]!==undefined?arguments[3]:64;var color1=arguments.length>4&&arguments[4]!==undefined?arguments[4]:0x444444;var color2=arguments.length>5&&arguments[5]!==undefined?arguments[5]:0x888888;color1=new Color(color1);color2=new Color(color2);var vertices=[];var colors=[];// create the radials
  2565. for(var _i369=0;_i369<=radials;_i369++){var v=_i369/radials*(Math.PI*2);var x=Math.sin(v)*radius;var z=Math.cos(v)*radius;vertices.push(0,0,0);vertices.push(x,0,z);var color=_i369&1?color1:color2;colors.push(color.r,color.g,color.b);colors.push(color.r,color.g,color.b);}// create the circles
  2566. for(var _i370=0;_i370<=circles;_i370++){var _color=_i370&1?color1:color2;var r=radius-radius/circles*_i370;for(var j=0;j<divisions;j++){// first vertex
  2567. var _v4=j/divisions*(Math.PI*2);var _x5=Math.sin(_v4)*r;var _z3=Math.cos(_v4)*r;vertices.push(_x5,0,_z3);colors.push(_color.r,_color.g,_color.b);// second vertex
  2568. _v4=(j+1)/divisions*(Math.PI*2);_x5=Math.sin(_v4)*r;_z3=Math.cos(_v4)*r;vertices.push(_x5,0,_z3);colors.push(_color.r,_color.g,_color.b);}}var geometry=new BufferGeometry();geometry.setAttribute('position',new Float32BufferAttribute(vertices,3));geometry.setAttribute('color',new Float32BufferAttribute(colors,3));var material=new LineBasicMaterial({vertexColors:true,toneMapped:false});super(geometry,material);this.type='PolarGridHelper';}}var _v1$6=/*@__PURE__*/new Vector3();var _v2$3=/*@__PURE__*/new Vector3();var _v3$1=/*@__PURE__*/new Vector3();class DirectionalLightHelper extends Object3D{constructor(light,size,color){super();this.light=light;this.light.updateMatrixWorld();this.matrix=light.matrixWorld;this.matrixAutoUpdate=false;this.color=color;if(size===undefined)size=1;var geometry=new BufferGeometry();geometry.setAttribute('position',new Float32BufferAttribute([-size,size,0,size,size,0,size,-size,0,-size,-size,0,-size,size,0],3));var material=new LineBasicMaterial({fog:false,toneMapped:false});this.lightPlane=new Line(geometry,material);this.add(this.lightPlane);geometry=new BufferGeometry();geometry.setAttribute('position',new Float32BufferAttribute([0,0,0,0,0,1],3));this.targetLine=new Line(geometry,material);this.add(this.targetLine);this.update();}dispose(){this.lightPlane.geometry.dispose();this.lightPlane.material.dispose();this.targetLine.geometry.dispose();this.targetLine.material.dispose();}update(){_v1$6.setFromMatrixPosition(this.light.matrixWorld);_v2$3.setFromMatrixPosition(this.light.target.matrixWorld);_v3$1.subVectors(_v2$3,_v1$6);this.lightPlane.lookAt(_v2$3);if(this.color!==undefined){this.lightPlane.material.color.set(this.color);this.targetLine.material.color.set(this.color);}else {this.lightPlane.material.color.copy(this.light.color);this.targetLine.material.color.copy(this.light.color);}this.targetLine.lookAt(_v2$3);this.targetLine.scale.z=_v3$1.length();}}var _vector$c=/*@__PURE__*/new Vector3();var _camera=/*@__PURE__*/new Camera();/**
  2569. * - shows frustum, line of sight and up of the camera
  2570. * - suitable for fast updates
  2571. * - based on frustum visualization in lightgl.js shadowmap example
  2572. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  2573. */class CameraHelper extends LineSegments{constructor(camera){var geometry=new BufferGeometry();var material=new LineBasicMaterial({color:0xffffff,vertexColors:true,toneMapped:false});var vertices=[];var colors=[];var pointMap={};// colors
  2574. var colorFrustum=new Color(0xffaa00);var colorCone=new Color(0xff0000);var colorUp=new Color(0x00aaff);var colorTarget=new Color(0xffffff);var colorCross=new Color(0x333333);// near
  2575. addLine('n1','n2',colorFrustum);addLine('n2','n4',colorFrustum);addLine('n4','n3',colorFrustum);addLine('n3','n1',colorFrustum);// far
  2576. addLine('f1','f2',colorFrustum);addLine('f2','f4',colorFrustum);addLine('f4','f3',colorFrustum);addLine('f3','f1',colorFrustum);// sides
  2577. addLine('n1','f1',colorFrustum);addLine('n2','f2',colorFrustum);addLine('n3','f3',colorFrustum);addLine('n4','f4',colorFrustum);// cone
  2578. addLine('p','n1',colorCone);addLine('p','n2',colorCone);addLine('p','n3',colorCone);addLine('p','n4',colorCone);// up
  2579. addLine('u1','u2',colorUp);addLine('u2','u3',colorUp);addLine('u3','u1',colorUp);// target
  2580. addLine('c','t',colorTarget);addLine('p','c',colorCross);// cross
  2581. addLine('cn1','cn2',colorCross);addLine('cn3','cn4',colorCross);addLine('cf1','cf2',colorCross);addLine('cf3','cf4',colorCross);function addLine(a,b,color){addPoint(a,color);addPoint(b,color);}function addPoint(id,color){vertices.push(0,0,0);colors.push(color.r,color.g,color.b);if(pointMap[id]===undefined){pointMap[id]=[];}pointMap[id].push(vertices.length/3-1);}geometry.setAttribute('position',new Float32BufferAttribute(vertices,3));geometry.setAttribute('color',new Float32BufferAttribute(colors,3));super(geometry,material);this.type='CameraHelper';this.camera=camera;if(this.camera.updateProjectionMatrix)this.camera.updateProjectionMatrix();this.matrix=camera.matrixWorld;this.matrixAutoUpdate=false;this.pointMap=pointMap;this.update();}update(){var geometry=this.geometry;var pointMap=this.pointMap;var w=1,h=1;// we need just camera projection matrix inverse
  2582. // world matrix must be identity
  2583. _camera.projectionMatrixInverse.copy(this.camera.projectionMatrixInverse);// center / target
  2584. setPoint('c',pointMap,geometry,_camera,0,0,-1);setPoint('t',pointMap,geometry,_camera,0,0,1);// near
  2585. setPoint('n1',pointMap,geometry,_camera,-w,-h,-1);setPoint('n2',pointMap,geometry,_camera,w,-h,-1);setPoint('n3',pointMap,geometry,_camera,-w,h,-1);setPoint('n4',pointMap,geometry,_camera,w,h,-1);// far
  2586. setPoint('f1',pointMap,geometry,_camera,-w,-h,1);setPoint('f2',pointMap,geometry,_camera,w,-h,1);setPoint('f3',pointMap,geometry,_camera,-w,h,1);setPoint('f4',pointMap,geometry,_camera,w,h,1);// up
  2587. setPoint('u1',pointMap,geometry,_camera,w*0.7,h*1.1,-1);setPoint('u2',pointMap,geometry,_camera,-w*0.7,h*1.1,-1);setPoint('u3',pointMap,geometry,_camera,0,h*2,-1);// cross
  2588. setPoint('cf1',pointMap,geometry,_camera,-w,0,1);setPoint('cf2',pointMap,geometry,_camera,w,0,1);setPoint('cf3',pointMap,geometry,_camera,0,-h,1);setPoint('cf4',pointMap,geometry,_camera,0,h,1);setPoint('cn1',pointMap,geometry,_camera,-w,0,-1);setPoint('cn2',pointMap,geometry,_camera,w,0,-1);setPoint('cn3',pointMap,geometry,_camera,0,-h,-1);setPoint('cn4',pointMap,geometry,_camera,0,h,-1);geometry.getAttribute('position').needsUpdate=true;}}function setPoint(point,pointMap,geometry,camera,x,y,z){_vector$c.set(x,y,z).unproject(camera);var points=pointMap[point];if(points!==undefined){var position=geometry.getAttribute('position');for(var _i371=0,l=points.length;_i371<l;_i371++){position.setXYZ(points[_i371],_vector$c.x,_vector$c.y,_vector$c.z);}}}var _box$3=/*@__PURE__*/new Box3();class BoxHelper extends LineSegments{constructor(object){var color=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0xffff00;var indices=new Uint16Array([0,1,1,2,2,3,3,0,4,5,5,6,6,7,7,4,0,4,1,5,2,6,3,7]);var positions=new Float32Array(8*3);var geometry=new BufferGeometry();geometry.setIndex(new BufferAttribute(indices,1));geometry.setAttribute('position',new BufferAttribute(positions,3));super(geometry,new LineBasicMaterial({color:color,toneMapped:false}));this.object=object;this.type='BoxHelper';this.matrixAutoUpdate=false;this.update();}update(object){if(object!==undefined){console.warn('THREE.BoxHelper: .update() has no longer arguments.');}if(this.object!==undefined){_box$3.setFromObject(this.object);}if(_box$3.isEmpty())return;var min=_box$3.min;var max=_box$3.max;/*
  2589. 5____4
  2590. 1/___0/|
  2591. | 6__|_7
  2592. 2/___3/
  2593. 0: max.x, max.y, max.z
  2594. 1: min.x, max.y, max.z
  2595. 2: min.x, min.y, max.z
  2596. 3: max.x, min.y, max.z
  2597. 4: max.x, max.y, min.z
  2598. 5: min.x, max.y, min.z
  2599. 6: min.x, min.y, min.z
  2600. 7: max.x, min.y, min.z
  2601. */var position=this.geometry.attributes.position;var array=position.array;array[0]=max.x;array[1]=max.y;array[2]=max.z;array[3]=min.x;array[4]=max.y;array[5]=max.z;array[6]=min.x;array[7]=min.y;array[8]=max.z;array[9]=max.x;array[10]=min.y;array[11]=max.z;array[12]=max.x;array[13]=max.y;array[14]=min.z;array[15]=min.x;array[16]=max.y;array[17]=min.z;array[18]=min.x;array[19]=min.y;array[20]=min.z;array[21]=max.x;array[22]=min.y;array[23]=min.z;position.needsUpdate=true;this.geometry.computeBoundingSphere();}setFromObject(object){this.object=object;this.update();return this;}copy(source){LineSegments.prototype.copy.call(this,source);this.object=source.object;return this;}}class Box3Helper extends LineSegments{constructor(box){var color=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0xffff00;var indices=new Uint16Array([0,1,1,2,2,3,3,0,4,5,5,6,6,7,7,4,0,4,1,5,2,6,3,7]);var positions=[1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,-1,-1,1,-1,-1,-1,-1,1,-1,-1];var geometry=new BufferGeometry();geometry.setIndex(new BufferAttribute(indices,1));geometry.setAttribute('position',new Float32BufferAttribute(positions,3));super(geometry,new LineBasicMaterial({color:color,toneMapped:false}));this.box=box;this.type='Box3Helper';this.geometry.computeBoundingSphere();}updateMatrixWorld(force){var box=this.box;if(box.isEmpty())return;box.getCenter(this.position);box.getSize(this.scale);this.scale.multiplyScalar(0.5);super.updateMatrixWorld(force);}}class PlaneHelper extends Line{constructor(plane){var size=arguments.length>1&&arguments[1]!==undefined?arguments[1]:1;var hex=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0xffff00;var color=hex;var positions=[1,-1,1,-1,1,1,-1,-1,1,1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,0,0,1,0,0,0];var geometry=new BufferGeometry();geometry.setAttribute('position',new Float32BufferAttribute(positions,3));geometry.computeBoundingSphere();super(geometry,new LineBasicMaterial({color:color,toneMapped:false}));this.type='PlaneHelper';this.plane=plane;this.size=size;var positions2=[1,1,1,-1,1,1,-1,-1,1,1,1,1,-1,-1,1,1,-1,1];var geometry2=new BufferGeometry();geometry2.setAttribute('position',new Float32BufferAttribute(positions2,3));geometry2.computeBoundingSphere();this.add(new Mesh(geometry2,new MeshBasicMaterial({color:color,opacity:0.2,transparent:true,depthWrite:false,toneMapped:false})));}updateMatrixWorld(force){var scale=-this.plane.constant;if(Math.abs(scale)<1e-8)scale=1e-8;// sign does not matter
  2602. this.scale.set(0.5*this.size,0.5*this.size,scale);this.children[0].material.side=scale<0?BackSide:FrontSide;// renderer flips side when determinant < 0; flipping not wanted here
  2603. this.lookAt(this.plane.normal);super.updateMatrixWorld(force);}}var _axis$1=/*@__PURE__*/new Vector3();var _lineGeometry,_coneGeometry;class ArrowHelper extends Object3D{constructor(dir,origin,length,color,headLength,headWidth){super();// dir is assumed to be normalized
  2604. this.type='ArrowHelper';if(dir===undefined)dir=new Vector3(0,0,1);if(origin===undefined)origin=new Vector3(0,0,0);if(length===undefined)length=1;if(color===undefined)color=0xffff00;if(headLength===undefined)headLength=0.2*length;if(headWidth===undefined)headWidth=0.2*headLength;if(_lineGeometry===undefined){_lineGeometry=new BufferGeometry();_lineGeometry.setAttribute('position',new Float32BufferAttribute([0,0,0,0,1,0],3));_coneGeometry=new CylinderBufferGeometry(0,0.5,1,5,1);_coneGeometry.translate(0,-0.5,0);}this.position.copy(origin);this.line=new Line(_lineGeometry,new LineBasicMaterial({color:color,toneMapped:false}));this.line.matrixAutoUpdate=false;this.add(this.line);this.cone=new Mesh(_coneGeometry,new MeshBasicMaterial({color:color,toneMapped:false}));this.cone.matrixAutoUpdate=false;this.add(this.cone);this.setDirection(dir);this.setLength(length,headLength,headWidth);}setDirection(dir){// dir is assumed to be normalized
  2605. if(dir.y>0.99999){this.quaternion.set(0,0,0,1);}else if(dir.y<-0.99999){this.quaternion.set(1,0,0,0);}else {_axis$1.set(dir.z,0,-dir.x).normalize();var radians=Math.acos(dir.y);this.quaternion.setFromAxisAngle(_axis$1,radians);}}setLength(length,headLength,headWidth){if(headLength===undefined)headLength=0.2*length;if(headWidth===undefined)headWidth=0.2*headLength;this.line.scale.set(1,Math.max(0.0001,length-headLength),1);// see #17458
  2606. this.line.updateMatrix();this.cone.scale.set(headWidth,headLength,headWidth);this.cone.position.y=length;this.cone.updateMatrix();}setColor(color){this.line.material.color.set(color);this.cone.material.color.set(color);}copy(source){super.copy(source,false);this.line.copy(source.line);this.cone.copy(source.cone);return this;}}class AxesHelper extends LineSegments{constructor(){var size=arguments.length>0&&arguments[0]!==undefined?arguments[0]:1;var vertices=[0,0,0,size,0,0,0,0,0,0,size,0,0,0,0,0,0,size];var colors=[1,0,0,1,0.6,0,0,1,0,0.6,1,0,0,0,1,0,0.6,1];var geometry=new BufferGeometry();geometry.setAttribute('position',new Float32BufferAttribute(vertices,3));geometry.setAttribute('color',new Float32BufferAttribute(colors,3));var material=new LineBasicMaterial({vertexColors:true,toneMapped:false});super(geometry,material);this.type='AxesHelper';}}var _floatView=new Float32Array(1);var _int32View=new Int32Array(_floatView.buffer);var DataUtils={// Converts float32 to float16 (stored as uint16 value).
  2607. toHalfFloat:function toHalfFloat(val){// Source: http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
  2608. /* This method is faster than the OpenEXR implementation (very often
  2609. * used, eg. in Ogre), with the additional benefit of rounding, inspired
  2610. * by James Tursa?s half-precision code. */_floatView[0]=val;var x=_int32View[0];var bits=x>>16&0x8000;/* Get the sign */var m=x>>12&0x07ff;/* Keep one extra bit for rounding */var e=x>>23&0xff;/* Using int is faster here */ /* If zero, or denormal, or exponent underflows too much for a denormal
  2611. * half, return signed zero. */if(e<103)return bits;/* If NaN, return NaN. If Inf or exponent overflow, return Inf. */if(e>142){bits|=0x7c00;/* If exponent was 0xff and one mantissa bit was set, it means NaN,
  2612. * not Inf, so make sure we set one mantissa bit too. */bits|=(e==255?0:1)&&x&0x007fffff;return bits;}/* If exponent underflows but not too much, return a denormal */if(e<113){m|=0x0800;/* Extra rounding may overflow and set mantissa to 0 and exponent
  2613. * to 1, which is OK. */bits|=(m>>114-e)+(m>>113-e&1);return bits;}bits|=e-112<<10|m>>1;/* Extra rounding. An overflow will set mantissa to 0 and increment
  2614. * the exponent, which is OK. */bits+=m&1;return bits;}};var LOD_MIN=4;var LOD_MAX=8;var SIZE_MAX=Math.pow(2,LOD_MAX);// The standard deviations (radians) associated with the extra mips. These are
  2615. // chosen to approximate a Trowbridge-Reitz distribution function times the
  2616. // geometric shadowing function. These sigma values squared must match the
  2617. // variance #defines in cube_uv_reflection_fragment.glsl.js.
  2618. var EXTRA_LOD_SIGMA=[0.125,0.215,0.35,0.446,0.526,0.582];var TOTAL_LODS=LOD_MAX-LOD_MIN+1+EXTRA_LOD_SIGMA.length;// The maximum length of the blur for loop. Smaller sigmas will use fewer
  2619. // samples and exit early, but not recompile the shader.
  2620. var MAX_SAMPLES=20;var ENCODINGS={[LinearEncoding]:0,[sRGBEncoding]:1,[RGBEEncoding]:2,[RGBM7Encoding]:3,[RGBM16Encoding]:4,[RGBDEncoding]:5,[GammaEncoding]:6};var _flatCamera=/*@__PURE__*/new OrthographicCamera();var{_lodPlanes,_sizeLods,_sigmas}=/*@__PURE__*/_createPlanes();var _clearColor=/*@__PURE__*/new Color();var _oldTarget=null;// Golden Ratio
  2621. var PHI=(1+Math.sqrt(5))/2;var INV_PHI=1/PHI;// Vertices of a dodecahedron (except the opposites, which represent the
  2622. // same axis), used as axis directions evenly spread on a sphere.
  2623. var _axisDirections=[/*@__PURE__*/new Vector3(1,1,1),/*@__PURE__*/new Vector3(-1,1,1),/*@__PURE__*/new Vector3(1,1,-1),/*@__PURE__*/new Vector3(-1,1,-1),/*@__PURE__*/new Vector3(0,PHI,INV_PHI),/*@__PURE__*/new Vector3(0,PHI,-INV_PHI),/*@__PURE__*/new Vector3(INV_PHI,0,PHI),/*@__PURE__*/new Vector3(-INV_PHI,0,PHI),/*@__PURE__*/new Vector3(PHI,INV_PHI,0),/*@__PURE__*/new Vector3(-PHI,INV_PHI,0)];/**
  2624. * This class generates a Prefiltered, Mipmapped Radiance Environment Map
  2625. * (PMREM) from a cubeMap environment texture. This allows different levels of
  2626. * blur to be quickly accessed based on material roughness. It is packed into a
  2627. * special CubeUV format that allows us to perform custom interpolation so that
  2628. * we can support nonlinear formats such as RGBE. Unlike a traditional mipmap
  2629. * chain, it only goes down to the LOD_MIN level (above), and then creates extra
  2630. * even more filtered 'mips' at the same LOD_MIN resolution, associated with
  2631. * higher roughness levels. In this way we maintain resolution to smoothly
  2632. * interpolate diffuse lighting while limiting sampling computation.
  2633. */class PMREMGenerator{constructor(renderer){this._renderer=renderer;this._pingPongRenderTarget=null;this._blurMaterial=_getBlurShader(MAX_SAMPLES);this._equirectShader=null;this._cubemapShader=null;this._compileMaterial(this._blurMaterial);}/**
  2634. * Generates a PMREM from a supplied Scene, which can be faster than using an
  2635. * image if networking bandwidth is low. Optional sigma specifies a blur radius
  2636. * in radians to be applied to the scene before PMREM generation. Optional near
  2637. * and far planes ensure the scene is rendered in its entirety (the cubeCamera
  2638. * is placed at the origin).
  2639. */fromScene(scene){var sigma=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var near=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0.1;var far=arguments.length>3&&arguments[3]!==undefined?arguments[3]:100;_oldTarget=this._renderer.getRenderTarget();var cubeUVRenderTarget=this._allocateTargets();this._sceneToCubeUV(scene,near,far,cubeUVRenderTarget);if(sigma>0){this._blur(cubeUVRenderTarget,0,0,sigma);}this._applyPMREM(cubeUVRenderTarget);this._cleanup(cubeUVRenderTarget);return cubeUVRenderTarget;}/**
  2640. * Generates a PMREM from an equirectangular texture, which can be either LDR
  2641. * (RGBFormat) or HDR (RGBEFormat). The ideal input image size is 1k (1024 x 512),
  2642. * as this matches best with the 256 x 256 cubemap output.
  2643. */fromEquirectangular(equirectangular){return this._fromTexture(equirectangular);}/**
  2644. * Generates a PMREM from an cubemap texture, which can be either LDR
  2645. * (RGBFormat) or HDR (RGBEFormat). The ideal input cube size is 256 x 256,
  2646. * as this matches best with the 256 x 256 cubemap output.
  2647. */fromCubemap(cubemap){return this._fromTexture(cubemap);}/**
  2648. * Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
  2649. * your texture's network fetch for increased concurrency.
  2650. */compileCubemapShader(){if(this._cubemapShader===null){this._cubemapShader=_getCubemapShader();this._compileMaterial(this._cubemapShader);}}/**
  2651. * Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during
  2652. * your texture's network fetch for increased concurrency.
  2653. */compileEquirectangularShader(){if(this._equirectShader===null){this._equirectShader=_getEquirectShader();this._compileMaterial(this._equirectShader);}}/**
  2654. * Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class,
  2655. * so you should not need more than one PMREMGenerator object. If you do, calling dispose() on
  2656. * one of them will cause any others to also become unusable.
  2657. */dispose(){this._blurMaterial.dispose();if(this._cubemapShader!==null)this._cubemapShader.dispose();if(this._equirectShader!==null)this._equirectShader.dispose();for(var _i372=0;_i372<_lodPlanes.length;_i372++){_lodPlanes[_i372].dispose();}}// private interface
  2658. _cleanup(outputTarget){this._pingPongRenderTarget.dispose();this._renderer.setRenderTarget(_oldTarget);outputTarget.scissorTest=false;_setViewport(outputTarget,0,0,outputTarget.width,outputTarget.height);}_fromTexture(texture){_oldTarget=this._renderer.getRenderTarget();var cubeUVRenderTarget=this._allocateTargets(texture);this._textureToCubeUV(texture,cubeUVRenderTarget);this._applyPMREM(cubeUVRenderTarget);this._cleanup(cubeUVRenderTarget);return cubeUVRenderTarget;}_allocateTargets(texture){// warning: null texture is valid
  2659. var params={magFilter:NearestFilter,minFilter:NearestFilter,generateMipmaps:false,type:UnsignedByteType,format:RGBEFormat,encoding:_isLDR(texture)?texture.encoding:RGBEEncoding,depthBuffer:false};var cubeUVRenderTarget=_createRenderTarget(params);cubeUVRenderTarget.depthBuffer=texture?false:true;this._pingPongRenderTarget=_createRenderTarget(params);return cubeUVRenderTarget;}_compileMaterial(material){var tmpMesh=new Mesh(_lodPlanes[0],material);this._renderer.compile(tmpMesh,_flatCamera);}_sceneToCubeUV(scene,near,far,cubeUVRenderTarget){var fov=90;var aspect=1;var cubeCamera=new PerspectiveCamera(fov,aspect,near,far);var upSign=[1,-1,1,1,1,1];var forwardSign=[1,1,1,-1,-1,-1];var renderer=this._renderer;var outputEncoding=renderer.outputEncoding;var toneMapping=renderer.toneMapping;renderer.getClearColor(_clearColor);var clearAlpha=renderer.getClearAlpha();renderer.toneMapping=NoToneMapping;renderer.outputEncoding=LinearEncoding;var background=scene.background;if(background&&background.isColor){background.convertSRGBToLinear();// Convert linear to RGBE
  2660. var maxComponent=Math.max(background.r,background.g,background.b);var fExp=Math.min(Math.max(Math.ceil(Math.log2(maxComponent)),-128.0),127.0);background=background.multiplyScalar(Math.pow(2.0,-fExp));var alpha=(fExp+128.0)/255.0;renderer.setClearColor(background,alpha);scene.background=null;}for(var _i373=0;_i373<6;_i373++){var col=_i373%3;if(col==0){cubeCamera.up.set(0,upSign[_i373],0);cubeCamera.lookAt(forwardSign[_i373],0,0);}else if(col==1){cubeCamera.up.set(0,0,upSign[_i373]);cubeCamera.lookAt(0,forwardSign[_i373],0);}else {cubeCamera.up.set(0,upSign[_i373],0);cubeCamera.lookAt(0,0,forwardSign[_i373]);}_setViewport(cubeUVRenderTarget,col*SIZE_MAX,_i373>2?SIZE_MAX:0,SIZE_MAX,SIZE_MAX);renderer.setRenderTarget(cubeUVRenderTarget);renderer.render(scene,cubeCamera);}renderer.toneMapping=toneMapping;renderer.outputEncoding=outputEncoding;renderer.setClearColor(_clearColor,clearAlpha);}_textureToCubeUV(texture,cubeUVRenderTarget){var renderer=this._renderer;if(texture.isCubeTexture){if(this._cubemapShader==null){this._cubemapShader=_getCubemapShader();}}else {if(this._equirectShader==null){this._equirectShader=_getEquirectShader();}}var material=texture.isCubeTexture?this._cubemapShader:this._equirectShader;var mesh=new Mesh(_lodPlanes[0],material);var uniforms=material.uniforms;uniforms['envMap'].value=texture;if(!texture.isCubeTexture){uniforms['texelSize'].value.set(1.0/texture.image.width,1.0/texture.image.height);}uniforms['inputEncoding'].value=ENCODINGS[texture.encoding];uniforms['outputEncoding'].value=ENCODINGS[cubeUVRenderTarget.texture.encoding];_setViewport(cubeUVRenderTarget,0,0,3*SIZE_MAX,2*SIZE_MAX);renderer.setRenderTarget(cubeUVRenderTarget);renderer.render(mesh,_flatCamera);}_applyPMREM(cubeUVRenderTarget){var renderer=this._renderer;var autoClear=renderer.autoClear;renderer.autoClear=false;for(var _i374=1;_i374<TOTAL_LODS;_i374++){var sigma=Math.sqrt(_sigmas[_i374]*_sigmas[_i374]-_sigmas[_i374-1]*_sigmas[_i374-1]);var poleAxis=_axisDirections[(_i374-1)%_axisDirections.length];this._blur(cubeUVRenderTarget,_i374-1,_i374,sigma,poleAxis);}renderer.autoClear=autoClear;}/**
  2661. * This is a two-pass Gaussian blur for a cubemap. Normally this is done
  2662. * vertically and horizontally, but this breaks down on a cube. Here we apply
  2663. * the blur latitudinally (around the poles), and then longitudinally (towards
  2664. * the poles) to approximate the orthogonally-separable blur. It is least
  2665. * accurate at the poles, but still does a decent job.
  2666. */_blur(cubeUVRenderTarget,lodIn,lodOut,sigma,poleAxis){var pingPongRenderTarget=this._pingPongRenderTarget;this._halfBlur(cubeUVRenderTarget,pingPongRenderTarget,lodIn,lodOut,sigma,'latitudinal',poleAxis);this._halfBlur(pingPongRenderTarget,cubeUVRenderTarget,lodOut,lodOut,sigma,'longitudinal',poleAxis);}_halfBlur(targetIn,targetOut,lodIn,lodOut,sigmaRadians,direction,poleAxis){var renderer=this._renderer;var blurMaterial=this._blurMaterial;if(direction!=='latitudinal'&&direction!=='longitudinal'){console.error('blur direction must be either latitudinal or longitudinal!');}// Number of standard deviations at which to cut off the discrete approximation.
  2667. var STANDARD_DEVIATIONS=3;var blurMesh=new Mesh(_lodPlanes[lodOut],blurMaterial);var blurUniforms=blurMaterial.uniforms;var pixels=_sizeLods[lodIn]-1;var radiansPerPixel=isFinite(sigmaRadians)?Math.PI/(2*pixels):2*Math.PI/(2*MAX_SAMPLES-1);var sigmaPixels=sigmaRadians/radiansPerPixel;var samples=isFinite(sigmaRadians)?1+Math.floor(STANDARD_DEVIATIONS*sigmaPixels):MAX_SAMPLES;if(samples>MAX_SAMPLES){console.warn("sigmaRadians, ".concat(sigmaRadians,", is too large and will clip, as it requested ").concat(samples," samples when the maximum is set to ").concat(MAX_SAMPLES));}var weights=[];var sum=0;for(var _i375=0;_i375<MAX_SAMPLES;++_i375){var _x6=_i375/sigmaPixels;var weight=Math.exp(-_x6*_x6/2);weights.push(weight);if(_i375==0){sum+=weight;}else if(_i375<samples){sum+=2*weight;}}for(var _i376=0;_i376<weights.length;_i376++){weights[_i376]=weights[_i376]/sum;}blurUniforms['envMap'].value=targetIn.texture;blurUniforms['samples'].value=samples;blurUniforms['weights'].value=weights;blurUniforms['latitudinal'].value=direction==='latitudinal';if(poleAxis){blurUniforms['poleAxis'].value=poleAxis;}blurUniforms['dTheta'].value=radiansPerPixel;blurUniforms['mipInt'].value=LOD_MAX-lodIn;blurUniforms['inputEncoding'].value=ENCODINGS[targetIn.texture.encoding];blurUniforms['outputEncoding'].value=ENCODINGS[targetIn.texture.encoding];var outputSize=_sizeLods[lodOut];var x=3*Math.max(0,SIZE_MAX-2*outputSize);var y=(lodOut===0?0:2*SIZE_MAX)+2*outputSize*(lodOut>LOD_MAX-LOD_MIN?lodOut-LOD_MAX+LOD_MIN:0);_setViewport(targetOut,x,y,3*outputSize,2*outputSize);renderer.setRenderTarget(targetOut);renderer.render(blurMesh,_flatCamera);}}function _isLDR(texture){if(texture===undefined||texture.type!==UnsignedByteType)return false;return texture.encoding===LinearEncoding||texture.encoding===sRGBEncoding||texture.encoding===GammaEncoding;}function _createPlanes(){var _lodPlanes=[];var _sizeLods=[];var _sigmas=[];var lod=LOD_MAX;for(var _i377=0;_i377<TOTAL_LODS;_i377++){var sizeLod=Math.pow(2,lod);_sizeLods.push(sizeLod);var sigma=1.0/sizeLod;if(_i377>LOD_MAX-LOD_MIN){sigma=EXTRA_LOD_SIGMA[_i377-LOD_MAX+LOD_MIN-1];}else if(_i377==0){sigma=0;}_sigmas.push(sigma);var texelSize=1.0/(sizeLod-1);var min=-texelSize/2;var max=1+texelSize/2;var uv1=[min,min,max,min,max,max,min,min,max,max,min,max];var cubeFaces=6;var vertices=6;var positionSize=3;var uvSize=2;var faceIndexSize=1;var position=new Float32Array(positionSize*vertices*cubeFaces);var uv=new Float32Array(uvSize*vertices*cubeFaces);var faceIndex=new Float32Array(faceIndexSize*vertices*cubeFaces);for(var face=0;face<cubeFaces;face++){var x=face%3*2/3-1;var y=face>2?0:-1;var coordinates=[x,y,0,x+2/3,y,0,x+2/3,y+1,0,x,y,0,x+2/3,y+1,0,x,y+1,0];position.set(coordinates,positionSize*vertices*face);uv.set(uv1,uvSize*vertices*face);var fill=[face,face,face,face,face,face];faceIndex.set(fill,faceIndexSize*vertices*face);}var planes=new BufferGeometry();planes.setAttribute('position',new BufferAttribute(position,positionSize));planes.setAttribute('uv',new BufferAttribute(uv,uvSize));planes.setAttribute('faceIndex',new BufferAttribute(faceIndex,faceIndexSize));_lodPlanes.push(planes);if(lod>LOD_MIN){lod--;}}return {_lodPlanes,_sizeLods,_sigmas};}function _createRenderTarget(params){var cubeUVRenderTarget=new WebGLRenderTarget(3*SIZE_MAX,3*SIZE_MAX,params);cubeUVRenderTarget.texture.mapping=CubeUVReflectionMapping;cubeUVRenderTarget.texture.name='PMREM.cubeUv';cubeUVRenderTarget.scissorTest=true;return cubeUVRenderTarget;}function _setViewport(target,x,y,width,height){target.viewport.set(x,y,width,height);target.scissor.set(x,y,width,height);}function _getBlurShader(maxSamples){var weights=new Float32Array(maxSamples);var poleAxis=new Vector3(0,1,0);var shaderMaterial=new RawShaderMaterial({name:'SphericalGaussianBlur',defines:{'n':maxSamples},uniforms:{'envMap':{value:null},'samples':{value:1},'weights':{value:weights},'latitudinal':{value:false},'dTheta':{value:0},'mipInt':{value:0},'poleAxis':{value:poleAxis},'inputEncoding':{value:ENCODINGS[LinearEncoding]},'outputEncoding':{value:ENCODINGS[LinearEncoding]}},vertexShader:_getCommonVertexShader(),fragmentShader:/* glsl */"\n\n\t\t\tprecision mediump float;\n\t\t\tprecision mediump int;\n\n\t\t\tvarying vec3 vOutputDirection;\n\n\t\t\tuniform sampler2D envMap;\n\t\t\tuniform int samples;\n\t\t\tuniform float weights[ n ];\n\t\t\tuniform bool latitudinal;\n\t\t\tuniform float dTheta;\n\t\t\tuniform float mipInt;\n\t\t\tuniform vec3 poleAxis;\n\n\t\t\t".concat(_getEncodings(),"\n\n\t\t\t#define ENVMAP_TYPE_CUBE_UV\n\t\t\t#include <cube_uv_reflection_fragment>\n\n\t\t\tvec3 getSample( float theta, vec3 axis ) {\n\n\t\t\t\tfloat cosTheta = cos( theta );\n\t\t\t\t// Rodrigues' axis-angle rotation\n\t\t\t\tvec3 sampleDirection = vOutputDirection * cosTheta\n\t\t\t\t\t+ cross( axis, vOutputDirection ) * sin( theta )\n\t\t\t\t\t+ axis * dot( axis, vOutputDirection ) * ( 1.0 - cosTheta );\n\n\t\t\t\treturn bilinearCubeUV( envMap, sampleDirection, mipInt );\n\n\t\t\t}\n\n\t\t\tvoid main() {\n\n\t\t\t\tvec3 axis = latitudinal ? poleAxis : cross( poleAxis, vOutputDirection );\n\n\t\t\t\tif ( all( equal( axis, vec3( 0.0 ) ) ) ) {\n\n\t\t\t\t\taxis = vec3( vOutputDirection.z, 0.0, - vOutputDirection.x );\n\n\t\t\t\t}\n\n\t\t\t\taxis = normalize( axis );\n\n\t\t\t\tgl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );\n\t\t\t\tgl_FragColor.rgb += weights[ 0 ] * getSample( 0.0, axis );\n\n\t\t\t\tfor ( int i = 1; i < n; i++ ) {\n\n\t\t\t\t\tif ( i >= samples ) {\n\n\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t}\n\n\t\t\t\t\tfloat theta = dTheta * float( i );\n\t\t\t\t\tgl_FragColor.rgb += weights[ i ] * getSample( -1.0 * theta, axis );\n\t\t\t\t\tgl_FragColor.rgb += weights[ i ] * getSample( theta, axis );\n\n\t\t\t\t}\n\n\t\t\t\tgl_FragColor = linearToOutputTexel( gl_FragColor );\n\n\t\t\t}\n\t\t"),blending:NoBlending,depthTest:false,depthWrite:false});return shaderMaterial;}function _getEquirectShader(){var texelSize=new Vector2(1,1);var shaderMaterial=new RawShaderMaterial({name:'EquirectangularToCubeUV',uniforms:{'envMap':{value:null},'texelSize':{value:texelSize},'inputEncoding':{value:ENCODINGS[LinearEncoding]},'outputEncoding':{value:ENCODINGS[LinearEncoding]}},vertexShader:_getCommonVertexShader(),fragmentShader:/* glsl */"\n\n\t\t\tprecision mediump float;\n\t\t\tprecision mediump int;\n\n\t\t\tvarying vec3 vOutputDirection;\n\n\t\t\tuniform sampler2D envMap;\n\t\t\tuniform vec2 texelSize;\n\n\t\t\t".concat(_getEncodings(),"\n\n\t\t\t#include <common>\n\n\t\t\tvoid main() {\n\n\t\t\t\tgl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );\n\n\t\t\t\tvec3 outputDirection = normalize( vOutputDirection );\n\t\t\t\tvec2 uv = equirectUv( outputDirection );\n\n\t\t\t\tvec2 f = fract( uv / texelSize - 0.5 );\n\t\t\t\tuv -= f * texelSize;\n\t\t\t\tvec3 tl = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;\n\t\t\t\tuv.x += texelSize.x;\n\t\t\t\tvec3 tr = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;\n\t\t\t\tuv.y += texelSize.y;\n\t\t\t\tvec3 br = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;\n\t\t\t\tuv.x -= texelSize.x;\n\t\t\t\tvec3 bl = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;\n\n\t\t\t\tvec3 tm = mix( tl, tr, f.x );\n\t\t\t\tvec3 bm = mix( bl, br, f.x );\n\t\t\t\tgl_FragColor.rgb = mix( tm, bm, f.y );\n\n\t\t\t\tgl_FragColor = linearToOutputTexel( gl_FragColor );\n\n\t\t\t}\n\t\t"),blending:NoBlending,depthTest:false,depthWrite:false});return shaderMaterial;}function _getCubemapShader(){var shaderMaterial=new RawShaderMaterial({name:'CubemapToCubeUV',uniforms:{'envMap':{value:null},'inputEncoding':{value:ENCODINGS[LinearEncoding]},'outputEncoding':{value:ENCODINGS[LinearEncoding]}},vertexShader:_getCommonVertexShader(),fragmentShader:/* glsl */"\n\n\t\t\tprecision mediump float;\n\t\t\tprecision mediump int;\n\n\t\t\tvarying vec3 vOutputDirection;\n\n\t\t\tuniform samplerCube envMap;\n\n\t\t\t".concat(_getEncodings(),"\n\n\t\t\tvoid main() {\n\n\t\t\t\tgl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );\n\t\t\t\tgl_FragColor.rgb = envMapTexelToLinear( textureCube( envMap, vec3( - vOutputDirection.x, vOutputDirection.yz ) ) ).rgb;\n\t\t\t\tgl_FragColor = linearToOutputTexel( gl_FragColor );\n\n\t\t\t}\n\t\t"),blending:NoBlending,depthTest:false,depthWrite:false});return shaderMaterial;}function _getCommonVertexShader(){return/* glsl */"\n\n\t\tprecision mediump float;\n\t\tprecision mediump int;\n\n\t\tattribute vec3 position;\n\t\tattribute vec2 uv;\n\t\tattribute float faceIndex;\n\n\t\tvarying vec3 vOutputDirection;\n\n\t\t// RH coordinate system; PMREM face-indexing convention\n\t\tvec3 getDirection( vec2 uv, float face ) {\n\n\t\t\tuv = 2.0 * uv - 1.0;\n\n\t\t\tvec3 direction = vec3( uv, 1.0 );\n\n\t\t\tif ( face == 0.0 ) {\n\n\t\t\t\tdirection = direction.zyx; // ( 1, v, u ) pos x\n\n\t\t\t} else if ( face == 1.0 ) {\n\n\t\t\t\tdirection = direction.xzy;\n\t\t\t\tdirection.xz *= -1.0; // ( -u, 1, -v ) pos y\n\n\t\t\t} else if ( face == 2.0 ) {\n\n\t\t\t\tdirection.x *= -1.0; // ( -u, v, 1 ) pos z\n\n\t\t\t} else if ( face == 3.0 ) {\n\n\t\t\t\tdirection = direction.zyx;\n\t\t\t\tdirection.xz *= -1.0; // ( -1, v, -u ) neg x\n\n\t\t\t} else if ( face == 4.0 ) {\n\n\t\t\t\tdirection = direction.xzy;\n\t\t\t\tdirection.xy *= -1.0; // ( -u, -1, v ) neg y\n\n\t\t\t} else if ( face == 5.0 ) {\n\n\t\t\t\tdirection.z *= -1.0; // ( u, v, -1 ) neg z\n\n\t\t\t}\n\n\t\t\treturn direction;\n\n\t\t}\n\n\t\tvoid main() {\n\n\t\t\tvOutputDirection = getDirection( uv, faceIndex );\n\t\t\tgl_Position = vec4( position, 1.0 );\n\n\t\t}\n\t";}function _getEncodings(){return/* glsl */"\n\n\t\tuniform int inputEncoding;\n\t\tuniform int outputEncoding;\n\n\t\t#include <encodings_pars_fragment>\n\n\t\tvec4 inputTexelToLinear( vec4 value ) {\n\n\t\t\tif ( inputEncoding == 0 ) {\n\n\t\t\t\treturn value;\n\n\t\t\t} else if ( inputEncoding == 1 ) {\n\n\t\t\t\treturn sRGBToLinear( value );\n\n\t\t\t} else if ( inputEncoding == 2 ) {\n\n\t\t\t\treturn RGBEToLinear( value );\n\n\t\t\t} else if ( inputEncoding == 3 ) {\n\n\t\t\t\treturn RGBMToLinear( value, 7.0 );\n\n\t\t\t} else if ( inputEncoding == 4 ) {\n\n\t\t\t\treturn RGBMToLinear( value, 16.0 );\n\n\t\t\t} else if ( inputEncoding == 5 ) {\n\n\t\t\t\treturn RGBDToLinear( value, 256.0 );\n\n\t\t\t} else {\n\n\t\t\t\treturn GammaToLinear( value, 2.2 );\n\n\t\t\t}\n\n\t\t}\n\n\t\tvec4 linearToOutputTexel( vec4 value ) {\n\n\t\t\tif ( outputEncoding == 0 ) {\n\n\t\t\t\treturn value;\n\n\t\t\t} else if ( outputEncoding == 1 ) {\n\n\t\t\t\treturn LinearTosRGB( value );\n\n\t\t\t} else if ( outputEncoding == 2 ) {\n\n\t\t\t\treturn LinearToRGBE( value );\n\n\t\t\t} else if ( outputEncoding == 3 ) {\n\n\t\t\t\treturn LinearToRGBM( value, 7.0 );\n\n\t\t\t} else if ( outputEncoding == 4 ) {\n\n\t\t\t\treturn LinearToRGBM( value, 16.0 );\n\n\t\t\t} else if ( outputEncoding == 5 ) {\n\n\t\t\t\treturn LinearToRGBD( value, 256.0 );\n\n\t\t\t} else {\n\n\t\t\t\treturn LinearToGamma( value, 2.2 );\n\n\t\t\t}\n\n\t\t}\n\n\t\tvec4 envMapTexelToLinear( vec4 color ) {\n\n\t\t\treturn inputTexelToLinear( color );\n\n\t\t}\n\t";}function Face4(a,b,c,d,normal,color,materialIndex){console.warn('THREE.Face4 has been removed. A THREE.Face3 will be created instead.');return new Face3(a,b,c,normal,color,materialIndex);}var LineStrip=0;var LinePieces=1;var NoColors=0;var FaceColors=1;var VertexColors=2;function MeshFaceMaterial(materials){console.warn('THREE.MeshFaceMaterial has been removed. Use an Array instead.');return materials;}function MultiMaterial(){var materials=arguments.length>0&&arguments[0]!==undefined?arguments[0]:[];console.warn('THREE.MultiMaterial has been removed. Use an Array instead.');materials.isMultiMaterial=true;materials.materials=materials;materials.clone=function(){return materials.slice();};return materials;}function PointCloud(geometry,material){console.warn('THREE.PointCloud has been renamed to THREE.Points.');return new Points(geometry,material);}function Particle(material){console.warn('THREE.Particle has been renamed to THREE.Sprite.');return new Sprite$1(material);}function ParticleSystem(geometry,material){console.warn('THREE.ParticleSystem has been renamed to THREE.Points.');return new Points(geometry,material);}function PointCloudMaterial(parameters){console.warn('THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.');return new PointsMaterial(parameters);}function ParticleBasicMaterial(parameters){console.warn('THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.');return new PointsMaterial(parameters);}function ParticleSystemMaterial(parameters){console.warn('THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.');return new PointsMaterial(parameters);}function Vertex(x,y,z){console.warn('THREE.Vertex has been removed. Use THREE.Vector3 instead.');return new Vector3(x,y,z);}//
  2668. function DynamicBufferAttribute(array,itemSize){console.warn('THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setUsage( THREE.DynamicDrawUsage ) instead.');return new BufferAttribute(array,itemSize).setUsage(DynamicDrawUsage);}function Int8Attribute(array,itemSize){console.warn('THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.');return new Int8BufferAttribute(array,itemSize);}function Uint8Attribute(array,itemSize){console.warn('THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.');return new Uint8BufferAttribute(array,itemSize);}function Uint8ClampedAttribute(array,itemSize){console.warn('THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.');return new Uint8ClampedBufferAttribute(array,itemSize);}function Int16Attribute(array,itemSize){console.warn('THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.');return new Int16BufferAttribute(array,itemSize);}function Uint16Attribute(array,itemSize){console.warn('THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.');return new Uint16BufferAttribute(array,itemSize);}function Int32Attribute(array,itemSize){console.warn('THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.');return new Int32BufferAttribute(array,itemSize);}function Uint32Attribute(array,itemSize){console.warn('THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.');return new Uint32BufferAttribute(array,itemSize);}function Float32Attribute(array,itemSize){console.warn('THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.');return new Float32BufferAttribute(array,itemSize);}function Float64Attribute(array,itemSize){console.warn('THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.');return new Float64BufferAttribute(array,itemSize);}//
  2669. Curve.create=function(construct,getPoint){console.log('THREE.Curve.create() has been deprecated');construct.prototype=Object.create(Curve.prototype);construct.prototype.constructor=construct;construct.prototype.getPoint=getPoint;return construct;};//
  2670. Object.assign(CurvePath.prototype,{createPointsGeometry:function createPointsGeometry(divisions){console.warn('THREE.CurvePath: .createPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.');// generate geometry from path points (for Line or Points objects)
  2671. var pts=this.getPoints(divisions);return this.createGeometry(pts);},createSpacedPointsGeometry:function createSpacedPointsGeometry(divisions){console.warn('THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.');// generate geometry from equidistant sampling along the path
  2672. var pts=this.getSpacedPoints(divisions);return this.createGeometry(pts);},createGeometry:function createGeometry(points){console.warn('THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.');var geometry=new Geometry();for(var _i378=0,l=points.length;_i378<l;_i378++){var point=points[_i378];geometry.vertices.push(new Vector3(point.x,point.y,point.z||0));}return geometry;}});//
  2673. Object.assign(Path.prototype,{fromPoints:function fromPoints(points){console.warn('THREE.Path: .fromPoints() has been renamed to .setFromPoints().');return this.setFromPoints(points);}});//
  2674. function ClosedSplineCurve3(points){console.warn('THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');CatmullRomCurve3.call(this,points);this.type='catmullrom';this.closed=true;}ClosedSplineCurve3.prototype=Object.create(CatmullRomCurve3.prototype);//
  2675. function SplineCurve3(points){console.warn('THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');CatmullRomCurve3.call(this,points);this.type='catmullrom';}SplineCurve3.prototype=Object.create(CatmullRomCurve3.prototype);//
  2676. function Spline(points){console.warn('THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.');CatmullRomCurve3.call(this,points);this.type='catmullrom';}Spline.prototype=Object.create(CatmullRomCurve3.prototype);Object.assign(Spline.prototype,{initFromArray:function initFromArray(/* a */){console.error('THREE.Spline: .initFromArray() has been removed.');},getControlPointsArray:function getControlPointsArray(/* optionalTarget */){console.error('THREE.Spline: .getControlPointsArray() has been removed.');},reparametrizeByArcLength:function reparametrizeByArcLength(/* samplingCoef */){console.error('THREE.Spline: .reparametrizeByArcLength() has been removed.');}});//
  2677. function AxisHelper(size){console.warn('THREE.AxisHelper has been renamed to THREE.AxesHelper.');return new AxesHelper(size);}function BoundingBoxHelper(object,color){console.warn('THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.');return new BoxHelper(object,color);}function EdgesHelper(object,hex){console.warn('THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.');return new LineSegments(new EdgesGeometry(object.geometry),new LineBasicMaterial({color:hex!==undefined?hex:0xffffff}));}GridHelper.prototype.setColors=function(){console.error('THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.');};SkeletonHelper.prototype.update=function(){console.error('THREE.SkeletonHelper: update() no longer needs to be called.');};function WireframeHelper(object,hex){console.warn('THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.');return new LineSegments(new WireframeGeometry(object.geometry),new LineBasicMaterial({color:hex!==undefined?hex:0xffffff}));}//
  2678. Object.assign(Loader.prototype,{extractUrlBase:function extractUrlBase(url){console.warn('THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.');return LoaderUtils.extractUrlBase(url);}});Loader.Handlers={add:function add(/* regex, loader */){console.error('THREE.Loader: Handlers.add() has been removed. Use LoadingManager.addHandler() instead.');},get:function get(/* file */){console.error('THREE.Loader: Handlers.get() has been removed. Use LoadingManager.getHandler() instead.');}};function XHRLoader(manager){console.warn('THREE.XHRLoader has been renamed to THREE.FileLoader.');return new FileLoader(manager);}function BinaryTextureLoader(manager){console.warn('THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.');return new DataTextureLoader(manager);}//
  2679. Object.assign(Box2.prototype,{center:function center(optionalTarget){console.warn('THREE.Box2: .center() has been renamed to .getCenter().');return this.getCenter(optionalTarget);},empty:function empty(){console.warn('THREE.Box2: .empty() has been renamed to .isEmpty().');return this.isEmpty();},isIntersectionBox:function isIntersectionBox(box){console.warn('THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().');return this.intersectsBox(box);},size:function size(optionalTarget){console.warn('THREE.Box2: .size() has been renamed to .getSize().');return this.getSize(optionalTarget);}});Object.assign(Box3.prototype,{center:function center(optionalTarget){console.warn('THREE.Box3: .center() has been renamed to .getCenter().');return this.getCenter(optionalTarget);},empty:function empty(){console.warn('THREE.Box3: .empty() has been renamed to .isEmpty().');return this.isEmpty();},isIntersectionBox:function isIntersectionBox(box){console.warn('THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().');return this.intersectsBox(box);},isIntersectionSphere:function isIntersectionSphere(sphere){console.warn('THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().');return this.intersectsSphere(sphere);},size:function size(optionalTarget){console.warn('THREE.Box3: .size() has been renamed to .getSize().');return this.getSize(optionalTarget);}});Object.assign(Sphere.prototype,{empty:function empty(){console.warn('THREE.Sphere: .empty() has been renamed to .isEmpty().');return this.isEmpty();}});Frustum.prototype.setFromMatrix=function(m){console.warn('THREE.Frustum: .setFromMatrix() has been renamed to .setFromProjectionMatrix().');return this.setFromProjectionMatrix(m);};Line3.prototype.center=function(optionalTarget){console.warn('THREE.Line3: .center() has been renamed to .getCenter().');return this.getCenter(optionalTarget);};Object.assign(MathUtils,{random16:function random16(){console.warn('THREE.Math: .random16() has been deprecated. Use Math.random() instead.');return Math.random();},nearestPowerOfTwo:function nearestPowerOfTwo(value){console.warn('THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().');return MathUtils.floorPowerOfTwo(value);},nextPowerOfTwo:function nextPowerOfTwo(value){console.warn('THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().');return MathUtils.ceilPowerOfTwo(value);}});Object.assign(Matrix3.prototype,{flattenToArrayOffset:function flattenToArrayOffset(array,offset){console.warn('THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.');return this.toArray(array,offset);},multiplyVector3:function multiplyVector3(vector){console.warn('THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.');return vector.applyMatrix3(this);},multiplyVector3Array:function multiplyVector3Array(/* a */){console.error('THREE.Matrix3: .multiplyVector3Array() has been removed.');},applyToBufferAttribute:function applyToBufferAttribute(attribute){console.warn('THREE.Matrix3: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix3( matrix ) instead.');return attribute.applyMatrix3(this);},applyToVector3Array:function applyToVector3Array(/* array, offset, length */){console.error('THREE.Matrix3: .applyToVector3Array() has been removed.');},getInverse:function getInverse(matrix){console.warn('THREE.Matrix3: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.');return this.copy(matrix).invert();}});Object.assign(Matrix4.prototype,{extractPosition:function extractPosition(m){console.warn('THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().');return this.copyPosition(m);},flattenToArrayOffset:function flattenToArrayOffset(array,offset){console.warn('THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.');return this.toArray(array,offset);},getPosition:function getPosition(){console.warn('THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.');return new Vector3().setFromMatrixColumn(this,3);},setRotationFromQuaternion:function setRotationFromQuaternion(q){console.warn('THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().');return this.makeRotationFromQuaternion(q);},multiplyToArray:function multiplyToArray(){console.warn('THREE.Matrix4: .multiplyToArray() has been removed.');},multiplyVector3:function multiplyVector3(vector){console.warn('THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.');return vector.applyMatrix4(this);},multiplyVector4:function multiplyVector4(vector){console.warn('THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.');return vector.applyMatrix4(this);},multiplyVector3Array:function multiplyVector3Array(/* a */){console.error('THREE.Matrix4: .multiplyVector3Array() has been removed.');},rotateAxis:function rotateAxis(v){console.warn('THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.');v.transformDirection(this);},crossVector:function crossVector(vector){console.warn('THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.');return vector.applyMatrix4(this);},translate:function translate(){console.error('THREE.Matrix4: .translate() has been removed.');},rotateX:function rotateX(){console.error('THREE.Matrix4: .rotateX() has been removed.');},rotateY:function rotateY(){console.error('THREE.Matrix4: .rotateY() has been removed.');},rotateZ:function rotateZ(){console.error('THREE.Matrix4: .rotateZ() has been removed.');},rotateByAxis:function rotateByAxis(){console.error('THREE.Matrix4: .rotateByAxis() has been removed.');},applyToBufferAttribute:function applyToBufferAttribute(attribute){console.warn('THREE.Matrix4: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix4( matrix ) instead.');return attribute.applyMatrix4(this);},applyToVector3Array:function applyToVector3Array(/* array, offset, length */){console.error('THREE.Matrix4: .applyToVector3Array() has been removed.');},makeFrustum:function makeFrustum(left,right,bottom,top,near,far){console.warn('THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.');return this.makePerspective(left,right,top,bottom,near,far);},getInverse:function getInverse(matrix){console.warn('THREE.Matrix4: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.');return this.copy(matrix).invert();}});Plane.prototype.isIntersectionLine=function(line){console.warn('THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().');return this.intersectsLine(line);};Object.assign(Quaternion.prototype,{multiplyVector3:function multiplyVector3(vector){console.warn('THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.');return vector.applyQuaternion(this);},inverse:function inverse(){console.warn('THREE.Quaternion: .inverse() has been renamed to invert().');return this.invert();}});Object.assign(Ray.prototype,{isIntersectionBox:function isIntersectionBox(box){console.warn('THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().');return this.intersectsBox(box);},isIntersectionPlane:function isIntersectionPlane(plane){console.warn('THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().');return this.intersectsPlane(plane);},isIntersectionSphere:function isIntersectionSphere(sphere){console.warn('THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().');return this.intersectsSphere(sphere);}});Object.assign(Triangle.prototype,{area:function area(){console.warn('THREE.Triangle: .area() has been renamed to .getArea().');return this.getArea();},barycoordFromPoint:function barycoordFromPoint(point,target){console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');return this.getBarycoord(point,target);},midpoint:function midpoint(target){console.warn('THREE.Triangle: .midpoint() has been renamed to .getMidpoint().');return this.getMidpoint(target);},normal:function normal(target){console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');return this.getNormal(target);},plane:function plane(target){console.warn('THREE.Triangle: .plane() has been renamed to .getPlane().');return this.getPlane(target);}});Object.assign(Triangle,{barycoordFromPoint:function barycoordFromPoint(point,a,b,c,target){console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');return Triangle.getBarycoord(point,a,b,c,target);},normal:function normal(a,b,c,target){console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');return Triangle.getNormal(a,b,c,target);}});Object.assign(Shape.prototype,{extractAllPoints:function extractAllPoints(divisions){console.warn('THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.');return this.extractPoints(divisions);},extrude:function extrude(options){console.warn('THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.');return new ExtrudeGeometry(this,options);},makeGeometry:function makeGeometry(options){console.warn('THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.');return new ShapeGeometry(this,options);}});Object.assign(Vector2.prototype,{fromAttribute:function fromAttribute(attribute,index,offset){console.warn('THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().');return this.fromBufferAttribute(attribute,index,offset);},distanceToManhattan:function distanceToManhattan(v){console.warn('THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');return this.manhattanDistanceTo(v);},lengthManhattan:function lengthManhattan(){console.warn('THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().');return this.manhattanLength();}});Object.assign(Vector3.prototype,{setEulerFromRotationMatrix:function setEulerFromRotationMatrix(){console.error('THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.');},setEulerFromQuaternion:function setEulerFromQuaternion(){console.error('THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.');},getPositionFromMatrix:function getPositionFromMatrix(m){console.warn('THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().');return this.setFromMatrixPosition(m);},getScaleFromMatrix:function getScaleFromMatrix(m){console.warn('THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().');return this.setFromMatrixScale(m);},getColumnFromMatrix:function getColumnFromMatrix(index,matrix){console.warn('THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().');return this.setFromMatrixColumn(matrix,index);},applyProjection:function applyProjection(m){console.warn('THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.');return this.applyMatrix4(m);},fromAttribute:function fromAttribute(attribute,index,offset){console.warn('THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().');return this.fromBufferAttribute(attribute,index,offset);},distanceToManhattan:function distanceToManhattan(v){console.warn('THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');return this.manhattanDistanceTo(v);},lengthManhattan:function lengthManhattan(){console.warn('THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().');return this.manhattanLength();}});Object.assign(Vector4.prototype,{fromAttribute:function fromAttribute(attribute,index,offset){console.warn('THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().');return this.fromBufferAttribute(attribute,index,offset);},lengthManhattan:function lengthManhattan(){console.warn('THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().');return this.manhattanLength();}});//
  2680. Object.assign(Geometry.prototype,{computeTangents:function computeTangents(){console.error('THREE.Geometry: .computeTangents() has been removed.');},computeLineDistances:function computeLineDistances(){console.error('THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.');},applyMatrix:function applyMatrix(matrix){console.warn('THREE.Geometry: .applyMatrix() has been renamed to .applyMatrix4().');return this.applyMatrix4(matrix);}});Object.assign(Object3D.prototype,{getChildByName:function getChildByName(name){console.warn('THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().');return this.getObjectByName(name);},renderDepth:function renderDepth(){console.warn('THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.');},translate:function translate(distance,axis){console.warn('THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.');return this.translateOnAxis(axis,distance);},getWorldRotation:function getWorldRotation(){console.error('THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.');},applyMatrix:function applyMatrix(matrix){console.warn('THREE.Object3D: .applyMatrix() has been renamed to .applyMatrix4().');return this.applyMatrix4(matrix);}});Object.defineProperties(Object3D.prototype,{eulerOrder:{get:function get(){console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');return this.rotation.order;},set:function set(value){console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');this.rotation.order=value;}},useQuaternion:{get:function get(){console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');},set:function set(){console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');}}});Object.assign(Mesh.prototype,{setDrawMode:function setDrawMode(){console.error('THREE.Mesh: .setDrawMode() has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');}});Object.defineProperties(Mesh.prototype,{drawMode:{get:function get(){console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode.');return TrianglesDrawMode;},set:function set(){console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');}}});Object.defineProperties(LOD.prototype,{objects:{get:function get(){console.warn('THREE.LOD: .objects has been renamed to .levels.');return this.levels;}}});Object.defineProperty(Skeleton.prototype,'useVertexTexture',{get:function get(){console.warn('THREE.Skeleton: useVertexTexture has been removed.');},set:function set(){console.warn('THREE.Skeleton: useVertexTexture has been removed.');}});SkinnedMesh.prototype.initBones=function(){console.error('THREE.SkinnedMesh: initBones() has been removed.');};Object.defineProperty(Curve.prototype,'__arcLengthDivisions',{get:function get(){console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');return this.arcLengthDivisions;},set:function set(value){console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');this.arcLengthDivisions=value;}});//
  2681. PerspectiveCamera.prototype.setLens=function(focalLength,filmGauge){console.warn('THREE.PerspectiveCamera.setLens is deprecated. '+'Use .setFocalLength and .filmGauge for a photographic setup.');if(filmGauge!==undefined)this.filmGauge=filmGauge;this.setFocalLength(focalLength);};//
  2682. Object.defineProperties(Light.prototype,{onlyShadow:{set:function set(){console.warn('THREE.Light: .onlyShadow has been removed.');}},shadowCameraFov:{set:function set(value){console.warn('THREE.Light: .shadowCameraFov is now .shadow.camera.fov.');this.shadow.camera.fov=value;}},shadowCameraLeft:{set:function set(value){console.warn('THREE.Light: .shadowCameraLeft is now .shadow.camera.left.');this.shadow.camera.left=value;}},shadowCameraRight:{set:function set(value){console.warn('THREE.Light: .shadowCameraRight is now .shadow.camera.right.');this.shadow.camera.right=value;}},shadowCameraTop:{set:function set(value){console.warn('THREE.Light: .shadowCameraTop is now .shadow.camera.top.');this.shadow.camera.top=value;}},shadowCameraBottom:{set:function set(value){console.warn('THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.');this.shadow.camera.bottom=value;}},shadowCameraNear:{set:function set(value){console.warn('THREE.Light: .shadowCameraNear is now .shadow.camera.near.');this.shadow.camera.near=value;}},shadowCameraFar:{set:function set(value){console.warn('THREE.Light: .shadowCameraFar is now .shadow.camera.far.');this.shadow.camera.far=value;}},shadowCameraVisible:{set:function set(){console.warn('THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.');}},shadowBias:{set:function set(value){console.warn('THREE.Light: .shadowBias is now .shadow.bias.');this.shadow.bias=value;}},shadowDarkness:{set:function set(){console.warn('THREE.Light: .shadowDarkness has been removed.');}},shadowMapWidth:{set:function set(value){console.warn('THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.');this.shadow.mapSize.width=value;}},shadowMapHeight:{set:function set(value){console.warn('THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.');this.shadow.mapSize.height=value;}}});//
  2683. Object.defineProperties(BufferAttribute.prototype,{length:{get:function get(){console.warn('THREE.BufferAttribute: .length has been deprecated. Use .count instead.');return this.array.length;}},dynamic:{get:function get(){console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');return this.usage===DynamicDrawUsage;},set:function set(/* value */){console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');this.setUsage(DynamicDrawUsage);}}});Object.assign(BufferAttribute.prototype,{setDynamic:function setDynamic(value){//console.warn( 'THREE.BufferAttribute: .setDynamic() has been deprecated. Use .setUsage() instead.' );
  2684. this.setUsage(value===true?DynamicDrawUsage:StaticDrawUsage);return this;},copyIndicesArray:function copyIndicesArray(/* indices */){console.error('THREE.BufferAttribute: .copyIndicesArray() has been removed.');},setArray:function setArray(/* array */){console.error('THREE.BufferAttribute: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');}});Object.assign(BufferGeometry.prototype,{addIndex:function addIndex(index){console.warn('THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().');this.setIndex(index);},addAttribute:function addAttribute(name,attribute){console.warn('THREE.BufferGeometry: .addAttribute() has been renamed to .setAttribute().');if(!(attribute&&attribute.isBufferAttribute)&&!(attribute&&attribute.isInterleavedBufferAttribute)){console.warn('THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).');return this.setAttribute(name,new BufferAttribute(arguments[1],arguments[2]));}if(name==='index'){console.warn('THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.');this.setIndex(attribute);return this;}return this.setAttribute(name,attribute);},addDrawCall:function addDrawCall(start,count,indexOffset){if(indexOffset!==undefined){console.warn('THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.');}console.warn('THREE.BufferGeometry: .addDrawCall() is now .addGroup().');this.addGroup(start,count);},clearDrawCalls:function clearDrawCalls(){console.warn('THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().');this.clearGroups();},computeTangents:function computeTangents(){console.warn('THREE.BufferGeometry: .computeTangents() has been removed.');},computeOffsets:function computeOffsets(){console.warn('THREE.BufferGeometry: .computeOffsets() has been removed.');},removeAttribute:function removeAttribute(name){console.warn('THREE.BufferGeometry: .removeAttribute() has been renamed to .deleteAttribute().');return this.deleteAttribute(name);},applyMatrix:function applyMatrix(matrix){console.warn('THREE.BufferGeometry: .applyMatrix() has been renamed to .applyMatrix4().');return this.applyMatrix4(matrix);}});Object.defineProperties(BufferGeometry.prototype,{drawcalls:{get:function get(){console.error('THREE.BufferGeometry: .drawcalls has been renamed to .groups.');return this.groups;}},offsets:{get:function get(){console.warn('THREE.BufferGeometry: .offsets has been renamed to .groups.');return this.groups;}}});Object.defineProperties(InstancedBufferGeometry.prototype,{maxInstancedCount:{get:function get(){console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');return this.instanceCount;},set:function set(value){console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');this.instanceCount=value;}}});Object.defineProperties(Raycaster.prototype,{linePrecision:{get:function get(){console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');return this.params.Line.threshold;},set:function set(value){console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');this.params.Line.threshold=value;}}});Object.defineProperties(InterleavedBuffer.prototype,{dynamic:{get:function get(){console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');return this.usage===DynamicDrawUsage;},set:function set(value){console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');this.setUsage(value);}}});Object.assign(InterleavedBuffer.prototype,{setDynamic:function setDynamic(value){console.warn('THREE.InterleavedBuffer: .setDynamic() has been deprecated. Use .setUsage() instead.');this.setUsage(value===true?DynamicDrawUsage:StaticDrawUsage);return this;},setArray:function setArray(/* array */){console.error('THREE.InterleavedBuffer: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');}});//
  2685. Object.assign(ExtrudeBufferGeometry.prototype,{getArrays:function getArrays(){console.error('THREE.ExtrudeBufferGeometry: .getArrays() has been removed.');},addShapeList:function addShapeList(){console.error('THREE.ExtrudeBufferGeometry: .addShapeList() has been removed.');},addShape:function addShape(){console.error('THREE.ExtrudeBufferGeometry: .addShape() has been removed.');}});//
  2686. Object.assign(Scene.prototype,{dispose:function dispose(){console.error('THREE.Scene: .dispose() has been removed.');}});//
  2687. Object.defineProperties(Uniform.prototype,{dynamic:{set:function set(){console.warn('THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.');}},onUpdate:{value:function value(){console.warn('THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.');return this;}}});//
  2688. Object.defineProperties(Material.prototype,{wrapAround:{get:function get(){console.warn('THREE.Material: .wrapAround has been removed.');},set:function set(){console.warn('THREE.Material: .wrapAround has been removed.');}},overdraw:{get:function get(){console.warn('THREE.Material: .overdraw has been removed.');},set:function set(){console.warn('THREE.Material: .overdraw has been removed.');}},wrapRGB:{get:function get(){console.warn('THREE.Material: .wrapRGB has been removed.');return new Color();}},shading:{get:function get(){console.error('THREE.'+this.type+': .shading has been removed. Use the boolean .flatShading instead.');},set:function set(value){console.warn('THREE.'+this.type+': .shading has been removed. Use the boolean .flatShading instead.');this.flatShading=value===FlatShading$1;}},stencilMask:{get:function get(){console.warn('THREE.'+this.type+': .stencilMask has been removed. Use .stencilFuncMask instead.');return this.stencilFuncMask;},set:function set(value){console.warn('THREE.'+this.type+': .stencilMask has been removed. Use .stencilFuncMask instead.');this.stencilFuncMask=value;}}});Object.defineProperties(MeshPhongMaterial.prototype,{metal:{get:function get(){console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.');return false;},set:function set(){console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead');}}});Object.defineProperties(MeshPhysicalMaterial.prototype,{transparency:{get:function get(){console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');return this.transmission;},set:function set(value){console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');this.transmission=value;}}});Object.defineProperties(ShaderMaterial.prototype,{derivatives:{get:function get(){console.warn('THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');return this.extensions.derivatives;},set:function set(value){console.warn('THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');this.extensions.derivatives=value;}}});//
  2689. Object.assign(WebGLRenderer.prototype,{clearTarget:function clearTarget(renderTarget,color,depth,stencil){console.warn('THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.');this.setRenderTarget(renderTarget);this.clear(color,depth,stencil);},animate:function animate(callback){console.warn('THREE.WebGLRenderer: .animate() is now .setAnimationLoop().');this.setAnimationLoop(callback);},getCurrentRenderTarget:function getCurrentRenderTarget(){console.warn('THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().');return this.getRenderTarget();},getMaxAnisotropy:function getMaxAnisotropy(){console.warn('THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().');return this.capabilities.getMaxAnisotropy();},getPrecision:function getPrecision(){console.warn('THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.');return this.capabilities.precision;},resetGLState:function resetGLState(){console.warn('THREE.WebGLRenderer: .resetGLState() is now .state.reset().');return this.state.reset();},supportsFloatTextures:function supportsFloatTextures(){console.warn('THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).');return this.extensions.get('OES_texture_float');},supportsHalfFloatTextures:function supportsHalfFloatTextures(){console.warn('THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).');return this.extensions.get('OES_texture_half_float');},supportsStandardDerivatives:function supportsStandardDerivatives(){console.warn('THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).');return this.extensions.get('OES_standard_derivatives');},supportsCompressedTextureS3TC:function supportsCompressedTextureS3TC(){console.warn('THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).');return this.extensions.get('WEBGL_compressed_texture_s3tc');},supportsCompressedTexturePVRTC:function supportsCompressedTexturePVRTC(){console.warn('THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).');return this.extensions.get('WEBGL_compressed_texture_pvrtc');},supportsBlendMinMax:function supportsBlendMinMax(){console.warn('THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).');return this.extensions.get('EXT_blend_minmax');},supportsVertexTextures:function supportsVertexTextures(){console.warn('THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.');return this.capabilities.vertexTextures;},supportsInstancedArrays:function supportsInstancedArrays(){console.warn('THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).');return this.extensions.get('ANGLE_instanced_arrays');},enableScissorTest:function enableScissorTest(boolean){console.warn('THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().');this.setScissorTest(boolean);},initMaterial:function initMaterial(){console.warn('THREE.WebGLRenderer: .initMaterial() has been removed.');},addPrePlugin:function addPrePlugin(){console.warn('THREE.WebGLRenderer: .addPrePlugin() has been removed.');},addPostPlugin:function addPostPlugin(){console.warn('THREE.WebGLRenderer: .addPostPlugin() has been removed.');},updateShadowMap:function updateShadowMap(){console.warn('THREE.WebGLRenderer: .updateShadowMap() has been removed.');},setFaceCulling:function setFaceCulling(){console.warn('THREE.WebGLRenderer: .setFaceCulling() has been removed.');},allocTextureUnit:function allocTextureUnit(){console.warn('THREE.WebGLRenderer: .allocTextureUnit() has been removed.');},setTexture:function setTexture(){console.warn('THREE.WebGLRenderer: .setTexture() has been removed.');},setTexture2D:function setTexture2D(){console.warn('THREE.WebGLRenderer: .setTexture2D() has been removed.');},setTextureCube:function setTextureCube(){console.warn('THREE.WebGLRenderer: .setTextureCube() has been removed.');},getActiveMipMapLevel:function getActiveMipMapLevel(){console.warn('THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().');return this.getActiveMipmapLevel();}});Object.defineProperties(WebGLRenderer.prototype,{shadowMapEnabled:{get:function get(){return this.shadowMap.enabled;},set:function set(value){console.warn('THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.');this.shadowMap.enabled=value;}},shadowMapType:{get:function get(){return this.shadowMap.type;},set:function set(value){console.warn('THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.');this.shadowMap.type=value;}},shadowMapCullFace:{get:function get(){console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');return undefined;},set:function set(/* value */){console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');}},context:{get:function get(){console.warn('THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.');return this.getContext();}},vr:{get:function get(){console.warn('THREE.WebGLRenderer: .vr has been renamed to .xr');return this.xr;}},gammaInput:{get:function get(){console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');return false;},set:function set(){console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');}},gammaOutput:{get:function get(){console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');return false;},set:function set(value){console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');this.outputEncoding=value===true?sRGBEncoding:LinearEncoding;}},toneMappingWhitePoint:{get:function get(){console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');return 1.0;},set:function set(){console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');}}});Object.defineProperties(WebGLShadowMap.prototype,{cullFace:{get:function get(){console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');return undefined;},set:function set(/* cullFace */){console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');}},renderReverseSided:{get:function get(){console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');return undefined;},set:function set(){console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');}},renderSingleSided:{get:function get(){console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');return undefined;},set:function set(){console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');}}});function WebGLRenderTargetCube(width,height,options){console.warn('THREE.WebGLRenderTargetCube( width, height, options ) is now WebGLCubeRenderTarget( size, options ).');return new WebGLCubeRenderTarget(width,options);}//
  2690. Object.defineProperties(WebGLRenderTarget.prototype,{wrapS:{get:function get(){console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');return this.texture.wrapS;},set:function set(value){console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');this.texture.wrapS=value;}},wrapT:{get:function get(){console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');return this.texture.wrapT;},set:function set(value){console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');this.texture.wrapT=value;}},magFilter:{get:function get(){console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');return this.texture.magFilter;},set:function set(value){console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');this.texture.magFilter=value;}},minFilter:{get:function get(){console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');return this.texture.minFilter;},set:function set(value){console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');this.texture.minFilter=value;}},anisotropy:{get:function get(){console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');return this.texture.anisotropy;},set:function set(value){console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');this.texture.anisotropy=value;}},offset:{get:function get(){console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');return this.texture.offset;},set:function set(value){console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');this.texture.offset=value;}},repeat:{get:function get(){console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');return this.texture.repeat;},set:function set(value){console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');this.texture.repeat=value;}},format:{get:function get(){console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');return this.texture.format;},set:function set(value){console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');this.texture.format=value;}},type:{get:function get(){console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');return this.texture.type;},set:function set(value){console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');this.texture.type=value;}},generateMipmaps:{get:function get(){console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');return this.texture.generateMipmaps;},set:function set(value){console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');this.texture.generateMipmaps=value;}}});//
  2691. Object.defineProperties(Audio.prototype,{load:{value:function value(file){console.warn('THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.');var scope=this;var audioLoader=new AudioLoader();audioLoader.load(file,function(buffer){scope.setBuffer(buffer);});return this;}},startTime:{set:function set(){console.warn('THREE.Audio: .startTime is now .play( delay ).');}}});AudioAnalyser.prototype.getData=function(){console.warn('THREE.AudioAnalyser: .getData() is now .getFrequencyData().');return this.getFrequencyData();};//
  2692. CubeCamera.prototype.updateCubeMap=function(renderer,scene){console.warn('THREE.CubeCamera: .updateCubeMap() is now .update().');return this.update(renderer,scene);};CubeCamera.prototype.clear=function(renderer,color,depth,stencil){console.warn('THREE.CubeCamera: .clear() is now .renderTarget.clear().');return this.renderTarget.clear(renderer,color,depth,stencil);};//
  2693. var GeometryUtils={merge:function merge(geometry1,geometry2,materialIndexOffset){console.warn('THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.');var matrix;if(geometry2.isMesh){geometry2.matrixAutoUpdate&&geometry2.updateMatrix();matrix=geometry2.matrix;geometry2=geometry2.geometry;}geometry1.merge(geometry2,matrix,materialIndexOffset);},center:function center(geometry){console.warn('THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.');return geometry.center();}};ImageUtils.crossOrigin=undefined;ImageUtils.loadTexture=function(url,mapping,onLoad,onError){console.warn('THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.');var loader=new TextureLoader();loader.setCrossOrigin(this.crossOrigin);var texture=loader.load(url,onLoad,undefined,onError);if(mapping)texture.mapping=mapping;return texture;};ImageUtils.loadTextureCube=function(urls,mapping,onLoad,onError){console.warn('THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.');var loader=new CubeTextureLoader();loader.setCrossOrigin(this.crossOrigin);var texture=loader.load(urls,onLoad,undefined,onError);if(mapping)texture.mapping=mapping;return texture;};ImageUtils.loadCompressedTexture=function(){console.error('THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.');};ImageUtils.loadCompressedTextureCube=function(){console.error('THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.');};//
  2694. function CanvasRenderer(){console.error('THREE.CanvasRenderer has been removed');}//
  2695. function JSONLoader(){console.error('THREE.JSONLoader has been removed.');}//
  2696. var SceneUtils={createMultiMaterialObject:function createMultiMaterialObject(/* geometry, materials */){console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');},detach:function detach(/* child, parent, scene */){console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');},attach:function attach(/* child, scene, parent */){console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');}};//
  2697. function LensFlare(){console.error('THREE.LensFlare has been moved to /examples/jsm/objects/Lensflare.js');}if(typeof __THREE_DEVTOOLS__!=='undefined'){/* eslint-disable no-undef */__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('register',{detail:{revision:REVISION}}));/* eslint-enable no-undef */}
  2698. var THREE$1 = /*#__PURE__*/Object.freeze({
  2699. __proto__: null,
  2700. ACESFilmicToneMapping: ACESFilmicToneMapping,
  2701. AddEquation: AddEquation,
  2702. AddOperation: AddOperation,
  2703. AdditiveAnimationBlendMode: AdditiveAnimationBlendMode,
  2704. AdditiveBlending: AdditiveBlending,
  2705. AlphaFormat: AlphaFormat,
  2706. AlwaysDepth: AlwaysDepth,
  2707. AlwaysStencilFunc: AlwaysStencilFunc,
  2708. AmbientLight: AmbientLight,
  2709. AmbientLightProbe: AmbientLightProbe,
  2710. AnimationClip: AnimationClip,
  2711. AnimationLoader: AnimationLoader,
  2712. AnimationMixer: AnimationMixer,
  2713. AnimationObjectGroup: AnimationObjectGroup,
  2714. AnimationUtils: AnimationUtils,
  2715. ArcCurve: ArcCurve,
  2716. ArrayCamera: ArrayCamera,
  2717. ArrowHelper: ArrowHelper,
  2718. Audio: Audio,
  2719. AudioAnalyser: AudioAnalyser,
  2720. AudioContext: AudioContext,
  2721. AudioListener: AudioListener,
  2722. AudioLoader: AudioLoader,
  2723. AxesHelper: AxesHelper,
  2724. AxisHelper: AxisHelper,
  2725. BackSide: BackSide,
  2726. BasicDepthPacking: BasicDepthPacking,
  2727. BasicShadowMap: BasicShadowMap,
  2728. BinaryTextureLoader: BinaryTextureLoader,
  2729. Bone: Bone,
  2730. BooleanKeyframeTrack: BooleanKeyframeTrack,
  2731. BoundingBoxHelper: BoundingBoxHelper,
  2732. Box2: Box2,
  2733. Box3: Box3,
  2734. Box3Helper: Box3Helper,
  2735. BoxBufferGeometry: BoxBufferGeometry,
  2736. BoxGeometry: BoxGeometry,
  2737. BoxHelper: BoxHelper,
  2738. BufferAttribute: BufferAttribute,
  2739. BufferGeometry: BufferGeometry,
  2740. BufferGeometryLoader: BufferGeometryLoader,
  2741. ByteType: ByteType,
  2742. Cache: Cache,
  2743. Camera: Camera,
  2744. CameraHelper: CameraHelper,
  2745. CanvasRenderer: CanvasRenderer,
  2746. CanvasTexture: CanvasTexture,
  2747. CatmullRomCurve3: CatmullRomCurve3,
  2748. CineonToneMapping: CineonToneMapping,
  2749. CircleBufferGeometry: CircleBufferGeometry,
  2750. CircleGeometry: CircleGeometry,
  2751. ClampToEdgeWrapping: ClampToEdgeWrapping,
  2752. Clock: Clock,
  2753. ClosedSplineCurve3: ClosedSplineCurve3,
  2754. Color: Color,
  2755. ColorKeyframeTrack: ColorKeyframeTrack,
  2756. CompressedTexture: CompressedTexture,
  2757. CompressedTextureLoader: CompressedTextureLoader,
  2758. ConeBufferGeometry: ConeBufferGeometry,
  2759. ConeGeometry: ConeGeometry,
  2760. CubeCamera: CubeCamera,
  2761. CubeGeometry: BoxGeometry,
  2762. CubeReflectionMapping: CubeReflectionMapping,
  2763. CubeRefractionMapping: CubeRefractionMapping,
  2764. CubeTexture: CubeTexture,
  2765. CubeTextureLoader: CubeTextureLoader,
  2766. CubeUVReflectionMapping: CubeUVReflectionMapping,
  2767. CubeUVRefractionMapping: CubeUVRefractionMapping,
  2768. CubicBezierCurve: CubicBezierCurve,
  2769. CubicBezierCurve3: CubicBezierCurve3,
  2770. CubicInterpolant: CubicInterpolant,
  2771. CullFaceBack: CullFaceBack,
  2772. CullFaceFront: CullFaceFront,
  2773. CullFaceFrontBack: CullFaceFrontBack,
  2774. CullFaceNone: CullFaceNone,
  2775. Curve: Curve,
  2776. CurvePath: CurvePath,
  2777. CustomBlending: CustomBlending,
  2778. CustomToneMapping: CustomToneMapping,
  2779. CylinderBufferGeometry: CylinderBufferGeometry,
  2780. CylinderGeometry: CylinderGeometry,
  2781. Cylindrical: Cylindrical,
  2782. DataTexture: DataTexture,
  2783. DataTexture2DArray: DataTexture2DArray,
  2784. DataTexture3D: DataTexture3D,
  2785. DataTextureLoader: DataTextureLoader,
  2786. DataUtils: DataUtils,
  2787. DecrementStencilOp: DecrementStencilOp,
  2788. DecrementWrapStencilOp: DecrementWrapStencilOp,
  2789. DefaultLoadingManager: DefaultLoadingManager,
  2790. DepthFormat: DepthFormat,
  2791. DepthStencilFormat: DepthStencilFormat,
  2792. DepthTexture: DepthTexture,
  2793. DirectionalLight: DirectionalLight,
  2794. DirectionalLightHelper: DirectionalLightHelper,
  2795. DiscreteInterpolant: DiscreteInterpolant,
  2796. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  2797. DodecahedronGeometry: DodecahedronGeometry,
  2798. DoubleSide: DoubleSide,
  2799. DstAlphaFactor: DstAlphaFactor,
  2800. DstColorFactor: DstColorFactor,
  2801. DynamicBufferAttribute: DynamicBufferAttribute,
  2802. DynamicCopyUsage: DynamicCopyUsage,
  2803. DynamicDrawUsage: DynamicDrawUsage,
  2804. DynamicReadUsage: DynamicReadUsage,
  2805. EdgesGeometry: EdgesGeometry,
  2806. EdgesHelper: EdgesHelper,
  2807. EllipseCurve: EllipseCurve,
  2808. EqualDepth: EqualDepth,
  2809. EqualStencilFunc: EqualStencilFunc,
  2810. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  2811. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  2812. Euler: Euler,
  2813. EventDispatcher: EventDispatcher,
  2814. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  2815. ExtrudeGeometry: ExtrudeGeometry,
  2816. Face3: Face3,
  2817. Face4: Face4,
  2818. FaceColors: FaceColors,
  2819. FileLoader: FileLoader,
  2820. FlatShading: FlatShading$1,
  2821. Float16BufferAttribute: Float16BufferAttribute,
  2822. Float32Attribute: Float32Attribute,
  2823. Float32BufferAttribute: Float32BufferAttribute,
  2824. Float64Attribute: Float64Attribute,
  2825. Float64BufferAttribute: Float64BufferAttribute,
  2826. FloatType: FloatType,
  2827. Fog: Fog,
  2828. FogExp2: FogExp2,
  2829. Font: Font,
  2830. FontLoader: FontLoader,
  2831. FrontSide: FrontSide,
  2832. Frustum: Frustum,
  2833. GLBufferAttribute: GLBufferAttribute,
  2834. GLSL1: GLSL1,
  2835. GLSL3: GLSL3,
  2836. GammaEncoding: GammaEncoding,
  2837. Geometry: Geometry,
  2838. GeometryUtils: GeometryUtils,
  2839. GreaterDepth: GreaterDepth,
  2840. GreaterEqualDepth: GreaterEqualDepth,
  2841. GreaterEqualStencilFunc: GreaterEqualStencilFunc,
  2842. GreaterStencilFunc: GreaterStencilFunc,
  2843. GridHelper: GridHelper,
  2844. Group: Group,
  2845. HalfFloatType: HalfFloatType,
  2846. HemisphereLight: HemisphereLight,
  2847. HemisphereLightHelper: HemisphereLightHelper,
  2848. HemisphereLightProbe: HemisphereLightProbe,
  2849. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  2850. IcosahedronGeometry: IcosahedronGeometry,
  2851. ImageBitmapLoader: ImageBitmapLoader,
  2852. ImageLoader: ImageLoader,
  2853. ImageUtils: ImageUtils,
  2854. ImmediateRenderObject: ImmediateRenderObject,
  2855. IncrementStencilOp: IncrementStencilOp,
  2856. IncrementWrapStencilOp: IncrementWrapStencilOp,
  2857. InstancedBufferAttribute: InstancedBufferAttribute,
  2858. InstancedBufferGeometry: InstancedBufferGeometry,
  2859. InstancedInterleavedBuffer: InstancedInterleavedBuffer,
  2860. InstancedMesh: InstancedMesh,
  2861. Int16Attribute: Int16Attribute,
  2862. Int16BufferAttribute: Int16BufferAttribute,
  2863. Int32Attribute: Int32Attribute,
  2864. Int32BufferAttribute: Int32BufferAttribute,
  2865. Int8Attribute: Int8Attribute,
  2866. Int8BufferAttribute: Int8BufferAttribute,
  2867. IntType: IntType,
  2868. InterleavedBuffer: InterleavedBuffer,
  2869. InterleavedBufferAttribute: InterleavedBufferAttribute,
  2870. Interpolant: Interpolant,
  2871. InterpolateDiscrete: InterpolateDiscrete,
  2872. InterpolateLinear: InterpolateLinear,
  2873. InterpolateSmooth: InterpolateSmooth,
  2874. InvertStencilOp: InvertStencilOp,
  2875. JSONLoader: JSONLoader,
  2876. KeepStencilOp: KeepStencilOp,
  2877. KeyframeTrack: KeyframeTrack,
  2878. LOD: LOD,
  2879. LatheBufferGeometry: LatheBufferGeometry,
  2880. LatheGeometry: LatheGeometry,
  2881. Layers: Layers,
  2882. LensFlare: LensFlare,
  2883. LessDepth: LessDepth,
  2884. LessEqualDepth: LessEqualDepth,
  2885. LessEqualStencilFunc: LessEqualStencilFunc,
  2886. LessStencilFunc: LessStencilFunc,
  2887. Light: Light,
  2888. LightProbe: LightProbe,
  2889. Line: Line,
  2890. Line3: Line3,
  2891. LineBasicMaterial: LineBasicMaterial,
  2892. LineCurve: LineCurve,
  2893. LineCurve3: LineCurve3,
  2894. LineDashedMaterial: LineDashedMaterial,
  2895. LineLoop: LineLoop,
  2896. LinePieces: LinePieces,
  2897. LineSegments: LineSegments,
  2898. LineStrip: LineStrip,
  2899. LinearEncoding: LinearEncoding,
  2900. LinearFilter: LinearFilter,
  2901. LinearInterpolant: LinearInterpolant,
  2902. LinearMipMapLinearFilter: LinearMipMapLinearFilter,
  2903. LinearMipMapNearestFilter: LinearMipMapNearestFilter,
  2904. LinearMipmapLinearFilter: LinearMipmapLinearFilter,
  2905. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  2906. LinearToneMapping: LinearToneMapping,
  2907. Loader: Loader,
  2908. LoaderUtils: LoaderUtils,
  2909. LoadingManager: LoadingManager,
  2910. LogLuvEncoding: LogLuvEncoding,
  2911. LoopOnce: LoopOnce,
  2912. LoopPingPong: LoopPingPong,
  2913. LoopRepeat: LoopRepeat,
  2914. LuminanceAlphaFormat: LuminanceAlphaFormat,
  2915. LuminanceFormat: LuminanceFormat,
  2916. MOUSE: MOUSE,
  2917. Material: Material,
  2918. MaterialLoader: MaterialLoader,
  2919. Math: MathUtils,
  2920. MathUtils: MathUtils,
  2921. Matrix3: Matrix3,
  2922. Matrix4: Matrix4,
  2923. MaxEquation: MaxEquation,
  2924. Mesh: Mesh,
  2925. MeshBasicMaterial: MeshBasicMaterial,
  2926. MeshDepthMaterial: MeshDepthMaterial,
  2927. MeshDistanceMaterial: MeshDistanceMaterial,
  2928. MeshFaceMaterial: MeshFaceMaterial,
  2929. MeshLambertMaterial: MeshLambertMaterial,
  2930. MeshMatcapMaterial: MeshMatcapMaterial,
  2931. MeshNormalMaterial: MeshNormalMaterial,
  2932. MeshPhongMaterial: MeshPhongMaterial,
  2933. MeshPhysicalMaterial: MeshPhysicalMaterial,
  2934. MeshStandardMaterial: MeshStandardMaterial,
  2935. MeshToonMaterial: MeshToonMaterial,
  2936. MinEquation: MinEquation,
  2937. MirroredRepeatWrapping: MirroredRepeatWrapping,
  2938. MixOperation: MixOperation,
  2939. MultiMaterial: MultiMaterial,
  2940. MultiplyBlending: MultiplyBlending,
  2941. MultiplyOperation: MultiplyOperation,
  2942. NearestFilter: NearestFilter,
  2943. NearestMipMapLinearFilter: NearestMipMapLinearFilter,
  2944. NearestMipMapNearestFilter: NearestMipMapNearestFilter,
  2945. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  2946. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  2947. NeverDepth: NeverDepth,
  2948. NeverStencilFunc: NeverStencilFunc,
  2949. NoBlending: NoBlending,
  2950. NoColors: NoColors,
  2951. NoToneMapping: NoToneMapping,
  2952. NormalAnimationBlendMode: NormalAnimationBlendMode,
  2953. NormalBlending: NormalBlending,
  2954. NotEqualDepth: NotEqualDepth,
  2955. NotEqualStencilFunc: NotEqualStencilFunc,
  2956. NumberKeyframeTrack: NumberKeyframeTrack,
  2957. Object3D: Object3D,
  2958. ObjectLoader: ObjectLoader,
  2959. ObjectSpaceNormalMap: ObjectSpaceNormalMap,
  2960. OctahedronBufferGeometry: OctahedronBufferGeometry,
  2961. OctahedronGeometry: OctahedronGeometry,
  2962. OneFactor: OneFactor,
  2963. OneMinusDstAlphaFactor: OneMinusDstAlphaFactor,
  2964. OneMinusDstColorFactor: OneMinusDstColorFactor,
  2965. OneMinusSrcAlphaFactor: OneMinusSrcAlphaFactor,
  2966. OneMinusSrcColorFactor: OneMinusSrcColorFactor,
  2967. OrthographicCamera: OrthographicCamera,
  2968. PCFShadowMap: PCFShadowMap,
  2969. PCFSoftShadowMap: PCFSoftShadowMap,
  2970. PMREMGenerator: PMREMGenerator,
  2971. ParametricBufferGeometry: ParametricBufferGeometry,
  2972. ParametricGeometry: ParametricGeometry,
  2973. Particle: Particle,
  2974. ParticleBasicMaterial: ParticleBasicMaterial,
  2975. ParticleSystem: ParticleSystem,
  2976. ParticleSystemMaterial: ParticleSystemMaterial,
  2977. Path: Path,
  2978. PerspectiveCamera: PerspectiveCamera,
  2979. Plane: Plane,
  2980. PlaneBufferGeometry: PlaneBufferGeometry,
  2981. PlaneGeometry: PlaneGeometry,
  2982. PlaneHelper: PlaneHelper,
  2983. PointCloud: PointCloud,
  2984. PointCloudMaterial: PointCloudMaterial,
  2985. PointLight: PointLight,
  2986. PointLightHelper: PointLightHelper,
  2987. Points: Points,
  2988. PointsMaterial: PointsMaterial,
  2989. PolarGridHelper: PolarGridHelper,
  2990. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  2991. PolyhedronGeometry: PolyhedronGeometry,
  2992. PositionalAudio: PositionalAudio,
  2993. PropertyBinding: PropertyBinding,
  2994. PropertyMixer: PropertyMixer,
  2995. QuadraticBezierCurve: QuadraticBezierCurve,
  2996. QuadraticBezierCurve3: QuadraticBezierCurve3,
  2997. Quaternion: Quaternion,
  2998. QuaternionKeyframeTrack: QuaternionKeyframeTrack,
  2999. QuaternionLinearInterpolant: QuaternionLinearInterpolant,
  3000. REVISION: REVISION,
  3001. RGBADepthPacking: RGBADepthPacking,
  3002. RGBAFormat: RGBAFormat,
  3003. RGBAIntegerFormat: RGBAIntegerFormat,
  3004. RGBA_ASTC_10x10_Format: RGBA_ASTC_10x10_Format,
  3005. RGBA_ASTC_10x5_Format: RGBA_ASTC_10x5_Format,
  3006. RGBA_ASTC_10x6_Format: RGBA_ASTC_10x6_Format,
  3007. RGBA_ASTC_10x8_Format: RGBA_ASTC_10x8_Format,
  3008. RGBA_ASTC_12x10_Format: RGBA_ASTC_12x10_Format,
  3009. RGBA_ASTC_12x12_Format: RGBA_ASTC_12x12_Format,
  3010. RGBA_ASTC_4x4_Format: RGBA_ASTC_4x4_Format,
  3011. RGBA_ASTC_5x4_Format: RGBA_ASTC_5x4_Format,
  3012. RGBA_ASTC_5x5_Format: RGBA_ASTC_5x5_Format,
  3013. RGBA_ASTC_6x5_Format: RGBA_ASTC_6x5_Format,
  3014. RGBA_ASTC_6x6_Format: RGBA_ASTC_6x6_Format,
  3015. RGBA_ASTC_8x5_Format: RGBA_ASTC_8x5_Format,
  3016. RGBA_ASTC_8x6_Format: RGBA_ASTC_8x6_Format,
  3017. RGBA_ASTC_8x8_Format: RGBA_ASTC_8x8_Format,
  3018. RGBA_BPTC_Format: RGBA_BPTC_Format,
  3019. RGBA_ETC2_EAC_Format: RGBA_ETC2_EAC_Format,
  3020. RGBA_PVRTC_2BPPV1_Format: RGBA_PVRTC_2BPPV1_Format,
  3021. RGBA_PVRTC_4BPPV1_Format: RGBA_PVRTC_4BPPV1_Format,
  3022. RGBA_S3TC_DXT1_Format: RGBA_S3TC_DXT1_Format$1,
  3023. RGBA_S3TC_DXT3_Format: RGBA_S3TC_DXT3_Format,
  3024. RGBA_S3TC_DXT5_Format: RGBA_S3TC_DXT5_Format$1,
  3025. RGBDEncoding: RGBDEncoding,
  3026. RGBEEncoding: RGBEEncoding,
  3027. RGBEFormat: RGBEFormat,
  3028. RGBFormat: RGBFormat,
  3029. RGBIntegerFormat: RGBIntegerFormat,
  3030. RGBM16Encoding: RGBM16Encoding,
  3031. RGBM7Encoding: RGBM7Encoding,
  3032. RGB_ETC1_Format: RGB_ETC1_Format,
  3033. RGB_ETC2_Format: RGB_ETC2_Format,
  3034. RGB_PVRTC_2BPPV1_Format: RGB_PVRTC_2BPPV1_Format,
  3035. RGB_PVRTC_4BPPV1_Format: RGB_PVRTC_4BPPV1_Format,
  3036. RGB_S3TC_DXT1_Format: RGB_S3TC_DXT1_Format,
  3037. RGFormat: RGFormat,
  3038. RGIntegerFormat: RGIntegerFormat,
  3039. RawShaderMaterial: RawShaderMaterial,
  3040. Ray: Ray,
  3041. Raycaster: Raycaster,
  3042. RectAreaLight: RectAreaLight,
  3043. RedFormat: RedFormat,
  3044. RedIntegerFormat: RedIntegerFormat,
  3045. ReinhardToneMapping: ReinhardToneMapping,
  3046. RepeatWrapping: RepeatWrapping,
  3047. ReplaceStencilOp: ReplaceStencilOp,
  3048. ReverseSubtractEquation: ReverseSubtractEquation,
  3049. RingBufferGeometry: RingBufferGeometry,
  3050. RingGeometry: RingGeometry,
  3051. SRGB8_ALPHA8_ASTC_10x10_Format: SRGB8_ALPHA8_ASTC_10x10_Format,
  3052. SRGB8_ALPHA8_ASTC_10x5_Format: SRGB8_ALPHA8_ASTC_10x5_Format,
  3053. SRGB8_ALPHA8_ASTC_10x6_Format: SRGB8_ALPHA8_ASTC_10x6_Format,
  3054. SRGB8_ALPHA8_ASTC_10x8_Format: SRGB8_ALPHA8_ASTC_10x8_Format,
  3055. SRGB8_ALPHA8_ASTC_12x10_Format: SRGB8_ALPHA8_ASTC_12x10_Format,
  3056. SRGB8_ALPHA8_ASTC_12x12_Format: SRGB8_ALPHA8_ASTC_12x12_Format,
  3057. SRGB8_ALPHA8_ASTC_4x4_Format: SRGB8_ALPHA8_ASTC_4x4_Format,
  3058. SRGB8_ALPHA8_ASTC_5x4_Format: SRGB8_ALPHA8_ASTC_5x4_Format,
  3059. SRGB8_ALPHA8_ASTC_5x5_Format: SRGB8_ALPHA8_ASTC_5x5_Format,
  3060. SRGB8_ALPHA8_ASTC_6x5_Format: SRGB8_ALPHA8_ASTC_6x5_Format,
  3061. SRGB8_ALPHA8_ASTC_6x6_Format: SRGB8_ALPHA8_ASTC_6x6_Format,
  3062. SRGB8_ALPHA8_ASTC_8x5_Format: SRGB8_ALPHA8_ASTC_8x5_Format,
  3063. SRGB8_ALPHA8_ASTC_8x6_Format: SRGB8_ALPHA8_ASTC_8x6_Format,
  3064. SRGB8_ALPHA8_ASTC_8x8_Format: SRGB8_ALPHA8_ASTC_8x8_Format,
  3065. Scene: Scene,
  3066. SceneUtils: SceneUtils,
  3067. ShaderChunk: ShaderChunk,
  3068. ShaderLib: ShaderLib,
  3069. ShaderMaterial: ShaderMaterial,
  3070. ShadowMaterial: ShadowMaterial,
  3071. Shape: Shape,
  3072. ShapeBufferGeometry: ShapeBufferGeometry,
  3073. ShapeGeometry: ShapeGeometry,
  3074. ShapePath: ShapePath,
  3075. ShapeUtils: ShapeUtils,
  3076. ShortType: ShortType,
  3077. Skeleton: Skeleton,
  3078. SkeletonHelper: SkeletonHelper,
  3079. SkinnedMesh: SkinnedMesh,
  3080. SmoothShading: SmoothShading,
  3081. Sphere: Sphere,
  3082. SphereBufferGeometry: SphereBufferGeometry,
  3083. SphereGeometry: SphereGeometry,
  3084. Spherical: Spherical,
  3085. SphericalHarmonics3: SphericalHarmonics3,
  3086. Spline: Spline,
  3087. SplineCurve: SplineCurve,
  3088. SplineCurve3: SplineCurve3,
  3089. SpotLight: SpotLight,
  3090. SpotLightHelper: SpotLightHelper,
  3091. Sprite: Sprite$1,
  3092. SpriteMaterial: SpriteMaterial,
  3093. SrcAlphaFactor: SrcAlphaFactor,
  3094. SrcAlphaSaturateFactor: SrcAlphaSaturateFactor,
  3095. SrcColorFactor: SrcColorFactor,
  3096. StaticCopyUsage: StaticCopyUsage,
  3097. StaticDrawUsage: StaticDrawUsage,
  3098. StaticReadUsage: StaticReadUsage,
  3099. StereoCamera: StereoCamera,
  3100. StreamCopyUsage: StreamCopyUsage,
  3101. StreamDrawUsage: StreamDrawUsage,
  3102. StreamReadUsage: StreamReadUsage,
  3103. StringKeyframeTrack: StringKeyframeTrack,
  3104. SubtractEquation: SubtractEquation,
  3105. SubtractiveBlending: SubtractiveBlending,
  3106. TOUCH: TOUCH,
  3107. TangentSpaceNormalMap: TangentSpaceNormalMap,
  3108. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  3109. TetrahedronGeometry: TetrahedronGeometry,
  3110. TextBufferGeometry: TextBufferGeometry,
  3111. TextGeometry: TextGeometry,
  3112. Texture: Texture,
  3113. TextureLoader: TextureLoader,
  3114. TorusBufferGeometry: TorusBufferGeometry,
  3115. TorusGeometry: TorusGeometry,
  3116. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  3117. TorusKnotGeometry: TorusKnotGeometry,
  3118. Triangle: Triangle,
  3119. TriangleFanDrawMode: TriangleFanDrawMode,
  3120. TriangleStripDrawMode: TriangleStripDrawMode,
  3121. TrianglesDrawMode: TrianglesDrawMode,
  3122. TubeBufferGeometry: TubeBufferGeometry,
  3123. TubeGeometry: TubeGeometry,
  3124. UVMapping: UVMapping,
  3125. Uint16Attribute: Uint16Attribute,
  3126. Uint16BufferAttribute: Uint16BufferAttribute,
  3127. Uint32Attribute: Uint32Attribute,
  3128. Uint32BufferAttribute: Uint32BufferAttribute,
  3129. Uint8Attribute: Uint8Attribute,
  3130. Uint8BufferAttribute: Uint8BufferAttribute,
  3131. Uint8ClampedAttribute: Uint8ClampedAttribute,
  3132. Uint8ClampedBufferAttribute: Uint8ClampedBufferAttribute,
  3133. Uniform: Uniform,
  3134. UniformsLib: UniformsLib,
  3135. UniformsUtils: UniformsUtils,
  3136. UnsignedByteType: UnsignedByteType,
  3137. UnsignedInt248Type: UnsignedInt248Type$1,
  3138. UnsignedIntType: UnsignedIntType,
  3139. UnsignedShort4444Type: UnsignedShort4444Type,
  3140. UnsignedShort5551Type: UnsignedShort5551Type,
  3141. UnsignedShort565Type: UnsignedShort565Type,
  3142. UnsignedShortType: UnsignedShortType,
  3143. VSMShadowMap: VSMShadowMap,
  3144. Vector2: Vector2,
  3145. Vector3: Vector3,
  3146. Vector4: Vector4,
  3147. VectorKeyframeTrack: VectorKeyframeTrack,
  3148. Vertex: Vertex,
  3149. VertexColors: VertexColors,
  3150. VideoTexture: VideoTexture,
  3151. WebGL1Renderer: WebGL1Renderer,
  3152. WebGLCubeRenderTarget: WebGLCubeRenderTarget,
  3153. WebGLMultisampleRenderTarget: WebGLMultisampleRenderTarget,
  3154. WebGLRenderTarget: WebGLRenderTarget,
  3155. WebGLRenderTargetCube: WebGLRenderTargetCube,
  3156. WebGLRenderer: WebGLRenderer,
  3157. WebGLUtils: WebGLUtils,
  3158. WireframeGeometry: WireframeGeometry,
  3159. WireframeHelper: WireframeHelper,
  3160. WrapAroundEnding: WrapAroundEnding,
  3161. XHRLoader: XHRLoader,
  3162. ZeroCurvatureEnding: ZeroCurvatureEnding,
  3163. ZeroFactor: ZeroFactor,
  3164. ZeroSlopeEnding: ZeroSlopeEnding,
  3165. ZeroStencilOp: ZeroStencilOp,
  3166. sRGBEncoding: sRGBEncoding
  3167. });
  3168. var points = [];
  3169. var lines = [];
  3170. var rings = [];
  3171. var precision = 0.1; //容错精度 //正常是0.01 但是在编辑时容易出现交错的线看不出来,导致需要getSliceLines 然后多出新增点
  3172. var getPoint = function getPoint(o, type) {
  3173. var point;
  3174. if (typeof o == "string" || typeof o == "number") point = points.find(p => p.ids.includes(o));else {
  3175. point = points.find(p => math.closeTo(p.x, o.x, precision) && math.closeTo(p.y, o.y, precision));
  3176. if (!point) point = new Point(o.x, o.y, {
  3177. record: true,
  3178. id: o.id
  3179. }, type);else {
  3180. //console.log('addPoint', point, o)
  3181. point.addPoint(o.id);
  3182. }
  3183. }
  3184. if (!point) {
  3185. console.log("no point!");
  3186. }
  3187. return point;
  3188. };
  3189. var getLine = function getLine(id) {
  3190. return lines.find(line => line.ids.includes(id));
  3191. };
  3192. var getAngleInfo = function getAngleInfo(points) {
  3193. var info = {};
  3194. info.angle = points[1].clone().sub(points[0]).angle();
  3195. if (math.closeTo(info.angle, Math.PI * 2)) {
  3196. //如360-0.01
  3197. info.angle -= Math.PI * 2; //有可能得到负数-0.001
  3198. } else if (info.angle > Math.PI || math.closeTo(info.angle, Math.PI)) {
  3199. //如180+-0.01
  3200. info.angle -= Math.PI;
  3201. info.reverse = true;
  3202. }
  3203. return info; //结果大约是 0 - 3.14
  3204. };
  3205. class Point extends Vector2 {
  3206. constructor(x, y) {
  3207. var o = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  3208. super(x, y);
  3209. if (o.record) {
  3210. this.id = o.id;
  3211. if (this.id == void 0) this.id = "add_" + points.length;
  3212. this.ids = [this.id]; //存储拥有该坐标的点原始数据的id
  3213. points.push(this);
  3214. }
  3215. this.type = o.type || "";
  3216. this.lines = [];
  3217. }
  3218. addPoint(id) {
  3219. this.ids.push(id);
  3220. }
  3221. searchLineByFactor(dir, type, comeLine) {
  3222. var lines = this.lines.filter(line => line.searchTime < 2);
  3223. if (lines.length == 0) return;else if (lines.length == 1) return lines[0];else lines = lines.filter(line => line != comeLine);
  3224. if (lines.length == 1) return lines[0];
  3225. var result;
  3226. lines.forEach(line => {
  3227. var vec = line.getVector();
  3228. if (line.points[1] == this) vec.negate();
  3229. var factor = math.getVec2Angle(dir, vec);
  3230. if (new Vector3(dir.x, dir.y, 0).cross(new Vector3(vec.x, vec.y, 0)).z < 0) factor *= -1; /////
  3231. if (!result) {
  3232. result = {
  3233. line,
  3234. factor
  3235. };
  3236. } else {
  3237. if (type == "min" && factor < result.factor || type == "max" && factor > result.factor) result = {
  3238. line,
  3239. factor
  3240. };
  3241. }
  3242. });
  3243. return result.line;
  3244. }
  3245. }
  3246. var lineLen = 0;
  3247. class Line$1 {
  3248. constructor(o) {
  3249. if (o.points[0] == o.points[1]) return;
  3250. this.points = o.points;
  3251. this.type = o.type || 'line';
  3252. if (this.type == 'line') {
  3253. var oldLine = lines.find(line => line.points.includes(o.points[0]) && line.points.includes(o.points[1]));
  3254. if (oldLine) {
  3255. o.id != void 0 && oldLine.ids.push(o.id);
  3256. return oldLine;
  3257. }
  3258. this.id = o.id == void 0 ? "line" + lineLen++ : o.id;
  3259. this.ids = [this.id];
  3260. o.dontWriteToPoint || this.points.forEach(point => {
  3261. point.lines.push(this);
  3262. });
  3263. o.isChild || lines.push(this);
  3264. this.searchTime = 0; // 最多两次
  3265. }
  3266. this.children = []; //分割
  3267. this.parents = []; //分割
  3268. this.match = [];
  3269. }
  3270. getAngleInfo() {
  3271. var angleInfo = getAngleInfo(this.points);
  3272. this.angle = angleInfo.angle;
  3273. this.reverse = angleInfo.reverse;
  3274. }
  3275. getIntersectWithLine(line, precision) {
  3276. var joint = line.points.find(point => this.points.includes(point));
  3277. if (joint) return {
  3278. point: joint,
  3279. type: "joint"
  3280. };
  3281. var intersect = math.isLineIntersect(line.points, this.points, false, precision);
  3282. if (intersect) return {
  3283. point: intersect,
  3284. type: "intersect"
  3285. };
  3286. }
  3287. writeToPoint() {
  3288. this.points.forEach(point => {
  3289. point.lines.includes(this) || point.lines.push(this);
  3290. });
  3291. }
  3292. checkIfParent(line) {
  3293. if (this == line) {
  3294. return true; //原因就是slice的点和端点很近 误差导致
  3295. } else return this.parents.find(e => e.checkIfParent(line));
  3296. }
  3297. splitByPoint(point) {
  3298. var line1 = new Line$1({
  3299. points: [point, this.points[0]],
  3300. dontWriteToPoint: true,
  3301. hasntsure: true
  3302. });
  3303. var line2 = new Line$1({
  3304. points: [point, this.points[1]],
  3305. dontWriteToPoint: true,
  3306. hasntsure: true
  3307. });
  3308. if (!line1.points || !line2.points) {
  3309. //有至少一个是点相同的,没写到group.lines里
  3310. console.warn('splitByPoint 线有点相同');
  3311. return;
  3312. }
  3313. if (this.checkIfParent(line1) || this.checkIfParent(line2) || line1.checkIfParent(this) || line2.checkIfParent(this)) {
  3314. console.warn("splitByPoint 发现parent和children一样"); //,请检查getSliceWalls,尤其 if(math.closeTo(line1.angle,line2.angle)){ 处
  3315. return;
  3316. }
  3317. var deal = line => {
  3318. this.children.push(line);
  3319. line.parents.push(this);
  3320. if (!lines.includes(line)) lines.push(line);
  3321. line.writeToPoint();
  3322. };
  3323. deal(line1);
  3324. deal(line2);
  3325. var index = this.points[0].lines.indexOf(this);
  3326. index > -1 && this.points[0].lines.splice(index, 1);
  3327. var index = this.points[1].lines.indexOf(this);
  3328. index > -1 && this.points[1].lines.splice(index, 1);
  3329. return [line1, line2];
  3330. }
  3331. splitByPoints(points) {
  3332. points = points.map(point => {
  3333. return {
  3334. dis: point.distanceTo(this.points[0]),
  3335. point: point
  3336. };
  3337. });
  3338. points.sort((point1, point2) => {
  3339. return point1.dis - point2.dis;
  3340. });
  3341. var children = [];
  3342. points.forEach((point, index) => {
  3343. var line1 = new Line$1({
  3344. points: [point.point, index == 0 ? this.points[0] : points[index - 1].point],
  3345. group: this.group,
  3346. dontWriteToPoint: true,
  3347. hasntsure: true
  3348. });
  3349. children.push(line1);
  3350. });
  3351. var line2 = new Line$1({
  3352. points: [points[points.length - 1].point, this.points[1]],
  3353. group: this.group,
  3354. dontWriteToPoint: true,
  3355. hasntsure: true
  3356. });
  3357. children.push(line2);
  3358. var a = children.find(line => !line.points || this.checkIfParent(line) || line.checkIfParent(this));
  3359. if (a) {
  3360. console.error("splitByPoints return");
  3361. return;
  3362. }
  3363. children.forEach(line => {
  3364. this.children.push(line);
  3365. line.parents.push(this);
  3366. if (!lines.includes(line)) lines.push(line);
  3367. line.writeToPoint();
  3368. line.writeToPoint();
  3369. });
  3370. var index = this.points[0].lines.indexOf(this);
  3371. index > -1 && this.points[0].lines.splice(index, 1);
  3372. var index = this.points[1].lines.indexOf(this);
  3373. index > -1 && this.points[1].lines.splice(index, 1);
  3374. }
  3375. getAllSlices() {
  3376. //如果有被分割的片段 就返回片段,否则返回自身
  3377. var children = [];
  3378. var _traverse = function traverse(elem) {
  3379. if (elem.children.length == 0) children.push(elem);else elem.children.forEach(_traverse);
  3380. };
  3381. _traverse(this);
  3382. return children;
  3383. }
  3384. getVector() {
  3385. return this.points[1].clone().sub(this.points[0]);
  3386. }
  3387. getLength() {
  3388. return this.points[0].distanceTo(this.points[1]);
  3389. }
  3390. getCenter() {
  3391. return this.points[1].clone().add(this.points[0]).multiplyScalar(.5);
  3392. }
  3393. }
  3394. var getMixedSet = function getMixedSet(arr1, arr2) {
  3395. //交集
  3396. return arr1.filter(item => arr2.includes(item));
  3397. };
  3398. var getUnionSet = function getUnionSet(arr1, arr2) {
  3399. //并集
  3400. return arr1.concat(arr2.filter(item => !arr1.includes(item)));
  3401. };
  3402. var getDifferenceSet = function getDifferenceSet(arr1, arr2) {
  3403. //差集
  3404. var arr11 = arr1.filter(item => !arr2.includes(item));
  3405. var arr22 = arr2.filter(item => !arr1.includes(item));
  3406. return arr11.concat(arr22);
  3407. };
  3408. var getDifferenceSetMuti = function getDifferenceSetMuti(arr) {
  3409. //收集绝对没有重复的元素,也就是判断出现次数=1的
  3410. var set = [];
  3411. arr.forEach(arr1 => {
  3412. arr1.forEach(item => {
  3413. var index = set.indexOf(item);
  3414. if (index > -1) {
  3415. set.splice(index, 1);
  3416. } else {
  3417. set.push(item);
  3418. }
  3419. });
  3420. });
  3421. return set;
  3422. };
  3423. function DoorAtWhichLine(points, lines) {
  3424. var mid = points[0].clone().add(points[1]).multiplyScalar(0.5);
  3425. lines = lines.filter(line => math.ifPointAtLineBound(mid, line.points, precision));
  3426. if (lines.length == 0) return;
  3427. var result = {
  3428. line: null,
  3429. dis: Infinity
  3430. };
  3431. lines.forEach(line => {
  3432. var foot = math.getFootPoint(mid, line.points[0], line.points[1]);
  3433. var dis = foot.distanceTo(mid);
  3434. if (dis < result.dis) {
  3435. result.line = line;
  3436. result.dis = dis;
  3437. }
  3438. });
  3439. return result;
  3440. }
  3441. var ringLen = 0;
  3442. class Ring {
  3443. constructor(o) {
  3444. this.id = ringLen++;
  3445. this.type = o.type || 'normal';
  3446. this.points = o.points;
  3447. this.lines = o.lines;
  3448. rings.push(this);
  3449. this.child = []; //包含的环
  3450. this.parent = []; //被包含的环
  3451. this.smallNeibours = []; //相邻最小环(存在和它有一个以上的相同边的最小环)
  3452. var area = math.getArea(this.points);
  3453. this.area = Math.abs(area);
  3454. this.isClockwise = area < 0; //是否逆时针。一般都是逆时针得到的,如果是顺时针,可能是贪吃蛇的情况,可能不是最小环,需要去掉。
  3455. }
  3456. }
  3457. var findLine = function findLine(p1, p2) {
  3458. return lines.find(line => line.points.includes(p1) && line.points.includes(p2));
  3459. };
  3460. var ifSamePart = function ifSamePart(checkPart, part) {
  3461. //checkPart中所包含的part片段是否和基准part的顺序一样(逆序也可以, 中间有其他数也可以,起始不同也行。比如 01234和204一样的)
  3462. var axis,
  3463. startIndex,
  3464. newCheckPart = [];
  3465. for (var j = 0, len1 = checkPart.length; j < len1; j++) {
  3466. //将checkPart中比part多的数除去,使两个数组中包含的数完全相同。
  3467. if (part.indexOf(checkPart[j]) > -1) newCheckPart.push(checkPart[j]);
  3468. }
  3469. for (var i = 0, len = part.length; i < len; i++) {
  3470. var index = newCheckPart.indexOf(part[i]);
  3471. if (index == -1) return false;
  3472. if (i == 0) startIndex = index; //标记第一个查找点对应的index
  3473. else if (i == 1) {
  3474. //标记查找顺序是正还是逆
  3475. axis = index - startIndex;
  3476. if (axis == len - 1) axis = -1; //刚好是首和尾
  3477. else if (axis == 1 - len) axis = 1;
  3478. if (axis != -1 && axis != 1) {
  3479. return false;
  3480. }
  3481. } else {
  3482. //判断是否是按顺序的
  3483. if (index != (startIndex + axis * i + len) % len) return false;
  3484. }
  3485. }
  3486. return {
  3487. sameAxis: axis > 0
  3488. }; //如果一样的话返回正逆是否相同
  3489. };
  3490. //或者判断是否有相同边(但是相同点是可以组成不同环)
  3491. var ifSameRing = function ifSameRing(ring1, ring2) {
  3492. //判断两个环是否相等。 除了可以逆向外顺序要对
  3493. if (ring1 instanceof Ring) ring1 = ring1.points;
  3494. if (ring2 instanceof Ring) ring2 = ring2.points;
  3495. if (ring1.length != ring2.length) return false;
  3496. if (ring1.lines && ring2.lines) {
  3497. if (getDifferenceSet(ring1.lines, ring2.lines).length == 0) return true; //差集个数为0
  3498. } else {
  3499. if (ifSamePart(ring1, ring2)) return true;
  3500. }
  3501. };
  3502. var _atWhichChildLine = function atWhichChildLine(point, line, precision) {
  3503. if (line.children.length == 0) {
  3504. //这里可能要放低精度 保证能找到
  3505. if (math.ifPointAtLineBound(point, line.points, precision)) return line;
  3506. } else {
  3507. for (var i = 0; i < line.children.length; i++) {
  3508. var at = _atWhichChildLine(point, line.children[i], precision);
  3509. if (at) return at;
  3510. }
  3511. }
  3512. };
  3513. function getSliceLines() {
  3514. var len = lines.length;
  3515. var _deal = function deal(line1, line2) {
  3516. if (line1 == line2) return;
  3517. if (line1.angle == void 0) line1.getAngleInfo();
  3518. if (line2.angle == void 0) line2.getAngleInfo();
  3519. var intersect = line1.getIntersectWithLine(line2, precision);
  3520. if (intersect) {
  3521. var point; //得到交点
  3522. if (intersect.type == "intersect") {
  3523. point = getPoint(intersect.point, "whenGetSliceLines");
  3524. var line1_ = _atWhichChildLine(point, line1);
  3525. var line2_ = _atWhichChildLine(point, line2);
  3526. //重合的情况还没考虑(平行)
  3527. if (!line1_) line1_ = _atWhichChildLine(point, line1, precision); //降低精度
  3528. if (!line1_) line1_ = _atWhichChildLine(point, line1, precision * 2); //降低精度
  3529. if (!line2_) line2_ = _atWhichChildLine(point, line2, precision);
  3530. if (!line2_) line2_ = _atWhichChildLine(point, line2, precision * 2); //降低精度
  3531. //拆分线条:
  3532. //如果还报错,找不到ChildLine,就直接返回吧 或者搞个循环 逐渐降低精度
  3533. if (!line1_ || !line2_) {
  3534. console.warn("atWhichChildLine仍旧找不到 :" + line1.id + ',' + line2.id + ", pointId: " + point.id);
  3535. line1_ || console.warn("找不到line1");
  3536. line2_ || console.warn("找不到line2");
  3537. return;
  3538. }
  3539. if (line1_.points.find(p => p == point) && line2_.points.find(p => p == point)) {//这个点是line1_、 line2_端点,不做处理
  3540. //console.log("joint型 "+point.id)
  3541. } else if (line1_.points.find(p => p == point)) {
  3542. //T型交叉
  3543. line2_.splitByPoint(point); //加入到母线中,之后还先用母线判断交点
  3544. //console.log("T型交叉1 "+point.id)
  3545. } else if (line2_.points.find(p => p == point)) {
  3546. //T型交叉
  3547. line1_.splitByPoint(point);
  3548. //console.log("T型交叉2 "+point.id)
  3549. } else {
  3550. //十字交叉
  3551. line1_.splitByPoint(point);
  3552. line2_.splitByPoint(point);
  3553. }
  3554. } else {
  3555. point = intersect.point; //交点是端点
  3556. if (math.closeTo(line1.angle, line2.angle)) {
  3557. //重合一部分
  3558. var children1 = line1.getAllSlices();
  3559. var children2 = line2.getAllSlices();
  3560. if (children1.length > 1 || children2.length > 1) {
  3561. //使用最小分割片段来比较
  3562. children1.forEach(child1 => {
  3563. children2.forEach(child2 => {
  3564. _deal(child1, child2);
  3565. });
  3566. });
  3567. return;
  3568. }
  3569. var anotherPoint1 = line1.points.find(point_ => point_ != point);
  3570. var anotherPoint2 = line2.points.find(point_ => point_ != point);
  3571. if (math.ifPointAtLineBound(anotherPoint1, line2.points)) {
  3572. line2.splitByPoint(anotherPoint1);
  3573. } else if (math.ifPointAtLineBound(anotherPoint2, line1.points)) {
  3574. line1.splitByPoint(anotherPoint2);
  3575. }
  3576. }
  3577. }
  3578. } else if (math.closeTo(line1.angle, line2.angle)) {
  3579. var vec1 = line1.getVector();
  3580. var vec = line1.points[0].clone().sub(line2.points[0]);
  3581. var cos = math.getVec2Cos(vec1, vec);
  3582. if (math.closeTo(cos, -1, 1e-4) || math.closeTo(cos, 1, 1e-4)) {
  3583. //共线
  3584. var children1 = line1.getAllSlices();
  3585. var children2 = line2.getAllSlices();
  3586. if (children1.length > 1 || children2.length > 1) {
  3587. //使用最小分割片段来比较
  3588. children1.forEach(child1 => {
  3589. children2.forEach(child2 => {
  3590. _deal(child1, child2);
  3591. });
  3592. });
  3593. return;
  3594. }
  3595. //判断是否重叠
  3596. var A = line1.points[0];
  3597. var C = line1.reverse == line2.reverse ? line2.points[0] : line2.points[1];
  3598. var B = line1.points[1];
  3599. var D = line1.reverse == line2.reverse ? line2.points[1] : line2.points[0];
  3600. var BC = C.clone().sub(B);
  3601. var AD = D.clone().sub(A);
  3602. if (BC.length() < AD.length()) {
  3603. var BA = A.clone().sub(B);
  3604. if (math.getVec2Angle(BC, BA) >= 1.57) return; //没有重叠部分
  3605. } else {
  3606. var AB = B.clone().sub(A);
  3607. if (math.getVec2Angle(AD, AB) >= 1.57) return;
  3608. }
  3609. var f = function f(line1, line2) {
  3610. var one = math.ifPointAtLineBound(line1.points[0], line2.points);
  3611. var two = math.ifPointAtLineBound(line1.points[1], line2.points);
  3612. if (one && two) {
  3613. //line1在line2上
  3614. line2.splitByPoints(line1.points);
  3615. return true;
  3616. } else if (one || two) {
  3617. //错开
  3618. var point1 = one ? line1.points[0] : line1.points[1];
  3619. var anotherPoint1 = one ? line1.points[1] : line1.points[0];
  3620. var dis1 = line2.points[0].distanceTo(anotherPoint1);
  3621. var dis2 = line2.points[1].distanceTo(anotherPoint1);
  3622. var point2 = dis1 < dis2 ? line2.points[0] : line2.points[1];
  3623. line1.splitByPoint(point2);
  3624. line2.splitByPoint(point1);
  3625. return true;
  3626. }
  3627. };
  3628. f(line1, line2) || f(line2, line1);
  3629. }
  3630. }
  3631. };
  3632. for (var i = 0; i < len; i++) {
  3633. var line1 = lines[i];
  3634. for (var j = i + 1; j < len; j++) {
  3635. var line2 = lines[j];
  3636. _deal(line1, line2);
  3637. }
  3638. }
  3639. //console.log("原有线条个数:"+len)
  3640. //lines = lines.filter((line)=>{return line.children.length == 0})
  3641. //console.log("现有线条个数:"+lines.length)
  3642. }
  3643. var bound = new Box2();
  3644. var build = function build(o) {
  3645. //融合了相近点
  3646. //根据bound 处理precision
  3647. o.points.forEach(p => {
  3648. bound.expandByPoint(new Vector2(p.x, p.y));
  3649. });
  3650. if (o.precision != void 0) {
  3651. precision = o.precision;
  3652. } else {
  3653. var boundSize = bound.getSize(new Vector2());
  3654. precision = MathUtils.clamp(Math.max(boundSize.x, boundSize.y) / 70, 0.2, 2);
  3655. }
  3656. o.points.forEach(point => getPoint(point)); //{x:..,y:..}
  3657. o.lines.forEach(line => {
  3658. //{p1:id1. p2:id2}
  3659. new Line$1({
  3660. points: [getPoint(line.p1), getPoint(line.p2)],
  3661. id: line.id
  3662. });
  3663. });
  3664. //注意:不能出现一条线的两个点坐标一致,否则寻路时方向出错。 所以手动融合下相近点。
  3665. };
  3666. var searchRings = function searchRings() {
  3667. var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  3668. points = [];
  3669. lines = [];
  3670. rings = [];
  3671. lineLen = ringLen = 0;
  3672. o.points = o.points || [];
  3673. o.lines = o.lines || [];
  3674. build(o);
  3675. if (!o.dontSliceLines) {
  3676. getSliceLines();
  3677. }
  3678. //查找最小回路:
  3679. //参考: 引入方向因子的最小回路、最大回路搜索算法.pdf
  3680. //方法: 逆时针寻找(标记)最外层大环 -->从走过的点开始逆时针寻找最小环(直到所有可走的路被走过两次)-->逆时针寻找最外层大环(直到所有可走的路被走过两次)-->..
  3681. //其中找大环时选择方向因子最小的路, 而小环则相反(但只有开始第一条路是一样的, 都是选择最左边的点的因子最小的路)。
  3682. //标记方法: 每条线需要被搜索两次才算完毕。搜索完毕的线退出搜索。(依据:搜索完全部最小回路后 , 在无向图中删除搜索过 2 次的边及孤立节点得到退化图 , 恰好构成最大回路。)
  3683. var searchTime = 0;
  3684. var addRingJudgeCount = 0;
  3685. var addRingJudge = function addRingJudge(ring, lines, connectedLines, type) {
  3686. // 处理拣出的片段
  3687. addRingJudgeCount++;
  3688. //console.log("addRingJudge points("+ type+"):"+ ring.map(point=>point.id) )
  3689. if (o.onlyGetOutRing && type == "small") return;
  3690. if (type == "small" || o.onlyGetOutRing) {
  3691. //挑出回路:
  3692. var newRings = [];
  3693. while (ring.length) {
  3694. var road = [];
  3695. var turnBack = false;
  3696. for (var i = 0; i < ring.length; i++) {
  3697. if (road.includes(ring[i])) {
  3698. //如果走到方才的点,可能形成回路。 无论是不是回路都要摘去这段。
  3699. var index = road.indexOf(ring[i]);
  3700. var pointArr = ring.slice(index, i);
  3701. var linesArr = lines.slice(index, i);
  3702. ring.splice(index, i - index);
  3703. lines.splice(index, i - index);
  3704. if (pointArr.length > 2) {
  3705. // 如果只有两个数,代表原路返回, 如 1->2(->1)
  3706. if (!rings.find(ring_ => ifSameRing(pointArr, ring_))) newRings.push(new Ring({
  3707. points: pointArr,
  3708. lines: linesArr
  3709. }));
  3710. }
  3711. turnBack = true;
  3712. break;
  3713. } else {
  3714. road.push(ring[i]);
  3715. turnBack = false;
  3716. }
  3717. }
  3718. if (!turnBack) {
  3719. //没有重复的点,那么就直接处理整条。
  3720. if (ring.length > 2) {
  3721. // 如果只有两个数,代表原路返回, 如 1->2(->1)
  3722. if (!rings.find(ring_ => ifSameRing(ring, ring_))) newRings.push(new Ring({
  3723. points: ring,
  3724. lines
  3725. }));
  3726. }
  3727. break;
  3728. }
  3729. }
  3730. if (type != 'small') {
  3731. newRings.forEach(e => e.isOutRing = true);
  3732. }
  3733. //console.log(newRings)
  3734. } else {
  3735. return ring;
  3736. }
  3737. };
  3738. var _search = function search(point2d, comeRoad, type, connectedLines) {
  3739. searchTime++;
  3740. var goLine;
  3741. var direction;
  3742. if (type.includes("big")) {
  3743. if (!comeRoad) {
  3744. if (type.includes("Left")) {
  3745. //逆时针
  3746. direction = new Vector2(1, 0);
  3747. } else {
  3748. direction = new Vector2(-1, 0);
  3749. }
  3750. goLine = point2d.searchLineByFactor(direction, "min");
  3751. } else {
  3752. var lastPoint = comeRoad.points[comeRoad.points.length - 1];
  3753. direction = point2d.clone().sub(lastPoint);
  3754. goLine = point2d.searchLineByFactor(direction, "min", findLine(point2d, lastPoint));
  3755. }
  3756. } else {
  3757. if (!comeRoad) {
  3758. //似乎找最小环时,第一条线也是找最小的因子,这样才能保证逆时针(除非只有顺时针一条路)
  3759. direction = new Vector2(1, 0);
  3760. goLine = point2d.searchLineByFactor(direction, "min");
  3761. } else {
  3762. var lastPoint = comeRoad.points[comeRoad.points.length - 1];
  3763. direction = point2d.clone().sub(lastPoint);
  3764. goLine = point2d.searchLineByFactor(direction, "max", findLine(point2d, lastPoint));
  3765. }
  3766. }
  3767. if (!goLine) return;
  3768. goLine.searchTime++;
  3769. connectedLines.includes(goLine) || connectedLines.push(goLine);
  3770. var nextPoint = goLine.points.find(point => point2d != point);
  3771. //if( comeRoad && comeRoad.points[comeRoad.points.length - 1] == nextPoint ) return;//不能查找来时的方向(反方向)
  3772. //走不通就原路返回
  3773. var roadPoints = comeRoad ? comeRoad.points.concat([point2d]) : [point2d]; //每个分叉都能构成一条新的road
  3774. var roadLines = comeRoad ? comeRoad.lines.concat([goLine]) : [goLine];
  3775. //走到第一个点就算停止,这时候可能得到一个环、或者一段走了两遍的线、或者一条线上带了些环。
  3776. if (nextPoint == roadPoints[0]) return addRingJudge(roadPoints, roadLines, connectedLines, type); //形成环
  3777. else {
  3778. /* var len = roadPoints.indexOf(nextPoint);
  3779. if( len > -1){ //走到走过的路的某一点 构成这段路的回路
  3780. var points = roadPoints.slice(len, roadPoints.length);
  3781. var lines = roadLines.slice(len, roadPoints.length);
  3782. addRingJudge(points, lines)
  3783. }else{ */
  3784. return _search(nextPoint, {
  3785. lines: roadLines,
  3786. points: roadPoints
  3787. }, type, connectedLines); //继续寻路
  3788. //}
  3789. }
  3790. };
  3791. while (1) {
  3792. //搜寻一次大环
  3793. var connectedLines = []; //被搜寻过的且searchTime<2的线。一旦全部搜完就说明该连通区域搜寻完毕,继续查下一个连通区域。
  3794. var startPoint = null;
  3795. points.forEach(point => {
  3796. //找出x最小的点
  3797. if (!point.lines.find(line => line.searchTime < 2)) return;
  3798. if (!startPoint) startPoint = point;else if (point.x < startPoint.x) startPoint = point;
  3799. });
  3800. if (!startPoint) break; //说明全部找完
  3801. var ring = _search(startPoint, null, "bigLeft", connectedLines); //逆时针
  3802. //search(startPoint, null, "bigRight", connectedLines);//顺时针(为了防止最外层不是回路之前写了顺时针,但如果是回路就会走重复。后来发现只要逆时针即可,因为走完后剩下的可以再次找大环)
  3803. connectedLines = connectedLines.filter(line => line.searchTime < 2);
  3804. var _loop = function _loop() {
  3805. //目标是顺着connectedLines把所有连通的小环都找到
  3806. var points_ = []; //connectedLines中所有的点
  3807. connectedLines.forEach(line => line.points.forEach(point => {
  3808. if (!points_.includes(point)) points_.push(point);
  3809. }));
  3810. startPoint = null;
  3811. points_.forEach(point => {
  3812. //找出x最小的点
  3813. if (!point.lines.find(line => line.searchTime < 2)) return;
  3814. if (!startPoint) startPoint = point;else if (point.x < startPoint.x) startPoint = point;
  3815. });
  3816. if (!startPoint) return 1; // break
  3817. _search(startPoint, null, "small", connectedLines);
  3818. connectedLines = connectedLines.filter(line => line.searchTime < 2);
  3819. },
  3820. startPoint;
  3821. while (connectedLines.length > 0) {
  3822. if (_loop()) break;
  3823. }
  3824. }
  3825. /* if(o.onlyGetOutRing){
  3826. rings = rings.filter(e=>e.isOutRing)
  3827. } */
  3828. //console.log("searchTime "+searchTime + ", addRingJudgeCount " +addRingJudgeCount)
  3829. //找出所有的相邻关系,包括公共边
  3830. var len = rings.length;
  3831. for (var i = 0; i < len; i++) {
  3832. var ring1 = rings[i];
  3833. for (var j = i + 1; j < len; j++) {
  3834. var ring2 = rings[j];
  3835. var bothHasLines = getMixedSet(ring1.lines, ring2.lines);
  3836. if (bothHasLines.length) {
  3837. //ring1oíring2?àáú
  3838. ring1.smallNeibours.push(ring2);
  3839. ring2.smallNeibours.push(ring1);
  3840. } else {}
  3841. }
  3842. }
  3843. rings.forEach(ring1 => {
  3844. for (var _i = 0; _i < len; _i++) {
  3845. var ring2 = rings[_i];
  3846. if (ring1 == ring2 || ring1.smallNeibours.includes(ring2)) continue;
  3847. var inside = void 0;
  3848. for (var u = 0; u < ring1.points.length; u++) {
  3849. inside = math.isPointInArea(ring2.points, null, ring1.points[u]);
  3850. if (!inside) break;else if (inside && !inside.atLine) {
  3851. break;
  3852. }
  3853. }
  3854. if (inside) {
  3855. //只要其中一个点在ring2内,就说明ring1是内环
  3856. if (inside.atLine) {
  3857. //(还是会存在点全在线上的情况,这时候判断中心点)
  3858. var center = math.getCenterOfGravityPoint(ring1.points);
  3859. var inside1 = math.isPointInArea(ring2.points, null, center);
  3860. if (!inside1) {
  3861. continue;
  3862. }
  3863. }
  3864. ring2.child.push(ring1);
  3865. ring1.parent.push(ring2);
  3866. }
  3867. }
  3868. });
  3869. //去除非最小的ring 是否应该检测parent child?
  3870. /*
  3871. like this:
  3872. |———————————————————————|
  3873. |———|———————|———————| |
  3874. | | | | |
  3875. | |———————|———————| |
  3876. |———————————————————————|
  3877. */
  3878. var wiseRings = rings.filter(r => !r.isClockwise); //一般都是逆时针得到的,如果是顺时针,可能是贪吃蛇的情况,可能不是最小环,需要去掉。
  3879. if (wiseRings.length > 0) {
  3880. //console.log('%c存在非最小的ring! 进行处理:',"color:#00f");
  3881. wiseRings.forEach(ring => {
  3882. //(此案例验证出smallNeibours就是它的最小构成,可以再看看别的案例)
  3883. if (ring.smallNeibours.length > 0) {
  3884. //另:如果内部只有一个,说明它是最小环,不需要处理
  3885. var is = false;
  3886. var difference = getDifferenceSet(ring.lines, getDifferenceSetMuti(ring.smallNeibours.concat(ring.child).map(ring => ring.lines))); //获取所有smallNeibours和child的边中没有重复过的边(就是outline) 和该ring的线比较
  3887. is = difference.every(line => ring.child.find(r => r.lines.includes(line))); //多出的线只能是child中的线
  3888. if (is) {
  3889. console.log('%c删除非最小环 ring' + ring.id, "color:#00f");
  3890. console.log(ring);
  3891. rings.splice(rings.indexOf(ring), 1);
  3892. ring.child.forEach(c => {
  3893. var index = c.parent.indexOf(ring);
  3894. index > -1 && c.parent.splice(index, 1);
  3895. });
  3896. ring.parent.forEach(c => {
  3897. var index = c.child.indexOf(ring);
  3898. index > -1 && c.child.splice(index, 1);
  3899. });
  3900. ring.smallNeibours.forEach(c => {
  3901. var index = c.smallNeibours.indexOf(ring);
  3902. index > -1 && c.smallNeibours.splice(index, 1);
  3903. });
  3904. }
  3905. }
  3906. });
  3907. }
  3908. /* rings = rings.filter(ring=>{
  3909. rings = rings.filter(ring=>{
  3910. var enoughSize = ring.area > 0.5
  3911. if(!enoughSize){console.log('因面积过小去除ring '+ring.id + " , area: "+ring.area)}
  3912. return enoughSize
  3913. })
  3914. rings.forEach(ring=>{
  3915. if(ring.closetChilds){
  3916. ring.closetChilds = ring.closetChilds.filter(e=>rings.includes(e))
  3917. }
  3918. })
  3919. return rings
  3920. }) */ //在dealRings前不能随意删除rings,因为判断是否是最小环时需要全部的环
  3921. rings.forEach(ring => {
  3922. //这里和cad中的不太一样, cad中双数个parent算外环,单数内环; 这里不分内外, 只看有无parent child
  3923. if (ring.parent.length) {
  3924. ring.closetParent = ring.parent.find(ring_ => ring_.parent.length == ring.parent.length - 1); //最近一层的大环就是比它的parent个数少一的
  3925. ring.closetParent.closetChilds || (ring.closetParent.closetChilds = []); //内环可能多个
  3926. ring.closetParent.closetChilds.push(ring);
  3927. }
  3928. });
  3929. //console.log(rings)
  3930. var _ring = rings.map(ring => {
  3931. var data = {
  3932. id: ring.id,
  3933. points: ring.points.map(point => {
  3934. return {
  3935. id: point.ids[0],
  3936. x: point.x,
  3937. y: point.y
  3938. };
  3939. }),
  3940. /* doors : o.doors.filter(door=>{
  3941. if(ring.closetChilds){
  3942. var childOutLines = getDifferenceSetMuti(ring.closetChilds.map(ring=>ring.lines)) //最近子环的外边
  3943. return ring.lines.concat(childOutLines).includes(door.atLine)
  3944. }else{
  3945. return ring.lines.includes(door.atLine)
  3946. }
  3947. }), */
  3948. area: ring.area,
  3949. closetParent: ring.closetParent && ring.closetParent.id,
  3950. closetChilds: ring.closetChilds && ring.closetChilds.map(e => e.id)
  3951. };
  3952. return data;
  3953. });
  3954. //console.log(JSON.stringify(_ring))
  3955. return _ring;
  3956. };
  3957. var easing = {};
  3958. //渐变曲线函数,反应加速度的变化
  3959. //currentTime:x轴当前时间(从0-到duration), startY:起始点, duration:总时长, wholeY:路程 (即endY-startY)
  3960. //参数基本是 x, 0, 1, 1
  3961. /*
  3962. easeOut 基本是y= m * (x-dur)^k + n, 若k为偶数,m<0, 若k为奇数,m>0; (因为偶数的话必须开口向下才能获得斜率递减的递增的那段,而奇数是对称的,单调递增. )
  3963. 根据x=0时y=0, x=dur时y=S , 得 n = S,m = -S/(-dur)^k
  3964. */
  3965. easing.getEaseOut = function (k) {
  3966. // k 是>=2的整数. 越大变化率越大, 相同初始速度所需要时间越久
  3967. var easeFun;
  3968. k = Math.round(k);
  3969. if (k < 2) {
  3970. k = Math.PI / 2;
  3971. easeFun = easing.easeOutSine;
  3972. } else {
  3973. easeFun = function easeFun(currentTime, startY, wholeY, duration) {
  3974. if (k > 2) {
  3975. console.log(k);
  3976. }
  3977. return -wholeY / Math.pow(-duration, k) * Math.pow(currentTime - duration, k) + wholeY;
  3978. };
  3979. }
  3980. return {
  3981. k,
  3982. easeFun
  3983. };
  3984. };
  3985. easing.linearTween = function (currentTime, startY, wholeY, duration) {
  3986. return wholeY * currentTime / duration + startY;
  3987. }, easing.easeInQuad = function (currentTime, startY, wholeY, duration) {
  3988. return currentTime /= duration, wholeY * currentTime * currentTime + startY;
  3989. }, easing.easeOutQuad = function (currentTime, startY, wholeY, duration) {
  3990. // 如套上实际的距离S和时长dur, y = - S / dur *(x^2-2x) 当s为1,dur为1时,是 y = -(x-1)^2 + 1 , 在0-1中是斜率递减的递增函数. 导数- S / dur *(2x-2 ) 可求出实时速度 故在0这一时刻,速度为 2S/dur
  3991. return currentTime /= duration, -wholeY * currentTime * (currentTime - 2) + startY;
  3992. }, easing.easeInOutQuad = function (currentTime, startY, wholeY, duration) {
  3993. return currentTime /= duration / 2, currentTime < 1 ? wholeY / 2 * currentTime * currentTime + startY : (currentTime--, -wholeY / 2 * (currentTime * (currentTime - 2) - 1) + startY);
  3994. }, easing.easeInCubic = function (currentTime, startY, wholeY, duration) {
  3995. return currentTime /= duration, wholeY * currentTime * currentTime * currentTime + startY;
  3996. }, easing.easeOutCubic = function (currentTime, startY, wholeY, duration) {
  3997. // y = S / dur^3 *(x-dur)^3 + S,对称中心是(dur,S),从0-dur是 斜率递减的递增函数,导数为3S/dur^3 * (x-dur)^2, 0时速度为3S/dur
  3998. return currentTime /= duration, currentTime--, wholeY * (currentTime * currentTime * currentTime + 1) + startY;
  3999. }, easing.easeInOutCubic = function (currentTime, startY, wholeY, duration) {
  4000. return currentTime /= duration / 2, currentTime < 1 ? wholeY / 2 * currentTime * currentTime * currentTime + startY : (currentTime -= 2, wholeY / 2 * (currentTime * currentTime * currentTime + 2) + startY);
  4001. }, easing.easeInQuart = function (currentTime, startY, wholeY, duration) {
  4002. return currentTime /= duration, wholeY * currentTime * currentTime * currentTime * currentTime + startY;
  4003. }, easing.easeOutQuart = function (currentTime, startY, wholeY, duration) {
  4004. //根据上面的计算,估计0时速度应该是4S/dur吧……
  4005. return currentTime /= duration, currentTime--, -wholeY * (currentTime * currentTime * currentTime * currentTime - 1) + startY;
  4006. }, easing.easeInOutQuart = function (currentTime, startY, wholeY, duration) {
  4007. return currentTime /= duration / 2, currentTime < 1 ? wholeY / 2 * currentTime * currentTime * currentTime * currentTime + startY : (currentTime -= 2, -wholeY / 2 * (currentTime * currentTime * currentTime * currentTime - 2) + startY);
  4008. }, easing.easeInQuint = function (currentTime, startY, wholeY, duration) {
  4009. return currentTime /= duration, wholeY * currentTime * currentTime * currentTime * currentTime * currentTime + startY;
  4010. }, easing.easeOutQuint = function (currentTime, startY, wholeY, duration) {
  4011. return currentTime /= duration, currentTime--, wholeY * (currentTime * currentTime * currentTime * currentTime * currentTime + 1) + startY;
  4012. }, easing.easeInOutQuint = function (currentTime, startY, wholeY, duration) {
  4013. return currentTime /= duration / 2, currentTime < 1 ? wholeY / 2 * currentTime * currentTime * currentTime * currentTime * currentTime + startY : (currentTime -= 2, wholeY / 2 * (currentTime * currentTime * currentTime * currentTime * currentTime + 2) + startY);
  4014. }, easing.easeInSine = function (currentTime, startY, wholeY, duration) {
  4015. return -wholeY * Math.cos(currentTime / duration * (Math.PI / 2)) + wholeY + startY;
  4016. }, easing.easeOutSine = function (currentTime, startY, wholeY, duration) {
  4017. // y' = S * PI / 2 / dur * cos(PI/2/dur * x)
  4018. return wholeY * Math.sin(currentTime / duration * (Math.PI / 2)) + startY;
  4019. }, easing.easeInOutSine = function (currentTime, startY, wholeY, duration) {
  4020. return -wholeY / 2 * (Math.cos(Math.PI * currentTime / duration) - 1) + startY;
  4021. }, easing.easeInExpo = function (currentTime, startY, wholeY, duration) {
  4022. return wholeY * Math.pow(2, 10 * (currentTime / duration - 1)) + startY;
  4023. }, easing.easeOutExpo = function (currentTime, startY, wholeY, duration) {
  4024. return wholeY * (-Math.pow(2, -10 * currentTime / duration) + 1) + startY;
  4025. }, easing.easeInOutExpo = function (currentTime, startY, wholeY, duration) {
  4026. return currentTime /= duration / 2, currentTime < 1 ? wholeY / 2 * Math.pow(2, 10 * (currentTime - 1)) + startY : (currentTime--, wholeY / 2 * (-Math.pow(2, -10 * currentTime) + 2) + startY);
  4027. }, easing.easeInCirc = function (currentTime, startY, wholeY, duration) {
  4028. return currentTime /= duration, -wholeY * (Math.sqrt(1 - currentTime * currentTime) - 1) + startY;
  4029. }, easing.easeOutCirc = function (currentTime, startY, wholeY, duration) {
  4030. return currentTime /= duration, currentTime--, wholeY * Math.sqrt(1 - currentTime * currentTime) + startY;
  4031. }, easing.easeInOutCirc = function (currentTime, startY, wholeY, duration) {
  4032. return currentTime /= duration / 2, currentTime < 1 ? -wholeY / 2 * (Math.sqrt(1 - currentTime * currentTime) - 1) + startY : (currentTime -= 2, wholeY / 2 * (Math.sqrt(1 - currentTime * currentTime) + 1) + startY);
  4033. }, easing.easeInElastic = function (currentTime, startY, wholeY, duration) {
  4034. var r = 1.70158,
  4035. o = 0,
  4036. a = wholeY;
  4037. return 0 === currentTime ? startY : 1 === (currentTime /= duration) ? startY + wholeY : (o || (o = .3 * duration), a < Math.abs(wholeY) ? (a = wholeY, r = o / 4) : r = o / (2 * Math.PI) * Math.asin(wholeY / a), -(a * Math.pow(2, 10 * (currentTime -= 1)) * Math.sin((currentTime * duration - r) * (2 * Math.PI) / o)) + startY);
  4038. }, easing.easeOutElastic = function (currentTime, startY, wholeY, duration) {
  4039. var r = 1.70158,
  4040. o = 0,
  4041. a = wholeY;
  4042. return 0 === currentTime ? startY : 1 === (currentTime /= duration) ? startY + wholeY : (o || (o = .3 * duration), a < Math.abs(wholeY) ? (a = wholeY, r = o / 4) : r = o / (2 * Math.PI) * Math.asin(wholeY / a), a * Math.pow(2, -10 * currentTime) * Math.sin((currentTime * duration - r) * (2 * Math.PI) / o) + wholeY + startY);
  4043. }, easing.easeInOutElastic = function (currentTime, startY, wholeY, duration) {
  4044. var r = 1.70158,
  4045. o = 0,
  4046. a = wholeY;
  4047. return 0 === currentTime ? startY : 2 === (currentTime /= duration / 2) ? startY + wholeY : (o || (o = duration * (.3 * 1.5)), a < Math.abs(wholeY) ? (a = wholeY, r = o / 4) : r = o / (2 * Math.PI) * Math.asin(wholeY / a), currentTime < 1 ? -.5 * (a * Math.pow(2, 10 * (currentTime -= 1)) * Math.sin((currentTime * duration - r) * (2 * Math.PI) / o)) + startY : a * Math.pow(2, -10 * (currentTime -= 1)) * Math.sin((currentTime * duration - r) * (2 * Math.PI) / o) * .5 + wholeY + startY);
  4048. }, easing.easeInBack = function (currentTime, startY, wholeY, duration, r) {
  4049. return void 0 === r && (r = 1.70158), wholeY * (currentTime /= duration) * currentTime * ((r + 1) * currentTime - r) + startY;
  4050. }, easing.easeOutBack = function (currentTime, startY, wholeY, duration, r) {
  4051. return void 0 === r && (r = 1.70158), wholeY * ((currentTime = currentTime / duration - 1) * currentTime * ((r + 1) * currentTime + r) + 1) + startY;
  4052. }, easing.easeInOutBack = function (currentTime, startY, wholeY, duration, r) {
  4053. return void 0 === r && (r = 1.70158), (currentTime /= duration / 2) < 1 ? wholeY / 2 * (currentTime * currentTime * (((r *= 1.525) + 1) * currentTime - r)) + startY : wholeY / 2 * ((currentTime -= 2) * currentTime * (((r *= 1.525) + 1) * currentTime + r) + 2) + startY;
  4054. }, easing.easeOutBounce = function (currentTime, startY, wholeY, duration) {
  4055. return (currentTime /= duration) < 1 / 2.75 ? wholeY * (7.5625 * currentTime * currentTime) + startY : currentTime < 2 / 2.75 ? wholeY * (7.5625 * (currentTime -= 1.5 / 2.75) * currentTime + .75) + startY : currentTime < 2.5 / 2.75 ? wholeY * (7.5625 * (currentTime -= 2.25 / 2.75) * currentTime + .9375) + startY : wholeY * (7.5625 * (currentTime -= 2.625 / 2.75) * currentTime + .984375) + startY;
  4056. }, easing.easeInBounce = function (currentTime, startY, wholeY, r) {
  4057. return wholeY - easing.easeOutBounce(r - currentTime, 0, wholeY, r) + startY;
  4058. }, easing.easeInOutBounce = function (currentTime, startY, wholeY, r) {
  4059. return currentTime < r / 2 ? .5 * easing.easeInBounce(2 * currentTime, 0, wholeY, r) + startY : .5 * easing.easeOutBounce(x, 2 * currentTime - r, 0, wholeY, r) + .5 * wholeY + startY;
  4060. };
  4061. var lerp = {
  4062. /* vector: function(currentTime, startY, f) {//xzw change, add f
  4063. var wholeY = currentTime.clone();
  4064. return startY = startY.clone(),
  4065. function(duration) {
  4066. currentTime.set(wholeY.x * (1 - duration) + startY.x * duration, wholeY.y * (1 - duration) + startY.y * duration, wholeY.z * (1 - duration) + startY.z * duration)
  4067. f && f(currentTime,duration);
  4068. }
  4069. },
  4070. quaternion: function(currentTime, startY, f) {//xzw change, add f
  4071. var wholeY = currentTime.clone();
  4072. return function(duration) {
  4073. currentTime.copy(wholeY).slerp(startY, duration);
  4074. f && f(currentTime,duration);
  4075. }
  4076. },
  4077. property: function(currentTime, startY, wholeY, duration) {
  4078. var r = currentTime[startY];
  4079. return function(o) {
  4080. currentTime[startY] = r * (1 - o) + wholeY * o,
  4081. duration && duration(currentTime[startY])
  4082. }
  4083. },
  4084. uniform: function(currentTime, startY, wholeY) {
  4085. var duration = currentTime.material.uniforms[startY].value;
  4086. return function(r) {
  4087. try{
  4088. currentTime.material.uniforms[startY] && (currentTime.material.uniforms[startY].value = duration * (1 - r) + wholeY * r)
  4089. }catch(currentTime){
  4090. console.log(1)
  4091. }
  4092. }
  4093. },
  4094. matrix4: function(currentTime, startY) {
  4095. var wholeY = currentTime.clone();
  4096. return function(duration) {
  4097. for (var r = currentTime.elements, o = wholeY.elements, a = startY.elements, s = 0; s < 16; s++)
  4098. r[s] = o[s] * (1 - duration) + a[s] * duration
  4099. }
  4100. },
  4101. allUniforms: function(currentTime, startY, wholeY) {
  4102. var duration = currentTime.map(function(currentTime) {
  4103. return this.uniform(currentTime, startY, wholeY)
  4104. }
  4105. .bind(this));
  4106. return function(currentTime) {
  4107. duration.forEach(function(startY) {
  4108. startY(currentTime)
  4109. })
  4110. }
  4111. } */
  4112. vector: function vector(t, i, f) {
  4113. //xzw change, add f
  4114. var n = t.clone();
  4115. return i = i.clone(), function (e, delta) {
  4116. t.set(n.x * (1 - e) + i.x * e, n.y * (1 - e) + i.y * e, n.z * (1 - e) + i.z * e);
  4117. f && f(t, e, delta);
  4118. };
  4119. },
  4120. quaternion: function quaternion(t, i, f) {
  4121. //xzw change, add f
  4122. var n = t.clone();
  4123. return function (e) {
  4124. t.copy(n).slerp(i, e);
  4125. f && f(t, e);
  4126. };
  4127. },
  4128. property: function property(t, i, n, r) {
  4129. var o = t[i];
  4130. return function (e) {
  4131. t[i] = o * (1 - e) + n * e, r && r(t[i]);
  4132. };
  4133. },
  4134. uniform: function uniform(t, i, n) {
  4135. var r = t.material.uniforms[i].value;
  4136. return function (e) {
  4137. t.material.uniforms[i] && (t.material.uniforms[i].value = r * (1 - e) + n * e);
  4138. };
  4139. },
  4140. matrix4: function matrix4(o, a) {
  4141. var s = o.clone();
  4142. return function (e) {
  4143. for (var t = o.elements, i = s.elements, n = a.elements, r = 0; r < 16; r++) t[r] = i[r] * (1 - e) + n[r] * e;
  4144. };
  4145. },
  4146. allUniforms: function allUniforms(e, t, i) {
  4147. var n = e.map(function (e) {
  4148. return this.uniform(e, t, i);
  4149. }.bind(this));
  4150. return function (t) {
  4151. n.forEach(function (e) {
  4152. e(t);
  4153. });
  4154. };
  4155. }
  4156. };
  4157. /*
  4158. 渐变
  4159. */
  4160. var transitions = {
  4161. globalDone: null,
  4162. funcs: [],
  4163. counter: 0,
  4164. uniqueID: 0,
  4165. start: function start(func, duration, done, delay, ease, name, id, cancelFun) {
  4166. var ignoreFirstFrame = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : true;
  4167. return delay = delay || 0, this.funcs.push({
  4168. func: func,
  4169. current: -delay * Math.abs(duration),
  4170. //当前时间
  4171. duration: (1 - Math.max(delay, 0)) * Math.abs(duration),
  4172. //总时长
  4173. done: done,
  4174. easing: ease || easing.linearTween,
  4175. //渐变曲线
  4176. cycling: duration < 0,
  4177. running: !0,
  4178. debug: delay < 0,
  4179. name: name || "T" + this.counter,
  4180. id: void 0 === id ? this.counter : id,
  4181. paused: !1,
  4182. cancelFun: cancelFun,
  4183. //取消时执行的函数
  4184. updateCount: 0,
  4185. ignoreFirstFrame
  4186. }), func(0, 16), this.counter += 1, func;
  4187. },
  4188. trigger: function trigger(e) {
  4189. var t = void 0 === e.delayRatio ? 0 : e.delayRatio,
  4190. u = e.func || function () {},
  4191. r = void 0 === e.duration ? 0 : e.duration;
  4192. void 0 !== e.cycling && e.cycling && (r = -Math.abs(r));
  4193. var o = e.done || null,
  4194. a = e.easing || easing.linearTween,
  4195. s = e.name || "R" + this.counter,
  4196. l = void 0 === e.id ? this.counter : e.id;
  4197. return this.start(u, r, o, t, a, s, l);
  4198. },
  4199. setTimeout: function setTimeout(e, t, u) {
  4200. var duration = void 0 === u ? this.counter : u;
  4201. return this.trigger({
  4202. done: e,
  4203. duration: void 0 === t ? 0 : t,
  4204. name: "O" + this.counter,
  4205. id: duration
  4206. });
  4207. },
  4208. pause: function pause() {
  4209. this.paused = !0;
  4210. },
  4211. resume: function resume() {
  4212. this.paused = !1;
  4213. },
  4214. update: function update(e) {
  4215. this.funcs.forEach(function (t) {
  4216. if (t.updateCount++ == 0 && t.ignoreFirstFrame) return; //add start可能发生在一帧中任意时刻,而每次update的是在一帧中的固定时刻,所以从start到第一次update的时间并不是所传入的delta,该delta 是上一帧的update到这一帧的update的耗时。 故去掉了第一次的update,相当于延迟一帧再update.
  4217. if (!(t.paused || (t.current += 1e3 * e, t.current < 0))) {
  4218. if (t.current >= t.duration && !t.cycling) {
  4219. var u = t.easing(1, 0, 1, 1);
  4220. t.func(u, 1e3 * e), t.done && t.done(), t.running = !1;
  4221. } else {
  4222. var duration = t.easing(t.current % t.duration / t.duration, 0, 1, 1),
  4223. r = t.func(duration, 1e3 * e) || !1;
  4224. r && (t.done && t.done(), t.running = !1);
  4225. }
  4226. }
  4227. });
  4228. var t = this.funcs.length;
  4229. this.funcs = this.funcs.filter(function (e) {
  4230. return e.running;
  4231. });
  4232. var u = this.funcs.length;
  4233. if (t > 0 && 0 === u && this.globalDone) {
  4234. var duration = this.globalDone;
  4235. this.globalDone = null, duration();
  4236. }
  4237. },
  4238. adjustSpeed: function adjustSpeed(e, t) {
  4239. for (var u = this.getById(e), duration = 0; duration < u.length; duration++) {
  4240. var r = u[duration];
  4241. r.duration /= t, r.current /= t;
  4242. }
  4243. },
  4244. getById: function getById(e) {
  4245. return this.funcs.filter(function (t) {
  4246. return e === t.id;
  4247. });
  4248. },
  4249. get: function get(e) {
  4250. for (var t = 0; t < this.funcs.length; t += 1) if (this.funcs[t].func === e) return this.funcs[t];
  4251. return null;
  4252. },
  4253. isRunning: function isRunning(e) {
  4254. var t = this.get(e);
  4255. return null !== t && t.running;
  4256. },
  4257. countActive: function countActive() {
  4258. for (var e = 0, t = 0; t < this.funcs.length; t += 1) e += this.funcs[t].running;
  4259. return e;
  4260. },
  4261. listActive: function listActive() {
  4262. for (var e = [], t = 0; t < this.funcs.length; t += 1) this.funcs[t].running && e.push(this.funcs[t].name);
  4263. return e;
  4264. },
  4265. done: function done(e) {
  4266. this.globalDone = e;
  4267. },
  4268. cancelById: function cancelById(e, dealCancelFun) {
  4269. //xzw add dealDone
  4270. var t = void 0 === e ? 0 : e;
  4271. var cancels = [];
  4272. this.funcs = this.funcs.filter(function (e) {
  4273. var is = e.id == t;
  4274. if (is && dealCancelFun) {
  4275. e.cancelFun && cancels.push(e.cancelFun);
  4276. //e.cancelFun && e.cancelFun()
  4277. }
  4278. return !is;
  4279. });
  4280. cancels.forEach(e => {
  4281. e();
  4282. }); //先从funcs中去除后再执行
  4283. },
  4284. cancel: function cancel(e) {
  4285. this.funcs = this.funcs.filter(function (t) {
  4286. return t.func !== e;
  4287. });
  4288. },
  4289. getUniqueId: function getUniqueId() {
  4290. return this.uniqueID -= 1, this.uniqueID;
  4291. }
  4292. };
  4293. //THREE.Vector2.name2 = 'Common'
  4294. var Common = {
  4295. sortByScore: function sortByScore(list, request, rank) {
  4296. var i = request ? Common.filterAll(list, request) : list;
  4297. return 0 === i.length ? [] : i = i.map(function (e) {
  4298. var results = rank.map(function (f) {
  4299. return f(e);
  4300. });
  4301. var scores = results.map(e => e.score != void 0 ? e.score : e);
  4302. var logs = results.map(e => e.log);
  4303. return {
  4304. item: e,
  4305. scores,
  4306. logs,
  4307. score: scores.reduce(function (t, i) {
  4308. //总分
  4309. return t + i;
  4310. }, 0)
  4311. };
  4312. }).sort(function (e, t) {
  4313. return t.score - e.score;
  4314. });
  4315. },
  4316. filterAll: function filterAll(e, t) {
  4317. return e.filter(function (e) {
  4318. return t.every(function (t) {
  4319. return t(e);
  4320. });
  4321. });
  4322. },
  4323. //---------------
  4324. find: function find(list, request, rank, sortByScore) {
  4325. if (sortByScore) {
  4326. var r = this.sortByScore(list, request, rank);
  4327. return r[0] && r[0].item;
  4328. } else {
  4329. var i = request ? Common.filterAll(list, request) : list;
  4330. return 0 === i.length ? null : (rank && rank.forEach(function (e) {
  4331. i = Common.stableSort(i, e);
  4332. }), i[0]);
  4333. }
  4334. },
  4335. stableSort: function stableSort(e, f) {
  4336. //用到排序函数,涉及到两个item相减
  4337. return e.map(function (e, i) {
  4338. return {
  4339. value: e,
  4340. index: i
  4341. };
  4342. }).sort(function (e, u) {
  4343. var n = f(e.value, u.value);
  4344. return 0 !== n ? n : e.index - u.index; //似乎就是加多了这一步:若差距为0,按照原顺序
  4345. }).map(function (e) {
  4346. return e.value;
  4347. });
  4348. },
  4349. average: function average(e, t) {
  4350. if (0 === e.length) return null;
  4351. for (var i = 0, n = 0, r = 0; r < e.length; r++) {
  4352. var o = t ? e[r][t] : e[r];
  4353. i += o, n++;
  4354. }
  4355. return i / n;
  4356. },
  4357. //---------------------------
  4358. getMixedSet: function getMixedSet(arr1, arr2) {
  4359. //交集
  4360. return arr1.filter(item => arr2.includes(item));
  4361. },
  4362. getUnionSet: function getUnionSet(arr1, arr2) {
  4363. //并集
  4364. return arr1.concat(arr2.filter(item => !arr1.includes(item)));
  4365. },
  4366. getDifferenceSet: function getDifferenceSet(arr1, arr2) {
  4367. //差集 不能识别重复的,如getDifferenceSet([1,2,2],[1,1,2]) 为空
  4368. var arr11 = arr1.filter(item => !arr2.includes(item));
  4369. var arr22 = arr2.filter(item => !arr1.includes(item));
  4370. return arr11.concat(arr22);
  4371. },
  4372. getDifferenceSetMuti: function getDifferenceSetMuti(arr) {
  4373. //收集绝对没有重复的元素,也就是判断出现次数=1的
  4374. var set = [];
  4375. arr.forEach(arr1 => {
  4376. arr1.forEach(item => {
  4377. var index = set.indexOf(item);
  4378. if (index > -1) {
  4379. set.splice(index, 1);
  4380. } else {
  4381. set.push(item);
  4382. }
  4383. });
  4384. });
  4385. return set;
  4386. },
  4387. CloneJson: function CloneJson(data) {
  4388. var str = JSON.stringify(data);
  4389. return JSON.parse(str);
  4390. },
  4391. CloneObject: function CloneObject(copyObj, isSimpleCopy) {
  4392. var simpleCopyList = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
  4393. var judgeSimpleCopyFun = arguments.length > 3 ? arguments[3] : undefined;
  4394. //isSimpleCopy 只复制最外层
  4395. //复制json result的可能:普通数字或字符串、普通数组、复杂对象
  4396. judgeSimpleCopyFun || (judgeSimpleCopyFun = () => {});
  4397. if (!copyObj || typeof copyObj == 'number' || typeof copyObj == 'string' || copyObj.isObject3D || copyObj instanceof Function || simpleCopyList.some(className => copyObj instanceof className) || judgeSimpleCopyFun(copyObj)) {
  4398. return copyObj;
  4399. }
  4400. if (copyObj instanceof Array) {
  4401. return copyObj.map(e => {
  4402. return this.CloneObject(e, isSimpleCopy, simpleCopyList, judgeSimpleCopyFun);
  4403. });
  4404. } else {
  4405. if (copyObj.clone instanceof Function) {
  4406. //解决一部分
  4407. return copyObj.clone();
  4408. }
  4409. }
  4410. var result = {};
  4411. for (var key in copyObj) {
  4412. if (copyObj[key] instanceof Object && !isSimpleCopy) result[key] = this.CloneObject(copyObj[key], isSimpleCopy, simpleCopyList, judgeSimpleCopyFun);else result[key] = copyObj[key];
  4413. //如果是函数类同基本数据,即复制引用
  4414. }
  4415. return result;
  4416. },
  4417. CloneClassObject: function CloneClassObject(copyObj) {
  4418. var {
  4419. ignoreList = [],
  4420. simpleCopyList = []
  4421. } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  4422. //复杂类对象
  4423. var newobj = new copyObj.constructor();
  4424. this.CopyClassObject(newobj, copyObj, {
  4425. ignoreList,
  4426. simpleCopyList
  4427. });
  4428. return newobj;
  4429. },
  4430. CopyClassObject: function CopyClassObject(targetObj, copyObj) {
  4431. var {
  4432. ignoreList = [],
  4433. simpleCopyList = []
  4434. } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  4435. //复杂类对象
  4436. for (var i in copyObj) {
  4437. if (i in copyObj.__proto__) break; //到函数了跳出
  4438. if (ignoreList.includes(i)) {
  4439. continue;
  4440. } else if (simpleCopyList.includes(i)) {
  4441. targetObj[i] = copyObj[i];
  4442. } else {
  4443. targetObj[i] = this.CloneObject(copyObj[i], false, simpleCopyList);
  4444. }
  4445. /* else if(copyObj[i].clone instanceof Function ){
  4446. targetObj[i] = copyObj[i].clone()
  4447. }else{
  4448. targetObj[i] = copyObj[i];
  4449. } */
  4450. }
  4451. },
  4452. ifSame: function ifSame(object1, object2) {
  4453. var simpleEqualClass = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
  4454. //对于复杂的类对象,若能简单判断就直接写进simpleEqualClass
  4455. if (object1 == object2) return true; // 0 != undefined , 0 == ''
  4456. else if (!object1 || !object2) return false;else if (object1.constructor != object2.constructor) {
  4457. return false;
  4458. } else if (simpleEqualClass.some(className => object1 instanceof className)) {
  4459. return object1 == object2;
  4460. } else if (object1 instanceof Array) {
  4461. if (object1.length != object2.length) return false;
  4462. var _object2 = object2.slice(0);
  4463. var _loop = function _loop(i) {
  4464. u = _object2.find(e => Common.ifSame(object1[i], e, simpleEqualClass));
  4465. if (u == void 0 && !_object2.includes(u) && !object1.includes(u)) return {
  4466. v: false
  4467. };else {
  4468. var index = _object2.indexOf(u);
  4469. _object2.splice(index, 1);
  4470. }
  4471. },
  4472. u,
  4473. _ret;
  4474. for (var i = 0; i < object1.length; i++) {
  4475. _ret = _loop(i);
  4476. if (_ret) return _ret.v;
  4477. }
  4478. return true;
  4479. } else if (object1.equals instanceof Function) {
  4480. //复杂数据仅支持这种,其他的可能卡住?
  4481. return object1.equals(object2);
  4482. } else if (typeof object1 == 'number' || typeof object1 == 'string') {
  4483. if (isNaN(object1) && isNaN(object2)) return true;else return object1 == object2;
  4484. } else if (typeof object1 == "object") {
  4485. var keys1 = Object.keys(object1);
  4486. var keys2 = Object.keys(object2);
  4487. if (!Common.ifSame(keys1, keys2, simpleEqualClass)) return false;
  4488. for (var _i in object1) {
  4489. var same = Common.ifSame(object1[_i], object2[_i], simpleEqualClass);
  4490. if (!same) return false;
  4491. }
  4492. return true;
  4493. } else {
  4494. console.log('isSame出现例外');
  4495. }
  4496. },
  4497. downloadFile: function downloadFile(data, filename, cb) {
  4498. var save_link = document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
  4499. save_link.href = data;
  4500. save_link.download = filename;
  4501. var event = document.createEvent('MouseEvents');
  4502. event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  4503. save_link.dispatchEvent(event);
  4504. cb && cb();
  4505. },
  4506. replaceAll: function replaceAll(str, f, e) {
  4507. //f全部替换成e
  4508. var reg = new RegExp(f, "g"); //创建正则RegExp对象
  4509. return str.replace(reg, e);
  4510. },
  4511. dealURL(url) {
  4512. var urlNew = this.replaceAll(url, "\\+", "%2B"); // 浏览器似乎不支持访问带+的地址
  4513. urlNew = this.replaceAll(urlNew, "/.//", "/"); //去除双斜杠(/.//)
  4514. return urlNew;
  4515. },
  4516. getNameFromURL(url) {
  4517. if (!url) return '';
  4518. var get = e => {
  4519. return e.split('/').pop();
  4520. };
  4521. if (url instanceof Array) {
  4522. return url.map(e => get(e));
  4523. }
  4524. return get(url);
  4525. },
  4526. //---------------------------
  4527. intervalTool: {
  4528. //延时update,防止卡顿
  4529. list: [],
  4530. /* isWaiting:function(name, func, delayTime){
  4531. if(!this.list.includes(name)){ //如果没有该项, 则开始判断
  4532. var needWait = func(); //触发了改变,则等待一段时间后再自动判断
  4533. if(needWait){
  4534. this.list.push(name);
  4535. setTimeout(()=>{
  4536. var a = this.list.indexOf(name);
  4537. this.list.splice(a,1);
  4538. this.isWaiting(name, func, delayTime) //循环
  4539. },delayTime)
  4540. }
  4541. }
  4542. }, */
  4543. isWaiting: function isWaiting(name, func, delayTime /* , autoCycle */) {
  4544. var item = this.list.find(e => e.name == name);
  4545. if (!item) {
  4546. //如果没有该项, 则加入循环
  4547. var ifContinue = func();
  4548. item = {
  4549. name,
  4550. func,
  4551. delayTime
  4552. };
  4553. this.list.push(item);
  4554. setTimeout(() => {
  4555. var a = this.list.indexOf(item);
  4556. this.list.splice(a, 1);
  4557. var {
  4558. func,
  4559. delayTime
  4560. } = item;
  4561. if (item.requestUpdate || ifContinue) this.isWaiting(name, func, delayTime); //循环
  4562. }, delayTime);
  4563. } else {
  4564. //如果有该项,说明现在请求下一次继续更新
  4565. //if(delayTime == 0){//想立刻更新一次
  4566. // func()
  4567. //}else{
  4568. //更新属性
  4569. item.func = func;
  4570. item.delayTime = delayTime;
  4571. item.requestUpdate = true;
  4572. //}
  4573. }
  4574. }
  4575. },
  4576. pushToGroupAuto: function pushToGroupAuto(items, groups, recognizeFunction, recognizeGroup) {
  4577. //自动分组。 items是将分到一起的组合。items.length = 1 or 2.
  4578. recognizeFunction = recognizeFunction || function () {};
  4579. if (recognizeGroup) {
  4580. //有更复杂的识别处理,直接传递整个组
  4581. var atGroups = groups.filter(group => recognizeGroup(group, items));
  4582. } else {
  4583. var atGroups = groups.filter(group => group.find(item => items[0] == item || recognizeFunction(item, items[0]) || items[1] == item || items[1] && recognizeFunction(item, items[1])));
  4584. }
  4585. if (atGroups.length) {
  4586. //在不同组
  4587. //因为items是一组的,所以先都放入组1
  4588. items.forEach(item => {
  4589. if (!atGroups[0].includes(item)) atGroups[0].push(item);
  4590. });
  4591. if (atGroups.length > 1) {
  4592. //如果在不同组,说明这两个组需要合并
  4593. var combineGroup = [];
  4594. atGroups.forEach(group => {
  4595. combineGroup = Common.getUnionSet(combineGroup, group);
  4596. groups.splice(groups.indexOf(group), 1);
  4597. });
  4598. groups.push(combineGroup);
  4599. }
  4600. } else {
  4601. //直接加入为一组
  4602. groups.push(items);
  4603. }
  4604. },
  4605. getBestCount: function () {
  4606. var lastCount = {};
  4607. return function (name) {
  4608. var minCount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
  4609. var maxCount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 6;
  4610. var durBound1 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1.2;
  4611. var durBound2 = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 10;
  4612. var ifLog = arguments.length > 5 ? arguments[5] : undefined;
  4613. var maxHistory = arguments.length > 6 ? arguments[6] : undefined;
  4614. var timeStamp = performance.getEntriesByName("loop-start");
  4615. var count;
  4616. if (timeStamp.length) {
  4617. var dur = performance.now() - timeStamp[timeStamp.length - 1].startTime; //dur在iphoneX中静止有7,pc是2
  4618. count = Math.round(math.linearClamp(dur, [durBound1, durBound2], [maxCount, minCount]));
  4619. if (maxHistory) {
  4620. if (!lastCount[name]) lastCount[name] = [];
  4621. if (count == 0 && lastCount[name].length > maxHistory - 1 && !lastCount[name].some(e => e > 0)) {
  4622. count = 1;
  4623. }
  4624. lastCount[name].push(count);
  4625. if (lastCount[name].length > maxHistory) lastCount[name].splice(0, 1);
  4626. }
  4627. if (ifLog) {
  4628. //注意,console.log本身用时挺高, 降4倍时可能占用0.5毫秒
  4629. name && count && console.log(name, count, ' ,dur:', dur.toFixed(3));
  4630. }
  4631. } else {
  4632. count = maxCount; // ?
  4633. }
  4634. //主要在手机端有效果。
  4635. return count;
  4636. };
  4637. }(),
  4638. batchHandling: {
  4639. //分批处理
  4640. lists: [],
  4641. getSlice: function getSlice(name, items, _ref) {
  4642. var {
  4643. stopWhenAllUsed,
  4644. min = 5,
  4645. max = 100,
  4646. durBound1,
  4647. durBound2,
  4648. useEquals,
  4649. maxUseCount
  4650. } = _ref;
  4651. if (items.length == 0 || (maxUseCount = maxUseCount == void 0 ? Common.getBestCount(name, min, max, durBound1, durBound2 /* , true */) : maxUseCount, !maxUseCount) //本次最多可以使用的个数
  4652. ) {
  4653. return {
  4654. list: []
  4655. };
  4656. }
  4657. if (!this.lists[name]) this.lists[name] = {
  4658. list: []
  4659. };
  4660. //更新列表项目,但不变原来的顺序
  4661. var list = this.lists[name].list.filter(a => items.some(item => useEquals ? a.item.equals(item) : a.item == item)); //去掉已经不在items里的项目
  4662. this.lists[name].list = list;
  4663. items.forEach(item => {
  4664. //增加新的项目。
  4665. if (!list.some(a => useEquals ? a.item.equals(item) : a.item == item)) {
  4666. list.push({
  4667. item,
  4668. count: 0
  4669. });
  4670. }
  4671. });
  4672. //至此,在后排的都是未使用的
  4673. var unUsed = list.filter(e => e.count == 0); //未使用的项目(count为0)优先
  4674. var result = [];
  4675. unUsed.slice(0, maxUseCount).forEach(e => {
  4676. result.push(e.item);
  4677. e.count++;
  4678. });
  4679. if (unUsed.length > maxUseCount) {
  4680. //还是剩有未使用的项目,等待下一次
  4681. } else {
  4682. //所有项目都能使用一次
  4683. if (!stopWhenAllUsed) {
  4684. //若不是全部使用就停止
  4685. var wholeCount = Math.min(items.length, maxUseCount);
  4686. var restCount = wholeCount - result.length; //补齐
  4687. list.slice(0, restCount).forEach(e => {
  4688. result.push(e.item);
  4689. e.count++;
  4690. });
  4691. }
  4692. list.forEach(e => e.count--); //复原,等待新的循环
  4693. }
  4694. /* result.forEach((e,i)=>{//有重复的
  4695. if( result.slice(0,i).some(a=>a.equals(e)) || result.slice(i+1).some(a=>a.equals(e)) ) {
  4696. console.log(e)
  4697. }
  4698. }) */
  4699. return {
  4700. list: result
  4701. };
  4702. }
  4703. },
  4704. getRootWindow() {
  4705. //获取包含Potree的根window
  4706. var win = window;
  4707. try {
  4708. while (win.parent != win && win.parent.Potree) {
  4709. win = win.parent;
  4710. }
  4711. if (window != win) return win;
  4712. } catch (e) {
  4713. //console.log(e) //可能跨域,从而win.parent.Potree报错
  4714. console.log('getRootWindow 跨域');
  4715. return;
  4716. }
  4717. },
  4718. watch: function watch(object, propName, initialValue) {
  4719. //监听某个属性的变化
  4720. var v = initialValue;
  4721. Object.defineProperty(object, propName, {
  4722. get: function get() {
  4723. return v;
  4724. },
  4725. set: function set(e) {
  4726. console.warn('watch:', propName, e);
  4727. v = e;
  4728. }
  4729. });
  4730. },
  4731. imgAddLabel: function imgAddLabel(img, labelImg) {
  4732. var labelInfo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  4733. //图上加另一张小图,用于添加水印
  4734. var canvas;
  4735. if (img instanceof Image) {
  4736. canvas = document.createElement('canvas');
  4737. } else {
  4738. canvas = img;
  4739. }
  4740. var context = canvas.getContext('2d');
  4741. var marginLeft = labelInfo.bgMargin && labelInfo.bgMargin.left || 0;
  4742. var marginRight = labelInfo.bgMargin && labelInfo.bgMargin.right || 0;
  4743. var marginTop = labelInfo.bgMargin && labelInfo.bgMargin.top || 0;
  4744. var marginBottom = labelInfo.bgMargin && labelInfo.bgMargin.bottom || 0;
  4745. if (img instanceof Image) {
  4746. //如果img是canvas,说明已绘制在canvas上了就不用绘制了
  4747. var width = img.width + marginLeft + marginRight;
  4748. var height = img.height + marginTop + marginBottom;
  4749. canvas.width = width;
  4750. canvas.height = height;
  4751. if (labelInfo.bgColor) {
  4752. context.fillStyle = 'rgba(' + labelInfo.bgColor.r + ',' + labelInfo.bgColor.g + ',' + labelInfo.bgColor.b + ',' + labelInfo.bgColor.a + ')';
  4753. context.fillRect(0, 0, width, height);
  4754. }
  4755. context.drawImage(img, marginLeft, marginTop, img.width, img.height);
  4756. }
  4757. var labelWidth = labelInfo.widthRatioToImg ? img.width * labelInfo.widthRatioToImg : labelImg.width; //widthRatioToImg:label的width占img的width的比例
  4758. var labelHeight = labelWidth * labelImg.height / labelImg.width;
  4759. if (labelInfo.leftRatioToImg == void 0 && labelInfo.rightRatioToImg != void 0) {
  4760. labelInfo.leftRatioToImg = 1 - labelInfo.rightRatioToImg - (labelInfo.widthRatioToImg || labelImg.width / img.width);
  4761. }
  4762. if (labelInfo.topRatioToImg == void 0 && labelInfo.bottomRatioToImg != void 0) {
  4763. labelInfo.topRatioToImg = 1 - labelInfo.bottomRatioToImg - labelHeight / img.height;
  4764. }
  4765. var labelLeft = img.width * labelInfo.leftRatioToImg + marginLeft; //leftRatioToImg:label的left占img的width的比例
  4766. var labelTop = img.height * labelInfo.topRatioToImg + marginTop; //topRatioToImg:label的top占img的height的比例
  4767. context.globalAlpha = labelInfo.opacity != void 0 ? labelInfo.opacity : 1;
  4768. context.drawImage(labelImg, labelLeft, labelTop, labelWidth, labelHeight);
  4769. if (labelInfo.outputCanvas) {
  4770. return canvas;
  4771. }
  4772. var dataUrl = canvas.toDataURL('image/png', labelInfo.compressRatio);
  4773. //Common.downloadFile(dataUrl, 'screenshot.png')
  4774. context.clearRect(0, 0, canvas.width, canvas.height);
  4775. return dataUrl;
  4776. },
  4777. changeShaderToWebgl2(vs, fs, matType) {
  4778. var otherReplaces = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
  4779. //部分shader要根据webgl版本作更改
  4780. if (!Potree.settings.isWebgl2) return {
  4781. vs,
  4782. fs
  4783. };
  4784. var turnTo300 = matType != 'ShaderMaterial' && (vs.includes('gl_FragDepthEXT') || fs.includes('gl_FragDepthEXT'));
  4785. var addV300 = turnTo300 && matType != 'RawShaderMaterial'; // RawShaderMaterial直接material.glslVersion = '300 es' 以加在define之前
  4786. var change = (shader, shaderType) => {
  4787. var newShader = shader;
  4788. if (turnTo300) {
  4789. //非shaderMaterial需要手动改为300 es的写法
  4790. addV300 && (newShader = '#version 300 es \n' + newShader); //需要加 #version 300 es。 three.js自带的渲染会自动加所以不用
  4791. newShader = newShader.replaceAll('varying ', shaderType == 'vs' ? 'out ' : 'in ');
  4792. newShader = newShader.replaceAll('attribute ', 'in ');
  4793. if (shaderType == 'fs') {
  4794. newShader = newShader.replaceAll('gl_FragColor', 'fragColor');
  4795. newShader = newShader.replace('void main', 'out vec4 fragColor;\n void main'); //在void main前加入这个声明
  4796. }
  4797. newShader = newShader.replaceAll('gl_FragDepthEXT', 'gl_FragDepth');
  4798. newShader = newShader.replaceAll('texture2D', 'texture');
  4799. newShader = newShader.replaceAll('textureCube', 'texture');
  4800. }
  4801. newShader = newShader.replace('#extension GL_EXT_frag_depth : enable', '');
  4802. newShader = newShader.replaceAll('defined(GL_EXT_frag_depth) &&', '');
  4803. otherReplaces.forEach(_ref2 => {
  4804. var {
  4805. oldStr,
  4806. newStr
  4807. } = _ref2;
  4808. newShader = newShader.replaceAll(oldStr, newStr);
  4809. });
  4810. return newShader;
  4811. };
  4812. vs = change(vs, 'vs');
  4813. fs = change(fs, 'fs');
  4814. //console.log('成功替换为webgl2' )
  4815. return {
  4816. vs,
  4817. fs
  4818. };
  4819. } //three.js的shaderMaterial也有替换功能,搜 '#define gl_FragDepthEXT gl_FragDepth',
  4820. };
  4821. Potree.Common = Common;
  4822. class View {
  4823. //base
  4824. constructor() {
  4825. this.position = new Vector3(0, 0, 0);
  4826. this.yaw = Math.PI / 4;
  4827. this._pitch = -Math.PI / 4;
  4828. this.radius = 1;
  4829. this.maxPitch = Math.PI / 2;
  4830. this.minPitch = -Math.PI / 2;
  4831. }
  4832. clone() {
  4833. var c = new View();
  4834. c.yaw = this.yaw;
  4835. c._pitch = this.pitch;
  4836. c.radius = this.radius;
  4837. c.maxPitch = this.maxPitch;
  4838. c.minPitch = this.minPitch;
  4839. return c;
  4840. }
  4841. get pitch() {
  4842. return this._pitch;
  4843. }
  4844. set pitch(angle) {
  4845. this._pitch = Math.max(Math.min(angle, this.maxPitch), this.minPitch);
  4846. }
  4847. get direction() {
  4848. var dir = new Vector3(0, 1, 0);
  4849. dir.applyAxisAngle(new Vector3(1, 0, 0), this.pitch);
  4850. dir.applyAxisAngle(new Vector3(0, 0, 1), this.yaw);
  4851. return dir;
  4852. }
  4853. set direction(dir) {
  4854. dir = dir.clone().normalize(); //add
  4855. if (dir.x === 0 && dir.y === 0) {
  4856. this.pitch = Math.PI / 2 * Math.sign(dir.z);
  4857. //this.yaw = 0 //add:还是要指定一下, 否则不统一
  4858. } else {
  4859. var yaw = Math.atan2(dir.y, dir.x) - Math.PI / 2;
  4860. var pitch = Math.atan2(dir.z, Math.sqrt(dir.x * dir.x + dir.y * dir.y));
  4861. this.yaw = yaw;
  4862. this.pitch = pitch;
  4863. }
  4864. }
  4865. lookAt(t) {
  4866. //setPivot
  4867. var V;
  4868. if (arguments.length === 1) {
  4869. V = new Vector3().subVectors(t, this.position);
  4870. } else if (arguments.length === 3) {
  4871. V = new Vector3().subVectors(new Vector3(...arguments), this.position);
  4872. }
  4873. var radius = V.length();
  4874. var dir = V.normalize();
  4875. this.radius = radius;
  4876. this.direction = dir;
  4877. }
  4878. getPivot() {
  4879. return new Vector3().addVectors(this.position, this.direction.multiplyScalar(this.radius));
  4880. }
  4881. getSide() {
  4882. var side = new Vector3(1, 0, 0);
  4883. side.applyAxisAngle(new Vector3(0, 0, 1), this.yaw);
  4884. return side;
  4885. }
  4886. pan(x, y) {
  4887. var dir = new Vector3(0, 1, 0);
  4888. dir.applyAxisAngle(new Vector3(1, 0, 0), this.pitch);
  4889. dir.applyAxisAngle(new Vector3(0, 0, 1), this.yaw);
  4890. // let side = new THREE.Vector3(1, 0, 0);
  4891. // side.applyAxisAngle(new THREE.Vector3(0, 0, 1), this.yaw);
  4892. var side = this.getSide();
  4893. var up = side.clone().cross(dir);
  4894. var pan = side.multiplyScalar(x).add(up.multiplyScalar(y));
  4895. this.position = this.position.add(pan);
  4896. // this.target = this.target.add(pan);
  4897. }
  4898. translate(x, y, z) {
  4899. var dir = new Vector3(0, 1, 0);
  4900. dir.applyAxisAngle(new Vector3(1, 0, 0), this.pitch);
  4901. dir.applyAxisAngle(new Vector3(0, 0, 1), this.yaw);
  4902. var side = new Vector3(1, 0, 0);
  4903. side.applyAxisAngle(new Vector3(0, 0, 1), this.yaw);
  4904. var up = side.clone().cross(dir);
  4905. var t = side.multiplyScalar(x).add(dir.multiplyScalar(y)).add(up.multiplyScalar(z));
  4906. this.position = this.position.add(t);
  4907. }
  4908. translateWorld(x, y, z) {
  4909. this.position.x += x;
  4910. this.position.y += y;
  4911. this.position.z += z;
  4912. }
  4913. setView(position, target) {
  4914. var duration = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  4915. var callback = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
  4916. var endPosition = null;
  4917. if (position instanceof Array) {
  4918. endPosition = new Vector3(...position);
  4919. } else if (position.x != null) {
  4920. endPosition = position.clone();
  4921. }
  4922. var endTarget = null;
  4923. if (target instanceof Array) {
  4924. endTarget = new Vector3(...target);
  4925. } else if (target.x != null) {
  4926. endTarget = target.clone();
  4927. }
  4928. var startPosition = this.position.clone();
  4929. var startTarget = this.getPivot();
  4930. //const endPosition = position.clone();
  4931. //const endTarget = target.clone();
  4932. var easing = TWEEN.Easing.Quartic.Out;
  4933. if (duration === 0) {
  4934. this.position.copy(endPosition);
  4935. this.lookAt(endTarget);
  4936. } else {
  4937. var value = {
  4938. x: 0
  4939. };
  4940. var tween = new TWEEN.Tween(value).to({
  4941. x: 1
  4942. }, duration);
  4943. tween.easing(easing);
  4944. //this.tweens.push(tween);
  4945. tween.onUpdate(() => {
  4946. var t = value.x;
  4947. //console.log(t);
  4948. var pos = new Vector3((1 - t) * startPosition.x + t * endPosition.x, (1 - t) * startPosition.y + t * endPosition.y, (1 - t) * startPosition.z + t * endPosition.z);
  4949. var target = new Vector3((1 - t) * startTarget.x + t * endTarget.x, (1 - t) * startTarget.y + t * endTarget.y, (1 - t) * startTarget.z + t * endTarget.z);
  4950. this.position.copy(pos);
  4951. this.lookAt(target);
  4952. });
  4953. tween.start();
  4954. tween.onComplete(() => {
  4955. if (callback) {
  4956. callback();
  4957. }
  4958. });
  4959. }
  4960. }
  4961. }
  4962. ;
  4963. var sid = 0;
  4964. class ExtendView extends View {
  4965. constructor() {
  4966. super();
  4967. this.yaw = 0; //Math.PI / 4; // = 4dkk lon + 90
  4968. this._pitch = 0; //-Math.PI / 4; //上下旋转 = 4dkk lat
  4969. this.sid = sid++;
  4970. this.LookTransition = 'LookTransition' + this.sid;
  4971. this.FlyTransition = 'FlyTransition' + this.sid;
  4972. }
  4973. //add------
  4974. applyToCamera(camera) {
  4975. camera.position.copy(this.position);
  4976. camera.rotation.copy(this.rotation);
  4977. camera.updateMatrix();
  4978. camera.updateMatrixWorld();
  4979. //camera.matrixWorldInverse.copy(camera.matrixWorld).invert();
  4980. }
  4981. get rotation() {
  4982. var rotation = new Euler();
  4983. rotation.order = "ZXY";
  4984. rotation.x = Math.PI / 2 + this.pitch;
  4985. rotation.z = this.yaw;
  4986. return rotation;
  4987. }
  4988. set rotation(rotation) {
  4989. if (rotation.y != 0) {
  4990. //因为 rotation的y不一定是0 , 所以不能直接逆着get rotation写。
  4991. //console.error('set rotation y不为0!!!!?', rotation ) //过渡时因为quaternion lerp所以不为0。没办法了orz
  4992. this.direction = new Vector3(0, 0, -1).applyEuler(rotation); //转回direction有损耗,在俯视时的(dir.x==dir.y==0), 丢失yaw信息从而 yaw无法获取(希望不要遇到这种情况,如果有的话,考虑先计算yaw,似乎好像可以算)
  4993. } else {
  4994. //尽量不用direction
  4995. this.pitch = rotation.x - Math.PI / 2;
  4996. this.yaw = rotation.z;
  4997. }
  4998. }
  4999. get quaternion() {
  5000. return new Quaternion().setFromEuler(this.rotation);
  5001. }
  5002. set quaternion(q) {
  5003. this.rotation = new Euler().setFromQuaternion(q);
  5004. }
  5005. copy(a) {
  5006. Common.CopyClassObject(this, a, {
  5007. ignoreList: ['_listeners']
  5008. });
  5009. }
  5010. clone() {
  5011. return Common.CloneClassObject(this, {
  5012. ignoreList: ['_listeners']
  5013. });
  5014. }
  5015. //----------
  5016. setCubeView(dir) {
  5017. switch (dir) {
  5018. case "front":
  5019. this.yaw = 0;
  5020. this.pitch = 0;
  5021. break;
  5022. case "back":
  5023. this.yaw = Math.PI;
  5024. this.pitch = 0;
  5025. break;
  5026. case "left":
  5027. this.yaw = -Math.PI / 2;
  5028. this.pitch = 0;
  5029. break;
  5030. case "right":
  5031. this.yaw = Math.PI / 2;
  5032. this.pitch = 0;
  5033. break;
  5034. case "top":
  5035. this.yaw = 0;
  5036. this.pitch = -Math.PI / 2;
  5037. break;
  5038. case "bottom":
  5039. this.yaw = -Math.PI;
  5040. this.pitch = Math.PI / 2;
  5041. break;
  5042. }
  5043. }
  5044. /* pan (x, y) {
  5045. let dir = new THREE.Vector3(0, 1, 0);
  5046. dir.applyAxisAngle(new THREE.Vector3(1, 0, 0), this.pitch);
  5047. dir.applyAxisAngle(new THREE.Vector3(0, 0, 1), this.yaw);
  5048. // let side = new THREE.Vector3(1, 0, 0);
  5049. // side.applyAxisAngle(new THREE.Vector3(0, 0, 1), this.yaw);
  5050. let side = this.getSide();
  5051. let up = side.clone().cross(dir);
  5052. let pan = side.multiplyScalar(x).add(up.multiplyScalar(y));
  5053. this.position = this.position.add(pan);
  5054. // this.target = this.target.add(pan);
  5055. } */
  5056. pan(x, y) {
  5057. //发现pan其实就是translate
  5058. this.translate(x, 0, y);
  5059. }
  5060. translate(x, y, z, forceHorizon) {
  5061. //相机方向
  5062. var dir = new Vector3(0, 1, 0);
  5063. dir.applyAxisAngle(new Vector3(1, 0, 0), forceHorizon ? 0 : this.pitch); //上下角度
  5064. dir.applyAxisAngle(new Vector3(0, 0, 1), this.yaw); //水平角度
  5065. var side = new Vector3(1, 0, 0);
  5066. side.applyAxisAngle(new Vector3(0, 0, 1), this.yaw); //垂直于相机当前水平朝向的 左右方向
  5067. var up = side.clone().cross(dir); //垂直于相机当前水平朝向的 向上方向
  5068. var t = side.multiplyScalar(x) //x影响 左右分量
  5069. .add(dir.multiplyScalar(y)) //y影响 前后分量
  5070. .add(up.multiplyScalar(z)); //z影响 上下分量
  5071. this.position = this.position.add(t);
  5072. if ((!math.closeTo(x, 0, 1e-2) || !math.closeTo(y, 0, 1e-2) || !math.closeTo(z, 0, 1e-2)) && Potree.settings.displayMode != 'showPanos') {
  5073. this.cancelFlying('pos');
  5074. }
  5075. this.restrictPos();
  5076. }
  5077. translateWorld(x, y, z) {
  5078. super.translateWorld(x, y, z);
  5079. if ((!math.closeTo(x, 0, 1e-2) || !math.closeTo(y, 0, 1e-2) || !math.closeTo(z, 0, 1e-2)) && Potree.settings.displayMode != 'showPanos') {
  5080. this.cancelFlying('pos');
  5081. }
  5082. this.restrictPos();
  5083. }
  5084. restrictPos(position) {
  5085. //add
  5086. if (this.limitBound) {
  5087. (position || this.position).clamp(this.limitBound.min, this.limitBound.max);
  5088. }
  5089. }
  5090. isFlying() {
  5091. var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'all';
  5092. var a = transitions.getById(this.FlyTransition).length > 0;
  5093. var b = transitions.getById(this.LookTransition).length > 0;
  5094. return type == 'pos' ? a : type == 'rotate' ? b : a || b;
  5095. }
  5096. cancelFlying() {
  5097. var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'all';
  5098. var dealCancel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  5099. //外界只能通过这个来cancel
  5100. type == 'pos' ? transitions.cancelById(this.FlyTransition, dealCancel) : type == 'rotate' ? transitions.cancelById(this.LookTransition, dealCancel) : (transitions.cancelById(this.FlyTransition, dealCancel), transitions.cancelById(this.LookTransition, dealCancel));
  5101. //console.log('cancelFlying ' , this.sid, type)
  5102. }
  5103. setView() {
  5104. var info = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  5105. // position, target, duration = 0, callback = null, onUpdate = null, Easing='', cancelFun
  5106. this.cancelFlying();
  5107. var posWaitDone, rotWaitDone, dir;
  5108. var posDone = () => {
  5109. rotWaitDone || done();
  5110. posWaitDone = false;
  5111. };
  5112. var rotDone = () => {
  5113. if (endTarget) {
  5114. this.lookAt(endTarget); //compute radius for orbitcontrol
  5115. } else if (endQuaternion) {
  5116. this.rotation = new Euler().setFromQuaternion(endQuaternion);
  5117. } else if (endYaw != void 0) {
  5118. this.yaw = endYaw, this.pitch = endPitch;
  5119. }
  5120. //if(dir.x == 0 && dir.y == 0)this.yaw = 0 //统一一下 朝上的话是正的。朝下的一般不是0,会保留一个接近0的小数所以不用管
  5121. posWaitDone || done();
  5122. rotWaitDone = false;
  5123. };
  5124. var done = () => {
  5125. //一定要旋转和位移都结束了才能执行
  5126. var f = () => {
  5127. this.position.copy(endPosition); //因为延时1后control的update会导致位置改变
  5128. info.callback && info.callback();
  5129. this.dispatchEvent('flyingDone');
  5130. };
  5131. if (info.duration) {
  5132. setTimeout(f, 1); //延迟是为了使isFlying先为false
  5133. } else {
  5134. f(); //有的需要迅速执行回调
  5135. }
  5136. };
  5137. var endPosition = new Vector3().copy(info.position);
  5138. var startPosition = this.position.clone();
  5139. var startQuaternion,
  5140. endQuaternion,
  5141. endTarget = info.target && new Vector3().copy(info.target),
  5142. endYaw,
  5143. startYaw,
  5144. endPitch,
  5145. startPitch;
  5146. this.restrictPos(endPosition);
  5147. if (info.endYaw == void 0) {
  5148. if (info.target) {
  5149. endQuaternion = math.getQuaFromPosAim(endPosition, endTarget); //若为垂直,会自动偏向x负的方向
  5150. } else if (info.quaternion) {
  5151. endQuaternion = info.quaternion.clone();
  5152. }
  5153. if (endQuaternion && math.closeTo(Math.abs(this.direction.z), 1, 1e-4)) {
  5154. //在垂直的视角下的quaternion刚开始突变的厉害,这时候可能渐变yaw比较好(如俯视时点击测量线)
  5155. var a = this.clone();
  5156. a.quaternion = endQuaternion;
  5157. info.endYaw = a.yaw;
  5158. info.endPitch = a.pitch;
  5159. //console.log('turn to yaw')
  5160. }
  5161. }
  5162. if (info.endYaw != void 0) {
  5163. startPitch = this.pitch;
  5164. endPitch = info.endPitch;
  5165. startYaw = this.yaw;
  5166. endYaw = info.endYaw;
  5167. if (Math.abs(startYaw - endYaw) > Math.PI) {
  5168. //如果差距大于半个圆,就要反个方向转(把大的那个数字减去360度)
  5169. startYaw > endYaw ? startYaw -= Math.PI * 2 : endYaw -= Math.PI * 2;
  5170. }
  5171. //console.log('startYaw', startYaw, 'endYaw', endYaw)
  5172. }
  5173. if (endQuaternion) {
  5174. startQuaternion = this.quaternion;
  5175. }
  5176. if (!info.duration) {
  5177. this.position.copy(endPosition);
  5178. this.restrictPos();
  5179. posWaitDone = true, rotWaitDone = true;
  5180. info.onUpdate && info.onUpdate(1);
  5181. posDone();
  5182. rotDone();
  5183. } else {
  5184. info.onUpdate && info.onUpdate(0); //初始化progress
  5185. var posChange = !this.position.equals(endPosition);
  5186. if (posChange) {
  5187. posWaitDone = true;
  5188. transitions.start(lerp.vector(this.position, endPosition, (pos, progress, delta) => {
  5189. info.onUpdate && info.onUpdate(progress, delta);
  5190. }), info.duration, posDone, 0, info.Easing ? easing[info.Easing] : easing.easeInOutSine, null, this.FlyTransition, () => {
  5191. //中途取消
  5192. if (rotWaitDone) {
  5193. /* endPosition = new THREE.Vector3().copy(this.position)//更改旋转的endQuaternion
  5194. endQuaternion = math.getQuaFromPosAim(endPosition,endTarget) */
  5195. //直接改变endQuaternion会突变,所以还是cancel吧
  5196. this.cancelFlying('rotate');
  5197. } else {
  5198. this.dispatchEvent('flyCancel');
  5199. }
  5200. posWaitDone = false;
  5201. info.cancelFun && info.cancelFun();
  5202. }, info.ignoreFirstFrame);
  5203. }
  5204. if (endQuaternion || endYaw != void 0) {
  5205. rotWaitDone = true;
  5206. transitions.start((progress, delta) => {
  5207. if (endYaw != void 0) {
  5208. this.yaw = startYaw * (1 - progress) + endYaw * progress;
  5209. this.pitch = startPitch * (1 - progress) + endPitch * progress;
  5210. } else {
  5211. var quaternion = new Quaternion().copy(startQuaternion);
  5212. lerp.quaternion(quaternion, endQuaternion)(progress); //在垂直的视角下的角度突变的厉害,这时候可能渐变yaw比较好
  5213. this.quaternion = quaternion;
  5214. //console.log(quaternion,this.yaw)
  5215. }
  5216. posChange || info.onUpdate && info.onUpdate(progress, delta);
  5217. }, info.duration, rotDone, 0, info.Easing ? easing[info.Easing] : easing.easeInOutSine, null, this.LookTransition, () => {
  5218. //中途取消
  5219. rotWaitDone = false;
  5220. info.cancelFun && info.cancelFun();
  5221. this.dispatchEvent('flyCancel');
  5222. }, info.ignoreFirstFrame);
  5223. }
  5224. if (!posWaitDone && !rotWaitDone) {
  5225. //已经到达目标
  5226. info.onUpdate && info.onUpdate(1);
  5227. done();
  5228. }
  5229. /* transitions.start(lerp.vector(this.position, endPosition, (pos, progress)=>{
  5230. let t = progress
  5231. if(endQuaternion){
  5232. let quaternion = (new THREE.Quaternion()).copy(startQuaternion)
  5233. lerp.quaternion(quaternion, endQuaternion)(progress),
  5234. this.rotation = new THREE.Euler().setFromQuaternion(quaternion)
  5235. }
  5236. this.restrictPos()
  5237. //console.log('setView flying')
  5238. info.onUpdate && info.onUpdate(t)//add
  5239. }), info.duration, done, 0, info.Easing ? easing[info.Easing] : easing.easeInOutSine ,null, this.LookTransition, info.cancelFun); //easeInOutQuad
  5240. */
  5241. }
  5242. }
  5243. //平移Ortho相机
  5244. moveOrthoCamera(viewport, info, duration, easeName) {
  5245. //boundSize优先于endZoom。
  5246. var camera = info.camera || viewport.camera;
  5247. var startZoom = camera.zoom;
  5248. var endPosition = info.endPosition;
  5249. var boundSize = info.boundSize;
  5250. var endZoom = info.endZoom;
  5251. var margin = info.margin || {
  5252. x: 0,
  5253. y: 0
  5254. }; /* 200 */ //像素
  5255. var _onUpdate = info.onUpdate;
  5256. if (info.bound) {
  5257. //需要修改boundSize以适应相机的旋转,当相机不在xy水平面上朝向z时
  5258. endPosition = endPosition || info.bound.getCenter(new Vector3());
  5259. var matrixRot = new Matrix4().makeRotationFromEuler(this.rotation).invert();
  5260. var boundingBox = info.bound.clone().applyMatrix4(matrixRot);
  5261. boundSize = boundingBox.getSize(new Vector3());
  5262. }
  5263. if (boundSize && boundSize.x == 0 && boundSize.y == 0) {
  5264. boundSize.set(1, 1); //避免infinity
  5265. }
  5266. this.setView(Object.assign(info, {
  5267. position: endPosition,
  5268. duration,
  5269. onUpdate: (progress, delta) => {
  5270. if (boundSize || endZoom) {
  5271. if (boundSize) {
  5272. var aspect = boundSize.x / boundSize.y;
  5273. var w, h;
  5274. if (camera.aspect > aspect) {
  5275. //视野更宽则用bound的纵向来决定
  5276. h = boundSize.y;
  5277. endZoom = (viewport.resolution.y - margin.y) / h; //注意,要在resolution不为0时执行
  5278. } else {
  5279. w = boundSize.x;
  5280. endZoom = (viewport.resolution.x - margin.x) / w;
  5281. }
  5282. //onUpdate时更新endzoom是因为画布大小可能更改
  5283. }
  5284. this.zoom = camera.zoom = endZoom * progress + startZoom * (1 - progress); //view里也加一下,有些地方需要记录,如截图
  5285. camera.updateProjectionMatrix();
  5286. _onUpdate && _onUpdate(progress, delta);
  5287. }
  5288. },
  5289. Easing: easeName
  5290. }));
  5291. }
  5292. zoomOrthoCamera(camera, endZoom, pointer, duration, onProgress) {
  5293. //定点缩放
  5294. var startZoom = camera.zoom;
  5295. var pointerPos = new Vector3(pointer.x, pointer.y, 0.5);
  5296. transitions.start(progress => {
  5297. var oldPos = pointerPos.clone().unproject(camera);
  5298. this.zoom = camera.zoom = endZoom * progress + startZoom * (1 - progress);
  5299. camera.updateProjectionMatrix();
  5300. var newPos = pointerPos.clone().unproject(camera);
  5301. //定点缩放, 恢复一下鼠标所在位置的位置改变量
  5302. var moveVec = new Vector3().subVectors(newPos, oldPos);
  5303. camera.position.sub(moveVec);
  5304. this.position.copy(camera.position);
  5305. onProgress && onProgress();
  5306. }, duration, null /* done */, 0, easing.easeInOutSine, null, "zoomInView" /* , info.cancelFun */);
  5307. }
  5308. tranCamera(viewport, info, duration, easeName) {
  5309. viewport.camera = info.midCamera;
  5310. //viewport.camera.matrixWorld = info.endCamera.matrixWorld
  5311. //viewer.setCameraMode(CameraMode.ORTHOGRAPHIC)
  5312. info.midCamera.projectionMatrix.copy(info.startCamera.projectionMatrix);
  5313. var onUpdate = info.onUpdate;
  5314. info.onUpdate = (progress, delta) => {
  5315. lerp.matrix4(info.midCamera.projectionMatrix, info.endCamera.projectionMatrix)(progress);
  5316. onUpdate && onUpdate(progress, delta);
  5317. };
  5318. var callback = info.callback;
  5319. info.callback = () => {
  5320. viewport.camera = info.endCamera;
  5321. viewer.scene.measurements.forEach(e => {
  5322. Potree.Utils.updateVisible(e, 'tranCamera', true);
  5323. });
  5324. this.applyToCamera(viewport.camera);
  5325. viewer.dispatchEvent({
  5326. type: 'camera_changed',
  5327. viewport: viewer.mainViewport,
  5328. changeInfo: {}
  5329. }); //update sprite
  5330. callback && callback();
  5331. };
  5332. //info.forbitCancel = true
  5333. info.camera = info.endCamera;
  5334. if (info.camera.type == "OrthographicCamera") {
  5335. this.moveOrthoCamera(viewport, info, duration, easeName);
  5336. } else {
  5337. this.setView(Object.assign(info, {
  5338. duration
  5339. }));
  5340. }
  5341. }
  5342. }
  5343. ;
  5344. var math = {
  5345. getBaseLog(x, y) {
  5346. //返回以 x 为底 y 的对数(即 logx y) . Math.log 返回一个数的自然对数
  5347. return Math.log(y) / Math.log(x);
  5348. },
  5349. convertVector: {
  5350. ZupToYup: function ZupToYup(e) {
  5351. //navvis -> 4dkk
  5352. return new Vector3(e.x, e.z, -e.y);
  5353. },
  5354. YupToZup: function YupToZup(e) {
  5355. //4dkk -> navvis
  5356. return new Vector3(e.x, -e.z, e.y);
  5357. }
  5358. },
  5359. convertQuaternion: {
  5360. ZupToYup: function ZupToYup(e) {
  5361. //navvis -> 4dkk //不同于convertVisionQuaternion
  5362. var rotation = new Euler(-Math.PI / 2, 0, 0);
  5363. var quaternion = new Quaternion().setFromEuler(rotation);
  5364. return e.clone().premultiply(quaternion);
  5365. //return new THREE.Quaternion(e.x,e.z,-e.y,e.w).multiply((new THREE.Quaternion).setFromAxisAngle(new THREE.Vector3(1,0,0), THREE.Math.degToRad(90)))
  5366. },
  5367. YupToZup: function YupToZup(e) {
  5368. //4dkk -> navvis
  5369. var rotation = new Euler(Math.PI / 2, 0, 0);
  5370. var quaternion = new Quaternion().setFromEuler(rotation);
  5371. return e.clone().premultiply(quaternion);
  5372. }
  5373. },
  5374. convertVisionQuaternion: function convertVisionQuaternion(e) {
  5375. return new Quaternion(e.x, e.z, -e.y, e.w).multiply(new Quaternion().setFromAxisAngle(new Vector3(0, 1, 0), MathUtils.degToRad(90)));
  5376. },
  5377. invertVisionQuaternion: function invertVisionQuaternion(e) {
  5378. //反转给算法部
  5379. var a = e.clone().multiply(new Quaternion().setFromAxisAngle(new Vector3(0, 1, 0), MathUtils.degToRad(-90)));
  5380. return new Quaternion(a.x, -a.z, a.y, a.w);
  5381. },
  5382. //------------
  5383. getVec2Angle: function getVec2Angle(dir1, dir2) {
  5384. return Math.acos(MathUtils.clamp(this.getVec2Cos(dir1, dir2), -1, 1));
  5385. },
  5386. getVec2Cos: function getVec2Cos(dir1, dir2) {
  5387. return dir1.dot(dir2) / dir1.length() / dir2.length();
  5388. },
  5389. getAngle: function getAngle(vec1, vec2) {
  5390. var axis = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'z';
  5391. //带方向的角度 vector3
  5392. if (!vec1.isVector3) {
  5393. vec1 = new Vector3(vec1.x, vec1.y, 0);
  5394. vec2 = new Vector3(vec2.x, vec2.y, 0);
  5395. }
  5396. var angle = vec1.angleTo(vec2);
  5397. var axis_ = vec1.clone().cross(vec2);
  5398. if (typeof axis == 'string') {
  5399. if (axis_[axis] < 0) {
  5400. angle *= -1;
  5401. }
  5402. } else {
  5403. //vector3
  5404. if (axis_.dot(axis) < 0) {
  5405. angle *= -1;
  5406. }
  5407. }
  5408. return angle;
  5409. },
  5410. closeTo: function closeTo(a, b) {
  5411. var precision = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1e-6;
  5412. var f = (a, b) => {
  5413. return Math.abs(a - b) < precision;
  5414. };
  5415. if (typeof a == 'number') {
  5416. return f(a, b);
  5417. } else {
  5418. var judge = name => {
  5419. if (a[name] == void 0) return true; //有值就判断,没值就不判断
  5420. else return f(a[name], b[name]);
  5421. };
  5422. return judge('x') && judge('y') && judge('z') && judge('w');
  5423. }
  5424. },
  5425. toPrecision: function toPrecision(e, t) {
  5426. //xzw change 保留小数
  5427. var f = function f(e, t) {
  5428. var i = Math.pow(10, t);
  5429. return Math.round(e * i) / i;
  5430. };
  5431. if (e instanceof Array) {
  5432. for (var s = 0; s < e.length; s++) {
  5433. e[s] = f(e[s], t);
  5434. }
  5435. return e;
  5436. } else if (e instanceof Object) {
  5437. for (var s in e) {
  5438. e[s] = f(e[s], t);
  5439. }
  5440. return e;
  5441. } else if (typeof e == 'number') {
  5442. return f(e, t);
  5443. } else {
  5444. return e;
  5445. }
  5446. },
  5447. isEmptyQuaternion: function isEmptyQuaternion(e) {
  5448. return 0 === Math.abs(e.x) && 0 === Math.abs(e.y) && 0 === Math.abs(e.z) && 0 === Math.abs(e.w);
  5449. },
  5450. projectPositionToCanvas: function projectPositionToCanvas(e, t, i) {
  5451. i = i || new Vector3(), i.copy(e);
  5452. var r = .5 * $('#player').width(),
  5453. o = .5 * $('#player').height();
  5454. return i.project(t), i.x = i.x * r + r, i.y = -(i.y * o) + o, i;
  5455. },
  5456. handelPadResize: false,
  5457. /* handelPadding : function () { //去除player左边和上面的宽高,因为pc的player左上有其他element 许钟文
  5458. var pads = [];//记录下来避免反复计算
  5459. var index = [];
  5460. var resetPad = function(){
  5461. pads = [];
  5462. index = [];
  5463. math.handelPadResize = false; //switchview时resized为true
  5464. }
  5465. if(config.isEdit && !config.isMobile){
  5466. window.addEventListener('resize',resetPad);
  5467. }
  5468. return function(x, y, domE){
  5469. if(!config.isEdit || config.isMobile) {
  5470. return {
  5471. x: x,
  5472. y: y
  5473. }
  5474. }
  5475. if(this.handelPadResize)resetPad();
  5476. domE = domE || $('#player')[0];
  5477. var pad;
  5478. var i = index.indexOf(domE);
  5479. if (i == -1){
  5480. index.push(domE);
  5481. pad = {
  5482. x: this.getOffset("left", domE),
  5483. y: this.getOffset("top", domE)
  5484. }
  5485. pads.push(pad)
  5486. }
  5487. else pad = pads[i];
  5488. return {
  5489. x: x - pad.x,
  5490. y: y - pad.y
  5491. }
  5492. }
  5493. }(), */
  5494. getOffset: function getOffset(type, element, parent) {
  5495. //获取元素的边距 许钟文
  5496. var offset = type == "left" ? element.offsetLeft : element.offsetTop;
  5497. if (!parent) parent = $("body")[0];
  5498. while (element = element.offsetParent) {
  5499. if (element == parent) break;
  5500. offset += type == "left" ? element.offsetLeft : element.offsetTop;
  5501. }
  5502. return offset;
  5503. },
  5504. constrainedTurn: function constrainedTurn(e) {
  5505. var t = e % (2 * Math.PI);
  5506. return t = t > Math.PI ? t -= 2 * Math.PI : t < -Math.PI ? t += 2 * Math.PI : t;
  5507. },
  5508. getFOVDotThreshold: function getFOVDotThreshold(e) {
  5509. return Math.cos(MathUtils.degToRad(e / 2));
  5510. },
  5511. transform2DForwardVectorByCubeFace: function transform2DForwardVectorByCubeFace(e, t, i, n) {
  5512. switch (e) {
  5513. case GLCubeFaces.GL_TEXTURE_CUBE_MAP_POSITIVE_X:
  5514. i.set(1, t.y, t.x);
  5515. break;
  5516. case GLCubeFaces.GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
  5517. i.set(-1, t.y, -t.x);
  5518. break;
  5519. case GLCubeFaces.GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
  5520. i.set(-t.x, 1, -t.y);
  5521. break;
  5522. case GLCubeFaces.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
  5523. i.set(-t.x, -1, t.y);
  5524. break;
  5525. case GLCubeFaces.GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
  5526. i.set(-t.x, t.y, 1);
  5527. break;
  5528. case GLCubeFaces.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
  5529. i.set(t.x, t.y, -1);
  5530. }
  5531. n && i.normalize();
  5532. },
  5533. getFootPoint: function getFootPoint(oldPos, p1, p2, restricInline) {
  5534. //找oldPos在线段p1, p2上的垂足
  5535. /* if(isWorld){//输出全局坐标 需要考虑meshGroup.position
  5536. p1 = p1.clone();
  5537. p2 = p2.clone();
  5538. p1.y += mainDesign.meshGroup.position.y;
  5539. p2.y += mainDesign.meshGroup.position.y;
  5540. } */
  5541. if (p1.equals(p2)) return p1.clone();
  5542. var op1 = oldPos.clone().sub(p1);
  5543. var p1p2 = p1.clone().sub(p2);
  5544. var p1p2Len = p1p2.length();
  5545. var leftLen = op1.dot(p1p2) / p1p2Len;
  5546. var pos = p1.clone().add(p1p2.multiplyScalar(leftLen / p1p2Len));
  5547. if (restricInline && pos.clone().sub(p1).dot(pos.clone().sub(p2)) > 0) {
  5548. //foot不在线段上
  5549. if (pos.distanceTo(p1) < pos.distanceTo(p2)) pos = p1.clone();else pos = p2.clone();
  5550. }
  5551. return pos;
  5552. },
  5553. /**
  5554. * 计算多边形的重心
  5555. * @param {*} points
  5556. */
  5557. getCenterOfGravityPoint: function getCenterOfGravityPoint(mPoints) {
  5558. var area = 0.0; //多边形面积
  5559. var Gx = 0.0,
  5560. Gy = 0.0; // 重心的x、y
  5561. for (var i = 1; i <= mPoints.length; i++) {
  5562. var ix = mPoints[i % mPoints.length].x;
  5563. var iy = mPoints[i % mPoints.length].y;
  5564. var nx = mPoints[i - 1].x;
  5565. var ny = mPoints[i - 1].y;
  5566. var temp = (ix * ny - iy * nx) / 2.0;
  5567. area += temp;
  5568. Gx += temp * (ix + nx) / 3.0;
  5569. Gy += temp * (iy + ny) / 3.0;
  5570. }
  5571. Gx = Gx / area;
  5572. Gy = Gy / area;
  5573. return {
  5574. x: Gx,
  5575. y: Gy
  5576. };
  5577. },
  5578. getBound: function getBound(ring) {
  5579. var bound = new Box2();
  5580. for (var j = 0, len = ring.length; j < len; j++) {
  5581. bound.expandByPoint(ring[j]);
  5582. }
  5583. return bound;
  5584. },
  5585. isPointInArea: function isPointInArea(ring, holes, point, ifAtLine) {
  5586. //判断点是否在某个环内, 若传递了holes代表还要不能在内环内
  5587. var bound = this.getBound(ring);
  5588. if (point.x < bound.min.x || point.x > bound.max.x || point.y < bound.min.y || point.y > bound.max.y) return false;
  5589. var inside = false;
  5590. var x = point.x,
  5591. y = point.y;
  5592. for (var i = 0, j = ring.length - 1; i < ring.length; j = i++) {
  5593. var xi = ring[i].x,
  5594. yi = ring[i].y;
  5595. var xj = ring[j].x,
  5596. yj = ring[j].y;
  5597. if ((xi - x) * (yj - y) == (xi - x) * (yi - y) && x >= Math.min(xi, xj) && x <= Math.max(xi, xj) //xzw add
  5598. && y >= Math.min(yi, yj) && y <= Math.max(yi, yj)) {
  5599. //return !!ifAtLine;//在线段上,则判断为…… (默认在外)
  5600. return {
  5601. atLine: true
  5602. };
  5603. }
  5604. if (yi > y != yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi) {
  5605. inside = !inside;
  5606. }
  5607. }
  5608. if (inside && holes) {
  5609. return !holes.some(ring => this.isPointInArea(ring, null, point, ifAtLine)); //不能存在于任何一个二级内环内
  5610. } else {
  5611. return inside;
  5612. }
  5613. },
  5614. getArea: function getArea(ring) {
  5615. //求面积 顺时针为正 来自three shape
  5616. for (var t = ring.length, i = 0, n = t - 1, r = 0; r < t; n = r++) i += ring[n].x * ring[r].y - ring[r].x * ring[n].y;
  5617. return -.5 * i;
  5618. },
  5619. getVolume: function getVolume(faceArr) {//求三角多面体的体积。和求面积同理都用鞋带计算法 https://blog.csdn.net/weixin_43414513/article/details/123758897
  5620. //问题:怎么确定方向
  5621. //每个三角形的顺序必须是右手螺旋法则指向物体外(外向里看为逆时针),分别为ABC,则每个三角形和原点O构成的三棱锥体积为 (OA cross OB) dot(OC) / 6 . 结果一般朝向原点的为负,反之为正
  5622. },
  5623. isInBetween: function isInBetween(a, b, c, precision) {
  5624. // 如果b几乎等于a或c,返回false.为了避免浮点运行时两值几乎相等,但存在相差0.00000...0001的这种情况出现使用下面方式进行避免
  5625. /* if (Math.abs(a - b) < 0.000001 || Math.abs(b - c) < 0.000001) {
  5626. return false;
  5627. }
  5628. return (a <= b && b <= c) || (c <= b && b <= a);*/
  5629. //更改:如果b和a或c中一个接近 就算在a和c之间
  5630. return a <= b && b <= c || c <= b && b <= a || this.closeTo(a, b, precision) || this.closeTo(b, c, precision);
  5631. },
  5632. ifPointAtLineBound: function ifPointAtLineBound(point, linePoints, precision) {
  5633. //待验证 横线和竖线比较特殊
  5634. return math.isInBetween(linePoints[0].x, point.x, linePoints[1].x, precision) && math.isInBetween(linePoints[0].y, point.y, linePoints[1].y, precision);
  5635. },
  5636. isLineIntersect: function isLineIntersect(line1, line2, notSegment, precision) {
  5637. //线段和线段是否有交点. notSegment代表是直线而不是线段
  5638. var a1 = line1[1].y - line1[0].y;
  5639. var b1 = line1[0].x - line1[1].x;
  5640. var c1 = a1 * line1[0].x + b1 * line1[0].y;
  5641. //转换成一般式: Ax+By = C
  5642. var a2 = line2[1].y - line2[0].y;
  5643. var b2 = line2[0].x - line2[1].x;
  5644. var c2 = a2 * line2[0].x + b2 * line2[0].y;
  5645. // 计算交点
  5646. var d = a1 * b2 - a2 * b1;
  5647. // 当d==0时,两线平行
  5648. if (d == 0) {
  5649. return false;
  5650. } else {
  5651. var x = (b2 * c1 - b1 * c2) / d;
  5652. var y = (a1 * c2 - a2 * c1) / d;
  5653. // 检测交点是否在两条线段上
  5654. /* if (notSegment || (isInBetween(line1[0].x, x, line1[1].x) || isInBetween(line1[0].y, y, line1[1].y)) &&
  5655. (isInBetween(line2[0].x, x, line2[1].x) || isInBetween(line2[0].y, y, line2[1].y))) {
  5656. return {x,y};
  5657. } */
  5658. if (notSegment || math.ifPointAtLineBound({
  5659. x,
  5660. y
  5661. }, line1, precision) && math.ifPointAtLineBound({
  5662. x,
  5663. y
  5664. }, line2, precision)) {
  5665. return {
  5666. x,
  5667. y
  5668. };
  5669. }
  5670. }
  5671. },
  5672. getNormal2d: function getNormal2d() {
  5673. var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  5674. //获取二维法向量 方向向内
  5675. var x, y, x1, y1;
  5676. //line2d的向量
  5677. if (o.vec) {
  5678. x1 = o.vec.x;
  5679. y1 = o.vec.y;
  5680. } else {
  5681. x1 = o.p1.x - o.p2.x;
  5682. y1 = o.p1.y - o.p2.y;
  5683. }
  5684. //假设法向量的x或y固定为1或-1
  5685. if (y1 != 0) {
  5686. x = 1;
  5687. y = -(x1 * x) / y1;
  5688. } else if (x1 != 0) {
  5689. //y如果为0,正常情况x不会是0
  5690. y = 1;
  5691. x = -(y1 * y) / x1;
  5692. } else {
  5693. console.log("两个点一样");
  5694. return null;
  5695. }
  5696. //判断方向里或者外:
  5697. var vNormal = new Vector3(x, 0, y);
  5698. var vLine = new Vector3(x1, 0, y1);
  5699. var vDir = vNormal.cross(vLine);
  5700. if (vDir.y > 0) {
  5701. x *= -1;
  5702. y *= -1;
  5703. }
  5704. return new Vector2(x, y).normalize();
  5705. },
  5706. getQuaBetween2Vector: function getQuaBetween2Vector(oriVec, newVec, upVec) {
  5707. //获取从oriVec旋转到newVec可以应用的quaternion
  5708. var angle = oriVec.angleTo(newVec);
  5709. var axis = oriVec.clone().cross(newVec).normalize(); //两个up之间
  5710. if (axis.length() == 0) {
  5711. //当夹角为180 或 0 度时,得到的axis为(0,0,0),故使用备用的指定upVec
  5712. return new Quaternion().setFromAxisAngle(upVec, angle);
  5713. }
  5714. return new Quaternion().setFromAxisAngle(axis, angle);
  5715. },
  5716. /*
  5717. getQuaBetween2Vector2 : function(oriVec, newVec ){//not camera
  5718. var _ = (new THREE.Matrix4).lookAt( oriVec, new THREE.Vector3, new THREE.Vector3(0,1,0))
  5719. var aimQua = (new THREE.Quaternion).setFromRotationMatrix(_)
  5720. var _2 = (new THREE.Matrix4).lookAt( newVec, new THREE.Vector3, new THREE.Vector3(0,1,0))
  5721. var aimQua2 = (new THREE.Quaternion).setFromRotationMatrix(_2)
  5722. return aimQua2.multiply(aimQua.clone().inverse())
  5723. } */
  5724. getQuaByAim: function getQuaByAim(aim) {
  5725. var center = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Vector3();
  5726. var forward = new Vector3(0, 1, 0);
  5727. var qua1 = new Quaternion().setFromUnitVectors(forward, aim.clone().sub(center).normalize());
  5728. /* var _ = (new THREE.Matrix4).lookAt(center,aim, new THREE.Vector3(0,1,0));
  5729. let qua2 = (new THREE.Quaternion).setFromRotationMatrix(_);
  5730. let rot1 = new THREE.Euler().setFromQuaternion(qua1)
  5731. let rot2 = new THREE.Euler().setFromQuaternion(qua2) //奇怪,qua2怎么都不对
  5732. console.log(rot1,rot2) */
  5733. return qua1;
  5734. },
  5735. getAimByQua: function getAimByQua(quaternion) {
  5736. var center = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Vector3();
  5737. return new Vector3(0, 0, -1).applyQuaternion(quaternion).add(center);
  5738. },
  5739. getScaleForConstantSize: function () {
  5740. //获得规定二维大小的mesh的scale值。可以避免因camera的projection造成的mesh视觉大小改变。 来源:tag.updateDisc
  5741. var w;
  5742. var i = new Vector3(),
  5743. o = new Vector3(),
  5744. l = new Vector3(),
  5745. c = new Vector3(),
  5746. h = new Vector3();
  5747. return function () {
  5748. var op = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  5749. if (op.width2d) w = op.width2d; //如果恒定二维宽度
  5750. else {
  5751. //否则考虑上距离,加一丢丢近大远小的效果
  5752. var currentDis, nearBound, farBound;
  5753. if (op.camera.type == "OrthographicCamera") {
  5754. currentDis = 200 / op.camera.zoom; //(op.camera.right - op.camera.left) / op.camera.zoom
  5755. } else {
  5756. currentDis = op.position.distanceTo(op.camera.position);
  5757. }
  5758. w = op.maxSize - (op.maxSize - op.minSize) * MathUtils.smoothstep(currentDis, op.nearBound, op.farBound);
  5759. //maxSize : mesh要表现的最大像素宽度; nearBound: 最近距离,若比nearBound近,则使用maxSize
  5760. }
  5761. i.copy(op.position).project(op.camera); //tag中心在屏幕上的二维坐标
  5762. o.set(op.resolution.x / 2, op.resolution.y / 2, 1).multiply(i); //转化成px -w/2 到 w/2的范围
  5763. l.set(w / 2, 0, 0).add(o); //加上tag宽度的一半
  5764. c.set(2 / op.resolution.x, 2 / op.resolution.y, 1).multiply(l); //再转回 -1 到 1的范围
  5765. h.copy(c).unproject(op.camera); //再转成三维坐标,求得tag边缘的位置
  5766. var g = h.distanceTo(op.position); //就能得到tag的三维半径
  5767. //这里使用的都是resolution2, 好处是手机端不会太小, 坏处是pc更改网页显示百分比时显示的大小会变(或许可以自己算出设备真实的deviceRatio, 因window.screen是不会改变的),但考虑到用户可以自行调节字大小也许是好的
  5768. return g; //可能NAN 当相机和position重叠时
  5769. };
  5770. }(),
  5771. //W , H, left, top分别是rect的宽、高、左、上
  5772. getCrossPointAtRect: function getCrossPointAtRect(p1, aim, W, H, left, top) {
  5773. //求射线p1-aim在rect边界上的交点,其中aim在rect范围内,p1则不一定(交点在aim这边的延长线上)
  5774. var x, y, borderX;
  5775. var r = (aim.x - p1.x) / (aim.y - p1.y); //根据相似三角形原理先求出这个比值
  5776. var getX = function getX(y) {
  5777. return r * (y - p1.y) + p1.x;
  5778. };
  5779. var getY = function getY(x) {
  5780. return 1 / r * (x - p1.x) + p1.y;
  5781. };
  5782. if (aim.x >= p1.x) {
  5783. borderX = W + left;
  5784. } else {
  5785. borderX = left;
  5786. }
  5787. x = borderX;
  5788. y = getY(x);
  5789. if (y < top || y > top + H) {
  5790. if (y < top) {
  5791. y = top;
  5792. } else {
  5793. y = top + H;
  5794. }
  5795. x = getX(y);
  5796. }
  5797. return new Vector2(x, y);
  5798. },
  5799. getDirFromUV: function getDirFromUV(uv) {
  5800. //获取dir 反向计算 - - 二维转三维比较麻烦
  5801. var dirB; //所求 单位向量
  5802. var y = Math.cos(uv.y * Math.PI); //uv中纵向可以直接确定y, 根据上面getUVfromDir的反向计算
  5803. // 故 uv.y * Math.PI 就是到垂直线(向上)的夹角
  5804. var angle = 2 * Math.PI * uv.x - Math.PI; //x/z代表的是角度
  5805. var axisX, axisZ; //axis为1代表是正,-1是负数
  5806. if (-Math.PI <= angle && angle < 0) {
  5807. axisX = -1; //下半圆
  5808. } else {
  5809. axisX = 1; //上半圆
  5810. }
  5811. if (-Math.PI / 2 <= angle && angle < Math.PI / 2) {
  5812. axisZ = 1; //右半圆
  5813. } else {
  5814. axisZ = -1; //左半圆
  5815. }
  5816. var XDivideZ = Math.tan(angle);
  5817. var z = Math.sqrt((1 - y * y) / (1 + XDivideZ * XDivideZ));
  5818. var x = XDivideZ * z;
  5819. if (z * axisZ < 0) {
  5820. //异号
  5821. z *= -1;
  5822. x *= -1;
  5823. if (x * axisX < 0) {
  5824. // console.log("wrong!!!!!??????????")
  5825. }
  5826. }
  5827. x *= -1; //计算完成后这里不能漏掉 *= -1
  5828. dirB = this.convertVector.YupToZup(new Vector3(x, y, z));
  5829. //理想状态下x和z和anotherDir相同
  5830. return dirB;
  5831. },
  5832. getUVfromDir: function getUVfromDir(dir) {
  5833. //获取UV 同shader里的计算
  5834. var dir = this.convertVector.ZupToYup(dir);
  5835. dir.x *= -1; //计算前这里不能漏掉 *= -1 见shader
  5836. var tx = Math.atan2(dir.x, dir.z) / (Math.PI * 2.0) + 0.5; //atan2(y,x) 返回从 X 轴正向逆时针旋转到点 (x,y) 时经过的角度。区间是-PI 到 PI 之间的值
  5837. var ty = Math.acos(dir.y) / Math.PI;
  5838. return new Vector2(tx, ty);
  5839. //理想状态下tx相同
  5840. },
  5841. getDirByLonLat: function getDirByLonLat(lon, lat) {
  5842. var dir = new Vector3();
  5843. var phi = MathUtils.degToRad(90 - lat);
  5844. var theta = MathUtils.degToRad(lon);
  5845. dir.x = Math.sin(phi) * Math.cos(theta);
  5846. dir.y = Math.cos(phi);
  5847. dir.z = Math.sin(phi) * Math.sin(theta);
  5848. return dir;
  5849. } //0,0 => (1,0,0) 270=>(0,0,-1)
  5850. ,
  5851. projectPointAtPlane: function projectPointAtPlane() {
  5852. var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  5853. //获取一个点在一个面上的投影 {facePoints:[a,b,c], point:}
  5854. var plane = new Plane().setFromCoplanarPoints(...o.facePoints);
  5855. return plane.projectPoint(o.point, new Vector3());
  5856. },
  5857. getPolygonsMixedRings: function getPolygonsMixedRings(polygons, onlyGetOutRing) {
  5858. //{points:[vector2,...],holes:[[],[]]}
  5859. var points = [];
  5860. var lines = [];
  5861. var i = 0;
  5862. polygons.forEach(e => points.push(...e.map(a => new Vector2().copy(a))));
  5863. polygons.forEach((ps, j) => {
  5864. var length = ps.length;
  5865. var index = 0;
  5866. while (index < length) {
  5867. lines.push({
  5868. p1: index + i,
  5869. p2: (index + 1) % length + i
  5870. });
  5871. index++;
  5872. }
  5873. i += length;
  5874. });
  5875. points.forEach((p, j) => {
  5876. p.id = j;
  5877. });
  5878. var rings = searchRings({
  5879. points,
  5880. lines,
  5881. onlyGetOutRing
  5882. });
  5883. //console.log(rings)
  5884. rings = rings.filter(e => e.closetParent == void 0); // 子环不加,被外环包含了
  5885. return rings;
  5886. },
  5887. getQuaFromPosAim(position, target) {
  5888. /* let matrix = (new THREE.Matrix4).lookAt(position, target, new THREE.Vector3(0,0,1)) //这里垂直的话会默认给一个右向所以不这么写
  5889. return (new THREE.Quaternion).setFromRotationMatrix(matrix) */
  5890. var view = new ExtendView();
  5891. view.direction = new Vector3().subVectors(target, position);
  5892. return view.quaternion;
  5893. },
  5894. getBoundByPoints(points, minSize) {
  5895. var bound = new Box3();
  5896. points.forEach(point => {
  5897. bound.expandByPoint(point);
  5898. });
  5899. var center = bound.getCenter(new Vector3());
  5900. if (minSize) {
  5901. var minBound = new Box3().setFromCenterAndSize(center, minSize);
  5902. bound.union(minBound);
  5903. }
  5904. return {
  5905. bounding: bound,
  5906. size: bound.getSize(new Vector3()),
  5907. center
  5908. };
  5909. },
  5910. /* linearClamp(value, x1,x2, y1, y2){//x为bound.min, bound.max
  5911. value = THREE.Math.clamp(value, x1,x2)
  5912. return y1 + ( y2 - y1) * (value - x1) / (x2 - x1)
  5913. } */
  5914. linearClamp(value, xArr, yArr) {
  5915. //xArr需要按顺序从小到大,yArr对应xArr中的值
  5916. var len = xArr.length;
  5917. if (value <= xArr[0]) return yArr[0];
  5918. if (value >= xArr[len - 1]) return yArr[len - 1];
  5919. var i = 0;
  5920. while (++i < len) {
  5921. if (value < xArr[i]) {
  5922. var x1 = xArr[i - 1],
  5923. x2 = xArr[i],
  5924. y1 = yArr[i - 1],
  5925. y2 = yArr[i];
  5926. value = y1 + (y2 - y1) * (value - x1) / (x2 - x1);
  5927. break;
  5928. }
  5929. }
  5930. return value;
  5931. }
  5932. };
  5933. /*
  5934. 如何将若干个点拟合出线段
  5935. // 假设你有一个点数组,每个点表示为一个包含x和y坐标的对象
  5936. const points = [
  5937. { x: 1, y: 2 },
  5938. { x: 2, y: 3 },
  5939. { x: 3, y: 4 },
  5940. { x: 4, y: 5 },
  5941. // ... 更多点
  5942. ];
  5943. // 定义用于计算最小二乘法参数的函数
  5944. function leastSquares( ) {
  5945. let sumX = 0;
  5946. let sumY = 0;
  5947. let sumXY = 0;
  5948. let sumX2 = 0;
  5949. let n = points.length;
  5950. for (const point of points) {
  5951. sumX += point.x;
  5952. sumY += point.y;
  5953. sumXY += point.x * point.y;
  5954. sumX2 += point.x * point.x;
  5955. }
  5956. const k = (n * sumXY - sumX * sumY) / (n * sumX2 - sumX * sumX); //不知道为何这样算,自己解不出来(使点到直线距离之和平方最小),但测了下似乎是准的
  5957. const b = (sumY - k * sumX) / n;
  5958. return { k, b };
  5959. }
  5960. // 使用上述函数计算拟合直线的参数
  5961. const { k, b } = leastSquares(points);
  5962. // 现在你可以使用这些参数来表示拟合出的线段
  5963. console.log(`拟合线段的方程为: y = ${k}x + ${b}`);
  5964. */
  5965. Potree.math = math;
  5966. function mobileVersion(e, t) {
  5967. //ios的版本
  5968. var i = window.navigator.userAgent,
  5969. n = i.match(e);
  5970. return n = n ? n[1].split(t) : [], {
  5971. major: parseInt(n[0]) || 0,
  5972. minor: parseInt(n[1]) || 0,
  5973. patch: parseInt(n[2]) || 0
  5974. };
  5975. }
  5976. var browser = {
  5977. isFullscreen: function isFullscreen() {
  5978. return document.fullscreenElement || document.mozFullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement || document.msFullscreenElement;
  5979. },
  5980. supportsFullscreen: function supportsFullscreen() {
  5981. return document.fullscreenEnabled || document.mozFullscreenEnabled || document.mozFullScreenEnabled || document.webkitFullscreenEnabled || document.msFullscreenEnabled;
  5982. },
  5983. isPointerLocked: function isPointerLocked() {
  5984. return document.pointerLockElement || document.mozPointerLockElement || document.webkitPointerLockElement;
  5985. },
  5986. requestFullscreen: function requestFullscreen(dom, t) {
  5987. dom.requestFullscreen ? dom.requestFullscreen() : dom.mozRequestFullScreen ? dom.mozRequestFullScreen() : dom.webkitRequestFullscreen ? dom.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT) : dom.msRequestFullscreen && dom.msRequestFullscreen(), t && $(document).on("fullscreenchange webkitfullscreenchange mozfullscreenchange MSFullscreenChange", browser.requestPointerLock);
  5988. },
  5989. requestPointerLock: function requestPointerLock() {
  5990. var e;
  5991. if (document.fullscreenElement) e = document.fullscreenElement();else if (document.mozFullscreenElement) e = document.mozFullscreenElement();else if (document.mozFullScreenElement) e = document.mozFullScreenElement();else {
  5992. if (!document.webkitFullscreenElement) return;
  5993. e = document.webkitFullscreenElement();
  5994. }
  5995. ;
  5996. e.requestPointerLock = e.requestPointerLock || e.mozRequestPointerLock || e.webkitRequestPointerLock, e.requestPointerLock(), $(document).off("fullscreenchange webkitfullscreenchange mozfullscreenchange MSFullscreenChange", this);
  5997. },
  5998. exitPointerLock: function exitPointerLock() {
  5999. ;
  6000. document.exitPointerLock = document.exitPointerLock || document.mozExitPointerLock || document.webkitExitPointerLock, document.exitPointerLock();
  6001. },
  6002. exitFullscreen: function exitFullscreen() {
  6003. document.exitFullscreen ? document.exitFullscreen() : document.msExitFullscreen ? document.msExitFullscreen() : document.mozCancelFullScreen ? document.mozCancelFullScreen() : document.webkitExitFullscreen && document.webkitExitFullscreen();
  6004. },
  6005. details: function details() {
  6006. var e = navigator.userAgent.match("(Firefox|Chrome|Safari)/([\\d]+)");
  6007. return e ? {
  6008. name: e[1],
  6009. version: parseInt(e[2]),
  6010. platform: navigator.platform
  6011. } : {};
  6012. },
  6013. is: function is(e) {
  6014. return this.details() && this.details().name === e;
  6015. },
  6016. inIframe: function inIframe() {
  6017. return window.parent !== window;
  6018. },
  6019. aspectRatio: function aspectRatio($elem) {
  6020. $elem = $elem || $("#player");
  6021. var e = $elem.width() / $elem.height();
  6022. return isFinite(e) ? e : 0;
  6023. },
  6024. userAgent: function userAgent() {
  6025. return window.navigator.userAgent;
  6026. },
  6027. isMobile: function isMobile() {
  6028. var e = navigator.userAgent || navigator.vendor || window.opera;
  6029. return /(android|bb\d+|meego).+mobile|android|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od|ad)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(e) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(e.substr(0, 4));
  6030. },
  6031. isLandscape: function isLandscape() {
  6032. return this.isMobile && this.aspectRatio() > 1;
  6033. },
  6034. isSmallScreen: function isSmallScreen() {
  6035. var e = screen.width / window.devicePixelRatio;
  6036. return e < 240;
  6037. },
  6038. detectIE: function detectIE() {
  6039. var e = window.navigator.userAgent,
  6040. t = e.indexOf("MSIE ");
  6041. return t !== -1 || !!navigator.userAgent.match(/Trident.*rv\:11\./);
  6042. },
  6043. detectSafari: function detectSafari() {
  6044. var e = window.navigator.userAgent,
  6045. t = e.indexOf("Safari");
  6046. return t !== -1 && !this.detectOpera() && !this.detectChrome(); //xzw add detectOpera
  6047. },
  6048. detectFirefox: function detectFirefox() {
  6049. var e = window.navigator.userAgent;
  6050. return e.indexOf("Firefox") !== -1;
  6051. },
  6052. detectChrome: function detectChrome() {
  6053. var e = window.navigator.userAgent;
  6054. return e.indexOf("Chrome") !== -1 && !this.detectOpera();
  6055. },
  6056. detectOpera: function detectOpera() {
  6057. var e = window.navigator.userAgent;
  6058. return e.indexOf("OPR") !== -1;
  6059. },
  6060. detectIOS: function detectIOS() {
  6061. return this.detectIPhone() || this.detectIPad() || this.detectIPod();
  6062. },
  6063. detectIPad: function detectIPad() {
  6064. var e = window.navigator.userAgent,
  6065. t = /iPad/;
  6066. return t.test(e);
  6067. },
  6068. detectIPod: function detectIPod() {
  6069. var e = window.navigator.userAgent,
  6070. t = /iPod/;
  6071. return t.test(e);
  6072. },
  6073. detectIPhone: function detectIPhone() {
  6074. var e = window.navigator.userAgent,
  6075. t = /iPhone/;
  6076. return t.test(e);
  6077. },
  6078. detectAndroid: function detectAndroid() {
  6079. var e = window.navigator.userAgent;
  6080. return e.indexOf("Android") !== -1;
  6081. },
  6082. detectAndroidMobile: function detectAndroidMobile() {
  6083. var e = window.navigator.userAgent;
  6084. return this.detectAndroid() && e.indexOf("Mobile") !== -1;
  6085. },
  6086. detectSamsungNative: function detectSamsungNative() {
  6087. var e = window.navigator.userAgent;
  6088. return e.indexOf("SM-G900H") !== -1 || e.indexOf("GT-I9500") !== -1 || e.indexOf("SM-N900") !== -1;
  6089. },
  6090. detectSamsungS6: function detectSamsungS6() {
  6091. var e = window.navigator.userAgent;
  6092. return e.indexOf("SM-G92") !== -1;
  6093. },
  6094. /************************************************************徐世廷*************************************************************/
  6095. detectHUAWEI5X: function detectHUAWEI5X() {
  6096. return -1 !== window.navigator.userAgent.indexOf("KIW-TL00H");
  6097. },
  6098. /*******************************************************************************************************************************/
  6099. detectWebVR: function detectWebVR() {
  6100. return !(!window.navigator.getVRDisplays || !window.VRDisplay);
  6101. },
  6102. getVRDisplay: function getVRDisplay() {
  6103. var e = $.Deferred();
  6104. return this.detectWebVR() ? (navigator.getVRDisplays().then(function (t) {
  6105. t.length >= 1 && e.resolve(t[0]), e.reject(null);
  6106. }), e) : e.reject(null);
  6107. },
  6108. iosVersion: function iosVersion() {
  6109. if (!this.detectIOS()) throw new DeviceMismatchException("Did not detect an iDevice");
  6110. var e = /((?:\d+\_?){1,3}) like Mac OS/,
  6111. t = "_";
  6112. return mobileVersion(e, t);
  6113. },
  6114. androidVersion: function androidVersion() {
  6115. if (!this.detectAndroid()) throw new DeviceMismatchException("Did not detect an Android based device");
  6116. var e = /Android ((?:\d+\.?){1,3})/,
  6117. t = ".";
  6118. return mobileVersion(e, t);
  6119. },
  6120. valueFromCookie: function valueFromCookie(e, t) {
  6121. var i = new RegExp(e + "=([0-9a-f]+)(; ?|$)").exec(document.cookie);
  6122. if (!i) return t;
  6123. var n = i[1];
  6124. return "boolean" == typeof t ? "true" === n || "1" === n : "number" == typeof t ? parseFloat(n) : n;
  6125. },
  6126. valueFromHash: function valueFromHash(e, t) {
  6127. var i = new RegExp("[#&?]" + e + "=([^#&?]*)"),
  6128. n = i.exec(window.location.href);
  6129. if (!n) return t;
  6130. var r = n[1];
  6131. return "boolean" == typeof t ? "true" === r || "1" === r : "number" == typeof t ? parseFloat(r) : window.decodeURIComponent(r);
  6132. },
  6133. //-------许钟文:-------------------------------------------------
  6134. getProjectNum: function getProjectNum() {
  6135. //获取场景projectNum
  6136. if (window.__ProjectNum && window.__ProjectNum != "__ProjectNum__") {
  6137. return window.__ProjectNum;
  6138. }
  6139. var number = window.location.href.substring(window.location.href.indexOf("=") + 1);
  6140. if (number.indexOf("&") != -1) {
  6141. number = number.substring(0, number.indexOf("&"));
  6142. }
  6143. if (number.indexOf("#") != -1) {
  6144. number = number.substring(0, number.indexOf("#"));
  6145. }
  6146. return number;
  6147. },
  6148. urlHasValue: function urlHasValue(key, isGetValue) {
  6149. var querys = window.location.search.substr(1).split("&");
  6150. if (isGetValue) {
  6151. for (var i = 0; i < querys.length; i++) {
  6152. var keypair = querys[i].split("=");
  6153. if (keypair.length === 2 && keypair[0] === key) {
  6154. return keypair[1];
  6155. }
  6156. }
  6157. return "";
  6158. } else {
  6159. for (var _i = 0; _i < querys.length; _i++) {
  6160. var _keypair = querys[_i].split("=");
  6161. if (_keypair[0] == key) {
  6162. return true;
  6163. }
  6164. }
  6165. return false;
  6166. }
  6167. },
  6168. /**
  6169. * 获取查询参数的值
  6170. * @param {String} key
  6171. * @returns String
  6172. */
  6173. urlQueryValue(key) {
  6174. return this.urlHasValue(key, true) || "";
  6175. },
  6176. /**
  6177. * 判断是否存在hash
  6178. * @param {String} key
  6179. * @returns Boolean
  6180. */
  6181. urlIsHasHash(key) {
  6182. var querys = window.location.hash.substr(1).replace('/?', '').split("&");
  6183. return querys.includes(key);
  6184. },
  6185. islongPhone: function islongPhone() {
  6186. //是否是刘海全面屏幕 仅仅根据比例判断 - -
  6187. //screen.height == 812 && screen.width == 375)
  6188. var r = screen.height / screen.width; //可能横屏
  6189. return this.isMobile() && (r > 1.99 || r < 0.502512); //18/9=2.165 //???
  6190. },
  6191. detectWeixin: function detectWeixin() {
  6192. //微信 包括PC的微信
  6193. return window.navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == "micromessenger";
  6194. },
  6195. detectWeixinMiniProgram: function detectWeixinMiniProgram() {
  6196. return window.navigator.userAgent.match("miniProgram");
  6197. },
  6198. detectEdge: function detectEdge() {
  6199. return window.navigator.userAgent.indexOf("Edge") > -1;
  6200. },
  6201. detectApp: function detectApp() {
  6202. return this.urlHasValue("app");
  6203. },
  6204. /**
  6205. * 判断标签页是否切换状态
  6206. */
  6207. isTabHidden: function isTabHidden() {
  6208. var prefixes = ["webkit", "moz", "ms", "o"];
  6209. if ("hidden" in document) return document.hidden;
  6210. for (var i = 0; i < prefixes.length; i++) {
  6211. if (prefixes[i] + "Hidden" in document) return document[prefixes[i] + "Hidden"];
  6212. }
  6213. return false;
  6214. }
  6215. };
  6216. WebGLRenderer.prototype.paramThreeToGL = function (e) {
  6217. var t,
  6218. i = this.extensions,
  6219. r = this.getContext(); //context;
  6220. if (e === RepeatWrapping) return r.REPEAT;
  6221. if (e === ClampToEdgeWrapping) return r.CLAMP_TO_EDGE;
  6222. if (e === MirroredRepeatWrapping) return r.MIRRORED_REPEAT;
  6223. if (e === NearestFilter) return r.NEAREST;
  6224. if (e === NearestMipMapNearestFilter) return r.NEAREST_MIPMAP_NEAREST;
  6225. if (e === NearestMipMapLinearFilter) return r.NEAREST_MIPMAP_LINEAR;
  6226. if (e === LinearFilter) return r.LINEAR;
  6227. if (e === LinearMipMapNearestFilter) return r.LINEAR_MIPMAP_NEAREST;
  6228. if (e === LinearMipMapLinearFilter) return r.LINEAR_MIPMAP_LINEAR;
  6229. if (e === UnsignedByteType) return r.UNSIGNED_BYTE;
  6230. if (e === UnsignedShort4444Type) return r.UNSIGNED_SHORT_4_4_4_4;
  6231. if (e === UnsignedShort5551Type) return r.UNSIGNED_SHORT_5_5_5_1;
  6232. if (e === UnsignedShort565Type) return r.UNSIGNED_SHORT_5_6_5;
  6233. if (e === ByteType) return r.BYTE;
  6234. if (e === ShortType) return r.SHORT;
  6235. if (e === UnsignedShortType) return r.UNSIGNED_SHORT;
  6236. if (e === IntType) return r.INT;
  6237. if (e === UnsignedIntType) return r.UNSIGNED_INT;
  6238. if (e === FloatType) return r.FLOAT;
  6239. if (t = i.get("OES_texture_half_float"), null !== t && e === HalfFloatType) return t.HALF_FLOAT_OES;
  6240. if (e === AlphaFormat) return r.ALPHA;
  6241. if (e === RGBFormat) return r.RGB;
  6242. if (e === RGBAFormat) return r.RGBA;
  6243. if (e === LuminanceFormat) return r.LUMINANCE;
  6244. if (e === LuminanceAlphaFormat) return r.LUMINANCE_ALPHA;
  6245. if (e === AddEquation) return r.FUNC_ADD;
  6246. if (e === SubtractEquation) return r.FUNC_SUBTRACT;
  6247. if (e === ReverseSubtractEquation) return r.FUNC_REVERSE_SUBTRACT;
  6248. if (e === ZeroFactor) return r.ZERO;
  6249. if (e === OneFactor) return r.ONE;
  6250. if (e === SrcColorFactor) return r.SRC_COLOR;
  6251. if (e === OneMinusSrcColorFactor) return r.ONE_MINUS_SRC_COLOR;
  6252. if (e === SrcAlphaFactor) return r.SRC_ALPHA;
  6253. if (e === OneMinusSrcAlphaFactor) return r.ONE_MINUS_SRC_ALPHA;
  6254. if (e === DstAlphaFactor) return r.DST_ALPHA;
  6255. if (e === OneMinusDstAlphaFactor) return r.ONE_MINUS_DST_ALPHA;
  6256. if (e === DstColorFactor) return r.DST_COLOR;
  6257. if (e === OneMinusDstColorFactor) return r.ONE_MINUS_DST_COLOR;
  6258. if (e === SrcAlphaSaturateFactor) return r.SRC_ALPHA_SATURATE;
  6259. if (t = i.get("WEBGL_compressed_texture_s3tc"), null !== t) {
  6260. if (e === RGB_S3TC_DXT1_Format) return t.COMPRESSED_RGB_S3TC_DXT1_EXT;
  6261. if (e === RGBA_S3TC_DXT1_Format$1) return t.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  6262. if (e === RGBA_S3TC_DXT3_Format) return t.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  6263. if (e === RGBA_S3TC_DXT5_Format$1) return t.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  6264. }
  6265. if (t = i.get("WEBGL_compressed_texture_pvrtc"), null !== t) {
  6266. if (e === RGB_PVRTC_4BPPV1_Format) return t.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  6267. if (e === RGB_PVRTC_2BPPV1_Format) return t.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  6268. if (e === RGBA_PVRTC_4BPPV1_Format) return t.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  6269. if (e === RGBA_PVRTC_2BPPV1_Format) return t.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  6270. }
  6271. if (t = i.get("WEBGL_compressed_texture_etc1"), null !== t && e === RGB_ETC1_Format) return t.COMPRESSED_RGB_ETC1_WEBGL;
  6272. if (t = i.get("EXT_blend_minmax"), null !== t) {
  6273. if (e === MinEquation) return t.MIN_EXT;
  6274. if (e === MaxEquation) return t.MAX_EXT;
  6275. }
  6276. return 0;
  6277. };
  6278. EventDispatcher.prototype.addEventListener = function (type, listener) {
  6279. var {
  6280. importance = 0,
  6281. once
  6282. } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  6283. //add importance
  6284. if (this._listeners === undefined) this._listeners = {};
  6285. var listeners = this._listeners;
  6286. if (listeners[type] === undefined) {
  6287. listeners[type] = [];
  6288. }
  6289. /* if(type == 'flyingDone'){
  6290. console.log('addEventListener flyingDone')
  6291. } */
  6292. if (!listeners[type].some(e => e.listener == listener)) {
  6293. listeners[type].push({
  6294. listener,
  6295. importance,
  6296. once
  6297. });
  6298. listeners[type] = listeners[type].sort((e, a) => a.importance - e.importance); //add
  6299. }
  6300. };
  6301. EventDispatcher.prototype.hasEventListener = function (type, listener) {
  6302. if (this._listeners === undefined) return false;
  6303. var listeners = this._listeners;
  6304. return listeners[type] !== undefined && listeners[type].some(e => e.listener == listener);
  6305. };
  6306. EventDispatcher.prototype.removeEventListener = function (type, listener) {
  6307. if (this._listeners === undefined) return;
  6308. var listeners = this._listeners;
  6309. var listenerArray = listeners[type];
  6310. if (listenerArray !== undefined) {
  6311. /* const index = listenerArray.indexOf( listener );
  6312. if ( index !== - 1 ) {
  6313. listenerArray.splice( index, 1 );
  6314. } */
  6315. var item = listenerArray.find(e => e.listener == listener);
  6316. item && listenerArray.splice(listenerArray.indexOf(item), 1);
  6317. }
  6318. };
  6319. EventDispatcher.prototype.removeEventListeners = function (type) {
  6320. //add
  6321. if (this._listeners && this._listeners[type] !== undefined) {
  6322. delete this._listeners[type];
  6323. }
  6324. };
  6325. EventDispatcher.prototype.removeAllListeners = function () {
  6326. //add
  6327. this._listeners = {};
  6328. };
  6329. EventDispatcher.prototype.dispatchEvent = function (event) {
  6330. if (typeof event == 'string') {
  6331. //add
  6332. event = {
  6333. type: event
  6334. };
  6335. }
  6336. if (this._listeners === undefined) return;
  6337. var listeners = this._listeners;
  6338. var listenerArray = listeners[event.type];
  6339. if (listenerArray !== undefined) {
  6340. event.target = this;
  6341. // Make a copy, in case listeners are removed while iterating.
  6342. for (var {
  6343. listener,
  6344. once
  6345. } of listenerArray.slice(0)) {
  6346. if (once) {
  6347. this.removeEventListener(event.type, listener);
  6348. }
  6349. var result = listener.call(this, event); //add stopContinue
  6350. if (result && result.stopContinue) {
  6351. break;
  6352. }
  6353. }
  6354. }
  6355. };
  6356. EventDispatcher.prototype.traverse = function (callback) {
  6357. var result = callback(this);
  6358. if (result && result.stopContinue) {
  6359. //xzw add
  6360. return;
  6361. }
  6362. var children = this.children;
  6363. if (children) {
  6364. for (var i = 0, l = children.length; i < l; i++) {
  6365. children[i].traverse(callback);
  6366. }
  6367. }
  6368. };
  6369. Object3D.prototype.traverse = function (callback) {
  6370. var result = callback(this);
  6371. if (result && result.stopContinue) {
  6372. //xzw add
  6373. return;
  6374. }
  6375. var children = this.children;
  6376. for (var i = 0, l = children.length; i < l; i++) {
  6377. children[i] && children[i].traverse(callback);
  6378. }
  6379. };
  6380. Material.prototype.setValues = function (values) {
  6381. if (values === undefined) return;
  6382. for (var key in values) {
  6383. var newValue = values[key];
  6384. if (newValue === undefined) {
  6385. console.warn('THREE.Material: \'' + key + '\' parameter is undefined.');
  6386. continue;
  6387. }
  6388. // for backward compatability if shading is set in the constructor
  6389. if (key === 'shading') {
  6390. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  6391. this.flatShading = newValue === FlatShading ? true : false;
  6392. continue;
  6393. }
  6394. var currentValue = this[key];
  6395. /* if ( currentValue === undefined ) { //-----主要删了这段,否则很难和 set 一起使用
  6396. //console.warn( 'THREE.' + this.type + ': \'' + key + '\' is not a property of this material.' );
  6397. continue;
  6398. } */
  6399. if (currentValue && currentValue.isColor) {
  6400. currentValue.set(newValue);
  6401. } else if (currentValue && currentValue.isVector3 && newValue && newValue.isVector3) {
  6402. currentValue.copy(newValue);
  6403. } else {
  6404. this[key] = newValue;
  6405. }
  6406. }
  6407. };
  6408. function ascSort$1(a, b) {
  6409. return a.distance - b.distance;
  6410. }
  6411. function intersectObject(object, raycaster, intersects, recursive, ignoreUnvisible) {
  6412. if (ignoreUnvisible && !object.visible) return; //add
  6413. if (object.layers.test(raycaster.layers)) {
  6414. object.raycast(raycaster, intersects);
  6415. }
  6416. if (recursive === true) {
  6417. var children = object.children;
  6418. for (var i = 0, l = children.length; i < l; i++) {
  6419. intersectObject(children[i], raycaster, intersects, true, ignoreUnvisible);
  6420. }
  6421. }
  6422. }
  6423. Raycaster.prototype.intersectObject = function (object, recursive, optionalTarget, ignoreUnvisible) {
  6424. var intersects = optionalTarget || [];
  6425. intersectObject(object, this, intersects, recursive, ignoreUnvisible);
  6426. intersects.sort(ascSort$1);
  6427. return intersects;
  6428. };
  6429. Raycaster.prototype.intersectObjects = function (objects, recursive, optionalTarget, ignoreUnvisible) {
  6430. //add ignoreUnvisible 跳过不可见
  6431. var intersects = optionalTarget || [];
  6432. if (Array.isArray(objects) === false) {
  6433. console.warn('THREE.Raycaster.intersectObjects: objects is not an Array.');
  6434. return intersects;
  6435. }
  6436. for (var i = 0, l = objects.length; i < l; i++) {
  6437. intersectObject(objects[i], this, intersects, recursive, ignoreUnvisible);
  6438. }
  6439. intersects.sort(ascSort$1);
  6440. return intersects;
  6441. };
  6442. Object3D.prototype.realVisible = function () {
  6443. var v = true;
  6444. var parent = this;
  6445. var lastParent;
  6446. while (parent) {
  6447. if (parent.visible === false) {
  6448. v = false;
  6449. break;
  6450. }
  6451. lastParent = parent;
  6452. parent = parent.parent;
  6453. }
  6454. if (v && !(lastParent instanceof Scene)) {
  6455. //已被删除
  6456. v = false;
  6457. }
  6458. return v;
  6459. };
  6460. var MathLight = {};
  6461. MathLight.RADIANS_PER_DEGREE = Math.PI / 180;
  6462. MathLight.DEGREES_PER_RADIAN = 180 / Math.PI;
  6463. MathLight.Vector3 = function (e, t, i) {
  6464. this.x = e || 0, this.y = t || 0, this.z = i || 0;
  6465. };
  6466. MathLight.Matrix4 = function () {
  6467. this.elements = new Float32Array([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]), arguments.length > 0 && console.error("MathLight.Matrix4: the constructor no longer reads arguments. use .set() instead.");
  6468. };
  6469. MathLight.Matrix4.prototype = {
  6470. identity: function identity() {
  6471. return this.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1), this;
  6472. },
  6473. copy: function copy(e) {
  6474. return this.elements.set(e.elements), this;
  6475. },
  6476. applyToVector3: function applyToVector3(e) {
  6477. var t = e.x,
  6478. i = e.y,
  6479. n = e.z,
  6480. r = this.elements;
  6481. return e.x = r[0] * t + r[4] * i + r[8] * n + r[12], e.y = r[1] * t + r[5] * i + r[9] * n + r[13], e.z = r[2] * t + r[6] * i + r[10] * n + r[14], this;
  6482. },
  6483. getInverse: function getInverse(e, t) {
  6484. var i = this.elements,
  6485. n = e.elements,
  6486. r = n[0],
  6487. o = n[1],
  6488. a = n[2],
  6489. s = n[3],
  6490. l = n[4],
  6491. c = n[5],
  6492. h = n[6],
  6493. u = n[7],
  6494. d = n[8],
  6495. p = n[9],
  6496. f = n[10],
  6497. g = n[11],
  6498. m = n[12],
  6499. v = n[13],
  6500. A = n[14],
  6501. y = n[15],
  6502. C = p * A * u - v * f * u + v * h * g - c * A * g - p * h * y + c * f * y,
  6503. I = m * f * u - d * A * u - m * h * g + l * A * g + d * h * y - l * f * y,
  6504. E = d * v * u - m * p * u + m * c * g - l * v * g - d * c * y + l * p * y,
  6505. b = m * p * h - d * v * h - m * c * f + l * v * f + d * c * A - l * p * A,
  6506. w = r * C + o * I + a * E + s * b;
  6507. if (0 === w) {
  6508. var _ = "MathLight.Matrix4.getInverse(): can't invert matrix, determinant is 0";
  6509. if (t) throw new Error(_);
  6510. return console.warn(_), this.identity();
  6511. }
  6512. var T = 1 / w;
  6513. return i[0] = C * T, i[1] = (v * f * s - p * A * s - v * a * g + o * A * g + p * a * y - o * f * y) * T, i[2] = (c * A * s - v * h * s + v * a * u - o * A * u - c * a * y + o * h * y) * T, i[3] = (p * h * s - c * f * s - p * a * u + o * f * u + c * a * g - o * h * g) * T, i[4] = I * T, i[5] = (d * A * s - m * f * s + m * a * g - r * A * g - d * a * y + r * f * y) * T, i[6] = (m * h * s - l * A * s - m * a * u + r * A * u + l * a * y - r * h * y) * T, i[7] = (l * f * s - d * h * s + d * a * u - r * f * u - l * a * g + r * h * g) * T, i[8] = E * T, i[9] = (m * p * s - d * v * s - m * o * g + r * v * g + d * o * y - r * p * y) * T, i[10] = (l * v * s - m * c * s + m * o * u - r * v * u - l * o * y + r * c * y) * T, i[11] = (d * c * s - l * p * s - d * o * u + r * p * u + l * o * g - r * c * g) * T, i[12] = b * T, i[13] = (d * v * a - m * p * a + m * o * f - r * v * f - d * o * A + r * p * A) * T, i[14] = (m * c * a - l * v * a - m * o * h + r * v * h + l * o * A - r * c * A) * T, i[15] = (l * p * a - d * c * a + d * o * h - r * p * h - l * o * f + r * c * f) * T, this;
  6514. },
  6515. makeRotationFromQuaternion: function makeRotationFromQuaternion(e) {
  6516. var t = this.elements,
  6517. i = e.x,
  6518. n = e.y,
  6519. r = e.z,
  6520. o = e.w,
  6521. a = i + i,
  6522. s = n + n,
  6523. l = r + r,
  6524. c = i * a,
  6525. h = i * s,
  6526. u = i * l,
  6527. d = n * s,
  6528. p = n * l,
  6529. f = r * l,
  6530. g = o * a,
  6531. m = o * s,
  6532. v = o * l;
  6533. return t[0] = 1 - (d + f), t[4] = h - v, t[8] = u + m, t[1] = h + v, t[5] = 1 - (c + f), t[9] = p - g, t[2] = u - m, t[6] = p + g, t[10] = 1 - (c + d), t[3] = 0, t[7] = 0, t[11] = 0, t[12] = 0, t[13] = 0, t[14] = 0, t[15] = 1, this;
  6534. }
  6535. };
  6536. MathLight.Quaternion = function (e, t, i, n) {
  6537. this._x = e || 0, this._y = t || 0, this._z = i || 0, this._w = void 0 !== n ? n : 1;
  6538. };
  6539. MathLight.Quaternion.prototype = {
  6540. get x() {
  6541. return this._x;
  6542. },
  6543. set x(e) {
  6544. this._x = e;
  6545. },
  6546. get y() {
  6547. return this._y;
  6548. },
  6549. set y(e) {
  6550. this._y = e;
  6551. },
  6552. get z() {
  6553. return this._z;
  6554. },
  6555. set z(e) {
  6556. this._z = e;
  6557. },
  6558. get w() {
  6559. return this._w;
  6560. },
  6561. set w(e) {
  6562. this._w = e;
  6563. },
  6564. copy: function copy(e) {
  6565. this._x = e.x, this._y = e.y, this._z = e.z, this._w = e.w;
  6566. },
  6567. inverse: function inverse() {
  6568. return this.conjugate().normalize();
  6569. },
  6570. conjugate: function conjugate() {
  6571. return this._x *= -1, this._y *= -1, this._z *= -1, this;
  6572. },
  6573. length: function length() {
  6574. return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w);
  6575. },
  6576. normalize: function normalize() {
  6577. var e = this.length();
  6578. return 0 === e ? (this._x = 0, this._y = 0, this._z = 0, this._w = 1) : (e = 1 / e, this._x = this._x * e, this._y = this._y * e, this._z = this._z * e, this._w = this._w * e), this;
  6579. },
  6580. setFromAxisAngle: function setFromAxisAngle(e, t) {
  6581. var i = t / 2,
  6582. n = Math.sin(i);
  6583. return this._x = e.x * n, this._y = e.y * n, this._z = e.z * n, this._w = Math.cos(i), this;
  6584. },
  6585. setFromUnitVectors: function () {
  6586. var e,
  6587. t,
  6588. i = 1e-6;
  6589. return function (n, o) {
  6590. return void 0 === e && (e = new MathLight.Vector3()), t = MathLight.dot(n, o) + 1, t < i ? (t = 0, Math.abs(n.x) > Math.abs(n.z) ? MathLight.setVector(e, -n.y, n.x, 0) : MathLight.setVector(e, 0, -n.z, n.y)) : MathLight.cross(n, o, e), this._x = e.x, this._y = e.y, this._z = e.z, this._w = t, this.normalize();
  6591. };
  6592. }(),
  6593. multiply: function multiply(e) {
  6594. return this.multiplyQuaternions(this, e);
  6595. },
  6596. premultiply: function premultiply(e) {
  6597. return this.multiplyQuaternions(e, this);
  6598. },
  6599. multiplyQuaternions: function multiplyQuaternions(e, t) {
  6600. var i = e._x,
  6601. n = e._y,
  6602. r = e._z,
  6603. o = e._w,
  6604. a = t._x,
  6605. s = t._y,
  6606. l = t._z,
  6607. c = t._w;
  6608. return this._x = i * c + o * a + n * l - r * s, this._y = n * c + o * s + r * a - i * l, this._z = r * c + o * l + i * s - n * a, this._w = o * c - i * a - n * s - r * l, this;
  6609. }
  6610. };
  6611. MathLight.convertWorkshopVector = function (e) {
  6612. return new MathLight.Vector3(-e.x, e.y, e.z);
  6613. };
  6614. MathLight.convertWorkshopQuaternion = function (e) {
  6615. return new MathLight.Quaternion(-e.x, e.y, e.z, -e.w).multiply(new MathLight.Quaternion(Math.sqrt(2) / 2, Math.sqrt(2) / 2, 0, 0));
  6616. };
  6617. MathLight.convertWorkshopOrthoZoom = function (e) {
  6618. //return e === -1 ? -1 : e / 16 * ($('#player').width() / $('#player').height()) / n.workshopApsect
  6619. return e === -1 ? -1 : e * ($("#player").width() / $("#player").height());
  6620. };
  6621. MathLight.convertWorkshopPanoramaQuaternion = function (e) {
  6622. return new MathLight.Quaternion(e.x, -e.y, -e.z, e.w).normalize().multiply(new MathLight.Quaternion().setFromAxisAngle(new MathLight.Vector3(0, 1, 0), 270 * MathLight.RADIANS_PER_DEGREE));
  6623. };
  6624. MathLight.normalize = function (e) {
  6625. var t = e.x * e.x + e.y * e.y + e.z * e.z,
  6626. i = Math.sqrt(t);
  6627. e.x /= i, e.y /= i, e.z /= i;
  6628. };
  6629. MathLight.dot = function (e, t) {
  6630. return e.x * t.x + e.y * t.y + e.z * t.z;
  6631. };
  6632. MathLight.cross = function (e, t, i) {
  6633. var n = e.x,
  6634. r = e.y,
  6635. o = e.z;
  6636. i.x = r * t.z - o * t.y, i.y = o * t.x - n * t.z, i.z = n * t.y - r * t.x;
  6637. };
  6638. MathLight.setVector = function (e, t, i, n) {
  6639. e.x = t, e.y = i, e.z = n;
  6640. };
  6641. MathLight.copyVector = function (e, t) {
  6642. t.x = e.x, t.y = e.y, t.z = e.z;
  6643. };
  6644. MathLight.addVector = function (e, t) {
  6645. e.x += t.x, e.y += t.y, e.z += t.z;
  6646. };
  6647. MathLight.subVector = function (e, t) {
  6648. e.x -= t.x, e.y -= t.y, e.z -= t.z;
  6649. };
  6650. MathLight.applyQuaternionToVector = function (e, t) {
  6651. var i = t.x,
  6652. n = t.y,
  6653. r = t.z,
  6654. o = e.x,
  6655. a = e.y,
  6656. s = e.z,
  6657. l = e.w,
  6658. c = l * i + a * r - s * n,
  6659. h = l * n + s * i - o * r,
  6660. u = l * r + o * n - a * i,
  6661. d = -o * i - a * n - s * r;
  6662. t.x = c * l + d * -o + h * -s - u * -a, t.y = h * l + d * -a + u * -o - c * -s, t.z = u * l + d * -s + c * -a - h * -o;
  6663. };
  6664. MathLight.angleBetweenVectors = function (e, t) {
  6665. return Math.acos(MathLight.dot(e, t));
  6666. };
  6667. var cameraLight = {
  6668. clampVFOV: function clampVFOV(currentFov, maxHFov, width, height) {
  6669. //限制currentFov, 使之造成的横向fov不大于指定值maxHFov
  6670. var r = cameraLight.getHFOVFromVFOV(currentFov, width, height);
  6671. return r > maxHFov ? cameraLight.getVFOVFromHFOV(maxHFov, width, height) : currentFov;
  6672. },
  6673. getHFOVForCamera: function getHFOVForCamera(camera, getRad) {
  6674. return cameraLight.getHFOVByScreenPrecent(camera.fov, camera.aspect, getRad);
  6675. },
  6676. //add
  6677. getHFOVByScreenPrecent: function getHFOVByScreenPrecent(fov, percent, getRad) {
  6678. //当fov为占比百分百时,percent代表在屏幕上从中心到边缘的占比
  6679. var rad = 2 * Math.atan(percent * Math.tan(fov * MathLight.RADIANS_PER_DEGREE / 2));
  6680. if (getRad) return rad;else return rad * MathLight.DEGREES_PER_RADIAN;
  6681. }
  6682. };
  6683. var XHRFactory = {
  6684. config: {
  6685. withCredentials: false,
  6686. customHeaders: [{
  6687. header: null,
  6688. value: null
  6689. }]
  6690. },
  6691. createXMLHttpRequest: function createXMLHttpRequest() {
  6692. var xhr = new XMLHttpRequest();
  6693. if (this.config.customHeaders && Array.isArray(this.config.customHeaders) && this.config.customHeaders.length > 0) {
  6694. var baseOpen = xhr.open;
  6695. var customHeaders = this.config.customHeaders;
  6696. xhr.open = function () {
  6697. baseOpen.apply(this, [].slice.call(arguments));
  6698. customHeaders.forEach(function (customHeader) {
  6699. if (!!customHeader.header && !!customHeader.value) {
  6700. xhr.setRequestHeader(customHeader.header, customHeader.value);
  6701. }
  6702. });
  6703. };
  6704. }
  6705. return xhr;
  6706. }
  6707. };
  6708. // /**
  6709. class TextSprite$1 extends Object3D {
  6710. //old
  6711. constructor(text) {
  6712. super();
  6713. var texture = new Texture();
  6714. texture.minFilter = LinearFilter;
  6715. texture.magFilter = LinearFilter;
  6716. var spriteMaterial = new SpriteMaterial({
  6717. map: texture,
  6718. depthTest: false,
  6719. depthWrite: false
  6720. });
  6721. this.texture = texture;
  6722. this.material = spriteMaterial;
  6723. //this.material = getRawMaterial(texture);
  6724. this.sprite = new Sprite$1(this.material);
  6725. this.add(this.sprite);
  6726. this.borderThickness = 4;
  6727. this.fontface = 'Arial';
  6728. this.fontsize = 28;
  6729. this.borderColor = {
  6730. r: 0,
  6731. g: 0,
  6732. b: 0,
  6733. a: 1.0
  6734. };
  6735. this.backgroundColor = {
  6736. r: 255,
  6737. g: 255,
  6738. b: 255,
  6739. a: 1.0
  6740. };
  6741. this.textColor = {
  6742. r: 255,
  6743. g: 255,
  6744. b: 255,
  6745. a: 1.0
  6746. };
  6747. this.text = '';
  6748. this.setText(text);
  6749. }
  6750. setText(text) {
  6751. if (this.text !== text) {
  6752. this.text = text;
  6753. this.update();
  6754. }
  6755. }
  6756. setTextColor(color) {
  6757. this.textColor = color;
  6758. this.update();
  6759. }
  6760. setBorderColor(color) {
  6761. this.borderColor = color;
  6762. this.update();
  6763. }
  6764. setBackgroundColor(color) {
  6765. this.backgroundColor = color;
  6766. this.update();
  6767. }
  6768. update() {
  6769. var canvas = document.createElement('canvas');
  6770. var context = canvas.getContext('2d');
  6771. context.font = 'Bold ' + this.fontsize + 'px ' + this.fontface;
  6772. // get size data (height depends only on font size)
  6773. var metrics = context.measureText(this.text);
  6774. var textWidth = metrics.width;
  6775. var margin = 5;
  6776. var spriteWidth = 2 * margin + textWidth + 2 * this.borderThickness;
  6777. var spriteHeight = this.fontsize * 1.4 + 2 * this.borderThickness;
  6778. context.canvas.width = spriteWidth;
  6779. context.canvas.height = spriteHeight;
  6780. context.font = 'Bold ' + this.fontsize + 'px ' + this.fontface;
  6781. // background color
  6782. context.fillStyle = 'rgba(' + this.backgroundColor.r + ',' + this.backgroundColor.g + ',' + this.backgroundColor.b + ',' + this.backgroundColor.a + ')';
  6783. // border color
  6784. context.strokeStyle = 'rgba(' + this.borderColor.r + ',' + this.borderColor.g + ',' + this.borderColor.b + ',' + this.borderColor.a + ')';
  6785. context.lineWidth = this.borderThickness;
  6786. this.roundRect(context, this.borderThickness / 2, this.borderThickness / 2, textWidth + this.borderThickness + 2 * margin, this.fontsize * 1.4 + this.borderThickness, 6);
  6787. // text color
  6788. context.strokeStyle = 'rgba(0, 0, 0, 1.0)';
  6789. context.strokeText(this.text, this.borderThickness + margin, this.fontsize + this.borderThickness);
  6790. context.fillStyle = 'rgba(' + this.textColor.r + ',' + this.textColor.g + ',' + this.textColor.b + ',' + this.textColor.a + ')';
  6791. context.fillText(this.text, this.borderThickness + margin, this.fontsize + this.borderThickness);
  6792. var texture = new Texture(canvas);
  6793. texture.minFilter = LinearFilter;
  6794. texture.magFilter = LinearFilter;
  6795. texture.needsUpdate = true;
  6796. //this.material.needsUpdate = true;
  6797. // { // screen-space sprite
  6798. // let [screenWidth, screenHeight] = [1620, 937];
  6799. // let uniforms = this.sprite.material.uniforms;
  6800. // let aspect = spriteHeight / spriteWidth;
  6801. // let factor = 0.5;
  6802. // let w = spriteWidth / screenWidth;
  6803. // let h = spriteHeight / screenHeight;
  6804. // uniforms.uScale.value = [2 * w, 2 * h];
  6805. // //uniforms.uScale.value = [factor * 1, factor * aspect];
  6806. // this.sprite.material.uniforms.map.value = texture;
  6807. // }
  6808. this.sprite.material.map = texture;
  6809. this.texture = texture;
  6810. this.sprite.scale.set(spriteWidth * 0.01, spriteHeight * 0.01, 1.0);
  6811. }
  6812. roundRect(ctx, x, y, w, h, r) {
  6813. ctx.beginPath();
  6814. ctx.moveTo(x + r, y);
  6815. ctx.lineTo(x + w - r, y);
  6816. ctx.quadraticCurveTo(x + w, y, x + w, y + r);
  6817. ctx.lineTo(x + w, y + h - r);
  6818. ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
  6819. ctx.lineTo(x + r, y + h);
  6820. ctx.quadraticCurveTo(x, y + h, x, y + h - r);
  6821. ctx.lineTo(x, y + r);
  6822. ctx.quadraticCurveTo(x, y, x + r, y);
  6823. ctx.closePath();
  6824. ctx.fill();
  6825. ctx.stroke();
  6826. }
  6827. }
  6828. class Volume extends Object3D {
  6829. constructor() {
  6830. var args = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  6831. super();
  6832. if (this.constructor.name === "Volume") {
  6833. console.warn("Can't create object of class Volume directly. Use classes BoxVolume or SphereVolume instead.");
  6834. }
  6835. //console.log(this);
  6836. //console.log(this.constructor);
  6837. //console.log(this.constructor.name);
  6838. this._clip = args.clip || false;
  6839. this._visible = true;
  6840. this.showVolumeLabel = true;
  6841. this._modifiable = args.modifiable || true;
  6842. this.label = new TextSprite$1('0');
  6843. this.label.setBorderColor({
  6844. r: 0,
  6845. g: 255,
  6846. b: 0,
  6847. a: 0.0
  6848. });
  6849. this.label.setBackgroundColor({
  6850. r: 0,
  6851. g: 255,
  6852. b: 0,
  6853. a: 0.0
  6854. });
  6855. this.label.material.depthTest = false;
  6856. this.label.material.depthWrite = false;
  6857. this.label.material.transparent = true;
  6858. this.label.position.y -= 0.5;
  6859. this.add(this.label);
  6860. this.label.updateMatrixWorld = () => {
  6861. var volumeWorldPos = new Vector3();
  6862. volumeWorldPos.setFromMatrixPosition(this.matrixWorld);
  6863. this.label.position.copy(volumeWorldPos);
  6864. this.label.updateMatrix();
  6865. this.label.matrixWorld.copy(this.label.matrix);
  6866. this.label.matrixWorldNeedsUpdate = false;
  6867. for (var i = 0, l = this.label.children.length; i < l; i++) {
  6868. this.label.children[i].updateMatrixWorld(true);
  6869. }
  6870. };
  6871. {
  6872. // event listeners
  6873. this.addEventListener('select', e => {});
  6874. this.addEventListener('deselect', e => {});
  6875. }
  6876. }
  6877. get visible() {
  6878. return this._visible;
  6879. }
  6880. set visible(value) {
  6881. if (this._visible !== value) {
  6882. this._visible = value;
  6883. this.dispatchEvent({
  6884. type: "visibility_changed",
  6885. object: this
  6886. });
  6887. }
  6888. }
  6889. getVolume() {
  6890. console.warn("override this in subclass");
  6891. }
  6892. update() {}
  6893. raycast(raycaster, intersects) {}
  6894. get clip() {
  6895. return this._clip;
  6896. }
  6897. set clip(value) {
  6898. if (this._clip !== value) {
  6899. this._clip = value;
  6900. this.update();
  6901. this.dispatchEvent({
  6902. type: "clip_changed",
  6903. object: this
  6904. });
  6905. }
  6906. }
  6907. get modifieable() {
  6908. return this._modifiable;
  6909. }
  6910. set modifieable(value) {
  6911. this._modifiable = value;
  6912. this.update();
  6913. }
  6914. }
  6915. ;
  6916. class BoxVolume extends Volume {
  6917. constructor() {
  6918. var args = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  6919. super(args);
  6920. this.constructor.counter = this.constructor.counter === undefined ? 0 : this.constructor.counter + 1;
  6921. this.name = 'box_' + this.constructor.counter;
  6922. var boxGeometry = new BoxGeometry(1, 1, 1);
  6923. boxGeometry.computeBoundingBox();
  6924. var boxFrameGeometry = new Geometry();
  6925. {
  6926. var Vector3$1 = Vector3;
  6927. boxFrameGeometry.vertices.push(
  6928. // bottom
  6929. new Vector3$1(-0.5, -0.5, 0.5), new Vector3$1(0.5, -0.5, 0.5), new Vector3$1(0.5, -0.5, 0.5), new Vector3$1(0.5, -0.5, -0.5), new Vector3$1(0.5, -0.5, -0.5), new Vector3$1(-0.5, -0.5, -0.5), new Vector3$1(-0.5, -0.5, -0.5), new Vector3$1(-0.5, -0.5, 0.5),
  6930. // top
  6931. new Vector3$1(-0.5, 0.5, 0.5), new Vector3$1(0.5, 0.5, 0.5), new Vector3$1(0.5, 0.5, 0.5), new Vector3$1(0.5, 0.5, -0.5), new Vector3$1(0.5, 0.5, -0.5), new Vector3$1(-0.5, 0.5, -0.5), new Vector3$1(-0.5, 0.5, -0.5), new Vector3$1(-0.5, 0.5, 0.5),
  6932. // sides
  6933. new Vector3$1(-0.5, -0.5, 0.5), new Vector3$1(-0.5, 0.5, 0.5), new Vector3$1(0.5, -0.5, 0.5), new Vector3$1(0.5, 0.5, 0.5), new Vector3$1(0.5, -0.5, -0.5), new Vector3$1(0.5, 0.5, -0.5), new Vector3$1(-0.5, -0.5, -0.5), new Vector3$1(-0.5, 0.5, -0.5));
  6934. }
  6935. this.material = new MeshBasicMaterial({
  6936. color: 0x00ff00,
  6937. transparent: true,
  6938. opacity: 0.3,
  6939. depthTest: true,
  6940. depthWrite: false
  6941. });
  6942. this.box = new Mesh(boxGeometry, this.material);
  6943. this.box.geometry.computeBoundingBox();
  6944. this.boundingBox = this.box.geometry.boundingBox;
  6945. this.add(this.box);
  6946. this.frame = new LineSegments(boxFrameGeometry, new LineBasicMaterial({
  6947. color: 0x000000
  6948. }));
  6949. // this.frame.mode = THREE.Lines;
  6950. this.add(this.frame);
  6951. this.update();
  6952. }
  6953. update() {
  6954. this.boundingBox = this.box.geometry.boundingBox;
  6955. this.boundingSphere = this.boundingBox.getBoundingSphere(new Sphere());
  6956. if (this._clip) {
  6957. this.box.visible = false;
  6958. this.label.visible = false;
  6959. } else {
  6960. this.box.visible = true;
  6961. this.label.visible = this.showVolumeLabel;
  6962. }
  6963. }
  6964. raycast(raycaster, intersects) {
  6965. var is = [];
  6966. this.box.raycast(raycaster, is);
  6967. if (is.length > 0) {
  6968. var I = is[0];
  6969. intersects.push({
  6970. distance: I.distance,
  6971. object: this,
  6972. point: I.point.clone()
  6973. });
  6974. }
  6975. }
  6976. getVolume() {
  6977. return Math.abs(this.scale.x * this.scale.y * this.scale.z);
  6978. }
  6979. }
  6980. ;
  6981. class SphereVolume$1 extends Volume {
  6982. constructor() {
  6983. var args = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  6984. super(args);
  6985. this.constructor.counter = this.constructor.counter === undefined ? 0 : this.constructor.counter + 1;
  6986. this.name = 'sphere_' + this.constructor.counter;
  6987. var sphereGeometry = new SphereGeometry(1, 32, 32);
  6988. sphereGeometry.computeBoundingBox();
  6989. this.material = new MeshBasicMaterial({
  6990. color: 0x00ff00,
  6991. transparent: true,
  6992. opacity: 0.3,
  6993. depthTest: true,
  6994. depthWrite: false
  6995. });
  6996. this.sphere = new Mesh(sphereGeometry, this.material);
  6997. this.sphere.visible = false;
  6998. this.sphere.geometry.computeBoundingBox();
  6999. this.boundingBox = this.sphere.geometry.boundingBox;
  7000. this.add(this.sphere);
  7001. this.label.visible = false;
  7002. var frameGeometry = new Geometry();
  7003. {
  7004. var steps = 64;
  7005. var uSegments = 8;
  7006. var vSegments = 5;
  7007. var r = 1;
  7008. for (var uSegment = 0; uSegment < uSegments; uSegment++) {
  7009. var alpha = uSegment / uSegments * Math.PI * 2;
  7010. var dirx = Math.cos(alpha);
  7011. var diry = Math.sin(alpha);
  7012. for (var i = 0; i <= steps; i++) {
  7013. var v = i / steps * Math.PI * 2;
  7014. var vNext = v + 2 * Math.PI / steps;
  7015. var height = Math.sin(v);
  7016. var xyAmount = Math.cos(v);
  7017. var heightNext = Math.sin(vNext);
  7018. var xyAmountNext = Math.cos(vNext);
  7019. var vertex = new Vector3(dirx * xyAmount, diry * xyAmount, height);
  7020. frameGeometry.vertices.push(vertex);
  7021. var vertexNext = new Vector3(dirx * xyAmountNext, diry * xyAmountNext, heightNext);
  7022. frameGeometry.vertices.push(vertexNext);
  7023. }
  7024. }
  7025. // creates rings at poles, just because it's easier to implement
  7026. for (var vSegment = 0; vSegment <= vSegments + 1; vSegment++) {
  7027. //let height = (vSegment / (vSegments + 1)) * 2 - 1; // -1 to 1
  7028. var uh = vSegment / (vSegments + 1); // -1 to 1
  7029. uh = (1 - uh) * (-Math.PI / 2) + uh * (Math.PI / 2);
  7030. var _height = Math.sin(uh);
  7031. console.log(uh, _height);
  7032. for (var _i = 0; _i <= steps; _i++) {
  7033. var u = _i / steps * Math.PI * 2;
  7034. var uNext = u + 2 * Math.PI / steps;
  7035. var _dirx = Math.cos(u);
  7036. var _diry = Math.sin(u);
  7037. var dirxNext = Math.cos(uNext);
  7038. var diryNext = Math.sin(uNext);
  7039. var _xyAmount = Math.sqrt(1 - _height * _height);
  7040. var _vertex = new Vector3(_dirx * _xyAmount, _diry * _xyAmount, _height);
  7041. frameGeometry.vertices.push(_vertex);
  7042. var _vertexNext = new Vector3(dirxNext * _xyAmount, diryNext * _xyAmount, _height);
  7043. frameGeometry.vertices.push(_vertexNext);
  7044. }
  7045. }
  7046. }
  7047. this.frame = new LineSegments(frameGeometry, new LineBasicMaterial({
  7048. color: 0x000000
  7049. }));
  7050. this.add(this.frame);
  7051. var frameMaterial = new MeshBasicMaterial({
  7052. wireframe: true,
  7053. color: 0x000000
  7054. });
  7055. this.frame = new Mesh(sphereGeometry, frameMaterial);
  7056. //this.add(this.frame);
  7057. //this.frame = new THREE.LineSegments(boxFrameGeometry, new THREE.LineBasicMaterial({color: 0x000000}));
  7058. // this.frame.mode = THREE.Lines;
  7059. //this.add(this.frame);
  7060. this.update();
  7061. }
  7062. update() {
  7063. this.boundingBox = this.sphere.geometry.boundingBox;
  7064. this.boundingSphere = this.boundingBox.getBoundingSphere(new Sphere());
  7065. //if (this._clip) {
  7066. // this.sphere.visible = false;
  7067. // this.label.visible = false;
  7068. //} else {
  7069. // this.sphere.visible = true;
  7070. // this.label.visible = this.showVolumeLabel;
  7071. //}
  7072. }
  7073. raycast(raycaster, intersects) {
  7074. var is = [];
  7075. this.sphere.raycast(raycaster, is);
  7076. if (is.length > 0) {
  7077. var I = is[0];
  7078. intersects.push({
  7079. distance: I.distance,
  7080. object: this,
  7081. point: I.point.clone()
  7082. });
  7083. }
  7084. }
  7085. // see https://en.wikipedia.org/wiki/Ellipsoid#Volume
  7086. getVolume() {
  7087. return 4 / 3 * Math.PI * this.scale.x * this.scale.y * this.scale.z;
  7088. }
  7089. }
  7090. ;
  7091. class Profile extends Object3D {
  7092. constructor() {
  7093. super();
  7094. this.constructor.counter = this.constructor.counter === undefined ? 0 : this.constructor.counter + 1;
  7095. this.name = 'Profile_' + this.constructor.counter;
  7096. this.points = [];
  7097. this.spheres = [];
  7098. this.edges = [];
  7099. this.boxes = [];
  7100. this.width = 1;
  7101. this.height = 20;
  7102. this._modifiable = true;
  7103. this.sphereGeometry = new SphereGeometry(0.4, 10, 10);
  7104. this.color = new Color(0xff0000);
  7105. this.lineColor = new Color(0xff0000);
  7106. }
  7107. createSphereMaterial() {
  7108. var sphereMaterial = new MeshLambertMaterial({
  7109. //shading: THREE.SmoothShading,
  7110. color: 0xff0000,
  7111. depthTest: false,
  7112. depthWrite: false
  7113. });
  7114. return sphereMaterial;
  7115. }
  7116. getSegments() {
  7117. var segments = [];
  7118. for (var i = 0; i < this.points.length - 1; i++) {
  7119. var start = this.points[i].clone();
  7120. var end = this.points[i + 1].clone();
  7121. segments.push({
  7122. start: start,
  7123. end: end
  7124. });
  7125. }
  7126. return segments;
  7127. }
  7128. getSegmentMatrices() {
  7129. var segments = this.getSegments();
  7130. var matrices = [];
  7131. for (var segment of segments) {
  7132. var {
  7133. start,
  7134. end
  7135. } = segment;
  7136. var box = new Object3D();
  7137. var length = start.clone().setZ(0).distanceTo(end.clone().setZ(0));
  7138. box.scale.set(length, 10000, this.width);
  7139. box.up.set(0, 0, 1);
  7140. var center = new Vector3().addVectors(start, end).multiplyScalar(0.5);
  7141. var diff = new Vector3().subVectors(end, start);
  7142. var target = new Vector3(diff.y, -diff.x, 0);
  7143. box.position.set(0, 0, 0);
  7144. box.lookAt(target);
  7145. box.position.copy(center);
  7146. box.updateMatrixWorld();
  7147. matrices.push(box.matrixWorld);
  7148. }
  7149. return matrices;
  7150. }
  7151. addMarker(point) {
  7152. this.points.push(point);
  7153. var sphere = new Mesh(this.sphereGeometry, this.createSphereMaterial());
  7154. this.add(sphere);
  7155. this.spheres.push(sphere);
  7156. // edges & boxes
  7157. if (this.points.length > 1) {
  7158. var lineGeometry = new Geometry();
  7159. lineGeometry.vertices.push(new Vector3(), new Vector3());
  7160. lineGeometry.colors.push(this.lineColor, this.lineColor, this.lineColor);
  7161. var lineMaterial = new LineBasicMaterial({
  7162. vertexColors: VertexColors,
  7163. linewidth: 2,
  7164. transparent: true,
  7165. opacity: 0.4
  7166. });
  7167. lineMaterial.depthTest = false;
  7168. var edge = new Line(lineGeometry, lineMaterial);
  7169. edge.visible = false;
  7170. this.add(edge);
  7171. this.edges.push(edge);
  7172. var boxGeometry = new BoxGeometry(1, 1, 1);
  7173. var boxMaterial = new MeshBasicMaterial({
  7174. color: 0xff0000,
  7175. transparent: true,
  7176. opacity: 0.2
  7177. });
  7178. var box = new Mesh(boxGeometry, boxMaterial);
  7179. box.visible = false;
  7180. this.add(box);
  7181. this.boxes.push(box);
  7182. }
  7183. {
  7184. // event listeners
  7185. var drag = e => {
  7186. var I = Utils.getMousePointCloudIntersection(e.drag.end, e.viewer.scene.getActiveCamera(), e.viewer, e.viewer.scene.pointclouds);
  7187. if (I) {
  7188. var i = this.spheres.indexOf(e.drag.object);
  7189. if (i !== -1) {
  7190. this.setPosition(i, I.location);
  7191. //this.dispatchEvent({
  7192. // 'type': 'marker_moved',
  7193. // 'profile': this,
  7194. // 'index': i
  7195. //});
  7196. }
  7197. }
  7198. };
  7199. var drop = e => {
  7200. var i = this.spheres.indexOf(e.drag.object);
  7201. if (i !== -1) {
  7202. this.dispatchEvent({
  7203. 'type': 'marker_dropped',
  7204. 'profile': this,
  7205. 'index': i
  7206. });
  7207. }
  7208. };
  7209. var mouseover = e => e.object.material.emissive.setHex(0x888888);
  7210. var mouseleave = e => e.object.material.emissive.setHex(0x000000);
  7211. sphere.addEventListener('drag', drag);
  7212. sphere.addEventListener('drop', drop);
  7213. sphere.addEventListener('mouseover', mouseover);
  7214. sphere.addEventListener('mouseleave', mouseleave);
  7215. }
  7216. var event = {
  7217. type: 'marker_added',
  7218. profile: this,
  7219. sphere: sphere
  7220. };
  7221. this.dispatchEvent(event);
  7222. this.setPosition(this.points.length - 1, point);
  7223. }
  7224. removeMarker(index) {
  7225. this.points.splice(index, 1);
  7226. this.remove(this.spheres[index]);
  7227. var edgeIndex = index === 0 ? 0 : index - 1;
  7228. this.remove(this.edges[edgeIndex]);
  7229. this.edges.splice(edgeIndex, 1);
  7230. this.remove(this.boxes[edgeIndex]);
  7231. this.boxes.splice(edgeIndex, 1);
  7232. this.spheres.splice(index, 1);
  7233. this.update();
  7234. this.dispatchEvent({
  7235. 'type': 'marker_removed',
  7236. 'profile': this
  7237. });
  7238. }
  7239. setPosition(index, position) {
  7240. var point = this.points[index];
  7241. point.copy(position);
  7242. var event = {
  7243. type: 'marker_moved',
  7244. profile: this,
  7245. index: index,
  7246. position: point.clone()
  7247. };
  7248. this.dispatchEvent(event);
  7249. this.update();
  7250. }
  7251. setWidth(width) {
  7252. this.width = width;
  7253. var event = {
  7254. type: 'width_changed',
  7255. profile: this,
  7256. width: width
  7257. };
  7258. this.dispatchEvent(event);
  7259. this.update();
  7260. }
  7261. getWidth() {
  7262. return this.width;
  7263. }
  7264. update() {
  7265. if (this.points.length === 0) {
  7266. return;
  7267. } else if (this.points.length === 1) {
  7268. var point = this.points[0];
  7269. this.spheres[0].position.copy(point);
  7270. return;
  7271. }
  7272. var min = this.points[0].clone();
  7273. var max = this.points[0].clone();
  7274. var centroid = new Vector3();
  7275. var lastIndex = this.points.length - 1;
  7276. for (var i = 0; i <= lastIndex; i++) {
  7277. var _point = this.points[i];
  7278. var sphere = this.spheres[i];
  7279. var leftIndex = i === 0 ? lastIndex : i - 1;
  7280. // let rightIndex = (i === lastIndex) ? 0 : i + 1;
  7281. var leftVertex = this.points[leftIndex];
  7282. // let rightVertex = this.points[rightIndex];
  7283. var leftEdge = this.edges[leftIndex];
  7284. var rightEdge = this.edges[i];
  7285. var leftBox = this.boxes[leftIndex];
  7286. // rightBox = this.boxes[i];
  7287. // let leftEdgeLength = point.distanceTo(leftVertex);
  7288. // let rightEdgeLength = point.distanceTo(rightVertex);
  7289. // let leftEdgeCenter = new THREE.Vector3().addVectors(leftVertex, point).multiplyScalar(0.5);
  7290. // let rightEdgeCenter = new THREE.Vector3().addVectors(point, rightVertex).multiplyScalar(0.5);
  7291. sphere.position.copy(_point);
  7292. if (this._modifiable) {
  7293. sphere.visible = true;
  7294. } else {
  7295. sphere.visible = false;
  7296. }
  7297. if (leftEdge) {
  7298. leftEdge.geometry.vertices[1].copy(_point);
  7299. leftEdge.geometry.verticesNeedUpdate = true;
  7300. leftEdge.geometry.computeBoundingSphere();
  7301. }
  7302. if (rightEdge) {
  7303. rightEdge.geometry.vertices[0].copy(_point);
  7304. rightEdge.geometry.verticesNeedUpdate = true;
  7305. rightEdge.geometry.computeBoundingSphere();
  7306. }
  7307. if (leftBox) {
  7308. var start = leftVertex;
  7309. var end = _point;
  7310. var length = start.clone().setZ(0).distanceTo(end.clone().setZ(0));
  7311. leftBox.scale.set(length, 1000000, this.width);
  7312. leftBox.up.set(0, 0, 1);
  7313. var center = new Vector3().addVectors(start, end).multiplyScalar(0.5);
  7314. var diff = new Vector3().subVectors(end, start);
  7315. var target = new Vector3(diff.y, -diff.x, 0);
  7316. leftBox.position.set(0, 0, 0);
  7317. leftBox.lookAt(target);
  7318. leftBox.position.copy(center);
  7319. }
  7320. centroid.add(_point);
  7321. min.min(_point);
  7322. max.max(_point);
  7323. }
  7324. centroid.multiplyScalar(1 / this.points.length);
  7325. for (var _i = 0; _i < this.boxes.length; _i++) {
  7326. var box = this.boxes[_i];
  7327. box.position.z = min.z + (max.z - min.z) / 2;
  7328. }
  7329. }
  7330. raycast(raycaster, intersects) {
  7331. for (var i = 0; i < this.points.length; i++) {
  7332. var sphere = this.spheres[i];
  7333. sphere.raycast(raycaster, intersects);
  7334. }
  7335. // recalculate distances because they are not necessarely correct
  7336. // for scaled objects.
  7337. // see https://github.com/mrdoob/three.js/issues/5827
  7338. // TODO: remove this once the bug has been fixed
  7339. for (var _i2 = 0; _i2 < intersects.length; _i2++) {
  7340. var I = intersects[_i2];
  7341. I.distance = raycaster.ray.origin.distanceTo(I.point);
  7342. }
  7343. intersects.sort(function (a, b) {
  7344. return a.distance - b.distance;
  7345. });
  7346. }
  7347. get modifiable() {
  7348. return this._modifiable;
  7349. }
  7350. set modifiable(value) {
  7351. this._modifiable = value;
  7352. this.update();
  7353. }
  7354. }
  7355. var _box$4 = new Box3();
  7356. var _vector$d = new Vector3();
  7357. class LineSegmentsGeometry extends InstancedBufferGeometry {
  7358. constructor() {
  7359. super();
  7360. this.isLineSegmentsGeometry = true;
  7361. this.type = 'LineSegmentsGeometry';
  7362. var positions = [-1, 2, 0, 1, 2, 0, -1, 1, 0, 1, 1, 0, -1, 0, 0, 1, 0, 0, -1, -1, 0, 1, -1, 0];
  7363. var uvs = [-1, 2, 1, 2, -1, 1, 1, 1, -1, -1, 1, -1, -1, -2, 1, -2];
  7364. var index = [0, 2, 1, 2, 3, 1, 2, 4, 3, 4, 5, 3, 4, 6, 5, 6, 7, 5];
  7365. this.setIndex(index);
  7366. this.setAttribute('position', new Float32BufferAttribute(positions, 3));
  7367. this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  7368. }
  7369. applyMatrix4(matrix) {
  7370. var start = this.attributes.instanceStart;
  7371. var end = this.attributes.instanceEnd;
  7372. if (start !== undefined) {
  7373. start.applyMatrix4(matrix);
  7374. end.applyMatrix4(matrix);
  7375. start.needsUpdate = true;
  7376. }
  7377. if (this.boundingBox !== null) {
  7378. this.computeBoundingBox();
  7379. }
  7380. if (this.boundingSphere !== null) {
  7381. this.computeBoundingSphere();
  7382. }
  7383. return this;
  7384. }
  7385. setPositions(array) {
  7386. var lineSegments;
  7387. if (array instanceof Float32Array) {
  7388. lineSegments = array;
  7389. } else if (Array.isArray(array)) {
  7390. lineSegments = new Float32Array(array);
  7391. }
  7392. var instanceBuffer = new InstancedInterleavedBuffer(lineSegments, 6, 1); // xyz, xyz
  7393. this.setAttribute('instanceStart', new InterleavedBufferAttribute(instanceBuffer, 3, 0)); // xyz
  7394. this.setAttribute('instanceEnd', new InterleavedBufferAttribute(instanceBuffer, 3, 3)); // xyz
  7395. //
  7396. this.computeBoundingBox();
  7397. this.computeBoundingSphere();
  7398. return this;
  7399. }
  7400. setColors(array) {
  7401. var colors;
  7402. if (array instanceof Float32Array) {
  7403. colors = array;
  7404. } else if (Array.isArray(array)) {
  7405. colors = new Float32Array(array);
  7406. }
  7407. var instanceColorBuffer = new InstancedInterleavedBuffer(colors, 6, 1); // rgb, rgb
  7408. this.setAttribute('instanceColorStart', new InterleavedBufferAttribute(instanceColorBuffer, 3, 0)); // rgb
  7409. this.setAttribute('instanceColorEnd', new InterleavedBufferAttribute(instanceColorBuffer, 3, 3)); // rgb
  7410. return this;
  7411. }
  7412. fromWireframeGeometry(geometry) {
  7413. this.setPositions(geometry.attributes.position.array);
  7414. return this;
  7415. }
  7416. fromEdgesGeometry(geometry) {
  7417. this.setPositions(geometry.attributes.position.array);
  7418. return this;
  7419. }
  7420. fromMesh(mesh) {
  7421. this.fromWireframeGeometry(new WireframeGeometry(mesh.geometry));
  7422. // set colors, maybe
  7423. return this;
  7424. }
  7425. fromLineSegments(lineSegments) {
  7426. var geometry = lineSegments.geometry;
  7427. this.setPositions(geometry.attributes.position.array); // assumes non-indexed
  7428. // set colors, maybe
  7429. return this;
  7430. }
  7431. computeBoundingBox() {
  7432. if (this.boundingBox === null) {
  7433. this.boundingBox = new Box3();
  7434. }
  7435. var start = this.attributes.instanceStart;
  7436. var end = this.attributes.instanceEnd;
  7437. if (start !== undefined && end !== undefined) {
  7438. this.boundingBox.setFromBufferAttribute(start);
  7439. _box$4.setFromBufferAttribute(end);
  7440. this.boundingBox.union(_box$4);
  7441. }
  7442. }
  7443. computeBoundingSphere() {
  7444. if (this.boundingSphere === null) {
  7445. this.boundingSphere = new Sphere();
  7446. }
  7447. if (this.boundingBox === null) {
  7448. this.computeBoundingBox();
  7449. }
  7450. var start = this.attributes.instanceStart;
  7451. var end = this.attributes.instanceEnd;
  7452. if (start !== undefined && end !== undefined) {
  7453. var center = this.boundingSphere.center;
  7454. this.boundingBox.getCenter(center);
  7455. var maxRadiusSq = 0;
  7456. for (var i = 0, il = start.count; i < il; i++) {
  7457. _vector$d.fromBufferAttribute(start, i);
  7458. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$d));
  7459. _vector$d.fromBufferAttribute(end, i);
  7460. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$d));
  7461. }
  7462. this.boundingSphere.radius = Math.sqrt(maxRadiusSq);
  7463. if (isNaN(this.boundingSphere.radius)) {
  7464. console.error('THREE.LineSegmentsGeometry.computeBoundingSphere(): Computed radius is NaN. The instanced position data is likely to have NaN values.', this);
  7465. }
  7466. }
  7467. }
  7468. toJSON() {
  7469. // todo
  7470. }
  7471. applyMatrix(matrix) {
  7472. console.warn('THREE.LineSegmentsGeometry: applyMatrix() has been renamed to applyMatrix4().');
  7473. return this.applyMatrix4(matrix);
  7474. }
  7475. }
  7476. /**
  7477. * parameters = {
  7478. * color: <hex>,
  7479. * lineWidth: <float>,
  7480. * dashed: <boolean>,
  7481. * dashScale: <float>,
  7482. * dashSize: <float>,
  7483. * dashOffset: <float>,
  7484. * gapSize: <float>,
  7485. * resolution: <Vector2>, // to be set by renderer
  7486. * }
  7487. */
  7488. UniformsLib.line = {
  7489. /*
  7490. worldUnits: { value: 1 },
  7491. lineWidth: { value: 1 },
  7492. resolution: { value: new Vector2( 1, 1 ) },
  7493. dashOffset: { value: 0 },
  7494. dashScale: { value: 1 },
  7495. dashSize: { value: 1 },
  7496. gapSize: { value: 1 } // todo FIX - maybe change to totalSize
  7497. */
  7498. worldUnits: {
  7499. value: 1
  7500. },
  7501. lineWidth: {
  7502. value: 1
  7503. },
  7504. resolution: {
  7505. value: new Vector2(1, 1)
  7506. },
  7507. viewportOffset: {
  7508. value: new Vector2(0, 0)
  7509. },
  7510. //left, top
  7511. devicePixelRatio: {
  7512. value: window.devicePixelRatio
  7513. },
  7514. dashScale: {
  7515. value: 1
  7516. },
  7517. dashSize: {
  7518. value: 1
  7519. },
  7520. dashOffset: {
  7521. value: 0
  7522. },
  7523. gapSize: {
  7524. value: 1
  7525. },
  7526. opacity: {
  7527. value: 1
  7528. },
  7529. backColor: {
  7530. type: 'v3',
  7531. value: new Color("#ddd")
  7532. },
  7533. clipDistance: {
  7534. type: 'f',
  7535. value: 4
  7536. },
  7537. //消失距离
  7538. occlusionDistance: {
  7539. type: 'f',
  7540. value: 1
  7541. },
  7542. //变为backColor距离
  7543. maxClipFactor: {
  7544. type: 'f',
  7545. value: 1
  7546. },
  7547. //0-1
  7548. maxOcclusionFactor: {
  7549. type: 'f',
  7550. value: 1
  7551. },
  7552. //0-1
  7553. depthTexture: {
  7554. value: null
  7555. },
  7556. nearPlane: {
  7557. value: 0.1
  7558. },
  7559. farPlane: {
  7560. value: 100000
  7561. }
  7562. //uUseOrthographicCamera:{ type: "b", value: false },
  7563. };
  7564. ShaderLib['line'] = {
  7565. uniforms: UniformsUtils.merge([UniformsLib.common, UniformsLib.fog, UniformsLib.line]),
  7566. vertexShader: /* glsl */"\n\t\t#include <common>\n\t\t#include <color_pars_vertex>\n\t\t#include <fog_pars_vertex>\n\t\t#include <logdepthbuf_pars_vertex>\n\t\t#include <clipping_planes_pars_vertex>\n\n\t\tuniform float lineWidth;\n\t\tuniform vec2 resolution;\n uniform float devicePixelRatio; //add\n \n \n\t\tattribute vec3 instanceStart;\n\t\tattribute vec3 instanceEnd;\n\n\t\tattribute vec3 instanceColorStart;\n\t\tattribute vec3 instanceColorEnd;\n\n\t\t#ifdef WORLD_UNITS\n\n\t\t\tvarying vec4 worldPos;\n\t\t\tvarying vec3 worldStart;\n\t\t\tvarying vec3 worldEnd;\n\n\t\t\t#ifdef USE_DASH\n\n\t\t\t\tvarying vec2 vUv;\n\n\t\t\t#endif\n\n\t\t#else\n\n\t\t\tvarying vec2 vUv;\n\n\t\t#endif\n\n\t\t#ifdef USE_DASH\n\n\t\t\tuniform float dashScale;\n\t\t\tattribute float instanceDistanceStart;\n\t\t\tattribute float instanceDistanceEnd;\n\t\t\tvarying float vLineDistance;\n\n\t\t#endif\n\n\t\tvoid trimSegment( const in vec4 start, inout vec4 end ) {\n\n\t\t\t// trim end segment so it terminates between the camera plane and the near plane\n\n\t\t\t// conservative estimate of the near plane\n\t\t\tfloat a = projectionMatrix[ 2 ][ 2 ]; // 3nd entry in 3th column\n\t\t\tfloat b = projectionMatrix[ 3 ][ 2 ]; // 3nd entry in 4th column\n\t\t\tfloat nearEstimate = - 0.5 * b / a;\n\n\t\t\tfloat alpha = ( nearEstimate - start.z ) / ( end.z - start.z );\n\n\t\t\tend.xyz = mix( start.xyz, end.xyz, alpha );\n\n\t\t}\n\n\t\tvoid main() {\n\n\t\t\t#ifdef USE_COLOR\n\n\t\t\t\tvColor.xyz = ( position.y < 0.5 ) ? instanceColorStart : instanceColorEnd;\n\n\t\t\t#endif\n\n\t\t\t#ifdef USE_DASH\n\n\t\t\t\tvLineDistance = ( position.y < 0.5 ) ? dashScale * instanceDistanceStart : dashScale * instanceDistanceEnd;\n\t\t\t\tvUv = uv;\n\n\t\t\t#endif\n\n\t\t\tfloat aspect = resolution.x / resolution.y;\n\n\t\t\t// camera space\n\t\t\tvec4 start = modelViewMatrix * vec4( instanceStart, 1.0 );\n\t\t\tvec4 end = modelViewMatrix * vec4( instanceEnd, 1.0 );\n\n\t\t\t#ifdef WORLD_UNITS\n\n\t\t\t\tworldStart = start.xyz;\n\t\t\t\tworldEnd = end.xyz;\n\n\t\t\t#else\n\n\t\t\t\tvUv = uv;\n\n\t\t\t#endif\n\n\t\t\t// special case for perspective projection, and segments that terminate either in, or behind, the camera plane\n\t\t\t// clearly the gpu firmware has a way of addressing this issue when projecting into ndc space\n\t\t\t// but we need to perform ndc-space calculations in the shader, so we must address this issue directly\n\t\t\t// perhaps there is a more elegant solution -- WestLangley\n\n\t\t\tbool perspective = ( projectionMatrix[ 2 ][ 3 ] == - 1.0 ); // 4th entry in the 3rd column\n\n\t\t\tif ( perspective ) {\n\n\t\t\t\tif ( start.z < 0.0 && end.z >= 0.0 ) {\n\n\t\t\t\t\ttrimSegment( start, end );\n\n\t\t\t\t} else if ( end.z < 0.0 && start.z >= 0.0 ) {\n\n\t\t\t\t\ttrimSegment( end, start );\n\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t\t// clip space\n\t\t\tvec4 clipStart = projectionMatrix * start;\n\t\t\tvec4 clipEnd = projectionMatrix * end;\n\n\t\t\t// ndc space\n\t\t\tvec3 ndcStart = clipStart.xyz / clipStart.w;\n\t\t\tvec3 ndcEnd = clipEnd.xyz / clipEnd.w;\n\n\t\t\t// direction\n\t\t\tvec2 dir = ndcEnd.xy - ndcStart.xy;\n\n\t\t\t// account for clip-space aspect ratio\n\t\t\tdir.x *= aspect;\n\t\t\tdir = normalize( dir );\n\n\t\t\t#ifdef WORLD_UNITS\n\n\t\t\t\t// get the offset direction as perpendicular to the view vector\n\t\t\t\tvec3 worldDir = normalize( end.xyz - start.xyz );\n\t\t\t\tvec3 offset;\n\t\t\t\tif ( position.y < 0.5 ) {\n\n\t\t\t\t\toffset = normalize( cross( start.xyz, worldDir ) );\n\n\t\t\t\t} else {\n\n\t\t\t\t\toffset = normalize( cross( end.xyz, worldDir ) );\n\n\t\t\t\t}\n\n\t\t\t\t// sign flip\n\t\t\t\tif ( position.x < 0.0 ) offset *= - 1.0;\n\n\t\t\t\tfloat forwardOffset = dot( worldDir, vec3( 0.0, 0.0, 1.0 ) );\n\n\t\t\t\t// don't extend the line if we're rendering dashes because we\n\t\t\t\t// won't be rendering the endcaps\n\t\t\t\t#ifndef USE_DASH\n\n\t\t\t\t\t// extend the line bounds to encompass endcaps\n\t\t\t\t\tstart.xyz += - worldDir * lineWidth * 0.5;\n\t\t\t\t\tend.xyz += worldDir * lineWidth * 0.5;\n\n\t\t\t\t\t// shift the position of the quad so it hugs the forward edge of the line\n\t\t\t\t\toffset.xy -= dir * forwardOffset;\n\t\t\t\t\toffset.z += 0.5;\n\n\t\t\t\t#endif\n\n\t\t\t\t// endcaps\n\t\t\t\tif ( position.y > 1.0 || position.y < 0.0 ) {\n\n\t\t\t\t\toffset.xy += dir * 2.0 * forwardOffset;\n\n\t\t\t\t}\n\n\t\t\t\t// adjust for lineWidth\n\t\t\t\toffset *= lineWidth * 0.5;\n\n\t\t\t\t// set the world position\n\t\t\t\tworldPos = ( position.y < 0.5 ) ? start : end;\n\t\t\t\tworldPos.xyz += offset;\n\n\t\t\t\t// project the worldpos\n\t\t\t\tvec4 clip = projectionMatrix * worldPos;\n\n\t\t\t\t// shift the depth of the projected points so the line\n\t\t\t\t// segments overlap neatly\n\t\t\t\tvec3 clipPose = ( position.y < 0.5 ) ? ndcStart : ndcEnd;\n\t\t\t\tclip.z = clipPose.z * clip.w;\n\n\t\t\t#else\n\n\t\t\t\tvec2 offset = vec2( dir.y, - dir.x );\n\t\t\t\t// undo aspect ratio adjustment\n\t\t\t\tdir.x /= aspect;\n\t\t\t\toffset.x /= aspect;\n\n\t\t\t\t// sign flip\n\t\t\t\tif ( position.x < 0.0 ) offset *= - 1.0;\n\n\t\t\t\t// endcaps\n\t\t\t\tif ( position.y < 0.0 ) {\n\n\t\t\t\t\toffset += - dir;\n\n\t\t\t\t} else if ( position.y > 1.0 ) {\n\n\t\t\t\t\toffset += dir;\n\n\t\t\t\t}\n\n\t\t\t\t// adjust for lineWidth\n\t\t\t\toffset *= lineWidth;\n\n\t\t\t\t// adjust for clip-space to screen-space conversion // maybe resolution should be based on viewport ...\n\t\t\t\toffset /= resolution.y; //* devicePixelRatio;\n\n\t\t\t\t// select end\n\t\t\t\tvec4 clip = ( position.y < 0.5 ) ? clipStart : clipEnd;\n\n\t\t\t\t// back to clip space\n\t\t\t\toffset *= clip.w;\n\n\t\t\t\tclip.xy += offset;\n\n\t\t\t#endif\n\n\t\t\tgl_Position = clip;\n\n\t\t\tvec4 mvPosition = ( position.y < 0.5 ) ? start : end; // this is an approximation\n\n\t\t\t#include <logdepthbuf_vertex>\n\t\t\t#include <clipping_planes_vertex>\n\t\t\t#include <fog_vertex>\n\n\t\t}\n\t\t",
  7567. fragmentShader: /* glsl */"\n\t\tuniform vec3 diffuse;\n\t\tuniform float opacity;\n\t\tuniform float lineWidth;\n uniform bool uUseOrthographicCamera; \n\t\t#ifdef USE_DASH\n\n\t\t\tuniform float dashOffset;\n\t\t\tuniform float dashSize;\n\t\t\tuniform float gapSize; \n\t\t#endif\n \n //\u52A0\n #if defined(GL_EXT_frag_depth) && defined(useDepth) \n uniform sampler2D depthTexture;\n uniform float nearPlane;\n uniform float farPlane; \n uniform vec2 resolution;\n uniform vec2 viewportOffset;\n uniform vec3 backColor;\n uniform float occlusionDistance;\n uniform float clipDistance;\n uniform float maxClipFactor;\n uniform float maxOcclusionFactor;\n #endif\n\n\n\n\t\tvarying float vLineDistance;\n\n\t\t#ifdef WORLD_UNITS\n\n\t\t\tvarying vec4 worldPos;\n\t\t\tvarying vec3 worldStart;\n\t\t\tvarying vec3 worldEnd;\n\n\t\t\t#ifdef USE_DASH\n\n\t\t\t\tvarying vec2 vUv;\n\n\t\t\t#endif\n\n\t\t#else\n\n\t\t\tvarying vec2 vUv;\n\n\t\t#endif\n\n\t\t#include <common>\n\t\t#include <color_pars_fragment>\n\t\t#include <fog_pars_fragment>\n\t\t#include <logdepthbuf_pars_fragment>\n\t\t#include <clipping_planes_pars_fragment>\n\n\n #if defined(GL_EXT_frag_depth) && defined(useDepth) \n float convertToLinear(float zValue)\n {\n //if(uUseOrthographicCamera){\n // return zValue*(farPlane-nearPlane)+nearPlane;\n //}else{ \n float z = zValue * 2.0 - 1.0;\n return (2.0 * nearPlane * farPlane) / (farPlane + nearPlane - z * (farPlane - nearPlane));\n //} \n }\n #endif\n\n\n\n\t\tvec2 closestLineToLine(vec3 p1, vec3 p2, vec3 p3, vec3 p4) {\n\n\t\t\tfloat mua;\n\t\t\tfloat mub;\n\n\t\t\tvec3 p13 = p1 - p3;\n\t\t\tvec3 p43 = p4 - p3;\n\n\t\t\tvec3 p21 = p2 - p1;\n\n\t\t\tfloat d1343 = dot( p13, p43 );\n\t\t\tfloat d4321 = dot( p43, p21 );\n\t\t\tfloat d1321 = dot( p13, p21 );\n\t\t\tfloat d4343 = dot( p43, p43 );\n\t\t\tfloat d2121 = dot( p21, p21 );\n\n\t\t\tfloat denom = d2121 * d4343 - d4321 * d4321;\n\n\t\t\tfloat numer = d1343 * d4321 - d1321 * d4343;\n\n\t\t\tmua = numer / denom;\n\t\t\tmua = clamp( mua, 0.0, 1.0 );\n\t\t\tmub = ( d1343 + d4321 * ( mua ) ) / d4343;\n\t\t\tmub = clamp( mub, 0.0, 1.0 );\n\n\t\t\treturn vec2( mua, mub );\n\n\t\t}\n\n\t\tvoid main() {\n\n\t\t\t#include <clipping_planes_fragment>\n\n\t\t\t/*#ifdef USE_DASH\n\n\t\t\t\tif ( vUv.y < - 1.0 || vUv.y > 1.0 ) discard; // discard endcaps\n\n\t\t\t\tif ( mod( vLineDistance + dashOffset, dashSize + gapSize ) > dashSize ) discard; // todo - FIX\n\n\t\t\t#endif*/\n \n\t\t\t#ifdef USE_DASH\n\n\t\t\t\tif ( vUv.y < - 1.0 || vUv.y > 1.0 ) discard; // discard endcaps\n \n \n bool unvisible = mod( vLineDistance + dashOffset, dashSize + gapSize ) > dashSize;\n //\u52A0\n #ifdef DASH_with_depth\n \n #else \n if (unvisible) discard; // todo - FIX\n #endif\n\t\t\t#endif\n \n\n\t\t\tfloat alpha = opacity;\n\n\t\t\t#ifdef WORLD_UNITS\n\n\t\t\t\t// Find the closest points on the view ray and the line segment\n\t\t\t\tvec3 rayEnd = normalize( worldPos.xyz ) * 1e5;\n\t\t\t\tvec3 lineDir = worldEnd - worldStart;\n\t\t\t\tvec2 params = closestLineToLine( worldStart, worldEnd, vec3( 0.0, 0.0, 0.0 ), rayEnd );\n\n\t\t\t\tvec3 p1 = worldStart + lineDir * params.x;\n\t\t\t\tvec3 p2 = rayEnd * params.y;\n\t\t\t\tvec3 delta = p1 - p2;\n\t\t\t\tfloat len = length( delta );\n\t\t\t\tfloat norm = len / lineWidth;\n\n\t\t\t\t#ifndef USE_DASH\n\n\t\t\t\t\t#ifdef USE_ALPHA_TO_COVERAGE\n\n\t\t\t\t\t\tfloat dnorm = fwidth( norm );\n\t\t\t\t\t\talpha = 1.0 - smoothstep( 0.5 - dnorm, 0.5 + dnorm, norm );\n\n\t\t\t\t\t#else\n\n\t\t\t\t\t\tif ( norm > 0.5 ) {\n\n\t\t\t\t\t\t\tdiscard;\n\n\t\t\t\t\t\t}\n\n\t\t\t\t\t#endif\n\n\t\t\t\t#endif\n\n\t\t\t#else\n\n\t\t\t\t#ifdef USE_ALPHA_TO_COVERAGE\n\n\t\t\t\t\t// artifacts appear on some hardware if a derivative is taken within a conditional\n\t\t\t\t\tfloat a = vUv.x;\n\t\t\t\t\tfloat b = ( vUv.y > 0.0 ) ? vUv.y - 1.0 : vUv.y + 1.0;\n\t\t\t\t\tfloat len2 = a * a + b * b;\n\t\t\t\t\tfloat dlen = fwidth( len2 );\n\n\t\t\t\t\tif ( abs( vUv.y ) > 1.0 ) {\n\n\t\t\t\t\t\talpha = 1.0 - smoothstep( 1.0 - dlen, 1.0 + dlen, len2 );\n\n\t\t\t\t\t}\n\n\t\t\t\t#else\n\n\t\t\t\t\tif ( abs( vUv.y ) > 1.0 ) {\n\n\t\t\t\t\t\tfloat a = vUv.x;\n\t\t\t\t\t\tfloat b = ( vUv.y > 0.0 ) ? vUv.y - 1.0 : vUv.y + 1.0;\n\t\t\t\t\t\tfloat len2 = a * a + b * b;\n\n\t\t\t\t\t\tif ( len2 > 1.0 ) discard;\n\n\t\t\t\t\t}\n\n\t\t\t\t#endif\n\n\t\t\t#endif\n\n\t\t\tvec4 diffuseColor = vec4( diffuse, alpha );\n\n\n //\u52A0\n #if defined(GL_EXT_frag_depth) && defined(useDepth) \n \n float mixFactor = 0.0;\n float clipFactor = 0.0;\n\n float fragDepth = convertToLinear(gl_FragCoord.z);\n //gl_FragCoord\u5927\u5C0F\u4E3A viewport client\u5927\u5C0F \n vec2 depthTxtCoords = vec2(gl_FragCoord.x - viewportOffset.x, gl_FragCoord.y - viewportOffset.y) / resolution;\n\n float textureDepth = convertToLinear(texture2D(depthTexture, depthTxtCoords).r);\n\n float delta = fragDepth - textureDepth;\n\n if (delta > 0.0)\n {\n \n mixFactor = clamp(delta / occlusionDistance, 0.0, maxOcclusionFactor);\n clipFactor = clamp(delta / clipDistance, 0.0, maxClipFactor);\n }\n \n if (clipFactor == 1.0)\n {\n discard;\n }\n \n vec4 backColor_ = vec4(backColor, opacity); //vec4(0.8,0.8,0.8, 0.8*opacity);\n \n #ifdef DASH_with_depth \n // \u53EA\u5728\u88AB\u906E\u4F4F\u7684\u90E8\u5206\u663E\u793A\u865A\u7EBF, \u6240\u4EE5\u82E5\u540C\u65F6\u662F\u865A\u7EBF\u4E0D\u53EF\u89C1\u90E8\u5206\u548C\u88AB\u906E\u4F4F\u65F6\uFF0C a\u4E3A0\n if(unvisible) backColor_.a = 0.0;\n #endif \n \n //vec4 diffuseColor = vec4(mix(diffuse, backColor_, mixFactor), opacity*(1.0 - clipFactor));\n \n \n \n diffuseColor = mix(diffuseColor, backColor_ , mixFactor); \n \n \n diffuseColor.a *= (1.0 - clipFactor); \n \n #endif\n\n\n\n\t\t\t#include <logdepthbuf_fragment>\n\t\t\t#include <color_fragment>\n\n\t\t\t//gl_FragColor = vec4( diffuseColor.rgb, alpha );\n\t\t\tgl_FragColor = vec4( diffuseColor.rgb, diffuseColor.a );\n\t\t\t#include <tonemapping_fragment>\n\t\t\t#include <encodings_fragment>\n\t\t\t#include <fog_fragment>\n\t\t\t#include <premultiplied_alpha_fragment>\n\n\t\t}\n\t\t"
  7568. };
  7569. class LineMaterial extends ShaderMaterial {
  7570. constructor(parameters) {
  7571. var {
  7572. vs,
  7573. fs
  7574. } = Potree.Common.changeShaderToWebgl2(ShaderLib['line'].vertexShader, ShaderLib['line'].fragmentShader, 'ShaderMaterial');
  7575. super({
  7576. type: 'LineMaterial',
  7577. uniforms: UniformsUtils.clone(ShaderLib['line'].uniforms),
  7578. vertexShader: vs,
  7579. fragmentShader: fs,
  7580. clipping: true // required for clipping support
  7581. });
  7582. this.isLineMaterial = true;
  7583. this.lineWidth_ = 0;
  7584. this.supportExtDepth = parameters.supportExtDepth;
  7585. this.depthTestWhenPick = false; //pick时是否识别点云等
  7586. if (parameters.color) {
  7587. this.color = new Color(parameters.color);
  7588. }
  7589. if (parameters.backColor) {
  7590. this.uniforms.backColor.value = new Color(parameters.backColor);
  7591. }
  7592. if (parameters.clipDistance) {
  7593. this.uniforms.clipDistance.value = parameters.clipDistance;
  7594. }
  7595. if (parameters.occlusionDistance) {
  7596. this.uniforms.occlusionDistance.value = parameters.occlusionDistance;
  7597. }
  7598. if (parameters.maxClipFactor) {
  7599. this.uniforms.maxClipFactor.value = parameters.maxClipFactor;
  7600. }
  7601. Object.defineProperties(this, {
  7602. color: {
  7603. enumerable: true,
  7604. get: function get() {
  7605. return this.uniforms.diffuse.value;
  7606. },
  7607. set: function set(value) {
  7608. this.uniforms.diffuse.value = value;
  7609. }
  7610. },
  7611. worldUnits: {
  7612. enumerable: true,
  7613. get: function get() {
  7614. return 'WORLD_UNITS' in this.defines;
  7615. },
  7616. set: function set(value) {
  7617. if (value === true) {
  7618. this.defines.WORLD_UNITS = '';
  7619. } else {
  7620. delete this.defines.WORLD_UNITS;
  7621. }
  7622. }
  7623. },
  7624. lineWidth: {
  7625. enumerable: true,
  7626. get: function get() {
  7627. return this.lineWidth_; //this.uniforms.lineWidth.value;
  7628. },
  7629. set: function set(value) {
  7630. this.uniforms.lineWidth.value = value * window.devicePixelRatio;
  7631. this.lineWidth_ = value;
  7632. }
  7633. },
  7634. dashed: {
  7635. enumerable: true,
  7636. get: function get() {
  7637. return Boolean('USE_DASH' in this.defines);
  7638. },
  7639. set(value) {
  7640. if (Boolean(value) !== Boolean('USE_DASH' in this.defines)) {
  7641. this.needsUpdate = true;
  7642. }
  7643. if (value === true) {
  7644. this.defines.USE_DASH = '';
  7645. } else {
  7646. delete this.defines.USE_DASH;
  7647. }
  7648. }
  7649. },
  7650. dashScale: {
  7651. enumerable: true,
  7652. get: function get() {
  7653. return this.uniforms.dashScale.value;
  7654. },
  7655. set: function set(value) {
  7656. this.uniforms.dashScale.value = value;
  7657. }
  7658. },
  7659. dashSize: {
  7660. enumerable: true,
  7661. get: function get() {
  7662. return this.uniforms.dashSize.value;
  7663. },
  7664. set: function set(value) {
  7665. this.uniforms.dashSize.value = value;
  7666. }
  7667. },
  7668. dashOffset: {
  7669. enumerable: true,
  7670. get: function get() {
  7671. return this.uniforms.dashOffset.value;
  7672. },
  7673. set: function set(value) {
  7674. this.uniforms.dashOffset.value = value;
  7675. }
  7676. },
  7677. gapSize: {
  7678. enumerable: true,
  7679. get: function get() {
  7680. return this.uniforms.gapSize.value;
  7681. },
  7682. set: function set(value) {
  7683. this.uniforms.gapSize.value = value;
  7684. }
  7685. },
  7686. opacity: {
  7687. enumerable: true,
  7688. get: function get() {
  7689. return this.uniforms.opacity.value;
  7690. },
  7691. set: function set(value) {
  7692. this.uniforms.opacity.value = value;
  7693. }
  7694. },
  7695. resolution: {
  7696. enumerable: true,
  7697. get: function get() {
  7698. return this.uniforms.resolution.value;
  7699. },
  7700. set: function set(value) {
  7701. this.uniforms.resolution.value.copy(value);
  7702. }
  7703. },
  7704. alphaToCoverage: {
  7705. enumerable: true,
  7706. get: function get() {
  7707. return Boolean('USE_ALPHA_TO_COVERAGE' in this.defines);
  7708. },
  7709. set: function set(value) {
  7710. if (Boolean(value) !== Boolean('USE_ALPHA_TO_COVERAGE' in this.defines)) {
  7711. this.needsUpdate = true;
  7712. }
  7713. if (value === true) {
  7714. this.defines.USE_ALPHA_TO_COVERAGE = '';
  7715. this.extensions.derivatives = true;
  7716. } else {
  7717. delete this.defines.USE_ALPHA_TO_COVERAGE;
  7718. this.extensions.derivatives = false;
  7719. }
  7720. }
  7721. },
  7722. dashWithDepth: {
  7723. //add
  7724. enumerable: true,
  7725. get: function get() {
  7726. return 'DASH_with_depth' in this.defines;
  7727. },
  7728. set: function set(value) {
  7729. value = value && !!this.supportExtDepth;
  7730. if (value != this.dashWithDepth) {
  7731. if (value) {
  7732. this.defines.DASH_with_depth = '';
  7733. } else {
  7734. delete this.defines.DASH_with_depth;
  7735. }
  7736. this.needsUpdate = true;
  7737. }
  7738. }
  7739. }
  7740. });
  7741. this.events = {
  7742. setSize: e => {
  7743. //如果出现横条状的异常,往往是viewportOffset出错 //地图不需要
  7744. var viewport = e.viewport;
  7745. //console.log(viewport.name, viewport.resolution2)
  7746. this.uniforms.resolution.value.copy(viewport.resolution2);
  7747. this.uniforms.devicePixelRatio.value = window.devicePixelRatio;
  7748. this.lineWidth = this.lineWidth_; //update
  7749. if (!this.realUseDepth || !e.viewport) return;
  7750. var viewportOffset = viewport.offset || new THREE.Vector2();
  7751. this.uniforms.viewportOffset.value.copy(viewportOffset);
  7752. },
  7753. render: e => {
  7754. //before render 如果有大于两个viewport的话,不同viewport用不同的depthTex
  7755. this.useDepth && this.updateDepthParams(e);
  7756. var viewport = e.viewport || viewer.mainViewport;
  7757. if (viewport != this.lastViewport) {
  7758. //当mapViewer要渲染测量线后,就需要变viewport
  7759. this.events.setSize({
  7760. viewport
  7761. });
  7762. }
  7763. this.lastViewport = viewport;
  7764. }
  7765. };
  7766. this.setValues(parameters);
  7767. var viewport = viewer.mainViewport;
  7768. this.events.setSize({
  7769. viewport
  7770. });
  7771. viewer.addEventListener('resize', this.events.setSize);
  7772. viewer.addEventListener("render.begin", this.events.render);
  7773. }
  7774. get useDepth() {
  7775. return this.useDepth_;
  7776. }
  7777. set useDepth(value) {
  7778. value = value && this.supportExtDepth; //如果不支持 EXT_DEPTH 的话会失效
  7779. if (this.useDepth_ != value) {
  7780. this.setRealDepth(value);
  7781. this.useDepth_ = value;
  7782. }
  7783. }
  7784. setRealDepth(useDepth, viewport) {
  7785. //确实使用到depthTex
  7786. if (this.realUseDepth != useDepth) {
  7787. if (useDepth) {
  7788. this.defines.useDepth = '';
  7789. } else {
  7790. delete this.defines.useDepth;
  7791. }
  7792. this.realUseDepth = useDepth;
  7793. if (this.autoDepthTest) this.depthWrite = this.depthTest = !useDepth; //如果useDepth = false,使用原始的depthTest
  7794. this.needsUpdate = true;
  7795. if (!viewport) viewport = viewer.mainViewport; //暂时这么设置
  7796. useDepth && this.events.setSize({
  7797. viewport
  7798. });
  7799. }
  7800. }
  7801. updateDepthParams() {
  7802. var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  7803. var viewport = e.viewport || viewer.mainViewport;
  7804. var camera = viewport.camera;
  7805. var hasDepth = this.useDepth && camera.isPerspectiveCamera && (Potree.settings.pointEnableRT || Potree.settings.displayMode == 'showPanos' || viewer.useEDL);
  7806. this.setRealDepth(hasDepth, viewport);
  7807. if (hasDepth) {
  7808. this.uniforms.depthTexture.value = viewer.getPRenderer().getRtEDL(viewport).depthTexture; //其实只赋值一次就行
  7809. this.uniforms.nearPlane.value = camera.near;
  7810. this.uniforms.farPlane.value = camera.far;
  7811. }
  7812. //this.uniforms.uUseOrthographicCamera.value = !camera.isPerspectiveCamera
  7813. }
  7814. }
  7815. var _start$2 = new Vector3();
  7816. var _end$2 = new Vector3();
  7817. var _start4 = new Vector4();
  7818. var _end4 = new Vector4();
  7819. var _ssOrigin = new Vector4();
  7820. var _ssOrigin3 = new Vector3();
  7821. var _mvMatrix = new Matrix4();
  7822. var _line = new Line3();
  7823. var _closestPoint = new Vector3();
  7824. var _box$5 = new Box3();
  7825. var _sphere$4 = new Sphere();
  7826. var _clipToWorldVector = new Vector4();
  7827. var _ray$3, _instanceStart, _instanceEnd, _lineWidth;
  7828. // Returns the margin required to expand by in world space given the distance from the camera,
  7829. // line width, resolution, and camera projection
  7830. function getWorldSpaceHalfWidth(camera, distance, resolution) {
  7831. // transform into clip space, adjust the x and y values by the pixel width offset, then
  7832. // transform back into world space to get world offset. Note clip space is [-1, 1] so full
  7833. // width does not need to be halved.
  7834. _clipToWorldVector.set(0, 0, -distance, 1.0).applyMatrix4(camera.projectionMatrix);
  7835. _clipToWorldVector.multiplyScalar(1.0 / _clipToWorldVector.w);
  7836. _clipToWorldVector.x = _lineWidth / resolution.width;
  7837. _clipToWorldVector.y = _lineWidth / resolution.height;
  7838. _clipToWorldVector.applyMatrix4(camera.projectionMatrixInverse);
  7839. _clipToWorldVector.multiplyScalar(1.0 / _clipToWorldVector.w);
  7840. return Math.abs(Math.max(_clipToWorldVector.x, _clipToWorldVector.y));
  7841. }
  7842. function raycastWorldUnits(lineSegments, intersects) {
  7843. for (var i = 0, l = _instanceStart.count; i < l; i++) {
  7844. _line.start.fromBufferAttribute(_instanceStart, i);
  7845. _line.end.fromBufferAttribute(_instanceEnd, i);
  7846. var pointOnLine = new Vector3();
  7847. var point = new Vector3();
  7848. _ray$3.distanceSqToSegment(_line.start, _line.end, point, pointOnLine);
  7849. var isInside = point.distanceTo(pointOnLine) < _lineWidth * 0.5;
  7850. if (isInside) {
  7851. intersects.push({
  7852. point,
  7853. pointOnLine,
  7854. distance: _ray$3.origin.distanceTo(point),
  7855. object: lineSegments,
  7856. face: null,
  7857. faceIndex: i,
  7858. uv: null,
  7859. uv2: null
  7860. });
  7861. }
  7862. }
  7863. }
  7864. function raycastScreenSpace(lineSegments, camera, intersects) {
  7865. var projectionMatrix = camera.projectionMatrix;
  7866. var material = lineSegments.material;
  7867. var resolution = material.resolution;
  7868. var matrixWorld = lineSegments.matrixWorld;
  7869. var geometry = lineSegments.geometry;
  7870. var instanceStart = geometry.attributes.instanceStart;
  7871. var instanceEnd = geometry.attributes.instanceEnd;
  7872. var near = -camera.near;
  7873. //
  7874. // pick a point 1 unit out along the ray to avoid the ray origin
  7875. // sitting at the camera origin which will cause "w" to be 0 when
  7876. // applying the projection matrix.
  7877. _ray$3.at(1, _ssOrigin);
  7878. // ndc space [ - 1.0, 1.0 ]
  7879. _ssOrigin.w = 1;
  7880. _ssOrigin.applyMatrix4(camera.matrixWorldInverse);
  7881. _ssOrigin.applyMatrix4(projectionMatrix);
  7882. _ssOrigin.multiplyScalar(1 / _ssOrigin.w);
  7883. // screen space
  7884. _ssOrigin.x *= resolution.x / 2;
  7885. _ssOrigin.y *= resolution.y / 2;
  7886. _ssOrigin.z = 0;
  7887. _ssOrigin3.copy(_ssOrigin);
  7888. _mvMatrix.multiplyMatrices(camera.matrixWorldInverse, matrixWorld);
  7889. for (var i = 0, l = instanceStart.count; i < l; i++) {
  7890. _start4.fromBufferAttribute(instanceStart, i);
  7891. _end4.fromBufferAttribute(instanceEnd, i);
  7892. _start4.w = 1;
  7893. _end4.w = 1;
  7894. // camera space
  7895. _start4.applyMatrix4(_mvMatrix);
  7896. _end4.applyMatrix4(_mvMatrix);
  7897. // skip the segment if it's entirely behind the camera
  7898. var isBehindCameraNear = _start4.z > near && _end4.z > near;
  7899. if (isBehindCameraNear) {
  7900. continue;
  7901. }
  7902. // trim the segment if it extends behind camera near
  7903. if (_start4.z > near) {
  7904. var deltaDist = _start4.z - _end4.z;
  7905. var t = (_start4.z - near) / deltaDist;
  7906. _start4.lerp(_end4, t);
  7907. } else if (_end4.z > near) {
  7908. var _deltaDist = _end4.z - _start4.z;
  7909. var _t = (_end4.z - near) / _deltaDist;
  7910. _end4.lerp(_start4, _t);
  7911. }
  7912. // clip space
  7913. _start4.applyMatrix4(projectionMatrix);
  7914. _end4.applyMatrix4(projectionMatrix);
  7915. // ndc space [ - 1.0, 1.0 ]
  7916. _start4.multiplyScalar(1 / _start4.w);
  7917. _end4.multiplyScalar(1 / _end4.w);
  7918. // screen space
  7919. _start4.x *= resolution.x / 2;
  7920. _start4.y *= resolution.y / 2;
  7921. _end4.x *= resolution.x / 2;
  7922. _end4.y *= resolution.y / 2;
  7923. // create 2d segment
  7924. _line.start.copy(_start4);
  7925. _line.start.z = 0;
  7926. _line.end.copy(_end4);
  7927. _line.end.z = 0;
  7928. // get closest point on ray to segment
  7929. var param = _line.closestPointToPointParameter(_ssOrigin3, true);
  7930. _line.at(param, _closestPoint);
  7931. // check if the intersection point is within clip space
  7932. var zPos = MathUtils.lerp(_start4.z, _end4.z, param);
  7933. var isInClipSpace = zPos >= -1 && zPos <= 1;
  7934. var isInside = _ssOrigin3.distanceTo(_closestPoint) < _lineWidth * 0.5;
  7935. if (isInClipSpace && isInside) {
  7936. _line.start.fromBufferAttribute(instanceStart, i);
  7937. _line.end.fromBufferAttribute(instanceEnd, i);
  7938. _line.start.applyMatrix4(matrixWorld);
  7939. _line.end.applyMatrix4(matrixWorld);
  7940. var pointOnLine = new Vector3();
  7941. var point = new Vector3();
  7942. _ray$3.distanceSqToSegment(_line.start, _line.end, point, pointOnLine);
  7943. intersects.push({
  7944. point: point,
  7945. pointOnLine: pointOnLine,
  7946. distance: _ray$3.origin.distanceTo(point),
  7947. object: lineSegments,
  7948. face: null,
  7949. faceIndex: i,
  7950. uv: null,
  7951. uv2: null
  7952. });
  7953. }
  7954. }
  7955. }
  7956. class LineSegments2 extends Mesh {
  7957. constructor() {
  7958. var geometry = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new LineSegmentsGeometry();
  7959. var material = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new LineMaterial({
  7960. color: Math.random() * 0xffffff
  7961. });
  7962. super(geometry, material);
  7963. this.isLineSegments2 = true;
  7964. this.type = 'LineSegments2';
  7965. }
  7966. // for backwards-compatibility, but could be a method of LineSegmentsGeometry...
  7967. computeLineDistances() {
  7968. var geometry = this.geometry;
  7969. var instanceStart = geometry.attributes.instanceStart;
  7970. var instanceEnd = geometry.attributes.instanceEnd;
  7971. var lineDistances = new Float32Array(2 * instanceStart.count);
  7972. for (var i = 0, j = 0, l = instanceStart.count; i < l; i++, j += 2) {
  7973. _start$2.fromBufferAttribute(instanceStart, i);
  7974. _end$2.fromBufferAttribute(instanceEnd, i);
  7975. lineDistances[j] = j === 0 ? 0 : lineDistances[j - 1];
  7976. lineDistances[j + 1] = lineDistances[j] + _start$2.distanceTo(_end$2);
  7977. }
  7978. var instanceDistanceBuffer = new InstancedInterleavedBuffer(lineDistances, 2, 1); // d0, d1
  7979. geometry.setAttribute('instanceDistanceStart', new InterleavedBufferAttribute(instanceDistanceBuffer, 1, 0)); // d0
  7980. geometry.setAttribute('instanceDistanceEnd', new InterleavedBufferAttribute(instanceDistanceBuffer, 1, 1)); // d1
  7981. return this;
  7982. }
  7983. raycast(raycaster, intersects) {
  7984. var worldUnits = this.material.worldUnits;
  7985. var camera = raycaster.camera;
  7986. if (camera === null && !worldUnits) {
  7987. console.error('LineSegments2: "Raycaster.camera" needs to be set in order to raycast against LineSegments2 while worldUnits is set to false.');
  7988. }
  7989. var threshold = raycaster.params.Line2 !== undefined ? raycaster.params.Line2.threshold || 0 : 0;
  7990. _ray$3 = raycaster.ray;
  7991. var matrixWorld = this.matrixWorld;
  7992. var geometry = this.geometry;
  7993. var material = this.material;
  7994. _lineWidth = material.lineWidth + threshold;
  7995. _instanceStart = geometry.attributes.instanceStart;
  7996. _instanceEnd = geometry.attributes.instanceEnd;
  7997. // check if we intersect the sphere bounds
  7998. if (geometry.boundingSphere === null) {
  7999. geometry.computeBoundingSphere();
  8000. }
  8001. _sphere$4.copy(geometry.boundingSphere).applyMatrix4(matrixWorld);
  8002. // increase the sphere bounds by the worst case line screen space width
  8003. var sphereMargin;
  8004. if (worldUnits) {
  8005. sphereMargin = _lineWidth * 0.5;
  8006. } else {
  8007. var distanceToSphere = Math.max(camera.near, _sphere$4.distanceToPoint(_ray$3.origin));
  8008. sphereMargin = getWorldSpaceHalfWidth(camera, distanceToSphere, material.resolution);
  8009. }
  8010. _sphere$4.radius += sphereMargin;
  8011. if (_ray$3.intersectsSphere(_sphere$4) === false) {
  8012. return;
  8013. }
  8014. // check if we intersect the box bounds
  8015. if (geometry.boundingBox === null) {
  8016. geometry.computeBoundingBox();
  8017. }
  8018. _box$5.copy(geometry.boundingBox).applyMatrix4(matrixWorld);
  8019. // increase the box bounds by the worst case line width
  8020. var boxMargin;
  8021. if (worldUnits) {
  8022. boxMargin = _lineWidth * 0.5;
  8023. } else {
  8024. var distanceToBox = Math.max(camera.near, _box$5.distanceToPoint(_ray$3.origin));
  8025. boxMargin = getWorldSpaceHalfWidth(camera, distanceToBox, material.resolution);
  8026. }
  8027. _box$5.expandByScalar(boxMargin);
  8028. if (_ray$3.intersectsBox(_box$5) === false) {
  8029. return;
  8030. }
  8031. if (worldUnits) {
  8032. raycastWorldUnits(this, intersects);
  8033. } else {
  8034. raycastScreenSpace(this, camera, intersects);
  8035. }
  8036. }
  8037. }
  8038. class LineGeometry extends LineSegmentsGeometry {
  8039. constructor() {
  8040. super();
  8041. this.isLineGeometry = true;
  8042. this.type = 'LineGeometry';
  8043. }
  8044. setPositions(array) {
  8045. //见potree.shim.js
  8046. // converts [ x1, y1, z1, x2, y2, z2, ... ] to pairs format
  8047. var length = array.length - 3;
  8048. var points = new Float32Array(2 * length);
  8049. for (var i = 0; i < length; i += 3) {
  8050. points[2 * i] = array[i];
  8051. points[2 * i + 1] = array[i + 1];
  8052. points[2 * i + 2] = array[i + 2];
  8053. points[2 * i + 3] = array[i + 3];
  8054. points[2 * i + 4] = array[i + 4];
  8055. points[2 * i + 5] = array[i + 5];
  8056. }
  8057. super.setPositions(points);
  8058. return this;
  8059. }
  8060. setColors(array) {
  8061. // converts [ r1, g1, b1, r2, g2, b2, ... ] to pairs format
  8062. var length = array.length - 3;
  8063. var colors = new Float32Array(2 * length);
  8064. for (var i = 0; i < length; i += 3) {
  8065. colors[2 * i] = array[i];
  8066. colors[2 * i + 1] = array[i + 1];
  8067. colors[2 * i + 2] = array[i + 2];
  8068. colors[2 * i + 3] = array[i + 3];
  8069. colors[2 * i + 4] = array[i + 4];
  8070. colors[2 * i + 5] = array[i + 5];
  8071. }
  8072. super.setColors(colors);
  8073. return this;
  8074. }
  8075. fromLine(line) {
  8076. var geometry = line.geometry;
  8077. this.setPositions(geometry.attributes.position.array); // assumes non-indexed
  8078. // set colors, maybe
  8079. return this;
  8080. }
  8081. }
  8082. class Line2 extends LineSegments2 {
  8083. constructor() {
  8084. var geometry = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new LineGeometry();
  8085. var material = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new LineMaterial({
  8086. color: Math.random() * 0xffffff
  8087. });
  8088. super(geometry, material);
  8089. this.isLine2 = true;
  8090. this.type = 'Line2';
  8091. }
  8092. }
  8093. //old
  8094. function createHeightLine() {
  8095. var lineGeometry = new LineGeometry();
  8096. lineGeometry.setPositions([0, 0, 0, 0, 0, 0]);
  8097. var lineMaterial = new LineMaterial({
  8098. color: 0x00ff00,
  8099. dashSize: 5,
  8100. gapSize: 2,
  8101. linewidth: 2,
  8102. resolution: new Vector2(1000, 1000)
  8103. });
  8104. lineMaterial.depthTest = false;
  8105. var heightEdge = new Line2(lineGeometry, lineMaterial);
  8106. heightEdge.visible = false;
  8107. //this.add(this.heightEdge);
  8108. return heightEdge;
  8109. }
  8110. function createHeightLabel() {
  8111. var heightLabel = new TextSprite$1('');
  8112. heightLabel.setTextColor({
  8113. r: 140,
  8114. g: 250,
  8115. b: 140,
  8116. a: 1.0
  8117. });
  8118. heightLabel.setBorderColor({
  8119. r: 0,
  8120. g: 0,
  8121. b: 0,
  8122. a: 1.0
  8123. });
  8124. heightLabel.setBackgroundColor({
  8125. r: 0,
  8126. g: 0,
  8127. b: 0,
  8128. a: 1.0
  8129. });
  8130. heightLabel.fontsize = 16;
  8131. heightLabel.material.depthTest = false;
  8132. heightLabel.material.opacity = 1;
  8133. heightLabel.visible = false;
  8134. return heightLabel;
  8135. }
  8136. function createAreaLabel() {
  8137. var areaLabel = new TextSprite$1('');
  8138. areaLabel.setTextColor({
  8139. r: 140,
  8140. g: 250,
  8141. b: 140,
  8142. a: 1.0
  8143. });
  8144. areaLabel.setBorderColor({
  8145. r: 0,
  8146. g: 0,
  8147. b: 0,
  8148. a: 1.0
  8149. });
  8150. areaLabel.setBackgroundColor({
  8151. r: 0,
  8152. g: 0,
  8153. b: 0,
  8154. a: 1.0
  8155. });
  8156. areaLabel.fontsize = 16;
  8157. areaLabel.material.depthTest = false;
  8158. areaLabel.material.opacity = 1;
  8159. areaLabel.visible = false;
  8160. return areaLabel;
  8161. }
  8162. function createCircleRadiusLabel() {
  8163. var circleRadiusLabel = new TextSprite$1("");
  8164. circleRadiusLabel.setTextColor({
  8165. r: 140,
  8166. g: 250,
  8167. b: 140,
  8168. a: 1.0
  8169. });
  8170. circleRadiusLabel.setBorderColor({
  8171. r: 0,
  8172. g: 0,
  8173. b: 0,
  8174. a: 1.0
  8175. });
  8176. circleRadiusLabel.setBackgroundColor({
  8177. r: 0,
  8178. g: 0,
  8179. b: 0,
  8180. a: 1.0
  8181. });
  8182. circleRadiusLabel.fontsize = 16;
  8183. circleRadiusLabel.material.depthTest = false;
  8184. circleRadiusLabel.material.opacity = 1;
  8185. circleRadiusLabel.visible = false;
  8186. return circleRadiusLabel;
  8187. }
  8188. function createCircleRadiusLine() {
  8189. var lineGeometry = new LineGeometry();
  8190. lineGeometry.setPositions([0, 0, 0, 0, 0, 0]);
  8191. var lineMaterial = new LineMaterial({
  8192. color: 0xff0000,
  8193. linewidth: 2,
  8194. resolution: new Vector2(1000, 1000),
  8195. gapSize: 1,
  8196. dashed: true
  8197. });
  8198. lineMaterial.depthTest = false;
  8199. var circleRadiusLine = new Line2(lineGeometry, lineMaterial);
  8200. circleRadiusLine.visible = false;
  8201. return circleRadiusLine;
  8202. }
  8203. function createCircleLine() {
  8204. var coordinates = [];
  8205. var n = 128;
  8206. for (var i = 0; i <= n; i++) {
  8207. var u0 = 2 * Math.PI * (i / n);
  8208. var u1 = 2 * Math.PI * (i + 1) / n;
  8209. var p0 = new Vector3(Math.cos(u0), Math.sin(u0), 0);
  8210. var p1 = new Vector3(Math.cos(u1), Math.sin(u1), 0);
  8211. coordinates.push(...p0.toArray(), ...p1.toArray());
  8212. }
  8213. var geometry = new LineGeometry();
  8214. geometry.setPositions(coordinates);
  8215. var material = new LineMaterial({
  8216. color: 0xff0000,
  8217. dashSize: 5,
  8218. gapSize: 2,
  8219. linewidth: 2,
  8220. resolution: new Vector2(1000, 1000)
  8221. });
  8222. material.depthTest = false;
  8223. var circleLine = new Line2(geometry, material);
  8224. circleLine.visible = false;
  8225. circleLine.computeLineDistances();
  8226. return circleLine;
  8227. }
  8228. function createCircleCenter() {
  8229. var sg = new SphereGeometry(1, 32, 32);
  8230. var sm = new MeshNormalMaterial();
  8231. var circleCenter = new Mesh(sg, sm);
  8232. circleCenter.visible = false;
  8233. return circleCenter;
  8234. }
  8235. function createLine() {
  8236. var geometry = new LineGeometry();
  8237. geometry.setPositions([0, 0, 0, 0, 0, 0]);
  8238. var material = new LineMaterial({
  8239. color: 0xff0000,
  8240. linewidth: 2,
  8241. resolution: new Vector2(1000, 1000),
  8242. gapSize: 1,
  8243. dashed: true
  8244. });
  8245. material.depthTest = false;
  8246. var line = new Line2(geometry, material);
  8247. return line;
  8248. }
  8249. function createCircle() {
  8250. var coordinates = [];
  8251. var n = 128;
  8252. for (var i = 0; i <= n; i++) {
  8253. var u0 = 2 * Math.PI * (i / n);
  8254. var u1 = 2 * Math.PI * (i + 1) / n;
  8255. var p0 = new Vector3(Math.cos(u0), Math.sin(u0), 0);
  8256. var p1 = new Vector3(Math.cos(u1), Math.sin(u1), 0);
  8257. coordinates.push(...p0.toArray(), ...p1.toArray());
  8258. }
  8259. var geometry = new LineGeometry();
  8260. geometry.setPositions(coordinates);
  8261. var material = new LineMaterial({
  8262. color: 0xff0000,
  8263. dashSize: 5,
  8264. gapSize: 2,
  8265. linewidth: 2,
  8266. resolution: new Vector2(1000, 1000)
  8267. });
  8268. material.depthTest = false;
  8269. var line = new Line2(geometry, material);
  8270. line.computeLineDistances();
  8271. return line;
  8272. }
  8273. function createAzimuth() {
  8274. var azimuth = {
  8275. label: null,
  8276. center: null,
  8277. target: null,
  8278. north: null,
  8279. centerToNorth: null,
  8280. centerToTarget: null,
  8281. centerToTargetground: null,
  8282. targetgroundToTarget: null,
  8283. circle: null,
  8284. node: null
  8285. };
  8286. var sg = new SphereGeometry(1, 32, 32);
  8287. var sm = new MeshNormalMaterial();
  8288. {
  8289. var label = new TextSprite$1("");
  8290. label.setTextColor({
  8291. r: 140,
  8292. g: 250,
  8293. b: 140,
  8294. a: 1.0
  8295. });
  8296. label.setBorderColor({
  8297. r: 0,
  8298. g: 0,
  8299. b: 0,
  8300. a: 1.0
  8301. });
  8302. label.setBackgroundColor({
  8303. r: 0,
  8304. g: 0,
  8305. b: 0,
  8306. a: 1.0
  8307. });
  8308. label.fontsize = 16;
  8309. label.material.depthTest = false;
  8310. label.material.opacity = 1;
  8311. azimuth.label = label;
  8312. }
  8313. azimuth.center = new Mesh(sg, sm);
  8314. azimuth.target = new Mesh(sg, sm);
  8315. azimuth.north = new Mesh(sg, sm);
  8316. azimuth.centerToNorth = createLine();
  8317. azimuth.centerToTarget = createLine();
  8318. azimuth.centerToTargetground = createLine();
  8319. azimuth.targetgroundToTarget = createLine();
  8320. azimuth.circle = createCircle();
  8321. azimuth.node = new Object3D();
  8322. azimuth.node.add(azimuth.centerToNorth, azimuth.centerToTarget, azimuth.centerToTargetground, azimuth.targetgroundToTarget, azimuth.circle, azimuth.label, azimuth.center, azimuth.target, azimuth.north);
  8323. return azimuth;
  8324. }
  8325. class Measure extends Object3D {
  8326. constructor() {
  8327. super();
  8328. this.constructor.counter = this.constructor.counter === undefined ? 0 : this.constructor.counter + 1;
  8329. this.name = 'Measure_' + this.constructor.counter;
  8330. this.points = [];
  8331. this._showDistances = true;
  8332. this._showCoordinates = false;
  8333. this._showArea = false;
  8334. this._closed = true;
  8335. this._showAngles = false;
  8336. this._showCircle = false;
  8337. this._showHeight = false;
  8338. this._showEdges = true;
  8339. this._showAzimuth = false;
  8340. this.maxMarkers = Number.MAX_SAFE_INTEGER;
  8341. this.sphereGeometry = new SphereGeometry(0.4, 10, 10);
  8342. this.color = new Color(0xff0000);
  8343. this.spheres = [];
  8344. this.edges = [];
  8345. this.sphereLabels = [];
  8346. this.edgeLabels = [];
  8347. this.angleLabels = [];
  8348. this.coordinateLabels = [];
  8349. this.heightEdge = createHeightLine();
  8350. this.heightLabel = createHeightLabel();
  8351. this.areaLabel = createAreaLabel();
  8352. this.circleRadiusLabel = createCircleRadiusLabel();
  8353. this.circleRadiusLine = createCircleRadiusLine();
  8354. this.circleLine = createCircleLine();
  8355. this.circleCenter = createCircleCenter();
  8356. this.azimuth = createAzimuth();
  8357. this.add(this.heightEdge);
  8358. this.add(this.heightLabel);
  8359. this.add(this.areaLabel);
  8360. this.add(this.circleRadiusLabel);
  8361. this.add(this.circleRadiusLine);
  8362. this.add(this.circleLine);
  8363. this.add(this.circleCenter);
  8364. this.add(this.azimuth.node);
  8365. }
  8366. createSphereMaterial() {
  8367. var sphereMaterial = new MeshLambertMaterial({
  8368. //shading: THREE.SmoothShading,
  8369. color: this.color,
  8370. depthTest: false,
  8371. depthWrite: false
  8372. });
  8373. return sphereMaterial;
  8374. }
  8375. addMarker(point) {
  8376. if (point.x != null) {
  8377. point = {
  8378. position: point
  8379. };
  8380. } else if (point instanceof Array) {
  8381. point = {
  8382. position: new Vector3(...point)
  8383. };
  8384. }
  8385. this.points.push(point);
  8386. // sphere
  8387. var sphere = new Mesh(this.sphereGeometry, this.createSphereMaterial());
  8388. this.add(sphere);
  8389. this.spheres.push(sphere);
  8390. {
  8391. // edges
  8392. var lineGeometry = new LineGeometry();
  8393. lineGeometry.setPositions([0, 0, 0, 0, 0, 0]);
  8394. var lineMaterial = new LineMaterial({
  8395. color: 0xff0000,
  8396. linewidth: 2,
  8397. resolution: new Vector2(1000, 1000)
  8398. });
  8399. lineMaterial.depthTest = false;
  8400. var edge = new Line2(lineGeometry, lineMaterial);
  8401. edge.visible = true;
  8402. this.add(edge);
  8403. this.edges.push(edge);
  8404. }
  8405. {
  8406. // edge labels
  8407. var edgeLabel = new TextSprite$1();
  8408. edgeLabel.setBorderColor({
  8409. r: 0,
  8410. g: 0,
  8411. b: 0,
  8412. a: 1.0
  8413. });
  8414. edgeLabel.setBackgroundColor({
  8415. r: 0,
  8416. g: 0,
  8417. b: 0,
  8418. a: 1.0
  8419. });
  8420. edgeLabel.material.depthTest = false;
  8421. edgeLabel.visible = false;
  8422. edgeLabel.fontsize = 16;
  8423. this.edgeLabels.push(edgeLabel);
  8424. this.add(edgeLabel);
  8425. }
  8426. {
  8427. // angle labels
  8428. var angleLabel = new TextSprite$1();
  8429. angleLabel.setBorderColor({
  8430. r: 0,
  8431. g: 0,
  8432. b: 0,
  8433. a: 1.0
  8434. });
  8435. angleLabel.setBackgroundColor({
  8436. r: 0,
  8437. g: 0,
  8438. b: 0,
  8439. a: 1.0
  8440. });
  8441. angleLabel.fontsize = 16;
  8442. angleLabel.material.depthTest = false;
  8443. angleLabel.material.opacity = 1;
  8444. angleLabel.visible = false;
  8445. this.angleLabels.push(angleLabel);
  8446. this.add(angleLabel);
  8447. }
  8448. {
  8449. // coordinate labels
  8450. var coordinateLabel = new TextSprite$1();
  8451. coordinateLabel.setBorderColor({
  8452. r: 0,
  8453. g: 0,
  8454. b: 0,
  8455. a: 1.0
  8456. });
  8457. coordinateLabel.setBackgroundColor({
  8458. r: 0,
  8459. g: 0,
  8460. b: 0,
  8461. a: 1.0
  8462. });
  8463. coordinateLabel.fontsize = 16;
  8464. coordinateLabel.material.depthTest = false;
  8465. coordinateLabel.material.opacity = 1;
  8466. coordinateLabel.visible = false;
  8467. this.coordinateLabels.push(coordinateLabel);
  8468. this.add(coordinateLabel);
  8469. }
  8470. {
  8471. // Event Listeners
  8472. var drag = e => {
  8473. var I = Utils.getMousePointCloudIntersection(e.drag.end, e.viewer.scene.getActiveCamera(), e.viewer, e.viewer.scene.pointclouds, {
  8474. pickClipped: true
  8475. });
  8476. if (I) {
  8477. var i = this.spheres.indexOf(e.drag.object);
  8478. if (i !== -1) {
  8479. var _point = this.points[i];
  8480. // loop through current keys and cleanup ones that will be orphaned
  8481. for (var key of Object.keys(_point)) {
  8482. if (!I.point[key]) {
  8483. delete _point[key];
  8484. }
  8485. }
  8486. for (var _key of Object.keys(I.point).filter(e => e !== 'position')) {
  8487. _point[_key] = I.point[_key];
  8488. }
  8489. this.setPosition(i, I.location);
  8490. }
  8491. }
  8492. };
  8493. var drop = e => {
  8494. var i = this.spheres.indexOf(e.drag.object);
  8495. if (i !== -1) {
  8496. this.dispatchEvent({
  8497. 'type': 'marker_dropped',
  8498. 'measurement': this,
  8499. 'index': i
  8500. });
  8501. }
  8502. };
  8503. var mouseover = e => e.object.material.emissive.setHex(0x888888);
  8504. var mouseleave = e => e.object.material.emissive.setHex(0x000000);
  8505. sphere.addEventListener('drag', drag);
  8506. sphere.addEventListener('drop', drop);
  8507. sphere.addEventListener('mouseover', mouseover);
  8508. sphere.addEventListener('mouseleave', mouseleave);
  8509. }
  8510. var event = {
  8511. type: 'marker_added',
  8512. measurement: this,
  8513. sphere: sphere
  8514. };
  8515. this.dispatchEvent(event);
  8516. this.setMarker(this.points.length - 1, point);
  8517. }
  8518. removeMarker(index) {
  8519. this.points.splice(index, 1);
  8520. this.remove(this.spheres[index]);
  8521. var edgeIndex = index === 0 ? 0 : index - 1;
  8522. this.remove(this.edges[edgeIndex]);
  8523. this.edges.splice(edgeIndex, 1);
  8524. this.remove(this.edgeLabels[edgeIndex]);
  8525. this.edgeLabels.splice(edgeIndex, 1);
  8526. this.coordinateLabels.splice(index, 1);
  8527. this.remove(this.angleLabels[index]);
  8528. this.angleLabels.splice(index, 1);
  8529. this.spheres.splice(index, 1);
  8530. this.update();
  8531. this.dispatchEvent({
  8532. type: 'marker_removed',
  8533. measurement: this
  8534. });
  8535. }
  8536. setMarker(index, point) {
  8537. this.points[index] = point;
  8538. var event = {
  8539. type: 'marker_moved',
  8540. measure: this,
  8541. index: index,
  8542. position: point.position.clone()
  8543. };
  8544. this.dispatchEvent(event);
  8545. this.update();
  8546. }
  8547. setPosition(index, position) {
  8548. var point = this.points[index];
  8549. point.position.copy(position);
  8550. var event = {
  8551. type: 'marker_moved',
  8552. measure: this,
  8553. index: index,
  8554. position: position.clone()
  8555. };
  8556. this.dispatchEvent(event);
  8557. this.update();
  8558. }
  8559. getArea() {
  8560. var area = 0;
  8561. var j = this.points.length - 1;
  8562. for (var i = 0; i < this.points.length; i++) {
  8563. var p1 = this.points[i].position;
  8564. var p2 = this.points[j].position;
  8565. area += (p2.x + p1.x) * (p1.y - p2.y);
  8566. j = i;
  8567. }
  8568. return Math.abs(area / 2);
  8569. }
  8570. getTotalDistance() {
  8571. if (this.points.length === 0) {
  8572. return 0;
  8573. }
  8574. var distance = 0;
  8575. for (var i = 1; i < this.points.length; i++) {
  8576. var prev = this.points[i - 1].position;
  8577. var curr = this.points[i].position;
  8578. var d = prev.distanceTo(curr);
  8579. distance += d;
  8580. }
  8581. if (this.closed && this.points.length > 1) {
  8582. var first = this.points[0].position;
  8583. var last = this.points[this.points.length - 1].position;
  8584. var _d = last.distanceTo(first);
  8585. distance += _d;
  8586. }
  8587. return distance;
  8588. }
  8589. getAngleBetweenLines(cornerPoint, point1, point2) {
  8590. var v1 = new Vector3().subVectors(point1.position, cornerPoint.position);
  8591. var v2 = new Vector3().subVectors(point2.position, cornerPoint.position);
  8592. // avoid the error printed by threejs if denominator is 0
  8593. var denominator = Math.sqrt(v1.lengthSq() * v2.lengthSq());
  8594. if (denominator === 0) {
  8595. return 0;
  8596. } else {
  8597. return v1.angleTo(v2);
  8598. }
  8599. }
  8600. getAngle(index) {
  8601. if (this.points.length < 3 || index >= this.points.length) {
  8602. return 0;
  8603. }
  8604. var previous = index === 0 ? this.points[this.points.length - 1] : this.points[index - 1];
  8605. var point = this.points[index];
  8606. var next = this.points[(index + 1) % this.points.length];
  8607. return this.getAngleBetweenLines(point, previous, next);
  8608. }
  8609. // updateAzimuth(){
  8610. // // if(this.points.length !== 2){
  8611. // // return;
  8612. // // }
  8613. // // const azimuth = this.azimuth;
  8614. // // const [p0, p1] = this.points;
  8615. // // const r = p0.position.distanceTo(p1.position);
  8616. // }
  8617. update() {
  8618. if (this.points.length === 0) {
  8619. return;
  8620. } else if (this.points.length === 1) {
  8621. var point = this.points[0];
  8622. var position = point.position;
  8623. this.spheres[0].position.copy(position);
  8624. {
  8625. // coordinate labels
  8626. var coordinateLabel = this.coordinateLabels[0];
  8627. var msg = position.toArray().map(p => Utils.addCommas(p.toFixed(2))).join(" / ");
  8628. coordinateLabel.setText(msg);
  8629. coordinateLabel.visible = this.showCoordinates;
  8630. }
  8631. return;
  8632. }
  8633. var lastIndex = this.points.length - 1;
  8634. var centroid = new Vector3();
  8635. for (var i = 0; i <= lastIndex; i++) {
  8636. var _point2 = this.points[i];
  8637. centroid.add(_point2.position);
  8638. }
  8639. centroid.divideScalar(this.points.length);
  8640. for (var _i = 0; _i <= lastIndex; _i++) {
  8641. var index = _i;
  8642. var nextIndex = _i + 1 > lastIndex ? 0 : _i + 1;
  8643. var previousIndex = _i === 0 ? lastIndex : _i - 1;
  8644. var _point3 = this.points[index];
  8645. var nextPoint = this.points[nextIndex];
  8646. var previousPoint = this.points[previousIndex];
  8647. var sphere = this.spheres[index];
  8648. // spheres
  8649. sphere.position.copy(_point3.position);
  8650. sphere.material.color = this.color;
  8651. {
  8652. // edges
  8653. var edge = this.edges[index];
  8654. edge.material.color = this.color;
  8655. edge.position.copy(_point3.position);
  8656. edge.geometry.setPositions([0, 0, 0, ...nextPoint.position.clone().sub(_point3.position).toArray()]);
  8657. edge.geometry.verticesNeedUpdate = true;
  8658. edge.geometry.computeBoundingSphere();
  8659. edge.computeLineDistances();
  8660. edge.visible = index < lastIndex || this.closed;
  8661. if (!this.showEdges) {
  8662. edge.visible = false;
  8663. }
  8664. }
  8665. {
  8666. // edge labels
  8667. var edgeLabel = this.edgeLabels[_i];
  8668. var center = new Vector3().add(_point3.position);
  8669. center.add(nextPoint.position);
  8670. center = center.multiplyScalar(0.5);
  8671. var distance = _point3.position.distanceTo(nextPoint.position);
  8672. edgeLabel.position.copy(center);
  8673. var suffix = "";
  8674. if (this.lengthUnit != null && this.lengthUnitDisplay != null) {
  8675. distance = distance / this.lengthUnit.unitspermeter * this.lengthUnitDisplay.unitspermeter; //convert to meters then to the display unit
  8676. suffix = this.lengthUnitDisplay.code;
  8677. }
  8678. var txtLength = Utils.addCommas(distance.toFixed(2));
  8679. edgeLabel.setText("".concat(txtLength, " ").concat(suffix));
  8680. edgeLabel.visible = this.showDistances && (index < lastIndex || this.closed) && this.points.length >= 2 && distance > 0;
  8681. }
  8682. {
  8683. // angle labels
  8684. var angleLabel = this.angleLabels[_i];
  8685. var angle = this.getAngleBetweenLines(_point3, previousPoint, nextPoint);
  8686. var dir = nextPoint.position.clone().sub(previousPoint.position);
  8687. dir.multiplyScalar(0.5);
  8688. dir = previousPoint.position.clone().add(dir).sub(_point3.position).normalize();
  8689. var dist = Math.min(_point3.position.distanceTo(previousPoint.position), _point3.position.distanceTo(nextPoint.position));
  8690. dist = dist / 9;
  8691. var labelPos = _point3.position.clone().add(dir.multiplyScalar(dist));
  8692. angleLabel.position.copy(labelPos);
  8693. var _msg = Utils.addCommas((angle * (180.0 / Math.PI)).toFixed(1)) + '\u00B0';
  8694. angleLabel.setText(_msg);
  8695. angleLabel.visible = this.showAngles && (index < lastIndex || this.closed) && this.points.length >= 3 && angle > 0;
  8696. }
  8697. }
  8698. {
  8699. // update height stuff
  8700. var heightEdge = this.heightEdge;
  8701. heightEdge.visible = this.showHeight;
  8702. this.heightLabel.visible = this.showHeight;
  8703. if (this.showHeight) {
  8704. var sorted = this.points.slice().sort((a, b) => a.position.z - b.position.z);
  8705. var lowPoint = sorted[0].position.clone();
  8706. var highPoint = sorted[sorted.length - 1].position.clone();
  8707. var min = lowPoint.z;
  8708. var max = highPoint.z;
  8709. var height = max - min;
  8710. var start = new Vector3(highPoint.x, highPoint.y, min);
  8711. var end = new Vector3(highPoint.x, highPoint.y, max);
  8712. heightEdge.position.copy(lowPoint);
  8713. heightEdge.geometry.setPositions([0, 0, 0, ...start.clone().sub(lowPoint).toArray(), ...start.clone().sub(lowPoint).toArray(), ...end.clone().sub(lowPoint).toArray()]);
  8714. heightEdge.geometry.verticesNeedUpdate = true;
  8715. // heightEdge.geometry.computeLineDistances();
  8716. // heightEdge.geometry.lineDistancesNeedUpdate = true;
  8717. heightEdge.geometry.computeBoundingSphere();
  8718. heightEdge.computeLineDistances();
  8719. // heightEdge.material.dashSize = height / 40;
  8720. // heightEdge.material.gapSize = height / 40;
  8721. var heightLabelPosition = start.clone().add(end).multiplyScalar(0.5);
  8722. this.heightLabel.position.copy(heightLabelPosition);
  8723. var _suffix = "";
  8724. if (this.lengthUnit != null && this.lengthUnitDisplay != null) {
  8725. height = height / this.lengthUnit.unitspermeter * this.lengthUnitDisplay.unitspermeter; //convert to meters then to the display unit
  8726. _suffix = this.lengthUnitDisplay.code;
  8727. }
  8728. var txtHeight = Utils.addCommas(height.toFixed(2));
  8729. var _msg2 = "".concat(txtHeight, " ").concat(_suffix);
  8730. this.heightLabel.setText(_msg2);
  8731. }
  8732. }
  8733. {
  8734. // update circle stuff
  8735. var circleRadiusLabel = this.circleRadiusLabel;
  8736. var circleRadiusLine = this.circleRadiusLine;
  8737. var circleLine = this.circleLine;
  8738. var circleCenter = this.circleCenter;
  8739. var circleOkay = this.points.length === 3;
  8740. circleRadiusLabel.visible = this.showCircle && circleOkay;
  8741. circleRadiusLine.visible = this.showCircle && circleOkay;
  8742. circleLine.visible = this.showCircle && circleOkay;
  8743. circleCenter.visible = this.showCircle && circleOkay;
  8744. if (this.showCircle && circleOkay) {
  8745. var A = this.points[0].position;
  8746. var B = this.points[1].position;
  8747. var C = this.points[2].position;
  8748. var AB = B.clone().sub(A);
  8749. var AC = C.clone().sub(A);
  8750. var N = AC.clone().cross(AB).normalize();
  8751. var _center = Potree.Utils.computeCircleCenter(A, B, C);
  8752. var radius = _center.distanceTo(A);
  8753. var scale = radius / 20;
  8754. circleCenter.position.copy(_center);
  8755. circleCenter.scale.set(scale, scale, scale);
  8756. //circleRadiusLine.geometry.vertices[0].set(0, 0, 0);
  8757. //circleRadiusLine.geometry.vertices[1].copy(B.clone().sub(center));
  8758. circleRadiusLine.geometry.setPositions([0, 0, 0, ...B.clone().sub(_center).toArray()]);
  8759. circleRadiusLine.geometry.verticesNeedUpdate = true;
  8760. circleRadiusLine.geometry.computeBoundingSphere();
  8761. circleRadiusLine.position.copy(_center);
  8762. circleRadiusLine.computeLineDistances();
  8763. var target = _center.clone().add(N);
  8764. circleLine.position.copy(_center);
  8765. circleLine.scale.set(radius, radius, radius);
  8766. circleLine.lookAt(target);
  8767. circleRadiusLabel.visible = true;
  8768. circleRadiusLabel.position.copy(_center.clone().add(B).multiplyScalar(0.5));
  8769. circleRadiusLabel.setText("".concat(radius.toFixed(3)));
  8770. }
  8771. }
  8772. {
  8773. // update area label
  8774. this.areaLabel.position.copy(centroid);
  8775. this.areaLabel.visible = this.showArea && this.points.length >= 3;
  8776. var area = this.getArea();
  8777. var _suffix2 = "";
  8778. if (this.lengthUnit != null && this.lengthUnitDisplay != null) {
  8779. area = area / Math.pow(this.lengthUnit.unitspermeter, 2) * Math.pow(this.lengthUnitDisplay.unitspermeter, 2); //convert to square meters then to the square display unit
  8780. _suffix2 = this.lengthUnitDisplay.code;
  8781. }
  8782. var txtArea = Utils.addCommas(area.toFixed(1));
  8783. var _msg3 = "".concat(txtArea, " ").concat(_suffix2, "\xB2");
  8784. this.areaLabel.setText(_msg3);
  8785. }
  8786. // this.updateAzimuth();
  8787. }
  8788. raycast(raycaster, intersects) {
  8789. for (var i = 0; i < this.points.length; i++) {
  8790. var sphere = this.spheres[i];
  8791. sphere.raycast(raycaster, intersects);
  8792. }
  8793. // recalculate distances because they are not necessarely correct
  8794. // for scaled objects.
  8795. // see https://github.com/mrdoob/three.js/issues/5827
  8796. // TODO: remove this once the bug has been fixed
  8797. for (var _i2 = 0; _i2 < intersects.length; _i2++) {
  8798. var I = intersects[_i2];
  8799. I.distance = raycaster.ray.origin.distanceTo(I.point);
  8800. }
  8801. intersects.sort(function (a, b) {
  8802. return a.distance - b.distance;
  8803. });
  8804. }
  8805. get showCoordinates() {
  8806. return this._showCoordinates;
  8807. }
  8808. set showCoordinates(value) {
  8809. this._showCoordinates = value;
  8810. this.update();
  8811. }
  8812. get showAngles() {
  8813. return this._showAngles;
  8814. }
  8815. set showAngles(value) {
  8816. this._showAngles = value;
  8817. this.update();
  8818. }
  8819. get showCircle() {
  8820. return this._showCircle;
  8821. }
  8822. set showCircle(value) {
  8823. this._showCircle = value;
  8824. this.update();
  8825. }
  8826. get showAzimuth() {
  8827. return this._showAzimuth;
  8828. }
  8829. set showAzimuth(value) {
  8830. this._showAzimuth = value;
  8831. this.update();
  8832. }
  8833. get showEdges() {
  8834. return this._showEdges;
  8835. }
  8836. set showEdges(value) {
  8837. this._showEdges = value;
  8838. this.update();
  8839. }
  8840. get showHeight() {
  8841. return this._showHeight;
  8842. }
  8843. set showHeight(value) {
  8844. this._showHeight = value;
  8845. this.update();
  8846. }
  8847. get showArea() {
  8848. return this._showArea;
  8849. }
  8850. set showArea(value) {
  8851. this._showArea = value;
  8852. this.update();
  8853. }
  8854. get closed() {
  8855. return this._closed;
  8856. }
  8857. set closed(value) {
  8858. this._closed = value;
  8859. this.update();
  8860. }
  8861. get showDistances() {
  8862. return this._showDistances;
  8863. }
  8864. set showDistances(value) {
  8865. this._showDistances = value;
  8866. this.update();
  8867. }
  8868. }
  8869. class PolygonClipVolume extends Object3D {
  8870. constructor(camera) {
  8871. super();
  8872. this.constructor.counter = this.constructor.counter === undefined ? 0 : this.constructor.counter + 1;
  8873. this.name = "polygon_clip_volume_" + this.constructor.counter;
  8874. this.camera = camera.clone();
  8875. this.camera.rotation.set(...camera.rotation.toArray()); // [r85] workaround because camera.clone() doesn't work on rotation
  8876. this.camera.rotation.order = camera.rotation.order;
  8877. this.camera.updateMatrixWorld();
  8878. this.camera.updateProjectionMatrix();
  8879. this.camera.matrixWorldInverse.copy(this.camera.matrixWorld).invert();
  8880. this.viewMatrix = this.camera.matrixWorldInverse.clone();
  8881. this.projMatrix = this.camera.projectionMatrix.clone();
  8882. // projected markers
  8883. this.markers = [];
  8884. this.initialized = false;
  8885. }
  8886. addMarker() {
  8887. var marker = new Mesh();
  8888. var cancel;
  8889. var drag = e => {
  8890. var size = e.viewer.renderer.getSize(new Vector2());
  8891. var projectedPos = new Vector3(2.0 * (e.drag.end.x / size.width) - 1.0, -2.0 * (e.drag.end.y / size.height) + 1.0, 0);
  8892. marker.position.copy(projectedPos);
  8893. };
  8894. var drop = e => {
  8895. cancel();
  8896. };
  8897. cancel = e => {
  8898. marker.removeEventListener("drag", drag);
  8899. marker.removeEventListener("drop", drop);
  8900. };
  8901. marker.addEventListener("drag", drag);
  8902. marker.addEventListener("drop", drop);
  8903. this.markers.push(marker);
  8904. }
  8905. removeLastMarker() {
  8906. if (this.markers.length > 0) {
  8907. this.markers.splice(this.markers.length - 1, 1);
  8908. }
  8909. }
  8910. }
  8911. ;
  8912. class Utils {
  8913. static async loadShapefileFeatures(file, callback) {
  8914. var features = [];
  8915. var handleFinish = () => {
  8916. callback(features);
  8917. };
  8918. var source = await shapefile.open(file);
  8919. while (true) {
  8920. var result = await source.read();
  8921. if (result.done) {
  8922. handleFinish();
  8923. break;
  8924. }
  8925. if (result.value && result.value.type === 'Feature' && result.value.geometry !== undefined) {
  8926. features.push(result.value);
  8927. }
  8928. }
  8929. }
  8930. static toString(value) {
  8931. if (value.x != null) {
  8932. return value.x.toFixed(2) + ', ' + value.y.toFixed(2) + ', ' + value.z.toFixed(2);
  8933. } else {
  8934. return '' + value + '';
  8935. }
  8936. }
  8937. static normalizeURL(url) {
  8938. var u = new URL(url);
  8939. return u.protocol + '//' + u.hostname + u.pathname.replace(/\/+/g, '/');
  8940. }
  8941. static pathExists(url) {
  8942. var req = XHRFactory.createXMLHttpRequest();
  8943. req.open('GET', url, false);
  8944. req.send(null);
  8945. if (req.status !== 200) {
  8946. return false;
  8947. }
  8948. return true;
  8949. }
  8950. static debugSphere(parent, position, scale, color) {
  8951. var geometry = new SphereGeometry(1, 8, 8);
  8952. var material;
  8953. if (color !== undefined) {
  8954. material = new MeshBasicMaterial({
  8955. color: color
  8956. });
  8957. } else {
  8958. material = new MeshNormalMaterial();
  8959. }
  8960. var sphere = new Mesh(geometry, material);
  8961. sphere.position.copy(position);
  8962. sphere.scale.set(scale, scale, scale);
  8963. parent.add(sphere);
  8964. return sphere;
  8965. }
  8966. static debugLine(parent, start, end, color) {
  8967. var material = new LineBasicMaterial({
  8968. color: color
  8969. });
  8970. var geometry = new Geometry();
  8971. var p1 = new Vector3(0, 0, 0);
  8972. var p2 = end.clone().sub(start);
  8973. geometry.vertices.push(p1, p2);
  8974. var tl = new Line(geometry, material);
  8975. tl.position.copy(start);
  8976. parent.add(tl);
  8977. var line = {
  8978. node: tl,
  8979. set: (start, end) => {
  8980. geometry.vertices[0].copy(start);
  8981. geometry.vertices[1].copy(end);
  8982. geometry.verticesNeedUpdate = true;
  8983. }
  8984. };
  8985. return line;
  8986. }
  8987. static debugCircle(parent, center, radius, normal, color) {
  8988. var material = new LineBasicMaterial({
  8989. color: color
  8990. });
  8991. var geometry = new Geometry();
  8992. var n = 32;
  8993. for (var i = 0; i <= n; i++) {
  8994. var u0 = 2 * Math.PI * (i / n);
  8995. var u1 = 2 * Math.PI * (i + 1) / n;
  8996. var p0 = new Vector3(Math.cos(u0), Math.sin(u0), 0);
  8997. var p1 = new Vector3(Math.cos(u1), Math.sin(u1), 0);
  8998. geometry.vertices.push(p0, p1);
  8999. }
  9000. var tl = new Line(geometry, material);
  9001. tl.position.copy(center);
  9002. tl.scale.set(radius, radius, radius);
  9003. parent.add(tl);
  9004. }
  9005. static debugBox(parent, box) {
  9006. var transform = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new Matrix4();
  9007. var color = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0xFFFF00;
  9008. var vertices = [[box.min.x, box.min.y, box.min.z], [box.min.x, box.min.y, box.max.z], [box.min.x, box.max.y, box.min.z], [box.min.x, box.max.y, box.max.z], [box.max.x, box.min.y, box.min.z], [box.max.x, box.min.y, box.max.z], [box.max.x, box.max.y, box.min.z], [box.max.x, box.max.y, box.max.z]].map(v => new Vector3(...v));
  9009. var edges = [[0, 4], [4, 5], [5, 1], [1, 0], [2, 6], [6, 7], [7, 3], [3, 2], [0, 2], [4, 6], [5, 7], [1, 3]];
  9010. var center = box.getCenter(new Vector3());
  9011. var centroids = [{
  9012. position: [box.min.x, center.y, center.z],
  9013. color: 0xFF0000
  9014. }, {
  9015. position: [box.max.x, center.y, center.z],
  9016. color: 0x880000
  9017. }, {
  9018. position: [center.x, box.min.y, center.z],
  9019. color: 0x00FF00
  9020. }, {
  9021. position: [center.x, box.max.y, center.z],
  9022. color: 0x008800
  9023. }, {
  9024. position: [center.x, center.y, box.min.z],
  9025. color: 0x0000FF
  9026. }, {
  9027. position: [center.x, center.y, box.max.z],
  9028. color: 0x000088
  9029. }];
  9030. for (var vertex of vertices) {
  9031. var pos = vertex.clone().applyMatrix4(transform);
  9032. Utils.debugSphere(parent, pos, 0.1, 0xFF0000);
  9033. }
  9034. for (var edge of edges) {
  9035. var start = vertices[edge[0]].clone().applyMatrix4(transform);
  9036. var end = vertices[edge[1]].clone().applyMatrix4(transform);
  9037. Utils.debugLine(parent, start, end, color);
  9038. }
  9039. for (var centroid of centroids) {
  9040. var _pos = new Vector3(...centroid.position).applyMatrix4(transform);
  9041. Utils.debugSphere(parent, _pos, 0.1, centroid.color);
  9042. }
  9043. }
  9044. static debugPlane(parent, plane) {
  9045. var size = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
  9046. var color = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0x0000FF;
  9047. var planehelper = new PlaneHelper(plane, size, color);
  9048. parent.add(planehelper);
  9049. }
  9050. /**
  9051. * adapted from mhluska at https://github.com/mrdoob/three.js/issues/1561
  9052. */
  9053. static computeTransformedBoundingBox(box, transform) {
  9054. var vertices = [new Vector3(box.min.x, box.min.y, box.min.z).applyMatrix4(transform), new Vector3(box.min.x, box.min.y, box.min.z).applyMatrix4(transform), new Vector3(box.max.x, box.min.y, box.min.z).applyMatrix4(transform), new Vector3(box.min.x, box.max.y, box.min.z).applyMatrix4(transform), new Vector3(box.min.x, box.min.y, box.max.z).applyMatrix4(transform), new Vector3(box.min.x, box.max.y, box.max.z).applyMatrix4(transform), new Vector3(box.max.x, box.max.y, box.min.z).applyMatrix4(transform), new Vector3(box.max.x, box.min.y, box.max.z).applyMatrix4(transform), new Vector3(box.max.x, box.max.y, box.max.z).applyMatrix4(transform)];
  9055. var boundingBox = new Box3();
  9056. boundingBox.setFromPoints(vertices);
  9057. return boundingBox;
  9058. }
  9059. //感觉就是bound.applyMatrix4(transform)
  9060. /**
  9061. * add separators to large numbers
  9062. *
  9063. * @param nStr
  9064. * @returns
  9065. */
  9066. static addCommas(nStr) {
  9067. nStr += '';
  9068. var x = nStr.split('.');
  9069. var x1 = x[0];
  9070. var x2 = x.length > 1 ? '.' + x[1] : '';
  9071. var rgx = /(\d+)(\d{3})/;
  9072. while (rgx.test(x1)) {
  9073. x1 = x1.replace(rgx, '$1' + ',' + '$2');
  9074. }
  9075. return x1 + x2;
  9076. }
  9077. static removeCommas(str) {
  9078. return str.replace(/,/g, '');
  9079. }
  9080. /**
  9081. * create worker from a string
  9082. *
  9083. * code from http://stackoverflow.com/questions/10343913/how-to-create-a-web-worker-from-a-string
  9084. */
  9085. static createWorker(code) {
  9086. var blob = new Blob([code], {
  9087. type: 'application/javascript'
  9088. });
  9089. var worker = new Worker(URL.createObjectURL(blob));
  9090. return worker;
  9091. }
  9092. static moveTo(scene, endPosition, endTarget) {
  9093. var view = scene.view;
  9094. var camera = scene.getActiveCamera();
  9095. var animationDuration = 500;
  9096. var easing = TWEEN.Easing.Quartic.Out;
  9097. {
  9098. // animate camera position
  9099. var tween = new TWEEN.Tween(view.position).to(endPosition, animationDuration);
  9100. tween.easing(easing);
  9101. tween.start();
  9102. }
  9103. {
  9104. // animate camera target
  9105. var camTargetDistance = camera.position.distanceTo(endTarget);
  9106. var target = new Vector3().addVectors(camera.position, camera.getWorldDirection(new Vector3()).clone().multiplyScalar(camTargetDistance));
  9107. var _tween = new TWEEN.Tween(target).to(endTarget, animationDuration);
  9108. _tween.easing(easing);
  9109. _tween.onUpdate(() => {
  9110. view.lookAt(target);
  9111. });
  9112. _tween.onComplete(() => {
  9113. view.lookAt(target);
  9114. });
  9115. _tween.start();
  9116. }
  9117. }
  9118. static loadSkybox(path) {
  9119. var parent = new Object3D("skybox_root");
  9120. var camera = new PerspectiveCamera(75, window.innerWidth / window.innerHeight, 1, 100000);
  9121. camera.up.set(0, 0, 1);
  9122. var scene = new Scene();
  9123. var format = '.jpg';
  9124. var urls = [path + 'px' + format, path + 'nx' + format, path + 'py' + format, path + 'ny' + format, path + 'pz' + format, path + 'nz' + format];
  9125. var materialArray = [];
  9126. {
  9127. var _loop = function _loop() {
  9128. var material = new MeshBasicMaterial({
  9129. map: null,
  9130. side: BackSide,
  9131. depthTest: false,
  9132. depthWrite: false,
  9133. color: 0x424556
  9134. });
  9135. materialArray.push(material);
  9136. var loader = new TextureLoader();
  9137. loader.load(urls[i], function loaded(texture) {
  9138. material.map = texture;
  9139. material.needsUpdate = true;
  9140. material.color.setHex(0xffffff);
  9141. }, function progress(xhr) {
  9142. // console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
  9143. }, function error(xhr) {
  9144. console.log('An error happened', xhr);
  9145. });
  9146. };
  9147. for (var i = 0; i < 6; i++) {
  9148. _loop();
  9149. }
  9150. }
  9151. var skyGeometry = new BoxGeometry(700, 700, 700);
  9152. var skybox = new Mesh(skyGeometry, materialArray);
  9153. scene.add(skybox);
  9154. scene.traverse(n => n.frustumCulled = false);
  9155. // z up
  9156. scene.rotation.x = Math.PI / 2;
  9157. parent.children.push(camera);
  9158. camera.parent = parent;
  9159. return {
  9160. camera,
  9161. scene,
  9162. parent
  9163. };
  9164. }
  9165. static createGrid(width, length, spacing, color) {
  9166. var material = new LineBasicMaterial({
  9167. color: color || 0x888888
  9168. });
  9169. var geometry = new Geometry();
  9170. for (var i = 0; i <= length; i++) {
  9171. geometry.vertices.push(new Vector3(-(spacing * width) / 2, i * spacing - spacing * length / 2, 0));
  9172. geometry.vertices.push(new Vector3(+(spacing * width) / 2, i * spacing - spacing * length / 2, 0));
  9173. }
  9174. for (var _i = 0; _i <= width; _i++) {
  9175. geometry.vertices.push(new Vector3(_i * spacing - spacing * width / 2, -(spacing * length) / 2, 0));
  9176. geometry.vertices.push(new Vector3(_i * spacing - spacing * width / 2, +(spacing * length) / 2, 0));
  9177. }
  9178. var line = new LineSegments(geometry, material, LinePieces);
  9179. line.receiveShadow = true;
  9180. return line;
  9181. }
  9182. static createBackgroundTexture(width, height) {
  9183. function gauss(x, y) {
  9184. return 1 / (2 * Math.PI) * Math.exp(-(x * x + y * y) / 2);
  9185. }
  9186. ;
  9187. // map.magFilter = THREE.NearestFilter;
  9188. var size = width * height;
  9189. var data = new Uint8Array(3 * size);
  9190. var chroma = [1, 1.5, 1.7];
  9191. var max = gauss(0, 0);
  9192. for (var x = 0; x < width; x++) {
  9193. for (var y = 0; y < height; y++) {
  9194. var u = 2 * (x / width) - 1;
  9195. var v = 2 * (y / height) - 1;
  9196. var i = x + width * y;
  9197. var d = gauss(2 * u, 2 * v) / max;
  9198. var r = (Math.random() + Math.random() + Math.random()) / 3;
  9199. r = (d * 0.5 + 0.5) * r * 0.03;
  9200. r = r * 0.4;
  9201. // d = Math.pow(d, 0.6);
  9202. data[3 * i + 0] = 255 * (d / 15 + 0.05 + r) * chroma[0];
  9203. data[3 * i + 1] = 255 * (d / 15 + 0.05 + r) * chroma[1];
  9204. data[3 * i + 2] = 255 * (d / 15 + 0.05 + r) * chroma[2];
  9205. }
  9206. }
  9207. var texture = new DataTexture(data, width, height, RGBFormat);
  9208. texture.needsUpdate = true;
  9209. return texture;
  9210. }
  9211. static getMousePointCloudIntersection(mouse, camera, viewer, pointclouds) {
  9212. var params = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
  9213. var renderer = viewer.renderer;
  9214. var nmouse = {
  9215. x: mouse.x / renderer.domElement.clientWidth * 2 - 1,
  9216. y: -(mouse.y / renderer.domElement.clientHeight) * 2 + 1
  9217. };
  9218. var pickParams = {};
  9219. if (params.pickClipped) {
  9220. pickParams.pickClipped = params.pickClipped;
  9221. }
  9222. pickParams.x = mouse.x;
  9223. pickParams.y = renderer.domElement.clientHeight - mouse.y;
  9224. var raycaster = new Raycaster();
  9225. raycaster.setFromCamera(nmouse, camera);
  9226. var ray = raycaster.ray;
  9227. var selectedPointcloud = null;
  9228. var closestDistance = Infinity;
  9229. var closestIntersection = null;
  9230. var closestPoint = null;
  9231. for (var pointcloud of pointclouds) {
  9232. var point = pointcloud.pick(viewer, camera, ray, pickParams);
  9233. if (!point) {
  9234. continue;
  9235. }
  9236. var distance = camera.position.distanceTo(point.position);
  9237. if (distance < closestDistance) {
  9238. closestDistance = distance;
  9239. selectedPointcloud = pointcloud;
  9240. closestIntersection = point.position;
  9241. closestPoint = point;
  9242. }
  9243. }
  9244. if (selectedPointcloud) {
  9245. return {
  9246. location: closestIntersection,
  9247. distance: closestDistance,
  9248. pointcloud: selectedPointcloud,
  9249. point: closestPoint
  9250. };
  9251. } else {
  9252. return null;
  9253. }
  9254. }
  9255. static pixelsArrayToImage(pixels, width, height) {
  9256. var canvas = document.createElement('canvas');
  9257. canvas.width = width;
  9258. canvas.height = height;
  9259. var context = canvas.getContext('2d');
  9260. pixels = new pixels.constructor(pixels);
  9261. for (var i = 0; i < pixels.length; i++) {
  9262. pixels[i * 4 + 3] = 255;
  9263. }
  9264. var imageData = context.createImageData(width, height);
  9265. imageData.data.set(pixels);
  9266. context.putImageData(imageData, 0, 0);
  9267. var img = new Image();
  9268. img.src = canvas.toDataURL();
  9269. // img.style.transform = "scaleY(-1)";
  9270. return img;
  9271. }
  9272. static pixelsArrayToDataUrl(pixels, width, height) {
  9273. var canvas = document.createElement('canvas');
  9274. canvas.width = width;
  9275. canvas.height = height;
  9276. var context = canvas.getContext('2d');
  9277. pixels = new pixels.constructor(pixels);
  9278. for (var i = 0; i < pixels.length; i++) {
  9279. pixels[i * 4 + 3] = 255;
  9280. }
  9281. var imageData = context.createImageData(width, height);
  9282. imageData.data.set(pixels);
  9283. context.putImageData(imageData, 0, 0);
  9284. var dataURL = canvas.toDataURL();
  9285. return dataURL;
  9286. }
  9287. static pixelsArrayToCanvas(pixels, width, height) {
  9288. var canvas = document.createElement('canvas');
  9289. canvas.width = width;
  9290. canvas.height = height;
  9291. var context = canvas.getContext('2d');
  9292. pixels = new pixels.constructor(pixels);
  9293. //for (let i = 0; i < pixels.length; i++) {
  9294. // pixels[i * 4 + 3] = 255;
  9295. //}
  9296. // flip vertically
  9297. var bytesPerLine = width * 4;
  9298. for (var i = 0; i < parseInt(height / 2); i++) {
  9299. var j = height - i - 1;
  9300. var lineI = pixels.slice(i * bytesPerLine, i * bytesPerLine + bytesPerLine);
  9301. var lineJ = pixels.slice(j * bytesPerLine, j * bytesPerLine + bytesPerLine);
  9302. pixels.set(lineJ, i * bytesPerLine);
  9303. pixels.set(lineI, j * bytesPerLine);
  9304. }
  9305. var imageData = context.createImageData(width, height);
  9306. imageData.data.set(pixels);
  9307. context.putImageData(imageData, 0, 0);
  9308. return canvas;
  9309. }
  9310. static removeListeners(dispatcher, type) {
  9311. if (dispatcher._listeners === undefined) {
  9312. return;
  9313. }
  9314. if (dispatcher._listeners[type]) {
  9315. delete dispatcher._listeners[type];
  9316. }
  9317. }
  9318. static mouseToRay(mouse, camera, width, height) {
  9319. var normalizedMouse = {
  9320. x: mouse.x / width * 2 - 1,
  9321. y: -(mouse.y / height) * 2 + 1
  9322. };
  9323. var vector = new Vector3(normalizedMouse.x, normalizedMouse.y, 0.5);
  9324. var origin = camera.position.clone();
  9325. vector.unproject(camera);
  9326. var direction = new Vector3().subVectors(vector, origin).normalize();
  9327. var ray = new Ray(origin, direction);
  9328. return ray;
  9329. }
  9330. static projectedRadius(radius, camera, distance, screenWidth, screenHeight) {
  9331. if (camera instanceof OrthographicCamera) {
  9332. return Utils.projectedRadiusOrtho(radius, camera.projectionMatrix, screenWidth, screenHeight);
  9333. } else if (camera instanceof PerspectiveCamera) {
  9334. return Utils.projectedRadiusPerspective(radius, camera.fov * Math.PI / 180, distance, screenHeight);
  9335. } else {
  9336. throw new Error("invalid parameters");
  9337. }
  9338. }
  9339. static projectedRadiusPerspective(radius, fov, distance, screenHeight) {
  9340. var projFactor = 1 / Math.tan(fov / 2) / distance;
  9341. projFactor = projFactor * screenHeight / 2;
  9342. return radius * projFactor;
  9343. }
  9344. static projectedRadiusOrtho(radius, proj, screenWidth, screenHeight) {
  9345. var p1 = new Vector4(0);
  9346. var p2 = new Vector4(radius);
  9347. p1.applyMatrix4(proj);
  9348. p2.applyMatrix4(proj);
  9349. p1 = new Vector3(p1.x, p1.y, p1.z);
  9350. p2 = new Vector3(p2.x, p2.y, p2.z);
  9351. p1.x = (p1.x + 1.0) * 0.5 * screenWidth;
  9352. p1.y = (p1.y + 1.0) * 0.5 * screenHeight;
  9353. p2.x = (p2.x + 1.0) * 0.5 * screenWidth;
  9354. p2.y = (p2.y + 1.0) * 0.5 * screenHeight;
  9355. return p1.distanceTo(p2);
  9356. }
  9357. static topView(camera, node) {
  9358. camera.position.set(0, 1, 0);
  9359. camera.rotation.set(-Math.PI / 2, 0, 0);
  9360. camera.zoomTo(node, 1);
  9361. }
  9362. static frontView(camera, node) {
  9363. camera.position.set(0, 0, 1);
  9364. camera.rotation.set(0, 0, 0);
  9365. camera.zoomTo(node, 1);
  9366. }
  9367. static leftView(camera, node) {
  9368. camera.position.set(-1, 0, 0);
  9369. camera.rotation.set(0, -Math.PI / 2, 0);
  9370. camera.zoomTo(node, 1);
  9371. }
  9372. static rightView(camera, node) {
  9373. camera.position.set(1, 0, 0);
  9374. camera.rotation.set(0, Math.PI / 2, 0);
  9375. camera.zoomTo(node, 1);
  9376. }
  9377. static findClosestGpsTime(target, viewer) {
  9378. var start = performance.now();
  9379. var nodes = [];
  9380. for (var pc of viewer.scene.pointclouds) {
  9381. nodes.push(pc.root);
  9382. for (var child of pc.root.children) {
  9383. if (child) {
  9384. nodes.push(child);
  9385. }
  9386. }
  9387. }
  9388. var closestNode = null;
  9389. var closestIndex = Infinity;
  9390. var closestDistance = Infinity;
  9391. var closestValue = 0;
  9392. for (var node of nodes) {
  9393. var isOkay = node.geometryNode != null && node.geometryNode.geometry != null && node.sceneNode != null;
  9394. if (!isOkay) {
  9395. continue;
  9396. }
  9397. var _geometry = node.geometryNode.geometry;
  9398. var gpsTime = _geometry.attributes["gps-time"];
  9399. var range = gpsTime.potree.range;
  9400. for (var i = 0; i < gpsTime.array.length; i++) {
  9401. var value = gpsTime.array[i];
  9402. value = value * (range[1] - range[0]) + range[0];
  9403. var distance = Math.abs(target - value);
  9404. if (distance < closestDistance) {
  9405. closestIndex = i;
  9406. closestDistance = distance;
  9407. closestValue = value;
  9408. closestNode = node;
  9409. //console.log("found a closer one: " + value);
  9410. }
  9411. }
  9412. }
  9413. var geometry = closestNode.geometryNode.geometry;
  9414. var position = new Vector3(geometry.attributes.position.array[3 * closestIndex + 0], geometry.attributes.position.array[3 * closestIndex + 1], geometry.attributes.position.array[3 * closestIndex + 2]);
  9415. position.applyMatrix4(closestNode.sceneNode.matrixWorld);
  9416. var end = performance.now();
  9417. var duration = end - start;
  9418. console.log("duration: ".concat(duration.toFixed(3), "ms"));
  9419. return {
  9420. node: closestNode,
  9421. index: closestIndex,
  9422. position: position
  9423. };
  9424. }
  9425. /**
  9426. *
  9427. * 0: no intersection
  9428. * 1: intersection
  9429. * 2: fully inside
  9430. */
  9431. static frustumSphereIntersection(frustum, sphere) {
  9432. var planes = frustum.planes;
  9433. var center = sphere.center;
  9434. var negRadius = -sphere.radius;
  9435. var minDistance = Number.MAX_VALUE;
  9436. for (var i = 0; i < 6; i++) {
  9437. var distance = planes[i].distanceToPoint(center);
  9438. if (distance < negRadius) {
  9439. return 0;
  9440. }
  9441. minDistance = Math.min(minDistance, distance);
  9442. }
  9443. return minDistance >= sphere.radius ? 2 : 1;
  9444. }
  9445. // code taken from three.js
  9446. // ImageUtils - generateDataTexture()
  9447. static generateDataTexture(width, height, color) {
  9448. var size = width * height;
  9449. var data = new Uint8Array(4 * width * height);
  9450. var r = Math.floor(color.r * 255);
  9451. var g = Math.floor(color.g * 255);
  9452. var b = Math.floor(color.b * 255);
  9453. for (var i = 0; i < size; i++) {
  9454. data[i * 3] = r;
  9455. data[i * 3 + 1] = g;
  9456. data[i * 3 + 2] = b;
  9457. }
  9458. var texture = new DataTexture(data, width, height, RGBAFormat);
  9459. texture.needsUpdate = true;
  9460. texture.magFilter = NearestFilter;
  9461. return texture;
  9462. }
  9463. // from http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript
  9464. static getParameterByName(name) {
  9465. name = name.replace(/[[]/, '\\[').replace(/[\]]/, '\\]');
  9466. var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
  9467. var results = regex.exec(document.location.search);
  9468. return results === null ? null : decodeURIComponent(results[1].replace(/\+/g, ' '));
  9469. }
  9470. static setParameter(name, value) {
  9471. // value = encodeURIComponent(value);
  9472. name = name.replace(/[[]/, '\\[').replace(/[\]]/, '\\]');
  9473. var regex = new RegExp('([\\?&])(' + name + '=([^&#]*))');
  9474. var results = regex.exec(document.location.search);
  9475. var url = window.location.href;
  9476. if (results === null) {
  9477. if (window.location.search.length === 0) {
  9478. url = url + '?';
  9479. } else {
  9480. url = url + '&';
  9481. }
  9482. url = url + name + '=' + value;
  9483. } else {
  9484. var newValue = name + '=' + value;
  9485. url = url.replace(results[2], newValue);
  9486. }
  9487. window.history.replaceState({}, '', url);
  9488. }
  9489. static createChildAABB(aabb, index) {
  9490. var min = aabb.min.clone();
  9491. var max = aabb.max.clone();
  9492. var size = new Vector3().subVectors(max, min);
  9493. if ((index & 0b0001) > 0) {
  9494. min.z += size.z / 2;
  9495. } else {
  9496. max.z -= size.z / 2;
  9497. }
  9498. if ((index & 0b0010) > 0) {
  9499. min.y += size.y / 2;
  9500. } else {
  9501. max.y -= size.y / 2;
  9502. }
  9503. if ((index & 0b0100) > 0) {
  9504. min.x += size.x / 2;
  9505. } else {
  9506. max.x -= size.x / 2;
  9507. }
  9508. return new Box3(min, max);
  9509. }
  9510. // see https://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript
  9511. static clipboardCopy(text) {
  9512. var textArea = document.createElement("textarea");
  9513. textArea.style.position = 'fixed';
  9514. textArea.style.top = 0;
  9515. textArea.style.left = 0;
  9516. textArea.style.width = '2em';
  9517. textArea.style.height = '2em';
  9518. textArea.style.padding = 0;
  9519. textArea.style.border = 'none';
  9520. textArea.style.outline = 'none';
  9521. textArea.style.boxShadow = 'none';
  9522. textArea.style.background = 'transparent';
  9523. textArea.value = text;
  9524. document.body.appendChild(textArea);
  9525. textArea.select();
  9526. try {
  9527. var success = document.execCommand('copy');
  9528. if (success) {
  9529. console.log("copied text to clipboard");
  9530. } else {
  9531. console.log("copy to clipboard failed");
  9532. }
  9533. } catch (err) {
  9534. console.log("error while trying to copy to clipboard");
  9535. }
  9536. document.body.removeChild(textArea);
  9537. }
  9538. static getMeasurementIcon(measurement) {
  9539. if (measurement instanceof Measure) {
  9540. if (measurement.showDistances && !measurement.showArea && !measurement.showAngles) {
  9541. return "".concat(Potree.resourcePath, "/icons/distance.svg");
  9542. } else if (measurement.showDistances && measurement.showArea && !measurement.showAngles) {
  9543. return "".concat(Potree.resourcePath, "/icons/area.svg");
  9544. } else if (measurement.maxMarkers === 1) {
  9545. return "".concat(Potree.resourcePath, "/icons/point.svg");
  9546. } else if (!measurement.showDistances && !measurement.showArea && measurement.showAngles) {
  9547. return "".concat(Potree.resourcePath, "/icons/angle.png");
  9548. } else if (measurement.showHeight) {
  9549. return "".concat(Potree.resourcePath, "/icons/height.svg");
  9550. } else {
  9551. return "".concat(Potree.resourcePath, "/icons/distance.svg");
  9552. }
  9553. } else if (measurement instanceof Profile) {
  9554. return "".concat(Potree.resourcePath, "/icons/profile.svg");
  9555. } else if (measurement instanceof Volume) {
  9556. return "".concat(Potree.resourcePath, "/icons/volume.svg");
  9557. } else if (measurement instanceof PolygonClipVolume) {
  9558. return "".concat(Potree.resourcePath, "/icons/clip-polygon.svg");
  9559. }
  9560. }
  9561. static lineToLineIntersection(P0, P1, P2, P3) {
  9562. var P = [P0, P1, P2, P3];
  9563. var d = (m, n, o, p) => {
  9564. var result = (P[m].x - P[n].x) * (P[o].x - P[p].x) + (P[m].y - P[n].y) * (P[o].y - P[p].y) + (P[m].z - P[n].z) * (P[o].z - P[p].z);
  9565. return result;
  9566. };
  9567. var mua = (d(0, 2, 3, 2) * d(3, 2, 1, 0) - d(0, 2, 1, 0) * d(3, 2, 3, 2)
  9568. /**-----------------------------------------------------------------**/) / (d(1, 0, 1, 0) * d(3, 2, 3, 2) - d(3, 2, 1, 0) * d(3, 2, 1, 0));
  9569. var mub = (d(0, 2, 3, 2) + mua * d(3, 2, 1, 0)
  9570. /**--------------------------------------**/) / d(3, 2, 3, 2);
  9571. var P01 = P1.clone().sub(P0);
  9572. var P23 = P3.clone().sub(P2);
  9573. var Pa = P0.clone().add(P01.multiplyScalar(mua));
  9574. var Pb = P2.clone().add(P23.multiplyScalar(mub));
  9575. var center = Pa.clone().add(Pb).multiplyScalar(0.5);
  9576. return center;
  9577. }
  9578. static computeCircleCenter(A, B, C) {
  9579. var AB = B.clone().sub(A);
  9580. var AC = C.clone().sub(A);
  9581. var N = AC.clone().cross(AB).normalize();
  9582. var ab_dir = AB.clone().cross(N).normalize();
  9583. var ac_dir = AC.clone().cross(N).normalize();
  9584. var ab_origin = A.clone().add(B).multiplyScalar(0.5);
  9585. var ac_origin = A.clone().add(C).multiplyScalar(0.5);
  9586. var P0 = ab_origin;
  9587. var P1 = ab_origin.clone().add(ab_dir);
  9588. var P2 = ac_origin;
  9589. var P3 = ac_origin.clone().add(ac_dir);
  9590. var center = Utils.lineToLineIntersection(P0, P1, P2, P3);
  9591. return center;
  9592. // Potree.Utils.debugLine(viewer.scene.scene, P0, P1, 0x00ff00);
  9593. // Potree.Utils.debugLine(viewer.scene.scene, P2, P3, 0x0000ff);
  9594. // Potree.Utils.debugSphere(viewer.scene.scene, center, 0.03, 0xff00ff);
  9595. // const radius = center.distanceTo(A);
  9596. // Potree.Utils.debugCircle(viewer.scene.scene, center, radius, new THREE.Vector3(0, 0, 1), 0xff00ff);
  9597. }
  9598. static getNorthVec(p1, distance, projection) {
  9599. if (projection) {
  9600. // if there is a projection, transform coordinates to WGS84
  9601. // and compute angle to north there
  9602. proj4.defs("pointcloud", projection);
  9603. var transform = proj4("pointcloud", "WGS84");
  9604. var llP1 = transform.forward(p1.toArray());
  9605. var llP2 = transform.forward([p1.x, p1.y + distance]);
  9606. var polarRadius = Math.sqrt((llP2[0] - llP1[0]) ** 2 + (llP2[1] - llP1[1]) ** 2);
  9607. llP2 = [llP1[0], llP1[1] + polarRadius];
  9608. var northVec = transform.inverse(llP2);
  9609. return new Vector3(...northVec, p1.z).sub(p1);
  9610. } else {
  9611. // if there is no projection, assume [0, 1, 0] as north direction
  9612. var vec = new Vector3(0, 1, 0).multiplyScalar(distance);
  9613. return vec;
  9614. }
  9615. }
  9616. static computeAzimuth(p1, p2, projection) {
  9617. var azimuth = 0;
  9618. if (projection) {
  9619. // if there is a projection, transform coordinates to WGS84
  9620. // and compute angle to north there
  9621. var transform;
  9622. if (projection.includes('EPSG')) {
  9623. transform = proj4(projection, "WGS84");
  9624. } else {
  9625. proj4.defs("pointcloud", projection);
  9626. transform = proj4("pointcloud", "WGS84");
  9627. }
  9628. var llP1 = transform.forward(p1.toArray());
  9629. var llP2 = transform.forward(p2.toArray());
  9630. var dir = [llP2[0] - llP1[0], llP2[1] - llP1[1]];
  9631. azimuth = Math.atan2(dir[1], dir[0]) - Math.PI / 2;
  9632. } else {
  9633. // if there is no projection, assume [0, 1, 0] as north direction
  9634. var _dir = [p2.x - p1.x, p2.y - p1.y];
  9635. azimuth = Math.atan2(_dir[1], _dir[0]) - Math.PI / 2;
  9636. }
  9637. // make clockwise
  9638. azimuth = -azimuth;
  9639. return azimuth;
  9640. }
  9641. static async loadScript(url) {
  9642. return new Promise(resolve => {
  9643. var element = document.getElementById(url);
  9644. if (element) {
  9645. resolve();
  9646. } else {
  9647. var script = document.createElement("script");
  9648. script.id = url;
  9649. script.onload = () => {
  9650. resolve();
  9651. };
  9652. script.src = url;
  9653. document.body.appendChild(script);
  9654. }
  9655. });
  9656. }
  9657. static createSvgGradient(scheme) {
  9658. // this is what we are creating:
  9659. //
  9660. //<svg width="1em" height="3em" xmlns="http://www.w3.org/2000/svg">
  9661. // <defs>
  9662. // <linearGradient id="gradientID" gradientTransform="rotate(90)">
  9663. // <stop offset="0%" stop-color="rgb(93, 78, 162)" />
  9664. // ...
  9665. // <stop offset="100%" stop-color="rgb(157, 0, 65)" />
  9666. // </linearGradient>
  9667. // </defs>
  9668. //
  9669. // <rect width="100%" height="100%" fill="url('#myGradient')" stroke="black" stroke-width="0.1em"/>
  9670. //</svg>
  9671. var gradientId = "".concat(Math.random(), "_").concat(Date.now());
  9672. var svgn = "http://www.w3.org/2000/svg";
  9673. var svg = document.createElementNS(svgn, "svg");
  9674. svg.setAttributeNS(null, "width", "2em");
  9675. svg.setAttributeNS(null, "height", "3em");
  9676. {
  9677. // <defs>
  9678. var defs = document.createElementNS(svgn, "defs");
  9679. var linearGradient = document.createElementNS(svgn, "linearGradient");
  9680. linearGradient.setAttributeNS(null, "id", gradientId);
  9681. linearGradient.setAttributeNS(null, "gradientTransform", "rotate(90)");
  9682. for (var i = scheme.length - 1; i >= 0; i--) {
  9683. var stopVal = scheme[i];
  9684. var percent = parseInt(100 - stopVal[0] * 100);
  9685. var [r, g, b] = stopVal[1].toArray().map(v => parseInt(v * 255));
  9686. var stop = document.createElementNS(svgn, "stop");
  9687. stop.setAttributeNS(null, "offset", "".concat(percent, "%"));
  9688. stop.setAttributeNS(null, "stop-color", "rgb(".concat(r, ", ").concat(g, ", ").concat(b, ")"));
  9689. linearGradient.appendChild(stop);
  9690. }
  9691. defs.appendChild(linearGradient);
  9692. svg.appendChild(defs);
  9693. }
  9694. var rect = document.createElementNS(svgn, "rect");
  9695. rect.setAttributeNS(null, "width", "100%");
  9696. rect.setAttributeNS(null, "height", "100%");
  9697. rect.setAttributeNS(null, "fill", "url(\"#".concat(gradientId, "\")"));
  9698. rect.setAttributeNS(null, "stroke", "black");
  9699. rect.setAttributeNS(null, "stroke-width", "0.1em");
  9700. svg.appendChild(rect);
  9701. return svg;
  9702. }
  9703. static async waitAny(promises) {
  9704. return new Promise(resolve => {
  9705. promises.map(promise => {
  9706. promise.then(() => {
  9707. resolve();
  9708. });
  9709. });
  9710. });
  9711. }
  9712. }
  9713. Utils.screenPass = new function () {
  9714. this.screenScene = new Scene();
  9715. this.screenQuad = new Mesh(new PlaneBufferGeometry(2, 2, 1));
  9716. this.screenQuad.material.depthTest = true;
  9717. this.screenQuad.material.depthWrite = true;
  9718. this.screenQuad.material.transparent = true;
  9719. this.screenScene.add(this.screenQuad);
  9720. this.camera = new Camera();
  9721. this.render = function (renderer, material, target) {
  9722. this.screenQuad.material = material;
  9723. if (typeof target === 'undefined') {
  9724. renderer.render(this.screenScene, this.camera);
  9725. } else {
  9726. renderer.render(this.screenScene, this.camera, target);
  9727. }
  9728. };
  9729. }();
  9730. class Version {
  9731. constructor(version) {
  9732. this.version = version;
  9733. var vmLength = version.indexOf('.') === -1 ? version.length : version.indexOf('.');
  9734. this.versionMajor = parseInt(version.substr(0, vmLength));
  9735. this.versionMinor = parseInt(version.substr(vmLength + 1));
  9736. if (this.versionMinor.length === 0) {
  9737. this.versionMinor = 0;
  9738. }
  9739. }
  9740. newerThan(version) {
  9741. var v = new Version(version);
  9742. if (this.versionMajor > v.versionMajor) {
  9743. return true;
  9744. } else if (this.versionMajor === v.versionMajor && this.versionMinor > v.versionMinor) {
  9745. return true;
  9746. } else {
  9747. return false;
  9748. }
  9749. }
  9750. equalOrHigher(version) {
  9751. var v = new Version(version);
  9752. if (this.versionMajor > v.versionMajor) {
  9753. return true;
  9754. } else if (this.versionMajor === v.versionMajor && this.versionMinor >= v.versionMinor) {
  9755. return true;
  9756. } else {
  9757. return false;
  9758. }
  9759. }
  9760. upTo(version) {
  9761. return !this.newerThan(version);
  9762. }
  9763. }
  9764. //加载 解析点云
  9765. class BinaryLoader {
  9766. constructor(version, boundingBox, scale) {
  9767. if (typeof version === 'string') {
  9768. this.version = new Version(version);
  9769. } else {
  9770. this.version = version;
  9771. }
  9772. this.boundingBox = boundingBox;
  9773. this.scale = scale;
  9774. }
  9775. load(node) {
  9776. if (node.loaded) {
  9777. return;
  9778. }
  9779. var url = node.getURL();
  9780. if (this.version.equalOrHigher('1.4')) {
  9781. url += '.bin';
  9782. }
  9783. var xhr = XHRFactory.createXMLHttpRequest();
  9784. xhr.open('GET', url, true);
  9785. xhr.responseType = 'arraybuffer';
  9786. xhr.overrideMimeType('text/plain; charset=x-user-defined');
  9787. xhr.onreadystatechange = () => {
  9788. if (xhr.readyState === 4) {
  9789. if ((xhr.status === 200 || xhr.status === 0) && xhr.response !== null) {
  9790. var buffer = xhr.response;
  9791. this.parse(node, buffer);
  9792. } else {
  9793. //console.error(`Failed to load file! HTTP status: ${xhr.status}, file: ${url}`);
  9794. throw new Error("Failed to load file! HTTP status: ".concat(xhr.status, ", file: ").concat(url));
  9795. }
  9796. }
  9797. };
  9798. try {
  9799. xhr.send(null);
  9800. } catch (e) {
  9801. console.log('fehler beim laden der punktwolke: ' + e);
  9802. }
  9803. }
  9804. parse(node, buffer, callback) {
  9805. var pointAttributes = node.pcoGeometry.pointAttributes;
  9806. var numPoints = buffer.byteLength / node.pcoGeometry.pointAttributes.byteSize;
  9807. if (this.version.upTo('1.5')) {
  9808. node.numPoints = numPoints;
  9809. }
  9810. var workerPath = Potree.scriptPath + '/workers/BinaryDecoderWorker.js';
  9811. var worker = Potree.workerPool.getWorker(workerPath);
  9812. worker.onmessage = function (e) {
  9813. var data = e.data;
  9814. var buffers = data.attributeBuffers;
  9815. var tightBoundingBox = new Box3(new Vector3().fromArray(data.tightBoundingBox.min), new Vector3().fromArray(data.tightBoundingBox.max));
  9816. Potree.workerPool.returnWorker(workerPath, worker);
  9817. var geometry = new BufferGeometry();
  9818. var _loop = function _loop() {
  9819. var buffer = buffers[property].buffer;
  9820. var batchAttribute = buffers[property].attribute;
  9821. if (property === "POSITION_CARTESIAN") {
  9822. geometry.setAttribute('position', new BufferAttribute(new Float32Array(buffer), 3));
  9823. } else if (property === "rgba") {
  9824. geometry.setAttribute("rgba", new BufferAttribute(new Uint8Array(buffer), 4, true));
  9825. } else if (property === "NORMAL_SPHEREMAPPED") {
  9826. geometry.setAttribute('normal', new BufferAttribute(new Float32Array(buffer), 3));
  9827. } else if (property === "NORMAL_OCT16") {
  9828. geometry.setAttribute('normal', new BufferAttribute(new Float32Array(buffer), 3));
  9829. } else if (property === "NORMAL") {
  9830. geometry.setAttribute('normal', new BufferAttribute(new Float32Array(buffer), 3));
  9831. } else if (property === "INDICES") {
  9832. var bufferAttribute = new BufferAttribute(new Uint8Array(buffer), 4);
  9833. bufferAttribute.normalized = true;
  9834. geometry.setAttribute('indices', bufferAttribute);
  9835. } else if (property === "SPACING") {
  9836. var _bufferAttribute = new BufferAttribute(new Float32Array(buffer), 1);
  9837. geometry.setAttribute('spacing', _bufferAttribute);
  9838. } else {
  9839. var _bufferAttribute2 = new BufferAttribute(new Float32Array(buffer), 1);
  9840. _bufferAttribute2.potree = {
  9841. offset: buffers[property].offset,
  9842. scale: buffers[property].scale,
  9843. preciseBuffer: buffers[property].preciseBuffer,
  9844. range: batchAttribute.range
  9845. };
  9846. geometry.setAttribute(property, _bufferAttribute2);
  9847. var attribute = pointAttributes.attributes.find(a => a.name === batchAttribute.name);
  9848. attribute.range[0] = Math.min(attribute.range[0], batchAttribute.range[0]);
  9849. attribute.range[1] = Math.max(attribute.range[1], batchAttribute.range[1]);
  9850. if (node.getLevel() === 0) {
  9851. attribute.initialRange = batchAttribute.range;
  9852. }
  9853. }
  9854. };
  9855. for (var property in buffers) {
  9856. _loop();
  9857. }
  9858. tightBoundingBox.max.sub(tightBoundingBox.min);
  9859. tightBoundingBox.min.set(0, 0, 0);
  9860. var numPoints = e.data.buffer.byteLength / pointAttributes.byteSize;
  9861. node.numPoints = numPoints;
  9862. node.geometry = geometry;
  9863. node.mean = new Vector3(...data.mean);
  9864. node.tightBoundingBox = tightBoundingBox;
  9865. node.loaded = true;
  9866. node.loading = false;
  9867. node.estimatedSpacing = data.estimatedSpacing;
  9868. Potree.numNodesLoading--;
  9869. callback(); //add
  9870. };
  9871. var message = {
  9872. buffer: buffer,
  9873. pointAttributes: pointAttributes,
  9874. version: this.version.version,
  9875. min: [node.boundingBox.min.x, node.boundingBox.min.y, node.boundingBox.min.z],
  9876. offset: [node.pcoGeometry.offset.x, node.pcoGeometry.offset.y, node.pcoGeometry.offset.z],
  9877. scale: this.scale,
  9878. spacing: node.spacing,
  9879. hasChildren: node.hasChildren,
  9880. name: node.name
  9881. };
  9882. worker.postMessage(message, [message.buffer]);
  9883. }
  9884. }
  9885. var ftCanvas = document.createElement('canvas');
  9886. var Features = function () {
  9887. var gl = ftCanvas.getContext('webgl') || ftCanvas.getContext('experimental-webgl');
  9888. if (gl === null) {
  9889. return {};
  9890. }
  9891. // -- code taken from THREE.WebGLRenderer --
  9892. var _vertexShaderPrecisionHighpFloat = gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.HIGH_FLOAT);
  9893. var _vertexShaderPrecisionMediumpFloat = gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.MEDIUM_FLOAT);
  9894. // Unused: let _vertexShaderPrecisionLowpFloat = gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.LOW_FLOAT);
  9895. var _fragmentShaderPrecisionHighpFloat = gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.HIGH_FLOAT);
  9896. var _fragmentShaderPrecisionMediumpFloat = gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT);
  9897. // Unused: let _fragmentShaderPrecisionLowpFloat = gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.LOW_FLOAT);
  9898. var highpAvailable = _vertexShaderPrecisionHighpFloat.precision > 0 && _fragmentShaderPrecisionHighpFloat.precision > 0;
  9899. var mediumpAvailable = _vertexShaderPrecisionMediumpFloat.precision > 0 && _fragmentShaderPrecisionMediumpFloat.precision > 0;
  9900. // -----------------------------------------
  9901. var precision;
  9902. if (highpAvailable) {
  9903. precision = 'highp';
  9904. } else if (mediumpAvailable) {
  9905. precision = 'mediump';
  9906. } else {
  9907. precision = 'lowp';
  9908. }
  9909. return {
  9910. SHADER_INTERPOLATION: {
  9911. isSupported: function isSupported() {
  9912. var supported = true;
  9913. supported = supported && gl.getExtension('EXT_frag_depth');
  9914. supported = supported && gl.getParameter(gl.MAX_VARYING_VECTORS) >= 8;
  9915. return supported;
  9916. }
  9917. },
  9918. SHADER_SPLATS: {
  9919. isSupported: function isSupported() {
  9920. var supported = true;
  9921. supported = supported && gl.getExtension('EXT_frag_depth');
  9922. supported = supported && gl.getExtension('OES_texture_float');
  9923. supported = supported && gl.getParameter(gl.MAX_VARYING_VECTORS) >= 8;
  9924. return supported;
  9925. }
  9926. },
  9927. SHADER_EDL: {
  9928. isSupported: function isSupported() {
  9929. var supported = true;
  9930. supported = supported && gl.getExtension('EXT_frag_depth');
  9931. supported = supported && gl.getExtension('OES_texture_float');
  9932. supported = supported && gl.getParameter(gl.MAX_VARYING_VECTORS) >= 8;
  9933. //supported = supported || (gl instanceof WebGL2RenderingContext);
  9934. return supported;
  9935. }
  9936. },
  9937. //WEBGL2: {
  9938. // isSupported: function(){
  9939. // return typeof WebGL2RenderingContext != 'undefined' && gl instanceof WebGL2RenderingContext;
  9940. // }
  9941. //},
  9942. precision: precision
  9943. };
  9944. }();
  9945. /**
  9946. * Some types of possible point attribute data formats
  9947. *
  9948. * @class
  9949. */
  9950. var PointAttributeTypes = {
  9951. DATA_TYPE_DOUBLE: {
  9952. ordinal: 0,
  9953. name: "double",
  9954. size: 8
  9955. },
  9956. DATA_TYPE_FLOAT: {
  9957. ordinal: 1,
  9958. name: "float",
  9959. size: 4
  9960. },
  9961. DATA_TYPE_INT8: {
  9962. ordinal: 2,
  9963. name: "int8",
  9964. size: 1
  9965. },
  9966. DATA_TYPE_UINT8: {
  9967. ordinal: 3,
  9968. name: "uint8",
  9969. size: 1
  9970. },
  9971. DATA_TYPE_INT16: {
  9972. ordinal: 4,
  9973. name: "int16",
  9974. size: 2
  9975. },
  9976. DATA_TYPE_UINT16: {
  9977. ordinal: 5,
  9978. name: "uint16",
  9979. size: 2
  9980. },
  9981. DATA_TYPE_INT32: {
  9982. ordinal: 6,
  9983. name: "int32",
  9984. size: 4
  9985. },
  9986. DATA_TYPE_UINT32: {
  9987. ordinal: 7,
  9988. name: "uint32",
  9989. size: 4
  9990. },
  9991. DATA_TYPE_INT64: {
  9992. ordinal: 8,
  9993. name: "int64",
  9994. size: 8
  9995. },
  9996. DATA_TYPE_UINT64: {
  9997. ordinal: 9,
  9998. name: "uint64",
  9999. size: 8
  10000. }
  10001. };
  10002. var i$1 = 0;
  10003. for (var obj in PointAttributeTypes) {
  10004. PointAttributeTypes[i$1] = PointAttributeTypes[obj];
  10005. i$1++;
  10006. }
  10007. class PointAttribute {
  10008. constructor(name, type, numElements) {
  10009. this.name = name;
  10010. this.type = type;
  10011. this.numElements = numElements;
  10012. this.byteSize = this.numElements * this.type.size;
  10013. this.description = "";
  10014. this.range = [Infinity, -Infinity];
  10015. }
  10016. }
  10017. ;
  10018. PointAttribute.POSITION_CARTESIAN = new PointAttribute("POSITION_CARTESIAN", PointAttributeTypes.DATA_TYPE_FLOAT, 3);
  10019. PointAttribute.RGBA_PACKED = new PointAttribute("COLOR_PACKED", PointAttributeTypes.DATA_TYPE_INT8, 4);
  10020. PointAttribute.COLOR_PACKED = PointAttribute.RGBA_PACKED;
  10021. PointAttribute.RGB_PACKED = new PointAttribute("COLOR_PACKED", PointAttributeTypes.DATA_TYPE_INT8, 3);
  10022. PointAttribute.NORMAL_FLOATS = new PointAttribute("NORMAL_FLOATS", PointAttributeTypes.DATA_TYPE_FLOAT, 3);
  10023. PointAttribute.INTENSITY = new PointAttribute("INTENSITY", PointAttributeTypes.DATA_TYPE_UINT16, 1);
  10024. PointAttribute.CLASSIFICATION = new PointAttribute("CLASSIFICATION", PointAttributeTypes.DATA_TYPE_UINT8, 1);
  10025. PointAttribute.NORMAL_SPHEREMAPPED = new PointAttribute("NORMAL_SPHEREMAPPED", PointAttributeTypes.DATA_TYPE_UINT8, 2);
  10026. PointAttribute.NORMAL_OCT16 = new PointAttribute("NORMAL_OCT16", PointAttributeTypes.DATA_TYPE_UINT8, 2);
  10027. PointAttribute.NORMAL = new PointAttribute("NORMAL", PointAttributeTypes.DATA_TYPE_FLOAT, 3);
  10028. PointAttribute.RETURN_NUMBER = new PointAttribute("RETURN_NUMBER", PointAttributeTypes.DATA_TYPE_UINT8, 1);
  10029. PointAttribute.NUMBER_OF_RETURNS = new PointAttribute("NUMBER_OF_RETURNS", PointAttributeTypes.DATA_TYPE_UINT8, 1);
  10030. PointAttribute.SOURCE_ID = new PointAttribute("SOURCE_ID", PointAttributeTypes.DATA_TYPE_UINT16, 1);
  10031. PointAttribute.INDICES = new PointAttribute("INDICES", PointAttributeTypes.DATA_TYPE_UINT32, 1);
  10032. PointAttribute.SPACING = new PointAttribute("SPACING", PointAttributeTypes.DATA_TYPE_FLOAT, 1);
  10033. PointAttribute.GPS_TIME = new PointAttribute("GPS_TIME", PointAttributeTypes.DATA_TYPE_DOUBLE, 1);
  10034. class PointAttributes {
  10035. constructor(pointAttributes) {
  10036. this.attributes = [];
  10037. this.byteSize = 0;
  10038. this.size = 0;
  10039. this.vectors = [];
  10040. if (pointAttributes != null) {
  10041. for (var _i = 0; _i < pointAttributes.length; _i++) {
  10042. var pointAttributeName = pointAttributes[_i];
  10043. var pointAttribute = PointAttribute[pointAttributeName];
  10044. this.attributes.push(pointAttribute);
  10045. this.byteSize += pointAttribute.byteSize;
  10046. this.size++;
  10047. }
  10048. }
  10049. }
  10050. add(pointAttribute) {
  10051. this.attributes.push(pointAttribute);
  10052. this.byteSize += pointAttribute.byteSize;
  10053. this.size++;
  10054. }
  10055. addVector(vector) {
  10056. this.vectors.push(vector);
  10057. }
  10058. hasNormals() {
  10059. for (var name in this.attributes) {
  10060. var pointAttribute = this.attributes[name];
  10061. if (pointAttribute === PointAttribute.NORMAL_SPHEREMAPPED || pointAttribute === PointAttribute.NORMAL_FLOATS || pointAttribute === PointAttribute.NORMAL || pointAttribute === PointAttribute.NORMAL_OCT16) {
  10062. return true;
  10063. }
  10064. }
  10065. return false;
  10066. }
  10067. }
  10068. class Points$1 {
  10069. constructor() {
  10070. this.boundingBox = new Box3();
  10071. this.numPoints = 0;
  10072. this.data = {};
  10073. }
  10074. add(points) {
  10075. var currentSize = this.numPoints;
  10076. var additionalSize = points.numPoints;
  10077. var newSize = currentSize + additionalSize;
  10078. var thisAttributes = Object.keys(this.data);
  10079. var otherAttributes = Object.keys(points.data);
  10080. var attributes = new Set([...thisAttributes, ...otherAttributes]);
  10081. for (var attribute of attributes) {
  10082. if (thisAttributes.includes(attribute) && otherAttributes.includes(attribute)) {
  10083. // attribute in both, merge
  10084. var Type = this.data[attribute].constructor;
  10085. var merged = new Type(this.data[attribute].length + points.data[attribute].length);
  10086. merged.set(this.data[attribute], 0);
  10087. merged.set(points.data[attribute], this.data[attribute].length);
  10088. this.data[attribute] = merged;
  10089. } else if (thisAttributes.includes(attribute) && !otherAttributes.includes(attribute)) {
  10090. // attribute only in this; take over this and expand to new size
  10091. var elementsPerPoint = this.data[attribute].length / this.numPoints;
  10092. var _Type = this.data[attribute].constructor;
  10093. var expanded = new _Type(elementsPerPoint * newSize);
  10094. expanded.set(this.data[attribute], 0);
  10095. this.data[attribute] = expanded;
  10096. } else if (!thisAttributes.includes(attribute) && otherAttributes.includes(attribute)) {
  10097. // attribute only in points to be added; take over new points and expand to new size
  10098. var _elementsPerPoint = points.data[attribute].length / points.numPoints;
  10099. var _Type2 = points.data[attribute].constructor;
  10100. var _expanded = new _Type2(_elementsPerPoint * newSize);
  10101. _expanded.set(points.data[attribute], _elementsPerPoint * currentSize);
  10102. this.data[attribute] = _expanded;
  10103. }
  10104. }
  10105. this.numPoints = newSize;
  10106. this.boundingBox.union(points.boundingBox);
  10107. }
  10108. }
  10109. class CSVExporter {
  10110. static toString(points) {
  10111. var string = '';
  10112. var attributes = Object.keys(points.data).filter(a => a !== 'normal').sort((a, b) => {
  10113. if (a === 'position') return -1;
  10114. if (b === 'position') return 1;
  10115. if (a === 'rgba') return -1;
  10116. if (b === 'rgba') return 1;
  10117. });
  10118. var headerValues = [];
  10119. for (var attribute of attributes) {
  10120. var itemSize = points.data[attribute].length / points.numPoints;
  10121. if (attribute === 'position') {
  10122. headerValues = headerValues.concat(['x', 'y', 'z']);
  10123. } else if (attribute === 'rgba') {
  10124. headerValues = headerValues.concat(['r', 'g', 'b', 'a']);
  10125. } else if (itemSize > 1) {
  10126. for (var i = 0; i < itemSize; i++) {
  10127. headerValues.push("".concat(attribute, "_").concat(i));
  10128. }
  10129. } else {
  10130. headerValues.push(attribute);
  10131. }
  10132. }
  10133. string = headerValues.join(', ') + '\n';
  10134. for (var _i = 0; _i < points.numPoints; _i++) {
  10135. var values = [];
  10136. for (var _attribute of attributes) {
  10137. var _itemSize = points.data[_attribute].length / points.numPoints;
  10138. var value = points.data[_attribute].subarray(_itemSize * _i, _itemSize * _i + _itemSize).join(', ');
  10139. values.push(value);
  10140. }
  10141. string += values.join(', ') + '\n';
  10142. }
  10143. return string;
  10144. }
  10145. }
  10146. ;
  10147. class LASExporter {
  10148. static toLAS(points) {
  10149. // TODO Unused: let string = '';
  10150. var boundingBox = points.boundingBox;
  10151. var offset = boundingBox.min.clone();
  10152. var diagonal = boundingBox.min.distanceTo(boundingBox.max);
  10153. var scale = new Vector3(0.001, 0.001, 0.001);
  10154. if (diagonal > 1000 * 1000) {
  10155. scale = new Vector3(0.01, 0.01, 0.01);
  10156. } else {
  10157. scale = new Vector3(0.001, 0.001, 0.001);
  10158. }
  10159. var setString = function setString(string, offset, buffer) {
  10160. var view = new Uint8Array(buffer);
  10161. for (var i = 0; i < string.length; i++) {
  10162. var charCode = string.charCodeAt(i);
  10163. view[offset + i] = charCode;
  10164. }
  10165. };
  10166. var buffer = new ArrayBuffer(227 + 28 * points.numPoints);
  10167. var view = new DataView(buffer);
  10168. var u8View = new Uint8Array(buffer);
  10169. // let u16View = new Uint16Array(buffer);
  10170. setString('LASF', 0, buffer);
  10171. u8View[24] = 1;
  10172. u8View[25] = 2;
  10173. // system identifier o:26 l:32
  10174. // generating software o:58 l:32
  10175. setString('Potree 1.7', 58, buffer);
  10176. // file creation day of year o:90 l:2
  10177. // file creation year o:92 l:2
  10178. // header size o:94 l:2
  10179. view.setUint16(94, 227, true);
  10180. // offset to point data o:96 l:4
  10181. view.setUint32(96, 227, true);
  10182. // number of letiable length records o:100 l:4
  10183. // point data record format 104 1
  10184. u8View[104] = 2;
  10185. // point data record length 105 2
  10186. view.setUint16(105, 28, true);
  10187. // number of point records 107 4
  10188. view.setUint32(107, points.numPoints, true);
  10189. // number of points by return 111 20
  10190. // x scale factor 131 8
  10191. view.setFloat64(131, scale.x, true);
  10192. // y scale factor 139 8
  10193. view.setFloat64(139, scale.y, true);
  10194. // z scale factor 147 8
  10195. view.setFloat64(147, scale.z, true);
  10196. // x offset 155 8
  10197. view.setFloat64(155, offset.x, true);
  10198. // y offset 163 8
  10199. view.setFloat64(163, offset.y, true);
  10200. // z offset 171 8
  10201. view.setFloat64(171, offset.z, true);
  10202. // max x 179 8
  10203. view.setFloat64(179, boundingBox.max.x, true);
  10204. // min x 187 8
  10205. view.setFloat64(187, boundingBox.min.x, true);
  10206. // max y 195 8
  10207. view.setFloat64(195, boundingBox.max.y, true);
  10208. // min y 203 8
  10209. view.setFloat64(203, boundingBox.min.y, true);
  10210. // max z 211 8
  10211. view.setFloat64(211, boundingBox.max.z, true);
  10212. // min z 219 8
  10213. view.setFloat64(219, boundingBox.min.z, true);
  10214. var boffset = 227;
  10215. for (var i = 0; i < points.numPoints; i++) {
  10216. var px = points.data.position[3 * i + 0];
  10217. var py = points.data.position[3 * i + 1];
  10218. var pz = points.data.position[3 * i + 2];
  10219. var ux = parseInt((px - offset.x) / scale.x);
  10220. var uy = parseInt((py - offset.y) / scale.y);
  10221. var uz = parseInt((pz - offset.z) / scale.z);
  10222. view.setUint32(boffset + 0, ux, true);
  10223. view.setUint32(boffset + 4, uy, true);
  10224. view.setUint32(boffset + 8, uz, true);
  10225. if (points.data.intensity) {
  10226. view.setUint16(boffset + 12, points.data.intensity[i], true);
  10227. }
  10228. var rt = 0;
  10229. if (points.data.returnNumber) {
  10230. rt += points.data.returnNumber[i];
  10231. }
  10232. if (points.data.numberOfReturns) {
  10233. rt += points.data.numberOfReturns[i] << 3;
  10234. }
  10235. view.setUint8(boffset + 14, rt);
  10236. if (points.data.classification) {
  10237. view.setUint8(boffset + 15, points.data.classification[i]);
  10238. }
  10239. // scan angle rank
  10240. // user data
  10241. // point source id
  10242. if (points.data.pointSourceID) {
  10243. view.setUint16(boffset + 18, points.data.pointSourceID[i]);
  10244. }
  10245. if (points.data.rgba) {
  10246. var rgba = points.data.rgba;
  10247. view.setUint16(boffset + 20, rgba[4 * i + 0] * 255, true);
  10248. view.setUint16(boffset + 22, rgba[4 * i + 1] * 255, true);
  10249. view.setUint16(boffset + 24, rgba[4 * i + 2] * 255, true);
  10250. }
  10251. boffset += 28;
  10252. }
  10253. return buffer;
  10254. }
  10255. }
  10256. /**
  10257. * @author mrdoob / http://mrdoob.com/ https://github.com/mrdoob/eventdispatcher.js
  10258. *
  10259. * with slight modifications by mschuetz, http://potree.org
  10260. *
  10261. */
  10262. // The MIT License
  10263. //
  10264. // Copyright (c) 2011 Mr.doob
  10265. //
  10266. // Permission is hereby granted, free of charge, to any person obtaining a copy
  10267. // of this software and associated documentation files (the "Software"), to deal
  10268. // in the Software without restriction, including without limitation the rights
  10269. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10270. // copies of the Software, and to permit persons to whom the Software is
  10271. // furnished to do so, subject to the following conditions:
  10272. //
  10273. // The above copyright notice and this permission notice shall be included in
  10274. // all copies or substantial portions of the Software.
  10275. //
  10276. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  10277. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  10278. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  10279. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  10280. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  10281. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  10282. // THE SOFTWARE.
  10283. class EventDispatcher$1 {
  10284. constructor() {
  10285. this._listeners = {};
  10286. }
  10287. addEventListener(type, listener) {
  10288. var listeners = this._listeners;
  10289. if (listeners[type] === undefined) {
  10290. listeners[type] = [];
  10291. }
  10292. if (listeners[type].indexOf(listener) === -1) {
  10293. listeners[type].push(listener);
  10294. }
  10295. }
  10296. hasEventListener(type, listener) {
  10297. var listeners = this._listeners;
  10298. return listeners[type] !== undefined && listeners[type].indexOf(listener) !== -1;
  10299. }
  10300. removeEventListener(type, listener) {
  10301. var listeners = this._listeners;
  10302. var listenerArray = listeners[type];
  10303. if (listenerArray !== undefined) {
  10304. var index = listenerArray.indexOf(listener);
  10305. if (index !== -1) {
  10306. listenerArray.splice(index, 1);
  10307. }
  10308. }
  10309. }
  10310. removeEventListeners(type) {
  10311. if (this._listeners[type] !== undefined) {
  10312. delete this._listeners[type];
  10313. }
  10314. }
  10315. dispatchEvent(event) {
  10316. var listeners = this._listeners;
  10317. var listenerArray = listeners[event.type];
  10318. if (listenerArray !== undefined) {
  10319. event.target = this;
  10320. for (var listener of listenerArray.slice(0)) {
  10321. listener.call(this, event);
  10322. }
  10323. }
  10324. }
  10325. }
  10326. class PointCloudTreeNode extends EventDispatcher$1 {
  10327. constructor() {
  10328. super();
  10329. this.needsTransformUpdate = true;
  10330. }
  10331. getChildren() {
  10332. throw new Error('override function');
  10333. }
  10334. getBoundingBox() {
  10335. throw new Error('override function');
  10336. }
  10337. isLoaded() {
  10338. throw new Error('override function');
  10339. }
  10340. isGeometryNode() {
  10341. throw new Error('override function');
  10342. }
  10343. isTreeNode() {
  10344. throw new Error('override function');
  10345. }
  10346. getLevel() {
  10347. throw new Error('override function');
  10348. }
  10349. getBoundingSphere() {
  10350. throw new Error('override function');
  10351. }
  10352. }
  10353. ;
  10354. class PointCloudTree extends Object3D {
  10355. constructor() {
  10356. super();
  10357. //this.spriteGroup = new THREE.Object3D //add
  10358. }
  10359. initialized() {
  10360. return this.root !== null;
  10361. }
  10362. }
  10363. ;
  10364. class PointCloudOctreeGeometry {
  10365. constructor() {
  10366. this.url = null;
  10367. this.octreeDir = null;
  10368. this.spacing = 0;
  10369. this.boundingBox = null;
  10370. this.root = null;
  10371. this.nodes = null;
  10372. this.pointAttributes = null;
  10373. this.hierarchyStepSize = -1;
  10374. this.loader = null;
  10375. }
  10376. }
  10377. class PointCloudOctreeGeometryNode extends PointCloudTreeNode {
  10378. constructor(name, pcoGeometry, boundingBox) {
  10379. super();
  10380. this.id = PointCloudOctreeGeometryNode.IDCount++;
  10381. this.name = name;
  10382. this.index = parseInt(name.charAt(name.length - 1));
  10383. this.pcoGeometry = pcoGeometry;
  10384. this.geometry = null;
  10385. this.boundingBox = boundingBox;
  10386. this.boundingSphere = boundingBox.getBoundingSphere(new Sphere());
  10387. this.children = {};
  10388. this.numPoints = 0;
  10389. this.level = null;
  10390. this.loaded = false;
  10391. this.oneTimeDisposeHandlers = [];
  10392. }
  10393. isGeometryNode() {
  10394. return true;
  10395. }
  10396. getLevel() {
  10397. return this.level;
  10398. }
  10399. isTreeNode() {
  10400. return false;
  10401. }
  10402. isLoaded() {
  10403. return this.loaded;
  10404. }
  10405. getBoundingSphere() {
  10406. return this.boundingSphere;
  10407. }
  10408. getBoundingBox() {
  10409. return this.boundingBox;
  10410. }
  10411. getChildren() {
  10412. var children = [];
  10413. for (var i = 0; i < 8; i++) {
  10414. if (this.children[i]) {
  10415. children.push(this.children[i]);
  10416. }
  10417. }
  10418. return children;
  10419. }
  10420. getBoundingBox() {
  10421. return this.boundingBox;
  10422. }
  10423. getURL() {
  10424. var url = '';
  10425. var version = this.pcoGeometry.loader.version;
  10426. if (version.equalOrHigher('1.5')) {
  10427. url = this.pcoGeometry.octreeDir + '/' + this.getHierarchyPath() + '/' + this.name;
  10428. } else if (version.equalOrHigher('1.4')) {
  10429. url = this.pcoGeometry.octreeDir + '/' + this.name;
  10430. } else if (version.upTo('1.3')) {
  10431. url = this.pcoGeometry.octreeDir + '/' + this.name;
  10432. }
  10433. return url;
  10434. }
  10435. getHierarchyPath() {
  10436. var path = 'r/';
  10437. var hierarchyStepSize = this.pcoGeometry.hierarchyStepSize;
  10438. var indices = this.name.substr(1);
  10439. var numParts = Math.floor(indices.length / hierarchyStepSize);
  10440. for (var i = 0; i < numParts; i++) {
  10441. path += indices.substr(i * hierarchyStepSize, hierarchyStepSize) + '/';
  10442. }
  10443. path = path.slice(0, -1);
  10444. return path;
  10445. }
  10446. addChild(child) {
  10447. this.children[child.index] = child;
  10448. child.parent = this;
  10449. }
  10450. load() {
  10451. if (this.loading === true || this.loaded === true || Potree.numNodesLoading >= Potree.maxNodesLoading) {
  10452. return;
  10453. }
  10454. this.loading = true;
  10455. Potree.numNodesLoading++;
  10456. if (this.pcoGeometry.loader.version.equalOrHigher('1.5')) {
  10457. if (this.level % this.pcoGeometry.hierarchyStepSize === 0 && this.hasChildren) {
  10458. this.loadHierachyThenPoints();
  10459. } else {
  10460. this.loadPoints();
  10461. }
  10462. } else {
  10463. this.pcoGeometry.dispatchEvent({
  10464. type: 'updateNodeMaxLevel',
  10465. level: this.level
  10466. }); //add
  10467. this.loadPoints();
  10468. }
  10469. }
  10470. loadPoints() {
  10471. this.pcoGeometry.loader.load(this);
  10472. }
  10473. loadHierachyThenPoints() {
  10474. var node = this;
  10475. // load hierarchy
  10476. var callback = function callback(node, hbuffer) {
  10477. var tStart = performance.now();
  10478. var view = new DataView(hbuffer);
  10479. var stack = [];
  10480. var children = view.getUint8(0);
  10481. var numPoints = view.getUint32(1, true);
  10482. node.numPoints = numPoints;
  10483. stack.push({
  10484. children: children,
  10485. numPoints: numPoints,
  10486. name: node.name
  10487. });
  10488. var decoded = [];
  10489. var offset = 5;
  10490. while (stack.length > 0) {
  10491. var snode = stack.shift();
  10492. var mask = 1;
  10493. for (var i = 0; i < 8; i++) {
  10494. if ((snode.children & mask) !== 0) {
  10495. var childName = snode.name + i;
  10496. var childChildren = view.getUint8(offset);
  10497. var childNumPoints = view.getUint32(offset + 1, true);
  10498. stack.push({
  10499. children: childChildren,
  10500. numPoints: childNumPoints,
  10501. name: childName
  10502. });
  10503. decoded.push({
  10504. children: childChildren,
  10505. numPoints: childNumPoints,
  10506. name: childName
  10507. });
  10508. offset += 5;
  10509. }
  10510. mask = mask * 2;
  10511. }
  10512. if (offset === hbuffer.byteLength) {
  10513. break;
  10514. }
  10515. }
  10516. // console.log(decoded);
  10517. var nodes = {};
  10518. nodes[node.name] = node;
  10519. var pco = node.pcoGeometry;
  10520. for (var _i = 0; _i < decoded.length; _i++) {
  10521. var name = decoded[_i].name;
  10522. var decodedNumPoints = decoded[_i].numPoints;
  10523. var index = parseInt(name.charAt(name.length - 1));
  10524. var parentName = name.substring(0, name.length - 1);
  10525. var parentNode = nodes[parentName];
  10526. var level = name.length - 1;
  10527. var boundingBox = Utils.createChildAABB(parentNode.boundingBox, index);
  10528. var currentNode = new PointCloudOctreeGeometryNode(name, pco, boundingBox);
  10529. currentNode.level = level;
  10530. currentNode.numPoints = decodedNumPoints;
  10531. currentNode.hasChildren = decoded[_i].children > 0;
  10532. currentNode.spacing = pco.spacing / Math.pow(2, level);
  10533. parentNode.addChild(currentNode);
  10534. nodes[name] = currentNode;
  10535. }
  10536. var duration = performance.now() - tStart;
  10537. if (duration > 5) {
  10538. var msg = "duration: ".concat(duration, "ms, numNodes: ").concat(decoded.length);
  10539. console.log(msg);
  10540. }
  10541. node.loadPoints();
  10542. };
  10543. if (node.level % node.pcoGeometry.hierarchyStepSize === 0) {
  10544. // let hurl = node.pcoGeometry.octreeDir + "/../hierarchy/" + node.name + ".hrc";
  10545. var hurl = node.pcoGeometry.octreeDir + '/' + node.getHierarchyPath() + '/' + node.name + '.hrc';
  10546. var xhr = XHRFactory.createXMLHttpRequest();
  10547. xhr.open('GET', hurl, true);
  10548. xhr.responseType = 'arraybuffer';
  10549. xhr.overrideMimeType('text/plain; charset=x-user-defined');
  10550. xhr.onreadystatechange = () => {
  10551. if (xhr.readyState === 4) {
  10552. if (xhr.status === 200 || xhr.status === 0) {
  10553. var hbuffer = xhr.response;
  10554. callback(node, hbuffer);
  10555. } else {
  10556. console.log('Failed to load file! HTTP status: ' + xhr.status + ', file: ' + hurl);
  10557. Potree.numNodesLoading--;
  10558. }
  10559. }
  10560. };
  10561. try {
  10562. xhr.send(null);
  10563. } catch (e) {
  10564. console.log('fehler beim laden der punktwolke: ' + e);
  10565. }
  10566. }
  10567. }
  10568. getNumPoints() {
  10569. return this.numPoints;
  10570. }
  10571. dispose() {
  10572. if (this.geometry && this.parent != null) {
  10573. this.geometry.dispose();
  10574. this.geometry = null;
  10575. this.loaded = false;
  10576. this.dispatchEvent({
  10577. type: 'dispose'
  10578. });
  10579. for (var i = 0; i < this.oneTimeDisposeHandlers.length; i++) {
  10580. var handler = this.oneTimeDisposeHandlers[i];
  10581. handler();
  10582. }
  10583. this.oneTimeDisposeHandlers = [];
  10584. }
  10585. }
  10586. }
  10587. PointCloudOctreeGeometryNode.IDCount = 0;
  10588. // -------------------------------------------
  10589. // to get a ready to use gradient array from a chroma.js gradient:
  10590. // http://gka.github.io/chroma.js/
  10591. // -------------------------------------------
  10592. //
  10593. // let stops = [];
  10594. // for(let i = 0; i <= 10; i++){
  10595. // let range = chroma.scale(['yellow', 'navy']).mode('lch').domain([10,0])(i)._rgb
  10596. // .slice(0, 3)
  10597. // .map(v => (v / 255).toFixed(4))
  10598. // .join(", ");
  10599. //
  10600. // let line = `[${i / 10}, new THREE.Color(${range})],`;
  10601. //
  10602. // stops.push(line);
  10603. // }
  10604. // stops.join("\n");
  10605. //
  10606. //
  10607. //
  10608. // -------------------------------------------
  10609. // to get a ready to use gradient array from matplotlib:
  10610. // -------------------------------------------
  10611. // import matplotlib.pyplot as plt
  10612. // import matplotlib.colors as colors
  10613. //
  10614. // norm = colors.Normalize(vmin=0,vmax=1)
  10615. // cmap = plt.cm.viridis
  10616. //
  10617. // for i in range(0,11):
  10618. // u = i / 10
  10619. // rgb = cmap(norm(u))[0:3]
  10620. // rgb = ["{0:.3f}".format(v) for v in rgb]
  10621. // rgb = "[" + str(u) + ", new THREE.Color(" + ", ".join(rgb) + ")],"
  10622. // print(rgb)
  10623. var Gradients = {
  10624. // From chroma spectral http://gka.github.io/chroma.js/
  10625. SPECTRAL: [[0, new Color(0.3686, 0.3098, 0.6353)], [0.1, new Color(0.1961, 0.5333, 0.7412)], [0.2, new Color(0.4000, 0.7608, 0.6471)], [0.3, new Color(0.6706, 0.8667, 0.6431)], [0.4, new Color(0.9020, 0.9608, 0.5961)], [0.5, new Color(1.0000, 1.0000, 0.7490)], [0.6, new Color(0.9961, 0.8784, 0.5451)], [0.7, new Color(0.9922, 0.6824, 0.3804)], [0.8, new Color(0.9569, 0.4275, 0.2627)], [0.9, new Color(0.8353, 0.2431, 0.3098)], [1, new Color(0.6196, 0.0039, 0.2588)]],
  10626. PLASMA: [[0.0, new Color(0.241, 0.015, 0.610)], [0.1, new Color(0.387, 0.001, 0.654)], [0.2, new Color(0.524, 0.025, 0.653)], [0.3, new Color(0.651, 0.125, 0.596)], [0.4, new Color(0.752, 0.227, 0.513)], [0.5, new Color(0.837, 0.329, 0.431)], [0.6, new Color(0.907, 0.435, 0.353)], [0.7, new Color(0.963, 0.554, 0.272)], [0.8, new Color(0.992, 0.681, 0.195)], [0.9, new Color(0.987, 0.822, 0.144)], [1.0, new Color(0.940, 0.975, 0.131)]],
  10627. YELLOW_GREEN: [[0, new Color(0.1647, 0.2824, 0.3451)], [0.1, new Color(0.1338, 0.3555, 0.4227)], [0.2, new Color(0.0610, 0.4319, 0.4864)], [0.3, new Color(0.0000, 0.5099, 0.5319)], [0.4, new Color(0.0000, 0.5881, 0.5569)], [0.5, new Color(0.1370, 0.6650, 0.5614)], [0.6, new Color(0.2906, 0.7395, 0.5477)], [0.7, new Color(0.4453, 0.8099, 0.5201)], [0.8, new Color(0.6102, 0.8748, 0.4850)], [0.9, new Color(0.7883, 0.9323, 0.4514)], [1, new Color(0.9804, 0.9804, 0.4314)]],
  10628. VIRIDIS: [[0.0, new Color(0.267, 0.005, 0.329)], [0.1, new Color(0.283, 0.141, 0.458)], [0.2, new Color(0.254, 0.265, 0.530)], [0.3, new Color(0.207, 0.372, 0.553)], [0.4, new Color(0.164, 0.471, 0.558)], [0.5, new Color(0.128, 0.567, 0.551)], [0.6, new Color(0.135, 0.659, 0.518)], [0.7, new Color(0.267, 0.749, 0.441)], [0.8, new Color(0.478, 0.821, 0.318)], [0.9, new Color(0.741, 0.873, 0.150)], [1.0, new Color(0.993, 0.906, 0.144)]],
  10629. INFERNO: [[0.0, new Color(0.077, 0.042, 0.206)], [0.1, new Color(0.225, 0.036, 0.388)], [0.2, new Color(0.373, 0.074, 0.432)], [0.3, new Color(0.522, 0.128, 0.420)], [0.4, new Color(0.665, 0.182, 0.370)], [0.5, new Color(0.797, 0.255, 0.287)], [0.6, new Color(0.902, 0.364, 0.184)], [0.7, new Color(0.969, 0.516, 0.063)], [0.8, new Color(0.988, 0.683, 0.072)], [0.9, new Color(0.961, 0.859, 0.298)], [1.0, new Color(0.988, 0.998, 0.645)]],
  10630. GRAYSCALE: [[0, new Color(0, 0, 0)], [1, new Color(1, 1, 1)]],
  10631. // 16 samples of the TURBU color scheme
  10632. // values taken from: https://gist.github.com/mikhailov-work/ee72ba4191942acecc03fe6da94fc73f
  10633. // original file licensed under Apache-2.0
  10634. TURBO: [[0.00, new Color(0.18995, 0.07176, 0.23217)], [0.07, new Color(0.25107, 0.25237, 0.63374)], [0.13, new Color(0.27628, 0.42118, 0.89123)], [0.20, new Color(0.25862, 0.57958, 0.99876)], [0.27, new Color(0.15844, 0.73551, 0.92305)], [0.33, new Color(0.09267, 0.86554, 0.7623)], [0.40, new Color(0.19659, 0.94901, 0.59466)], [0.47, new Color(0.42778, 0.99419, 0.38575)], [0.53, new Color(0.64362, 0.98999, 0.23356)], [0.60, new Color(0.80473, 0.92452, 0.20459)], [0.67, new Color(0.93301, 0.81236, 0.22667)], [0.73, new Color(0.99314, 0.67408, 0.20348)], [0.80, new Color(0.9836, 0.49291, 0.12849)], [0.87, new Color(0.92105, 0.31489, 0.05475)], [0.93, new Color(0.81608, 0.18462, 0.01809)], [1.00, new Color(0.66449, 0.08436, 0.00424)]],
  10635. RAINBOW: [[0, new Color(0.278, 0, 0.714)], [1 / 6, new Color(0, 0, 1)], [2 / 6, new Color(0, 1, 1)], [3 / 6, new Color(0, 1, 0)], [4 / 6, new Color(1, 1, 0)], [5 / 6, new Color(1, 0.64, 0)], [1, new Color(1, 0, 0)]],
  10636. CONTOUR: [[0.00, new Color(0, 0, 0)], [0.03, new Color(0, 0, 0)], [0.04, new Color(1, 1, 1)], [1.00, new Color(1, 1, 1)]]
  10637. };
  10638. var Shaders = {};
  10639. Shaders["pointcloud_new.vs"] = "\nprecision highp float;\nprecision highp int;\n \n#define PI 3.141592653589793\n\n \n\n\n\n#if defined(usePanoMap) \n \n uniform samplerCube pano0Map; //\u968F\u4FBF\u8BBE\u7F6E\u4E00\u4E2AsamplerCube\u53BB\u4F7F\u7528\u90FD\u4F1A\u8BA9\u70B9\u4E91\u6D88\u5931\n uniform samplerCube pano1Map;\n \n uniform float progress;\n uniform float easeInOutRatio;\n\n \n uniform vec3 pano0Position;\n uniform mat4 pano0Matrix; \n uniform vec3 pano1Position;\n uniform mat4 pano1Matrix;\n /*\n varying vec3 vWorldPosition0;\n varying vec3 vWorldPosition1;\n */\n#endif \n\n\n\n\n \n\n//--------------\n\n\n\n\n\nattribute vec3 position;\nattribute vec3 color;\nattribute float intensity;\nattribute float classification;\nattribute float returnNumber;\nattribute float numberOfReturns;\nattribute float pointSourceID;\nattribute vec4 indices; //\u6BCF\u4E2A\u70B9\u7684index\nattribute float spacing;\nattribute float gpsTime;\nattribute vec3 normal;\nattribute float aExtra;\n\nuniform mat4 modelMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat4 uViewInv;\n\n//uniform float uScreenWidth;\n//uniform float uScreenHeight;\nuniform vec2 resolution;\n\n\nuniform float fov;\nuniform float near;\nuniform float far;\n\n\n\n\nuniform bool uDebug;\n\nuniform bool uUseOrthographicCamera;\nuniform float uOrthoWidth;\nuniform float uOrthoHeight;\n\n#define CLIPTASK_NONE 0\n#define CLIPTASK_HIGHLIGHT 1\n#define CLIPTASK_SHOW_INSIDE 2\n#define CLIPTASK_SHOW_OUTSIDE 3\n\n#define CLIPMETHOD_INSIDE_ANY 0\n#define CLIPMETHOD_INSIDE_ALL 1\n\n//\u6700\u5916\u5C42\u88C1\u526A\uFF08\u4E0B\u8F7D\uFF09\n#if defined(bigClipInBox)\n\tuniform mat4 clipBoxBig_in;\n#endif\n//\u5185\u5C42\u88C1\u526A\n#if defined(num_in_clipboxes) && num_in_clipboxes > 0\n\tuniform mat4 clipBoxes_in[num_in_clipboxes];\n#endif\n#if defined(num_out_clipboxes) && num_out_clipboxes > 0\n\tuniform mat4 clipBoxes_out[num_out_clipboxes];\n#endif\n\n\n#if defined(num_clipspheres) && num_clipspheres > 0\n\tuniform mat4 uClipSpheres[num_clipspheres];\n#endif\n\n \n#if defined(num_highlightBox) && num_highlightBox > 0\n uniform mat4 boxes_highlight[num_highlightBox]; \n#endif \n\t\t \n\n#if defined(num_prism) && num_prism > 0\n uniform mat3 prismList[num_prism];\n uniform vec2 prismPoints[prismPointCountSum]; \n#endif \n\n#if defined(showBaseHeight) \n uniform sampler2D baseHeightAreaMap ;\n uniform vec2 baseHeightBoundZ;\n uniform vec4 baseHeightBoundXY; \n#endif \n\nuniform float size;\nuniform float minSize;\nuniform float maxSize; \nuniform float orthoMaxSize;//add\n\n\nuniform float uPCIndex;\nuniform float uOctreeSpacing;\nuniform float uNodeSpacing;\nuniform float uOctreeSize;\nuniform vec3 uBBSize;\nuniform float uLevel;\nuniform float levelPercent;//add\nuniform float uVNStart;\nuniform bool uIsLeafNode;\n\nuniform vec3 uColor;\nuniform float uOpacity; \nvarying float vOpacity; //add\n\n\n\nuniform vec2 elevationRange;\nuniform vec2 intensityRange;\n\nuniform vec2 uFilterReturnNumberRange;\nuniform vec2 uFilterNumberOfReturnsRange;\nuniform vec2 uFilterPointSourceIDClipRange;\nuniform vec2 uFilterGPSTimeClipRange;\n//uniform float ufilterByNormalThreshold; \n\nuniform float uGpsScale;\nuniform float uGpsOffset;\n\nuniform vec2 uNormalizedGpsBufferRange;\n\nuniform vec3 uIntensity_gbc;\nuniform vec3 uRGB_gbc;\nuniform vec3 uExtra_gbc;\n\nuniform float uTransition;\nuniform float wRGB;\nuniform float wIntensity;\nuniform float wElevation;\nuniform float wClassification;\nuniform float wReturnNumber;\nuniform float wSourceID;\n\nuniform vec2 uExtraNormalizedRange;\nuniform vec2 uExtraRange;\nuniform float uExtraScale;\nuniform float uExtraOffset;\n\nuniform vec3 uShadowColor;\n\nuniform sampler2D visibleNodes;\nuniform sampler2D gradient;\nuniform sampler2D classificationLUT;\n\n#if defined(color_type_matcap)\nuniform sampler2D matcapTextureUniform;\n#endif\nuniform bool backfaceCulling;\n\n#if defined(num_shadowmaps) && num_shadowmaps > 0\nuniform sampler2D uShadowMap[num_shadowmaps];\nuniform mat4 uShadowWorldView[num_shadowmaps];\nuniform mat4 uShadowProj[num_shadowmaps];\n#endif\n\n\n\nvarying vec3\tvColor;\nvarying float\tvLogDepth;\nvarying vec3\tvViewPosition;\nvarying float \tvRadius;\nvarying float \tvPointSize;\n\n\nfloat Round(float number){\n\treturn floor(number + 0.5);\n}\n\n// \n// ### ######## ### ######## ######## #### ## ## ######## ###### #### ######## ######## ###### \n// ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## \n// ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## \n// ## ## ## ## ## ## ######## ## ## ## ## ###### ###### ## ## ###### ###### \n// ######### ## ## ######### ## ## ## ## ## ## ## ## ## ## ## \n// ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## \n// ## ## ######## ## ## ## ## #### ### ######## ###### #### ######## ######## ###### \n// \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\n\n// ---------------------\n// OCTREE\n// ---------------------\n\n#if (defined(adaptive_point_size) || defined(color_type_level_of_detail)) && defined(tree_type_octree)\n/**\n * number of 1-bits up to inclusive index position\n * number is treated as if it were an integer in the range 0-255\n *\n */\nint numberOfOnes(int number, int index){\n\tint numOnes = 0;\n\tint tmp = 128;\n\tfor(int i = 7; i >= 0; i--){\n\t\t\n\t\tif(number >= tmp){\n\t\t\tnumber = number - tmp;\n\n\t\t\tif(i <= index){\n\t\t\t\tnumOnes++;\n\t\t\t}\n\t\t}\n\t\t\n\t\ttmp = tmp / 2;\n\t}\n\n\treturn numOnes;\n}\n\n\n/**\n * checks whether the bit at index is 1\n * number is treated as if it were an integer in the range 0-255\n *\n */\nbool isBitSet(int number, int index){\n\n\t// weird multi else if due to lack of proper array, int and bitwise support in WebGL 1.0\n\tint powi = 1;\n\tif(index == 0){\n\t\tpowi = 1;\n\t}else if(index == 1){\n\t\tpowi = 2;\n\t}else if(index == 2){\n\t\tpowi = 4;\n\t}else if(index == 3){\n\t\tpowi = 8;\n\t}else if(index == 4){\n\t\tpowi = 16;\n\t}else if(index == 5){\n\t\tpowi = 32;\n\t}else if(index == 6){\n\t\tpowi = 64;\n\t}else if(index == 7){\n\t\tpowi = 128;\n\t}else{\n\t\treturn false;\n\t}\n\n\tint ndp = number / powi;\n\n\treturn mod(float(ndp), 2.0) != 0.0;\n}\n\n\n/**\n * find the LOD at the point position\n */\nfloat getLOD(){//////we use this\n\t \n\tvec3 offset = vec3(0.0, 0.0, 0.0);\n\tint iOffset = int(uVNStart);\n\tfloat depth = uLevel;\n\tfor(float i = 0.0; i <= 30.0; i++){\n\t\tfloat nodeSizeAtLevel = uOctreeSize / pow(2.0, i + uLevel + 0.0);\n\t\t\n\t\tvec3 index3d = (position-offset) / nodeSizeAtLevel;\n\t\tindex3d = floor(index3d + 0.5);\n\t\tint index = int(Round(4.0 * index3d.x + 2.0 * index3d.y + index3d.z));\n\t\t\n\t\tvec4 value = texture2D(visibleNodes, vec2(float(iOffset) / 2048.0, 0.0));\n\t\tint mask = int(Round(value.r * 255.0));\n\n\t\tif(isBitSet(mask, index)){\n\t\t\t// there are more visible child nodes at this position\n\t\t\tint advanceG = int(Round(value.g * 255.0)) * 256;\n\t\t\tint advanceB = int(Round(value.b * 255.0));\n\t\t\tint advanceChild = numberOfOnes(mask, index - 1);\n\t\t\tint advance = advanceG + advanceB + advanceChild;\n\n\t\t\tiOffset = iOffset + advance;\n\t\t\t\n\t\t\tdepth++;\n\t\t}else{\n\t\t\t// no more visible child nodes at this position\n\t\t\t//return value.a * 255.0;\n\n\t\t\tfloat lodOffset = (255.0 * value.a) / 10.0 - 10.0;\n\n\t\t\treturn depth + lodOffset;\n\t\t}\n\t\t\n\t\toffset = offset + (vec3(1.0, 1.0, 1.0) * nodeSizeAtLevel * 0.5) * index3d;\n\t}\n\t\t\n\treturn depth;\n}\n\nfloat getSpacing(){\n\tvec3 offset = vec3(0.0, 0.0, 0.0);\n\tint iOffset = int(uVNStart);\n\tfloat depth = uLevel;\n\tfloat spacing = uNodeSpacing;\n\tfor(float i = 0.0; i <= 30.0; i++){\n\t\tfloat nodeSizeAtLevel = uOctreeSize / pow(2.0, i + uLevel + 0.0);\n\t\t\n\t\tvec3 index3d = (position-offset) / nodeSizeAtLevel;\n\t\tindex3d = floor(index3d + 0.5);\n\t\tint index = int(Round(4.0 * index3d.x + 2.0 * index3d.y + index3d.z));\n\t\t\n\t\tvec4 value = texture2D(visibleNodes, vec2(float(iOffset) / 2048.0, 0.0));\n\t\tint mask = int(Round(value.r * 255.0));\n\t\tfloat spacingFactor = value.a;\n\n\t\tif(i > 0.0){\n\t\t\tspacing = spacing / (255.0 * spacingFactor);\n\t\t}\n\t\t\n\n\t\tif(isBitSet(mask, index)){\n\t\t\t// there are more visible child nodes at this position\n\t\t\tint advanceG = int(Round(value.g * 255.0)) * 256;\n\t\t\tint advanceB = int(Round(value.b * 255.0));\n\t\t\tint advanceChild = numberOfOnes(mask, index - 1);\n\t\t\tint advance = advanceG + advanceB + advanceChild;\n\n\t\t\tiOffset = iOffset + advance;\n\n\t\t\t//spacing = spacing / (255.0 * spacingFactor);\n\t\t\t//spacing = spacing / 3.0;\n\t\t\t\n\t\t\tdepth++;\n\t\t}else{\n\t\t\t// no more visible child nodes at this position\n\t\t\treturn spacing;\n\t\t}\n\t\t\n\t\toffset = offset + (vec3(1.0, 1.0, 1.0) * nodeSizeAtLevel * 0.5) * index3d;\n\t}\n\t\t\n\treturn spacing;\n}\n\nfloat getPointSizeAttenuation(){\n\treturn pow(2.0, getLOD());\n}\n\n\n#endif\n\n\n// ---------------------\n// KD-TREE\n// ---------------------\n\n#if (defined(adaptive_point_size) || defined(color_type_level_of_detail)) && defined(tree_type_kdtree)\n\nfloat getLOD(){\n\tvec3 offset = vec3(0.0, 0.0, 0.0);\n\tfloat iOffset = 0.0;\n\tfloat depth = 0.0;\n\t\t\n\t\t\n\tvec3 size = uBBSize;\t\n\tvec3 pos = position;\n\t\t\n\tfor(float i = 0.0; i <= 1000.0; i++){\n\t\t\n\t\tvec4 value = texture2D(visibleNodes, vec2(iOffset / 2048.0, 0.0));\n\t\t\n\t\tint children = int(value.r * 255.0);\n\t\tfloat next = value.g * 255.0;\n\t\tint split = int(value.b * 255.0);\n\t\t\n\t\tif(next == 0.0){\n\t\t \treturn depth;\n\t\t}\n\t\t\n\t\tvec3 splitv = vec3(0.0, 0.0, 0.0);\n\t\tif(split == 1){\n\t\t\tsplitv.x = 1.0;\n\t\t}else if(split == 2){\n\t\t \tsplitv.y = 1.0;\n\t\t}else if(split == 4){\n\t\t \tsplitv.z = 1.0;\n\t\t}\n\t\t\n\t\tiOffset = iOffset + next;\n\t\t\n\t\tfloat factor = length(pos * splitv / size);\n\t\tif(factor < 0.5){\n\t\t\t// left\n\t\tif(children == 0 || children == 2){\n\t\t\t\treturn depth;\n\t\t\t}\n\t\t}else{\n\t\t\t// right\n\t\t\tpos = pos - size * splitv * 0.5;\n\t\t\tif(children == 0 || children == 1){\n\t\t\t\treturn depth;\n\t\t\t}\n\t\t\tif(children == 3){\n\t\t\t\tiOffset = iOffset + 1.0;\n\t\t\t}\n\t\t}\n\t\tsize = size * ((1.0 - (splitv + 1.0) / 2.0) + 0.5);\n\t\t\n\t\tdepth++;\n\t}\n\t\t\n\t\t\n\treturn depth;\t\n}\n\nfloat getPointSizeAttenuation(){\n\treturn 0.5 * pow(1.3, getLOD());\n}\n\n#endif\n\n\n\n// \n// ### ######## ######## ######## #### ######## ## ## ######## ######## ###### \n// ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## \n// ## ## ## ## ## ## ## ## ## ## ## ## ## ## \n// ## ## ## ## ######## ## ######## ## ## ## ###### ###### \n// ######### ## ## ## ## ## ## ## ## ## ## ## ## \n// ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## \n// ## ## ## ## ## ## #### ######## ####### ## ######## ###### \n// \n\n\n\n// formula adapted from: http://www.dfstudios.co.uk/articles/programming/image-programming-algorithms/image-processing-algorithms-part-5-contrast-adjustment/\nfloat getContrastFactor(float contrast){\n\treturn (1.0158730158730156 * (contrast + 1.0)) / (1.0158730158730156 - contrast);\n}\n\nvec3 getRGB(){\n\tvec3 rgb = color;\n\t\n\trgb = pow(rgb, vec3(uRGB_gbc.x));\n\trgb = rgb + uRGB_gbc.y;\n\trgb = (rgb - 0.5) * getContrastFactor(uRGB_gbc.z) + 0.5;\n\trgb = clamp(rgb, 0.0, 1.0);\n\n\treturn rgb;\n}\n\nfloat getIntensity(){\n\tfloat w = (intensity - intensityRange.x) / (intensityRange.y - intensityRange.x);\n\tw = pow(w, uIntensity_gbc.x);\n\tw = w + uIntensity_gbc.y;\n\tw = (w - 0.5) * getContrastFactor(uIntensity_gbc.z) + 0.5;\n\tw = clamp(w, 0.0, 1.0);\n\n\treturn w;\n}\n\nvec3 getGpsTime(){\n\n\tfloat w = (gpsTime + uGpsOffset) * uGpsScale;\n\n\n\tvec3 c = texture2D(gradient, vec2(w, 1.0 - w)).rgb;\n\n\n\t// vec2 r = uNormalizedGpsBufferRange;\n\t// float w = gpsTime * (r.y - r.x) + r.x;\n\t// w = clamp(w, 0.0, 1.0);\n\t// vec3 c = texture2D(gradient, vec2(w,1.0-w)).rgb;\n\t\n\treturn c;\n}\n\nvec3 getElevation(vec4 world){ \n\tfloat w = (world.z - elevationRange.x) / (elevationRange.y - elevationRange.x);\n\tvec3 cElevation = texture2D(gradient, vec2(w,1.0-w)).rgb;\n\treturn cElevation;\n}\n\nvec4 getClassification(){\n\tvec2 uv = vec2(classification / 255.0, 0.5);\n\tvec4 classColor = texture2D(classificationLUT, uv);\n\t\n\treturn classColor;\n}\n\nvec3 getReturns(){\n\n\t// 0b 00_000_111\n\tfloat rn = mod(returnNumber, 8.0);\n\t// 0b 00_111_000\n\tfloat nr = mod(returnNumber / 8.0, 8.0);\n\n\tif(nr <= 1.0){\n\t\treturn vec3(1.0, 0.0, 0.0);\n\t}else{\n\t\treturn vec3(0.0, 1.0, 0.0);\n\t}\n\n\t// return vec3(nr / 4.0, 0.0, 0.0);\n\n\t// if(nr == 1.0){\n\t// \treturn vec3(1.0, 1.0, 0.0);\n\t// }else{\n\t// \tif(rn == 1.0){\n\t// \t\treturn vec3(1.0, 0.0, 0.0);\n\t// \t}else if(rn == nr){\n\t// \t\treturn vec3(0.0, 0.0, 1.0);\n\t// \t}else{\n\t// \t\treturn vec3(0.0, 1.0, 0.0);\n\t// \t}\n\t// }\n\n\t// if(numberOfReturns == 1.0){\n\t// \treturn vec3(1.0, 1.0, 0.0);\n\t// }else{\n\t// \tif(returnNumber == 1.0){\n\t// \t\treturn vec3(1.0, 0.0, 0.0);\n\t// \t}else if(returnNumber == numberOfReturns){\n\t// \t\treturn vec3(0.0, 0.0, 1.0);\n\t// \t}else{\n\t// \t\treturn vec3(0.0, 1.0, 0.0);\n\t// \t}\n\t// }\n}\n\nvec3 getReturnNumber(){\n\tif(numberOfReturns == 1.0){\n\t\treturn vec3(1.0, 1.0, 0.0);\n\t}else{\n\t\tif(returnNumber == 1.0){\n\t\t\treturn vec3(1.0, 0.0, 0.0);\n\t\t}else if(returnNumber == numberOfReturns){\n\t\t\treturn vec3(0.0, 0.0, 1.0);\n\t\t}else{\n\t\t\treturn vec3(0.0, 1.0, 0.0);\n\t\t}\n\t}\n}\n\nvec3 getNumberOfReturns(){\n\tfloat value = numberOfReturns;\n\n\tfloat w = value / 6.0;\n\n\tvec3 color = texture2D(gradient, vec2(w, 1.0 - w)).rgb;\n\n\treturn color;\n}\n\nvec3 getSourceID(){\n\tfloat w = mod(pointSourceID, 10.0) / 10.0;\n\treturn texture2D(gradient, vec2(w,1.0 - w)).rgb;\n}\n\nvec3 getCompositeColor(vec4 world){\n\tvec3 c;\n\tfloat w;\n\n\tc += wRGB * getRGB();\n\tw += wRGB;\n\t\n\tc += wIntensity * getIntensity() * vec3(1.0, 1.0, 1.0);\n\tw += wIntensity;\n\t\n\tc += wElevation * getElevation(world);\n\tw += wElevation;\n\t\n\tc += wReturnNumber * getReturnNumber();\n\tw += wReturnNumber;\n\t\n\tc += wSourceID * getSourceID();\n\tw += wSourceID;\n\t\n\tvec4 cl = wClassification * getClassification();\n\tc += cl.a * cl.rgb;\n\tw += wClassification * cl.a;\n\n\tc = c / w;\n\t\n\tif(w == 0.0){\n\t\t//c = color;\n\t\tgl_Position = vec4(100.0, 100.0, 100.0, 0.0);\n\t}\n\t\n\treturn c;\n}\n\n\nvec3 getNormal(){\n\t//vec3 n_hsv = vec3( modelMatrix * vec4( normal, 0.0 )) * 0.5 + 0.5; // (n_world.xyz + vec3(1.,1.,1.)) / 2.;\n\tvec3 n_view = normalize( vec3(modelViewMatrix * vec4( normal, 0.0 )) );\n\treturn n_view;\n}\nbool applyBackfaceCulling() {\n\t// Black not facing vertices / Backface culling\n \n\tvec3 e = normalize(vec3(modelViewMatrix * vec4( position, 1. )));\n\tvec3 n = getNormal(); // normalize( vec3(modelViewMatrix * vec4( normal, 0.0 )) );\n\n\tif((uUseOrthographicCamera && n.z <= 0.) || (!uUseOrthographicCamera && dot( n, e ) >= 0.)) { \n\t\treturn true;\n\t} else {\n\t\treturn false;\n\t}\n}\n\n#if defined(color_type_matcap)\n// Matcap Material\nvec3 getMatcap(){ \n\tvec3 eye = normalize( vec3( modelViewMatrix * vec4( position, 1. ) ) ); \n\tif(uUseOrthographicCamera) { \n\t\teye = vec3(0., 0., -1.);\n\t}\n\tvec3 r_en = reflect( eye, getNormal() ); // or r_en = e - 2. * dot( n, e ) * n;\n\tfloat m = 2. * sqrt(pow( r_en.x, 2. ) + pow( r_en.y, 2. ) + pow( r_en.z + 1., 2. ));\n\tvec2 vN = r_en.xy / m + .5;\n\treturn texture2D(matcapTextureUniform, vN).rgb; \n}\n#endif\n\nvec3 getExtra(){\n\n\tfloat w = (aExtra + uExtraOffset) * uExtraScale;\n\tw = clamp(w, 0.0, 1.0);\n\n\tvec3 color = texture2D(gradient, vec2(w,1.0-w)).rgb;\n\n\t// vec2 r = uExtraNormalizedRange;\n\n\t// float w = aExtra * (r.y - r.x) + r.x;\n\n\t// w = (w - uExtraRange.x) / (uExtraRange.y - uExtraRange.x);\n\n\t// w = clamp(w, 0.0, 1.0);\n\n\t// vec3 color = texture2D(gradient, vec2(w,1.0-w)).rgb;\n\n\treturn color;\n}\n\nvec3 getColor(vec4 world){\n\tvec3 color;\n\t\n\t#ifdef color_type_rgba\n\t\tcolor = getRGB();\n \n \n\t#elif defined color_type_height || defined color_type_elevation\n\t\tcolor = getElevation(world);\n\t#elif defined color_type_rgb_height\n\t\tvec3 cHeight = getElevation();\n\t\tcolor = (1.0 - uTransition) * getRGB() + uTransition * cHeight;\n\t#elif defined color_type_depth\n\t\tfloat linearDepth = gl_Position.w;\n\t\tfloat expDepth = (gl_Position.z / gl_Position.w) * 0.5 + 0.5;\n\t\tcolor = vec3(linearDepth, expDepth, 0.0);\n\t\t//color = vec3(1.0, 0.5, 0.3);\n\t#elif defined color_type_intensity\n\t\tfloat w = getIntensity();\n\t\tcolor = vec3(w, w, w);\n\t#elif defined color_type_gps_time\n\t\tcolor = getGpsTime();\n\t#elif defined color_type_intensity_gradient\n\t\tfloat w = getIntensity();\n\t\tcolor = texture2D(gradient, vec2(w,1.0-w)).rgb;\n\t#elif defined color_type_color\n\t\tcolor = uColor;\n\t#elif defined color_type_level_of_detail\n\t\tfloat depth = getLOD();\n\t\tfloat w = depth / 10.0;\n\t\tcolor = texture2D(gradient, vec2(w,1.0-w)).rgb;\n\t#elif defined color_type_indices\n\t\tcolor = indices.rgb;\n\t#elif defined color_type_classification\n\t\tvec4 cl = getClassification(); \n\t\tcolor = cl.rgb;\n\t#elif defined color_type_return_number\n\t\tcolor = getReturnNumber();\n\t#elif defined color_type_returns\n\t\tcolor = getReturns();\n\t#elif defined color_type_number_of_returns\n\t\tcolor = getNumberOfReturns();\n\t#elif defined color_type_source_id\n\t\tcolor = getSourceID();\n\t#elif defined color_type_point_source_id\n\t\tcolor = getSourceID();\n\t#elif defined color_type_normal\n\t\tcolor = (modelMatrix * vec4(normal, 0.0)).xyz;\n\t#elif defined color_type_phong\n\t\tcolor = color;\n\t#elif defined color_type_composite\n\t\tcolor = getCompositeColor(world);\n\t#elif defined color_type_matcap\n\t\tcolor = getMatcap();\n\t#elif defined color_type_heightCpt //add\n color = vec3(0.0,0.0,0.0);\n #else\n\t\tcolor = getExtra();\n\t#endif\n\t\n\tif (backfaceCulling && applyBackfaceCulling()){\n //color = vec3(0.);\n }\n //applyBackfaceCulling\u76F4\u63A5\u8FD4\u56DEfalse\u6216\u8005\u6CE8\u91CAcolor = vec3(0.);\u90FD\u6CA1\u95EE\u9898\n\treturn color;\n}\n\nfloat getPointSize(){\n\tfloat pointSize = 1.0;\n\tfloat maxSize_ = maxSize;\n\tfloat slope = tan(fov / 2.0);\n\tfloat projFactor = -0.5 * resolution.y / (slope * vViewPosition.z);\n \n \n \n /*\n\tfloat scale = length(\n\t\tmodelViewMatrix * vec4(0, 0, 0, 1) - \n\t\tmodelViewMatrix * vec4(uOctreeSpacing, 0, 0, 1)\n\t) / uOctreeSpacing;\n \n\tprojFactor = projFactor * scale;\n\t*/\n \n \n\tfloat r = uOctreeSpacing * 1.7;\n\t//vRadius = r;\n \n \n\t#if defined fixed_point_size\n\t\tpointSize = size;\n\t#elif defined attenuated_point_size\n\t\tif(uUseOrthographicCamera){ \n pointSize = size / uOrthoWidth * resolution.x; //\u6539\u6210\u8FD1\u4F3Cadaptive_point_size\u6839\u636E\u7A97\u53E3\u7F29\u653E\u3002\u5176\u5B9E\u5C31\u662Fsize * zoom (size\u5355\u4F4D\u8F6C\u5316\u4E3A\u7C73\uFF0C\u5982size\u4E3A1\u4EE3\u8868\u4E00\u4E2A\u70B9\u4E91\u5728\u573A\u666F\u4E2D1\u7C73\u5BBD,zoom\u4EE3\u88681px=1/zoom\u7C73)\n maxSize_ = orthoMaxSize; //for panoEditor, when zoom in, need more details, rather than always same size\n\n\t\t}else{ //\u8FD1\u5927\u8FDC\u5C0F\uFF0C\u6A21\u62DF\u771F\u5B9Emesh\uFF0C\u8FB9\u7F18\u653E\u5927\n\t\t\t//pointSize = size * spacing * projFactor; //spacing\u662Fattribute \u4E3A\u7A7A \u5982\u679C\u6709\u8FD9\u4E2A\u503C\u5C31\u80FD\u66F4\u81EA\u9002\u5E94\u586B\u8865\n //pointSize = size * uOctreeSpacing * projFactor / 18.0; //\u76F4\u63A5\u7528cloud\u7684spacing\u91CC\uFF0C\u4E0D\u8FC7\u56E0\u4E3A\u90FD\u4E00\u6837\u6240\u4EE5\u53EF\u80FD\u6CA1\u6709\u4EC0\u4E48\u610F\u4E49\n\t\t\t//pointSize = pointSize * projFactor;\n pointSize = size * projFactor ;\n\t\t}\n \n\t#elif defined adaptive_point_size\n\t\tif(uUseOrthographicCamera) {\n\t\t\tfloat worldSpaceSize = 1.0 * size * r / getPointSizeAttenuation();\n\t\t\tpointSize = (worldSpaceSize / uOrthoWidth) * resolution.x; //uScreenWidth;\n maxSize_ = orthoMaxSize;\n\t\t} else {\n\t\t\tfloat worldSpaceSize = 1.0 * size * r / getPointSizeAttenuation();\n\t\t\tpointSize = worldSpaceSize * projFactor;\n\t\t}\n \n\t#endif\n\n\tpointSize = max(minSize, pointSize);\n\tpointSize = min(maxSize_, pointSize);\n\t\n\tvRadius = pointSize / projFactor;\n\n\treturn pointSize;\n} \n\n\nbool insideBox(mat4 clipBox, vec4 worldPos){//add\n vec4 clipPosition = clipBox * worldPos;\n bool inside = -0.5 <= clipPosition.x && clipPosition.x <= 0.5;\n inside = inside && -0.5 <= clipPosition.y && clipPosition.y <= 0.5;\n inside = inside && -0.5 <= clipPosition.z && clipPosition.z <= 0.5;\n\n return inside;\n}\n\n\n\n#if defined(color_type_heightCpt)\n vec3 percentToByte(float num){\n //\u8F93\u51FA\u662F0-1\uFF0C shader\u7CBE\u5EA6\u4E0D\u591F\uFF0C\u53EA\u591F\u5B583\u4E2A\u6570\n float a = 1.0;\n float result[4];\n for(int i=0;i<3;i++){\n a = i == 2 ? a/255.0 : a / 256.0 ; \n //\u5206\u6210256\u4EFD\uFF0C\u5176\u4E2D255\u4EFD\u7ED9\u5F53\u524D\u4F4D\u7F6E\uFF0C\u6700\u540E\u4E00\u4EFD\u7ED9\u540E\u4E00\u4E2A\u4F4D\u7F6E\uFF0C\u800C\u5230\u4E86\u6700\u540E\u4E00\u4E2A\u4F4D\u7F6E\u65F6\u6CA1\u6709\u4E0B\u4E00\u4E2A\u4F4D\u7F6E\u4E86\u6240\u4EE5\u53EA\u5206\u6210255\u4EFD\n if(num > a){\n float c = num / a;\n float r = floor(c);\n r = min(255.0, r);\n result[i] = r;\n num -= r * a;\n }else{\n result[i] = 0.0;\n }\n } \n return vec3(result[0]/255.0, result[1]/255.0,result[2]/255.0); \n \n //\u9664\u4EE5\u591A\u5C11255\u8FD8\u662F256? \u53C2\u8003uPCIndex / 255.0 \u5E94\u8BE5\u662F255\n } \n#endif\n\n \n\n#if defined(num_prism) && num_prism > 0\n \n \n int insidePrism(mat3 prismInfo, int pointIndexStart, vec4 worldPos){//\u662F\u5426\u5728\u68F1\u67F1\u91CC \n \n float zMin = prismInfo[0][0];\n float zMid = prismInfo[0][1];\n float zMax = prismInfo[0][2]; \n float xMin = prismInfo[1][0];\n float xMax = prismInfo[1][1];\n float yMin = prismInfo[1][2];\n float yMax = prismInfo[2][0]; \n\n int pointCount = int(Round(prismInfo[2][1]));\n \n if( worldPos.x < xMin || worldPos.x > xMax || worldPos.y < yMin || worldPos.y > yMax)return 0;\n #ifndef showBaseHeight\n if( worldPos.z < zMin || worldPos.z > zMax) return 0;\n #endif\n \n \n bool inside = false;\n \n int j=pointCount-1;\n \n for(int i=0; i<prism_maxPointsCount; i++){\n if(i>=pointCount)break;\n float xi = prismPoints[i+pointIndexStart].x, yi = prismPoints[i+pointIndexStart].y, xj = prismPoints[j+pointIndexStart].x, yj = prismPoints[j+pointIndexStart].y;\n\n if(((yi > worldPos.y) != (yj > worldPos.y)) && (worldPos.x < (xj - xi) * (worldPos.y - yi) / (yj - yi) + xi)){\n inside = !inside;\n }\n j=i; \n }\n \n if(inside){\n #ifdef showBaseHeight\n return 1;\n #else \n #ifdef color_type_heightCpt \n vColor = percentToByte((worldPos.z - zMin) / (zMax - zMin)); \n #endif \n #endif\n \n return worldPos.z < zMid ? 1 : 2;\n }else return 0; \n } \n \n#endif\n\n#ifdef showBaseHeight\n float byteToFloat(vec3 color){ \n float percent = 0.0;\n float a = 1.0; \n for(int i=0;i<3;i++){\n a = i == 2 ? a/255.0 : a/256.0; \n percent += a * color[i] ;\n }\n return percent * 255.0 ; \n } \n \n#endif\n\n\n \n\n\nvoid doClipping(vec4 world){\n\n\t{\n\t\tvec4 cl = getClassification(); \n\t\tif(cl.a == 0.0){\n\t\t\tgl_Position = vec4(100.0, 100.0, 100.0, 0.0);\n\t\t\t\n\t\t\treturn;\n\t\t}\n\t}\n\n\t#if defined(clip_return_number_enabled)\n\t{ // return number filter\n\t\tvec2 range = uFilterReturnNumberRange;\n\t\tif(returnNumber < range.x || returnNumber > range.y){\n\t\t\tgl_Position = vec4(100.0, 100.0, 100.0, 0.0);\n\t\t\t\n\t\t\treturn;\n\t\t}\n\t}\n\t#endif\n\n\t#if defined(clip_number_of_returns_enabled)\n\t{ // number of return filter\n\t\tvec2 range = uFilterNumberOfReturnsRange;\n\t\tif(numberOfReturns < range.x || numberOfReturns > range.y){\n\t\t\tgl_Position = vec4(100.0, 100.0, 100.0, 0.0);\n\t\t\t\n\t\t\treturn;\n\t\t}\n\t}\n\t#endif\n\n\t#if defined(clip_gps_enabled)\n\t{ // GPS time filter\n\t\tfloat time = (gpsTime + uGpsOffset) * uGpsScale;\n\t\tvec2 range = uFilterGPSTimeClipRange;\n\n\t\tif(time < range.x || time > range.y){\n\t\t\tgl_Position = vec4(100.0, 100.0, 100.0, 0.0);\n\t\t\t\n\t\t\treturn;\n\t\t}\n\t}\n\t#endif\n\n\t#if defined(clip_point_source_id_enabled)\n\t{ // point source id filter\n\t\tvec2 range = uFilterPointSourceIDClipRange;\n\t\tif(pointSourceID < range.x || pointSourceID > range.y){\n\t\t\tgl_Position = vec4(100.0, 100.0, 100.0, 0.0);\n\t\t\t\n\t\t\treturn;\n\t\t}\n\t}\n\t#endif\n\n\t \n\n\n //\u603B\u5171\u4E09\u79CDbox : \u6700\u5916\u5C42\u53EF\u89C1\u3001\u5185\u5C42\u53EF\u89C1\u548C\u4E0D\u53EF\u89C1(\u5916\u5C42\u53EF\u89C1\u548C\u5185\u5C42\u53EF\u89C1\u662F\u4EA4\u96C6\uFF0C\u5185\u5C42\u53EF\u89C1\u548C\u5185\u5C42\u4E0D\u53EF\u89C1\u662F\u5E76\u96C6)\n \n #if defined(bigClipInBox) \n if(!insideBox(clipBoxBig_in, world)){ \n gl_Position = vec4(100.0, 100.0, 100.0, 1.0);\n return;;\n } \n #endif \n \n #if defined(num_in_clipboxes) && num_in_clipboxes > 0\n //\u5F53\u6709\u53EF\u89C1box\u65F6\uFF0C\u9700\u8981\u5728\u4EFB\u4E00\u53EF\u89C1box\u5185\u624D\u53EF\u89C1\n bool visi1 = false;\n\t\tfor(int i = 0; i < num_in_clipboxes; i++){ \n if(insideBox(clipBoxes_in[i], world)){\n visi1 = true;\n break;\n } \n\t\t}\n if(!visi1){\n gl_Position = vec4(100.0, 100.0, 100.0, 1.0);\n return;\n }\n\t#endif\n\n\n #if defined(num_out_clipboxes) && num_out_clipboxes > 0\n //\u5F53\u6709\u4E0D\u53EF\u89C1box\u65F6\uFF0C\u4E0D\u5728\u6240\u6709\u4E0D\u53EF\u89C1box\u5185\u624D\u53EF\u89C1\n bool visi2 = true;\n\t\tfor(int i = 0; i < num_out_clipboxes; i++){ \n if(insideBox(clipBoxes_out[i], world)){\n visi2 = false;\n break;\n } \n\t\t}\n if(!visi2){\n gl_Position = vec4(100.0, 100.0, 100.0, 1.0);\n return;\n }\n\t#endif \n \n \n #if defined(num_highlightBox) && num_highlightBox > 0\n //\u5F53\u6709\u9AD8\u4EAEbox\u65F6\uFF0C\u9700\u8981\u5728\u4EFB\u4E00\u53EF\u89C1\u9AD8\u4EAE\u5185\u90FD\u9AD8\u5BBD\n bool highlight = false;\n\t\tfor(int i = 0; i < num_highlightBox; i++){ \n if(insideBox(boxes_highlight[i], world)){\n highlight = true;\n break;\n } \n\t\t}\n if(highlight){\n vColor.r += 0.5; \n }\n\t#endif\n \n \n \n int highlight_ = 0; \n \n #if defined(num_prism) && num_prism > 0 \n //\u57FA\u4E8Eprism\u68F1\u67F1\u7684\u571F\u65B9\u91CF\u663E\u793A\u6216\u8BA1\u7B97\n \n int pointIndexStart = 0;\n\t\tfor(int i = 0; i < num_prism; i++){ \n highlight_ = insidePrism(prismList[i], pointIndexStart, world);\n \n if(highlight_>0){ \n #if !defined(showBaseHeight) && !defined(color_type_heightCpt)\n if(highlight_ == 1){\n vColor.r += 0.5; \n }else if(highlight_ == 2){\n vColor.g += 0.5;\n }\n #endif\n \n break;\n }\n \n \n pointIndexStart += int(Round(prismList[i][2][1])); \n\t\t} \n \n #ifdef color_type_heightCpt \n if(highlight_==0){ \n gl_Position = vec4(100.0, 100.0, 100.0, 1.0); //unvisible\n return;\n }\n #endif \n \n\t#endif\n \n \n \n \n #ifdef showBaseHeight\n //\u57FA\u4E8E\u6A21\u578B\u7684\u571F\u65B9\u91CF\u663E\u793A\u6216\u8BA1\u7B97\n bool outsidePrism = false;\n #if defined(num_prism) && num_prism > 0//\u9AD8\u4EAE\u4EA4\u96C6\n if( highlight_ == 0 ){\n outsidePrism = true;\n }\n #endif \n \n if(!outsidePrism){\n \n float zMin = baseHeightBoundZ.x; \n float zMax = baseHeightBoundZ.y; \n float xMin = baseHeightBoundXY.x;\n float xMax = baseHeightBoundXY.y;\n float yMin = baseHeightBoundXY.z;\n float yMax = baseHeightBoundXY.w; \n \n bool inside = false;\n if(world.z < zMin || world.z > zMax || world.x < xMin || world.x > xMax || world.y < yMin || world.y > yMax){\n inside = false;\n }else{\n vec2 uv = vec2((world.x - xMin) / (xMax - xMin), (world.y - yMin) / (yMax - yMin) );\n \n vec4 color = texture2D(baseHeightAreaMap,uv);\n //\u6297\u952F\u9F7F\u5F85\u5199\n \n \n if(color.a==1.0){ \n \n float currentHeight = (world.z - zMin) / (zMax - zMin) ; \n \n #ifdef color_type_heightCpt\n /*float diff = currentHeight - baseHeight;\n if(diff<0.0){\n diff = -diff;\n vOpacity = 0.5;//\u9700\u8981\u900F\u660E\u901A\u9053\uFF0C\u5BB9\u6613\u51FA\u9519\n }else{\n vOpacity = 1.0;\n }\n vColor = percentToByte(diff); \n */ \n vColor = percentToByte(currentHeight);\n //vColor = color.rgb;\n vOpacity = 1.0;\n \n #else\n //vColor = color.rgb;\n float baseHeight = byteToFloat(color.rgb);\n if(currentHeight > baseHeight){\n vColor.g += 0.5; \n }else{\n vColor.r += 0.5; \n }\n #endif\n \n inside = true;\n }else{\n inside = false;\n }\n \n \n \n } \n \n if(inside == false){\n #ifdef color_type_heightCpt\n gl_Position = vec4(100.0, 100.0, 100.0, 1.0); //unvisible\n return;\n #endif\n }\n \n }\n\t#endif\n}\n\n\n\n// \n// ## ## ### #### ## ## \n// ### ### ## ## ## ### ## \n// #### #### ## ## ## #### ## \n// ## ### ## ## ## ## ## ## ## \n// ## ## ######### ## ## #### \n// ## ## ## ## ## ## ### \n// ## ## ## ## #### ## ## \n//\n\n\nvec2 getSamplerCoord( vec3 direction ) \n{\n direction = normalize(direction);\n float tx=atan(direction.x,-direction.y)/(PI*2.0)+0.5;\n float ty=acos(direction.z)/PI;\n\n return vec2(tx,ty);\n} \n\nvec3 transformAxis( vec3 direction ) //navvis->4dkk\n{\n float y = direction.y;\n direction.y = direction.z;\n direction.z = -y;\n return direction;\n}\n\nvoid main() {\n //bool filtered_by_normal = false; \n float normalZ = 0.0;\n\n\n\n #ifdef use_filter_by_normal\n /*if(abs(getNormal().z) > 0.4) { //ufilterByNormalThreshold \u6682\u5B9A 3\n\t\t\t// Move point outside clip space space to discard it.\n\t\t\t//gl_Position = vec4(0.0, 0.0, 2.0, 1.0); //gl_Position\u7684\u53EF\u89C6\u533A\u57DF\u662F x,y,z\u90FD\u662F[-1,1] \n //return;\n //filtered_by_normal = true; //\u6807\u8BB0\u4E00\u4E0B\u3002\u4E0D\u76F4\u63A5\u4E0D\u7ED8\u5236\uFF0C\u56E0\u4E3A\u6709\u7684\u6CD5\u7EBF\u90FD\u662F\u5782\u76F4\u5411\u4E0A\n \n\t\t}*/\n \n normalZ = abs(getNormal().z);\n #endif\n \n \n vec4 worldPos = modelMatrix * vec4(position, 1.0); \n vec4 mvPosition = modelViewMatrix * vec4(position, 1.0 ); //vec4 mvPosition = viewMatrix * worldPos;\n vViewPosition = mvPosition.xyz;\n gl_Position = projectionMatrix * mvPosition;\n vLogDepth = log2(-mvPosition.z);\n \n \n \n // COLOR\n //\u52A0-------------------\n #if defined(usePanoMap)\n \n vec3 positionLocalToPanoCenter0 = worldPos.xyz - pano0Position;\n vec3 vWorldPosition0 = (vec4(positionLocalToPanoCenter0, 1.0) * pano0Matrix).xyz; \n vWorldPosition0.x *= -1.0;\n vWorldPosition0 = transformAxis(vWorldPosition0);\n \n vec3 positionLocalToPanoCenter1 = worldPos.xyz - pano1Position;\n vec3 vWorldPosition1 = (vec4(positionLocalToPanoCenter1, 1.0) * pano1Matrix).xyz; \n vWorldPosition1.x *= -1.0;\n vWorldPosition1 = transformAxis(vWorldPosition1);\n \n /*\n vec2 samplerCoord0 = getSamplerCoord(vWorldPosition0.xyz);\n vec2 samplerCoord1 = getSamplerCoord(vWorldPosition1.xyz); \n vec4 colorFromPano0 = texture2D(pano0Map,samplerCoord0);\n vec4 colorFromPano1 = texture2D(pano1Map,samplerCoord1);\n */\n \n \n \n \n vec4 colorFromPano0=textureCube(pano0Map,vWorldPosition0.xyz);\n vec4 colorFromPano1=textureCube(pano1Map,vWorldPosition1.xyz);\n\n vColor = mix(colorFromPano0,colorFromPano1,progress).xyz; \n\n \n //float easeInOutRatio = 0.0; //\u7F13\u51B2\uFF0C\u6E10\u53D8\u70B9\u4E91\u5230\u8D34\u56FE\u7684\u989C\u8272 \n if(progress < easeInOutRatio){\n float easeProgress = (easeInOutRatio - progress) / easeInOutRatio;\n vec3 vColor1 = getColor(worldPos);\n vColor = mix(vColor,vColor1,easeProgress); \n }else if(progress > 1.0 - easeInOutRatio){ \n float easeProgress = (progress - (1.0 - easeInOutRatio) ) / easeInOutRatio;\n vec3 vColor1 = getColor(worldPos);\n vColor = mix(vColor,vColor1,easeProgress); \n }\n \n\n #else\n \n vColor = getColor(worldPos);\n \n #endif\n \n \n //------------------- \n \n if(uOpacity>=1.0 || uUseOrthographicCamera){ \n vOpacity = uOpacity; \n \n \n if(uOpacity<1.0){ //uUseOrthographicCamera \n //\u9632\u6B62\u7F29\u5C0F\u540E\u70B9\u4E91\u51E0\u4E4E\u770B\u4E0D\u89C1 \n vOpacity *= 4.0-3.0 * levelPercent; \n \n }\n \n }else{ //#ifdef attenuated_opacity zoom\u4E0D\u4F1A\u6539\u53D8z \u6240\u4EE5\u8FD9\u5E76\u4E0D\u662F\u7528\u5728\u5206\u5C4F\u65F6\u5019\u7684\n float v = -gl_Position.z-1.0 ; // \u8303\u56F4\u4ECE-2\u52300\uFF0C e\u7684-2\u52300\u6B21\u65B9\u7684\u8303\u56F4\u662F0.818\u52301 \n //vOpacity = uOpacity * exp(v/ (levelPercent * 20.0 ) ); \n \n //\u8FD1\u5904\u52A0\u6DF1\uFF0C\u8FDC\u5904\u53D8\u6DE1 gl_Position.z\u4F3C\u4E4E\u671D\u5411\u5C4F\u5E55\u91CC\u4E3A\u6B63\n float r = clamp( pow(1.1, v/10.0 ), 0.1, 1.0 ); //\u9664\u4EE5\u7684\u6570\u5B57\u8D8A\u5927\uFF0C\u8FD1\u9AD8\u8FDC\u4F4E\u7684\u7A0B\u5EA6\u8D8A\u5C0F\uFF0C\u8303\u56F4\u8D8A\u957F\u3002 \u7A0B\u5EA6\u592A\u9AD8\u8FDC\u5904\u5355\u8584\u7684\u533A\u57DF\u770B\u4E0D\u89C1 pow\u7684\u5E95\u6570\u8D8A\u5927\u6539\u53D8\u7387\u8D8A\u5927\n vOpacity = uOpacity * r ;\n \n \n } \n \n vOpacity *= max(0.3, pow((1.0 - normalZ),5.0));//\u5782\u76F4\u671D\u76F8\u673A\u65F6\u964D\u4F4E\u900F\u660E\u5EA6 \n //vOpacity = clamp(vOpacity, 0.0, 1.0); \n\n\n\n // POINT SIZE\n float pointSize = getPointSize();\n \n gl_PointSize = pointSize;\n vPointSize = pointSize;\n\n \n \n \n \n\n // only for \"replacing\" approaches\n // if(getLOD() != uLevel){\n // \tgl_Position = vec4(10.0, 10.0, 10.0, 1.0);\n // }\n\n\n #if defined hq_depth_pass\n float originalDepth = gl_Position.w;\n float adjustedDepth = originalDepth + 2.0 * vRadius;\n float adjust = adjustedDepth / originalDepth;\n\n mvPosition.xyz = mvPosition.xyz * adjust;\n gl_Position = projectionMatrix * mvPosition;\n #endif\n\n\n // CLIPPING\n doClipping(worldPos);\n\n #if defined(num_clipspheres) && num_clipspheres > 0\n for(int i = 0; i < num_clipspheres; i++){\n vec4 sphereLocal = uClipSpheres[i] * mvPosition;\n\n float distance = length(sphereLocal.xyz);\n\n if(distance < 1.0){\n float w = distance;\n vec3 cGradient = texture2D(gradient, vec2(w, 1.0 - w)).rgb;\n \n vColor = cGradient;\n //vColor = cGradient * 0.7 + vColor * 0.3;\n }\n }\n #endif\n\n #if defined(num_shadowmaps) && num_shadowmaps > 0\n\n const float sm_near = 0.1;\n const float sm_far = 10000.0;\n\n for(int i = 0; i < num_shadowmaps; i++){\n vec3 viewPos = (uShadowWorldView[i] * vec4(position, 1.0)).xyz;\n float distanceToLight = abs(viewPos.z);\n \n vec4 projPos = uShadowProj[i] * uShadowWorldView[i] * vec4(position, 1);\n vec3 nc = projPos.xyz / projPos.w;\n \n float u = nc.x * 0.5 + 0.5;\n float v = nc.y * 0.5 + 0.5;\n\n vec2 sampleStep = vec2(1.0 / (2.0*1024.0), 1.0 / (2.0*1024.0)) * 1.5;\n vec2 sampleLocations[9];\n sampleLocations[0] = vec2(0.0, 0.0);\n sampleLocations[1] = sampleStep;\n sampleLocations[2] = -sampleStep;\n sampleLocations[3] = vec2(sampleStep.x, -sampleStep.y);\n sampleLocations[4] = vec2(-sampleStep.x, sampleStep.y);\n\n sampleLocations[5] = vec2(0.0, sampleStep.y);\n sampleLocations[6] = vec2(0.0, -sampleStep.y);\n sampleLocations[7] = vec2(sampleStep.x, 0.0);\n sampleLocations[8] = vec2(-sampleStep.x, 0.0);\n\n float visibleSamples = 0.0;\n float numSamples = 0.0;\n\n float bias = vRadius * 2.0;\n\n for(int j = 0; j < 9; j++){\n vec4 depthMapValue = texture2D(uShadowMap[i], vec2(u, v) + sampleLocations[j]);\n\n float linearDepthFromSM = depthMapValue.x + bias;\n float linearDepthFromViewer = distanceToLight;\n\n if(linearDepthFromSM > linearDepthFromViewer){\n visibleSamples += 1.0;\n }\n\n numSamples += 1.0;\n }\n\n float visibility = visibleSamples / numSamples;\n\n if(u < 0.0 || u > 1.0 || v < 0.0 || v > 1.0 || nc.x < -1.0 || nc.x > 1.0 || nc.y < -1.0 || nc.y > 1.0 || nc.z < -1.0 || nc.z > 1.0){\n //vColor = vec3(0.0, 0.0, 0.2);\n }else{\n //vColor = vec3(1.0, 1.0, 1.0) * visibility + vec3(1.0, 1.0, 1.0) * vec3(0.5, 0.0, 0.0) * (1.0 - visibility);\n vColor = vColor * visibility + vColor * uShadowColor * (1.0 - visibility);\n }\n\n\n }\n\n #endif\n\n \n \n}\n";
  10640. Shaders["pointcloud_new.fs"] = "\n#if defined paraboloid_point_shape\n\t#extension GL_EXT_frag_depth : enable\n#endif\n#define PI 3.141592653589793\n\n\n\nprecision highp float;\nprecision highp int;\n\n/*\n#if defined(usePanoMap) \n \n uniform samplerCube pano0Map; //\u968F\u4FBF\u8BBE\u7F6E\u4E00\u4E2AsamplerCube\u53BB\u4F7F\u7528\u90FD\u4F1A\u8BA9\u70B9\u4E91\u6D88\u5931\n uniform samplerCube pano1Map;\n \n uniform float progress;\n uniform float easeInOutRatio;\n\n \n uniform vec3 pano0Position;\n uniform mat4 pano0Matrix; \n uniform vec3 pano1Position;\n uniform mat4 pano1Matrix;\n varying vec3 vWorldPosition0;\n varying vec3 vWorldPosition1;\n\n#endif \n*/\n\n\n\n//------------\n\n\n\n\n\nuniform mat4 viewMatrix;\nuniform mat4 uViewInv;\nuniform mat4 uProjInv;\nuniform vec3 cameraPosition;\n\n\nuniform mat4 projectionMatrix;\n//uniform float uOpacity;\nvarying float vOpacity; //add\n\nuniform float blendHardness;\nuniform float blendDepthSupplement;\nuniform float fov;\nuniform float uSpacing;\nuniform float near;\nuniform float far;\nuniform float uPCIndex;\nuniform float uScreenWidth;\nuniform float uScreenHeight;\n\nvarying vec3\tvColor;\nvarying float\tvLogDepth;\nvarying vec3\tvViewPosition;\nvarying float\tvRadius;\nvarying float \tvPointSize;\nvarying vec3 \tvPosition;\n\n\nfloat specularStrength = 1.0;\n\n\nvec2 getSamplerCoord( vec3 direction ) \n{\n direction = normalize(direction);\n float tx=atan(direction.x,-direction.y)/(PI*2.0)+0.5;\n float ty=acos(direction.z)/PI;\n\n return vec2(tx,ty);\n} \n\n\n\n\nvoid main() {\n\n vec3 color = vColor; \n\t \n \n /*#if defined(usePanoMap) //\u52A0 \u7ECF\u6D4B\u8BD5\uFF0C\u5373\u4F7F\u5168\u90E8\u5199\u5728fragment\u91CC\u4E5F\u662F\u65E0\u8BBApointsize\u591A\u5927\u90FD\u662F\u4E00\u4E2A\u70B9\u4E00\u4E2A\u989C\u8272\uFF0C\u6240\u4EE5\u5E72\u8106\u5199\u5728vectex\u91CC\n \n \n vec4 colorFromPano0=textureCube(pano0Map,vWorldPosition0.xyz);\n vec4 colorFromPano1=textureCube(pano1Map,vWorldPosition1.xyz);\n \n color = mix(colorFromPano0,colorFromPano1,progress).xyz; \n \n \n //float easeInOutRatio = 0.0; //\u7F13\u51B2\uFF0C\u6E10\u53D8\u70B9\u4E91\u5230\u8D34\u56FE\u7684\u989C\u8272 \n if(progress < easeInOutRatio){\n float easeProgress = (easeInOutRatio - progress) / easeInOutRatio; \n color = mix(color,vColor,easeProgress); \n }else if(progress > 1.0 - easeInOutRatio){ \n float easeProgress = (progress - (1.0 - easeInOutRatio) ) / easeInOutRatio; \n color = mix(color,vColor,easeProgress); \n }\n \n \n #else \n color = vColor;\n #endif*/\n \n \n \n\tfloat depth = gl_FragCoord.z;\n\n\t#if defined(circle_point_shape) || defined(paraboloid_point_shape) \n\t\tfloat u = 2.0 * gl_PointCoord.x - 1.0;\n\t\tfloat v = 2.0 * gl_PointCoord.y - 1.0;\n\t#endif\n\t\n\t#if defined(circle_point_shape) \n\t\tfloat cc = u*u + v*v;\n\t\tif(cc > 1.0){\n\t\t\tdiscard;\n\t\t}\n\t#endif\n\t\n\n \n\n\t\n \n #if defined color_type_indices //pick point recognize\n\t\tgl_FragColor = vec4(color, uPCIndex / 255.0); //uPCIndex : node Index\n\t#else\n\t\tgl_FragColor = vec4(color, vOpacity);\n\t#endif\n \n \n \n \n \n \n \n \n\n\t#if defined paraboloid_point_shape\n\t\tfloat wi = 0.0 - ( u*u + v*v);\n\t\tvec4 pos = vec4(vViewPosition, 1.0);\n\t\tpos.z += wi * vRadius;\n\t\tfloat linearDepth = -pos.z;\n\t\tpos = projectionMatrix * pos;\n\t\tpos = pos / pos.w;\n\t\tfloat expDepth = pos.z;\n\t\tdepth = (pos.z + 1.0) / 2.0;\n\t\tgl_FragDepthEXT = depth;\n\t\tgl_FragDepthEXT = clamp(gl_FragDepthEXT, 0.0, 1.0); //add\n \n \n\t\t#if defined(color_type_depth)\n\t\t\tcolor.r = linearDepth;\n\t\t\tcolor.g = expDepth;\n\t\t#endif\n\t\t\n\t\t#if defined(use_edl)\n\t\t\tgl_FragColor.a = log2(linearDepth);\n\t\t#endif\n\t\t\n\t#else\n\t\t#if defined(use_edl)\n\t\t\tgl_FragColor.a = vLogDepth;\n\t\t#endif\n\t#endif\n\n\t#if defined(weighted_splats)\n\t\tfloat distance = 2.0 * length(gl_PointCoord.xy - 0.5);\n\t\tfloat weight = max(0.0, 1.0 - distance);\n\t\tweight = pow(weight, 1.5);\n\n\t\tgl_FragColor.a = weight;\n\t\tgl_FragColor.xyz = gl_FragColor.xyz * weight;\n\t#endif\n\n\t//gl_FragColor = vec4(0.0, 0.7, 0.0, 1.0);\n\t\n}\n\n\n";
  10641. Shaders["pointcloud_sm.vs"] = "\nprecision mediump float;\nprecision mediump int;\n\nattribute vec3 position;\nattribute vec3 color;\n\nuniform mat4 modelMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\n\nuniform float uScreenWidth;\nuniform float uScreenHeight;\nuniform float near;\nuniform float far;\n\nuniform float uSpacing;\nuniform float uOctreeSize;\nuniform float uLevel;\nuniform float uVNStart;\n\nuniform sampler2D visibleNodes;\n\nvarying float vLinearDepth;\nvarying vec3 vColor;\n\n#define PI 3.141592653589793\n\n\n\n// ---------------------\n// OCTREE\n// ---------------------\n\n#if defined(adaptive_point_size)\n/**\n * number of 1-bits up to inclusive index position\n * number is treated as if it were an integer in the range 0-255\n *\n */\nfloat numberOfOnes(float number, float index){\n\tfloat tmp = mod(number, pow(2.0, index + 1.0));\n\tfloat numOnes = 0.0;\n\tfor(float i = 0.0; i < 8.0; i++){\n\t\tif(mod(tmp, 2.0) != 0.0){\n\t\t\tnumOnes++;\n\t\t}\n\t\ttmp = floor(tmp / 2.0);\n\t}\n\treturn numOnes;\n}\n\n\n/**\n * checks whether the bit at index is 1\n * number is treated as if it were an integer in the range 0-255\n *\n */\nbool isBitSet(float number, float index){\n\treturn mod(floor(number / pow(2.0, index)), 2.0) != 0.0;\n}\n\n\n/**\n * find the LOD at the point position\n */\nfloat getLOD(){\n\t\n\tvec3 offset = vec3(0.0, 0.0, 0.0);\n\tfloat iOffset = uVNStart;\n\tfloat depth = uLevel;\n\tfor(float i = 0.0; i <= 30.0; i++){\n\t\tfloat nodeSizeAtLevel = uOctreeSize / pow(2.0, i + uLevel + 0.0);\n\t\t\n\t\tvec3 index3d = (position-offset) / nodeSizeAtLevel;\n\t\tindex3d = floor(index3d + 0.5);\n\t\tfloat index = 4.0 * index3d.x + 2.0 * index3d.y + index3d.z;\n\t\t\n\t\tvec4 value = texture2D(visibleNodes, vec2(iOffset / 2048.0, 0.0));\n\t\tfloat mask = value.r * 255.0;\n\t\tif(isBitSet(mask, index)){\n\t\t\t// there are more visible child nodes at this position\n\t\t\tiOffset = iOffset + value.g * 255.0 * 256.0 + value.b * 255.0 + numberOfOnes(mask, index - 1.0);\n\t\t\tdepth++;\n\t\t}else{\n\t\t\t// no more visible child nodes at this position\n\t\t\treturn depth;\n\t\t}\n\t\t\n\t\toffset = offset + (vec3(1.0, 1.0, 1.0) * nodeSizeAtLevel * 0.5) * index3d;\n\t}\n\t\t\n\treturn depth;\n}\n\n#endif\n\nfloat getPointSize(){\n\tfloat pointSize = 1.0;\n\t\n\tfloat slope = tan(fov / 2.0);\n\tfloat projFactor = -0.5 * uScreenHeight / (slope * vViewPosition.z);\n\t\n\tfloat r = uOctreeSpacing * 1.5;\n\tvRadius = r;\n\t#if defined fixed_point_size\n\t\tpointSize = size;\n\t#elif defined attenuated_point_size\n\t\tif(uUseOrthographicCamera){\n\t\t\tpointSize = size;\t\t\t\n\t\t}else{\n\t\t\tpointSize = pointSize * projFactor;\n\t\t}\n\t#elif defined adaptive_point_size\n\t\tif(uUseOrthographicCamera) {\n\t\t\tfloat worldSpaceSize = 1.5 * size * r / getPointSizeAttenuation();\n\t\t\tpointSize = (worldSpaceSize / uOrthoWidth) * uScreenWidth;\n\t\t} else {\n\t\t\tfloat worldSpaceSize = 1.5 * size * r / getPointSizeAttenuation();\n\t\t\tpointSize = worldSpaceSize * projFactor;\n\t\t}\n\t#endif\n\n\tpointSize = max(minSize, pointSize);\n\tpointSize = min(maxSize, pointSize);\n\t\n\tvRadius = pointSize / projFactor;\n\n\treturn pointSize;\n}\n\n\nvoid main() {\n\n\tvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\n\tvLinearDepth = gl_Position.w;\n\n\tfloat pointSize = getPointSize();\n\tgl_PointSize = pointSize;\n\n}\n";
  10642. Shaders["pointcloud_sm.fs"] = "\nprecision mediump float;\nprecision mediump int;\n\nvarying vec3 vColor;\nvarying float vLinearDepth;\n\nvoid main() {\n\n\t//gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n\t//gl_FragColor = vec4(vColor, 1.0);\n\t//gl_FragColor = vec4(vLinearDepth, pow(vLinearDepth, 2.0), 0.0, 1.0);\n\tgl_FragColor = vec4(vLinearDepth, vLinearDepth / 30.0, vLinearDepth / 30.0, 1.0);\n\t\n}\n\n\n";
  10643. Shaders["normalize.vs"] = "\nprecision mediump float;\nprecision mediump int;\n\nattribute vec3 position;\nattribute vec2 uv;\n\nuniform mat4 projectionMatrix;\nuniform mat4 modelViewMatrix;\n\nvarying vec2 vUv;\n\nvoid main() {\n\tvUv = uv;\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.0);\n}";
  10644. Shaders["normalize.fs"] = "\n#extension GL_EXT_frag_depth : enable\n\nprecision mediump float;\nprecision mediump int;\n\nuniform sampler2D uWeightMap;\nuniform sampler2D uDepthMap;\n\nvarying vec2 vUv;\n\nvoid main() {\n\tfloat depth = texture2D(uDepthMap, vUv).r;\n\t\n\tif(depth >= 1.0){\n\t\tdiscard;\n\t}\n\n\tgl_FragColor = vec4(depth, 1.0, 0.0, 1.0);\n\n\tvec4 color = texture2D(uWeightMap, vUv); \n\tcolor = color / color.w;\n\t\n\tgl_FragColor = vec4(color.xyz, 1.0); \n\t\n\tgl_FragDepthEXT = depth;\n\n\n}";
  10645. Shaders["normalize_and_edl.fs"] = "\n#extension GL_EXT_frag_depth : enable\n\n// \n// adapted from the EDL shader code from Christian Boucheny in cloud compare:\n// https://github.com/cloudcompare/trunk/tree/master/plugins/qEDL/shaders/EDL\n//\n\nprecision mediump float;\nprecision mediump int;\n\nuniform sampler2D uWeightMap;\nuniform sampler2D uEDLMap;\nuniform sampler2D uDepthMap;\n\nuniform float screenWidth;\nuniform float screenHeight;\nuniform vec2 neighbours[NEIGHBOUR_COUNT];\nuniform float edlStrength;\nuniform float radius;\n\nvarying vec2 vUv;\n\nfloat response(float depth){\n\tvec2 uvRadius = radius / vec2(screenWidth, screenHeight);\n\t\n\tfloat sum = 0.0;\n\t\n\tfor(int i = 0; i < NEIGHBOUR_COUNT; i++){\n\t\tvec2 uvNeighbor = vUv + uvRadius * neighbours[i];\n\t\t\n\t\tfloat neighbourDepth = texture2D(uEDLMap, uvNeighbor).a;\n\n\t\tif(neighbourDepth != 0.0){\n\t\t\tif(depth == 0.0){\n\t\t\t\tsum += 100.0;\n\t\t\t}else{\n\t\t\t\tsum += max(0.0, depth - neighbourDepth);\n\t\t\t}\n\t\t}\n\t}\n\t\n\treturn sum / float(NEIGHBOUR_COUNT);\n}\n\nvoid main() {\n\n\tfloat edlDepth = texture2D(uEDLMap, vUv).a;\n\tfloat res = response(edlDepth);\n\tfloat shade = exp(-res * 300.0 * edlStrength);\n\n\tfloat depth = texture2D(uDepthMap, vUv).r;\n\tif(depth >= 1.0 && res == 0.0){\n\t\tdiscard;\n\t}\n\t\n\tvec4 color = texture2D(uWeightMap, vUv); \n\tcolor = color / color.w;\n\tcolor = color * shade;\n\n\tgl_FragColor = vec4(color.xyz, 1.0); \n\n\tgl_FragDepthEXT = depth;\n}";
  10646. Shaders["edl_new.vs"] = "\nprecision mediump float;\nprecision mediump int;\n\nattribute vec3 position;\nattribute vec2 uv;\n\nuniform mat4 projectionMatrix;\nuniform mat4 modelViewMatrix;\n\nvarying vec2 vUv;\n\nvoid main() {\n\tvUv = uv;\n\t\n\tvec4 mvPosition = modelViewMatrix * vec4(position,1.0);\n\n\tgl_Position = projectionMatrix * mvPosition;\n}";
  10647. Shaders["edl_new.fs"] = "\n#extension GL_EXT_frag_depth : enable\n\n// \n// adapted from the EDL shader code from Christian Boucheny in cloud compare:\n// https://github.com/cloudcompare/trunk/tree/master/plugins/qEDL/shaders/EDL\n//\n\nprecision mediump float;\nprecision mediump int;\n\n//uniform float screenWidth;\n//uniform float screenHeight;\nuniform vec2 resolution;\n\n\nuniform vec2 neighbours[NEIGHBOUR_COUNT];\nuniform float edlStrength;\nuniform float radius;\nuniform float opacity;\n\n//uniform float uNear;\n//uniform float uFar;\n\nuniform mat4 uProj;\n\nuniform sampler2D uEDLColor;\nuniform sampler2D uEDLDepth;\n\nvarying vec2 vUv;\n\nuniform int useEDL;\n\nfloat response(float depth){\n\tvec2 uvRadius = radius / resolution; //vec2(screenWidth, screenHeight);\n\t\n\tfloat sum = 0.0;\n\t\n\tfor(int i = 0; i < NEIGHBOUR_COUNT; i++){\n\t\tvec2 uvNeighbor = vUv + uvRadius * neighbours[i];\n\t\t//\u83B7\u53D6\u5468\u56F4\u516B\u4E2A\u683C\u5B50\u7684\u503C\n\t\tfloat neighbourDepth = texture2D(uEDLColor, uvNeighbor).a;\n\t\tneighbourDepth = (neighbourDepth == 1.0) ? 0.0 : neighbourDepth;\n\n\t\tif(neighbourDepth != 0.0){\n\t\t\t //if(depth == 0.0){\n\t\t\t //\tsum += 100.0;\n\t\t\t //}else{\n\t\t\t\tsum += max(0.0, depth - neighbourDepth); //\u83B7\u53D6\u5DEE\u503C\n\t\t\t //}\n\t\t}\n\t}\n\t\n\treturn sum / float(NEIGHBOUR_COUNT);\n}\n\nvoid main(){\n\tvec4 cEDL = texture2D(uEDLColor, vUv);\n\t\n\tfloat depth = cEDL.a;\n\tdepth = (depth == 1.0) ? 0.0 : depth;\n \n if(depth == 0.0){ //\u53BB\u6389\u8FD9\u53E5\u5C31\u80FD\u5728\u65E0\u70B9\u4E91\u50CF\u7D20\u7684\u5730\u65B9\u6E32\u67D3outline\uFF0C\u4F46\u4F1A\u906E\u4F4F\u5176\u4ED6mesh\n\t\tdiscard;\n\t}\n \n \n if(useEDL == 1){\n float res = response(depth); \n float shade = exp(-res * 300.0 * edlStrength); //\u81EA\u7136\u5E38\u6570e\u4E3A\u5E95\u7684\u6307\u6570\u51FD\u6570 \n const float min = 0.2; //add \u4F7F\u8FB9\u7F18\u8272\u53D8\u6D45 \u8303\u56F4\u4ECE0-1 \u53D8\u4E3Amin-1\n shade = shade * (1.0-min) + min;\n gl_FragColor = vec4(cEDL.rgb * shade, opacity); \n }else{//\u52A0 \u4E0D\u6539\u989C\u8272\u7684\u60C5\u51B5 \n gl_FragColor = vec4(cEDL.rgb, opacity);\n } \n //\u6CE8\u610F\uFF0CedlStrength\u8D8A\u5F3A\uFF0C\u5728\u76F8\u540Cdepth\u7684\u53E0\u653E\u7684\u70B9\u4E91\u95F4\u7684\u8F6E\u5ED3\u7EBF\u989C\u8272\u8D8A\u6DF1\n //\u4F5C\u7528\uFF1A\u52FE\u52D2\u8FB9\u7F18\uFF0C\u5F3A\u5316\u6DF1\u5EA6\u5DEE\u5F02\uFF0C\u6A21\u62DF\u9634\u5F71\uFF0C\u52A0\u5F3A\u7ED3\u6784\u7ACB\u4F53\u611F\n \n { // write regular hyperbolic depth values to depth buffer \u4FEE\u6539\u6DF1\u5EA6\n float dl = pow(2.0, depth);\n\n vec4 dp = uProj * vec4(0.0, 0.0, -dl, 1.0);\n float pz = dp.z / dp.w;\n float fragDepth = (pz + 1.0) / 2.0;\n\n gl_FragDepthEXT = fragDepth;\n }\n\t\n}\n";
  10648. Shaders["blur.vs"] = "\nvarying vec2 vUv;\n\nvoid main() {\n\tvUv = uv;\n\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.0);\n}";
  10649. Shaders["blur.fs"] = "\nuniform mat4 projectionMatrix;\n\nuniform float screenWidth;\nuniform float screenHeight;\nuniform float near;\nuniform float far;\n\nuniform sampler2D map;\n\nvarying vec2 vUv;\n\nvoid main() {\n\n\tfloat dx = 1.0 / screenWidth;\n\tfloat dy = 1.0 / screenHeight;\n\n\tvec3 color = vec3(0.0, 0.0, 0.0);\n\tcolor += texture2D(map, vUv + vec2(-dx, -dy)).rgb;\n\tcolor += texture2D(map, vUv + vec2( 0, -dy)).rgb;\n\tcolor += texture2D(map, vUv + vec2(+dx, -dy)).rgb;\n\tcolor += texture2D(map, vUv + vec2(-dx, 0)).rgb;\n\tcolor += texture2D(map, vUv + vec2( 0, 0)).rgb;\n\tcolor += texture2D(map, vUv + vec2(+dx, 0)).rgb;\n\tcolor += texture2D(map, vUv + vec2(-dx, dy)).rgb;\n\tcolor += texture2D(map, vUv + vec2( 0, dy)).rgb;\n\tcolor += texture2D(map, vUv + vec2(+dx, dy)).rgb;\n\n\tcolor = color / 9.0;\n\t\n\tgl_FragColor = vec4(color, 1.0);\n}";
  10650. Shaders["depthBasic.vs"] = "\n \n\nvarying vec2 vUv;\nvoid main() {\n \n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n} \n ";
  10651. Shaders["depthBasic.fs"] = "varying vec2 vUv;\nuniform float opacity;\nuniform float mapScale;\nuniform vec3 baseColor;\n\n#if defined use_map\n uniform sampler2D map; \n \n vec4 getMapColor(vec4 color){ \n if(mapScale == 1.0){\n color = texture2D(map, vUv) * color; \n return color;\n }else{ \n vec2 uv = (vUv - 0.5) / mapScale + 0.5; \n if(uv.x > 1.0 || uv.y > 1.0 || uv.x < 0.0 || uv.y < 0.0){\n //color = vec4(0.0,0.0,0.0,0.0);\n discard;\n }else{\n color = texture2D(map, uv) * color; \n }\n return color; \n }\n }\n#endif\n \n\n #if defined(GL_EXT_frag_depth) && defined(useDepth)\n //\u4F3C\u4E4E\u901A\u8FC7gl.getExtension('EXT_frag_depth')\u5F97\u5230\u7684GL_EXT_frag_depth\n \n uniform sampler2D depthTexture;\n uniform float nearPlane;\n uniform float farPlane; \n uniform vec2 resolution;\n uniform vec2 viewportOffset; // viewportOffset \u8303\u56F4\u4ECE0-\u6574\u4E2A\u753B\u5E03\u7684\u50CF\u7D20\n uniform vec3 backColor;\n uniform float occlusionDistance;\n uniform float clipDistance;\n uniform float maxClipFactor;\n uniform float maxOcclusionFactor;\n //uniform bool uUseOrthographicCamera; \n\n float convertToLinear(float zValue)\n {\n //if(uUseOrthographicCamera){\n // return zValue*(farPlane-nearPlane)+nearPlane;\n //}else{ \n float z = zValue * 2.0 - 1.0;\n return (2.0 * nearPlane * farPlane) / (farPlane + nearPlane - z * (farPlane - nearPlane));\n //} \n }\n#endif\n \n \n \nvoid main() {\n \n \n vec4 color = vec4(baseColor, opacity);\n \n \n \n #if defined(GL_EXT_frag_depth) && defined(useDepth) \n // mixFactor and clipFactor define the color mixing proportion between the states of\n // full visibility and occluded visibility\n // and\n // full visibility and total invisibility\n \n float mixFactor = 0.0;\n float clipFactor = 0.0;\n \n \n // The linear depth value of the current fragment\n float fragDepth = convertToLinear(gl_FragCoord.z);\n\n // The coordinates of the current fragment in the depth texture\n vec2 depthTxtCoords = vec2(gl_FragCoord.x-viewportOffset.x, gl_FragCoord.y - viewportOffset.y) / resolution;\n //gl_FragCoord\u5927\u5C0F\u4E3A viewport client\u5927\u5C0F \n \n // The linear depth value of the pixel occupied by this fragment in the depth buffer\n float textureDepth = convertToLinear(texture2D(depthTexture, depthTxtCoords).r);\n\n // The difference between the two depths\n float delta = fragDepth - textureDepth;\n\n if (delta > 0.0)//\u5DEE\u8DDD\n {\n // occlusionDistance and clipDistance define the width of the respective zones and\n // mixFactor and clipFactor express the interpolation between the two colors depending on the position\n // of the current fragment withing those zones.\n \n \n mixFactor = clamp(delta / occlusionDistance, 0.0, maxOcclusionFactor);\n clipFactor = clamp(delta / clipDistance, 0.0, maxClipFactor);\n }\n \n // If the fragment is totally transparent, don't bother drawing it\n if (clipFactor == 1.0)\n {\n discard;\n }else{\n \n #if defined use_map\n color = getMapColor(color); \n #endif\n \n \n color = vec4(mix(color.rgb, backColor, mixFactor), color.a * (1.0 - clipFactor));\n }\n \n #else\n #if defined use_map\n color = getMapColor(color); \n #endif \n #endif\n \n gl_FragColor = color;\n \n}\n";
  10652. Shaders["copyCubeMap.vs"] = "varying vec3 vWorldPos;\nvec3 transformAxis( vec3 direction ) //navvis->4dkk\n{\n float y = direction.y;\n direction.y = direction.z;\n direction.z = -y;\n return direction;\n}\nvoid main() {\n vWorldPos = vec3(-position.x, -position.y, position.z);\n //vWorldPos = transformAxis(vWorldPos);\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n} \n ";
  10653. Shaders["copyCubeMap.fs"] = "varying vec3 vWorldPos;\nuniform float alpha;\nuniform samplerCube tDiffuse;\n\n\nvoid main() {\n vec4 texColor = textureCube(tDiffuse, vWorldPos);\n gl_FragColor = vec4(texColor.rgb, texColor.a * alpha);\n} \n ";
  10654. Shaders["basicTextured.vs"] = "varying vec2 vUv;\nvoid main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n} \n ";
  10655. Shaders["basicTextured.fs"] = "varying vec2 vUv;\nuniform float opacity;\n \n\n#ifdef HasMap\n uniform sampler2D map; \n#endif\n#ifdef HasColor\n uniform vec3 color;\n#endif\n\nvoid main() {\n vec4 color_;\n #ifdef HasColor\n color_ = vec4(color, opacity); \n #else\n color_ = vec4(1.0,1.0,1.0, opacity);\n #endif\n \n #ifdef HasMap\n vec4 texColor = texture2D(map, vUv); \n gl_FragColor = texColor * color_;\n \n /*#ifdef InverseColor\n bool inverse = false; //gl_FragColor.r < 0.3 || gl_FragColor.g < 0.3 || gl_FragColor.b < 0.3 ||\n \n //\u6DF1\u8272\u5B57\u548C\u767D\u8272\u5730\u9762\u8981\u53CD\u8F6C\n \n if(gl_FragColor.r > 0.9 && gl_FragColor.g > 0.9 && gl_FragColor.b > 0.9){\n //gl_FragColor.r = 1.0 - gl_FragColor.r;\n //gl_FragColor.g = 1.0 - gl_FragColor.g;\n //gl_FragColor.b = 1.0 - gl_FragColor.b; \n gl_FragColor = vec4(0.07,0.22, 0.5,1.0);\n }else{//\u6D77\u548C\u8349\u576A\u989C\u8272\u52A0\u6DF1\n \n gl_FragColor = texColor * vec4(0.3,0.5,0.7,1.0);\n } \n \n #endif*/\n \n #else\n gl_FragColor = color_;\n #endif\n \n \n}\n";
  10656. Shaders["skybox.vs"] = "uniform mat4 matrix; \nvarying vec3 vWorldPosition;\n\n\n\nvoid main() \n{ \n \n vWorldPosition = (modelMatrix * vec4(position, 1.0)).xyz ; // - cameraPosition; \n vWorldPosition = (vec4(vWorldPosition, 1.0) * matrix).xyz;\n vWorldPosition.x *= -1.0;\n\n\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  10657. Shaders["skybox.fs"] = "varying vec3 vWorldPosition;\nuniform sampler2D tDiffuse; \n\n#define PI 3.141592653 \n\n/*vec2 getSamplerCoord( vec3 direction ) \n{\n direction = normalize(direction);\n float tx=atan(direction.x,direction.z)/(PI*2.0)+0.5;\n float ty=acos(direction.y)/PI;\n\n return vec2(tx,ty);\n}*/\nvec2 getSamplerCoord( vec3 direction ) \n{\n direction = normalize(direction);\n float tx=atan(direction.x,-direction.y)/(PI*2.0)+0.5;\n float ty=acos(direction.z)/PI;\n\n return vec2(tx,ty);\n} \nvoid main() \n{\n vec2 samplerCoord = getSamplerCoord(vWorldPosition);\n vec4 color = texture2D(tDiffuse, samplerCoord);\n //gl_FragColor = RGBEToLinear( color ); //\u5BF9\u4E8Ehdr\u5FC5\u987B\u52A0\u8FD9\u4E00\u53E5\uFF0C\u5426\u5219\u6548\u679C\u5F88\u5947\u602A\u3002copy\u81EAmeshBasicMaterial\u91CC\u7684mat_fragment\u7684mapTexelToLinear\u51FD\u6570\uFF0C\u53EA\u8981\u6709map\u5C31\u4F1A\u4F7F\u7528\u8BE5\u51FD\u6570\n gl_FragColor = color;\n //#include <tonemapping_fragment>\n //////#include <encodings_fragment>\n\n} \n";
  10658. var ClassificationScheme = {
  10659. DEFAULT: {
  10660. 0: {
  10661. visible: true,
  10662. name: 'never classified',
  10663. color: [0.5, 0.5, 0.5, 1.0]
  10664. },
  10665. 1: {
  10666. visible: true,
  10667. name: 'unclassified',
  10668. color: [0.5, 0.5, 0.5, 1.0]
  10669. },
  10670. 2: {
  10671. visible: true,
  10672. name: 'ground',
  10673. color: [0.63, 0.32, 0.18, 1.0]
  10674. },
  10675. 3: {
  10676. visible: true,
  10677. name: 'low vegetation',
  10678. color: [0.0, 1.0, 0.0, 1.0]
  10679. },
  10680. 4: {
  10681. visible: true,
  10682. name: 'medium vegetation',
  10683. color: [0.0, 0.8, 0.0, 1.0]
  10684. },
  10685. 5: {
  10686. visible: true,
  10687. name: 'high vegetation',
  10688. color: [0.0, 0.6, 0.0, 1.0]
  10689. },
  10690. 6: {
  10691. visible: true,
  10692. name: 'building',
  10693. color: [1.0, 0.66, 0.0, 1.0]
  10694. },
  10695. 7: {
  10696. visible: true,
  10697. name: 'low point(noise)',
  10698. color: [1.0, 0.0, 1.0, 1.0]
  10699. },
  10700. 8: {
  10701. visible: true,
  10702. name: 'key-point',
  10703. color: [1.0, 0.0, 0.0, 1.0]
  10704. },
  10705. 9: {
  10706. visible: true,
  10707. name: 'water',
  10708. color: [0.0, 0.0, 1.0, 1.0]
  10709. },
  10710. 12: {
  10711. visible: true,
  10712. name: 'overlap',
  10713. color: [1.0, 1.0, 0.0, 1.0]
  10714. },
  10715. DEFAULT: {
  10716. visible: true,
  10717. name: 'default',
  10718. color: [0.3, 0.6, 0.6, 0.5]
  10719. }
  10720. }
  10721. };
  10722. Object.defineProperty(ClassificationScheme, 'RANDOM', {
  10723. get: function get() {
  10724. var scheme = {};
  10725. for (var i = 0; i <= 255; i++) {
  10726. scheme[i] = new Vector4(Math.random(), Math.random(), Math.random());
  10727. }
  10728. scheme["DEFAULT"] = new Vector4(Math.random(), Math.random(), Math.random());
  10729. return scheme;
  10730. }
  10731. });
  10732. class EnumItem {
  10733. constructor(object) {
  10734. for (var key of Object.keys(object)) {
  10735. this[key] = object[key];
  10736. }
  10737. }
  10738. inspect() {
  10739. return "Enum(".concat(this.name, ": ").concat(this.value, ")");
  10740. }
  10741. }
  10742. ;
  10743. class Enum {
  10744. constructor(object) {
  10745. this.object = object;
  10746. for (var key of Object.keys(object)) {
  10747. var value = object[key];
  10748. if (typeof value === "object") {
  10749. value.name = key;
  10750. } else {
  10751. value = {
  10752. name: key,
  10753. value: value
  10754. };
  10755. }
  10756. this[key] = new EnumItem(value);
  10757. }
  10758. }
  10759. fromValue(value) {
  10760. for (var key of Object.keys(this.object)) {
  10761. if (this[key].value === value) {
  10762. return this[key];
  10763. }
  10764. }
  10765. throw new Error("No enum for value: ".concat(value));
  10766. }
  10767. }
  10768. ;
  10769. var CameraMode = {
  10770. ORTHOGRAPHIC: 0,
  10771. PERSPECTIVE: 1,
  10772. VR: 2
  10773. };
  10774. var ClipTask = {
  10775. NONE: 0,
  10776. HIGHLIGHT: 1,
  10777. SHOW_INSIDE: 2,
  10778. SHOW_OUTSIDE: 3
  10779. };
  10780. var ClipMethod = {
  10781. INSIDE_ANY: 0,
  10782. INSIDE_ALL: 1
  10783. };
  10784. var ElevationGradientRepeat = {
  10785. CLAMP: 0,
  10786. REPEAT: 1,
  10787. MIRRORED_REPEAT: 2
  10788. };
  10789. var MOUSE$1 = {
  10790. LEFT: 0b0001,
  10791. RIGHT: 0b0010,
  10792. MIDDLE: 0b0100
  10793. };
  10794. var PointSizeType = {
  10795. FIXED: 0,
  10796. ATTENUATED: 1,
  10797. ADAPTIVE: 2
  10798. };
  10799. var PointShape$1 = {
  10800. SQUARE: 0,
  10801. CIRCLE: 1,
  10802. PARABOLOID: 2
  10803. };
  10804. var TreeType = {
  10805. OCTREE: 0,
  10806. KDTREE: 1
  10807. };
  10808. var LengthUnits = {
  10809. METER: {
  10810. code: 'm',
  10811. unitspermeter: 1.0
  10812. },
  10813. FEET: {
  10814. code: 'ft',
  10815. unitspermeter: 3.28084
  10816. },
  10817. INCH: {
  10818. code: '\u2033',
  10819. unitspermeter: 39.3701
  10820. }
  10821. };
  10822. //
  10823. // how to calculate the radius of a projected sphere in screen space
  10824. // http://stackoverflow.com/questions/21648630/radius-of-projected-sphere-in-screen-space
  10825. // http://stackoverflow.com/questions/3717226/radius-of-projected-sphere
  10826. //
  10827. class PointCloudMaterial$1 extends RawShaderMaterial {
  10828. //base
  10829. constructor() {
  10830. var parameters = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  10831. super();
  10832. this.visibleNodesTexture = Utils.generateDataTexture(2048, 1, new Color(0xffffff));
  10833. this.visibleNodesTexture.minFilter = NearestFilter;
  10834. this.visibleNodesTexture.magFilter = NearestFilter;
  10835. var getValid = (a, b) => {
  10836. if (a !== undefined) {
  10837. return a;
  10838. } else {
  10839. return b;
  10840. }
  10841. };
  10842. var pointSize = getValid(parameters.size, 1.0);
  10843. var minSize = getValid(parameters.minSize, 2.0);
  10844. var maxSize = getValid(parameters.maxSize, 50.0);
  10845. var treeType = getValid(parameters.treeType, TreeType.OCTREE);
  10846. this._pointSizeType = PointSizeType.FIXED;
  10847. this._shape = PointShape$1.SQUARE;
  10848. this._useClipBox = false;
  10849. this.clipBoxes = [];
  10850. this.clipPolygons = [];
  10851. this._weighted = false;
  10852. this._gradient = Gradients.SPECTRAL;
  10853. this.gradientTexture = PointCloudMaterial$1.generateGradientTexture(this._gradient);
  10854. //this._matcap = "matcap.jpg";
  10855. //this.matcapTexture = PointCloudMaterial.generateMatcapTexture(this._matcap);
  10856. this.lights = false;
  10857. this.fog = false;
  10858. this._treeType = treeType;
  10859. this._useEDL = false;
  10860. this.defines = new Map();
  10861. this.ranges = new Map();
  10862. this._activeAttributeName = null;
  10863. this._defaultIntensityRangeChanged = false;
  10864. this._defaultElevationRangeChanged = false;
  10865. {
  10866. var [width, height] = [256, 1];
  10867. var data = new Uint8Array(width * 4);
  10868. var texture = new DataTexture(data, width, height, RGBAFormat);
  10869. texture.magFilter = NearestFilter;
  10870. texture.needsUpdate = true;
  10871. this.classificationTexture = texture;
  10872. }
  10873. this.attributes = {
  10874. position: {
  10875. type: 'fv',
  10876. value: []
  10877. },
  10878. color: {
  10879. type: 'fv',
  10880. value: []
  10881. },
  10882. normal: {
  10883. type: 'fv',
  10884. value: []
  10885. },
  10886. intensity: {
  10887. type: 'f',
  10888. value: []
  10889. },
  10890. classification: {
  10891. type: 'f',
  10892. value: []
  10893. },
  10894. returnNumber: {
  10895. type: 'f',
  10896. value: []
  10897. },
  10898. numberOfReturns: {
  10899. type: 'f',
  10900. value: []
  10901. },
  10902. pointSourceID: {
  10903. type: 'f',
  10904. value: []
  10905. },
  10906. indices: {
  10907. type: 'fv',
  10908. value: []
  10909. }
  10910. };
  10911. this.uniforms = {
  10912. level: {
  10913. type: "f",
  10914. value: 0.0
  10915. },
  10916. vnStart: {
  10917. type: "f",
  10918. value: 0.0
  10919. },
  10920. spacing: {
  10921. type: "f",
  10922. value: 1.0
  10923. },
  10924. blendHardness: {
  10925. type: "f",
  10926. value: 2.0
  10927. },
  10928. blendDepthSupplement: {
  10929. type: "f",
  10930. value: 0.0
  10931. },
  10932. fov: {
  10933. type: "f",
  10934. value: 1.0
  10935. },
  10936. screenWidth: {
  10937. type: "f",
  10938. value: 1.0
  10939. },
  10940. screenHeight: {
  10941. type: "f",
  10942. value: 1.0
  10943. },
  10944. near: {
  10945. type: "f",
  10946. value: 0.1
  10947. },
  10948. far: {
  10949. type: "f",
  10950. value: 1.0
  10951. },
  10952. uColor: {
  10953. type: "c",
  10954. value: new Color(0xffffff)
  10955. },
  10956. uOpacity: {
  10957. type: "f",
  10958. value: 1.0
  10959. },
  10960. size: {
  10961. type: "f",
  10962. value: pointSize
  10963. },
  10964. minSize: {
  10965. type: "f",
  10966. value: minSize
  10967. },
  10968. maxSize: {
  10969. type: "f",
  10970. value: maxSize
  10971. },
  10972. octreeSize: {
  10973. type: "f",
  10974. value: 0
  10975. },
  10976. bbSize: {
  10977. type: "fv",
  10978. value: [0, 0, 0]
  10979. },
  10980. elevationRange: {
  10981. type: "2fv",
  10982. value: [0, 0]
  10983. },
  10984. clipBoxCount: {
  10985. type: "f",
  10986. value: 0
  10987. },
  10988. //clipSphereCount: { type: "f", value: 0 },
  10989. clipPolygonCount: {
  10990. type: "i",
  10991. value: 0
  10992. },
  10993. clipBoxes: {
  10994. type: "Matrix4fv",
  10995. value: []
  10996. },
  10997. //clipSpheres: { type: "Matrix4fv", value: [] },
  10998. clipPolygons: {
  10999. type: "3fv",
  11000. value: []
  11001. },
  11002. clipPolygonVCount: {
  11003. type: "iv",
  11004. value: []
  11005. },
  11006. clipPolygonVP: {
  11007. type: "Matrix4fv",
  11008. value: []
  11009. },
  11010. visibleNodes: {
  11011. type: "t",
  11012. value: this.visibleNodesTexture
  11013. },
  11014. pcIndex: {
  11015. type: "f",
  11016. value: 0
  11017. },
  11018. gradient: {
  11019. type: "t",
  11020. value: this.gradientTexture
  11021. },
  11022. classificationLUT: {
  11023. type: "t",
  11024. value: this.classificationTexture
  11025. },
  11026. uHQDepthMap: {
  11027. type: "t",
  11028. value: null
  11029. },
  11030. toModel: {
  11031. type: "Matrix4f",
  11032. value: []
  11033. },
  11034. diffuse: {
  11035. type: "fv",
  11036. value: [1, 1, 1]
  11037. },
  11038. transition: {
  11039. type: "f",
  11040. value: 0.5
  11041. },
  11042. intensityRange: {
  11043. type: "fv",
  11044. value: [Infinity, -Infinity]
  11045. },
  11046. intensity_gbc: {
  11047. type: "fv",
  11048. value: [1, 0, 0]
  11049. },
  11050. uRGB_gbc: {
  11051. type: "fv",
  11052. value: [1, 0, 0]
  11053. },
  11054. // intensityGamma: { type: "f", value: 1 },
  11055. // intensityContrast: { type: "f", value: 0 },
  11056. // intensityBrightness:{ type: "f", value: 0 },
  11057. // rgbGamma: { type: "f", value: 1 },
  11058. // rgbContrast: { type: "f", value: 0 },
  11059. // rgbBrightness: { type: "f", value: 0 },
  11060. wRGB: {
  11061. type: "f",
  11062. value: 1
  11063. },
  11064. wIntensity: {
  11065. type: "f",
  11066. value: 0
  11067. },
  11068. wElevation: {
  11069. type: "f",
  11070. value: 0
  11071. },
  11072. wClassification: {
  11073. type: "f",
  11074. value: 0
  11075. },
  11076. wReturnNumber: {
  11077. type: "f",
  11078. value: 0
  11079. },
  11080. wSourceID: {
  11081. type: "f",
  11082. value: 0
  11083. },
  11084. useOrthographicCamera: {
  11085. type: "b",
  11086. value: false
  11087. },
  11088. elevationGradientRepat: {
  11089. type: "i",
  11090. value: ElevationGradientRepeat.CLAMP
  11091. },
  11092. clipTask: {
  11093. type: "i",
  11094. value: 1
  11095. },
  11096. clipMethod: {
  11097. type: "i",
  11098. value: 1
  11099. },
  11100. uShadowColor: {
  11101. type: "3fv",
  11102. value: [0, 0, 0]
  11103. },
  11104. uExtraScale: {
  11105. type: "f",
  11106. value: 1
  11107. },
  11108. uExtraOffset: {
  11109. type: "f",
  11110. value: 0
  11111. },
  11112. uExtraRange: {
  11113. type: "2fv",
  11114. value: [0, 1]
  11115. },
  11116. uExtraGammaBrightContr: {
  11117. type: "3fv",
  11118. value: [1, 0, 0]
  11119. },
  11120. uFilterReturnNumberRange: {
  11121. type: "fv",
  11122. value: [0, 7]
  11123. },
  11124. uFilterNumberOfReturnsRange: {
  11125. type: "fv",
  11126. value: [0, 7]
  11127. },
  11128. uFilterGPSTimeClipRange: {
  11129. type: "fv",
  11130. value: [0, 7]
  11131. },
  11132. uFilterPointSourceIDClipRange: {
  11133. type: "fv",
  11134. value: [0, 65535]
  11135. },
  11136. //matcapTextureUniform: { type: "t", value: this.matcapTexture },
  11137. backfaceCulling: {
  11138. type: "b",
  11139. value: false
  11140. }
  11141. };
  11142. this.classification = ClassificationScheme.DEFAULT;
  11143. this.defaultAttributeValues.normal = [0, 0, 0];
  11144. this.defaultAttributeValues.classification = [0, 0, 0];
  11145. this.defaultAttributeValues.indices = [0, 0, 0, 0];
  11146. this.vertexShader = Shaders['pointcloud.vs'];
  11147. this.fragmentShader = Shaders['pointcloud.fs'];
  11148. this.vertexColors = VertexColors;
  11149. this.updateShaderSource();
  11150. }
  11151. setDefine(key, value) {
  11152. if (value !== undefined && value !== null) {
  11153. if (this.defines.get(key) !== value) {
  11154. this.defines.set(key, value);
  11155. this.updateShaderSource();
  11156. }
  11157. } else {
  11158. this.removeDefine(key);
  11159. }
  11160. }
  11161. removeDefine(key) {
  11162. this.defines.delete(key);
  11163. }
  11164. updateShaderSource() {
  11165. var vs = Shaders['pointcloud.vs'];
  11166. var fs = Shaders['pointcloud.fs'];
  11167. var definesString = this.getDefines();
  11168. var vsVersionIndex = vs.indexOf("#version ");
  11169. var fsVersionIndex = fs.indexOf("#version ");
  11170. if (vsVersionIndex >= 0) {
  11171. vs = vs.replace(/(#version .*)/, "$1\n".concat(definesString));
  11172. } else {
  11173. vs = "".concat(definesString, "\n").concat(vs);
  11174. }
  11175. if (fsVersionIndex >= 0) {
  11176. fs = fs.replace(/(#version .*)/, "$1\n".concat(definesString));
  11177. } else {
  11178. fs = "".concat(definesString, "\n").concat(fs);
  11179. }
  11180. this.vertexShader = vs;
  11181. this.fragmentShader = fs;
  11182. if (this.opacity === 1.0) {
  11183. this.blending = NoBlending;
  11184. this.transparent = false;
  11185. this.depthTest = true;
  11186. this.depthWrite = true;
  11187. this.depthFunc = LessEqualDepth;
  11188. } else if (this.opacity < 1.0 && !this.useEDL) {
  11189. this.blending = AdditiveBlending;
  11190. this.transparent = true;
  11191. this.depthTest = false;
  11192. this.depthWrite = true;
  11193. this.depthFunc = AlwaysDepth;
  11194. }
  11195. if (this.weighted) {
  11196. this.blending = AdditiveBlending;
  11197. this.transparent = true;
  11198. this.depthTest = true;
  11199. this.depthWrite = false;
  11200. }
  11201. this.needsUpdate = true;
  11202. }
  11203. getDefines() {
  11204. var defines = [];
  11205. if (this.pointSizeType === PointSizeType.FIXED) {
  11206. defines.push('#define fixed_point_size');
  11207. } else if (this.pointSizeType === PointSizeType.ATTENUATED) {
  11208. defines.push('#define attenuated_point_size');
  11209. } else if (this.pointSizeType === PointSizeType.ADAPTIVE) {
  11210. defines.push('#define adaptive_point_size');
  11211. }
  11212. if (this.shape === PointShape$1.SQUARE) {
  11213. defines.push('#define square_point_shape');
  11214. } else if (this.shape === PointShape$1.CIRCLE) {
  11215. defines.push('#define circle_point_shape');
  11216. } else if (this.shape === PointShape$1.PARABOLOID) {
  11217. defines.push('#define paraboloid_point_shape');
  11218. }
  11219. if (this._useEDL) {
  11220. defines.push('#define use_edl');
  11221. }
  11222. if (this.activeAttributeName) {
  11223. var attributeName = this.activeAttributeName.replace(/[^a-zA-Z0-9]/g, '_');
  11224. defines.push("#define color_type_".concat(attributeName));
  11225. }
  11226. if (this._treeType === TreeType.OCTREE) {
  11227. defines.push('#define tree_type_octree');
  11228. } else if (this._treeType === TreeType.KDTREE) {
  11229. defines.push('#define tree_type_kdtree');
  11230. }
  11231. if (this.weighted) {
  11232. defines.push('#define weighted_splats');
  11233. }
  11234. for (var [key, value] of this.defines) {
  11235. defines.push(value);
  11236. }
  11237. return defines.join("\n");
  11238. }
  11239. setClipBoxes(clipBoxes) {
  11240. if (!clipBoxes) {
  11241. return;
  11242. }
  11243. var doUpdate = this.clipBoxes.length !== clipBoxes.length && (clipBoxes.length === 0 || this.clipBoxes.length === 0);
  11244. this.uniforms.clipBoxCount.value = this.clipBoxes.length;
  11245. this.clipBoxes = clipBoxes;
  11246. if (doUpdate) {
  11247. this.updateShaderSource();
  11248. }
  11249. this.uniforms.clipBoxes.value = new Float32Array(this.clipBoxes.length * 16);
  11250. for (var i = 0; i < this.clipBoxes.length; i++) {
  11251. var box = clipBoxes[i];
  11252. this.uniforms.clipBoxes.value.set(box.inverse.elements, 16 * i);
  11253. }
  11254. for (var _i = 0; _i < this.uniforms.clipBoxes.value.length; _i++) {
  11255. if (Number.isNaN(this.uniforms.clipBoxes.value[_i])) {
  11256. this.uniforms.clipBoxes.value[_i] = Infinity;
  11257. }
  11258. }
  11259. }
  11260. setClipPolygons(clipPolygons, maxPolygonVertices) {
  11261. if (!clipPolygons) {
  11262. return;
  11263. }
  11264. this.clipPolygons = clipPolygons;
  11265. var doUpdate = this.clipPolygons.length !== clipPolygons.length;
  11266. if (doUpdate) {
  11267. this.updateShaderSource();
  11268. }
  11269. }
  11270. get gradient() {
  11271. return this._gradient;
  11272. }
  11273. set gradient(value) {
  11274. //海拔贴图
  11275. if (this._gradient !== value) {
  11276. this._gradient = value;
  11277. this.gradientTexture = PointCloudMaterial$1.generateGradientTexture(this._gradient);
  11278. this.uniforms.gradient.value = this.gradientTexture;
  11279. }
  11280. }
  11281. /* get matcap(){
  11282. return this._matcap;
  11283. }
  11284. set matcap (value) {
  11285. if (this._matcap !== value) {
  11286. this._matcap = value;
  11287. this.matcapTexture = Potree.PointCloudMaterial.generateMatcapTexture(this._matcap);
  11288. this.uniforms.matcapTextureUniform.value = this.matcapTexture;
  11289. }
  11290. } */
  11291. get useOrthographicCamera() {
  11292. return this.uniforms.useOrthographicCamera.value;
  11293. }
  11294. set useOrthographicCamera(value) {
  11295. if (this.uniforms.useOrthographicCamera.value !== value) {
  11296. this.uniforms.useOrthographicCamera.value = value;
  11297. }
  11298. }
  11299. get backfaceCulling() {
  11300. return this.uniforms.backfaceCulling.value;
  11301. }
  11302. set backfaceCulling(value) {
  11303. if (this.uniforms.backfaceCulling.value !== value) {
  11304. this.uniforms.backfaceCulling.value = value;
  11305. this.dispatchEvent({
  11306. type: 'backface_changed',
  11307. target: this
  11308. });
  11309. }
  11310. }
  11311. recomputeClassification() {
  11312. var classification = this.classification;
  11313. var data = this.classificationTexture.image.data;
  11314. var width = 256;
  11315. var black = [1, 1, 1, 1];
  11316. var valuesChanged = false;
  11317. for (var i = 0; i < width; i++) {
  11318. var color = void 0;
  11319. var visible = true;
  11320. if (classification[i]) {
  11321. color = classification[i].color;
  11322. visible = classification[i].visible;
  11323. } else if (classification[i % 32]) {
  11324. color = classification[i % 32].color;
  11325. visible = classification[i % 32].visible;
  11326. } else if (classification.DEFAULT) {
  11327. color = classification.DEFAULT.color;
  11328. visible = classification.DEFAULT.visible;
  11329. } else {
  11330. color = black;
  11331. }
  11332. var r = parseInt(255 * color[0]);
  11333. var g = parseInt(255 * color[1]);
  11334. var b = parseInt(255 * color[2]);
  11335. var a = visible ? parseInt(255 * color[3]) : 0;
  11336. if (data[4 * i + 0] !== r) {
  11337. data[4 * i + 0] = r;
  11338. valuesChanged = true;
  11339. }
  11340. if (data[4 * i + 1] !== g) {
  11341. data[4 * i + 1] = g;
  11342. valuesChanged = true;
  11343. }
  11344. if (data[4 * i + 2] !== b) {
  11345. data[4 * i + 2] = b;
  11346. valuesChanged = true;
  11347. }
  11348. if (data[4 * i + 3] !== a) {
  11349. data[4 * i + 3] = a;
  11350. valuesChanged = true;
  11351. }
  11352. }
  11353. if (valuesChanged) {
  11354. this.classificationTexture.needsUpdate = true;
  11355. this.dispatchEvent({
  11356. type: 'material_property_changed',
  11357. target: this
  11358. });
  11359. }
  11360. }
  11361. get spacing() {
  11362. return this.uniforms.spacing.value;
  11363. }
  11364. set spacing(value) {
  11365. if (this.uniforms.spacing.value !== value) {
  11366. // 即 uOctreeSpacing 来自cloud.js里
  11367. this.uniforms.spacing.value = value;
  11368. }
  11369. }
  11370. get useClipBox() {
  11371. return this._useClipBox;
  11372. }
  11373. set useClipBox(value) {
  11374. if (this._useClipBox !== value) {
  11375. this._useClipBox = value;
  11376. this.updateShaderSource();
  11377. }
  11378. }
  11379. get clipTask() {
  11380. return this.uniforms.clipTask.value;
  11381. }
  11382. set clipTask(mode) {
  11383. this.uniforms.clipTask.value = mode;
  11384. }
  11385. get elevationGradientRepat() {
  11386. return this.uniforms.elevationGradientRepat.value;
  11387. }
  11388. set elevationGradientRepat(mode) {
  11389. this.uniforms.elevationGradientRepat.value = mode;
  11390. }
  11391. get clipMethod() {
  11392. return this.uniforms.clipMethod.value;
  11393. }
  11394. set clipMethod(mode) {
  11395. this.uniforms.clipMethod.value = mode;
  11396. }
  11397. get weighted() {
  11398. return this._weighted;
  11399. }
  11400. set weighted(value) {
  11401. if (this._weighted !== value) {
  11402. this._weighted = value;
  11403. this.updateShaderSource();
  11404. }
  11405. }
  11406. get fov() {
  11407. return this.uniforms.fov.value;
  11408. }
  11409. set fov(value) {
  11410. if (this.uniforms.fov.value !== value) {
  11411. this.uniforms.fov.value = value;
  11412. // this.updateShaderSource();
  11413. }
  11414. }
  11415. get screenWidth() {
  11416. return this.uniforms.screenWidth.value;
  11417. }
  11418. set screenWidth(value) {
  11419. if (this.uniforms.screenWidth.value !== value) {
  11420. this.uniforms.screenWidth.value = value;
  11421. // this.updateShaderSource();
  11422. }
  11423. }
  11424. get screenHeight() {
  11425. return this.uniforms.screenHeight.value;
  11426. }
  11427. set screenHeight(value) {
  11428. if (this.uniforms.screenHeight.value !== value) {
  11429. this.uniforms.screenHeight.value = value;
  11430. // this.updateShaderSource();
  11431. }
  11432. }
  11433. get near() {
  11434. return this.uniforms.near.value;
  11435. }
  11436. set near(value) {
  11437. if (this.uniforms.near.value !== value) {
  11438. this.uniforms.near.value = value;
  11439. }
  11440. }
  11441. get far() {
  11442. return this.uniforms.far.value;
  11443. }
  11444. set far(value) {
  11445. if (this.uniforms.far.value !== value) {
  11446. this.uniforms.far.value = value;
  11447. }
  11448. }
  11449. get opacity() {
  11450. return this.uniforms.uOpacity.value;
  11451. }
  11452. set opacity(value) {
  11453. if (this.uniforms && this.uniforms.uOpacity) {
  11454. if (this.uniforms.uOpacity.value !== value) {
  11455. this.uniforms.uOpacity.value = value;
  11456. this.updateShaderSource();
  11457. this.dispatchEvent({
  11458. type: 'opacity_changed',
  11459. target: this
  11460. });
  11461. this.dispatchEvent({
  11462. type: 'material_property_changed',
  11463. target: this
  11464. });
  11465. }
  11466. }
  11467. }
  11468. get activeAttributeName() {
  11469. return this._activeAttributeName;
  11470. }
  11471. set activeAttributeName(value) {
  11472. if (this._activeAttributeName !== value) {
  11473. this._activeAttributeName = value;
  11474. this.updateShaderSource();
  11475. this.dispatchEvent({
  11476. type: 'active_attribute_changed',
  11477. target: this
  11478. });
  11479. this.dispatchEvent({
  11480. type: 'material_property_changed',
  11481. target: this
  11482. });
  11483. }
  11484. }
  11485. get pointSizeType() {
  11486. return this._pointSizeType;
  11487. }
  11488. set pointSizeType(value) {
  11489. if (this._pointSizeType !== value) {
  11490. this._pointSizeType = value;
  11491. this.updateShaderSource(); //这句表明这个属性频繁更改会卡顿
  11492. this.dispatchEvent({
  11493. type: 'point_size_type_changed',
  11494. target: this
  11495. });
  11496. this.dispatchEvent({
  11497. type: 'material_property_changed',
  11498. target: this
  11499. });
  11500. }
  11501. }
  11502. get useEDL() {
  11503. return this._useEDL;
  11504. }
  11505. set useEDL(value) {
  11506. if (this._useEDL !== value) {
  11507. this._useEDL = value;
  11508. this.updateShaderSource();
  11509. }
  11510. }
  11511. get color() {
  11512. return this.uniforms.uColor.value;
  11513. }
  11514. set color(value) {
  11515. if (!this.uniforms.uColor.value.equals(value)) {
  11516. this.uniforms.uColor.value.copy(value);
  11517. this.dispatchEvent({
  11518. type: 'color_changed',
  11519. target: this
  11520. });
  11521. this.dispatchEvent({
  11522. type: 'material_property_changed',
  11523. target: this
  11524. });
  11525. }
  11526. }
  11527. get shape() {
  11528. return this._shape;
  11529. }
  11530. set shape(value) {
  11531. if (this._shape !== value) {
  11532. this._shape = value;
  11533. this.updateShaderSource();
  11534. this.dispatchEvent({
  11535. type: 'point_shape_changed',
  11536. target: this
  11537. });
  11538. this.dispatchEvent({
  11539. type: 'material_property_changed',
  11540. target: this
  11541. });
  11542. }
  11543. }
  11544. get treeType() {
  11545. return this._treeType;
  11546. }
  11547. set treeType(value) {
  11548. if (this._treeType !== value) {
  11549. this._treeType = value;
  11550. this.updateShaderSource();
  11551. }
  11552. }
  11553. get bbSize() {
  11554. return this.uniforms.bbSize.value;
  11555. }
  11556. set bbSize(value) {
  11557. this.uniforms.bbSize.value = value;
  11558. }
  11559. get size() {
  11560. return this.uniforms.size.value;
  11561. }
  11562. set size(value) {
  11563. if (this.uniforms.size.value !== value) {
  11564. this.uniforms.size.value = value;
  11565. this.dispatchEvent({
  11566. type: 'point_size_changed',
  11567. target: this
  11568. });
  11569. this.dispatchEvent({
  11570. type: 'material_property_changed',
  11571. target: this
  11572. });
  11573. }
  11574. }
  11575. get minSize() {
  11576. return this.uniforms.minSize.value;
  11577. }
  11578. set minSize(value) {
  11579. if (this.uniforms.minSize.value !== value) {
  11580. this.uniforms.minSize.value = value;
  11581. this.dispatchEvent({
  11582. type: 'point_size_changed',
  11583. target: this
  11584. });
  11585. this.dispatchEvent({
  11586. type: 'material_property_changed',
  11587. target: this
  11588. });
  11589. }
  11590. }
  11591. get elevationRange() {
  11592. return this.uniforms.elevationRange.value;
  11593. }
  11594. set elevationRange(value) {
  11595. var changed = this.uniforms.elevationRange.value[0] !== value[0] || this.uniforms.elevationRange.value[1] !== value[1];
  11596. if (changed) {
  11597. this.uniforms.elevationRange.value = value;
  11598. this._defaultElevationRangeChanged = true;
  11599. this.dispatchEvent({
  11600. type: 'material_property_changed',
  11601. target: this
  11602. });
  11603. }
  11604. }
  11605. get heightMin() {
  11606. return this.uniforms.elevationRange.value[0];
  11607. }
  11608. set heightMin(value) {
  11609. this.elevationRange = [value, this.elevationRange[1]];
  11610. }
  11611. get heightMax() {
  11612. return this.uniforms.elevationRange.value[1];
  11613. }
  11614. set heightMax(value) {
  11615. this.elevationRange = [this.elevationRange[0], value];
  11616. }
  11617. get transition() {
  11618. return this.uniforms.transition.value;
  11619. }
  11620. set transition(value) {
  11621. this.uniforms.transition.value = value;
  11622. }
  11623. get intensityRange() {
  11624. return this.uniforms.intensityRange.value;
  11625. }
  11626. set intensityRange(value) {
  11627. if (!(value instanceof Array && value.length === 2)) {
  11628. return;
  11629. }
  11630. if (value[0] === this.uniforms.intensityRange.value[0] && value[1] === this.uniforms.intensityRange.value[1]) {
  11631. return;
  11632. }
  11633. this.uniforms.intensityRange.value = value;
  11634. this._defaultIntensityRangeChanged = true;
  11635. this.dispatchEvent({
  11636. type: 'material_property_changed',
  11637. target: this
  11638. });
  11639. }
  11640. get intensityGamma() {
  11641. return this.uniforms.intensity_gbc.value[0];
  11642. }
  11643. set intensityGamma(value) {
  11644. if (this.uniforms.intensity_gbc.value[0] !== value) {
  11645. this.uniforms.intensity_gbc.value[0] = value;
  11646. this.dispatchEvent({
  11647. type: 'material_property_changed',
  11648. target: this
  11649. });
  11650. }
  11651. }
  11652. get intensityContrast() {
  11653. return this.uniforms.intensity_gbc.value[2];
  11654. }
  11655. set intensityContrast(value) {
  11656. if (this.uniforms.intensity_gbc.value[2] !== value) {
  11657. this.uniforms.intensity_gbc.value[2] = value;
  11658. this.dispatchEvent({
  11659. type: 'material_property_changed',
  11660. target: this
  11661. });
  11662. }
  11663. }
  11664. get intensityBrightness() {
  11665. return this.uniforms.intensity_gbc.value[1];
  11666. }
  11667. set intensityBrightness(value) {
  11668. if (this.uniforms.intensity_gbc.value[1] !== value) {
  11669. this.uniforms.intensity_gbc.value[1] = value;
  11670. this.dispatchEvent({
  11671. type: 'material_property_changed',
  11672. target: this
  11673. });
  11674. }
  11675. }
  11676. get rgbGamma() {
  11677. return this.uniforms.uRGB_gbc.value[0];
  11678. }
  11679. set rgbGamma(value) {
  11680. if (this.uniforms.uRGB_gbc.value[0] !== value) {
  11681. this.uniforms.uRGB_gbc.value[0] = value;
  11682. this.dispatchEvent({
  11683. type: 'material_property_changed',
  11684. target: this
  11685. });
  11686. }
  11687. }
  11688. get rgbContrast() {
  11689. return this.uniforms.uRGB_gbc.value[2];
  11690. }
  11691. set rgbContrast(value) {
  11692. if (this.uniforms.uRGB_gbc.value[2] !== value) {
  11693. this.uniforms.uRGB_gbc.value[2] = value;
  11694. this.dispatchEvent({
  11695. type: 'material_property_changed',
  11696. target: this
  11697. });
  11698. }
  11699. }
  11700. get rgbBrightness() {
  11701. return this.uniforms.uRGB_gbc.value[1];
  11702. }
  11703. set rgbBrightness(value) {
  11704. if (this.uniforms.uRGB_gbc.value[1] !== value) {
  11705. this.uniforms.uRGB_gbc.value[1] = value;
  11706. this.dispatchEvent({
  11707. type: 'material_property_changed',
  11708. target: this
  11709. });
  11710. }
  11711. }
  11712. get extraGamma() {
  11713. return this.uniforms.uExtraGammaBrightContr.value[0];
  11714. }
  11715. set extraGamma(value) {
  11716. if (this.uniforms.uExtraGammaBrightContr.value[0] !== value) {
  11717. this.uniforms.uExtraGammaBrightContr.value[0] = value;
  11718. this.dispatchEvent({
  11719. type: 'material_property_changed',
  11720. target: this
  11721. });
  11722. }
  11723. }
  11724. get extraBrightness() {
  11725. return this.uniforms.uExtraGammaBrightContr.value[1];
  11726. }
  11727. set extraBrightness(value) {
  11728. if (this.uniforms.uExtraGammaBrightContr.value[1] !== value) {
  11729. this.uniforms.uExtraGammaBrightContr.value[1] = value;
  11730. this.dispatchEvent({
  11731. type: 'material_property_changed',
  11732. target: this
  11733. });
  11734. }
  11735. }
  11736. get extraContrast() {
  11737. return this.uniforms.uExtraGammaBrightContr.value[2];
  11738. }
  11739. set extraContrast(value) {
  11740. if (this.uniforms.uExtraGammaBrightContr.value[2] !== value) {
  11741. this.uniforms.uExtraGammaBrightContr.value[2] = value;
  11742. this.dispatchEvent({
  11743. type: 'material_property_changed',
  11744. target: this
  11745. });
  11746. }
  11747. }
  11748. getRange(attributeName) {
  11749. return this.ranges.get(attributeName);
  11750. }
  11751. setRange(attributeName, newRange) {
  11752. var rangeChanged = false;
  11753. var oldRange = this.ranges.get(attributeName);
  11754. if (oldRange != null && newRange != null) {
  11755. rangeChanged = oldRange[0] !== newRange[0] || oldRange[1] !== newRange[1];
  11756. } else {
  11757. rangeChanged = true;
  11758. }
  11759. this.ranges.set(attributeName, newRange);
  11760. if (rangeChanged) {
  11761. this.dispatchEvent({
  11762. type: 'material_property_changed',
  11763. target: this
  11764. });
  11765. }
  11766. }
  11767. get extraRange() {
  11768. return this.uniforms.uExtraRange.value;
  11769. }
  11770. set extraRange(value) {
  11771. if (!(value instanceof Array && value.length === 2)) {
  11772. return;
  11773. }
  11774. if (value[0] === this.uniforms.uExtraRange.value[0] && value[1] === this.uniforms.uExtraRange.value[1]) {
  11775. return;
  11776. }
  11777. this.uniforms.uExtraRange.value = value;
  11778. this._defaultExtraRangeChanged = true;
  11779. this.dispatchEvent({
  11780. type: 'material_property_changed',
  11781. target: this
  11782. });
  11783. }
  11784. get weightRGB() {
  11785. return this.uniforms.wRGB.value;
  11786. }
  11787. set weightRGB(value) {
  11788. if (this.uniforms.wRGB.value !== value) {
  11789. this.uniforms.wRGB.value = value;
  11790. this.dispatchEvent({
  11791. type: 'material_property_changed',
  11792. target: this
  11793. });
  11794. }
  11795. }
  11796. get weightIntensity() {
  11797. return this.uniforms.wIntensity.value;
  11798. }
  11799. set weightIntensity(value) {
  11800. if (this.uniforms.wIntensity.value !== value) {
  11801. this.uniforms.wIntensity.value = value;
  11802. this.dispatchEvent({
  11803. type: 'material_property_changed',
  11804. target: this
  11805. });
  11806. }
  11807. }
  11808. get weightElevation() {
  11809. return this.uniforms.wElevation.value;
  11810. }
  11811. set weightElevation(value) {
  11812. if (this.uniforms.wElevation.value !== value) {
  11813. this.uniforms.wElevation.value = value;
  11814. this.dispatchEvent({
  11815. type: 'material_property_changed',
  11816. target: this
  11817. });
  11818. }
  11819. }
  11820. get weightClassification() {
  11821. return this.uniforms.wClassification.value;
  11822. }
  11823. set weightClassification(value) {
  11824. if (this.uniforms.wClassification.value !== value) {
  11825. this.uniforms.wClassification.value = value;
  11826. this.dispatchEvent({
  11827. type: 'material_property_changed',
  11828. target: this
  11829. });
  11830. }
  11831. }
  11832. get weightReturnNumber() {
  11833. return this.uniforms.wReturnNumber.value;
  11834. }
  11835. set weightReturnNumber(value) {
  11836. if (this.uniforms.wReturnNumber.value !== value) {
  11837. this.uniforms.wReturnNumber.value = value;
  11838. this.dispatchEvent({
  11839. type: 'material_property_changed',
  11840. target: this
  11841. });
  11842. }
  11843. }
  11844. get weightSourceID() {
  11845. return this.uniforms.wSourceID.value;
  11846. }
  11847. set weightSourceID(value) {
  11848. if (this.uniforms.wSourceID.value !== value) {
  11849. this.uniforms.wSourceID.value = value;
  11850. this.dispatchEvent({
  11851. type: 'material_property_changed',
  11852. target: this
  11853. });
  11854. }
  11855. }
  11856. static generateGradientTexture(gradient) {
  11857. var size = 64;
  11858. // create canvas
  11859. var canvas = document.createElement('canvas');
  11860. canvas.width = size;
  11861. canvas.height = size;
  11862. // get context
  11863. var context = canvas.getContext('2d');
  11864. // draw gradient
  11865. context.rect(0, 0, size, size);
  11866. var ctxGradient = context.createLinearGradient(0, 0, size, size);
  11867. for (var i = 0; i < gradient.length; i++) {
  11868. var step = gradient[i];
  11869. ctxGradient.addColorStop(step[0], '#' + step[1].getHexString());
  11870. }
  11871. context.fillStyle = ctxGradient;
  11872. context.fill();
  11873. //let texture = new THREE.Texture(canvas);
  11874. var texture = new CanvasTexture(canvas);
  11875. texture.needsUpdate = true;
  11876. texture.minFilter = LinearFilter;
  11877. texture.wrap = RepeatWrapping;
  11878. texture.repeat = 2;
  11879. // textureImage = texture.image;
  11880. return texture;
  11881. }
  11882. static generateMatcapTexture(matcap) {
  11883. var url = new URL(Potree.resourcePath + "/textures/matcap/" + matcap).href;
  11884. var texture = new TextureLoader().load(url);
  11885. texture.magFilter = texture.minFilter = LinearFilter;
  11886. texture.needsUpdate = true;
  11887. // PotreeConverter_1.6_2018_07_29_windows_x64\PotreeConverter.exe autzen_xyzrgbXYZ_ascii.xyz -f xyzrgbXYZ -a RGB NORMAL -o autzen_xyzrgbXYZ_ascii_a -p index --overwrite
  11888. // Switch matcap texture on the fly : viewer.scene.pointclouds[0].material.matcap = 'matcap1.jpg';
  11889. // For non power of 2, use LinearFilter and dont generate mipmaps, For power of 2, use NearestFilter and generate mipmaps : matcap2.jpg 1 2 8 11 12 13
  11890. return texture;
  11891. }
  11892. disableEvents() {
  11893. if (this._hiddenListeners === undefined) {
  11894. this._hiddenListeners = this._listeners;
  11895. this._listeners = {};
  11896. }
  11897. }
  11898. enableEvents() {
  11899. this._listeners = this._hiddenListeners;
  11900. this._hiddenListeners = undefined;
  11901. }
  11902. } // copyFrom(from){
  11903. // var a = 10;
  11904. // for(let name of Object.keys(this.uniforms)){
  11905. // this.uniforms[name].value = from.uniforms[name].value;
  11906. // }
  11907. // }
  11908. // copy(from){
  11909. // this.copyFrom(from);
  11910. // }
  11911. //见ExtendPointCloudOctree
  11912. class PointCloudOctreeNode extends PointCloudTreeNode {
  11913. constructor() {
  11914. super();
  11915. //this.children = {};
  11916. this.children = [];
  11917. this.sceneNode = null;
  11918. this.octree = null;
  11919. }
  11920. getNumPoints() {
  11921. return this.geometryNode.numPoints;
  11922. }
  11923. isLoaded() {
  11924. return true;
  11925. }
  11926. isTreeNode() {
  11927. return true;
  11928. }
  11929. isGeometryNode() {
  11930. return false;
  11931. }
  11932. getLevel() {
  11933. return this.geometryNode.level;
  11934. }
  11935. getBoundingSphere() {
  11936. return this.geometryNode.boundingSphere;
  11937. }
  11938. getBoundingBox() {
  11939. return this.geometryNode.boundingBox;
  11940. }
  11941. getChildren() {
  11942. var children = [];
  11943. for (var i = 0; i < 8; i++) {
  11944. if (this.children[i]) {
  11945. children.push(this.children[i]);
  11946. }
  11947. }
  11948. return children;
  11949. }
  11950. getPointsInBox(boxNode) {
  11951. if (!this.sceneNode) {
  11952. return null;
  11953. }
  11954. var buffer = this.geometryNode.buffer;
  11955. var posOffset = buffer.offset("position");
  11956. var stride = buffer.stride;
  11957. var view = new DataView(buffer.data);
  11958. var worldToBox = boxNode.matrixWorld.clone().invert();
  11959. var objectToBox = new Matrix4().multiplyMatrices(worldToBox, this.sceneNode.matrixWorld);
  11960. var inBox = [];
  11961. var pos = new Vector4();
  11962. for (var i = 0; i < buffer.numElements; i++) {
  11963. var x = view.getFloat32(i * stride + posOffset + 0, true);
  11964. var y = view.getFloat32(i * stride + posOffset + 4, true);
  11965. var z = view.getFloat32(i * stride + posOffset + 8, true);
  11966. pos.set(x, y, z, 1);
  11967. pos.applyMatrix4(objectToBox);
  11968. if (-0.5 < pos.x && pos.x < 0.5) {
  11969. if (-0.5 < pos.y && pos.y < 0.5) {
  11970. if (-0.5 < pos.z && pos.z < 0.5) {
  11971. pos.set(x, y, z, 1).applyMatrix4(this.sceneNode.matrixWorld);
  11972. inBox.push(new Vector3(pos.x, pos.y, pos.z));
  11973. }
  11974. }
  11975. }
  11976. }
  11977. return inBox;
  11978. }
  11979. get name() {
  11980. return this.geometryNode.name;
  11981. }
  11982. }
  11983. ;
  11984. class PointCloudOctree extends PointCloudTree {
  11985. //base
  11986. constructor(geometry, material) {
  11987. var _this2;
  11988. super();
  11989. _this2 = this;
  11990. this.pointBudget = Infinity; //一直是这个值
  11991. this.pcoGeometry = geometry;
  11992. this.boundingBox = this.pcoGeometry.boundingBox;
  11993. this.boundingSphere = this.boundingBox.getBoundingSphere(new Sphere());
  11994. this.material = material || new PointCloudMaterial$1();
  11995. this.visiblePointsTarget = 2 * 1000 * 1000;
  11996. this.minimumNodePixelSize = 150;
  11997. this.level = 0;
  11998. this.position.copy(geometry.offset);
  11999. this.updateMatrix();
  12000. {
  12001. var priorityQueue = ["rgba", "rgb", "intensity", "classification"];
  12002. var selected = "rgba";
  12003. var _loop = function _loop(attributeName) {
  12004. var attribute = _this2.pcoGeometry.pointAttributes.attributes.find(a => a.name === attributeName);
  12005. if (!attribute) {
  12006. return 0; // continue
  12007. }
  12008. var min = attribute.range[0].constructor.name === "Array" ? attribute.range[0] : [attribute.range[0]];
  12009. var max = attribute.range[1].constructor.name === "Array" ? attribute.range[1] : [attribute.range[1]];
  12010. var range_min = new Vector3(...min);
  12011. var range_max = new Vector3(...max);
  12012. var range = range_min.distanceTo(range_max);
  12013. if (range === 0) {
  12014. return 0; // continue
  12015. }
  12016. selected = attributeName;
  12017. return 1; // break
  12018. },
  12019. _ret;
  12020. for (var attributeName of priorityQueue) {
  12021. _ret = _loop(attributeName);
  12022. if (_ret === 0) continue;
  12023. if (_ret === 1) break;
  12024. }
  12025. this.material.activeAttributeName = selected;
  12026. }
  12027. this.showBoundingBox = false;
  12028. this.boundingBoxNodes = [];
  12029. this.loadQueue = [];
  12030. this.visibleBounds = new Box3();
  12031. this.visibleNodes = [];
  12032. this.visibleGeometry = [];
  12033. this.generateDEM = false;
  12034. this.profileRequests = [];
  12035. this.name = '';
  12036. this._visible = true;
  12037. {
  12038. var box = [this.pcoGeometry.tightBoundingBox, this.getBoundingBoxWorld()].find(v => v !== undefined);
  12039. this.updateMatrixWorld(true);
  12040. box = Utils.computeTransformedBoundingBox(box, this.matrixWorld);
  12041. var bMin = box.min.z;
  12042. var bMax = box.max.z;
  12043. this.material.heightMin = bMin;
  12044. this.material.heightMax = bMax;
  12045. }
  12046. // TODO read projection from file instead
  12047. this.projection = geometry.projection;
  12048. this.fallbackProjection = geometry.fallbackProjection;
  12049. this.root = this.pcoGeometry.root;
  12050. }
  12051. setName(name) {
  12052. if (this.name !== name) {
  12053. this.name = name;
  12054. this.dispatchEvent({
  12055. type: 'name_changed',
  12056. name: name,
  12057. pointcloud: this
  12058. });
  12059. }
  12060. }
  12061. getName() {
  12062. return this.name;
  12063. }
  12064. getAttribute(name) {
  12065. var attribute = this.pcoGeometry.pointAttributes.attributes.find(a => a.name === name);
  12066. if (attribute) {
  12067. return attribute;
  12068. } else {
  12069. return null;
  12070. }
  12071. }
  12072. getAttributes() {
  12073. return this.pcoGeometry.pointAttributes;
  12074. }
  12075. toTreeNode(geometryNode, parent) {
  12076. var node = new PointCloudOctreeNode();
  12077. // if(geometryNode.name === "r40206"){
  12078. // console.log("creating node for r40206");
  12079. // }
  12080. var sceneNode = new Points(geometryNode.geometry, this.material);
  12081. sceneNode.name = geometryNode.name;
  12082. sceneNode.position.copy(geometryNode.boundingBox.min);
  12083. sceneNode.frustumCulled = false;
  12084. sceneNode.onBeforeRender = (_this, scene, camera, geometry, material, group) => {
  12085. if (material.program) {
  12086. _this.getContext().useProgram(material.program.program);
  12087. if (material.program.getUniforms().map.level) {
  12088. var level = geometryNode.getLevel();
  12089. material.uniforms.level.value = level;
  12090. material.program.getUniforms().map.level.setValue(_this.getContext(), level);
  12091. }
  12092. if (this.visibleNodeTextureOffsets && material.program.getUniforms().map.vnStart) {
  12093. var vnStart = this.visibleNodeTextureOffsets.get(node);
  12094. material.uniforms.vnStart.value = vnStart;
  12095. material.program.getUniforms().map.vnStart.setValue(_this.getContext(), vnStart);
  12096. }
  12097. if (material.program.getUniforms().map.pcIndex) {
  12098. var i = node.pcIndex ? node.pcIndex : this.visibleNodes.indexOf(node);
  12099. material.uniforms.pcIndex.value = i;
  12100. material.program.getUniforms().map.pcIndex.setValue(_this.getContext(), i);
  12101. }
  12102. }
  12103. };
  12104. // { // DEBUG
  12105. // let sg = new THREE.SphereGeometry(1, 16, 16);
  12106. // let sm = new THREE.MeshNormalMaterial();
  12107. // let s = new THREE.Mesh(sg, sm);
  12108. // s.scale.set(5, 5, 5);
  12109. // s.position.copy(geometryNode.mean)
  12110. // .add(this.position)
  12111. // .add(geometryNode.boundingBox.min);
  12112. //
  12113. // viewer.scene.scene.add(s);
  12114. // }
  12115. node.geometryNode = geometryNode;
  12116. node.sceneNode = sceneNode;
  12117. node.pointcloud = this;
  12118. node.children = [];
  12119. //for (let key in geometryNode.children) {
  12120. // node.children[key] = geometryNode.children[key];
  12121. //}
  12122. for (var i = 0; i < 8; i++) {
  12123. node.children[i] = geometryNode.children[i];
  12124. }
  12125. if (!parent) {
  12126. this.root = node;
  12127. this.add(sceneNode);
  12128. } else {
  12129. var childIndex = parseInt(geometryNode.name[geometryNode.name.length - 1]);
  12130. parent.sceneNode.add(sceneNode);
  12131. parent.children[childIndex] = node;
  12132. }
  12133. var disposeListener = function disposeListener() {
  12134. var childIndex = parseInt(geometryNode.name[geometryNode.name.length - 1]);
  12135. parent.sceneNode.remove(node.sceneNode);
  12136. parent.children[childIndex] = geometryNode;
  12137. };
  12138. geometryNode.oneTimeDisposeHandlers.push(disposeListener);
  12139. return node;
  12140. }
  12141. updateVisibleBounds() {
  12142. var leafNodes = [];
  12143. for (var i = 0; i < this.visibleNodes.length; i++) {
  12144. var node = this.visibleNodes[i];
  12145. var isLeaf = true;
  12146. for (var j = 0; j < node.children.length; j++) {
  12147. var child = node.children[j];
  12148. if (child instanceof PointCloudOctreeNode) {
  12149. isLeaf = isLeaf && !child.sceneNode.visible;
  12150. } else if (child instanceof PointCloudOctreeGeometryNode) {
  12151. isLeaf = true;
  12152. }
  12153. }
  12154. if (isLeaf) {
  12155. leafNodes.push(node);
  12156. }
  12157. }
  12158. this.visibleBounds.min = new Vector3(Infinity, Infinity, Infinity);
  12159. this.visibleBounds.max = new Vector3(-Infinity, -Infinity, -Infinity);
  12160. for (var _i = 0; _i < leafNodes.length; _i++) {
  12161. var _node = leafNodes[_i];
  12162. this.visibleBounds.expandByPoint(_node.getBoundingBox().min);
  12163. this.visibleBounds.expandByPoint(_node.getBoundingBox().max);
  12164. }
  12165. }
  12166. updateMaterial(material, visibleNodes, camera, renderer) {
  12167. material.fov = camera.fov * (Math.PI / 180);
  12168. material.screenWidth = renderer.domElement.clientWidth;
  12169. material.screenHeight = renderer.domElement.clientHeight;
  12170. material.spacing = this.pcoGeometry.spacing; // * Math.max(this.scale.x, this.scale.y, this.scale.z);
  12171. material.near = camera.near;
  12172. material.far = camera.far;
  12173. material.uniforms.octreeSize.value = this.pcoGeometry.boundingBox.getSize(new Vector3()).x;
  12174. }
  12175. computeVisibilityTextureData(nodes, camera) {
  12176. if (Potree.measureTimings) performance.mark("computeVisibilityTextureData-start");
  12177. var data = new Uint8Array(nodes.length * 4);
  12178. var visibleNodeTextureOffsets = new Map();
  12179. // copy array
  12180. nodes = nodes.slice();
  12181. // sort by level and index, e.g. r, r0, r3, r4, r01, r07, r30, ...
  12182. var sort = function sort(a, b) {
  12183. var na = a.geometryNode.name;
  12184. var nb = b.geometryNode.name;
  12185. if (na.length !== nb.length) return na.length - nb.length;
  12186. if (na < nb) return -1;
  12187. if (na > nb) return 1;
  12188. return 0;
  12189. };
  12190. nodes.sort(sort);
  12191. var worldDir = new Vector3();
  12192. var nodeMap = new Map();
  12193. var offsetsToChild = new Array(nodes.length).fill(Infinity);
  12194. for (var i = 0; i < nodes.length; i++) {
  12195. var node = nodes[i];
  12196. nodeMap.set(node.name, node);
  12197. visibleNodeTextureOffsets.set(node, i);
  12198. if (i > 0) {
  12199. var index = parseInt(node.name.slice(-1));
  12200. var parentName = node.name.slice(0, -1);
  12201. var parent = nodeMap.get(parentName);
  12202. var parentOffset = visibleNodeTextureOffsets.get(parent);
  12203. var parentOffsetToChild = i - parentOffset;
  12204. offsetsToChild[parentOffset] = Math.min(offsetsToChild[parentOffset], parentOffsetToChild);
  12205. data[parentOffset * 4 + 0] = data[parentOffset * 4 + 0] | 1 << index;
  12206. data[parentOffset * 4 + 1] = offsetsToChild[parentOffset] >> 8;
  12207. data[parentOffset * 4 + 2] = offsetsToChild[parentOffset] % 256;
  12208. }
  12209. var density = node.geometryNode.density;
  12210. if (typeof density === "number") {
  12211. var lodOffset = Math.log2(density) / 2 - 1.5;
  12212. var offsetUint8 = (lodOffset + 10) * 10;
  12213. data[i * 4 + 3] = offsetUint8;
  12214. } else {
  12215. data[i * 4 + 3] = 100;
  12216. }
  12217. }
  12218. if (Potree.measureTimings) {
  12219. performance.mark("computeVisibilityTextureData-end");
  12220. performance.measure("render.computeVisibilityTextureData", "computeVisibilityTextureData-start", "computeVisibilityTextureData-end");
  12221. }
  12222. return {
  12223. data: data,
  12224. offsets: visibleNodeTextureOffsets
  12225. };
  12226. }
  12227. nodeIntersectsProfile(node, profile) {
  12228. var bbWorld = node.boundingBox.clone().applyMatrix4(this.matrixWorld);
  12229. var bsWorld = bbWorld.getBoundingSphere(new Sphere());
  12230. var intersects = false;
  12231. for (var i = 0; i < profile.points.length - 1; i++) {
  12232. var start = new Vector3(profile.points[i + 0].x, profile.points[i + 0].y, bsWorld.center.z);
  12233. var end = new Vector3(profile.points[i + 1].x, profile.points[i + 1].y, bsWorld.center.z);
  12234. var closest = new Line3(start, end).closestPointToPoint(bsWorld.center, true, new Vector3());
  12235. var distance = closest.distanceTo(bsWorld.center);
  12236. intersects = intersects || distance < bsWorld.radius + profile.width;
  12237. }
  12238. //console.log(`${node.name}: ${intersects}`);
  12239. return intersects;
  12240. }
  12241. deepestNodeAt(position) {
  12242. var toObjectSpace = this.matrixWorld.clone().invert();
  12243. var objPos = position.clone().applyMatrix4(toObjectSpace);
  12244. var current = this.root;
  12245. while (true) {
  12246. var containingChild = null;
  12247. for (var child of current.children) {
  12248. if (child !== undefined) {
  12249. if (child.getBoundingBox().containsPoint(objPos)) {
  12250. containingChild = child;
  12251. }
  12252. }
  12253. }
  12254. if (containingChild !== null && containingChild instanceof PointCloudOctreeNode) {
  12255. current = containingChild;
  12256. } else {
  12257. break;
  12258. }
  12259. }
  12260. var deepest = current;
  12261. return deepest;
  12262. }
  12263. nodesOnRay(nodes, ray) {
  12264. var nodesOnRay = [];
  12265. var _ray = ray.clone();
  12266. for (var i = 0; i < nodes.length; i++) {
  12267. var node = nodes[i];
  12268. var sphere = node.getBoundingSphere().clone().applyMatrix4(this.matrixWorld);
  12269. if (_ray.intersectsSphere(sphere)) {
  12270. nodesOnRay.push(node);
  12271. }
  12272. }
  12273. return nodesOnRay;
  12274. }
  12275. updateMatrixWorld(force) {
  12276. if (this.matrixAutoUpdate === true) this.updateMatrix();
  12277. if (this.matrixWorldNeedsUpdate === true || force === true) {
  12278. if (!this.parent) {
  12279. this.matrixWorld.copy(this.matrix);
  12280. } else {
  12281. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  12282. }
  12283. this.matrixWorldNeedsUpdate = false;
  12284. force = true;
  12285. }
  12286. }
  12287. hideDescendants(object) {
  12288. var stack = [];
  12289. for (var i = 0; i < object.children.length; i++) {
  12290. var child = object.children[i];
  12291. if (child.visible) {
  12292. stack.push(child);
  12293. }
  12294. }
  12295. while (stack.length > 0) {
  12296. var _object = stack.shift();
  12297. _object.visible = false;
  12298. for (var _i2 = 0; _i2 < _object.children.length; _i2++) {
  12299. var _child = _object.children[_i2];
  12300. if (_child.visible) {
  12301. stack.push(_child);
  12302. }
  12303. }
  12304. }
  12305. }
  12306. moveToOrigin() {
  12307. this.position.set(0, 0, 0);
  12308. this.updateMatrixWorld(true);
  12309. var box = this.boundingBox;
  12310. var transform = this.matrixWorld;
  12311. var tBox = Utils.computeTransformedBoundingBox(box, transform);
  12312. this.position.set(0, 0, 0).sub(tBox.getCenter(new Vector3()));
  12313. }
  12314. moveToGroundPlane() {
  12315. this.updateMatrixWorld(true);
  12316. var box = this.boundingBox;
  12317. var transform = this.matrixWorld;
  12318. var tBox = Utils.computeTransformedBoundingBox(box, transform);
  12319. this.position.y += -tBox.min.y;
  12320. }
  12321. getBoundingBoxWorld() {
  12322. this.updateMatrixWorld(true);
  12323. var box = this.boundingBox;
  12324. var transform = this.matrixWorld;
  12325. var tBox = Utils.computeTransformedBoundingBox(box, transform);
  12326. return tBox;
  12327. }
  12328. /**
  12329. * returns points inside the profile points
  12330. *
  12331. * maxDepth: search points up to the given octree depth
  12332. *
  12333. *
  12334. * The return value is an array with all segments of the profile path
  12335. * let segment = {
  12336. * start: THREE.Vector3,
  12337. * end: THREE.Vector3,
  12338. * points: {}
  12339. * project: function()
  12340. * };
  12341. *
  12342. * The project() function inside each segment can be used to transform
  12343. * that segments point coordinates to line up along the x-axis.
  12344. *
  12345. *
  12346. */
  12347. getPointsInProfile(profile, maxDepth, callback) {
  12348. if (callback) {
  12349. var request = new Potree.ProfileRequest(this, profile, maxDepth, callback);
  12350. this.profileRequests.push(request);
  12351. return request;
  12352. }
  12353. var points = {
  12354. segments: [],
  12355. boundingBox: new Box3(),
  12356. projectedBoundingBox: new Box2()
  12357. };
  12358. // evaluate segments
  12359. for (var i = 0; i < profile.points.length - 1; i++) {
  12360. var start = profile.points[i];
  12361. var end = profile.points[i + 1];
  12362. var ps = this.getProfile(start, end, profile.width, maxDepth);
  12363. var segment = {
  12364. start: start,
  12365. end: end,
  12366. points: ps,
  12367. project: null
  12368. };
  12369. points.segments.push(segment);
  12370. points.boundingBox.expandByPoint(ps.boundingBox.min);
  12371. points.boundingBox.expandByPoint(ps.boundingBox.max);
  12372. }
  12373. // add projection functions to the segments
  12374. var mileage = new Vector3();
  12375. for (var _i3 = 0; _i3 < points.segments.length; _i3++) {
  12376. var _segment = points.segments[_i3];
  12377. var _start2 = _segment.start;
  12378. var _end2 = _segment.end;
  12379. var project = function (_start, _end, _mileage, _boundingBox) {
  12380. var start = _start;
  12381. var end = _end;
  12382. var mileage = _mileage;
  12383. var boundingBox = _boundingBox;
  12384. var xAxis = new Vector3(1, 0, 0);
  12385. var dir = new Vector3().subVectors(end, start);
  12386. dir.y = 0;
  12387. dir.normalize();
  12388. var alpha = Math.acos(xAxis.dot(dir));
  12389. if (dir.z > 0) {
  12390. alpha = -alpha;
  12391. }
  12392. return function (position) {
  12393. var toOrigin = new Matrix4().makeTranslation(-start.x, -boundingBox.min.y, -start.z);
  12394. var alignWithX = new Matrix4().makeRotationY(-alpha);
  12395. var applyMileage = new Matrix4().makeTranslation(mileage.x, 0, 0);
  12396. var pos = position.clone();
  12397. pos.applyMatrix4(toOrigin);
  12398. pos.applyMatrix4(alignWithX);
  12399. pos.applyMatrix4(applyMileage);
  12400. return pos;
  12401. };
  12402. }(_start2, _end2, mileage.clone(), points.boundingBox.clone());
  12403. _segment.project = project;
  12404. mileage.x += new Vector3(_start2.x, 0, _start2.z).distanceTo(new Vector3(_end2.x, 0, _end2.z));
  12405. mileage.y += _end2.y - _start2.y;
  12406. }
  12407. points.projectedBoundingBox.min.x = 0;
  12408. points.projectedBoundingBox.min.y = points.boundingBox.min.y;
  12409. points.projectedBoundingBox.max.x = mileage.x;
  12410. points.projectedBoundingBox.max.y = points.boundingBox.max.y;
  12411. return points;
  12412. }
  12413. /**
  12414. * returns points inside the given profile bounds.
  12415. *
  12416. * start:
  12417. * end:
  12418. * width:
  12419. * depth: search points up to the given octree depth
  12420. * callback: if specified, points are loaded before searching
  12421. *
  12422. *
  12423. */
  12424. getProfile(start, end, width, depth, callback) {
  12425. var request = new Potree.ProfileRequest(start, end, width, depth, callback);
  12426. this.profileRequests.push(request);
  12427. }
  12428. getVisibleExtent() {
  12429. return this.visibleBounds.applyMatrix4(this.matrixWorld);
  12430. }
  12431. intersectsPoint(position) {
  12432. var rootAvailable = this.pcoGeometry.root && this.pcoGeometry.root.geometry;
  12433. if (!rootAvailable) {
  12434. return false;
  12435. }
  12436. if (typeof this.signedDistanceField === "undefined") {
  12437. var resolution = 32;
  12438. var field = new Float32Array(resolution ** 3).fill(Infinity);
  12439. var positions = this.pcoGeometry.root.geometry.attributes.position;
  12440. var boundingBox = this.boundingBox;
  12441. var n = positions.count;
  12442. for (var i = 0; i < n; i = i + 3) {
  12443. var x = positions.array[3 * i + 0];
  12444. var y = positions.array[3 * i + 1];
  12445. var z = positions.array[3 * i + 2];
  12446. var ix = parseInt(Math.min(resolution * (x / boundingBox.max.x), resolution - 1));
  12447. var iy = parseInt(Math.min(resolution * (y / boundingBox.max.y), resolution - 1));
  12448. var iz = parseInt(Math.min(resolution * (z / boundingBox.max.z), resolution - 1));
  12449. var index = ix + iy * resolution + iz * resolution * resolution;
  12450. field[index] = 0;
  12451. }
  12452. var sdf = {
  12453. resolution: resolution,
  12454. field: field
  12455. };
  12456. this.signedDistanceField = sdf;
  12457. }
  12458. {
  12459. var _sdf = this.signedDistanceField;
  12460. var _boundingBox2 = this.boundingBox;
  12461. var toObjectSpace = this.matrixWorld.clone().invert();
  12462. var objPos = position.clone().applyMatrix4(toObjectSpace);
  12463. var _resolution = _sdf.resolution;
  12464. var _ix = parseInt(_resolution * (objPos.x / _boundingBox2.max.x));
  12465. var _iy = parseInt(_resolution * (objPos.y / _boundingBox2.max.y));
  12466. var _iz = parseInt(_resolution * (objPos.z / _boundingBox2.max.z));
  12467. if (_ix < 0 || _iy < 0 || _iz < 0) {
  12468. return false;
  12469. }
  12470. if (_ix >= _resolution || _iy >= _resolution || _iz >= _resolution) {
  12471. return false;
  12472. }
  12473. var _index = _ix + _iy * _resolution + _iz * _resolution * _resolution;
  12474. var value = _sdf.field[_index];
  12475. if (value === 0) {
  12476. return true;
  12477. }
  12478. }
  12479. return false;
  12480. }
  12481. /**
  12482. *
  12483. *
  12484. *
  12485. * params.pickWindowSize: Look for points inside a pixel window of this size.
  12486. * Use odd values: 1, 3, 5, ...
  12487. *
  12488. *
  12489. * TODO: only draw pixels that are actually read with readPixels().
  12490. *
  12491. */
  12492. pick(viewer, camera, ray) {
  12493. var params = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  12494. var renderer = viewer.renderer;
  12495. var pRenderer = viewer.pRenderer;
  12496. performance.mark("pick-start");
  12497. var getVal = (a, b) => a !== undefined ? a : b;
  12498. var pickWindowSize = getVal(params.pickWindowSize, 65);
  12499. var pickOutsideClipRegion = getVal(params.pickOutsideClipRegion, false);
  12500. var size = renderer.getSize(new Vector2());
  12501. var width = Math.ceil(getVal(params.width, size.width));
  12502. var height = Math.ceil(getVal(params.height, size.height));
  12503. var pointSizeType = getVal(params.pointSizeType, this.material.pointSizeType);
  12504. var pointSize = getVal(params.pointSize, this.material.size);
  12505. var nodes = this.nodesOnRay(this.visibleNodes, ray);
  12506. if (nodes.length === 0) {
  12507. return null;
  12508. }
  12509. if (!this.pickState) {
  12510. var scene = new Scene();
  12511. var material = new Potree.PointCloudMaterial();
  12512. material.activeAttributeName = "indices";
  12513. var renderTarget = new WebGLRenderTarget(1, 1, {
  12514. minFilter: LinearFilter,
  12515. magFilter: NearestFilter,
  12516. format: RGBAFormat
  12517. });
  12518. this.pickState = {
  12519. renderTarget: renderTarget,
  12520. material: material,
  12521. scene: scene
  12522. };
  12523. }
  12524. ;
  12525. var pickState = this.pickState;
  12526. var pickMaterial = pickState.material;
  12527. {
  12528. // update pick material
  12529. pickMaterial.pointSizeType = pointSizeType;
  12530. //pickMaterial.shape = this.material.shape;
  12531. pickMaterial.shape = Potree.PointShape.PARABOLOID;
  12532. pickMaterial.uniforms.uFilterReturnNumberRange.value = this.material.uniforms.uFilterReturnNumberRange.value;
  12533. pickMaterial.uniforms.uFilterNumberOfReturnsRange.value = this.material.uniforms.uFilterNumberOfReturnsRange.value;
  12534. pickMaterial.uniforms.uFilterGPSTimeClipRange.value = this.material.uniforms.uFilterGPSTimeClipRange.value;
  12535. pickMaterial.uniforms.uFilterPointSourceIDClipRange.value = this.material.uniforms.uFilterPointSourceIDClipRange.value;
  12536. pickMaterial.activeAttributeName = "indices";
  12537. pickMaterial.size = pointSize;
  12538. pickMaterial.uniforms.minSize.value = this.material.uniforms.minSize.value;
  12539. pickMaterial.uniforms.maxSize.value = this.material.uniforms.maxSize.value;
  12540. pickMaterial.classification = this.material.classification;
  12541. pickMaterial.recomputeClassification();
  12542. if (params.pickClipped) {
  12543. pickMaterial.clipBoxes = this.material.clipBoxes;
  12544. pickMaterial.uniforms.clipBoxes = this.material.uniforms.clipBoxes;
  12545. if (this.material.clipTask === Potree.ClipTask.HIGHLIGHT) {
  12546. pickMaterial.clipTask = Potree.ClipTask.NONE;
  12547. } else {
  12548. pickMaterial.clipTask = this.material.clipTask;
  12549. }
  12550. pickMaterial.clipMethod = this.material.clipMethod;
  12551. } else {
  12552. pickMaterial.clipBoxes = [];
  12553. }
  12554. this.updateMaterial(pickMaterial, nodes, camera, renderer);
  12555. }
  12556. pickState.renderTarget.setSize(width, height);
  12557. var pixelPos = new Vector2(params.x, params.y);
  12558. var gl = renderer.getContext();
  12559. gl.enable(gl.SCISSOR_TEST);
  12560. gl.scissor(parseInt(pixelPos.x - (pickWindowSize - 1) / 2), parseInt(pixelPos.y - (pickWindowSize - 1) / 2), parseInt(pickWindowSize), parseInt(pickWindowSize));
  12561. renderer.state.buffers.depth.setTest(pickMaterial.depthTest);
  12562. renderer.state.buffers.depth.setMask(pickMaterial.depthWrite);
  12563. renderer.state.setBlending(NoBlending);
  12564. {
  12565. // RENDER
  12566. renderer.setRenderTarget(pickState.renderTarget);
  12567. gl.clearColor(0, 0, 0, 0);
  12568. renderer.clear(true, true, true);
  12569. var tmp = this.material;
  12570. this.material = pickMaterial;
  12571. pRenderer.renderOctree(this, nodes, camera, pickState.renderTarget);
  12572. this.material = tmp;
  12573. }
  12574. var clamp = (number, min, max) => Math.min(Math.max(min, number), max);
  12575. var x = parseInt(clamp(pixelPos.x - (pickWindowSize - 1) / 2, 0, width));
  12576. var y = parseInt(clamp(pixelPos.y - (pickWindowSize - 1) / 2, 0, height));
  12577. var w = parseInt(Math.min(x + pickWindowSize, width) - x);
  12578. var h = parseInt(Math.min(y + pickWindowSize, height) - y);
  12579. var pixelCount = w * h;
  12580. var buffer = new Uint8Array(4 * pixelCount);
  12581. gl.readPixels(x, y, pickWindowSize, pickWindowSize, gl.RGBA, gl.UNSIGNED_BYTE, buffer);
  12582. renderer.setRenderTarget(null);
  12583. renderer.state.reset();
  12584. renderer.setScissorTest(false);
  12585. gl.disable(gl.SCISSOR_TEST);
  12586. var pixels = buffer;
  12587. var ibuffer = new Uint32Array(buffer.buffer);
  12588. // find closest hit inside pixelWindow boundaries
  12589. var min = Number.MAX_VALUE;
  12590. var hits = [];
  12591. for (var u = 0; u < pickWindowSize; u++) {
  12592. for (var v = 0; v < pickWindowSize; v++) {
  12593. var offset = u + v * pickWindowSize;
  12594. var distance = Math.pow(u - (pickWindowSize - 1) / 2, 2) + Math.pow(v - (pickWindowSize - 1) / 2, 2);
  12595. var pcIndex = pixels[4 * offset + 3];
  12596. pixels[4 * offset + 3] = 0;
  12597. var pIndex = ibuffer[offset];
  12598. if (!(pcIndex === 0 && pIndex === 0) && pcIndex !== undefined && pIndex !== undefined) {
  12599. var hit = {
  12600. pIndex: pIndex,
  12601. pcIndex: pcIndex,
  12602. distanceToCenter: distance
  12603. };
  12604. if (params.all) {
  12605. hits.push(hit);
  12606. } else {
  12607. if (hits.length > 0) {
  12608. if (distance < hits[0].distanceToCenter) {
  12609. hits[0] = hit;
  12610. }
  12611. } else {
  12612. hits.push(hit);
  12613. }
  12614. }
  12615. }
  12616. }
  12617. }
  12618. // { // DEBUG: show panel with pick image
  12619. // let img = Utils.pixelsArrayToImage(buffer, w, h);
  12620. // let screenshot = img.src;
  12621. // if(!this.debugDIV){
  12622. // this.debugDIV = $(`
  12623. // <div id="pickDebug"
  12624. // style="position: absolute;
  12625. // right: 400px; width: 300px;
  12626. // bottom: 44px; width: 300px;
  12627. // z-index: 1000;
  12628. // "></div>`);
  12629. // $(document.body).append(this.debugDIV);
  12630. // }
  12631. // this.debugDIV.empty();
  12632. // this.debugDIV.append($(`<img src="${screenshot}"
  12633. // style="transform: scaleY(-1); width: 300px"/>`));
  12634. // //$(this.debugWindow.document).append($(`<img src="${screenshot}"/>`));
  12635. // //this.debugWindow.document.write('<img src="'+screenshot+'"/>');
  12636. // }
  12637. for (var _hit of hits) {
  12638. var point = {};
  12639. if (!nodes[_hit.pcIndex]) {
  12640. return null;
  12641. }
  12642. var node = nodes[_hit.pcIndex];
  12643. var pc = node.sceneNode;
  12644. var geometry = node.geometryNode.geometry;
  12645. var _loop2 = function _loop2() {
  12646. var attribute = geometry.attributes[attributeName];
  12647. if (attributeName === 'position') {
  12648. var _x = attribute.array[3 * _hit.pIndex + 0];
  12649. var _y = attribute.array[3 * _hit.pIndex + 1];
  12650. var z = attribute.array[3 * _hit.pIndex + 2];
  12651. var position = new Vector3(_x, _y, z);
  12652. position.applyMatrix4(pc.matrixWorld);
  12653. point[attributeName] = position;
  12654. } else if (attributeName === 'indices') {} else {
  12655. var values = attribute.array.slice(attribute.itemSize * _hit.pIndex, attribute.itemSize * (_hit.pIndex + 1));
  12656. if (attribute.potree) {
  12657. var {
  12658. scale,
  12659. offset: _offset
  12660. } = attribute.potree;
  12661. values = values.map(v => v / scale + _offset);
  12662. }
  12663. point[attributeName] = values;
  12664. //debugger;
  12665. //if (values.itemSize === 1) {
  12666. // point[attribute.name] = values.array[hit.pIndex];
  12667. //} else {
  12668. // let value = [];
  12669. // for (let j = 0; j < values.itemSize; j++) {
  12670. // value.push(values.array[values.itemSize * hit.pIndex + j]);
  12671. // }
  12672. // point[attribute.name] = value;
  12673. //}
  12674. }
  12675. };
  12676. for (var attributeName in geometry.attributes) {
  12677. _loop2();
  12678. }
  12679. _hit.point = point;
  12680. }
  12681. performance.mark("pick-end");
  12682. performance.measure("pick", "pick-start", "pick-end");
  12683. if (params.all) {
  12684. return hits.map(hit => hit.point);
  12685. } else {
  12686. if (hits.length === 0) {
  12687. return null;
  12688. } else {
  12689. return hits[0].point;
  12690. //let sorted = hits.sort( (a, b) => a.distanceToCenter - b.distanceToCenter);
  12691. //return sorted[0].point;
  12692. }
  12693. }
  12694. }
  12695. *getFittedBoxGen(boxNode) {
  12696. var start = performance.now();
  12697. var shrinkedLocalBounds = new Box3();
  12698. var worldToBox = boxNode.matrixWorld.clone().invert();
  12699. for (var node of this.visibleNodes) {
  12700. if (!node.sceneNode) {
  12701. continue;
  12702. }
  12703. var buffer = node.geometryNode.buffer;
  12704. var posOffset = buffer.offset("position");
  12705. var stride = buffer.stride;
  12706. var view = new DataView(buffer.data);
  12707. var objectToBox = new Matrix4().multiplyMatrices(worldToBox, node.sceneNode.matrixWorld);
  12708. var pos = new Vector4();
  12709. for (var i = 0; i < buffer.numElements; i++) {
  12710. var x = view.getFloat32(i * stride + posOffset + 0, true);
  12711. var y = view.getFloat32(i * stride + posOffset + 4, true);
  12712. var z = view.getFloat32(i * stride + posOffset + 8, true);
  12713. pos.set(x, y, z, 1);
  12714. pos.applyMatrix4(objectToBox);
  12715. if (-0.5 < pos.x && pos.x < 0.5) {
  12716. if (-0.5 < pos.y && pos.y < 0.5) {
  12717. if (-0.5 < pos.z && pos.z < 0.5) {
  12718. shrinkedLocalBounds.expandByPoint(pos);
  12719. }
  12720. }
  12721. }
  12722. }
  12723. yield;
  12724. }
  12725. var fittedPosition = shrinkedLocalBounds.getCenter(new Vector3()).applyMatrix4(boxNode.matrixWorld);
  12726. var fitted = new Object3D();
  12727. fitted.position.copy(fittedPosition);
  12728. fitted.scale.copy(boxNode.scale);
  12729. fitted.rotation.copy(boxNode.rotation);
  12730. var ds = new Vector3().subVectors(shrinkedLocalBounds.max, shrinkedLocalBounds.min);
  12731. fitted.scale.multiply(ds);
  12732. var duration = performance.now() - start;
  12733. console.log("duration: ", duration);
  12734. yield fitted;
  12735. }
  12736. getFittedBox(boxNode) {
  12737. var maxLevel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Infinity;
  12738. maxLevel = Infinity;
  12739. var start = performance.now();
  12740. var shrinkedLocalBounds = new Box3();
  12741. var worldToBox = boxNode.matrixWorld.clone().invert();
  12742. for (var node of this.visibleNodes) {
  12743. if (!node.sceneNode || node.getLevel() > maxLevel) {
  12744. continue;
  12745. }
  12746. var buffer = node.geometryNode.buffer;
  12747. var posOffset = buffer.offset("position");
  12748. var stride = buffer.stride;
  12749. var view = new DataView(buffer.data);
  12750. var objectToBox = new Matrix4().multiplyMatrices(worldToBox, node.sceneNode.matrixWorld);
  12751. var pos = new Vector4();
  12752. for (var i = 0; i < buffer.numElements; i++) {
  12753. var x = view.getFloat32(i * stride + posOffset + 0, true);
  12754. var y = view.getFloat32(i * stride + posOffset + 4, true);
  12755. var z = view.getFloat32(i * stride + posOffset + 8, true);
  12756. pos.set(x, y, z, 1);
  12757. pos.applyMatrix4(objectToBox);
  12758. if (-0.5 < pos.x && pos.x < 0.5) {
  12759. if (-0.5 < pos.y && pos.y < 0.5) {
  12760. if (-0.5 < pos.z && pos.z < 0.5) {
  12761. shrinkedLocalBounds.expandByPoint(pos);
  12762. }
  12763. }
  12764. }
  12765. }
  12766. }
  12767. var fittedPosition = shrinkedLocalBounds.getCenter(new Vector3()).applyMatrix4(boxNode.matrixWorld);
  12768. var fitted = new Object3D();
  12769. fitted.position.copy(fittedPosition);
  12770. fitted.scale.copy(boxNode.scale);
  12771. fitted.rotation.copy(boxNode.rotation);
  12772. var ds = new Vector3().subVectors(shrinkedLocalBounds.max, shrinkedLocalBounds.min);
  12773. fitted.scale.multiply(ds);
  12774. var duration = performance.now() - start;
  12775. console.log("duration: ", duration);
  12776. return fitted;
  12777. }
  12778. get progress() {
  12779. return this.visibleNodes.length / this.visibleGeometry.length;
  12780. }
  12781. find(name) {
  12782. var node = null;
  12783. for (var char of name) {
  12784. if (char === "r") {
  12785. node = this.root;
  12786. } else {
  12787. node = node.children[char];
  12788. }
  12789. }
  12790. return node;
  12791. }
  12792. get visible() {
  12793. return this._visible;
  12794. }
  12795. set visible(value) {
  12796. if (value !== this._visible) {
  12797. this._visible = value;
  12798. this.dispatchEvent({
  12799. type: 'visibility_changed',
  12800. pointcloud: this
  12801. });
  12802. }
  12803. }
  12804. }
  12805. class PointCloudArena4DNode extends PointCloudTreeNode {
  12806. constructor() {
  12807. super();
  12808. this.left = null;
  12809. this.right = null;
  12810. this.sceneNode = null;
  12811. this.kdtree = null;
  12812. }
  12813. getNumPoints() {
  12814. return this.geometryNode.numPoints;
  12815. }
  12816. isLoaded() {
  12817. return true;
  12818. }
  12819. isTreeNode() {
  12820. return true;
  12821. }
  12822. isGeometryNode() {
  12823. return false;
  12824. }
  12825. getLevel() {
  12826. return this.geometryNode.level;
  12827. }
  12828. getBoundingSphere() {
  12829. return this.geometryNode.boundingSphere;
  12830. }
  12831. getBoundingBox() {
  12832. return this.geometryNode.boundingBox;
  12833. }
  12834. toTreeNode(child) {
  12835. var geometryNode = null;
  12836. if (this.left === child) {
  12837. geometryNode = this.left;
  12838. } else if (this.right === child) {
  12839. geometryNode = this.right;
  12840. }
  12841. if (!geometryNode.loaded) {
  12842. return;
  12843. }
  12844. var node = new PointCloudArena4DNode();
  12845. var sceneNode = PointCloud(geometryNode.geometry, this.kdtree.material);
  12846. sceneNode.visible = false;
  12847. node.kdtree = this.kdtree;
  12848. node.geometryNode = geometryNode;
  12849. node.sceneNode = sceneNode;
  12850. node.parent = this;
  12851. node.left = this.geometryNode.left;
  12852. node.right = this.geometryNode.right;
  12853. }
  12854. getChildren() {
  12855. var children = [];
  12856. if (this.left) {
  12857. children.push(this.left);
  12858. }
  12859. if (this.right) {
  12860. children.push(this.right);
  12861. }
  12862. return children;
  12863. }
  12864. }
  12865. ;
  12866. class PointCloudArena4D$1 extends PointCloudTree {
  12867. constructor(geometry) {
  12868. super();
  12869. this.root = null;
  12870. if (geometry.root) {
  12871. this.root = geometry.root;
  12872. } else {
  12873. geometry.addEventListener('hierarchy_loaded', () => {
  12874. this.root = geometry.root;
  12875. });
  12876. }
  12877. this.visiblePointsTarget = 2 * 1000 * 1000;
  12878. this.minimumNodePixelSize = 150;
  12879. this.position.sub(geometry.offset);
  12880. this.updateMatrix();
  12881. this.numVisibleNodes = 0;
  12882. this.numVisiblePoints = 0;
  12883. this.boundingBoxNodes = [];
  12884. this.loadQueue = [];
  12885. this.visibleNodes = [];
  12886. this.pcoGeometry = geometry;
  12887. this.boundingBox = this.pcoGeometry.boundingBox;
  12888. this.boundingSphere = this.pcoGeometry.boundingSphere;
  12889. this.material = new PointCloudMaterial$1({
  12890. vertexColors: VertexColors,
  12891. size: 0.05,
  12892. treeType: TreeType.KDTREE
  12893. });
  12894. this.material.sizeType = PointSizeType.ATTENUATED;
  12895. this.material.size = 0.05;
  12896. this.profileRequests = [];
  12897. this.name = '';
  12898. }
  12899. getBoundingBoxWorld() {
  12900. this.updateMatrixWorld(true);
  12901. var box = this.boundingBox;
  12902. var transform = this.matrixWorld;
  12903. var tBox = Utils.computeTransformedBoundingBox(box, transform);
  12904. return tBox;
  12905. }
  12906. setName(name) {
  12907. if (this.name !== name) {
  12908. this.name = name;
  12909. this.dispatchEvent({
  12910. type: 'name_changed',
  12911. name: name,
  12912. pointcloud: this
  12913. });
  12914. }
  12915. }
  12916. getName() {
  12917. return this.name;
  12918. }
  12919. getLevel() {
  12920. return this.level;
  12921. }
  12922. toTreeNode(geometryNode, parent) {
  12923. var node = new PointCloudArena4DNode();
  12924. var sceneNode = new Points(geometryNode.geometry, this.material);
  12925. sceneNode.frustumCulled = false;
  12926. sceneNode.onBeforeRender = (_this, scene, camera, geometry, material, group) => {
  12927. if (material.program) {
  12928. _this.getContext().useProgram(material.program.program);
  12929. if (material.program.getUniforms().map.level) {
  12930. var level = geometryNode.getLevel();
  12931. material.uniforms.level.value = level;
  12932. material.program.getUniforms().map.level.setValue(_this.getContext(), level);
  12933. }
  12934. if (this.visibleNodeTextureOffsets && material.program.getUniforms().map.vnStart) {
  12935. var vnStart = this.visibleNodeTextureOffsets.get(node);
  12936. material.uniforms.vnStart.value = vnStart;
  12937. material.program.getUniforms().map.vnStart.setValue(_this.getContext(), vnStart);
  12938. }
  12939. if (material.program.getUniforms().map.pcIndex) {
  12940. var i = node.pcIndex ? node.pcIndex : this.visibleNodes.indexOf(node);
  12941. material.uniforms.pcIndex.value = i;
  12942. material.program.getUniforms().map.pcIndex.setValue(_this.getContext(), i);
  12943. }
  12944. }
  12945. };
  12946. node.geometryNode = geometryNode;
  12947. node.sceneNode = sceneNode;
  12948. node.pointcloud = this;
  12949. node.left = geometryNode.left;
  12950. node.right = geometryNode.right;
  12951. if (!parent) {
  12952. this.root = node;
  12953. this.add(sceneNode);
  12954. } else {
  12955. parent.sceneNode.add(sceneNode);
  12956. if (parent.left === geometryNode) {
  12957. parent.left = node;
  12958. } else if (parent.right === geometryNode) {
  12959. parent.right = node;
  12960. }
  12961. }
  12962. var disposeListener = function disposeListener() {
  12963. parent.sceneNode.remove(node.sceneNode);
  12964. if (parent.left === node) {
  12965. parent.left = geometryNode;
  12966. } else if (parent.right === node) {
  12967. parent.right = geometryNode;
  12968. }
  12969. };
  12970. geometryNode.oneTimeDisposeHandlers.push(disposeListener);
  12971. return node;
  12972. }
  12973. updateMaterial(material, visibleNodes, camera, renderer) {
  12974. material.fov = camera.fov * (Math.PI / 180);
  12975. material.screenWidth = renderer.domElement.clientWidth;
  12976. material.screenHeight = renderer.domElement.clientHeight;
  12977. material.spacing = this.pcoGeometry.spacing;
  12978. material.near = camera.near;
  12979. material.far = camera.far;
  12980. // reduce shader source updates by setting maxLevel slightly higher than actually necessary
  12981. if (this.maxLevel > material.levels) {
  12982. material.levels = this.maxLevel + 2;
  12983. }
  12984. // material.uniforms.octreeSize.value = this.boundingBox.size().x;
  12985. var bbSize = this.boundingBox.getSize(new Vector3());
  12986. material.bbSize = [bbSize.x, bbSize.y, bbSize.z];
  12987. }
  12988. updateVisibleBounds() {}
  12989. hideDescendants(object) {
  12990. var stack = [];
  12991. for (var i = 0; i < object.children.length; i++) {
  12992. var child = object.children[i];
  12993. if (child.visible) {
  12994. stack.push(child);
  12995. }
  12996. }
  12997. while (stack.length > 0) {
  12998. var _child = stack.shift();
  12999. _child.visible = false;
  13000. if (_child.boundingBoxNode) {
  13001. _child.boundingBoxNode.visible = false;
  13002. }
  13003. for (var _i = 0; _i < _child.children.length; _i++) {
  13004. var childOfChild = _child.children[_i];
  13005. if (childOfChild.visible) {
  13006. stack.push(childOfChild);
  13007. }
  13008. }
  13009. }
  13010. }
  13011. updateMatrixWorld(force) {
  13012. // node.matrixWorld.multiplyMatrices( node.parent.matrixWorld, node.matrix );
  13013. if (this.matrixAutoUpdate === true) this.updateMatrix();
  13014. if (this.matrixWorldNeedsUpdate === true || force === true) {
  13015. if (this.parent === undefined) {
  13016. this.matrixWorld.copy(this.matrix);
  13017. } else {
  13018. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  13019. }
  13020. this.matrixWorldNeedsUpdate = false;
  13021. force = true;
  13022. }
  13023. }
  13024. nodesOnRay(nodes, ray) {
  13025. var nodesOnRay = [];
  13026. var _ray = ray.clone();
  13027. for (var i = 0; i < nodes.length; i++) {
  13028. var node = nodes[i];
  13029. var sphere = node.getBoundingSphere().clone().applyMatrix4(node.sceneNode.matrixWorld);
  13030. // TODO Unused: let box = node.getBoundingBox().clone().applyMatrix4(node.sceneNode.matrixWorld);
  13031. if (_ray.intersectsSphere(sphere)) {
  13032. nodesOnRay.push(node);
  13033. }
  13034. // if(_ray.isIntersectionBox(box)){
  13035. // nodesOnRay.push(node);
  13036. // }
  13037. }
  13038. return nodesOnRay;
  13039. }
  13040. pick(viewer, camera, ray) {
  13041. var params = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  13042. var renderer = viewer.renderer;
  13043. var pRenderer = viewer.pRenderer;
  13044. performance.mark("pick-start");
  13045. var getVal = (a, b) => a !== undefined ? a : b;
  13046. var pickWindowSize = getVal(params.pickWindowSize, 17);
  13047. var pickOutsideClipRegion = getVal(params.pickOutsideClipRegion, false);
  13048. var size = renderer.getSize(new Vector2());
  13049. var width = Math.ceil(getVal(params.width, size.width));
  13050. var height = Math.ceil(getVal(params.height, size.height));
  13051. var pointSizeType = getVal(params.pointSizeType, this.material.pointSizeType);
  13052. var pointSize = getVal(params.pointSize, this.material.size);
  13053. var nodes = this.nodesOnRay(this.visibleNodes, ray);
  13054. if (nodes.length === 0) {
  13055. return null;
  13056. }
  13057. if (!this.pickState) {
  13058. var scene = new Scene();
  13059. var material = new PointCloudMaterial$1();
  13060. material.activeAttributeName = "indices";
  13061. var renderTarget = new WebGLRenderTarget(1, 1, {
  13062. minFilter: LinearFilter,
  13063. magFilter: NearestFilter,
  13064. format: RGBAFormat
  13065. });
  13066. this.pickState = {
  13067. renderTarget: renderTarget,
  13068. material: material,
  13069. scene: scene
  13070. };
  13071. }
  13072. ;
  13073. var pickState = this.pickState;
  13074. var pickMaterial = pickState.material;
  13075. {
  13076. // update pick material
  13077. pickMaterial.pointSizeType = pointSizeType;
  13078. pickMaterial.shape = this.material.shape;
  13079. pickMaterial.size = pointSize;
  13080. pickMaterial.uniforms.minSize.value = this.material.uniforms.minSize.value;
  13081. pickMaterial.uniforms.maxSize.value = this.material.uniforms.maxSize.value;
  13082. pickMaterial.classification = this.material.classification;
  13083. if (params.pickClipped) {
  13084. pickMaterial.clipBoxes = this.material.clipBoxes;
  13085. if (this.material.clipTask === ClipTask.HIGHLIGHT) {
  13086. pickMaterial.clipTask = ClipTask.NONE;
  13087. } else {
  13088. pickMaterial.clipTask = this.material.clipTask;
  13089. }
  13090. } else {
  13091. pickMaterial.clipBoxes = [];
  13092. }
  13093. this.updateMaterial(pickMaterial, nodes, camera, renderer);
  13094. }
  13095. pickState.renderTarget.setSize(width, height);
  13096. var pixelPos = new Vector2(params.x, params.y);
  13097. var gl = renderer.getContext();
  13098. gl.enable(gl.SCISSOR_TEST);
  13099. gl.scissor(parseInt(pixelPos.x - (pickWindowSize - 1) / 2), parseInt(pixelPos.y - (pickWindowSize - 1) / 2), parseInt(pickWindowSize), parseInt(pickWindowSize));
  13100. renderer.state.buffers.depth.setTest(pickMaterial.depthTest);
  13101. renderer.state.buffers.depth.setMask(pickMaterial.depthWrite);
  13102. renderer.state.setBlending(NoBlending);
  13103. renderer.clearTarget(pickState.renderTarget, true, true, true);
  13104. {
  13105. // RENDER
  13106. renderer.setRenderTarget(pickState.renderTarget);
  13107. gl.clearColor(0, 0, 0, 0);
  13108. renderer.clearTarget(pickState.renderTarget, true, true, true);
  13109. var tmp = this.material;
  13110. this.material = pickMaterial;
  13111. pRenderer.renderOctree(this, nodes, camera, pickState.renderTarget);
  13112. this.material = tmp;
  13113. }
  13114. var clamp = (number, min, max) => Math.min(Math.max(min, number), max);
  13115. var x = parseInt(clamp(pixelPos.x - (pickWindowSize - 1) / 2, 0, width));
  13116. var y = parseInt(clamp(pixelPos.y - (pickWindowSize - 1) / 2, 0, height));
  13117. var w = parseInt(Math.min(x + pickWindowSize, width) - x);
  13118. var h = parseInt(Math.min(y + pickWindowSize, height) - y);
  13119. var pixelCount = w * h;
  13120. var buffer = new Uint8Array(4 * pixelCount);
  13121. gl.readPixels(x, y, pickWindowSize, pickWindowSize, gl.RGBA, gl.UNSIGNED_BYTE, buffer);
  13122. renderer.setRenderTarget(null);
  13123. renderer.state.reset();
  13124. renderer.setScissorTest(false);
  13125. gl.disable(gl.SCISSOR_TEST);
  13126. var pixels = buffer;
  13127. var ibuffer = new Uint32Array(buffer.buffer);
  13128. // find closest hit inside pixelWindow boundaries
  13129. var min = Number.MAX_VALUE;
  13130. var hits = [];
  13131. for (var u = 0; u < pickWindowSize; u++) {
  13132. for (var v = 0; v < pickWindowSize; v++) {
  13133. var offset = u + v * pickWindowSize;
  13134. var distance = Math.pow(u - (pickWindowSize - 1) / 2, 2) + Math.pow(v - (pickWindowSize - 1) / 2, 2);
  13135. var pcIndex = pixels[4 * offset + 3];
  13136. pixels[4 * offset + 3] = 0;
  13137. var pIndex = ibuffer[offset];
  13138. if (!(pcIndex === 0 && pIndex === 0) && pcIndex !== undefined && pIndex !== undefined) {
  13139. var hit = {
  13140. pIndex: pIndex,
  13141. pcIndex: pcIndex,
  13142. distanceToCenter: distance
  13143. };
  13144. if (params.all) {
  13145. hits.push(hit);
  13146. } else {
  13147. if (hits.length > 0) {
  13148. if (distance < hits[0].distanceToCenter) {
  13149. hits[0] = hit;
  13150. }
  13151. } else {
  13152. hits.push(hit);
  13153. }
  13154. }
  13155. }
  13156. }
  13157. }
  13158. for (var _hit of hits) {
  13159. var point = {};
  13160. if (!nodes[_hit.pcIndex]) {
  13161. return null;
  13162. }
  13163. var node = nodes[_hit.pcIndex];
  13164. var pc = node.sceneNode;
  13165. var geometry = node.geometryNode.geometry;
  13166. for (var attributeName in geometry.attributes) {
  13167. var attribute = geometry.attributes[attributeName];
  13168. if (attributeName === 'position') {
  13169. var _x = attribute.array[3 * _hit.pIndex + 0];
  13170. var _y = attribute.array[3 * _hit.pIndex + 1];
  13171. var z = attribute.array[3 * _hit.pIndex + 2];
  13172. var position = new Vector3(_x, _y, z);
  13173. position.applyMatrix4(pc.matrixWorld);
  13174. point[attributeName] = position;
  13175. } else if (attributeName === 'indices') {} else {
  13176. //if (values.itemSize === 1) {
  13177. // point[attribute.name] = values.array[hit.pIndex];
  13178. //} else {
  13179. // let value = [];
  13180. // for (let j = 0; j < values.itemSize; j++) {
  13181. // value.push(values.array[values.itemSize * hit.pIndex + j]);
  13182. // }
  13183. // point[attribute.name] = value;
  13184. //}
  13185. }
  13186. }
  13187. _hit.point = point;
  13188. }
  13189. performance.mark("pick-end");
  13190. performance.measure("pick", "pick-start", "pick-end");
  13191. if (params.all) {
  13192. return hits.map(hit => hit.point);
  13193. } else {
  13194. if (hits.length === 0) {
  13195. return null;
  13196. } else {
  13197. return hits[0].point;
  13198. }
  13199. }
  13200. }
  13201. computeVisibilityTextureData(nodes) {
  13202. if (exports.measureTimings) performance.mark("computeVisibilityTextureData-start");
  13203. var data = new Uint8Array(nodes.length * 3);
  13204. var visibleNodeTextureOffsets = new Map();
  13205. // copy array
  13206. nodes = nodes.slice();
  13207. // sort by level and number
  13208. var sort = function sort(a, b) {
  13209. var la = a.geometryNode.level;
  13210. var lb = b.geometryNode.level;
  13211. var na = a.geometryNode.number;
  13212. var nb = b.geometryNode.number;
  13213. if (la !== lb) return la - lb;
  13214. if (na < nb) return -1;
  13215. if (na > nb) return 1;
  13216. return 0;
  13217. };
  13218. nodes.sort(sort);
  13219. var visibleNodeNames = [];
  13220. for (var i = 0; i < nodes.length; i++) {
  13221. visibleNodeNames.push(nodes[i].geometryNode.number);
  13222. }
  13223. for (var _i2 = 0; _i2 < nodes.length; _i2++) {
  13224. var node = nodes[_i2];
  13225. visibleNodeTextureOffsets.set(node, _i2);
  13226. var b1 = 0; // children
  13227. var b2 = 0; // offset to first child
  13228. var b3 = 0; // split
  13229. if (node.geometryNode.left && visibleNodeNames.indexOf(node.geometryNode.left.number) > 0) {
  13230. b1 += 1;
  13231. b2 = visibleNodeNames.indexOf(node.geometryNode.left.number) - _i2;
  13232. }
  13233. if (node.geometryNode.right && visibleNodeNames.indexOf(node.geometryNode.right.number) > 0) {
  13234. b1 += 2;
  13235. b2 = b2 === 0 ? visibleNodeNames.indexOf(node.geometryNode.right.number) - _i2 : b2;
  13236. }
  13237. if (node.geometryNode.split === 'X') {
  13238. b3 = 1;
  13239. } else if (node.geometryNode.split === 'Y') {
  13240. b3 = 2;
  13241. } else if (node.geometryNode.split === 'Z') {
  13242. b3 = 4;
  13243. }
  13244. data[_i2 * 3 + 0] = b1;
  13245. data[_i2 * 3 + 1] = b2;
  13246. data[_i2 * 3 + 2] = b3;
  13247. }
  13248. if (exports.measureTimings) {
  13249. performance.mark("computeVisibilityTextureData-end");
  13250. performance.measure("render.computeVisibilityTextureData", "computeVisibilityTextureData-start", "computeVisibilityTextureData-end");
  13251. }
  13252. return {
  13253. data: data,
  13254. offsets: visibleNodeTextureOffsets
  13255. };
  13256. }
  13257. get progress() {
  13258. if (this.pcoGeometry.root) {
  13259. return exports.numNodesLoading > 0 ? 0 : 1;
  13260. } else {
  13261. return 0;
  13262. }
  13263. }
  13264. }
  13265. ;
  13266. // Copied from three.js: WebGLRenderer.js
  13267. function paramThreeToGL(_gl, p) {
  13268. var extension;
  13269. if (p === RepeatWrapping) return _gl.REPEAT;
  13270. if (p === ClampToEdgeWrapping) return _gl.CLAMP_TO_EDGE;
  13271. if (p === MirroredRepeatWrapping) return _gl.MIRRORED_REPEAT;
  13272. if (p === NearestFilter) return _gl.NEAREST;
  13273. if (p === NearestMipMapNearestFilter) return _gl.NEAREST_MIPMAP_NEAREST;
  13274. if (p === NearestMipMapLinearFilter) return _gl.NEAREST_MIPMAP_LINEAR;
  13275. if (p === LinearFilter) return _gl.LINEAR;
  13276. if (p === LinearMipMapNearestFilter) return _gl.LINEAR_MIPMAP_NEAREST;
  13277. if (p === LinearMipMapLinearFilter) return _gl.LINEAR_MIPMAP_LINEAR;
  13278. if (p === UnsignedByteType) return _gl.UNSIGNED_BYTE;
  13279. if (p === UnsignedShort4444Type) return _gl.UNSIGNED_SHORT_4_4_4_4;
  13280. if (p === UnsignedShort5551Type) return _gl.UNSIGNED_SHORT_5_5_5_1;
  13281. if (p === UnsignedShort565Type) return _gl.UNSIGNED_SHORT_5_6_5;
  13282. if (p === ByteType) return _gl.BYTE;
  13283. if (p === ShortType) return _gl.SHORT;
  13284. if (p === UnsignedShortType) return _gl.UNSIGNED_SHORT;
  13285. if (p === IntType) return _gl.INT;
  13286. if (p === UnsignedIntType) return _gl.UNSIGNED_INT;
  13287. if (p === FloatType) return _gl.FLOAT;
  13288. if (p === HalfFloatType) {
  13289. extension = extensions.get('OES_texture_half_float');
  13290. if (extension !== null) return extension.HALF_FLOAT_OES;
  13291. }
  13292. if (p === AlphaFormat) return _gl.ALPHA;
  13293. if (p === RGBFormat) return _gl.RGB;
  13294. if (p === RGBAFormat) return _gl.RGBA;
  13295. if (p === LuminanceFormat) return _gl.LUMINANCE;
  13296. if (p === LuminanceAlphaFormat) return _gl.LUMINANCE_ALPHA;
  13297. if (p === DepthFormat) return _gl.DEPTH_COMPONENT;
  13298. if (p === DepthStencilFormat) return _gl.DEPTH_STENCIL;
  13299. if (p === AddEquation) return _gl.FUNC_ADD;
  13300. if (p === SubtractEquation) return _gl.FUNC_SUBTRACT;
  13301. if (p === ReverseSubtractEquation) return _gl.FUNC_REVERSE_SUBTRACT;
  13302. if (p === ZeroFactor) return _gl.ZERO;
  13303. if (p === OneFactor) return _gl.ONE;
  13304. if (p === SrcColorFactor) return _gl.SRC_COLOR;
  13305. if (p === OneMinusSrcColorFactor) return _gl.ONE_MINUS_SRC_COLOR;
  13306. if (p === SrcAlphaFactor) return _gl.SRC_ALPHA;
  13307. if (p === OneMinusSrcAlphaFactor) return _gl.ONE_MINUS_SRC_ALPHA;
  13308. if (p === DstAlphaFactor) return _gl.DST_ALPHA;
  13309. if (p === OneMinusDstAlphaFactor) return _gl.ONE_MINUS_DST_ALPHA;
  13310. if (p === DstColorFactor) return _gl.DST_COLOR;
  13311. if (p === OneMinusDstColorFactor) return _gl.ONE_MINUS_DST_COLOR;
  13312. if (p === SrcAlphaSaturateFactor) return _gl.SRC_ALPHA_SATURATE;
  13313. if (p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format || p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format) {
  13314. extension = extensions.get('WEBGL_compressed_texture_s3tc');
  13315. if (extension !== null) {
  13316. if (p === RGB_S3TC_DXT1_Format) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  13317. if (p === RGBA_S3TC_DXT1_Format$1) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  13318. if (p === RGBA_S3TC_DXT3_Format) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  13319. if (p === RGBA_S3TC_DXT5_Format$1) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  13320. }
  13321. }
  13322. if (p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format || p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format) {
  13323. extension = extensions.get('WEBGL_compressed_texture_pvrtc');
  13324. if (extension !== null) {
  13325. if (p === RGB_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  13326. if (p === RGB_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  13327. if (p === RGBA_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  13328. if (p === RGBA_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  13329. }
  13330. }
  13331. if (p === RGB_ETC1_Format) {
  13332. extension = extensions.get('WEBGL_compressed_texture_etc1');
  13333. if (extension !== null) return extension.COMPRESSED_RGB_ETC1_WEBGL;
  13334. }
  13335. if (p === MinEquation || p === MaxEquation) {
  13336. extension = extensions.get('EXT_blend_minmax');
  13337. if (extension !== null) {
  13338. if (p === MinEquation) return extension.MIN_EXT;
  13339. if (p === MaxEquation) return extension.MAX_EXT;
  13340. }
  13341. }
  13342. if (p === UnsignedInt248Type) {
  13343. extension = extensions.get('WEBGL_depth_texture');
  13344. if (extension !== null) return extension.UNSIGNED_INT_24_8_WEBGL;
  13345. }
  13346. return 0;
  13347. }
  13348. ;
  13349. var attributeLocations = {
  13350. "position": {
  13351. name: "position",
  13352. location: 0
  13353. },
  13354. "color": {
  13355. name: "color",
  13356. location: 1
  13357. },
  13358. "rgba": {
  13359. name: "color",
  13360. location: 1
  13361. },
  13362. "intensity": {
  13363. name: "intensity",
  13364. location: 2
  13365. },
  13366. "classification": {
  13367. name: "classification",
  13368. location: 3
  13369. },
  13370. "returnNumber": {
  13371. name: "returnNumber",
  13372. location: 4
  13373. },
  13374. "return number": {
  13375. name: "returnNumber",
  13376. location: 4
  13377. },
  13378. "returns": {
  13379. name: "returnNumber",
  13380. location: 4
  13381. },
  13382. "numberOfReturns": {
  13383. name: "numberOfReturns",
  13384. location: 5
  13385. },
  13386. "number of returns": {
  13387. name: "numberOfReturns",
  13388. location: 5
  13389. },
  13390. "pointSourceID": {
  13391. name: "pointSourceID",
  13392. location: 6
  13393. },
  13394. "source id": {
  13395. name: "pointSourceID",
  13396. location: 6
  13397. },
  13398. "point source id": {
  13399. name: "pointSourceID",
  13400. location: 6
  13401. },
  13402. "indices": {
  13403. name: "indices",
  13404. location: 7
  13405. },
  13406. "normal": {
  13407. name: "normal",
  13408. location: 8
  13409. },
  13410. "spacing": {
  13411. name: "spacing",
  13412. location: 9
  13413. },
  13414. "gps-time": {
  13415. name: "gpsTime",
  13416. location: 10
  13417. },
  13418. "aExtra": {
  13419. name: "aExtra",
  13420. location: 11
  13421. }
  13422. };
  13423. class Shader {
  13424. constructor(gl, name, vsSource, fsSource) {
  13425. this.gl = gl;
  13426. this.name = name;
  13427. this.vsSource = vsSource;
  13428. this.fsSource = fsSource;
  13429. this.cache = new Map();
  13430. this.vs = null;
  13431. this.fs = null;
  13432. this.program = null;
  13433. this.uniformLocations = {};
  13434. this.attributeLocations = {};
  13435. this.uniformBlockIndices = {};
  13436. this.uniformBlocks = {};
  13437. this.uniforms = {};
  13438. this.update(vsSource, fsSource);
  13439. }
  13440. update(vsSource, fsSource) {
  13441. this.vsSource = vsSource;
  13442. this.fsSource = fsSource;
  13443. this.linkProgram();
  13444. }
  13445. compileShader(shader, source) {
  13446. var gl = this.gl;
  13447. gl.shaderSource(shader, source);
  13448. gl.compileShader(shader);
  13449. var success = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  13450. if (!success) {
  13451. var info = gl.getShaderInfoLog(shader);
  13452. var numberedSource = source.split("\n").map((a, i) => "".concat(i + 1).padEnd(5) + a).join("\n");
  13453. throw "could not compile shader ".concat(this.name, ": ").concat(info, ", \n").concat(numberedSource);
  13454. }
  13455. }
  13456. linkProgram() {
  13457. var tStart = performance.now();
  13458. var gl = this.gl;
  13459. this.uniformLocations = {};
  13460. this.attributeLocations = {};
  13461. this.uniforms = {};
  13462. gl.useProgram(null);
  13463. var cached = this.cache.get("".concat(this.vsSource, ", ").concat(this.fsSource));
  13464. if (cached) {
  13465. this.program = cached.program;
  13466. this.vs = cached.vs;
  13467. this.fs = cached.fs;
  13468. this.attributeLocations = cached.attributeLocations;
  13469. this.uniformLocations = cached.uniformLocations;
  13470. this.uniformBlocks = cached.uniformBlocks;
  13471. this.uniforms = cached.uniforms;
  13472. return;
  13473. } else {
  13474. this.vs = gl.createShader(gl.VERTEX_SHADER);
  13475. this.fs = gl.createShader(gl.FRAGMENT_SHADER);
  13476. this.program = gl.createProgram();
  13477. for (var name of Object.keys(attributeLocations)) {
  13478. var location = attributeLocations[name].location;
  13479. var glslName = attributeLocations[name].name;
  13480. gl.bindAttribLocation(this.program, location, glslName);
  13481. }
  13482. this.compileShader(this.vs, this.vsSource);
  13483. this.compileShader(this.fs, this.fsSource);
  13484. var program = this.program;
  13485. gl.attachShader(program, this.vs);
  13486. gl.attachShader(program, this.fs);
  13487. gl.linkProgram(program);
  13488. gl.detachShader(program, this.vs);
  13489. gl.detachShader(program, this.fs);
  13490. var success = gl.getProgramParameter(program, gl.LINK_STATUS);
  13491. if (!success) {
  13492. var info = gl.getProgramInfoLog(program);
  13493. throw "could not link program ".concat(this.name, ": ").concat(info);
  13494. }
  13495. {
  13496. // attribute locations
  13497. var numAttributes = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
  13498. for (var i = 0; i < numAttributes; i++) {
  13499. var attribute = gl.getActiveAttrib(program, i);
  13500. var _location = gl.getAttribLocation(program, attribute.name);
  13501. this.attributeLocations[attribute.name] = _location;
  13502. }
  13503. }
  13504. {
  13505. // uniform locations
  13506. var numUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
  13507. for (var _i = 0; _i < numUniforms; _i++) {
  13508. var uniform = gl.getActiveUniform(program, _i);
  13509. var _location2 = gl.getUniformLocation(program, uniform.name);
  13510. this.uniformLocations[uniform.name] = _location2;
  13511. this.uniforms[uniform.name] = {
  13512. location: _location2,
  13513. value: null
  13514. };
  13515. }
  13516. }
  13517. // uniform blocks
  13518. if (typeof WebGL2RenderingContext != 'undefined' && gl instanceof WebGL2RenderingContext) {
  13519. var numBlocks = gl.getProgramParameter(program, gl.ACTIVE_UNIFORM_BLOCKS);
  13520. for (var _i2 = 0; _i2 < numBlocks; _i2++) {
  13521. var blockName = gl.getActiveUniformBlockName(program, _i2);
  13522. var blockIndex = gl.getUniformBlockIndex(program, blockName);
  13523. this.uniformBlockIndices[blockName] = blockIndex;
  13524. gl.uniformBlockBinding(program, blockIndex, blockIndex);
  13525. var dataSize = gl.getActiveUniformBlockParameter(program, blockIndex, gl.UNIFORM_BLOCK_DATA_SIZE);
  13526. var uBuffer = gl.createBuffer();
  13527. gl.bindBuffer(gl.UNIFORM_BUFFER, uBuffer);
  13528. gl.bufferData(gl.UNIFORM_BUFFER, dataSize, gl.DYNAMIC_READ);
  13529. gl.bindBufferBase(gl.UNIFORM_BUFFER, blockIndex, uBuffer);
  13530. gl.bindBuffer(gl.UNIFORM_BUFFER, null);
  13531. this.uniformBlocks[blockName] = {
  13532. name: blockName,
  13533. index: blockIndex,
  13534. dataSize: dataSize,
  13535. buffer: uBuffer
  13536. };
  13537. }
  13538. }
  13539. var _cached = {
  13540. program: this.program,
  13541. vs: this.vs,
  13542. fs: this.fs,
  13543. attributeLocations: this.attributeLocations,
  13544. uniformLocations: this.uniformLocations,
  13545. uniforms: this.uniforms,
  13546. uniformBlocks: this.uniformBlocks
  13547. };
  13548. this.cache.set("".concat(this.vsSource, ", ").concat(this.fsSource), _cached);
  13549. }
  13550. var tEnd = performance.now();
  13551. var duration = tEnd - tStart;
  13552. console.log("shader compile duration: ".concat(duration.toFixed(3)));
  13553. }
  13554. setUniformMatrix4(name, value) {
  13555. var gl = this.gl;
  13556. var location = this.uniformLocations[name];
  13557. if (location == null) {
  13558. return;
  13559. }
  13560. var tmp = new Float32Array(value.elements);
  13561. gl.uniformMatrix4fv(location, false, tmp);
  13562. }
  13563. setUniform1f(name, value) {
  13564. var gl = this.gl;
  13565. var uniform = this.uniforms[name];
  13566. if (uniform === undefined) {
  13567. return;
  13568. }
  13569. if (uniform.value === value) {
  13570. return;
  13571. }
  13572. uniform.value = value;
  13573. gl.uniform1f(uniform.location, value);
  13574. }
  13575. setUniformBoolean(name, value) {
  13576. var gl = this.gl;
  13577. var uniform = this.uniforms[name];
  13578. if (uniform === undefined) {
  13579. return;
  13580. }
  13581. if (uniform.value === value) {
  13582. return;
  13583. }
  13584. uniform.value = value;
  13585. gl.uniform1i(uniform.location, value);
  13586. }
  13587. setUniformTexture(name, value) {
  13588. var gl = this.gl;
  13589. var location = this.uniformLocations[name];
  13590. if (location == null) {
  13591. return;
  13592. }
  13593. gl.uniform1i(location, value);
  13594. }
  13595. setUniform2f(name, value) {
  13596. var gl = this.gl;
  13597. var location = this.uniformLocations[name];
  13598. if (location == null) {
  13599. return;
  13600. }
  13601. gl.uniform2f(location, value[0], value[1]);
  13602. }
  13603. setUniform3f(name, value) {
  13604. var gl = this.gl;
  13605. var location = this.uniformLocations[name];
  13606. if (location == null) {
  13607. return;
  13608. }
  13609. gl.uniform3f(location, value[0], value[1], value[2]);
  13610. }
  13611. setUniform(name, value) {
  13612. if (value.constructor === Matrix4) {
  13613. this.setUniformMatrix4(name, value);
  13614. } else if (typeof value === "number") {
  13615. this.setUniform1f(name, value);
  13616. } else if (typeof value === "boolean") {
  13617. this.setUniformBoolean(name, value);
  13618. } else if (value instanceof WebGLTexture) {
  13619. this.setUniformTexture(name, value);
  13620. } else if (value instanceof Array) {
  13621. if (value.length === 2) {
  13622. this.setUniform2f(name, value);
  13623. } else if (value.length === 3) {
  13624. this.setUniform3f(name, value);
  13625. }
  13626. } else {
  13627. console.error("unhandled uniform type: ", name, value);
  13628. }
  13629. }
  13630. setUniform1i(name, value) {
  13631. var gl = this.gl;
  13632. var location = this.uniformLocations[name];
  13633. if (location == null) {
  13634. return;
  13635. }
  13636. gl.uniform1i(location, value);
  13637. }
  13638. }
  13639. ;
  13640. class WebGLTexture {
  13641. constructor(gl, texture) {
  13642. this.gl = gl;
  13643. this.texture = texture;
  13644. this.id = gl.createTexture();
  13645. this.target = gl.TEXTURE_2D;
  13646. this.version = -1;
  13647. this.update(texture);
  13648. }
  13649. update() {
  13650. if (!this.texture.image) {
  13651. this.version = this.texture.version;
  13652. return;
  13653. }
  13654. var gl = this.gl;
  13655. var texture = this.texture;
  13656. if (this.version === texture.version) {
  13657. return;
  13658. }
  13659. this.target = gl.TEXTURE_2D;
  13660. gl.bindTexture(this.target, this.id);
  13661. var level = 0;
  13662. var internalFormat = paramThreeToGL(gl, texture.format);
  13663. var width = texture.image.width;
  13664. var height = texture.image.height;
  13665. var border = 0;
  13666. var srcFormat = internalFormat;
  13667. var srcType = paramThreeToGL(gl, texture.type);
  13668. var data;
  13669. gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, texture.flipY);
  13670. gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha);
  13671. gl.pixelStorei(gl.UNPACK_ALIGNMENT, texture.unpackAlignment);
  13672. if (texture instanceof DataTexture) {
  13673. data = texture.image.data;
  13674. gl.texParameteri(this.target, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  13675. gl.texParameteri(this.target, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  13676. gl.texParameteri(this.target, gl.TEXTURE_MAG_FILTER, paramThreeToGL(gl, texture.magFilter));
  13677. gl.texParameteri(this.target, gl.TEXTURE_MIN_FILTER, paramThreeToGL(gl, texture.minFilter));
  13678. gl.texImage2D(this.target, level, internalFormat, width, height, border, srcFormat, srcType, data);
  13679. } else if (texture instanceof CanvasTexture || texture instanceof Texture) {
  13680. data = texture.image;
  13681. gl.texParameteri(this.target, gl.TEXTURE_WRAP_S, paramThreeToGL(gl, texture.wrapS));
  13682. gl.texParameteri(this.target, gl.TEXTURE_WRAP_T, paramThreeToGL(gl, texture.wrapT));
  13683. gl.texParameteri(this.target, gl.TEXTURE_MAG_FILTER, paramThreeToGL(gl, texture.magFilter));
  13684. gl.texParameteri(this.target, gl.TEXTURE_MIN_FILTER, paramThreeToGL(gl, texture.minFilter));
  13685. gl.texImage2D(this.target, level, internalFormat, internalFormat, srcType, data);
  13686. if (texture instanceof Texture) {
  13687. gl.generateMipmap(gl.TEXTURE_2D);
  13688. }
  13689. }
  13690. gl.bindTexture(this.target, null);
  13691. this.version = texture.version;
  13692. }
  13693. }
  13694. ;
  13695. class WebGLBuffer {
  13696. constructor() {
  13697. this.numElements = 0;
  13698. this.vao = null;
  13699. this.vbos = new Map();
  13700. }
  13701. }
  13702. ;
  13703. class Renderer {
  13704. constructor(threeRenderer) {
  13705. this.threeRenderer = threeRenderer;
  13706. this.gl = this.threeRenderer.getContext();
  13707. this.buffers = new Map();
  13708. this.shaders = new Map();
  13709. this.textures = new Map();
  13710. this.glTypeMapping = new Map();
  13711. this.glTypeMapping.set(Float32Array, this.gl.FLOAT);
  13712. this.glTypeMapping.set(Uint8Array, this.gl.UNSIGNED_BYTE);
  13713. this.glTypeMapping.set(Uint16Array, this.gl.UNSIGNED_SHORT);
  13714. this.toggle = 0;
  13715. }
  13716. deleteBuffer(geometry) {
  13717. var gl = this.gl;
  13718. var webglBuffer = this.buffers.get(geometry);
  13719. if (webglBuffer != null) {
  13720. for (var attributeName in geometry.attributes) {
  13721. gl.deleteBuffer(webglBuffer.vbos.get(attributeName).handle);
  13722. }
  13723. this.buffers.delete(geometry);
  13724. }
  13725. }
  13726. createBuffer(geometry) {
  13727. var gl = this.gl;
  13728. var webglBuffer = new WebGLBuffer();
  13729. webglBuffer.vao = gl.createVertexArray();
  13730. webglBuffer.numElements = geometry.attributes.position.count;
  13731. gl.bindVertexArray(webglBuffer.vao);
  13732. for (var attributeName in geometry.attributes) {
  13733. var bufferAttribute = geometry.attributes[attributeName];
  13734. var vbo = gl.createBuffer();
  13735. gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
  13736. gl.bufferData(gl.ARRAY_BUFFER, bufferAttribute.array, gl.STATIC_DRAW);
  13737. var normalized = bufferAttribute.normalized;
  13738. var type = this.glTypeMapping.get(bufferAttribute.array.constructor);
  13739. if (attributeLocations[attributeName] === undefined) {
  13740. //attributeLocation = attributeLocations["aExtra"];
  13741. } else {
  13742. var attributeLocation = attributeLocations[attributeName].location;
  13743. gl.vertexAttribPointer(attributeLocation, bufferAttribute.itemSize, type, normalized, 0, 0);
  13744. gl.enableVertexAttribArray(attributeLocation);
  13745. }
  13746. webglBuffer.vbos.set(attributeName, {
  13747. handle: vbo,
  13748. name: attributeName,
  13749. count: bufferAttribute.count,
  13750. itemSize: bufferAttribute.itemSize,
  13751. type: geometry.attributes.position.array.constructor,
  13752. version: 0
  13753. });
  13754. }
  13755. gl.bindBuffer(gl.ARRAY_BUFFER, null);
  13756. gl.bindVertexArray(null);
  13757. var disposeHandler = event => {
  13758. this.deleteBuffer(geometry);
  13759. geometry.removeEventListener("dispose", disposeHandler);
  13760. };
  13761. geometry.addEventListener("dispose", disposeHandler);
  13762. return webglBuffer;
  13763. }
  13764. updateBuffer(geometry) {
  13765. var gl = this.gl;
  13766. var webglBuffer = this.buffers.get(geometry);
  13767. gl.bindVertexArray(webglBuffer.vao);
  13768. for (var attributeName in geometry.attributes) {
  13769. var bufferAttribute = geometry.attributes[attributeName];
  13770. var normalized = bufferAttribute.normalized;
  13771. var type = this.glTypeMapping.get(bufferAttribute.array.constructor);
  13772. var vbo = null;
  13773. if (!webglBuffer.vbos.has(attributeName)) {
  13774. vbo = gl.createBuffer();
  13775. webglBuffer.vbos.set(attributeName, {
  13776. handle: vbo,
  13777. name: attributeName,
  13778. count: bufferAttribute.count,
  13779. itemSize: bufferAttribute.itemSize,
  13780. type: geometry.attributes.position.array.constructor,
  13781. version: bufferAttribute.version
  13782. });
  13783. } else {
  13784. vbo = webglBuffer.vbos.get(attributeName).handle;
  13785. webglBuffer.vbos.get(attributeName).version = bufferAttribute.version;
  13786. }
  13787. gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
  13788. gl.bufferData(gl.ARRAY_BUFFER, bufferAttribute.array, gl.STATIC_DRAW);
  13789. if (attributeLocations[attributeName] === undefined) {
  13790. //attributeLocation = attributeLocations["aExtra"];
  13791. } else {
  13792. var attributeLocation = attributeLocations[attributeName].location;
  13793. gl.vertexAttribPointer(attributeLocation, bufferAttribute.itemSize, type, normalized, 0, 0);
  13794. gl.enableVertexAttribArray(attributeLocation);
  13795. }
  13796. }
  13797. gl.bindBuffer(gl.ARRAY_BUFFER, null);
  13798. gl.bindVertexArray(null);
  13799. }
  13800. traverse(scene) {
  13801. var octrees = [];
  13802. var stack = [scene];
  13803. while (stack.length > 0) {
  13804. var node = stack.pop();
  13805. if (node instanceof PointCloudTree) {
  13806. octrees.push(node);
  13807. continue;
  13808. }
  13809. var visibleChildren = node.children.filter(c => c.visible);
  13810. stack.push(...visibleChildren);
  13811. }
  13812. var result = {
  13813. octrees: octrees
  13814. };
  13815. return result;
  13816. }
  13817. renderNodes(octree, nodes, visibilityTextureData, camera, target, shader, params) {
  13818. var _this = this;
  13819. if (exports.measureTimings) performance.mark("renderNodes-start");
  13820. var gl = this.gl;
  13821. var material = params.material ? params.material : octree.material;
  13822. var shadowMaps = params.shadowMaps == null ? [] : params.shadowMaps;
  13823. var view = camera.matrixWorldInverse;
  13824. if (params.viewOverride) {
  13825. view = params.viewOverride;
  13826. }
  13827. var worldView = new Matrix4();
  13828. var mat4holder = new Float32Array(16);
  13829. var i = 0;
  13830. var _loop = function _loop() {
  13831. if (exports.debug.allowedNodes !== undefined) {
  13832. if (!exports.debug.allowedNodes.includes(node.name)) {
  13833. return 1; // continue
  13834. }
  13835. }
  13836. var world = node.sceneNode.matrixWorld;
  13837. worldView.multiplyMatrices(view, world);
  13838. if (visibilityTextureData) {
  13839. var vnStart = visibilityTextureData.offsets.get(node);
  13840. shader.setUniform1f("uVNStart", vnStart);
  13841. }
  13842. var level = node.getLevel();
  13843. if (node.debug) {
  13844. shader.setUniform("uDebug", true);
  13845. } else {
  13846. shader.setUniform("uDebug", false);
  13847. }
  13848. // let isLeaf = false;
  13849. // if(node instanceof PointCloudOctreeNode){
  13850. // isLeaf = Object.keys(node.children).length === 0;
  13851. // }else if(node instanceof PointCloudArena4DNode){
  13852. // isLeaf = node.geometryNode.isLeaf;
  13853. // }
  13854. // shader.setUniform("uIsLeafNode", isLeaf);
  13855. // let isLeaf = node.children.filter(n => n != null).length === 0;
  13856. // if(!isLeaf){
  13857. // continue;
  13858. // }
  13859. // TODO consider passing matrices in an array to avoid uniformMatrix4fv overhead
  13860. var lModel = shader.uniformLocations["modelMatrix"];
  13861. if (lModel) {
  13862. mat4holder.set(world.elements);
  13863. gl.uniformMatrix4fv(lModel, false, mat4holder);
  13864. }
  13865. var lModelView = shader.uniformLocations["modelViewMatrix"];
  13866. //mat4holder.set(worldView.elements);
  13867. // faster then set in chrome 63
  13868. for (var j = 0; j < 16; j++) {
  13869. mat4holder[j] = worldView.elements[j];
  13870. }
  13871. gl.uniformMatrix4fv(lModelView, false, mat4holder);
  13872. {
  13873. // Clip Polygons
  13874. if (material.clipPolygons && material.clipPolygons.length > 0) {
  13875. var clipPolygonVCount = [];
  13876. var worldViewProjMatrices = [];
  13877. for (var clipPolygon of material.clipPolygons) {
  13878. var _view = clipPolygon.viewMatrix;
  13879. var proj = clipPolygon.projMatrix;
  13880. var worldViewProj = proj.clone().multiply(_view).multiply(world);
  13881. clipPolygonVCount.push(clipPolygon.markers.length);
  13882. worldViewProjMatrices.push(worldViewProj);
  13883. }
  13884. var flattenedMatrices = [].concat(...worldViewProjMatrices.map(m => m.elements));
  13885. var flattenedVertices = new Array(8 * 3 * material.clipPolygons.length);
  13886. for (var _i3 = 0; _i3 < material.clipPolygons.length; _i3++) {
  13887. var _clipPolygon = material.clipPolygons[_i3];
  13888. for (var _j = 0; _j < _clipPolygon.markers.length; _j++) {
  13889. flattenedVertices[_i3 * 24 + (_j * 3 + 0)] = _clipPolygon.markers[_j].position.x;
  13890. flattenedVertices[_i3 * 24 + (_j * 3 + 1)] = _clipPolygon.markers[_j].position.y;
  13891. flattenedVertices[_i3 * 24 + (_j * 3 + 2)] = _clipPolygon.markers[_j].position.z;
  13892. }
  13893. }
  13894. var lClipPolygonVCount = shader.uniformLocations["uClipPolygonVCount[0]"];
  13895. gl.uniform1iv(lClipPolygonVCount, clipPolygonVCount);
  13896. var lClipPolygonVP = shader.uniformLocations["uClipPolygonWVP[0]"];
  13897. gl.uniformMatrix4fv(lClipPolygonVP, false, flattenedMatrices);
  13898. var lClipPolygons = shader.uniformLocations["uClipPolygonVertices[0]"];
  13899. gl.uniform3fv(lClipPolygons, flattenedVertices);
  13900. }
  13901. }
  13902. //shader.setUniformMatrix4("modelMatrix", world);
  13903. //shader.setUniformMatrix4("modelViewMatrix", worldView);
  13904. shader.setUniform1f("uLevel", level);
  13905. shader.setUniform1f("uNodeSpacing", node.geometryNode.estimatedSpacing);
  13906. shader.setUniform1f("uPCIndex", i);
  13907. // uBBSize
  13908. if (shadowMaps.length > 0) {
  13909. var lShadowMap = shader.uniformLocations["uShadowMap[0]"];
  13910. shader.setUniform3f("uShadowColor", material.uniforms.uShadowColor.value);
  13911. var bindingStart = 5;
  13912. var bindingPoints = new Array(shadowMaps.length).fill(bindingStart).map((a, i) => a + i);
  13913. gl.uniform1iv(lShadowMap, bindingPoints);
  13914. for (var _i4 = 0; _i4 < shadowMaps.length; _i4++) {
  13915. var shadowMap = shadowMaps[_i4];
  13916. var bindingPoint = bindingPoints[_i4];
  13917. var glTexture = _this.threeRenderer.properties.get(shadowMap.target.texture).__webglTexture;
  13918. gl.activeTexture(gl["TEXTURE".concat(bindingPoint)]);
  13919. gl.bindTexture(gl.TEXTURE_2D, glTexture);
  13920. }
  13921. {
  13922. var worldViewMatrices = shadowMaps.map(sm => sm.camera.matrixWorldInverse).map(view => new Matrix4().multiplyMatrices(view, world));
  13923. var _flattenedMatrices = [].concat(...worldViewMatrices.map(c => c.elements));
  13924. var lWorldView = shader.uniformLocations["uShadowWorldView[0]"];
  13925. gl.uniformMatrix4fv(lWorldView, false, _flattenedMatrices);
  13926. }
  13927. {
  13928. var _flattenedMatrices2 = [].concat(...shadowMaps.map(sm => sm.camera.projectionMatrix.elements));
  13929. var lProj = shader.uniformLocations["uShadowProj[0]"];
  13930. gl.uniformMatrix4fv(lProj, false, _flattenedMatrices2);
  13931. }
  13932. }
  13933. var geometry = node.geometryNode.geometry;
  13934. if (geometry.attributes["gps-time"]) {
  13935. var bufferAttribute = geometry.attributes["gps-time"];
  13936. var attGPS = octree.getAttribute("gps-time");
  13937. var initialRange = attGPS.initialRange;
  13938. var initialRangeSize = initialRange[1] - initialRange[0];
  13939. var globalRange = attGPS.range;
  13940. var globalRangeSize = globalRange[1] - globalRange[0];
  13941. var scale = initialRangeSize / globalRangeSize;
  13942. var offset = -(globalRange[0] - initialRange[0]) / initialRangeSize;
  13943. scale = Number.isNaN(scale) ? 1 : scale;
  13944. offset = Number.isNaN(offset) ? 0 : offset;
  13945. shader.setUniform1f("uGpsScale", scale);
  13946. shader.setUniform1f("uGpsOffset", offset);
  13947. //shader.setUniform2f("uFilterGPSTimeClipRange", [-Infinity, Infinity]);
  13948. var uFilterGPSTimeClipRange = material.uniforms.uFilterGPSTimeClipRange.value;
  13949. // let gpsCliPRangeMin = uFilterGPSTimeClipRange[0]
  13950. // let gpsCliPRangeMax = uFilterGPSTimeClipRange[1]
  13951. // shader.setUniform2f("uFilterGPSTimeClipRange", [gpsCliPRangeMin, gpsCliPRangeMax]);
  13952. var normalizedClipRange = [(uFilterGPSTimeClipRange[0] - globalRange[0]) / globalRangeSize, (uFilterGPSTimeClipRange[1] - globalRange[0]) / globalRangeSize];
  13953. shader.setUniform2f("uFilterGPSTimeClipRange", normalizedClipRange);
  13954. // // ranges in full gps coordinate system
  13955. // const globalRange = attGPS.range;
  13956. // const bufferRange = bufferAttribute.potree.range;
  13957. // // ranges in [0, 1]
  13958. // // normalizedGlobalRange = [0, 1]
  13959. // // normalizedBufferRange: norm buffer within norm global range e.g. [0.2, 0.8]
  13960. // const globalWidth = globalRange[1] - globalRange[0];
  13961. // const normalizedBufferRange = [
  13962. // (bufferRange[0] - globalRange[0]) / globalWidth,
  13963. // (bufferRange[1] - globalRange[0]) / globalWidth,
  13964. // ];
  13965. // shader.setUniform2f("uNormalizedGpsBufferRange", normalizedBufferRange);
  13966. // let uFilterGPSTimeClipRange = material.uniforms.uFilterGPSTimeClipRange.value;
  13967. // let gpsCliPRangeMin = uFilterGPSTimeClipRange[0]
  13968. // let gpsCliPRangeMax = uFilterGPSTimeClipRange[1]
  13969. // shader.setUniform2f("uFilterGPSTimeClipRange", [gpsCliPRangeMin, gpsCliPRangeMax]);
  13970. // shader.setUniform1f("uGpsScale", bufferAttribute.potree.scale);
  13971. // shader.setUniform1f("uGpsOffset", bufferAttribute.potree.offset);
  13972. }
  13973. {
  13974. var uFilterReturnNumberRange = material.uniforms.uFilterReturnNumberRange.value;
  13975. var uFilterNumberOfReturnsRange = material.uniforms.uFilterNumberOfReturnsRange.value;
  13976. var uFilterPointSourceIDClipRange = material.uniforms.uFilterPointSourceIDClipRange.value;
  13977. shader.setUniform2f("uFilterReturnNumberRange", uFilterReturnNumberRange);
  13978. shader.setUniform2f("uFilterNumberOfReturnsRange", uFilterNumberOfReturnsRange);
  13979. shader.setUniform2f("uFilterPointSourceIDClipRange", uFilterPointSourceIDClipRange);
  13980. }
  13981. var webglBuffer = null;
  13982. if (!_this.buffers.has(geometry)) {
  13983. webglBuffer = _this.createBuffer(geometry);
  13984. _this.buffers.set(geometry, webglBuffer);
  13985. } else {
  13986. webglBuffer = _this.buffers.get(geometry);
  13987. for (var attributeName in geometry.attributes) {
  13988. var attribute = geometry.attributes[attributeName];
  13989. if (attribute.version > webglBuffer.vbos.get(attributeName).version) {
  13990. _this.updateBuffer(geometry);
  13991. }
  13992. }
  13993. }
  13994. gl.bindVertexArray(webglBuffer.vao);
  13995. var isExtraAttribute = attributeLocations[material.activeAttributeName] === undefined && Object.keys(geometry.attributes).includes(material.activeAttributeName);
  13996. if (isExtraAttribute) {
  13997. var attributeLocation = attributeLocations["aExtra"].location;
  13998. for (var _attributeName in geometry.attributes) {
  13999. var _bufferAttribute = geometry.attributes[_attributeName];
  14000. var _vbo = webglBuffer.vbos.get(_attributeName);
  14001. gl.bindBuffer(gl.ARRAY_BUFFER, _vbo.handle);
  14002. gl.disableVertexAttribArray(attributeLocation);
  14003. }
  14004. var attName = material.activeAttributeName;
  14005. var _bufferAttribute2 = geometry.attributes[attName];
  14006. var vbo = webglBuffer.vbos.get(attName);
  14007. if (_bufferAttribute2 !== undefined && vbo !== undefined) {
  14008. var type = _this.glTypeMapping.get(_bufferAttribute2.array.constructor);
  14009. var normalized = _bufferAttribute2.normalized;
  14010. gl.bindBuffer(gl.ARRAY_BUFFER, vbo.handle);
  14011. gl.vertexAttribPointer(attributeLocation, _bufferAttribute2.itemSize, type, normalized, 0, 0);
  14012. gl.enableVertexAttribArray(attributeLocation);
  14013. }
  14014. {
  14015. var attExtra = octree.pcoGeometry.pointAttributes.attributes.find(a => a.name === attName);
  14016. var range = material.getRange(attName);
  14017. if (!range) {
  14018. range = attExtra.range;
  14019. }
  14020. if (!range) {
  14021. range = [0, 1];
  14022. }
  14023. var _initialRange = attExtra.initialRange;
  14024. var _initialRangeSize = _initialRange[1] - _initialRange[0];
  14025. var _globalRange = range;
  14026. var _globalRangeSize = _globalRange[1] - _globalRange[0];
  14027. var _scale = _initialRangeSize / _globalRangeSize;
  14028. var _offset = -(_globalRange[0] - _initialRange[0]) / _initialRangeSize;
  14029. _scale = Number.isNaN(_scale) ? 1 : _scale;
  14030. _offset = Number.isNaN(_offset) ? 0 : _offset;
  14031. shader.setUniform1f("uExtraScale", _scale);
  14032. shader.setUniform1f("uExtraOffset", _offset);
  14033. }
  14034. } else {
  14035. for (var _attributeName2 in geometry.attributes) {
  14036. var _bufferAttribute3 = geometry.attributes[_attributeName2];
  14037. var _vbo2 = webglBuffer.vbos.get(_attributeName2);
  14038. if (attributeLocations[_attributeName2] !== undefined) {
  14039. var _attributeLocation = attributeLocations[_attributeName2].location;
  14040. var _type = _this.glTypeMapping.get(_bufferAttribute3.array.constructor);
  14041. var _normalized = _bufferAttribute3.normalized;
  14042. gl.bindBuffer(gl.ARRAY_BUFFER, _vbo2.handle);
  14043. gl.vertexAttribPointer(_attributeLocation, _bufferAttribute3.itemSize, _type, _normalized, 0, 0);
  14044. gl.enableVertexAttribArray(_attributeLocation);
  14045. }
  14046. }
  14047. }
  14048. var numPoints = webglBuffer.numElements;
  14049. gl.drawArrays(gl.POINTS, 0, numPoints);
  14050. i++;
  14051. };
  14052. for (var node of nodes) {
  14053. if (_loop()) continue;
  14054. }
  14055. gl.bindVertexArray(null);
  14056. if (exports.measureTimings) {
  14057. performance.mark("renderNodes-end");
  14058. performance.measure("render.renderNodes", "renderNodes-start", "renderNodes-end");
  14059. }
  14060. }
  14061. renderOctree(octree, nodes, camera, target) {
  14062. var params = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
  14063. var gl = this.gl;
  14064. var material = params.material ? params.material : octree.material;
  14065. var shadowMaps = params.shadowMaps == null ? [] : params.shadowMaps;
  14066. var view = camera.matrixWorldInverse;
  14067. var viewInv = camera.matrixWorld;
  14068. if (params.viewOverride) {
  14069. view = params.viewOverride;
  14070. viewInv = view.clone().invert();
  14071. }
  14072. var proj = camera.projectionMatrix;
  14073. var projInv = proj.clone().invert();
  14074. //let worldView = new THREE.Matrix4();
  14075. var shader = null;
  14076. var visibilityTextureData = null;
  14077. var currentTextureBindingPoint = 0;
  14078. if (material.pointSizeType >= 0) {
  14079. if (material.pointSizeType === PointSizeType.ADAPTIVE || material.activeAttributeName === "level of detail") {
  14080. var vnNodes = params.vnTextureNodes != null ? params.vnTextureNodes : nodes;
  14081. visibilityTextureData = octree.computeVisibilityTextureData(vnNodes, camera);
  14082. var vnt = material.visibleNodesTexture;
  14083. var data = vnt.image.data;
  14084. data.set(visibilityTextureData.data);
  14085. vnt.needsUpdate = true;
  14086. }
  14087. }
  14088. {
  14089. // UPDATE SHADER AND TEXTURES
  14090. if (!this.shaders.has(material)) {
  14091. var [vs, fs] = [material.vertexShader, material.fragmentShader];
  14092. var _shader = new Shader(gl, "pointcloud", vs, fs);
  14093. this.shaders.set(material, _shader);
  14094. }
  14095. shader = this.shaders.get(material);
  14096. //if(material.needsUpdate){
  14097. {
  14098. var [_vs, _fs] = [material.vertexShader, material.fragmentShader];
  14099. var numSnapshots = material.snapEnabled ? material.numSnapshots : 0;
  14100. var numClipBoxes = material.clipBoxes && material.clipBoxes.length ? material.clipBoxes.length : 0;
  14101. var numClipSpheres = params.clipSpheres && params.clipSpheres.length ? params.clipSpheres.length : 0;
  14102. var numClipPolygons = material.clipPolygons && material.clipPolygons.length ? material.clipPolygons.length : 0;
  14103. var defines = ["#define num_shadowmaps ".concat(shadowMaps.length), "#define num_snapshots ".concat(numSnapshots), "#define num_clipboxes ".concat(numClipBoxes), "#define num_clipspheres ".concat(numClipSpheres), "#define num_clippolygons ".concat(numClipPolygons)];
  14104. if (octree.pcoGeometry.root.isLoaded()) {
  14105. var attributes = octree.pcoGeometry.root.geometry.attributes;
  14106. if (attributes["gps-time"]) {
  14107. defines.push("#define clip_gps_enabled");
  14108. }
  14109. if (attributes["return number"]) {
  14110. defines.push("#define clip_return_number_enabled");
  14111. }
  14112. if (attributes["number of returns"]) {
  14113. defines.push("#define clip_number_of_returns_enabled");
  14114. }
  14115. if (attributes["source id"] || attributes["point source id"]) {
  14116. defines.push("#define clip_point_source_id_enabled");
  14117. }
  14118. }
  14119. var definesString = defines.join("\n");
  14120. var vsVersionIndex = _vs.indexOf("#version ");
  14121. var fsVersionIndex = _fs.indexOf("#version ");
  14122. if (vsVersionIndex >= 0) {
  14123. _vs = _vs.replace(/(#version .*)/, "$1\n".concat(definesString));
  14124. } else {
  14125. _vs = "".concat(definesString, "\n").concat(_vs);
  14126. }
  14127. if (fsVersionIndex >= 0) {
  14128. _fs = _fs.replace(/(#version .*)/, "$1\n".concat(definesString));
  14129. } else {
  14130. _fs = "".concat(definesString, "\n").concat(_fs);
  14131. }
  14132. shader.update(_vs, _fs);
  14133. material.needsUpdate = false;
  14134. }
  14135. for (var uniformName of Object.keys(material.uniforms)) {
  14136. var uniform = material.uniforms[uniformName];
  14137. if (uniform.type == "t") {
  14138. var texture = uniform.value;
  14139. if (!texture) {
  14140. continue;
  14141. }
  14142. if (!this.textures.has(texture)) {
  14143. var webglTexture = new WebGLTexture(gl, texture);
  14144. this.textures.set(texture, webglTexture);
  14145. }
  14146. var webGLTexture = this.textures.get(texture);
  14147. webGLTexture.update();
  14148. }
  14149. }
  14150. }
  14151. gl.useProgram(shader.program);
  14152. var transparent = false;
  14153. if (params.transparent !== undefined) {
  14154. transparent = params.transparent && material.opacity < 1;
  14155. } else {
  14156. transparent = material.opacity < 1;
  14157. }
  14158. if (transparent) {
  14159. gl.enable(gl.BLEND);
  14160. gl.blendFunc(gl.SRC_ALPHA, gl.ONE);
  14161. gl.depthMask(false);
  14162. gl.disable(gl.DEPTH_TEST);
  14163. } else {
  14164. gl.disable(gl.BLEND);
  14165. gl.depthMask(true);
  14166. gl.enable(gl.DEPTH_TEST);
  14167. }
  14168. if (params.blendFunc !== undefined) {
  14169. gl.enable(gl.BLEND);
  14170. gl.blendFunc(...params.blendFunc);
  14171. }
  14172. if (params.depthTest !== undefined) {
  14173. if (params.depthTest === true) {
  14174. gl.enable(gl.DEPTH_TEST);
  14175. } else {
  14176. gl.disable(gl.DEPTH_TEST);
  14177. }
  14178. }
  14179. if (params.depthWrite !== undefined) {
  14180. if (params.depthWrite === true) {
  14181. gl.depthMask(true);
  14182. } else {
  14183. gl.depthMask(false);
  14184. }
  14185. }
  14186. {
  14187. // UPDATE UNIFORMS
  14188. shader.setUniformMatrix4("projectionMatrix", proj);
  14189. shader.setUniformMatrix4("viewMatrix", view);
  14190. shader.setUniformMatrix4("uViewInv", viewInv);
  14191. shader.setUniformMatrix4("uProjInv", projInv);
  14192. var screenWidth = target ? target.width : material.screenWidth;
  14193. var screenHeight = target ? target.height : material.screenHeight;
  14194. shader.setUniform1f("uScreenWidth", screenWidth);
  14195. shader.setUniform1f("uScreenHeight", screenHeight);
  14196. shader.setUniform1f("fov", Math.PI * camera.fov / 180);
  14197. shader.setUniform1f("near", camera.near);
  14198. shader.setUniform1f("far", camera.far);
  14199. if (camera instanceof OrthographicCamera) {
  14200. shader.setUniform("uUseOrthographicCamera", true);
  14201. shader.setUniform("uOrthoWidth", camera.right - camera.left);
  14202. shader.setUniform("uOrthoHeight", camera.top - camera.bottom);
  14203. } else {
  14204. shader.setUniform("uUseOrthographicCamera", false);
  14205. }
  14206. if (material.clipBoxes.length + material.clipPolygons.length === 0) {
  14207. shader.setUniform1i("clipTask", ClipTask.NONE);
  14208. } else {
  14209. shader.setUniform1i("clipTask", material.clipTask);
  14210. }
  14211. shader.setUniform1i("clipMethod", material.clipMethod);
  14212. if (material.clipBoxes && material.clipBoxes.length > 0) {
  14213. //let flattenedMatrices = [].concat(...material.clipBoxes.map(c => c.inverse.elements));
  14214. //const lClipBoxes = shader.uniformLocations["clipBoxes[0]"];
  14215. //gl.uniformMatrix4fv(lClipBoxes, false, flattenedMatrices);
  14216. var lClipBoxes = shader.uniformLocations["clipBoxes[0]"];
  14217. gl.uniformMatrix4fv(lClipBoxes, false, material.uniforms.clipBoxes.value);
  14218. }
  14219. // TODO CLIPSPHERES
  14220. if (params.clipSpheres && params.clipSpheres.length > 0) {
  14221. var clipSpheres = params.clipSpheres;
  14222. var matrices = [];
  14223. for (var clipSphere of clipSpheres) {
  14224. //let mScale = new THREE.Matrix4().makeScale(...clipSphere.scale.toArray());
  14225. //let mTranslate = new THREE.Matrix4().makeTranslation(...clipSphere.position.toArray());
  14226. //let clipToWorld = new THREE.Matrix4().multiplyMatrices(mTranslate, mScale);
  14227. var clipToWorld = clipSphere.matrixWorld;
  14228. var viewToWorld = camera.matrixWorld;
  14229. var worldToClip = clipToWorld.clone().invert();
  14230. var viewToClip = new Matrix4().multiplyMatrices(worldToClip, viewToWorld);
  14231. matrices.push(viewToClip);
  14232. }
  14233. var flattenedMatrices = [].concat(...matrices.map(matrix => matrix.elements));
  14234. var lClipSpheres = shader.uniformLocations["uClipSpheres[0]"];
  14235. gl.uniformMatrix4fv(lClipSpheres, false, flattenedMatrices);
  14236. //const lClipSpheres = shader.uniformLocations["uClipSpheres[0]"];
  14237. //gl.uniformMatrix4fv(lClipSpheres, false, material.uniforms.clipSpheres.value);
  14238. }
  14239. shader.setUniform1f("size", material.size);
  14240. shader.setUniform1f("maxSize", material.uniforms.maxSize.value);
  14241. shader.setUniform1f("minSize", material.uniforms.minSize.value);
  14242. // uniform float uPCIndex
  14243. shader.setUniform1f("uOctreeSpacing", material.spacing);
  14244. shader.setUniform("uOctreeSize", material.uniforms.octreeSize.value);
  14245. //uniform vec3 uColor;
  14246. shader.setUniform3f("uColor", material.color.toArray());
  14247. //uniform float opacity;
  14248. shader.setUniform1f("uOpacity", material.opacity);
  14249. shader.setUniform2f("elevationRange", material.elevationRange);
  14250. shader.setUniform2f("intensityRange", material.intensityRange);
  14251. shader.setUniform3f("uIntensity_gbc", [material.intensityGamma, material.intensityBrightness, material.intensityContrast]);
  14252. shader.setUniform3f("uRGB_gbc", [material.rgbGamma, material.rgbBrightness, material.rgbContrast]);
  14253. shader.setUniform1f("uTransition", material.transition);
  14254. shader.setUniform1f("wRGB", material.weightRGB);
  14255. shader.setUniform1f("wIntensity", material.weightIntensity);
  14256. shader.setUniform1f("wElevation", material.weightElevation);
  14257. shader.setUniform1f("wClassification", material.weightClassification);
  14258. shader.setUniform1f("wReturnNumber", material.weightReturnNumber);
  14259. shader.setUniform1f("wSourceID", material.weightSourceID);
  14260. shader.setUniform("backfaceCulling", material.uniforms.backfaceCulling.value);
  14261. var vnWebGLTexture = this.textures.get(material.visibleNodesTexture);
  14262. if (vnWebGLTexture) {
  14263. shader.setUniform1i("visibleNodesTexture", currentTextureBindingPoint);
  14264. gl.activeTexture(gl.TEXTURE0 + currentTextureBindingPoint);
  14265. gl.bindTexture(vnWebGLTexture.target, vnWebGLTexture.id);
  14266. currentTextureBindingPoint++;
  14267. }
  14268. var gradientTexture = this.textures.get(material.gradientTexture);
  14269. shader.setUniform1i("gradient", currentTextureBindingPoint);
  14270. gl.activeTexture(gl.TEXTURE0 + currentTextureBindingPoint);
  14271. gl.bindTexture(gradientTexture.target, gradientTexture.id);
  14272. var repeat = material.elevationGradientRepeat;
  14273. if (repeat === ElevationGradientRepeat.REPEAT) {
  14274. gl.texParameteri(gradientTexture.target, gl.TEXTURE_WRAP_S, gl.REPEAT);
  14275. gl.texParameteri(gradientTexture.target, gl.TEXTURE_WRAP_T, gl.REPEAT);
  14276. } else if (repeat === ElevationGradientRepeat.MIRRORED_REPEAT) {
  14277. gl.texParameteri(gradientTexture.target, gl.TEXTURE_WRAP_S, gl.MIRRORED_REPEAT);
  14278. gl.texParameteri(gradientTexture.target, gl.TEXTURE_WRAP_T, gl.MIRRORED_REPEAT);
  14279. } else {
  14280. gl.texParameteri(gradientTexture.target, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  14281. gl.texParameteri(gradientTexture.target, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  14282. }
  14283. currentTextureBindingPoint++;
  14284. var classificationTexture = this.textures.get(material.classificationTexture);
  14285. shader.setUniform1i("classificationLUT", currentTextureBindingPoint);
  14286. gl.activeTexture(gl.TEXTURE0 + currentTextureBindingPoint);
  14287. gl.bindTexture(classificationTexture.target, classificationTexture.id);
  14288. currentTextureBindingPoint++;
  14289. var matcapTexture = this.textures.get(material.matcapTexture);
  14290. shader.setUniform1i("matcapTextureUniform", currentTextureBindingPoint);
  14291. gl.activeTexture(gl.TEXTURE0 + currentTextureBindingPoint);
  14292. gl.bindTexture(matcapTexture.target, matcapTexture.id);
  14293. currentTextureBindingPoint++;
  14294. if (material.snapEnabled === true) {
  14295. {
  14296. var lSnapshot = shader.uniformLocations["uSnapshot[0]"];
  14297. var lSnapshotDepth = shader.uniformLocations["uSnapshotDepth[0]"];
  14298. var bindingStart = currentTextureBindingPoint;
  14299. var lSnapshotBindingPoints = new Array(5).fill(bindingStart).map((a, i) => a + i);
  14300. var lSnapshotDepthBindingPoints = new Array(5).fill(1 + Math.max(...lSnapshotBindingPoints)).map((a, i) => a + i);
  14301. currentTextureBindingPoint = 1 + Math.max(...lSnapshotDepthBindingPoints);
  14302. gl.uniform1iv(lSnapshot, lSnapshotBindingPoints);
  14303. gl.uniform1iv(lSnapshotDepth, lSnapshotDepthBindingPoints);
  14304. for (var i = 0; i < 5; i++) {
  14305. var _texture = material.uniforms["uSnapshot"].value[i];
  14306. var textureDepth = material.uniforms["uSnapshotDepth"].value[i];
  14307. if (!_texture) {
  14308. break;
  14309. }
  14310. var snapTexture = this.threeRenderer.properties.get(_texture).__webglTexture;
  14311. var snapTextureDepth = this.threeRenderer.properties.get(textureDepth).__webglTexture;
  14312. var bindingPoint = lSnapshotBindingPoints[i];
  14313. var depthBindingPoint = lSnapshotDepthBindingPoints[i];
  14314. gl.activeTexture(gl["TEXTURE".concat(bindingPoint)]);
  14315. gl.bindTexture(gl.TEXTURE_2D, snapTexture);
  14316. gl.activeTexture(gl["TEXTURE".concat(depthBindingPoint)]);
  14317. gl.bindTexture(gl.TEXTURE_2D, snapTextureDepth);
  14318. }
  14319. }
  14320. {
  14321. var _flattenedMatrices3 = [].concat(...material.uniforms.uSnapView.value.map(c => c.elements));
  14322. var lSnapView = shader.uniformLocations["uSnapView[0]"];
  14323. gl.uniformMatrix4fv(lSnapView, false, _flattenedMatrices3);
  14324. }
  14325. {
  14326. var _flattenedMatrices4 = [].concat(...material.uniforms.uSnapProj.value.map(c => c.elements));
  14327. var lSnapProj = shader.uniformLocations["uSnapProj[0]"];
  14328. gl.uniformMatrix4fv(lSnapProj, false, _flattenedMatrices4);
  14329. }
  14330. {
  14331. var _flattenedMatrices5 = [].concat(...material.uniforms.uSnapProjInv.value.map(c => c.elements));
  14332. var lSnapProjInv = shader.uniformLocations["uSnapProjInv[0]"];
  14333. gl.uniformMatrix4fv(lSnapProjInv, false, _flattenedMatrices5);
  14334. }
  14335. {
  14336. var _flattenedMatrices6 = [].concat(...material.uniforms.uSnapViewInv.value.map(c => c.elements));
  14337. var lSnapViewInv = shader.uniformLocations["uSnapViewInv[0]"];
  14338. gl.uniformMatrix4fv(lSnapViewInv, false, _flattenedMatrices6);
  14339. }
  14340. }
  14341. }
  14342. this.renderNodes(octree, nodes, visibilityTextureData, camera, target, shader, params);
  14343. gl.activeTexture(gl.TEXTURE2);
  14344. gl.bindTexture(gl.TEXTURE_2D, null);
  14345. gl.activeTexture(gl.TEXTURE0);
  14346. }
  14347. render(scene, camera) {
  14348. var target = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  14349. var params = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  14350. var gl = this.gl;
  14351. // PREPARE
  14352. if (target != null) {
  14353. this.threeRenderer.setRenderTarget(target);
  14354. }
  14355. //camera.updateProjectionMatrix();
  14356. // camera.matrixWorldInverse.invert(camera.matrixWorld);
  14357. var traversalResult = this.traverse(scene);
  14358. // RENDER
  14359. for (var octree of traversalResult.octrees) {
  14360. var nodes = octree.visibleNodes;
  14361. this.renderOctree(octree, nodes, camera, target, params);
  14362. }
  14363. // CLEANUP
  14364. gl.activeTexture(gl.TEXTURE1);
  14365. gl.bindTexture(gl.TEXTURE_2D, null);
  14366. gl.bindBuffer(gl.ARRAY_BUFFER, null);
  14367. gl.bindVertexArray(null);
  14368. this.threeRenderer.resetState();
  14369. }
  14370. }
  14371. ;
  14372. function copyMaterial(source, target) {
  14373. for (var name of Object.keys(target.uniforms)) {
  14374. target.uniforms[name].value = source.uniforms[name].value;
  14375. }
  14376. target.gradientTexture = source.gradientTexture;
  14377. target.visibleNodesTexture = source.visibleNodesTexture;
  14378. target.classificationTexture = source.classificationTexture;
  14379. target.matcapTexture = source.matcapTexture;
  14380. target.activeAttributeName = source.activeAttributeName;
  14381. target.ranges = source.ranges;
  14382. //target.updateShaderSource();
  14383. }
  14384. class Batch {
  14385. constructor(geometry, material) {
  14386. this.geometry = geometry;
  14387. this.material = material;
  14388. this.sceneNode = new Points(geometry, material);
  14389. this.geometryNode = {
  14390. estimatedSpacing: 1.0,
  14391. geometry: geometry
  14392. };
  14393. }
  14394. getLevel() {
  14395. return 0;
  14396. }
  14397. }
  14398. class ProfileFakeOctree extends PointCloudTree {
  14399. constructor(octree) {
  14400. super();
  14401. this.trueOctree = octree;
  14402. this.pcoGeometry = octree.pcoGeometry;
  14403. this.points = [];
  14404. this.visibleNodes = [];
  14405. //this.material = this.trueOctree.material;
  14406. this.material = new PointCloudMaterial$1();
  14407. //this.material.copy(this.trueOctree.material);
  14408. copyMaterial(this.trueOctree.material, this.material);
  14409. this.material.pointSizeType = PointSizeType.FIXED;
  14410. this.batchSize = 100 * 1000;
  14411. this.currentBatch = null;
  14412. }
  14413. getAttribute(name) {
  14414. return this.trueOctree.getAttribute(name);
  14415. }
  14416. dispose() {
  14417. for (var node of this.visibleNodes) {
  14418. node.geometry.dispose();
  14419. }
  14420. this.visibleNodes = [];
  14421. this.currentBatch = null;
  14422. this.points = [];
  14423. }
  14424. addPoints(data) {
  14425. // since each call to addPoints can deliver very very few points,
  14426. // we're going to batch them into larger buffers for efficiency.
  14427. if (this.currentBatch === null) {
  14428. this.currentBatch = this.createNewBatch(data);
  14429. }
  14430. this.points.push(data);
  14431. var updateRange = {
  14432. start: this.currentBatch.geometry.drawRange.count,
  14433. count: 0
  14434. };
  14435. var projectedBox = new Box3();
  14436. var truePos = new Vector3();
  14437. for (var i = 0; i < data.numPoints; i++) {
  14438. if (updateRange.start + updateRange.count >= this.batchSize) {
  14439. // current batch full, start new batch
  14440. for (var key of Object.keys(this.currentBatch.geometry.attributes)) {
  14441. var attribute = this.currentBatch.geometry.attributes[key];
  14442. attribute.updateRange.offset = updateRange.start;
  14443. attribute.updateRange.count = updateRange.count;
  14444. attribute.needsUpdate = true;
  14445. }
  14446. this.currentBatch.geometry.computeBoundingBox();
  14447. this.currentBatch.geometry.computeBoundingSphere();
  14448. this.currentBatch = this.createNewBatch(data);
  14449. updateRange = {
  14450. start: 0,
  14451. count: 0
  14452. };
  14453. }
  14454. truePos.set(data.data.position[3 * i + 0] + this.trueOctree.position.x, data.data.position[3 * i + 1] + this.trueOctree.position.y, data.data.position[3 * i + 2] + this.trueOctree.position.z);
  14455. var x = data.data.mileage[i];
  14456. var y = 0;
  14457. var z = truePos.z;
  14458. projectedBox.expandByPoint(new Vector3(x, y, z));
  14459. var index = updateRange.start + updateRange.count;
  14460. var geometry = this.currentBatch.geometry;
  14461. for (var attributeName of Object.keys(data.data)) {
  14462. var source = data.data[attributeName];
  14463. var target = geometry.attributes[attributeName];
  14464. var numElements = target.itemSize;
  14465. for (var item = 0; item < numElements; item++) {
  14466. target.array[numElements * index + item] = source[numElements * i + item];
  14467. }
  14468. }
  14469. {
  14470. var position = geometry.attributes.position;
  14471. position.array[3 * index + 0] = x;
  14472. position.array[3 * index + 1] = y;
  14473. position.array[3 * index + 2] = z;
  14474. }
  14475. updateRange.count++;
  14476. this.currentBatch.geometry.drawRange.count++;
  14477. }
  14478. for (var _key of Object.keys(this.currentBatch.geometry.attributes)) {
  14479. var _attribute = this.currentBatch.geometry.attributes[_key];
  14480. _attribute.updateRange.offset = updateRange.start;
  14481. _attribute.updateRange.count = updateRange.count;
  14482. _attribute.needsUpdate = true;
  14483. }
  14484. data.projectedBox = projectedBox;
  14485. this.projectedBox = this.points.reduce((a, i) => a.union(i.projectedBox), new Box3());
  14486. }
  14487. createNewBatch(data) {
  14488. var geometry = new BufferGeometry();
  14489. // create new batches with batch_size elements of the same type as the attribute
  14490. for (var attributeName of Object.keys(data.data)) {
  14491. var buffer = data.data[attributeName];
  14492. var numElements = buffer.length / data.numPoints; // 3 for pos, 4 for col, 1 for scalars
  14493. var _constructor = buffer.constructor;
  14494. var normalized = false;
  14495. if (this.trueOctree.root.sceneNode) {
  14496. if (this.trueOctree.root.sceneNode.geometry.attributes[attributeName]) {
  14497. normalized = this.trueOctree.root.sceneNode.geometry.attributes[attributeName].normalized;
  14498. }
  14499. }
  14500. var batchBuffer = new _constructor(numElements * this.batchSize);
  14501. var bufferAttribute = new BufferAttribute(batchBuffer, numElements, normalized);
  14502. bufferAttribute.potree = {
  14503. range: [0, 1]
  14504. };
  14505. geometry.setAttribute(attributeName, bufferAttribute);
  14506. }
  14507. geometry.drawRange.start = 0;
  14508. geometry.drawRange.count = 0;
  14509. var batch = new Batch(geometry, this.material);
  14510. this.visibleNodes.push(batch);
  14511. return batch;
  14512. }
  14513. computeVisibilityTextureData() {
  14514. var data = new Uint8Array(this.visibleNodes.length * 4);
  14515. var offsets = new Map();
  14516. for (var i = 0; i < this.visibleNodes.length; i++) {
  14517. var node = this.visibleNodes[i];
  14518. offsets[node] = i;
  14519. }
  14520. return {
  14521. data: data,
  14522. offsets: offsets
  14523. };
  14524. }
  14525. }
  14526. class ProfileWindow extends EventDispatcher$1 {
  14527. constructor(viewer) {
  14528. super();
  14529. this.viewer = viewer;
  14530. this.elRoot = $('#profile_window');
  14531. this.renderArea = this.elRoot.find('#profileCanvasContainer');
  14532. this.svg = d3.select('svg#profileSVG');
  14533. this.mouseIsDown = false;
  14534. this.projectedBox = new Box3();
  14535. this.pointclouds = new Map();
  14536. this.numPoints = 0;
  14537. this.lastAddPointsTimestamp = undefined;
  14538. this.mouse = new Vector2(0, 0);
  14539. this.scale = new Vector3(1, 1, 1);
  14540. this.autoFitEnabled = true; // completely disable/enable
  14541. this.autoFit = false; // internal
  14542. var cwIcon = "".concat(exports.resourcePath, "/icons/arrow_cw.svg");
  14543. $('#potree_profile_rotate_cw').attr('src', cwIcon);
  14544. var ccwIcon = "".concat(exports.resourcePath, "/icons/arrow_ccw.svg");
  14545. $('#potree_profile_rotate_ccw').attr('src', ccwIcon);
  14546. var forwardIcon = "".concat(exports.resourcePath, "/icons/arrow_up.svg");
  14547. $('#potree_profile_move_forward').attr('src', forwardIcon);
  14548. var backwardIcon = "".concat(exports.resourcePath, "/icons/arrow_down.svg");
  14549. $('#potree_profile_move_backward').attr('src', backwardIcon);
  14550. var csvIcon = "".concat(exports.resourcePath, "/icons/file_csv_2d.svg");
  14551. $('#potree_download_csv_icon').attr('src', csvIcon);
  14552. var lasIcon = "".concat(exports.resourcePath, "/icons/file_las_3d.svg");
  14553. $('#potree_download_las_icon').attr('src', lasIcon);
  14554. var closeIcon = "".concat(exports.resourcePath, "/icons/close.svg");
  14555. $('#closeProfileContainer').attr("src", closeIcon);
  14556. this.initTHREE();
  14557. this.initSVG();
  14558. this.initListeners();
  14559. this.pRenderer = new Renderer(this.renderer);
  14560. this.elRoot.i18n();
  14561. }
  14562. initListeners() {
  14563. $(window).resize(() => {
  14564. if (this.enabled) {
  14565. this.render();
  14566. }
  14567. });
  14568. this.renderArea.mousedown(e => {
  14569. this.mouseIsDown = true;
  14570. });
  14571. this.renderArea.mouseup(e => {
  14572. this.mouseIsDown = false;
  14573. });
  14574. var viewerPickSphereSizeHandler = () => {
  14575. var camera = this.viewer.scene.getActiveCamera();
  14576. var domElement = this.viewer.renderer.domElement;
  14577. var distance = this.viewerPickSphere.position.distanceTo(camera.position);
  14578. var pr = Utils.projectedRadius(1, camera, distance, domElement.clientWidth, domElement.clientHeight);
  14579. var scale = 10 / pr;
  14580. this.viewerPickSphere.scale.set(scale, scale, scale);
  14581. };
  14582. this.renderArea.mousemove(e => {
  14583. if (this.pointclouds.size === 0) {
  14584. return;
  14585. }
  14586. var rect = this.renderArea[0].getBoundingClientRect();
  14587. var x = e.clientX - rect.left;
  14588. var y = e.clientY - rect.top;
  14589. var newMouse = new Vector2(x, y);
  14590. if (this.mouseIsDown) {
  14591. // DRAG
  14592. this.autoFit = false;
  14593. this.lastDrag = new Date().getTime();
  14594. var cPos = [this.scaleX.invert(this.mouse.x), this.scaleY.invert(this.mouse.y)];
  14595. var ncPos = [this.scaleX.invert(newMouse.x), this.scaleY.invert(newMouse.y)];
  14596. this.camera.position.x -= ncPos[0] - cPos[0];
  14597. this.camera.position.z -= ncPos[1] - cPos[1];
  14598. this.render();
  14599. } else if (this.pointclouds.size > 0) {
  14600. // FIND HOVERED POINT
  14601. var radius = Math.abs(this.scaleX.invert(0) - this.scaleX.invert(40));
  14602. var mileage = this.scaleX.invert(newMouse.x);
  14603. var elevation = this.scaleY.invert(newMouse.y);
  14604. var closest = this.selectPoint(mileage, elevation, radius);
  14605. if (closest) {
  14606. var point = closest.point;
  14607. var position = new Float64Array([point.position[0] + closest.pointcloud.position.x, point.position[1] + closest.pointcloud.position.y, point.position[2] + closest.pointcloud.position.z]);
  14608. this.elRoot.find('#profileSelectionProperties').fadeIn(200);
  14609. this.pickSphere.visible = true;
  14610. this.pickSphere.scale.set(0.5 * radius, 0.5 * radius, 0.5 * radius);
  14611. this.pickSphere.position.set(point.mileage, 0, position[2]);
  14612. this.viewerPickSphere.position.set(...position);
  14613. if (!this.viewer.scene.scene.children.includes(this.viewerPickSphere)) {
  14614. this.viewer.scene.scene.add(this.viewerPickSphere);
  14615. if (!this.viewer.hasEventListener("update", viewerPickSphereSizeHandler)) {
  14616. this.viewer.addEventListener("update", viewerPickSphereSizeHandler);
  14617. }
  14618. }
  14619. var info = this.elRoot.find('#profileSelectionProperties');
  14620. var html = '<table>';
  14621. var _loop = function _loop() {
  14622. var value = point[attributeName];
  14623. var attribute = closest.pointcloud.getAttribute(attributeName);
  14624. var transform = value => value;
  14625. if (attribute && attribute.type.size > 4) {
  14626. var range = attribute.initialRange;
  14627. var scale = 1 / (range[1] - range[0]);
  14628. var offset = range[0];
  14629. transform = value => value / scale + offset;
  14630. }
  14631. if (attributeName === 'position') {
  14632. var values = [...position].map(v => Utils.addCommas(v.toFixed(3)));
  14633. html += "\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<td>x</td>\n\t\t\t\t\t\t\t\t\t<td>".concat(values[0], "</td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<td>y</td>\n\t\t\t\t\t\t\t\t\t<td>").concat(values[1], "</td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<td>z</td>\n\t\t\t\t\t\t\t\t\t<td>").concat(values[2], "</td>\n\t\t\t\t\t\t\t\t</tr>");
  14634. } else if (attributeName === 'rgba') {
  14635. html += "\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<td>".concat(attributeName, "</td>\n\t\t\t\t\t\t\t\t\t<td>").concat(value.join(', '), "</td>\n\t\t\t\t\t\t\t\t</tr>");
  14636. } else if (attributeName === 'normal') {
  14637. return 1; // continue
  14638. } else if (attributeName === 'mileage') {
  14639. html += "\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<td>".concat(attributeName, "</td>\n\t\t\t\t\t\t\t\t\t<td>").concat(value.toFixed(3), "</td>\n\t\t\t\t\t\t\t\t</tr>");
  14640. } else {
  14641. html += "\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<td>".concat(attributeName, "</td>\n\t\t\t\t\t\t\t\t\t<td>").concat(transform(value), "</td>\n\t\t\t\t\t\t\t\t</tr>");
  14642. }
  14643. };
  14644. for (var attributeName of Object.keys(point)) {
  14645. if (_loop()) continue;
  14646. }
  14647. html += '</table>';
  14648. info.html(html);
  14649. this.selectedPoint = point;
  14650. } else {
  14651. // this.pickSphere.visible = false;
  14652. // this.selectedPoint = null;
  14653. this.viewer.scene.scene.add(this.viewerPickSphere);
  14654. var index = this.viewer.scene.scene.children.indexOf(this.viewerPickSphere);
  14655. if (index >= 0) {
  14656. this.viewer.scene.scene.children.splice(index, 1);
  14657. }
  14658. this.viewer.removeEventListener("update", viewerPickSphereSizeHandler);
  14659. }
  14660. this.render();
  14661. }
  14662. this.mouse.copy(newMouse);
  14663. });
  14664. var onWheel = e => {
  14665. this.autoFit = false;
  14666. var delta = 0;
  14667. if (e.wheelDelta !== undefined) {
  14668. // WebKit / Opera / Explorer 9
  14669. delta = e.wheelDelta;
  14670. } else if (e.detail !== undefined) {
  14671. // Firefox
  14672. delta = -e.detail;
  14673. }
  14674. var ndelta = Math.sign(delta);
  14675. var cPos = [this.scaleX.invert(this.mouse.x), this.scaleY.invert(this.mouse.y)];
  14676. if (ndelta > 0) {
  14677. // + 10%
  14678. this.scale.multiplyScalar(1.1);
  14679. } else {
  14680. // - 10%
  14681. this.scale.multiplyScalar(100 / 110);
  14682. }
  14683. this.updateScales();
  14684. var ncPos = [this.scaleX.invert(this.mouse.x), this.scaleY.invert(this.mouse.y)];
  14685. this.camera.position.x -= ncPos[0] - cPos[0];
  14686. this.camera.position.z -= ncPos[1] - cPos[1];
  14687. this.render();
  14688. this.updateScales();
  14689. };
  14690. $(this.renderArea)[0].addEventListener('mousewheel', onWheel, false);
  14691. $(this.renderArea)[0].addEventListener('DOMMouseScroll', onWheel, false); // Firefox
  14692. $('#closeProfileContainer').click(() => {
  14693. this.hide();
  14694. });
  14695. var getProfilePoints = () => {
  14696. var points = new Points$1();
  14697. for (var [pointcloud, entry] of this.pointclouds) {
  14698. for (var pointSet of entry.points) {
  14699. var originPos = pointSet.data.position;
  14700. var trueElevationPosition = new Float32Array(originPos);
  14701. for (var i = 0; i < pointSet.numPoints; i++) {
  14702. trueElevationPosition[3 * i + 2] += pointcloud.position.z;
  14703. }
  14704. pointSet.data.position = trueElevationPosition;
  14705. points.add(pointSet);
  14706. pointSet.data.position = originPos;
  14707. }
  14708. }
  14709. return points;
  14710. };
  14711. $('#potree_download_csv_icon').click(() => {
  14712. var points = getProfilePoints();
  14713. var string = CSVExporter.toString(points);
  14714. var blob = new Blob([string], {
  14715. type: "text/string"
  14716. });
  14717. $('#potree_download_profile_ortho_link').attr('href', URL.createObjectURL(blob));
  14718. });
  14719. $('#potree_download_las_icon').click(() => {
  14720. var points = getProfilePoints();
  14721. var buffer = LASExporter.toLAS(points);
  14722. var blob = new Blob([buffer], {
  14723. type: "application/octet-binary"
  14724. });
  14725. $('#potree_download_profile_link').attr('href', URL.createObjectURL(blob));
  14726. });
  14727. }
  14728. selectPoint(mileage, elevation, radius) {
  14729. var closest = {
  14730. distance: Infinity,
  14731. pointcloud: null,
  14732. points: null,
  14733. index: null
  14734. };
  14735. var pointBox = new Box2(new Vector2(mileage - radius, elevation - radius), new Vector2(mileage + radius, elevation + radius));
  14736. var numTested = 0;
  14737. var numSkipped = 0;
  14738. var numTestedPoints = 0;
  14739. var numSkippedPoints = 0;
  14740. for (var [pointcloud, entry] of this.pointclouds) {
  14741. for (var points of entry.points) {
  14742. var collisionBox = new Box2(new Vector2(points.projectedBox.min.x, points.projectedBox.min.z), new Vector2(points.projectedBox.max.x, points.projectedBox.max.z));
  14743. var intersects = collisionBox.intersectsBox(pointBox);
  14744. if (!intersects) {
  14745. numSkipped++;
  14746. numSkippedPoints += points.numPoints;
  14747. continue;
  14748. }
  14749. numTested++;
  14750. numTestedPoints += points.numPoints;
  14751. for (var i = 0; i < points.numPoints; i++) {
  14752. var m = points.data.mileage[i] - mileage;
  14753. var e = points.data.position[3 * i + 2] - elevation + pointcloud.position.z;
  14754. var r = Math.sqrt(m * m + e * e);
  14755. var withinDistance = r < radius && r < closest.distance;
  14756. var unfilteredClass = true;
  14757. if (points.data.classification) {
  14758. var classification = pointcloud.material.classification;
  14759. var pointClassID = points.data.classification[i];
  14760. var pointClassValue = classification[pointClassID];
  14761. if (pointClassValue && (!pointClassValue.visible || pointClassValue.color.w === 0)) {
  14762. unfilteredClass = false;
  14763. }
  14764. }
  14765. if (withinDistance && unfilteredClass) {
  14766. closest = {
  14767. distance: r,
  14768. pointcloud: pointcloud,
  14769. points: points,
  14770. index: i
  14771. };
  14772. }
  14773. }
  14774. }
  14775. }
  14776. //console.log(`nodes: ${numTested}, ${numSkipped} || points: ${numTestedPoints}, ${numSkippedPoints}`);
  14777. if (closest.distance < Infinity) {
  14778. var _points = closest.points;
  14779. var point = {};
  14780. var attributes = Object.keys(_points.data);
  14781. for (var attribute of attributes) {
  14782. var attributeData = _points.data[attribute];
  14783. var itemSize = attributeData.length / _points.numPoints;
  14784. var value = attributeData.subarray(itemSize * closest.index, itemSize * closest.index + itemSize);
  14785. if (value.length === 1) {
  14786. point[attribute] = value[0];
  14787. } else {
  14788. point[attribute] = value;
  14789. }
  14790. }
  14791. closest.point = point;
  14792. return closest;
  14793. } else {
  14794. return null;
  14795. }
  14796. }
  14797. initTHREE() {
  14798. this.renderer = new WebGLRenderer({
  14799. alpha: true,
  14800. premultipliedAlpha: false
  14801. });
  14802. this.renderer.setClearColor(0x000000, 0);
  14803. this.renderer.setSize(10, 10);
  14804. this.renderer.autoClear = false;
  14805. this.renderArea.append($(this.renderer.domElement));
  14806. this.renderer.domElement.tabIndex = '2222';
  14807. $(this.renderer.domElement).css('width', '100%');
  14808. $(this.renderer.domElement).css('height', '100%');
  14809. {
  14810. var gl = this.renderer.getContext();
  14811. if (gl.createVertexArray == null) {
  14812. var extVAO = gl.getExtension('OES_vertex_array_object');
  14813. if (!extVAO) {
  14814. throw new Error("OES_vertex_array_object extension not supported");
  14815. }
  14816. gl.createVertexArray = extVAO.createVertexArrayOES.bind(extVAO);
  14817. gl.bindVertexArray = extVAO.bindVertexArrayOES.bind(extVAO);
  14818. }
  14819. }
  14820. this.camera = new OrthographicCamera(-1000, 1000, 1000, -1000, -1000, 1000);
  14821. this.camera.up.set(0, 0, 1);
  14822. this.camera.rotation.order = "ZXY";
  14823. this.camera.rotation.x = Math.PI / 2.0;
  14824. this.scene = new Scene();
  14825. this.profileScene = new Scene();
  14826. var sg = new SphereGeometry(1, 16, 16);
  14827. var sm = new MeshNormalMaterial();
  14828. this.pickSphere = new Mesh(sg, sm);
  14829. this.scene.add(this.pickSphere);
  14830. this.viewerPickSphere = new Mesh(sg, sm);
  14831. }
  14832. initSVG() {
  14833. var width = this.renderArea[0].clientWidth;
  14834. var height = this.renderArea[0].clientHeight;
  14835. var marginLeft = this.renderArea[0].offsetLeft;
  14836. this.svg.selectAll('*').remove();
  14837. this.scaleX = d3.scale.linear().domain([this.camera.left + this.camera.position.x, this.camera.right + this.camera.position.x]).range([0, width]);
  14838. this.scaleY = d3.scale.linear().domain([this.camera.bottom + this.camera.position.z, this.camera.top + this.camera.position.z]).range([height, 0]);
  14839. this.xAxis = d3.svg.axis().scale(this.scaleX).orient('bottom').innerTickSize(-height).outerTickSize(1).tickPadding(10).ticks(width / 50);
  14840. this.yAxis = d3.svg.axis().scale(this.scaleY).orient('left').innerTickSize(-width).outerTickSize(1).tickPadding(10).ticks(height / 20);
  14841. this.elXAxis = this.svg.append('g').attr('class', 'x axis').attr('transform', "translate(".concat(marginLeft, ", ").concat(height, ")")).call(this.xAxis);
  14842. this.elYAxis = this.svg.append('g').attr('class', 'y axis').attr('transform', "translate(".concat(marginLeft, ", 0)")).call(this.yAxis);
  14843. }
  14844. addPoints(pointcloud, points) {
  14845. if (points.numPoints === 0) {
  14846. return;
  14847. }
  14848. var entry = this.pointclouds.get(pointcloud);
  14849. if (!entry) {
  14850. entry = new ProfileFakeOctree(pointcloud);
  14851. this.pointclouds.set(pointcloud, entry);
  14852. this.profileScene.add(entry);
  14853. var materialChanged = () => {
  14854. this.render();
  14855. };
  14856. materialChanged();
  14857. pointcloud.material.addEventListener('material_property_changed', materialChanged);
  14858. this.addEventListener("on_reset_once", () => {
  14859. pointcloud.material.removeEventListener('material_property_changed', materialChanged);
  14860. });
  14861. }
  14862. entry.addPoints(points);
  14863. this.projectedBox.union(entry.projectedBox);
  14864. if (this.autoFit && this.autoFitEnabled) {
  14865. var width = this.renderArea[0].clientWidth;
  14866. var height = this.renderArea[0].clientHeight;
  14867. var size = this.projectedBox.getSize(new Vector3());
  14868. var sx = width / size.x;
  14869. var sy = height / size.z;
  14870. var scale = Math.min(sx, sy);
  14871. var center = this.projectedBox.getCenter(new Vector3());
  14872. this.scale.set(scale, scale, 1);
  14873. this.camera.position.copy(center);
  14874. //console.log("camera: ", this.camera.position.toArray().join(", "));
  14875. }
  14876. //console.log(entry);
  14877. this.render();
  14878. var numPoints = 0;
  14879. for (var [key, value] of this.pointclouds.entries()) {
  14880. numPoints += value.points.reduce((a, i) => a + i.numPoints, 0);
  14881. }
  14882. $("#profile_num_points").html(Utils.addCommas(numPoints));
  14883. }
  14884. reset() {
  14885. this.lastReset = new Date().getTime();
  14886. this.dispatchEvent({
  14887. type: "on_reset_once"
  14888. });
  14889. this.removeEventListeners("on_reset_once");
  14890. this.autoFit = true;
  14891. this.projectedBox = new Box3();
  14892. for (var [key, entry] of this.pointclouds) {
  14893. entry.dispose();
  14894. }
  14895. this.pointclouds.clear();
  14896. this.mouseIsDown = false;
  14897. this.mouse.set(0, 0);
  14898. if (this.autoFitEnabled) {
  14899. this.scale.set(1, 1, 1);
  14900. }
  14901. this.pickSphere.visible = false;
  14902. this.elRoot.find('#profileSelectionProperties').hide();
  14903. this.render();
  14904. }
  14905. show() {
  14906. this.elRoot.fadeIn();
  14907. this.enabled = true;
  14908. }
  14909. hide() {
  14910. this.elRoot.fadeOut();
  14911. this.enabled = false;
  14912. }
  14913. updateScales() {
  14914. var width = this.renderArea[0].clientWidth;
  14915. var height = this.renderArea[0].clientHeight;
  14916. var left = -width / 2 / this.scale.x;
  14917. var right = +width / 2 / this.scale.x;
  14918. var top = +height / 2 / this.scale.y;
  14919. var bottom = -height / 2 / this.scale.y;
  14920. this.camera.left = left;
  14921. this.camera.right = right;
  14922. this.camera.top = top;
  14923. this.camera.bottom = bottom;
  14924. this.camera.updateProjectionMatrix();
  14925. this.scaleX.domain([this.camera.left + this.camera.position.x, this.camera.right + this.camera.position.x]).range([0, width]);
  14926. this.scaleY.domain([this.camera.bottom + this.camera.position.z, this.camera.top + this.camera.position.z]).range([height, 0]);
  14927. var marginLeft = this.renderArea[0].offsetLeft;
  14928. this.xAxis.scale(this.scaleX).orient('bottom').innerTickSize(-height).outerTickSize(1).tickPadding(10).ticks(width / 50);
  14929. this.yAxis.scale(this.scaleY).orient('left').innerTickSize(-width).outerTickSize(1).tickPadding(10).ticks(height / 20);
  14930. this.elXAxis.attr('transform', "translate(".concat(marginLeft, ", ").concat(height, ")")).call(this.xAxis);
  14931. this.elYAxis.attr('transform', "translate(".concat(marginLeft, ", 0)")).call(this.yAxis);
  14932. }
  14933. requestScaleUpdate() {
  14934. var threshold = 100;
  14935. var allowUpdate = this.lastReset === undefined || this.lastScaleUpdate === undefined || new Date().getTime() - this.lastReset > threshold && new Date().getTime() - this.lastScaleUpdate > threshold;
  14936. if (allowUpdate) {
  14937. this.updateScales();
  14938. this.lastScaleUpdate = new Date().getTime();
  14939. this.scaleUpdatePending = false;
  14940. } else if (!this.scaleUpdatePending) {
  14941. setTimeout(this.requestScaleUpdate.bind(this), 100);
  14942. this.scaleUpdatePending = true;
  14943. }
  14944. }
  14945. render() {
  14946. var width = this.renderArea[0].clientWidth;
  14947. var height = this.renderArea[0].clientHeight;
  14948. var {
  14949. renderer,
  14950. pRenderer,
  14951. camera,
  14952. profileScene,
  14953. scene
  14954. } = this;
  14955. var {
  14956. scaleX,
  14957. pickSphere
  14958. } = this;
  14959. renderer.setSize(width, height);
  14960. renderer.setClearColor(0x000000, 0);
  14961. renderer.clear(true, true, false);
  14962. for (var pointcloud of this.pointclouds.keys()) {
  14963. var source = pointcloud.material;
  14964. var target = this.pointclouds.get(pointcloud).material;
  14965. copyMaterial(source, target);
  14966. target.size = 2;
  14967. }
  14968. pRenderer.render(profileScene, camera, null);
  14969. var radius = Math.abs(scaleX.invert(0) - scaleX.invert(5));
  14970. if (radius === 0) {
  14971. pickSphere.visible = false;
  14972. } else {
  14973. pickSphere.scale.set(radius, radius, radius);
  14974. pickSphere.visible = true;
  14975. }
  14976. renderer.render(scene, camera);
  14977. this.requestScaleUpdate();
  14978. }
  14979. }
  14980. ;
  14981. class ProfileWindowController {
  14982. constructor(viewer) {
  14983. this.viewer = viewer;
  14984. this.profileWindow = viewer.profileWindow;
  14985. this.profile = null;
  14986. this.numPoints = 0;
  14987. this.threshold = 60 * 1000;
  14988. this.rotateAmount = 10;
  14989. this.scheduledRecomputeTime = null;
  14990. this.enabled = true;
  14991. this.requests = [];
  14992. this._recompute = () => {
  14993. this.recompute();
  14994. };
  14995. this.viewer.addEventListener("scene_changed", e => {
  14996. e.oldScene.removeEventListener("pointcloud_added", this._recompute);
  14997. e.scene.addEventListener("pointcloud_added", this._recompute);
  14998. });
  14999. this.viewer.scene.addEventListener("pointcloud_added", this._recompute);
  15000. $("#potree_profile_rotate_amount").val(parseInt(this.rotateAmount));
  15001. $("#potree_profile_rotate_amount").on("input", e => {
  15002. var str = $("#potree_profile_rotate_amount").val();
  15003. if (!isNaN(str)) {
  15004. var value = parseFloat(str);
  15005. this.rotateAmount = value;
  15006. $("#potree_profile_rotate_amount").css("background-color", "");
  15007. } else {
  15008. $("#potree_profile_rotate_amount").css("background-color", "#ff9999");
  15009. }
  15010. });
  15011. var rotate = radians => {
  15012. var profile = this.profile;
  15013. var points = profile.points;
  15014. var start = points[0];
  15015. var end = points[points.length - 1];
  15016. var center = start.clone().add(end).multiplyScalar(0.5);
  15017. var mMoveOrigin = new Matrix4().makeTranslation(-center.x, -center.y, -center.z);
  15018. var mRotate = new Matrix4().makeRotationZ(radians);
  15019. var mMoveBack = new Matrix4().makeTranslation(center.x, center.y, center.z);
  15020. //const transform = mMoveOrigin.multiply(mRotate).multiply(mMoveBack);
  15021. var transform = mMoveBack.multiply(mRotate).multiply(mMoveOrigin);
  15022. var rotatedPoints = points.map(point => point.clone().applyMatrix4(transform));
  15023. this.profileWindow.autoFitEnabled = false;
  15024. for (var i = 0; i < points.length; i++) {
  15025. profile.setPosition(i, rotatedPoints[i]);
  15026. }
  15027. };
  15028. $("#potree_profile_rotate_cw").click(() => {
  15029. var radians = MathUtils.degToRad(this.rotateAmount);
  15030. rotate(-radians);
  15031. });
  15032. $("#potree_profile_rotate_ccw").click(() => {
  15033. var radians = MathUtils.degToRad(this.rotateAmount);
  15034. rotate(radians);
  15035. });
  15036. $("#potree_profile_move_forward").click(() => {
  15037. var profile = this.profile;
  15038. var points = profile.points;
  15039. var start = points[0];
  15040. var end = points[points.length - 1];
  15041. var dir = end.clone().sub(start).normalize();
  15042. var up = new Vector3(0, 0, 1);
  15043. var forward = up.cross(dir);
  15044. var move = forward.clone().multiplyScalar(profile.width / 2);
  15045. this.profileWindow.autoFitEnabled = false;
  15046. for (var i = 0; i < points.length; i++) {
  15047. profile.setPosition(i, points[i].clone().add(move));
  15048. }
  15049. });
  15050. $("#potree_profile_move_backward").click(() => {
  15051. var profile = this.profile;
  15052. var points = profile.points;
  15053. var start = points[0];
  15054. var end = points[points.length - 1];
  15055. var dir = end.clone().sub(start).normalize();
  15056. var up = new Vector3(0, 0, 1);
  15057. var forward = up.cross(dir);
  15058. var move = forward.clone().multiplyScalar(-profile.width / 2);
  15059. this.profileWindow.autoFitEnabled = false;
  15060. for (var i = 0; i < points.length; i++) {
  15061. profile.setPosition(i, points[i].clone().add(move));
  15062. }
  15063. });
  15064. }
  15065. setProfile(profile) {
  15066. if (this.profile !== null && this.profile !== profile) {
  15067. this.profile.removeEventListener('marker_moved', this._recompute);
  15068. this.profile.removeEventListener('marker_added', this._recompute);
  15069. this.profile.removeEventListener('marker_removed', this._recompute);
  15070. this.profile.removeEventListener('width_changed', this._recompute);
  15071. }
  15072. this.profile = profile;
  15073. {
  15074. this.profile.addEventListener('marker_moved', this._recompute);
  15075. this.profile.addEventListener('marker_added', this._recompute);
  15076. this.profile.addEventListener('marker_removed', this._recompute);
  15077. this.profile.addEventListener('width_changed', this._recompute);
  15078. }
  15079. this.recompute();
  15080. }
  15081. reset() {
  15082. this.profileWindow.reset();
  15083. this.numPoints = 0;
  15084. if (this.profile) {
  15085. for (var request of this.requests) {
  15086. request.cancel();
  15087. }
  15088. }
  15089. }
  15090. progressHandler(pointcloud, progress) {
  15091. for (var segment of progress.segments) {
  15092. this.profileWindow.addPoints(pointcloud, segment.points);
  15093. this.numPoints += segment.points.numPoints;
  15094. }
  15095. }
  15096. cancel() {
  15097. for (var request of this.requests) {
  15098. request.cancel();
  15099. // request.finishLevelThenCancel();
  15100. }
  15101. this.requests = [];
  15102. }
  15103. finishLevelThenCancel() {
  15104. for (var request of this.requests) {
  15105. request.finishLevelThenCancel();
  15106. }
  15107. this.requests = [];
  15108. }
  15109. recompute() {
  15110. var _this = this;
  15111. if (!this.profile) {
  15112. return;
  15113. }
  15114. if (this.scheduledRecomputeTime !== null && this.scheduledRecomputeTime > new Date().getTime()) {
  15115. return;
  15116. } else {
  15117. this.scheduledRecomputeTime = new Date().getTime() + 100;
  15118. }
  15119. this.scheduledRecomputeTime = null;
  15120. this.reset();
  15121. var _loop2 = function _loop2(pointcloud) {
  15122. var request = pointcloud.getPointsInProfile(_this.profile, null, {
  15123. 'onProgress': event => {
  15124. if (!_this.enabled) {
  15125. return;
  15126. }
  15127. _this.progressHandler(pointcloud, event.points);
  15128. if (_this.numPoints > _this.threshold) {
  15129. _this.finishLevelThenCancel();
  15130. }
  15131. },
  15132. 'onFinish': event => {
  15133. if (!_this.enabled) {}
  15134. },
  15135. 'onCancel': () => {
  15136. if (!_this.enabled) {}
  15137. }
  15138. });
  15139. _this.requests.push(request);
  15140. };
  15141. for (var pointcloud of this.viewer.scene.pointclouds.filter(p => p.visible)) {
  15142. _loop2(pointcloud);
  15143. }
  15144. }
  15145. }
  15146. ;
  15147. //import { EventDispatcher } from "../EventDispatcher.js";
  15148. class VolumeTool extends EventDispatcher {
  15149. constructor(viewer) {
  15150. super();
  15151. this.viewer = viewer;
  15152. this.renderer = viewer.renderer;
  15153. this.addEventListener('start_inserting_volume', e => {
  15154. this.viewer.dispatchEvent({
  15155. type: 'cancel_insertions'
  15156. });
  15157. });
  15158. this.scene = new Scene();
  15159. this.scene.name = 'scene_volume';
  15160. this.viewer.inputHandler.registerInteractiveScene(this.scene);
  15161. this.onRemove = e => {
  15162. this.scene.remove(e.volume);
  15163. };
  15164. this.onAdd = e => {
  15165. this.scene.add(e.volume);
  15166. };
  15167. for (var volume of viewer.scene.volumes) {
  15168. this.onAdd({
  15169. volume: volume
  15170. });
  15171. }
  15172. this.viewer.inputHandler.addEventListener('delete', e => {
  15173. var volumes = e.selection.filter(e => e instanceof Volume);
  15174. volumes.forEach(e => this.viewer.scene.removeVolume(e));
  15175. });
  15176. viewer.addEventListener("update", this.update.bind(this));
  15177. viewer.addEventListener("render.pass.scene", e => this.render(e));
  15178. viewer.addEventListener("scene_changed", this.onSceneChange.bind(this));
  15179. viewer.scene.addEventListener('volume_added', this.onAdd);
  15180. viewer.scene.addEventListener('volume_removed', this.onRemove);
  15181. }
  15182. onSceneChange(e) {
  15183. if (e.oldScene) {
  15184. e.oldScene.removeEventListeners('volume_added', this.onAdd);
  15185. e.oldScene.removeEventListeners('volume_removed', this.onRemove);
  15186. }
  15187. e.scene.addEventListener('volume_added', this.onAdd);
  15188. e.scene.addEventListener('volume_removed', this.onRemove);
  15189. }
  15190. startInsertion() {
  15191. var args = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  15192. var volume;
  15193. if (args.type) {
  15194. volume = new args.type();
  15195. } else {
  15196. volume = new BoxVolume();
  15197. }
  15198. volume.clip = args.clip || false;
  15199. volume.name = args.name || 'Volume';
  15200. this.dispatchEvent({
  15201. type: 'start_inserting_volume',
  15202. volume: volume
  15203. });
  15204. this.viewer.scene.addVolume(volume);
  15205. this.scene.add(volume);
  15206. var cancel = {
  15207. callback: null
  15208. };
  15209. var drag = e => {
  15210. var camera = this.viewer.scene.getActiveCamera();
  15211. var I = Utils.getMousePointCloudIntersection(e.drag.end, this.viewer.scene.getActiveCamera(), this.viewer, this.viewer.scene.pointclouds, {
  15212. pickClipped: false
  15213. });
  15214. if (I) {
  15215. volume.position.copy(I.location);
  15216. var wp = volume.getWorldPosition(new Vector3()).applyMatrix4(camera.matrixWorldInverse);
  15217. // let pp = new THREE.Vector4(wp.x, wp.y, wp.z).applyMatrix4(camera.projectionMatrix);
  15218. var w = Math.abs(wp.z / 5);
  15219. volume.scale.set(w, w, w);
  15220. }
  15221. };
  15222. var drop = e => {
  15223. volume.removeEventListener('drag', drag);
  15224. volume.removeEventListener('drop', drop);
  15225. cancel.callback();
  15226. };
  15227. cancel.callback = e => {
  15228. volume.removeEventListener('drag', drag);
  15229. volume.removeEventListener('drop', drop);
  15230. this.viewer.removeEventListener('cancel_insertions', cancel.callback);
  15231. };
  15232. volume.addEventListener('drag', drag);
  15233. volume.addEventListener('drop', drop);
  15234. this.viewer.addEventListener('cancel_insertions', cancel.callback);
  15235. this.viewer.inputHandler.startDragging(volume);
  15236. return volume;
  15237. }
  15238. update() {
  15239. if (!this.viewer.scene) {
  15240. return;
  15241. }
  15242. var camera = this.viewer.scene.getActiveCamera();
  15243. var renderAreaSize = this.viewer.renderer.getSize(new Vector2());
  15244. var clientWidth = renderAreaSize.width;
  15245. var clientHeight = renderAreaSize.height;
  15246. var volumes = this.viewer.scene.volumes;
  15247. for (var volume of volumes) {
  15248. var label = volume.label;
  15249. {
  15250. var distance = label.position.distanceTo(camera.position);
  15251. var pr = Utils.projectedRadius(1, camera, distance, clientWidth, clientHeight);
  15252. var scale = 70 / pr;
  15253. label.scale.set(scale, scale, scale);
  15254. }
  15255. var calculatedVolume = volume.getVolume();
  15256. calculatedVolume = calculatedVolume / Math.pow(this.viewer.lengthUnit.unitspermeter, 3) * Math.pow(this.viewer.lengthUnitDisplay.unitspermeter, 3); //convert to cubic meters then to the cubic display unit
  15257. var text = Utils.addCommas(calculatedVolume.toFixed(3)) + ' ' + this.viewer.lengthUnitDisplay.code + '\u00B3';
  15258. label.setText(text);
  15259. }
  15260. }
  15261. render(params) {
  15262. var renderer = this.viewer.renderer;
  15263. var oldTarget = renderer.getRenderTarget();
  15264. if (params.renderTarget) {
  15265. renderer.setRenderTarget(params.renderTarget);
  15266. }
  15267. renderer.render(this.scene, this.viewer.scene.getActiveCamera());
  15268. renderer.setRenderTarget(oldTarget);
  15269. }
  15270. }
  15271. /**
  15272. *
  15273. * code adapted from three.js BoxHelper.js
  15274. * https://github.com/mrdoob/three.js/blob/dev/src/helpers/BoxHelper.js
  15275. *
  15276. * @author mrdoob / http://mrdoob.com/
  15277. * @author Mugen87 / http://github.com/Mugen87
  15278. * @author mschuetz / http://potree.org
  15279. */
  15280. class Box3Helper$1 extends LineSegments {
  15281. constructor(box, color) {
  15282. var depthTest = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
  15283. if (color === undefined) color = 0xffff00;
  15284. var indices = new Uint16Array([0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7]);
  15285. var positions = new Float32Array([box.min.x, box.min.y, box.min.z, box.max.x, box.min.y, box.min.z, box.max.x, box.min.y, box.max.z, box.min.x, box.min.y, box.max.z, box.min.x, box.max.y, box.min.z, box.max.x, box.max.y, box.min.z, box.max.x, box.max.y, box.max.z, box.min.x, box.max.y, box.max.z]);
  15286. var geometry = new BufferGeometry();
  15287. geometry.setIndex(new BufferAttribute(indices, 1));
  15288. geometry.setAttribute('position', new BufferAttribute(positions, 3));
  15289. var material = new LineBasicMaterial({
  15290. color: color,
  15291. depthTest
  15292. });
  15293. super(geometry, material);
  15294. }
  15295. }
  15296. var KeyCodes = {
  15297. LEFT: 37,
  15298. UP: 38,
  15299. RIGHT: 39,
  15300. BOTTOM: 40,
  15301. DELETE: 46,
  15302. A: 'A'.charCodeAt(0),
  15303. S: 'S'.charCodeAt(0),
  15304. D: 'D'.charCodeAt(0),
  15305. W: 'W'.charCodeAt(0),
  15306. Q: 'Q'.charCodeAt(0),
  15307. E: 'E'.charCodeAt(0),
  15308. R: 'R'.charCodeAt(0),
  15309. F: 'F'.charCodeAt(0)
  15310. };
  15311. class NormalizationMaterial extends RawShaderMaterial {
  15312. constructor() {
  15313. var parameters = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  15314. super();
  15315. var uniforms = {
  15316. uDepthMap: {
  15317. type: 't',
  15318. value: null
  15319. },
  15320. uWeightMap: {
  15321. type: 't',
  15322. value: null
  15323. }
  15324. };
  15325. this.setValues({
  15326. uniforms: uniforms,
  15327. vertexShader: this.getDefines() + Shaders['normalize.vs'],
  15328. fragmentShader: this.getDefines() + Shaders['normalize.fs']
  15329. });
  15330. }
  15331. getDefines() {
  15332. var defines = '';
  15333. return defines;
  15334. }
  15335. updateShaderSource() {
  15336. var vs = this.getDefines() + Shaders['normalize.vs'];
  15337. var fs = this.getDefines() + Shaders['normalize.fs'];
  15338. this.setValues({
  15339. vertexShader: vs,
  15340. fragmentShader: fs
  15341. });
  15342. this.needsUpdate = true;
  15343. }
  15344. }
  15345. class NormalizationEDLMaterial extends RawShaderMaterial {
  15346. constructor() {
  15347. var parameters = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  15348. super();
  15349. var uniforms = {
  15350. screenWidth: {
  15351. type: 'f',
  15352. value: 0
  15353. },
  15354. screenHeight: {
  15355. type: 'f',
  15356. value: 0
  15357. },
  15358. edlStrength: {
  15359. type: 'f',
  15360. value: 1.0
  15361. },
  15362. radius: {
  15363. type: 'f',
  15364. value: 1.0
  15365. },
  15366. neighbours: {
  15367. type: '2fv',
  15368. value: []
  15369. },
  15370. uEDLMap: {
  15371. type: 't',
  15372. value: null
  15373. },
  15374. uDepthMap: {
  15375. type: 't',
  15376. value: null
  15377. },
  15378. uWeightMap: {
  15379. type: 't',
  15380. value: null
  15381. }
  15382. };
  15383. this.setValues({
  15384. uniforms: uniforms,
  15385. vertexShader: this.getDefines() + Shaders['normalize.vs'],
  15386. fragmentShader: this.getDefines() + Shaders['normalize_and_edl.fs']
  15387. });
  15388. this.neighbourCount = 8;
  15389. }
  15390. getDefines() {
  15391. var defines = '';
  15392. defines += '#define NEIGHBOUR_COUNT ' + this.neighbourCount + '\n';
  15393. return defines;
  15394. }
  15395. updateShaderSource() {
  15396. var vs = this.getDefines() + Shaders['normalize.vs'];
  15397. var fs = this.getDefines() + Shaders['normalize_and_edl.fs'];
  15398. this.setValues({
  15399. vertexShader: vs,
  15400. fragmentShader: fs
  15401. });
  15402. this.uniforms.neighbours.value = this.neighbours;
  15403. this.needsUpdate = true;
  15404. }
  15405. get neighbourCount() {
  15406. return this._neighbourCount;
  15407. }
  15408. set neighbourCount(value) {
  15409. if (this._neighbourCount !== value) {
  15410. this._neighbourCount = value;
  15411. this.neighbours = new Float32Array(this._neighbourCount * 2);
  15412. for (var c = 0; c < this._neighbourCount; c++) {
  15413. this.neighbours[2 * c + 0] = Math.cos(2 * c * Math.PI / this._neighbourCount);
  15414. this.neighbours[2 * c + 1] = Math.sin(2 * c * Math.PI / this._neighbourCount);
  15415. }
  15416. this.updateShaderSource();
  15417. }
  15418. }
  15419. }
  15420. //在potree.shim中修改。 。official中用不到且有bug
  15421. class HQSplatRenderer {
  15422. constructor(viewer) {
  15423. this.viewer = viewer;
  15424. this.depthMaterials = new Map();
  15425. this.attributeMaterials = new Map();
  15426. this.normalizationMaterial = null;
  15427. this.rtDepth = null;
  15428. this.rtAttribute = null;
  15429. this.gl = viewer.renderer.getContext();
  15430. this.initialized = false;
  15431. }
  15432. init() {
  15433. if (this.initialized) {
  15434. return;
  15435. }
  15436. this.normalizationMaterial = new NormalizationMaterial();
  15437. this.normalizationMaterial.depthTest = true;
  15438. this.normalizationMaterial.depthWrite = true;
  15439. this.normalizationMaterial.transparent = true;
  15440. this.normalizationEDLMaterial = new NormalizationEDLMaterial();
  15441. this.normalizationEDLMaterial.depthTest = true;
  15442. this.normalizationEDLMaterial.depthWrite = true;
  15443. this.normalizationEDLMaterial.transparent = true;
  15444. this.rtDepth = new WebGLRenderTarget(1024, 1024, {
  15445. minFilter: NearestFilter,
  15446. magFilter: NearestFilter,
  15447. format: RGBAFormat,
  15448. type: FloatType,
  15449. depthTexture: new DepthTexture(undefined, undefined, UnsignedIntType)
  15450. });
  15451. this.rtAttribute = new WebGLRenderTarget(1024, 1024, {
  15452. minFilter: NearestFilter,
  15453. magFilter: NearestFilter,
  15454. format: RGBAFormat,
  15455. type: FloatType,
  15456. depthTexture: this.rtDepth.depthTexture
  15457. });
  15458. this.initialized = true;
  15459. }
  15460. resize(width, height) {
  15461. this.rtDepth.setSize(width, height);
  15462. this.rtAttribute.setSize(width, height);
  15463. }
  15464. clearTargets() {
  15465. var viewer = this.viewer;
  15466. var {
  15467. renderer
  15468. } = viewer;
  15469. var oldTarget = renderer.getRenderTarget();
  15470. renderer.setClearColor(0x000000, 0);
  15471. renderer.setRenderTarget(this.rtDepth);
  15472. renderer.clear(true, true, true);
  15473. renderer.setRenderTarget(this.rtAttribute);
  15474. renderer.clear(true, true, true);
  15475. renderer.setRenderTarget(oldTarget);
  15476. }
  15477. clear() {
  15478. this.init();
  15479. var {
  15480. renderer,
  15481. background
  15482. } = this.viewer;
  15483. if (background === "skybox") {
  15484. renderer.setClearColor(0x000000, 0);
  15485. } else if (background === 'gradient') {
  15486. renderer.setClearColor(0x000000, 0);
  15487. } else if (background === 'black') {
  15488. renderer.setClearColor(0x000000, 1);
  15489. } else if (background === 'white') {
  15490. renderer.setClearColor(0xFFFFFF, 1);
  15491. } else {
  15492. renderer.setClearColor(0x000000, 0);
  15493. }
  15494. renderer.clear();
  15495. this.clearTargets();
  15496. }
  15497. render(params) {
  15498. this.init();
  15499. var viewer = this.viewer;
  15500. var camera = params.camera ? params.camera : viewer.scene.getActiveCamera();
  15501. var {
  15502. width,
  15503. height
  15504. } = this.viewer.renderer.getSize(new Vector2());
  15505. viewer.dispatchEvent({
  15506. type: "render.pass.begin",
  15507. viewer: viewer
  15508. });
  15509. this.resize(width, height);
  15510. var visiblePointClouds = viewer.scene.pointclouds.filter(pc => pc.visible);
  15511. var originalMaterials = new Map();
  15512. for (var pointcloud of visiblePointClouds) {
  15513. originalMaterials.set(pointcloud, pointcloud.material);
  15514. if (!this.attributeMaterials.has(pointcloud)) {
  15515. var attributeMaterial = new PointCloudMaterial$1();
  15516. this.attributeMaterials.set(pointcloud, attributeMaterial);
  15517. }
  15518. if (!this.depthMaterials.has(pointcloud)) {
  15519. var depthMaterial = new PointCloudMaterial$1();
  15520. depthMaterial.setDefine("depth_pass", "#define hq_depth_pass");
  15521. depthMaterial.setDefine("use_edl", "#define use_edl");
  15522. this.depthMaterials.set(pointcloud, depthMaterial);
  15523. }
  15524. }
  15525. {
  15526. // DEPTH PASS
  15527. for (var _pointcloud of visiblePointClouds) {
  15528. var octreeSize = _pointcloud.pcoGeometry.boundingBox.getSize(new Vector3()).x;
  15529. var material = originalMaterials.get(_pointcloud);
  15530. var _depthMaterial = this.depthMaterials.get(_pointcloud);
  15531. _depthMaterial.size = material.size;
  15532. _depthMaterial.minSize = material.minSize;
  15533. _depthMaterial.maxSize = material.maxSize;
  15534. _depthMaterial.pointSizeType = material.pointSizeType;
  15535. _depthMaterial.visibleNodesTexture = material.visibleNodesTexture;
  15536. _depthMaterial.weighted = false;
  15537. _depthMaterial.screenWidth = width;
  15538. _depthMaterial.shape = PointShape$1.CIRCLE;
  15539. _depthMaterial.screenHeight = height;
  15540. _depthMaterial.uniforms.visibleNodes.value = material.visibleNodesTexture;
  15541. _depthMaterial.uniforms.octreeSize.value = octreeSize;
  15542. _depthMaterial.spacing = _pointcloud.pcoGeometry.spacing; // * Math.max(...pointcloud.scale.toArray());
  15543. _depthMaterial.classification = material.classification;
  15544. _depthMaterial.uniforms.classificationLUT.value.image.data = material.uniforms.classificationLUT.value.image.data;
  15545. _depthMaterial.classificationTexture.needsUpdate = true;
  15546. _depthMaterial.uniforms.uFilterReturnNumberRange.value = material.uniforms.uFilterReturnNumberRange.value;
  15547. _depthMaterial.uniforms.uFilterNumberOfReturnsRange.value = material.uniforms.uFilterNumberOfReturnsRange.value;
  15548. _depthMaterial.uniforms.uFilterGPSTimeClipRange.value = material.uniforms.uFilterGPSTimeClipRange.value;
  15549. _depthMaterial.uniforms.uFilterPointSourceIDClipRange.value = material.uniforms.uFilterPointSourceIDClipRange.value;
  15550. _depthMaterial.clipTask = material.clipTask;
  15551. _depthMaterial.clipMethod = material.clipMethod;
  15552. _depthMaterial.setClipBoxes(material.clipBoxes);
  15553. _depthMaterial.setClipPolygons(material.clipPolygons);
  15554. _pointcloud.material = _depthMaterial;
  15555. }
  15556. viewer.pRenderer.render(viewer.scene.scenePointCloud, camera, this.rtDepth, {
  15557. clipSpheres: viewer.scene.volumes.filter(v => v instanceof SphereVolume$1)
  15558. });
  15559. }
  15560. {
  15561. // ATTRIBUTE PASS
  15562. for (var _pointcloud2 of visiblePointClouds) {
  15563. var _octreeSize = _pointcloud2.pcoGeometry.boundingBox.getSize(new Vector3()).x;
  15564. var _material = originalMaterials.get(_pointcloud2);
  15565. var _attributeMaterial = this.attributeMaterials.get(_pointcloud2);
  15566. _attributeMaterial.size = _material.size;
  15567. _attributeMaterial.minSize = _material.minSize;
  15568. _attributeMaterial.maxSize = _material.maxSize;
  15569. _attributeMaterial.pointSizeType = _material.pointSizeType;
  15570. _attributeMaterial.activeAttributeName = _material.activeAttributeName;
  15571. _attributeMaterial.visibleNodesTexture = _material.visibleNodesTexture;
  15572. _attributeMaterial.weighted = true;
  15573. _attributeMaterial.screenWidth = width;
  15574. _attributeMaterial.screenHeight = height;
  15575. _attributeMaterial.shape = PointShape$1.CIRCLE;
  15576. _attributeMaterial.uniforms.visibleNodes.value = _material.visibleNodesTexture;
  15577. _attributeMaterial.uniforms.octreeSize.value = _octreeSize;
  15578. _attributeMaterial.spacing = _pointcloud2.pcoGeometry.spacing; // * Math.max(...pointcloud.scale.toArray());
  15579. _attributeMaterial.classification = _material.classification;
  15580. _attributeMaterial.uniforms.classificationLUT.value.image.data = _material.uniforms.classificationLUT.value.image.data;
  15581. _attributeMaterial.classificationTexture.needsUpdate = true;
  15582. _attributeMaterial.uniforms.uFilterReturnNumberRange.value = _material.uniforms.uFilterReturnNumberRange.value;
  15583. _attributeMaterial.uniforms.uFilterNumberOfReturnsRange.value = _material.uniforms.uFilterNumberOfReturnsRange.value;
  15584. _attributeMaterial.uniforms.uFilterGPSTimeClipRange.value = _material.uniforms.uFilterGPSTimeClipRange.value;
  15585. _attributeMaterial.uniforms.uFilterPointSourceIDClipRange.value = _material.uniforms.uFilterPointSourceIDClipRange.value;
  15586. _attributeMaterial.elevationGradientRepeat = _material.elevationGradientRepeat;
  15587. _attributeMaterial.elevationRange = _material.elevationRange;
  15588. _attributeMaterial.gradient = _material.gradient;
  15589. _attributeMaterial.matcap = _material.matcap;
  15590. _attributeMaterial.intensityRange = _material.intensityRange;
  15591. _attributeMaterial.intensityGamma = _material.intensityGamma;
  15592. _attributeMaterial.intensityContrast = _material.intensityContrast;
  15593. _attributeMaterial.intensityBrightness = _material.intensityBrightness;
  15594. _attributeMaterial.rgbGamma = _material.rgbGamma;
  15595. _attributeMaterial.rgbContrast = _material.rgbContrast;
  15596. _attributeMaterial.rgbBrightness = _material.rgbBrightness;
  15597. _attributeMaterial.weightRGB = _material.weightRGB;
  15598. _attributeMaterial.weightIntensity = _material.weightIntensity;
  15599. _attributeMaterial.weightElevation = _material.weightElevation;
  15600. _attributeMaterial.weightRGB = _material.weightRGB;
  15601. _attributeMaterial.weightClassification = _material.weightClassification;
  15602. _attributeMaterial.weightReturnNumber = _material.weightReturnNumber;
  15603. _attributeMaterial.weightSourceID = _material.weightSourceID;
  15604. _attributeMaterial.color = _material.color;
  15605. _attributeMaterial.clipTask = _material.clipTask;
  15606. _attributeMaterial.clipMethod = _material.clipMethod;
  15607. _attributeMaterial.setClipBoxes(_material.clipBoxes);
  15608. _attributeMaterial.setClipPolygons(_material.clipPolygons);
  15609. _pointcloud2.material = _attributeMaterial;
  15610. }
  15611. var gl = this.gl;
  15612. viewer.renderer.setRenderTarget(null);
  15613. viewer.pRenderer.render(viewer.scene.scenePointCloud, camera, this.rtAttribute, {
  15614. clipSpheres: viewer.scene.volumes.filter(v => v instanceof SphereVolume$1),
  15615. //material: this.attributeMaterial,
  15616. blendFunc: [gl.SRC_ALPHA, gl.ONE],
  15617. //depthTest: false,
  15618. depthWrite: false
  15619. });
  15620. }
  15621. for (var [_pointcloud3, _material2] of originalMaterials) {
  15622. _pointcloud3.material = _material2;
  15623. }
  15624. viewer.renderer.setRenderTarget(null);
  15625. if (viewer.background === "skybox") {
  15626. viewer.renderer.setClearColor(0x000000, 0);
  15627. viewer.renderer.clear();
  15628. viewer.skybox.camera.rotation.copy(viewer.scene.cameraP.rotation);
  15629. viewer.skybox.camera.fov = viewer.scene.cameraP.fov;
  15630. viewer.skybox.camera.aspect = viewer.scene.cameraP.aspect;
  15631. viewer.skybox.parent.rotation.x = 0;
  15632. viewer.skybox.parent.updateMatrixWorld();
  15633. viewer.skybox.camera.updateProjectionMatrix();
  15634. viewer.renderer.render(viewer.skybox.scene, viewer.skybox.camera);
  15635. } else if (viewer.background === 'gradient') {
  15636. viewer.renderer.setClearColor(0x000000, 0);
  15637. viewer.renderer.clear();
  15638. viewer.renderer.render(viewer.scene.sceneBG, viewer.scene.cameraBG);
  15639. } else if (viewer.background === 'black') {
  15640. viewer.renderer.setClearColor(0x000000, 1);
  15641. viewer.renderer.clear();
  15642. } else if (viewer.background === 'white') {
  15643. viewer.renderer.setClearColor(0xFFFFFF, 1);
  15644. viewer.renderer.clear();
  15645. } else {
  15646. viewer.renderer.setClearColor(0x000000, 0);
  15647. viewer.renderer.clear();
  15648. }
  15649. {
  15650. // NORMALIZATION PASS
  15651. var normalizationMaterial = this.useEDL ? this.normalizationEDLMaterial : this.normalizationMaterial;
  15652. if (this.useEDL) {
  15653. normalizationMaterial.uniforms.edlStrength.value = viewer.edlStrength;
  15654. normalizationMaterial.uniforms.radius.value = viewer.edlRadius;
  15655. normalizationMaterial.uniforms.screenWidth.value = width;
  15656. normalizationMaterial.uniforms.screenHeight.value = height;
  15657. normalizationMaterial.uniforms.uEDLMap.value = this.rtDepth.texture;
  15658. }
  15659. normalizationMaterial.uniforms.uWeightMap.value = this.rtAttribute.texture;
  15660. normalizationMaterial.uniforms.uDepthMap.value = this.rtAttribute.depthTexture;
  15661. Utils.screenPass.render(viewer.renderer, normalizationMaterial);
  15662. }
  15663. viewer.renderer.render(viewer.scene.scene, camera);
  15664. viewer.dispatchEvent({
  15665. type: "render.pass.scene",
  15666. viewer: viewer
  15667. });
  15668. viewer.renderer.clearDepth();
  15669. viewer.transformationTool.update();
  15670. viewer.dispatchEvent({
  15671. type: "render.pass.perspective_overlay",
  15672. viewer: viewer
  15673. });
  15674. viewer.renderer.render(viewer.controls.sceneControls, camera);
  15675. viewer.renderer.render(viewer.clippingTool.sceneVolume, camera);
  15676. viewer.renderer.render(viewer.transformationTool.scene, camera);
  15677. viewer.renderer.setViewport(width - viewer.navigationCube.width, height - viewer.navigationCube.width, viewer.navigationCube.width, viewer.navigationCube.width);
  15678. viewer.renderer.render(viewer.navigationCube, viewer.navigationCube.camera);
  15679. viewer.renderer.setViewport(0, 0, width, height);
  15680. viewer.dispatchEvent({
  15681. type: "render.pass.end",
  15682. viewer: viewer
  15683. });
  15684. }
  15685. }
  15686. class LRUItem {
  15687. constructor(node) {
  15688. this.previous = null;
  15689. this.next = null;
  15690. this.node = node;
  15691. }
  15692. }
  15693. /**
  15694. *
  15695. * @class A doubly-linked-list of the least recently used elements.
  15696. */
  15697. class LRU {
  15698. constructor() {
  15699. //类似链表存储
  15700. // the least recently used item
  15701. this.first = null;
  15702. // the most recently used item
  15703. this.last = null;
  15704. // a list of all items in the lru list
  15705. this.items = {}; //按node的id存储。(id为0的就是root,name='r')
  15706. this.elements = 0;
  15707. this.numPoints = 0;
  15708. }
  15709. size() {
  15710. return this.elements;
  15711. }
  15712. contains(node) {
  15713. return this.items[node.id] == null;
  15714. }
  15715. touch(node) {
  15716. //链接node,并且永远放在最后. (每次updatePointClouds都要刷新一次链表)
  15717. if (!node.loaded) {
  15718. return;
  15719. }
  15720. var item;
  15721. if (this.items[node.id] == null) {
  15722. // add to list
  15723. item = new LRUItem(node);
  15724. item.previous = this.last;
  15725. this.last = item;
  15726. if (item.previous !== null) {
  15727. item.previous.next = item;
  15728. }
  15729. this.items[node.id] = item;
  15730. this.elements++;
  15731. if (this.first === null) {
  15732. this.first = item;
  15733. }
  15734. this.numPoints += node.numPoints;
  15735. } else {
  15736. // update in list
  15737. item = this.items[node.id];
  15738. if (item.previous === null) {
  15739. // handle touch on first element
  15740. if (item.next !== null) {
  15741. this.first = item.next;
  15742. this.first.previous = null;
  15743. item.previous = this.last;
  15744. item.next = null;
  15745. this.last = item;
  15746. item.previous.next = item;
  15747. }
  15748. } else if (item.next === null) {
  15749. // handle touch on last element
  15750. } else {
  15751. //从原来的位置挑出放最后
  15752. // handle touch on any other element
  15753. item.previous.next = item.next;
  15754. item.next.previous = item.previous;
  15755. item.previous = this.last;
  15756. item.next = null;
  15757. this.last = item;
  15758. item.previous.next = item;
  15759. }
  15760. }
  15761. }
  15762. //因为需要显示的都放末尾,所以不显示的部分都在前面,删除时从头删除。(但并不代表开头的一定是不显示的,所以如果第一个仍是显示的,它很可能是root,也就是name='r'的nodeGeo,删除它也就会删除全部)
  15763. remove(node) {
  15764. var lruItem = this.items[node.id];
  15765. if (lruItem) {
  15766. if (this.elements === 1) {
  15767. this.first = null;
  15768. this.last = null;
  15769. } else {
  15770. if (!lruItem.previous) {
  15771. this.first = lruItem.next;
  15772. this.first.previous = null;
  15773. }
  15774. if (!lruItem.next) {
  15775. this.last = lruItem.previous;
  15776. this.last.next = null;
  15777. }
  15778. if (lruItem.previous && lruItem.next) {
  15779. lruItem.previous.next = lruItem.next;
  15780. lruItem.next.previous = lruItem.previous;
  15781. }
  15782. }
  15783. delete this.items[node.id];
  15784. this.elements--;
  15785. this.numPoints -= node.numPoints;
  15786. }
  15787. }
  15788. getLRUItem() {
  15789. if (this.first === null) {
  15790. return null;
  15791. }
  15792. var lru = this.first;
  15793. return lru.node;
  15794. }
  15795. toString() {
  15796. var string = '{ ';
  15797. var curr = this.first;
  15798. while (curr !== null) {
  15799. string += curr.node.id;
  15800. if (curr.next !== null) {
  15801. string += ', ';
  15802. }
  15803. curr = curr.next;
  15804. }
  15805. string += '}';
  15806. string += '(' + this.size() + ')';
  15807. return string;
  15808. }
  15809. freeMemory() {
  15810. if (this.elements <= 1) {
  15811. return;
  15812. }
  15813. while (this.numPoints > Potree.pointLoadLimit) {
  15814. var element = this.first;
  15815. var node = element.node;
  15816. this.disposeDescendants(node);
  15817. }
  15818. }
  15819. disposeDescendants(node) {
  15820. var stack = [];
  15821. stack.push(node);
  15822. while (stack.length > 0) {
  15823. var current = stack.pop();
  15824. // console.log(current);
  15825. current.dispose(); //真正删除geometry等
  15826. this.remove(current);
  15827. for (var key in current.children) {
  15828. if (current.children.hasOwnProperty(key)) {
  15829. var child = current.children[key];
  15830. if (child.loaded) {
  15831. stack.push(current.children[key]);
  15832. }
  15833. }
  15834. }
  15835. }
  15836. }
  15837. }
  15838. //
  15839. // how to calculate the radius of a projected sphere in screen space
  15840. // http://stackoverflow.com/questions/21648630/radius-of-projected-sphere-in-screen-space
  15841. // http://stackoverflow.com/questions/3717226/radius-of-projected-sphere
  15842. //
  15843. class ExtendPointCloudMaterial extends PointCloudMaterial$1 {
  15844. constructor() {
  15845. var parameters = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  15846. super(parameters);
  15847. var getValid = (a, b) => {
  15848. if (a !== undefined) {
  15849. return a;
  15850. } else {
  15851. return b;
  15852. }
  15853. };
  15854. var maxSize = getValid(parameters.maxSize, 200.0);
  15855. var orthoMaxSize = getValid(parameters.orthoMaxSize, 3.0);
  15856. this._gradient = Gradients.RAINBOW; //Gradients.SPECTRAL;//海拔贴图种类
  15857. this.gradientTexture = ExtendPointCloudMaterial.generateGradientTexture(this._gradient);
  15858. //this.matcapTexture = ExtendPointCloudMaterial.generateMatcapTexture(this._matcap);
  15859. delete this.uniforms.screenWidth;
  15860. delete this.uniforms.screenHeight;
  15861. delete this.uniforms.clipBoxes;
  15862. delete this.uniforms.clipPolygons;
  15863. delete this.uniforms.clipPolygonVCount;
  15864. delete this.uniforms.clipPolygonVP;
  15865. delete this.uniforms.clipBoxCount;
  15866. //注意:这里修改了uniforms后,还需要在PotreeRender中手动传递到shader, like: gl.uniformMatrix4fv(....
  15867. Object.assign(this.uniforms, {
  15868. resolution: {
  15869. type: 'v2',
  15870. value: new Vector2()
  15871. },
  15872. maxSize: {
  15873. type: "f",
  15874. value: maxSize
  15875. },
  15876. orthoMaxSize: {
  15877. type: "f",
  15878. value: orthoMaxSize
  15879. },
  15880. gradient: {
  15881. type: "t",
  15882. value: this.gradientTexture
  15883. },
  15884. clipBoxes_in: {
  15885. type: "Matrix4fv",
  15886. value: []
  15887. },
  15888. clipBoxes_out: {
  15889. type: "Matrix4fv",
  15890. value: []
  15891. },
  15892. clipBoxBig_in: {
  15893. type: "Matrix4fv",
  15894. value: []
  15895. },
  15896. boxes_highlight: {
  15897. type: "Matrix4fv",
  15898. value: []
  15899. },
  15900. progress: {
  15901. type: "f",
  15902. value: 0
  15903. },
  15904. easeInOutRatio: {
  15905. type: "f",
  15906. value: 0.3
  15907. },
  15908. pano0Map: {
  15909. type: "t",
  15910. value: null
  15911. },
  15912. pano0Position: {
  15913. type: "v3",
  15914. value: new Vector3()
  15915. },
  15916. pano0Matrix: {
  15917. type: "m4",
  15918. value: new Matrix4()
  15919. },
  15920. pano1Map: {
  15921. type: "t",
  15922. value: null
  15923. },
  15924. pano1Position: {
  15925. type: "v3",
  15926. value: new Vector3()
  15927. },
  15928. pano1Matrix: {
  15929. type: "m4",
  15930. value: new Matrix4()
  15931. },
  15932. prismList: {
  15933. type: "Matrix3fv",
  15934. value: null
  15935. },
  15936. prismPoints: {
  15937. type: "vec2fv",
  15938. value: null
  15939. },
  15940. baseHeightAreaMap: {
  15941. type: 't',
  15942. value: null
  15943. },
  15944. baseHeightBoundZ: {
  15945. type: 'vec2',
  15946. value: new Vector2()
  15947. },
  15948. baseHeightBoundXY: {
  15949. type: 'vec4',
  15950. value: new Vector4()
  15951. }
  15952. });
  15953. delete this.clipBoxes;
  15954. this.clipBoxes_in = [];
  15955. this.clipBoxes_out = [];
  15956. this.highlightBoxes = [];
  15957. this.prisms = [];
  15958. var {
  15959. vs,
  15960. fs
  15961. } = Common.changeShaderToWebgl2(Shaders['pointcloud_new.vs'], Shaders['pointcloud_new.fs'], 'selfBuild');
  15962. Shaders['pointcloud_new.vs'] = vs;
  15963. Shaders['pointcloud_new.fs'] = fs;
  15964. this.updateShaderSource();
  15965. }
  15966. updateShaderSource() {
  15967. var vs = Shaders['pointcloud_new.vs']; //改
  15968. var fs = Shaders['pointcloud_new.fs']; //改
  15969. var definesString = this.getDefines();
  15970. var vsVersionIndex = vs.indexOf("#version ");
  15971. var fsVersionIndex = fs.indexOf("#version ");
  15972. if (vsVersionIndex >= 0) {
  15973. vs = vs.replace(/(#version .*)/, "$1\n".concat(definesString));
  15974. } else {
  15975. vs = "".concat(definesString, "\n").concat(vs);
  15976. }
  15977. if (fsVersionIndex >= 0) {
  15978. fs = fs.replace(/(#version .*)/, "$1\n".concat(definesString));
  15979. } else {
  15980. fs = "".concat(definesString, "\n").concat(fs);
  15981. }
  15982. this.vertexShader = vs;
  15983. this.fragmentShader = fs;
  15984. if (this.opacity === 1.0 && !this.useFilterByNormal) {
  15985. //add useFilterByNormal
  15986. this.blending = NoBlending;
  15987. this.transparent = false;
  15988. this.depthTest = true;
  15989. this.depthWrite = true;
  15990. this.depthFunc = LessEqualDepth;
  15991. } else if ((this.opacity < 1.0 || this.useFilterByNormal) && !this.useEDL) {
  15992. //add useFilterByNormal
  15993. this.blending = AdditiveBlending;
  15994. this.transparent = true;
  15995. this.depthTest = false;
  15996. this.depthWrite = true;
  15997. this.depthFunc = AlwaysDepth;
  15998. }
  15999. if (this.weighted) {
  16000. this.blending = AdditiveBlending;
  16001. this.transparent = true;
  16002. this.depthTest = true;
  16003. this.depthWrite = false;
  16004. }
  16005. this.shaderNeedsUpdate = true;
  16006. }
  16007. getDefines() {
  16008. var defines = [];
  16009. if (this.pointSizeType === PointSizeType.FIXED) {
  16010. defines.push('#define fixed_point_size');
  16011. } else if (this.pointSizeType === PointSizeType.ATTENUATED) {
  16012. defines.push('#define attenuated_point_size');
  16013. } else if (this.pointSizeType === PointSizeType.ADAPTIVE) {
  16014. defines.push('#define adaptive_point_size');
  16015. }
  16016. if (!Features.EXT_DEPTH.isSupported(viewer.renderer.getContext()) && this.shape === PointShape$1.PARABOLOID) {
  16017. this.shape = PointShape$1.SQUARE; //强行替换
  16018. }
  16019. if (this.shape === PointShape$1.SQUARE) {
  16020. defines.push('#define square_point_shape');
  16021. } else if (this.shape === PointShape$1.CIRCLE) {
  16022. defines.push('#define circle_point_shape');
  16023. } else if (this.shape === PointShape$1.PARABOLOID) {
  16024. defines.push('#define paraboloid_point_shape');
  16025. }
  16026. //console.log('this.shape PARABOLOID', this.shape, this.shape === PointShape.PARABOLOID)
  16027. if (this._useEDL || this.fakeEDL) {
  16028. defines.push('#define use_edl');
  16029. }
  16030. if (this.activeAttributeName) {
  16031. var attributeName = this.activeAttributeName.replace(/[^a-zA-Z0-9]/g, '_');
  16032. defines.push("#define color_type_".concat(attributeName));
  16033. }
  16034. if (this._treeType === TreeType.OCTREE) {
  16035. defines.push('#define tree_type_octree');
  16036. } else if (this._treeType === TreeType.KDTREE) {
  16037. defines.push('#define tree_type_kdtree');
  16038. }
  16039. if (this.weighted) {
  16040. defines.push('#define weighted_splats');
  16041. }
  16042. for (var [key, value] of this.defines) {
  16043. defines.push(value);
  16044. }
  16045. return defines.join("\n");
  16046. }
  16047. get pointSizeType() {
  16048. return this._pointSizeType;
  16049. }
  16050. set pointSizeType(value) {
  16051. if (typeof value == 'string') value = PointSizeType[value];
  16052. super.pointSizeType = value;
  16053. /* if (this._pointSizeType !== value) {
  16054. this._pointSizeType = value;
  16055. this.updateShaderSource(); //这句表明这个属性频繁更改会卡顿
  16056. this.dispatchEvent({
  16057. type: 'point_size_type_changed',
  16058. target: this
  16059. });
  16060. this.dispatchEvent({
  16061. type: 'material_property_changed',
  16062. target: this
  16063. });
  16064. } */
  16065. }
  16066. get color() {
  16067. return this.uniforms.uColor.value;
  16068. }
  16069. set color(value) {
  16070. //改
  16071. if (value == this.color_) return;
  16072. var color = value;
  16073. //if (!this.uniforms.uColor.value.equals(value)) {
  16074. if (typeof value == 'string') {
  16075. var colorArr = Potree.config.colors[value];
  16076. if (!colorArr) {
  16077. //console.warn('没找到该颜色值'+ value)
  16078. } else {
  16079. color = new Color().fromArray(colorArr).multiplyScalar(1 / 255);
  16080. }
  16081. }
  16082. this.uniforms.uColor.value.set(color);
  16083. //this.uniforms.uColor.value.copy(value);
  16084. this.dispatchEvent({
  16085. type: 'color_changed',
  16086. target: this
  16087. });
  16088. this.dispatchEvent({
  16089. type: 'material_property_changed',
  16090. target: this
  16091. });
  16092. //}
  16093. this.color_ = value; //记录下str
  16094. }
  16095. ////////////////////////add
  16096. setProjectedPanos(pano0, pano1, progressValue, easeInOutRatio) {
  16097. //this.uniforms.usePanoMap.value = 1
  16098. this.usePanoMap = true;
  16099. progressValue != void 0 && (this.uniforms.progress.value = progressValue);
  16100. //pano0.ensureSkyboxReadyForRender();
  16101. this.uniforms.pano0Map.value = pano0.getSkyboxTexture();
  16102. this.uniforms.pano0Position.value.copy(pano0.position);
  16103. this.uniforms.pano0Matrix.value.copy(pano0.panoMatrix);
  16104. //pano1.ensureSkyboxReadyForRender();
  16105. this.uniforms.easeInOutRatio.value = easeInOutRatio || 0; //之前做点云和全景混合时加的,为了让点云颜色柔和切换到全景颜色。如不混合就0
  16106. this.uniforms.pano1Map.value = pano1.getSkyboxTexture();
  16107. this.uniforms.pano1Position.value.copy(pano1.position);
  16108. this.uniforms.pano1Matrix.value.copy(pano1.panoMatrix);
  16109. //this.updateShaderSource()
  16110. //this.needsUpdate = true;
  16111. }
  16112. stopProjectedPanos() {
  16113. //this.uniforms.usePanoMap.value = 0
  16114. this.usePanoMap = false;
  16115. }
  16116. setClipBoxes(bigClipInBox, clipBoxes_in, clipBoxes_out, highlightBoxes) {
  16117. var prismPolygons = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
  16118. if (!clipBoxes_in || !clipBoxes_out) {
  16119. return;
  16120. }
  16121. this.uniforms.clipBoxBig_in.value = bigClipInBox && bigClipInBox.inverse;
  16122. this.uniforms.clipBoxes_in.value = new Float32Array(clipBoxes_in.length * 16);
  16123. this.uniforms.clipBoxes_out.value = new Float32Array(clipBoxes_out.length * 16);
  16124. this.uniforms.boxes_highlight.value = new Float32Array(highlightBoxes.length * 16);
  16125. for (var i = 0; i < clipBoxes_in.length; i++) {
  16126. var box = clipBoxes_in[i];
  16127. this.uniforms.clipBoxes_in.value.set(box.inverse.elements, 16 * i);
  16128. }
  16129. for (var _i = 0; _i < clipBoxes_out.length; _i++) {
  16130. var _box = clipBoxes_out[_i];
  16131. this.uniforms.clipBoxes_out.value.set(_box.inverse.elements, 16 * _i);
  16132. }
  16133. for (var _i2 = 0; _i2 < highlightBoxes.length; _i2++) {
  16134. var _box2 = highlightBoxes[_i2];
  16135. this.uniforms.boxes_highlight.value.set(_box2.inverse.elements, 16 * _i2);
  16136. }
  16137. /* for (let i = 0; i < this.uniforms.clipBoxes.value.length; i++) {??
  16138. if (Number.isNaN(this.uniforms.clipBoxes.value[i])) {
  16139. this.uniforms.clipBoxes.value[i] = Infinity;
  16140. }
  16141. } */
  16142. if (prismPolygons.length) {
  16143. var pointsCount = prismPolygons.pointsCount = prismPolygons.reduce((w, c) => {
  16144. return w + c.points.length;
  16145. }, 0);
  16146. this.uniforms.prismList.value = new Float32Array(9 * prismPolygons.length);
  16147. this.uniforms.prismPoints.value = new Float32Array(2 * pointsCount);
  16148. prismPolygons.maxPointsCount = 0; //单个prism最大点个数
  16149. var pointIndex = 0;
  16150. for (var _i3 = 0; _i3 < prismPolygons.length; _i3++) {
  16151. var bound = prismPolygons[_i3].prismBound;
  16152. var z = prismPolygons[_i3].horizonZ;
  16153. //z = Potree.browser.urlHasValue('zmin',true) || zs[0]
  16154. this.uniforms.prismList.value.set([bound.min.z, z, bound.max.z, bound.min.x, bound.max.x, bound.min.y, bound.max.y, prismPolygons[_i3].points.length], 9 * _i3);
  16155. for (var j = 0; j < prismPolygons[_i3].points.length; j++) {
  16156. this.uniforms.prismPoints.value.set([prismPolygons[_i3].points[j].x, prismPolygons[_i3].points[j].y], 2 * j + pointIndex);
  16157. }
  16158. pointIndex += 2 * prismPolygons[_i3].points.length;
  16159. prismPolygons.maxPointsCount = Math.max(prismPolygons.maxPointsCount, prismPolygons[_i3].points.length);
  16160. }
  16161. }
  16162. var doUpdate = this.clipBoxes_in.length !== clipBoxes_in.length || this.clipBoxes_out.length != clipBoxes_out.length || this.highlightBoxes.length !== highlightBoxes.length || !this.bigClipInBox != !bigClipInBox || this.prisms.length != prismPolygons.length || this.prisms.maxPointsCount != prismPolygons.maxPointsCount;
  16163. //this.clipBoxes = clipBoxes;
  16164. if (doUpdate) {
  16165. this.shaderNeedsUpdate = true;
  16166. viewer.dispatchEvent('content_changed');
  16167. }
  16168. this.bigClipInBox = bigClipInBox;
  16169. this.clipBoxes_in = clipBoxes_in;
  16170. this.clipBoxes_out = clipBoxes_out;
  16171. this.highlightBoxes = highlightBoxes;
  16172. this.prisms = prismPolygons;
  16173. }
  16174. }
  16175. var defaultColor = new Color(1, 1, 1); //config.applicationName == "zhiHouse" ? Colors.zhiBlue : Colors.lightGreen;
  16176. function dealPosArr(points) {
  16177. //识别是否每个点都不一样,把连续点变为不连续的片段连接
  16178. var add = points => {
  16179. var points2 = [],
  16180. len = points.length;
  16181. for (var i = 0; i < len - 1; i++) {
  16182. points2.push(points[i], points[i + 1]);
  16183. }
  16184. return points2;
  16185. };
  16186. if (points[0] && points[0] instanceof Array) {
  16187. //多组,每组间连续,但组之间不连续
  16188. var points2 = [];
  16189. points.forEach(ps => points2.push(...add(ps)));
  16190. return points2;
  16191. } else if (points.length > 2 && !points[2].equals(points[1])) {
  16192. return add(points);
  16193. } else return points;
  16194. }
  16195. var LineDraw = {
  16196. createLine: function createLine(posArr) {
  16197. var o = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  16198. //多段普通线 (第二个点和第三个点之间是没有线段的, 所以不用在意线段顺序)
  16199. var mat;
  16200. if (o.mat) {
  16201. mat = o.mat;
  16202. } else {
  16203. var prop = Object.assign({
  16204. lineWidth: o.lineWidth || 1,
  16205. //windows无效。 似乎mac/ios上粗细有效 ?
  16206. color: o.color || defaultColor
  16207. }, o);
  16208. if (o.deshed) {
  16209. prop.dashSize = o.dashSize || 0.1, prop.gapSize = o.gapSize || 0.1;
  16210. }
  16211. mat = new THREE$1[o.deshed ? "LineDashedMaterial" : "LineBasicMaterial"](prop);
  16212. }
  16213. var line = new LineSegments(new BufferGeometry(), mat);
  16214. line.renderOrder = o.renderOrder || Potree.config.renderOrders.lines;
  16215. this.moveLine(line, posArr);
  16216. return line;
  16217. },
  16218. moveLine: function moveLine(line, posArr) {
  16219. //if(posArr.length == 0)return
  16220. if (!line.uncontinuous || posArr[0] && posArr[0] instanceof Array) posArr = dealPosArr(posArr);
  16221. var position = [];
  16222. posArr.forEach(e => position.push(e.x, e.y, e.z));
  16223. line.geometry.setAttribute('position', new Float32BufferAttribute( /* new Float32Array( */position /* ) */, 3));
  16224. line.geometry.attributes.position.needsUpdate = true;
  16225. line.geometry.computeBoundingSphere();
  16226. if (line.material instanceof LineDashedMaterial) {
  16227. line.computeLineDistances();
  16228. //line.geometry.attributes.lineDistance.needsUpdate = true;
  16229. line.geometry.verticesNeedUpdate = true; //没用
  16230. }
  16231. },
  16232. createFatLineMat: function createFatLineMat(o) {
  16233. var supportExtDepth = !!Features.EXT_DEPTH.isSupported();
  16234. var params = $.extend({}, {
  16235. //默认
  16236. lineWidth: 5,
  16237. color: 0xffffff,
  16238. transparent: true,
  16239. depthWrite: false,
  16240. depthTest: false,
  16241. dashSize: 0.1,
  16242. gapSize: 0.1
  16243. }, o, {
  16244. //修正覆盖:
  16245. dashed: o.dashWithDepth ? supportExtDepth && !!o.dashed : !!o.dashed,
  16246. dashWithDepth: !!o.dashWithDepth,
  16247. //只在被遮住的部分显示虚线
  16248. useDepth: !!o.useDepth,
  16249. supportExtDepth
  16250. });
  16251. var mat = new LineMaterial(params);
  16252. //if(o.dashed)(mat.defines.USE_DASH = "")
  16253. return mat;
  16254. },
  16255. /*
  16256. 创建可以改变粗细的线。
  16257. */
  16258. createFatLine: function createFatLine(posArr, o) {
  16259. var geometry = new LineGeometry();
  16260. geometry.setColors(o.color || [1, 1, 1]);
  16261. var matLine = o.mat || this.createFatLineMat(o);
  16262. var line = new Line2(geometry, matLine);
  16263. //line.computeLineDistances();
  16264. line.uncontinuous = o.uncontinuous; //线不连续,由线段组成
  16265. line.scale.set(1, 1, 1);
  16266. line.renderOrder = Potree.config.renderOrders.lines;
  16267. this.moveFatLine(line, posArr);
  16268. return line;
  16269. },
  16270. moveFatLine: function moveFatLine(line, posArr) {
  16271. var geometry = line.geometry;
  16272. var positions = [];
  16273. if (!line.uncontinuous || posArr[0] && posArr[0] instanceof Array) posArr = dealPosArr(posArr);
  16274. posArr.forEach(e => {
  16275. positions.push(...e.toArray());
  16276. });
  16277. if (!geometry) {
  16278. geometry = line.geometry = new LineGeometry();
  16279. }
  16280. if (geometry.attributes.instanceEnd && geometry.attributes.instanceEnd.data.array.length != positions.length) {
  16281. //positions个数改变会有部分显示不出来,所以重建
  16282. geometry.dispose();
  16283. geometry = new LineGeometry();
  16284. line.geometry = geometry;
  16285. }
  16286. geometry.setPositions(positions);
  16287. if (line.material.defines.USE_DASH != void 0) {
  16288. //line.geometry.verticesNeedUpdate = true; //没用
  16289. line.geometry.computeBoundingSphere(); //for raycaster
  16290. line.computeLineDistances();
  16291. }
  16292. },
  16293. updateLine: function updateLine(line, posArr) {
  16294. if (line instanceof Line2) {
  16295. LineDraw.moveFatLine(line, posArr);
  16296. } else {
  16297. LineDraw.moveLine(line, posArr);
  16298. }
  16299. },
  16300. /*
  16301. 为line创建用于检测鼠标的透明mesh,实际是个1-2段圆台。
  16302. 由于近大远小的原因,假设没有透视畸变、创建的是等粗的圆柱的话, 所看到的线上每个位置的粗细应该和距离成反比。所以将圆柱改为根据距离线性渐变其截面半径的圆台,在最近点(相机到线的垂足)最细。如果最近点在线段上,则分成两段圆台,否则一段。
  16303. */
  16304. createBoldLine: function createBoldLine(points, o) {
  16305. o = o || {};
  16306. var cylinder = o && o.cylinder;
  16307. var CD = points[1].clone().sub(points[0]);
  16308. var rotate = function rotate() {
  16309. //根据端点旋转好模型
  16310. cylinder.lastVector = CD; //记录本次的端点向量
  16311. var AB = new Vector3(0, -1, 0);
  16312. var axisVec = AB.clone().cross(CD).normalize(); //得到垂直于它们的向量,也就是旋转轴
  16313. var rotationAngle = AB.angleTo(CD);
  16314. cylinder.quaternion.setFromAxisAngle(axisVec, rotationAngle);
  16315. };
  16316. if (o && o.type == "init") {
  16317. cylinder = new Mesh();
  16318. cylinder.material = o.mat;
  16319. if (CD.length() == 0) return cylinder;
  16320. rotate();
  16321. }
  16322. if (CD.length() == 0) return cylinder;
  16323. if (o.type != "update") {
  16324. var CDcenter = points[0].clone().add(points[1]).multiplyScalar(.5);
  16325. cylinder.position.copy(CDcenter);
  16326. if (!cylinder.lastVector || o.type == "moveAndRotate") rotate();else if (cylinder.lastVector && CD.angleTo(cylinder.lastVector) > 0) rotate(); //线方向改了or线反向了 重新旋转一下模型
  16327. if (config.isEdit && !objects.mainDesign.editing) return cylinder; //节省初始加载时间?
  16328. }
  16329. //为了保证线段任何地方的可检测点击范围看起来一样大,更新圆台的结构(但是在镜头边缘会比中心看起来大)
  16330. var height = points[0].distanceTo(points[1]);
  16331. var standPos = o && o.standPos || objects.player.position;
  16332. var k = config.isMobile ? 20 : 40;
  16333. var dis1 = points[0].distanceTo(standPos);
  16334. var dis2 = points[1].distanceTo(standPos);
  16335. var foot = math.getFootPoint(standPos, points[0], points[1]); //垂足
  16336. if (o.constantBold || objects.player.mode != "panorama") {
  16337. var width = 0.1; //0.08;
  16338. var pts = [new Vector2(width, height / 2), new Vector2(width, -height / 2)];
  16339. } else if (foot.clone().sub(points[0]).dot(foot.clone().sub(points[1])) > 0) {
  16340. //foot不在线段上
  16341. var pts = [new Vector2(dis1 / k, height / 2), new Vector2(dis2 / k, -height / 2)];
  16342. } else {
  16343. //在线段上的话,要在垂足这加一个节点,因它距离站位最近,而两端较远
  16344. var dis3 = foot.distanceTo(standPos);
  16345. var len = foot.distanceTo(points[0]);
  16346. var pts = [new Vector2(dis1 / k, height / 2), new Vector2(dis3 / k, height / 2 - len), new Vector2(dis2 / k, -height / 2)];
  16347. }
  16348. cylinder.geometry && cylinder.geometry.dispose(); //若不删除会占用内存
  16349. cylinder.geometry = new LatheBufferGeometry(pts, 4 /* Math.min(dis1,dis2)<10?4:3 */);
  16350. cylinder.renderOrder = 2;
  16351. return cylinder;
  16352. },
  16353. updateBoldLine: function updateBoldLine(cylinder, points, type, standPos, constantBold) {
  16354. this.createBoldLine(points, {
  16355. type: type,
  16356. cylinder: cylinder,
  16357. standPos: standPos,
  16358. constantBold
  16359. }); //type:move:平移 会改长短 , type:update根据距离和角度更新 不改长短
  16360. }
  16361. };
  16362. var MeshDraw = {
  16363. getShape: function getShape(shapes, holes) {
  16364. //不一定闭合 暂时所有shapes共享holes。如果要单独的话, shapes改为[{shape:[],holes:[]},{}]的形式
  16365. if (shapes[0] && !(shapes[0] instanceof Array)) {
  16366. //仅是一个shape的点
  16367. shapes = [shapes];
  16368. }
  16369. var holesArr = [];
  16370. if (holes) {
  16371. //挖空
  16372. holes.forEach(points => {
  16373. var holePath = new Path();
  16374. holePath.moveTo(points[0].x, points[0].y);
  16375. for (var i = 1, len = points.length; i < len; i++) {
  16376. holePath.lineTo(points[i].x, points[i].y);
  16377. }
  16378. holesArr.push(holePath);
  16379. });
  16380. }
  16381. var shapesArr = shapes.map(points => {
  16382. var shape = new Shape();
  16383. shape.moveTo(points[0].x, points[0].y);
  16384. for (var i = 1, len = points.length; i < len; i++) {
  16385. shape.lineTo(points[i].x, points[i].y);
  16386. }
  16387. shape.holes.push(...holesArr);
  16388. shape.dontClose = points.dontClose; //add 有的shape不需要闭合
  16389. return shape;
  16390. });
  16391. return shapesArr;
  16392. },
  16393. /* getShape:function(shapes, holes){
  16394. var shape = new THREE.Shape();
  16395. if(shapes[0] && !(shapes[0] instanceof Array) ){//仅是一个shape的点
  16396. shapes = [shapes]
  16397. }
  16398. shapes.forEach((points)=>{
  16399. shape.moveTo( points[0].x, points[0].y );
  16400. for(var i=1,len=points.length; i<len; i++){
  16401. shape.lineTo(points[i].x, points[i].y )
  16402. }
  16403. })
  16404. //多个points的数组绘制在一个shape中,缺点是这些数组之间可能绘制出来会连在一起。
  16405. if(holes){//挖空
  16406. holes.forEach((points)=>{
  16407. var holePath = new THREE.Path()
  16408. holePath.moveTo( points[0].x, points[0].y )
  16409. for(var i=1,len=points.length; i<len; i++){
  16410. holePath.lineTo(points[i].x, points[i].y )
  16411. }
  16412. shape.holes.push( holePath );
  16413. })
  16414. }
  16415. return shape
  16416. }, */
  16417. getShapeGeo: function getShapeGeo(shapes, holes) {
  16418. //获取任意形状(多边形或弧形)的形状面 //quadraticCurveTo() 这是弧形的含函数
  16419. var geometry = new ShapeBufferGeometry(this.getShape(shapes, holes)); //ShapeGeometry
  16420. /* var matrix = new THREE.Matrix4();//将竖直的面变为水平
  16421. matrix.set(//z = y
  16422. 1, 0, 0, 0,
  16423. 0, 0, 0, 0,
  16424. 0, 1, 0, 0,
  16425. 0, 0, 0, 1
  16426. )
  16427. geometry.applyMatrix(matrix) */
  16428. //geometry.computeVertexNormals();//对于光照需要的是点法线
  16429. return geometry;
  16430. },
  16431. getExtrudeGeo: function getExtrudeGeo(shapes, holes) {
  16432. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
  16433. openEnded: false,
  16434. shapeDontClose: false
  16435. };
  16436. //获得挤出棱柱,可以选择传递height,或者extrudePath
  16437. var shape = this.getShape(shapes, holes); //points是横截面 [vector2,...]
  16438. if (options.extrudePath) {
  16439. // 路径 :[vector3,...]
  16440. var length = options.extrudePath.reduce((total, currentValue, currentIndex, arr) => {
  16441. if (currentIndex == 0) return 0;
  16442. return total + currentValue.distanceTo(arr[currentIndex - 1]);
  16443. }, 0);
  16444. //options.extrudePath = new THREE.CatmullRomCurve3(options.extrudePath)
  16445. if (options.extrudePath.length == 2) {
  16446. options.tension = 0; //否则一端扭曲
  16447. options.steps = 1;
  16448. }
  16449. {
  16450. //去掉重复的点
  16451. var path = [];
  16452. var minDis = options.dontSmooth ? 0 : 0.2; //CatmullRomCurve3 经常扭曲,如果两个点靠得很近可能会扭曲,这里去除靠的太近的点。但去除后依旧会出现一定扭曲.
  16453. options.extrudePath.forEach((p, i) => {
  16454. if (i == 0 || i == options.extrudePath.length - 1) return path.push(p); //首尾直接加入
  16455. var last = path[path.length - 1]; //和上一个比
  16456. var dis = last.distanceTo(p);
  16457. if (dis <= minDis) {
  16458. console.log("\u7B2C".concat(i, "\u4E2A\u70B9(").concat(p.toArray(), ")\u56E0\u4E3A\u548C\u4E0A\u4E00\u4E2A\u6570\u636E(").concat(last.toArray(), ")\u592A\u63A5\u8FD1(dis:").concat(dis, ")\u6240\u4EE5\u5220\u9664"));
  16459. } else if (i == options.extrudePath.length - 2) {
  16460. //因为最后一个必定加入,所以倒数第二个还也不能太靠近最后一个
  16461. last = options.extrudePath[options.extrudePath.length - 1]; //和下一个(最后一个比)
  16462. if (dis <= minDis) {
  16463. console.log("\u7B2C".concat(i, "\u4E2A\u70B9(").concat(p.toArray(), ")\u56E0\u4E3A\u548C\u4E0B\u4E00\u4E2A\u6570\u636E(").concat(last.toArray(), ")\u592A\u63A5\u8FD1(dis:").concat(dis, ")\u6240\u4EE5\u5220\u9664"));
  16464. } else {
  16465. path.push(p);
  16466. }
  16467. } else {
  16468. path.push(p);
  16469. }
  16470. });
  16471. options.extrudePath = path;
  16472. }
  16473. if (options.dontSmooth) {
  16474. var curvePath = new CurvePath(); //通用的曲线路径对象,它可以包含直线段和曲线段。在这里只做折线
  16475. for (var i = 0; i < options.extrudePath.length - 1; i++) {
  16476. var curve3 = new LineCurve3(options.extrudePath[i], options.extrudePath[i + 1]); //添加线段
  16477. curvePath.add(curve3);
  16478. }
  16479. options.extrudePath = curvePath;
  16480. } else {
  16481. //平滑连续的曲线(但经常会有扭曲的问题,tension:0能缓解, 另外shape和path都最好在原点附近,也就是点需减去bound.min )
  16482. options.extrudePath = new CatmullRomCurve3(options.extrudePath, options.closed, 'catmullrom' /* 'centripetal' */, options.tension); //tension:拐弯剧烈程度,但随着长度增长,该值需要减小,否则会扭曲
  16483. }
  16484. }
  16485. var extrudeSettings = $.extend(options, {
  16486. steps: options.steps != void 0 ? options.steps : options.extrudePath ? Math.round(length / (options.spaceDis || 0.3)) : 1,
  16487. //分成几段 spaceDis每段长度
  16488. bevelEnabled: false //不加的话,height为0时会有圆弧高度
  16489. //openEnded默认false
  16490. });
  16491. var geometry = new ExtrudeBufferGeometry(shape, extrudeSettings); //修改了three.js文件, buildLidFaces处,创建顶底面加了选项,可以选择开口。
  16492. return geometry;
  16493. },
  16494. getUnPosPlaneGeo: function () {
  16495. //获取还没有赋值位置的plane geometry
  16496. var e = new Uint16Array([0, 1, 2, 0, 2, 3])
  16497. // , t = new Float32Array([-.5, -.5, 0, .5, -.5, 0, .5, .5, 0, -.5, .5, 0])
  16498. ,
  16499. i = new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]),
  16500. g = new BufferGeometry();
  16501. g.setIndex(new BufferAttribute(e, 1)),
  16502. //g.addAttribute("position", new n.BufferAttribute(t, 3)),
  16503. g.setAttribute("uv", new BufferAttribute(i, 2));
  16504. return function () {
  16505. return g;
  16506. };
  16507. }(),
  16508. getPlaneGeo: function getPlaneGeo(A, B, C, D) {
  16509. var geo = this.getUnPosPlaneGeo().clone();
  16510. var pos = [A.x, A.y, A.z, B.x, B.y, B.z, C.x, C.y, C.z, D.x, D.y, D.z];
  16511. //geo.addAttribute("position", new THREE.BufferAttribute(pos, 3))
  16512. geo.setAttribute('position', new Float32BufferAttribute(pos, 3));
  16513. geo.computeVertexNormals();
  16514. geo.computeBoundingSphere(); //for raycaster
  16515. return geo;
  16516. },
  16517. drawPlane: function drawPlane(A, B, C, D, material) {
  16518. var wall = new Mesh(this.getPlaneGeo(A, B, C, D), material);
  16519. return wall;
  16520. },
  16521. movePlane: function movePlane(mesh, A, B, C, D) {
  16522. var pos = new Float32Array([A.x, A.y, A.z, B.x, B.y, B.z, C.x, C.y, C.z, D.x, D.y, D.z]);
  16523. mesh.geometry.addAttribute("position", new BufferAttribute(pos, 3));
  16524. mesh.geometry.computeBoundingSphere(); //for checkIntersect
  16525. },
  16526. createGeometry: function createGeometry(posArr, faceArr, uvArr, normalArr) {
  16527. //创建复杂mesh. faceArr:[[0,1,2],[0,2,3]]
  16528. var geo = new BufferGeometry();
  16529. var positions = [];
  16530. posArr.forEach(p => positions.push(p.x, p.y, p.z));
  16531. geo.setAttribute('position', new Float32BufferAttribute(positions, 3));
  16532. if (faceArr) {
  16533. var indice = [];
  16534. faceArr.forEach(f => indice.push(...f));
  16535. geo.setIndex(indice); // auto set Uint16BufferAttribute or Uint32BufferAttribute
  16536. }
  16537. if (uvArr) {
  16538. var uvs = [];
  16539. uvArr.forEach(uv => uvs.push(uv.x, uv.y));
  16540. geo.setAttribute("uv", new Float32BufferAttribute(uvs, 2));
  16541. }
  16542. if (normalArr) {
  16543. var normals = [];
  16544. normalArr.forEach(n => normals.push(n.x, n.y, n.z));
  16545. geo.setAttribute("normal", new Float32BufferAttribute(normals, 3));
  16546. }
  16547. /*
  16548. geo.computeVertexNormals()
  16549. geo.computeBoundingSphere() //for raycaster
  16550. */
  16551. return geo;
  16552. },
  16553. updateGeometry: function updateGeometry(geo, posArr, faceArr, uvArr, normalArr) {
  16554. //创建复杂mesh. faceArr:[[0,1,2],[0,2,3]]
  16555. var positions = [];
  16556. posArr.forEach(p => positions.push(p.x, p.y, p.z));
  16557. geo.setAttribute('position', new Float32BufferAttribute(positions, 3));
  16558. geo.attributes.position.needsUpdate = true;
  16559. if (faceArr) {
  16560. var indice = [];
  16561. faceArr.forEach(f => indice.push(...f));
  16562. geo.setIndex(indice); // auto set Uint16BufferAttribute or Uint32BufferAttribute
  16563. }
  16564. if (uvArr) {
  16565. var uvs = [];
  16566. uvArr.forEach(uv => uvs.push(uv.x, uv.y));
  16567. geo.setAttribute("uv", new Float32BufferAttribute(uvs, 2));
  16568. }
  16569. if (normalArr) {
  16570. var normals = [];
  16571. normalArr.forEach(n => normals.push(n.x, n.y, n.z));
  16572. geo.setAttribute("normal", new Float32BufferAttribute(normals, 3));
  16573. }
  16574. /*
  16575. geo.computeVertexNormals()
  16576. */
  16577. geo.computeBoundingSphere(); //for raycaster and visi
  16578. return geo;
  16579. }
  16580. };
  16581. class DepthBasicMaterial extends ShaderMaterial {
  16582. constructor() {
  16583. var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  16584. var {
  16585. width,
  16586. height
  16587. } = viewer.renderer.getSize(new Vector2());
  16588. var uniforms = {
  16589. resolution: {
  16590. type: 'v2',
  16591. value: new Vector2(width, height)
  16592. },
  16593. viewportOffset: {
  16594. type: 'v2',
  16595. value: new Vector2(0, 0)
  16596. },
  16597. //left, top
  16598. //uUseOrthographicCamera:{ type: "b", value: false },
  16599. nearPlane: {
  16600. type: 'f',
  16601. value: 0.1
  16602. },
  16603. farPlane: {
  16604. type: 'f',
  16605. value: 10000
  16606. },
  16607. depthTexture: {
  16608. type: 't',
  16609. value: null
  16610. },
  16611. opacity: {
  16612. type: 'f',
  16613. value: 1
  16614. },
  16615. map: {
  16616. type: 't',
  16617. value: o.map
  16618. },
  16619. baseColor: {
  16620. type: 'v3',
  16621. value: o.color ? new Color(o.color) : new Color("#ffffff")
  16622. },
  16623. backColor: {
  16624. type: 'v3',
  16625. value: o.backColor ? new Color(o.backColor) : new Color("#ddd")
  16626. },
  16627. clipDistance: {
  16628. type: 'f',
  16629. value: o.clipDistance || 4
  16630. },
  16631. //消失距离
  16632. occlusionDistance: {
  16633. type: 'f',
  16634. value: o.occlusionDistance || 1
  16635. },
  16636. //变为backColor距离
  16637. maxClipFactor: {
  16638. type: 'f',
  16639. value: o.maxClipFactor || 1
  16640. },
  16641. //0-1
  16642. maxOcclusionFactor: {
  16643. type: 'f',
  16644. value: o.maxOcclusionFactor || 1
  16645. },
  16646. //0-1
  16647. mapScale: {
  16648. type: 'f',
  16649. value: o.mapScale || 1
  16650. } //0-1
  16651. };
  16652. var {
  16653. vs,
  16654. fs
  16655. } = Common.changeShaderToWebgl2(Shaders['depthBasic.vs'], Shaders['depthBasic.fs'], 'ShaderMaterial');
  16656. super({
  16657. uniforms,
  16658. vertexShader: vs,
  16659. fragmentShader: fs,
  16660. depthWrite: false,
  16661. depthTest: false,
  16662. transparent: o.transparent == void 0 ? true : o.transparent,
  16663. side: o.side || 0 /* THREE.DoubleSide */
  16664. });
  16665. this.events = {
  16666. setSize: e => {
  16667. //如果出现横条状的异常,往往是viewportOffset出错 //地图不需要
  16668. if (!this.realUseDepth || !e.viewport) return;
  16669. var viewport = e.viewport;
  16670. var viewportOffset = viewport.offset || new Vector2();
  16671. this.uniforms.resolution.value.copy(viewport.resolution2); //2023.6.12突然发现ratio>1的用resolution不对,得用2才对。但是之前明明记得不是这样
  16672. this.uniforms.viewportOffset.value.copy(viewportOffset);
  16673. },
  16674. render: e => {
  16675. //before render 如果有大于两个viewport的话,不同viewport用不同的depthTex
  16676. this.updateDepthParams(e);
  16677. }
  16678. /* cameraChange:(e)=>{
  16679. if(e.changeInfo.projectionChanged){//resize时也会触发。虽然保守起见的话加上resize比较好//所以当时为何不用resize
  16680. //console.log('projectionChanged')
  16681. this.events.setSize(e)
  16682. }
  16683. } */
  16684. };
  16685. //-----其他----
  16686. this.autoDepthTest = o.autoDepthTest;
  16687. if (o.opacity != void 0) {
  16688. this.opacity = o.opacity;
  16689. }
  16690. this.useDepth = o.useDepth;
  16691. this.map = o.map;
  16692. }
  16693. get useDepth() {
  16694. return this.useDepth_;
  16695. }
  16696. set useDepth(value) {
  16697. value = value && Features.EXT_DEPTH.isSupported(); //如果不支持 EXT_DEPTH 的话会失效
  16698. if (this.useDepth_ != value) {
  16699. this.setRealDepth(value);
  16700. this.useDepth_ = value;
  16701. if (value) {
  16702. viewer.addEventListener("render.begin", this.events.render);
  16703. //viewer.addEventListener('camera_changed', this.events.cameraChange)
  16704. viewer.addEventListener('resize', this.events.setSize);
  16705. this.updateDepthParams();
  16706. } else {
  16707. viewer.removeEventListener("render.begin", this.events.render);
  16708. viewer.removeEventListener('resize', this.events.setSize);
  16709. }
  16710. }
  16711. }
  16712. setRealDepth(useDepth, viewport) {
  16713. //确实使用到depthTex
  16714. if (this.realUseDepth != useDepth) {
  16715. if (useDepth) {
  16716. this.defines.useDepth = '';
  16717. } else {
  16718. delete this.defines.useDepth;
  16719. }
  16720. this.realUseDepth = useDepth;
  16721. if (this.autoDepthTest) this.depthWrite = this.depthTest = !useDepth; //如果useDepth = false,使用原始的depthTest
  16722. this.needsUpdate = true;
  16723. if (!viewport) viewport = viewer.mainViewport; //暂时这么设置
  16724. useDepth && this.events.setSize({
  16725. viewport
  16726. });
  16727. }
  16728. }
  16729. get map() {
  16730. return this.uniforms.map.value;
  16731. }
  16732. set map(map) {
  16733. this.uniforms.map.value = map;
  16734. if (map) {
  16735. this.defines.use_map = '';
  16736. } else {
  16737. delete this.defines.use_map;
  16738. }
  16739. }
  16740. get opacity() {
  16741. return this.uniforms.opacity.value;
  16742. }
  16743. set opacity(o) {
  16744. this.uniforms && (this.uniforms.opacity.value = o);
  16745. }
  16746. get color() {
  16747. return this.uniforms.baseColor.value;
  16748. }
  16749. set color(c) {
  16750. this.uniforms && this.uniforms.baseColor.value.set(c);
  16751. }
  16752. /* dispose(){
  16753. super.dispose()
  16754. viewer.depthBasic
  16755. } */
  16756. copy(source) {
  16757. super.copy(source);
  16758. this.useDepth = source.useDepth;
  16759. this.map = source.map;
  16760. return this;
  16761. }
  16762. updateDepthParams() {
  16763. var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  16764. //主要用于点云遮住mesh
  16765. var viewport = e.viewport || viewer.mainViewport;
  16766. var camera = viewport.camera;
  16767. var hasDepth = this.useDepth && camera.isPerspectiveCamera && (Potree.settings.pointEnableRT || Potree.settings.displayMode == 'showPanos' || viewer.useEDL);
  16768. this.setRealDepth(hasDepth, viewport);
  16769. if (hasDepth) {
  16770. this.uniforms.depthTexture.value = viewer.getPRenderer().getRtEDL(viewport).depthTexture; //其实只赋值一次就行
  16771. this.uniforms.nearPlane.value = camera.near;
  16772. this.uniforms.farPlane.value = camera.far;
  16773. }
  16774. //this.uniforms.uUseOrthographicCamera.value = !camera.isPerspectiveCamera
  16775. }
  16776. }
  16777. var geo = new PlaneBufferGeometry(1, 1);
  16778. class Sprite$2 extends Mesh {
  16779. constructor() {
  16780. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  16781. super(geo, options.mat || new DepthBasicMaterial(options)); /* ({map:options.map, useDepth:options.useDepth})) */
  16782. this.root = options.root || this;
  16783. this.renderOrder = options.renderOrder != void 0 ? options.renderOrder : 4;
  16784. this.pickOrder = options.pickOrder || 0;
  16785. this.sizeInfo = options.sizeInfo;
  16786. this.dontFixOrient = options.dontFixOrient;
  16787. this.options = options;
  16788. this.position.y = options.disToLine || 0; //离线距离
  16789. this.matrixAutoUpdate = false;
  16790. this.matrixMap = new Map();
  16791. if (this.root != this) {
  16792. this.matrixMapRoot = new Map();
  16793. this.root.matrixAutoUpdate = false;
  16794. }
  16795. this.visiMap = new Map();
  16796. this.name = options.name || 'sprite';
  16797. this.useViewport = null;
  16798. this.viewports = options.viewports; //指定更新的viewports
  16799. this.visible_ = true;
  16800. var clear = e => {
  16801. this.matrixMap.clear(); //清空后在所有viewport上都必须更新才能渲染 //this.needsUpdate = true
  16802. };
  16803. viewer.mapViewer && viewer.mapViewer.addEventListener("camera_changed", clear);
  16804. viewer.addEventListener("camera_changed", clear);
  16805. /* if(viewer.viewports.length == 1){//直接更新。如果有多个不在这更新,在"render.begin"
  16806. this.update(e)
  16807. } */
  16808. var applyMatrix = e => {
  16809. this.applyMatrix(e);
  16810. };
  16811. viewer.addEventListener("raycaster", applyMatrix); //before render
  16812. viewer.addEventListener("render.begin", applyMatrix); //before render
  16813. viewer.addEventListener("render.begin2", applyMatrix);
  16814. viewer.addEventListener("cameraSetLayers", applyMatrix);
  16815. this.addEventListener('dispose', () => {
  16816. viewer.mapViewer && viewer.mapViewer.removeEventListener("camera_changed", clear);
  16817. viewer.removeEventListener("camera_changed", clear);
  16818. viewer.removeEventListener("raycaster", applyMatrix); //before render
  16819. viewer.removeEventListener("render.begin", applyMatrix);
  16820. viewer.removeEventListener("render.begin2", applyMatrix);
  16821. });
  16822. }
  16823. set visible(v) {
  16824. var oldV = this.visible_;
  16825. this.visible_ = v;
  16826. if (v && !oldV) {
  16827. this.matrixMap && this.matrixMap.clear(); //this.update() //update内有unableCompute会无限回调
  16828. }
  16829. }
  16830. get visible() {
  16831. return this.visible_;
  16832. }
  16833. realVisible(viewport, interactables /* , raycaster */) {
  16834. if (interactables) {
  16835. if (!interactables.some(object => {
  16836. //interactables中是否能找到this
  16837. var finded;
  16838. object.traverse(object => {
  16839. if (object == this) {
  16840. finded = true;
  16841. return {
  16842. stopContinue: true
  16843. };
  16844. }
  16845. });
  16846. return finded;
  16847. })) return;
  16848. }
  16849. /* if(interactables && viewport.name == 'mapViewport'){
  16850. console.log(this)
  16851. } */
  16852. if (!( /* raycaster || */viewport.camera).layers.test(this.layers)) {
  16853. //如地图上一般不可见测量线
  16854. return false;
  16855. }
  16856. if (!this.visible && this.unvisibleReasons && this.unvisibleReasons.some(e => e.reason != 'unableCompute')) {
  16857. return false;
  16858. }
  16859. var v = true;
  16860. var parent = this.parent;
  16861. var lastParent = this;
  16862. while (parent) {
  16863. if (parent.visible === false) {
  16864. v = false;
  16865. break;
  16866. }
  16867. lastParent = parent;
  16868. parent = parent.parent;
  16869. }
  16870. if (v && !(lastParent instanceof Scene)) {
  16871. //已被删除
  16872. v = false;
  16873. }
  16874. /* if(!this.latestRealVisi && v){//变为可见后先update
  16875. this.latestRealVisi = true
  16876. setTimeout(()=>{
  16877. this.update()
  16878. },1)//延迟 防止无限调用
  16879. return false
  16880. }
  16881. this.latestRealVisi = v */
  16882. return v;
  16883. }
  16884. waitUpdate() {
  16885. this.matrixMap.clear(); //清空后在所有viewport上都必须更新才能渲染
  16886. //viewer.dispatchEvent('content_changed')
  16887. }
  16888. update() {
  16889. var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  16890. if (!e.viewport) {
  16891. var viewports = this.viewports || viewer.viewports;
  16892. if (!viewports) return;
  16893. viewports.forEach(view => {
  16894. this.update({
  16895. viewport: view
  16896. });
  16897. });
  16898. return;
  16899. }
  16900. if (!this.root || !this.realVisible(e.viewport, e.interactables) /* this.visible */) return;
  16901. if (this.viewports && !this.viewports.includes(e.viewport)) return;
  16902. if (e.viewport.name == 'magnifier') return;
  16903. var camera = e.viewport.camera;
  16904. //rotation
  16905. if (!this.dontFixOrient) {
  16906. //orthoCamera一般要加dontFixOrient
  16907. var orient2dAngle;
  16908. if (this.root.lineDir) {
  16909. this.root.updateMatrix(); //先更新,getWorldPosition才能得到正确的
  16910. this.root.updateMatrixWorld(true);
  16911. var center = this.root.getWorldPosition(new Vector3());
  16912. //由于两个端点容易在屏幕外,所以使用center和center加dir
  16913. var setVisi = state => {
  16914. this.visiMap.set(e.viewport, state);
  16915. Potree.Utils.updateVisible(this, 'unableCompute', !!state);
  16916. };
  16917. var renderer = e.viewer ? e.viewer.renderer : e.renderer;
  16918. var r1 = Potree.Utils.getPos2d(center, e.viewport, renderer.domElement.parentElement, renderer);
  16919. //let r1 = Potree.Utils.getPos2d(center, e.viewport, viewer.renderArea, viewer.renderer);
  16920. if (!r1.trueSide) return setVisi(false); // 但这句会使realVisible为false从而无法更新//console.error('!r1.trueSide') //中心点如果在背面直接不渲染了
  16921. var r2, point2;
  16922. var p2State = '',
  16923. len = 1,
  16924. p2StateHistory = [];
  16925. while (p2State != 'got' && p2StateHistory.length < 10) {
  16926. point2 = center.clone().add(this.root.lineDir.clone().multiplyScalar(len));
  16927. r2 = Potree.Utils.getPos2d(point2, e.viewport, renderer.domElement.parentElement, renderer);
  16928. if (!r2.trueSide) {
  16929. //很少遇到点2在背面的
  16930. if (!p2StateHistory.includes('tooLong-reverse')) {
  16931. p2State = 'tooLong-reverse'; //先尝试反向
  16932. len = -len;
  16933. } else {
  16934. p2State = 'tooLong';
  16935. len = len / 2;
  16936. }
  16937. } else {
  16938. var _dis = r2.pos.distanceTo(r1.pos);
  16939. if (math.closeTo(_dis, 0)) {
  16940. //console.log('dis == 0')
  16941. setVisi(false);
  16942. return;
  16943. break;
  16944. }
  16945. if (_dis < 10 && !p2StateHistory.includes('tooLong')) {
  16946. //和r1的屏幕距离太近,要加长,否则精度过低
  16947. p2State = 'tooShort';
  16948. len = 100 / _dis * len;
  16949. } else {
  16950. p2State = 'got';
  16951. break;
  16952. }
  16953. }
  16954. p2StateHistory.push(p2State);
  16955. }
  16956. //console.log(p2StateHistory,len)
  16957. if (!r2.trueSide) {
  16958. return setVisi(false); //, console.log(' !r2.trueSide', )
  16959. }
  16960. var p1 = r1.pos,
  16961. p2 = r2.pos;
  16962. if (p2StateHistory.filter(e => e == 'tooLong-reverse').length % 2 == 1) {
  16963. //反,for marker
  16964. p2 = r1.pos, p1 = r2.pos;
  16965. }
  16966. var vec = new Vector2().subVectors(p1, p2);
  16967. orient2dAngle = -vec.angle(); //根据测量线在屏幕上的角度在旋转label,使之和屏幕上的二维线平行。
  16968. var y = Math.abs(this.position.y);
  16969. var facePlane = this.root.measure && this.root.measure.facePlane;
  16970. var eyeDir = new Vector3().subVectors(center, camera.position);
  16971. var clockWise = facePlane && facePlane.normal.dot(eyeDir /* e.viewport.view.direction */) < 0;
  16972. if (p1.x < p2.x) {
  16973. orient2dAngle += Math.PI; //避免字是倒着的情况。(使字一直在线的下方)
  16974. clockWise != void 0 && (this.position.y = clockWise ? y : -y);
  16975. } else {
  16976. clockWise != void 0 && (this.position.y = clockWise ? -y : y); //使area类型的edgeLabel都在外侧
  16977. }
  16978. //this.parent.text && console.log(this.parent.text, clockWise, this.position.y, e.viewport.name /* THREE.Math.radToDeg(angle), p1.x < p2.x */ )
  16979. setVisi(true);
  16980. }
  16981. var parentQua = this.root.parent.getWorldQuaternion(new Quaternion());
  16982. this.root.quaternion.multiplyQuaternions(parentQua.invert(), camera.quaternion); //乘上parentQua.invert()是为了中和掉父结点的qua,使只剩下camera.quaternion
  16983. if (orient2dAngle) {
  16984. var qua = new Quaternion().setFromAxisAngle(new Vector3(0, 0, 1), orient2dAngle);
  16985. this.root.quaternion.multiply(qua);
  16986. }
  16987. }
  16988. //scale
  16989. var info = this.sizeInfo;
  16990. if (info) {
  16991. this.root.updateMatrix(); //先更新,getWorldPosition才能得到正确的
  16992. this.root.updateMatrixWorld(true);
  16993. var scale;
  16994. if (info.nearBound == void 0 && info.farBound != void 0 || info.nearBound != void 0 && info.farBound == void 0) {
  16995. //仅限制最大或最小的话,不判断像素大小,直接限制mesh的scale
  16996. //这个判断也可以写到getScaleForConstantSize里,可以更严谨控制像素宽度,这里只简单计算大小
  16997. var dis = camera.position.distanceTo(this.root.getWorldPosition(new Vector3()));
  16998. if (info.farBound == void 0 && dis < info.nearBound) {
  16999. scale = info.scale * dis / info.nearBound;
  17000. } else if (info.nearBound == void 0 && dis > info.farBound) {
  17001. scale = info.scale * dis / info.farBound;
  17002. } else {
  17003. scale = info.scale;
  17004. }
  17005. } else {
  17006. scale = math.getScaleForConstantSize($.extend(info, {
  17007. //规定下最小最大像素
  17008. camera,
  17009. position: this.root.getWorldPosition(new Vector3()),
  17010. resolution: e.viewport.resolution //2
  17011. }));
  17012. }
  17013. if (!isNaN(scale)) {
  17014. this.root.scale.set(scale, scale, scale);
  17015. }
  17016. }
  17017. this.updateMatrix();
  17018. //this.root.updateMatrixWorld(true)
  17019. //console.log(this.root.text, this.root.matrix.elements)
  17020. this.matrixMap.set(e.viewport, this.matrix.clone());
  17021. if (this.root != this) {
  17022. this.root.updateMatrix(); //因this.position可能在两个viewport不同
  17023. this.matrixMapRoot.set(e.viewport, this.root.matrix.clone());
  17024. }
  17025. this.needsUpdate = false;
  17026. this.useViewport = e.viewport;
  17027. }
  17028. applyMatrix(e) {
  17029. if (!e) e = {
  17030. viewport: viewer.mainViewport
  17031. }; //随便写一个viewport
  17032. var visi = this.visiMap.get(e.viewport); //还原可见性
  17033. Potree.Utils.updateVisible(this, 'unableCompute', visi == false ? false : true);
  17034. /* if(e.viewport.name == 'mapViewport' && visi && this.visiMap.get(viewer.mainViewport) == false){
  17035. console.log(1)
  17036. } */
  17037. if (e.viewport.name == 'magnifier') return;
  17038. if (this.viewports && !this.viewports.includes(e.viewport)) return;
  17039. if (!this.root || !this.realVisible(e.viewport, e.interactables)) return;
  17040. var matrix = this.matrixMap.get(e.viewport);
  17041. if (!matrix) {
  17042. this.update(e);
  17043. matrix = this.matrixMap.get(e.viewport);
  17044. if (!matrix) return;
  17045. }
  17046. if (e.viewport == this.useViewport) {
  17047. return;
  17048. }
  17049. this.useViewport = e.viewport;
  17050. this.matrix.copy(matrix);
  17051. if (this.root != this) {
  17052. var matrix2 = this.matrixMapRoot.get(e.viewport);
  17053. this.root.matrix.copy(matrix2);
  17054. }
  17055. e.raycaster && this.root.updateMatrixWorld(true); //渲染前会自动updateMatrixWorld,但raycaster不会
  17056. //console.log(this.root.name + e.viewport.name + " : "+this.root.matrixWorld.elements)
  17057. }
  17058. setUniforms(name, value) {
  17059. this.material.setUniforms(name, value);
  17060. }
  17061. dispose() {
  17062. this.removeAllListeners();
  17063. this.parent && this.parent.remove(this);
  17064. this.dispatchEvent('dispose');
  17065. }
  17066. }
  17067. /*
  17068. let orient2d
  17069. if(this.lineDir){
  17070. this.root.updateMatrix();//先更新,getWorldPosition才能得到正确的
  17071. this.root.updateMatrixWorld(true)
  17072. let center = this.root.getWorldPosition(new THREE.Vector3())
  17073. //由于两个端点容易在屏幕外,所以使用center和center加dir
  17074. let lineDir = this.lineDir.clone();
  17075. let r1 = Potree.Utils.getPos2d(center, camera, viewer.renderArea, e.viewport);
  17076. if(!r1.trueSide)return Potree.Utils.updateVisible(this, 'unableCompute', false);// 但这句会使realVisible为false从而无法更新//console.error('!r1.trueSide') //中心点如果在背面直接不渲染了
  17077. let r2, point2
  17078. let p2State = '', len=1, p2StateHistory = []
  17079. while(p2State != 'got' && p2StateHistory.length<10){
  17080. point2 = center.clone().add(lineDir.multiplyScalar(len));
  17081. r2 = Potree.Utils.getPos2d(point2, camera, viewer.renderArea, e.viewport);
  17082. if(!r2.trueSide){ //很少遇到点2在背面的
  17083. if(!p2StateHistory.includes('tooLong-reverse')){
  17084. p2State = 'tooLong-reverse' //先尝试反向
  17085. len = -len
  17086. }else{
  17087. p2State = 'tooLong'
  17088. len = len / 2
  17089. }
  17090. }else{
  17091. let dis = r2.pos.distanceTo(r1.pos)
  17092. if(dis == 0){
  17093. //console.log('dis == 0')
  17094. Potree.Utils.updateVisible(this, 'unableCompute', false)
  17095. return
  17096. break
  17097. }
  17098. if(dis<10 && !p2StateHistory.includes('tooLong')){//和r1的屏幕距离太近,要加长,否则精度过低
  17099. p2State = 'tooShort'
  17100. len = 100/dis * len
  17101. }else{
  17102. p2State = 'got'; break;
  17103. }
  17104. }
  17105. p2StateHistory.push(p2State)
  17106. }
  17107. //console.log(p2StateHistory,len)
  17108. if(!r2.trueSide){
  17109. return Potree.Utils.updateVisible(this, 'unableCompute', false)//, console.log(' !r2.trueSide', )
  17110. }
  17111. Potree.Utils.updateVisible(this, 'unableCompute', true)
  17112. let p1 = r1.pos, p2 = r2.pos
  17113. let vec = new THREE.Vector2().subVectors(p1,p2);
  17114. let angle = -vec.angle() //根据测量线在屏幕上的角度在旋转label,使之和屏幕上的二维线平行。
  17115. if(p1.x < p2.x) angle += Math.PI //避免字是倒着的情况
  17116. orient2d = new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0,0,1), angle)
  17117. //console.log(this.parent.text, THREE.Math.radToDeg(angle), p1.x < p2.x )
  17118. }
  17119. let parentQua = this.root.parent.getWorldQuaternion(new THREE.Quaternion)
  17120. this.root.quaternion.multiplyQuaternions(parentQua.invert(),camera.quaternion) //乘上parentQua.invert()是为了中和掉父结点的qua,使只剩下camera.quaternion
  17121. if(this.lineDir){
  17122. this.root.quaternion.multiply(orient2d)
  17123. }
  17124. */
  17125. // /**
  17126. //可能还是要用html写,因为要加按钮和图片
  17127. class TextSprite$2 extends Object3D {
  17128. //注:为了分两层控制scale,不直接extend Sprite
  17129. constructor() {
  17130. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  17131. super();
  17132. var map = new Texture();
  17133. map.minFilter = LinearFilter;
  17134. map.magFilter = LinearFilter;
  17135. this.sprite = new Sprite$2(Object.assign({
  17136. root: this
  17137. }, options, {
  17138. map
  17139. }));
  17140. this.add(this.sprite);
  17141. this.fontWeight = options.fontWeight == void 0 ? 'Bold' : options.fontWeight;
  17142. this.rectBorderThick = options.rectBorderThick || 0;
  17143. this.textBorderThick = options.textBorderThick || 0;
  17144. this.fontface = 'Arial';
  17145. this.fontsize = options.fontsize || 16;
  17146. this.textBorderColor = options.textBorderColor ? Common.CloneObject(options.textBorderColor) : {
  17147. r: 0,
  17148. g: 0,
  17149. b: 0,
  17150. a: 0.0
  17151. };
  17152. this.backgroundColor = options.backgroundColor ? Common.CloneObject(options.backgroundColor) : {
  17153. r: 255,
  17154. g: 255,
  17155. b: 255,
  17156. a: 1.0
  17157. };
  17158. this.textColor = options.textColor ? Common.CloneObject(options.textColor) : {
  17159. r: 0,
  17160. g: 0,
  17161. b: 0,
  17162. a: 1.0
  17163. };
  17164. this.borderColor = options.borderColor ? Common.CloneObject(options.borderColor) : {
  17165. r: 0,
  17166. g: 0,
  17167. b: 0,
  17168. a: 0.0
  17169. };
  17170. this.borderRadius = options.borderRadius || 6;
  17171. this.margin = options.margin;
  17172. this.setText(options.text);
  17173. this.name = options.name;
  17174. //this.setText(text);
  17175. }
  17176. setText(text) {
  17177. if (text == void 0) text = '';
  17178. if (this.text !== text) {
  17179. if (!(text instanceof Array)) {
  17180. this.text = [text + ''];
  17181. } else this.text = text;
  17182. this.updateTexture();
  17183. this.sprite.waitUpdate(); //重新计算各个viewport的matrix
  17184. }
  17185. }
  17186. setTextColor(color) {
  17187. this.textColor = Common.CloneObject(color);
  17188. this.updateTexture();
  17189. }
  17190. setBorderColor(color) {
  17191. this.borderColor = Common.CloneObject(color);
  17192. this.updateTexture();
  17193. }
  17194. setBackgroundColor(color) {
  17195. this.backgroundColor = Common.CloneObject(color);
  17196. this.updateTexture();
  17197. }
  17198. setPos(pos) {
  17199. this.position.copy(pos);
  17200. this.sprite.waitUpdate();
  17201. }
  17202. update() {
  17203. this.sprite.waitUpdate();
  17204. }
  17205. /* setVisible(v){
  17206. Potree.Utils.updateVisible(this, 'setVisible', v)
  17207. } */
  17208. setUniforms(name, value) {
  17209. this.sprite.setUniforms(name, value);
  17210. }
  17211. updateTexture1() {
  17212. var canvas = document.createElement('canvas');
  17213. var context = canvas.getContext('2d');
  17214. var r = window.devicePixelRatio;
  17215. context.font = this.fontWeight + ' ' + this.fontsize * r + 'px ' + this.fontface;
  17216. //context["font-weight"] = 100; //语法与 CSS font 属性相同。
  17217. //this.text = '啊啊啊啊啊啊fag'
  17218. var metrics = context.measureText(this.text);
  17219. var textWidth = metrics.width;
  17220. var margin = (this.margin ? new Vector2().copy(this.margin) : new Vector2(this.fontsize, Math.max(this.fontsize * 0.4, 10))).clone().multiplyScalar(r);
  17221. var spriteWidth = 2 * margin.x + textWidth + 2 * this.rectBorderThick * r;
  17222. var spriteHeight = 2 * margin.y + this.fontsize * r + 2 * this.rectBorderThick * r;
  17223. context.canvas.width = spriteWidth;
  17224. context.canvas.height = spriteHeight;
  17225. context.font = this.fontWeight + ' ' + this.fontsize * r + 'px ' + this.fontface;
  17226. /* let diff = 2//针对英文大部分在baseLine之上所以降低一点(metrics.fontBoundingBoxAscent - metrics.fontBoundingBoxDescent) / 2
  17227. context.textBaseline = "middle"
  17228. */
  17229. var expand = Math.max(1, Math.pow(this.fontsize / 16, 1.3)) * r; // 针对英文大部分在baseLine之上所以降低一点,或者可以识别当不包含jgqp时才加这个值
  17230. //canvas原点在左上角
  17231. context.textBaseline = 'alphabetic'; // "middle" //设置文字基线。当起点y设置为0时,只有该线以下的部分被绘制出来。middle时文字显示一半(但是对该字体所有字的一半,有的字是不一定显示一半的,尤其汉字),alphabetic时是英文字母的那条基线。
  17232. //let actualHeight = metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent; // 当前文本字符串在这个字体下用的实际高度
  17233. //文字y向距离从textBaseline向上算
  17234. var actualBoundingBoxAscent = metrics.actualBoundingBoxAscent == void 0 ? this.fontsize * r * 0.8 : metrics.actualBoundingBoxAscent; //有的流览器没有。只能大概给一个
  17235. var y = actualBoundingBoxAscent + margin.y + expand;
  17236. //console.log(this.text, 'y' , y, 'actualBoundingBoxAscent', metrics.actualBoundingBoxAscent,'expand',expand )
  17237. // border color
  17238. context.strokeStyle = 'rgba(' + this.borderColor.r + ',' + this.borderColor.g + ',' + this.borderColor.b + ',' + this.borderColor.a + ')';
  17239. var rectBorderThick = this.rectBorderThick * r;
  17240. context.lineWidth = rectBorderThick;
  17241. // background color
  17242. context.fillStyle = 'rgba(' + this.backgroundColor.r + ',' + this.backgroundColor.g + ',' + this.backgroundColor.b + ',' + this.backgroundColor.a + ')';
  17243. this.roundRect(context, rectBorderThick / 2, rectBorderThick / 2, spriteWidth - rectBorderThick, spriteHeight - rectBorderThick, this.borderRadius * r);
  17244. // text color
  17245. if (this.textBorderThick) {
  17246. context.strokeStyle = 'rgba(' + this.textBorderColor.r + ',' + this.textBorderColor.g + ',' + this.textBorderColor.b + ',' + this.textBorderColor.a + ')';
  17247. context.lineWidth = this.textBorderThick * r;
  17248. context.strokeText(this.text, rectBorderThick + margin.x, y /* spriteHeight/2 + diff */);
  17249. }
  17250. context.fillStyle = 'rgba(' + this.textColor.r + ',' + this.textColor.g + ',' + this.textColor.b + ',' + this.textColor.a + ')';
  17251. context.fillText(this.text, rectBorderThick + margin.x, y /* spriteHeight/2 + diff */); //x,y
  17252. var texture = new Texture(canvas);
  17253. texture.minFilter = LinearFilter;
  17254. texture.magFilter = LinearFilter;
  17255. texture.needsUpdate = true;
  17256. //this.material.needsUpdate = true;
  17257. if (this.sprite.material.map) {
  17258. this.sprite.material.map.dispose();
  17259. }
  17260. this.sprite.material.map = texture;
  17261. this.sprite.scale.set(spriteWidth * 0.01 / r, spriteHeight * 0.01 / r, 1.0);
  17262. }
  17263. updateTexture() {
  17264. var canvas = document.createElement('canvas');
  17265. var context = canvas.getContext('2d');
  17266. var r = window.devicePixelRatio;
  17267. context.font = this.fontWeight + ' ' + this.fontsize * r + 'px ' + this.fontface;
  17268. //context["font-weight"] = 100; //语法与 CSS font 属性相同。
  17269. //this.text = '啊啊啊啊啊啊fag'
  17270. var textMaxWidth = 0,
  17271. infos = [];
  17272. for (var text of this.text) {
  17273. var metrics = context.measureText(text);
  17274. var textWidth = metrics.width;
  17275. infos.push(metrics);
  17276. textMaxWidth = Math.max(textMaxWidth, textWidth);
  17277. }
  17278. var margin = (this.margin ? new Vector2().copy(this.margin) : new Vector2(this.fontsize, Math.max(this.fontsize * 0.4, 10))).clone().multiplyScalar(r);
  17279. var lineSpace = (this.fontsize + margin.y) * 0.5;
  17280. var spriteWidth = 2 * margin.x + textMaxWidth + 2 * (this.rectBorderThick + this.textBorderThick) * r; //还要考虑this.textshadowColor,太麻烦了不写了
  17281. var spriteHeight = 2 * margin.y + (this.fontsize + this.textBorderThick * 2) * r * this.text.length + 2 * this.rectBorderThick * r + lineSpace * (this.text.length - 1);
  17282. context.canvas.width = spriteWidth;
  17283. context.canvas.height = spriteHeight;
  17284. context.font = this.fontWeight + ' ' + this.fontsize * r + 'px ' + this.fontface;
  17285. if (spriteWidth > 4000) {
  17286. console.error('spriteWidth', spriteWidth, 'spriteHeight', spriteHeight, this.fontsize, r, this.text, margin);
  17287. }
  17288. /* let diff = 2//针对英文大部分在baseLine之上所以降低一点(metrics.fontBoundingBoxAscent - metrics.fontBoundingBoxDescent) / 2
  17289. context.textBaseline = "middle"
  17290. */
  17291. var expand = Math.max(1, Math.pow(this.fontsize / 16, 1.3)) * r; // 针对英文大部分在baseLine之上所以降低一点,或者可以识别当不包含jgqp时才加这个值
  17292. //canvas原点在左上角
  17293. context.textBaseline = 'alphabetic'; // "middle" //设置文字基线。当起点y设置为0时,只有该线以下的部分被绘制出来。middle时文字显示一半(但是对该字体所有字的一半,有的字是不一定显示一半的,尤其汉字),alphabetic时是英文字母的那条基线。
  17294. // border color
  17295. context.strokeStyle = 'rgba(' + this.borderColor.r + ',' + this.borderColor.g + ',' + this.borderColor.b + ',' + this.borderColor.a + ')';
  17296. var rectBorderThick = this.rectBorderThick * r;
  17297. context.lineWidth = rectBorderThick;
  17298. // background color
  17299. context.fillStyle = 'rgba(' + this.backgroundColor.r + ',' + this.backgroundColor.g + ',' + this.backgroundColor.b + ',' + this.backgroundColor.a + ')';
  17300. this.roundRect(context, rectBorderThick / 2, rectBorderThick / 2, spriteWidth - rectBorderThick, spriteHeight - rectBorderThick, this.borderRadius * r);
  17301. context.fillStyle = 'rgba(' + this.textColor.r + ',' + this.textColor.g + ',' + this.textColor.b + ',' + this.textColor.a + ')';
  17302. var y = margin.y;
  17303. for (var i = 0; i < this.text.length; i++) {
  17304. //let actualHeight = metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent // 当前文本字符串在这个字体下用的实际高度
  17305. //文字y向距离从textBaseline向上算
  17306. var actualBoundingBoxAscent = infos[i].actualBoundingBoxAscent == void 0 ? this.fontsize * r * 0.8 : infos[i].actualBoundingBoxAscent; //有的流览器没有。只能大概给一个
  17307. y += actualBoundingBoxAscent + expand + this.textBorderThick;
  17308. //console.log(actualBoundingBoxAscent)
  17309. //console.log(this.text, 'y' , y, 'actualBoundingBoxAscent', metrics.actualBoundingBoxAscent,'expand',expand )
  17310. var textLeftSpace = (textMaxWidth - infos[i].width) / 2;
  17311. var x = this.rectBorderThick + margin.x + textLeftSpace;
  17312. // text color
  17313. if (this.textBorderThick) {
  17314. context.strokeStyle = 'rgba(' + this.textBorderColor.r + ',' + this.textBorderColor.g + ',' + this.textBorderColor.b + ',' + this.textBorderColor.a + ')';
  17315. context.lineWidth = this.textBorderThick * r;
  17316. context.strokeText(this.text[i], x, y);
  17317. }
  17318. if (this.textshadowColor) {
  17319. context.shadowOffsetX = 0;
  17320. context.shadowOffsetY = 0;
  17321. context.shadowColor = this.textshadowColor;
  17322. context.shadowBlur = 12 * r;
  17323. }
  17324. context.fillText(this.text[i], x, y);
  17325. y += lineSpace;
  17326. }
  17327. var texture = new Texture(canvas);
  17328. texture.minFilter = LinearFilter;
  17329. texture.magFilter = LinearFilter;
  17330. texture.needsUpdate = true;
  17331. //this.material.needsUpdate = true;
  17332. if (this.sprite.material.map) {
  17333. this.sprite.material.map.dispose();
  17334. }
  17335. this.sprite.material.map = texture;
  17336. this.sprite.scale.set(spriteWidth * 0.01 / r, spriteHeight * 0.01 / r, 1.0);
  17337. }
  17338. roundRect(ctx, x, y, w, h, r) {
  17339. ctx.beginPath();
  17340. ctx.moveTo(x + r, y);
  17341. ctx.lineTo(x + w - r, y);
  17342. ctx.arcTo(x + w, y, x + w, y + r, r); //圆弧。前四个参数同quadraticCurveTo
  17343. //ctx.quadraticCurveTo(x + w, y, x + w, y + r); //二次贝塞尔曲线需要两个点。第一个点是用于二次贝塞尔计算中的控制点,第二个点是曲线的结束点。
  17344. ctx.lineTo(x + w, y + h - r);
  17345. ctx.arcTo(x + w, y + h, x + w - r, y + h, r);
  17346. ctx.lineTo(x + r, y + h);
  17347. ctx.arcTo(x, y + h, x, y + h - r, r);
  17348. ctx.lineTo(x, y + r);
  17349. ctx.arcTo(x, y, x + r, y, r);
  17350. ctx.closePath();
  17351. ctx.fill();
  17352. ctx.stroke();
  17353. }
  17354. dispose() {
  17355. this.sprite.material.uniforms.map.value.dispose();
  17356. this.parent && this.parent.remove(this);
  17357. this.sprite.dispose();
  17358. this.removeAllListeners();
  17359. this.dispatchEvent('dispose');
  17360. }
  17361. }
  17362. /*
  17363. z
  17364. |
  17365. |
  17366. |
  17367. |
  17368. x <-------| 中心为点云position加boudingbox中心
  17369. /
  17370. /
  17371. y
  17372. */
  17373. var lineLen$1 = 2,
  17374. stemLen = 4,
  17375. arrowLen = 2,
  17376. lineDisToStem = 5;
  17377. var opacity = 0.5;
  17378. class Axis extends Object3D {
  17379. // 坐标轴
  17380. constructor() {
  17381. super();
  17382. this.getArrow();
  17383. this.createArrows();
  17384. //this.position.copy(position) 点云的中心点就是在(0,0,0)
  17385. //this.scale.set(2,2,2)
  17386. /* viewer.addEventListener('camera_changed', e => {
  17387. if(e.viewport.name != 'MainView')return //只调整mainView,否则需要每次渲染前调整。缺点:地图上的大小变来变去
  17388. let s = Potree.math.getScaleForConstantSize( {//规定下最小最大像素
  17389. width2d:50, camera:e.camera , position:this.position,
  17390. resolution: e.viewport.resolution//2
  17391. })
  17392. this.scale.set(s,s,s)
  17393. }) */
  17394. }
  17395. getArrow() {
  17396. var arrowGroup = new Object3D();
  17397. var line = LineDraw.createLine([new Vector3(), new Vector3(0, 0, lineLen$1)]);
  17398. var stem = new Mesh(new BoxGeometry(0.3, 0.3, stemLen));
  17399. stem.position.set(0, 0, lineLen$1 + lineDisToStem + stemLen / 2);
  17400. var arrow = new Mesh(new CylinderBufferGeometry(0, 0.6, arrowLen, 12, 1, false)); //radiusTop = 1, radiusBottom = 1, height = 1, radialSegments = 8, heightSegments = 1, openEnded = false, thetaStart = 0, thetaLength = Math.PI * 2
  17401. arrow.position.set(0, 0, lineLen$1 + lineDisToStem + stemLen + arrowLen / 2);
  17402. arrow.rotation.set(Math.PI / 2, 0, 0);
  17403. arrowGroup.add(stem);
  17404. arrowGroup.add(line);
  17405. arrowGroup.add(arrow);
  17406. this.arrowGroup = arrowGroup;
  17407. }
  17408. createArrows() {
  17409. var material = new MeshBasicMaterial({
  17410. color: "#00d7df",
  17411. side: 2,
  17412. transparent: true,
  17413. opacity: 0.8,
  17414. depthWrite: false
  17415. });
  17416. ['x', 'y', 'z'].forEach(axisText => {
  17417. var color = new Color().set(Potree.config.axis[axisText].color);
  17418. var group = this.arrowGroup.clone();
  17419. group.children.forEach(e => {
  17420. e.material = e.material.clone();
  17421. /* e.material.opacity = opacity
  17422. e.material.transparent = true */
  17423. e.material.color.copy(color);
  17424. });
  17425. var label = this.createLabel(axisText, color);
  17426. label.position.set(0, 0, lineLen$1 + stemLen + arrowLen + lineDisToStem + 3);
  17427. group.add(label);
  17428. if (axisText == 'y') {
  17429. group.rotation.x = -Math.PI / 2;
  17430. } else if (axisText == 'x') {
  17431. group.rotation.y = Math.PI / 2;
  17432. }
  17433. this.add(group);
  17434. });
  17435. }
  17436. createLabel(text, color) {
  17437. var label = new TextSprite$2({
  17438. //无法解决 因其祖先有设定quaternion, 无法对着镜头
  17439. backgroundColor: {
  17440. r: 0,
  17441. g: 0,
  17442. b: 0,
  17443. a: 0
  17444. },
  17445. textColor: {
  17446. r: color.r * 255,
  17447. g: color.g * 255,
  17448. b: color.b * 255,
  17449. a: 1
  17450. },
  17451. fontsize: 120,
  17452. //useDepth : true ,
  17453. renderOrder: 5,
  17454. // pickOrder:5,
  17455. text,
  17456. name: 'axis'
  17457. });
  17458. label.scale.set(3, 3, 3);
  17459. return label;
  17460. }
  17461. /* createLabel(text,color){
  17462. var canvas = document.createElement("canvas")
  17463. var context = canvas.getContext("2d");
  17464. canvas.width = 256,
  17465. canvas.height = 256;
  17466. var fontSize = 120
  17467. context.fillStyle = color //"#00ffee";
  17468. context.font = "normal " + fontSize + "px 微软雅黑"
  17469. var textWidth = context.measureText(text).width;
  17470. context.clearRect(0,0,canvas.width,canvas.height);
  17471. context.fillText(text, (canvas.width - textWidth) / 2 , (canvas.height + fontSize) / 2);
  17472. var tex = new THREE.Texture(canvas);
  17473. tex.needsUpdate = true
  17474. tex.minFilter = THREE.NearestFilter//防止边缘发黑
  17475. tex.magFilter = THREE.NearestFilter//防止边缘发黑
  17476. var sprite = new THREE.Sprite(new THREE.SpriteMaterial({
  17477. map: tex , // depthWrite:false,
  17478. }))
  17479. sprite.renderOrder = 1//防止在透明后还是出现白矩形挡住其他mesh
  17480. sprite.scale.set(3,3,3)
  17481. return sprite
  17482. } */
  17483. }
  17484. class Action extends EventDispatcher$1 {
  17485. constructor() {
  17486. var args = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  17487. super();
  17488. this.icon = args.icon || '';
  17489. this.tooltip = args.tooltip;
  17490. if (args.onclick !== undefined) {
  17491. this.onclick = args.onclick;
  17492. }
  17493. }
  17494. onclick(event) {}
  17495. pairWith(object) {}
  17496. setIcon(newIcon) {
  17497. var oldIcon = this.icon;
  17498. if (newIcon === oldIcon) {
  17499. return;
  17500. }
  17501. this.icon = newIcon;
  17502. this.dispatchEvent({
  17503. type: 'icon_changed',
  17504. action: this,
  17505. icon: newIcon,
  17506. oldIcon: oldIcon
  17507. });
  17508. }
  17509. }
  17510. ;
  17511. //Potree.Actions = {};
  17512. //
  17513. //Potree.Actions.ToggleAnnotationVisibility = class ToggleAnnotationVisibility extends Potree.Action {
  17514. // constructor (args = {}) {
  17515. // super(args);
  17516. //
  17517. // this.icon = Potree.resourcePath + '/icons/eye.svg';
  17518. // this.showIn = 'sidebar';
  17519. // this.tooltip = 'toggle visibility';
  17520. // }
  17521. //
  17522. // pairWith (annotation) {
  17523. // if (annotation.visible) {
  17524. // this.setIcon(Potree.resourcePath + '/icons/eye.svg');
  17525. // } else {
  17526. // this.setIcon(Potree.resourcePath + '/icons/eye_crossed.svg');
  17527. // }
  17528. //
  17529. // annotation.addEventListener('visibility_changed', e => {
  17530. // let annotation = e.annotation;
  17531. //
  17532. // if (annotation.visible) {
  17533. // this.setIcon(Potree.resourcePath + '/icons/eye.svg');
  17534. // } else {
  17535. // this.setIcon(Potree.resourcePath + '/icons/eye_crossed.svg');
  17536. // }
  17537. // });
  17538. // }
  17539. //
  17540. // onclick (event) {
  17541. // let annotation = event.annotation;
  17542. //
  17543. // annotation.visible = !annotation.visible;
  17544. //
  17545. // if (annotation.visible) {
  17546. // this.setIcon(Potree.resourcePath + '/icons/eye.svg');
  17547. // } else {
  17548. // this.setIcon(Potree.resourcePath + '/icons/eye_crossed.svg');
  17549. // }
  17550. // }
  17551. //};
  17552. class Annotation extends EventDispatcher$1 {
  17553. constructor() {
  17554. var _this;
  17555. var args = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  17556. super();
  17557. _this = this;
  17558. this.scene = null;
  17559. this._title = args.title || 'No Title';
  17560. this._description = args.description || '';
  17561. this.offset = new Vector3();
  17562. this.uuid = MathUtils.generateUUID();
  17563. if (!args.position) {
  17564. this.position = null;
  17565. } else if (args.position.x != null) {
  17566. this.position = args.position;
  17567. } else {
  17568. this.position = new Vector3(...args.position);
  17569. }
  17570. this.cameraPosition = args.cameraPosition instanceof Array ? new Vector3().fromArray(args.cameraPosition) : args.cameraPosition;
  17571. this.cameraTarget = args.cameraTarget instanceof Array ? new Vector3().fromArray(args.cameraTarget) : args.cameraTarget;
  17572. this.radius = args.radius;
  17573. this.view = args.view || null;
  17574. this.keepOpen = false;
  17575. this.descriptionVisible = false;
  17576. this.showDescription = true;
  17577. this.actions = args.actions || [];
  17578. this.isHighlighted = false;
  17579. this._visible = true;
  17580. this.__visible = true;
  17581. this._display = true;
  17582. this._expand = false;
  17583. this.collapseThreshold = [args.collapseThreshold, 100].find(e => e !== undefined);
  17584. this.children = [];
  17585. this.parent = null;
  17586. this.boundingBox = new Box3();
  17587. var iconClose = exports.resourcePath + '/icons/close.svg';
  17588. this.domElement = $("\n\t\t\t<div class=\"annotation\" oncontextmenu=\"return false;\">\n\t\t\t\t<div class=\"annotation-titlebar\">\n\t\t\t\t\t<span class=\"annotation-label\"></span>\n\t\t\t\t</div>\n\t\t\t\t<div class=\"annotation-description\">\n\t\t\t\t\t<span class=\"annotation-description-close\">\n\t\t\t\t\t\t<img src=\"".concat(iconClose, "\" width=\"16px\">\n\t\t\t\t\t</span>\n\t\t\t\t\t<span class=\"annotation-description-content\">").concat(this._description, "</span>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t"));
  17589. this.elTitlebar = this.domElement.find('.annotation-titlebar');
  17590. this.elTitle = this.elTitlebar.find('.annotation-label');
  17591. this.elTitle.append(this._title);
  17592. this.elDescription = this.domElement.find('.annotation-description');
  17593. this.elDescriptionClose = this.elDescription.find('.annotation-description-close');
  17594. // this.elDescriptionContent = this.elDescription.find(".annotation-description-content");
  17595. this.clickTitle = () => {
  17596. if (this.hasView()) {
  17597. this.moveHere(this.scene.getActiveCamera());
  17598. }
  17599. this.dispatchEvent({
  17600. type: 'click',
  17601. target: this
  17602. });
  17603. };
  17604. this.elTitle.click(this.clickTitle);
  17605. this.actions = this.actions.map(a => {
  17606. if (a instanceof Action) {
  17607. return a;
  17608. } else {
  17609. return new Action(a);
  17610. }
  17611. });
  17612. for (var action of this.actions) {
  17613. action.pairWith(this);
  17614. }
  17615. var actions = this.actions.filter(a => a.showIn === undefined || a.showIn.includes('scene'));
  17616. var _loop = function _loop(_action) {
  17617. var elButton = $("<img src=\"".concat(_action.icon, "\" class=\"annotation-action-icon\">"));
  17618. _this.elTitlebar.append(elButton);
  17619. elButton.click(() => _action.onclick({
  17620. annotation: _this
  17621. }));
  17622. };
  17623. for (var _action of actions) {
  17624. _loop(_action);
  17625. }
  17626. this.elDescriptionClose.hover(e => this.elDescriptionClose.css('opacity', '1'), e => this.elDescriptionClose.css('opacity', '0.5'));
  17627. this.elDescriptionClose.click(e => this.setHighlighted(false));
  17628. // this.elDescriptionContent.html(this._description);
  17629. this.domElement.mouseenter(e => this.setHighlighted(true));
  17630. this.domElement.mouseleave(e => this.setHighlighted(false));
  17631. this.domElement.on('touchstart', e => {
  17632. this.setHighlighted(!this.isHighlighted);
  17633. });
  17634. this.display = false;
  17635. //this.display = true;
  17636. }
  17637. installHandles(viewer) {
  17638. if (this.handles !== undefined) {
  17639. return;
  17640. }
  17641. var domElement = $("\n\t\t\t<div style=\"position: absolute; left: 300; top: 200; pointer-events: none\">\n\t\t\t\t<svg width=\"300\" height=\"600\">\n\t\t\t\t\t<line x1=\"0\" y1=\"0\" x2=\"1200\" y2=\"200\" style=\"stroke: black; stroke-width:2\" />\n\t\t\t\t\t<circle cx=\"50\" cy=\"50\" r=\"4\" stroke=\"black\" stroke-width=\"2\" fill=\"gray\" />\n\t\t\t\t\t<circle cx=\"150\" cy=\"50\" r=\"4\" stroke=\"black\" stroke-width=\"2\" fill=\"gray\" />\n\t\t\t\t</svg>\n\t\t\t</div>\n\t\t");
  17642. var svg = domElement.find("svg")[0];
  17643. var elLine = domElement.find("line")[0];
  17644. var elStart = domElement.find("circle")[0];
  17645. var elEnd = domElement.find("circle")[1];
  17646. var setCoordinates = (start, end) => {
  17647. elStart.setAttribute("cx", "".concat(start.x));
  17648. elStart.setAttribute("cy", "".concat(start.y));
  17649. elEnd.setAttribute("cx", "".concat(end.x));
  17650. elEnd.setAttribute("cy", "".concat(end.y));
  17651. elLine.setAttribute("x1", start.x);
  17652. elLine.setAttribute("y1", start.y);
  17653. elLine.setAttribute("x2", end.x);
  17654. elLine.setAttribute("y2", end.y);
  17655. var box = svg.getBBox();
  17656. svg.setAttribute("width", "".concat(box.width));
  17657. svg.setAttribute("height", "".concat(box.height));
  17658. svg.setAttribute("viewBox", "".concat(box.x, " ").concat(box.y, " ").concat(box.width, " ").concat(box.height));
  17659. var ya = start.y - end.y;
  17660. var xa = start.x - end.x;
  17661. if (ya > 0) {
  17662. start.y = start.y - ya;
  17663. }
  17664. if (xa > 0) {
  17665. start.x = start.x - xa;
  17666. }
  17667. domElement.css("left", "".concat(start.x, "px"));
  17668. domElement.css("top", "".concat(start.y, "px"));
  17669. };
  17670. $(viewer.renderArea).append(domElement);
  17671. var annotationStartPos = this.position.clone();
  17672. var annotationStartOffset = this.offset.clone();
  17673. $(this.domElement).draggable({
  17674. start: (event, ui) => {
  17675. annotationStartPos = this.position.clone();
  17676. annotationStartOffset = this.offset.clone();
  17677. $(this.domElement).find(".annotation-titlebar").css("pointer-events", "none");
  17678. console.log($(this.domElement).find(".annotation-titlebar"));
  17679. },
  17680. stop: () => {
  17681. $(this.domElement).find(".annotation-titlebar").css("pointer-events", "");
  17682. },
  17683. drag: (event, ui) => {
  17684. var renderAreaWidth = viewer.renderer.getSize(new Vector2()).width;
  17685. //let renderAreaHeight = viewer.renderer.getSize().height;
  17686. var diff = {
  17687. x: ui.originalPosition.left - ui.position.left,
  17688. y: ui.originalPosition.top - ui.position.top
  17689. };
  17690. var nDiff = {
  17691. x: -(diff.x / renderAreaWidth) * 2,
  17692. y: diff.y / renderAreaWidth * 2
  17693. };
  17694. var camera = viewer.scene.getActiveCamera();
  17695. var oldScreenPos = new Vector3().addVectors(annotationStartPos, annotationStartOffset).project(camera);
  17696. var newScreenPos = oldScreenPos.clone();
  17697. newScreenPos.x += nDiff.x;
  17698. newScreenPos.y += nDiff.y;
  17699. var newPos = newScreenPos.clone();
  17700. newPos.unproject(camera);
  17701. var newOffset = new Vector3().subVectors(newPos, this.position);
  17702. this.offset.copy(newOffset);
  17703. }
  17704. });
  17705. var updateCallback = () => {
  17706. var position = this.position;
  17707. var scene = viewer.scene;
  17708. var renderAreaSize = viewer.renderer.getSize(new Vector2());
  17709. var renderAreaWidth = renderAreaSize.width;
  17710. var renderAreaHeight = renderAreaSize.height;
  17711. var start = this.position.clone();
  17712. var end = new Vector3().addVectors(this.position, this.offset);
  17713. var toScreen = position => {
  17714. var camera = scene.getActiveCamera();
  17715. var screenPos = new Vector3();
  17716. var worldView = new Matrix4().multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  17717. var ndc = new Vector4(position.x, position.y, position.z, 1.0).applyMatrix4(worldView);
  17718. // limit w to small positive value, in case position is behind the camera
  17719. ndc.w = Math.max(ndc.w, 0.1);
  17720. ndc.divideScalar(ndc.w);
  17721. screenPos.copy(ndc);
  17722. screenPos.x = renderAreaWidth * (screenPos.x + 1) / 2;
  17723. screenPos.y = renderAreaHeight * (1 - (screenPos.y + 1) / 2);
  17724. return screenPos;
  17725. };
  17726. start = toScreen(start);
  17727. end = toScreen(end);
  17728. setCoordinates(start, end);
  17729. };
  17730. viewer.addEventListener("update", updateCallback);
  17731. this.handles = {
  17732. domElement: domElement,
  17733. setCoordinates: setCoordinates,
  17734. updateCallback: updateCallback
  17735. };
  17736. }
  17737. removeHandles(viewer) {
  17738. if (this.handles === undefined) {
  17739. return;
  17740. }
  17741. //$(viewer.renderArea).remove(this.handles.domElement);
  17742. this.handles.domElement.remove();
  17743. viewer.removeEventListener("update", this.handles.updateCallback);
  17744. delete this.handles;
  17745. }
  17746. get visible() {
  17747. return this._visible;
  17748. }
  17749. set visible(value) {
  17750. if (this._visible === value) {
  17751. return;
  17752. }
  17753. this._visible = value;
  17754. //this.traverse(node => {
  17755. // node.display = value;
  17756. //});
  17757. this.dispatchEvent({
  17758. type: 'visibility_changed',
  17759. annotation: this
  17760. });
  17761. }
  17762. get display() {
  17763. return this._display;
  17764. }
  17765. set display(display) {
  17766. if (this._display === display) {
  17767. return;
  17768. }
  17769. this._display = display;
  17770. if (display) {
  17771. // this.domElement.fadeIn(200);
  17772. this.domElement.show();
  17773. } else {
  17774. // this.domElement.fadeOut(200);
  17775. this.domElement.hide();
  17776. }
  17777. }
  17778. get expand() {
  17779. return this._expand;
  17780. }
  17781. set expand(expand) {
  17782. if (this._expand === expand) {
  17783. return;
  17784. }
  17785. if (expand) {
  17786. this.display = false;
  17787. } else {
  17788. this.display = true;
  17789. this.traverseDescendants(node => {
  17790. node.display = false;
  17791. });
  17792. }
  17793. this._expand = expand;
  17794. }
  17795. get title() {
  17796. return this._title;
  17797. }
  17798. set title(title) {
  17799. if (this._title === title) {
  17800. return;
  17801. }
  17802. this._title = title;
  17803. this.elTitle.empty();
  17804. this.elTitle.append(this._title);
  17805. this.dispatchEvent({
  17806. type: "annotation_changed",
  17807. annotation: this
  17808. });
  17809. }
  17810. get description() {
  17811. return this._description;
  17812. }
  17813. set description(description) {
  17814. if (this._description === description) {
  17815. return;
  17816. }
  17817. this._description = description;
  17818. var elDescriptionContent = this.elDescription.find(".annotation-description-content");
  17819. elDescriptionContent.empty();
  17820. elDescriptionContent.append(this._description);
  17821. this.dispatchEvent({
  17822. type: "annotation_changed",
  17823. annotation: this
  17824. });
  17825. }
  17826. add(annotation) {
  17827. if (!this.children.includes(annotation)) {
  17828. this.children.push(annotation);
  17829. annotation.parent = this;
  17830. var descendants = [];
  17831. annotation.traverse(a => {
  17832. descendants.push(a);
  17833. });
  17834. for (var descendant of descendants) {
  17835. var c = this;
  17836. while (c !== null) {
  17837. c.dispatchEvent({
  17838. 'type': 'annotation_added',
  17839. 'annotation': descendant
  17840. });
  17841. c = c.parent;
  17842. }
  17843. }
  17844. }
  17845. }
  17846. level() {
  17847. if (this.parent === null) {
  17848. return 0;
  17849. } else {
  17850. return this.parent.level() + 1;
  17851. }
  17852. }
  17853. hasChild(annotation) {
  17854. return this.children.includes(annotation);
  17855. }
  17856. remove(annotation) {
  17857. if (this.hasChild(annotation)) {
  17858. annotation.removeAllChildren();
  17859. annotation.dispose();
  17860. this.children = this.children.filter(e => e !== annotation);
  17861. annotation.parent = null;
  17862. }
  17863. }
  17864. removeAllChildren() {
  17865. this.children.forEach(child => {
  17866. if (child.children.length > 0) {
  17867. child.removeAllChildren();
  17868. }
  17869. this.remove(child);
  17870. });
  17871. }
  17872. updateBounds() {
  17873. var box = new Box3();
  17874. if (this.position) {
  17875. box.expandByPoint(this.position);
  17876. }
  17877. for (var child of this.children) {
  17878. child.updateBounds();
  17879. box.union(child.boundingBox);
  17880. }
  17881. this.boundingBox.copy(box);
  17882. }
  17883. traverse(handler) {
  17884. var expand = handler(this);
  17885. if (expand === undefined || expand === true) {
  17886. for (var child of this.children) {
  17887. child.traverse(handler);
  17888. }
  17889. }
  17890. }
  17891. traverseDescendants(handler) {
  17892. for (var child of this.children) {
  17893. child.traverse(handler);
  17894. }
  17895. }
  17896. flatten() {
  17897. var annotations = [];
  17898. this.traverse(annotation => {
  17899. annotations.push(annotation);
  17900. });
  17901. return annotations;
  17902. }
  17903. descendants() {
  17904. var annotations = [];
  17905. this.traverse(annotation => {
  17906. if (annotation !== this) {
  17907. annotations.push(annotation);
  17908. }
  17909. });
  17910. return annotations;
  17911. }
  17912. setHighlighted(highlighted) {
  17913. if (highlighted) {
  17914. this.domElement.css('opacity', '0.8');
  17915. this.elTitlebar.css('box-shadow', '0 0 5px #fff');
  17916. this.domElement.css('z-index', '1000');
  17917. if (this._description) {
  17918. this.descriptionVisible = true;
  17919. this.elDescription.fadeIn(200);
  17920. this.elDescription.css('position', 'relative');
  17921. }
  17922. } else {
  17923. this.domElement.css('opacity', '0.5');
  17924. this.elTitlebar.css('box-shadow', '');
  17925. this.domElement.css('z-index', '100');
  17926. this.descriptionVisible = false;
  17927. this.elDescription.css('display', 'none');
  17928. }
  17929. this.isHighlighted = highlighted;
  17930. }
  17931. hasView() {
  17932. var hasPosTargetView = this.cameraTarget.x != null;
  17933. hasPosTargetView = hasPosTargetView && this.cameraPosition.x != null;
  17934. var hasRadiusView = this.radius !== undefined;
  17935. var hasView = hasPosTargetView || hasRadiusView;
  17936. return hasView;
  17937. }
  17938. moveHere(camera) {
  17939. if (!this.hasView()) {
  17940. return;
  17941. }
  17942. var view = this.scene.view;
  17943. var animationDuration = 500;
  17944. var easing = TWEEN.Easing.Quartic.Out;
  17945. var endTarget;
  17946. if (this.cameraTarget) {
  17947. endTarget = this.cameraTarget;
  17948. } else if (this.position) {
  17949. endTarget = this.position;
  17950. } else {
  17951. endTarget = this.boundingBox.getCenter(new Vector3());
  17952. }
  17953. if (this.cameraPosition) {
  17954. var endPosition = this.cameraPosition;
  17955. Utils.moveTo(this.scene, endPosition, endTarget);
  17956. } else if (this.radius) {
  17957. var direction = view.direction;
  17958. var _endPosition = endTarget.clone().add(direction.multiplyScalar(-this.radius));
  17959. var startRadius = view.radius;
  17960. var endRadius = this.radius;
  17961. {
  17962. // animate camera position
  17963. var tween = new TWEEN.Tween(view.position).to(_endPosition, animationDuration);
  17964. tween.easing(easing);
  17965. tween.start();
  17966. }
  17967. {
  17968. // animate radius
  17969. var t = {
  17970. x: 0
  17971. };
  17972. var _tween = new TWEEN.Tween(t).to({
  17973. x: 1
  17974. }, animationDuration).onUpdate(function () {
  17975. view.radius = this.x * endRadius + (1 - this.x) * startRadius;
  17976. });
  17977. _tween.easing(easing);
  17978. _tween.start();
  17979. }
  17980. }
  17981. }
  17982. dispose() {
  17983. if (this.domElement.parentElement) {
  17984. this.domElement.parentElement.removeChild(this.domElement);
  17985. }
  17986. }
  17987. toString() {
  17988. return 'Annotation: ' + this._title;
  17989. }
  17990. }
  17991. ;
  17992. class Scene$1 extends EventDispatcher$1 {
  17993. //base
  17994. constructor() {
  17995. super();
  17996. this.annotations = new Annotation();
  17997. this.scene = new Scene();
  17998. this.sceneBG = new Scene();
  17999. this.scenePointCloud = new Scene();
  18000. this.cameraP = new PerspectiveCamera(this.fov, 1, 0.1, 1000 * 1000);
  18001. this.cameraO = new OrthographicCamera(-1, 1, 1, -1, 0.1, 1000 * 1000);
  18002. this.cameraVR = new PerspectiveCamera();
  18003. this.cameraBG = new Camera();
  18004. this.cameraScreenSpace = new OrthographicCamera(-1, 1, 1, -1, 0.1, 10);
  18005. this.cameraMode = CameraMode.PERSPECTIVE;
  18006. this.overrideCamera = null;
  18007. this.pointclouds = [];
  18008. this.measurements = [];
  18009. this.profiles = [];
  18010. this.volumes = [];
  18011. this.polygonClipVolumes = [];
  18012. this.cameraAnimations = [];
  18013. this.orientedImages = [];
  18014. this.images360 = [];
  18015. this.geopackages = [];
  18016. this.fpControls = null;
  18017. this.orbitControls = null;
  18018. this.earthControls = null;
  18019. this.geoControls = null;
  18020. this.deviceControls = null;
  18021. this.inputHandler = null;
  18022. this.view = new ExtendView();
  18023. this.directionalLight = null;
  18024. this.initialize();
  18025. }
  18026. estimateHeightAt(position) {
  18027. var height = null;
  18028. var fromSpacing = Infinity;
  18029. for (var pointcloud of this.pointclouds) {
  18030. if (pointcloud.root.geometryNode === undefined) {
  18031. continue;
  18032. }
  18033. var pHeight = null;
  18034. var pFromSpacing = Infinity;
  18035. var lpos = position.clone().sub(pointcloud.position);
  18036. lpos.z = 0;
  18037. var ray = new Ray(lpos, new Vector3(0, 0, 1));
  18038. var stack = [pointcloud.root];
  18039. while (stack.length > 0) {
  18040. var node = stack.pop();
  18041. var box = node.getBoundingBox();
  18042. var inside = ray.intersectBox(box);
  18043. if (!inside) {
  18044. continue;
  18045. }
  18046. var h = node.geometryNode.mean.z + pointcloud.position.z + node.geometryNode.boundingBox.min.z;
  18047. if (node.geometryNode.spacing <= pFromSpacing) {
  18048. pHeight = h;
  18049. pFromSpacing = node.geometryNode.spacing;
  18050. }
  18051. for (var index of Object.keys(node.children)) {
  18052. var child = node.children[index];
  18053. if (child.geometryNode) {
  18054. stack.push(node.children[index]);
  18055. }
  18056. }
  18057. }
  18058. if (height === null || pFromSpacing < fromSpacing) {
  18059. height = pHeight;
  18060. fromSpacing = pFromSpacing;
  18061. }
  18062. }
  18063. return height;
  18064. }
  18065. getBoundingBox() {
  18066. var pointclouds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.pointclouds;
  18067. var box = new Box3();
  18068. this.scenePointCloud.updateMatrixWorld(true);
  18069. this.referenceFrame.updateMatrixWorld(true);
  18070. for (var pointcloud of pointclouds) {
  18071. pointcloud.updateMatrixWorld(true);
  18072. var pointcloudBox = pointcloud.pcoGeometry.tightBoundingBox ? pointcloud.pcoGeometry.tightBoundingBox : pointcloud.boundingBox;
  18073. var boxWorld = Utils.computeTransformedBoundingBox(pointcloudBox, pointcloud.matrixWorld);
  18074. box.union(boxWorld);
  18075. }
  18076. return box;
  18077. }
  18078. addPointCloud(pointcloud) {
  18079. this.pointclouds.push(pointcloud);
  18080. this.scenePointCloud.add(pointcloud);
  18081. this.dispatchEvent({
  18082. type: 'pointcloud_added',
  18083. pointcloud: pointcloud
  18084. });
  18085. }
  18086. addVolume(volume) {
  18087. this.volumes.push(volume);
  18088. this.dispatchEvent({
  18089. 'type': 'volume_added',
  18090. 'scene': this,
  18091. 'volume': volume
  18092. });
  18093. viewer.dispatchEvent('content_changed');
  18094. }
  18095. addOrientedImages(images) {
  18096. this.orientedImages.push(images);
  18097. this.scene.add(images.node);
  18098. this.dispatchEvent({
  18099. 'type': 'oriented_images_added',
  18100. 'scene': this,
  18101. 'images': images
  18102. });
  18103. }
  18104. removeOrientedImages(images) {
  18105. var index = this.orientedImages.indexOf(images);
  18106. if (index > -1) {
  18107. this.orientedImages.splice(index, 1);
  18108. this.dispatchEvent({
  18109. 'type': 'oriented_images_removed',
  18110. 'scene': this,
  18111. 'images': images
  18112. });
  18113. }
  18114. }
  18115. add360Images(images) {
  18116. this.images360.push(images);
  18117. this.scene.add(images.node);
  18118. this.dispatchEvent({
  18119. 'type': '360_images_added',
  18120. 'scene': this,
  18121. 'images': images
  18122. });
  18123. }
  18124. remove360Images(images) {
  18125. var index = this.images360.indexOf(images);
  18126. if (index > -1) {
  18127. this.images360.splice(index, 1);
  18128. this.dispatchEvent({
  18129. 'type': '360_images_removed',
  18130. 'scene': this,
  18131. 'images': images
  18132. });
  18133. }
  18134. }
  18135. addGeopackage(geopackage) {
  18136. this.geopackages.push(geopackage);
  18137. this.scene.add(geopackage.node);
  18138. this.dispatchEvent({
  18139. 'type': 'geopackage_added',
  18140. 'scene': this,
  18141. 'geopackage': geopackage
  18142. });
  18143. }
  18144. removeGeopackage(geopackage) {
  18145. var index = this.geopackages.indexOf(geopackage);
  18146. if (index > -1) {
  18147. this.geopackages.splice(index, 1);
  18148. this.dispatchEvent({
  18149. 'type': 'geopackage_removed',
  18150. 'scene': this,
  18151. 'geopackage': geopackage
  18152. });
  18153. }
  18154. }
  18155. removeVolume(volume) {
  18156. var index = this.volumes.indexOf(volume);
  18157. if (index > -1) {
  18158. this.volumes.splice(index, 1);
  18159. this.dispatchEvent({
  18160. 'type': 'volume_removed',
  18161. 'scene': this,
  18162. 'volume': volume
  18163. });
  18164. }
  18165. viewer.dispatchEvent('content_changed');
  18166. }
  18167. addCameraAnimation(animation) {
  18168. this.cameraAnimations.push(animation);
  18169. this.dispatchEvent({
  18170. 'type': 'camera_animation_added',
  18171. 'scene': this,
  18172. 'animation': animation
  18173. });
  18174. }
  18175. removeCameraAnimation(animation) {
  18176. var index = this.cameraAnimations.indexOf(volume);
  18177. if (index > -1) {
  18178. this.cameraAnimations.splice(index, 1);
  18179. this.dispatchEvent({
  18180. 'type': 'camera_animation_removed',
  18181. 'scene': this,
  18182. 'animation': animation
  18183. });
  18184. }
  18185. }
  18186. addPolygonClipVolume(volume) {
  18187. this.polygonClipVolumes.push(volume);
  18188. this.dispatchEvent({
  18189. "type": "polygon_clip_volume_added",
  18190. "scene": this,
  18191. "volume": volume
  18192. });
  18193. }
  18194. removePolygonClipVolume(volume) {
  18195. var index = this.polygonClipVolumes.indexOf(volume);
  18196. if (index > -1) {
  18197. this.polygonClipVolumes.splice(index, 1);
  18198. this.dispatchEvent({
  18199. "type": "polygon_clip_volume_removed",
  18200. "scene": this,
  18201. "volume": volume
  18202. });
  18203. }
  18204. }
  18205. addMeasurement(measurement) {
  18206. measurement.lengthUnit = this.lengthUnit;
  18207. measurement.lengthUnitDisplay = this.lengthUnitDisplay;
  18208. this.measurements.push(measurement);
  18209. this.dispatchEvent({
  18210. 'type': 'measurement_added',
  18211. 'scene': this,
  18212. 'measurement': measurement
  18213. });
  18214. viewer.dispatchEvent('content_changed');
  18215. }
  18216. removeMeasurement(measurement) {
  18217. var index = this.measurements.indexOf(measurement);
  18218. if (index > -1) {
  18219. this.measurements.splice(index, 1);
  18220. this.dispatchEvent({
  18221. 'type': 'measurement_removed',
  18222. 'scene': this,
  18223. 'measurement': measurement
  18224. });
  18225. viewer.dispatchEvent('content_changed');
  18226. }
  18227. }
  18228. addProfile(profile) {
  18229. this.profiles.push(profile);
  18230. this.dispatchEvent({
  18231. 'type': 'profile_added',
  18232. 'scene': this,
  18233. 'profile': profile
  18234. });
  18235. }
  18236. removeProfile(profile) {
  18237. var index = this.profiles.indexOf(profile);
  18238. if (index > -1) {
  18239. this.profiles.splice(index, 1);
  18240. this.dispatchEvent({
  18241. 'type': 'profile_removed',
  18242. 'scene': this,
  18243. 'profile': profile
  18244. });
  18245. }
  18246. }
  18247. removeAllMeasurements() {
  18248. while (this.measurements.length > 0) {
  18249. this.removeMeasurement(this.measurements[0]);
  18250. }
  18251. while (this.profiles.length > 0) {
  18252. this.removeProfile(this.profiles[0]);
  18253. }
  18254. while (this.volumes.length > 0) {
  18255. this.removeVolume(this.volumes[0]);
  18256. }
  18257. }
  18258. removeAllClipVolumes() {
  18259. var clipVolumes = this.volumes.filter(volume => volume.clip === true);
  18260. for (var clipVolume of clipVolumes) {
  18261. this.removeVolume(clipVolume);
  18262. }
  18263. while (this.polygonClipVolumes.length > 0) {
  18264. this.removePolygonClipVolume(this.polygonClipVolumes[0]);
  18265. }
  18266. }
  18267. getActiveCamera() {
  18268. if (this.overrideCamera) {
  18269. return this.overrideCamera;
  18270. }
  18271. if (this.cameraMode === CameraMode.PERSPECTIVE) {
  18272. return this.cameraP;
  18273. } else if (this.cameraMode === CameraMode.ORTHOGRAPHIC) {
  18274. return this.cameraO;
  18275. } else if (this.cameraMode === CameraMode.VR) {
  18276. return this.cameraVR;
  18277. }
  18278. return null;
  18279. }
  18280. initialize() {
  18281. this.referenceFrame = new Object3D();
  18282. this.referenceFrame.matrixAutoUpdate = false;
  18283. this.scenePointCloud.add(this.referenceFrame);
  18284. this.cameraP.up.set(0, 0, 1);
  18285. this.cameraP.position.set(1000, 1000, 1000);
  18286. this.cameraO.up.set(0, 0, 1);
  18287. this.cameraO.position.set(1000, 1000, 1000);
  18288. //this.camera.rotation.y = -Math.PI / 4;
  18289. //this.camera.rotation.x = -Math.PI / 6;
  18290. this.cameraScreenSpace.lookAt(new Vector3(0, 0, 0), new Vector3(0, 0, -1), new Vector3(0, 1, 0));
  18291. this.directionalLight = new DirectionalLight(0xffffff, 0.5);
  18292. this.directionalLight.position.set(10, 10, 10);
  18293. this.directionalLight.lookAt(new Vector3(0, 0, 0));
  18294. this.scenePointCloud.add(this.directionalLight);
  18295. var light = new AmbientLight(0x555555); // soft white light
  18296. this.scenePointCloud.add(light);
  18297. {
  18298. // background
  18299. var texture = Utils.createBackgroundTexture(512, 512);
  18300. texture.minFilter = texture.magFilter = NearestFilter;
  18301. texture.minFilter = texture.magFilter = LinearFilter;
  18302. var bg = new Mesh(new PlaneBufferGeometry(2, 2, 1), new MeshBasicMaterial({
  18303. map: texture
  18304. }));
  18305. bg.material.depthTest = false;
  18306. bg.material.depthWrite = false;
  18307. this.sceneBG.add(bg);
  18308. }
  18309. // { // lights
  18310. // {
  18311. // let light = new THREE.DirectionalLight(0xffffff);
  18312. // light.position.set(10, 10, 1);
  18313. // light.target.position.set(0, 0, 0);
  18314. // this.scene.add(light);
  18315. // }
  18316. // {
  18317. // let light = new THREE.DirectionalLight(0xffffff);
  18318. // light.position.set(-10, 10, 1);
  18319. // light.target.position.set(0, 0, 0);
  18320. // this.scene.add(light);
  18321. // }
  18322. // {
  18323. // let light = new THREE.DirectionalLight(0xffffff);
  18324. // light.position.set(0, -10, 20);
  18325. // light.target.position.set(0, 0, 0);
  18326. // this.scene.add(light);
  18327. // }
  18328. // }
  18329. }
  18330. addAnnotation(position) {
  18331. var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  18332. if (position instanceof Array) {
  18333. args.position = new Vector3().fromArray(position);
  18334. } else if (position.x != null) {
  18335. args.position = position;
  18336. }
  18337. var annotation = new Annotation(args);
  18338. this.annotations.add(annotation);
  18339. return annotation;
  18340. }
  18341. getAnnotations() {
  18342. return this.annotations;
  18343. }
  18344. removeAnnotation(annotationToRemove) {
  18345. this.annotations.remove(annotationToRemove);
  18346. }
  18347. }
  18348. ;
  18349. class ExtendScene extends Scene$1 {
  18350. constructor() {
  18351. super();
  18352. delete this.sceneBG;
  18353. this.cameraP = new PerspectiveCamera(this.fov, 1, Potree.config.view.near, Potree.config.view.near);
  18354. this.cameraO = new OrthographicCamera(-1, 1, 1, -1, Potree.config.view.near, Potree.settings.cameraFar);
  18355. this.cameraP.limitFar = true; //add
  18356. this.initializeExtend();
  18357. //-------------
  18358. this.axisArrow = new Axis();
  18359. this.scene.add(this.axisArrow);
  18360. if (!Potree.settings.isDebug && !Potree.settings.showAxis) this.axisArrow.visible = false;
  18361. Potree.Utils.setObjectLayers(this.axisArrow, 'bothMapAndScene');
  18362. this.tags = new Object3D();
  18363. this.scene.add(this.tags);
  18364. }
  18365. estimateHeightAt(position) {
  18366. var height = null;
  18367. var fromSpacing = Infinity;
  18368. for (var pointcloud of this.pointclouds) {
  18369. if (pointcloud.root.geometryNode === undefined) {
  18370. continue;
  18371. }
  18372. var pHeight = null;
  18373. var pFromSpacing = Infinity;
  18374. var lpos = position.clone().sub(pointcloud.position);
  18375. lpos.z = 0;
  18376. var ray = new Ray(lpos, new Vector3(0, 0, 1));
  18377. var stack = [pointcloud.root];
  18378. while (stack.length > 0) {
  18379. var node = stack.pop();
  18380. var box = node.getBoundingBox();
  18381. var inside = ray.intersectBox(box);
  18382. if (!inside) {
  18383. continue;
  18384. }
  18385. var h = node.geometryNode.mean.z + pointcloud.position.z + node.geometryNode.boundingBox.min.z;
  18386. if (node.geometryNode.spacing <= pFromSpacing) {
  18387. pHeight = h;
  18388. pFromSpacing = node.geometryNode.spacing;
  18389. }
  18390. for (var index of Object.keys(node.children)) {
  18391. var child = node.children[index];
  18392. if (child.geometryNode) {
  18393. stack.push(node.children[index]);
  18394. }
  18395. }
  18396. }
  18397. if (height === null || pFromSpacing < fromSpacing) {
  18398. height = pHeight;
  18399. fromSpacing = pFromSpacing;
  18400. }
  18401. }
  18402. return height;
  18403. }
  18404. //add:
  18405. removePointCloud(pointcloud) {
  18406. var index = this.pointclouds.indexOf(pointcloud);
  18407. if (index == -1) return;
  18408. this.pointclouds.splice(index, 1);
  18409. this.scenePointCloud.remove(pointcloud);
  18410. pointcloud.panos.forEach(pano => {
  18411. pano.dispose();
  18412. });
  18413. }
  18414. removeCameraAnimation(animation) {
  18415. var index = this.cameraAnimations.indexOf(animation);
  18416. if (index > -1) {
  18417. this.cameraAnimations.splice(index, 1);
  18418. this.dispatchEvent({
  18419. 'type': 'camera_animation_removed',
  18420. 'scene': this,
  18421. 'animation': animation
  18422. });
  18423. }
  18424. }
  18425. getActiveCamera() {
  18426. return viewer.mainViewport.camera;
  18427. }
  18428. initialize() {//不用旧的 因为还没创建完变量
  18429. }
  18430. initializeExtend() {
  18431. //add 新的initialize
  18432. this.referenceFrame = new Object3D();
  18433. this.referenceFrame.matrixAutoUpdate = false;
  18434. this.scenePointCloud.add(this.referenceFrame);
  18435. if (window.axisYup) {} else {
  18436. this.cameraP.up.set(0, 0, 1);
  18437. this.cameraO.up.set(0, 0, 1);
  18438. }
  18439. this.cameraP.position.set(1000, 1000, 1000);
  18440. this.cameraO.position.set(1000, 1000, 1000);
  18441. //this.camera.rotation.y = -Math.PI / 4;
  18442. //this.camera.rotation.x = -Math.PI / 6;
  18443. this.cameraScreenSpace.lookAt(new Vector3(0, 0, 0), new Vector3(0, 0, -1), new Vector3(0, 1, 0));
  18444. this.directionalLight = new DirectionalLight(0xffffff, 0.5);
  18445. this.directionalLight.position.set(10, 10, 10);
  18446. this.directionalLight.lookAt(new Vector3(0, 0, 0));
  18447. this.scenePointCloud.add(this.directionalLight);
  18448. var light = new AmbientLight(0x555555); // soft white light
  18449. this.scenePointCloud.add(light);
  18450. //add:------给空间模型的box 或其他obj------
  18451. var light2 = new AmbientLight(16777215, 0.5);
  18452. Potree.Utils.setObjectLayers(light2, 'light' /* 'bothMapAndScene' */);
  18453. this.scene.add(light2);
  18454. var light3 = new DirectionalLight(16777215, 0.7);
  18455. light3.position.set(10, 10, 10);
  18456. light3.lookAt(new Vector3(0, 0, 0));
  18457. Potree.Utils.setObjectLayers(light3, 'light');
  18458. this.scene.add(light3);
  18459. var light4 = new DirectionalLight(16777215, 0.3); //补光
  18460. light4.position.set(-10, -5, -7);
  18461. light4.lookAt(new Vector3(0, 0, 0));
  18462. Potree.Utils.setObjectLayers(light4, 'light');
  18463. this.scene.add(light4);
  18464. //--------------------------------------------
  18465. {
  18466. // background
  18467. var texture = Utils.createBackgroundTexture(512, 512);
  18468. texture.minFilter = texture.magFilter = NearestFilter;
  18469. texture.minFilter = texture.magFilter = LinearFilter;
  18470. var bg = new Mesh(new PlaneBufferGeometry(2, 2, 1), new MeshBasicMaterial({
  18471. map: texture
  18472. }));
  18473. bg.material.depthTest = false;
  18474. bg.material.depthWrite = false;
  18475. bg.name = 'bg';
  18476. //this.sceneBG.add(bg);
  18477. this.scene.add(bg);
  18478. bg.layers.set(Potree.config.renderLayers.bg);
  18479. }
  18480. {
  18481. // background color
  18482. var bg2 = new Mesh(new PlaneBufferGeometry(2, 2, 1), new MeshBasicMaterial({
  18483. transparent: true
  18484. }));
  18485. bg2.material.depthTest = false;
  18486. bg2.material.depthWrite = false;
  18487. bg2.name = 'bg2';
  18488. this.scene.add(bg2);
  18489. bg2.layers.set(Potree.config.renderLayers.bg2);
  18490. this.bg2 = bg2;
  18491. }
  18492. // { // lights
  18493. // {
  18494. // let light = new THREE.DirectionalLight(0xffffff);
  18495. // light.position.set(10, 10, 1);
  18496. // light.target.position.set(0, 0, 0);
  18497. // this.scene.add(light);
  18498. // }
  18499. // {
  18500. // let light = new THREE.DirectionalLight(0xffffff);
  18501. // light.position.set(-10, 10, 1);
  18502. // light.target.position.set(0, 0, 0);
  18503. // this.scene.add(light);
  18504. // }
  18505. // {
  18506. // let light = new THREE.DirectionalLight(0xffffff);
  18507. // light.position.set(0, -10, 20);
  18508. // light.target.position.set(0, 0, 0);
  18509. // this.scene.add(light);
  18510. // }
  18511. // }
  18512. }
  18513. }
  18514. ;
  18515. KeyCodes.BACKSPACE = 8;
  18516. //注意,这时候Potree.js中export的内容还不在Potree变量中
  18517. var texLoader$1 = new TextureLoader();
  18518. texLoader$1.crossOrigin = "anonymous";
  18519. {
  18520. //defines:
  18521. Potree.defines = {};
  18522. Potree.defines.Buttons = {
  18523. // MouseEvent.buttons
  18524. //buttons,设置按下了鼠标哪些键,是一个3个比特位的二进制值,默认为0。1表示按下主键(通常是左键),2表示按下次要键(通常是右键),4表示按下辅助键(通常是中间的键)。
  18525. NONE: 0,
  18526. //add
  18527. LEFT: 0b0001,
  18528. RIGHT: 0b0010,
  18529. MIDDLE: 0b0100
  18530. };
  18531. /* 如果访问的是button, 用THREE.MOUSE来判断:
  18532. button,设置按下了哪一个鼠标按键,默认为0。-1表示没有按键,0表示按下主键(通常是左键),1表示按下辅助键(通常是中间的键),2表示按下次要键(通常是右键)
  18533. */
  18534. Potree.browser = browser;
  18535. /////////// add //////////////////////////////////
  18536. Potree.defines.GLCubeFaces = {
  18537. GL_TEXTURE_CUBE_MAP_POSITIVE_X: 0,
  18538. GL_TEXTURE_CUBE_MAP_NEGATIVE_X: 1,
  18539. GL_TEXTURE_CUBE_MAP_POSITIVE_Y: 2,
  18540. GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: 3,
  18541. GL_TEXTURE_CUBE_MAP_POSITIVE_Z: 4,
  18542. GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: 5
  18543. };
  18544. Potree.defines.PanoSizeClass = {
  18545. BASE: 1,
  18546. STANDARD: 2,
  18547. HIGH: 3,
  18548. ULTRAHIGH: 4
  18549. };
  18550. Potree.defines.PanoRendererEvents = {
  18551. PanoRenderComplete: "panorama.render.complete",
  18552. TileRenderFailure: "panorama.tile.render.failed",
  18553. TileRenderSuccess: "panorama.tile.render.success",
  18554. TileUploadAttempted: "panorama.tile.upload.attempted",
  18555. UploadAttemptedForAllTiles: "panorama.upload.attempted.all.tiles",
  18556. ZoomLevelRenderStarted: "panorama.zoom.render.started"
  18557. };
  18558. Potree.defines.SceneRendererEvents = {
  18559. ContextCreated: "scene-renderer-context-created",
  18560. AfterRender: "after-render",
  18561. MemoryUsageUpdated: "scene-renderer-memory-usage-updated"
  18562. };
  18563. Potree.defines.TileDownloaderEvents = {
  18564. TileDownloadSuccess: "tiledownloader.download.success",
  18565. TileDownloadFailure: "tiledownloader.download.failure",
  18566. PanoDownloadComplete: "tiledownloader.pano.download.complete"
  18567. };
  18568. Potree.defines.Vectors = {
  18569. UP: new Vector3(0, 1, 0),
  18570. DOWN: new Vector3(0, -1, 0),
  18571. LEFT: new Vector3(-1, 0, 0),
  18572. RIGHT: new Vector3(1, 0, 0),
  18573. FORWARD: new Vector3(0, 0, -1),
  18574. BACK: new Vector3(0, 0, 1)
  18575. };
  18576. /* var Vectors2 = {}
  18577. for(var i in Vectors){
  18578. Vectors2[i] = math.convertVector.YupToZup(Vectors[i])
  18579. }
  18580. */
  18581. Potree.defines.DownloadStatus = Object.freeze({
  18582. None: 0,
  18583. Queued: 1,
  18584. ForceQueued: 2,
  18585. Downloading: 3,
  18586. Downloaded: 4,
  18587. DownloadFailed: 5
  18588. });
  18589. Potree.defines.ModelManagerEvents = {
  18590. ModelAdded: "model-added",
  18591. ActiveModelChanged: "active-model-changed"
  18592. };
  18593. Potree.defines.PanoramaEvents = {
  18594. Enter: 'panorama.enter',
  18595. Exit: 'panorama.exit',
  18596. LoadComplete: "panorama.load.complete",
  18597. LoadFailed: "panorama.load.failed",
  18598. TileLoaded: "panorama.tile.loaded",
  18599. VideoRendered: "panorama.video.rendered"
  18600. };
  18601. ClipTask.SHOW_INSIDE_Big = 4;
  18602. }
  18603. {
  18604. //Features
  18605. var gl_;
  18606. Features.EXT_DEPTH = {
  18607. isSupported: function isSupported(gl) {
  18608. gl = gl || gl_;
  18609. gl_ = gl;
  18610. if (browser.detectIOS()) {
  18611. var {
  18612. major,
  18613. minor,
  18614. patch
  18615. } = browser.iosVersion();
  18616. //console.warn('iosVersion',major,minor,patch)
  18617. if (major == 15 && minor == 4 && patch == 1) {
  18618. console.warn('检测到是ios15.4.1, 关闭EXT_frag_depth'); //该版本ext_depth有问题,导致clear错乱。没有解决办法先关闭。
  18619. return false;
  18620. }
  18621. }
  18622. return typeof WebGL2RenderingContext != 'undefined' && gl instanceof WebGL2RenderingContext || gl.getExtension('EXT_frag_depth'); //shader中的GL_EXT_frag_depth需要判断一下detectIOS吗。。
  18623. }
  18624. };
  18625. }
  18626. Utils.loadSkybox = function (path, oldSky, callback) {
  18627. var camera, scene, parent, cameraOrtho;
  18628. if (!oldSky) {
  18629. parent = new Object3D("skybox_root");
  18630. camera = new PerspectiveCamera(75, window.innerWidth / window.innerHeight, 1, 100000);
  18631. cameraOrtho = new OrthographicCamera(-1, 1, 1, -1, Potree.config.view.near, Potree.settings.cameraFar);
  18632. if (!window.axisYup) camera.up.set(0, 0, 1); //add
  18633. scene = new Scene();
  18634. var skyboxBgWidth = Potree.config.skyboxBgWidth;
  18635. var skyGeometry = new BoxBufferGeometry(skyboxBgWidth, skyboxBgWidth, skyboxBgWidth);
  18636. var skybox = new Mesh(skyGeometry, new ShaderMaterial({
  18637. vertexShader: Shaders['skybox.vs'],
  18638. fragmentShader: Shaders['skybox.fs'],
  18639. side: BackSide,
  18640. uniforms: {
  18641. tDiffuse: {
  18642. type: "t",
  18643. value: null
  18644. },
  18645. matrix: {
  18646. type: "m4",
  18647. value: new Matrix4()
  18648. }
  18649. },
  18650. depthTest: false,
  18651. depthWrite: false
  18652. }));
  18653. scene.add(skybox);
  18654. scene.traverse(n => n.frustumCulled = false);
  18655. // z up
  18656. //scene.rotation.x = Math.PI / 2;
  18657. parent.children.push(camera);
  18658. camera.parent = parent;
  18659. } else {
  18660. camera = oldSky.camera, scene = oldSky.scene;
  18661. parent = oldSky.parent;
  18662. cameraOrtho = oldSky.cameraOrtho;
  18663. }
  18664. var texture = texLoader$1.load(path, () => {
  18665. console.log('loadSkybox成功', path);
  18666. texture.wrapS = RepeatWrapping;
  18667. texture.flipY = false;
  18668. texture.magFilter = LinearFilter;
  18669. texture.minFilter = LinearFilter;
  18670. scene.children[0].material.uniforms.tDiffuse.value = texture;
  18671. callback && callback();
  18672. viewer.dispatchEvent('content_changed');
  18673. }, null, e => {
  18674. //error
  18675. console.error('loadSkybox失败', path);
  18676. });
  18677. return {
  18678. camera,
  18679. scene,
  18680. parent,
  18681. cameraOrtho
  18682. };
  18683. };
  18684. Utils.getMousePointCloudIntersection = function (viewport, mouse, pointer, camera, viewer, pointclouds) {
  18685. var pickParams = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : {};
  18686. //getIntersectByDepthTex
  18687. /* let result = viewer.edlRenderer.depthTexSampler.sample(viewport, mouse)//add
  18688. if(result != 'unsupport')return result
  18689. */
  18690. if (!pointclouds || pointclouds.filter(e => Potree.Utils.getObjVisiByReason(e, 'datasetSelection')).length == 0) return;
  18691. //console.log('getMousePointCloudIntersection')
  18692. var renderer = viewer.renderer;
  18693. if (viewport) {
  18694. //转换到类似整个画面时
  18695. /*let mouseInViewport = Utils.convertNDCToScreenPosition(pointer, null, viewport.resolution.x, viewport.resolution.y)
  18696. pickParams.x = mouseInViewport.x //mouse.x / viewport.width;
  18697. pickParams.y = mouseInViewport.y //renderer.domElement.clientHeight - mouse.y / viewport.height; */
  18698. pickParams.x = mouse.x;
  18699. pickParams.y = viewport.resolution.y - mouse.y;
  18700. } else {
  18701. pickParams.x = mouse.x;
  18702. pickParams.y = renderer.domElement.clientHeight - mouse.y;
  18703. }
  18704. //console.log('getMousePointCloudIntersection')
  18705. /* if(!raycaster){
  18706. raycaster = new THREE.Raycaster();
  18707. raycaster.setFromCamera(pointer, camera);
  18708. } */
  18709. var raycaster = new Raycaster();
  18710. raycaster.setFromCamera(pointer, camera);
  18711. var ray = raycaster.ray;
  18712. var selectedPointcloud = null;
  18713. var closestDistance = Infinity;
  18714. var closestIntersection = null;
  18715. var closestPoint = null;
  18716. //-----------add--------------------
  18717. var old_clipBoxes_in = new Map();
  18718. var old_clipBoxes_out = new Map();
  18719. var old_bigClipInBox = new Map();
  18720. var old_highlightBoxes = new Map();
  18721. var old_visibleNodes = new Map();
  18722. //bigClipInBox 最好也写下
  18723. var density;
  18724. var sizeType;
  18725. var size = new Map();
  18726. var visiMap = new Map();
  18727. var needsUpdate = false;
  18728. if (pickParams.measuring || Potree.settings.displayMode == 'showPanos') {
  18729. //测量或无深度图时的全景模式提高精准度. (全景模式有深度图时不会执行到这)
  18730. density = Potree.settings.pointDensity;
  18731. Potree.settings.pointDensity = 'magnifier'; //加载最高level
  18732. pointclouds.forEach(e => {
  18733. //因为全景模式的pointSizeType是fixed所以要还原下
  18734. visiMap.set(e, e.visible);
  18735. e.visible = Potree.Utils.getObjVisiByReason(e, 'datasetSelection'); //先将隐藏的点云显示
  18736. if (!e.visible) return;
  18737. size.set(e, e.temp.pointSize);
  18738. sizeType = e.material.pointSizeType;
  18739. e.material.pointSizeType = Potree.config.material.pointSizeType;
  18740. //e.changePointSize(Potree.config.material.realPointSize*2, true)//更改点云大小到能铺满为止,否则容易识别不到
  18741. });
  18742. needsUpdate = true;
  18743. } else {
  18744. if (viewer.viewports.filter(e => !e.noPointcloud && e.active).length > 1 || pickParams.cameraChanged) {
  18745. //在pick时相机和渲染时不一样的话
  18746. viewport.beforeRender && viewport.beforeRender();
  18747. needsUpdate = true; //不updatePointClouds的话hover久了会不准 因node是错的
  18748. //但依旧需要camera真的移动到那个位置才能加载出点云
  18749. }
  18750. }
  18751. if (!pickParams.pickClipped) {
  18752. // 无视clipBoxes
  18753. for (var pointcloud of pointclouds) {
  18754. old_clipBoxes_in.set(pointcloud, pointcloud.clipBoxes_in);
  18755. old_clipBoxes_out.set(pointcloud, pointcloud.clipBoxes_out);
  18756. old_bigClipInBox.set(pointcloud, pointcloud.bigClipInBox);
  18757. old_highlightBoxes.set(pointcloud, pointcloud.highlightBoxes);
  18758. pointcloud.material.setClipBoxes(null, [], [], []);
  18759. }
  18760. needsUpdate = true;
  18761. }
  18762. if (needsUpdate) {
  18763. for (var _pointcloud of pointclouds) {
  18764. old_visibleNodes.set(_pointcloud, _pointcloud.visibleNodes);
  18765. }
  18766. if (window.notViewOffset) {
  18767. Potree.updatePointClouds(pointclouds, camera, viewport.resolution);
  18768. } else {
  18769. //尽量减少点云加载的范围,集中在pick的空间(这部分以外还是会加载一些散点的)
  18770. var viewWidth = 80; //viewer.magnifier ? viewer.magnifier.viewport.resolution.x : 200
  18771. var camera_ = camera.clone();
  18772. camera_.setViewOffset(viewport.resolution.x, viewport.resolution.y, pickParams.x - viewWidth / 2, viewport.resolution.y - pickParams.y - viewWidth / 2, viewWidth, viewWidth); //注意offsetY是从上到下,和一般的不同
  18773. Potree.updatePointClouds(pointclouds, camera_, viewport.resolution);
  18774. }
  18775. }
  18776. //------------------------------------------------
  18777. var allPointclouds = [];
  18778. for (var _pointcloud2 of pointclouds) {
  18779. var point = _pointcloud2.pick(viewer, viewport, camera, ray, pickParams);
  18780. if (!point) {
  18781. continue;
  18782. }
  18783. allPointclouds.push(_pointcloud2);
  18784. var distance = camera.position.distanceTo(point.position);
  18785. if (distance < closestDistance) {
  18786. closestDistance = distance;
  18787. selectedPointcloud = _pointcloud2;
  18788. closestIntersection = point.position;
  18789. closestPoint = point;
  18790. }
  18791. }
  18792. //恢复
  18793. if (pickParams.measuring || Potree.settings.displayMode == 'showPanos') {
  18794. Potree.settings.pointDensity = density;
  18795. pointclouds.forEach(e => {
  18796. if (e.visible) {
  18797. e.material.pointSizeType = sizeType;
  18798. //e.changePointSize(size.get(e))
  18799. }
  18800. e.visible = visiMap.get(e);
  18801. });
  18802. } else {
  18803. /* if(viewer.viewports.filter(e=>!e.noPointcloud).length>1){
  18804. viewport.afterRender && viewport.afterRender()
  18805. } */
  18806. }
  18807. if (!pickParams.pickClipped) {
  18808. //add
  18809. for (var _pointcloud3 of pointclouds) {
  18810. _pointcloud3.material.setClipBoxes(old_bigClipInBox.get(_pointcloud3), old_clipBoxes_in.get(_pointcloud3), old_clipBoxes_out.get(_pointcloud3), old_highlightBoxes.get(_pointcloud3));
  18811. }
  18812. }
  18813. if (needsUpdate) {
  18814. for (var _pointcloud4 of pointclouds) {
  18815. //不恢复的话(尤其cameraChanged时),在下次render前,再次pick可能是错的。表现为多数据集刚开始reticule消失了,直到ifPointBlockedByIntersect停止
  18816. _pointcloud4.visibleNodes = old_visibleNodes.get(_pointcloud4);
  18817. }
  18818. }
  18819. if (selectedPointcloud) {
  18820. return {
  18821. location: closestIntersection,
  18822. distance: closestDistance,
  18823. pointcloud: selectedPointcloud,
  18824. point: closestPoint,
  18825. pointclouds: allPointclouds,
  18826. //add
  18827. normal: closestPoint.normal && new Vector3().fromArray(closestPoint.normal).applyMatrix4(selectedPointcloud.rotateMatrix) //add
  18828. };
  18829. } else {
  18830. return null;
  18831. }
  18832. };
  18833. Utils.pixelsArrayToDataUrl = function (pixels, width, height) {
  18834. var compressRatio = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0.7;
  18835. var canvas = document.createElement('canvas');
  18836. canvas.width = width;
  18837. canvas.height = height;
  18838. var context = canvas.getContext('2d');
  18839. pixels = new pixels.constructor(pixels);
  18840. /* for (let i = 0; i < pixels.length; i++) {
  18841. pixels[i * 4 + 3] = 255;
  18842. } */
  18843. // flip vertically
  18844. var bytesPerLine = width * 4;
  18845. for (var i = 0; i < parseInt(height / 2); i++) {
  18846. var j = height - i - 1;
  18847. var lineI = pixels.slice(i * bytesPerLine, i * bytesPerLine + bytesPerLine);
  18848. var lineJ = pixels.slice(j * bytesPerLine, j * bytesPerLine + bytesPerLine);
  18849. pixels.set(lineJ, i * bytesPerLine);
  18850. pixels.set(lineI, j * bytesPerLine);
  18851. }
  18852. var imageData = context.createImageData(width, height);
  18853. imageData.data.set(pixels);
  18854. context.putImageData(imageData, 0, 0);
  18855. var dataURL = canvas.toDataURL(compressRatio);
  18856. return dataURL;
  18857. };
  18858. Utils.renderTargetToDataUrl = function (renderTarget, width, height, renderer) {
  18859. var compressRatio = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0.7;
  18860. var pixelCount = width * height;
  18861. var buffer = new Uint8Array(4 * pixelCount);
  18862. renderer.readRenderTargetPixels(renderTarget, 0, 0, width, height, buffer);
  18863. var dataUrl = Utils.pixelsArrayToDataUrl(buffer, width, height, compressRatio);
  18864. return dataUrl;
  18865. };
  18866. Utils.mouseToRay = function (pointer, camera) {
  18867. var vector = new Vector3(pointer.x, pointer.y, 1);
  18868. var origin = new Vector3(pointer.x, pointer.y, -1); //不能用camera.position,在orbitCamera时不准
  18869. vector.unproject(camera);
  18870. origin.unproject(camera);
  18871. var direction = new Vector3().subVectors(vector, origin).normalize();
  18872. var ray = new Ray(origin, direction);
  18873. return ray;
  18874. };
  18875. Utils.getPos2d = function (point, viewport, dom, renderer) {
  18876. //获取一个三维坐标对应屏幕中的二维坐标
  18877. var pos;
  18878. if (math.closeTo(viewport.camera.position, point, 1e-5)) {
  18879. //和相机位置重合时显示会四处飘,看是要改成一直显示中间还是隐藏?
  18880. pos = new Vector3(0, 0, 1.5); //1.5是为了不可见
  18881. } else {
  18882. pos = point.clone().project(viewport.camera); //比之前hotspot的计算方式写得简单 project用于3转2(求法同shader); unproject用于2转3 :new r.Vector3(e.x, e.y, -1).unproject(this.camera);
  18883. }
  18884. var size = renderer && renderer.getSize(new Vector2()); //如果是渲染到renderTarget上,resolution和dom的大小不一致。如果输出的结果给前端2d用,就使用clinetWidth,如果自己场景用,用renderer.size
  18885. var w = renderer ? size.x : dom.clientWidth;
  18886. var h = renderer ? size.y : dom.clientHeight;
  18887. var x, y, left, top;
  18888. x = (pos.x + 1) / 2 * w * viewport.width;
  18889. y = (1 - (pos.y + 1) / 2) * h * viewport.height;
  18890. left = viewport.left * w;
  18891. top = (1 - viewport.bottom - viewport.height) * h;
  18892. var inSight = pos.x <= 1 && pos.x >= -1 //是否在屏幕中
  18893. && pos.x <= 1 && pos.y >= -1;
  18894. return {
  18895. pos: new Vector2(left + x, top + y),
  18896. // 屏幕像素坐标
  18897. vector: pos,
  18898. //(范围 -1 ~ 1)
  18899. trueSide: pos.z < 1,
  18900. //trueSide为false时,即使在屏幕范围内可见,也是反方向的另一个不可以被渲染的点 参见Tag.update
  18901. inSight: inSight,
  18902. //在屏幕范围内可见,
  18903. posInViewport: new Vector2(x, y)
  18904. };
  18905. };
  18906. Utils.screenPass = new function () {
  18907. this.screenScene = new Scene();
  18908. this.screenQuad = new Mesh(new PlaneBufferGeometry(2, 2, 1));
  18909. this.screenQuad.material.depthTest = true;
  18910. this.screenQuad.material.depthWrite = true;
  18911. this.screenQuad.material.transparent = true;
  18912. this.screenScene.add(this.screenQuad);
  18913. this.camera = new Camera();
  18914. this.render = function (renderer, material, target, composer) {
  18915. this.screenQuad.material = material;
  18916. if (typeof target === 'undefined') {
  18917. (composer || renderer).render(this.screenScene, this.camera);
  18918. } else {
  18919. var oldTarget = renderer.getRenderTarget();
  18920. renderer.setRenderTarget(target);
  18921. //renderer.clear(); //有时候不能clear,如renderBG后再
  18922. (composer || renderer).render(this.screenScene, this.camera);
  18923. renderer.setRenderTarget(oldTarget);
  18924. }
  18925. };
  18926. }();
  18927. //add
  18928. Utils.computePointcloudsBound = function (pointclouds) {
  18929. var boundingBox = new Box3();
  18930. pointclouds.forEach(pointcloud => {
  18931. pointcloud.updateBound();
  18932. boundingBox.union(pointcloud.bound2);
  18933. });
  18934. var boundSize = boundingBox.getSize(new Vector3());
  18935. var center = boundingBox.getCenter(new Vector3());
  18936. return {
  18937. boundSize,
  18938. center,
  18939. boundingBox
  18940. };
  18941. };
  18942. Utils.convertScreenPositionToNDC = function (pointer, mouse, width, height) {
  18943. return pointer = pointer || new Vector2(), pointer.x = mouse.x / width * 2 - 1, pointer.y = 2 * -(mouse.y / height) + 1, pointer;
  18944. };
  18945. Utils.convertNDCToScreenPosition = function (pointer, mouse, width, height) {
  18946. return mouse = mouse || new Vector2(), mouse.x = Math.round((pointer.x + 1) / 2 * width), mouse.y = Math.round(-(pointer.y - 1) / 2 * height), mouse;
  18947. };
  18948. Utils.getOrthoCameraMoveVec = function (pointerDelta, camera) {
  18949. //获取当camera为Ortho型时 屏幕点1 到 屏幕点2 的三维距离
  18950. var cameraViewWidth = camera.right / camera.zoom;
  18951. var cameraViewHeight = camera.top / camera.zoom;
  18952. var moveVec = new Vector3();
  18953. moveVec.set(pointerDelta.x * cameraViewWidth, pointerDelta.y * cameraViewHeight, 0).applyQuaternion(camera.quaternion);
  18954. return moveVec;
  18955. };
  18956. Utils.VectorFactory = {
  18957. fromArray: function fromArray(t) {
  18958. if (t) {
  18959. if (t.length < 2 || t.length > 3) console.error("Wrong number of ordinates for a point!");
  18960. return 3 === t.length ? new Vector3().fromArray(t) : new Vector2().fromArray(t);
  18961. }
  18962. },
  18963. fromArray3: function fromArray3(t) {
  18964. if (t) {
  18965. if (3 !== t.length) console.error("Wrong number of ordinates for a point!");
  18966. return new Vector3().fromArray(t);
  18967. }
  18968. },
  18969. fromArray2: function fromArray2(t) {
  18970. if (t) {
  18971. if (2 !== t.length) console.error("Wrong number of ordinates for a point!");
  18972. return new Vector2().fromArray(t);
  18973. }
  18974. },
  18975. toString: function toString(t) {
  18976. return t.x.toFixed(8) + "," + t.y.toFixed(8) + "," + t.z.toFixed(3);
  18977. }
  18978. };
  18979. Utils.QuaternionFactory = {
  18980. rot90: new Quaternion().setFromAxisAngle(new Vector3(0, 0, 1), MathUtils.degToRad(-90)),
  18981. fromArray: function fromArray(t) {
  18982. if (t) {
  18983. if (4 !== t.length) console.error("Wrong number of ordinates for a quaternion!");
  18984. return new Quaternion(t[1], t[2], t[3], t[0]).multiply(this.rot90);
  18985. }
  18986. },
  18987. toArray: function toArray(t) {
  18988. if (t) {
  18989. var e = t.clone().multiply(a).toArray();
  18990. return [e[3], e[0], e[1], e[2]];
  18991. }
  18992. },
  18993. fromLonLat: function fromLonLat(t) {
  18994. if (t) return new Quaternion().setFromEuler(new Euler(t.lon, t.lat, 0));
  18995. },
  18996. toLonLat: function toLonLat(t) {
  18997. if (t) {
  18998. var e = new Euler().setFromQuaternion(t);
  18999. return {
  19000. lon: e.x,
  19001. lat: e.y
  19002. };
  19003. }
  19004. }
  19005. };
  19006. Utils.datasetPosTransform = function () {
  19007. var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  19008. var pointcloud = o.pointcloud || viewer.scene.pointclouds.find(e => e.dataset_id == o.datasetId);
  19009. var tranMatrix;
  19010. if (pointcloud) {
  19011. if (Potree.settings.editType == 'merge') {
  19012. tranMatrix = o.fromDataset ? pointcloud.matrixWorld : new Matrix4().copy(pointcloud.matrixWorld).invert();
  19013. } else {
  19014. tranMatrix = o.fromDataset ? pointcloud.transformMatrix : pointcloud.transformInvMatrix;
  19015. }
  19016. } else {
  19017. if (Potree.settings.intersectOnObjs) {
  19018. var object = o.object || viewer.objs.children.find(e => e.dataset_id == o.datasetId);
  19019. if (object) {
  19020. tranMatrix = o.fromDataset ? object.matrixWorld : new Matrix4().copy(object.matrixWorld).invert();
  19021. }
  19022. }
  19023. }
  19024. if (tranMatrix) {
  19025. return new Vector3().copy(o.position).applyMatrix4(tranMatrix);
  19026. } else {
  19027. if (o.datasetId != void 0) {
  19028. console.error("datasetPosTransform\u627E\u4E0D\u5230datasetId\u4E3A".concat(o.datasetId, "\u7684\u6570\u636E\u96C6\u6216\u6A21\u578B\uFF0C\u8BF7\u68C0\u67E5\u6570\u636E\uFF0C \u6A21\u578B\u672A\u521B\u5EFA\u6216\u5220\u9664"));
  19029. //很可能是旧的热点,需要删除
  19030. }
  19031. }
  19032. };
  19033. Utils.datasetRotTransform = function () {
  19034. var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  19035. var pointcloud = o.pointcloud || viewer.scene.pointclouds.find(e => e.dataset_id == o.datasetId);
  19036. if (pointcloud) {
  19037. var matrix, newMatrix, result;
  19038. if (o.rotation) {
  19039. matrix = new Matrix4().makeRotationFromEuler(o.rotation);
  19040. } else if (o.quaternion) {
  19041. matrix = new Matrix4().makeRotationFromQuaternion(o.quaternion);
  19042. } else if (o.matrix) {
  19043. matrix = o.matrix.clone();
  19044. } else {
  19045. return;
  19046. }
  19047. var rotateMatrix = o.fromDataset ? pointcloud.rotateMatrix : pointcloud.rotateInvMatrix;
  19048. newMatrix = new Matrix4().multiplyMatrices(rotateMatrix, matrix);
  19049. if (o.getRotation) {
  19050. result = new Euler().setFromRotationMatrix(newMatrix);
  19051. } else if (o.getQuaternion) {
  19052. result = new Quaternion().setFromRotationMatrix(newMatrix);
  19053. } else if (o.getMatrix) {
  19054. result = newMatrix;
  19055. }
  19056. return result;
  19057. }
  19058. };
  19059. Utils.isInsideFrustum = function (bounding, camera) {
  19060. // bounding是否在视野范围内有可见部分(视野就是一个锥状box)
  19061. var frustumMatrix = new Matrix4();
  19062. frustumMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  19063. var frustum = new Frustum();
  19064. frustum.setFromProjectionMatrix(frustumMatrix);
  19065. if (bounding instanceof Sphere) {
  19066. return frustum.intersectsSphere(bounding);
  19067. } else {
  19068. return frustum.intersectsBox(bounding);
  19069. }
  19070. };
  19071. Utils.isIntersectBox = function (object, boxMatrix) {
  19072. //object是否有在box中的部分。 object可以是点或者bounding, box原为1*1*1,但可能形变
  19073. //let frustum = new THREE.Frustum();
  19074. //frustum.setFromProjectionMatrix(boxMatrixInverse) --错
  19075. var px = new Vector3(+0.5, 0, 0).applyMatrix4(boxMatrix);
  19076. var nx = new Vector3(-0.5, 0, 0).applyMatrix4(boxMatrix);
  19077. var py = new Vector3(0, +0.5, 0).applyMatrix4(boxMatrix);
  19078. var ny = new Vector3(0, -0.5, 0).applyMatrix4(boxMatrix);
  19079. var pz = new Vector3(0, 0, +0.5).applyMatrix4(boxMatrix);
  19080. var nz = new Vector3(0, 0, -0.5).applyMatrix4(boxMatrix);
  19081. var pxN = new Vector3().subVectors(nx, px).normalize();
  19082. var nxN = pxN.clone().multiplyScalar(-1);
  19083. var pyN = new Vector3().subVectors(ny, py).normalize();
  19084. var nyN = pyN.clone().multiplyScalar(-1);
  19085. var pzN = new Vector3().subVectors(nz, pz).normalize();
  19086. var nzN = pzN.clone().multiplyScalar(-1);
  19087. var pxPlane = new Plane().setFromNormalAndCoplanarPoint(pxN, px);
  19088. var nxPlane = new Plane().setFromNormalAndCoplanarPoint(nxN, nx);
  19089. var pyPlane = new Plane().setFromNormalAndCoplanarPoint(pyN, py);
  19090. var nyPlane = new Plane().setFromNormalAndCoplanarPoint(nyN, ny);
  19091. var pzPlane = new Plane().setFromNormalAndCoplanarPoint(pzN, pz);
  19092. var nzPlane = new Plane().setFromNormalAndCoplanarPoint(nzN, nz);
  19093. var frustum = new Frustum(pxPlane, nxPlane, pyPlane, nyPlane, pzPlane, nzPlane);
  19094. if (object instanceof Box3) {
  19095. var boxBound = new Box3(new Vector3(-0.5, -0.5, -0.5), new Vector3(0.5, 0.5, 0.5)).applyMatrix4(boxMatrix); //large boundingbox
  19096. if (!object.intersectsBox(boxBound)) return;
  19097. return frustum.intersectsBox(object); //根据该函数, 若存在某个plane在box上的对应点都在plane背面,则不相交. 可得知在box构成的frustum倾斜时不准确,不相交也判断为相交,甚至不如bound相交准确。所以前面加步骤排除下,但仍不完全准确。(可在裁剪中将box放置到数据集上方旋转下校验)
  19098. } else if (object instanceof Array) {
  19099. //点合集, 只能粗略计算下
  19100. var sphere = new Sphere();
  19101. sphere.setFromPoints(object);
  19102. return this.isIntersectBox(sphere, boxMatrix);
  19103. } else if (object instanceof Sphere) {
  19104. return frustum.intersectsSphere(object);
  19105. } else if (object instanceof Vector3) {
  19106. return frustum.containsPoint(object);
  19107. } else if (object instanceof Matrix4) {//第一个参数如果和第二个参数一样都是box的worldMatrix
  19108. }
  19109. /* containsPoint: ƒ containsPoint( point )
  19110. intersectsBox: ƒ intersectsBox( box )
  19111. intersectsObject: ƒ intersectsObject( object )//geo
  19112. intersectsSphere: ƒ intersectsSphere( sphere )
  19113. intersectsSprite: ƒ intersectsSprite( sprite )
  19114. */
  19115. };
  19116. Utils.getIntersect = function (camera, meshes, pointer, raycaster) {
  19117. //获取鼠标和meshes交点
  19118. if (!raycaster) {
  19119. //getMouseIntersect
  19120. camera.updateMatrixWorld();
  19121. raycaster = new Raycaster();
  19122. var origin = new Vector3(pointer.x, pointer.y, -1).unproject(camera),
  19123. end = new Vector3(pointer.x, pointer.y, 1).unproject(camera);
  19124. var dir = end.sub(origin).normalize();
  19125. raycaster.set(origin, dir);
  19126. }
  19127. meshes.forEach(e => {
  19128. raycaster.layers.enable(math.getBaseLog(2, e.layers.mask));
  19129. });
  19130. var n = raycaster.intersectObjects(meshes);
  19131. if (0 === n.length) return null;
  19132. return n[0];
  19133. };
  19134. Utils.addOrRemoveDefine = function (material, defineName, type) {
  19135. var value = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
  19136. var defines = material.defines;
  19137. if (type == 'add') {
  19138. if (defines[defineName] != void 0 && defines[defineName] == value) return;
  19139. defines[defineName] = value;
  19140. } else {
  19141. if (defines[defineName] != void 0) return;
  19142. delete defines[defineName];
  19143. }
  19144. material.needsUpdate = true;
  19145. };
  19146. Utils.makeTexDontResize = function (map) {
  19147. //避免贴图因非2的次方而缩小。小心使用
  19148. if (!map || !map.image) {
  19149. return console.log('!map || !map.image', map, map && map.image);
  19150. }
  19151. if (MathUtils.isPowerOfTwo(map.image.width) && MathUtils.isPowerOfTwo(map.image.height)) return;
  19152. map.wrapS = map.wrapT = ClampToEdgeWrapping; //原默认 RepeatWrapping
  19153. map.minFilter = LinearFilter; // or THREE.NearestFilter 原默认 LinearMipmapLinearFilter
  19154. map.generateMipmaps = false;
  19155. map.needsUpdate = true;
  19156. };
  19157. Utils.updateVisible = function (object, reason, ifShow) {
  19158. var level = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
  19159. var type = arguments.length > 4 ? arguments[4] : undefined;
  19160. //当所有加入的条件都不为false时才显示. reason='force'一般是强制、临时的
  19161. if (!object.unvisibleReasons) object.unvisibleReasons = []; //如果length>0代表不可见
  19162. if (!object.visibleReasons) object.visibleReasons = []; //在同级时,优先可见
  19163. var update = function update() {
  19164. //先按从高到低的level排列
  19165. object.unvisibleReasons = object.unvisibleReasons.sort((a, b) => b.level - a.level);
  19166. object.visibleReasons = object.visibleReasons.sort((a, b) => b.level - a.level);
  19167. var maxVisiLevel = object.visibleReasons[0] ? object.visibleReasons[0].level : -1;
  19168. var maxunVisiLevel = object.unvisibleReasons[0] ? object.unvisibleReasons[0].level : -1;
  19169. var shouldVisi = maxVisiLevel >= maxunVisiLevel;
  19170. var visiBefore = object.visible;
  19171. if (visiBefore != shouldVisi) {
  19172. object.visible = shouldVisi;
  19173. object.dispatchEvent({
  19174. type: 'isVisible',
  19175. visible: shouldVisi,
  19176. reason
  19177. });
  19178. }
  19179. };
  19180. if (ifShow) {
  19181. var index = object.unvisibleReasons.findIndex(e => e.reason == reason);
  19182. if (index > -1) {
  19183. type = 'cancel';
  19184. object.unvisibleReasons.splice(index, 1);
  19185. }
  19186. if (type == 'add') {
  19187. if (!object.visibleReasons.some(e => e.reason == reason)) {
  19188. object.visibleReasons.push({
  19189. reason,
  19190. level
  19191. });
  19192. }
  19193. }
  19194. } else {
  19195. var index = object.visibleReasons.findIndex(e => e.reason == reason);
  19196. if (index > -1) {
  19197. type = 'cancel';
  19198. object.visibleReasons.splice(index, 1);
  19199. }
  19200. if (type != 'cancel') {
  19201. if (!object.unvisibleReasons.some(e => e.reason == reason)) {
  19202. object.unvisibleReasons.push({
  19203. reason,
  19204. level
  19205. });
  19206. }
  19207. }
  19208. }
  19209. update();
  19210. };
  19211. /*
  19212. 复杂案例: 如果物体默认隐藏, 当符合任何一个其他条件时可见,则可:
  19213. Potree.Utils.updateVisible(this, "default", false, 0 ) //默认隐藏
  19214. Potree.Utils.updateVisible(this, 条件名, ifShow, 1, ifShow?'add':'cancel' ) //其他的条件
  19215. */
  19216. Utils.getObjVisiByReason = function (object, reason) {
  19217. //获取在某条件下是否可见. 注: 用户在数据集选择可不可见为"datasetSelection"
  19218. if (object.visible) return true;else {
  19219. return !object.unvisibleReasons || !object.unvisibleReasons.some(e => e.reason == reason);
  19220. }
  19221. };
  19222. Utils.setCameraLayers = function (camera, enableLayers) {
  19223. var extraEnableLayers = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
  19224. //add
  19225. camera.layers.disableAll();
  19226. enableLayers.concat(extraEnableLayers).forEach(e => {
  19227. var layer = Potree.config.renderLayers[e];
  19228. if (layer == void 0) {
  19229. console.error('setCameraLayer没找到layer!');
  19230. return;
  19231. }
  19232. camera.layers.enable(layer);
  19233. });
  19234. };
  19235. Utils.setObjectLayers = function (object, layerName) {
  19236. //add
  19237. var layer = Potree.config.renderLayers[layerName];
  19238. if (layer == void 0) {
  19239. console.error('setObjectLayers没找到layer!', layerName);
  19240. return;
  19241. }
  19242. object.traverse(e => {
  19243. e.layers.set(layer);
  19244. });
  19245. };
  19246. Utils.imgAddText = async (img, text, labelInfo) => {
  19247. var label = new Potree.TextSprite(Object.assign({
  19248. //如果直接在canvas里写字,要另外写很多和canvas.drawText有关的,所以还是借助textSprite吧
  19249. backgroundColor: {
  19250. r: 0,
  19251. g: 0,
  19252. b: 0,
  19253. a: 0
  19254. },
  19255. textColor: {
  19256. r: 255,
  19257. g: 255,
  19258. b: 255,
  19259. a: 1
  19260. },
  19261. margin: {
  19262. x: 3,
  19263. y: 3
  19264. },
  19265. renderOrder: 50,
  19266. fontsize: 20,
  19267. text
  19268. }, labelInfo));
  19269. var labelImg = new Image();
  19270. labelImg.src = label.sprite.material.map.image.toDataURL('image/png');
  19271. return new Promise((resolve, reject) => {
  19272. labelImg.onload = () => {
  19273. if (labelInfo.horizonCenter) {
  19274. //水平居中(对img来说)
  19275. labelInfo.leftRatioToImg = 0.5 - labelImg.width / img.width / 2;
  19276. }
  19277. var result = Common.imgAddLabel(img, labelImg, labelInfo);
  19278. label.dispose();
  19279. resolve(result);
  19280. };
  19281. });
  19282. };
  19283. Utils.combineImgs = async (imgs, compressRatio, width, height) => {
  19284. //拼合图片,顺序从上到下从左到右, 每张图大小不一定一致,但同列的宽一致,同行宽一致
  19285. return new Promise((resolve, reject) => {
  19286. var item = imgs[0][0];
  19287. var wc = imgs.length,
  19288. hc = imgs[0].length,
  19289. loadCount = 0,
  19290. amount = wc * hc;
  19291. width = width || imgs.reduce((w, c) => w + c[0].width, 0),
  19292. //相加得到的可能比想要得到的大几个像素,之后会重叠
  19293. height = height || imgs[0].reduce((w, c) => w + c.height, 0);
  19294. var canvas = document.createElement('canvas');
  19295. canvas.width = width;
  19296. canvas.height = height;
  19297. var context = canvas.getContext('2d');
  19298. for (var i = 0; i < wc; i++) {
  19299. var _loop = function _loop() {
  19300. var img = new Image();
  19301. img.src = imgs[i][j].dataUrl;
  19302. img.index = {
  19303. i,
  19304. j
  19305. };
  19306. img.onload = () => {
  19307. loadCount++;
  19308. context.drawImage(img, img.index.i * img.width, img.index.j * img.height, img.width, img.height);
  19309. if (loadCount == amount) {
  19310. var dataUrl = canvas.toDataURL('image/png', compressRatio);
  19311. context.clearRect(0, 0, width, height);
  19312. resolve(dataUrl);
  19313. }
  19314. };
  19315. };
  19316. for (var j = 0; j < hc; j++) {
  19317. _loop();
  19318. }
  19319. }
  19320. });
  19321. };
  19322. BinaryLoader.prototype.load = function (node, callback) {
  19323. //解析点云
  19324. if (node.loaded) {
  19325. return;
  19326. }
  19327. var url = node.getURL();
  19328. if (this.version.equalOrHigher('1.4')) {
  19329. url += '.bin';
  19330. }
  19331. url += '?m=' + node.pcoGeometry.timeStamp; //add
  19332. var xhr = XHRFactory.createXMLHttpRequest();
  19333. xhr.open('GET', url, true);
  19334. xhr.responseType = 'arraybuffer';
  19335. xhr.overrideMimeType('text/plain; charset=x-user-defined');
  19336. xhr.onreadystatechange = () => {
  19337. if (xhr.readyState === 4) {
  19338. if ((xhr.status === 200 || xhr.status === 0) && xhr.response !== null) {
  19339. var buffer = xhr.response;
  19340. this.parse(node, buffer, callback);
  19341. } else {
  19342. node.loadFailed = 'status:' + xhr.status + ",url:" + url;
  19343. Potree.numNodesLoading--;
  19344. //console.error(`Failed to load file! HTTP status: ${xhr.status}, file: ${url}`);
  19345. throw new Error("Failed to load file! HTTP status: ".concat(xhr.status, ", file: ").concat(url));
  19346. }
  19347. }
  19348. };
  19349. try {
  19350. xhr.send(null);
  19351. } catch (e) {
  19352. node.loadFailed = 'catchError';
  19353. Potree.numNodesLoading--;
  19354. console.error('加载点云node出错 ', url, e);
  19355. }
  19356. };
  19357. PointAttribute.RGBA_PACKED = new PointAttribute("rgba", PointAttributeTypes.DATA_TYPE_INT8, 4);
  19358. PointAttribute.COLOR_PACKED = PointAttribute.RGBA_PACKED;
  19359. PointAttribute.INTENSITY = new PointAttribute("intensity", PointAttributeTypes.DATA_TYPE_UINT16, 1);
  19360. PointAttribute.CLASSIFICATION = new PointAttribute("classification", PointAttributeTypes.DATA_TYPE_UINT8, 1);
  19361. PointAttribute.GPS_TIME = new PointAttribute("gps-time", PointAttributeTypes.DATA_TYPE_DOUBLE, 1);
  19362. ProfileWindow.prototype.initTHREE = function () {
  19363. this.renderer = new WebGLRenderer({
  19364. alpha: true,
  19365. premultipliedAlpha: false
  19366. });
  19367. this.renderer.setClearColor(0x000000, 0);
  19368. this.renderer.setSize(10, 10);
  19369. this.renderer.autoClear = false;
  19370. this.renderArea.append($(this.renderer.domElement));
  19371. this.renderer.domElement.tabIndex = '2222';
  19372. $(this.renderer.domElement).css('width', '100%');
  19373. $(this.renderer.domElement).css('height', '100%');
  19374. {
  19375. var gl = this.renderer.getContext();
  19376. if (gl.createVertexArray == null) {
  19377. var extVAO = gl.getExtension('OES_vertex_array_object');
  19378. if (!extVAO) {
  19379. throw new Error("OES_vertex_array_object extension not supported");
  19380. }
  19381. gl.createVertexArray = extVAO.createVertexArrayOES.bind(extVAO);
  19382. gl.bindVertexArray = extVAO.bindVertexArrayOES.bind(extVAO);
  19383. }
  19384. }
  19385. this.camera = new OrthographicCamera(-1000, 1000, 1000, -1000, -1000, 1000);
  19386. this.camera.up.set(0, 0, 1);
  19387. this.camera.rotation.order = "ZXY";
  19388. this.camera.rotation.x = Math.PI / 2.0;
  19389. this.scene = new Scene();
  19390. this.profileScene = new Scene();
  19391. var sg = new SphereGeometry(1, 16, 16);
  19392. var sm = new MeshNormalMaterial();
  19393. this.pickSphere = new Mesh(sg, sm);
  19394. this.scene.add(this.pickSphere);
  19395. this.viewerPickSphere = new Mesh(sg, sm);
  19396. };
  19397. //Potree_update_visibility
  19398. Potree.updatePointClouds = function (pointclouds, camera, areaSize) {
  19399. viewer.addTimeMark('updateClouds', 'start');
  19400. for (var pointcloud of pointclouds) {
  19401. var start = performance.now();
  19402. for (var profileRequest of pointcloud.profileRequests) {
  19403. profileRequest.update();
  19404. var _duration = performance.now() - start;
  19405. if (_duration > 5) {
  19406. break;
  19407. }
  19408. }
  19409. var duration = performance.now() - start;
  19410. }
  19411. var result = Potree.updateVisibility(pointclouds, camera, areaSize);
  19412. for (var _pointcloud5 of pointclouds) {
  19413. //pointcloud.updateMaterial(pointcloud.material, pointcloud.visibleNodes, camera, renderer);//转移到渲染时
  19414. _pointcloud5.updateVisibleBounds();
  19415. }
  19416. Potree.lru.freeMemory(); //即Potree.lru 能看到所有在加载的node
  19417. viewer.addTimeMark('updateClouds', 'end');
  19418. return result;
  19419. };
  19420. Potree.updateVisibilityStructures = function (pointclouds, camera, areaSize) {
  19421. var frustums = {};
  19422. var camObjPositions = {};
  19423. var camObjDirs = {}; //add
  19424. var priorityQueue = new BinaryHeap(function (x) {
  19425. return -x.weight; /* 1 / x.weight; */
  19426. }); //二叉堆。 改,之前的weight不支持负数
  19427. viewer.addTimeMark('visiStructure', 'start');
  19428. //camera.updateMatrixWorld();
  19429. var viewI = camera.matrixWorldInverse;
  19430. var proj = camera.projectionMatrix;
  19431. var view = camera.matrixWorld;
  19432. var projViewI = new Matrix4().multiply(proj).multiply(viewI);
  19433. /* let list = pointclouds // stopWhenAllUsed = !viewer.lastFrameChanged
  19434. let min = 5, max = Math.max(20 , Math.round(list.length / 10 ))
  19435. let result = Common.batchHandling.getSlice('pcGetFrustum', list, { min,max, durBound1: 3, durBound2: 10} ) //iphonex稳定后大概在7-10。
  19436. */
  19437. for (var i = 0; i < pointclouds.length; i++) {
  19438. var pointcloud = pointclouds[i];
  19439. if (!pointcloud.initialized()) {
  19440. continue;
  19441. }
  19442. /* let info = history.get(pointcloud)
  19443. if() */
  19444. pointcloud.numVisibleNodes = 0;
  19445. pointcloud.numVisiblePoints = 0;
  19446. pointcloud.deepestVisibleLevel = 0;
  19447. pointcloud.visibleNodes = [];
  19448. pointcloud.visibleGeometry = [];
  19449. // 因漫游模式而隐藏的话 依旧需要加入visibleNodes,因为pick需要
  19450. /* if (pointcloud.visible && pointcloud.root !== null) {
  19451. priorityQueue.push({pointcloud: i, node: pointcloud.root, weight: Number.MAX_VALUE});
  19452. } */
  19453. if (pointcloud.visible || !pointcloud.hasDepthTex && pointcloud.unvisibleReasons && pointcloud.unvisibleReasons.length == 1 && pointcloud.unvisibleReasons[0].reason == 'displayMode' && pointcloud.root !== null) {
  19454. //改 visible ->
  19455. priorityQueue.push({
  19456. pointcloud: i,
  19457. node: pointcloud.root,
  19458. weight: Number.MAX_VALUE
  19459. });
  19460. } else {
  19461. continue;
  19462. }
  19463. // frustum in object space
  19464. var frustum = new Frustum();
  19465. var world = pointcloud.matrixWorld;
  19466. // use close near plane for frustum intersection
  19467. /* let frustumCam = camera.clone();
  19468. frustumCam.zoom = camera.zoom //add
  19469. frustumCam.near = Math.min(camera.near, 0.1);
  19470. frustumCam.updateProjectionMatrix(); */ //----没用到frustumCam,删了
  19471. var fm = new Matrix4().multiply(projViewI).multiply(world);
  19472. frustum.setFromProjectionMatrix(fm);
  19473. frustums[i] = frustum; //frustums.push(frustum);
  19474. // camera position in object space
  19475. var worldI = pointcloud.matrixWorldInverse;
  19476. var camMatrixObject = new Matrix4().multiply(worldI).multiply(view); //假设点云无变换的话,相机相对于点云的变换矩阵
  19477. var camObjPos = new Vector3().setFromMatrixPosition(camMatrixObject);
  19478. camObjPositions[i] = camObjPos; //camObjPositions.push(camObjPos);
  19479. var quaternion = new Quaternion().setFromRotationMatrix(camMatrixObject);
  19480. var camDir = new Vector3(0, 0, -1).applyQuaternion(quaternion);
  19481. camObjDirs[i] = camDir;
  19482. // hide all previously visible nodes
  19483. // if(pointcloud.root instanceof PointCloudOctreeNode){
  19484. // pointcloud.hideDescendants(pointcloud.root.sceneNode);
  19485. // }
  19486. if (pointcloud.root.isTreeNode()) {
  19487. pointcloud.hideDescendants(pointcloud.root.sceneNode);
  19488. }
  19489. for (var j = 0; j < pointcloud.boundingBoxNodes.length; j++) {
  19490. pointcloud.boundingBoxNodes[j].visible = false;
  19491. }
  19492. }
  19493. viewer.addTimeMark('visiStructure', 'end');
  19494. return {
  19495. 'frustums': frustums,
  19496. 'camObjPositions': camObjPositions,
  19497. 'priorityQueue': priorityQueue,
  19498. camObjDirs
  19499. };
  19500. };
  19501. Potree.updateVisibility = function (pointclouds, camera, areaSize) {
  19502. var numVisibleNodes = 0;
  19503. var numVisiblePoints = 0;
  19504. var numVisiblePointsInPointclouds = new Map(pointclouds.map(pc => [pc, 0]));
  19505. var visibleNodes = [];
  19506. var visibleGeometry = [];
  19507. var unloadedGeometry = [];
  19508. var lowestSpacing = Infinity;
  19509. // calculate object space frustum and cam pos and setup priority queue
  19510. var s = Potree.updateVisibilityStructures(pointclouds, camera, areaSize); //得到相机可见范围
  19511. var frustums = s.frustums;
  19512. var camObjPositions = s.camObjPositions;
  19513. var priorityQueue = s.priorityQueue;
  19514. var camObjDirs = s.camObjDirs;
  19515. var loadedToGPUThisFrame = 0;
  19516. var domWidth = areaSize.x; //renderer.domElement.clientWidth;
  19517. var domHeight = areaSize.y; //renderer.domElement.clientHeight;
  19518. var fov = camera.fov * Math.PI / 180;
  19519. var slope = Math.tan(fov / 2);
  19520. var projFactor0 = 0.5 * domHeight / slope;
  19521. // check if pointcloud has been transformed
  19522. // some code will only be executed if changes have been detected
  19523. if (!Potree._pointcloudTransformVersion) {
  19524. Potree._pointcloudTransformVersion = new Map();
  19525. }
  19526. var pointcloudTransformVersion = Potree._pointcloudTransformVersion;
  19527. for (var pointcloud of pointclouds) {
  19528. if (pointcloud.hasDepthTex ? !pointcloud.visible : !Potree.Utils.getObjVisiByReason(pointcloud, 'datasetSelection')) {
  19529. //改 visible ->
  19530. continue;
  19531. }
  19532. //if(!pointcloud.visible) continue
  19533. pointcloud.updateMatrixWorld();
  19534. if (!pointcloudTransformVersion.has(pointcloud)) {
  19535. pointcloudTransformVersion.set(pointcloud, {
  19536. number: 0,
  19537. transform: pointcloud.matrixWorld.clone()
  19538. });
  19539. } else {
  19540. var version = pointcloudTransformVersion.get(pointcloud);
  19541. if (!version.transform.equals(pointcloud.matrixWorld)) {
  19542. version.number++;
  19543. version.transform.copy(pointcloud.matrixWorld);
  19544. pointcloud.dispatchEvent({
  19545. type: "transformation_changed",
  19546. target: pointcloud
  19547. });
  19548. }
  19549. }
  19550. }
  19551. var _loop2 = function _loop2() {
  19552. var element = priorityQueue.pop(); //取出权重最大的一个
  19553. var node = element.node;
  19554. var parent = element.parent;
  19555. var pointcloud = pointclouds[element.pointcloud];
  19556. // { // restrict to certain nodes for debugging
  19557. // let allowedNodes = ["r", "r0", "r4"];
  19558. // if(!allowedNodes.includes(node.name)){
  19559. // continue;
  19560. // }
  19561. // }
  19562. var box = node.getBoundingBox();
  19563. var frustum = frustums[element.pointcloud];
  19564. var camObjPos = camObjPositions[element.pointcloud];
  19565. if (!frustum) return 0; // continue
  19566. //add
  19567. var camObjDir = camObjDirs[element.pointcloud];
  19568. var insideFrustum = frustum.intersectsBox(box);
  19569. var maxLevel = pointcloud.maxLevel == void 0 ? Infinity : pointcloud.maxLevel;
  19570. var minLevel = pointcloud.minLevel == void 0 ? 0 : pointcloud.minLevel; //add
  19571. var level = node.getLevel();
  19572. var visible = insideFrustum;
  19573. visible = visible && !(numVisiblePoints + node.getNumPoints() > Potree.pointBudget);
  19574. visible = visible && !(numVisiblePointsInPointclouds.get(pointcloud) + node.getNumPoints() > pointcloud.pointBudget); // pointcloud.pointBudget一直是Infinity
  19575. visible = visible && level <= maxLevel /* && level >= minLevel */; //< 改为 <=
  19576. //visible = visible || node.getLevel() <= 2;
  19577. var pcWorldInverse = pointcloud.matrixWorld.clone().invert();
  19578. /* let m = pcWorldInverse.elements
  19579. let pcWorldInvM3 = new THREE.Matrix3().set(m[0],m[4],m[12],m[1],m[5],m[13],m[3],m[7],m[15]) //去掉z的
  19580. */
  19581. //pointcloud.pcMatrix3 = new THREE.Matrix3().set(m[0],m[4],m[12],m[1],m[5],m[13],m[3],m[7],m[15]) //去掉z的
  19582. var intersectBox = clipBox => {
  19583. var toPCObject = pcWorldInverse.clone().multiply(clipBox.box.matrixWorld); //box乘上点云逆矩阵
  19584. return Potree.Utils.isIntersectBox(box, toPCObject);
  19585. };
  19586. //改 总共两种box : 可见和不可见(都是并集)
  19587. var clipBoxes_in = pointcloud.material.clipBoxes_in;
  19588. var clipBoxes_out = pointcloud.material.clipBoxes_out;
  19589. var bigClipInBox = pointcloud.material.bigClipInBox;
  19590. if (visible && bigClipInBox) {
  19591. //不在剪裁下载的框内
  19592. if (!intersectBox(bigClipInBox)) {
  19593. visible = false;
  19594. }
  19595. }
  19596. if (visible && clipBoxes_in.length > 0) {
  19597. //当有可见box时,需要在任一可见box内才可见
  19598. var visi = false;
  19599. for (var _i = 0, length = clipBoxes_in.length; _i < length; _i++) {
  19600. if (intersectBox(clipBoxes_in[_i])) {
  19601. visi = true;
  19602. break;
  19603. }
  19604. }
  19605. if (!visi) {
  19606. visible = false;
  19607. }
  19608. }
  19609. //outside不做处理。因为node必须完全在clipBox内才能完全隐藏,而这里的intersect只能识别出部分在clipBox内。因而只能说明不在任意一个box内绝对可见,没有意义,这里需要找出不可见的。
  19610. if (visible) {
  19611. var prism = pointcloud.material.activeAttributeName == 'prismHeight' && pointcloud.material.prisms && pointcloud.material.prisms.find(e => e.computing);
  19612. if (prism) {
  19613. var bound = box.clone().applyMatrix4(pointcloud.matrixWorld);
  19614. if (bound.intersectsBox(prism.prismBound)) {
  19615. /* //node box是否包含points中的一个点
  19616. let box2 = new THREE.Box2().copy(box)
  19617. let points2d = prisms.points.map(e=>new THREE.Vector2().copy(e).applyMatrix3(pcWorldInvM3))
  19618. let intersect = points2d.some(e=>{
  19619. return box2.containsPoint(e)
  19620. })
  19621. if(!intersect){
  19622. //或者多边形中是否包含node box中的一个点
  19623. intersect = [
  19624. new THREE.Vector2(box.min.x, box.min.y),
  19625. new THREE.Vector2(box.max.x, box.max.y),
  19626. new THREE.Vector2(box.min.x, box.max.y),
  19627. new THREE.Vector2(box.max.x, box.min.y),
  19628. ].some(e=>{
  19629. if(math.isPointInArea(points2d, null, e) ){
  19630. return true
  19631. }
  19632. })
  19633. //z是不是在外层已经判断好了?
  19634. if(!intersect){
  19635. visible = false
  19636. }
  19637. } */
  19638. //会有两个互不包含点但是交叉了的情况,所以就不仔细判断了(如横竖两个矩形构成十字架)
  19639. } else visible = false;
  19640. }
  19641. }
  19642. if (node.spacing) {
  19643. lowestSpacing = Math.min(lowestSpacing, node.spacing);
  19644. } else if (node.geometryNode && node.geometryNode.spacing) {
  19645. lowestSpacing = Math.min(lowestSpacing, node.geometryNode.spacing);
  19646. }
  19647. if (numVisiblePoints + node.getNumPoints() > Potree.pointBudget) {
  19648. viewer.dispatchEvent({
  19649. type: 'overPointBudget',
  19650. restQueueSize: priorityQueue.size(),
  19651. numVisiblePoints
  19652. });
  19653. return 1; // break
  19654. }
  19655. if (!visible) {
  19656. return 0; // continue
  19657. }
  19658. // TODO: not used, same as the declaration?
  19659. // numVisibleNodes++;
  19660. numVisiblePoints += node.getNumPoints();
  19661. var numVisiblePointsInPointcloud = numVisiblePointsInPointclouds.get(pointcloud);
  19662. numVisiblePointsInPointclouds.set(pointcloud, numVisiblePointsInPointcloud + node.getNumPoints());
  19663. pointcloud.numVisibleNodes++;
  19664. pointcloud.numVisiblePoints += node.getNumPoints();
  19665. if (node.isGeometryNode() && (!parent || parent.isTreeNode())) {
  19666. if (node.isLoaded() && loadedToGPUThisFrame < 2) {
  19667. node = pointcloud.toTreeNode(node, parent);
  19668. loadedToGPUThisFrame++;
  19669. } else {
  19670. //console.log('unloadedGeometry',node)
  19671. unloadedGeometry.push({
  19672. pointcloud,
  19673. node
  19674. }); //加载点云。虽然还没加载,但也计入了visibleNodes,只是无children,numPoints=0
  19675. visibleGeometry.push(node);
  19676. }
  19677. }
  19678. if (node.isTreeNode()) {
  19679. Potree.lru.touch(node.geometryNode); //在缓存中计入点云
  19680. node.sceneNode.visible = true;
  19681. node.sceneNode.material = pointcloud.material;
  19682. /* level >= minLevel && */
  19683. visibleNodes.push(node);
  19684. /* level >= minLevel && */
  19685. pointcloud.visibleNodes.push(node);
  19686. if (node._transformVersion === undefined) {
  19687. node._transformVersion = -1;
  19688. }
  19689. var transformVersion = pointcloudTransformVersion.get(pointcloud);
  19690. if (node._transformVersion !== transformVersion.number) {
  19691. node.sceneNode.updateMatrix();
  19692. //node.sceneNode.matrixWorld.multiplyMatrices(pointcloud.matrixWorld, node.sceneNode.matrix);
  19693. node.sceneNode.matrixWorld.multiplyMatrices(pointcloud.matrixWorld, node.sceneNode.matrix);
  19694. node._transformVersion = transformVersion.number;
  19695. }
  19696. if (pointcloud.showBoundingBox && !node.boundingBoxNode && node.getBoundingBox) {
  19697. var colorHue = level / (maxLevel + 1);
  19698. var _s = 0.1 + level / (maxLevel + 1);
  19699. var color = new Color().setHSL(colorHue, _s, _s);
  19700. var boxHelper = new Box3Helper$1(node.getBoundingBox(), color);
  19701. boxHelper.matrixAutoUpdate = false;
  19702. pointcloud.boundingBoxNodes.push(boxHelper);
  19703. node.boundingBoxNode = boxHelper;
  19704. node.boundingBoxNode.matrix.copy(pointcloud.matrixWorld);
  19705. } else if (pointcloud.showBoundingBox) {
  19706. node.boundingBoxNode.visible = true;
  19707. node.boundingBoxNode.matrix.copy(pointcloud.matrixWorld);
  19708. } else if (!pointcloud.showBoundingBox && node.boundingBoxNode) {
  19709. node.boundingBoxNode.visible = false;
  19710. }
  19711. // if(node.boundingBoxNode !== undefined && exports.debug.allowedNodes !== undefined){
  19712. // if(!exports.debug.allowedNodes.includes(node.name)){
  19713. // node.boundingBoxNode.visible = false;
  19714. // }
  19715. // }
  19716. }
  19717. // add child nodes to priorityQueue 由近及远、由大及小逐渐加载
  19718. var children = node.getChildren();
  19719. for (var _i2 = 0; _i2 < children.length; _i2++) {
  19720. var child = children[_i2];
  19721. var weight = 0;
  19722. if (camera.isPerspectiveCamera) {
  19723. var sphere = child.getBoundingSphere();
  19724. var center = sphere.center;
  19725. var dd = sphere.center.distanceToSquared(camObjPos);
  19726. var addPow = 0.2; //viewer.mainViewport.view.isFlying() ? 0 : 0.5 //0-0.5,正常原本是0. 数字越大近处加载越快。但会造成远处加载慢甚至因pointBudge限制不加载。 isFlying:漫游时需要尽量加载一下远处的点云
  19727. //addPow *= window.devicePixelRatio //devicePixelRatio高的手机需要优先加载最近的高级点云,减少远处的中高级点云。
  19728. var distance = Math.pow(dd, 0.5 + addPow); //Math.sqrt(dd); //提高距离权重,为了提高近处加载速度。 某些场景近处加载慢优化明显,如SS-t-cqCAL6rJ5i
  19729. //let attenuateDis = 10;//add
  19730. var radius = sphere.radius;
  19731. var projFactor = projFactor0 / distance;
  19732. var screenPixelRadius = radius * projFactor;
  19733. /* if(distance > attenuateDis){
  19734. screenPixelRadius -= (distance - attenuateDis) * Math.sqrt(radius) * projFactor0 * 0.002
  19735. } */
  19736. //screenPixelRadius 和 domHeight 成正比,所以手机横屏后screenPixelRadius会变小。这是正常的,因为vhov不变,相同物体高度在横屏后高度变小,所需要的密度不需要那么高了。但hfov横屏后扩大,所以可见的node范围变大,又增加了一些可见node;只是总体的可见node还是减少了。
  19737. //使用hfov和domWidth计算结果相同。
  19738. if (screenPixelRadius < pointcloud.minimumNodePixelSize / Math.pow(dd, addPow)) {
  19739. //理论上因手机像素小,更不容易堆叠铺满,minimumNodePixelSize应该除以window.deviceRatio 但会造成加载过多,而内存小
  19740. continue;
  19741. }
  19742. weight = screenPixelRadius;
  19743. if (!sphere.containsPoint(camObjPos)) {
  19744. //add 优先加载屏幕中央的点云(手机端缩小离远效果明显,不会那么稀疏)
  19745. var dir = new Vector3().subVectors(center, camObjPos).normalize();
  19746. var cos = 1 + dir.dot(camObjDir); //0-2
  19747. weight *= cos / 2; //Math.pow(cos,0.5) //幂越高,旁边的容易加载不到,出现缺块 如SS-t-7DUfWAUZ3V
  19748. }
  19749. if (distance - radius < 0) {
  19750. weight = Number.MAX_VALUE;
  19751. }
  19752. //如果能得到每个方向上的密度,也就是node数量,密度大的远处少加载,因为被遮挡了显示也没有意义,就好了。
  19753. } else {
  19754. // TODO ortho visibility
  19755. //let bb = child.getBoundingBox();
  19756. var _sphere = child.getBoundingSphere();
  19757. //let diagonal = bb.max.clone().sub(bb.min).length();
  19758. var reduce = 0; //0-0.5,正常原本是0.
  19759. if (_sphere.radius * /* Math.pow( */camera.zoom /* ,1-reduce) */ < pointcloud.minimumNodePixelSize) {
  19760. continue;
  19761. }
  19762. var _distance = _sphere.center.distanceToSquared(camObjPos); //先加载中间然后四周
  19763. weight = _sphere.radius / _distance;
  19764. /* let vec = new THREE.Vector3().subVectors(sphere.center, camObjPos)
  19765. let disOnCamDir = vec.dot(camObjDir)
  19766. let vecOnCamDir = camObjDir.clone().multiplyScalar(disOnCamDir)
  19767. let vecSide = new THREE.Vector3().subVectors(vec, vecOnCamDir) //在屏幕上从中心到该node的向量
  19768. let disSide = vecSide.length()
  19769. //weight = sphere.radius / disSide * camera.zoom - disOnCamDir * 2; //如果用除的,ortho的camera离远了的话dis的影响就小了
  19770. weight = sphere.radius / ( disSide * 0.1 + disOnCamDir * 14 )
  19771. */
  19772. //weight = diagonal;
  19773. }
  19774. priorityQueue.push({
  19775. pointcloud: element.pointcloud,
  19776. node: child,
  19777. parent: node,
  19778. weight: weight
  19779. }); //貌似好像二叉堆中子节点和父节点没什么关系,就只是为了方便排序层层遍历
  19780. }
  19781. //手机上像素点更小,所以远处感觉会更稀疏
  19782. },
  19783. _ret;
  19784. while (priorityQueue.size() > 0) {
  19785. _ret = _loop2();
  19786. if (_ret === 0) continue;
  19787. if (_ret === 1) break;
  19788. } // end priority queue loop
  19789. {
  19790. // update DEM 这是什么
  19791. var maxDEMLevel = 4;
  19792. var candidates = pointclouds.filter(p => p.generateDEM && p.dem instanceof Potree.DEM);
  19793. for (var _pointcloud6 of candidates) {
  19794. var updatingNodes = _pointcloud6.visibleNodes.filter(n => n.getLevel() <= maxDEMLevel);
  19795. _pointcloud6.dem.update(updatingNodes);
  19796. }
  19797. }
  19798. unloadedGeometry = unloadedGeometry.filter(e => !e.loadFailed); //过滤加载失败的,否则有失败的就无法发送加载完成
  19799. if (unloadedGeometry.length) {
  19800. //加载点云
  19801. var maxNodesLoading = Common.getBestCount('unloadedGeometry', viewer.lastFrameChanged ? 1 : 3, 6, 4, 15 /* , true */); //dur在iphoneX中静止有7,pc是2 //!lastFrameChanged静止时加速下载
  19802. //THREE.Math.clamp(Math.round(9 - dur), 1, 6 )
  19803. //console.log('unloadedGeometry', unloadedGeometry.length)
  19804. //主要在手机端有效果。不改之前在展示的点云较多时前进会卡。
  19805. for (var i = 0; i < Math.min(maxNodesLoading, unloadedGeometry.length); i++) {
  19806. unloadedGeometry[i].node.load(unloadedGeometry[i].pointcloud.pcoGeometry);
  19807. }
  19808. if (!Potree.pointsLoading) {
  19809. Potree.pointsLoading = true;
  19810. //console.log('startLoad')
  19811. viewer.dispatchEvent('startLoadPoints');
  19812. }
  19813. } else {
  19814. if (Potree.pointsLoading) {
  19815. Potree.pointsLoading = false;
  19816. //console.log('load done!')
  19817. setTimeout(() => {
  19818. Potree.pointsLoading || viewer.dispatchEvent('pointsLoaded');
  19819. }, document.hidden ? 3000 : 50); //hidden时可能好几秒才更新一次,所以这个并不准
  19820. }
  19821. }
  19822. Potree.unloadedGeometry = unloadedGeometry;
  19823. //add:
  19824. Potree.numVisiblePoints = numVisiblePoints;
  19825. return {
  19826. visibleNodes: visibleNodes,
  19827. numVisiblePoints: numVisiblePoints,
  19828. lowestSpacing: lowestSpacing
  19829. };
  19830. };
  19831. Potree.numVisiblePoints = 0;
  19832. /*
  19833. note:
  19834. 缓存中的点数 Potree.lru.numPoints 一般会 大于 每个点云显示点总数的numVisiblePoints
  19835. 当超出缓冲区最大点云数时,加载的点云节点会被dispose彻底消除;否则,隐藏的节点就会等待再次被使用显示
  19836. 由于加载按照由近及远、由大及小的顺序,要降低卡顿,就只需要降低Potree.pointBudget即可。但目前只设置了三个层次;另外提供maxLevel细节调节,能显示更均匀. 最好多一个调节pointBudge的滑动条
  19837. Potree.lru.numPoints
  19838. Potree.numVisiblePoints
  19839. viewer.scene.pointclouds[0].visibleNodes.length
  19840. */
  19841. {
  19842. //HQSplatRenderer
  19843. var oldInit = HQSplatRenderer.prototype.init;
  19844. HQSplatRenderer.prototype.init = function () {
  19845. oldInit();
  19846. viewer.addEventListener('resize', this.resize.bind(this));
  19847. };
  19848. HQSplatRenderer.prototype.resize = function (e) {
  19849. this.rtDepth.setSize(e.canvasWidth, e.canvasHeight);
  19850. this.rtAttribute.setSize(e.canvasWidth, e.canvasHeight);
  19851. };
  19852. HQSplatRenderer.prototype.clear = function () {
  19853. var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  19854. this.init();
  19855. var {
  19856. renderer,
  19857. background
  19858. } = this.viewer;
  19859. if (background === "skybox") {
  19860. renderer.setClearColor(0x000000, 0);
  19861. } else if (background === 'gradient') {
  19862. renderer.setClearColor(0x000000, 0);
  19863. } else if (background === 'black') {
  19864. renderer.setClearColor(0x000000, 1);
  19865. } else if (background === 'white') {
  19866. renderer.setClearColor(0xFFFFFF, 1);
  19867. } else {
  19868. renderer.setClearColor(0x000000, 0);
  19869. }
  19870. params.target || renderer.clear();
  19871. this.clearTargets(params);
  19872. };
  19873. HQSplatRenderer.prototype.render = function () {
  19874. var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  19875. this.init();
  19876. var viewer = this.viewer;
  19877. var camera = params.camera ? params.camera : viewer.scene.getActiveCamera();
  19878. var {
  19879. width,
  19880. height
  19881. } = params.width ? params : this.viewer.renderer.getSize(new Vector2());
  19882. viewer.renderer.setRenderTarget(params.target || null);
  19883. viewer.dispatchEvent({
  19884. type: "render.pass.begin",
  19885. viewer: viewer
  19886. });
  19887. //params.target || this.resize(width, height);
  19888. var visiblePointClouds = viewer.scene.pointclouds.filter(pc => pc.visible);
  19889. var originalMaterials = new Map();
  19890. for (var pointcloud of visiblePointClouds) {
  19891. originalMaterials.set(pointcloud, pointcloud.material);
  19892. if (!this.attributeMaterials.has(pointcloud)) {
  19893. var attributeMaterial = new ExtendPointCloudMaterial();
  19894. this.attributeMaterials.set(pointcloud, attributeMaterial);
  19895. }
  19896. if (!this.depthMaterials.has(pointcloud)) {
  19897. var depthMaterial = new ExtendPointCloudMaterial();
  19898. depthMaterial.setDefine("depth_pass", "#define hq_depth_pass");
  19899. depthMaterial.setDefine("use_edl", "#define use_edl");
  19900. this.depthMaterials.set(pointcloud, depthMaterial);
  19901. }
  19902. }
  19903. {
  19904. // DEPTH PASS
  19905. for (var _pointcloud7 of visiblePointClouds) {
  19906. var octreeSize = _pointcloud7.pcoGeometry.boundingBox.getSize(new Vector3()).x;
  19907. var material = originalMaterials.get(_pointcloud7);
  19908. var _depthMaterial = this.depthMaterials.get(_pointcloud7);
  19909. _depthMaterial.size = material.size;
  19910. _depthMaterial.minSize = material.minSize;
  19911. _depthMaterial.maxSize = material.maxSize;
  19912. _depthMaterial.pointSizeType = material.pointSizeType;
  19913. _depthMaterial.visibleNodesTexture = material.visibleNodesTexture;
  19914. _depthMaterial.weighted = false;
  19915. _depthMaterial.screenWidth = width;
  19916. _depthMaterial.shape = PointShape.CIRCLE;
  19917. _depthMaterial.screenHeight = height;
  19918. _depthMaterial.uniforms.visibleNodes.value = material.visibleNodesTexture;
  19919. _depthMaterial.uniforms.octreeSize.value = octreeSize;
  19920. _depthMaterial.spacing = _pointcloud7.pcoGeometry.spacing; // * Math.max(...pointcloud.scale.toArray());
  19921. _depthMaterial.classification = material.classification;
  19922. _depthMaterial.uniforms.classificationLUT.value.image.data = material.uniforms.classificationLUT.value.image.data;
  19923. _depthMaterial.classificationTexture.needsUpdate = true;
  19924. _depthMaterial.uniforms.uFilterReturnNumberRange.value = material.uniforms.uFilterReturnNumberRange.value;
  19925. _depthMaterial.uniforms.uFilterNumberOfReturnsRange.value = material.uniforms.uFilterNumberOfReturnsRange.value;
  19926. _depthMaterial.uniforms.uFilterGPSTimeClipRange.value = material.uniforms.uFilterGPSTimeClipRange.value;
  19927. _depthMaterial.uniforms.uFilterPointSourceIDClipRange.value = material.uniforms.uFilterPointSourceIDClipRange.value;
  19928. _depthMaterial.clipTask = material.clipTask;
  19929. _depthMaterial.clipMethod = material.clipMethod;
  19930. _depthMaterial.setClipBoxes(material.clipBoxes);
  19931. _depthMaterial.setClipPolygons(material.clipPolygons);
  19932. _pointcloud7.material = _depthMaterial;
  19933. }
  19934. viewer.pRenderer.render(viewer.scene.scenePointCloud, camera, params.rtEDL || this.rtDepth, {
  19935. clipSpheres: viewer.scene.volumes.filter(v => v instanceof SphereVolume)
  19936. });
  19937. }
  19938. {
  19939. // ATTRIBUTE PASS
  19940. for (var _pointcloud8 of visiblePointClouds) {
  19941. var _octreeSize = _pointcloud8.pcoGeometry.boundingBox.getSize(new Vector3()).x;
  19942. var _material = originalMaterials.get(_pointcloud8);
  19943. var _attributeMaterial = this.attributeMaterials.get(_pointcloud8);
  19944. _attributeMaterial.size = _material.size;
  19945. _attributeMaterial.minSize = _material.minSize;
  19946. _attributeMaterial.maxSize = _material.maxSize;
  19947. _attributeMaterial.pointSizeType = _material.pointSizeType;
  19948. _attributeMaterial.activeAttributeName = _material.activeAttributeName;
  19949. _attributeMaterial.visibleNodesTexture = _material.visibleNodesTexture;
  19950. _attributeMaterial.weighted = true;
  19951. _attributeMaterial.screenWidth = width;
  19952. _attributeMaterial.screenHeight = height;
  19953. _attributeMaterial.shape = PointShape.CIRCLE;
  19954. _attributeMaterial.uniforms.visibleNodes.value = _material.visibleNodesTexture;
  19955. _attributeMaterial.uniforms.octreeSize.value = _octreeSize;
  19956. _attributeMaterial.spacing = _pointcloud8.pcoGeometry.spacing; // * Math.max(...pointcloud.scale.toArray());
  19957. _attributeMaterial.classification = _material.classification;
  19958. _attributeMaterial.uniforms.classificationLUT.value.image.data = _material.uniforms.classificationLUT.value.image.data;
  19959. _attributeMaterial.classificationTexture.needsUpdate = true;
  19960. _attributeMaterial.uniforms.uFilterReturnNumberRange.value = _material.uniforms.uFilterReturnNumberRange.value;
  19961. _attributeMaterial.uniforms.uFilterNumberOfReturnsRange.value = _material.uniforms.uFilterNumberOfReturnsRange.value;
  19962. _attributeMaterial.uniforms.uFilterGPSTimeClipRange.value = _material.uniforms.uFilterGPSTimeClipRange.value;
  19963. _attributeMaterial.uniforms.uFilterPointSourceIDClipRange.value = _material.uniforms.uFilterPointSourceIDClipRange.value;
  19964. _attributeMaterial.elevationGradientRepeat = _material.elevationGradientRepeat;
  19965. _attributeMaterial.elevationRange = _material.elevationRange;
  19966. _attributeMaterial.gradient = _material.gradient;
  19967. _attributeMaterial.matcap = _material.matcap;
  19968. _attributeMaterial.intensityRange = _material.intensityRange;
  19969. _attributeMaterial.intensityGamma = _material.intensityGamma;
  19970. _attributeMaterial.intensityContrast = _material.intensityContrast;
  19971. _attributeMaterial.intensityBrightness = _material.intensityBrightness;
  19972. _attributeMaterial.rgbGamma = _material.rgbGamma;
  19973. _attributeMaterial.rgbContrast = _material.rgbContrast;
  19974. _attributeMaterial.rgbBrightness = _material.rgbBrightness;
  19975. _attributeMaterial.weightRGB = _material.weightRGB;
  19976. _attributeMaterial.weightIntensity = _material.weightIntensity;
  19977. _attributeMaterial.weightElevation = _material.weightElevation;
  19978. _attributeMaterial.weightRGB = _material.weightRGB;
  19979. _attributeMaterial.weightClassification = _material.weightClassification;
  19980. _attributeMaterial.weightReturnNumber = _material.weightReturnNumber;
  19981. _attributeMaterial.weightSourceID = _material.weightSourceID;
  19982. _attributeMaterial.color = _material.color;
  19983. _attributeMaterial.clipTask = _material.clipTask;
  19984. _attributeMaterial.clipMethod = _material.clipMethod;
  19985. _attributeMaterial.setClipBoxes(_material.clipBoxes);
  19986. _attributeMaterial.setClipPolygons(_material.clipPolygons);
  19987. _pointcloud8.material = _attributeMaterial;
  19988. }
  19989. var gl = this.gl;
  19990. //viewer.renderer.setRenderTarget(null);
  19991. viewer.pRenderer.render(viewer.scene.scenePointCloud, camera, this.rtAttribute, {
  19992. clipSpheres: viewer.scene.volumes.filter(v => v instanceof SphereVolume),
  19993. //material: this.attributeMaterial,
  19994. blendFunc: [gl.SRC_ALPHA, gl.ONE],
  19995. //depthTest: false,
  19996. depthWrite: false
  19997. });
  19998. }
  19999. for (var [_pointcloud9, _material2] of originalMaterials) {
  20000. _pointcloud9.material = _material2;
  20001. }
  20002. if (viewer.background === "skybox") {
  20003. viewer.renderer.setClearColor(0x000000, 0);
  20004. viewer.renderer.clear();
  20005. viewer.skybox.camera.rotation.copy(viewer.scene.cameraP.rotation);
  20006. viewer.skybox.camera.fov = viewer.scene.cameraP.fov;
  20007. viewer.skybox.camera.aspect = viewer.scene.cameraP.aspect;
  20008. viewer.skybox.parent.rotation.x = 0;
  20009. viewer.skybox.parent.updateMatrixWorld();
  20010. viewer.skybox.camera.updateProjectionMatrix();
  20011. viewer.renderer.render(viewer.skybox.scene, viewer.skybox.camera);
  20012. } else if (viewer.background === 'gradient') {
  20013. viewer.renderer.setClearColor(0x000000, 0);
  20014. viewer.renderer.clear();
  20015. viewer.renderer.render(viewer.scene.sceneBG, viewer.scene.cameraBG);
  20016. } else if (viewer.background === 'black') {
  20017. viewer.renderer.setClearColor(0x000000, 1);
  20018. viewer.renderer.clear();
  20019. } else if (viewer.background === 'white') {
  20020. viewer.renderer.setClearColor(0xFFFFFF, 1);
  20021. viewer.renderer.clear();
  20022. } else {
  20023. viewer.renderer.setClearColor(0x000000, 0);
  20024. viewer.renderer.clear();
  20025. }
  20026. {
  20027. // NORMALIZATION PASS
  20028. var normalizationMaterial = this.useEDL ? this.normalizationEDLMaterial : this.normalizationMaterial;
  20029. if (this.useEDL) {
  20030. normalizationMaterial.uniforms.edlStrength.value = viewer.edlStrength;
  20031. normalizationMaterial.uniforms.radius.value = viewer.edlRadius;
  20032. normalizationMaterial.uniforms.screenWidth.value = width;
  20033. normalizationMaterial.uniforms.screenHeight.value = height;
  20034. normalizationMaterial.uniforms.uEDLMap.value = (params.rtEDL || this.rtDepth).texture;
  20035. }
  20036. normalizationMaterial.uniforms.uWeightMap.value = this.rtAttribute.texture;
  20037. normalizationMaterial.uniforms.uDepthMap.value = this.rtAttribute.depthTexture;
  20038. Utils.screenPass.render(viewer.renderer, normalizationMaterial);
  20039. }
  20040. viewer.renderer.render(viewer.scene.scene, camera);
  20041. viewer.dispatchEvent({
  20042. type: "render.pass.scene",
  20043. viewer: viewer
  20044. });
  20045. viewer.renderer.render(viewer.scene.sceneOverlay, camera); // add 透明贴图层
  20046. viewer.renderer.clearDepth();
  20047. viewer.transformationTool.update();
  20048. if (!params.target) {
  20049. //测量线
  20050. viewer.dispatchEvent({
  20051. type: "render.pass.perspective_overlay",
  20052. viewer: viewer,
  20053. camera
  20054. });
  20055. viewer.renderer.render(viewer.overlay, camera); //从 viewer.renderDefault搬过来,为了reticule不遮住测量线
  20056. }
  20057. viewer.renderer.render(viewer.controls.sceneControls, camera);
  20058. viewer.renderer.render(viewer.clippingTool.sceneVolume, camera);
  20059. viewer.renderer.render(viewer.transformationTool.scene, camera);
  20060. viewer.renderer.setViewport(width - viewer.navigationCube.width, height - viewer.navigationCube.width, viewer.navigationCube.width, viewer.navigationCube.width);
  20061. viewer.renderer.render(viewer.navigationCube, viewer.navigationCube.camera);
  20062. viewer.renderer.setViewport(0, 0, width, height);
  20063. viewer.dispatchEvent({
  20064. type: "render.pass.end",
  20065. viewer: viewer
  20066. });
  20067. viewer.renderer.setRenderTarget(null);
  20068. };
  20069. }
  20070. //PointCloudOctreeGeometry.js
  20071. PointCloudOctreeGeometryNode.prototype.loadHierachyThenPoints = function (pointcloud) {
  20072. var node = this;
  20073. // load hierarchy
  20074. var callback = function callback(node, hbuffer) {
  20075. var tStart = performance.now();
  20076. var view = new DataView(hbuffer);
  20077. var stack = [];
  20078. var children = view.getUint8(0);
  20079. var numPoints = view.getUint32(1, true);
  20080. node.numPoints = numPoints;
  20081. stack.push({
  20082. children: children,
  20083. numPoints: numPoints,
  20084. name: node.name
  20085. });
  20086. var decoded = [];
  20087. var offset = 5;
  20088. while (stack.length > 0) {
  20089. var snode = stack.shift();
  20090. var mask = 1;
  20091. for (var i = 0; i < 8; i++) {
  20092. if ((snode.children & mask) !== 0) {
  20093. var childName = snode.name + i;
  20094. var childChildren = view.getUint8(offset);
  20095. var childNumPoints = view.getUint32(offset + 1, true);
  20096. stack.push({
  20097. children: childChildren,
  20098. numPoints: childNumPoints,
  20099. name: childName
  20100. });
  20101. decoded.push({
  20102. children: childChildren,
  20103. numPoints: childNumPoints,
  20104. name: childName
  20105. });
  20106. offset += 5;
  20107. }
  20108. mask = mask * 2;
  20109. }
  20110. if (offset === hbuffer.byteLength) {
  20111. break;
  20112. }
  20113. }
  20114. // console.log(decoded);
  20115. var nodes = {};
  20116. nodes[node.name] = node;
  20117. var pco = node.pcoGeometry;
  20118. var maxLevel_ = 0;
  20119. for (var _i3 = 0; _i3 < decoded.length; _i3++) {
  20120. var name = decoded[_i3].name;
  20121. var decodedNumPoints = decoded[_i3].numPoints;
  20122. var index = parseInt(name.charAt(name.length - 1));
  20123. var parentName = name.substring(0, name.length - 1);
  20124. var parentNode = nodes[parentName];
  20125. var level = name.length - 1;
  20126. maxLevel_ = Math.max(maxLevel_, level); //add
  20127. var boundingBox = Utils.createChildAABB(parentNode.boundingBox, index);
  20128. var currentNode = new PointCloudOctreeGeometryNode(name, pco, boundingBox);
  20129. currentNode.level = level;
  20130. currentNode.numPoints = decodedNumPoints;
  20131. currentNode.hasChildren = decoded[_i3].children > 0;
  20132. currentNode.spacing = pco.spacing / Math.pow(2, level);
  20133. parentNode.addChild(currentNode);
  20134. nodes[name] = currentNode;
  20135. }
  20136. pco.dispatchEvent({
  20137. type: 'updateNodeMaxLevel',
  20138. level: maxLevel_
  20139. }); //add
  20140. var duration = performance.now() - tStart;
  20141. if (duration > 5) {
  20142. /* let msg = `duration: ${duration}ms, numNodes: ${decoded.length}`;
  20143. console.log(msg); */
  20144. }
  20145. node.loadPoints();
  20146. };
  20147. if (node.level % node.pcoGeometry.hierarchyStepSize === 0) {
  20148. // let hurl = node.pcoGeometry.octreeDir + "/../hierarchy/" + node.name + ".hrc";
  20149. var hurl = node.pcoGeometry.octreeDir + '/' + node.getHierarchyPath() + '/' + node.name + '.hrc';
  20150. hurl += '?m=' + node.pcoGeometry.timeStamp; //add
  20151. var xhr = XHRFactory.createXMLHttpRequest();
  20152. xhr.open('GET', hurl, true);
  20153. xhr.responseType = 'arraybuffer';
  20154. xhr.overrideMimeType('text/plain; charset=x-user-defined');
  20155. xhr.onreadystatechange = () => {
  20156. if (xhr.readyState === 4) {
  20157. if (xhr.status === 200 || xhr.status === 0) {
  20158. var hbuffer = xhr.response;
  20159. callback(node, hbuffer);
  20160. } else {
  20161. console.log('Failed to load file! HTTP status: ' + xhr.status + ', file: ' + hurl);
  20162. Potree.numNodesLoading--;
  20163. }
  20164. }
  20165. };
  20166. try {
  20167. xhr.send(null);
  20168. } catch (e) {
  20169. console.log('fehler beim laden der punktwolke: ' + e);
  20170. }
  20171. }
  20172. };
  20173. PointCloudOctreeGeometryNode.prototype.loadPoints = function () {
  20174. var name = this.name;
  20175. this.pcoGeometry.loader.load(this, () => {
  20176. //callback
  20177. viewer.dispatchEvent('pointcloud_changed');
  20178. //console.log('loadPoints success ', name)
  20179. });
  20180. };
  20181. //加载点云成功->准备渲染画面->更新点云可见性updateVisibility->请求加载新的点云
  20182. PointCloudOctreeGeometryNode.prototype.traverse = function (t, e) {
  20183. //add from navvis 25.js
  20184. void 0 === e && (e = !0);
  20185. for (var n, i = e ? [this] : []; void 0 !== (n = i.pop());) {
  20186. t(n);
  20187. for (var o = 0, r = n.children; o < r.length; o++) {
  20188. var a = r[o];
  20189. null !== a && i.push(a);
  20190. }
  20191. }
  20192. };
  20193. Object.assign(PointCloudOctreeGeometry.prototype, EventDispatcher.prototype);
  20194. LRU.prototype.freeMemory = function () {
  20195. if (this.elements <= 1) {
  20196. return;
  20197. }
  20198. var memoryRatio = browser.isMobile() ? 2 : 5;
  20199. //改成navvis的,使用pointBudget,否则四屏点云闪烁。 (似乎要比updateVisiblede的node时限制要宽些,作为缓存继续存着。否则会闪烁)
  20200. var max = MathUtils.clamp(viewer.viewports.length * memoryRatio * Potree.pointBudget, 0, 40e6);
  20201. for (; this.numPoints > max;) {
  20202. var node = this.getLRUItem();
  20203. node && this.disposeDescendants(node);
  20204. }
  20205. };
  20206. VolumeTool.prototype.update = function () {};
  20207. VolumeTool.prototype.startInsertion = function () {
  20208. var args = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  20209. var volume;
  20210. if (args.type) {
  20211. volume = new args.type();
  20212. } else {
  20213. volume = new Potree.BoxVolume(Object.assign(args, {
  20214. clip: true
  20215. }));
  20216. }
  20217. volume.highlight = true;
  20218. volume.name = args.name || 'Volume-' + args.clipTask;
  20219. volume.isNew = true;
  20220. viewer.transformObject(null); //先清空
  20221. //console.log('startInsertion',volume.uuid)
  20222. var oldVisiBoxes;
  20223. if (args.clipTask == Potree.ClipTask.SHOW_INSIDE) {
  20224. //如果是显示类型,需要将所有同类型的解除效果,否则看不到效果。 (或者可以在添加非第一个时去除highlight效果,会更自然,但看不清全貌)
  20225. oldVisiBoxes = viewer.scene.volumes.filter(v => v.clipTask == Potree.ClipTask.SHOW_INSIDE && !v.highlight);
  20226. oldVisiBoxes.forEach(box => box.highlight = true);
  20227. }
  20228. var updatePose = () => {
  20229. //保证在视野中的大小一致:
  20230. var camera = this.viewer.scene.getActiveCamera();
  20231. var w = math.getScaleForConstantSize({
  20232. width2d: 300,
  20233. camera,
  20234. position: volume.getWorldPosition(new Vector3()),
  20235. resolution: viewer.mainViewport.resolution //2
  20236. });
  20237. /* let wp = volume.getWorldPosition(new THREE.Vector3()).applyMatrix4(camera.matrixWorldInverse);
  20238. // let pp = new THREE.Vector4(wp.x, wp.y, wp.z).applyMatrix4(camera.projectionMatrix);
  20239. let w = Math.abs((wp.z / 3));*/
  20240. if (!isNaN(w)) volume.scale.set(w, w, w);
  20241. {
  20242. //使水平朝向与camera一致
  20243. var direction = viewer.mainViewport.view.direction.setZ(0);
  20244. volume.quaternion.copy(math.getQuaByAim(direction));
  20245. }
  20246. };
  20247. this.dispatchEvent({
  20248. type: 'start_inserting_volume',
  20249. volume: volume
  20250. });
  20251. updatePose();
  20252. this.viewer.scene.addVolume(volume);
  20253. this.scene.add(volume);
  20254. var drag = e => {
  20255. if (e.hoverViewport.name == 'mapViewport') return;
  20256. var I = Utils.getMousePointCloudIntersection(viewer.mainViewport, viewer.inputHandler.mouse, viewer.inputHandler.pointer, this.viewer.scene.getActiveCamera(), this.viewer, this.viewer.scene.pointclouds, {
  20257. pickClipped: args.clipTask == Potree.ClipTask.SHOW_OUTSIDE
  20258. } //无视clip状态
  20259. );
  20260. var worldPos = I && I.location;
  20261. if (!worldPos) {
  20262. return;
  20263. }
  20264. volume.position.copy(worldPos);
  20265. updatePose();
  20266. };
  20267. var cancel = () => {
  20268. end('remove');
  20269. };
  20270. var end = e => {
  20271. if (e.button == MOUSE.RIGHT && e.pressDistance <= Potree.config.clickMaxDragDis) {
  20272. //remove
  20273. e = 'remove';
  20274. }
  20275. //console.log('end',volume.uuid, e)
  20276. if (e != 'remove' && (!e.isAtDomElement || e.pressDistance > Potree.config.clickMaxDragDis)) return continueDrag();
  20277. volume.removeEventListener('drag', drag);
  20278. volume.removeEventListener('drop', end);
  20279. this.viewer.removeEventListener('cancel_insertions', cancel);
  20280. volume.isNew = false;
  20281. viewer.removeEventListener('camera_changed', updatePose);
  20282. if (e == 'remove') {
  20283. viewer.scene.removeVolume(volume); //删除没完成的
  20284. } else {
  20285. viewer.transformObject(volume);
  20286. volume.highlight = false;
  20287. }
  20288. volume.dispatchEvent({
  20289. type: 'createFinish',
  20290. success: e != 'remove'
  20291. });
  20292. oldVisiBoxes && oldVisiBoxes.forEach(box => box.highlight = false);
  20293. };
  20294. var continueDrag = () => {
  20295. //console.log('continueDrag',volume.uuid )
  20296. var timer = setTimeout(() => {
  20297. //等 drag=null之后 //右键拖拽结束后需要重新得到drag
  20298. if (volume.parent && volume.isNew) {
  20299. viewer.inputHandler.startDragging(volume, {
  20300. notPressMouse: true
  20301. }
  20302. /* {endDragFun: e.drag.endDragFun, notPressMouse:e.drag.notPressMouse, dragViewport:e.drag.dragViewport} */);
  20303. }
  20304. }, 1);
  20305. return timer;
  20306. };
  20307. volume.addEventListener('drag', drag);
  20308. volume.addEventListener('drop', end);
  20309. this.viewer.addEventListener('cancel_insertions', cancel);
  20310. viewer.addEventListener('camera_changed', updatePose);
  20311. this.viewer.inputHandler.startDragging(volume, {
  20312. notPressMouse: true
  20313. });
  20314. return volume;
  20315. };
  20316. LineGeometry.prototype.setPositions = function (array) {
  20317. //xzw改成类似LineSegments的多段线 (第二个点和第三个点之间是没有线段的, 所以不用在意线段顺序)
  20318. var points = new Float32Array(array);
  20319. LineSegmentsGeometry.prototype.setPositions.call(this, points);
  20320. return this;
  20321. };
  20322. Object.assign(ExtendView.prototype, EventDispatcher.prototype);
  20323. Object.assign(ExtendScene.prototype, EventDispatcher.prototype);
  20324. function start(dom, mapDom, number) {
  20325. //t-Zvd3w0m
  20326. /* {
  20327. let obj = JSON.parse(localStorage.getItem('setting'))
  20328. for(let i in obj){
  20329. console.log(i + ': ' + obj[i])
  20330. }
  20331. }
  20332. */
  20333. Potree.settings.number = number || 't-o5YMR13'; // 't-iksBApb'// 写在viewer前
  20334. if (!Potree.settings.isOfficial) {
  20335. if ( /* Potree.settings.isTest && */browser.isMobile()) {
  20336. changeLog();
  20337. }
  20338. }
  20339. if (browser.urlHasValue('google')) Potree.settings.mapCompany = 'google';
  20340. if (browser.urlHasValue('timing')) Potree.measureTimings = 1;
  20341. var viewer = new Potree.Viewer(dom, mapDom);
  20342. /* viewer.addEventListener('allLoaded',()=>{
  20343. const baseGeometry = new THREE.BufferGeometry();
  20344. baseGeometry.setIndex([0, 1, 2, 0, 2, 3]);
  20345. const positionsArray = new Float32Array(4 * 3);
  20346. const positions = new THREE.BufferAttribute(positionsArray, 3);
  20347. baseGeometry.setAttribute('position', positions);
  20348. positions.setXYZ(0, -1.0, -1.0, 0.0);
  20349. positions.setXYZ(1, -1.0, 1.0, 0.0);
  20350. positions.setXYZ(2, 1.0, 1.0, 0.0);
  20351. positions.setXYZ(3, 1.0, -1.0, 0.0);
  20352. positions.needsUpdate = true;
  20353. const geometry = new THREE.InstancedBufferGeometry().copy(baseGeometry);
  20354. let maxSplatCount = 8
  20355. // Splat index buffer
  20356. const splatIndexArray = new Uint32Array(maxSplatCount);
  20357. const splatIndexes = new THREE.InstancedBufferAttribute(splatIndexArray, 1, false);
  20358. splatIndexes.setUsage(THREE.DynamicDrawUsage);
  20359. geometry.setAttribute('splatIndex', splatIndexes);
  20360. const splatPosArray = new Float32Array(maxSplatCount*3);
  20361. const splatPoses = new THREE.InstancedBufferAttribute(splatPosArray, 3, false);
  20362. splatPoses.setUsage(THREE.DynamicDrawUsage);
  20363. geometry.setAttribute('splatCenter', splatPoses);
  20364. splatPosArray.set([0,0,0,
  20365. 1,1,1,
  20366. 2,2,2,
  20367. 3,3,3,
  20368. 4,4,4,
  20369. 5,5,5,
  20370. 6,6,6,
  20371. 7,7,7])
  20372. let vertexShaderSource = `
  20373. precision highp float;
  20374. #include <common>
  20375. attribute vec3 splatCenter;
  20376. attribute float splatIndex;
  20377. varying vec2 vPosition;
  20378. const float sqrt8 = sqrt(8.0);
  20379. const float minAlpha = 1.0 / 255.0;
  20380. void main () {
  20381. mat4 transformModelViewMatrix = modelViewMatrix;
  20382. vec4 viewCenter = transformModelViewMatrix * vec4(splatCenter, 1.0);
  20383. vec4 clipCenter = projectionMatrix * viewCenter;
  20384. float clip = 1.2 * clipCenter.w;
  20385. if (clipCenter.z < -clip || clipCenter.x < -clip || clipCenter.x > clip || clipCenter.y < -clip || clipCenter.y > clip) {
  20386. gl_Position = vec4(0.0, 0.0, 2.0, 1.0);
  20387. return;
  20388. }
  20389. vPosition = position.xy;
  20390. vec3 ndcCenter = clipCenter.xyz / clipCenter.w;
  20391. float eigenValue1 = 0.2;
  20392. float eigenValue2 = 0.2;
  20393. //vec2 eigenVector1 = normalize(vec2(b, eigenValue1 - a));
  20394. vec2 eigenVector1 = normalize(vec2(0.5, 0.5));
  20395. vec2 eigenVector2 = vec2(eigenVector1.y, -eigenVector1.x);
  20396. vec2 basisVector1 = eigenVector1 * min(sqrt8 * sqrt(eigenValue1), 2048.0);
  20397. vec2 basisVector2 = eigenVector2 * min(sqrt8 * sqrt(eigenValue2), 2048.0);
  20398. vec2 ndcOffset = vec2(vPosition.x * basisVector1 + vPosition.y * basisVector2) / viewport * 2.0 ;
  20399. gl_Position = vec4(ndcCenter.xy + ndcOffset, ndcCenter.z , 1.0);
  20400. vPosition *= sqrt8;
  20401. }`;
  20402. //面片模拟椭球,总是有厚度
  20403. const fragmentShaderSource = `
  20404. precision highp float;
  20405. #include <common>
  20406. uniform vec3 color;
  20407. varying vec2 vPosition;
  20408. void main () {
  20409. float A = dot(vPosition, vPosition);
  20410. if (A > 8.0) discard; //position的范围半径为1。指一个rectangle面中的范围。椭圆外的完全透明
  20411. float opacity = exp(-0.5 * A) * vColor.a; //周围的透明度降低
  20412. gl_FragColor = vec4(color.rgb, opacity);
  20413. }`;
  20414. const uniforms = {
  20415. 'viewport': {
  20416. 'type': 'v2',
  20417. 'value': new THREE.Vector2()
  20418. } ,
  20419. color:{
  20420. 'type': 'v3',
  20421. 'value': new THREE.Color()
  20422. }
  20423. };
  20424. const material = new THREE.ShaderMaterial({
  20425. uniforms: uniforms,
  20426. vertexShader: vertexShaderSource,
  20427. fragmentShader: fragmentShaderSource,
  20428. transparent: true,
  20429. alphaTest: 1.0,
  20430. blending: THREE.NormalBlending,
  20431. depthTest: true,
  20432. depthWrite: false,
  20433. side: THREE.DoubleSide
  20434. });
  20435. window.splatMesh = new THREE.Mesh(geometry, material)
  20436. viewer.scene.scene.add(window.splatMesh)
  20437. viewer.addEventListener('resize',(e)=>{
  20438. if(e.viewport.name == 'mainViewport'){
  20439. uniforms.viewport.copy(e.viewport.resolution)
  20440. }
  20441. })
  20442. window.setSplatIndexes = (globalIndexes)=>{
  20443. geometry.attributes.splatIndex.set(globalIndexes);
  20444. geometry.attributes.splatIndex.needsUpdate = true;
  20445. geometry.instanceCount = globalIndexes.length
  20446. }
  20447. })
  20448. */
  20449. var Alignment = viewer.modules.Alignment;
  20450. viewer.setEDLEnabled(false);
  20451. viewer.setFOV(Potree.config.view.fov);
  20452. //viewer.loadSettingsFromURL();
  20453. Potree.settings.cameraFar = Potree.config.view.far;
  20454. if (!Potree.settings.isOfficial) {
  20455. viewer.loadGUI(() => {
  20456. viewer.setLanguage('en');
  20457. //$("#menu_appearance").next().show();
  20458. $("#menu_tools").next().show();
  20459. $("#menu_scene").next().show();
  20460. $("#siteModel").show();
  20461. //$("#alignment").show();
  20462. viewer.toggleSidebar();
  20463. });
  20464. Potree.settings.sizeFitToLevel = true; //当type为衰减模式时自动根据level调节大小。每长一级,大小就除以2
  20465. Potree.settings.rotAroundPoint = false;
  20466. }
  20467. Potree.loadDatasetsCallback = function (data, ifReload) {
  20468. if (!data || data.length == 0) return console.error('getDataSet加载的数据为空');
  20469. Potree.datasetData = data;
  20470. viewer.transform = null;
  20471. var datasetLength = data.length;
  20472. var pointcloudLoaded = 0;
  20473. var panosLoaded = 0;
  20474. var pointcloudLoadDone = function pointcloudLoadDone() {//点云cloud.js加载完毕后
  20475. };
  20476. var panosLoadDone = function panosLoadDone() {
  20477. viewer.images360.loadDone();
  20478. viewer.scene.add360Images(viewer.images360);
  20479. viewer.mapViewer.addListener(viewer.images360);
  20480. viewer.updateModelBound(); //需等pano加载完
  20481. var {
  20482. boundSize,
  20483. center
  20484. } = viewer.bound;
  20485. if (!Potree.settings.isOfficial) {
  20486. Potree.loadMapEntity('all'); //加载floorplan
  20487. }
  20488. if (!ifReload) {
  20489. viewer.dispatchEvent({
  20490. type: 'loadPointCloudDone'
  20491. });
  20492. if (!Potree.settings.UserPointDensity) {
  20493. Potree.settings.UserPointDensity = 'high'; //'middle'
  20494. }
  20495. Potree.Log('loadPointCloudDone 点云加载完毕');
  20496. }
  20497. {
  20498. //初始位置
  20499. var panoId = browser.urlHasValue('pano', true);
  20500. if (panoId !== '') {
  20501. var pos;
  20502. var pano = viewer.images360.panos.find(e => e.id == panoId);
  20503. if (pano) {
  20504. viewer.images360.focusPano({
  20505. pano,
  20506. duration: 0,
  20507. callback: () => {/* Potree.settings.displayMode = 'showPanos' */}
  20508. });
  20509. }
  20510. } else {
  20511. //考虑到多数据集距离很远,或者像隧道那种场景,要使视野范围内一定能看到点云,最好初始点设置在漫游点上
  20512. var {
  20513. boundSize: _boundSize,
  20514. center: _center
  20515. } = viewer.bound;
  20516. var _pano = viewer.images360.findNearestPano(_center);
  20517. if (_pano) {
  20518. viewer.images360.flyToPano({
  20519. pano: _pano,
  20520. duration: 0,
  20521. target: viewer.images360.bound.center.setZ(_pano.position.z) //平视中心区域(但也不能保证这个方向一定能看到点云密集区,如果在边缘的话)
  20522. });
  20523. } else {
  20524. // 无漫游点 避免加载时看不到点云 SG-t-DXmdymgZ2sX SG-t-rVB03a5GXr8
  20525. //SG-t-XPf1k9pv3Zg 总有极端的场景,如这是倾斜的桥 - -, 只能调整为看到全局了
  20526. viewer.mainViewport.view.pitch = -0.7; //相对俯视
  20527. var bound = viewer.bound.boundingBox.clone();
  20528. viewer.focusOnObject({
  20529. boundingBox: bound
  20530. }, 'boundingBox', 0, {
  20531. dontChangeCamDir: true
  20532. });
  20533. if (viewer.bound.boundSize.length() > 20) {
  20534. //否则有可能超出far范围
  20535. viewer.mainViewport.camera.far = 10000;
  20536. viewer.mainViewport.camera.updateProjectionMatrix();
  20537. viewer.fixCamFar = true; //不允许修改camera.far
  20538. //等有点云加载出来后,再去focus其中一个,使camera.far不超过最大值
  20539. var count_ = 0;
  20540. var done = () => {
  20541. viewer.fixCamFar = false;
  20542. viewer.mainViewport.camera.far = Potree.settings.cameraFar;
  20543. viewer.mainViewport.camera.updateProjectionMatrix();
  20544. viewer.removeEventListener('pageVisible', focusPoint);
  20545. clearTimeout(timer);
  20546. };
  20547. var timer;
  20548. var focusPoint = e => {
  20549. //拉近到某个点
  20550. if (e && e.v === false) return;
  20551. viewer.removeEventListener('pageVisible', focusPoint);
  20552. var pointcloud = viewer.scene.pointclouds.find(e => e.root.geometryNode);
  20553. console.log('初始加载focus点云', e, pointcloud);
  20554. if (!pointcloud) {
  20555. if (count_ < 10) {
  20556. //可能没加载到,可能被隐藏
  20557. if (document.hidden) {
  20558. //等回到页面再focus
  20559. console.log('focus hidden');
  20560. return viewer.addEventListener('pageVisible', focusPoint);
  20561. }
  20562. count_++; //如果在别的
  20563. timer = setTimeout(focusPoint, 200);
  20564. } else {
  20565. //放弃
  20566. console.log('初始加载focus点云 放弃');
  20567. done();
  20568. }
  20569. return console.warn('no!!!!!!!!!!!!!!');
  20570. }
  20571. viewer.flyToDataset({
  20572. focusOnPoint: true,
  20573. pointcloud,
  20574. duration: 0
  20575. });
  20576. console.warn('ok!!!!!!!!!!!!!!!!');
  20577. done();
  20578. };
  20579. var focus = () => {
  20580. timer = setTimeout(focusPoint, 300);
  20581. };
  20582. viewer.addEventListener('setPose', () => {
  20583. //设置了初始画面
  20584. viewer.removeEventListener('pointcloud_changed', focus);
  20585. done();
  20586. });
  20587. viewer.addEventListener('pointcloud_changed', focus, {
  20588. once: true
  20589. }); //加载了点之后
  20590. }
  20591. }
  20592. }
  20593. }
  20594. viewer.addVideo(); //addFire()
  20595. viewer.scene.pointclouds.some(e => !e.hasDepthTex) && (Potree.config.shelterMargin *= 3); //没有深度图的话在全景模式测量有偏差
  20596. console.log('allLoaded');
  20597. viewer.addTube({
  20598. 't-8KbK1JjubE': [{
  20599. //地上管子 黄色
  20600. path: [{
  20601. "x": -109.83,
  20602. "y": -68.33,
  20603. "z": -7.52
  20604. }, {
  20605. "x": -95.17,
  20606. "y": -59.3,
  20607. "z": -7.38
  20608. }, {
  20609. "x": -38.75,
  20610. "y": -24.01,
  20611. "z": -6.01
  20612. }, {
  20613. "x": 0.5,
  20614. "y": 0.19,
  20615. "z": -3.89
  20616. }, {
  20617. "x": 39.29,
  20618. "y": 24.41,
  20619. "z": -1.31
  20620. }, {
  20621. "x": 43.58,
  20622. "y": 27.7,
  20623. "z": -0.97
  20624. }, {
  20625. "x": 40.22,
  20626. "y": 35.37,
  20627. "z": -0.67
  20628. } // 拐弯向右
  20629. , {
  20630. "x": 39.18,
  20631. "y": 36.71,
  20632. "z": 0.35
  20633. }, {
  20634. "x": 38.69,
  20635. "y": 36.04,
  20636. "z": 18.04
  20637. } // 拐弯向上 }
  20638. ],
  20639. color: '#b86',
  20640. radius: 0.08,
  20641. height: 0.13
  20642. }, {
  20643. //地下管子 藍色
  20644. path: [{
  20645. "x": -108.24,
  20646. "y": -70.61,
  20647. "z": -7.52
  20648. }, {
  20649. "x": -57.8,
  20650. "y": -39.31,
  20651. "z": -6.72
  20652. }, {
  20653. "x": -18.8,
  20654. "y": -15.35,
  20655. "z": -5.01
  20656. }, {
  20657. "x": 55.87,
  20658. "y": 31.67,
  20659. "z": -0.04
  20660. }, {
  20661. "x": 110.53,
  20662. "y": 66.48,
  20663. "z": 5.14
  20664. }],
  20665. color: '#48a',
  20666. radius: 0.08,
  20667. height: -0.5
  20668. }]
  20669. /* 'SG-t-h0I7LnfGFwj':[ //港华M层
  20670. {
  20671. path:[[20.295,-10.269,-1.152],[19.996,-10.252,-1.153],[19.98,-10.253,-1.156],[19.967,-10.252,-1.165],[19.957,-10.251,-1.179],[19.953,-10.251,-1.225],[19.961,-10.242,-1.267],[19.968,-10.223,-1.296],[19.967,-10.193,-1.304],[20.007,-10.092,-1.321],[19.997,-10.063,-1.309],[19.979,-10.039,-1.284],[19.989,-10.028,-1.256],[19.993,-10.024,-1.23],[19.972,-10.026,-1.181],[20.009,-10.045,-1.026],[20.025,-10.048,-1.013],[20.045,-10.05,-1.006],[20.056,-10.052,-1.001],[20.413,-10.073,-1.016],[20.461,-10.075,-1.02],[20.498,-10.053,-1.018],[20.525,-10.022,-1.025],[20.538,-9.983,-1.029],[20.554,-9.536,-1.111],[20.554,-9.487,-1.118],[20.545,-9.445,-1.129],[20.521,-9.418,-1.14],[20.478,-9.396,-1.156],[20.427,-9.379,-1.182],[20.367,-9.369,-1.198],[19.971,-9.304,-1.221],[19.749,-9.197,-1.345]]
  20672. ,color:'#8c99aa', radius:0.025, height:-0, fromDataset:true, tension:0.01, spaceDis:0.02,visiEntity:'厨房'
  20673. },
  20674. {
  20675. path:[[19.708,-2.921,-1.145],[19.721,-2.924,-1.119],[20.704,-2.881,-1.134],[20.736,-2.87,-1.138],[20.76,-2.852,-1.147],[20.773,-2.828,-1.148],[20.777,-2.809,-1.148],[20.794,-2.493,-1.167],[20.793,-2.461,-1.169],[20.776,-2.436,-1.174],[20.742,-2.425,-1.198],[20.14,-2.459,-1.309],[20.123,-2.457,-1.309],[20.108,-2.451,-1.31],[20.101,-2.439,-1.311],[20.095,-2.42,-1.313],[20.094,-2.399,-1.311],[20.092,-1.966,-1.295],[20.093,-1.945,-1.286],[20.094,-1.931,-1.269],[20.093,-1.929,-1.251],[20.09,-1.921,-1.197],[20.096,-1.914,-1.181],[20.107,-1.909,-1.174],[20.176,-1.893,-1.141],[20.699,-1.848,-1.076],[20.759,-1.824,-1.068],[20.81,-1.754,-1.076],[20.837,-1.71,-1.086],[20.85,-1.634,-1.1],[20.815,-1.01,-1.104],[20.824,-0.979,-1.115],[20.83,-0.957,-1.124],[20.843,-0.936,-1.132],[20.871,-0.925,-1.139],[21.065,-0.936,-1.166],[21.096,-0.935,-1.167],[21.115,-0.919,-1.167],[21.129,-0.887,-1.165],[21.136,-0.783,-1.167],[21.136,0.555,-1.201],[21.128,0.599,-1.201],[21.1,0.627,-1.199],[21.058,0.639,-1.198],[20.832,0.616,-1.179],[20.782,0.62,-1.186],[20.748,0.637,-1.19],[20.728,0.698,-1.21],[20.731,1.311,-1.233],[20.68,2.081,-1.292],[20.654,2.157,-1.307],[20.576,2.215,-1.314],[20.484,2.274,-1.321],[20.035,2.354,-1.353],[20.013,2.367,-1.363],[20.008,2.39,-1.371],[19.989,3.124,-1.384],[19.993,3.175,-1.39],[19.995,3.208,-1.393],[19.995,3.233,-1.374],[20.002,3.246,-1.324],[20.006,3.248,-1.266],[20.027,3.243,-1.245],[20.063,3.241,-1.239],[20.62,3.229,-1.226],[20.645,3.235,-1.204],[20.658,3.251,-1.191],[20.667,3.278,-1.184],[20.675,3.312,-1.193],[20.716,3.71,-1.24],[20.722,3.767,-1.251],[20.704,3.823,-1.268],[20.652,3.864,-1.279],[20.026,3.901,-1.368],[19.999,3.919,-1.37],[19.982,3.95,-1.361],[19.933,4.69,-1.285],[19.972,4.812,-1.332],[19.978,4.817,-1.233],[19.992,4.814,-1.203],[20.047,4.81,-1.196],[20.738,4.794,-1.196]]
  20676. ,color:'#8c99aa', radius:0.025, height:-0, fromDataset:true, tension:0.01, spaceDis:0.02,visiEntity:'厨房'
  20677. },
  20678. {
  20679. path:[[19.685,-2.896,-1.115],[19.699,-2.93,-1.274],[19.701,-2.936,-1.295],[19.707,-2.94,-1.316],[19.712,-2.951,-1.34],[19.714,-2.965,-1.353],[19.716,-2.986,-1.359],[19.7,-3.595,-1.309],[19.703,-3.619,-1.303],[19.704,-3.628,-1.274],[19.719,-3.632,-1.256],[20.063,-3.633,-1.275],[20.089,-3.637,-1.254],[20.103,-3.64,-1.227],[20.11,-3.642,-1.191],[20.083,-3.669,-1.027],[20.075,-3.68,-0.999],[20.053,-3.694,-0.978],[20.053,-3.805,-0.957],[20.063,-3.827,-0.963],[20.045,-3.836,-0.962],[20.01,-3.841,-0.957],[19.737,-3.818,-0.964],[19.712,-3.814,-0.985],[19.699,-3.819,-1.059],[19.724,-3.817,-1.247],[19.725,-3.827,-1.28],[19.719,-3.842,-1.309],[19.719,-3.858,-1.33],[19.714,-3.881,-1.341],[19.699,-4.56,-1.339],[19.7,-4.62,-1.336],[19.7,-4.643,-1.334],[19.699,-4.66,-1.326],[19.698,-4.675,-1.31],[19.697,-4.678,-1.279],[19.697,-4.678,-1.21],[19.704,-4.682,-1.187],[19.716,-4.682,-1.173],[19.736,-4.683,-1.164],[20.481,-4.817,-1.026],[20.529,-4.847,-0.984],[20.562,-4.89,-0.935],[20.585,-4.932,-0.909],[20.59,-4.992,-0.887],[20.565,-5.98,-0.847],[20.547,-6.08,-0.846],[20.541,-6.17,-0.86],[20.476,-6.21,-0.858],[19.847,-6.207,-0.808],[19.803,-6.22,-0.827],[19.775,-6.217,-0.885],[19.75,-6.188,-1.289],[19.743,-6.193,-1.341],[19.742,-6.207,-1.375],[19.75,-6.232,-1.401],[19.722,-6.905,-1.359],[19.723,-6.958,-1.352],[19.722,-6.987,-1.342],[19.721,-7.001,-1.31],[19.721,-7.004,-1.231],[19.734,-7.03,-0.976],[19.742,-7.041,-0.947],[19.747,-7.059,-0.922],[19.755,-7.284,-0.764],[19.761,-7.312,-0.731],[19.776,-7.337,-0.711],[19.795,-7.355,-0.702],[20.502,-7.453,-0.715],[20.578,-7.496,-0.715],[20.631,-7.557,-0.719],[20.66,-7.653,-0.718],[20.658,-8.639,-0.766],[20.654,-8.789,-0.763],[20.639,-8.856,-0.763],[20.605,-8.89,-0.76],[20.57,-8.916,-0.761],[20.539,-8.945,-0.773],[19.879,-9.028,-0.814],[19.853,-9.032,-0.828],[19.834,-9.033,-0.842],[19.83,-9.033,-0.876],[19.857,-9.033,-1.292],[19.837,-9.037,-1.333],[19.819,-9.051,-1.354],[19.812,-9.082,-1.381],[19.79,-9.184,-1.386]]
  20680. ,color:'#8c99aa', radius:0.02, height:-0, fromDataset:true, tension:0.01, spaceDis:0.02,visiEntity:'厨房'
  20681. }
  20682. ],
  20683. 'SG-t-RGUFiJAoxvL':[ //济南工地覆土后
  20684. {//--旧的 整条
  20685. path: [[23.522,-19.432,-1.744],[25.344,20.312,-1.855],[25.344,21.302,-1.861],[25.253,21.904,-1.861],[25.088,22.381,-1.859],[24.748,22.772,-1.861],[24.222,22.893,-1.873],[-24.547,16.774,-1.319]]
  20686. ,color:'#445', radius:0.08, height:-1.16, fromDataset:true, tension:0.01,// spaceDis:0.1
  20687. },
  20688. {
  20689. path:[[22.726,22.678,-1.938],[-24.541,16.782,-1.319]]
  20690. ,color:'#445', radius:0.08, height:-1.16, fromDataset:true, tension:0,// spaceDis:0.1
  20691. },
  20692. {
  20693. path:[[23.519,-19.473,-1.744],[25.117,15.447,-1.783]]
  20694. ,color:'#445', radius:0.08, height:-1.16, fromDataset:true, tension:0,// spaceDis:0.1
  20695. }
  20696. ],
  20697. 'SG-t-TK0S5EqWBxd':[ //济南工地
  20698. {
  20699. path:[[-25.768,-12.695,-1.305],[-26.334,-21.834,-1.511],[-26.355,-22.153,-1.514],[-26.366,-22.418,-1.513],[-26.31,-22.66,-1.515],[-26.126,-22.841,-1.519],[-25.871,-22.968,-1.525],[-25.443,-22.969,-1.532],[-24.953,-22.956,-1.585],[-23.697,-22.854,-1.637]]
  20700. ,color:'#445', radius:0.08, height:-1.16, fromDataset:true, spaceDis:0.2// tension:0.01,
  20701. },
  20702. ],*/
  20703. });
  20704. viewer.dispatchEvent('allLoaded');
  20705. };
  20706. var transformPointcloud = (pointcloud, dataset) => {
  20707. var locationLonLat = dataset.location.slice(0, 3); // [lon,lat,高程海拔]
  20708. //当只有一个dataset时,无论如何transform 点云和漫游点都能对应上。
  20709. var location = viewer.transform.lonlatToLocal.forward(locationLonLat); //transform.inverse()
  20710. //初始化位置
  20711. viewer.sidebar && viewer.sidebar.addAlignmentButton(pointcloud);
  20712. //dataset.orientation = 0
  20713. Alignment.rotate(pointcloud, null, dataset.orientation);
  20714. Alignment.translate(pointcloud, new Vector3(location[0], location[1], dataset.location[2] - originDataset.location[2])); //要使初始数据集的z为0,所以要减去初始数据集的z
  20715. pointcloud.updateMatrixWorld();
  20716. Potree.Log("\u70B9\u4E91".concat(pointcloud.dataset_id, "(").concat(pointcloud.name, ")\u65CB\u8F6C\u503C:").concat(pointcloud.orientationUser, ", \u4F4D\u7F6E").concat(math.toPrecision(pointcloud.translateUser.toArray(), 3), ", \u7ECF\u7EAC\u5EA6 ").concat(dataset.location, ", spacing ").concat(pointcloud.material.spacing), {
  20717. font: {
  20718. color: "#5af",
  20719. fontSize: 13
  20720. }
  20721. });
  20722. };
  20723. if (!Potree.settings.originDatasetId) Potree.settings.originDatasetId = data[0].id;
  20724. var originDataset = data.find(e => e.id == Potree.settings.originDatasetId);
  20725. /* originDataset.location[0] = 113.60608878174709
  20726. originDataset.location[1] = 22.381189423935155
  20727. let ano = data.find(e=>e.name == 'SG-t-Jw0xyhL6oSY')
  20728. ano.location[0] = 113.6060509967498
  20729. ano.location[1] = 22.381061273279244 */
  20730. {
  20731. //拿初始数据集作为基准。它的位置要放到000
  20732. var locationLonLat = originDataset.location.slice(0, 2);
  20733. Potree.setLonlat(locationLonLat[0], locationLonLat[1]);
  20734. /* if(window.AMapWith84){//需要转换为高德的,但该函数不准确,转入后再转出,和原来的有偏差. navvis的我看data中存的globalLocation直接输入到高德地图后的定位和其要展示的定位一致,而我们要转为高德后才一致,猜测是navvis后台转为了高德可用的经纬度。 若不转的话,其他看起来没问题,仅高德地图定位不准确,因其为被加密后的火星坐标系。
  20735. locationLonLat = AMapWith84.wgs84ToAMap({x:locationLonLat[0], y:locationLonLat[1]})
  20736. locationLonLat = [locationLonLat.x,locationLonLat.y]
  20737. }
  20738. proj4.defs("LOCAL", "+proj=tmerc +ellps=WGS84 +lon_0=" + locationLonLat[0].toPrecision(15) + " +lat_0=" + locationLonLat[1].toPrecision(15)); //高德坐标系
  20739. proj4.defs("LOCAL_MAP", "+proj=tmerc +ellps=WGS84 +lon_0=" + locationLonLat[0].toPrecision(15) + " +lat_0=" + locationLonLat[1].toPrecision(15)); //地图和本地一样
  20740. proj4.defs("WGS84", "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs");
  20741. let transform1 = proj4("WGS84", "LOCAL"); //这个ok 是展开的平面投影 LOCAL即NAVVIS:TMERC
  20742. let transform2 = proj4("+proj=tmerc +lat_0=0 +lon_0=123 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs;");
  20743. //注:转入后再转出,和原来的有偏差。如果输入是local坐标,数字越大偏差越大,当百万时就明显了。如果是lonlat,很奇怪经度小于50时就乱了。
  20744. viewer.transform = {
  20745. lonlatToLocal : transform1,
  20746. lonlatTo4550 : transform2 // 转大地坐标EPSG:4550
  20747. }
  20748. if(window.AMapWith84 && Potree.settings.mapCompany != 'google'){//需要转换, 因本地高德用的lonlat和数据里的84不一样. (google地图在国内也用的高德,国外84)
  20749. let change = (transform)=>{
  20750. let forward = transform.forward
  20751. let inverse = transform.inverse;
  20752. transform.forward = function(e, not84){
  20753. let needTran = e.x == void 0
  20754. if(needTran)var a1 = {x:e[0],y:e[1]}
  20755. else var a1 = e
  20756. var a = not84 ? a1 : AMapWith84.wgs84ToAMap(a1)
  20757. if(needTran){
  20758. a = [a.x, a.y]; e[2] != void 0 && (a[2] = e[2])
  20759. }else{
  20760. e.z != void 0 && (a.z = e.z)
  20761. }
  20762. return forward(a)
  20763. }
  20764. transform.inverse = function(e, not84){
  20765. let needTran = e.x == void 0
  20766. var a = inverse(e)
  20767. needTran && (a = {x:a[0],y:a[1]})
  20768. a = not84 ? a : AMapWith84.aMapToWgs84(a)
  20769. if(needTran){
  20770. a = [a.x,a.y]; e[2] != void 0 && (a[2] = e[2])
  20771. }else{
  20772. e.z != void 0 && (a.z = e.z)
  20773. }
  20774. return a
  20775. }
  20776. }
  20777. for(let f in viewer.transform){
  20778. change(viewer.transform[f])
  20779. }
  20780. } */
  20781. viewer.mapViewer && viewer.mapViewer.mapLayer.maps[0].updateProjection();
  20782. }
  20783. data.forEach((dataset, index) => {
  20784. if (!ifReload) {
  20785. var datasetCode = dataset.sceneCode || dataset.name; //对应4dkk的场景码
  20786. if (Potree.settings.isLocal && dataset.mapping) {
  20787. var cloudPath = "".concat(Potree.settings.urls.prefix1, "/").concat(dataset.mapping, "/").concat(dataset.webBin); //webBin添加原因:每次裁剪之类的操作会换路径,因为oss文件缓存太严重,更新慢
  20788. } else {
  20789. var cloudPath = "".concat(Potree.settings.urls.prefix1, "/").concat(dataset.webBin); //webBin添加原因:每次裁剪之类的操作会换路径,因为oss文件缓存太严重,更新慢
  20790. }
  20791. //var cloudPath = `${Potree.scriptPath}/data/test/${dataset.name}/cloud.js`
  20792. var timeStamp = dataset.updateTime ? dataset.updateTime.replace(/[^0-9]/ig, '') : ''; //每重算一次后缀随updateTime更新一次
  20793. //console.warn(dataset.name, 'timeStamp', timeStamp)
  20794. Potree.loadPointCloud(cloudPath, dataset.name, datasetCode, timeStamp, e => {
  20795. var scene = viewer.scene;
  20796. var pointcloud = e.pointcloud;
  20797. var config = Potree.config.material;
  20798. var material = pointcloud.material;
  20799. pointcloud.datasetData = dataset;
  20800. pointcloud.dataset_id = dataset.id; //供漫游点找到属于的dataset点云
  20801. pointcloud.hasDepthTex = Potree.settings.useDepthTex && (!!dataset.has_depth || Potree.settings.isLocalhost && Potree.settings.number == 'SS-t-7DUfWAUZ3V'); //test
  20802. material.minSize = config.minSize;
  20803. material.maxSize = config.maxSize;
  20804. material.pointSizeType = /* Potree.settings.isOfficial ? */config.pointSizeType; /* : 'ADAPTIVE' */ //Potree.PointSizeType[config.pointSizeType]//Potree.PointSizeType.ADAPTIVE;//FIXED
  20805. pointcloud.changePointSize(config.realPointSize); //material.size = config.pointSize;
  20806. pointcloud.changePointOpacity(1);
  20807. material.shape = Potree.PointShape.SQUARE;
  20808. pointcloud.color = pointcloud.material.color = dataset.color;
  20809. pointcloud.timeStamp = timeStamp;
  20810. transformPointcloud(pointcloud, dataset);
  20811. scene.addPointCloud(pointcloud);
  20812. if (!Potree.settings.isOfficial) {
  20813. Potree.settings.floorplanEnables[dataset.id] = true;
  20814. Potree.settings.floorplanType[dataset.id] = 'default';
  20815. }
  20816. pointcloudLoaded++;
  20817. if (pointcloudLoaded == datasetLength) pointcloudLoadDone();
  20818. Potree.loadPanos(dataset.id, data => {
  20819. //console.log('loadPanos',dataset.sceneCode, dataset.id, data)
  20820. viewer.images360.addPanoData(data, pointcloud);
  20821. panosLoaded++;
  20822. if (panosLoaded == datasetLength) {
  20823. Potree.loadImgVersion(function () {
  20824. var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  20825. Potree.settings.panoVersion = e.imgVersion; //全景图被替换后
  20826. panosLoadDone();
  20827. });
  20828. }
  20829. });
  20830. });
  20831. } else {
  20832. var pointcloud = viewer.scene.pointclouds.find(p => p.dataset_id == dataset.id);
  20833. if (!pointcloud) {
  20834. Potree.Log('数据集id变了,自动使用第一个', {
  20835. font: {
  20836. color: '#500'
  20837. }
  20838. });
  20839. pointcloud = viewer.scene.pointclouds[0];
  20840. }
  20841. //先归零
  20842. Alignment.translate(pointcloud, pointcloud.translateUser.clone().negate());
  20843. Alignment.rotate(pointcloud, null, -pointcloud.orientationUser);
  20844. transformPointcloud(pointcloud, dataset);
  20845. }
  20846. });
  20847. if (ifReload) {
  20848. //loadDone()
  20849. }
  20850. };
  20851. number && Potree.loadDatasets(Potree.loadDatasetsCallback);
  20852. /*
  20853. //调试用,加载多个本地
  20854. Potree.loadDatasetsCallback([
  20855. {name:'webcloud_0',id:0, orientation:0, location:[0,0,0]},
  20856. {name:'webcloud_1',id:1, orientation:0.047234761795199476, location:[-0.07925513345058573,-0.0010590072536559839,-2.403613132687564]},
  20857. {name:'webcloud_2',id:2, orientation:-1.5299545647758208, location:[1.5603736310030292, -0.0009340812579088904, -2.4464530770974139]},
  20858. ]) */
  20859. window.testTransform = function (locationLonLat, location1, location2) {
  20860. proj4.defs("NAVVIS:test", "+proj=tmerc +ellps=WGS84 +lon_0=" + locationLonLat[0].toPrecision(15) + " +lat_0=" + locationLonLat[1].toPrecision(15));
  20861. var transform = proj4("WGS84", "NAVVIS:test"); //这个ok navvis里也是这两种转换 见proj4Factory
  20862. if (location1) {
  20863. //经纬度
  20864. return transform.forward(location1);
  20865. } else {
  20866. return transform.inverse(location2);
  20867. }
  20868. };
  20869. window.THREE = THREE$1;
  20870. window.buttonFunction = function () {
  20871. viewer.scene.pointclouds.forEach(e => e.predictNodeMaxLevel());
  20872. /*
  20873. viewer.startScreenshot({type:'measure', measurement:viewer.scene.measurements[0]})
  20874. viewer.modules.RouteGuider.routeStart = new THREE.Vector3(0,0,-1.3)
  20875. viewer.modules.RouteGuider.routeEnd = new THREE.Vector3(-10,0,-1.3)
  20876. */
  20877. };
  20878. if (Potree.settings.isLocalhost) {
  20879. var before = {};
  20880. viewer.inputHandler.addEventListener('keydown', e => {
  20881. //测试的代码
  20882. if (e.event.key == 't') {
  20883. viewer.images360.cube.visible = true;
  20884. viewer.images360.cube.material.wireframe = true;
  20885. } else if (e.event.key == 'y') {
  20886. viewer.images360.cube.material.wireframe = false;
  20887. viewer.images360.cube.visible = Potree.settings.displayMode == 'showPanos';
  20888. }
  20889. });
  20890. //--------------------------------
  20891. /* if(!number){
  20892. Potree.settings.boundAddObjs = true
  20893. Potree.settings.intersectOnObjs = true
  20894. // Load untextured bunny from ply
  20895. viewer.loadModel({
  20896. fileType:'ply',
  20897. url:Potree.resourcePath + "/models/indoor.ply",
  20898. name:'test',
  20899. },
  20900. (object)=>{
  20901. object.isModel = true
  20902. viewer.updateModelBound()
  20903. }
  20904. )
  20905. } */
  20906. }
  20907. }
  20908. //=======================================================================
  20909. /*
  20910. 漫游点编辑
  20911. */
  20912. //=======================================================================
  20913. function panoEditStart(dom, number, fileServer) {
  20914. Potree.settings.editType = 'pano';
  20915. Potree.settings.number = number;
  20916. Potree.settings.unableNavigate = true;
  20917. Potree.settings.sizeFitToLevel = true; //当type为衰减模式时自动根据level调节大小。每长一级,大小就除以2
  20918. var viewer = new Potree.Viewer(dom);
  20919. var Alignment = viewer.modules.Alignment;
  20920. viewer.setEDLEnabled(false);
  20921. viewer.setFOV(Potree.config.view.fov);
  20922. //viewer.loadSettingsFromURL();
  20923. var datasetLoaded = 0;
  20924. if (!Potree.settings.isOfficial) {
  20925. viewer.loadGUI(() => {
  20926. viewer.setLanguage('en');
  20927. $("#menu_tools").next().show();
  20928. $("#panos").show();
  20929. $("#alignment").show();
  20930. viewer.toggleSidebar();
  20931. });
  20932. Potree.settings.sizeFitToLevel = true;
  20933. }
  20934. var pointcloudLoadDone = function pointcloudLoadDone() {
  20935. //所有点云cloud.js加载完毕后
  20936. viewer.scene.pointclouds.forEach(c => {
  20937. transformPointcloud(c);
  20938. });
  20939. viewer.images360.loadDone();
  20940. viewer.scene.add360Images(viewer.images360);
  20941. viewer.updateModelBound();
  20942. var {
  20943. boundSize,
  20944. center
  20945. } = viewer.bound;
  20946. Potree.Log("\u4E2D\u5FC3\u70B9: ".concat(math.toPrecision(center.toArray(), 2), ", boundSize: ").concat(math.toPrecision(boundSize.toArray(), 2), " "));
  20947. viewer.scene.view.setView({
  20948. position: center.clone().add(new Vector3(10, 5, 10)),
  20949. target: center
  20950. });
  20951. viewer.dispatchEvent({
  20952. type: 'loadPointCloudDone'
  20953. });
  20954. if (!Potree.settings.UserPointDensity) {
  20955. Potree.settings.UserPointDensity = 'panoEdit'; //'middle'
  20956. }
  20957. Potree.Log('loadPointCloudDone 点云加载完毕', {
  20958. font: [null, 10]
  20959. });
  20960. viewer.dispatchEvent('allLoaded');
  20961. };
  20962. var transformPointcloud = pointcloud => {
  20963. //初始化位置
  20964. viewer.sidebar && viewer.sidebar.addAlignmentButton(pointcloud);
  20965. var orientation = pointcloud.panos[0].dataRotation.z + Math.PI;
  20966. var location = pointcloud.panos[0].dataPosition.clone(); //.negate()
  20967. Alignment.rotate(pointcloud, null, orientation);
  20968. Alignment.translate(pointcloud, location);
  20969. pointcloud.updateMatrixWorld();
  20970. };
  20971. var loadPanosDone = Potree.loadPanosDone = (datasetId, panoData) => {
  20972. //一个数据集获取到它的panos后
  20973. Potree.settings.datasetsPanos[datasetId] = {
  20974. panoData,
  20975. panos: []
  20976. };
  20977. console.log('panoData', datasetId, panoData);
  20978. var panoCount = panoData.length;
  20979. var pointcloudLoaded = 0;
  20980. var datasetsCount = Object.keys(Potree.settings.datasetsPanos).length;
  20981. panoData.forEach((pano, index) => {
  20982. //let cloudPath = `${Potree.scriptPath}/data/panoEdit/uuidcloud/${pano.uuid}/cloud.js`
  20983. var cloudPath = "".concat(Potree.settings.urls.prefix1, "/").concat(Potree.settings.webSite, "/").concat(Potree.settings.number, "/data/bundle_").concat(Potree.settings.number, "/building/uuidcloud/").concat(pano.uuid, "/cloud.js");
  20984. /* if(Potree.settings.isLocal && dataset.mapping){
  20985. var cloudPath = `${Potree.settings.urls.prefix1}/${dataset.mapping}/${dataset.webBin}` //webBin添加原因:每次裁剪之类的操作会换路径,因为oss文件缓存太严重,更新慢
  20986. }else{
  20987. var cloudPath = `${Potree.settings.urls.prefix1}/${dataset.webBin}` //webBin添加原因:每次裁剪之类的操作会换路径,因为oss文件缓存太严重,更新慢
  20988. } */
  20989. var name = datasetId + '-' + pano.uuid;
  20990. var timeStamp = 0;
  20991. pano.index = index; //注意:index不等于uuid,因为有的uuid缺失。但是visibles中存的是下标!
  20992. Potree.loadPointCloud(cloudPath, name, name, timeStamp, e => {
  20993. //开始加载点云
  20994. var scene = viewer.scene;
  20995. var pointcloud = e.pointcloud;
  20996. var config = Potree.config.material;
  20997. var material = pointcloud.material;
  20998. material.minSize = config.minSize;
  20999. material.maxSize = config.maxSize;
  21000. material.pointSizeType = /* 'ADAPTIVE'// */config.pointSizeType; //Potree.PointSizeType[config.pointSizeType]//Potree.PointSizeType.ADAPTIVE;//FIXED
  21001. pointcloud.changePointSize(0.1 /* config.realPointSize */); //material.size = config.pointSize;
  21002. pointcloud.changePointOpacity(1);
  21003. material.shape = Potree.PointShape.SQUARE;
  21004. pointcloud.color = config.pointColor;
  21005. pointcloud.dataset_id = datasetId; //多个点云指向一个datasetId
  21006. pointcloud.panoUuid = pano.uuid;
  21007. pointcloud.timeStamp = timeStamp;
  21008. //transformPointcloud(pointcloud, pano)
  21009. scene.addPointCloud(pointcloud);
  21010. pointcloudLoaded++;
  21011. if (pointcloudLoaded == panoCount) {
  21012. datasetLoaded++;
  21013. viewer.images360.addPanoData(panoData, pointcloud);
  21014. if (datasetLoaded == datasetsCount) {
  21015. pointcloudLoadDone();
  21016. }
  21017. }
  21018. });
  21019. });
  21020. };
  21021. if (!Potree.settings.isOfficial) {
  21022. Potree.settings.datasetsPano = {
  21023. 'testDataset': null
  21024. };
  21025. Potree.loadPanosInfo(data => {
  21026. loadPanosDone('testDataset', data.sweepLocations);
  21027. });
  21028. }
  21029. }
  21030. function mergeEditStart(dom, mapDom) {
  21031. Potree.settings.editType = 'merge';
  21032. Potree.settings.intersectOnObjs = true;
  21033. Potree.settings.boundAddObjs = true;
  21034. Potree.settings.unableNavigate = true;
  21035. var viewer = new Potree.Viewer(dom, mapDom);
  21036. var Alignment = viewer.modules.Alignment;
  21037. viewer.setEDLEnabled(false);
  21038. viewer.setFOV(Potree.config.view.fov);
  21039. //viewer.loadSettingsFromURL();
  21040. {
  21041. viewer.mainViewport.view.position.set(30, 30, 30);
  21042. viewer.mainViewport.view.lookAt(0, 0, 0);
  21043. viewer.updateModelBound(); //init
  21044. //this.bound = new THREE.Box3(new THREE.Vector3(-1,-1,-1),new THREE.Vector3(1,1,1))
  21045. viewer.transformationTool.setModeEnable(['translation', 'rotation']);
  21046. //viewer.ssaaRenderPass.sampleLevel = 1 // sampleLevel为1 的话,ground就不会变黑
  21047. viewer.inputHandler.fixSelection = true; //不通过点击屏幕而切换transfrom选中状态
  21048. }
  21049. Potree.settings.sizeFitToLevel = true; //当type为衰减模式时自动根据level调节大小。每长一级,大小就除以2
  21050. Potree.loadPointCloudScene = function (url, type, id, title, done, onError, prefix) {
  21051. //对应4dkk的场景码
  21052. var dataset;
  21053. var loadCloud = _ref => {
  21054. var {
  21055. cloudPath,
  21056. sceneName,
  21057. sceneCode,
  21058. timeStamp,
  21059. color
  21060. } = _ref;
  21061. Potree.loadPointCloud(cloudPath, sceneName, sceneCode, timeStamp, e => {
  21062. var scene = viewer.scene;
  21063. var pointcloud = e.pointcloud;
  21064. var config = Potree.config.material;
  21065. var material = pointcloud.material;
  21066. pointcloud.datasetData = dataset;
  21067. pointcloud.hasDepthTex = dataset && Potree.settings.useDepthTex && !!dataset.has_depth;
  21068. material.minSize = config.minSize;
  21069. material.maxSize = config.maxSize;
  21070. material.pointSizeType = config.pointSizeType; //Potree.PointSizeType[config.pointSizeType]//Potree.PointSizeType.ADAPTIVE;//FIXED
  21071. pointcloud.changePointSize(config.realPointSize); //material.size = config.pointSize;
  21072. pointcloud.changePointOpacity(1);
  21073. material.shape = Potree.PointShape.SQUARE;
  21074. color && (pointcloud.color = pointcloud.material.color = color);
  21075. pointcloud.timeStamp = timeStamp;
  21076. //transformPointcloud(pointcloud, originDataset)
  21077. scene.addPointCloud(pointcloud);
  21078. {
  21079. viewer.updateModelBound();
  21080. var {
  21081. boundSize,
  21082. center
  21083. } = viewer.bound;
  21084. viewer.dispatchEvent({
  21085. type: 'loadPointCloudDone'
  21086. });
  21087. if (!Potree.settings.UserPointDensity) {
  21088. Potree.settings.UserPointDensity = 'high'; //'middle'
  21089. }
  21090. Potree.Log(' 点云加载完毕', sceneName, sceneCode);
  21091. }
  21092. viewer.dispatchEvent('allLoaded');
  21093. done(pointcloud);
  21094. }, onError);
  21095. };
  21096. if (type == 'laser') {
  21097. var sceneCode = url;
  21098. Potree.loadDatasets(data => {
  21099. var originDataset = data.find(e => e.sceneCode == sceneCode); //只加载初始数据集
  21100. var timeStamp = originDataset.updateTime ? originDataset.updateTime.replace(/[^0-9]/ig, '') : ''; //每重算一次后缀随updateTime更新一次
  21101. //let cloudPath = `${Potree.settings.urls.prefix1}/${Potree.settings.webSite}/${sceneCode}/data/${sceneCode}/webcloud/cloud.js`
  21102. var cloudPath = "".concat(Potree.settings.urls.prefix1, "/").concat(originDataset.webBin); //webBin添加原因:每次裁剪之类的操作会换路径,因为oss文件缓存太严重,更新慢
  21103. dataset = originDataset;
  21104. loadCloud({
  21105. cloudPath,
  21106. sceneName: originDataset.sceneName,
  21107. sceneCode,
  21108. timeStamp,
  21109. color: originDataset.color
  21110. });
  21111. }, sceneCode, onError, prefix);
  21112. } else {
  21113. //las or ply 直接用url
  21114. var name = type + '|' + id + '|' + title;
  21115. //有漫游点吗
  21116. if (url instanceof Array) {
  21117. if (url.length == 1) {
  21118. url = url[0];
  21119. } else {
  21120. console.error('有多个点云?暂时还不支持', url, name); //多个点云要一起移动没想好怎么写
  21121. }
  21122. }
  21123. var cloudPath = url + '/cloud.js';
  21124. loadCloud({
  21125. cloudPath,
  21126. sceneName: name,
  21127. sceneCode: name,
  21128. timeStamp: ''
  21129. });
  21130. }
  21131. };
  21132. var setMatrix = pointcloud => {
  21133. //为了漫游点变换,要算一下 类似setMatrix
  21134. /* pointcloud.transformMatrix = new THREE.Matrix4().multiplyMatrices(pointcloud.matrix, pointcloud.pos1MatrixInvert)//还原一点位移
  21135. pointcloud.transformInvMatrix.copy(pointcloud.transformMatrix).invert()
  21136. pointcloud.rotateMatrix = new THREE.Matrix4().makeRotationFromEuler(pointcloud.rotation);
  21137. pointcloud.rotateInvMatrix.copy(pointcloud.rotateMatrix).invert()
  21138. pointcloud.panos.forEach(e=>e.transformByPointcloud()) */
  21139. //pointcloud.updateBound()
  21140. //pointcloud.getPanosBound()
  21141. viewer.updateModelBound();
  21142. };
  21143. var moveModel = e => {
  21144. //根据鼠标移动的位置改变位置
  21145. var camera = viewer.mainViewport.camera;
  21146. var origin = new Vector3(e.pointer.x, e.pointer.y, -1).unproject(camera),
  21147. end = new Vector3(e.pointer.x, e.pointer.y, 1).unproject(camera);
  21148. var dir = end.sub(origin);
  21149. var planeZ = 0;
  21150. var r = (planeZ - origin.z) / dir.z;
  21151. var x = r * dir.x + origin.x;
  21152. var y = r * dir.y + origin.y;
  21153. //过后改为根据intersect的点来设置底部高度;这样的话,需要发送高度
  21154. /*let pos = new THREE.Vector3(x,y, planeZ )
  21155. modelEditing.updateMatrixWorld()
  21156. let boundCenter = modelEditing.boundingBox.getCenter(new THREE.Vector3).applyMatrix4(modelEditing.matrixWorld);
  21157. */
  21158. MergeEditor.moveBoundCenterTo(modelEditing, new Vector3(x, y, modelEditing.boundCenter.z)); //使模型中心的xy在鼠标所在位置
  21159. modelEditing.dispatchEvent("position_changed");
  21160. };
  21161. var cancelMove = () => {
  21162. modelEditing = null;
  21163. viewer.removeEventListener('global_mousemove', moveModel);
  21164. viewer.removeEventListener('global_click', confirmPos);
  21165. };
  21166. var confirmPos = () => {
  21167. MergeEditor.focusOn(modelEditing);
  21168. cancelMove();
  21169. return {
  21170. stopContinue: true
  21171. };
  21172. };
  21173. var modelType,
  21174. modelEditing,
  21175. MergeEditor = viewer.modules.MergeEditor;
  21176. Potree.addModel = function (prop, done, onProgress, onError) {
  21177. //加载模型
  21178. var loadDone = model => {
  21179. model.dataset_id = prop.id; //唯一标识
  21180. if (prop.position) {
  21181. model.position.copy(prop.position);
  21182. }
  21183. if (prop.rotation) {
  21184. //model.rotation.setFromVector3(prop.rotation)
  21185. model.rotation.copy(prop.rotation);
  21186. }
  21187. if (prop.scale) {
  21188. model.scale.set(prop.scale, prop.scale, prop.scale);
  21189. }
  21190. if (model.isPointcloud) {
  21191. model.renderOrder = Potree.config.renderOrders.model; //same as glb
  21192. }
  21193. if (Potree.settings.maintainBtmZ) {
  21194. //transform --------维持离地高度和中心点的版本(local ver)
  21195. var updateBound = () => {
  21196. model.updateMatrixWorld();
  21197. viewer.updateModelBound();
  21198. };
  21199. var maintainBtmZAndCenter = () => {
  21200. MergeEditor.maintainBoundXY(model);
  21201. MergeEditor.setModelBtmHeight(model);
  21202. updateBound();
  21203. model.dispatchEvent('transformChanged');
  21204. };
  21205. model.addEventListener('position_changed', () => {
  21206. updateBound();
  21207. MergeEditor.getBoundCenter(model); //更新boundcenter
  21208. MergeEditor.computeBtmHeight(model);
  21209. if (prop.bottomRange && (model.btmHeight > prop.bottomRange.max || model.btmHeight < prop.bottomRange.min)) {
  21210. model.btmHeight = MathUtils.clamp(model.btmHeight, prop.bottomRange.min, prop.bottomRange.max);
  21211. MergeEditor.setModelBtmHeight(model);
  21212. updateBound();
  21213. }
  21214. model.dispatchEvent('transformChanged');
  21215. });
  21216. model.addEventListener("rotation_changed", maintainBtmZAndCenter);
  21217. model.addEventListener("scale_changed", maintainBtmZAndCenter);
  21218. model.addEventListener('transformChanged', () => {
  21219. MergeEditor.modelTransformCallback(model);
  21220. });
  21221. //离地高度只是boundingbox在transform后的最低点的高度,而非模型transform后的最低点的高度,所以旋转过后看起来不太准确
  21222. } else {
  21223. //transform --------维持中心点的版本
  21224. var _updateBound = () => {
  21225. model.updateMatrixWorld();
  21226. viewer.updateModelBound();
  21227. };
  21228. var maintainCenter = () => {
  21229. //MergeEditor.maintainBoundXY(model)
  21230. MergeEditor.maintainBoundCenter(model);
  21231. _updateBound();
  21232. model.dispatchEvent('transformChanged');
  21233. };
  21234. model.addEventListener('position_changed', () => {
  21235. _updateBound();
  21236. MergeEditor.getBoundCenter(model); //更新boundcenter
  21237. model.dispatchEvent('transformChanged');
  21238. });
  21239. model.addEventListener("rotation_changed", maintainCenter);
  21240. model.addEventListener("scale_changed", maintainCenter);
  21241. model.addEventListener('transformChanged', () => {
  21242. MergeEditor.modelTransformCallback(model);
  21243. });
  21244. }
  21245. model.updateMatrixWorld();
  21246. viewer.updateModelBound();
  21247. MergeEditor.getBoundCenter(model); //初始化
  21248. //model.lastMatrixWorld = model.matrixWorld.clone()
  21249. model.lastMatrixWorld = new Matrix4();
  21250. MergeEditor.modelTransformCallback(model);
  21251. done(model); // 先发送成功,因为2d界面会随机执行changePosition等初始化,然后这边再将模型移到中心地面上
  21252. if (prop.isFirstLoad) {
  21253. MergeEditor.moveBoundCenterTo(model, new Vector3(0, 0, 0));
  21254. MergeEditor.setModelBtmHeight(model, 0); //初始加载设置离地高度为0
  21255. if (prop.mode != 'single') {
  21256. //如果不是模型展示页,模型会随着鼠标位置移动
  21257. modelEditing = model;
  21258. /* if(model.fileType == '3dTiles'){
  21259. setTimeout(()=>{
  21260. moveModel({pointer:{x:0,y:0}}) //3dTiles的移动会错乱,先默认放在当前视图中间吧
  21261. confirmPos()
  21262. },1)
  21263. }else{ */
  21264. viewer.addEventListener('global_mousemove', moveModel);
  21265. viewer.addEventListener('global_click', confirmPos, {
  21266. importance: 3
  21267. });
  21268. //}
  21269. }
  21270. model.dispatchEvent("position_changed");
  21271. } else {
  21272. //MergeEditor.setModelBtmHeight(model, prop.bottom || 0) //默认离地高度为0
  21273. modelEditing = null;
  21274. }
  21275. MergeEditor.modelAdded(model);
  21276. };
  21277. if (prop.type == 'glb') {
  21278. var callback = object => {
  21279. //focusOnSelect(object, 1000)
  21280. object.isModel = true;
  21281. //object.dataset_id = Date.now() //暂时
  21282. object.traverse(e => e.material && (e.material.transparent = true));
  21283. /* object.addEventListener('click',(e)=>{
  21284. //只是为了能得到hoverElement识别才加这个侦听
  21285. }) */
  21286. loadDone(object);
  21287. };
  21288. var info = {
  21289. fileType: prop.type,
  21290. id: prop.id,
  21291. unlit: prop.unlit,
  21292. url: prop.url,
  21293. name: prop.title
  21294. /* transform : {
  21295. position : prop.position,
  21296. rotation : new THREE.Euler().setFromVector3(prop.rotation),
  21297. scale: new THREE.Vector3(prop.scale,prop.scale,prop.scale),
  21298. } */
  21299. };
  21300. viewer.loadModel(info, callback, onProgress, onError);
  21301. } else if (prop.type == 'osgb' || prop.type == 'b3dm') {
  21302. //3d tiles
  21303. var _callback = object => {
  21304. object.isModel = true;
  21305. //透明度怎么办
  21306. //object.traverse(e=>e.material && (e.material.transparent = true))
  21307. loadDone(object);
  21308. };
  21309. viewer.loadModel({
  21310. fileType: '3dTiles',
  21311. id: prop.id,
  21312. name: prop.title,
  21313. maximumScreenSpaceError: prop.maximumScreenSpaceError,
  21314. /* tilesUrl: 'https://4dkk.4dage.com/scene_view_data/SS-Ds19qsmuFA/images/3dtiles/tileset.json',
  21315. transform : {
  21316. rotation : [Math.PI/2, 0, 0],
  21317. position : [0,0,0]
  21318. }
  21319. tilesUrl: 'https://testgis.4dage.com/LVBADUI_qp/tileset.json',
  21320. transform : {
  21321. rotation : [0, 0, 0],
  21322. position : [0,0,0]
  21323. } */
  21324. url: prop.url
  21325. }, _callback, onprogress);
  21326. } else if (prop.type == 'shp') {
  21327. var _callback2 = object => {
  21328. object.isModel = true;
  21329. loadDone(object);
  21330. };
  21331. viewer.loadModel({
  21332. fileType: 'shp',
  21333. id: prop.id,
  21334. name: prop.title,
  21335. url: prop.url
  21336. }, _callback2, onprogress);
  21337. //shpModel.position.set(-330000, 900000,10)//尽量移动到原点。原位置在江门那
  21338. } else if (prop.type == '3dgs') {
  21339. var _callback3 = object => {
  21340. object.isModel = true;
  21341. loadDone(object);
  21342. };
  21343. viewer.loadModel({
  21344. fileType: '3dgs',
  21345. id: prop.id,
  21346. name: prop.title,
  21347. url: prop.url
  21348. }, _callback3, onprogress);
  21349. } else {
  21350. //else if(prop.type == 'las' || prop.type == 'ply' || prop.type == 'laz' )
  21351. Potree.loadPointCloudScene(prop.url, prop.type, prop.modelId, prop.title, pointcloud => {
  21352. pointcloud.matrixAutoUpdate = true;
  21353. pointcloud.initialPosition = pointcloud.position.clone();
  21354. pointcloud.pos1MatrixInvert = new Matrix4().setPosition(pointcloud.initialPosition).invert();
  21355. if (Potree.settings.mergeType2 && pointcloud.datasetData) {
  21356. Potree.loadPanos(pointcloud.datasetData.id, data => {
  21357. viewer.images360.addPanoData(data, pointcloud);
  21358. viewer.images360.loadDone();
  21359. viewer.scene.add360Images(viewer.images360);
  21360. loadDone(pointcloud);
  21361. }, prop.url);
  21362. } else {
  21363. loadDone(pointcloud);
  21364. }
  21365. }, onError, prop.prefix);
  21366. }
  21367. };
  21368. return {
  21369. THREE: THREE$1
  21370. };
  21371. }
  21372. var changeLog = () => {
  21373. var textarea = document.createElement('textarea');
  21374. textarea.id = "consoleLog";
  21375. textarea.style.width = '160px';
  21376. textarea.style.height = '200px';
  21377. textarea.style.position = 'fixed';
  21378. textarea.style.left = 0;
  21379. textarea.style.bottom = '50px';
  21380. textarea.style['z-index'] = 9999;
  21381. textarea.style.color = 'black';
  21382. textarea.style.opacity = 0.9;
  21383. textarea.style['font-size'] = '12px';
  21384. textarea.style['backgroundColor'] = '#ffffff';
  21385. document.getElementsByTagName("body")[0].appendChild(textarea);
  21386. var list = ["log", "error", "warn", "debug", "info", "time", "timeEnd"];
  21387. var exchange = function exchange(o) {
  21388. console["old" + o] = console[o];
  21389. console[o] = function () {
  21390. var args = Array.from(arguments);
  21391. console["old" + o].apply(this, arguments);
  21392. var t = document.getElementById("consoleLog").innerHTML;
  21393. var str = '';
  21394. args.forEach(a => {
  21395. str += a + ' ';
  21396. });
  21397. document.getElementById("consoleLog").innerHTML = str + "\n\n" + t;
  21398. };
  21399. };
  21400. for (var i = 0; i < list.length; i++) {
  21401. exchange(list[i]);
  21402. }
  21403. };
  21404. /*
  21405. 坐标转换问题:
  21406. 由于控制点可以随便输入,所以本地和地理位置的转换也是可拉伸的。而navvis的转换是等比由中心展开,
  21407. 所以对比两种转化方式时误差较大。
  21408. 另外地理注册控制点是有参考数据集的,若参考数据集和我放置在0,0,0的数据集一致,就可直接使用,否则要转换。
  21409. ---------
  21410. lonlat和空间坐标其实并非线性关系,因为lonlat其实是角度。当两个数据集在地球两端时,它们之间的夹角都相差180度了。
  21411. 所以若要准确展示的话,需要将点云内所有物体,如漫游点,都先获取lonlat再去算local。或者直接将点云整体的transformMatrix考虑上在地球上相对于初始数据集的偏转。
  21412. 支持ctrl+z、ctrl+Y 撤销回退的页面有:
  21413. 测量、土方量、空间模型 这三个页面的点线拖拽;点云裁剪、点云下载中的裁剪 的框; 点云编辑的变换; 数据集校准;
  21414. (所有数据一旦删除则无效 )
  21415. 其他快捷键:
  21416. 按alt鼠标滚轮或WS键放慢。
  21417. 测量or土方量: 按Alt键可以平行拖拽点。&dragPolyBeyondPoint 后缀则可平行拖拽到无点云区域 。
  21418. 按M键拖拽点可以复制出当前点
  21419. 点云按空格键+左键拖拽场景,可以不改相机位置的旋转视角
  21420. */
  21421. //xzw add
  21422. var config$1 = {
  21423. //配置参数 不可修改
  21424. displayMode: {
  21425. showPointCloud: {
  21426. atPano: {
  21427. showPoint: true,
  21428. showSkybox: false,
  21429. pointUsePanoTex: false
  21430. },
  21431. transition: {
  21432. showPoint: true,
  21433. showSkybox: false,
  21434. pointUsePanoTex: false
  21435. },
  21436. canLeavePano: true //是否能离开pano位置
  21437. },
  21438. showPanos: {
  21439. atPano: {
  21440. showPoint: false,
  21441. showSkybox: true,
  21442. pointUsePanoTex: false
  21443. },
  21444. transition: {
  21445. //showPoint: true,
  21446. showSkybox: true
  21447. //pointUsePanoTex: true //是否使用全景贴图
  21448. },
  21449. canLeavePano: false
  21450. },
  21451. showBoth: {
  21452. atPano: {
  21453. showPoint: true,
  21454. showSkybox: true,
  21455. pointUsePanoTex: false //?
  21456. },
  21457. transition: {
  21458. showPoint: true,
  21459. showSkybox: true,
  21460. pointUsePanoTex: true
  21461. },
  21462. canLeavePano: true //是否能离开pano位置 离开后自动变为showPointCloud
  21463. },
  21464. //test:
  21465. pointUsePanoTex: {
  21466. //---静止时调点云
  21467. atPano: {
  21468. showPoint: true,
  21469. showSkybox: false,
  21470. pointUsePanoTex: true
  21471. },
  21472. transition: {
  21473. showPoint: true,
  21474. showSkybox: true,
  21475. pointUsePanoTex: true //是否使用全景贴图
  21476. },
  21477. canLeavePano: false
  21478. }
  21479. },
  21480. urls: {
  21481. //localTextures:'../resources/textures/',
  21482. prefix1: 'https://laser-oss.4dkankan.com',
  21483. //oss
  21484. prefix2: 'https://testlaser.4dkankan.com',
  21485. prefix3: 'https://4dkk.4dage.com',
  21486. prefix4: 'https://uat-laser.4dkankan.com',
  21487. //test.4dkankan
  21488. prefix5: 'https://laser.4dkankan.com/backend',
  21489. prefix6: 'https://mix3d.4dkankan.com/backend',
  21490. //融合
  21491. prefix7: 'https://xfhd.4dkankan.com/backend' //融合
  21492. },
  21493. transitionsTime: {
  21494. flyMinTime: 650,
  21495. // 毫秒/米
  21496. flytimeDistanceMultiplier: 120
  21497. },
  21498. view: {
  21499. fov: 70,
  21500. //navvis:50
  21501. near: 0.1,
  21502. far: 10000
  21503. },
  21504. map: {
  21505. //mapViewer
  21506. mapHeight: -1000,
  21507. //要比点云低。最低
  21508. cameraHeight: 1000 //最高 ,注意(如sitemodel)其他的物体不能超过这个高度
  21509. },
  21510. minNodeSize: 30,
  21511. // perspectiveCamera允许加载的node的最小可见像素宽度。越大越省性能
  21512. tiles3DMaxMemory: 300,
  21513. //M. 最大支持3dTiles的内存大小 超出会崩溃。 改太小太大都会卡,太大崩溃
  21514. pointDensity: {
  21515. magnifier: {
  21516. maxLevelPercent: 1,
  21517. pointBudget: 1 * 1000 * 1000,
  21518. //至少显示这么多
  21519. minNodeSize: 5 //pick时调高精度
  21520. },
  21521. panorama: {
  21522. //显示全景时的漫游。因为点只能显示1个像素的大小,所以必须很密集,但又要限制点的数量
  21523. maxLevelPercent: 0.6,
  21524. pointBudget: /* 4*1000*1000// */browser.isMobile() ? 0.2 * 1000 * 1000 : 0.4 * 1000 * 1000,
  21525. //点云总最大数
  21526. minNodeSize: 100
  21527. },
  21528. fourViewports: {
  21529. //分四屏时防止卡顿
  21530. maxLevelPercent: 0.9,
  21531. pointBudget: 3 * 1000 * 1000,
  21532. // 只要限制这个就足够 (为什么分屏focus区域不同会闪烁,navvis不会)(navvis:maxLevel:5,pointBudget:1*1000*1000)
  21533. minNodeSize: 70
  21534. },
  21535. fourViewportsMain: {
  21536. //分四屏时防止卡顿
  21537. maxLevelPercent: 0.9,
  21538. pointBudget: 3 * 1000 * 1000,
  21539. // 只要限制这个就足够 (为什么分屏focus区域不同会闪烁,navvis不会)(navvis:maxLevel:5,pointBudget:1*1000*1000)
  21540. minNodeSize: 70
  21541. },
  21542. panoEdit: {
  21543. maxLevelPercent: 1,
  21544. //在远处时由于pointBudget限制而展示稀疏,凑近时就变为最高质量了
  21545. pointBudget: 4 * 1000 * 1000,
  21546. //要使点云达到200个以上时还不卡
  21547. percentByUser: true,
  21548. minNodeSize: 80 //点云多的话远处的尽量就不可见吧
  21549. },
  21550. low: {
  21551. //highPerformance
  21552. maxLevelPercent: 0.4,
  21553. //最小为0
  21554. percentByUser: true,
  21555. //如果用户定义了percent,使用用户的
  21556. pointBudget: browser.isMobile() ? 1 * 1000 * 1000 : 2 * 1000 * 1000,
  21557. minNodeSize: 40 / window.devicePixelRatio
  21558. },
  21559. middle: {
  21560. //balanced //不同场景相同级别所产生的numVisibleNodes和numVisiblePoints不同,如果分层比较细,可能要到level8才能看清,那么level5看到的点就很大且很少,如隧道t-e2Kb2iU
  21561. maxLevelPercent: 0.7,
  21562. percentByUser: true,
  21563. pointBudget: browser.isMobile() ? 1.5 * 1000 * 1000 : 3.5 * 1000 * 1000,
  21564. minNodeSize: 30 / window.devicePixelRatio
  21565. },
  21566. high: {
  21567. //highQuality
  21568. maxLevelPercent: 1,
  21569. percentByUser: true,
  21570. pointBudget: browser.isMobile() ? 3 * 1000 * 1000 : 6 * 1000 * 1000,
  21571. //原本最高是8,但是大部分电脑都太卡了,降
  21572. minNodeSize: 20 / window.devicePixelRatio //手机上因为像素点小,远一点的时候更需要加载密集的点云。(没事,有pointBudget限制着,会先从近处加载高级node,再远就不加载了)
  21573. },
  21574. screenshot: {
  21575. maxLevelPercent: 1,
  21576. pointBudget: browser.isMobile() ? 4 * 1000 * 1000 : 10 * 1000 * 1000,
  21577. //一般只有电脑需要截图,手机的加载多会崩
  21578. minNodeSize: 40 / window.devicePixelRatio
  21579. },
  21580. screenshot2: {
  21581. maxLevelPercent: 1,
  21582. pointBudget: browser.isMobile() ? 8 * 1000 * 1000 : 15 * 1000 * 1000,
  21583. minNodeSize: 20 / window.devicePixelRatio
  21584. },
  21585. ultraHigh: {
  21586. maxLevelPercent: 1,
  21587. pointBudget: 20 * 1000 * 1000,
  21588. minNodeSize: 10 / window.devicePixelRatio
  21589. }
  21590. //数值由testLevelSteps得来,其中nodeMaxLevel为2时,low和middle的都是1,如果真有这么低的点云就单独处理下。
  21591. //多个viewport尽量保证pointBudget一样,或者pointBudget不能太低于所需,否则会反复加载了又清除
  21592. },
  21593. clip: {
  21594. color: '#FFC266' //map
  21595. },
  21596. measure: {
  21597. color: '#00C8AF',
  21598. default: {
  21599. color: "#64C8BB",
  21600. //"#00c7b2",
  21601. opacity: 0.7
  21602. },
  21603. highlight: {
  21604. color: '#00C8AF',
  21605. //"#00c7b2",
  21606. opacity: 1,
  21607. labelOpacity: 0.7 //1会挡住线和端点
  21608. },
  21609. guide: {
  21610. color: '#FFFFFF',
  21611. opacity: 0.8
  21612. },
  21613. backColor: '#333333',
  21614. lineWidth: 3,
  21615. textColor: "#000000",
  21616. //"#FFFFFF"
  21617. mulLabelHideFaraway: false,
  21618. // 多折线根据远近显示label
  21619. adsorptMinDis: 30 //最小吸附距离(像素)
  21620. },
  21621. material: {
  21622. //初始化
  21623. pointSize: 0.1,
  21624. realPointSize: 0.1,
  21625. //实际上的ui滑动条默认大小(兼容旧的版本)
  21626. minSize: 0.1,
  21627. maxSize: 10000,
  21628. pointSizeType: 'ATTENUATED',
  21629. //'ADAPTIVE'//'ADAPTIVE' \ FIXED //ADAPTIVE的在小房间里大小会不太匹配,但在远景似乎更好
  21630. /*
  21631. ATTENUATED : 衰减 真实大小,靠近时感觉是点云一点点变多,缝隙变小
  21632. ADAPTIVE: 自适应 大小根据level变化,越高越小。靠近时感觉点云由大慢慢细分成小份。这个感觉更佳但是navvis为何不用这个
  21633. */
  21634. absolutePanoramaSize: 1.3,
  21635. //全景漫游时的size 是fixed的模式
  21636. //sizeAtPanoRtEDL : 2000,
  21637. pointColor: '#ffffff'
  21638. //sizeAddAtPanoRtEDL : 0.5, //全景模式静止时的size
  21639. //ADAPTIVE : 字会失真扭曲
  21640. //'ATTENUATED' 往旁边看有缝隙、点在浮动
  21641. },
  21642. skyboxBgWidth: 100,
  21643. renderLayers: {
  21644. //渲染层,方便分批渲染管理,替代scene的创建。数字不代表顺序。(数字不能太大)
  21645. bg: 20,
  21646. bg2: 21,
  21647. skybox: 1,
  21648. pointcloud: 11,
  21649. sceneObjects: 0,
  21650. //default
  21651. model: 2,
  21652. light: 15,
  21653. measure: 4,
  21654. magnifier: 5,
  21655. magnifierContent: 16,
  21656. volume: 6,
  21657. transformationTool: 7,
  21658. map: 8,
  21659. mapObjects: 9,
  21660. //default
  21661. bothMapAndScene: 3,
  21662. siteModeOnlyMapVisi: 12,
  21663. //只能mapViewer可见
  21664. siteModelMapUnvisi: 13,
  21665. //只有mapViewer不可见
  21666. siteModeSideVisi: 14,
  21667. //只有侧面可见
  21668. layer1: 18,
  21669. // 备用1
  21670. layer2: 17 // 备用2
  21671. },
  21672. renderOrders: {
  21673. //会影响到绘制、pick时的顺序。
  21674. model: 10,
  21675. reticule: 5,
  21676. measureMarker: 6,
  21677. measureLabelSub: 7,
  21678. measureLabel: 8,
  21679. sorptionSign: 10,
  21680. model: 10,
  21681. magnifier: 50
  21682. },
  21683. siteModel: {
  21684. names: {
  21685. 'building': '建筑',
  21686. 'floor': '楼层',
  21687. 'room': '房间'
  21688. },
  21689. floorHeightDefault: 5 //一层楼的高度
  21690. },
  21691. panosEdit: {},
  21692. tiling: {
  21693. panoPreRenderRepeatDelay: 2500,
  21694. panoPreRenderDelay: 500,
  21695. preRenderTourPanos: browser.valueFromHash("tileprerender", 0),
  21696. tilingFlagNames: ["usetiles", "tiles"],
  21697. maxNavPanoQuality: browser.valueFromHash("maxtileq", null),
  21698. maxZoomPanoQuality: browser.valueFromHash("maxztileq", null),
  21699. overlayStyle: browser.valueFromHash("tileoverlay", 0),
  21700. uploadIntervalDelay: browser.valueFromHash("tileupdelay", 10),
  21701. initialIntervalDelay: browser.valueFromHash("itiledelay", 0),
  21702. maxNonBaseUploadsPerFrame: browser.valueFromHash("maxnbtpf", 1),
  21703. maxBaseUploadsPerFrame: browser.valueFromHash("maxbtpf", 6),
  21704. customCompression: browser.valueFromHash("tilecustcomp", 0),
  21705. mobileHighQualityOverride: !1,
  21706. allowUltraHighResolution: !0
  21707. },
  21708. navigation: {
  21709. panoScores: !1,
  21710. mouseDirection: !0,
  21711. filterStrictness: .75,
  21712. angleFactor: -30,
  21713. directionFactor: 10,
  21714. distanceFactor: -1,
  21715. optionalityFactor: 3
  21716. },
  21717. axis: {
  21718. 'x': {
  21719. color: '#ea3f3f' /* '#d0021b' */ /* 'red' */
  21720. },
  21721. 'y': {
  21722. color: '#86c215' /* '#86c542' */ /* 'green' */
  21723. },
  21724. 'z': {
  21725. color: '#3396f8' /* '#3399c8' */ /* 'blue' */
  21726. },
  21727. 'xyz': {
  21728. color: '#ccc'
  21729. }
  21730. },
  21731. shelterMargin: 0.15,
  21732. //多少米内不算遮挡 (有的场景深度图不准,和点云差别蛮大如SG-t-24F0iT3pKAO)
  21733. highQualityMaxZoom: 2,
  21734. ultraHighQualityMaxZoom: 3,
  21735. panoFieldRadius: 10,
  21736. //当前位置多远范围内可以切全景模式
  21737. clickMaxDragDis: 3,
  21738. clickMaxPressTime: 200,
  21739. //ms
  21740. doubleClickTime: 300,
  21741. //双击间隔时间
  21742. testNodeCount1: browser.isMobile() ? 6 : 4,
  21743. //testMaxNode次数达到这个数字时,changePointSize才使用nodeMaxLevel。 (调试时比较卡,在线上实际只需要3)
  21744. background: '#232323',
  21745. mapBG: /* '#232323', */'#F5F5F5',
  21746. //地图的clearColor
  21747. pickFrontPointRatio: 50,
  21748. colors: {
  21749. //from navvis
  21750. red: [213, 0, 0],
  21751. pink: [197, 17, 98],
  21752. purple: [170, 0, 255],
  21753. "deep purple": [98, 0, 234],
  21754. blue: [41, 98, 255],
  21755. "light blue": [0, 145, 234],
  21756. cyan: [0, 184, 212],
  21757. teal: [0, 191, 165],
  21758. green: [0, 200, 83],
  21759. "light green": [100, 221, 23],
  21760. lime: [174, 234, 0],
  21761. yellow: [255, 214, 0],
  21762. amber: [255, 171, 0],
  21763. orange: [255, 109, 0],
  21764. "deep orange": [255, 61, 0]
  21765. },
  21766. depthTexUVyLimit: 0.141 // 在这个范围内是没有深度的,从图片算的0.14003, 设置为稍大于这个数值
  21767. };
  21768. config$1.OrthoCameraLimit = {
  21769. standard: {
  21770. zoom: {
  21771. min: 0.0004,
  21772. max: 500
  21773. },
  21774. //如果camera缩太小,地图会因为数字边界问题而扭曲
  21775. latPad: 20,
  21776. xBound: [-4e6, 4e6]
  21777. },
  21778. expand: {
  21779. zoom: {
  21780. min: 0.0004,
  21781. max: 500
  21782. },
  21783. //如果camera缩太小,地图会因为数字边界问题而扭曲
  21784. latPad: 20,
  21785. xBound: [-6e6, 6e6]
  21786. }
  21787. };
  21788. /* 显示模式:
  21789. 1只显示点云: 滚轮为前进后退,方向键可以行走。进入漫游点时自动变为混合(这样全景可以弥补缝隙),过渡时只显示点云。
  21790. 2只显示全景: 不能任意行走。 过渡时显示贴图材质非edl的点云(否则有折痕不贴合)。
  21791. 3混合:都显示。 不能任意行走。过渡时显示贴图材质非edl的点云(因为只显示点云的话不太美,点云很碎,不细腻)
  21792. */
  21793. window.testLevelSteps = function (steps) {
  21794. //[0.4,0.7,1]
  21795. if (!steps) {
  21796. var s = Potree.config.pointDensity;
  21797. steps = [s.low.maxLevelPercent, s.middle.maxLevelPercent, s.high.maxLevelPercent];
  21798. }
  21799. var max = 1;
  21800. while (++max <= 12) {
  21801. var r1 = steps.map(e => e * max);
  21802. var r2 = steps.map(e => Math.round(e * max));
  21803. console.log("\u5F53nodeMaxLevel\u4E3A".concat(max, "\u65F6\uFF0C\u6BCF\u4E00\u7EA7\u7684level\u5206\u522B\u4E3A").concat(r2, ", (\u5C0F\u6570\uFF1A").concat(r1, ")"));
  21804. }
  21805. console.log('请检查每一层的三个level是否有重复');
  21806. };
  21807. function getPrefix() {
  21808. var u = window.location.href.split('//');
  21809. var v = u[1].split('/');
  21810. return v[0];
  21811. }
  21812. var isTest = browser.urlHasValue('test');
  21813. var settings = {
  21814. //设置 可修改
  21815. editType: '',
  21816. number: '',
  21817. //场景序号
  21818. originDatasetId: '',
  21819. //场景原本的数据集id,应该就是数据集第一个吧
  21820. isOfficial: false,
  21821. webSite: 'testdata',
  21822. //正式:'datav1', //不同环境对应的静态文件的地址不同
  21823. isLocal: false,
  21824. //是否本地 局域网版本
  21825. libsUrl: '../libs/',
  21826. displayMode: '',
  21827. isTest,
  21828. prefix: getPrefix(),
  21829. pointDensity: '',
  21830. UserPointDensity: '',
  21831. //pointDensity会随着进入不同的模块而自动改变,UserPointDensity记录了用户的设置
  21832. UserDensityPercent: null,
  21833. //点云密度百分比
  21834. ifShowMarker: true,
  21835. //显示漫游点
  21836. floorplanType: {},
  21837. //平面图类型 'default' | 'diy' 不同数据集不同{datasetId:...}
  21838. floorplanEnable: false,
  21839. floorplanEnables: {},
  21840. floorplanRequests: {},
  21841. //开始加载了的
  21842. mapEnable: true,
  21843. //地图区域是否加载地图
  21844. cameraFar: config$1.view.far,
  21845. //相机最远范围 1-300
  21846. //limitFar: true, //是否使用setting的cameraFar来限制(如在点云裁剪时为false)
  21847. showPanoMesh: false,
  21848. //显示小球,
  21849. dblToFocusPoint: false,
  21850. //调试时如果需要双击飞向某个点云的点,就打开。此时不在漫游点的话单击将无法漫游。//因和单击漫游冲突
  21851. unableNavigate: false,
  21852. //进入如裁剪界面时 禁止漫游
  21853. sizeFitToLevel: false,
  21854. //当type为衰减模式时自动根据level调节大小。每长一级,大小就除以2
  21855. zoom: {
  21856. enabled: true,
  21857. min: 1,
  21858. max: config$1.highQualityMaxZoom
  21859. },
  21860. navConstantly: true,
  21861. navTileClass: /* browser.isMobile() ? '1k' : */'2k',
  21862. //默认加载到
  21863. tileClass: '4k',
  21864. //最高可达
  21865. /* loadTilesWhenUnfocus:false, //页面unfocus时也仍在加载tiles
  21866. loadPointsWhenUnfocus:true, //页面unfocus时也仍在加载点云 */
  21867. //initialShowPano:true
  21868. drawEntityData: false,
  21869. //包括marker、线
  21870. zoomFromPointert: {
  21871. //定点缩放(包括点云模式、全景模式、地图)
  21872. whenPanos: true,
  21873. whenPointCloud: true,
  21874. map: true
  21875. },
  21876. rotAroundPoint: true,
  21877. //点云模式是否能绕intersectPoint旋转
  21878. tourTestCameraMove: false,
  21879. //测试镜头时,不移动真实的镜头, 只移动frustum
  21880. cameraAniSmoothRatio: 20,
  21881. //镜头动画平滑系数,越高越平滑
  21882. urls: $.extend({}, config$1.urls, {
  21883. prefix: config$1.urls.prefix4 //主要使用的 是测试环境,根据不同工程更改
  21884. }),
  21885. useDepthTex: true,
  21886. //使用深度贴图,但不代表一定有(得到的intersect更快速准确和稳定) SS-t-7DUfWAUZ3V
  21887. //matUseDepth:false,
  21888. //panoEdit:
  21889. datasetsPanos: {},
  21890. //mergeModel:
  21891. boundAddObjs: false,
  21892. intersectOnObjs: false,
  21893. intersectWhenHover: true,
  21894. depTexLocBindDataset: true,
  21895. //是否在pano模式下,使用深度图得到intersect的话,改intersect能属于该pano所在的点云。也就相当于在全景模式下intersect的点属于该全景图
  21896. notAdditiveBlending: false,
  21897. //点云是否使用普通的blend, 否则会曝光过渡
  21898. precision: 2,
  21899. // 两位小数
  21900. unit: 'm',
  21901. useV4url: true,
  21902. //v4的全景图等路径不一样 scene_view_data
  21903. useRTskybox: true,
  21904. //直接使用rtEDL绘制到屏幕,当是全景模式时. 在降4倍时能给render节省1毫秒,gpu时间未测
  21905. useRTPoint: true,
  21906. //直接使用rtEDL绘制到屏幕,当是点云模式时。可以大大节省gpu时间。但有锯齿
  21907. pointEnableRT: false,
  21908. //点云模式时是否绘制到rtEDL。如果不需要遮挡效果就不需绘制
  21909. cloudSameMat: true,
  21910. //因为点云个数较多,就使用相同的材质,可见降低绘制速度(要保证所有点云的maxNodelevel一样,且要算出 material.spacing的平均值)
  21911. showCompass: false,
  21912. showAxis: isTest,
  21913. //testCube : true,
  21914. // moveToCenter:true, //针对数据集间隔很远的场景 dis>5000 容易抖动
  21915. tiles3DMaxMemory: config$1.tiles3DMaxMemory,
  21916. adsorption: false,
  21917. //测量时吸附点
  21918. pickFrontPointRatio: config$1.pickFrontPointRatio,
  21919. //默认pick点云时选中靠近镜头的点的偏向
  21920. dragPolyBeyondPoint: browser.urlHasValue('dragPolyBeyondPoint'),
  21921. //ctrlPolygon是否可以拖拽到没点云的地方
  21922. panoZoomByPointer: false,
  21923. //全景图是否定点缩放
  21924. areaAtNotPlane: false
  21925. //fastTran: isTest
  21926. };
  21927. Potree.config = config$1;
  21928. Potree.settings = settings;
  21929. settings.isLocalhost = settings.prefix.includes('localhost:') || settings.prefix.includes('localhost:');
  21930. settings.isFormal = browser.urlHasValue('formal'); //正式环境 本地测试
  21931. if (settings.isFormal) {
  21932. settings.urls.prefix = settings.urls.prefix5;
  21933. settings.webSite = 'datav1';
  21934. }
  21935. /* let sid = 0
  21936. let getName = ()=>{
  21937. return sid ++
  21938. } */
  21939. class BasicMaterial extends ShaderMaterial {
  21940. constructor() {
  21941. var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  21942. super(Object.assign({}, {
  21943. uniforms: {
  21944. color: {
  21945. type: 'v3',
  21946. value: o.color || new Color("#FFF")
  21947. },
  21948. map: {
  21949. type: 't',
  21950. value: o.map
  21951. },
  21952. opacity: {
  21953. type: 'f',
  21954. value: o.opacity == void 0 ? 1 : o.opacity
  21955. }
  21956. },
  21957. vertexShader: Shaders['basicTextured.vs'],
  21958. fragmentShader: Shaders['basicTextured.fs'],
  21959. defines: {
  21960. HasColor: ''
  21961. }
  21962. }, o));
  21963. //this.name111 = getName()
  21964. }
  21965. copy(source) {
  21966. super.copy(source);
  21967. //console.log('copy', source.name111, this.name111, !!source.map )
  21968. this.map = source.map;
  21969. return this;
  21970. }
  21971. set opacity(o) {
  21972. this.uniforms && (this.uniforms.opacity.value = o);
  21973. }
  21974. get opacity() {
  21975. return this.uniforms.opacity.value;
  21976. }
  21977. set map(o) {
  21978. this.uniforms.map.value = o;
  21979. if (o) {
  21980. this.defines.HasMap = '';
  21981. } else {
  21982. delete this.defines.HasMap;
  21983. }
  21984. //可能需要needsUpdate
  21985. //console.log('hasMap', !!o, this.name111 )
  21986. }
  21987. get map() {
  21988. return this.uniforms.map.value;
  21989. }
  21990. }
  21991. var texLoader$2 = new TextureLoader();
  21992. texLoader$2.crossOrigin = "anonymous";
  21993. var createErrorMaterial = function createErrorMaterial() {
  21994. var t = new MeshBasicMaterial({
  21995. transparent: !0,
  21996. depthWrite: !1,
  21997. depthTest: !0,
  21998. opacity: 1,
  21999. side: DoubleSide
  22000. });
  22001. return t.color = new Color(3355443), t;
  22002. };
  22003. var tempVector = new Vector3(),
  22004. //sharedata
  22005. face1 = new Face3(0, 1, 2),
  22006. face2 = new Face3(2, 3, 0),
  22007. errorMaterial = createErrorMaterial(),
  22008. uv00 = new Vector2(0, 0),
  22009. uv01 = new Vector2(0, 1),
  22010. uv10 = new Vector2(1, 0),
  22011. uv11 = new Vector2(1, 1),
  22012. face1UV = [uv00, uv10, uv11],
  22013. face2UV = [uv11, uv01, uv00];
  22014. var HALF_WORLD_SIZE = 21e6; //略大于半个周长(mapSizeM/2)
  22015. var MAX_VERTICAL_DIST = 2;
  22016. var MAX_VERTICAL_DIST_TO_BEST = 1;
  22017. function defineLocalProj(locationLonLat) {
  22018. proj4.defs("LOCAL_MAP", "+proj=tmerc +ellps=WGS84 +lon_0=" + locationLonLat[0].toPrecision(15) + " +lat_0=" + locationLonLat[1].toPrecision(15));
  22019. }
  22020. var getSid = function () {
  22021. var sid = 0;
  22022. return function () {
  22023. return sid++;
  22024. };
  22025. }();
  22026. //高德坐标拾取工具 : https://lbs.amap.com/tools/picker
  22027. class MapLayer extends EventDispatcher {
  22028. // 包括了 MapLayerBase SceneLayer
  22029. constructor(viewer_, viewport) {
  22030. super();
  22031. this.sceneGroup = new Object3D();
  22032. this.sceneGroup.name = "MapLayer";
  22033. this.waitQueue = []; //等待加载的
  22034. this.loadingInProgress = 0;
  22035. this.maps = [];
  22036. this.frustum = new Frustum();
  22037. this.frustumMatrix = new Matrix4();
  22038. this.tileColor = new Color(16777215);
  22039. this.viewport = viewport;
  22040. this.changeViewer(viewer_);
  22041. //添加地图
  22042. var map = new TiledMapOpenStreetMap(this, this.tileColor);
  22043. this.addMap(map);
  22044. //map.setEnable(false)
  22045. this.sceneGroup.addEventListener('isVisible', () => {
  22046. this.viewer.mapChanged = true;
  22047. });
  22048. }
  22049. addMapEntity(data, datasetId) {
  22050. if (!data || !data[0]) {
  22051. Potree.Log('平面图无数据', {
  22052. font: 'red'
  22053. });
  22054. return;
  22055. }
  22056. data[0].datasetId = datasetId;
  22057. var floorplan = new TiledMapFromEntity(this, this.tileColor, data[0]); //[0]?
  22058. if (floorplan) {
  22059. floorplan.name += "_" + datasetId;
  22060. this.addMap(floorplan);
  22061. floorplan.updateProjection();
  22062. floorplan.updateObjectGroup();
  22063. var visible = false;
  22064. if (datasetId in Potree.settings.floorplanEnables) {
  22065. visible = Potree.settings.floorplanEnables[datasetId];
  22066. } else {
  22067. visible = Potree.settings.floorplanEnable;
  22068. }
  22069. if (visible) {
  22070. this.needUpdate = true;
  22071. } else {
  22072. floorplan.setEnable(false);
  22073. }
  22074. this.dispatchEvent({
  22075. type: 'floorplanLoaded',
  22076. floorplan
  22077. });
  22078. }
  22079. return floorplan;
  22080. }
  22081. getFloorplan(datasetId) {
  22082. return this.maps.find(e => e.name == 'floorplan' + "_" + datasetId);
  22083. }
  22084. addMap(t) {
  22085. this.maps.push(t);
  22086. //this.view.invalidateScene()
  22087. this.needUpdate = true;
  22088. this.viewer.mapChanged = true;
  22089. }
  22090. removeMap(t) {
  22091. var e = this.maps.indexOf(t);
  22092. if (e >= 0) {
  22093. t.removeFromSceneGroup(this.sceneGroup);
  22094. this.maps.splice(e, 1);
  22095. }
  22096. /* this.view.invalidateScene() */
  22097. this.needUpdate = true;
  22098. this.viewer.mapChanged = true;
  22099. }
  22100. changeViewer(viewer_) {
  22101. //add
  22102. this.viewer = viewer_;
  22103. }
  22104. initProjection() {
  22105. this.maps.forEach(map => {
  22106. map.updateProjection();
  22107. map.updateObjectGroup();
  22108. });
  22109. }
  22110. visibilityChanged() {
  22111. if (!this.visible) for (var t = 0, e = this.maps; t < e.length; t++) {
  22112. e[t].removeFromSceneGroup(this.sceneGroup);
  22113. }
  22114. }
  22115. update() {
  22116. this.needUpdate = false;
  22117. if (this.disabled || !this.maps.find(e => !e.disabled) || !this.maps.find(e => e.objectGroup.visible)) return; //add
  22118. this.viewer.mapChanged = true;
  22119. var e, n, i, r, o;
  22120. this.updateTimer = void 0, e = this.viewport.camera, n = e.projectionMatrix.clone();
  22121. var expandRatio = 1.3;
  22122. n.elements[0] /= expandRatio;
  22123. n.elements[5] /= expandRatio; // 为了缓存吗,使边界处也提前加载,扩大显示区域
  22124. this.frustumMatrix.multiplyMatrices(n, e.matrixWorldInverse), this.frustum.setFromProjectionMatrix(this.frustumMatrix), this.frustum.planes[4].setComponents(0, 0, 0, 0), this.frustum.planes[5].setComponents(0, 0, 0, 0), i = !0;
  22125. //console.log('-------------update-----------')
  22126. for (r = 0; r < this.maps.length; r++) {
  22127. var map = this.maps[r];
  22128. i = map.update(this.frustum, this.sceneGroup) && i;
  22129. }
  22130. return [2, i];
  22131. }
  22132. updateProjection() {
  22133. for (var t = 0, e = this.maps; t < e.length; t++) {
  22134. var n = e[t];
  22135. n.clearProjection(), n.updateObjectGroup();
  22136. }
  22137. }
  22138. }
  22139. class TiledMapBase extends EventDispatcher {
  22140. constructor(name, mapLayer, tileColor, projection) {
  22141. super();
  22142. this.name = name;
  22143. this.mapLayer = mapLayer, this.tileColor = tileColor, this.bias = 0;
  22144. this.zIndex = -1;
  22145. this.objectGroup = new Object3D();
  22146. this.objectGroup.name = name;
  22147. this.objectGroupAdded = !1, this.baseTile = new MapTile(this, this.objectGroup, this.tileColor, null, '0'), this.isTileVisibleBox = new Box3(), this.isTileVisibleVec = new Vector3();
  22148. this.projection = projection;
  22149. this._zoomLevel = 0; //1-20
  22150. this.objectGroup.addEventListener('isVisible', () => {
  22151. this.mapLayer.viewer.mapChanged = true;
  22152. });
  22153. this.computeCount = 0;
  22154. this.maxLoading = 3;
  22155. this.loadFailCount = 0;
  22156. this.loadingInProgress = 0;
  22157. }
  22158. get zoomLevel() {
  22159. return this._zoomLevel;
  22160. }
  22161. set zoomLevel(zoomLevel) {
  22162. if (this._zoomLevel != zoomLevel) {
  22163. this._zoomLevel = zoomLevel;
  22164. this.dispatchEvent({
  22165. type: 'zoomLevelChange',
  22166. zoomLevel
  22167. });
  22168. //if(this.name == 'map')console.log(zoomLevel,viewer.mapViewer.camera.zoom)
  22169. }
  22170. }
  22171. updateObjectGroup() {
  22172. this.position && this.objectGroup.position.copy(this.position).setZ(0), this.quaternion && this.objectGroup.quaternion.copy(this.quaternion), this.objectGroup.updateMatrixWorld(!0);
  22173. }
  22174. updateProjection() {
  22175. if (!this.transformMapToLocal) {
  22176. this.transformMapToLocal = proj4(this.projection, "LOCAL_MAP");
  22177. }
  22178. }
  22179. clearProjection() {
  22180. this.transformMapToLocal = void 0;
  22181. this.projection !== 'LOCAL_MAP' && this.baseTile.remove();
  22182. }
  22183. setEnable(enable) {
  22184. //add
  22185. if (!this.disabled == enable) return;
  22186. if (enable) {
  22187. //console.log('setEnable',true)
  22188. }
  22189. this.disabled = !enable;
  22190. Potree.Utils.updateVisible(this.objectGroup, 'setEnable', enable);
  22191. if (!enable) {
  22192. this.baseTile.remove();
  22193. } else {
  22194. this.mapLayer.needUpdate = true;
  22195. }
  22196. }
  22197. update(e, n) {
  22198. this.computeCount = 0;
  22199. var unavailable = this.disabled || !this.objectGroup.visible; //地图即使不显示也要获得zoomlevel
  22200. if (this.name != 'map' && unavailable) return;
  22201. this.updateProjection();
  22202. if (!this.transformMapToLocal) return;
  22203. if (!this.isTileVisible(new Vector3(0, 0, 0), this.mapSizeM, e)) return this.removeFromSceneGroup(n), !0;
  22204. var viewport = this.mapLayer.viewport;
  22205. var i = new Vector3(-.5 * this.mapSizeM, 0, 0);
  22206. i.applyMatrix4(this.objectGroup.matrixWorld), i.project(viewport.camera);
  22207. var o = new Vector3(.5 * this.mapSizeM, 0, 0);
  22208. o.applyMatrix4(this.objectGroup.matrixWorld), o.project(viewport.camera);
  22209. var a = viewport.resolution.x,
  22210. s = viewport.resolution.y;
  22211. if (a <= 0 || s <= 0 || isNaN(i.x) || isNaN(o.x)) return !1;
  22212. i.sub(o), i.x *= a / 2, i.y *= s / 2;
  22213. var scale;
  22214. if (this.name == 'map') {
  22215. //add 高纬度的因倾斜而造成tile较小,所以放大些,否则会造成显示的tile过多而卡
  22216. var lonlat = viewer.transform.lonlatToLocal.inverse(viewport.camera.position.clone());
  22217. var cos = Math.cos(MathUtils.degToRad(lonlat.y)); //越小就在纬度上越高,tile表现越小
  22218. //为什么lonlat.y会超出90?
  22219. /* if(lonlat.y>90){
  22220. console.log('lonlat.y>90',lonlat.y)
  22221. } */
  22222. cos = MathUtils.clamp(cos, 0, 1);
  22223. var lonShift = Math.abs(viewer.mapViewer.camera.position.x / this.mapSizeM * 16); //越大就在经度离中心越远,tile表现越大 。
  22224. lonShift = MathUtils.clamp(lonShift, 0, Math.PI);
  22225. lonShift = (1 - Math.sin(1 / 2 * lonShift + Math.PI / 2)) * Math.PI; // 0-Math.PI sin增速向上
  22226. scale = 0.5 * cos * (1 + lonShift) + 0.5 * Math.pow(cos, lonShift);
  22227. } else {
  22228. scale = 1;
  22229. }
  22230. var c = this.tileSizePx / i.length() / scale //多除以一个scale缩放因子,scale越大level越小
  22231. ,
  22232. level = Math.ceil(-Math.log(c) / Math.log(2) - this.bias);
  22233. if (this.style == 'dark-standard') {
  22234. //该模式贴图比较小放大点
  22235. level -= 1;
  22236. }
  22237. level = Math.max(level, 0);
  22238. level = Math.min(level, void 0 === this.maxDepth ? 1 / 0 : this.maxDepth);
  22239. this.zoomLevel = level; //add
  22240. /* if(isNaN(this.zoomLevel )){
  22241. console.log(level, cos , scale , lonlat )
  22242. } */
  22243. if (!unavailable) {
  22244. this.addToSceneGroup(n);
  22245. return this.baseTile.update(this, e, level, this.mapSizeM, 0, 0, "");
  22246. }
  22247. }
  22248. isTileVisible(e, n, i) {
  22249. if (n > HALF_WORLD_SIZE) return !0;
  22250. var r = .5 * n;
  22251. //简单版:
  22252. this.transformMapToLocal.forward(e); //e转化为local
  22253. this.isTileVisibleBox.makeEmpty();
  22254. this.isTileVisibleVec.set(e.x - r, e.y - r, e.z).applyMatrix4(this.objectGroup.matrixWorld);
  22255. this.isTileVisibleBox.expandByPoint(this.isTileVisibleVec);
  22256. this.isTileVisibleVec.set(e.x - r, e.y + r, e.z).applyMatrix4(this.objectGroup.matrixWorld);
  22257. this.isTileVisibleBox.expandByPoint(this.isTileVisibleVec);
  22258. this.isTileVisibleVec.set(e.x + r, e.y - r, e.z).applyMatrix4(this.objectGroup.matrixWorld);
  22259. this.isTileVisibleBox.expandByPoint(this.isTileVisibleVec);
  22260. this.isTileVisibleVec.set(e.x + r, e.y + r, e.z).applyMatrix4(this.objectGroup.matrixWorld);
  22261. this.isTileVisibleBox.expandByPoint(this.isTileVisibleVec);
  22262. //仿造createMesh写的准确版,但会因为大的tile非矩形,而视口是矩形,若视口刚好在tile的曲线边缘外却识别为可见,就会创建冗余tile。 但上面那个简单版在zoomlevel低的时候地球边缘容易有识别不到的tile,造成黑色三角形。
  22263. //容易出现奇怪的mesh
  22264. /* this.isTileVisibleBox.makeEmpty()
  22265. this.isTileVisibleVec.set(e.x - r, e.y - r, e.z)
  22266. this.transformMapToLocal.forward(this.isTileVisibleVec)
  22267. this.isTileVisibleVec.applyMatrix4(this.objectGroup.matrixWorld)
  22268. this.isTileVisibleBox.expandByPoint(this.isTileVisibleVec)
  22269. this.isTileVisibleVec.set(e.x - r, e.y + r, e.z)
  22270. this.transformMapToLocal.forward(this.isTileVisibleVec)
  22271. this.isTileVisibleVec.applyMatrix4(this.objectGroup.matrixWorld)
  22272. this.isTileVisibleBox.expandByPoint(this.isTileVisibleVec)
  22273. this.isTileVisibleVec.set(e.x + r, e.y - r, e.z)
  22274. this.transformMapToLocal.forward(this.isTileVisibleVec)
  22275. this.isTileVisibleVec.applyMatrix4(this.objectGroup.matrixWorld)
  22276. this.isTileVisibleBox.expandByPoint(this.isTileVisibleVec)
  22277. this.isTileVisibleVec.set(e.x + r, e.y + r, e.z)
  22278. this.transformMapToLocal.forward(this.isTileVisibleVec)
  22279. this.isTileVisibleVec.applyMatrix4(this.objectGroup.matrixWorld)
  22280. this.isTileVisibleBox.expandByPoint(this.isTileVisibleVec) */
  22281. return i.intersectsBox(this.isTileVisibleBox);
  22282. }
  22283. addToSceneGroup(t) {
  22284. this.objectGroupAdded || (t.add(this.objectGroup), this.objectGroupAdded = !0);
  22285. }
  22286. removeFromSceneGroup(t) {
  22287. this.baseTile.remove(), this.objectGroupAdded && (t.remove(this.objectGroup), this.objectGroupAdded = !1);
  22288. }
  22289. }
  22290. var loadDone = (tile, success) => {
  22291. tile.map.mapLayer.loadingInProgress--;
  22292. tile.map.loadingInProgress--;
  22293. //console.log('loaddone', tile.name, 'loadingInProgress',tile.map.mapLayer.loadingInProgress, Date.now())
  22294. tile.loading = false;
  22295. var next = tile.map.mapLayer.waitQueue[0];
  22296. if (next) {
  22297. addLoadTile(next);
  22298. } else {
  22299. if (tile.map.mapLayer.loadingInProgress == 0) {
  22300. //注意这时候不一定就加载完了,300ms后可能还会有新的tile加载
  22301. //console.log('loadDone All ?', Date.now())
  22302. tile.map.mapLayer.dispatchEvent('loadDone');
  22303. }
  22304. }
  22305. tile.mesh && (tile.mesh.material.needsUpdate = true);
  22306. };
  22307. function addLoadTile(tile) {
  22308. /* if(tile.texURL && tile.texURL.includes('testdata') ){
  22309. console.error('addLoadTile', tile.texURL.split('map_tiles/')[1] )
  22310. } */
  22311. if (tile.map.loadingInProgress < tile.map.maxLoading) {
  22312. if (!tile.mesh) return; //有时候会遇到这种情况, 为什么没有被cancelLoad呢?
  22313. tile.map.mapLayer.loadingInProgress++;
  22314. tile.map.loadingInProgress++;
  22315. tile.map.mapLayer.dispatchEvent('startLoad');
  22316. //console.log('addLoad', 'loadingInProgress',tile.map.mapLayer.loadingInProgress, Date.now())
  22317. //tile.texURL && tile.texURL.includes('testdata') && console.log('startloadTile ', tile.texURL.split('map_tiles/')[1] )
  22318. tile.loading = true;
  22319. var index = tile.map.mapLayer.waitQueue.indexOf(tile);
  22320. index > -1 && tile.map.mapLayer.waitQueue.splice(index, 1);
  22321. var tex = tile.mesh.material.map = texLoader$2.load(tile.texURL, tex => {
  22322. //如果一直加载不了会影响其他的加载,如google地图没有vpn会使全景图一直加载不了
  22323. if (tile.mesh) {
  22324. //如果还要显示的话
  22325. tile.textureLoaded = true;
  22326. tile.mesh.material.opacity = 1;
  22327. tile.map.mapLayer.viewer.mapChanged = true;
  22328. tile.map.mapLayer.needUpdate = true; //表示还要继续update(以removeChildren)
  22329. if (tile.map instanceof TiledMapOpenStreetMap) {
  22330. tile.map.maxLoading = browser.isMobile() ? 5 : 10;
  22331. }
  22332. } else {
  22333. //tile.texURL && tile.texURL.includes('testdata') && console.log('loadDone and dispose', tile.texURL.split('map_tiles/')[1] )
  22334. tex.dispose();
  22335. }
  22336. loadDone(tile, true);
  22337. }, void 0, () => {
  22338. //error
  22339. tile.textureLoaded = !0;
  22340. if (tile.mesh) {
  22341. tile.mesh.material.dispose();
  22342. tile.mesh.material = errorMaterial;
  22343. tile.map.mapLayer.viewer.mapChanged = true;
  22344. }
  22345. loadDone(tile, false);
  22346. tile.map.loadFailCount++;
  22347. if (tile.map instanceof TiledMapOpenStreetMap && Potree.settings.mapCompany == 'google' && tile.map.loadFailCount > 3) {
  22348. //极有可能没有vpn为了防止影响到其他资源加载,减少加载的个数
  22349. tile.map.maxLoading = 2;
  22350. }
  22351. });
  22352. tex.anisotropy = 0;
  22353. tex.generateMipmaps = !1;
  22354. tex.minFilter = LinearFilter;
  22355. tex.magFilter = LinearFilter;
  22356. } else {
  22357. tile.map.mapLayer.waitQueue.includes(tile) || tile.map.mapLayer.waitQueue.push(tile);
  22358. }
  22359. }
  22360. function cancelLoad(tile, log) {
  22361. //如果等待加载,但还没开始加载,取消加载
  22362. if (!tile.loading) {
  22363. var index = tile.map.mapLayer.waitQueue.indexOf(tile);
  22364. index > -1 && tile.map.mapLayer.waitQueue.splice(index, 1);
  22365. //index > -1 && tile.texURL && tile.texURL.includes('testdata') && console.log('cancelLoad', tile.texURL.split('map_tiles/')[1]/* , (log && waitQueue.indexOf(tile)>-1) ? log:'' , tile.loading */ )
  22366. }
  22367. }
  22368. class MapTile {
  22369. constructor(map, e, n, parent, name) {
  22370. this.map = map;
  22371. this.name = name;
  22372. this.parent = parent;
  22373. this.objectGroup = e, this.tileColor = n, this.meshAdded = !1, this.textureLoaded = !1, this.children = [];
  22374. this.id = getSid();
  22375. }
  22376. update(e, n, i, r, o, a, s) {
  22377. return !!this.doesNotContainTilesToBeDisplayed(e) || (0 === i ? this.updateTile(e, r, o, a) : this.updateSubTiles(e, n, i, r, o, a, s));
  22378. }
  22379. doesNotContainTilesToBeDisplayed(t) {
  22380. return t.tilePresenceMap && t.tilePresenceMap.empty;
  22381. }
  22382. updateTile(t, e, n, i) {
  22383. //真正显示mesh的是这一层,最高level
  22384. //if(this.map.name.includes('floorplan'))console.log('updateTile',this.name)
  22385. if (!this.mesh) {
  22386. this.createTileObject(t, e, n, i);
  22387. }
  22388. if (!this.meshAdded) {
  22389. this.objectGroup.add(this.mesh);
  22390. this.meshAdded = !0;
  22391. }
  22392. if (this.textureLoaded) {
  22393. //贴图加载完就不需要子集了
  22394. this.removeChildren();
  22395. } else {
  22396. this.cancelChildren(); //add 停止加载子集
  22397. }
  22398. return this.textureLoaded;
  22399. }
  22400. updateSubTiles(entity, n, level, o, a, s, c) {
  22401. //if(entity.name.includes('floorplan'))console.log('updateSubTiles',this.name) //名字越长代表level越高
  22402. for (var childrenLoaded = !0, u = [-.25 * o, .25 * o, -.25 * o, .25 * o], d = [.25 * o, .25 * o, -.25 * o, -.25 * o], p = 0; p < 4; ++p) {
  22403. var h = c + p.toString(10);
  22404. //一级(512):0 1 2 3分别为左上、右上、左下、右下。二级(1024)就是把一级的每一块分裂,如00 01 02 03分别是0的左上、右上、左下、右下……
  22405. if (!entity.tilePresenceMap || entity.tilePresenceMap[h]) {
  22406. //去掉判断,直接显示
  22407. var f = a + u[p],
  22408. m = s + d[p];
  22409. tempVector.set(f, m, 0);
  22410. this.map.computeCount++;
  22411. //console.log(this.map.computeCount, this.name, 'level:',level)
  22412. if (entity.isTileVisible(tempVector, .5 * o, n)) {
  22413. this.children[p] || (this.children[p] = new MapTile(this.map, this.objectGroup, this.tileColor, this, this.name + p));
  22414. //childrenLoaded = childrenLoaded && this.children[p].update(entity, n, level - 1, .5 * o, f, m, h) //这句会使若有一个tile还在加载,就阻断了。原版是这么写的。但是为了加快加载速度,改成下面两行。感觉直接全部updateTile也没太卡,不知道很大的场景会不会卡,单帧updateTile次数超过100次的话(应该不会吧,地图大小会限制住个数) -- 2023.12
  22415. var childLoaded = this.children[p].update(entity, n, level - 1, .5 * o, f, m, h);
  22416. childrenLoaded = childrenLoaded && childLoaded;
  22417. } else {
  22418. if (this.children[p]) {
  22419. this.children[p].remove();
  22420. delete this.children[p];
  22421. }
  22422. }
  22423. }
  22424. }
  22425. return childrenLoaded && this.removeObject3D(), childrenLoaded; //子项加载完,母项mesh可以去除。(最后母项的母项以及前面的都会被删除,只留最后的叶子结点)
  22426. }
  22427. /*
  22428. 一层层往后加载。加入第一次加载到第4层(因为level精细度是第4层),给第4层可见tile加上mesh。
  22429. 然后下一次加载到第5层,那么第4层的mesh就要被清空(当它所属的第5层子集都加载完后)
  22430. */
  22431. createTileObject(t, e, n, a) {
  22432. var s = this;
  22433. this.mesh = this.createMesh(t.transformMapToLocal, e, n, a), this.textureLoaded = !1;
  22434. var c = t.mapSizeM / e,
  22435. l = Math.log(c) / Math.log(2),
  22436. u = n / e + .5 * (c - 1),
  22437. d = -a / e + .5 * (c - 1),
  22438. p = t.getTileUrl(Math.round(l), Math.round(u), Math.round(d));
  22439. Potree.Utils.setObjectLayers(this.mesh, 'map');
  22440. this.mesh.renderOrder = -(1e6 - l - 100 * (t.zIndex || 0));
  22441. this.mesh.name = this.name; //add
  22442. this.texURL = p;
  22443. /* let area = math.getArea(this.mesh.geometry.vertices.slice(0,3));
  22444. if(area >0){
  22445. this.mesh.visible = false
  22446. console.log('area>0',this.mesh.name)
  22447. } */
  22448. addLoadTile(this);
  22449. }
  22450. createMesh(t, e, n, o) {
  22451. var a = new Geometry();
  22452. return tempVector.set(n - e / 2, o - e / 2, 0), a.vertices.push(new Vector3().copy(t.forward(tempVector))), tempVector.set(n + e / 2, o - e / 2, 0), a.vertices.push(new Vector3().copy(t.forward(tempVector))), tempVector.set(n + e / 2, o + e / 2, 0), a.vertices.push(new Vector3().copy(t.forward(tempVector))), tempVector.set(n - e / 2, o + e / 2, 0), a.vertices.push(new Vector3().copy(t.forward(tempVector))), a.faces.push(face1), a.faces.push(face2), a.faceVertexUvs[0].push(face1UV), a.faceVertexUvs[0].push(face2UV), new Mesh(a, this.createMaterial());
  22453. }
  22454. createMaterial() {
  22455. var t = new MeshBasicMaterial({
  22456. transparent: !0,
  22457. depthWrite: !1,
  22458. depthTest: !0,
  22459. opacity: 0,
  22460. side: DoubleSide
  22461. });
  22462. /* var t = new BasicMaterial({
  22463. transparent: !0,
  22464. depthWrite: !1,
  22465. depthTest: !0,
  22466. opacity: 0,
  22467. side: THREE.DoubleSide
  22468. })
  22469. t.defines.InverseColor = '' */
  22470. if (Potree.settings.isTest) {
  22471. var colorHue = Math.random();
  22472. t.color = new Color().setHSL(colorHue, 0.6, 0.92);
  22473. } else {
  22474. t.color = this.tileColor ? this.tileColor : new Color(16777215);
  22475. }
  22476. return t;
  22477. }
  22478. traverse(f) {
  22479. //add
  22480. return Mesh.prototype.traverse.call(this, f);
  22481. }
  22482. remove() {
  22483. this.removeObject3D(), this.removeChildren();
  22484. }
  22485. removeObject3D() {
  22486. var hasMesh = !!this.mesh;
  22487. if (this.mesh) {
  22488. this.objectGroup.remove(this.mesh);
  22489. if (this.textureLoaded) {
  22490. var t = this.mesh.material.map;
  22491. t && t.dispose();
  22492. } else {
  22493. cancelLoad(this);
  22494. }
  22495. this.mesh.material.dispose(); //o.disposeMeshMaterial(this.mesh),
  22496. this.mesh.geometry.dispose();
  22497. this.mesh = void 0;
  22498. }
  22499. this.meshAdded = !1, this.textureLoaded = !1;
  22500. //this.texURL && this.texURL.includes('testdata') && console.log('removeObject3D', this.id, 'hasMesh',hasMesh, this.texURL.split('map_tiles/')[1] )
  22501. }
  22502. removeChildren() {
  22503. for (var t = 0, e = this.children; t < e.length; t++) {
  22504. var n = e[t];
  22505. n && (n.removeObject3D(), n.removeChildren());
  22506. }
  22507. this.children.length = 0;
  22508. }
  22509. cancelChildren() {
  22510. //子集全部停止加载
  22511. for (var t = 0, e = this.children; t < e.length; t++) {
  22512. var n = e[t];
  22513. n && (cancelLoad(n, '提前'), n.cancelChildren());
  22514. }
  22515. }
  22516. }
  22517. proj4.defs("EPSG:3857", "+title=WGS 84 / Pseudo-Mercator +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs");
  22518. //这里地图世界的中心是不是lon:0,lat:0
  22519. class TiledMapOpenStreetMap extends TiledMapBase {
  22520. constructor(mapLayer, tileColor) {
  22521. //Potree.settings.mapCompany = 'google'
  22522. super('map', mapLayer, tileColor /* , projection */); //EPSG projection
  22523. //this.baseUrl = "https://wprd03.is.autonavi.com/appmaptile?style=7&x=${x}&y=${y}&z=${z}",
  22524. //this.baseUrl = "https://webrd01.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x=${x}&y=${y}&z=${z}" //最高只到18 level
  22525. this.switchStyle();
  22526. this.tileSizePx = 256;
  22527. this.mapSizeM = 40075017; //总占据多少米(地球赤道周长) 和三维空间的不一样 - -, 空间上的是直径,地图上的是半个圆周
  22528. this.bias = 0.5;
  22529. if (Potree.settings.mapCompany == 'google') {
  22530. this.attribution = "© PopSmart, © 谷歌地图";
  22531. this.projection = "EPSG:900913"; //"EPSG:4326"//4550
  22532. } else {
  22533. this.attribution = "© PopSmart, © 高德地图";
  22534. this.projection = "EPSG:3857";
  22535. }
  22536. }
  22537. getTileUrl(t, e, n) {
  22538. return this.baseUrl.replace(/\${z}/, t.toString(10)).replace(/\${x}/, e.toString(10)).replace(/\${y}/, n.toString(10));
  22539. }
  22540. switchStyle() {
  22541. var style = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'standard';
  22542. //if(Potree.settings.mapCompany == 'google')return
  22543. if (style == this.style) return;
  22544. if (Potree.settings.mapCompany == 'google') {
  22545. if (style == 'satellite') {
  22546. //卫星
  22547. this.baseUrl = "https://mt2.google.com/vt/lyrs=y@159000000&hl=zh-CN&gl=cn&x=${x}&y=${y}&z=${z}&s=mt1"; /* "http://mt2.google.cn/vt/lyrs=m@177000000&hl=zh-CN&gl=cn&src=app&x=${x}&y=${y}&z=${z}" */ //最高只到19
  22548. this.maxDepth = 22;
  22549. } else {
  22550. this.baseUrl = "https://mt2.google.com/vt/lyrs=m@159000000&hl=zh-CN&gl=cn&x=${x}&y=${y}&z=${z}&s=mt1"; /* "http://mt2.google.cn/vt/lyrs=m@177000000&hl=zh-CN&gl=cn&src=app&x=${x}&y=${y}&z=${z}" */ //最高只到19
  22551. this.maxDepth = 22;
  22552. }
  22553. /* 1)lyrs= 表示的是图层类型,即瓦片类型,具体含义如下:
  22554. m:路线图
  22555. t:地形图
  22556. p:带标签的地形图
  22557. s:卫星图
  22558. y:带标签的卫星图
  22559. h:标签层(路名、地名等)
  22560. 2)& gl=CN
  22561. 谷歌地图针对中国有两套坐标,一套做了偏移,一套没有。经测试在url加入gl=cn地图会有偏移。
  22562. Tips:如果谷歌地图和RTK测量的WGS84坐标有偏差,可以尝试在url里去掉& gl=cn。
  22563. 5)&hl=
  22564. 设置地图注记文字语言类型,缺省默认为中文。
  22565. hl=nl 中英双语
  22566. hl=zh-CN 中文
  22567. */
  22568. } else {
  22569. //baseUrl = "https://webst01.is.autonavi.com/appmaptile?lang=zh_cn&style=6&yrs=m&x=${x}&y=${y}&z=${z}" //卫星 maxDepth = 18
  22570. //搜索高德地图瓦片url
  22571. if (Potree.settings.isJiangMen) {
  22572. if (style == 'satellite') {
  22573. //卫星
  22574. this.maxDepth = 18;
  22575. this.baseUrl = "http://a.map.jms.gd/tile/weixing/${z}/${x}/${y}.png";
  22576. } else {
  22577. this.maxDepth = 19;
  22578. this.baseUrl = "http://a.map.jms.gd/tile/gd_xiangtu/${z}/${x}/${y}.png";
  22579. }
  22580. } else {
  22581. if (style == 'satellite') {
  22582. //卫星
  22583. this.maxDepth = 18;
  22584. this.baseUrl = "https://webst01.is.autonavi.com/appmaptile?lang=zh_cn&style=6&yrs=m&x=${x}&y=${y}&z=${z}";
  22585. } else if (style == 'dark-standard') {
  22586. this.maxDepth = 18;
  22587. this.baseUrl = "https://wprd01.is.autonavi.com/appmaptile?lang=zh_cn&style=8&yrs=m&x=${x}&y=${y}&z=${z}"; //路网 加上scl=2后去掉名字
  22588. } else {
  22589. this.maxDepth = 19;
  22590. this.baseUrl = "https://wprd04.is.autonavi.com/appmaptile?lang=zh_cn&style=7&yrs=m&x=${x}&y=${y}&z=${z}"; //
  22591. }
  22592. } //详解 https://www.cnblogs.com/lucio110/p/17310054.html
  22593. }
  22594. this.style = style;
  22595. this.setEnable(false);
  22596. this.setEnable(true);
  22597. viewer.dispatchEvent('content_changed');
  22598. }
  22599. }
  22600. class TiledMapFromEntity extends TiledMapBase {
  22601. constructor(mapLayer, tileColor, data) {
  22602. super('floorplan', mapLayer, tileColor, "LOCAL" /* "EPSG:3857" */ /* "WGS84" */); //直接就是本地坐标,没有projec
  22603. var entity = this.tiledMapEntity = this.fillFromData(data);
  22604. var time = entity.updateTime || entity.createTime;
  22605. this.tileSizePx = entity.tileSizePx, this.mapSizeM = entity.mapSizeM, this.maxDepth = entity.maxDepth;
  22606. this.postStamp = time ? time.replace(/[^0-9]/ig, '') : new Date().getTime();
  22607. //this.projection = n.crsLocal,
  22608. this.zIndex = 0, this.tilePresenceMap = this.decodeBitStream(this.tiledMapEntity.quadtree); //包含tile分裂信息,如果写错了会造成tile显示不全
  22609. this.maxLoading = 5;
  22610. this.bias = 0.5; //越大加载层级越低,越模糊
  22611. if (window.devicePixelRatio >= 2 && window.innerHeight * window.innerWidth < 768 * 1024) {
  22612. //手机还是加载高清点(反正也不需要截图等待),但平板太大了,要铺满屏幕可能慢,所以稍微模糊点?(反正可以继续放大去看)
  22613. this.bias = 0; //level更高些
  22614. }
  22615. }
  22616. fillFromData(e) {
  22617. var data = {};
  22618. data.id = e.id;
  22619. data.globalLocation = Potree.Utils.VectorFactory.fromArray3(e.location);
  22620. data.orientation = Potree.Utils.QuaternionFactory.fromArray(e.orientation);
  22621. var pointcloud = viewer.scene.pointclouds.find(p => p.dataset_id == e.datasetId);
  22622. if (pointcloud.datasetData.mapping) {
  22623. data.filePath = "".concat(Potree.settings.urls.prefix1, "/").concat(pointcloud.datasetData.mapping).concat(e.file_path);
  22624. } else {
  22625. data.filePath = "".concat(Potree.settings.urls.prefix1).concat(e.file_path);
  22626. }
  22627. data.fileName = '$DEPTH/$X/$Y.png';
  22628. data.type = e.type, data.mapSizeM = e.map_size_m, data.tileSizePx = e.tile_size_px, data.maxDepth = e.max_depth, data.quadtree = e.quadtree, data.floorId = e.floor_id, data.bundleId = e.bundle_id;
  22629. //this.computeLocalCoordinates()
  22630. return data;
  22631. }
  22632. computeLocalCoordinates() {
  22633. if (proj4.defs("LOCAL_MAP")) {
  22634. var lonlat = this.tiledMapEntity.globalLocation;
  22635. /* if(window.AMapWith84){//需要转换
  22636. lonlat = AMapWith84.wgs84ToAMap(lonlat)
  22637. } */
  22638. lonlat = viewer.transform.lonlatToLocal.forward(lonlat);
  22639. this.tiledMapEntity.location = new Vector3().copy(lonlat);
  22640. }
  22641. }
  22642. updateProjection() {
  22643. super.updateProjection();
  22644. if (!this.position) {
  22645. this.computeLocalCoordinates();
  22646. }
  22647. /* this.projection = this.TransformService.crsLocal,
  22648. t.prototype.updateProjection.call(this) */
  22649. }
  22650. get position() {
  22651. return this.tiledMapEntity.location;
  22652. /* enumerable: !0,
  22653. configurable: !0 */
  22654. }
  22655. get quaternion() {
  22656. return this.tiledMapEntity.orientation;
  22657. /* enumerable: !0,
  22658. configurable: !0 */
  22659. }
  22660. getTileUrl(t, e, n) {
  22661. var i = (this.tiledMapEntity.filePath + "/" + this.tiledMapEntity.fileName).replace(/\$DEPTH/g, t.toString(10)).replace(/\$X/g, e.toString(10)).replace(/\$Y/g, n.toString(10));
  22662. return i += "?t=" + this.postStamp;
  22663. //this.RestService.addAuthorizationQueryParameter(i) //????
  22664. }
  22665. decodeBitStream(t) {
  22666. if (!t) return {
  22667. empty: !0
  22668. };
  22669. for (var e = {}, n = [e], i = 0; i < t.length; i++) {
  22670. var r = n.shift(),
  22671. o = parseInt(t.substr(i, 1), 16);
  22672. if (1 & o) {
  22673. var a = {};
  22674. r[0] = a, n.push(a);
  22675. }
  22676. 2 & o && (a = {}, r[1] = a, n.push(a)), 4 & o && (a = {}, r[2] = a, n.push(a)), 8 & o && (a = {}, r[3] = a, n.push(a));
  22677. }
  22678. var s = {
  22679. empty: !0
  22680. };
  22681. return this.computeHashes(s, e, ""), s;
  22682. }
  22683. computeHashes(t, e, n) {
  22684. for (var i = 0; i < 4; i++) e[i] && (t[n + i.toString(10)] = !0, t.empty = !1, this.computeHashes(t, e[i], n + i.toString(10)));
  22685. }
  22686. }
  22687. /*
  22688. note:
  22689. 目前缩小了能看出形态是一个地球。相机在高空朝下观测,地球平放着。
  22690. 所以越靠近赤道和地球朝上的那面所在的中央经度(也就是local 0,0,0所对应的初始经度),tile越接近正方形。
  22691. 所以在两极地区要怎么显示?
  22692. 注册地理坐标时需要滚动地球吗?(修改初始经度、重定义NAVVIS:TMERC, 就需要更新所有三维世界中的物体位置)
  22693. 切换中心点:
  22694. var locationLonLat = viewer.transform.lonlatToLocal.inverse(viewer.mapViewer.camera.position.clone())
  22695. proj4.defs("LOCAL_MAP", "+proj=tmerc +ellps=WGS84 +lon_0=" + locationLonLat.x.toPrecision(15) + " +lat_0=" + locationLonLat.y.toPrecision(15));
  22696. viewer.mapViewer.mapLayer.maps[0].transformMapToLocal = null
  22697. 地理注册部分地图上的1和2标记有两层意思。当地图全屏展示时,标记的是当前右侧经纬度的位置;当地图为小窗时,标记的是对应场景里三维位置。(所以感觉最好换一个ui?)且在2023.2.1之前才改好,之前都是后者。
  22698. 为什么边缘总是有奇怪的mesh,是因为有顶点到背面了吗
  22699. https://lbs.amap.com/tools/picker 高德坐标拾取器(手机登录),但和这里展示的不一样, 要用AMapWith84.aMapToWgs84({x: ,y: })转成84。 (qq or 手机登录) 所以potree本地和有AMapWith84函数的laser地图展现不一样
  22700. https://www.google.com/maps/@77.7730021,-34.4952712,4z google取点
  22701. 打印所有mapTile的名字,字符串最长的代表有显示的mesh。
  22702. viewer.mapViewer.mapLayer.maps[0].baseTile.traverse(function(e){console.log(e.name)})
  22703. 能查看有几个显示的mesh
  22704. viewer.mapViewer.mapLayer.maps[0].objectGroup.children
  22705. 图片地址中 tiles/4/3/9.png 第一个数字越高代表level越高,放得越大 . (tile.name.length也能反映出
  22706. viewer.mapViewer.mapLayer.maps[1].objectGroup.children.map(e=>e.name.length-1)
  22707. 目前看的几个场景floorplan原图是1米=33.03个像素 图宽度= 512*2^(max_depth-1) , map_size_m 代表整个地图是多少米
  22708. 经纬度精度小数点后5位为米级别,6位为分米,7位是厘米
  22709. */
  22710. /**
  22711. * @author mschuetz / http://mschuetz.at
  22712. *
  22713. * adapted from THREE.OrbitControls by
  22714. *
  22715. * @author qiao / https://github.com/qiao
  22716. * @author mrdoob / http://mrdoob.com
  22717. * @author alteredq / http://alteredqualia.com/
  22718. * @author WestLangley / http://github.com/WestLangley
  22719. * @author erich666 / http://erichaines.com
  22720. *
  22721. *
  22722. *
  22723. */
  22724. var Buttons = Potree.defines.Buttons;
  22725. class FirstPersonControls extends EventDispatcher {
  22726. constructor(viewer, viewport) {
  22727. var _this;
  22728. super();
  22729. _this = this;
  22730. this.viewer = viewer;
  22731. this.renderer = viewer.renderer;
  22732. this.scene = viewer.scene;
  22733. this.rotationSpeed = 200;
  22734. this.moveSpeed = 10;
  22735. this.setCurrentViewport({
  22736. hoverViewport: viewport,
  22737. force: true
  22738. }); //this.currentViewport = viewport
  22739. this.keys = {
  22740. FORWARD: ['W'.charCodeAt(0), 38],
  22741. BACKWARD: ['S'.charCodeAt(0), 40],
  22742. LEFT: ['A'.charCodeAt(0), 37],
  22743. RIGHT: ['D'.charCodeAt(0), 39],
  22744. UP: ['Q'.charCodeAt(0)],
  22745. DOWN: ['E'.charCodeAt(0)],
  22746. //SHIFT : [16],
  22747. ALT: [18],
  22748. SPACE: [32],
  22749. Rotate_LEFT: ['L'.charCodeAt(0)],
  22750. Rotate_RIGHT: ['J'.charCodeAt(0)],
  22751. Rotate_UP: ['K'.charCodeAt(0)],
  22752. Rotate_DOWN: ['I'.charCodeAt(0)]
  22753. };
  22754. this.fadeFactor = 20;
  22755. this.yawDelta = 0;
  22756. this.pitchDelta = 0;
  22757. this.translationDelta = new Vector3(0, 0, 0);
  22758. this.translationWorldDelta = new Vector3(0, 0, 0);
  22759. this.tweens = [];
  22760. this.dollyStart = new Vector2();
  22761. this.dollyEnd = new Vector2();
  22762. //this.enableChangePos = true
  22763. this.viewer.addEventListener('camera_changed', e => {
  22764. if (this.viewer.name == 'mapViewer' || e.changeInfo && e.changeInfo.positionChanged && !viewer.mainViewport.view.isFlying()) {
  22765. this.setFPCMoveSpeed(e.viewport);
  22766. }
  22767. });
  22768. var drag = e => {
  22769. if (!this.enabled) return;
  22770. var viewport = e.dragViewport;
  22771. if (!viewport) return;
  22772. var camera = viewport.camera;
  22773. var mode;
  22774. if (e.isTouch) {
  22775. if (e.touches.length == 1) {
  22776. mode = !e.dragViewport || e.dragViewport.name == 'MainView' ? 'rotate' : 'pan';
  22777. } else if (e.touches.length == 2) {
  22778. mode = Potree.settings.displayMode == 'showPanos' ? 'scale' : 'pan-scale';
  22779. } else {
  22780. mode = !e.dragViewport || e.dragViewport.name == 'MainView' ? 'pan' : 'scale';
  22781. }
  22782. } else {
  22783. //mode = e.buttons === Buttons.LEFT && (!e.dragViewport || e.dragViewport.name == 'MainView') ? 'rotate' : 'pan'
  22784. mode = e.buttons === Buttons.LEFT && camera.type != 'OrthographicCamera' ? 'rotate' : 'pan';
  22785. }
  22786. //console.log('mode ', mode )
  22787. var moveSpeed = this.currentViewport.getMoveSpeed();
  22788. if (e.drag.startHandled === undefined) {
  22789. ///???????
  22790. e.drag.startHandled = true;
  22791. this.dispatchEvent({
  22792. type: 'start'
  22793. });
  22794. }
  22795. if (mode.includes('rotate')) {
  22796. //旋转
  22797. //来自panoramaControl updateRotation
  22798. if (!this.pointerDragStart) {
  22799. return this.pointerDragStart = e.pointer.clone();
  22800. }
  22801. var view = this.scene.view;
  22802. if (this.rotateStartInfo.rotAroundPoint) {
  22803. //定点旋转: 以当前intersect的点为target旋转,不改点在屏幕中的位置
  22804. var distance = camera.position.distanceTo(this.rotateStartInfo.rotCenter /* this.intersectStart.location */); //不按下ctrl的话
  22805. var posDir = new Vector3().subVectors(this.rotateStartInfo.rotCenter, view.position);
  22806. if (posDir.dot(view.direction) < 0) distance *= -1; //在背面
  22807. //按照orbitControl的方式旋转:
  22808. var rotationSpeed = 2;
  22809. this.yawDelta -= e.drag.pointerDelta.x * rotationSpeed;
  22810. this.pitchDelta += e.drag.pointerDelta.y * rotationSpeed;
  22811. /* //旋转方向和偏移量尽量和在漫游点处旋转方式的一样
  22812. this.yawDelta += e.drag.pointerDelta.x / 500 * viewport.resolution.x
  22813. this.pitchDelta -= e.drag.pointerDelta.y / 500 * viewport.resolution.y */
  22814. //先更新一下相机:
  22815. this.update();
  22816. view.applyToCamera(camera);
  22817. //然后得到新的相机角度下,原先点在屏幕中的位置所对应的3d点现在的坐标。只需要平移一下新旧坐标差值即可。//感觉貌似也可以用project和unproject后的差值的方式,还不用判断z背面
  22818. var newPointerDir = viewer.inputHandler.getMouseDirection(this.rotateStartInfo.rotCenter2d).direction.clone().multiplyScalar(distance);
  22819. var pivot = new Vector3().addVectors(camera.position, newPointerDir); //新的3d点
  22820. var moveVec = new Vector3().subVectors(pivot, this.rotateStartInfo.rotCenter);
  22821. this.translationWorldDelta.copy(moveVec.negate());
  22822. //立即更新下,防止因update和此drag频率不同而打滑。
  22823. this.update();
  22824. view.applyToCamera(camera);
  22825. } else {
  22826. var _matrixWorld = camera.matrixWorld;
  22827. camera.matrixWorld = new Matrix4(); //unproject 前先把相机置于原点
  22828. var e1 = new Vector3(this.pointerDragStart.x, this.pointerDragStart.y, -1).unproject(camera),
  22829. t = new Vector3(e.pointer.x, e.pointer.y, -1).unproject(camera),
  22830. i = Math.sqrt(e1.x * e1.x + e1.z * e1.z),
  22831. n = Math.sqrt(t.x * t.x + t.z * t.z),
  22832. o = Math.atan2(e1.y, i),
  22833. a = Math.atan2(t.y, n);
  22834. this.pitchDelta += o - a; //上下旋转
  22835. e1.y = 0, t.y = 0;
  22836. var s = Math.acos(e1.dot(t) / e1.length() / t.length());
  22837. if (!isNaN(s)) {
  22838. var yawDelta = s; //左右旋转
  22839. this.pointerDragStart.x > e.pointer.x && (yawDelta *= -1);
  22840. this.yawDelta += yawDelta;
  22841. }
  22842. //console.log('rotate:', this.pitchDelta, e.pointer.toArray(), this.pointerDragStart.toArray())
  22843. this.pointerDragStart.copy(e.pointer);
  22844. camera.matrixWorld = _matrixWorld;
  22845. }
  22846. }
  22847. if (mode.includes('pan')) {
  22848. //平移
  22849. if (!this.canMovePos(viewport)) {
  22850. return;
  22851. }
  22852. if (camera.type == "OrthographicCamera") {
  22853. //console.log(e.drag.pointerDelta, e.pointer, e.drag.end)
  22854. var _moveVec = Utils.getOrthoCameraMoveVec(e.drag.pointerDelta, camera); //最近一次移动向量
  22855. var pointclouds;
  22856. var Alignment = window.viewer.modules.Alignment;
  22857. var MergeEditor = window.viewer.modules.MergeEditor;
  22858. var handleState = Alignment.handleState;
  22859. //右键平移视图、左键操作点云
  22860. var _a = e.buttons === Buttons.LEFT && viewport.alignment && handleState && viewport.alignment[handleState];
  22861. if (Potree.settings.editType == 'pano') {
  22862. var PanoEditor = window.viewer.modules.PanoEditor;
  22863. if (_a && PanoEditor.selectedPano) {
  22864. if ( /* !PanoEditor.selectedGroup || */!PanoEditor.checkIfAllLinked({
  22865. group: PanoEditor.selectedGroup
  22866. })) {
  22867. if (handleState == 'translate' && (e.drag.intersectStart.pointclouds && Common.getMixedSet(PanoEditor.selectedClouds, e.drag.intersectStart.pointclouds).length || PanoEditor.selectedPano.hovered) //平移时 拖拽到点云上 或 circle。(其中点云只需要intersect的点云中包含选择的点云中之一即可)
  22868. || handleState == 'rotate')
  22869. //旋转模式不需要intersect
  22870. {
  22871. pointclouds = PanoEditor.selectedClouds;
  22872. }
  22873. } else {
  22874. PanoEditor.dispatchEvent('needToDisConnect');
  22875. console.warn('选中的漫游点连通了整个数据集,不允许移动');
  22876. }
  22877. }
  22878. if (!pointclouds && e.buttons === Buttons.LEFT && viewport.rotateSide) {
  22879. //侧视图 (有时候会卡顿,是mousemove执行延迟了,一般发生在突然加载很多点云时)
  22880. //console.log('rotateSide', -e.drag.pointerDelta.x )
  22881. return PanoEditor.rotateSideCamera(-e.drag.pointerDelta.x);
  22882. }
  22883. } else if (Potree.settings.editType == 'merge') {
  22884. if (e.buttons === Buttons.LEFT && viewport.rotateSide) {
  22885. return MergeEditor.rotateSideCamera(-e.drag.pointerDelta.x);
  22886. }
  22887. } else {
  22888. /* if(Alignment.selectedClouds && Alignment.selectedClouds.length){//多个点云
  22889. pointclouds = a && e.drag.intersectStart.pointclouds && Common.getMixedSet(Alignment.selectedClouds, e.drag.intersectStart.pointclouds).length && Alignment.selectedClouds
  22890. }else{ */
  22891. //pointclouds = a && e.drag.intersectStart.pointcloud && [e.drag.intersectStart.pointcloud]
  22892. //}
  22893. if (_a && e.drag.intersectStart.pointcloud) {
  22894. pointclouds = [e.drag.intersectStart.pointcloud];
  22895. if (e.drag.intersectStart.pointcloud.dataset_id == Potree.settings.originDatasetId) {
  22896. var p = e.drag.intersectStart.pointclouds.find(p => p.dataset_id != Potree.settings.originDatasetId);
  22897. if (p) pointclouds = [p];
  22898. }
  22899. }
  22900. }
  22901. if (pointclouds) {
  22902. if (handleState == 'translate' && viewport.alignment.translateVec) {
  22903. //只能沿某个方向移动
  22904. _moveVec.projectOnVector(viewport.alignment.translateVec);
  22905. }
  22906. this.dispatchEvent({
  22907. type: "transformPointcloud",
  22908. intersect: e.intersect.orthoIntersect,
  22909. intersectStart: e.drag.intersectStart.orthoIntersect,
  22910. moveVec: _moveVec,
  22911. pointclouds,
  22912. camera
  22913. });
  22914. } else {
  22915. this.translationWorldDelta.add(_moveVec.negate());
  22916. }
  22917. } else {
  22918. //perspectiveCamera:
  22919. if (e.drag.intersectStart) {
  22920. //如果拖拽着点云
  22921. var ifInit = e.drag.z == void 0;
  22922. var pointerStartPos2d = e.drag.intersectStart.location.clone().project(camera); //识别到的点云点的位置
  22923. e.drag.z = pointerStartPos2d.z; //记录z,保持拖拽物体到屏幕距离不变,所以z深度不变(如果拖拽过程中没有缩放,这个z其实不变)
  22924. if (ifInit) {
  22925. //拖拽开始
  22926. e.drag.projectionMatrixInverse = camera.projectionMatrixInverse.clone();
  22927. //防止吸附到最近点上(因为鼠标所在位置并非识别到的点云点的位置,需要得到鼠标所在位置的3d坐标。)
  22928. var pointerStartPos2dReal = new Vector3(this.pointerDragStart.x, this.pointerDragStart.y, e.drag.z);
  22929. e.drag.translateStartPos = pointerStartPos2dReal.clone().unproject(camera);
  22930. //console.log('开始拖拽', e.pointer.clone())
  22931. }
  22932. //拖拽的过程中将projectionMatrixInverse替换成开始拖拽时的,因为near、far一直在变,会导致unproject计算出的3d坐标改变很大而闪烁。
  22933. var _projectionMatrixInverse = camera.projectionMatrixInverse;
  22934. camera.projectionMatrixInverse = e.drag.projectionMatrixInverse;
  22935. var newPos2d = new Vector3(e.pointer.x, e.pointer.y, e.drag.z);
  22936. var newPos3d = newPos2d.clone().unproject(camera);
  22937. var _moveVec2 = newPos3d.clone().sub(e.drag.translateStartPos /* e.drag.intersectStart.location */); //移动相机,保持鼠标下的位置永远不变,所以用鼠标下的新位置减去鼠标下的原始位置
  22938. camera.projectionMatrixInverse = _projectionMatrixInverse;
  22939. this.translationWorldDelta.copy(_moveVec2.negate()); //这里没法用add,原因未知,打开console时会跳动
  22940. //console.log('pan 1', this.translationWorldDelta.clone())
  22941. //四指松开剩三指时会偏移一下,暂不知道哪里的问题,或许跟开头防止点云吸附有关?
  22942. } else {
  22943. //如果鼠标没有找到和点云的交点,就假设移动整个模型(也可以去扩大范围寻找最近点云)
  22944. /* let center = viewer.scene.pointclouds[0].position;
  22945. let radius = camera.position.distanceTo(center);
  22946. let ratio = radius * Math.tan(THREE.Math.degToRad(camera.fov)/2) / 1000 */
  22947. /* let speed = this.currentViewport.getMoveSpeed()
  22948. if(FirstPersonControls.boundPlane){
  22949. speed = FirstPersonControls.boundPlane.distanceToPoint(this.currentViewport.position)
  22950. speed = Math.max(1 , speed)
  22951. } */
  22952. var lastIntersect = this.target || viewport.lastIntersect && (viewport.lastIntersect.location || viewport.lastIntersect); //该viewport的最近一次鼠标和点云的交点
  22953. if (!lastIntersect || !(lastIntersect instanceof Vector3)) lastIntersect = viewer.bound.center;
  22954. var speed = camera.position.distanceTo(lastIntersect);
  22955. var fov = cameraLight.getHFOVForCamera(camera, true);
  22956. var ratio = speed * Math.tan(fov / 2);
  22957. this.translationDelta.x -= e.drag.pointerDelta.x * ratio;
  22958. this.translationDelta.z -= e.drag.pointerDelta.y * ratio;
  22959. //console.log('pan2', e.drag.pointerDelta)
  22960. }
  22961. }
  22962. this.useAttenuation = false;
  22963. }
  22964. if (mode.includes('scale')) {
  22965. //触屏缩放
  22966. this.dollyEnd.subVectors(e.touches[0].pointer, e.touches[1].pointer);
  22967. //if(!this.dollyStart)return
  22968. var scale = this.dollyEnd.length() / this.dollyStart.length();
  22969. var pointer = new Vector2().addVectors(e.touches[0].pointer, e.touches[1].pointer).multiplyScalar(0.5); //两个指头的中心点
  22970. dolly({
  22971. pointer,
  22972. scale,
  22973. camera,
  22974. drag: e.drag
  22975. });
  22976. this.dollyStart.copy(this.dollyEnd);
  22977. }
  22978. //最好按ctrl可以变为dollhouse的那种旋转
  22979. };
  22980. var drop = e => {
  22981. if (!this.enabled) return;
  22982. this.dispatchEvent({
  22983. type: 'end'
  22984. });
  22985. };
  22986. var dolly = function dolly() {
  22987. var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  22988. if (Potree.settings.displayMode == 'showPanos' && _this.currentViewport == viewer.mainViewport /* this.currentViewport.unableChangePos */) {
  22989. //全景时
  22990. _this.dispatchEvent({
  22991. type: 'dollyStopCauseUnable',
  22992. delta: e.delta,
  22993. scale: e.scale
  22994. });
  22995. return;
  22996. }
  22997. var camera = e.camera;
  22998. if (camera.type == "OrthographicCamera") {
  22999. var ratio;
  23000. if (e.delta != void 0) {
  23001. //滚轮缩放
  23002. if (e.delta == 0) {
  23003. //mac
  23004. return;
  23005. } else if (e.delta < 0) {
  23006. ratio = 0.9;
  23007. } else if (e.delta > 0) {
  23008. ratio = 1.12; //增加的需要比减少的多一些,否则缩放相同次数下,r0 * ([1+s)(1-s)]^n = r0 * (1-s^2)^n < r0
  23009. }
  23010. } else {
  23011. ratio = e.scale; //触屏缩放
  23012. }
  23013. var zoom = camera.zoom * ratio;
  23014. var limit = camera.zoomLimit;
  23015. if (limit) zoom = MathUtils.clamp(zoom, limit.min, limit.max);
  23016. var pointerPos = new Vector3(e.pointer.x, e.pointer.y, 0.5);
  23017. var oldPos = pointerPos.clone().unproject(camera);
  23018. if (camera.zoom != zoom) {
  23019. camera.zoom = zoom;
  23020. camera.updateProjectionMatrix();
  23021. }
  23022. var newPos = pointerPos.clone().unproject(camera);
  23023. //定点缩放, 恢复一下鼠标所在位置的位置改变量
  23024. var moveVec = new Vector3().subVectors(newPos, oldPos);
  23025. _this.translationWorldDelta.add(moveVec.negate());
  23026. _this.useAttenuation = false;
  23027. } else {
  23028. var speed = _this.currentViewport.getMoveSpeed() * 7,
  23029. direction;
  23030. if (e.delta != void 0) {
  23031. //滚轮缩放
  23032. if (e.delta == 0) return; //mac
  23033. /*if(this.target && !e.intersect){//如果没有intersect点云且有target的话,就朝target的方向. 但无限靠近时有问题,且到背面时前进却是后退
  23034. direction = new THREE.Vector3().subVectors(this.target, camera.position).normalize()
  23035. }else{ */
  23036. direction = _this.viewer.inputHandler.getMouseDirection().direction; //定点缩放
  23037. if (e.intersect && e.intersect.location) {
  23038. //和intersect的墙越接近,速度越慢,便于focus细节
  23039. var dis = camera.position.distanceTo(e.intersect.location);
  23040. speed = MathUtils.clamp(dis * 0.1, 0.3, speed);
  23041. }
  23042. if (e.delta < 0) {
  23043. speed *= -1;
  23044. }
  23045. var slightly = _this.keys.ALT.some(e => _this.viewer.inputHandler.pressedKeys[e]);
  23046. slightly && (speed *= 0.2);
  23047. _this.useAttenuation = true;
  23048. } else {
  23049. //触屏缩放
  23050. direction = _this.viewer.inputHandler.getMouseDirection(e.pointer).direction; //定点缩放
  23051. if (e.drag.intersectStart) {
  23052. //和intersect的墙越接近,速度越慢,便于focus细节
  23053. var _dis = camera.position.distanceTo(e.drag.intersectStart.location);
  23054. var r = 1 - 1 / e.scale;
  23055. var closeMin = 0.1,
  23056. standardMin = 0.001,
  23057. disBound1 = 2,
  23058. disBound2 = 5;
  23059. if (math.closeTo(e.scale, 1, 0.03)) {
  23060. //如果偏差小于0.01,就不限制最小值,因为平移容易正负抖动,近距离有最小值的话抖动明显
  23061. closeMin = 0; //所以若缩放不明显(双指滑动慢),就不设置最低值。(这时候穿越障碍物会比较困难。)
  23062. }
  23063. //console.log('closeMin',closeMin)
  23064. var min = math.linearClamp(_dis, [disBound1, disBound2], [closeMin, standardMin]); //触屏和滚轮不一样,触发较为连续,所以最小值设低一点。若要保持双指相对点云位置不变,理想最小值是0,但那样就无法穿越点云(最小值太小的话穿越密集点云如树丛很困难;太大会打滑)所以当离点云近时增大最小值
  23065. speed = Math.sign(r) * MathUtils.clamp(_dis * Math.abs(r), min, speed);
  23066. //console.log(speed, dis, e.scale)
  23067. } else {
  23068. _this.useAttenuation = true;
  23069. var accelerate = 40;
  23070. if (math.closeTo(e.scale, 1, 0.02)) {
  23071. //缩放小的时候很可能是双指平移时,容易抖动,所以降低移动速度
  23072. accelerate *= Math.min(40 * Math.abs(e.scale - 1), 0.8);
  23073. }
  23074. // console.log('accelerate',accelerate)
  23075. var constantDis = _this.currentViewport.getMoveSpeed() * accelerate; //constantDis = 10;//常量系数,当放大一倍时前进的距离。可以调整
  23076. speed = (e.scale - 1) * constantDis;
  23077. }
  23078. }
  23079. var vec = direction.multiplyScalar(speed);
  23080. //this.translationWorldDelta.copy(vec)
  23081. _this.translationWorldDelta.add(vec);
  23082. //console.log(direction.toArray(), speed, e.scale)
  23083. }
  23084. return true;
  23085. };
  23086. var scroll = e => {
  23087. if (!this.enabled || !e.hoverViewport) return;
  23088. this.setCurrentViewport(e);
  23089. e.camera = e.hoverViewport.camera;
  23090. dolly(e);
  23091. };
  23092. var dblclick = e => {
  23093. if (!this.enabled) return;
  23094. if (!Potree.settings.dblToFocusPoint) return; //调试时才可双击
  23095. if (Potree.settings.displayMode == 'showPointCloud' /* !viewer.images360.isAtPano() */) this.zoomToLocation(e.mouse);
  23096. };
  23097. this.viewer.addEventListener('global_drag', drag);
  23098. /* this.viewer.addEventListener('global_touchmove', (e)=>{
  23099. if(!this.enabled)return
  23100. if(e.touches.length>1){//单指的就触发上一句
  23101. //console.log('global_touchmove' )
  23102. drag(e)
  23103. }
  23104. }); */
  23105. this.viewer.addEventListener('global_drop', drop);
  23106. this.viewer.addEventListener('global_mousewheel', scroll);
  23107. this.viewer.addEventListener('global_dblclick', dblclick);
  23108. var prepareScale = e => {
  23109. //触屏的scale
  23110. this.dollyStart.subVectors(e.touches[0].pointer, e.touches[1].pointer);
  23111. e.drag.camDisToPointStart = null;
  23112. };
  23113. var prepareRotate = e => {
  23114. this.pointerDragStart = e.pointer.clone();
  23115. if (e.viewer.name != 'mainViewer') return;
  23116. var intersect = e.intersect || e.dragViewport.lastIntersect;
  23117. //在数据集外部时绕中心点旋转,在数据集内部时绕intersect点旋转(其他数据集的点也可以) 或者 原地旋转镜头
  23118. var rotAroundPoint = Potree.settings.rotAroundPoint && e.dragViewport.camera.type != 'OrthographicCamera' && (viewer.atDatasets.length == 0 || intersect) && this.canMovePos(viewport) && !viewer.images360.isAtPano() && !this.viewer.inputHandler.pressedKeys[32];
  23119. var rotCenter2d, rotCenter;
  23120. if (rotAroundPoint) {
  23121. var pivotType = this.target ? 'target' : viewer.atDatasets.length > 0 ? 'intersect' : viewer.inputHandler.selection.length ? 'selection' : this.target2 ? 'target2' : 'boundCenter';
  23122. rotCenter = pivotType == 'target' ? this.target : pivotType == 'intersect' ? intersect.location : pivotType == 'selection' ? viewer.inputHandler.selection[0].position : pivotType == 'target2' ? this.target2 : viewer.bound && viewer.bound.center;
  23123. if (rotCenter) {
  23124. rotCenter2d = rotCenter.clone().project(e.dragViewport.camera); //点在屏幕中的位置。 若z>1 则在背面 或 超出far范围
  23125. } else {
  23126. rotAroundPoint = false;
  23127. }
  23128. }
  23129. this.rotateStartInfo = {
  23130. rotAroundPoint,
  23131. //定点旋转
  23132. rotCenter,
  23133. rotCenter2d
  23134. };
  23135. //缺点:多数据集绕中心点转很难操作,感觉可以也改为绕lastIntersect
  23136. //console.log('prepareRotate' )
  23137. };
  23138. var preparePan = e => {
  23139. //触屏的pan点云 还是会偏移
  23140. this.pointerDragStart = e.pointer.clone();
  23141. e.drag.z = void 0; //清空
  23142. drag(e); //触屏点击时更新的pointer直接用一次drag
  23143. //console.log('preparePan ' )
  23144. };
  23145. this.viewer.addEventListener('global_mousedown' /* 'startDragging' */, e => {
  23146. if (!this.enabled) return;
  23147. this.setCurrentViewport(e);
  23148. prepareRotate(e);
  23149. });
  23150. //注意,每次增减指头都会修改pointer,需要更新下状态
  23151. this.viewer.addEventListener('global_touchstart', e => {
  23152. if (!this.enabled) return;
  23153. if (e.touches.length == 2) {
  23154. //只监听开头两个指头
  23155. prepareScale(e);
  23156. preparePan(e);
  23157. } else if (e.touches.length >= 3) {
  23158. preparePan(e);
  23159. }
  23160. });
  23161. this.viewer.addEventListener('global_touchend', e => {
  23162. //e.touches是剩余的指头
  23163. if (!this.enabled) return;
  23164. if (e.touches.length == 2) {
  23165. //停止平移,开始scale
  23166. prepareScale(e);
  23167. preparePan(e);
  23168. } else if (e.touches.length == 1) {
  23169. //停止scale,开始rotate
  23170. prepareRotate(e);
  23171. } else if (e.touches.length >= 3) {
  23172. //重新准备下平移(因为抬起的指头可能包含平移使用的数据),否则抬起时漂移
  23173. preparePan(e);
  23174. }
  23175. });
  23176. /* this.viewer.addEventListener('enableChangePos', (e)=>{
  23177. if(!this.enabled)return
  23178. this.enableChangePos = e.canLeavePano
  23179. }) */
  23180. }
  23181. canMovePos(viewport) {
  23182. if (viewport == viewer.mainViewport && (Potree.settings.displayMode == 'showPanos' || viewer.images360.bumping || viewer.images360.latestToPano)) return false;else return true;
  23183. }
  23184. setEnable(enabled) {
  23185. this.enabled = enabled;
  23186. if (!enabled) {
  23187. this.yawDelta = this.pitchDelta = 0;
  23188. this.translationDelta.set(0, 0, 0);
  23189. this.translationWorldDelta.set(0, 0, 0);
  23190. }
  23191. }
  23192. setTarget(target, index) {
  23193. //绕该点旋转,类似orbitControl
  23194. if (index == 2) this.target2 = target;else this.target = target;
  23195. }
  23196. setFPCMoveSpeed(viewport) {
  23197. if (viewport.camera.type == 'OrthographicCamera') {
  23198. var s = 1 / viewport.camera.zoom;
  23199. viewport.setMoveSpeed(s);
  23200. } else {
  23201. //根据和漫游点的最短距离算moveSpeed。缺点:对于导入的无漫游点的数据集没有意义。
  23202. if (viewport == viewer.mainViewport && viewer.images360) {
  23203. var position = viewer.mainViewport.view.position;
  23204. var speed;
  23205. var pano = viewer.images360.findNearestPano();
  23206. if (!pano) {
  23207. if (!viewer.bound || viewer.bound.boundSize.x == 0) return;
  23208. var boundFloor = viewer.bound.boundingBox.clone();
  23209. boundFloor.max.z = boundFloor.min.z;
  23210. speed = boundFloor.distanceToPoint(viewer.mainViewport.view.position);
  23211. speed = Math.sqrt(speed) / 50;
  23212. } else {
  23213. var dis = pano.position.distanceTo(position);
  23214. var minSpeed = 0.05,
  23215. minDis = 3,
  23216. multiplier = 0.005;
  23217. speed = dis <= minDis ? minSpeed : minSpeed + (dis - minDis) * multiplier;
  23218. //console.log('dis', dis, 'speed', speed, pano.id )
  23219. }
  23220. viewer.setMoveSpeed(speed * 2);
  23221. }
  23222. //调试场景t-FhDWmV5xur 两个数据集,大的数据集没有漫游点。
  23223. }
  23224. }
  23225. setCurrentViewport() {
  23226. var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  23227. //add
  23228. if (!this.enabled && !o.force) return;
  23229. if (o.hoverViewport && this.currentViewport != o.hoverViewport) {
  23230. this.currentViewport = o.hoverViewport;
  23231. //this.viewer.setMoveSpeed(this.currentViewport.radius/100);
  23232. this.setFPCMoveSpeed(this.currentViewport);
  23233. }
  23234. if (this.currentViewport.camera.type == 'OrthographicCamera') {
  23235. this.lockElevationOri = true;
  23236. this.lockRotation = true;
  23237. } else {
  23238. this.lockElevationOri = false;
  23239. this.lockRotation = false;
  23240. }
  23241. }
  23242. setScene(scene) {
  23243. this.scene = scene;
  23244. }
  23245. stop() {
  23246. this.yawDelta = 0;
  23247. this.pitchDelta = 0;
  23248. this.translationDelta.set(0, 0, 0);
  23249. }
  23250. zoomToLocation(mouse) {
  23251. if (!this.enabled) return;
  23252. var camera = this.scene.getActiveCamera();
  23253. /* let I = Utils.getMousePointCloudIntersection(
  23254. mouse,
  23255. camera,
  23256. this.viewer,
  23257. this.scene.pointclouds); */
  23258. var I = this.viewer.inputHandler.intersect;
  23259. if (!I) {
  23260. return;
  23261. }
  23262. var targetRadius = 0;
  23263. {
  23264. var minimumJumpDistance = 0.2;
  23265. var domElement = this.renderer.domElement;
  23266. var ray = Utils.mouseToRay(this.viewer.inputHandler.pointer, camera);
  23267. var {
  23268. origin,
  23269. direction
  23270. } = this.viewer.inputHandler.getMouseDirection();
  23271. var raycaster = new Raycaster();
  23272. raycaster.ray.set(origin, direction);
  23273. var nodes = I.pointcloud.nodesOnRay(I.pointcloud.visibleNodes, ray);
  23274. var nodes2 = I.pointcloud.nodesOnRay(I.pointcloud.visibleNodes, raycaster.ray);
  23275. var lastNode = nodes[nodes.length - 1];
  23276. var radius = lastNode.getBoundingSphere(new Sphere()).radius;
  23277. targetRadius = Math.min(this.scene.view.radius, radius);
  23278. targetRadius = Math.max(minimumJumpDistance, targetRadius);
  23279. }
  23280. var d = this.scene.view.direction.multiplyScalar(-1);
  23281. var cameraTargetPosition = new Vector3().addVectors(I.location, d.multiplyScalar(targetRadius));
  23282. // TODO Unused: let controlsTargetPosition = I.location;
  23283. var animationDuration = 600;
  23284. var easing = TWEEN.Easing.Quartic.Out;
  23285. {
  23286. // animate
  23287. var value = {
  23288. x: 0
  23289. };
  23290. var tween = new TWEEN.Tween(value).to({
  23291. x: 1
  23292. }, animationDuration);
  23293. tween.easing(easing);
  23294. this.tweens.push(tween);
  23295. var startPos = this.scene.view.position.clone();
  23296. var targetPos = cameraTargetPosition.clone();
  23297. var startRadius = this.scene.view.radius;
  23298. var _targetRadius = cameraTargetPosition.distanceTo(I.location);
  23299. tween.onUpdate(() => {
  23300. var t = value.x;
  23301. this.scene.view.position.x = (1 - t) * startPos.x + t * targetPos.x;
  23302. this.scene.view.position.y = (1 - t) * startPos.y + t * targetPos.y;
  23303. this.scene.view.position.z = (1 - t) * startPos.z + t * targetPos.z;
  23304. this.scene.view.radius = (1 - t) * startRadius + t * _targetRadius;
  23305. this.viewer.setMoveSpeed(this.scene.view.radius / 2.5);
  23306. });
  23307. tween.onComplete(() => {
  23308. this.tweens = this.tweens.filter(e => e !== tween);
  23309. });
  23310. tween.start();
  23311. }
  23312. }
  23313. update() {
  23314. var delta = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
  23315. if (!this.enabled) return;
  23316. //console.log('update')
  23317. var view = this.currentViewport.view;
  23318. {
  23319. // cancel move animations on user input
  23320. var changes = [this.yawDelta, this.pitchDelta, this.translationDelta.length(), this.translationWorldDelta.length()];
  23321. var changeHappens = changes.some(e => Math.abs(e) > 0.001);
  23322. if (changeHappens && this.tweens.length > 0) {
  23323. this.tweens.forEach(e => e.stop());
  23324. this.tweens = [];
  23325. }
  23326. }
  23327. {
  23328. // accelerate while input is given
  23329. var ih = this.viewer.inputHandler;
  23330. var moveForward = this.keys.FORWARD.some(e => ih.pressedKeys[e]);
  23331. var moveBackward = this.keys.BACKWARD.some(e => ih.pressedKeys[e]);
  23332. var moveLeft = this.keys.LEFT.some(e => ih.pressedKeys[e]);
  23333. var moveRight = this.keys.RIGHT.some(e => ih.pressedKeys[e]);
  23334. var moveUp = this.keys.UP.some(e => ih.pressedKeys[e]);
  23335. var moveDown = this.keys.DOWN.some(e => ih.pressedKeys[e]);
  23336. var rotateLeft = this.keys.Rotate_LEFT.some(e => ih.pressedKeys[e]);
  23337. var rotateRight = this.keys.Rotate_RIGHT.some(e => ih.pressedKeys[e]);
  23338. var rotateUp = this.keys.Rotate_UP.some(e => ih.pressedKeys[e]);
  23339. var rotateDown = this.keys.Rotate_DOWN.some(e => ih.pressedKeys[e]);
  23340. this.lockElevation = this.lockElevationOri || this.keys.SPACE.some(e => ih.pressedKeys[e]);
  23341. var slightly = this.keys.ALT.some(e => ih.pressedKeys[e]);
  23342. if (!this.lockRotation) {
  23343. if (rotateLeft) {
  23344. this.yawDelta -= 0.01;
  23345. } else if (rotateRight) {
  23346. this.yawDelta += 0.01;
  23347. }
  23348. if (rotateUp) {
  23349. this.pitchDelta -= 0.01;
  23350. } else if (rotateDown) {
  23351. this.pitchDelta += 0.01;
  23352. }
  23353. }
  23354. if (this.canMovePos(this.currentViewport) && !this.lockKey) {
  23355. if (this.lockElevation) {
  23356. var dir = view.direction;
  23357. dir.z = 0;
  23358. dir.normalize();
  23359. if (moveForward && moveBackward) {
  23360. this.translationWorldDelta.set(0, 0, 0);
  23361. } else if (moveForward) {
  23362. this.translationWorldDelta.copy(dir.multiplyScalar(this.currentViewport.getMoveSpeed()));
  23363. } else if (moveBackward) {
  23364. this.translationWorldDelta.copy(dir.multiplyScalar(-this.currentViewport.getMoveSpeed()));
  23365. }
  23366. } else {
  23367. if (moveForward && moveBackward) {
  23368. this.translationDelta.y = 0;
  23369. } else if (moveForward) {
  23370. this.translationDelta.y = this.currentViewport.getMoveSpeed() * (slightly ? 0.2 : 1);
  23371. } else if (moveBackward) {
  23372. this.translationDelta.y = -this.currentViewport.getMoveSpeed() * (slightly ? 0.2 : 1);
  23373. }
  23374. }
  23375. if (moveLeft && moveRight) {
  23376. this.translationDelta.x = 0;
  23377. } else if (moveLeft) {
  23378. this.translationDelta.x = -this.currentViewport.getMoveSpeed();
  23379. } else if (moveRight) {
  23380. this.translationDelta.x = this.currentViewport.getMoveSpeed();
  23381. }
  23382. if (moveUp && moveDown) {
  23383. this.translationWorldDelta.z = 0;
  23384. } else if (moveUp) {
  23385. this.translationWorldDelta.z = this.currentViewport.getMoveSpeed();
  23386. } else if (moveDown) {
  23387. this.translationWorldDelta.z = -this.currentViewport.getMoveSpeed();
  23388. }
  23389. if (moveUp || moveDown || moveForward || moveBackward) {
  23390. this.useAttenuation = false;
  23391. }
  23392. }
  23393. }
  23394. {
  23395. // apply rotation
  23396. var yaw = view.yaw;
  23397. var pitch = view.pitch;
  23398. yaw += this.yawDelta; /* * delta; */
  23399. pitch += this.pitchDelta; /* * delta; */
  23400. view.yaw = yaw;
  23401. view.pitch = pitch;
  23402. if (this.yawDelta || this.pitchDelta) {
  23403. view.cancelFlying('rotate');
  23404. }
  23405. this.yawDelta = 0;
  23406. this.pitchDelta = 0;
  23407. }
  23408. /* if(this.translationWorldDelta.length()>0) {
  23409. // console.log('translationDelta')
  23410. } */
  23411. {
  23412. // apply translation
  23413. view.translate(this.translationDelta.x, /* * delta, */
  23414. this.translationDelta.y, /* * delta, */
  23415. this.translationDelta.z /* * delta */);
  23416. this.translationDelta.set(0, 0, 0);
  23417. //if(this.translationWorldDelta.length())console.log(translationWorldDelta)
  23418. view.translateWorld(this.translationWorldDelta.x /* * delta */, this.translationWorldDelta.y /* * delta */, this.translationWorldDelta.z /* * delta */);
  23419. //this.translationWorldDelta.set(0,0,0)
  23420. }
  23421. {// set view target according to speed
  23422. //view.radius = 1 * this.currentViewport.getMoveSpeed();
  23423. /* if(viewer.bound) view.radius = view.position.distanceTo(viewer.bound.center)
  23424. let speed = view.radius/100;
  23425. this.viewer.setMoveSpeed(speed); */
  23426. //this.setMoveSpeed()
  23427. }
  23428. if (this.useAttenuation) {
  23429. //只有滚轮缩放时开启
  23430. var attenuation = Math.max(0, 1 - this.fadeFactor * delta);
  23431. /*this.yawDelta *= attenuation;
  23432. this.pitchDelta *= attenuation;
  23433. this.translationDelta.multiplyScalar(attenuation);*/
  23434. this.translationWorldDelta.multiplyScalar(attenuation);
  23435. } else {
  23436. this.translationWorldDelta.set(0, 0, 0);
  23437. }
  23438. }
  23439. }
  23440. ;
  23441. /**
  23442. * @author mschuetz / http://mschuetz.at
  23443. *
  23444. *
  23445. */
  23446. var {
  23447. Buttons: Buttons$1
  23448. } = Potree.defines;
  23449. class InputHandler extends EventDispatcher {
  23450. constructor(viewer, scene) {
  23451. super();
  23452. this.viewer = viewer;
  23453. this.renderer = viewer.renderer;
  23454. this.domElement = this.renderer.domElement;
  23455. this.enabled = true;
  23456. this.scene = scene;
  23457. this.interactiveScenes = [];
  23458. this.interactiveObjects = new Set();
  23459. this.inputListeners = [];
  23460. this.blacklist = new Set();
  23461. this.drag = null;
  23462. this.mouse = new Vector2(0, 0);
  23463. //add:
  23464. this.pointer = new Vector2(0, 0); //交互点的屏幕坐标,有别于DOM坐标,在此存放NDC坐标。(NDC,三维常用坐标系,二维坐标,整个屏幕映射范围(-1,1),屏幕中心为原点,+Y朝上,+X朝右)
  23465. this.mouseDownMouse = new Vector2(0, 0);
  23466. this.selection = [];
  23467. this.hoveredElements = [];
  23468. this.pressedKeys = {};
  23469. this.wheelDelta = 0;
  23470. this.speed = 1;
  23471. this.logMessages = false;
  23472. if (this.domElement.tabIndex === -1) {
  23473. this.domElement.tabIndex = 2222;
  23474. }
  23475. this.lastPointerUpTime = 0;
  23476. this.touches = [];
  23477. this.interactHistory = {
  23478. move: 0
  23479. }; //add
  23480. this.hoverViewport = viewer.viewports[0];
  23481. this.domElement.addEventListener('contextmenu', event => {
  23482. event.preventDefault();
  23483. }, false);
  23484. this.domElement.addEventListener('click', this.onMouseClick.bind(this), false);
  23485. this.domElement.addEventListener('mousedown', this.onMouseDown.bind(this), false);
  23486. window.addEventListener('mouseup', this.onMouseUp.bind(this), false);
  23487. if (Potree.isIframeChild) {
  23488. //子页面的话在父页面也要加侦听(应该不会有多层吧?否则要一直加到最外层)
  23489. //window.parent.addEventListener('mouseup', this.onMouseUp.bind(this), false); //可能跨域
  23490. //window.parent.postMessage('listenMouseup', '*');
  23491. window.addEventListener('mouseout', this.onMouseUp.bind(this), false); //cancel drag
  23492. }
  23493. this.domElement.addEventListener('mouseout', () => {
  23494. this.containsMouse = false;
  23495. }, false);
  23496. this.domElement.addEventListener('mousemove', this.onMouseMove.bind(this), false);
  23497. //add
  23498. /* this.domElement.addEventListener("pointerout", this.onMouseUp.bind(this)),
  23499. this.domElement.addEventListener("pointercancel", this.onMouseUp.bind(this)),
  23500. */
  23501. this.domElement.addEventListener('mousewheel', this.onMouseWheel.bind(this), false);
  23502. this.domElement.addEventListener('DOMMouseScroll', this.onMouseWheel.bind(this), false); // Firefox
  23503. //this.domElement.addEventListener('dblclick', this.onDoubleClick.bind(this)); //因为双击时间间隔是跟随系统的所以不好判断
  23504. window.addEventListener('keydown', this.onKeyDown.bind(this)); //原先是this.domElement,这样的话一开始要点击屏幕后才能监听到
  23505. window.addEventListener('keyup', this.onKeyUp.bind(this));
  23506. window.addEventListener('blur', this.onKeyUp.bind(this)); //add
  23507. this.domElement.addEventListener('touchstart', this.onTouchStart.bind(this));
  23508. this.domElement.addEventListener('touchend', this.onTouchEnd.bind(this));
  23509. this.domElement.addEventListener('touchmove', this.onTouchMove.bind(this));
  23510. {
  23511. this.measuring = []; //正在编辑的measure
  23512. //let mesureInfo = new THREE.EventDispatcher()
  23513. this.addEventListener('measuring', e => {
  23514. //true优先级高于false, 正在添加时dropMarker也不会停止
  23515. //Potree.Utils.updateVisible(mesureInfo, e.situation, e.v, 0, e.v?'add':'cancel' )//借用该函数,使true优先级高于false,防止正在添加时dropMarker而停止
  23516. if (e.v) {
  23517. this.measuring.includes(e.object) || this.measuring.push(e.object);
  23518. } else {
  23519. var index = this.measuring.indexOf(e.object);
  23520. index > -1 && this.measuring.splice(index, 1);
  23521. }
  23522. if (this.measuring.length == 0 && this.measuring.length > 0) {
  23523. this.viewer.viewports.forEach(viewport => {
  23524. this.collectClosePoints(viewport, true); //forceUpdate
  23525. });
  23526. }
  23527. //console.log('measuring',e.v, e.cause, e.situation, this.measuring.length )
  23528. });
  23529. }
  23530. window.viewer.addEventListener('loopStart', () => {
  23531. this.interactHistory = {}; //清空
  23532. });
  23533. }
  23534. /* addInputListener (listener) {
  23535. this.inputListeners.push(listener);
  23536. }
  23537. removeInputListener (listener) {
  23538. this.inputListeners = this.inputListeners.filter(e => e !== listener);
  23539. }
  23540. getSortedListeners(){
  23541. return this.inputListeners.sort( (a, b) => {
  23542. let ia = (a.importance !== undefined) ? a.importance : 0;
  23543. let ib = (b.importance !== undefined) ? b.importance : 0;
  23544. return ib - ia;
  23545. });
  23546. } */
  23547. //统一跟第一个触碰的viewport相同
  23548. updateTouchesInfo(e) {
  23549. var viewport, pointer, camera;
  23550. var oldTouches = this.touches;
  23551. var changedTouches = Array.from(e.changedTouches);
  23552. var touches = Array.from(e.touches);
  23553. this.touches = touches.map(touch => {
  23554. var touch_ = oldTouches.find(a => a.touch.identifier == touch.identifier);
  23555. var pointer = touch_ && touch_.pointer; //复制原先的值
  23556. return {
  23557. touch,
  23558. pointer
  23559. };
  23560. });
  23561. if (e.touches.length > 0) {
  23562. var newTouches = touches.filter(e => !oldTouches.some(a => a.touch.identifier == e.identifier) && !changedTouches.some(a => a.identifier == e.identifier)); //从按钮处划过时e.touches中会出现this.touches和changedTouches中都没有的identifier
  23563. if (newTouches.length > 0) {
  23564. console.warn('has new', newTouches.map(e => e.identifier));
  23565. }
  23566. newTouches.concat(changedTouches).forEach(touch => {
  23567. //修改changedTouches的
  23568. var touch_ = this.touches.find(a => a.touch.identifier == touch.identifier);
  23569. if (touch_) {
  23570. var a = this.getPointerInViewport(touch.pageX, touch.pageY, this.dragViewport || viewport, new Vector2());
  23571. touch_.pointer = a.pointer.clone();
  23572. viewport = a.viewport;
  23573. camera = a.camera;
  23574. }
  23575. });
  23576. //使用当前touches的平均
  23577. if (e.touches.length > 1) {
  23578. var pageX = Common.average(e.touches, "pageX");
  23579. var pageY = Common.average(e.touches, "pageY");
  23580. var a = this.getPointerInViewport(pageX, pageY, viewport, new Vector2());
  23581. this.pointer.copy(a.pointer);
  23582. //console.log('updateTouchesInfo', this.pointer.clone())
  23583. } else {
  23584. this.pointer = this.touches[0].pointer.clone(); //更新,使用当前touches中的第一个
  23585. }
  23586. /* if(this.touches.find(e=>!e.pointer)){
  23587. console.error(' touches has no pointer', oldTouches.map(e=>e.touch.identifier),
  23588. Array.from(e.touches).map(e=>e.identifier), Array.from(e.changedTouches).map(e=>e.identifier) )
  23589. } */
  23590. //console.log(this.touches)
  23591. //console.log('更新pointer1',this.pointer.toArray())
  23592. return {
  23593. viewport,
  23594. camera /* , pointer:this.pointer */
  23595. };
  23596. }
  23597. }
  23598. onTouchStart(e) {
  23599. if (this.logMessages) console.log(this.constructor.name + ': onTouchStart');
  23600. e.preventDefault();
  23601. /* if (e.touches.length === 1 || !this.drag) { //!this.drag代表一次性下了两个指头
  23602. let rect = this.domElement.getBoundingClientRect();
  23603. let x = e.touches[0].pageX
  23604. let y = e.touches[0].pageY
  23605. this.dealPointerDown(x,y,e,true)
  23606. }else{
  23607. this.updateTouchesInfo(e)
  23608. this.drag.end.copy(this.pointer)
  23609. } */
  23610. this.dealPointerDown(e, true);
  23611. this.viewer.dispatchEvent($.extend(this.getEventDesc(e, true), {
  23612. type: 'global_' + e.type,
  23613. changedTouches: e.changedTouches
  23614. }));
  23615. /* console.log('targetTouches :', Array.from(e.targetTouches).map(e=>'| identifier: '+ e.identifier),
  23616. 'changedTouches :', Array.from(e.changedTouches).map(e=>'| identifier: '+ e.identifier)
  23617. ) */
  23618. //console.log('')
  23619. }
  23620. onTouchMove(e) {
  23621. if (this.logMessages) console.log(this.constructor.name + ': onTouchMove');
  23622. e.preventDefault();
  23623. /* if (e.touches.length === 1) {
  23624. let rect = this.domElement.getBoundingClientRect();
  23625. let x = e.touches[0].pageX;
  23626. let y = e.touches[0].pageY;
  23627. }else{
  23628. this.updateTouchesInfo(e)
  23629. this.drag.pointerDelta.subVectors(this.pointer, this.drag.end)
  23630. this.drag.end.copy(this.pointer)
  23631. }
  23632. */
  23633. this.dealPointerMove(e, true);
  23634. this.viewer.dispatchEvent($.extend(this.getEventDesc(e, true), {
  23635. type: 'global_' + e.type,
  23636. changedTouches: e.changedTouches
  23637. }));
  23638. /* console.log('targetTouches :', Array.from(e.targetTouches).map(e=>'| identifier: '+ e.identifier),
  23639. 'changedTouches :', Array.from(e.changedTouches).map(e=>'| identifier: '+ e.identifier)
  23640. ) */
  23641. }
  23642. onTouchEnd(e) {
  23643. if (this.logMessages) console.log(this.constructor.name + ': onTouchEnd');
  23644. e.preventDefault();
  23645. //console.log('onTouchEnd')
  23646. this.updateTouchesInfo(e);
  23647. /* if (e.touches.length === 0) {
  23648. let rect = this.domElement.getBoundingClientRect();
  23649. let x = e.changedTouches[0].pageX //万一一次松开两个指头的怎么办
  23650. let y = e.changedTouches[0].pageY
  23651. this.dealPointerUp(x,y,e,true)
  23652. }else {
  23653. this.drag.end.copy(this.pointer)
  23654. } */
  23655. this.dealPointerUp(e, true);
  23656. this.viewer.dispatchEvent($.extend(this.getEventDesc(e, true), {
  23657. type: 'global_' + e.type
  23658. }));
  23659. //console.log('touchend length '+e.touches.length, this.touches.length)
  23660. }
  23661. onKeyDown(e) {
  23662. if (this.logMessages) console.log(this.constructor.name + ': onKeyDown');
  23663. if (e.target.nodeName == 'INPUT' || e.target.nodeName == 'TEXTAREA') return; //正在输入文字 或e.srcElement
  23664. if (!this.containsMouse) return; //在别的ui上无效
  23665. // DELETE
  23666. /* if (e.keyCode === KeyCodes.DELETE && this.selection.length > 0) {
  23667. this.dispatchEvent({
  23668. type: 'delete',
  23669. selection: this.selection
  23670. });
  23671. this.deselectAll();
  23672. } */
  23673. this.dispatchEvent({
  23674. type: 'keydown',
  23675. keyCode: e.keyCode,
  23676. event: e
  23677. });
  23678. // for(let l of this.getSortedListeners()){
  23679. // l.dispatchEvent({
  23680. // type: "keydown",
  23681. // keyCode: e.keyCode,
  23682. // event: e
  23683. // });
  23684. // }
  23685. this.pressedKeys[e.keyCode] = true;
  23686. // e.preventDefault();
  23687. }
  23688. onKeyUp(e) {
  23689. if (this.logMessages) console.log(this.constructor.name + ': onKeyUp');
  23690. if (e.keyCode != void 0) {
  23691. delete this.pressedKeys[e.keyCode];
  23692. } else {
  23693. this.pressedKeys = {};
  23694. }
  23695. e.preventDefault();
  23696. }
  23697. onDoubleClick(e) {
  23698. if (this.logMessages) console.log(this.constructor.name + ': onDoubleClick');
  23699. var consumed = false;
  23700. for (var hovered of this.hoveredElements) {
  23701. if (hovered._listeners && hovered._listeners['dblclick']) {
  23702. hovered.object.dispatchEvent({
  23703. type: 'dblclick',
  23704. mouse: this.mouse,
  23705. object: hovered.object
  23706. });
  23707. consumed = true;
  23708. break;
  23709. }
  23710. }
  23711. if (!consumed) {
  23712. /* for (let inputListener of this.getSortedListeners()) {
  23713. inputListener. */
  23714. this.viewer.dispatchEvent({
  23715. type: 'global_dblclick',
  23716. mouse: this.mouse,
  23717. object: null
  23718. });
  23719. //}
  23720. }
  23721. this.needSingleClick = false; //add
  23722. e.preventDefault();
  23723. }
  23724. onMouseClick(e) {
  23725. if (this.logMessages) console.log(this.constructor.name + ': onMouseClick');
  23726. e.preventDefault();
  23727. }
  23728. dealPointerDown(e, isTouch) {
  23729. e.preventDefault();
  23730. //重新获取一下pointer, 因点击了浏览器的按钮展开列表时 move回来不会触发onmousemove,所以pointer是旧的
  23731. if (isTouch) {
  23732. var {
  23733. camera,
  23734. viewport
  23735. } = this.updateTouchesInfo(e);
  23736. if (this.drag) {
  23737. //因为触屏在按下前缺少pointermove所以要更新下
  23738. this.drag.end = this.pointer.clone();
  23739. }
  23740. } else {
  23741. var {
  23742. camera,
  23743. viewport
  23744. } = this.getPointerInViewport(e.clientX, e.clientY);
  23745. }
  23746. this.dragViewport = this.hoverViewport = viewport;
  23747. //if(isTouch || !Potree.settings.intersectWhenHover ){
  23748. if (isTouch || !this.dragViewport.view.isFlying() && Potree.settings.intersectWhenHover && Potree.settings.editType != 'pano') {
  23749. //漫游点编辑如果拖拽前getIntersect旋转会延迟
  23750. //isTouch必须更新 否则是旧的
  23751. this.hoveredElements = this.getHoveredElements();
  23752. var dontIntersect = false;
  23753. this.intersect = this.getIntersect({
  23754. viewport,
  23755. dontIntersect,
  23756. clientX: e.clientX,
  23757. clientY: e.clientY
  23758. }); //更新intersect,避免在没有mousemove但flyToPano后intersect未更新。
  23759. //this.intersect = this.getWholeIntersect()
  23760. }
  23761. if (!viewport) return; //why add this?
  23762. if (!this.drag) {
  23763. var target = (isTouch || e.button == MOUSE.LEFT) && this.hoveredElements.find(el =>
  23764. //只有左键能拖拽
  23765. el.object._listeners && el.object._listeners['drag'] && el.object._listeners['drag'].length > 0);
  23766. if (target) {
  23767. this.startDragging(target.object, {
  23768. location: target.point
  23769. });
  23770. } else {
  23771. this.startDragging(null);
  23772. }
  23773. }
  23774. this.drag.intersectStart = this.intersect;
  23775. if (!isTouch || e.touches.length == 1) {
  23776. var consumed = false;
  23777. var consume = () => {
  23778. return consumed = true;
  23779. };
  23780. //if (this.hoveredElements.length === 0) {
  23781. this.viewer.dispatchEvent($.extend(this.getEventDesc(e, isTouch), {
  23782. type: 'global_mousedown'
  23783. }));
  23784. for (var hovered of this.hoveredElements) {
  23785. var object = hovered.object;
  23786. object.dispatchEvent({
  23787. type: 'mousedown',
  23788. viewer: this.viewer,
  23789. consume: consume
  23790. });
  23791. if (consumed) {
  23792. break;
  23793. }
  23794. }
  23795. }
  23796. this.mouseDownMouse = this.mouse.clone();
  23797. this.pointerDownTime = Date.now();
  23798. }
  23799. onMouseDown(e) {
  23800. if (this.logMessages) console.log(this.constructor.name + ': onMouseDown');
  23801. this.dealPointerDown(e);
  23802. }
  23803. /* getWholeIntersect(hoveredElements, intersectPoint){//add
  23804. hoveredElements = hoveredElements || this.hoveredElements
  23805. intersectPoint = intersectPoint || this.intersectPoint
  23806. if(Potree.settings.intersectOnObjs && hoveredElements[0] && hoveredElements[0].object.isModel){
  23807. return {//模拟点云的intersectPoint的结构写法
  23808. hoveredElement : hoveredElements[0] ,
  23809. location: hoveredElements[0].point,
  23810. point: {normal: hoveredElements[0].face.normal },
  23811. distance: hoveredElements[0].distance,
  23812. object: hoveredElements[0].object
  23813. }
  23814. }else return intersectPoint
  23815. } */
  23816. getEventDesc(e, isTouch) {
  23817. //搜集dispatchEvent要给的一般数据
  23818. var o = {
  23819. viewer: this.viewer,
  23820. mouse: this.mouse,
  23821. pointer: this.pointer,
  23822. drag: this.drag,
  23823. isTouch,
  23824. dragViewport: this.dragViewport,
  23825. hoverViewport: this.hoverViewport,
  23826. // button: isTouch ? 0 : e.button,
  23827. //intersectPoint:this.intersectPoint,
  23828. hoveredElement: this.hoveredElements[0],
  23829. intersect: this.intersect //this.getWholeIntersect() , //可能包含mesh上的,针对融合页面
  23830. };
  23831. if (e) {
  23832. o.isAtDomElement = e.target == this.domElement;
  23833. }
  23834. if (isTouch) {
  23835. o.touches = this.touches;
  23836. } else if (e) {
  23837. o.button = e.button;
  23838. o.buttons = e.buttons;
  23839. }
  23840. return o;
  23841. }
  23842. dealPointerUp(e, isTouch) {
  23843. if (!this.drag) {
  23844. // 在canvas外mousedown
  23845. return;
  23846. }
  23847. this.drag.end.copy(this.pointer);
  23848. if (isTouch && e.touches.length >= 1) {
  23849. return;
  23850. }
  23851. var now = Date.now();
  23852. if (this.logMessages) console.log(this.constructor.name + ': onMouseUp');
  23853. e.preventDefault();
  23854. var pressDistance = this.mouseDownMouse.distanceTo(this.mouse);
  23855. var pressTime = now - this.pointerDownTime;
  23856. var noMovement = this.drag.pointerDelta.length() == 0; //this.getNormalizedDrag().length() === 0;
  23857. var consumed = false;
  23858. var consume = () => {
  23859. return consumed = true;
  23860. };
  23861. //if (this.hoveredElements.length === 0) {
  23862. /* for (let inputListener of this.getSortedListeners()) {
  23863. inputListener */
  23864. this.viewer.dispatchEvent($.extend(this.getEventDesc(e, isTouch), {
  23865. type: 'global_mouseup',
  23866. pressDistance,
  23867. consume
  23868. }));
  23869. /* if(consumed){//??
  23870. break;
  23871. } */
  23872. //}
  23873. //}
  23874. if (this.hoveredElements.length > 0) {
  23875. var hovered = this.hoveredElements.map(e => e.object).find(e => e._listeners && e._listeners['mouseup']);
  23876. if (hovered) {
  23877. hovered.dispatchEvent({
  23878. type: 'mouseup',
  23879. viewer: this.viewer,
  23880. consume: consume
  23881. });
  23882. }
  23883. }
  23884. if (this.drag) {
  23885. //拖拽结束
  23886. if (this.drag.object /* && e.button == THREE.MOUSE.LEFT */) {
  23887. //add LEFT
  23888. if (this.logMessages) console.log("".concat(this.constructor.name, ": drop ").concat(this.drag.object.name));
  23889. this.drag.object.dispatchEvent($.extend(this.getEventDesc(e, isTouch), {
  23890. type: 'drop',
  23891. pressDistance
  23892. }));
  23893. } else {
  23894. this.viewer.dispatchEvent($.extend(this.getEventDesc(e, isTouch), {
  23895. type: 'global_drop',
  23896. pressDistance
  23897. }));
  23898. }
  23899. // check for a click
  23900. if (pressDistance < Potree.config.clickMaxDragDis && pressTime < Potree.config.clickMaxPressTime && !e.unableClick) {
  23901. var clickElement,
  23902. _consumed = false;
  23903. if (this.hoveredElements) {
  23904. clickElement = this.hoveredElements.find(e => e.object._listeners['click']);
  23905. if (clickElement) {
  23906. var canceled;
  23907. var cancel = () => {
  23908. return canceled = true;
  23909. };
  23910. //console.log('clickElement',clickElement)
  23911. if (this.logMessages) console.log("".concat(this.constructor.name, ": click ").concat(clickElement.name));
  23912. clickElement.object.dispatchEvent($.extend(this.getEventDesc(e, isTouch), {
  23913. type: 'click',
  23914. pressDistance,
  23915. cancel
  23916. }));
  23917. if (canceled) {
  23918. //比如只需要右键的话,可以忽视左键的点击
  23919. clickElement = null;
  23920. }
  23921. }
  23922. }
  23923. var selectable;
  23924. if ( /* !consumed && */!this.fixSelection) {
  23925. if (e.button === MOUSE.LEFT) {
  23926. //if (noMovement) {
  23927. selectable = this.hoveredElements.find(el => el.object._listeners && el.object._listeners['select']);
  23928. if (selectable) {
  23929. selectable = selectable.object;
  23930. if (this.isSelected(selectable)) {
  23931. this.deselectAll();
  23932. } else {
  23933. this.deselectAll();
  23934. this.toggleSelection(selectable);
  23935. }
  23936. _consumed = true; //add
  23937. } else {
  23938. if (this.selection.length > 0) _consumed = true; //add 取消选择后,阻断后续
  23939. this.deselectAll();
  23940. }
  23941. //}
  23942. } else if (e.button === MOUSE.RIGHT /* && noMovement */) {
  23943. this.deselectAll();
  23944. }
  23945. }
  23946. var _consume = () => {
  23947. return _consumed = true;
  23948. };
  23949. var desc = this.getEventDesc(e, isTouch);
  23950. if (!_consumed) {
  23951. this.viewer.dispatchEvent($.extend(desc, {
  23952. type: 'global_click',
  23953. pressDistance,
  23954. clickElement: clickElement /* || selectable */,
  23955. consume: _consume
  23956. }));
  23957. }
  23958. //增加 单击:
  23959. this.needSingleClick = true;
  23960. _consumed || setTimeout(() => {
  23961. if (this.needSingleClick) {
  23962. this.viewer.dispatchEvent($.extend(desc, {
  23963. type: 'global_single_click',
  23964. pressDistance,
  23965. clickElement
  23966. }));
  23967. }
  23968. }, Potree.config.doubleClickTime + 1);
  23969. //自行执行双击:
  23970. if (now - this.lastClickTime < Potree.config.doubleClickTime) {
  23971. this.onDoubleClick(e);
  23972. }
  23973. this.lastClickTime = now;
  23974. }
  23975. this.drag = null;
  23976. }
  23977. this.dragViewport = null;
  23978. }
  23979. onMouseUp(e) {
  23980. this.dealPointerUp(e);
  23981. }
  23982. getPointerInViewport(clientX, clientY, viewForceAt, pointer) {
  23983. var rect = this.domElement.getBoundingClientRect();
  23984. var x = clientX - rect.left;
  23985. var y = clientY - rect.top;
  23986. var camera;
  23987. var viewport;
  23988. pointer = pointer || this.pointer;
  23989. //if(this.viewer.viewports || viewForceAt){
  23990. var getDimension = view => {
  23991. var left = Math.ceil(this.domElement.clientWidth * view.left),
  23992. bottom = Math.ceil(this.domElement.clientHeight * view.bottom),
  23993. width = Math.ceil(this.domElement.clientWidth * view.width),
  23994. height = Math.ceil(this.domElement.clientHeight * view.height),
  23995. top = this.domElement.clientHeight - bottom - height;
  23996. return {
  23997. left,
  23998. bottom,
  23999. width,
  24000. height,
  24001. top
  24002. };
  24003. };
  24004. var getView = (view, left, bottom, width, height, top) => {
  24005. this.mouse.set(x - left, y - top);
  24006. Utils.convertScreenPositionToNDC(pointer, this.mouse, width, height);
  24007. //console.log('更新pointer2',this.pointer.toArray())
  24008. camera = view.camera;
  24009. viewport = view;
  24010. };
  24011. if (viewForceAt) {
  24012. var {
  24013. left: _left,
  24014. bottom: _bottom,
  24015. width: _width,
  24016. height: _height,
  24017. top: _top
  24018. } = getDimension(viewForceAt);
  24019. getView(viewForceAt, _left, _bottom, _width, _height, _top);
  24020. } else {
  24021. var length = this.viewer.viewports.length;
  24022. //var getif = false
  24023. for (var i = 0; i < length; i++) {
  24024. var view = this.viewer.viewports[i];
  24025. if (!view.active) continue;
  24026. var {
  24027. left,
  24028. bottom,
  24029. width,
  24030. height,
  24031. top
  24032. } = getDimension(view);
  24033. if (x >= left && x <= left + width && y >= top && y <= top + height) {
  24034. getView(view, left, bottom, width, height, top);
  24035. //getif = true
  24036. break;
  24037. }
  24038. }
  24039. }
  24040. return {
  24041. camera,
  24042. viewport,
  24043. pointer
  24044. };
  24045. }
  24046. ifBlockedByIntersect() {
  24047. var {
  24048. point,
  24049. margin = 0,
  24050. cameraPos,
  24051. pickWindowSize,
  24052. pano,
  24053. useDepthTex,
  24054. viewport
  24055. } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  24056. //某点是否被遮挡(不允许camera修改位置, 因为depthTex不好置换)
  24057. viewport = viewport || this.hoverViewport || viewer.mainViewport;
  24058. var intersect = this.getIntersect({
  24059. viewport,
  24060. onlyGetIntersect: true,
  24061. pickWindowSize,
  24062. useDepthTex,
  24063. point,
  24064. cameraPos,
  24065. pano
  24066. });
  24067. var cameraPos_ = !cameraPos && pano ? pano.position : cameraPos || viewport.view.position;
  24068. if (intersect && intersect.distance + margin <= point.distanceTo(cameraPos_)) {
  24069. return intersect; //被遮挡
  24070. }
  24071. //点云模式,对没加载出的点云不准确。 尤其是需要修改相机位置时,因临时修改并不能使点云加载。
  24072. }
  24073. collectClosePoints(viewport, forceUpdate) {
  24074. //获取吸附点
  24075. if (!Potree.settings.adsorption) return;
  24076. var point2ds = [];
  24077. //吸附测量线端点
  24078. viewer.scene.measurements.forEach(e => {
  24079. if (this.measuring.includes(e)) return; //不吸附到正在拖拽的自身
  24080. point2ds.push(...e.getPointsPos2d(viewport, forceUpdate));
  24081. });
  24082. return point2ds;
  24083. }
  24084. getIntersect() {
  24085. var {
  24086. viewport,
  24087. onlyGetIntersect,
  24088. pickWindowSize,
  24089. dontIntersect,
  24090. usePointcloud,
  24091. useDepthTex,
  24092. cameraPos,
  24093. point,
  24094. pano,
  24095. clientX,
  24096. clientY
  24097. } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  24098. // usePointcloud:必须使用点云
  24099. var intersect, intersectPoint, intersectOnModel, allElements;
  24100. var camera = viewport.camera;
  24101. var raycaster;
  24102. viewer.addTimeMark('getIntersect', 'start');
  24103. var getByDepthTex = () => {
  24104. var intersect;
  24105. if (point) {
  24106. var _cameraPos = pano ? pano.position : camera.position;
  24107. var _dir = new Vector3().subVectors(point, _cameraPos).normalize();
  24108. intersect = {
  24109. dir: _dir
  24110. };
  24111. } else {
  24112. intersect = Utils.getIntersect(camera, [viewer.images360.cube], this.pointer, raycaster);
  24113. }
  24114. intersectPoint = viewer.images360.depthSampler.sample(intersect, pano, !!point); //可能不准确, 因pano可能未加载depthTex
  24115. if (intersectPoint && Potree.settings.depTexLocBindDataset) {
  24116. intersectPoint.pointcloud = (pano || viewer.images360.currentPano).pointcloud;
  24117. //在全景模式下,虽然深度图上的点可能对应别的pointcloud,但因为是在当前全景图处得到的,所以即使将原本对应的点云移走,该点也不移动是有道理的。它可以永远跟着该全景图。
  24118. }
  24119. };
  24120. var getByCloud = () => {
  24121. var pointer, mouse;
  24122. if (point) {
  24123. //指定了目标点,而非只是用pointer所在位置
  24124. cameraPos && camera.position.copy(cameraPos);
  24125. camera.lookAt(point);
  24126. camera.updateMatrixWorld();
  24127. pointer = this.pointer.clone();
  24128. mouse = this.mouse.clone();
  24129. this.pointer.set(0, 0); //画布中心
  24130. this.mouse.set(Math.round(viewport.resolution.x / 2), Math.round(viewport.resolution.y / 2));
  24131. }
  24132. intersectPoint = viewport.noPointcloud || dontIntersect ? null : Utils.getMousePointCloudIntersection(viewport, this.mouse, this.pointer, camera, this.viewer, this.viewer.scene.pointclouds, {
  24133. pickClipped: true,
  24134. measuring: this.measuring.length > 0,
  24135. pickWindowSize,
  24136. cameraChanged: !!point
  24137. });
  24138. //恢复
  24139. if (point) {
  24140. viewport.view.applyToCamera(camera);
  24141. this.pointer.copy(pointer);
  24142. this.mouse.copy(mouse);
  24143. }
  24144. };
  24145. if (this.measuring.length && Potree.settings.adsorption) {
  24146. //吸附
  24147. var points = this.collectClosePoints(viewport);
  24148. var points2 = points.filter(e => e.trueSide && e.inSight && math.closeTo(this.mouse, e.posInViewport, Potree.config.measure.adsorptMinDis));
  24149. var disArr = points2.map(e => e.pos.distanceToSquared(this.mouse));
  24150. var min = points2.slice().sort((a, b) => disArr[points.indexOf(a)] - disArr[points.indexOf(b)]);
  24151. if (min[0]) {
  24152. intersect = {
  24153. //hoveredElement
  24154. location: min[0].pos3d,
  24155. //point: {normal: allElements[0].face.normal },
  24156. //normal
  24157. //distance
  24158. object: min[0].object,
  24159. adsorption: true
  24160. };
  24161. console.log('找到吸附点', min[0].pos3d, min[0].object.uuid);
  24162. }
  24163. }
  24164. if (!intersect) {
  24165. var canUseDepthTex = (Potree.settings.displayMode == 'showPanos' || useDepthTex) && viewer.images360.currentPano.pointcloud.hasDepthTex && viewport == viewer.mainViewport && !usePointcloud;
  24166. if (canUseDepthTex) getByDepthTex();else if (Potree.settings.mergeType2 && Potree.settings.displayMode == 'showPanos' && !viewer.images360.currentPano.pointcloud.isPointcloud) {} //融合页面进入非点云的场景的全景模式不用pick
  24167. else getByCloud();
  24168. /* if(canUseDepthTex && this.measuring.length){
  24169. getByDepthTex()
  24170. }else{
  24171. getByCloud()
  24172. if(!intersectPoint && canUseDepthTex ){ //若在测量,先尝试点云,再用全景 //后来发现有深度图的点云全景visibleNode为空,pick不到的
  24173. getByDepthTex()
  24174. }
  24175. } */
  24176. //console.log(viewport.name , intersectPoint && intersectPoint.location )
  24177. if (Potree.settings.intersectOnObjs && !dontIntersect) {
  24178. if (point) {
  24179. raycaster = new Raycaster();
  24180. var dir = new Vector3().subVectors(point, camera.position).normalize();
  24181. raycaster.set(camera.position, dir); //var origin = new THREE.Vector3(pointer.x, pointer.y, -1).unproject(camera),
  24182. }
  24183. allElements = this.getHoveredElements(viewer.objs.children, true, raycaster);
  24184. if (allElements[0]) {
  24185. var quaternion = new Quaternion();
  24186. var nor = allElements[0].face && allElements[0].face.normal;
  24187. nor && allElements[0].oriObject.matrixWorld.decompose(new Vector3(), quaternion, new Vector3());
  24188. intersectOnModel = {
  24189. //模拟点云的intersectPoint的结构写法
  24190. hoveredElement: allElements[0],
  24191. location: allElements[0].point,
  24192. //point: {normal: allElements[0].face.normal },
  24193. normal: nor && nor.applyQuaternion(quaternion),
  24194. distance: allElements[0].distance,
  24195. object: allElements[0].object
  24196. };
  24197. }
  24198. }
  24199. if (intersectPoint && intersectOnModel) {
  24200. if (intersectPoint.distance < intersectOnModel.distance) {
  24201. intersect = intersectPoint;
  24202. } else {
  24203. intersect = intersectOnModel;
  24204. }
  24205. } else {
  24206. intersect = intersectOnModel || intersectPoint;
  24207. }
  24208. }
  24209. if (viewport.camera.type == 'OrthographicCamera' /* == 'mapViewport' */) {
  24210. var pos3d = new Vector3(this.pointer.x, this.pointer.y, -1).unproject(viewport.camera); //z:-1朝外
  24211. if (!intersect) {
  24212. intersect = {};
  24213. }
  24214. intersect.orthoIntersect = pos3d.clone();
  24215. }
  24216. //记录全部hover到的:
  24217. if (intersect) {
  24218. intersect.allElements = allElements;
  24219. intersect.pointclouds = intersectPoint ? intersectPoint.pointclouds : [];
  24220. }
  24221. viewer.addTimeMark('getIntersect', 'end');
  24222. //点云费时:2-15ms
  24223. //深度图费时: 0.1-0.2ms
  24224. /*
  24225. intersect && intersect.location && intersect.location.applyMatrix4(viewer.scene.scene.matrix)//add
  24226. */
  24227. if (onlyGetIntersect) {
  24228. return intersect;
  24229. }
  24230. if (intersect) {
  24231. if (viewer.showCoordType) {
  24232. //显示坐标位置时
  24233. var pos = intersect.point.position.toArray();
  24234. if (viewer.showCoordType == "local") {} else if (viewer.showCoordType == "lonlat") {
  24235. pos = viewer.transform.lonlatToLocal.inverse(pos);
  24236. } else {
  24237. pos = viewer.transform.lonlatToLocal.inverse(pos);
  24238. pos = viewer.transform.lonlatTo4550.forward(pos);
  24239. }
  24240. viewer.dispatchEvent({
  24241. type: "coordinateChange",
  24242. pos
  24243. });
  24244. }
  24245. }
  24246. //console.log('getIntersect', !!intersectPoint)
  24247. this.intersect = intersect;
  24248. intersect && (this.hoverViewport.lastIntersect = intersect);
  24249. return intersect;
  24250. }
  24251. onMouseMove(e) {
  24252. return this.dealPointerMove(e);
  24253. }
  24254. dealPointerMove(e, isTouch) {
  24255. if (this.interactHistory.move) return; //一帧只触发一次
  24256. this.interactHistory.move = 1;
  24257. if (isTouch) {
  24258. var {
  24259. camera,
  24260. viewport
  24261. } = this.updateTouchesInfo(e);
  24262. } else {
  24263. var {
  24264. camera,
  24265. viewport
  24266. } = this.getPointerInViewport(e.clientX, e.clientY, this.dragViewport);
  24267. }
  24268. this.hoverViewport = viewport;
  24269. if (!viewport) return; //刚变化viewport时会找不到
  24270. var isFlying = this.viewer.viewports.some(e => e.view.isFlying()) || viewer.scene.cameraAnimations.some(c => c.onUpdate);
  24271. var intersect;
  24272. if (e.onlyGetIntersect || !this.drag || this.drag.object || viewport.alignment) {
  24273. //没有拖拽物体,但按下鼠标了的话,不intersect。触屏的就能直接避免intersect
  24274. var dontIntersect = this.drag && viewport.alignment || isFlying || !Potree.settings.intersectWhenHover; // flying 时可能卡顿
  24275. //console.log('dontIntersectPointcloud',dontIntersectPointcloud)
  24276. intersect = this.getIntersect(Object.assign({}, e, {
  24277. viewport,
  24278. dontIntersect,
  24279. clientX: e.clientX,
  24280. clientY: e.clientY
  24281. })); //数据集多的时候卡顿
  24282. }
  24283. if (e.onlyGetIntersect) {
  24284. return intersect;
  24285. }
  24286. e.preventDefault();
  24287. if (this.drag) {
  24288. //有拖拽(不一定拖拽了物体, 也不一定按下了鼠标)
  24289. this.drag.mouse = isTouch ? 1 : e.buttons;
  24290. //add:
  24291. //this.drag.pointer = this.pointer.clone();
  24292. //this.drag.hoverViewport = this.hoverViewport
  24293. this.drag.pointerDelta.subVectors(this.pointer, this.drag.end);
  24294. this.drag.end.copy(this.pointer);
  24295. var dragConsumed = false;
  24296. if (this.drag.object && (e.buttons == Buttons$1.NONE || !this.drag.notPressMouse)) {
  24297. //如果是本不需要按鼠标的拖拽,但按下了鼠标,就不执行这段(改为拖拽场景,如添加测量时突然拖拽画面)
  24298. if (this.logMessages) console.log(this.constructor.name + ': drag: ' + this.drag.object.name);
  24299. var refused;
  24300. this.drag.object.dispatchEvent($.extend(this.getEventDesc(e, isTouch), {
  24301. type: 'drag',
  24302. //拖拽物体
  24303. refuse: () => {
  24304. refused = true;
  24305. }
  24306. }));
  24307. if (!refused) dragConsumed = true;
  24308. viewer.dispatchEvent('content_changed');
  24309. }
  24310. if (!dragConsumed) {
  24311. if (this.logMessages) console.log(this.constructor.name + ': drag: ');
  24312. this.viewer.dispatchEvent($.extend(this.getEventDesc(e, isTouch), {
  24313. type: 'global_drag' //拖拽画面
  24314. //consume: () => {dragConsumed = true;}
  24315. }));
  24316. }
  24317. }
  24318. if (!isTouch || e.touches.length == 1) {
  24319. if ((!this.drag || this.drag.notPressMouse || Potree.settings.intersectOnObjs && this.drag.object) && !isFlying) {
  24320. /* let blacklist = this.drag && this.drag */
  24321. var hoveredElements = this.getHoveredElements();
  24322. if (hoveredElements.length > 0) {
  24323. var names = hoveredElements.map(h => h.object.name).join(", ");
  24324. if (this.logMessages) console.log("".concat(this.constructor.name, ": onMouseMove; hovered: '").concat(names, "'"));
  24325. }
  24326. var cur = hoveredElements.find(a => a.object);
  24327. var curr = cur && cur.object; //hoveredElements.map(a => a.object).find(a => true);//只取第一个
  24328. var prev = this.lastMouseoverElement; //this.hoveredElements.map(a => a.object).find(a => true);
  24329. if (curr !== prev) {
  24330. if (curr) {
  24331. if (this.logMessages) console.log("".concat(this.constructor.name, ": mouseover: ").concat(curr.name));
  24332. curr.dispatchEvent({
  24333. type: 'mouseover',
  24334. object: curr,
  24335. hoveredElement: cur
  24336. });
  24337. }
  24338. if (prev) {
  24339. if (this.logMessages) console.log("".concat(this.constructor.name, ": mouseleave: ").concat(prev.name));
  24340. prev.dispatchEvent({
  24341. type: 'mouseleave',
  24342. object: prev
  24343. });
  24344. }
  24345. this.lastMouseoverElement = curr;
  24346. viewer.dispatchEvent('content_changed');
  24347. }
  24348. if (hoveredElements.length > 0) {
  24349. var object = hoveredElements.map(e => e.object).find(e => e._listeners && e._listeners['mousemove']);
  24350. if (object) {
  24351. object.dispatchEvent({
  24352. type: 'mousemove',
  24353. object: object
  24354. });
  24355. }
  24356. }
  24357. this.hoveredElements = hoveredElements;
  24358. }
  24359. //this.intersect = this.getWholeIntersect()
  24360. this.viewer.dispatchEvent($.extend(this.getEventDesc(e, isTouch), {
  24361. type: 'global_mousemove'
  24362. }));
  24363. this.containsMouse = true;
  24364. }
  24365. }
  24366. onMouseWheel(e) {
  24367. if (!this.enabled) return;
  24368. if (this.logMessages) console.log(this.constructor.name + ": onMouseWheel");
  24369. e.preventDefault();
  24370. var delta = 0;
  24371. if (e.wheelDelta !== undefined) {
  24372. // WebKit / Opera / Explorer 9
  24373. delta = e.wheelDelta;
  24374. } else if (e.detail !== undefined) {
  24375. // Firefox
  24376. delta = -e.detail;
  24377. }
  24378. var ndelta = Math.sign(delta);
  24379. // this.wheelDelta += Math.sign(delta);
  24380. if (!this.hoverViewport) {
  24381. //调试手机版时会无
  24382. var {
  24383. viewport
  24384. } = this.getPointerInViewport(e.clientX, e.clientY);
  24385. this.hoverViewport = viewport;
  24386. }
  24387. if (this.hoveredElement) {
  24388. this.hoveredElement.object.dispatchEvent($.extend(this.getEventDesc(e, isTouch), {
  24389. type: 'mousewheel',
  24390. delta: ndelta,
  24391. object: this.hoveredElement.object
  24392. }));
  24393. } else {
  24394. this.viewer.dispatchEvent($.extend(this.getEventDesc(e), {
  24395. type: 'global_mousewheel',
  24396. delta: ndelta
  24397. }));
  24398. }
  24399. setTimeout(() => {
  24400. this.dealPointerMove(e); //add 在更新完view后重新获取intersect 和 drag
  24401. }, 1); //只延迟1会崩溃吗
  24402. }
  24403. startDragging(object) {
  24404. var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  24405. var name = object ? object.name : "no name";
  24406. if (this.logMessages) console.log("".concat(this.constructor.name, ": startDragging: '").concat(name, "'"));
  24407. this.drag = {
  24408. start: this.pointer.clone(),
  24409. end: this.pointer.clone(),
  24410. pointerDelta: new Vector2(0, 0),
  24411. object: object,
  24412. hoverViewport: this.hoverViewport,
  24413. //会变化
  24414. dragViewport: this.hoverViewport //不变
  24415. };
  24416. if (args) {
  24417. for (var key of Object.keys(args)) {
  24418. this.drag[key] = args[key];
  24419. }
  24420. }
  24421. if (object) {
  24422. object.dispatchEvent($.extend(this.getEventDesc(), {
  24423. type: 'startDragging'
  24424. }));
  24425. }
  24426. }
  24427. /* getMousePointCloudIntersection (mouse) {
  24428. return Utils.getMousePointCloudIntersection(
  24429. this.mouse,
  24430. this.scene.getActiveCamera(),
  24431. this.viewer,
  24432. this.scene.pointclouds);
  24433. } */
  24434. toggleSelection(object) {
  24435. var oldSelection = this.selection;
  24436. var index = this.selection.indexOf(object);
  24437. if (index === -1) {
  24438. this.selection.push(object);
  24439. object.dispatchEvent({
  24440. type: 'select'
  24441. });
  24442. } else {
  24443. this.selection.splice(index, 1);
  24444. object.dispatchEvent({
  24445. type: 'deselect'
  24446. });
  24447. }
  24448. this.dispatchEvent({
  24449. type: 'selection_changed',
  24450. oldSelection: oldSelection,
  24451. selection: this.selection
  24452. });
  24453. viewer.dispatchEvent('content_changed');
  24454. }
  24455. deselect(object) {
  24456. var oldSelection = this.selection;
  24457. var index = this.selection.indexOf(object);
  24458. if (index >= 0) {
  24459. this.selection.splice(index, 1);
  24460. object.dispatchEvent({
  24461. type: 'deselect'
  24462. });
  24463. this.dispatchEvent({
  24464. type: 'selection_changed',
  24465. oldSelection: oldSelection,
  24466. selection: this.selection
  24467. });
  24468. }
  24469. viewer.dispatchEvent('content_changed');
  24470. }
  24471. deselectAll() {
  24472. for (var object of this.selection) {
  24473. object.dispatchEvent({
  24474. type: 'deselect'
  24475. });
  24476. }
  24477. var oldSelection = this.selection;
  24478. if (this.selection.length > 0) {
  24479. this.selection = [];
  24480. this.dispatchEvent({
  24481. type: 'selection_changed',
  24482. oldSelection: oldSelection,
  24483. selection: this.selection
  24484. });
  24485. }
  24486. viewer.dispatchEvent('content_changed');
  24487. }
  24488. isSelected(object) {
  24489. var index = this.selection.indexOf(object);
  24490. return index !== -1;
  24491. }
  24492. registerInteractiveObject(object) {
  24493. this.interactiveObjects.add(object);
  24494. }
  24495. removeInteractiveObject(object) {
  24496. this.interactiveObjects.delete(object);
  24497. }
  24498. registerInteractiveScene(scene) {
  24499. var index = this.interactiveScenes.indexOf(scene);
  24500. if (index === -1) {
  24501. this.interactiveScenes.push(scene);
  24502. }
  24503. }
  24504. unregisterInteractiveScene(scene) {
  24505. var index = this.interactiveScenes.indexOf(scene);
  24506. if (index > -1) {
  24507. this.interactiveScenes.splice(index, 1);
  24508. }
  24509. }
  24510. getHoveredElement() {
  24511. var hoveredElements = this.getHoveredElements();
  24512. if (hoveredElements.length > 0) {
  24513. return hoveredElements[0];
  24514. } else {
  24515. return null;
  24516. }
  24517. }
  24518. getHoveredElements(interactables, dontCheckDis, raycaster) {
  24519. if (!interactables) {
  24520. var scenes = this.hoverViewport.interactiveScenes || this.interactiveScenes.concat(this.scene);
  24521. var interactableListeners = ['mouseup', 'mousemove', 'mouseover', 'mouseleave', 'drag', 'drop', 'click', 'select', 'deselect'];
  24522. interactables = [];
  24523. for (var scene of scenes) {
  24524. scene.traverseVisible(node => {
  24525. //检测加了侦听的object
  24526. if (node._listeners && node.visible && !this.blacklist.has(node)) {
  24527. var hasInteractableListener = interactableListeners.filter(e => {
  24528. return node._listeners[e] !== undefined;
  24529. }).length > 0;
  24530. if (hasInteractableListener) {
  24531. interactables.push(node);
  24532. }
  24533. }
  24534. });
  24535. }
  24536. } else interactables = interactables.filter(e => e.visible);
  24537. var camera = this.hoverViewport.camera;
  24538. if (!raycaster) {
  24539. var ray = Utils.mouseToRay(this.pointer, camera);
  24540. raycaster = new Raycaster();
  24541. raycaster.ray.set(ray.origin, ray.direction);
  24542. raycaster.camera = camera; //add
  24543. }
  24544. if (camera.type == "OrthographicCamera") {
  24545. //使无论多远,threshold区域都是一样宽的
  24546. raycaster.params.Line.threshold = 20 / camera.zoom;
  24547. } else {
  24548. raycaster.params.Line.threshold = 0.04; //相对长度
  24549. }
  24550. raycaster.params.Line2 = {
  24551. threshold: browser.isMobile() ? 100 : 20
  24552. }; //拓宽的lineWidth
  24553. //raycaster.layers.enableAll()//add
  24554. var layers = ['sceneObjects', 'mapObjects', 'measure', 'transformationTool', 'model', 'bothMapAndScene']; //设置能识别到的layers(如空间模型里只有mapViewer能识别到marker)
  24555. if (Potree.settings.mergeType2 && Potree.settings.modelSkybox && Potree.settings.displayMode == 'showPanos' && !viewer.images360.currentPano.pointcloud.hasDepthTex) layers.push('skybox'); //model变成skybox了
  24556. Potree.Utils.setCameraLayers(raycaster, layers, this.hoverViewport && this.hoverViewport.extraEnableLayers);
  24557. //this.hoverViewport.beforeRender && this.hoverViewport.beforeRender()
  24558. viewer.dispatchEvent({
  24559. type: 'raycaster',
  24560. viewport: this.hoverViewport,
  24561. raycaster,
  24562. viewer: this.viewer,
  24563. interactables
  24564. }); //add
  24565. var intersections = raycaster.intersectObjects(interactables, true, null, true); //原本是false 检测不到children
  24566. var intersectionsCopy = intersections.slice();
  24567. if (this.intersect && this.intersect.distance != void 0 && !dontCheckDis) {
  24568. //add
  24569. intersections = intersections.filter(e => {
  24570. if (this.intersect.hoveredElement && this.intersect.hoveredElement.oriObject == e.object) return true;
  24571. var material = e.object.material;
  24572. return e.object.pickDontCheckDis || (material.depthTest == false || material.depthWrite == false) && !material.realUseDepth //!material.depthTestWhenPick
  24573. || (material.useDepth ? e.distance <= this.intersect.distance + material.uniforms.clipDistance.value : e.distance <= this.intersect.distance);
  24574. //maxClipFactor是否需要考虑?
  24575. });
  24576. }
  24577. intersections = intersections.map(e => {
  24578. //add 转化为interactables
  24579. var object = e.object;
  24580. do {
  24581. if (interactables.includes(object)) {
  24582. e.oriObject = e.object;
  24583. e.object = object;
  24584. break;
  24585. }
  24586. object = object.parent;
  24587. } while (object);
  24588. return e;
  24589. });
  24590. //add for测量线,在检测到sphere时优先选中sphere而非线
  24591. //intersections = intersections.sort(function(a,b){return b.object.renderOrder-a.object.renderOrder}) // 降序
  24592. intersections = intersections.sort(function (a, b) {
  24593. var order2 = b.object.pickOrder || 0;
  24594. var order1 = a.object.pickOrder || 0;
  24595. return order2 - order1;
  24596. }); // 降序
  24597. //console.log('getHoveredElement ', intersections)
  24598. return intersections;
  24599. }
  24600. /* setScene (scene) {
  24601. this.deselectAll();
  24602. this.scene = scene;
  24603. } */
  24604. update(delta) {}
  24605. /*getNormalizedDrag () {
  24606. if (!this.drag) {
  24607. return new THREE.Vector2(0, 0);
  24608. }
  24609. let diff = new THREE.Vector2().subVectors(this.drag.end, this.drag.start);
  24610. diff.x = diff.x / this.domElement.clientWidth;
  24611. diff.y = diff.y / this.domElement.clientHeight;
  24612. return diff;
  24613. }
  24614. getNormalizedLastDrag () {
  24615. if (!this.drag) {
  24616. return new THREE.Vector2(0, 0);
  24617. }
  24618. let mouseDelta = this.drag.mouseDelta.clone();
  24619. mouseDelta.x = mouseDelta.x / this.domElement.clientWidth;
  24620. mouseDelta.y = mouseDelta.y / this.domElement.clientHeight;
  24621. return mouseDelta;
  24622. } */
  24623. getMouseDirection(pointer) {
  24624. //add
  24625. pointer = pointer || this.pointer;
  24626. var camera = this.hoverViewport.camera;
  24627. var t = new Vector3(pointer.x, pointer.y, -1).unproject(camera),
  24628. i = new Vector3(pointer.x, pointer.y, 1).unproject(camera);
  24629. return {
  24630. origin: t,
  24631. direction: i.clone().sub(t).normalize()
  24632. };
  24633. }
  24634. }
  24635. class ViewerBase extends EventDispatcher {
  24636. constructor(domElement) {
  24637. var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  24638. super();
  24639. this.name = args.name;
  24640. this.renderArea = domElement;
  24641. this.oldResolution = new Vector2();
  24642. this.oldResolution2 = new Vector2();
  24643. this.screenSizeInfo = {
  24644. W: 0,
  24645. H: 0,
  24646. pixelRatio: 1,
  24647. windowWidth: 0,
  24648. windowHeight: 0
  24649. };
  24650. this.initContext(args);
  24651. this.addEventListener('content_changed', () => {
  24652. //画面改变,需要渲染
  24653. this.needRender = true;
  24654. //console.log('needRender')
  24655. });
  24656. }
  24657. initContext(args) {
  24658. //console.log(`initializing three.js ${THREE.REVISION}`);
  24659. var width = this.renderArea.clientWidth;
  24660. var height = this.renderArea.clientHeight;
  24661. var contextAttributes = {
  24662. alpha: true,
  24663. //支持透明
  24664. depth: true,
  24665. stencil: false,
  24666. antialias: !!args.antialias,
  24667. preserveDrawingBuffer: args.preserveDrawingBuffer || false,
  24668. powerPreference: "high-performance"
  24669. };
  24670. var canvas = document.createElement("canvas");
  24671. var context = canvas.getContext('webgl2', contextAttributes); //不用webgl2是因为有的写法在webgl2不支持 如gl_FragDepthEXT
  24672. if (context) {
  24673. Potree.settings.isWebgl2 = true;
  24674. }
  24675. this.renderer = new WebGLRenderer({
  24676. premultipliedAlpha: false,
  24677. canvas: canvas,
  24678. context: context
  24679. });
  24680. this.renderer.sortObjects = true; //原先false 打开了renderOrder才奏效
  24681. //this.renderer.setSize(width, height);
  24682. this.renderer.autoClear = args.autoClear || false;
  24683. //args.clearColor = args.clearColor || '#aa0033'
  24684. args.clearColor && this.renderer.setClearColor(args.clearColor);
  24685. this.renderArea.appendChild(this.renderer.domElement);
  24686. this.renderer.domElement.tabIndex = '2222';
  24687. this.renderer.domElement.style.position = 'absolute';
  24688. this.renderer.domElement.addEventListener('mousedown', () => {
  24689. this.renderer.domElement.focus();
  24690. });
  24691. //this.renderer.domElement.focus();
  24692. // NOTE: If extension errors occur, pass the string into this.renderer.extensions.get(x) before enabling
  24693. // enable frag_depth extension for the interpolation shader, if available
  24694. var gl = this.renderer.getContext();
  24695. gl.getExtension('EXT_frag_depth');
  24696. gl.getExtension('WEBGL_depth_texture');
  24697. gl.getExtension('WEBGL_color_buffer_float'); // Enable explicitly for more portability, EXT_color_buffer_float is the proper name in WebGL 2
  24698. if (gl.createVertexArray == null) {
  24699. var extVAO = gl.getExtension('OES_vertex_array_object');
  24700. if (!extVAO) {
  24701. throw new Error("OES_vertex_array_object extension not supported");
  24702. }
  24703. gl.createVertexArray = extVAO.createVertexArrayOES.bind(extVAO);
  24704. gl.bindVertexArray = extVAO.bindVertexArrayOES.bind(extVAO);
  24705. }
  24706. /* let oldClear = gl.clear;
  24707. gl.clear = (bits)=>{
  24708. console.error('clear')
  24709. }
  24710. */
  24711. }
  24712. updateScreenSize() {
  24713. var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  24714. //有可能需要让viewport来判断,当窗口大小不变但viewport大小变时
  24715. if (this.screenshoting && !o.forceUpdateSize) return; //截图时不允许因窗口改变大小而updateScreenSize
  24716. var render = false,
  24717. ratio,
  24718. w,
  24719. h;
  24720. //记录应当render的大小
  24721. if (o.width != void 0 && o.height != void 0) {
  24722. w = o.width;
  24723. h = o.height;
  24724. render = true;
  24725. ratio = 1;
  24726. } else {
  24727. w = this.renderArea.clientWidth;
  24728. h = this.renderArea.clientHeight;
  24729. if (w !== this.screenSizeInfo.W || h !== this.screenSizeInfo.H || o.forceUpdateSize || this.screenSizeInfo.pixelRatio != window.devicePixelRatio) {
  24730. this.screenSizeInfo.W = w;
  24731. this.screenSizeInfo.H = h;
  24732. render = true;
  24733. this.screenSizeInfo.pixelRatio = window.devicePixelRatio; //如果player放在小窗口了,也要监测devicePixelRatio,因为缩放时client宽高不会改变
  24734. //config.isMobile ? (ratio = Math.min(window.devicePixelRatio, 2)) : (ratio = window.devicePixelRatio)
  24735. ratio = window.devicePixelRatio;
  24736. }
  24737. }
  24738. if (render) {
  24739. this.setSize(w, h, ratio, o.forTarget);
  24740. }
  24741. }
  24742. setSize(width, height, devicePixelRatio, onlyForTarget) {
  24743. //console.log('setSize', width)
  24744. if (!onlyForTarget) {
  24745. //onlyForTarget表示不更改当前renderer,只是为了rendertarget才要改变viewport
  24746. this.renderer.setPixelRatio(devicePixelRatio);
  24747. this.renderer.setSize(width, height); // resize之后会自动clear(似乎因为setScissor ),所以一定要立刻绘制,所以setSize要在cameraChanged、update之前
  24748. }
  24749. //this.composer && this.composer.setSize(width, height);
  24750. if (this.viewports) {
  24751. this.viewports.forEach((view, i) => {
  24752. //if(!view.active)return
  24753. var width_ = width * view.width;
  24754. var height_ = height * view.height;
  24755. view.setResolution(Math.ceil(width_), Math.ceil(height_), width, height);
  24756. if (height_ == 0) return; //avoid NAN
  24757. var aspect = width_ / height_; //camera的参数精确些,不用视口的归整的resolution像素值,否则hasChange无法为true, 导致canvasResize了但map没update从而闪烁
  24758. view.camera.aspect = aspect;
  24759. if (view.camera.type == "OrthographicCamera") {
  24760. /* //不改宽度 同4dkk
  24761. var heightHalf = view.camera.right / aspect
  24762. view.camera.top = heightHalf
  24763. view.camera.bottom = -heightHalf */
  24764. //高宽都改 使大小不随视口大小改变 navvis (直接和视口大小一致即可,通过zoom来定大小)
  24765. view.camera.left = -width_ / 2;
  24766. view.camera.right = width_ / 2;
  24767. view.camera.bottom = -height_ / 2;
  24768. view.camera.top = height_ / 2;
  24769. } else {}
  24770. view.camera.updateProjectionMatrix();
  24771. });
  24772. }
  24773. if (!onlyForTarget) {
  24774. //因为onlyForTarget不传递devicePixelRatio所以不发送了
  24775. this.dispatchEvent('viewerResize');
  24776. this.viewports.forEach(e => {
  24777. this.ifEmitResize({
  24778. viewport: e,
  24779. deviceRatio: devicePixelRatio
  24780. });
  24781. });
  24782. }
  24783. }
  24784. ifEmitResize(e) {
  24785. //切换viewport渲染时, 若这些viewport大小不同就发送一次, 通知一些材质更新resolution。
  24786. //console.log('ifEmitResize',e.viewport.name,e.viewport.resolution2 )
  24787. if (!e.viewport.resolution.equals(this.oldResolution) || !e.viewport.resolution2.equals(this.oldResolution2)) {
  24788. this.dispatchEvent($.extend(e, {
  24789. type: 'resize'
  24790. }));
  24791. this.oldResolution.copy(e.viewport.resolution);
  24792. this.oldResolution2.copy(e.viewport.resolution2);
  24793. }
  24794. }
  24795. cameraChanged() {
  24796. //判断相机是否改变
  24797. var changed = false;
  24798. /* if(this.needRender){
  24799. this.needRender = false
  24800. return true
  24801. } */
  24802. for (var i = 0, j = this.viewports.length; i < j; i++) {
  24803. var viewport = this.viewports[i];
  24804. var changeInfo = viewport.cameraChanged();
  24805. if (changeInfo.changed) {
  24806. changed = true;
  24807. //if(!this.changeTime ||this.changeTime<100){
  24808. this.dispatchEvent({
  24809. type: "camera_changed",
  24810. camera: viewport.camera,
  24811. viewport,
  24812. changeInfo
  24813. });
  24814. //this.changeTime = (this.changeTime || 0) +1
  24815. //}
  24816. viewport.needRender = true; //直接写这咯
  24817. if (changeInfo.resolutionChanged) {
  24818. this.ifEmitResize({
  24819. viewport
  24820. }); //for map
  24821. }
  24822. }
  24823. }
  24824. return changed;
  24825. }
  24826. makeScreenshot(size, viewports, compressRatio) {
  24827. //暂时不要指定viewports渲染,但也可以
  24828. var {
  24829. width,
  24830. height
  24831. } = size;
  24832. /* let oldBudget = Potree.pointBudget;
  24833. Potree.pointBudget = Math.max(10 * 1000 * 1000, 2 * oldBudget);
  24834. let result = Potree.updatePointClouds(this.scene.pointclouds, camera, size );
  24835. Potree.pointBudget = oldBudget;
  24836. this.dispatchEvent({ //resize everything such as lines targets
  24837. type: 'resize',
  24838. resolution: new THREE.Vector2(width,height),
  24839. });*/
  24840. var target = new WebGLRenderTarget(width, height, {
  24841. format: RGBAFormat
  24842. });
  24843. this.setSize(width, height, 1, true);
  24844. this.render({
  24845. target,
  24846. //camera ,
  24847. viewports: viewports || this.viewports,
  24848. screenshot: true,
  24849. width,
  24850. height,
  24851. resize: true //需要resize
  24852. });
  24853. var dataUrl = Potree.Utils.renderTargetToDataUrl(target, width, height, this.renderer, compressRatio);
  24854. /* let pixelCount = width * height;
  24855. let buffer = new Uint8Array(4 * pixelCount);
  24856. this.renderer.readRenderTargetPixels(target, 0, 0, width, height, buffer);
  24857. let dataUrl = Potree.Utils.pixelsArrayToDataUrl(buffer, width, height, compressRatio) */
  24858. target.dispose();
  24859. //resize back
  24860. //this.updateScreenSize({forceUpdateSize:true})
  24861. return {
  24862. width,
  24863. height,
  24864. dataUrl
  24865. };
  24866. }
  24867. dispose() {
  24868. var scene = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.scene;
  24869. scene.clear();
  24870. this.renderer.dispose();
  24871. this.renderer.forceContextLoss();
  24872. var gl = this.renderer.getContext();
  24873. gl.getExtension("WEBGL_lose_context") && gl.getExtension("WEBGL_lose_context").loseContext();
  24874. this.renderArea.removeChild(this.renderer.domElement);
  24875. this.dispatchEvent('dispose');
  24876. }
  24877. }
  24878. class Viewport extends EventDispatcher {
  24879. constructor(view, camera) {
  24880. var prop = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  24881. //目前不支持换camera
  24882. super();
  24883. this.left = prop.left;
  24884. this.bottom = prop.bottom;
  24885. this.width = prop.width;
  24886. this.height = prop.height;
  24887. this.name = prop.name;
  24888. this.view = view;
  24889. this.camera = camera;
  24890. this.active = true;
  24891. this.unableChangePos = false;
  24892. this.noPointcloud;
  24893. //this.keys = [...] firstPersonCtl....
  24894. this.resolution = new Vector2();
  24895. this.resolution2 = new Vector2();
  24896. this.offset = new Vector2(); //viewportOffset 范围从0-整个画布的像素
  24897. this.extraEnableLayers = prop.extraEnableLayers || []; //额外可展示的层
  24898. this.cameraLayers = prop.cameraLayers;
  24899. this.pixelRatio = prop.pixelRatio; //如果规定pixelRatio的话要传,这样就覆盖devicePicelRatio, 如magnifier
  24900. }
  24901. clone() {
  24902. return Common.CloneClassObject(this);
  24903. }
  24904. getMoveSpeed() {
  24905. return this.moveSpeed;
  24906. }
  24907. setMoveSpeed(e) {
  24908. this.moveSpeed = e;
  24909. }
  24910. layersAdd(name) {
  24911. this.extraEnableLayers.includes(name) || this.extraEnableLayers.push(name);
  24912. }
  24913. layersRemove(name) {
  24914. var index = this.extraEnableLayers.indexOf(name);
  24915. if (index > -1) {
  24916. this.extraEnableLayers.splice(index, 1);
  24917. }
  24918. }
  24919. cameraChanged() {
  24920. var copy = () => {
  24921. this.previousState = {
  24922. projectionMatrix: this.camera.projectionMatrix.clone(),
  24923. //worldMatrix在this.control时归零了所以不用了吧,用position和qua也一样
  24924. position: this.camera.position.clone(),
  24925. quaternion: this.camera.quaternion.clone(),
  24926. active: this.active,
  24927. resolution: this.resolution.clone(),
  24928. resolution2: this.resolution2.clone() //有时clientWidth没变但是ratio缩放了
  24929. };
  24930. };
  24931. var projectionChanged = true,
  24932. positionChanged = true,
  24933. quaternionChanged = true,
  24934. activeChanged = true,
  24935. resolutionChanged = true;
  24936. var getChanged = () => {
  24937. return {
  24938. projectionChanged,
  24939. positionChanged,
  24940. quaternionChanged,
  24941. activeChanged,
  24942. resolutionChanged,
  24943. changed: projectionChanged || positionChanged || quaternionChanged || activeChanged || resolutionChanged
  24944. };
  24945. };
  24946. if (this.previousState) {
  24947. projectionChanged = !this.camera.projectionMatrix.equals(this.previousState.projectionMatrix);
  24948. positionChanged = !this.camera.position.equals(this.previousState.position);
  24949. quaternionChanged = !this.camera.quaternion.equals(this.previousState.quaternion);
  24950. activeChanged = this.active != this.previousState.active;
  24951. resolutionChanged = !this.resolution.equals(this.previousState.resolution) || !this.resolution2.equals(this.previousState.resolution2);
  24952. }
  24953. copy();
  24954. return getChanged();
  24955. }
  24956. setResolution(w, h) {
  24957. var wholeW = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  24958. var wholeH = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
  24959. this.resolution.set(w, h); //是client的width height
  24960. this.resolution2.copy(this.resolution).multiplyScalar(this.pixelRatio || window.devicePixelRatio);
  24961. this.offset.set(wholeW, wholeH).multiply(new Vector2(this.left, this.bottom)); //.multiplyScalar(window.devicePixelRatio)
  24962. this.dispatchEvent({
  24963. type: 'resize'
  24964. });
  24965. }
  24966. }
  24967. var prefixVertex = "precision highp float;\nprecision highp int;\n\nuniform mat4 modelMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\n attribute vec3 position;\n attribute vec3 normal;\n attribute vec2 uv;\n";
  24968. var prefixFragment = "precision highp float;\nprecision highp int;\n\nuniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n";
  24969. var shader = {
  24970. uniforms: {
  24971. opacity: {
  24972. type: "f"
  24973. // value: 1
  24974. },
  24975. progress: {
  24976. type: "f",
  24977. value: 0
  24978. },
  24979. pano0Map: {
  24980. type: "t",
  24981. value: null
  24982. },
  24983. pano1Map: {
  24984. type: "t",
  24985. value: null
  24986. },
  24987. depthMap0: {
  24988. type: "t",
  24989. value: null
  24990. },
  24991. depthMap1: {
  24992. type: "t",
  24993. value: null
  24994. },
  24995. pano0Position: {
  24996. type: "v3",
  24997. value: new Vector3()
  24998. },
  24999. pano0Matrix: {
  25000. type: "m4",
  25001. value: new Matrix4()
  25002. },
  25003. pano1Position: {
  25004. type: "v3",
  25005. value: new Vector3()
  25006. },
  25007. pano1Matrix: {
  25008. type: "m4",
  25009. value: new Matrix4()
  25010. },
  25011. /* pano1Matrix2: {
  25012. type: "m4",
  25013. value: new THREE.Matrix4
  25014. },
  25015. */
  25016. inverseProjectionMatrix: {
  25017. value: new Matrix4()
  25018. },
  25019. /* projectionMatrix:{//需要再写一遍吗
  25020. value: new THREE.Matrix4
  25021. }, */
  25022. viewport: {
  25023. value: new Vector4()
  25024. },
  25025. //如 {x: 0, y: 0, z: 428, w: 969} xy应该是offset, zw是宽高
  25026. cameraHeight0: {
  25027. type: "f",
  25028. value: 1
  25029. },
  25030. cameraHeight1: {
  25031. type: "f",
  25032. value: 1
  25033. },
  25034. ceilHeight0: {
  25035. type: "f",
  25036. value: 2
  25037. },
  25038. ceilHeight1: {
  25039. type: "f",
  25040. value: 2
  25041. }
  25042. },
  25043. vertexShader: prefixVertex + "\n\n uniform vec3 pano0Position;\n uniform mat4 pano0Matrix;\n \n uniform vec3 pano1Position;\n uniform mat4 pano1Matrix; \n\n \n varying vec2 vUv; \n varying vec3 vWorldPosition0;\n varying vec3 vWorldPosition1;\n varying vec3 vWorldPosition12;\n \n vec3 transformAxis( vec3 direction ) //navvis->4dkk\n {\n float y = direction.y;\n direction.y = direction.z;\n direction.z = -y;\n return direction;\n }\n \n \n void main() {\n \n vUv = uv;\n vec4 worldPosition = modelMatrix * vec4(position, 1.0);\n \n \n \n vec3 positionLocalToPanoCenter0 = worldPosition.xyz - pano0Position;\n vWorldPosition0 = (vec4(positionLocalToPanoCenter0, 1.0) * pano0Matrix).xyz;\n vWorldPosition0.x *= -1.0;\n vWorldPosition0 = transformAxis(vWorldPosition0);\n \n vec3 positionLocalToPanoCenter1 = worldPosition.xyz - pano1Position;\n vWorldPosition1 = (vec4(positionLocalToPanoCenter1, 1.0) * pano1Matrix).xyz;\n vWorldPosition1.x *= -1.0;\n vWorldPosition1 = transformAxis(vWorldPosition1);\n \n /* \n vec3 positionLocalToPanoCenter12 = worldPosition.xyz - pano1Position;\n vWorldPosition12 = (vec4(positionLocalToPanoCenter12, 1.0) * pano1Matrix2).xyz;\n vWorldPosition12.x *= -1.0;\n vWorldPosition12 = transformAxis(vWorldPosition12);\n */\n \n \n \n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n \n }\n\n ",
  25044. fragmentShader: prefixFragment + "\n #extension GL_EXT_frag_depth : enable // otherwise error: 'GL_EXT_frag_depth' : extension is disabled\n \n #define PI 3.141592653 \n \n \n uniform float modelAlpha;\n uniform float opacity;\n uniform float progress;\n uniform int tranType;\n uniform vec3 pano0Position;\n uniform vec3 pano1Position;\n uniform float maxDistance;\n uniform float minDistance;\n uniform float minOpa;\n \n \n \n uniform samplerCube pano0Map;\n uniform samplerCube pano1Map;\n \n \n varying vec2 vUv; \n varying vec3 vWorldPosition0;\n varying vec3 vWorldPosition1; \n \n \n /* vec2 getSamplerCoord( vec3 direction ) \n {\n direction = normalize(direction);\n float tx=atan(direction.x,-direction.y)/(PI*2.0)+0.5;\n float ty=acos(direction.z)/PI;\n\n return vec2(tx,ty);\n } */\n\n vec2 getSamplerCoord2( vec3 direction ) \n { \n direction = normalize(direction);\n float tx=atan(direction.x,direction.z)/(PI*2.0)+0.5;\n float ty=acos(direction.y)/PI;\n\n return vec2(tx,ty); \n }\n \n \n #if defined(GL_EXT_frag_depth) && defined(hasDepthTex) \n uniform sampler2D depthMap0;\n uniform sampler2D depthMap1;\n uniform mat4 inverseProjectionMatrix;\n uniform mat4 projectionMatrix;\n uniform vec4 viewport; \n uniform float cameraHeight0;\n uniform float cameraHeight1;\n uniform float ceilHeight0;\n uniform float ceilHeight1;\n \n \n vec2 getDepth(vec3 dir, sampler2D depthMap, float heightDown, float heightUp, vec4 eyePos){\n vec2 depthValue = vec2(0.0, 0.0);\n vec2 uv2 = getSamplerCoord2( dir.xyz); //\u6682\u65F6\u53EA\u7528\u57FA\u4E8E\u76EE\u6807\u6F2B\u6E38\u70B9\u7684\u65B9\u5411\n uv2.x -= 0.25; //\u5168\u666F\u56FE\u548CCube\u7684\u6C34\u5E73\u91C7\u6837\u8D77\u59CB\u5750\u6807\u76F8\u5DEE90\u5EA6\uFF0C\u8FD9\u91CC\u77EB\u6B63 0.25 \u4E2A\u91C7\u6837\u504F\u79FB\n vec4 depth = texture2D(depthMap, uv2);\n //float distance = depth.r + 256. * (depth.g + 256. * depth.b);\n //distance *= 255. * .001; // distance is now in meters\n \n //\u66F4\u6539\n float distance = (depth.g + depth.r / 256.) * 255.; \n \n if(distance == 0.0){//\u6F2B\u6E38\u70B9\u5E95\u90E8\u8BC6\u522B\u4E0D\u5230\u7684\u533A\u57DF\uFF0C\u7ED9\u4E00\u4E2A\u5730\u677F\u9AD8\u5EA6 \n if(uv2.y < depthTexUVyLimit) distance = heightUp / dir.y; \n else if(uv2.y > 1.0 - depthTexUVyLimit) distance = heightDown / -dir.y; \n else distance = 100000.0;//\u7ED9\u4E2A\u8D85\u7EA7\u8FDC\u7684\u503C\n } \n \n if(distance == 0.0)distance = 100000.0;//\u7ED9\u4E2A\u8D85\u7EA7\u8FDC\u7684\u503C\n \n depthValue.x = distance;\n \n distance += .1; // add a safety margin\n\n vec4 eyePos2 = vec4(normalize(eyePos.xyz) * distance, 1.);\n vec4 clipPos2 = projectionMatrix * eyePos2;\n vec4 ndcPos2 = clipPos2 * 1. / clipPos2.w;\n\n \n depthValue.y = 0.5 * ((gl_DepthRange.far - gl_DepthRange.near) * ndcPos2.z\n + gl_DepthRange.near + gl_DepthRange.far); \n \n #if defined(depth_background) \n //\u540E\u6392\u7684 skybox \u4E0D\u80FD\u6321\u4F4Fchunk \n depthValue.y += 0.3;\n #endif\n \n \n \n return depthValue; \n }\n //\u6CE8\uFF1A\u672A\u52A0\u8F7D\u597D\u7684\u8BDD\uFF0Cdepth\u4E3A0\uFF0C\u5BFC\u81F4\u7B2C\u4E00\u6B21\u6F2B\u6E38\u8FC7\u53BB\u7684\u65F6\u5019\u8BB8\u591Amesh\u4F1A\u7ACB\u523B\u88AB\u906E\u6321\uFF0C\u6240\u4EE5\u8981\u786E\u4FDD\u52A0\u8F7D\u5B8C\n #endif\n \n void main()\n {\n vec3 vWorldPosition0N = normalize(vWorldPosition0);\n vec3 vWorldPosition1N = normalize(vWorldPosition1);\n float progress_ = progress;\n \n vec4 colorFromPano0 = vec4(0.0,0.0,0.0,0.0);\n #if defined(usePanoMap0)\n //\u5373progress < 1.0 \u901A\u5E38\u662F1\n colorFromPano0=textureCube(pano0Map,vWorldPosition0N.xyz);\n #else \n progress_ = 1.0;\n #endif\n vec4 colorFromPano1=textureCube(pano1Map,vWorldPosition1N.xyz);\n \n gl_FragColor = mix(colorFromPano0,colorFromPano1,progress_);\n \n \n \n \n //\u6DF1\u5EA6\u56FE\u4FEE\u6539\u6DF1\u5EA6\n \n #if defined(GL_EXT_frag_depth) && defined(hasDepthTex) \n vec4 ndcPos;\n ndcPos.xy = ((2.0 * gl_FragCoord.xy) - (2.0 * viewport.xy)) / (viewport.zw) - 1.;\n ndcPos.z = (2.0 * gl_FragCoord.z - gl_DepthRange.near - gl_DepthRange.far) /\n (gl_DepthRange.far - gl_DepthRange.near);\n ndcPos.w = 1.0;\n\n vec4 clipPos = ndcPos / gl_FragCoord.w;\n vec4 eyePos = inverseProjectionMatrix * clipPos;\n vec2 depth0 = vec2(0.0,0.0); \n #if defined(usePanoMap0)\n depth0 = getDepth(vWorldPosition0N, depthMap0, cameraHeight0, ceilHeight0, eyePos);\n #endif\n vec2 depth1 = getDepth(vWorldPosition1N, depthMap1, cameraHeight1, ceilHeight1, eyePos);\n \n \n gl_FragDepthEXT = mix(depth0.y,depth1.y,progress_); \n gl_FragDepthEXT = clamp(gl_FragDepthEXT, 0.0, 1.0); //\u9632\u6B62\u90E8\u5206\u624B\u673A\u51FA\u73B0\u9ED1\u5757\u3002ios 16 \u3002 \u56E0\u4E3A\u6211\u7ED9\u7684\u8D85\u8FDC\u503C\u8D85\u51FA\u8303\u56F4\n \n\n #endif\n\n \n }\n "
  25045. };
  25046. //注:gl_FragDepthEXT 修改了确实能像真实mesh那样遮挡住在后面的物体。但是为过渡时不能直接像有模型那样,和角度有关。
  25047. class ModelTextureMaterial extends RawShaderMaterial {
  25048. constructor() {
  25049. var defines = {
  25050. depthTexUVyLimit: Potree.config.depthTexUVyLimit
  25051. };
  25052. var {
  25053. vs,
  25054. fs
  25055. } = Common.changeShaderToWebgl2(shader.vertexShader, shader.fragmentShader, 'RawShaderMaterial');
  25056. super({
  25057. fragmentShader: fs,
  25058. vertexShader: vs,
  25059. uniforms: UniformsUtils.clone(shader.uniforms),
  25060. side: DoubleSide,
  25061. name: "ModelTextureMaterial",
  25062. defines
  25063. });
  25064. this.glslVersion = Potree.settings.isWebgl2 && '300 es';
  25065. var setSize = e => {
  25066. var viewport = e.viewport;
  25067. //let viewportOffset = viewport.offset || new Vector2()
  25068. var resolution = viewport.resolution2;
  25069. //this.uniforms.viewport.value.set(viewportOffset.x, viewportOffset.y, resolution.x, resolution.y)
  25070. this.uniforms.viewport.value.set(0, 0, resolution.x, resolution.y); // xy是在viewport中的left和bottom,和整个窗口没有关系,所以不是viewportOffset。几乎都是0,0
  25071. };
  25072. var viewport = viewer.mainViewport;
  25073. setSize({
  25074. viewport
  25075. });
  25076. viewer.addEventListener('resize', e => {
  25077. if (e.viewport.name != "MainView") return;
  25078. setSize(e);
  25079. });
  25080. //var supportExtDepth = !!Features.EXT_DEPTH.isSupported()
  25081. {
  25082. //add
  25083. viewer.addEventListener('camera_changed', e => {
  25084. if (e.viewport.name != "MainView") return;
  25085. //this.uniforms.projectionMatrix.value.copy(e.camera.projectionMatrix)
  25086. e.camera && this.uniforms.inverseProjectionMatrix.value.copy(e.camera.projectionMatrixInverse);
  25087. });
  25088. }
  25089. var progress = 0;
  25090. Object.defineProperty(this.uniforms.progress, 'value', {
  25091. get: function get() {
  25092. return progress;
  25093. },
  25094. set: e => {
  25095. if (e < 1 && !Potree.settings.fastTran) {
  25096. if (!('usePanoMap0' in this.defines)) {
  25097. this.defines.usePanoMap0 = '';
  25098. this.needsUpdate = true;
  25099. }
  25100. } else {
  25101. if ('usePanoMap0' in this.defines) {
  25102. delete this.defines.usePanoMap0;
  25103. this.needsUpdate = true;
  25104. }
  25105. }
  25106. progress = e;
  25107. }
  25108. });
  25109. //-------------------------------------
  25110. }
  25111. /**
  25112. *
  25113. * @param {Panorama} pano0
  25114. * @param {Panorama} pano1
  25115. * @param {boolean} flag
  25116. 更新全景图的材质uniforms
  25117. */
  25118. setProjectedPanos(pano0, pano1, progressValue) {
  25119. progressValue != void 0 && (this.uniforms.progress.value = progressValue);
  25120. //pano0.ensureSkyboxReadyForRender();
  25121. if (pano0) {
  25122. this.uniforms.pano0Map.value = pano0.getSkyboxTexture(); //pano0.texture
  25123. this.uniforms.pano0Position.value.copy(pano0.position);
  25124. this.uniforms.pano0Matrix.value.copy(pano0.panoMatrix /* pano0.mesh.matrixWorld */);
  25125. //pano1.ensureSkyboxReadyForRender();
  25126. }
  25127. this.uniforms.pano1Map.value = pano1.getSkyboxTexture(); //pano1.texture;
  25128. this.uniforms.pano1Position.value.copy(pano1.position);
  25129. this.uniforms.pano1Matrix.value.copy(pano1.panoMatrix /* pano1.mesh.matrixWorld */);
  25130. this.pano0 = pano0;
  25131. this.pano1 = pano1;
  25132. this.updateDepthTex(pano0);
  25133. this.updateDepthTex(pano1);
  25134. //console.log('setProjectedPanos', pano0&&pano0.id, pano1&&pano1.id)
  25135. this.needsUpdate = true;
  25136. }
  25137. updateDepthTex(pano, extra) {
  25138. if (!Potree.settings.useDepthTex || !pano || !pano.depthTex || pano != this.pano0 && pano != this.pano1) return;
  25139. //console.log('updateDepthTex', pano.id, this.pano0 && this.pano0.id, this.pano1 && this.pano1.id)
  25140. if (this.pano0) {
  25141. this.uniforms.depthMap0.value = this.pano0.entered ? this.pano0.depthTex : null; //dispose了就不要赋值否则dispose会失败
  25142. this.uniforms.cameraHeight0.value = this.pano0.floorPosition.distanceTo(this.pano0.position);
  25143. this.uniforms.ceilHeight0.value = this.pano0.getCeilHeight() - this.pano0.position.z;
  25144. }
  25145. if (this.pano1) {
  25146. this.uniforms.depthMap1.value = this.pano1.depthTex; //pano1还没entered时也需要,可能在飞入
  25147. this.uniforms.cameraHeight1.value = this.pano1.floorPosition.distanceTo(this.pano1.position);
  25148. this.uniforms.ceilHeight1.value = this.pano1.getCeilHeight() - this.pano1.position.z;
  25149. }
  25150. this.updateDepthTexEnable();
  25151. }
  25152. updateDepthTexEnable() {
  25153. if (this.dontChangeDepth) return;
  25154. var hasDepthTex = this.pano0 && this.pano1 && this.pano0.pointcloud.hasDepthTex && this.pano1.pointcloud.hasDepthTex; //暂时不知道一个有图一个没图怎么写所以
  25155. Potree.Utils.addOrRemoveDefine(this, 'hasDepthTex', hasDepthTex ? 'add' : 'remove');
  25156. }
  25157. /* EnableDepthTex(){//开启DepthTex
  25158. if(this.defines['hasDepthTex']){
  25159. return
  25160. }
  25161. this.defines['hasDepthTex'] = ''
  25162. this.needsUpdate = true;
  25163. } */
  25164. }
  25165. class FastTranPass {
  25166. constructor(renderer) {
  25167. this.renderer = renderer;
  25168. this.coverRenderTarget = new WebGLRenderTarget(100, 100, {
  25169. minFilter: LinearFilter,
  25170. magFilter: LinearFilter,
  25171. format: RGBAFormat
  25172. });
  25173. this.coverTex = this.coverRenderTarget.texture;
  25174. this.enabled = false;
  25175. /* this.oldClearColor = new THREE.Color();
  25176. this.oldClearAlpha = 1;
  25177. this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
  25178. this.scene = new THREE.Scene(); */
  25179. this.material = this.getMaskMaterial();
  25180. /* var copyShader = THREE.CopyShader;
  25181. this.materialCopy = new THREE.ShaderMaterial( {
  25182. uniforms: this.copyUniforms,
  25183. vertexShader: copyShader.vertexShader,
  25184. fragmentShader: copyShader.fragmentShader,
  25185. blending: THREE.NoBlending,
  25186. depthTest: false,
  25187. depthWrite: false,
  25188. transparent: true
  25189. } );
  25190. this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), this.material);
  25191. this.quad.frustumCulled = false; // Avoid getting clipped
  25192. this.scene.add( this.quad );
  25193. this.renderToScreen = true*/
  25194. }
  25195. setSize(width, height) {
  25196. this.coverRenderTarget.setSize(width, height);
  25197. }
  25198. start() {
  25199. this.enabled = true;
  25200. var {
  25201. x,
  25202. y
  25203. } = viewer.mainViewport.resolution2;
  25204. this.setSize(x, y);
  25205. //draw coverTex
  25206. var oldTarget = this.renderer.getRenderTarget();
  25207. //let oldClearColor = this.renderer.getClearColor()
  25208. this.renderer.setRenderTarget(this.coverRenderTarget);
  25209. //this.renderer.setClearColor( 0x000000, 0)
  25210. var oldLayer = viewer.mainViewport.camera.layers.mask;
  25211. Potree.Utils.setCameraLayers(viewer.mainViewport.camera, ['skybox']);
  25212. this.renderer.render(viewer.scene.scene, viewer.mainViewport.camera);
  25213. //this.renderer.setClearColor( 0x000000, 0)
  25214. this.renderer.setRenderTarget(oldTarget);
  25215. viewer.mainViewport.camera.layers.mask = oldLayer;
  25216. this.material.uniforms.progress.value = 1;
  25217. console.log('start111');
  25218. }
  25219. render(scene, camera, viewports, renderer, writeBuffer, readBuffer) {
  25220. /* var oldAutoClear = renderer.autoClear;
  25221. renderer.autoClear = false;
  25222. */
  25223. var {
  25224. x,
  25225. y
  25226. } = viewer.mainViewport.resolution2;
  25227. var uniforms = this.material.uniforms;
  25228. //uniforms.bgTex.value = readBuffer.texture; //更新
  25229. uniforms.coverTex.value = this.coverTex;
  25230. uniforms.progress.value = viewer.images360.cube.material.uniforms.progress.value;
  25231. uniforms.screenRatio.value = x / y; // 使波纹为圆形
  25232. uniforms.screenRatio.value *= uniforms.screenRatio.value;
  25233. Potree.Utils.screenPass.render(viewer.renderer, viewer.images360.fastTranMaskPass.material);
  25234. //renderer.autoClear = oldAutoClear;
  25235. }
  25236. stop() {
  25237. this.enabled = false;
  25238. //console.log('stop111')
  25239. }
  25240. getMaskMaterial() {
  25241. return new ShaderMaterial({
  25242. uniforms: {
  25243. coverTex: {
  25244. type: "t",
  25245. value: null
  25246. },
  25247. progress: {
  25248. type: "f",
  25249. value: 0
  25250. },
  25251. screenRatio: {
  25252. type: "f",
  25253. value: 1
  25254. }
  25255. },
  25256. vertexShader: " \n varying vec2 vUv;\n \n void main() \n {\n vUv = uv;\n \n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n } \n \n ",
  25257. fragmentShader: " \n uniform sampler2D coverTex; \n uniform float progress; \n uniform float screenRatio;\n varying vec2 vUv;\n \n void main() {\n \n const float maxRadius = 0.708; // sqrt(0.5^2+0.5^2)\n const float minRadius = 0.0 ;\n \n float radius = screenRatio>1.0 ? sqrt((vUv.x - 0.5)*(vUv.x - 0.5) + (vUv.y - 0.5)*(vUv.y - 0.5)/screenRatio) : sqrt((vUv.x - 0.5)*(vUv.x - 0.5)*screenRatio+ (vUv.y - 0.5)*(vUv.y - 0.5));\n float diff = 0.292; //1.0-maxRadius;\n float radiusIn = maxRadius * progress + minRadius * (1.0-progress);\n float radiusOut = radiusIn + diff;\n if(radius < radiusIn) {\n \n discard;\n \n }else if(radius>radiusOut){\n gl_FragColor = texture2D(coverTex, vUv) ;\n //gl_FragColor = vec4(1.0,1.0,0.0,1.0);//\n \n }else{\n \n /* vec4 color1 = texture2D(bgTex, vUv);\n vec4 color2 = texture2D(coverTex, vUv);\n float rotio = smoothstep(radiusIn ,radiusOut,radius);\n \n gl_FragColor = mix(color1, color2, rotio); */\n \n float rotio = smoothstep(radiusIn ,radiusOut, radius);\n \n vec4 color2 = texture2D(coverTex, vUv);\n color2.a = rotio;\n \n \n }\n }\n "
  25258. });
  25259. }
  25260. /* getMaskMaterial(){
  25261. return new THREE.ShaderMaterial( {
  25262. uniforms: {
  25263. coverTex: {
  25264. type: "t",
  25265. value: null
  25266. },
  25267. bgTex: {
  25268. type: "t",
  25269. value: null
  25270. },
  25271. progress:{
  25272. type: "f",
  25273. value: 0
  25274. },
  25275. screenRatio:{
  25276. type: "f",
  25277. value: 1
  25278. }
  25279. },
  25280. vertexShader: `
  25281. varying vec2 vUv;
  25282. void main()
  25283. {
  25284. vUv = uv;
  25285. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  25286. }
  25287. `,
  25288. fragmentShader: `
  25289. uniform sampler2D coverTex;
  25290. uniform sampler2D bgTex;
  25291. uniform float progress;
  25292. uniform float screenRatio;
  25293. varying vec2 vUv;
  25294. void main() {
  25295. const float maxRadius = 0.708; // sqrt(0.5^2+0.5^2)
  25296. const float minRadius = 0.0 ;
  25297. float radius = screenRatio>1.0 ? sqrt((vUv.x - 0.5)*(vUv.x - 0.5) + (vUv.y - 0.5)*(vUv.y - 0.5)/screenRatio) : sqrt((vUv.x - 0.5)*(vUv.x - 0.5)*screenRatio+ (vUv.y - 0.5)*(vUv.y - 0.5));
  25298. float diff = 0.292; //1.0-maxRadius;
  25299. float radiusIn = maxRadius * progress + minRadius * (1.0-progress);
  25300. float radiusOut = radiusIn + diff;
  25301. if(radius < radiusIn) {
  25302. gl_FragColor = texture2D(bgTex, vUv);
  25303. //gl_FragColor = vec4(0.0,0.0,1.0,1.0);//
  25304. }else if(radius>radiusOut){
  25305. gl_FragColor = texture2D(coverTex, vUv) ;
  25306. //gl_FragColor = vec4(1.0,1.0,0.0,1.0);//
  25307. }else{
  25308. vec4 color1 = texture2D(bgTex, vUv);
  25309. vec4 color2 = texture2D(coverTex, vUv);
  25310. float rotio = smoothstep(radiusIn ,radiusOut,radius);
  25311. gl_FragColor = mix(color1, color2, rotio);
  25312. }
  25313. }
  25314. `
  25315. } );
  25316. } */
  25317. }
  25318. var GLCubeFaces$1 = Potree.defines.GLCubeFaces;
  25319. var TileUtils = {};
  25320. TileUtils.TILE_SIZE = 512, TileUtils.FACES_PER_PANO = 6, TileUtils.LocationOnTile = {
  25321. Center: 0,
  25322. UpperLeft: 1,
  25323. UpperRight: 2,
  25324. LowerRight: 3,
  25325. LowerLeft: 4
  25326. },
  25327. /*
  25328. * 获取某tile在cube中的方向 direction (向量起点在cube中心,终点在tile图的指定位置)。spherical通过先求uv,再直接得到dir
  25329. * @param {*} size 面分辨率
  25330. * @param {*} cubeFace 所在面
  25331. * @param {*} Center 在tile上的目标位置,默认为中心,其他位置就是四个顶点
  25332. * @param {*} c 似乎是在tile的缩进百分比,根据所在面的不同,分别向不同方向缩进,但都是向tile的中心
  25333. * @param {*} dir 所求方向
  25334. */
  25335. TileUtils.getTileVector = function () {
  25336. //获取某tile在cube中的方向 direction (向量起点在cube中心,终点在tile图的中心)
  25337. return function (size, tileSize, cubeFace, tileX, tileY, Center, c, dir) {
  25338. //c似乎是缩进百分比
  25339. Center = Center || TileUtils.LocationOnTile.Center;
  25340. //假设该cube边长为2:
  25341. var u = size / tileSize,
  25342. d = tileX / u;
  25343. tileY = -tileY + (u - 1);
  25344. var p = tileY / u,
  25345. f = tileSize / size,
  25346. g = 2 * f //一个tile的宽度 (乘以2是因为cube边长是2)
  25347. ,
  25348. m = g / 2,
  25349. v = 2 * d - 1 + m,
  25350. A = 2 * p - 1 + m;
  25351. switch (Center) {
  25352. //计算在tile中指定位置带来的偏移
  25353. case TileUtils.LocationOnTile.UpperLeft:
  25354. //1
  25355. v -= m, A += m, v += c * g; //似乎是向内缩进
  25356. break;
  25357. case TileUtils.LocationOnTile.UpperRight:
  25358. v += m, A += m, A -= c * g;
  25359. break;
  25360. case TileUtils.LocationOnTile.LowerRight:
  25361. v += m, A -= m, v -= c * g;
  25362. break;
  25363. case TileUtils.LocationOnTile.LowerLeft:
  25364. v -= m, A -= m, A += c * g;
  25365. break;
  25366. case TileUtils.LocationOnTile.Center: //0
  25367. }
  25368. switch (cubeFace) {
  25369. case GLCubeFaces$1.GL_TEXTURE_CUBE_MAP_POSITIVE_X:
  25370. MathLight.setVector(dir, -1, A, -v);
  25371. break;
  25372. case GLCubeFaces$1.GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
  25373. MathLight.setVector(dir, 1, A, v);
  25374. break;
  25375. case GLCubeFaces$1.GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
  25376. //顶面
  25377. MathLight.setVector(dir, -v, 1, -A);
  25378. break;
  25379. case GLCubeFaces$1.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
  25380. MathLight.setVector(dir, -v, -1, A);
  25381. break;
  25382. case GLCubeFaces$1.GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
  25383. MathLight.setVector(dir, -v, A, 1);
  25384. break;
  25385. case GLCubeFaces$1.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
  25386. MathLight.setVector(dir, v, A, -1);
  25387. }
  25388. MathLight.normalize(dir);
  25389. };
  25390. }(),
  25391. /*
  25392. * 获取该tile在第几个面(简易装载法)
  25393. */
  25394. TileUtils.getFaceForTile = function (size, index) {
  25395. //获取该tile在第几个面
  25396. var tileSize = TileUtils.TILE_SIZE;
  25397. size < TileUtils.TILE_SIZE && (tileSize = size);
  25398. var n = Math.floor(size / tileSize),
  25399. sum = n * n; //得每个面tile总数
  25400. return Math.floor(index / sum);
  25401. }, TileUtils.getTileLocation = function (size, t, result) {
  25402. var tileSize = TileUtils.TILE_SIZE;
  25403. size < TileUtils.TILE_SIZE && (tileSize = size);
  25404. var r = TileUtils.getFaceForTile(size, t),
  25405. a = Math.floor(size / tileSize),
  25406. s = a * a,
  25407. l = t - r * s;
  25408. result.tileX = l % a;
  25409. result.tileY = Math.floor(l / a);
  25410. result.face = r;
  25411. result.faceTileIndex = l;
  25412. return result;
  25413. },
  25414. /*
  25415. * 求size分辨率需要多少张tile
  25416. */
  25417. TileUtils.getTileCountForSize = function (e) {
  25418. if (e <= TileUtils.TILE_SIZE) return TileUtils.FACES_PER_PANO;
  25419. var t = Math.floor(e / TileUtils.TILE_SIZE),
  25420. i = t * t,
  25421. n = i * TileUtils.FACES_PER_PANO;
  25422. return n;
  25423. }, TileUtils.getRelativeDirection = function () {
  25424. var e = new MathLight.Matrix4(),
  25425. t = new MathLight.Quaternion();
  25426. return function (i, n) {
  25427. //i是pano.quaternion, n是camera的direction
  25428. t.copy(i), t.inverse(), e.makeRotationFromQuaternion(t), e.applyToVector3(n), MathLight.normalize(n);
  25429. };
  25430. }(),
  25431. /*
  25432. * 根据方向寻找合适的tile加载
  25433. */
  25434. TileUtils.matchingTilesInDirection = function () {
  25435. var e = new MathLight.Vector3(),
  25436. t = new MathLight.Vector3(0, 0, -1),
  25437. i = new MathLight.Quaternion(),
  25438. n = function n(e, t) {
  25439. e.push({
  25440. face: t.face,
  25441. faceTileIndex: t.faceTileIndex,
  25442. tileX: t.tileX,
  25443. tileY: t.tileY
  25444. });
  25445. },
  25446. a = function () {
  25447. var e = {
  25448. face: -1,
  25449. faceTileIndex: -1,
  25450. tileX: -1,
  25451. tileY: -1
  25452. };
  25453. return function (size, i, r) {
  25454. for (var a = TileUtils.getTileCountForSize(size), s = 0, l = 0; l < a; l++) TileUtils.getTileLocation(size, l, e), i && !i(e) || (s++, r && n(r, e));
  25455. return s;
  25456. };
  25457. }();
  25458. return function (pano, size, dir, hFov, vFov, result) {
  25459. var d = size < TileUtils.TILE_SIZE ? size : TileUtils.TILE_SIZE;
  25460. //TileUtils.getTileCountForSize(size);
  25461. if (!hFov && !vFov) return a(size, null, result);
  25462. var p = !!vFov;
  25463. vFov = vFov || hFov, vFov = Math.max(0, Math.min(vFov, 360)), hFov = Math.max(0, Math.min(hFov, 360)), MathLight.copyVector(dir, e), TileUtils.getRelativeDirection(pano.quaternion4dkk, e);
  25464. if (p) {
  25465. //如果有vFov hFov
  25466. i.setFromUnitVectors(e, t);
  25467. var f = function f(e) {
  25468. return TileUtils.isTileWithinFrustum(size, d, e.face, e.tileX, e.tileY, i, hFov, vFov); //在视野中的
  25469. };
  25470. return a(size, f, result);
  25471. }
  25472. var g = function g(t) {
  25473. //如果仅有hFov
  25474. return TileUtils.isTileWithinFOV(size, d, t.face, t.tileX, t.tileY, e, hFov);
  25475. };
  25476. return a(size, g, result);
  25477. };
  25478. }(),
  25479. /*
  25480. * 是否在屏幕范围内
  25481. */
  25482. TileUtils.isTileWithinFrustum = function () {
  25483. var e = new MathLight.Vector3(),
  25484. t = 1e-5;
  25485. return function (i, n, a, s, l, c, h, u) {
  25486. for (var d = Math.tan(.5 * u * MathLight.RADIANS_PER_DEGREE), p = -d, f = Math.tan(.5 * h * MathLight.RADIANS_PER_DEGREE), g = -f, m = TileUtils.mapFaceToCubemapFace(a), v = 0, A = 0, y = 0, C = 0, I = 0, E = 0, b = TileUtils.LocationOnTile.Center; b <= TileUtils.LocationOnTile.LowerLeft; b++) {
  25487. TileUtils.getTileVector(i, n, m, s, l, b, 0, e),
  25488. //get e // size, tileSize, cubeFace, tileX, tileY, Center, c, dir
  25489. MathLight.applyQuaternionToVector(c, e);
  25490. if (e.z >= -t)
  25491. //似乎是在相机背面
  25492. I++;else {
  25493. var w = -1 / e.z,
  25494. _ = e.x * w,
  25495. T = e.y * w;
  25496. T > d ? v++ : T < p && A++,
  25497. //这四种似乎代表在这个画框之外,如在左、在上、在下、在右
  25498. _ > f ? y++ : _ < g && C++, E++;
  25499. }
  25500. }
  25501. return A !== E && v !== E && y !== E && C !== E; //如果有一项和E相等代表要么是在相机背面要么是tile的四个顶点都画在画布的同一边,所以肯定不在画布上
  25502. };
  25503. }(),
  25504. /*
  25505. * 是否在FOV范围内
  25506. */
  25507. TileUtils.isTileWithinFOV = function () {
  25508. var e = new MathLight.Vector3(),
  25509. t = new MathLight.Vector3(0, 1, 0),
  25510. i = new MathLight.Vector3(1, 0, 0);
  25511. return function (panoSize, tileSize, face, tileX, tileY, direction, fov) {
  25512. //direction是作用了pano.quaternion的camera.direction
  25513. var d = TileUtils.mapFaceToCubemapFace(face);
  25514. MathLight.cross(direction, t, i); //get i 好像没用到
  25515. TileUtils.getTileVector(panoSize, tileSize, d, tileX, tileY, TileUtils.LocationOnTile.Center, 0, e);
  25516. if (TileUtils.isWithinFOV(e, direction, fov, null))
  25517. //先判断tile中心在不在FOV内
  25518. return !0;
  25519. for (var p = fov / 360, f = Math.floor(1 / p), g = 0, m = 0; m < f; m++) {
  25520. for (var v = TileUtils.LocationOnTile.UpperLeft; v <= TileUtils.LocationOnTile.LowerLeft; v++) if (TileUtils.getTileVector(panoSize, tileSize, d, tileX, tileY, v, g, e), TileUtils.isWithinFOV(e, direction, fov, null)) return !0;
  25521. g += p; //可能是考虑到有可能tile比fov覆盖了fov(虽然一般不可能,除非fov特别小),所以将tile分成若干段,取tile中的点再检测下
  25522. }
  25523. return !1;
  25524. };
  25525. }(), TileUtils.isWithinFOV = function () {
  25526. var e = new MathLight.Vector3(),
  25527. t = new MathLight.Vector3();
  25528. return function (dir, cameraDir, fov, a) {
  25529. if (MathLight.copyVector(dir, t), a) {
  25530. MathLight.copyVector(a, e), MathLight.normalize(e);
  25531. var s = MathLight.dot(e, dir);
  25532. e.x *= s, e.y *= s, e.z *= s, MathLight.subVector(t, e);
  25533. }
  25534. var l = fov / 2 * MathLight.RADIANS_PER_DEGREE,
  25535. c = Math.cos(l),
  25536. h = MathLight.dot(t, cameraDir);
  25537. return h >= c;
  25538. };
  25539. }(), TileUtils.mapFaceToCubemapFace = function () {
  25540. var e = {
  25541. 0: GLCubeFaces$1.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
  25542. 1: GLCubeFaces$1.GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
  25543. 2: GLCubeFaces$1.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
  25544. 3: GLCubeFaces$1.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
  25545. 4: GLCubeFaces$1.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
  25546. 5: GLCubeFaces$1.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
  25547. };
  25548. return function (t) {
  25549. return e[t];
  25550. };
  25551. }();
  25552. var {
  25553. PanoRendererEvents,
  25554. PanoramaEvents,
  25555. PanoSizeClass
  25556. } = Potree.defines;
  25557. var texLoader$3 = new TextureLoader();
  25558. var markerOpacitys = {
  25559. default: 0.4,
  25560. hovered: 1
  25561. };
  25562. var labelProp = {
  25563. sizeInfo: {
  25564. minSize: 200,
  25565. maxSize: 250,
  25566. nearBound: 0.8,
  25567. farBound: 10
  25568. },
  25569. backgroundColor: {
  25570. r: 255,
  25571. g: 255,
  25572. b: 255,
  25573. a: 0.4
  25574. },
  25575. textColor: {
  25576. r: 0,
  25577. g: 0,
  25578. b: 0,
  25579. a: 1
  25580. },
  25581. borderRadius: 15,
  25582. renderOrder: 10,
  25583. useDepth: true,
  25584. clipDistance: 30,
  25585. maxClipFactor: 0.3,
  25586. occlusionDistance: 3
  25587. };
  25588. var labelProp2 = {
  25589. //sizeInfo: {minSize : 200 , maxSize : 250, nearBound : 0.8, farBound : 10},
  25590. backgroundColor: {
  25591. r: 255,
  25592. g: 255,
  25593. b: 255,
  25594. a: 0
  25595. },
  25596. textColor: {
  25597. r: 255,
  25598. g: 255,
  25599. b: 255,
  25600. a: 1
  25601. },
  25602. textBorderColor: {
  25603. r: 30,
  25604. g: 30,
  25605. b: 30,
  25606. a: 1
  25607. },
  25608. textBorderThick: 3,
  25609. dontFixOrient: true,
  25610. renderOrder: 10,
  25611. fontsize: 30
  25612. };
  25613. var markerTex;
  25614. //显示全景图时marker没有被遮挡,如果需要,要换成depthBasicMaterial 或者直接把skybox的深度修改(拿到深度贴图后更如此)
  25615. var planeGeo = new PlaneBufferGeometry(0.2, 0.2);
  25616. var sg = new SphereGeometry(0.1, 8, 8);
  25617. var smHovered = new MeshBasicMaterial({
  25618. /* side: THREE.BackSide, */color: 0xff0000
  25619. });
  25620. var sm = new MeshBasicMaterial({/* side: THREE.BackSide */});
  25621. var rot90 = new Quaternion().setFromAxisAngle(new Vector3(0, 0, 1), Math.PI / 2); //使用的是刚好适合全景图的,给cube贴图需要转90°
  25622. //var rot90 = new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(1,0,0), -Math.PI/2 ); //4dkk->navvis
  25623. //var rot901 = new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0,1,0), -Math.PI/2 ); //整张球幕图要旋转下
  25624. //rot90 = new THREE.Quaternion().multiplyQuaternions( rot901, rot90)
  25625. var old = null;
  25626. /*
  25627. 转成四维看看的axis:
  25628. var a = new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0,0,1), THREE.Math.degToRad(-90)) 因为四维的要绕y转90
  25629. 这里的quaternion.multiply(a);
  25630. 先乘再换顺序 w : q.w, x:q.x , y:-q.z, z:q.y
  25631. */
  25632. //暂时直接用4dkkconsole输出的数据
  25633. class Panorama extends EventDispatcher {
  25634. constructor(o, images360) {
  25635. //file, time, longitude, latitude, altitude, course, pitch, roll
  25636. super();
  25637. this.id = o.id; //唯一标识
  25638. this.images360 = images360;
  25639. this.visible = true; //for updateVisible
  25640. this.enabled = true; //是否可以走
  25641. this.addEventListener('isVisible', e => {
  25642. //是否显示该点的mesh(不显示也能走)
  25643. //console.log('pano isVisible', this.id, e.visible)
  25644. Potree.Utils.updateVisible(this.marker, 'panoVisi', e.visible);
  25645. Potree.settings.showPanoMesh && (this.mesh.visible = e.visible);
  25646. if (e.reason == 'screenshot' || e.visible) {
  25647. this.label && (this.label.visible = e.visible); //截图时隐藏下
  25648. }
  25649. this.label2 && Potree.Utils.updateVisible(this.label2, 'panoVisi', e.visible);
  25650. });
  25651. /*
  25652. 漫游点可见性:旧
  25653. level reason 类型
  25654. 2(最高)buildingChange(不在此楼层) unvisible
  25655. 1 modeIsShowPanos(漫游模式) visible //不记得为什么加这个了,所以重写
  25656. 0 pointcloudVisi(隐藏了数据集) unvisible
  25657. */
  25658. /*
  25659. 漫游点可见性:新
  25660. level reason 类型
  25661. 2(最高)buildingChange(不在此楼层) unvisible
  25662. 1 ifShowMarker(marker显示开关) unvisible
  25663. 0 pointcloudVisi(隐藏了数据集) unvisible
  25664. */
  25665. if (Potree.settings.editType == 'pano') {
  25666. //漫游点拼合编辑
  25667. this.uuid = o.uuid; //因为有多个数据集 所以会重复
  25668. this.index = this.originID = o.index; //下标, 用于visibles
  25669. this.pointcloud = viewer.scene.pointclouds.find(e => e.panoUuid == o.uuid);
  25670. this.pointcloud.panos.push(this);
  25671. this.sid = this.pointcloud.dataset_id + '|' + this.uuid; //不会更改的标记 用于entity.panos里的标记
  25672. this.panosData = o;
  25673. //数据中原本的位置朝向
  25674. this.dataPosition = new Vector3().copy(o.pose.translation);
  25675. this.dataQuaternion = new Quaternion().copy(o.pose.rotation);
  25676. this.dataRotation = new Euler().setFromQuaternion(this.dataQuaternion);
  25677. //因为位置朝向随着点云位置改变,所以直接运用到点云上,这里清零
  25678. this.originPosition = new Vector3(); //{x: 0, y: 0, z: 0}
  25679. this.quaternion = new Quaternion(); //{w: 0, x: 0, y: 0, z: 1}
  25680. //this.quaternion4dkk = math.convertVisionQuaternion(this.quaternion)//4dkk内使用的quaternion
  25681. this.visibles = o.visibles;
  25682. this.rtkState = o.has_rtk ? o.use_rtk : null;
  25683. var height = 1.4; //相机高度
  25684. this.originFloorPosition = this.originPosition.clone();
  25685. this.originFloorPosition.z -= height;
  25686. /* this.originPosition = new THREE.Vector3().copy(o.pose.translation) //{x: 0, y: 0, z: 0}
  25687. this.quaternion = new THREE.Quaternion().copy(o.pose.rotation) //{w: 0, x: 0, y: 0, z: 1}
  25688. //this.quaternion4dkk = math.convertVisionQuaternion(this.quaternion)//4dkk内使用的quaternion
  25689. this.visibles = o.visibles
  25690. this.pointcloud = viewer.scene.pointclouds.find(e=>e.dataset_id == o.uuid)
  25691. this.pointcloud.panos.push(this)
  25692. const height = 1.5; //相机高度
  25693. this.originFloorPosition = this.originPosition.clone()
  25694. this.originFloorPosition.z -= height
  25695. */
  25696. } else {
  25697. this.originPosition = new Vector3().fromArray(o.dataset_location); //完全对应vision.txt的translation
  25698. this.originFloorPosition = new Vector3().fromArray(o.dataset_floor_location);
  25699. this.originID = parseInt(o.file_id); //"file_id":"00022"对应是原本的4dkk的id --来自vision.txt
  25700. this.pointcloud = o.pointcloud; //viewer.scene.pointclouds.find(e=>e.dataset_id == o.dataset_id) || viewer.scene.pointclouds[0]
  25701. this.pointcloud.panos.push(this);
  25702. //this.sid = this.pointcloud.sceneCode + '|' + this.originID //不会更改的标记
  25703. this.sid = this.pointcloud.dataset_id + '|' + this.originID; //不会更改的标记
  25704. //全景图和Cube的水平采样起始坐标相差90度
  25705. /* if(from4dkk){
  25706. var qua = o.dataset_orientation
  25707. var quaternion = new THREE.Quaternion().fromArray(qua)
  25708. quaternion = new THREE.Quaternion().multiplyQuaternions(quaternion, rot901);//整张球幕图要旋转下 因为在4dkk里转过,还原。如果是tiles的不用
  25709. this.quaternion = new THREE.Quaternion(quaternion.x, -quaternion.z, quaternion.y, quaternion.w) //转化坐标
  25710. }else{ */
  25711. var qua = o.dataset_orientation; //完全对应vision.txt的rotation
  25712. qua = [qua[1], qua[2], qua[3], qua[0]];
  25713. this.quaternion = new Quaternion().fromArray(qua);
  25714. this.quaternion4dkk = math.convertVisionQuaternion(this.quaternion); //4dkk内使用的quaternion
  25715. this.quaternion2 = this.quaternion.clone();
  25716. this.quaternion = new Quaternion().multiplyQuaternions(this.quaternion, rot90); //全景图和Cube的水平采样起始坐标相差90度,cubeTex转90度
  25717. this.rotation4dkk = new Euler().setFromQuaternion(this.quaternion4dkk);
  25718. //}
  25719. //this.quaternion1 = Potree.Utils.QuaternionFactory.fromArray(o.dataset_orientation)
  25720. //同quaternion
  25721. //let xy = this.transform.forward([this.longitude, this.latitude]);
  25722. //this.file = `https://4dkk.4dage.com/images/images${Potree.settings.number}/pan/high/${this.id}.jpg`
  25723. this.neighbours = [];
  25724. }
  25725. this.rotation = new Euler().setFromQuaternion(this.quaternion);
  25726. this.build();
  25727. this.transformByPointcloud(); //初始化位移
  25728. {
  25729. //tile
  25730. this.minimumTiledPanoLoaded = !1;
  25731. this.highestPartialTileRenderOpCompleted = 0;
  25732. this.highestFullTileRenderOpCompleted = 0;
  25733. this.shouldRedrawOnBaseLoaded = !1;
  25734. this.resolutionPromise = {};
  25735. this.tiledPanoRenderTarget = null;
  25736. this.zoomed = !1;
  25737. images360.panoRenderer.addEventListener(PanoRendererEvents.TileRenderSuccess, this.onTileRendered.bind(this));
  25738. images360.panoRenderer.addEventListener(PanoRendererEvents.PanoRenderComplete, this.onPanoRendered.bind(this));
  25739. images360.panoRenderer.addEventListener(PanoRendererEvents.TileRenderFailure, this.onTileRenderFail.bind(this));
  25740. images360.panoRenderer.addEventListener(PanoRendererEvents.UploadAttemptedForAllTiles, this.onUploadAttemptedForAllTiles.bind(this));
  25741. }
  25742. this.addEventListener('hoverOn', e => {
  25743. //from Map
  25744. if (!e.byMainView) {
  25745. this.hoverOn(e);
  25746. }
  25747. });
  25748. this.addEventListener('hoverOff', e => {
  25749. if (!e.byMainView) {
  25750. this.hoverOff(e);
  25751. }
  25752. });
  25753. }
  25754. get noNeighbour() {
  25755. //是否绝对到不到的孤立点
  25756. for (var i = 0, j = this.images360.panos.length; i < j; i++) {
  25757. if (this.images360.neighbourMap[this.id][i] !== false) {
  25758. return false;
  25759. }
  25760. }
  25761. return true;
  25762. //return this.neighbours.length == 0
  25763. }
  25764. setEnable(enable) {
  25765. //是否可以走
  25766. Potree.Utils.updateVisible(this, 'isEnabled', enable); //令所有marker不可见
  25767. this.enabled = enable;
  25768. //如果当前在全景模式且在这个点,需要切换显示吗? 目前用不到
  25769. }
  25770. loadDepthImg() {
  25771. if (!this.pointcloud.hasDepthTex || this.depthTex || this.depthTexLoading) return;
  25772. this.depthTexLoading = true;
  25773. var mapping = Potree.settings.isLocal2 ? '' : this.pointcloud.datasetData.mapping; //非离线包的话加mapping
  25774. var src = "".concat(Potree.settings.urls.prefix1, "/").concat(mapping ? mapping + '/' : '').concat(Potree.settings.webSite, "/").concat(this.pointcloud.sceneCode, "/data/").concat(this.pointcloud.sceneCode, "/depthmap/").concat(this.originID, ".png");
  25775. // `${Potree.settings.urls.prefix1}/${Potree.settings.webSite}/${this.pointcloud.sceneCode}/data/${this.pointcloud.sceneCode}/depthmap/${this.originID}.png`
  25776. //console.log('开始下载depthImg', this.id)
  25777. var texture = texLoader$3.load(src, () => {
  25778. this.depthTex = texture;
  25779. this.dispatchEvent({
  25780. type: 'loadedDepthImg',
  25781. loaded: true
  25782. });
  25783. this.images360.dispatchEvent({
  25784. type: 'loadedDepthImg',
  25785. pano: this
  25786. });
  25787. this.depthTexLoading = false;
  25788. this.images360.updateDepthTex(this);
  25789. }, null, e => {
  25790. //error
  25791. console.error('loadDepthImg失败, 数据集sceneCode' + this.pointcloud.sceneCode, this.id);
  25792. this.pointcloud.hasDepthTex = false;
  25793. this.dispatchEvent({
  25794. type: 'loadedDepthImg'
  25795. });
  25796. });
  25797. texture.wrapS = RepeatWrapping;
  25798. texture.flipY = false;
  25799. texture.magFilter = LinearFilter;
  25800. texture.minFilter = LinearFilter;
  25801. texture.generateMipmaps = false;
  25802. }
  25803. build() {
  25804. {
  25805. // orientation
  25806. //add
  25807. //var quaternion = new THREE.Quaternion().multiplyQuaternions(this.quaternion, rot901);//改 为球目全
  25808. //quaternion.premultiply(rot90)
  25809. this.panoMatrix = new Matrix4().makeRotationFromQuaternion(this.quaternion);
  25810. this.oriPanoMatrix = this.panoMatrix.clone();
  25811. if (this.quaternion2) this.oriPanoMatrix2 = new Matrix4().makeRotationFromQuaternion(this.quaternion2);
  25812. //console.log(this.quaternion)
  25813. //this.quaternion = quaternion
  25814. }
  25815. /* let marker = new THREE.Mesh(planeGeo, this.getMarkerMat() )
  25816. //marker.lookAt(marker.up)
  25817. marker.scale.set(2,2,2) */
  25818. var marker = new Mesh(planeGeo, this.getMarkerMat()); //new Sprite({mat:this.getMarkerMat(), dontFixOrient:true })
  25819. marker.scale.set(2, 2, 2); //marker.scale.set(0.4,0.4,0.4)
  25820. marker.name = 'marker_' + this.id;
  25821. marker.up.set(0, 0, 1);
  25822. this.addEventListener('changeMarkerTex', e => {
  25823. marker.material.map = markerTex[e.name];
  25824. });
  25825. this.marker = marker;
  25826. marker.pano = this;
  25827. this.images360.node.add(marker);
  25828. Potree.settings.isTest && this.addLabel();
  25829. //this.addLabel2()
  25830. marker.addEventListener('mouseover', this.hoverOn.bind(this));
  25831. marker.addEventListener('mouseleave', this.hoverOff.bind(this));
  25832. }
  25833. transformByPointcloud() {
  25834. var position = this.originPosition.clone().applyMatrix4(this.pointcloud.transformMatrix); //也可以用datasetPosTransform算
  25835. var floorPosition = this.originFloorPosition.clone().applyMatrix4(this.pointcloud.transformMatrix);
  25836. this.setPosition(position, floorPosition);
  25837. this.panoMatrix = new Matrix4().multiplyMatrices(this.pointcloud.rotateMatrix, this.oriPanoMatrix);
  25838. //this.panoMatrix2 = Potree.Utils.datasetRotTransform({fromDataset:true, pointcloud:this.pointcloud, matrix:this.oriPanoMatrix, getMatrix:true}) //和上一行结果一样
  25839. //quaternion也变下
  25840. if (this.oriPanoMatrix2) {
  25841. this.panoMatrix2 = new Matrix4().multiplyMatrices(this.pointcloud.rotateMatrix, this.oriPanoMatrix2); //供DepthImageSampler使用
  25842. this.panoMatrix2Inverse = this.panoMatrix2.clone().invert();
  25843. }
  25844. this.dispatchEvent('rePos');
  25845. }
  25846. setPosition(position, floorPosition) {
  25847. this.position = position;
  25848. this.floorPosition = floorPosition;
  25849. //this.mesh.position.copy(this.position)
  25850. this.marker.position.copy(this.floorPosition);
  25851. this.marker.position.z += 0.04; //会被点云遮住
  25852. if (this.label) {
  25853. if (Potree.settings.editType == 'pano') {
  25854. this.label.position.copy(this.position);
  25855. } else {
  25856. this.label.position.copy(this.floorPosition);
  25857. }
  25858. this.label.position.z += 0.14;
  25859. this.label.update();
  25860. }
  25861. /* if(this.label2){
  25862. if(Potree.settings.editType == 'pano'){
  25863. this.label2.position.copy(this.position)
  25864. }else{
  25865. this.label2.position.copy(this.floorPosition)
  25866. }
  25867. this.label2.position.copy(this.marker.position)
  25868. this.label2.update()
  25869. } */
  25870. }
  25871. /* getRealPos(){//当整体移动以后
  25872. return this.position.clone().applyMatrix4(viewer.scene.scene.matrix)
  25873. } */
  25874. getMarkerMat() {
  25875. if (!markerTex) {
  25876. markerTex = {
  25877. default: texLoader$3.load(Potree.resourcePath + '/textures/marker.png'),
  25878. ring: texLoader$3.load(Potree.resourcePath + '/textures/marker2.png')
  25879. };
  25880. markerTex.default.anisotropy = 4; // 各向异性过滤 .防止倾斜模糊
  25881. markerTex.ring.anisotropy = 4;
  25882. //有可能被点云遮住吗。
  25883. }
  25884. var mat = new DepthBasicMaterial({
  25885. opacity: markerOpacitys.default,
  25886. side: DoubleSide,
  25887. map: markerTex.default,
  25888. transparent: true,
  25889. clipDistance: 2,
  25890. occlusionDistance: 1,
  25891. //不能设置太短,因为过渡时深度不准确
  25892. useDepth: !!(Potree.settings.useDepthTex && this.pointcloud.hasDepthTex || Potree.settings.modelSkybox && this.pointcloud.is4dkkModel),
  25893. autoDepthTest: true
  25894. //改为DepthBasicMaterial是因为原Basic的材质在有深度图时过渡会先隐藏后出现。 注:没有深度图时全景模式的marker无法遮挡
  25895. });
  25896. mat.mapTransparent = true;
  25897. return mat;
  25898. }
  25899. hoverOn() {
  25900. var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  25901. //console.log("hoverOn " + this.id )
  25902. transitions.start(lerp.property(this.marker.material, "opacity", markerOpacitys.hovered, () => {
  25903. viewer.dispatchEvent('content_changed');
  25904. }), this.marker.visible ? 250 : 0);
  25905. if (!e.byMap) this.dispatchEvent({
  25906. type: 'hoverOn',
  25907. byMainView: true
  25908. });
  25909. if (!e.byImages360) this.images360.dispatchEvent({
  25910. type: 'markerHover',
  25911. hovered: true,
  25912. pano: this
  25913. });
  25914. }
  25915. hoverOff() {
  25916. var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  25917. //console.log("hoverOff " + this.id )
  25918. transitions.start(lerp.property(this.marker.material, "opacity", markerOpacitys.default, () => {
  25919. viewer.dispatchEvent('content_changed');
  25920. }), this.marker.visible ? 250 : 0);
  25921. if (!e.byMap) this.dispatchEvent({
  25922. type: 'hoverOff',
  25923. byMainView: true
  25924. });
  25925. if (!e.byImages360) this.images360.dispatchEvent({
  25926. type: 'markerHover',
  25927. hovered: false,
  25928. pano: this
  25929. });
  25930. }
  25931. setZoomed(zoomed) {
  25932. this.zoomed = zoomed;
  25933. Potree.settings.displayMode == 'showPanos' && this.updateSkyboxForZoomLevel(); //放大后换成zoomTarget贴图
  25934. viewer.dispatchEvent({
  25935. type: 'panoSetZoom',
  25936. zoomed
  25937. });
  25938. }
  25939. enter() {
  25940. this.entered = true;
  25941. this.setZoomed(!1);
  25942. viewer.dispatchEvent({
  25943. type: PanoramaEvents.Enter,
  25944. oldPano: old,
  25945. newPano: this
  25946. });
  25947. old = this;
  25948. //console.log("enter pano "+ this.id)
  25949. }
  25950. exit() {
  25951. this.clearWaitDeferreds();
  25952. this.minimumTiledPanoLoaded = !1;
  25953. this.tiledPanoRenderTarget = null;
  25954. this.setZoomed(!1);
  25955. this.images360.panoRenderer.deactivateTiledPano(this);
  25956. this.highestPartialTileRenderOpCompleted = 0;
  25957. this.highestFullTileRenderOpCompleted = 0;
  25958. this.depthTex && this.depthTex.dispose(); //贴图不使用后先dispose,下次到该点时会自动还原
  25959. this.entered = false; //add
  25960. //console.log("exit pano "+ this.id)
  25961. viewer.dispatchEvent({
  25962. type: PanoramaEvents.Exit,
  25963. pano: this
  25964. });
  25965. }
  25966. updateSkyboxForZoomLevel() {
  25967. if (this.minimumTiledPanoLoaded) {
  25968. this.images360.updateProjectedPanos();
  25969. }
  25970. }
  25971. getSkyboxTexture() {
  25972. if (this.minimumTiledPanoLoaded) {
  25973. if (this.zoomed && this.images360.qualityManager.maxRenderTargetSize > this.images360.qualityManager.maxNavPanoSize)
  25974. //change 如果放大后和不放大都是2k就不用这个
  25975. {
  25976. return this.images360.panoRenderer.zoomRenderTarget.texture;
  25977. } else {
  25978. this.tiledPanoRenderTarget.texture.mapping = UVMapping; //add
  25979. return this.tiledPanoRenderTarget.texture;
  25980. }
  25981. } else {
  25982. return null;
  25983. }
  25984. }
  25985. isLoaded(e) {
  25986. if (e && "string" == typeof e) console.error("Wrong panoSize given to Panorama.isLoaded(); a tiled pano uses PanoSizeClass");
  25987. return !!this.minimumTiledPanoLoaded && (!e || this.highestFullTileRenderOpCompleted >= e); //改:原本是:this.highestPartialTileRenderOpCompleted >= e, 希望这代表全部加载完
  25988. }
  25989. getWaitDeferred(size) {
  25990. //获取不同size的tile贴图的promiss
  25991. var t = this.resolutionPromise[this.id];
  25992. t || (t = {}, this.resolutionPromise[this.id] = t);
  25993. var i = t[size];
  25994. return i || (i = {
  25995. deferred: $.Deferred(),
  25996. active: !1
  25997. }, t[size] = i), i;
  25998. }
  25999. clearWaitDeferreds() {
  26000. var e = this.resolutionPromise[this.id];
  26001. e || (e = {}, this.resolutionPromise[this.id] = e);
  26002. for (var t in e) if (e.hasOwnProperty(t)) {
  26003. var i = e[t];
  26004. i.active = !1, i.deferred = $.Deferred();
  26005. }
  26006. }
  26007. resetWaitDeferred(e) {
  26008. var t = this.getWaitDeferred(e);
  26009. t.active = !1;
  26010. t.deferred = $.Deferred();
  26011. }
  26012. onTileRendered(ev) {
  26013. ev.id === this.id && this.dispatchEvent({
  26014. type: PanoramaEvents.TileLoaded,
  26015. size: ev.panoSize,
  26016. index: ev.tileIndex,
  26017. count: ev.totalTiles
  26018. });
  26019. }
  26020. onPanoRendered(ev) {
  26021. if (ev.id === this.id) {
  26022. this.minimumTiledPanoLoaded = !0;
  26023. this.updateSkyboxForZoomLevel(); //更新贴图 setProjected
  26024. ev.panoSize > this.highestPartialTileRenderOpCompleted && (this.highestPartialTileRenderOpCompleted = ev.panoSize); //应该是更新最高获取到的Partial size
  26025. ev.updateFullComplete && ev.panoSize > this.highestFullTileRenderOpCompleted && (this.highestFullTileRenderOpCompleted = ev.panoSize); //应该是更新最高获取到的Full size
  26026. //this.dispatchEvent("load", ev.panoSize);
  26027. viewer.ifAllLoaded(this);
  26028. this.dispatchEvent({
  26029. type: PanoramaEvents.LoadComplete,
  26030. size: ev.panoSize,
  26031. count: ev.totalTiles
  26032. });
  26033. }
  26034. }
  26035. onTileRenderFail(ev) {
  26036. ev.id === this.id && this.dispatchEvent({
  26037. type: PanoramaEvents.LoadFailed
  26038. });
  26039. }
  26040. onUploadAttemptedForAllTiles(ev) {
  26041. if (ev.id === this.id) {
  26042. var n = this.images360.qualityManager.getPanoSize(PanoSizeClass.BASE);
  26043. if (ev.panoSize === n && this.shouldRedrawOnBaseLoaded)
  26044. //shouldRedrawOnBaseLoaded一直是false。在4dkk里只有初始点在quickstart后变为true。
  26045. {
  26046. this.shouldRedrawOnBaseLoaded = !1;
  26047. this.panoRenderer.resetRenderStatus(this.id, !0, !1);
  26048. this.panoRenderer.renderPanoTiles(this.id, null, !0, !0);
  26049. }
  26050. }
  26051. }
  26052. addLabel() {
  26053. this.removeTextLabel();
  26054. this.label = new TextSprite$2(Object.assign({}, labelProp, {
  26055. text: this.id + "(" + this.originID + ")"
  26056. }) //{text: `id:${this.id}, dataset:${this.pointcloud.name}, 4dkkId:${this.originID}`}
  26057. );
  26058. this.images360.node.add(this.label);
  26059. this.floorPosition && this.label.position.copy(this.floorPosition);
  26060. }
  26061. addLabel2() {
  26062. if (this.label2) return;
  26063. this.label2 = new TextSprite$2(Object.assign({}, labelProp2, {
  26064. text: /* this.originID */parseInt(this.id) + 1
  26065. }) //{text: `id:${this.id}, dataset:${this.pointcloud.name}, 4dkkId:${this.originID}`}
  26066. );
  26067. //this.images360.node.add(this.label2);
  26068. this.marker.add(this.label2);
  26069. //this.floorPosition && this.label2.position.copy(this.floorPosition)
  26070. var s = 0.2;
  26071. this.label2.scale.set(s, s, s);
  26072. Potree.Utils.updateVisible(this.label2, 'notDisplay', false);
  26073. Potree.Utils.updateVisible(this.label2, 'panoVisi', this.visible);
  26074. //Potree.Utils.setObjectLayers(this.label2, 'bothMapAndScene')
  26075. }
  26076. removeTextLabel() {
  26077. if (this.label) {
  26078. this.label.parent.remove(this.label);
  26079. }
  26080. }
  26081. dispose() {
  26082. var i = viewer.images360.panos.indexOf(this);
  26083. if (i == -1) return;
  26084. this.marker.parent.remove(this.marker);
  26085. this.removeTextLabel();
  26086. if (this.depthTex) this.depthTex.dispose();
  26087. viewer.images360.panos.splice(i, 1);
  26088. this.dispatchEvent('dispose');
  26089. //删除tile贴图、depthTex等以后再写
  26090. }
  26091. getCeilHeight() {
  26092. //天花板高度值 (假设不存在depth为0的点,所有为0的要么是在盲区,要么是无穷远。)
  26093. if (this.ceilZ == void 0) {
  26094. //const depthTiming = Potree.timeCollect.depthSampler.median //pc firefox达到4. chrome为0.01
  26095. //用三个间隔120度散开,和中心垂直线成一定夹角的三个向量去求 最高高度 (不求平均的原因:万一是0不好算)
  26096. var rotMat = new Matrix4().makeRotationX((Potree.config.depthTexUVyLimit + 0.01) * Math.PI); // 角度不能小于天花板中空的半径
  26097. var dir0 = new Vector3(0, 0, 1).applyMatrix4(rotMat);
  26098. var dirs = [dir0, dir0.clone().applyMatrix4(new Matrix4().makeRotationZ(Math.PI * 2 / 3)), dir0.clone().applyMatrix4(new Matrix4().makeRotationZ(-Math.PI * 2 / 3))];
  26099. /* if(depthTiming < 1){
  26100. let rotMat1 = new THREE.Matrix4().makeRotationZ(Math.PI*2 / 3);
  26101. dirs.push(dirs[0].clone().applyMatrix4(rotMat1))
  26102. }
  26103. if(depthTiming < 0.3){
  26104. let rotMat2 = new THREE.Matrix4().makeRotationZ(-Math.PI*2 / 3);
  26105. dirs.push(dirs[0].clone().applyMatrix4(rotMat2));
  26106. } */
  26107. var zs = dirs.map(dir_ => {
  26108. var dir = dir_.clone().applyMatrix4(this.panoMatrix2); //pano不一定是垂直的, 需要把之前的dirInPano先转成真实的dir,防止超出角度限制
  26109. var intersect = viewer.images360.getIntersect(this, dir);
  26110. var z = intersect ? intersect.location.z : Infinity; /* this.position.z+skyHeight */ //没有intersect代表可能是天空
  26111. return z;
  26112. });
  26113. zs.sort((a, b) => {
  26114. return b - a;
  26115. }); //得最大值 (不用中位数的原因:在屋檐处,如果仅有一个intersect是天空,因到了室外所以也用天空高度)
  26116. this.ceilZ = zs[0];
  26117. var min = this.position.z + 1; // 防止意外太低
  26118. this.ceilZ = Math.max(min, this.ceilZ);
  26119. //console.log(this.id, 'ceilZ:', this.ceilZ )
  26120. }
  26121. return this.ceilZ;
  26122. }
  26123. }
  26124. ;
  26125. Panorama.prototype.loadTiledPano = function () {
  26126. //var downloads = [] , t = [];
  26127. var downloaded = {},
  26128. eventAdded = {},
  26129. latestPartialRequest = {}; //每个pano对应一组这些
  26130. return function (size, dirs, fov, o, a, download) {
  26131. var dir = dirs.datasetsLocal.find(e => e.datasetId == this.pointcloud.dataset_id).direction;
  26132. //var dir = dirs
  26133. null !== o && void 0 !== o || (o = !0), null !== a && void 0 !== a || (a = !0);
  26134. var l = this.getWaitDeferred(size),
  26135. c = l.deferred,
  26136. h = null,
  26137. u = null;
  26138. fov && ("number" == typeof fov ? h = fov : (h = fov.hFov, u = fov.vFov));
  26139. if (!this.isLoaded(size)) {
  26140. //console.log('loadTiledPano', this.id, size, fov)
  26141. if (!l.active) {
  26142. l.active = !0;
  26143. var name = this.id + ":" + size;
  26144. downloaded[name] = downloaded[name] || [];
  26145. /*
  26146. this.downloaded = downloaded
  26147. this.latestPartialRequest = latestPartialRequest
  26148. */
  26149. latestPartialRequest[name] = null;
  26150. if (fov) {
  26151. var tileArr = []; //add
  26152. var d = TileUtils.matchingTilesInDirection(this, size, dir, h, u, tileArr);
  26153. latestPartialRequest[name] = tileArr;
  26154. downloaded[name].forEach(e => {
  26155. var item = latestPartialRequest[name].find(a => e.faceTileIndex == a.faceTileIndex && e.face == a.face);
  26156. if (item) {
  26157. item.loaded = true;
  26158. }
  26159. });
  26160. if (!latestPartialRequest[name].some(e => !e.loaded)) {
  26161. //所需要的全部加载成功
  26162. //let total = TileUtils.getTileCountForSize(size)
  26163. //this.onPanoRendered(this.id, size, total, !0);
  26164. c.resolve(size /* , total */);
  26165. this.resetWaitDeferred(size);
  26166. //console.log('该部分早已经加载好了'+size, this.id)
  26167. latestPartialRequest[name] = null;
  26168. }
  26169. //console.log("Loading partial pano: " + this.id + " with " + d + " tiles")
  26170. }
  26171. if (!eventAdded[this.id]) {
  26172. eventAdded[this.id] = !0;
  26173. this.addEventListener(PanoramaEvents.LoadComplete, function (ev /* e, t */) {
  26174. //本次任务全部加载完毕
  26175. //console.warn('点位(可能部分)下载完成 ', 'id:'+this.id, 'size:'+ev.size )
  26176. var i = this.getWaitDeferred(ev.size).deferred; //"pending"为还未完成
  26177. i && "pending" === i.state() && this.highestPartialTileRenderOpCompleted >= ev.size && (i.resolve(ev.size, ev.count), this.resetWaitDeferred(ev.size)); //恢复active为false
  26178. }.bind(this));
  26179. this.addEventListener(PanoramaEvents.LoadFailed, function (ev) {
  26180. var t = this.getWaitDeferred(e).deferred;
  26181. t && "pending" === t.state() && this.highestPartialTileRenderOpCompleted >= ev.t && (t.reject(ev.t), this.resetWaitDeferred(ev.t)); //恢复active为false
  26182. }.bind(this));
  26183. this.addEventListener(PanoramaEvents.TileLoaded, function (ev /* t, i, n */) {
  26184. //每张加载完时
  26185. //console.log('tileLoaded', 'id:'+this.id, 'size:'+ev.size, 'tileIndex:'+ev.index )
  26186. var tileIndex = ev.index;
  26187. var total = ev.count;
  26188. var size = ev.size;
  26189. var name = this.id + ":" + size;
  26190. downloaded[name] = downloaded[name] || []; //不是所有的加载都是从loadTiledPano获取的所以会有未定义的情况
  26191. var {
  26192. faceTileIndex,
  26193. face
  26194. } = TileUtils.getTileLocation(size, tileIndex, {});
  26195. downloaded[name].push({
  26196. faceTileIndex,
  26197. face
  26198. });
  26199. var r = this.getWaitDeferred(size).deferred;
  26200. if (r && "pending" === r.state()) {
  26201. r.notify(size, tileIndex, total);
  26202. if (latestPartialRequest[name]) {
  26203. var item = latestPartialRequest[name].find(e => e.faceTileIndex == faceTileIndex && e.face == face);
  26204. item && (item.loaded = true);
  26205. if (!latestPartialRequest[name].some(e => !e.loaded)) {
  26206. //所需要的局部tiles全部加载成功
  26207. this.onPanoRendered(this.id, size, total, !0); //onPanoRendered还会触发 PanoramaEvents.LoadComplete
  26208. r.resolve(size, total);
  26209. this.resetWaitDeferred(size);
  26210. //console.log('该部分加载好了'+size, this.id)
  26211. latestPartialRequest[name] = null;
  26212. }
  26213. }
  26214. }
  26215. viewer.dispatchEvent('content_changed');
  26216. /* var r = this.getWaitDeferred(ev.size).deferred;
  26217. if (r && "pending" === r.state()) {
  26218. r.notify(ev.size, ev.index, ev.count);
  26219. var o = downloads[this.id + ":" + ev.size];
  26220. if(o){//如果有规定下载哪些tile,只需要下载这些tile则LoadComplete
  26221. o.tileCount++
  26222. if(o.tileCount === o.targetTileCount){//达到下载目标数
  26223. this.onPanoRendered(this.id, ev.size, ev.count, !0);
  26224. r.resolve(ev.size, ev.count);
  26225. this.resetWaitDeferred(ev.size)
  26226. }
  26227. }
  26228. } */
  26229. }.bind(this));
  26230. }
  26231. }
  26232. this.images360.tileDownloader.clearForceQueue();
  26233. this.images360.tileDownloader.forceQueueTilesForPano(this, size, dir, h, u, download);
  26234. this.tiledPanoRenderTarget = this.images360.panoRenderer.activateTiledPano(this, this.images360.qualityManager.getMaxNavPanoSize(), o);
  26235. this.images360.panoRenderer.renderPanoTiles(this.id, dirs, a);
  26236. } else {
  26237. //console.log('早已经全加载好了' +size, this.id)
  26238. c.resolve(size);
  26239. }
  26240. return c.promise();
  26241. };
  26242. }();
  26243. var {
  26244. ModelManagerEvents,
  26245. PanoSizeClass: PanoSizeClass$1
  26246. } = Potree.defines;
  26247. class QualityManager {
  26248. constructor(e, t, i) {
  26249. this.maxNavPanoSize = -1;
  26250. this.maxZoomPanoSize = -1;
  26251. this.devicePixelDensity = e;
  26252. this.deviceScreenSize = t;
  26253. this.clientBandwidth = i;
  26254. this.panoSizeClassMap = {};
  26255. this.useHighResolutionPanos = !0; //是否能够使用2k及以上图
  26256. this.useUltraHighResolutionPanos = !1;
  26257. this.modelHasUltraHighPanos = !1;
  26258. this.qualityManager = this;
  26259. this.maxRenderTargetSize = browser.isMobile() ? 2048 : 4096; //add
  26260. this.init();
  26261. }
  26262. init(e) {
  26263. //var metadata = store.getters['scene/metadata'] ;//有时候请求不到
  26264. //if(metadata.sceneSource == 11 || metadata.sceneScheme == 12){
  26265. /* if(config.tileClass == '1k'){
  26266. this.useHighResolutionPanos = false //xzw add 只加载1k
  26267. } */
  26268. this.buildPanoSizeClassMap(this.devicePixelDensity, this.deviceScreenSize, this.clientBandwidth);
  26269. this.ultraHighSize = this.getPanoSize(PanoSizeClass$1.ULTRAHIGH);
  26270. this.highSize = this.getPanoSize(PanoSizeClass$1.HIGH);
  26271. this.standardSize = this.getPanoSize(PanoSizeClass$1.STANDARD);
  26272. this.baseSize = this.getPanoSize(PanoSizeClass$1.BASE);
  26273. config$1.tiling.maxZoomPanoQuality && this.ultraHighSize <= config$1.tiling.maxZoomPanoQuality && (config$1.tiling.allowUltraHighResolution = !0);
  26274. this.highQualityThreshold = browser.valueFromHash("threshold2k", config$1.windowHeightHighQualityThreshold);
  26275. this.updateMaximums();
  26276. //e.on(ModelManagerEvents.ActiveModelChanged, this.onModelChanged.bind(this));
  26277. }
  26278. updateFromModel(e) {
  26279. //this.updateHighResolutionSettings(e)
  26280. this.updateUltraHighResolutionSettings(e);
  26281. }
  26282. /* updateHighResolutionSettings(e) {
  26283. this.useHighResolutionPanos = !0
  26284. this.updateMaximums()
  26285. } */
  26286. updateUltraHighResolutionSettings(e) {
  26287. if (config$1.tiling.allowUltraHighResolution && this.modelHasUltraHighPanos) {
  26288. this.useUltraHighResolutionPanos = !0;
  26289. } else {
  26290. this.useUltraHighResolutionPanos = !1;
  26291. }
  26292. this.updateMaximums();
  26293. }
  26294. enableUltraHighQualityMode() {
  26295. this.modelHasUltraHighPanos = !0;
  26296. this.updateUltraHighResolutionSettings(null);
  26297. }
  26298. ultraHighQualityModeEnabled() {
  26299. return this.modelHasUltraHighPanos;
  26300. }
  26301. onModelChanged(e) {
  26302. this.updateFromModel(e.model), this.updateMaximums();
  26303. }
  26304. updateMaximums() {
  26305. this.maxNavPanoSize = config$1.tiling.maxNavPanoQuality || this.detectMaxNavPanoSize(), this.maxZoomPanoSize = config$1.tiling.maxZoomPanoQuality || this.detectMaxZoomPanoSize(), this.maxZoomPanoSize < this.maxNavPanoSize && (this.maxNavPanoSize = this.maxZoomPanoSize);
  26306. }
  26307. buildPanoSizeClassMap() {
  26308. this.panoSizeClassMap[PanoSizeClass$1.BASE] = 512, this.panoSizeClassMap[PanoSizeClass$1.STANDARD] = 1024, this.panoSizeClassMap[PanoSizeClass$1.HIGH] = 2048, this.panoSizeClassMap[PanoSizeClass$1.ULTRAHIGH] = 4096;
  26309. }
  26310. getPanoSize(e) {
  26311. return this.panoSizeClassMap[e];
  26312. }
  26313. getMaxPossiblePanoSize() {
  26314. return this.getPanoSize(PanoSizeClass$1.ULTRAHIGH);
  26315. }
  26316. getMaxPanoSize() {
  26317. return this.maxZoomPanoSize;
  26318. }
  26319. getMaxNavPanoSize() {
  26320. return this.maxNavPanoSize;
  26321. }
  26322. getMaxZoomPanoSize() {
  26323. return this.maxZoomPanoSize;
  26324. }
  26325. detectMaxNavPanoSizeClass() {
  26326. //return this.useHighResolutionPanos ? browser.isMobile() ? PanoSizeClass.STANDARD : window.innerHeight < this.highQualityThreshold ? PanoSizeClass.STANDARD : PanoSizeClass.HIGH : PanoSizeClass.STANDARD
  26327. /* if(config.name == 'decor'){
  26328. return PanoSizeClass.STANDARD
  26329. }
  26330. return PanoSizeClass.HIGH */
  26331. switch (Potree.settings.navTileClass) {
  26332. case '1k':
  26333. return PanoSizeClass$1.STANDARD;
  26334. break;
  26335. case '2k':
  26336. default:
  26337. return PanoSizeClass$1.HIGH;
  26338. }
  26339. }
  26340. detectMaxNavPanoSize() {
  26341. var e = this.detectMaxNavPanoSizeClass();
  26342. return this.getPanoSize(e);
  26343. }
  26344. detectMaxZoomPanoSize() {
  26345. //获取当前zoomRenderTarget应下载的最高级别
  26346. //若是有三个级别,每次只需要加载到当前的zoomLevel;而两级时因为有zoomed来判断是使用基本贴图还是zoomRenderTarget,所以只需要返回最大的即可
  26347. if (this.zoomLevelResolution) {
  26348. //有三个级别
  26349. if (this.zoomLevelResolution == '4k' && this.useUltraHighResolutionPanos) {
  26350. return this.getPanoSize(PanoSizeClass$1.ULTRAHIGH);
  26351. } else if (this.zoomLevelResolution == '1k' || !this.useHighResolutionPanos) {
  26352. return this.getPanoSize(PanoSizeClass$1.STANDARD);
  26353. } else {
  26354. return this.getPanoSize(PanoSizeClass$1.HIGH);
  26355. }
  26356. } else {
  26357. if (this.useHighResolutionPanos) {
  26358. /* if (browser.isMobile()) {//手机版如果要2k的将这里去掉
  26359. if (settings.tiling.mobileHighQualityOverride) {
  26360. return this.getPanoSize(PanoSizeClass.HIGH);
  26361. } else {
  26362. return this.getPanoSize(PanoSizeClass.STANDARD);
  26363. }
  26364. } else */
  26365. if (this.useUltraHighResolutionPanos) {
  26366. return this.getPanoSize(PanoSizeClass$1.ULTRAHIGH);
  26367. } else {
  26368. return this.getPanoSize(PanoSizeClass$1.HIGH);
  26369. }
  26370. } else {
  26371. return this.getPanoSize(PanoSizeClass$1.STANDARD);
  26372. }
  26373. }
  26374. }
  26375. }
  26376. var {
  26377. DownloadStatus
  26378. } = Potree.defines;
  26379. var h = Object.freeze({
  26380. None: 0,
  26381. DirectionalFOV: 1
  26382. });
  26383. var u = function () {
  26384. var e = function e(t, i) {
  26385. var n = e._panoSpaceDir,
  26386. r = e._fovThreshold,
  26387. o = e._fovThresholdNarrow,
  26388. a = Math.max(Math.min(n.dot(t.direction), 1), -1),
  26389. s = Math.max(Math.min(n.dot(i.direction), 1), -1);
  26390. return t._dot = a, i._dot = s, a >= r && s < r ? -1 : a < r && s >= r ? 1 : a >= o && s < o ? -1 : a < o && s >= o ? 1 : t.panoSize > i.panoSize ? 1 : i.panoSize > t.panoSize ? -1 : -(a - s);
  26391. };
  26392. return e._panoSpaceDir = new Vector3(), e._fovThreshold = -1, e._fovThresholdNarrow = -1, e;
  26393. }();
  26394. class TilePrioritizer {
  26395. //优先级处理序列
  26396. constructor(e, t, i, o, a) {
  26397. this.qualityManager = e;
  26398. this.maxNavQuality = this.qualityManager.getMaxNavPanoSize();
  26399. this.maxZoomQuality = this.qualityManager.getMaxZoomPanoSize();
  26400. this.baseSize = t;
  26401. this.standardSize = i;
  26402. this.highSize = o;
  26403. this.ultraHighSize = a;
  26404. this.priorityCriteria = new TilePrioritizer.PriorityCriteria(null, new Vector3(0, 0, 0), new Vector3(0, 0, -1), new Vector3(0, 0, -1));
  26405. }
  26406. updateCriteria(e, t, i, n) {
  26407. //由player更新
  26408. this.priorityCriteria.pano = e, this.priorityCriteria.cameraPosition.copy(t),
  26409. //this.priorityCriteria.cameraDir.copy(i),
  26410. this.priorityCriteria.cameraDirs = i;
  26411. this.priorityCriteria.upcomingPanos = n, this.maxNavQuality = this.qualityManager.getMaxNavPanoSize(), this.maxZoomQuality = this.qualityManager.getMaxZoomPanoSize();
  26412. }
  26413. canDownloadSize(e) {
  26414. return this.maxNavQuality >= e || this.maxZoomQuality >= e && this.zoomingActive;
  26415. }
  26416. /* populateNeighborPanos(e, t, i) {
  26417. i = i || [],
  26418. i.length = 0;
  26419. var n = t.getNeighbours(e);
  26420. for (var r in n)
  26421. if (n.hasOwnProperty(r)) {
  26422. var o = t.get(r);
  26423. if(!o){
  26424. console.log(1)
  26425. }
  26426. i.push(o)
  26427. }
  26428. return i
  26429. } */
  26430. populateScoredPanos(e, t, i, dirs, a, dontFilterDir) {
  26431. i = i || [], i.length = 0;
  26432. var s = [Images360.filters.not(e)],
  26433. l = [Images360.scoreFunctions.distanceSquared(e), Images360.scoreFunctions.direction(e.position, dirs)],
  26434. c = Common.sortByScore(t, s, l);
  26435. if (!dontFilterDir) {
  26436. s.push(Images360.filters.inPanoDirection(e.position, dirs, TilePrioritizer.DIRECTION_SCORE_STRICTNESS));
  26437. }
  26438. if (c) for (var h = 0; h < c.length && h < a; h++) {
  26439. var u = c[h].item;
  26440. i.push(u);
  26441. }
  26442. return i;
  26443. }
  26444. queueTilesForPanos(e, t, i, n, r) {
  26445. for (var o = 0, a = 0; a < t.length; a++) {
  26446. var s = t[a],
  26447. l = this.queueTilesForPano(e, i, s, n);
  26448. if (o += l > 0 ? 1 : 0, r && o >= r) break;
  26449. }
  26450. return o;
  26451. }
  26452. /* queueTilesInDirectionForPanos(e, t, i, n, r, o, a, s) {//没用到
  26453. for (var l = 0, c = 0; c < i.length; c++) {
  26454. var h = i[c],
  26455. u = this.queueTilesInDirectionForPano(e, t, h, n, o, a);
  26456. if (l += u > 0 ? 1 : 0,
  26457. s && l >= s)
  26458. break
  26459. }
  26460. return l
  26461. }
  26462. */
  26463. canIncludeDescriptor(e) {
  26464. return e.status !== DownloadStatus.Downloading && e.status !== DownloadStatus.Downloaded;
  26465. }
  26466. canIncludePano(e, t) {
  26467. return !e.isLoaded(t);
  26468. }
  26469. getFOVDotThreshold(e) {
  26470. return Math.cos(MathUtils.degToRad(e / 2));
  26471. }
  26472. setZoomingActive(e) {
  26473. e !== this.zoomingActive && (this.zoomingActive = e);
  26474. }
  26475. }
  26476. TilePrioritizer.PriorityCriteria = function (e, t, i, n, o) {
  26477. this.pano = e, this.cameraPosition = new Vector3().copy(t),
  26478. //this.cameraDir = (new THREE.Vector3).copy(i),
  26479. this.cameraDirs = [],
  26480. //
  26481. this.panoSpaceDir = new Vector3().copy(n), this.upcomingPanos = o, this.copy = function (e) {
  26482. this.pano = e.pano, this.cameraPosition.copy(e.cameraPosition),
  26483. //this.cameraDir.copy(e.cameraDir),
  26484. this.cameraDirs = e.cameraDirs;
  26485. this.panoSpaceDir.copy(e.panoSpaceDir), this.upcomingPanos = o;
  26486. }, this.zoomingActive = !1;
  26487. };
  26488. TilePrioritizer.DIRECTIONAL_FOV = 180;
  26489. TilePrioritizer.DIRECTIONAL_FOV_NARROW = 120;
  26490. TilePrioritizer.MAX_SCORED_PANOS_TOCONSIDER = 6;
  26491. TilePrioritizer.MAX_SCORED_PANOS_TOADD = 2;
  26492. TilePrioritizer.MAX_UPCOMING_PANOS_TOADD = 3;
  26493. TilePrioritizer.DIRECTION_SCORE_STRICTNESS = .75;
  26494. TilePrioritizer.appendQueue = function (e, t) {
  26495. if (e && t) for (var i = 0; i < t.length; i++) {
  26496. e.push(t[i]);
  26497. //console.log(t[i])
  26498. }
  26499. };
  26500. TilePrioritizer.sortPanoTiles = function (descriptors, pano, dir) {
  26501. if (dir.datasetsLocal) dir = dir.datasetsLocal.find(e => e.datasetId == pano.pointcloud.dataset_id).direction; //add
  26502. u._panoSpaceDir.copy(dir);
  26503. TileUtils.getRelativeDirection(pano.quaternion4dkk, u._panoSpaceDir); //应该是将dir根据quaternion转化下
  26504. u._fovThresholdNarrow = math.getFOVDotThreshold(TilePrioritizer.DIRECTIONAL_FOV_NARROW);
  26505. u._fovThreshold = math.getFOVDotThreshold(TilePrioritizer.DIRECTIONAL_FOV);
  26506. descriptors.sort(u);
  26507. };
  26508. TilePrioritizer.insertSortedPanoTile = function (e, t, pano, dir) {
  26509. if (dir.datasetsLocal) dir = dir.datasetsLocal.find(e => e.datasetId == pano.pointcloud.dataset_id).direction; //add
  26510. u._panoSpaceDir.copy(dir), TileUtils.getRelativeDirection(pano.quaternion4dkk, u._panoSpaceDir), u._fovThresholdNarrow = math.getFOVDotThreshold(TilePrioritizer.DIRECTIONAL_FOV_NARROW), u._fovThreshold = math.getFOVDotThreshold(TilePrioritizer.DIRECTIONAL_FOV);
  26511. for (var o = -1, a = 0; a < e.length; a++) {
  26512. var s = u(t, e[a]);
  26513. if (s <= 0) {
  26514. o = a;
  26515. break;
  26516. }
  26517. }
  26518. if (o === -1) e[e.length] = t;else {
  26519. for (var h = e.length; h > o; h--) e[h] = e[h - 1];
  26520. e[o] = t;
  26521. }
  26522. };
  26523. TilePrioritizer.prototype.filterDepthTex = function (panos) {
  26524. // 下载depthTex
  26525. if (!Potree.settings.useDepthTex || !this.priorityCriteria.pano || viewer.mainViewport.view.isFlying()) return;
  26526. var cameraDirLocals = this.priorityCriteria.cameraDirs.vectorForward;
  26527. var nearPanos = []; //用于获得邻近点位序列
  26528. this.populateScoredPanos(this.priorityCriteria.pano, panos, nearPanos, cameraDirLocals, Infinity, true);
  26529. var dlCount = browser.isMobile() ? 1 : 2;
  26530. var loadingCount = panos.filter(p => p.depthTexLoading).length;
  26531. if (viewer.mapViewer) {
  26532. var mapLayer = viewer.mapViewer.mapLayer;
  26533. loadingCount += mapLayer.loadingInProgress * 1.5 + mapLayer.waitQueue.length;
  26534. }
  26535. if (loadingCount < dlCount) {
  26536. nearPanos.filter(p => !p.depthTex).slice(0, dlCount - loadingCount).forEach(p => p.loadDepthImg());
  26537. }
  26538. this.nearPanos = nearPanos;
  26539. };
  26540. TilePrioritizer.prototype.filterAndPrioritize = function () {
  26541. //挑选出优先加载的 pano和tile (有点复杂,没看很懂)
  26542. var e = [],
  26543. t = [],
  26544. i = [];
  26545. return function (queue, panos, tileDownloader) {
  26546. //this.populateNeighborPanos(this.priorityCriteria.pano, panos, e);
  26547. /* let cameraDirLocals = this.priorityCriteria.cameraDirs.map(e=>{ //add
  26548. var dataset = viewer.scene.pointclouds.find(u=>u.dataset_id == e.datasetId)
  26549. var matrix = new THREE.Matrix4().copy(dataset.rotateMatrix)
  26550. var direction = math.convertVector.YupToZup(e.direction)
  26551. return {
  26552. datasetId:e.datasetId,
  26553. direction: direction.clone().applyMatrix4(matrix)
  26554. }
  26555. }) */
  26556. var cameraDirLocals = this.priorityCriteria.cameraDirs.vectorForward;
  26557. //获得视野范围内的邻近点位序列t
  26558. this.populateScoredPanos(this.priorityCriteria.pano, panos, t, cameraDirLocals, TilePrioritizer.MAX_SCORED_PANOS_TOCONSIDER);
  26559. //t.filter(p=>!p.depthTex).slice(0, Potree.config.depTexDlCount).forEach(p=>p.loadDepthImg()) //add
  26560. var s = this.baseSize //512
  26561. ,
  26562. l = this.standardSize //1024
  26563. ,
  26564. c = this.highSize //2048
  26565. ,
  26566. h = this.ultraHighSize; //4096
  26567. this.queueTilesForPano(queue, tileDownloader, this.priorityCriteria.pano, s); //把当前pano的512下载了
  26568. if (this.priorityCriteria.upcomingPanos) {
  26569. // 添加即将走到的点(之前用于导览路线)512 tiles
  26570. this.queueTilesForPanos(queue, this.priorityCriteria.upcomingPanos, tileDownloader, s, TilePrioritizer.MAX_UPCOMING_PANOS_TOADD);
  26571. }
  26572. i.length = 0;
  26573. //把当前pano角度范围内的tile按照分辨率从低到高加入队列
  26574. if (this.canDownloadSize(l)) {
  26575. //1024如果在限制范围内的话
  26576. this.queueTilesInDirectionForPano(i, tileDownloader, this.priorityCriteria.pano, l, this.priorityCriteria.cameraPosition, this.priorityCriteria.cameraDirs, TilePrioritizer.DIRECTIONAL_FOV_NARROW);
  26577. }
  26578. TilePrioritizer.sortPanoTiles(i, this.priorityCriteria.pano, this.priorityCriteria.cameraDirs); //排序
  26579. TilePrioritizer.appendQueue(queue, i);
  26580. //添加邻近点t 512的tiles
  26581. this.queueTilesForPanos(queue, t, tileDownloader, s, TilePrioritizer.MAX_SCORED_PANOS_TOADD);
  26582. i.length = 0;
  26583. //NARROW :
  26584. if (this.canDownloadSize(c)) {
  26585. //2048
  26586. this.queueTilesInDirectionForPano(i, tileDownloader, this.priorityCriteria.pano, c, this.priorityCriteria.cameraPosition, this.priorityCriteria.cameraDirs, TilePrioritizer.DIRECTIONAL_FOV_NARROW);
  26587. }
  26588. if (this.canDownloadSize(h)) {
  26589. //4096
  26590. this.queueTilesInDirectionForPano(i, tileDownloader, this.priorityCriteria.pano, h, this.priorityCriteria.cameraPosition, this.priorityCriteria.cameraDirs, TilePrioritizer.DIRECTIONAL_FOV_NARROW);
  26591. }
  26592. TilePrioritizer.sortPanoTiles(i, this.priorityCriteria.pano, this.priorityCriteria.cameraDirs); //排序
  26593. TilePrioritizer.appendQueue(queue, i);
  26594. i.length = 0;
  26595. if (this.canDownloadSize(l)) {
  26596. //1024
  26597. this.queueTilesInDirectionForPano(i, tileDownloader, this.priorityCriteria.pano, l, this.priorityCriteria.cameraPosition, this.priorityCriteria.cameraDirs, TilePrioritizer.DIRECTIONAL_FOV);
  26598. }
  26599. if (this.canDownloadSize(c)) {
  26600. //2048
  26601. this.queueTilesInDirectionForPano(i, tileDownloader, this.priorityCriteria.pano, c, this.priorityCriteria.cameraPosition, this.priorityCriteria.cameraDirs, TilePrioritizer.DIRECTIONAL_FOV);
  26602. }
  26603. if (this.canDownloadSize(h)) {
  26604. //4096
  26605. this.queueTilesInDirectionForPano(i, tileDownloader, this.priorityCriteria.pano, h, this.priorityCriteria.cameraPosition, this.priorityCriteria.cameraDirs, TilePrioritizer.DIRECTIONAL_FOV);
  26606. }
  26607. TilePrioritizer.sortPanoTiles(i, this.priorityCriteria.pano, this.priorityCriteria.cameraDirs); //排序
  26608. TilePrioritizer.appendQueue(queue, i);
  26609. this.queueTilesForPanos(queue, e, tileDownloader, s); // 如果前面有populateNeighborPanos的话,这步就是加neibour
  26610. };
  26611. }();
  26612. TilePrioritizer.prototype.queueTilesInDirectionForPano = function () {
  26613. var e = {
  26614. filter: h.DirectionalFOV,
  26615. direction: new Vector3(),
  26616. fov: 60
  26617. },
  26618. t = new Vector3();
  26619. return function (i, n, pano, o, a, dirs, c) {
  26620. var dir = dirs.datasetsLocal.find(e => e.datasetId == pano.pointcloud.dataset_id).direction; //add
  26621. //var dir = dirs
  26622. t.copy(dir);
  26623. TileUtils.getRelativeDirection(pano.quaternion4dkk, t);
  26624. e.direction.copy(t);
  26625. e.fov = c;
  26626. return this.filterAndQueueTileDownloadDescriptors(i, n, pano, o, e);
  26627. };
  26628. }();
  26629. TilePrioritizer.prototype.filterAndQueueTileDownloadDescriptors = function () {
  26630. var e = [];
  26631. return function (t, i, n, r, o) {
  26632. var a = i.getTileDownloadDescriptors(n, r);
  26633. e.length = 0, this.filterTileDownloadDescriptors(n, a, e, o);
  26634. for (var s = 0, l = 0; l < e.length; l++) {
  26635. var c = e[l];
  26636. if (c) {
  26637. t.push(c);
  26638. s++;
  26639. }
  26640. }
  26641. return s;
  26642. };
  26643. }();
  26644. TilePrioritizer.prototype.filterTileDownloadDescriptors = function () {
  26645. new Vector3();
  26646. return function (e, t, i, n) {
  26647. var r, o;
  26648. switch (n.filter) {
  26649. case h.DirectionalFOV:
  26650. for (r = 0; r < t.length; r++) o = t[r], TileUtils.isTileWithinFOV(o.panoSize, o.tileSize, o.face, o.tileX, o.tileY, n.direction, n.fov) && i.push(o);
  26651. break;
  26652. default:
  26653. for (r = 0; r < t.length; r++) o = t[r], i.push(o);
  26654. }
  26655. for (r = 0; r < i.length; r++) o = i[r], this.canIncludeDescriptor(o) || (i[r] = null);
  26656. };
  26657. }();
  26658. TilePrioritizer.prototype.queueTilesForPano = function () {
  26659. var e = {
  26660. filter: h.None
  26661. };
  26662. return function (t, i, n, r) {
  26663. return this.filterAndQueueTileDownloadDescriptors(t, i, n, r, e);
  26664. };
  26665. }();
  26666. /* TilePrioritizer.prototype.queueTilesForPanosInDirection = function () { //没用到
  26667. var e = new THREE.Vector3;
  26668. return function (t, i, n, r, o, a, s, l) {
  26669. for (var h = 0, u = 0; u < n.length; u++) {
  26670. var d = n[u];
  26671. e.copy(d.position),
  26672. e.sub(o),
  26673. e.normalize();
  26674. var p = Math.max(Math.min(a.dot(e), 1), -1),
  26675. f = c.getFOVDotThreshold(s);
  26676. if (p >= f) {
  26677. var g = this.queueTilesInDirectionForPano(t, i, d, r, o, a, s);
  26678. if (h += g > 0 ? 1 : 0,
  26679. l && h >= l)
  26680. break
  26681. }
  26682. }
  26683. return h
  26684. }
  26685. }() */
  26686. //import { i18n } from "@/lang/index"
  26687. // 媒体名称
  26688. /* export const mediaTypes = {
  26689. image: i18n.t("common.photo"),
  26690. video: i18n.t("common.video"),
  26691. audio: i18n.t("common.voice"),
  26692. } */
  26693. // 媒体扩展类型
  26694. var mediaMimes = {
  26695. image: ["jpg", "png", "jpeg", "bmp", "gif"],
  26696. audio: ["mp3", "aac", "ogg", "wav" /* , "m4a" */],
  26697. video: ["mp4", "mov", "quicktime", "webm" /* "rmvb", "wmv" */] //ios:mov
  26698. };
  26699. // 媒体大小显示(MB)
  26700. var mediaMaxSize = {
  26701. image: 10,
  26702. video: 20,
  26703. audio: 5
  26704. };
  26705. /**
  26706. * 获取媒体扩展类型
  26707. * @param {Stirng} filename 文件名称
  26708. */
  26709. var getMime = filename => {
  26710. if (!filename || filename.indexOf(".") === -1) {
  26711. return "";
  26712. }
  26713. return filename.split(".").pop().toLowerCase();
  26714. };
  26715. /**
  26716. * 在路径中获取文件名
  26717. * @param {*} path
  26718. */
  26719. var getFilename = path => {
  26720. var segment = (path || "").split("/");
  26721. return segment[segment.length - 1];
  26722. };
  26723. /**
  26724. * 检测媒体文件是否超过预设限制
  26725. * @param {String} type 媒体类型
  26726. * @param {Number} size 文件大小
  26727. */
  26728. var checkSizeLimit = (type, size) => {
  26729. size = size / 1024 / 1024;
  26730. return size <= mediaMaxSize[type];
  26731. };
  26732. var checkSizeLimitFree = (size, limit) => {
  26733. size = size / 1024 / 1024;
  26734. return size <= limit;
  26735. };
  26736. /**
  26737. * 检测媒体类型
  26738. * @param {String} type 媒体类型
  26739. * @param {String} filename 文件名称
  26740. */
  26741. var checkMediaMime = (type, filename) => {
  26742. var mime = getMime(filename);
  26743. var find = mediaMimes[type];
  26744. if (!find) {
  26745. return false;
  26746. }
  26747. return find.indexOf(mime) !== -1;
  26748. };
  26749. var checkMediaMimeByAccept = (accept, filename) => {
  26750. var mime = getMime(filename);
  26751. var type = accept;
  26752. if (type && type.indexOf("jpg") == -1 && type.indexOf("jpeg") != -1) {
  26753. type += ",image/jpg";
  26754. }
  26755. return (type || "").indexOf(mime) != -1;
  26756. };
  26757. var base64ToBlob = base64 => {
  26758. var arr = base64.split(","),
  26759. mime = arr[0].match(/:(.*?);/)[1],
  26760. bstr = atob(arr[1]),
  26761. n = bstr.length,
  26762. u8arr = new Uint8Array(n);
  26763. while (n--) {
  26764. u8arr[n] = bstr.charCodeAt(n);
  26765. }
  26766. return new Blob([u8arr], {
  26767. type: mime
  26768. });
  26769. };
  26770. var base64ToDataURL = base64 => {
  26771. return window.URL.createObjectURL(base64ToBlob(base64));
  26772. };
  26773. var blobToBase64 = function blobToBase64(blob) {
  26774. return new Promise(resolve => {
  26775. var reader = new FileReader();
  26776. reader.onload = function () {
  26777. resolve(reader.result);
  26778. };
  26779. reader.readAsDataURL(blob);
  26780. });
  26781. };
  26782. /*
  26783. * @Author: Rindy
  26784. * @Date: 2019-08-06 16:25:08
  26785. * @LastEditors: Rindy
  26786. * @LastEditTime: 2021-08-27 12:33:49
  26787. * @Description: Request
  26788. */
  26789. //import { $alert, $confirm, $loginTips } from "@/components/shared/message"
  26790. //import { $waiting } from "@/components/shared/loading"
  26791. //import { checkLogin } from "@/api"
  26792. //import { LoginDetector } from "@/core/starter"
  26793. //import { i18n } from "@/lang"
  26794. //import { password } from "@/utils/string"
  26795. //import store from "../Store"
  26796. // 空函数
  26797. var noop = function noop() {};
  26798. // 请求回调队列
  26799. var postQueue = [];
  26800. /**
  26801. * @property {number} NEXT - 继续执行
  26802. * @property {number} SUCCESS - 成功
  26803. * @property {number} EXCEPTION - 异常错误
  26804. * @property {number} FAILURE_CODE_3001 - 缺少必要参数
  26805. * @property {number} FAILURE_CODE_3002 - 访问异常
  26806. * @property {number} FAILURE_CODE_3003 - 非法访问
  26807. * @property {number} FAILURE_CODE_3004 - 用户未登录
  26808. * @property {number} FAILURE_CODE_3005 - 验证码已过期
  26809. * @property {number} FAILURE_CODE_3006 - 验证码错误
  26810. * @property {number} FAILURE_CODE_3007 - 昵称已存在
  26811. * @property {number} FAILURE_CODE_3008 - 该手机已被注册
  26812. * @property {number} FAILURE_CODE_3009 - 两次输入的密码不一致
  26813. * @property {number} FAILURE_CODE_3010 - 昵称长度错误
  26814. * @property {number} FAILURE_CODE_3011 - 密码长度错误
  26815. * @property {number} FAILURE_CODE_3012 - 昵称包含敏感词
  26816. * @property {number} FAILURE_CODE_3013 - 手机号码格式错误
  26817. * @property {number} FAILURE_CODE_3014 - 账号或密码不正确
  26818. * @property {number} FAILURE_CODE_3015 - 用户不存在
  26819. * @property {number} FAILURE_CODE_3016 - 您没有权限,请联系管理员
  26820. * @property {number} FAILURE_CODE_3017 - 空文件
  26821. * @property {number} FAILURE_CODE_3018 - 需要上传或使用的文件不存在
  26822. * @property {number} FAILURE_CODE_5010 - 找不到该场景对应的相机
  26823. * @property {number} FAILURE_CODE_5012 - 数据不正常
  26824. * @property {number} FAILURE_CODE_5014 - 无权操作该场景
  26825. * @property {number} FAILURE_CODE_5005 - 场景不存在
  26826. */
  26827. var statusCode = {
  26828. NEXT: -999,
  26829. SUCCESS: 0,
  26830. EXCEPTION: -1,
  26831. FAILURE_CODE_3001: 3001,
  26832. FAILURE_CODE_3002: 3002,
  26833. FAILURE_CODE_3003: 3003,
  26834. FAILURE_CODE_3004: 3004,
  26835. FAILURE_CODE_3005: 3005,
  26836. FAILURE_CODE_3006: 3006,
  26837. FAILURE_CODE_3007: 3007,
  26838. FAILURE_CODE_3008: 3008,
  26839. FAILURE_CODE_3009: 3009,
  26840. FAILURE_CODE_3010: 3010,
  26841. FAILURE_CODE_3011: 3011,
  26842. FAILURE_CODE_3012: 3012,
  26843. FAILURE_CODE_3013: 3013,
  26844. FAILURE_CODE_3014: 3014,
  26845. FAILURE_CODE_3015: 3015,
  26846. FAILURE_CODE_3016: 3016,
  26847. FAILURE_CODE_3017: 3017,
  26848. FAILURE_CODE_3018: 3018,
  26849. FAILURE_CODE_5010: 5010,
  26850. FAILURE_CODE_5012: 5012,
  26851. FAILURE_CODE_5014: 5014,
  26852. FAILURE_CODE_5005: 5005
  26853. };
  26854. /**
  26855. * 获取Token
  26856. * @function
  26857. */
  26858. function getToken() {
  26859. var urlToken = browser.urlHasValue("token", true);
  26860. if (urlToken) {
  26861. // 设置token共享给用户中心
  26862. localStorage.setItem("token", urlToken);
  26863. }
  26864. return urlToken || localStorage.getItem("token") || "";
  26865. }
  26866. /**
  26867. * 根据状态码的结果处理后续操作
  26868. * @function
  26869. * @param {number} code - 状态码
  26870. * @param {function} callback - 回调
  26871. */
  26872. function statusCodesHandler(code, callback) {
  26873. if (code == statusCode.EXCEPTION) {
  26874. return $alert({
  26875. content: i18n.t("tips.exception")
  26876. });
  26877. }
  26878. if (code == statusCode.FAILURE_CODE_3002 || code == statusCode.FAILURE_CODE_3003 || code == statusCode.FAILURE_CODE_3004) {
  26879. callback(code);
  26880. return showLoginTips();
  26881. }
  26882. if (code == statusCode.FAILURE_CODE_3001) {
  26883. callback(code);
  26884. return $alert({
  26885. content: i18n.t("tips.params_notfound")
  26886. });
  26887. }
  26888. if (code == statusCode.FAILURE_CODE_3017) {
  26889. callback(code);
  26890. return $alert({
  26891. content: i18n.t("tips.file_notfound")
  26892. });
  26893. }
  26894. if (code == statusCode.FAILURE_CODE_5005) {
  26895. /* if (!config.isEdit) {
  26896. return (location.href = config.pages.NotFound)
  26897. } */
  26898. callback(code);
  26899. return $alert({
  26900. content: i18n.t("tips.scene_notfound")
  26901. });
  26902. }
  26903. if (code == statusCode.FAILURE_CODE_5010) {
  26904. callback(code);
  26905. return $alert({
  26906. content: i18n.t("tips.camera_notfound")
  26907. });
  26908. }
  26909. if (code == statusCode.FAILURE_CODE_5012) {
  26910. callback(code);
  26911. return $alert({
  26912. content: i18n.t("tips.data_error")
  26913. });
  26914. }
  26915. if (code == statusCode.FAILURE_CODE_5014) {
  26916. callback(code);
  26917. return $alert({
  26918. content: i18n.t("tips.auth_deny")
  26919. });
  26920. }
  26921. return statusCode.NEXT;
  26922. }
  26923. $.ajaxSetup({
  26924. headers: {},
  26925. beforeSend: function beforeSend(xhr) {
  26926. var token = getToken();
  26927. if (token) {
  26928. xhr.setRequestHeader("token", token);
  26929. } else if (!token && this.url.indexOf("isLogin") != -1) {
  26930. showLoginTips();
  26931. }
  26932. /* if (config.oem == "localshow") {
  26933. // 本地版本兼容当前目录
  26934. if (this.url.indexOf("http") == -1 && this.url.indexOf("/") == 0) {
  26935. this.url = this.url.substr(1)
  26936. }
  26937. } */
  26938. // if(this.url.indexOf('http')==-1 && this.url.indexOf('/') !=0){
  26939. // this.url = '/'+this.url
  26940. // }
  26941. },
  26942. error: function error(xhr, status, _error) {
  26943. // 出错时默认的处理函数
  26944. if (this.url.indexOf("/scene.json") != -1 && xhr.status == 404) {
  26945. return $alert({
  26946. content: i18n.t("tips.scene_notfound")
  26947. });
  26948. } else if (this.type === "POST") {
  26949. return $alert({
  26950. content: i18n.t("tips.network_error")
  26951. });
  26952. }
  26953. },
  26954. success: function success(result) {},
  26955. complete: function complete() {
  26956. // Post类型请求无论成功或失败都关闭等待提示
  26957. if (this.type === "POST") {
  26958. http.__loading && $waiting.hide();
  26959. }
  26960. http.__loading = true;
  26961. }
  26962. });
  26963. /**
  26964. * @namespace http
  26965. * @type {Object}
  26966. */
  26967. var http = {
  26968. statusCode,
  26969. __loading: true,
  26970. __request(xhr, method, url, data, done, fail) {
  26971. if (typeof done != "function") {
  26972. done = noop;
  26973. }
  26974. if (typeof fail != "function") {
  26975. fail = noop;
  26976. }
  26977. xhr.done(result => {
  26978. if (typeof result.code !== "undefined") {
  26979. var flag = statusCodesHandler(result.code, function (code) {
  26980. // 需要登录的状态
  26981. if (code == statusCode.FAILURE_CODE_3001 || code == statusCode.FAILURE_CODE_3002 || code == statusCode.FAILURE_CODE_3003 || code == statusCode.FAILURE_CODE_3004) {
  26982. if (url.indexOf("isLogin") == -1 && url.indexOf("openSceneBykey") == -1) {
  26983. postQueue.push(function () {
  26984. http[method](url, data, done, fail);
  26985. });
  26986. }
  26987. }
  26988. fail();
  26989. });
  26990. if (flag === statusCode.NEXT) {
  26991. done(result, result.code == 0);
  26992. }
  26993. } else {
  26994. done(result);
  26995. }
  26996. });
  26997. xhr.fail(fail);
  26998. xhr.always(() => xhr = null);
  26999. return xhr;
  27000. },
  27001. /**
  27002. * Get请求
  27003. * @param {String} url 请求地址
  27004. * @param {Object?} data 请求参数
  27005. * @param {Function?} done 成功回调
  27006. * @param {Function?} fail 失败回调
  27007. */
  27008. get(url) {
  27009. var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  27010. var done = arguments.length > 2 ? arguments[2] : undefined;
  27011. var fail = arguments.length > 3 ? arguments[3] : undefined;
  27012. if (/\.json/.test(url)) {
  27013. // json文件格式自动调用getJson方法
  27014. return this.getJson(url, data, done, fail);
  27015. }
  27016. return this.__request($.get(url, data), "get", url, data, done, fail);
  27017. },
  27018. /**
  27019. * Get Blob请求
  27020. * @param {String} url 请求地址
  27021. * @param {Object?} data 请求参数
  27022. * @param {Function?} done 成功回调
  27023. * @param {Function?} fail 失败回调
  27024. */
  27025. getText(url) {
  27026. var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  27027. var done = arguments.length > 2 ? arguments[2] : undefined;
  27028. var fail = arguments.length > 3 ? arguments[3] : undefined;
  27029. return this.__request($.ajax({
  27030. url: url,
  27031. dataType: "text"
  27032. }), "getText", url, data, done, fail);
  27033. },
  27034. /**
  27035. * GetJson请求 读取json文件数据
  27036. * @param {String} url 请求地址
  27037. * @param {Object?} data 请求参数
  27038. * @param {Function?} done 成功回调
  27039. * @param {Function?} fail 失败回调
  27040. */
  27041. getJson(url) {
  27042. var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  27043. var done = arguments.length > 2 ? arguments[2] : undefined;
  27044. var fail = arguments.length > 3 ? arguments[3] : undefined;
  27045. return this.__request($.getJSON(url, data), "get", url, data, done, fail);
  27046. },
  27047. /**
  27048. * Get Blob请求
  27049. * @param {String} url 请求地址
  27050. * @param {Object?} data 请求参数
  27051. * @param {Function?} done 成功回调
  27052. * @param {Function?} fail 失败回调
  27053. */
  27054. getBlob(url) {
  27055. var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  27056. var done = arguments.length > 2 ? arguments[2] : undefined;
  27057. var fail = arguments.length > 3 ? arguments[3] : undefined;
  27058. return this.__request($.ajax({
  27059. url: url,
  27060. dataType: "blob"
  27061. }), "getBlob", url, data, done, fail);
  27062. },
  27063. /**
  27064. * Get Arraybuffer请求
  27065. * @param {String} url 请求地址
  27066. * @param {Object?} data 请求参数
  27067. * @param {Function?} done 成功回调
  27068. * @param {Function?} fail 失败回调
  27069. */
  27070. getArraybuffer(url) {
  27071. var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  27072. var done = arguments.length > 2 ? arguments[2] : undefined;
  27073. var fail = arguments.length > 3 ? arguments[3] : undefined;
  27074. return this.__request($.ajax({
  27075. url: url,
  27076. dataType: "arraybuffer"
  27077. }), "getArraybuffer", url, data, done, fail);
  27078. },
  27079. /**
  27080. * Post 请求
  27081. * @param {String} url 请求地址
  27082. * @param {Object?} data 请求参数
  27083. * @param {Function?} done 成功回调
  27084. * @param {Function?} fail 失败回调
  27085. */
  27086. post(url) {
  27087. var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  27088. var done = arguments.length > 2 ? arguments[2] : undefined;
  27089. var fail = arguments.length > 3 ? arguments[3] : undefined;
  27090. if (url.indexOf("isLogin") == -1) {
  27091. http.__loading && $waiting.show();
  27092. }
  27093. return this.__request($.post(url, data), "post", url, data, done, fail);
  27094. },
  27095. /**
  27096. * PostJson 请求
  27097. * @param {String} url 请求地址
  27098. * @param {Object?} data 请求参数
  27099. * @param {Function?} done 成功回调
  27100. * @param {Function?} fail 失败回调
  27101. */
  27102. postJson(url) {
  27103. var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  27104. var done = arguments.length > 2 ? arguments[2] : undefined;
  27105. var fail = arguments.length > 3 ? arguments[3] : undefined;
  27106. http.__loading && $waiting.show();
  27107. return this.__request($.ajax({
  27108. type: "POST",
  27109. url: url,
  27110. contentType: "application/json",
  27111. data: JSON.stringify(data)
  27112. }), "postJson", url, data, done, fail);
  27113. },
  27114. /**
  27115. * Post 表单 支持文件上传
  27116. * @param {String} url 请求地址
  27117. * @param {FormData?} formData 请求参数
  27118. * @param {Function?} done 成功回调
  27119. * @param {Function?} fail 失败回调
  27120. */
  27121. postForm(url, formData, done, fail, onProgress) {
  27122. if (typeof onProgress === "function") {
  27123. return this.__request($.ajax({
  27124. type: "POST",
  27125. url: url,
  27126. processData: false,
  27127. contentType: false,
  27128. data: formData,
  27129. xhr: function xhr() {
  27130. var xhr = new XMLHttpRequest();
  27131. xhr.upload.addEventListener("progress", function (e) {
  27132. onProgress(e.loaded / e.total * 100 + "%");
  27133. });
  27134. return xhr;
  27135. }
  27136. }), "postForm", url, formData, done, fail);
  27137. } else {
  27138. http.__loading && $waiting.show();
  27139. return this.__request($.ajax({
  27140. type: "POST",
  27141. url: url,
  27142. processData: false,
  27143. contentType: false,
  27144. data: formData
  27145. }), "postForm", url, formData, done, fail);
  27146. }
  27147. },
  27148. /**
  27149. * 加载图片
  27150. * @param {String} url 请求地址
  27151. * @param {Number?} retry 重试次数,默认为3
  27152. */
  27153. loadImage(url) {
  27154. var retry = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3;
  27155. var def = $.Deferred();
  27156. var img = new Image();
  27157. /* if (process.env.VUE_APP_REGION == "AWS" && url.indexOf("x-oss-process=image") != -1) {
  27158. var arr = url.split("?")
  27159. url = arr[0] + encodeURIComponent("?" + arr[1].replace(/\//g, "@"))
  27160. } */
  27161. var load = () => {
  27162. console.warn("Retrying load image: " + url);
  27163. this.loadImage(url, retry - 1).done(def.resolve.bind(def)).progress(def.notify.bind(def)).fail(def.reject.bind(def));
  27164. };
  27165. img.onerror = function () {
  27166. retry > 0 ? setTimeout(() => load(), 1e3) : def.reject("[".concat(url, "]\u52A0\u8F7D\u5931\u8D25"));
  27167. };
  27168. img.onload = function () {
  27169. def.resolve(img);
  27170. };
  27171. img.crossOrigin = "anonymous";
  27172. img.src = url;
  27173. return def;
  27174. },
  27175. /**
  27176. * 上传文件
  27177. * @param {String} url 请求地址
  27178. * @param {Object?} data 请求参数
  27179. * @param {Function?} done 成功回调
  27180. * @param {Function?} fail 失败回调
  27181. */
  27182. uploadFile(url) {
  27183. var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  27184. var done = arguments.length > 2 ? arguments[2] : undefined;
  27185. var fail = arguments.length > 3 ? arguments[3] : undefined;
  27186. var onProgress = arguments.length > 4 ? arguments[4] : undefined;
  27187. var form = new FormData();
  27188. // if (file.needTransfer) { //ie和苹果都不支持dataURLtoFile得传送,所以只能用blob
  27189. // form.append("file", common.dataURLtoBlob(file.file), file.name || file.file.name);
  27190. // } else {
  27191. // form.append("file", file.file, file.name || file.file.name);
  27192. // }
  27193. for (var key in data) {
  27194. if (key == "file") {
  27195. form.append("file", data[key], data.filename || data[key].name);
  27196. } else if (key != "filename") {
  27197. form.append(key, data[key]);
  27198. }
  27199. }
  27200. return this.postForm(url, form, done, fail, onProgress);
  27201. },
  27202. /**
  27203. * 上传文件
  27204. * @param {String} url 请求地址
  27205. * @param {Object?} data 请求参数 {file:'base64 string',filename:'image.jpg',...}
  27206. * @param {Function?} done 成功回调
  27207. * @param {Function?} fail 失败回调
  27208. */
  27209. uploadBlobFile(url) {
  27210. var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  27211. var done = arguments.length > 2 ? arguments[2] : undefined;
  27212. var fail = arguments.length > 3 ? arguments[3] : undefined;
  27213. var form = new FormData();
  27214. for (var key in data) {
  27215. if (key === "file") {
  27216. form.append("file", base64ToBlob(data.file), data.filename);
  27217. } else if (key != "filename") {
  27218. form.append(key, data[key]);
  27219. }
  27220. }
  27221. return this.postForm(url, form, done, fail);
  27222. }
  27223. };
  27224. var {
  27225. TileDownloaderEvents,
  27226. DownloadStatus: DownloadStatus$1
  27227. } = Potree.defines;
  27228. window.downloaded = {};
  27229. window.startdownloads = [];
  27230. class TileDownloader extends EventDispatcher {
  27231. constructor() {
  27232. super();
  27233. this.panos = null;
  27234. this.retryMinimumTime = 1e4;
  27235. this.panoLoadCallbacks = {};
  27236. this.downloadDescriptors = {};
  27237. this.priorityQueue = [];
  27238. this.forceQueue = [];
  27239. this.activeDownloads = [];
  27240. this.tilePrioritizer = null;
  27241. this.refreshInterval = null;
  27242. this.processPriorityQueue = !1;
  27243. this.concurrentDownloads = 6; //e.concurrentDownloads || 1;
  27244. this.downloadTestResults = {};
  27245. this.freeze = Object.freeze({
  27246. Testing: 1,
  27247. Success: 2,
  27248. Fail: 3
  27249. });
  27250. /* viewer.addEventListener('pageVisible', (e)=>{//不可见时不refreshUpdateInterval
  27251. //console.log('visibilitychange:', state)
  27252. Potree.Utils.updateVisible(this, 'pageVisible', e.v)
  27253. this.judgeStart()
  27254. })
  27255. this.visible = true //add 借用Potree.Utils.updateVisible来判断是否start
  27256. if(Potree.settings.useDepthTex){
  27257. this.judgeStart() //开始下载depthTex
  27258. }else{
  27259. Potree.Utils.updateVisible(this,'showPanos', false ) //默认visible = false
  27260. } */
  27261. }
  27262. setPanoData(e, t /* , i */) {
  27263. this.panos = e, this.imagePanos = t;
  27264. // this.panoGroupId = i
  27265. }
  27266. start() {
  27267. this.downloadCubeTex = true;
  27268. /* if(!Potree.settings.useDepthTex){
  27269. Potree.Utils.updateVisible(this,'showPanos', true )
  27270. this.judgeStart()
  27271. }else{
  27272. //this.refreshInterval || this.judgeStart()
  27273. } */
  27274. }
  27275. stop() {
  27276. this.downloadCubeTex = false;
  27277. /* if(!Potree.settings.useDepthTex){
  27278. Potree.Utils.updateVisible(this,'showPanos', false )
  27279. this.judgeStart()
  27280. } */
  27281. }
  27282. /* judgeStart(){//add
  27283. if(this.visible){
  27284. //console.log('judgeStart true')
  27285. this.started = true
  27286. //this.refreshUpdateInterval(0)
  27287. }else{
  27288. //console.log('judgeStart false')
  27289. this.started = false
  27290. //window.clearTimeout(this.refreshInterval)
  27291. }
  27292. } */
  27293. /* refreshUpdateInterval(e) {
  27294. e || (e = 0),
  27295. this.refreshInterval = window.setTimeout(function() {
  27296. var e = this.update();
  27297. e ? this.refreshUpdateInterval(TileDownloader.ACTIVE_REFRESH_DELAY) : this.refreshUpdateInterval(TileDownloader.IDLE_REFRESH_DELAY)
  27298. }
  27299. .bind(this), e)
  27300. } */
  27301. update() {
  27302. if (this.downloadCubeTex) {
  27303. //可以下载贴图
  27304. var e = this.forceQueue.length > 0;
  27305. this.processQueueForDownloading(this.forceQueue);
  27306. if (this.processPriorityQueue) {
  27307. Potree.Common.intervalTool.isWaiting('processPriorityQueue', () => {
  27308. //延时update,防止崩溃 , 未到时间就拦截(第一次直接执行)
  27309. this.queuePrioritizedTilesForPanos(this.panos); //这句比较耗时 降四倍时大概1-2毫秒
  27310. }, 66);
  27311. this.priorityQueue.length > 0 && (e = !0);
  27312. this.processQueueForDownloading(this.priorityQueue);
  27313. }
  27314. //return e
  27315. }
  27316. Potree.Common.intervalTool.isWaiting('filterDepthTex', () => {
  27317. this.tilePrioritizer.filterDepthTex(this.panos); //下载深度图
  27318. }, 77);
  27319. }
  27320. queuePrioritizedTilesForPanos(e) {
  27321. this.tilePrioritizer && (this.clearQueue(this.priorityQueue), this.tilePrioritizer.filterAndPrioritize(this.priorityQueue, e, this), this.clearFromQueue(this.priorityQueue, DownloadStatus$1.None, !0),
  27322. //去除state为DownloadStatus.None的(可能是去除已经在下载的)
  27323. this.setStatusOrRemoveForAllDescriptors(this.priorityQueue, DownloadStatus$1.Queued));
  27324. }
  27325. clearQueue(e) {
  27326. //停止下载并清空
  27327. this.setStatusForAllDescriptors(e, DownloadStatus$1.None), e.length = 0;
  27328. }
  27329. clearForceQueue() {
  27330. this.clearQueue(this.forceQueue);
  27331. }
  27332. clearFromQueue(e, t, i) {
  27333. for (var n = 0; n < e.length; n++) {
  27334. var r = e[n];
  27335. r && (t === r.status && !i || t !== r.status && i) && (e[n] = null);
  27336. }
  27337. }
  27338. setStatusForAllDescriptors(e, t) {
  27339. for (var i = 0; i < e.length; i++) {
  27340. var n = e[i];
  27341. n && (n.status = t);
  27342. }
  27343. }
  27344. setStatusOrRemoveForAllDescriptors(e, t) {
  27345. for (var i = 0; i < e.length; i++) {
  27346. var n = e[i];
  27347. n && (n.status !== t ? n.status = t : e[i] = null);
  27348. }
  27349. }
  27350. getTileDownloadDescriptors(pano, size) {
  27351. //获取该pano的该size的全部的tile的descriptor
  27352. var i = this.getAllTileDownloadDescriptorsForPano(pano),
  27353. n = i[size];
  27354. return n || (n = this.buildDownloadDescriptorArray(size),
  27355. //创建的全部是空的
  27356. i[size] = n, this.initTileDownloadDescriptors(n, pano, size)),
  27357. //绑定到该pano size
  27358. n;
  27359. }
  27360. getAllTileDownloadDescriptorsForPano(pano) {
  27361. //新建空Descriptors
  27362. var t = this.downloadDescriptors[pano.id];
  27363. return t || (t = {}, this.downloadDescriptors[pano.id] = t), t;
  27364. }
  27365. processQueueForDownloading(e, t) {
  27366. //执行下载任务
  27367. this.cleanupActiveDownloads();
  27368. if (e.length) {
  27369. var concurrentDownloads = Potree.Common.getBestCount('concurrentDownloads', 1, 6, 1.8, 14 /* ,true */); //flying ? (isMobile ? 2 : 3) : 6
  27370. if (this.activeDownloads.length < concurrentDownloads || t) {
  27371. var i = t ? e.length : concurrentDownloads - this.activeDownloads.length;
  27372. for (var n = 0, r = 0; n < i && e.length > 0; r++) {
  27373. var o = e.shift();
  27374. if (o) {
  27375. //add 为了防止1024的在512前下载完,这里强行等待512下载完毕再开始下载
  27376. if (o.panoSize > 512 && !this.isPanoDownloaded(o.pano, 512)) {
  27377. //console.log('512的还没下载好呢!')
  27378. e.push(o);
  27379. break; //一般512的都是连续下载的,所以后面就都不是512了直接中断
  27380. }
  27381. this.startDownload(o);
  27382. n++;
  27383. }
  27384. }
  27385. }
  27386. }
  27387. }
  27388. testDownload(panoSize, tileSize, callback) {
  27389. var n = this.downloadTestResults[panoSize];
  27390. if (n) return void (n === this.freeze.Success ? callback(!0) : n === this.freeze.Fail && callback(!1));
  27391. this.downloadTestResults[panoSize] = this.freeze.Testing;
  27392. var r = this.panos[0],
  27393. o = this.getTileUrl({
  27394. pano: r,
  27395. panoSize,
  27396. tileSize,
  27397. tileIndex: 0
  27398. } /* r.id, panoSize, tileSize, 0 */),
  27399. a = function (t) {
  27400. this.downloadTestResults[panoSize] = this.freeze.Success, callback(!0);
  27401. }.bind(this),
  27402. s = function () {
  27403. this.downloadTestResults[panoSize] = this.freeze.Fail, callback(!1);
  27404. }.bind(this);
  27405. this.loadImage(o, 0, a, s);
  27406. }
  27407. startDownload(e) {
  27408. //开始下载啦
  27409. //console.log('startDownload')
  27410. startdownloads.push(e);
  27411. e.local2SrcFailed = this.local2SrcFailed;
  27412. e.status = DownloadStatus$1.Downloading;
  27413. var t = this.getTileUrl(e /* e.pano.id, e.panoSize, e.tileSize, e.tileIndex, e.pano.alignmentType */); //xzw add alignmentType
  27414. if (!t) return;
  27415. this.activeDownloads.push(e);
  27416. this.loadImage(t, TileDownloader.DOWNLOAD_RETRIES, this.downloadComplete.bind(this, e), this.downloadFailed.bind(this, e));
  27417. }
  27418. downloadFailed(e, t) {
  27419. //add
  27420. if (Potree.settings.isLocal2 && !e.local2SrcFailed) {
  27421. //为了兼容旧的数据src,如果新src没加载成功,就加载旧的
  27422. e.local2SrcFailed = this.local2SrcFailed = true;
  27423. //this.startDownload(e)//重新下载
  27424. var t = this.getTileUrl(e);
  27425. this.loadImage(t, TileDownloader.DOWNLOAD_RETRIES, this.downloadComplete.bind(this, e), this.downloadFailed.bind(this, e));
  27426. }
  27427. }
  27428. downloadComplete(e, t) {
  27429. //下载成功时
  27430. //if (e.panoGroupId === this.panoGroupId) {
  27431. var i = this.getPanoLoadCallbacks(e.pano, e.panoSize);
  27432. e.status = DownloadStatus$1.Downloaded, i && i.onProgress && i.onProgress(e.pano, e.panoSize);
  27433. var n = {
  27434. panoId: e.pano.id,
  27435. image: t,
  27436. tileSize: e.tileSize,
  27437. panoSize: e.panoSize,
  27438. tileIndex: e.tileIndex,
  27439. faceTileIndex: e.faceTileIndex,
  27440. totalTiles: e.totalTiles,
  27441. face: e.face,
  27442. tileX: e.tileX,
  27443. tileY: e.tileY,
  27444. direction: e.direction
  27445. };
  27446. downloaded[e.pano.id] || (downloaded[e.pano.id] = {
  27447. 512: [],
  27448. 1024: [],
  27449. 2048: []
  27450. });
  27451. downloaded[e.pano.id][e.panoSize] || (downloaded[e.pano.id][e.panoSize] = []);
  27452. downloaded[e.pano.id][e.panoSize].push(e);
  27453. if (e.panoSize != 512 && downloaded[e.pano.id][512].length < 6) {
  27454. console.warn('没下完');
  27455. }
  27456. e.image = t, this.dispatchEvent({
  27457. type: TileDownloaderEvents.TileDownloadSuccess,
  27458. desc: n
  27459. });
  27460. this.isPanoDownloaded(e.pano, e.panoSize) && (n = {
  27461. panoId: e.pano.id,
  27462. tileSize: e.tileSize,
  27463. panoSize: e.panoSize
  27464. }, this.dispatchEvent({
  27465. type: TileDownloaderEvents.PanoDownloadComplete,
  27466. desc: n
  27467. }), i && i.onLoad && i.onLoad(e.pano, e.panoSize));
  27468. //}
  27469. }
  27470. isPanoDownloaded(e, t) {
  27471. var i = this.getTileDownloadDescriptors(e, t);
  27472. if (i.length <= 0) return !1;
  27473. for (var n = 0; n < i.length; n++) {
  27474. var r = i[n];
  27475. if (r.status !== DownloadStatus$1.Downloaded) return !1;
  27476. }
  27477. return !0;
  27478. }
  27479. setPanoLoadCallbacks(e, t, i, n, r) {
  27480. var o = e.id + ":" + this.qualityManager.getPanoSize(t);
  27481. this.panoLoadCallbacks[o] = {
  27482. onLoad: i,
  27483. onFail: n,
  27484. onProgress: r
  27485. };
  27486. }
  27487. getPanoLoadCallbacks(e, t) {
  27488. var i = e.id + ":" + t;
  27489. return this.panoLoadCallbacks[i];
  27490. }
  27491. buildDownloadDescriptorArray(e) {
  27492. for (var t = TileUtils.getTileCountForSize(e), i = [], n = 0; n < t; n++) {
  27493. var r = this.buildDownloadDescriptor();
  27494. i.push(r);
  27495. }
  27496. return i;
  27497. }
  27498. buildDownloadDescriptor() {
  27499. //Descriptor!
  27500. var e = {
  27501. panoGroupId: null,
  27502. pano: null,
  27503. panoSize: -1,
  27504. tileSize: -1,
  27505. tileIndex: -1,
  27506. totalTiles: -1,
  27507. faceTileIndex: -1,
  27508. status: DownloadStatus$1.None,
  27509. url: null,
  27510. image: null,
  27511. direction: new Vector3(),
  27512. //该tile在cube中的方向
  27513. face: -1,
  27514. cubeFace: -1,
  27515. tileX: -1,
  27516. tileY: -1
  27517. };
  27518. return e;
  27519. }
  27520. initTileDownloadDescriptors(e, t, i) {
  27521. for (var n = 0; n < e.length; n++) {
  27522. var r = e[n];
  27523. this.initTileDownloadDescriptor(r, t, i, n);
  27524. }
  27525. }
  27526. initTileDownloadDescriptor(desc, pano, size, index) {
  27527. var r = size >= TileUtils.TILE_SIZE ? TileUtils.TILE_SIZE : size;
  27528. desc.face = TileUtils.getFaceForTile(size, index); //根据顺序得到的face的index
  27529. desc.cubeFace = TileUtils.mapFaceToCubemapFace(desc.face); //为了贴图而转化的face index
  27530. //desc.panoGroupId = this.panoGroupId;//就是场景号
  27531. desc.pano = pano;
  27532. desc.panoSize = size;
  27533. desc.tileSize = r; //瓦片图size 512
  27534. desc.tileIndex = index;
  27535. desc.totalTiles = TileUtils.getTileCountForSize(size);
  27536. desc.status = DownloadStatus$1.None;
  27537. desc.image = null;
  27538. TileUtils.getTileLocation(desc.panoSize, desc.tileIndex, desc); //得到该tile在这个face中的具体位置(tileX等)
  27539. TileUtils.getTileVector(desc.panoSize, desc.tileSize, desc.cubeFace, desc.tileX, desc.tileY, TileUtils.LocationOnTile.Center, 0, desc.direction);
  27540. }
  27541. getTiles(d, sceneNum, useV4url, pointcloud) {
  27542. var v3OrV4Str = useV4url ? "/scene_view_data/".concat(sceneNum, "/images/") : "/images/images".concat(sceneNum, "/");
  27543. if (Potree.settings.isLocal && !this.local2SrcFailed && pointcloud.datasetData.mapping && !Potree.settings.isLocal2) {
  27544. //非离线包的话加mapping
  27545. return "".concat(Potree.settings.urls.prefix3, "/").concat(pointcloud.datasetData.mapping).concat(v3OrV4Str).concat(d);
  27546. }
  27547. return "".concat(Potree.settings.urls.prefix3).concat(v3OrV4Str).concat(d);
  27548. /*
  27549. if(Potree.settings.isLocal && !this.local2SrcFailed || useV4url){//新的地址 scene_view_data/场景码/images/tiles
  27550. if(pointcloud.datasetData.mapping && !Potree.settings.isLocal2){//非离线包的话加mapping
  27551. return `${Potree.settings.urls.prefix3}/${pointcloud.datasetData.mapping}/scene_view_data/${sceneNum}/images/${d}`
  27552. }else{
  27553. return `${Potree.settings.urls.prefix3}/scene_view_data/${sceneNum}/images/${d}`
  27554. }
  27555. }
  27556. return `${Potree.settings.urls.prefix3}/images/images${sceneNum}/${d}`
  27557. */
  27558. }
  27559. loadImage(e, t, i, n) {
  27560. //自己修改了ajax,把getImage改成了loadImg
  27561. http.loadImage(e, t).then(function (e) {
  27562. i(e);
  27563. }).fail(n);
  27564. }
  27565. }
  27566. TileDownloader.prototype.forceQueueTilesForPano = function () {
  27567. //根据条件开始加载tile
  27568. var e = [],
  27569. t = [];
  27570. return function (pano, size, dir, hFov, vFov, download) {
  27571. e.length = 0;
  27572. for (var u = this.getTileDownloadDescriptors(pano, size), d = 0; d < u.length; d++) {
  27573. var p = u[d];
  27574. p.status !== DownloadStatus$1.None && p.status !== DownloadStatus$1.Queued || e.push(p);
  27575. }
  27576. if (dir && e.length > 0) {
  27577. TilePrioritizer.sortPanoTiles(e, pano, dir); //按最佳方向排序e
  27578. t.length = 0;
  27579. TileUtils.matchingTilesInDirection(pano, size, dir, hFov, vFov, t); //得到在符合视野标准的集合t
  27580. for (var f = 0, g = function g(e) {
  27581. return e.face === m.face && e.faceTileIndex === m.faceTileIndex;
  27582. }; f < e.length;) {
  27583. //过滤掉不符合角度要求的
  27584. var m = e[f],
  27585. v = t.findIndex(g);
  27586. v < 0 ? e.splice(f, 1) : f++;
  27587. }
  27588. }
  27589. for (var A = 0; A < e.length; A++) {
  27590. this.forceQueue.push(e[A]); //装载
  27591. }
  27592. /* if(e.length){
  27593. console.log(e)
  27594. } */
  27595. this.setStatusForAllDescriptors(this.forceQueue, DownloadStatus$1.ForceQueued);
  27596. this.clearFromQueue(this.priorityQueue, DownloadStatus$1.ForceQueued, !1);
  27597. download && this.processQueueForDownloading(this.forceQueue, !0);
  27598. };
  27599. }();
  27600. TileDownloader.prototype.cleanupActiveDownloads = function () {
  27601. var e = [];
  27602. return function () {
  27603. e.length = 0;
  27604. for (var t = 0; t < this.activeDownloads.length; t++) {
  27605. var i = this.activeDownloads[t];
  27606. i.status !== DownloadStatus$1.Downloaded && i.status !== DownloadStatus$1.Failed && e.push(i);
  27607. }
  27608. this.activeDownloads.length = 0, this.activeDownloads.push.apply(this.activeDownloads, e);
  27609. };
  27610. }();
  27611. TileDownloader.prototype.getTileUrl = function () {
  27612. var e = {
  27613. 256: "256",
  27614. 512: "512",
  27615. 1024: "1k",
  27616. 2048: "2k",
  27617. 4096: "4k"
  27618. },
  27619. t = {
  27620. face: -1,
  27621. faceTileIndex: -1,
  27622. tileX: -1,
  27623. tileY: -1
  27624. };
  27625. return function () {
  27626. var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  27627. var id = o.pano.originID,
  27628. ////////
  27629. panoSize = o.panoSize,
  27630. tileSize = o.tileSize,
  27631. tileIndex = o.tileIndex,
  27632. sceneCode = o.pano.pointcloud.sceneCode,
  27633. useV4url = Potree.settings.useV4url && o.pano.pointcloud.datasetData.sceneVersion == 'V4'; //v4的全景图等路径不一样
  27634. var metadata = {
  27635. sceneScheme: 10
  27636. };
  27637. TileUtils.getTileLocation(panoSize, tileIndex, t);
  27638. var s = Math.floor(panoSize / tileSize),
  27639. l = s * s,
  27640. h = Math.floor(tileIndex / l),
  27641. u = "",
  27642. d = '',
  27643. g = '';
  27644. if (Potree.settings.tileOriginUrl) {
  27645. //原始规则
  27646. //1 === config.tiling.customCompression && (u = "_" + config.tiling["q" + e[panoSize]]);
  27647. //1 === o.tiling.customCompression && (u = "_" + o.tiling["q" + e[n]]);
  27648. d = "tiles/" + id + "/" + e[panoSize] + u + "_face" + h + "_" + t.tileX + "_" + t.tileY + ".jpg";
  27649. d = this.getTiles(d, sceneCode, useV4url, o.pano.pointcloud);
  27650. g = "?";
  27651. } else {
  27652. //阿里云oss的规则 if (metadata.sceneScheme == 10)
  27653. d = 'tiles/4k/' + id + '_skybox' + h + '.jpg?x-oss-process=';
  27654. if (e[panoSize] == '512') {
  27655. d += 'image/resize,h_512';
  27656. } else {
  27657. //4k的图,移动端是1k,pc端是2k,放大才是4k
  27658. if (e[panoSize] == '1k' || e[panoSize] == '2k') {
  27659. //https://4dkk.4dage.com/images/imagesx4iqYDG3/tiles/4k/122_skybox0.jpg?x-oss-process=image/resize,m_lfit,w_1024/crop,w_512,h_512,x_511,y_0
  27660. d += 'image/resize,m_lfit,w_' + panoSize + '/crop,w_512,h_512,';
  27661. } else {
  27662. d = 'tiles/4k/' + id + '_skybox' + h + '.jpg?x-oss-process=image/crop,w_512,h_512,';
  27663. }
  27664. //起始位置
  27665. if (t.tileX == 0) {
  27666. d += 'x_0,';
  27667. } else {
  27668. d += 'x_' + 512 * t.tileX /* - 1 */ + ',';
  27669. }
  27670. if (t.tileY == 0) {
  27671. d += 'y_0';
  27672. } else {
  27673. d += 'y_' + 512 * t.tileY /* - 1 */;
  27674. }
  27675. }
  27676. d = this.getTiles(d, sceneCode, useV4url, o.pano.pointcloud);
  27677. g = "&";
  27678. }
  27679. //Potree.settings.panoVersion = 4
  27680. d += g + (Potree.settings.panoVersion ? 'version=' + Potree.settings.panoVersion : 'time=' + o.pano.pointcloud.timeStamp); //加后缀
  27681. return d;
  27682. /* 4dkk
  27683. getViewImagesURL(url) {
  27684. if (url.indexOf('&_=') !== -1) {
  27685. return url
  27686. }
  27687. let version = url.indexOf('/panorama/') !== -1 ? this.linkVersion : this.imageVersion
  27688. if (url.indexOf('?') !== -1) {
  27689. return this.$app.config.resource + `scene_view_data/${this.num}/images/${url}&_=${version}`
  27690. }
  27691. return this.$app.config.resource + `scene_view_data/${this.num}/images/${url}?_=${version}`
  27692. }
  27693. /**
  27694. */
  27695. };
  27696. }();
  27697. TileDownloader.tilegen = true;
  27698. TileDownloader.IDLE_REFRESH_DELAY = 500;
  27699. TileDownloader.ACTIVE_REFRESH_DELAY = 16;
  27700. TileDownloader.DOWNLOAD_RETRIES = 4;
  27701. function Node$1(e, t) {
  27702. this.tree = e,
  27703. //所属树(TileTree)
  27704. this.parent = t, this.children = [], this.id = ++u$1;
  27705. }
  27706. function o(e, t, i, r, a, s, l, h) {
  27707. if (e) {
  27708. l = l || TileTree.TraversalType.PreOrder;
  27709. var u = r * c + i;
  27710. if (l === TileTree.TraversalType.PreOrder && (a && a(e, t, u, i, r), s && s.push(e)), e.children && 0 !== e.children.length) {
  27711. for (var d = r * c, p = i * c, f = 0; f < c; f++) for (var g = 0; g < c; g++) o(e.children[g * c + f], t + 1, p + f, d + g, a, s, l, h);
  27712. l === TileTree.TraversalType.PostOrder && (a && a(e, t, u, i, r), s && s.push(e));
  27713. }
  27714. }
  27715. }
  27716. function Plant(seed) {
  27717. seed.root = Branch(seed, null, 0);
  27718. }
  27719. function Branch(seed, parent, level) {
  27720. if (level > seed.levels) return null;
  27721. var node = new Node$1(seed, parent);
  27722. seed.allNodes.push(node);
  27723. for (var o = 0; o < h$1; o++) node.children[o] = Branch(seed, node, level + 1);
  27724. return node;
  27725. }
  27726. function l(parent, t, level, n, r) {
  27727. if (!parent) return null;
  27728. if (0 === level) return parent;
  27729. if (!parent.children || 0 === parent.children.length) return null;
  27730. var o = Math.pow(c, level),
  27731. a = o / c,
  27732. s = n % a,
  27733. h = r % a,
  27734. u = Math.floor(r / a),
  27735. d = Math.floor(n / a),
  27736. p = u * c + d,
  27737. f = parent.children[p];
  27738. return l(f, t + 1, level - 1, s, h);
  27739. }
  27740. /* cube每个面都有一个分层树 用于代表瓦片图的细分?
  27741. 树4096的分为三层,每层有4个子节点。(最后一层的四个子节点都是null)
  27742. */
  27743. var c = 2,
  27744. h$1 = c * c; //4个子节点
  27745. var u$1 = 0;
  27746. class TileTree {
  27747. constructor(e, t) {
  27748. this.levels = t, this.tileSize = e, this.root = null, this.allNodes = [], Plant(this);
  27749. }
  27750. getSubNode(e, t, i) {
  27751. (!t || e < this.tileSize) && (t = 0), (!i || e < this.tileSize) && (i = 0), e < this.tileSize && (e = this.tileSize);
  27752. var level = TileTree.getLevelCountForSize(this.tileSize, e),
  27753. o = l(this.root, 0, level, t, i);
  27754. return o;
  27755. }
  27756. breadthFirst(e) {
  27757. //广度优先搜索
  27758. e = e || {};
  27759. var t = !!e.nullLevelEnd,
  27760. i = e.maxLevel,
  27761. n = e.minLevel,
  27762. r = e.callback,
  27763. o = e.saveVisited,
  27764. a = [],
  27765. s = {},
  27766. l = 0,
  27767. c = 0;
  27768. for (a.push(this.root), a.push(s); a.length > 0 && !(i && l > i);) {
  27769. var h = a.shift();
  27770. if (h === s) (!n || l >= n) && (r && t && r(null), o && t && o.push(null)), a.length > 0 && a.push(s), l++, c = 0;else {
  27771. if (h.children) for (var u = 0; u < h.children.length; u++) {
  27772. var d = h.children[u];
  27773. d && a.push(h.children[u]);
  27774. }
  27775. var p = this.getFaceIndexFromNode(h);
  27776. (!n || l >= n) && (r && r(h, l, p), o && o.push(h)), c++;
  27777. }
  27778. }
  27779. }
  27780. getFaceIndexFromNode(e) {
  27781. if (!e) return -1;
  27782. for (var t = 1, i = e, n = 0, r = 0;;) {
  27783. var o = i.parent;
  27784. if (!o) break;
  27785. for (var a = -1, s = 0; s < o.children.length; s++) o.children[s] === i && (a = s);
  27786. var l = a % c,
  27787. h = Math.floor(a / c);
  27788. n = l * t + n, r = h * t + r, t *= c, i = o;
  27789. }
  27790. return r * t + n;
  27791. }
  27792. depthFirst(e, t, i) {
  27793. o(this.root, 0, 0, 0, e, t, i, this.tileSize);
  27794. }
  27795. }
  27796. TileTree.TraversalType = Object.freeze({
  27797. PreOrder: 0,
  27798. PostOrder: 1
  27799. });
  27800. TileTree.getLevelCountForSize = function (tileSize, size) {
  27801. //512->0 2024->1
  27802. var i = 0;
  27803. for (size < tileSize && (size = tileSize);;) {
  27804. if (size /= c, size < tileSize) break;
  27805. i++;
  27806. }
  27807. return i;
  27808. };
  27809. TileTree.getSizeForLevel = function (e, t) {
  27810. return Math.pow(c, t) * e;
  27811. };
  27812. var {
  27813. PanoSizeClass: PanoSizeClass$2,
  27814. PanoRendererEvents: PanoRendererEvents$1,
  27815. Vectors,
  27816. SceneRendererEvents,
  27817. TileDownloaderEvents: TileDownloaderEvents$1,
  27818. GLCubeFaces: GLCubeFaces$2
  27819. } = Potree.defines;
  27820. function createDescriptor() {
  27821. var e = {
  27822. renderTarget: null,
  27823. inUse: !1,
  27824. size: -1,
  27825. pano: null
  27826. };
  27827. return e;
  27828. }
  27829. /* function upload() {
  27830. if (!this.uploadIntervalCancelled) {
  27831. if (this.overlayTilesLoaded || !this.usingTileOverlay) {
  27832. b = !0
  27833. let maxNonBaseUploadsPerFrame = viewer.mainViewport.view.isFlying() ? 1 : this.maxNonBaseUploadsPerFrame //原先2。这是每帧uploadTile非512的瓦片tex的数量。之前的2太卡了,降为1。(检测卡顿方法:在一个pano点旋转至所有2048的tile都加载完,然后之后到这个点看看卡不卡。因为该点tiles都下载完了所以会在飞过来时陆续都加载,所以容易卡)
  27834. this.updateUploadQueue(maxNonBaseUploadsPerFrame, this.maxBaseUploadsPerFrame)
  27835. let time = viewer.mainViewport.view.isFlying() ? 60 : w //add 飞行有时候会卡,增长间隔
  27836. this.peekNextFromUploadQueue() ? this.refreshUploadInterval(time) : this.uploadInterval = null //定时下一次更新
  27837. } else {
  27838. this.refreshUploadInterval(this.uploadIntervalDelay)
  27839. }
  27840. }
  27841. } */
  27842. var b = !1,
  27843. w = config$1.tiling.uploadIntervalDelay,
  27844. _ = config$1.tiling.initialIntervalDelay,
  27845. T = config$1.tiling.maxNonBaseUploadsPerFrame,
  27846. //2 size>512的每次只upload这么多个
  27847. x$1 = config$1.tiling.maxBaseUploadsPerFrame,
  27848. //6
  27849. S = {
  27850. Base: 0,
  27851. Remaining: 1
  27852. }; /* ,
  27853. M = []; */
  27854. class PanoRenderer extends EventDispatcher {
  27855. constructor(viewer, tileDownloader, qualityManager) {
  27856. super();
  27857. this.tileDirectory = {};
  27858. this.activeRenderTargetDescriptors = {};
  27859. this.activePanos = [];
  27860. this.panoLODDescriptors = {};
  27861. this.panoDescriptors = {};
  27862. this.tileTrees = {};
  27863. this.forceQueue = [];
  27864. this.uploadQueues = {};
  27865. this.uploadInterval = null;
  27866. this.uploadIntervalCancelled = true; //!1;
  27867. this.usingTileOverlay = !1;
  27868. this.overlayTilesLoaded = !1;
  27869. this.overlayTileBase = null;
  27870. this.overlayTilesBasic = {};
  27871. this.overlayTilesEnhanced = {};
  27872. this.zoomRenderTarget = null; //用于缩放的rendertarget
  27873. this.zoomPano = null;
  27874. this.zoomingActive = !1;
  27875. this.zoomPanoId = null;
  27876. this.zoomPanoRenderingDisabled = !1;
  27877. this.direction = []; //new THREE.Vector3;
  27878. this.maxBaseUploadsPerFrame = x$1;
  27879. this.maxNonBaseUploadsPerFrame = T;
  27880. this.M = []; //move M to here 似乎列表里会有两个
  27881. this.viewer = viewer;
  27882. this.tileDownloader = tileDownloader;
  27883. this.qualityManager = qualityManager;
  27884. this.initTime = performance.now();
  27885. this.bindEvents();
  27886. }
  27887. getActivePanoTextures(e) {
  27888. e = e || [];
  27889. for (var t = 0; t < M.length; t++) {
  27890. var i = M[t];
  27891. i.renderTarget && i.renderTarget.texture && e.push(i.renderTarget.texture);
  27892. }
  27893. }
  27894. hasQueuedTiles() {
  27895. var e = this.peekNextFromUploadQueue();
  27896. return null !== e && void 0 !== e;
  27897. }
  27898. getActiveRenderTargetDescriptor(e) {
  27899. return this.activeRenderTargetDescriptors[e];
  27900. }
  27901. setActiveRenderTargetDescriptor(e, t) {
  27902. this.activeRenderTargetDescriptors[e] = t;
  27903. }
  27904. bindEvents() {
  27905. this.tileDownloader.addEventListener(TileDownloaderEvents$1.TileDownloadSuccess, this.onTileDownloaded.bind(this));
  27906. }
  27907. enableUltraHighQualityMode(e) {
  27908. if (config$1.tileClass == "2k" || config$1.tileClass == "1k") return this.enableHighQuality(e); //xzw add 濡傛灉鏈€澶氬彧瑕?k鐨勮瘽
  27909. if (!this.qualityManager.ultraHighQualityModeEnabled()) {
  27910. var t = this.qualityManager.getPanoSize(PanoSizeClass$2.ULTRAHIGH);
  27911. this.tileDownloader.testDownload(t, TileUtils.TILE_SIZE, function (t) {
  27912. t && (this.qualityManager.enableUltraHighQualityMode(), this.setupZoomRenderTarget(), e());
  27913. }.bind(this));
  27914. }
  27915. }
  27916. activateTiledPano(pano, size, i) {
  27917. i && this.clearAllQueuedUploads();
  27918. for (var n = 0; n < TileUtils.FACES_PER_PANO; n++) this.initTileTree(pano.id, n, this.qualityManager.getMaxPossiblePanoSize()); //得到this.tileTrees[pano.id],arr[6]
  27919. this.linkAllTilesAndNodes(pano);
  27920. var r = this.getActiveRenderTargetDescriptor(pano.id),
  27921. l = size;
  27922. l > this.qualityManager.getMaxNavPanoSize() && (l = this.qualityManager.getMaxNavPanoSize());
  27923. if (!r || l !== r.size) {
  27924. r && this.deactiveDescripor(r.renderTarget);
  27925. r = this.activeDescripor(l);
  27926. if (!r) {
  27927. var ren = this.initTiledPano(l, Potree.settings.disableAATarget ? false : !browser.isMobile()); //有的老设备如果抗锯齿打开场景时要多花五秒
  27928. r = this.initDescriptor(ren.width);
  27929. r.renderTarget = ren;
  27930. }
  27931. r.pano = pano;
  27932. this.resetPanoDescriptor(pano.id);
  27933. this.resetPanoLODDescriptors(pano.id);
  27934. this.resetRenderStatus(pano.id, !0, !0);
  27935. }
  27936. this.setActiveRenderTargetDescriptor(pano.id, r);
  27937. var h = i ? 0 : 1;
  27938. this.updateActivePanos(pano, h);
  27939. //console.log(`index:${this.viewer.index} ${r.renderTarget.texture.id} ${pano.id}`)
  27940. return r.renderTarget;
  27941. }
  27942. deactivateTiledPano(pano) {
  27943. var t = this.getActiveRenderTargetDescriptor(pano.id);
  27944. if (this.isRenderTargetDescriptorValid(t)) {
  27945. this.deactiveDescripor(t.renderTarget);
  27946. this.setActiveRenderTargetDescriptor(pano.id, null);
  27947. }
  27948. var i = this.getUploadQueueForPano(pano.id);
  27949. this.clearUploadQueue(i);
  27950. this.updateActivePanos();
  27951. viewer.cancelLoad(pano); //add
  27952. }
  27953. getActivePanoCount() {
  27954. return this.activePanos.length;
  27955. }
  27956. resetRenderStatus(e, t, i, n) {
  27957. var r = null;
  27958. n && (r = TileTree.getLevelCountForSize(TileUtils.TILE_SIZE, n) + 1);
  27959. for (var o = function o(e, n, r, _o) {
  27960. i && (n.tile.zoomUploaded = !1), t && (n.tile.uploaded = !1);
  27961. }, a = 0; a < TileUtils.FACES_PER_PANO; a++) {
  27962. var s = this.getTileTree(e, a);
  27963. s.breadthFirst({
  27964. callback: o.bind(this, a),
  27965. minLevel: r
  27966. });
  27967. }
  27968. }
  27969. copyBaseRenderStatusToZoomed(e) {
  27970. for (var t = TileTree.getLevelCountForSize(TileUtils.TILE_SIZE, this.qualityManager.getMaxNavPanoSize()), i = function i(e, t, _i, n) {
  27971. t.tile.zoomUploaded = t.tile.uploaded, t.zoomCovered = t.covered;
  27972. }, n = 0; n < TileUtils.FACES_PER_PANO; n++) {
  27973. var r = this.getTileTree(e, n);
  27974. r.breadthFirst({
  27975. callback: i.bind(this, n),
  27976. maxLevel: t
  27977. });
  27978. }
  27979. }
  27980. isRenderTargetDescriptorValid(e) {
  27981. return e && e.renderTarget;
  27982. }
  27983. isPanoActive(e) {
  27984. var t = this.getActiveRenderTargetDescriptor(e);
  27985. return this.isRenderTargetDescriptorValid(t);
  27986. }
  27987. isPanoZoomed(e) {
  27988. return this.zoomingActive && this.zoomPanoId === e;
  27989. }
  27990. initTileTree(e, t, i) {
  27991. var n = this.tileTrees[e];
  27992. n || (n = [], this.tileTrees[e] = n);
  27993. var r = n[t];
  27994. if (!r) {
  27995. var o = TileTree.getLevelCountForSize(TileUtils.TILE_SIZE, i);
  27996. r = new TileTree(TileUtils.TILE_SIZE, o), n[t] = r;
  27997. }
  27998. }
  27999. getTileTree(e, t) {
  28000. var i = this.tileTrees[e];
  28001. if (!i) console.error("PanoRenderer.getTileTree() -> Tree array not yet initialized!");
  28002. var n = i[t];
  28003. if (!n) console.error("PanoRenderer.getTileTree() -> Tree not yet initialized!");
  28004. return n;
  28005. }
  28006. /*
  28007. * 创建tile的renderTarget, 包括pano.tiledPanoRenderTarget和zoomRenderTarget
  28008. * @param {number} size 当前的panoSize,每个面的分辨率
  28009. */
  28010. initTiledPano(size, ifNormalFilter) {
  28011. //创建 RenderTargetCube
  28012. var renderer = this.viewer.renderer;
  28013. var renderTarget, texture;
  28014. renderTarget = new WebGLCubeRenderTarget(size, {
  28015. //THREE.WebGLRenderTargetCube(size, size, {
  28016. stencilBuffer: !1
  28017. });
  28018. texture = new CubeTexture([]);
  28019. texture.image = [null, null, null, null, null, null];
  28020. texture.flipY = !0, texture.format = RGBAFormat;
  28021. ifNormalFilter ? (texture.generateMipmaps = !0, texture.magFilter = LinearFilter, texture.minFilter = LinearMipMapLinearFilter) : (texture.generateMipmaps = !1, texture.magFilter = LinearFilter,
  28022. //LinearFilter更清晰,但锯齿噪点严重,相当于锐化,其实失真了。对于条纹状的画面移动镜头时锯齿明显 眩晕
  28023. texture.minFilter = LinearFilter);
  28024. //平时还是直接用LinearMipMapLinearFilter,其实并非不清晰,只是没有加锐化,像加了层柔光和抗锯齿,观感更好。放大后使用LinearFilter
  28025. // 如果抗锯齿的话,采用mipmap,会增加一倍的存储消耗。原版本都是不抗锯齿的。但是抗锯齿效果更柔和
  28026. renderTarget.texture = texture; //居然漏了一句,2022.10.9补
  28027. renderer.setRenderTarget(renderTarget);
  28028. renderer.setRenderTarget(null);
  28029. var o = renderer.properties.get(texture);
  28030. o.__image__webglTextureCube = o.__webglTexture;
  28031. //window.tex[r.id] = {texture:r, index:this.viewer.index }
  28032. return renderTarget;
  28033. }
  28034. getUploadQueueForPano(e) {
  28035. var t = this.uploadQueues[e];
  28036. return t || (t = [], this.uploadQueues[e] = t), t;
  28037. }
  28038. isTileUploaded(e) {
  28039. return this.isPanoZoomed(e.panoId) ? e.zoomUploaded : e.uploaded;
  28040. }
  28041. setUploaded(e, t) {
  28042. this.isPanoZoomed(e.panoId) ? e.zoomUploaded = t : e.uploaded = t;
  28043. }
  28044. queueTileUpload(e, t, i) {
  28045. var n = this.getActiveRenderTargetDescriptor(e.panoId);
  28046. if (this.isRenderTargetDescriptorValid(n) && e.downloaded && !this.isTileUploaded(e) && (!e.uploadQueued || i) && (!(e.panoSize > this.qualityManager.getMaxNavPanoSize()) || this.zoomingActive)) {
  28047. var r = this.getUploadQueueForPano(e.panoId);
  28048. //console.log(window.sceneName, 'queueTileUpload: ', e.panoId, e.tileIndex, i)
  28049. if (i) {
  28050. //console.log('512下载好了直接uploadTile')
  28051. this.uploadTile(e, !1); //提交后该tile直接loaded了,无需等待
  28052. } else {
  28053. if (this.shoulPushToFrontOfQueue(e)) {
  28054. //如果是512的优先
  28055. this.forceQueue.push(e);
  28056. } else {
  28057. if (t && this.direction) {
  28058. TilePrioritizer.insertSortedPanoTile(r, e, n.pano, this.direction);
  28059. } else r.push(e);
  28060. }
  28061. e.uploadQueued = !0;
  28062. this.uploadInterval || this.uploadIntervalCancelled || this.refreshUploadInterval(0);
  28063. }
  28064. }
  28065. }
  28066. shoulPushToFrontOfQueue(e) {
  28067. return 0 === TileTree.getLevelCountForSize(TileUtils.TILE_SIZE, e.panoSize);
  28068. }
  28069. getTopUploadQueue() {
  28070. for (var e = null, t = null, i = S.Base; i <= S.Remaining; i++) for (var n = 0; n < this.activePanos.length; n++) if (e = this.activePanos[n], t = this.getUploadQueueForPano(e.id), t.length > 0) switch (i) {
  28071. case S.Base:
  28072. if (0 === t[0].level) return t;
  28073. break;
  28074. case S.Remaining:
  28075. return t;
  28076. }
  28077. return null;
  28078. }
  28079. peekNextFromUploadQueue() {
  28080. if (this.forceQueue.length > 0) return this.forceQueue[0];
  28081. var e = this.getTopUploadQueue();
  28082. return e && e.length > 0 ? e[0] : null;
  28083. }
  28084. clearAllQueuedUploads() {
  28085. this.clearAllUploadQueues(null, 0);
  28086. }
  28087. clearAllQueuedUploadsForPano(e) {
  28088. this.clearAllUploadQueues(e, 0);
  28089. }
  28090. clearAllUploadQueues(e, t) {
  28091. if (e) this.clearUploadQueue(this.getUploadQueueForPano(e), t), this.clearUploadQueue(this.forceQueue, t, e);else {
  28092. for (var i = 0; i < this.activePanos.length; i++) {
  28093. var n = this.activePanos[i];
  28094. this.clearUploadQueue(this.getUploadQueueForPano(n.id), t);
  28095. }
  28096. this.clearUploadQueue(this.forceQueue, t);
  28097. }
  28098. }
  28099. clearUploadQueue(e, t, i) {
  28100. void 0 !== t && null !== t || (t = 0);
  28101. for (var n = 0; n < e.length;) {
  28102. var r = e[n];
  28103. (!i || i && i === r.tile.panoId) && r.level >= t ? (r.uploadQueued = !1, e.splice(n, 1)) : n++;
  28104. }
  28105. //若报错, r.tile.panoId改为 r.panoId
  28106. }
  28107. updateUploadQueue(maxNPF, maxPF /* e, t */) {
  28108. //参数是 maxNonBaseUploadsPerFrame and maxBaseUploadsPerFrame, 优先上传512
  28109. //maxNPF || (maxNPF = 1);
  28110. for (var i = 0, n = 0;;) {
  28111. //let old = this.forceQueue.slice(0)
  28112. if (n >= maxPF || i >= maxNPF) break;
  28113. var r = this.getNextFromUploadQueue();
  28114. if (!r) break;
  28115. //r.panoSize <2048 && console.log('panoId', r.panoId, 'panoSize', r.panoSize , old)
  28116. 0 !== r.level ? i++ : n++;
  28117. if (!(r.panoSize > this.qualityManager.getMaxNavPanoSize()) || this.zoomingActive) {
  28118. var o = this.getActiveRenderTargetDescriptor(r.panoId);
  28119. this.isRenderTargetDescriptorValid(o) && this.uploadTile(r, r.forceUpload);
  28120. }
  28121. }
  28122. }
  28123. updateDirection(e) {
  28124. if (e = e || this.direction) {
  28125. this.direction = e;
  28126. for (var t = 0; t < this.activePanos.length; t++) {
  28127. var i = this.activePanos[t],
  28128. n = this.getUploadQueueForPano(i.id);
  28129. TilePrioritizer.sortPanoTiles(n, i, this.direction);
  28130. }
  28131. }
  28132. }
  28133. anyUploaded(e) {
  28134. if (!e) return !1;
  28135. if (e.tile && this.isTileUploaded(e.tile)) return !0;
  28136. if (e.children) for (var t = 0; t < e.children.length; t++) {
  28137. var i = e.children[t];
  28138. if (this.anyUploaded(i)) return !0;
  28139. }
  28140. return !1;
  28141. }
  28142. setNodeCovered(e, t) {
  28143. this.isPanoZoomed(e.tile.panoId) ? e.zoomCovered = t : e.covered = t;
  28144. }
  28145. isNodeCovered(e) {
  28146. return !!e && (this.isPanoZoomed(e.tile.panoId) ? e.zoomCovered : e.covered);
  28147. }
  28148. addCoverageForNode(e) {
  28149. if (this.setNodeCovered(e, !0), e.parent && e.covered) {
  28150. var t = e.parent;
  28151. this.nodeSubcovered(t) && this.addCoverageForNode(t, !0);
  28152. }
  28153. }
  28154. calcFullCoverage(e) {
  28155. var t = !1;
  28156. if (e.children) for (var i = 0; i < e.children.length; i++) {
  28157. var n = e.children[i];
  28158. t = t || this.calcFullCoverage(n);
  28159. }
  28160. e.covered = e.tile.uploaded || t;
  28161. }
  28162. nodeSubcovered(e) {
  28163. if (!e.children) return !1;
  28164. for (var t = 0; t < e.children.length; t++) if (!e.children[t] || !this.isNodeCovered(e.children[t])) return !1;
  28165. return !0;
  28166. }
  28167. resetPanoDescriptor(e) {
  28168. this.getPanoDescriptor(e);
  28169. }
  28170. getPanoDescriptor(e) {
  28171. var t = this.panoDescriptors[e];
  28172. return t || (t = {}, this.panoDescriptors[e] = t), t;
  28173. }
  28174. resetPanoLODDescriptors(e) {
  28175. var t = this.getPanoLODDescriptors(e);
  28176. for (var i in t) if (t.hasOwnProperty(i)) {
  28177. var n = t[i];
  28178. n.uploadCount = 0, n.uploadAttempts = 0;
  28179. n.uploaded = [];
  28180. }
  28181. }
  28182. getPanoLODDescriptor(e, t) {
  28183. var i = this.getPanoLODDescriptors(e),
  28184. n = i[t];
  28185. return n || (n = {
  28186. uploadCount: 0,
  28187. uploadAttempts: 0,
  28188. uploaded: [] //add
  28189. }, i[t] = n), n;
  28190. }
  28191. getPanoLODDescriptors(e) {
  28192. var t = this.panoLODDescriptors[e];
  28193. return t || (t = {}, this.panoLODDescriptors[e] = t), t;
  28194. }
  28195. onTileDownloaded(o) {
  28196. var e = o.desc;
  28197. var t = TileTree.getLevelCountForSize(TileUtils.TILE_SIZE, e.panoSize),
  28198. i = this.getTileDirectoryEntry(e.panoId, e.face, t, e.faceTileIndex);
  28199. i.downloaded = !0;
  28200. i.image = e.image;
  28201. i.panoSize = e.panoSize;
  28202. i.tileX = e.tileX;
  28203. i.tileY = e.tileY;
  28204. i.totalTiles = e.totalTiles;
  28205. i.tileIndex = e.tileIndex;
  28206. i.faceTileIndex = e.faceTileIndex;
  28207. i.face = e.face;
  28208. i.cubeFace = TileUtils.mapFaceToCubemapFace(e.face);
  28209. i.panoId = e.panoId;
  28210. i.tileSize = e.tileSize;
  28211. i.direction = new Vector3().copy(e.direction);
  28212. i.node = null;
  28213. i.level = TileTree.getLevelCountForSize(TileUtils.TILE_SIZE, i.panoSize);
  28214. if (this.isPanoActive(i.panoId)) {
  28215. var n = this.getTileTree(i.panoId, i.face);
  28216. var r = n.getSubNode(i.panoSize, i.tileX, i.tileY);
  28217. this.linkTileAndNode(i, r);
  28218. this.queueTileUpload(i, !0);
  28219. }
  28220. }
  28221. getTileDirectoryEntry(panoId, t, i, n) {
  28222. var r = this.tileDirectory[panoId];
  28223. r || (r = {}, this.tileDirectory[panoId] = r);
  28224. var o = 16384 * t + 1024 * i + n,
  28225. //t:4096级别
  28226. a = r[o];
  28227. return a || (a = {
  28228. downloaded: !1,
  28229. uploaded: !1,
  28230. zoomUploaded: !1
  28231. }, r[o] = a), a._key = panoId + ":" + t + ":" + i + ":" + n,
  28232. //panoId : face : level : faceTileIndex
  28233. a._tileKey = o, a;
  28234. }
  28235. setZoomingActive(active, pano, i) {
  28236. //设置当前正在zoom的pano
  28237. this.zoomPanoRenderingDisabled || active === this.zoomingActive && this.zoomPanoId === pano.id || (this.zoomingActive = active, this.zoomPanoId = pano.id, this.zoomingActive && (this.zoomPanoId !== pano.id || i) && this.updateZoomedPanoFromBase(pano));
  28238. }
  28239. updateZoomedPanoFromBase(pano) {
  28240. //因更换pano所以将pano的rendertarget渲染到panoRenderer的zoomRenderTarget上
  28241. if (!this.zoomPanoRenderingDisabled) {
  28242. var t = this.getActiveRenderTargetDescriptor(pano.id);
  28243. if (t && t.renderTarget) {
  28244. if (this.zoomRenderTarget) {
  28245. var i = Math.min(this.qualityManager.maxRenderTargetSize, this.qualityManager.getMaxZoomPanoSize()),
  28246. //change
  28247. n = t.renderTarget,
  28248. r = t.size;
  28249. this.copyCubeMap(n.texture, this.zoomRenderTarget, r, r, i, i);
  28250. }
  28251. this.copyBaseRenderStatusToZoomed(pano.id);
  28252. }
  28253. }
  28254. }
  28255. add(e) {
  28256. this.M.push(e);
  28257. }
  28258. initDescriptor(size) {
  28259. var t = createDescriptor();
  28260. t.inUse = !0;
  28261. t.size = size;
  28262. this.add(t);
  28263. return t;
  28264. }
  28265. activeDescripor(e) {
  28266. for (var t = 0; t < this.M.length; t++) {
  28267. var i = this.M[t];
  28268. if (!i.inUse && i.size === e) {
  28269. i.inUse = !0;
  28270. return i;
  28271. }
  28272. }
  28273. return null;
  28274. }
  28275. deactiveDescripor(e) {
  28276. for (var t = 0; t < this.M.length; t++) {
  28277. var i = this.M[t];
  28278. if (i.renderTarget === e) {
  28279. i.inUse = !1;
  28280. return !0;
  28281. }
  28282. }
  28283. return !1;
  28284. }
  28285. enableHighQuality(e) {
  28286. //xzw add 如果最多只要2k图的话enableUltraHighQualityMode替换成这个
  28287. if (!this.qualityManager.highQualityModeStarted) {
  28288. this.setupZoomRenderTarget();
  28289. e();
  28290. //this.qualityManager.updateHighResolutionSettings(e)////////?
  28291. this.qualityManager.highQualityModeStarted = true;
  28292. }
  28293. }
  28294. linkTileAndNode(e, t) {
  28295. t.tile = e, e.node = t;
  28296. }
  28297. linkAllTilesAndNodes(e) {
  28298. var t = function t(_t, i, n, r, o) {
  28299. var a = this.getTileDirectoryEntry(e.id, i, r, o);
  28300. this.linkTileAndNode(a, n);
  28301. };
  28302. for (var i = 0; i < TileUtils.FACES_PER_PANO; i++) {
  28303. var n = this.getTileTree(e.id, i);
  28304. n.breadthFirst({
  28305. callback: t.bind(this, n, i)
  28306. });
  28307. }
  28308. }
  28309. //--------------sceneRenderer
  28310. initSizedTexture2D(e, t, i) {
  28311. var renderer = this.viewer.renderer,
  28312. o = renderer.getContext(),
  28313. a = renderer.state,
  28314. s = new Texture(null);
  28315. s.flipY = !1, i !== !0 && (i = !1), s.generateMipmaps = i;
  28316. var l = renderer.paramThreeToGL(s.format),
  28317. c = renderer.paramThreeToGL(s.type),
  28318. h = renderer.properties.get(s),
  28319. u = o.createTexture();
  28320. a.bindTexture(o.TEXTURE_2D, u), o.pixelStorei(o.UNPACK_FLIP_Y_WEBGL, s.flipY), o.texImage2D(o.TEXTURE_2D, 0, l, e, e, 0, l, c, null), s.wrapS = t, s.wrapT = t;
  28321. var d = renderer.paramThreeToGL(t);
  28322. return o.texParameteri(o.TEXTURE_2D, o.TEXTURE_WRAP_S, d), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_WRAP_T, d), i ? (s.magFilter = LinearFilter, s.minFilter = LinearMipMapLinearFilter, o.texParameteri(o.TEXTURE_2D, o.TEXTURE_MAG_FILTER, o.LINEAR), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_MIN_FILTER, o.LINEAR_MIPMAP_NEAREST), o.generateMipmap(o.TEXTURE_2D)) : (s.magFilter = LinearFilter, s.minFilter = LinearFilter, o.texParameteri(o.TEXTURE_2D, o.TEXTURE_MAG_FILTER, o.LINEAR), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_MIN_FILTER, o.LINEAR)), a.bindTexture(o.TEXTURE_2D, null), h.__webglTexture = u, s;
  28323. }
  28324. deallocateCubeTexture(e) {
  28325. var t = this.viewer.renderer,
  28326. i = t.getContext(),
  28327. renderer = t.properties.get(e);
  28328. i.deleteTexture(renderer.__image__webglTextureCube);
  28329. }
  28330. uploadTexture2D(img, tex, startX, startY, width, height) {
  28331. var renderer = this.viewer.renderer,
  28332. gl = renderer.getContext(),
  28333. webglState = renderer.state,
  28334. c = renderer.properties.get(tex);
  28335. webglState.bindTexture(gl.TEXTURE_2D, c.__webglTexture), gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, tex.flipY), gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, tex.premultiplyAlpha), gl.pixelStorei(gl.UNPACK_ALIGNMENT, tex.unpackAlignment), gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, renderer.paramThreeToGL(tex.wrapS)), gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, renderer.paramThreeToGL(tex.wrapT)), gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, renderer.paramThreeToGL(tex.magFilter)), gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, renderer.paramThreeToGL(tex.minFilter)), gl.texSubImage2D(gl.TEXTURE_2D, 0, startX, startY, gl.RGBA, gl.UNSIGNED_BYTE, img), tex.generateMipmaps && gl.generateMipmap(gl.TEXTURE_2D), webglState.bindTexture(gl.TEXTURE_2D, null);
  28336. }
  28337. getCubeOrientationForCubeFace(e, t) {
  28338. switch (e) {
  28339. case GLCubeFaces$2.GL_TEXTURE_CUBE_MAP_POSITIVE_X:
  28340. t.set(0, -Math.PI / 2, 0);
  28341. break;
  28342. case GLCubeFaces$2.GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
  28343. t.set(0, Math.PI / 2, 0);
  28344. break;
  28345. case GLCubeFaces$2.GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
  28346. t.set(Math.PI / 2, Math.PI, 0);
  28347. break;
  28348. case GLCubeFaces$2.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
  28349. t.set(-Math.PI / 2, Math.PI, 0);
  28350. break;
  28351. case GLCubeFaces$2.GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
  28352. t.set(0, -Math.PI, 0);
  28353. break;
  28354. case GLCubeFaces$2.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
  28355. t.set(0, 0, 0);
  28356. }
  28357. }
  28358. //dispose所有cubeRenderTarget
  28359. disposeIdelTargets() {
  28360. var disposeCount = 0;
  28361. for (var t = 0; t < this.M.length; t++) {
  28362. var i = this.M[t];
  28363. if (!i.inUse) {
  28364. disposeCount++;
  28365. i.renderTarget.dispose();
  28366. }
  28367. }
  28368. //console.log('disposeIdelTargets ', disposeCount, 'of', this.M.length)
  28369. }
  28370. }
  28371. PanoRenderer.prototype.setupZoomRenderTarget = function () {
  28372. var targets = {};
  28373. return function () {
  28374. if (this.qualityManager.maxRenderTargetSize == 2048 && this.qualityManager.getMaxNavPanoSize() == 2048) return; //不使用zoomTarget 直接用pano的tiledPanoRenderTarget,防崩溃
  28375. if (this.qualityManager.getMaxZoomPanoSize() >= this.qualityManager.getMaxNavPanoSize()) {
  28376. //部分手机2k时copyCubeMap会重载 , 所以如果没有超出当前分辨率,就不使用zoomRenderTarget。但在微信依旧会重载,只是优化了些,safari几乎不会。
  28377. if (this.zoomRenderTarget && this.zoomRenderTarget.width === this.qualityManager.getMaxZoomPanoSize()) return;
  28378. var e = this.zoomRenderTarget;
  28379. var size = this.qualityManager.getMaxZoomPanoSize();
  28380. if (size > this.qualityManager.maxRenderTargetSize) {
  28381. return;
  28382. }
  28383. if (targets[size]) {
  28384. this.zoomRenderTarget = targets[size];
  28385. } else {
  28386. this.zoomRenderTarget = this.initTiledPano(size, false); //放大后不使用抗锯齿,否则消
  28387. targets[size] = this.zoomRenderTarget;
  28388. }
  28389. if (e) {
  28390. //将旧的zoomRenderTarget渲染到新zoomRenderTarget上
  28391. var t = e.width,
  28392. i = this.zoomRenderTarget.width;
  28393. this.copyCubeMap(e.texture, this.zoomRenderTarget, t, t, i, i), e.texture.dispose(), e.texture.loaded = !1, e.texture.version = 0, this.deallocateCubeTexture(e.texture), e.texture = null;
  28394. }
  28395. this.zoomPanoRenderingDisabled = !1;
  28396. } else this.zoomPanoRenderingDisabled = !0;
  28397. };
  28398. }();
  28399. PanoRenderer.prototype.updateActivePanos = function () {
  28400. var e = [];
  28401. return function (t, i) {
  28402. e.length = 0;
  28403. for (var n = 0; n < this.activePanos.length; n++) {
  28404. t && e.length === i && e.push(t);
  28405. var r = this.activePanos[n],
  28406. o = this.getActiveRenderTargetDescriptor(r.id);
  28407. t && r.id === t.id || !this.isRenderTargetDescriptorValid(o) || e.push(r);
  28408. }
  28409. t && i >= e.length && e.push(t), this.activePanos.length = 0, this.activePanos.push.apply(this.activePanos, e);
  28410. };
  28411. }();
  28412. PanoRenderer.prototype.renderPanoTiles = function () {
  28413. var e = [];
  28414. return function (panoId, i, n, r) {
  28415. this.zoomRenderTarget && this.zoomRenderTarget.width === this.qualityManager.getMaxZoomPanoSize() || this.zoomPanoRenderingDisabled || this.setupZoomRenderTarget(),
  28416. //如果ZoomRenderTarget大小需要变动就重新创建
  28417. i = i || this.direction || Vectors.FORWARD; // [{1:Vectors.FORWARD}]?
  28418. var o = this.getActiveRenderTargetDescriptor(panoId);
  28419. if (!this.isRenderTargetDescriptorValid(o)) console.error("PanoRenderer.renderPanoTiles() -> Cannot render to a pano that is not activated.");
  28420. for (var a = 0; a < TileUtils.FACES_PER_PANO; a++) {
  28421. var s = this.getTileTree(panoId, a);
  28422. e.length = 0;
  28423. s.breadthFirst({
  28424. //获取该面所有node 85个 = 1+4+16+64
  28425. saveVisited: e
  28426. });
  28427. for (var l = 0; l < e.length; l++) {
  28428. var c = e[l];
  28429. this.queueTileUpload(c.tile, !1, r || 0 === l && n); // 第0个是512的,会直接uploadTile
  28430. }
  28431. }
  28432. this.updateDirection(i);
  28433. };
  28434. }();
  28435. PanoRenderer.prototype.getNextFromUploadQueue = function () {
  28436. var e = function e(_e) {
  28437. var t = _e.shift();
  28438. return t.uploadQueued = !1, t;
  28439. };
  28440. return function () {
  28441. if (this.forceQueue.length > 0) return e(this.forceQueue);
  28442. var t = this.getTopUploadQueue();
  28443. return t && t.length > 0 ? e(t) : null;
  28444. };
  28445. }();
  28446. /* PanoRenderer.prototype.refreshUploadInterval = function () {
  28447. var e = null;
  28448. return function (t) {
  28449. this.uploadIntervalCancelled || (e || (e = upload.bind(this)),
  28450. null !== t && void 0 !== t || (t = w),
  28451. b || (t = _),
  28452. this.uploadInterval = window.setTimeout(e, t),
  28453. this.uploadIntervalDelay = t)
  28454. }
  28455. }()
  28456. PanoRenderer.prototype.update = function () {
  28457. var e = performance.now(),
  28458. t = 0;
  28459. return function () {
  28460. this.uploadIntervalCancelled = !0;
  28461. window.clearTimeout(this.uploadInterval);
  28462. this.uploadInterval = null;
  28463. var i = performance.now() - e;
  28464. //!(i > w || 0 === t) || !this.overlayTilesLoaded && this.usingTileOverlay || (this.updateUploadQueue(this.maxNonBaseUploadsPerFrame, this.maxBaseUploadsPerFrame),
  28465. //e = performance.now()),
  28466. if (!(i > w || 0 === t) || !this.overlayTilesLoaded && this.usingTileOverlay) {} else {
  28467. this.updateUploadQueue(this.maxNonBaseUploadsPerFrame, this.maxBaseUploadsPerFrame);
  28468. e = performance.now();
  28469. }
  28470. t++;
  28471. }
  28472. }() */
  28473. PanoRenderer.prototype.update = function () {
  28474. //this.uploadIntervalCancelled = true ; //不使用setTimeout,而是在sceneRenderer每帧都update
  28475. if (viewer.images360.latestRequestMode == 'showPanos') {
  28476. var maxNonBaseUploadsPerFrame = viewer.lastFrameChanged ? Common.getBestCount('maxStandard', 0, 2, 1, 10 /* ,true */) : 2; // 这是每帧uploadTile非512的瓦片tex的数量。 手机在前进时可能会总是0,直到到漫游点后为2
  28477. var maxBaseUploadsPerFrame = viewer.lastFrameChanged ? Common.getBestCount('maxBase', 1, 6, 1, 14 /* ,true */) : 6; //this.maxBaseUploadsPerFrame //原先6. 但持续前进过程中会请求加载下一个漫游图,一次加6张会卡的。
  28478. this.updateUploadQueue(maxNonBaseUploadsPerFrame, maxBaseUploadsPerFrame);
  28479. //注:静止时看不出卡顿所以全速加载
  28480. }
  28481. };
  28482. /* function upload() {
  28483. if (!this.uploadIntervalCancelled) {
  28484. if (this.overlayTilesLoaded || !this.usingTileOverlay) {
  28485. b = !0
  28486. let maxNonBaseUploadsPerFrame = viewer.mainViewport.view.isFlying() ? 1 : this.maxNonBaseUploadsPerFrame //原先2。这是每帧uploadTile非512的瓦片tex的数量。之前的2太卡了,降为1。(检测卡顿方法:在一个pano点旋转至所有2048的tile都加载完,然后之后到这个点看看卡不卡。因为该点tiles都下载完了所以会在飞过来时陆续都加载,所以容易卡)
  28487. this.updateUploadQueue(maxNonBaseUploadsPerFrame, this.maxBaseUploadsPerFrame)
  28488. let time = viewer.mainViewport.view.isFlying() ? 60 : w //add 飞行有时候会卡,增长间隔
  28489. this.peekNextFromUploadQueue() ? this.refreshUploadInterval(time) : this.uploadInterval = null //定时下一次更新
  28490. } else {
  28491. this.refreshUploadInterval(this.uploadIntervalDelay)
  28492. }
  28493. }
  28494. } */
  28495. PanoRenderer.prototype.uploadTile = function () {
  28496. //重写
  28497. var collection = {},
  28498. overlayStyle = config$1.tiling.overlayStyle;
  28499. var failHistory = {};
  28500. return function (info, n) {
  28501. var id = info.panoId,
  28502. img = info.image,
  28503. tileSize = info.tileSize,
  28504. panoSize = info.panoSize,
  28505. tileIndex = info.tileIndex,
  28506. totalTiles = info.totalTiles,
  28507. tileX = info.tileX,
  28508. tileY = info.tileY,
  28509. p = !0,
  28510. g = !1,
  28511. ignore = false,
  28512. //add
  28513. LodDescripor = (this.getPanoDescriptor(id), this.getPanoLODDescriptor(id, panoSize)),
  28514. activeDescripor = this.getActiveRenderTargetDescriptor(id),
  28515. renderTarget = activeDescripor.renderTarget,
  28516. size = activeDescripor.size; //当前要渲染的面的分辨率,也就是MaxNavPanoSize
  28517. if (this.isPanoZoomed(id) && this.zoomRenderTarget) {
  28518. renderTarget = this.zoomRenderTarget;
  28519. size = this.zoomRenderTarget.width; //this.qualityManager.getMaxZoomPanoSize(); //放大后可能2048或4096
  28520. }
  28521. //console.log(window.sceneName, 'uploadTile ', id, tileIndex)
  28522. var done = () => {
  28523. if (!LodDescripor.uploaded.includes(tileIndex)) {
  28524. //已经upload过(本来这时候直接返回,但发现缩放后这不会归零,导致清晰度不更新,所以还是redraw且emit吧)
  28525. //console.log('try to reupload and return',tileIndex)
  28526. LodDescripor.uploaded.push(tileIndex);
  28527. LodDescripor.uploadCount++;
  28528. }
  28529. this.dispatchEvent({
  28530. type: PanoRendererEvents$1.TileRenderSuccess,
  28531. id,
  28532. panoSize,
  28533. tileIndex,
  28534. totalTiles
  28535. });
  28536. LodDescripor.uploadCount === totalTiles && this.dispatchEvent({
  28537. type: PanoRendererEvents$1.PanoRenderComplete,
  28538. id,
  28539. panoSize,
  28540. totalTiles,
  28541. updateFullComplete: true
  28542. });
  28543. this.setUploaded(info, !0);
  28544. this.addCoverageForNode(info.node);
  28545. };
  28546. {
  28547. //已经uploadTile过了不再uploadTile
  28548. if (!this.isRenderTargetDescriptorValid(activeDescripor)) {
  28549. p = !1;
  28550. g = !1;
  28551. }
  28552. if (!n) {
  28553. this.anyUploaded(info.node) && (p = !1, g = !0, ignore = true); //包括子集也uploadTile了
  28554. this.isTileUploaded(info) && (p = !1, g = !1, ignore = true); //当前tile uploadTile了
  28555. }
  28556. }
  28557. if (p) {
  28558. /*if(failHistory[id+':'+ panoSize+ ':' +tileIndex]){
  28559. console.log('uploadTile retry',id, panoSize, tileIndex)
  28560. }
  28561. console.log('uploadTile 成功', id, panoSize, tileIndex) */
  28562. var C = tileX * tileSize,
  28563. I = tileY * tileSize,
  28564. E = tileSize / panoSize * size,
  28565. // tile在renderTarget上渲染出的宽度
  28566. b = C / panoSize * size,
  28567. // tile在renderTarget上渲染的startX
  28568. w = I / panoSize * size; // tile在renderTarget上渲染的startY
  28569. if (panoSize > this.qualityManager.maxRenderTargetSize) {
  28570. //4096 改
  28571. /* var tex = this.initSizedTexture2D(tileSize, THREE.ClampToEdgeWrapping);
  28572. var loaded = this.viewer.images360.isHighMapLoaded(info.cubeFace, tileX,tileY) */
  28573. this.viewer.images360.getHighImage(img, info.cubeFace, tileX, tileY);
  28574. } else {
  28575. collection[tileSize] || (collection[tileSize] = this.initSizedTexture2D(tileSize, ClampToEdgeWrapping));
  28576. var tex = collection[tileSize];
  28577. this.uploadTexture2D(img, tex, 0, 0, tileSize, tileSize); //只替换tex对应的img,不新建
  28578. if (panoSize > this.qualityManager.maxRenderTargetSize) {
  28579. loaded || this.viewer.images360.updateHighMap(tex, info.cubeFace, tileX, tileY);
  28580. } else {
  28581. if (1 === overlayStyle || 2 === overlayStyle) {
  28582. var T = 1 === overlayStyle ? this.overlayTilesBasic : this.overlayTilesEnhanced;
  28583. this.renderToCubeMap(tex, renderTarget, tileSize, tileSize, 0, 0, tileSize, tileSize, b, w, E, E, info.cubeFace);
  28584. this.renderToCubeMap(T[panoSize], renderTarget, tileSize, tileSize, 0, 0, tileSize, tileSize, b, w, E, E, info.cubeFace, NormalBlending, !0, .5);
  28585. } else {
  28586. this.renderToCubeMap(tex, renderTarget, tileSize, tileSize, 0, 0, tileSize, tileSize, b, w, E, E, info.cubeFace);
  28587. }
  28588. }
  28589. }
  28590. done();
  28591. } else if (ignore) {
  28592. //console.log('finish because anyUploaded',id,panoSize,tileIndex)
  28593. done(); //改: 如果因为这部分更高清的贴图已加载所以才不绘制的话,直接完成
  28594. } else {
  28595. //console.log('uploadTile 失败', id, panoSize, tileIndex)
  28596. if (panoSize == 512) {
  28597. //console.log("!!!!!!!!!!!!!")
  28598. }
  28599. failHistory[id + ':' + panoSize + ':' + tileIndex] = true;
  28600. this.setUploaded(info, !1);
  28601. }
  28602. info.uploadAttempted || (LodDescripor.uploadAttempts++, this.dispatchEvent({
  28603. type: PanoRendererEvents$1.TileUploadAttempted,
  28604. id,
  28605. panoSize,
  28606. tileIndex,
  28607. totalTiles
  28608. })), info.uploadAttempted = !0;
  28609. LodDescripor.uploadAttempts === totalTiles && this.dispatchEvent({
  28610. type: PanoRendererEvents$1.UploadAttemptedForAllTiles,
  28611. id,
  28612. panoSize,
  28613. totalTiles
  28614. });
  28615. return g;
  28616. };
  28617. }();
  28618. /*
  28619. 注:tileY的方向同UV,从下到上
  28620. renderToCubeMap里的画布or镜头的xy范围是-0.5到0.5
  28621. */
  28622. PanoRenderer.prototype.renderToCubeMap = function () {
  28623. var inited = !1,
  28624. scene = null,
  28625. camera = null,
  28626. material = null,
  28627. geo = null,
  28628. plane = null,
  28629. l = 1;
  28630. return function (texture, renderTarget, tileWidth, tileHeight, startXinTile, startYinTile, widthinTile, heightinTile, startX, startY, width, height, cubeFace, E, b, w) {
  28631. var renderer = this.viewer.renderer;
  28632. inited || (camera = new OrthographicCamera(l / -2, l / 2, l / 2, l / -2, -200, 200), camera.position.z = 150, scene = new Scene(), scene.add(camera), material = new BasicMaterial({
  28633. depthWrite: !1,
  28634. depthTest: !1,
  28635. side: 0
  28636. }), geo = new PlaneBufferGeometry(l, l), plane = new Mesh(geo, material), plane.position.z = 0, scene.add(plane), inited = !0);
  28637. var uv = geo.getAttribute("uv");
  28638. uv.setDynamic(!0),
  28639. //setUsage
  28640. uv.needsUpdate = !0;
  28641. var uvArr = uv.array,
  28642. S = startXinTile / tileWidth,
  28643. //uv这几个值基本是固定的startXinTile:0,startYinTile:0,widthinTile:512,widthinTile:512,tileWidth:512,tileHeight:512 也就是说uv不会变、每张tile的有效范围是100%
  28644. M = startYinTile / tileHeight,
  28645. R = widthinTile / tileWidth,
  28646. P = heightinTile / tileHeight;
  28647. uvArr[0] = S, uvArr[1] = M + P, uvArr[2] = S + R, uvArr[3] = M + P, uvArr[4] = S, uvArr[5] = M, uvArr[6] = S + R, uvArr[7] = M;
  28648. //修改posistion,使该plane只占据需要绘制的部分。类似拼图。
  28649. //startX startY width height 都是在画布上的大小,比如画布大小为2048*2048,此tile为16分之一,tileX是1,tileY是1,则startX=2048/4,startY=2048/4
  28650. var pos = geo.getAttribute("position");
  28651. pos.setDynamic(!0), pos.needsUpdate = !0;
  28652. var posArr = pos.array,
  28653. D = startX / renderTarget.width - l / 2 // 起始x
  28654. ,
  28655. N = startY / renderTarget.height - l / 2 // 起始y
  28656. ,
  28657. B = width / renderTarget.width // 宽
  28658. ,
  28659. F = height / renderTarget.height; // 高
  28660. posArr[0] = D, posArr[1] = N + F, posArr[3] = D + B, posArr[4] = N + F, posArr[6] = D, posArr[7] = N, posArr[9] = D + B, posArr[10] = N;
  28661. //renderer.properties.get(scene);
  28662. material.map = texture; //material.uniforms.map.value = texture;
  28663. material.blending = E || NoBlending, material.transparent = !!b;
  28664. void 0 !== w && null !== w || (w = 1), material.uniforms.opacity.value = w,
  28665. // material.needUpdate = !0
  28666. //renderTarget.activeCubeFace = cubeFace, //0-5 应该是指定渲染h中的面 失效
  28667. /* renderer.setScissorTest(!0)
  28668. //指定绘制区域,类似遮罩(相对于屏幕)
  28669. renderer.setScissor(startX,startY,width,height) //加上这个会不会快一些,尤其是spherical
  28670. //指定绘制视口位置和大小(相对于屏幕)
  28671. */
  28672. renderTarget.viewport.set(0, 0, renderTarget.width, renderTarget.height);
  28673. var V = renderer.autoClear;
  28674. var oldTarget = renderer.getRenderTarget();
  28675. renderer.autoClear = !1;
  28676. renderer.setRenderTarget(renderTarget, cubeFace);
  28677. renderer.render(scene, camera /* , renderTarget, !1 */);
  28678. renderer.setRenderTarget(oldTarget);
  28679. renderer.autoClear = V;
  28680. //renderer.setScissorTest(!1)
  28681. /* this.renderer.render(scene, camera, this.planeTargets[cubeFace], !1),//针对有的场景app第一个点图加载不成功的问题
  28682. console.log(`图index ${cubeFace} , ${startX}, ${startY}, ${width}, ${height}`)
  28683. this.targetList[cubeFace] || (this.targetList[cubeFace] = [])
  28684. this.targetList[cubeFace].push([startX,startY,width,height])*/
  28685. };
  28686. }();
  28687. /*
  28688. * 将texture渲染到zoomRenderTarget上(目的是复制贴图到zoomRenderTarget)
  28689. */
  28690. PanoRenderer.prototype.copyCubeMap = function () {
  28691. //将texture渲染到zoomRenderTarget上
  28692. var inited = !1,
  28693. scene = null,
  28694. camera = null,
  28695. material = null,
  28696. geo = null,
  28697. mesh = null,
  28698. testCube = null,
  28699. //add
  28700. c = new Euler();
  28701. return function (texture, renderTarget, tWidth, tHeight, rWidth, rHeight, m, v, A) {
  28702. if (rWidth > this.qualityManager.maxRenderTargetSize) return; //add
  28703. if (!inited) {
  28704. var w = 2;
  28705. camera = new OrthographicCamera(w / -2, w / 2, w / 2, w / -2, 0, 200), camera.position.set(0, 0, 0), scene = new Scene(), scene.add(camera);
  28706. material = new ShaderMaterial({
  28707. uniforms: {
  28708. tDiffuse: {
  28709. type: "t",
  28710. value: null
  28711. },
  28712. alpha: {
  28713. type: "f",
  28714. value: 1
  28715. }
  28716. },
  28717. vertexShader: Shaders['copyCubeMap.vs'],
  28718. fragmentShader: Shaders['copyCubeMap.fs'],
  28719. depthWrite: !1,
  28720. depthTest: !1,
  28721. side: DoubleSide
  28722. });
  28723. geo = new BoxGeometry(w, w, w), mesh = new Mesh(geo, material), scene.add(mesh);
  28724. inited = !0;
  28725. /* testCube = mesh.clone();
  28726. viewer.scene.scene.add(testCube);
  28727. Potree.Utils.setObjectLayers(testCube, 'sceneObjects')
  28728. */
  28729. }
  28730. var autoClear = this.viewer.renderer.autoClear;
  28731. var oldTarget = this.viewer.renderer.getRenderTarget();
  28732. this.viewer.renderer.autoClear = false;
  28733. material.uniforms.tDiffuse.value = texture;
  28734. material.blending = m || NoBlending;
  28735. material.transparent = !!v;
  28736. void 0 !== A && null !== A || (A = 1);
  28737. material.uniforms.alpha.value = A;
  28738. material.needUpdate = !0;
  28739. for (var C = 0; C < 6; C++) {
  28740. this.getCubeOrientationForCubeFace(C, c);
  28741. mesh.rotation.copy(c);
  28742. mesh.matrixWorldNeedsUpdate = !0;
  28743. mesh.updateMatrixWorld();
  28744. renderTarget.viewport.set(0, 0, rWidth, rHeight);
  28745. this.viewer.renderer.setRenderTarget(renderTarget, C); //renderTarget.activeCubeFace = C//失效
  28746. this.viewer.renderer.render(scene, camera);
  28747. }
  28748. //console.warn('copyCubeMap' + rWidth)
  28749. this.viewer.renderer.autoClear = autoClear;
  28750. this.viewer.renderer.setRenderTarget(oldTarget);
  28751. };
  28752. }();
  28753. class DepthImageSampler extends EventDispatcher {
  28754. constructor() {
  28755. super();
  28756. var canvas = document.createElement("canvas");
  28757. this.canvas = canvas;
  28758. this.context = canvas.getContext("2d", {
  28759. willReadFrequently: true
  28760. });
  28761. this.imgDatas = [];
  28762. /* document.getElementsByTagName('body')[0].appendChild(canvas);
  28763. canvas.style.position = 'fixed';
  28764. canvas.style.width = '1024px';
  28765. canvas.style.top = canvas.style.left = 0
  28766. canvas.style['z-index'] = 100
  28767. */
  28768. this.maxDataCount = browser.isMobile() ? 6 : 20; //手机会崩溃. 平均每张图为8M数据量(以200个点的园区为例,加载时间久一些后,总内存=700 + 每张图的8M * maxDataCount)
  28769. this.maxNeighCount = browser.isMobile() ? 3 : 14; //包含在maxDataCount内的nearPanos最大个数.至少比maxDataCount少3个,留出空位给最近更新的pano
  28770. this.nearPanos = [];
  28771. }
  28772. updateNearPanos(panos) {
  28773. this.nearPanos = panos.slice(0, this.maxNeighCount);
  28774. }
  28775. changeImg(img, pano) {
  28776. this.pano = pano;
  28777. var item = this.imgDatas.find(p => p.pano == pano);
  28778. if ( /* this.img == img || */item) {
  28779. //最新的在末尾,所以换到末尾
  28780. var index = this.imgDatas.indexOf(item);
  28781. this.imgDatas.splice(index, 1);
  28782. this.imgDatas.push(item);
  28783. //console.log('重复使用',item.pano.id)
  28784. return;
  28785. }
  28786. Potree.timeCollect.depthSamChangeImg.start = true; //不过在刚启动时得到的用时较大
  28787. try {
  28788. viewer.addTimeMark('depthSamChangeImg', 'start');
  28789. this.canvas.width = img.width;
  28790. this.canvas.height = img.height;
  28791. this.context.drawImage(img, 0, 0);
  28792. var o = this.context.getImageData(0, 0, img.width, img.height);
  28793. var data = o && o.data; //getImageData 1px时 : pc chrome 耗时0.01毫秒左右(排除第一次的50) , 但firefox: 4。但换贴图之后就多达5甚至几十
  28794. //console.log('changeImg',pano.id )
  28795. //this.img = img
  28796. if (!data) {
  28797. console.error('getImageData 得不到?!why!');
  28798. return false;
  28799. }
  28800. if (this.imgDatas.length >= this.maxDataCount) {
  28801. var old = this.imgDatas.find(e => !this.nearPanos.includes(e.pano));
  28802. //console.log('推出',old.pano.id)
  28803. this.imgDatas.splice(this.imgDatas.indexOf(old), 1); //推出使用时间最早的一个非nearPano
  28804. }
  28805. this.imgDatas.push({
  28806. pano,
  28807. data
  28808. });
  28809. this.dispatchEvent({
  28810. type: 'changeImg',
  28811. pano
  28812. });
  28813. viewer.addTimeMark('depthSamChangeImg', 'end'); //耗时chrome 25ms,firefox: 38ms, iphoneX:33ms
  28814. } catch (e) {
  28815. console.error(e); //内存不足 Failed to execute 'getImageData' on 'CanvasRenderingContext2D': Out of memory at ImageData creation
  28816. return false;
  28817. }
  28818. /* pano.depthData = {}
  28819. for(let h=0; h<img.height; h++){
  28820. for(let w=0; w<img.width; w++){
  28821. let blockIndex = img.width * h + w
  28822. let r = data.slice(blockIndex*4, (blockIndex+1)*4)
  28823. let depth = r[1] + r[0] / 256
  28824. if(depth>0) pano.depthData[h+'|'+w] = depth
  28825. }
  28826. } */
  28827. }
  28828. clearTexData() {
  28829. this.imgDatas.length = 0;
  28830. }
  28831. getDepth(UVx, UVy, useNeighIfZero) {
  28832. //根据图片像素获取深度值
  28833. var x = Math.round(UVx * (this.canvas.width - 1)),
  28834. y = Math.round(UVy * (this.canvas.height - 1));
  28835. var imgData = this.imgDatas.find(p => p.pano == this.pano);
  28836. var get = (x, y) => {
  28837. if (!(x < 0 || y < 0 || x >= this.canvas.width || y >= this.canvas.height)) {
  28838. var blockIndex = this.canvas.width * y + x;
  28839. var color = imgData.data.slice(blockIndex * 4, (blockIndex + 1) * 4);
  28840. return color[1] + color[0] / 256; //为什么不是除以255见聊天记录.(验证过比点云的远一点点)
  28841. }
  28842. };
  28843. /* viewer.addTimeMark('depthSampler','start')
  28844. var r = this.context.getImageData(x, y, 1, 1).data; //pc chrome 耗时0.01毫秒左右(排除第一次的50) , 但firefox: 4。但换贴图之后就多达5甚至几十
  28845. viewer.addTimeMark('depthSampler','end')
  28846. */
  28847. var depth = get(x, y);
  28848. if (!depth && useNeighIfZero) {
  28849. //遇到过有的相隔很远且有阻挡的两个漫游点间居然depth为0,没有阻挡?但是周围点有四个非零。所以为了修正会飞到很远的点加个识别周围像素的depth 。 2024.3.19
  28850. var results = [];
  28851. var d = 0,
  28852. sum = 0,
  28853. count = 0,
  28854. maxResDis = 1;
  28855. while (d++ < maxResDis) {
  28856. for (var i = -d; i <= d; i++) {
  28857. for (var j = -d; j <= d; j++) {
  28858. if (i == -d || i == d || j == -d || j == d) {
  28859. //外围
  28860. var depth1 = get(x + i, y + j);
  28861. if (depth1 != 0) {
  28862. results.push(depth1);
  28863. }
  28864. }
  28865. }
  28866. }
  28867. }
  28868. if (results.length) {
  28869. depth = results.reduce((w, c) => {
  28870. return w + c;
  28871. }, 0) / results.length;
  28872. //console.error('useNeighIfZero', results, depth)
  28873. }
  28874. //console.log('useNeighIfZero', results, depth)
  28875. }
  28876. return depth;
  28877. }
  28878. sample(intersect, currentPano, onlyPos, useNeighIfZero) {
  28879. //通过和skybox的intersect得到真实的intersect的位置
  28880. if (!intersect) return;
  28881. var location = new Vector3();
  28882. var normal;
  28883. currentPano = currentPano || viewer.images360.currentPano;
  28884. if (currentPano != this.currentPano || !this.imgDatas.find(p => p.pano == currentPano)) {
  28885. if (!currentPano.depthTex /* || !currentPano.depthTex.image */) return; //未加载
  28886. if (this.changeImg(currentPano.depthTex.image, currentPano) === false) {
  28887. console.log('失败', currentPano.id);
  28888. return false; //失败
  28889. }
  28890. this.currentPano = currentPano;
  28891. }
  28892. var origin = currentPano.position;
  28893. var dir = intersect.dir || new Vector3().subVectors(intersect.point, origin).normalize();
  28894. //var uv = intersect.uv
  28895. //let dirInPano = math.getNormalDir(dir, currentPano)//转化为考虑漫游点旋转的方向
  28896. var dirInPano = dir.clone().applyMatrix4(currentPano.panoMatrix2Inverse).normalize(); //转化为考虑漫游点旋转的方向
  28897. var uv = math.getUVfromDir(dirInPano); //转化为uv
  28898. var distance = this.getDepth(uv.x, uv.y, useNeighIfZero);
  28899. //viewer.addTimeMark(markName,'end')
  28900. if (!distance) {
  28901. var margin = 0.1;
  28902. if (uv.y > 1 - Potree.config.depthTexUVyLimit) {
  28903. //漫游点底部识别不到的区域,给一个地板高度
  28904. distance = (currentPano.floorPosition.z - origin.z - margin) / dir.z;
  28905. location.copy(dir).multiplyScalar(distance).add(origin);
  28906. var _normal = new Vector3(0, 0, 1);
  28907. return {
  28908. location,
  28909. normal: _normal,
  28910. distance
  28911. };
  28912. } else if (uv.y < Potree.config.depthTexUVyLimit) {
  28913. var ceilZ = currentPano.getCeilHeight();
  28914. if (ceilZ == Infinity) return !1;else {
  28915. distance = (ceilZ - origin.z - margin) / dir.z;
  28916. location.copy(dir).multiplyScalar(distance).add(origin);
  28917. var _normal2 = new Vector3(0, 0, -1);
  28918. return {
  28919. location,
  28920. normal: _normal2,
  28921. distance
  28922. };
  28923. }
  28924. }
  28925. //console.log('无穷远')
  28926. return !1; //应该是天空或模型外 , 因为很少有漫游点的地方还拍不到地板
  28927. }
  28928. //console.log('distance', distance, dirInPano.clone().multiplyScalar(distance))
  28929. location.copy(dir).multiplyScalar(distance).add(origin);
  28930. if (!onlyPos) {
  28931. var pL = this.getNearbyPoint(origin, uv, -1, 0),
  28932. pR = this.getNearbyPoint(origin, uv, 1, 0),
  28933. pB = this.getNearbyPoint(origin, uv, 0, -1),
  28934. pT = this.getNearbyPoint(origin, uv, 0, 1);
  28935. normal = this.planeFit(dir, location, pL, pR, pB, pT);
  28936. }
  28937. /* if(normal.x != normal.x ){
  28938. console.log('NAN', normal)
  28939. var pL = this.getNearbyPoint(origin, uv, -1, 0)
  28940. , pR = this.getNearbyPoint(origin, uv, 1, 0)
  28941. , pB = this.getNearbyPoint(origin, uv, 0, -1)
  28942. , pT = this.getNearbyPoint(origin, uv, 0, 1);
  28943. } */
  28944. //console.log(location, normal, distance)
  28945. return {
  28946. location,
  28947. normal,
  28948. distance
  28949. };
  28950. }
  28951. getNearbyPoint(origin, uv, x, y) {
  28952. //获取附近的若干像素距离的点
  28953. var uv2 = uv.clone();
  28954. uv2.x += x / (this.canvas.width - 1);
  28955. uv2.x = this.clampUV(uv2.x);
  28956. uv2.y += y / (this.canvas.height - 1);
  28957. uv2.y = this.clampUV(uv2.y);
  28958. /* if(uv2.x < 0 || uv2.y < 0 || uv2.x > 1 || uv2.y > 1){
  28959. console.log('will nan')
  28960. } */
  28961. var dir = math.getDirFromUV(uv2); //从uv获取到方向
  28962. dir.applyMatrix4(viewer.images360.currentPano.panoMatrix2);
  28963. var depth = this.getDepth(uv2.x, uv2.y);
  28964. /* if(Math.abs(depth - this.mainDepth) > 0.3){
  28965. console.log('Math.abs(depth - this.mainDepth) > 0.3')
  28966. } */
  28967. //let dir = new THREE.Vector3().subVectors(intersect.point, origin).normalize()
  28968. var position = new Vector3().copy(dir).multiplyScalar(depth).add(origin);
  28969. //console.log('getNearbyPoint', uv2, depth, dir, position )
  28970. return position;
  28971. }
  28972. clampUV(v) {
  28973. return (v + 1) % 1; // 使输出在 0-1
  28974. }
  28975. planeFit(dir, position, pL, pR, pB, pT) {
  28976. //求平均法线
  28977. var normal = new Vector3();
  28978. var plane = new Plane();
  28979. function addNormal(p1, p2) {
  28980. //根据临接的四个点,分别求法线,然后法线相加能得到平均法线
  28981. if (!p1 || !p2) return;
  28982. plane.setFromCoplanarPoints(position, p1, p2);
  28983. //console.log('normalSub', plane.normal)
  28984. normal.addScaledVector(plane.normal, dir.dot(plane.normal) < 0 ? 1 : -1); //根据面的朝向判断加还是减
  28985. }
  28986. addNormal(pL, pB);
  28987. addNormal(pL, pT);
  28988. addNormal(pR, pB);
  28989. addNormal(pR, pT);
  28990. if (0 !== normal.x || 0 !== normal.y || 0 !== normal.z) {
  28991. normal.normalize();
  28992. //console.log(normal)
  28993. return normal;
  28994. }
  28995. /* 四个面拼成一个菱形 */
  28996. }
  28997. }
  28998. var {
  28999. PanoSizeClass: PanoSizeClass$3,
  29000. Vectors: Vectors$1,
  29001. GLCubeFaces: GLCubeFaces$3,
  29002. PanoramaEvents: PanoramaEvents$1
  29003. } = Potree.defines;
  29004. var rot90$1 = new Quaternion().setFromAxisAngle(new Vector3(0, 0, 1), Math.PI / 2); //使用的是刚好适合全景图的,给cube贴图需要转90°
  29005. var raycaster = new Raycaster();
  29006. //let currentlyHovered = null;
  29007. var texLoader$4 = new TextureLoader();
  29008. var addLine = function addLine(origin, dir, len) {
  29009. var color = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '#fff';
  29010. var line1 = LineDraw.createLine([origin, origin.clone().add(dir.clone().multiplyScalar(len || 1))], {
  29011. color
  29012. });
  29013. //console.log(origin.toArray(), dir.toArray())
  29014. viewer.scene.scene.add(line1);
  29015. return line1;
  29016. };
  29017. var tileArr = [];
  29018. var previousView = {
  29019. controls: null,
  29020. position: null,
  29021. target: null
  29022. };
  29023. var HighMapCubeWidth = 1;
  29024. var directionFactor = 400; //原先10,几乎只往距离近的走了;设置太大容易略过近处漫游点走向下坡,因为鼠标一般在地面,下坡的漫游点更有利
  29025. class Images360 extends EventDispatcher {
  29026. constructor(viewer) {
  29027. super();
  29028. this.viewer = viewer;
  29029. this.panos = [];
  29030. this.neighbourMap = {};
  29031. this.node = new Object3D();
  29032. this.node.name = 'ImagesNode';
  29033. this.cubePanos = [];
  29034. this.fastTranMaskPass = new FastTranPass(viewer.renderer);
  29035. {
  29036. this.cube = new Mesh(new BoxBufferGeometry(1, 1, 1, 1), new ModelTextureMaterial());
  29037. Potree.Utils.updateVisible(this.cube, 'showSkybox', false);
  29038. this.cube.layers.set(Potree.config.renderLayers.skybox);
  29039. this.cube.name = 'skyboxCube';
  29040. viewer.scene.scene.add(this.cube);
  29041. if (Potree.settings.mergeType2 && Potree.settings.modelSkybox) {
  29042. this.materialInside = new ModelTextureMaterial();
  29043. this.materialInside.dontChangeDepth = true; //chunk本身深度是对的,不用深度图,否则过渡会有很多裂痕
  29044. this.cube.material.defines.depth_background = ''; //skybox的深度改得向后一些, 避免盖住chunk,造成坑坑洼洼
  29045. this.addEventListener('endChangeMode', e => {
  29046. var _this$currentPano;
  29047. if ((_this$currentPano = this.currentPano) !== null && _this$currentPano !== void 0 && (_this$currentPano = _this$currentPano.pointcloud) !== null && _this$currentPano !== void 0 && _this$currentPano.is4dkkModel) {
  29048. var model = this.currentPano.pointcloud;
  29049. if (model.fileType == '3dTiles') {
  29050. viewer.setAllTilesets(model, child => {
  29051. child.runtime.limit2lowestDepth(e.mode == 'showPanos');
  29052. child.runtime.getTileset().tiles.forEach(e => {
  29053. this.judgeModelMat(e.tileContent);
  29054. });
  29055. });
  29056. } else {
  29057. this.judgeModelMat(model);
  29058. }
  29059. }
  29060. });
  29061. }
  29062. }
  29063. if (Potree.settings.testCube) {
  29064. this.cubeTest = this.cube.clone();
  29065. this.cubeTest.material = new MeshBasicMaterial({
  29066. wireframe: true,
  29067. color: '#FF3377',
  29068. transparent: true,
  29069. opacity: 0.7,
  29070. depthWrite: false,
  29071. depthTest: false
  29072. });
  29073. viewer.scene.scene.add(this.cubeTest);
  29074. this.cubeTest.visible = true;
  29075. }
  29076. this.flying_ = false;
  29077. this.currentPano = null;
  29078. this.mouseLastMoveTime = Date.now();
  29079. this.scrollZoomSpeed = 0.06;
  29080. this.zoomLevel = 1;
  29081. this.tileDownloader = new TileDownloader();
  29082. this.qualityManager = new QualityManager();
  29083. this.panoRenderer = new PanoRenderer(viewer, this.tileDownloader, this.qualityManager);
  29084. this.basePanoSize = this.qualityManager.getPanoSize(PanoSizeClass$3.BASE);
  29085. this.standardPanoSize = this.qualityManager.getPanoSize(PanoSizeClass$3.STANDARD);
  29086. this.highPanoSize = this.qualityManager.getPanoSize(PanoSizeClass$3.HIGH);
  29087. this.ultraHighPanoSize = this.qualityManager.getPanoSize(PanoSizeClass$3.ULTRAHIGH);
  29088. this.tileDownloader.processPriorityQueue = !1;
  29089. this.tileDownloader.tilePrioritizer = new TilePrioritizer(this.qualityManager, this.basePanoSize, this.standardPanoSize, this.highPanoSize, this.ultraHighPanoSize);
  29090. {
  29091. //高分辨率cube 放大
  29092. this.addHighMapCube();
  29093. viewer.addEventListener(PanoramaEvents$1.Enter, e => {
  29094. this.setHighMap(e.newPano);
  29095. });
  29096. viewer.addEventListener('panoSetZoom', e => {
  29097. if (Potree.settings.displayMode == 'showPanos') {
  29098. e.zoomed ? this.showHighMap() : this.hideHighMap(); //add
  29099. }
  29100. });
  29101. }
  29102. this.depthSampler = new DepthImageSampler();
  29103. viewer.fpControls.addEventListener('dollyStopCauseUnable', e => {
  29104. if ( /* e.hoverViewport != viewer.mainViewport || */!Potree.settings.zoom.enabled) return;
  29105. if (e.scale != void 0) {
  29106. //触屏
  29107. this.zoomBy(e.scale, e.pointer);
  29108. } else {
  29109. //滚轮
  29110. var zoom;
  29111. if (e.delta > 0) {
  29112. zoom = 1 + this.scrollZoomSpeed;
  29113. } else {
  29114. zoom = 1 - this.scrollZoomSpeed;
  29115. }
  29116. e.delta != 0 && this.zoomBy(zoom);
  29117. }
  29118. });
  29119. var click = e => {
  29120. //不用"mouseup" 是因为 mouseup有drag object时也会触发
  29121. if (e.clickElement || Potree.settings.unableNavigate || this.flying || !e.isTouch && e.button != MOUSE.LEFT || e.drag && e.drag.object //拖拽结束时不算
  29122. || Potree.settings.editType == 'pano' && viewer.modules.PanoEditor.activeViewName != 'mainView'
  29123. //|| Potree.settings.editType == 'merge' && !e.intersectPoint || viewer.inputHandler.hoveredElements[0] && viewer.inputHandler.hoveredElements[0].isModel && e.intersectPoint.distance > viewer.inputHandler.hoveredElements[0].distance
  29124. || Potree.settings.editType == 'merge' && !Potree.settings.mergeType2 || Potree.settings.mergeType2 && Potree.settings.displayMode == 'showPointCloud') return;
  29125. if (Potree.settings.editType != 'pano' && Potree.settings.editType != 'merge') {
  29126. if (e.hoverViewport == viewer.mapViewer.viewports[0]) {
  29127. return viewer.mapViewer.dispatchEvent(e /* {type:'global_click',e } */);
  29128. } else if (e.hoverViewport != viewer.mainViewport) {
  29129. //如数据集校准其他viewport
  29130. return;
  29131. }
  29132. }
  29133. if (!Potree.settings.dblToFocusPoint /* && this.currentPano */) {
  29134. //双击不会focus点云 或者 已经focusPano了
  29135. this.flyToPanoClosestToMouse();
  29136. }
  29137. };
  29138. viewer.addEventListener('global_click', click);
  29139. viewer.addEventListener("global_mousemove", e => {
  29140. if (!Potree.settings.unableNavigate && Potree.settings.ifShowMarker && e.hoverViewport == viewer.mainViewport) {
  29141. //如果不显示marker,就在点击时再更新
  29142. this.updateClosestPano(e.intersect);
  29143. }
  29144. });
  29145. this.addEventListener('markerHover', e => {
  29146. this.updateClosestPano(e.pano, e.hovered);
  29147. });
  29148. if (!Potree.settings.isOfficial) {
  29149. this.domRoot = viewer.renderer.domElement.parentElement;
  29150. var elUnfocus = $("<input type='button' value='unfocus'></input>");
  29151. elUnfocus.css({
  29152. position: "absolute",
  29153. right: '25%',
  29154. bottom: '20px',
  29155. zIndex: "10000",
  29156. fontSize: '1em',
  29157. color: "black",
  29158. display: 'none',
  29159. background: 'rgba(255,255,255,0.8)'
  29160. });
  29161. elUnfocus.on("click", () => this.unfocus());
  29162. this.elUnfocus = elUnfocus;
  29163. this.domRoot.appendChild(elUnfocus[0]);
  29164. if (Potree.settings.editType != 'merge') {
  29165. var elHide = $("<input type='button' value='隐藏点云'></input>");
  29166. elHide.css({
  29167. position: "absolute",
  29168. right: '40%',
  29169. bottom: '20px',
  29170. zIndex: "10000",
  29171. fontSize: '1em',
  29172. color: "black",
  29173. width: '100px',
  29174. background: 'rgba(255,255,255,0.8)'
  29175. });
  29176. this.domRoot.appendChild(elHide[0]);
  29177. elHide.on("click", e => {
  29178. var visi = Potree.Utils.getObjVisiByReason(viewer.scene.pointclouds[0], 'force');
  29179. viewer.scene.pointclouds.forEach(e => {
  29180. Potree.Utils.updateVisible(e, 'force', !visi);
  29181. });
  29182. elHide.val(!visi ? "隐藏点云" : "显示点云");
  29183. });
  29184. }
  29185. var elDisplayModel = $("<input type='button' value='>>全景'></input>");
  29186. elDisplayModel.css({
  29187. position: "absolute",
  29188. right: '65%',
  29189. bottom: '20px',
  29190. zIndex: "10000",
  29191. fontSize: '1em',
  29192. color: "black",
  29193. width: '100px',
  29194. background: 'rgba(255,255,255,0.8)'
  29195. });
  29196. this.domRoot.appendChild(elDisplayModel[0]);
  29197. elDisplayModel.on("click", e => {
  29198. if (Potree.settings.displayMode == 'showPointCloud' && this.panos.length == 0) return;
  29199. Potree.settings.displayMode = Potree.settings.displayMode == 'showPointCloud' ? 'showPanos' : 'showPointCloud';
  29200. });
  29201. this.elDisplayModel = elDisplayModel;
  29202. if (viewer.mapViewer) {
  29203. var mapStyleBtn = $("<input type='button' value='普通'></input>");
  29204. mapStyleBtn.css({
  29205. position: "absolute",
  29206. right: '50%',
  29207. bottom: '20px',
  29208. zIndex: "10000",
  29209. fontSize: '1em',
  29210. color: "black",
  29211. width: '100px',
  29212. background: 'rgba(255,255,255,0.8)'
  29213. });
  29214. this.domRoot.appendChild(mapStyleBtn[0]);
  29215. var map = viewer.mapViewer.mapLayer.maps.find(e => e.name == 'map');
  29216. mapStyleBtn.on("click", e => {
  29217. map.switchStyle(map.style == 'satellite' ? 'standard' : 'satellite');
  29218. mapStyleBtn.val(map.style == 'satellite' ? '卫星' : '普通');
  29219. });
  29220. }
  29221. }
  29222. {
  29223. //切换模式
  29224. var displayMode = '';
  29225. this.latestRequestMode = ''; //因为可能延迟,所以记录下每次的请求模式,延迟后判断这个
  29226. Object.defineProperty(Potree.settings, "displayMode", {
  29227. get: function get() {
  29228. return displayMode;
  29229. },
  29230. set: mode => {
  29231. this.latestRequestMode = mode;
  29232. console.warn('Request setMode: ' + mode);
  29233. this.dispatchEvent({
  29234. type: 'requestMode',
  29235. mode
  29236. });
  29237. var config2;
  29238. var config = Potree.config.displayMode[mode];
  29239. if (this.isAtPano() && !this.latestToPano) {
  29240. config2 = config.atPano;
  29241. } else {
  29242. config2 = config.transition;
  29243. }
  29244. var changeTileDownload = () => {
  29245. if (config2.showSkybox || config2.showPoint && config2.pointUsePanoTex) {
  29246. this.tileDownloader.start();
  29247. this.currentPano && this.currentPano.enter();
  29248. } else {
  29249. this.tileDownloader.stop();
  29250. this.currentPano && this.currentPano.exit();
  29251. this.nextPano && viewer.cancelLoad(this.nextPano);
  29252. }
  29253. };
  29254. if (mode != displayMode) {
  29255. var camera = viewer.scene.getActiveCamera();
  29256. if (mode == 'showPanos' && viewer.mainViewport.view.isFlying()) {
  29257. //飞完才能切换全景
  29258. var f = () => {
  29259. if (this.latestRequestMode == mode) {
  29260. //如果ui还是停在这个模式的话
  29261. Potree.settings.displayMode = mode;
  29262. }
  29263. viewer.mainViewport.view.removeEventListener('flyingDone', f);
  29264. viewer.mainViewport.view.removeEventListener('flyCancel', f);
  29265. };
  29266. viewer.mainViewport.view.addEventListener('flyingDone', f); //once
  29267. viewer.mainViewport.view.addEventListener('flyCancel', f);
  29268. return;
  29269. }
  29270. if (this.isAtPano() && !this.latestToPano) {
  29271. config2 = config.atPano;
  29272. } else {
  29273. config2 = config.transition;
  29274. if (mode == 'showPanos') {
  29275. //自动飞入一个pano
  29276. //要改成飞进最近的。。。
  29277. if (this.panos.length == 0) return;
  29278. //this.modeChanging = true //主要是因为到全景图不会立刻成功
  29279. var wait = e => {
  29280. console.log('flyToPanoDone');
  29281. this.removeEventListener('flyToPanoDone', wait);
  29282. setTimeout(() => {
  29283. if (this.latestRequestMode == mode) {
  29284. Potree.settings.displayMode = mode; //被打断,重新执行
  29285. }
  29286. }, e.makeIt ? 1 : 50);
  29287. };
  29288. this.addEventListener('flyToPanoDone', wait); //等待飞行完毕。flyToPano的callback可能不执行所以换这个。但也可能被cancel
  29289. this.flyToPano({
  29290. pano: this.findNearestPano()
  29291. //dealDoneWhenCancel:true,
  29292. /* callback: ()=>{
  29293. setTimeout(()=>{ //防止循环,所以延迟
  29294. if(this.latestRequestMode == mode ){
  29295. Potree.settings.displayMode = mode
  29296. }
  29297. },1)
  29298. } */
  29299. });
  29300. return;
  29301. } else {}
  29302. }
  29303. changeTileDownload();
  29304. if (config2.showSkybox || config2.pointUsePanoTex) {
  29305. var _wait = () => {
  29306. //console.log('waitdone')
  29307. //if(e.pano && e.pano != this.currentPano)return //loadedDepthImg
  29308. setTimeout(() => {
  29309. if (this.latestRequestMode == mode) {
  29310. Potree.settings.displayMode = mode;
  29311. }
  29312. }, 1);
  29313. };
  29314. //this.updateDepthTex()
  29315. if (this.checkAndWaitForPanoLoad(this.currentPano, this.basePanoSize, _wait)) {
  29316. //console.log('等待贴图加载2', this.currentPano.id)
  29317. return;
  29318. }
  29319. }
  29320. viewer.scene.pointclouds.forEach(e => {
  29321. Potree.Utils.updateVisible(e, 'displayMode', config2.showPoint, 2);
  29322. });
  29323. if (config2.pointUsePanoTex) {
  29324. viewer.scene.pointclouds.forEach(e => {
  29325. e.material.setProjectedPanos(this.currentPano, this.currentPano, 1);
  29326. });
  29327. } else {
  29328. viewer.scene.pointclouds.forEach(e => {
  29329. e.material.stopProjectedPanos();
  29330. });
  29331. }
  29332. Potree.Utils.updateVisible(this.cube, 'showSkybox', config2.showSkybox); // this.cube.visible = config2.showSkybox
  29333. //this.cube.visible = config.atPano.showSkybox
  29334. if (this.cube.visible) {
  29335. //this.cube.material.setProjectedPanos(this.currentPano, this.currentPano, 1)
  29336. this.setProjectedPanos({
  29337. progress: 1,
  29338. ifSkybox: true,
  29339. ifPointcloud: false,
  29340. easeInOutRatio: 0,
  29341. pano0: this.currentPano,
  29342. pano1: this.currentPano
  29343. });
  29344. } else {
  29345. this.smoothZoomTo(1);
  29346. this.resetHighMap();
  29347. this.hideHighMap();
  29348. }
  29349. /* viewer.dispatchEvent({
  29350. type: "enableChangePos",
  29351. canLeavePano : config.canLeavePano ,
  29352. viewport:
  29353. }) */
  29354. //viewer.mainViewport.unableChangePos = !config.canLeavePano
  29355. displayMode = mode;
  29356. if (mode == 'showPanos') {
  29357. camera.far = viewer.farWhenShowPano; //修改far
  29358. Potree.settings.pointDensity = 'panorama';
  29359. if (Potree.config.displayMode.showPanos.transition.pointUsePanoTex) {
  29360. viewer.scene.pointclouds.forEach(e => {
  29361. e.material.pointSizeType = 'FIXED';
  29362. });
  29363. }
  29364. this.updateCube(this.currentPano);
  29365. //viewer.setControls(viewer.fpControls)
  29366. } else {
  29367. if (camera.limitFar) camera.far = Potree.settings.cameraFar; //修改far
  29368. Potree.settings.pointDensity = Potree.settings.UserPointDensity;
  29369. //Potree.sdk && Potree.sdk.scene.changePointOpacity()
  29370. if (Potree.config.displayMode.showPanos.transition.pointUsePanoTex) {
  29371. viewer.scene.pointclouds.forEach(e => {
  29372. e.material.pointSizeType = Potree.config.material.pointSizeType;
  29373. });
  29374. }
  29375. //Potree.settings.editType == 'merge' && viewer.setControls(viewer.orbitControls)
  29376. }
  29377. camera.updateProjectionMatrix();
  29378. if (this.elDisplayModel) {
  29379. this.elDisplayModel.val(mode == 'showPointCloud' ? ">>全景" : '>>点云');
  29380. }
  29381. /* this.panos.forEach(e=>{
  29382. Potree.Utils.updateVisible(e, 'modeIsShowPanos', mode == 'showPanos', 1, mode == 'showPanos' ? 'add':'cancel') //
  29383. }) */
  29384. this.dispatchEvent({
  29385. type: 'endChangeMode',
  29386. mode
  29387. });
  29388. console.log('setModeSuccess: ' + mode);
  29389. } else {
  29390. changeTileDownload();
  29391. //this.dispatchEvent({type:'endChangeMode',mode})
  29392. }
  29393. }
  29394. });
  29395. Potree.settings.displayMode = 'showPointCloud';
  29396. } // 切换模式 end
  29397. {
  29398. //
  29399. var currentPano = null;
  29400. Object.defineProperty(this, "currentPano", {
  29401. get: function get() {
  29402. return currentPano;
  29403. },
  29404. set: function set(e) {
  29405. if (e != currentPano) {
  29406. //console.log('set currentPano ', e.id)
  29407. currentPano && currentPano.exit();
  29408. e && e.enter();
  29409. currentPano = e;
  29410. }
  29411. }
  29412. });
  29413. }
  29414. {
  29415. //是否显示marker
  29416. var ifShowMarker = true;
  29417. Object.defineProperty(Potree.settings, "ifShowMarker", {
  29418. get: function get() {
  29419. return ifShowMarker;
  29420. },
  29421. set: show => {
  29422. show = !!show;
  29423. if (show != ifShowMarker) {
  29424. this.panos.forEach(pano => {
  29425. Potree.Utils.updateVisible(pano, 'ifShowMarker', show, 1);
  29426. });
  29427. //this.emit('markersDisplayChange', show)
  29428. ifShowMarker = show;
  29429. viewer.dispatchEvent('showMarkerChanged');
  29430. viewer.dispatchEvent('content_changed');
  29431. }
  29432. }
  29433. });
  29434. }
  29435. viewer.addEventListener("update", () => {
  29436. this.update(viewer);
  29437. });
  29438. //viewer.inputHandler.addInputListener(this);
  29439. var keys = {
  29440. FORWARD: ['W'.charCodeAt(0), 38],
  29441. BACKWARD: ['S'.charCodeAt(0), 40],
  29442. LEFT: ['A'.charCodeAt(0), 37],
  29443. RIGHT: ['D'.charCodeAt(0), 39]
  29444. };
  29445. viewer.inputHandler.addEventListener('keydown', e => {
  29446. if (Potree.settings.displayMode == 'showPanos') {
  29447. for (var i in keys) {
  29448. if (keys[i].some(a => a == e.keyCode)) {
  29449. switch (i) {
  29450. case 'FORWARD':
  29451. this.flyLocalDirection(Vectors$1.FORWARD.clone());
  29452. break;
  29453. case 'BACKWARD':
  29454. this.flyLocalDirection(Vectors$1.BACK.clone());
  29455. break;
  29456. case 'LEFT':
  29457. this.flyLocalDirection(Vectors$1.LEFT.clone());
  29458. break;
  29459. case 'RIGHT':
  29460. this.flyLocalDirection(Vectors$1.RIGHT.clone());
  29461. break;
  29462. }
  29463. break;
  29464. }
  29465. }
  29466. }
  29467. });
  29468. }
  29469. judgeModelMat(object) {
  29470. if (!(Potree.settings.mergeType2 && Potree.settings.modelSkybox)) return;
  29471. object.traverse(mesh => {
  29472. if (mesh.material) {
  29473. if (!mesh.materialOutside) {
  29474. mesh.materialOutside = mesh.material;
  29475. }
  29476. mesh.material = Potree.settings.displayMode == 'showPanos' ? this.materialInside : mesh.materialOutside;
  29477. Potree.Utils.setObjectLayers(mesh, Potree.settings.displayMode == 'showPanos' ? 'skybox' : 'model'); //为了渲染到rtEDL
  29478. }
  29479. });
  29480. }
  29481. updateDepthTex(pano) {
  29482. if (this.currentPano != pano || !pano.depthTex) return;
  29483. //this.depthSampler.changeImg(pano.depthTex.image); //pick sampler要飞到了才能切换图,而skybox贴图是随着全景图切换而切换的
  29484. this.cube.material.updateDepthTex(pano); //确保一下
  29485. }
  29486. findNearestPano(pos) {
  29487. var panos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.panos;
  29488. pos = pos ? new Vector3().copy(pos) : this.position;
  29489. var result = Common.sortByScore(panos, [Images360.filters.isEnabled()], [e => -e.position.distanceTo(pos)]);
  29490. var pano = result[0] && result[0].item;
  29491. return pano;
  29492. }
  29493. /* set flying(v){//正在飞向pano
  29494. this.flying_ = !!v
  29495. //console.log('this.flying_ ', !!v )
  29496. //this.emit('flying', this.flying_)
  29497. let config = Potree.config.displayMode[Potree.settings.displayMode]
  29498. viewer.mainViewport.unableChangePos = !config.canLeavePano || !!v
  29499. }
  29500. get flying(){
  29501. return this.flying_
  29502. } */
  29503. flyLocalDirection(dir) {
  29504. var direction = this.getDirection(dir),
  29505. option1 = 1 === dir.y ? .4 : .75,
  29506. option2 = 1 === Math.abs(dir.x);
  29507. return this.flyDirection(direction, option1, option2, true);
  29508. }
  29509. getDirection(e) {
  29510. if (!e) {
  29511. return viewer.scene.view.direction;
  29512. } else {
  29513. return e = e ? e : new Vector3().copy(Vectors$1.FORWARD), e.applyQuaternion(viewer.mainViewport.camera.quaternion);
  29514. }
  29515. }
  29516. get position() {
  29517. return this.viewer.scene.view.position.clone();
  29518. }
  29519. isAtPano() {
  29520. var precision = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1e-6;
  29521. //是否在某个漫游点上
  29522. if (precision) {
  29523. return this.currentPano && math.closeTo(viewer.scene.view.position, this.currentPano.position, precision);
  29524. }
  29525. return this.currentPano && viewer.scene.view.position.equals(this.currentPano.position);
  29526. }
  29527. updateProjectedPanos() {
  29528. //更新材质贴图
  29529. //console.warn('updateProjectedPanos')
  29530. this.projectedPano0 && this.projectedPano1 && this.setProjectedPanos({
  29531. pano0: this.projectedPano0,
  29532. pano1: this.projectedPano1
  29533. });
  29534. }
  29535. setProjectedPanos() {
  29536. var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  29537. //设置cube和点云的材质贴图
  29538. this.cube.material.setProjectedPanos(o.pano0, o.pano1, o.progress);
  29539. this.materialInside && this.materialInside.setProjectedPanos(o.pano0, o.pano1, o.progress);
  29540. if (o.ifPointcloud) {
  29541. viewer.scene.pointclouds.forEach(e => {
  29542. e.material.setProjectedPanos(o.pano0, o.pano1, o.progress, o.easeInOutRatio);
  29543. });
  29544. }
  29545. //console.warn('setProjectedPanos ', o.pano0.id , o.pano1.id)
  29546. this.projectedPano0 = o.pano0;
  29547. this.projectedPano1 = o.pano1;
  29548. }
  29549. cancelFlyToPano(toPano) {
  29550. //取消当前已有的飞行准备,前提是相机还未移动
  29551. if (viewer.mainViewport.view.isFlying() || toPano && this.latestToPano != toPano) return;
  29552. //Potree.Log('cancelFlyToPano', this.latestToPano && this.latestToPano.pano.id)
  29553. this.nextPano = null;
  29554. this.latestToPano = null;
  29555. }
  29556. flyToPano(toPano) {
  29557. //飞向漫游点
  29558. if (!toPano) return;
  29559. if (typeof toPano == 'number') toPano = this.panos[toPano];
  29560. if (toPano instanceof Panorama) {
  29561. toPano = {
  29562. pano: toPano
  29563. };
  29564. }
  29565. var done = (makeIt, disturb) => {
  29566. //console.log('flyToPano done ', toPano.pano.id, makeIt, disturb )
  29567. if (makeIt || disturb) {
  29568. // disturb已经开始飞行但中途取消
  29569. toPano.callback && toPano.callback(makeIt);
  29570. //this.flying = false
  29571. this.cancelFlyToPano(toPano);
  29572. this.updateClosestPano(this.closestPano, false); //飞行结束后取消点击漫游点时得到的closestPano
  29573. } else {}
  29574. this.dispatchEvent({
  29575. type: 'flyToPanoDone',
  29576. makeIt,
  29577. disturb
  29578. });
  29579. this.fastTranMaskPass.stop();
  29580. toPano.deferred && toPano.deferred.resolve(makeIt); //测量线截图时发现,resolve需要写在flying=false 后才行。
  29581. };
  29582. if (!toPano.pano.enabled) return done(false, true);
  29583. //Potree.Log('hope flyToPano: '+toPano.pano.id, toPano.pano.position.toArray() )
  29584. if (!toPano.canCancelLast && this.latestToPano && this.latestToPano != toPano && (
  29585. //还在飞
  29586. this.latestToPano.pano != this.currentPano || !this.isAtPano())) {
  29587. //如果旧的toPano只在pano旋转镜头,就直接取消旧的,继续执行
  29588. return done(false);
  29589. }
  29590. if (this.currentPano == toPano.pano && this.isAtPano() && !toPano.target && !toPano.quaternion) {
  29591. //已在该pano
  29592. this.dispatchEvent({
  29593. type: 'flyToPano',
  29594. toPano
  29595. });
  29596. return done(true);
  29597. }
  29598. //Potree.Log('flyToPano: '+toPano.pano.id, toPano.pano.position.toArray() /* this.latestToPano && this.latestToPano.pano.id */ )
  29599. var target = toPano.target;
  29600. var config = Potree.config.displayMode[Potree.settings.displayMode];
  29601. var pano = toPano.pano;
  29602. var dis = pano.position.distanceTo(this.position);
  29603. this.nextPano = pano;
  29604. this.latestToPano = toPano;
  29605. //this.flying = true //防止新的请求
  29606. //Potree.Log('flyToPano:'+pano.id + ' , duration:'+toPano.duration, null, 12)
  29607. {
  29608. //不飞的话是否不要执行这段?
  29609. var wait = e => {
  29610. //console.log('wait done', pano.id)
  29611. if ( /* e.pano && */this.latestToPano && pano != this.latestToPano.pano) return; //loadedDepthImg
  29612. if (this.latestToPano != toPano) return Potree.Log('已经取消', pano.id); //如果取消了
  29613. setTimeout(() => {
  29614. if (this.latestToPano != toPano) return;
  29615. this.flyToPano(toPano);
  29616. }, 1);
  29617. };
  29618. if (!pano.depthTex && pano.pointcloud.hasDepthTex) {
  29619. //点云模式也要加载depthTex,因获取neighbour需要用到
  29620. console.log('等待加载depthtex', pano.id);
  29621. pano.addEventListener('loadedDepthImg', wait, {
  29622. once: true
  29623. });
  29624. return pano.loadDepthImg();
  29625. }
  29626. if (config.atPano.showSkybox || config.atPano.pointUsePanoTex) {
  29627. var a = this.updateCube(this.currentPano, toPano.pano);
  29628. if (a == 'useBound') {
  29629. toPano.useBound = true;
  29630. }
  29631. if (this.checkAndWaitForPanoLoad(pano, toPano.basePanoSize || this.basePanoSize, wait)) {
  29632. //console.log('等待贴图加载',pano.id)
  29633. return;
  29634. }
  29635. }
  29636. }
  29637. config = Potree.config.displayMode[Potree.settings.displayMode]; //可能换了
  29638. var pointcloudVisi = config.atPano.showPoint; //viewer.scene.pointclouds[0].visible
  29639. Potree.Utils.updateVisible(this.cube, 'showSkybox', config.atPano.showSkybox); // this.cube.visible = config.atPano.showSkybox
  29640. //console.log('开始飞1')
  29641. if (config.transition.showPoint) {
  29642. viewer.scene.pointclouds.forEach(e => {
  29643. Potree.Utils.updateVisible(e, 'displayMode', true);
  29644. });
  29645. }
  29646. var endPosition = pano.position.clone();
  29647. var T = Potree.config.transitionsTime;
  29648. /* let maxTime = this.isAtPano() ? T.panoToPanoMax : T.flyIn
  29649. let duration = toPano.duration == void 0 ? (T.flyMinTime+Math.min(T.flytimeDistanceMultiplier * dis, maxTime)) : toPano.duration
  29650. */
  29651. /* let maxDis = this.isAtPano() ? T.maxDistanceThreshold : T.maxDistanceThresholdFlyIn
  29652. let duration = toPano.duration == void 0 ? Math.min(dis, T.maxDistanceThreshold) * T.flytimeDistanceMultiplier + T.flyMinTime : toPano.duration
  29653. */
  29654. var maxDis = 7;
  29655. var duration = toPano.duration == void 0 ? Math.min(dis, maxDis) * T.flytimeDistanceMultiplier + T.flyMinTime : toPano.duration;
  29656. if (config.transition.showSkybox || config.transition.pointUsePanoTex) {
  29657. if (Potree.settings.fastTran) {
  29658. this.fastTranMaskPass.start(); //截图当前画面
  29659. viewer.scene.view.position.copy(endPosition);
  29660. }
  29661. this.setProjectedPanos({
  29662. progress: 0,
  29663. ifSkybox: this.cube.visible,
  29664. ifPointcloud: config.transition.pointUsePanoTex,
  29665. easeInOutRatio: pointcloudVisi ? 0.3 : 0,
  29666. pano0: this.currentPano,
  29667. pano1: pano
  29668. });
  29669. }
  29670. if (toPano.useBound) {
  29671. duration = Math.min(1500, duration);
  29672. toPano.easeName = 'easeInOutQuad';
  29673. } else {
  29674. if (endPosition.equals(this.position)) toPano.easeName = 'easeOutSine';
  29675. }
  29676. {
  29677. toPano.easeName = toPano.easeName || 'linearTween';
  29678. toPano.duration = duration;
  29679. this.beforeFlyToPano(toPano);
  29680. }
  29681. /* let fly = ()=>{
  29682. this.dispatchEvent({type:'flyToPano', toPano})
  29683. viewer.scene.view.setView({position:endPosition, target, quaternion:toPano.quaternion , duration,
  29684. callback:()=>{
  29685. if(!config.atPano.pointUsePanoTex){
  29686. viewer.scene.pointclouds.forEach(e=>{
  29687. e.material.stopProjectedPanos()
  29688. })
  29689. }
  29690. this.currentPano = pano;
  29691. this.nextPano = null;
  29692. if(Potree.settings.displayMode == 'showPanos'){
  29693. viewer.scene.pointclouds.forEach(e=>{
  29694. Potree.Utils.updateVisible(e, 'displayMode',pointcloudVisi)
  29695. })
  29696. }
  29697. done(true);
  29698. this.updateDepthTex(this.currentPano)
  29699. }, onUpdate:(progress)=>{
  29700. //console.log('uniforms progress',progress)
  29701. this.cube.material.uniforms.progress.value = progress
  29702. viewer.scene.pointclouds.forEach(e=>{
  29703. e.material.uniforms.progress.value = progress
  29704. })
  29705. },
  29706. cancelFun:()=>{ done(false, true) },
  29707. Easing:easeName
  29708. })
  29709. //duration > 0 && (this.flying = true) //再写一遍 防止cancel其他项目导致flying为false
  29710. } */
  29711. var _onUpdate = progress => {
  29712. this.cube.material.uniforms.progress.value = progress;
  29713. this.materialInside && (this.materialInside.uniforms.progress.value = progress);
  29714. viewer.scene.pointclouds.forEach(e => {
  29715. e.material.uniforms.progress.value = progress;
  29716. });
  29717. };
  29718. var fly = () => {
  29719. var startProgress = toPano.progress = toPano.progress || 0;
  29720. var loadNextProgress = MathUtils.clamp(1 - 2.5 / dis, 0.3, 0.8);
  29721. //console.log(loadNextProgress, (1-loadNextProgress) * dis )
  29722. this.dispatchEvent({
  29723. type: 'flyToPano',
  29724. toPano
  29725. });
  29726. viewer.scene.view.setView({
  29727. position: endPosition,
  29728. target,
  29729. quaternion: toPano.quaternion,
  29730. duration: toPano.duration,
  29731. onUpdate: (progress_, delta) => {
  29732. var progress = startProgress + progress_ * (1 - startProgress);
  29733. var currentSpeed;
  29734. if (progress_ != 1 && progress_ != 0) {
  29735. // 1的时候不准,往往偏小, 0的时候速度为0,也不记录
  29736. currentSpeed = (progress - toPano.progress) * dis / delta; //记录下当前速度,当变为匀速时可以过渡到flySpeed
  29737. } else {
  29738. currentSpeed = toPano.currentSpeed || 0;
  29739. }
  29740. toPano.currentSpeed = currentSpeed;
  29741. toPano.progress = progress;
  29742. //console.log('progress_', progress_, 'delta',delta , 'progress', progress/*, 'currentSpeed', currentSpeed, */ )
  29743. if (progress > loadNextProgress && toPano.easeName == 'linearTween' && currentSpeed) {
  29744. // 减速. 如果仅旋转就不停止
  29745. //console.log('减速', /* currentSpeed , */progress_ )
  29746. toPano.easeName = 'easeOutSine';
  29747. var restDis = (1 - progress) * dis;
  29748. toPano.duration = Math.PI / 2 * restDis / currentSpeed; // 这样能保证初始速度为currentSpeed
  29749. viewer.scene.view.cancelFlying('all', false); //为了防止执行cancelFun先主动cancel
  29750. toPano.flyCount = 2;
  29751. fly(toPano);
  29752. }
  29753. _onUpdate(progress);
  29754. },
  29755. callback: () => {
  29756. if (!config.atPano.pointUsePanoTex) {
  29757. viewer.scene.pointclouds.forEach(e => {
  29758. e.material.stopProjectedPanos();
  29759. });
  29760. }
  29761. this.lastPano = this.currentPano; //记录,调试
  29762. this.currentPano = pano;
  29763. this.nextPano = null;
  29764. if (Potree.settings.displayMode == 'showPanos') {
  29765. viewer.scene.pointclouds.forEach(e => {
  29766. Potree.Utils.updateVisible(e, 'displayMode', pointcloudVisi);
  29767. });
  29768. }
  29769. done(true);
  29770. this.updateDepthTex(this.currentPano); //删除dispose的depthTex
  29771. },
  29772. cancelFun: () => {
  29773. done(false, true);
  29774. },
  29775. Easing: toPano.easeName,
  29776. ignoreFirstFrame: toPano.flyCount != 2 //变换transition时不停一帧
  29777. });
  29778. };
  29779. if (Potree.settings.displayMode == 'showPanos') {
  29780. setTimeout(fly, 40); //更新geo后缓冲
  29781. } else {
  29782. fly();
  29783. }
  29784. //console.log('flyToPano:', toPano.pano.id)
  29785. }
  29786. beforeFlyToPano(toPano) {
  29787. if (this.currentPano != toPano.pano) {
  29788. if (Potree.settings.displayMode == 'showPanos') {
  29789. this.resetHighMap();
  29790. }
  29791. this.smoothZoomTo(toPano.zoomLevel || 1, toPano.duration / 2);
  29792. }
  29793. }
  29794. /* updateCube(pano0, pano1){
  29795. if(Potree.settings.displayMode != 'showPanos')return
  29796. if(!viewer.scene.pointclouds.some(e=>!e.hasDepthTex)) return this.updateCube2(pano0, pano1) //都hasDepthTex的话
  29797. let useBound = (bound, size)=>{
  29798. size = size || bound.getSize(new THREE.Vector3)
  29799. let center = bound.getCenter(new THREE.Vector3)
  29800. size.max(new THREE.Vector3(HighMapCubeWidth,HighMapCubeWidth,HighMapCubeWidth))
  29801. this.cube.scale.copy(size)
  29802. this.cube.position.copy(center)
  29803. }
  29804. let getPanoBound = (pano)=>{//因漫游点可能在点云外部,如室外平地,所以需要union进漫游点
  29805. let panoBound = new THREE.Box3
  29806. panoBound.expandByPoint(pano.position)
  29807. panoBound.expandByVector(new THREE.Vector3(10,10,10));//give pano a margin
  29808. return pano.pointcloud.bound.clone().union(panoBound)
  29809. }
  29810. let getDis = (bound1, bound2)=>{ //获取bound1边界到bound2边界距离
  29811. if(bound1.intersectsBox(bound2))return 0
  29812. let center1 = bound1.getCenter(new THREE.Vector3)
  29813. let center2 = bound2.getCenter(new THREE.Vector3)
  29814. let dis = center1.distanceTo(center2)
  29815. let dis1 = bound1.distanceToPoint(center2)
  29816. let dis2 = bound2.distanceToPoint(center1)
  29817. return dis1 + dis2 - dis
  29818. }
  29819. if(pano1){//过渡
  29820. if(pano0.pointcloud == pano1.pointcloud){//同一个数据集内的过渡
  29821. useBound(getPanoBound(pano0))
  29822. }else{//非同一个数据集内的过渡
  29823. let bound = getPanoBound(pano0).union(getPanoBound(pano1))
  29824. if(getDis(pano0.pointcloud.bound, pano1.pointcloud.bound) < 100){
  29825. useBound(bound)
  29826. }else{//如果两个数据集boundingbox距离大于这个距离,扩大一下,防止精度问题导致失真//对很远的数据集似乎没有什么用
  29827. let size = bound.getSize(new THREE.Vector3)
  29828. let max = Math.max(size.x, size.y, size.z)
  29829. size.set(max,max,max)
  29830. useBound(pano0.pointcloud.bound.clone().union(pano1.pointcloud.bound), size)
  29831. }
  29832. }
  29833. }else{
  29834. useBound(getPanoBound(pano0)) //假定一个数据集不会太大,否则会造成失真,且bump时移动距离看起来很小。或者可以考虑用固定大小
  29835. }
  29836. } */
  29837. getIntersect(pano, dir, origin) {
  29838. if (pano && pano.pointcloud.hasDepthTex) {
  29839. return this.depthSampler.sample({
  29840. dir
  29841. }, pano, true);
  29842. } else {
  29843. origin = origin || pano.position;
  29844. return viewer.inputHandler.getIntersect({
  29845. viewport: viewer.inputHandler.hoverViewport,
  29846. onlyGetIntersect: true,
  29847. usePointcloud: true,
  29848. point: origin.clone().add(dir),
  29849. cameraPos: origin
  29850. });
  29851. }
  29852. }
  29853. /* updateCube(pano0, pano1){//增加细分的版本,且垂直方向上也分多个
  29854. if(Potree.settings.displayMode != 'showPanos')return
  29855. console.log('updateCube',pano0.id, pano1&&pano1.id)
  29856. let f = (bound, size)=>{
  29857. size = size || bound.getSize(new THREE.Vector3)
  29858. let center = bound.getCenter(new THREE.Vector3)
  29859. size.max(new THREE.Vector3(HighMapCubeWidth,HighMapCubeWidth,HighMapCubeWidth))
  29860. this.cube.scale.copy(size)
  29861. this.cube.position.copy(center)
  29862. }
  29863. this.cube.geometry.dispose();
  29864. if(pano1){//过渡
  29865. let count1, count2;
  29866. let panoIndex = 0
  29867. let add = (pano, dir )=>{
  29868. let getPI = function(index, panoIndex_){
  29869. if(panoIndex_ == void 0) panoIndex_ = panoIndex
  29870. return (count1 * count2 + 2 ) * panoIndex_ + index + 2
  29871. }
  29872. let minZ, maxZ
  29873. minZ = pano.floorPosition.z
  29874. {//天花板高度值
  29875. //用三个间隔120度散开,和中心垂直线成一定夹角的三个向量去求 最高高度 (不求平均的原因:万一是0不好算)
  29876. let rotMat = new THREE.Matrix4().makeRotationX(THREE.Math.degToRad(40))// 角度不能小于天花板中空的半径,大概就是0.2*Math.PI=36度
  29877. let dir1 = new THREE.Vector3(0,0,1).applyMatrix4(rotMat)
  29878. let rotMat1 = new THREE.Matrix4().makeRotationZ(Math.PI*2 / 3);
  29879. let rotMat2 = new THREE.Matrix4().makeRotationZ(-Math.PI*2 / 3);
  29880. let dir2 = dir1.clone().applyMatrix4(rotMat1)
  29881. let dir3 = dir1.clone().applyMatrix4(rotMat2)
  29882. let zs = [dir1,dir2,dir3].map(dir_=>{
  29883. let intersect = this.depthSampler.sample( {dir: dir_}, pano, true )
  29884. let z = intersect ? intersect.location.z : pano.position.z
  29885. return z
  29886. })
  29887. zs.sort((a,b)=>{return b-a});//得最大值
  29888. maxZ = zs[0]
  29889. let min = pano.position.z + 1
  29890. if(maxZ < pano.position.z + 0.04){//户外
  29891. maxZ = pano.position.z + 50
  29892. }
  29893. maxZ = Math.max(min,maxZ)
  29894. console.log(pano.id, 'maxZ:',maxZ )
  29895. console.log(pano.id, 'minZ:',minZ )
  29896. }
  29897. [maxZ, minZ ].forEach(z=>{
  29898. posArr.push(pano.position.clone().setZ(z))
  29899. })
  29900. const angle = Math.PI/8
  29901. let getDir = (angle_)=>{
  29902. let rotMat = new THREE.Matrix4().makeRotationZ(angle_)
  29903. return dir.clone().applyMatrix4(rotMat)
  29904. }
  29905. 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度
  29906. count1 = dirs.length
  29907. dirs.forEach((dir, index)=>{//获取在这个方向上和墙体intersect的最远距离,使用中、上、下三个方向
  29908. let dirs_ = [
  29909. dir.clone().setZ(Math.tan(THREE.Math.degToRad(30))).normalize(),
  29910. dir.clone().setZ(Math.tan(THREE.Math.degToRad(15))).normalize(),
  29911. dir.clone(), // 水平方向
  29912. dir.clone().setZ(-Math.tan(THREE.Math.degToRad(15))).normalize(),
  29913. dir.clone().setZ(-Math.tan(THREE.Math.degToRad(30))).normalize(),
  29914. ];
  29915. count2 = dirs_.length
  29916. dirs_.forEach((dir_, i) =>{
  29917. let intersect = this.depthSampler.sample( {dir: dir_}, pano, true )
  29918. let location
  29919. if(!intersect){ //超级远
  29920. let distance = 100
  29921. location = dir_.clone().multiplyScalar(distance).add(pano.position)
  29922. intersect = {distance,location}
  29923. }
  29924. //intersect.distance
  29925. location = intersect.location.clone()
  29926. let shouldZ// = THREE.Math.clamp(intersect.location.z, minZ, maxZ);
  29927. let needShrink = false
  29928. if(i == 0){//最上方的点高度直接等于天花板
  29929. shouldZ = maxZ
  29930. if(location.z<maxZ)location.z = maxZ
  29931. else needShrink = true
  29932. }else if(i == count2-1){//最下方的点高度直接等于地板
  29933. shouldZ = minZ
  29934. if(location.z>minZ)location.z = minZ
  29935. else needShrink = true
  29936. }
  29937. if(needShrink ){//需要在保持dir_不变的情况下修改z
  29938. let len = (shouldZ - pano.position.z) / (intersect.location.z - pano.position.z) * intersect.distance
  29939. location = dir_.clone().multiplyScalar(len).add(pano.position)
  29940. }
  29941. posArr.push(location)
  29942. if(index!=0 && i!=0){//加入一块四方面
  29943. let curIndex = getPI(count2 * index + i);
  29944. faceArr.push([curIndex-1, curIndex-count2-1, curIndex-count2],
  29945. [curIndex-1, curIndex, curIndex-count2])
  29946. }
  29947. })
  29948. if(index!=0){
  29949. let top = -2;
  29950. let btm = -1
  29951. faceArr.push([getPI(count2*(index-1) ), getPI(count2*index ), getPI(top) ])//天花板扇形
  29952. faceArr.push([getPI(count2*index-1), getPI(count2*(index+1)-1), getPI(btm) ] )//地板扇形
  29953. }else{
  29954. //加入和另一个pano连接的其中一个侧边
  29955. let panoIndex2 = (panoIndex + 1) % 2;
  29956. for(let i=1;i<count2;i++){
  29957. faceArr.push([getPI(i-1), getPI(i), getPI((count1-1)*count2 +i, panoIndex2)],
  29958. [getPI(i-1), getPI((count1-1)*count2+i , panoIndex2) , getPI((count1-1)*count2+i-1 ,panoIndex2)])
  29959. }
  29960. faceArr.push([getPI(0), getPI((count1-1)*count2), getPI(0, panoIndex2)])//加入顶部的一半
  29961. faceArr.push([getPI(count2-1), getPI(count1*count2-1), getPI(count2-1, panoIndex2)])//加入底部的一半
  29962. }
  29963. });
  29964. panoIndex ++
  29965. }
  29966. let posArr = [];
  29967. let faceArr = []
  29968. //两点连线的水平向量
  29969. let vec = new THREE.Vector3().subVectors(pano0.position, pano1.position).setZ(0).normalize()
  29970. add(pano0, vec)
  29971. add(pano1, vec.negate())
  29972. let geo = MeshDraw.createGeometry(posArr, faceArr)
  29973. this.cube.geometry = geo
  29974. this.cube.scale.set(1,1,1);
  29975. this.cube.position.set(0,0,0)
  29976. }else{
  29977. this.cube.geometry = new THREE.BoxBufferGeometry(1,1,1,1)
  29978. f(pano0.pointcloud.bound)
  29979. }
  29980. } */
  29981. isNeighbour(pano0, pano1) {
  29982. var {
  29983. dontCompute,
  29984. onlyUseTex,
  29985. computeDirFirst,
  29986. computeTwoDir
  29987. } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  29988. //是否之间没有遮挡(在加载visibles之前,自己算) 最好pano0是currentPano
  29989. if (!pano0 || !pano1) return;
  29990. var margin = 0.1;
  29991. var map0 = this.neighbourMap[pano0.id]; //主
  29992. var map1 = this.neighbourMap[pano1.id]; //副
  29993. /* if(map0[pano1.id] != void 0){
  29994. ifNeighbour = map0[pano1.id]
  29995. }
  29996. if(!ifNeighbour && map1[pano0.id] != void 0){
  29997. ifNeighbour = map1[pano0.id]
  29998. } */
  29999. var ifNeighbour = map1[pano0.id] == void 0 ? map0[pano1.id] : map0[pano1.id] && map1[pano0.id]; //如果map1没计算就只要返回map0
  30000. var dis = pano0.position.distanceTo(pano1.position);
  30001. if (math.closeTo(dis, 0)) {
  30002. //两个点相同
  30003. ifNeighbour = map1[pano0.id] = map0[pano1.id] = true;
  30004. return true;
  30005. }
  30006. if (dontCompute) return ifNeighbour;
  30007. var logSids = [/* '1739923562316697600|3','1739923562316697600|2' */];
  30008. var ifLog = pano0.sid == logSids[0] && pano1.sid == logSids[1] || pano0.sid == logSids[1] && pano1.sid == logSids[0];
  30009. if (ifLog) {
  30010. console.log(2);
  30011. }
  30012. var ifSheltered = (mainPano, subPano) => {
  30013. //该点前方近处是否都被遮挡 。 为了防止杂点干扰,多个方向探测
  30014. var vec = new Vector3().subVectors(subPano.position, mainPano.position).normalize();
  30015. var getDir = (angle_, upDown) => {
  30016. //基于vec的方向 向左向右旋转
  30017. //if(upDown) vec.clone().applyAxisAngle(new THREE.Vector3(1, 0, 0), upDown);
  30018. return vec.clone().applyAxisAngle(new Vector3(0, 0, 1), angle_);
  30019. };
  30020. var minScore = 0.25;
  30021. var angles = [20, 16, 12.5, 10, 8, 6, 4.5, 3, 1, -1, -3, -4.5, -6, -8, -10, -12.5, -16, -20]; //水平方向角度 3之间有较大概率杂点, 3以外一部分有较大概率有空隙所以紧凑点
  30022. var wellCount = 0;
  30023. var seccess = [];
  30024. for (var i = 0; i < angles.length; i++) {
  30025. var rad = MathUtils.degToRad(angles[i]);
  30026. var dir = getDir(rad);
  30027. var color = void 0;
  30028. var intersectPoint = viewer.images360.depthSampler.sample({
  30029. dir
  30030. }, mainPano, true);
  30031. if (!intersectPoint || intersectPoint.distance * Math.cos(Math.abs(rad)) /* + margin */ > dis) {
  30032. //投影在vec方向的长度不超过漫游点间距
  30033. wellCount++;
  30034. seccess.push(angles[i]);
  30035. color = new Color('#0f8');
  30036. }
  30037. ifLog && addLine(mainPano.position, dir, dis, color);
  30038. }
  30039. //console.log('ifSheltered')
  30040. if (ifLog) {
  30041. console.log('ifSheltered seccess', seccess, 'id:', mainPano.originID, subPano.originID);
  30042. }
  30043. var score = wellCount / angles.length;
  30044. if (score >= minScore) {
  30045. //合格个数
  30046. return score;
  30047. }
  30048. };
  30049. /*
  30050. 识别一定角度范围内是否有遮挡时
  30051. 几种奇葩的情况:
  30052. 1 在墙的两边的但是墙是倾斜的漫游点:
  30053. A /
  30054. /
  30055. / B
  30056. 从B出发和BA成20度的射线和墙面的交点会远于A,导致识别为无遮挡。
  30057. 所以还是改为识别范围内多个深度图像素, 合格像素个数占比 至少要大于50%,因为半边墙壁是50%
  30058. 如SG-9UsbysDufBw&formal&test 的 6、9点。 而SS-GTmFBp1JN8k&formal&test的 2、3两点是人物遮挡
  30059. 2 可以通行,但是右边是墙,右边的都检测失败,左侧的又有一些杂点,导致成功dir个数很低。
  30060. 所以minRatio 要降低于0.5
  30061. */
  30062. //三个方向 : position0到position1, position0到floorPosition1, position1到floorPosition0。 只要有一个满足ifNeighbour就为true。 不过为了不使sampler总换图,先只考虑从主pano到副pano的方向
  30063. var getNeighbour = (mainPano, subPano) => {
  30064. var dirPoints = [[subPano.position, mainPano.position]]; //注: 点A能到B不代表点B能到A,因为拍摄时物体会移动,或点位相对位置不对,无论是否是意外遮挡都且记下来,反正最后只要有一方可行就算相邻。
  30065. if (dis < 20) {
  30066. //在远处去掉对floorPosition的判断
  30067. dirPoints.push([subPano.floorPosition.clone().add(new Vector3(0, 0, 0.1)), mainPano.position]);
  30068. }
  30069. if (dis < 12) {
  30070. //为了防止楼梯拐角、杂点遮挡。 尽量只在穿墙时不可通行
  30071. dirPoints.push([subPano.position.clone().add(new Vector3(0, 0, 0.8)), mainPano.position]);
  30072. var normal = math.getNormal2d({
  30073. p1: subPano.position,
  30074. p2: mainPano.position
  30075. }).multiplyScalar(0.3); //左右方向
  30076. dirPoints.push([subPano.position.clone().add(new Vector3(normal.x, normal.y, 0.1)), mainPano.position]);
  30077. dirPoints.push([subPano.position.clone().add(new Vector3(-normal.x, -normal.y, 0.1)), mainPano.position]);
  30078. }
  30079. //console.warn('getNeighbour', mainPano.id,subPano.id)
  30080. for (var i = 0; i < dirPoints.length; i++) {
  30081. var dir = new Vector3().subVectors(dirPoints[i][0], dirPoints[i][1]).normalize();
  30082. var intersectPoint = viewer.images360.depthSampler.sample({
  30083. dir
  30084. }, mainPano, true, true);
  30085. if (!intersectPoint || intersectPoint.distance + margin > dirPoints[i][0].distanceTo(dirPoints[i][1])) {
  30086. //if(i>2)console.log('haha',i,'id:',mainPano.id,subPano.id)
  30087. return true;
  30088. }
  30089. }
  30090. };
  30091. //if(!ifNeighbour && (map0[pano1.id] == void 0 || computeTwoDir && !map0[pano1.id] && map1[pano0.id] == void 0 )) {//主方向为空且不为邻居
  30092. if (pano0.pointcloud.hasDepthTex || pano1.pointcloud.hasDepthTex) {
  30093. if (computeTwoDir ? map0[pano1.id] == void 0 || map1[pano0.id] == void 0 : map0[pano1.id] == void 0 && map1[pano0.id] !== false) {
  30094. //2024.3.20改为必须两个方向都为true才行。 因为如果两个点分别在两个数据集相距很远,A确定有墙无法到B,B朝A看 没有B所在的数据集点云遮挡,因深度图不会包含别的数据集的点,故深度图探测到A处为无遮挡,就会导致会飞到遥远的A。 即使在同一个数据集,因为点云可以编辑位置,导致AB相对位置错误,也要避免这种情况可以互相乱走。 缺点是更容易被杂点阻挡,所以需要ifShelter降低阈值。
  30095. if (map0[pano1.id] == void 0 && pano0.depthTex) {
  30096. var is = getNeighbour(pano0, pano1);
  30097. map0[pano1.id] = !!is;
  30098. }
  30099. if (computeTwoDir && map0[pano1.id] && pano1.depthTex && map1[pano0.id] == void 0) {
  30100. //computeTwoDir : 允许反向计算,即可以读取另一张的深度图 。 如果map0为false,map1就不用计算,只需要等待计算ifShelter
  30101. var _is = getNeighbour(pano1, pano0);
  30102. map1[pano0.id] = !!_is;
  30103. }
  30104. if (map0[pano1.id] === false || map1[pano0.id] === false) {
  30105. if (dis < 20) {
  30106. //再检查下 只要两方都没有被完全遮挡就算可通行 针对杂点较多的情况
  30107. if (pano0.depthTex && pano1.depthTex) {
  30108. ifNeighbour = false;
  30109. var a = ifSheltered(pano0, pano1);
  30110. if (a) {
  30111. var b = ifSheltered(pano1, pano0);
  30112. if (b && a + b >= 0.6) {
  30113. ifNeighbour = true;
  30114. }
  30115. }
  30116. map0[pano1.id] = map1[pano0.id] = ifNeighbour;
  30117. }
  30118. } else {
  30119. //标记为无需再计算, 因已经失败。 当map0和map1都不为void 0后就无法再计算了。
  30120. if (map0[pano1.id] === void 0) map0[pano1.id] = 0;
  30121. if (map1[pano0.id] === void 0) map1[pano0.id] = 0;
  30122. }
  30123. }
  30124. ifNeighbour = map1[pano0.id] == void 0 ? map0[pano1.id] : map0[pano1.id] && map1[pano0.id]; //如果map1没计算就只要返回map0
  30125. if (ifLog) {
  30126. console.log('isNeighbour', pano0.id + "(" + pano0.originID + ")", pano1.id + "(" + pano1.originID + ")", map0[pano1.id], map1[pano0.id]);
  30127. }
  30128. }
  30129. } else if (!onlyUseTex && !ifNeighbour) {
  30130. //使用点云判断(有深度贴图时不会执行到这)
  30131. /* let inDirection = ()=>{
  30132. let dir = new THREE.Vector3().subVectors(pano1.position,pano0.position).normalize()
  30133. let dis = pano1.position.distanceTo(pano0.position)
  30134. let fov = THREE.Math.degToRad(viewer.mainViewport.camera.fov)
  30135. let hfov = cameraLight.getHFOVForCamera(viewer.mainViewport.camera , true );
  30136. let hov = Math.min(fov, hfov)
  30137. let max = Math.cos(THREE.Math.degToRad(10))
  30138. let min = Math.cos(THREE.Math.degToRad(40))
  30139. if(this.getDirection().dot(dir) > THREE.Math.clamp(Math.cos(hov/2 ) * dis / 10, min, max )){//距离越远要求和视线角度越接近
  30140. return true
  30141. }
  30142. }
  30143. if(computeDirFirst){//先计算方向,防止重复计算ifBlockedByIntersect
  30144. if(inDirection()){
  30145. ifNeighbour = !viewer.inputHandler.ifBlockedByIntersect({point:pano1.position, margin, cameraPos:pano0.position})
  30146. }
  30147. }else{
  30148. ifNeighbour = !viewer.inputHandler.ifBlockedByIntersect({point:pano1.position, margin, cameraPos:pano0.position})
  30149. if(ifNeighbour && !inDirection()){
  30150. ifNeighbour = undefined //不确定
  30151. }
  30152. }
  30153. map0[pano1.id] = map1[pano0.id] = ifNeighbour ? 'byCloud' : ifNeighbour//写简单点
  30154. */
  30155. map0[pano1.id] = map1[pano0.id] = true; //全部可通行
  30156. }
  30157. if (map0[pano1.id] && map1[pano0.id]) {
  30158. pano0.neighbours.includes(pano1) || pano0.neighbours.push(pano1);
  30159. pano1.neighbours.includes(pano0) || pano1.neighbours.push(pano0);
  30160. }
  30161. return ifNeighbour;
  30162. }
  30163. bump(direction) {
  30164. //撞墙弹回效果
  30165. if (!this.bumping && !this.latestToPano) {
  30166. var distance = Potree.settings.displayMode == 'showPanos' ? 0.15 : 0.12; //感觉点云模式比全景模式更明显,所以降低
  30167. var currentPos = this.position.clone();
  30168. var endPosition = new Vector3().addVectors(this.position, direction.clone().multiplyScalar(distance));
  30169. var duration = 150;
  30170. viewer.scene.view.setView({
  30171. position: endPosition,
  30172. duration,
  30173. callback: () => {
  30174. viewer.scene.view.setView({
  30175. position: currentPos,
  30176. duration: duration * 5,
  30177. callback: () => {
  30178. this.bumping = false;
  30179. //this.dispatchEvent('cameraMoveDone')
  30180. },
  30181. Easing: 'easeInOutSine',
  30182. cancelFun: () => {
  30183. this.bumping = false;
  30184. }
  30185. });
  30186. this.bumping = true;
  30187. },
  30188. cancelFun: () => {
  30189. this.bumping = false;
  30190. },
  30191. Easing: 'easeInOutSine'
  30192. });
  30193. this.bumping = true;
  30194. }
  30195. //备注:将4dkk中的‘前后方向变化fov、左右方向移动镜头’ 都改为移动镜头。 因为这里无法判断左右离壁距离。
  30196. }
  30197. flyToPanoClosestToMouse() {
  30198. /* if (Date.now() - this.mouseLastMoveTime > 50) {
  30199. //this.intersect = this.getMouseIntersect();
  30200. this.intersect && this.updateClosestPano(this.intersect);
  30201. } */
  30202. if (!Potree.settings.ifShowMarker) {
  30203. //不显示marker的时候mousemove没更新鼠标最近点所以更新
  30204. this.updateClosestPano(viewer.inputHandler.intersect);
  30205. }
  30206. //console.log('flyToPanoClosestToMouse',this.closestPano)
  30207. if (this.closestPano) {
  30208. var pano = this.closestPano;
  30209. return this.flyToPano({
  30210. pano,
  30211. easeName: this.isAtPano() ? 'linearTween' : 'easeInOutQuad'
  30212. });
  30213. }
  30214. var direction = this.viewer.inputHandler.getMouseDirection().direction;
  30215. this.flyDirection(direction);
  30216. }
  30217. flyDirection(direction, option1, option2, byKey) {
  30218. if (viewer.mainViewport.view.isFlying()) {
  30219. // closestPanoInDirection函数耗时长,飞行时运行会卡顿(如果以后加无缝过渡再说)
  30220. return;
  30221. }
  30222. var deferred = $.Deferred();
  30223. //this.history.invalidate();
  30224. var panoSet = this.closestPanoInDirection(direction, option1, option2, byKey);
  30225. if (panoSet) {
  30226. this.flyToPano({
  30227. pano: panoSet,
  30228. callback: deferred.resolve.bind(deferred, !0)
  30229. });
  30230. } else {
  30231. //如果离数据集较远,转动也很难找到点云,就飞到就近点:
  30232. if (Potree.settings.displayMode == 'showPointcloud') {
  30233. var po = viewer.scene.pointclouds.find(e => e.visibleNodes.some(a => a.getLevel() > Math.ceil(e.maxLevel * 0.15))); //虽然当点云在前方很远的地方也可能符合
  30234. if (!po) {
  30235. //无可见点云
  30236. //console.log('no visi cloud')
  30237. if (!this.panos.length) {
  30238. //如果场景中没有漫游点,如SG-t-XPf1k9pv3Zg 点击后回到可见区域
  30239. if (viewer.scene.pointclouds.length == 0) return;
  30240. var map = new Map();
  30241. var clouds = viewer.scene.pointclouds.filter(e => e.root.geometryNode);
  30242. clouds.forEach(e => map.set(e, e.bound.distanceToPoint(this.position)));
  30243. clouds.sort((a, b) => map.get(a) - map.get(b));
  30244. viewer.flyToDataset({
  30245. focusOnPoint: true,
  30246. pointcloud: clouds[0],
  30247. duration: 500
  30248. }); //飞最近的一个点云
  30249. return deferred.promise();
  30250. }
  30251. this.flyToPano({
  30252. pano: this.findNearestPano(),
  30253. duration: 500,
  30254. callback: deferred.resolve.bind(deferred, !0)
  30255. });
  30256. return deferred.promise();
  30257. }
  30258. }
  30259. this.bump(direction);
  30260. deferred.resolve(!1);
  30261. }
  30262. return deferred.promise();
  30263. }
  30264. closestPanoInDirection(direction, option1, option2, byKey) {
  30265. return this.rankedPanoInDirection(0, direction, option1, option2, byKey);
  30266. }
  30267. rankedPanoInDirection(t, direction, option1, option2, byKey) {
  30268. //此direction为mouseDirection,是否需要加上相机角度的权重
  30269. var startTime = Date.now();
  30270. var panoSet = {
  30271. pano: null,
  30272. candidates: [] //缓存顺序--如果需要打印的话
  30273. };
  30274. t || (t = 0);
  30275. option1 = void 0 !== option1 ? option1 : 0.6; //.75; 2024.3.22改小,也就是可以走的角度范围增加,主要针对像山野那种很大的场景,不知道可以走哪,容易因角度范围内无近点而飞到远处的情况。但不能太小,总是横着走路
  30276. var o = option2 ? "angle" : "direction";
  30277. var floor = viewer.modules.SiteModel.currentFloor;
  30278. var entity = viewer.modules.SiteModel.inEntity;
  30279. var getHeightDis = pano => {
  30280. if (floor && !floor.panos.includes(pano) && pano.position.z < this.position.z) {
  30281. //若是上方的漫游点,就正常走。因为一般不会点击天花板。
  30282. return this.position.z - pano.position.z;
  30283. } else {
  30284. return 0;
  30285. }
  30286. };
  30287. var disSquareMap = new Map();
  30288. this.panos.forEach(pano => {
  30289. var dis2 = pano.position.distanceToSquared(this.position); //距离目标点
  30290. disSquareMap.set(pano, dis2);
  30291. });
  30292. var changeTexCount = 0,
  30293. maxWaitDur = 300;
  30294. //maxSamplerChangeTex = THREE.Math.clamp( maxWaitDur / Potree.timeCollect.depthSampler.median, 2, 10) //计算换贴图最大数目
  30295. var request = [
  30296. //必要条件
  30297. Images360.filters.not(this.currentPano), Images360.filters.isEnabled(),
  30298. //Images360.filters.inFloorDirection( this.position, direction, option1 ), //原先用inPanoDirection,但容易穿楼层,当mouse较低或较高 //因不束缚纵向所以可能往相反反向
  30299. pano => {
  30300. /* let isNeighbour = this.isNeighbour(this.currentPano, pano, true, true); //不计算的
  30301. if(isNeighbour == void 0){
  30302. let willChangeTex = pano.depthTex && !this.depthSampler.imgDatas.some(e=>e.pano == pano)
  30303. if(changeTexCount < maxSamplerChangeTex || !willChangeTex ){
  30304. isNeighbour = this.isNeighbour(this.currentPano, pano, false, true);//计算
  30305. if(willChangeTex && isNeighbour != void 0) changeTexCount++
  30306. }else{
  30307. if(disSquareMap.get(pano) < 500)return true //因为费时,超过一定个数就不计算了,距离近的话先可通行。
  30308. }
  30309. } */
  30310. // 不会再changeTex了
  30311. var isNeighbour = this.isNeighbour(this.currentPano, pano, {
  30312. onlyUseTex: true
  30313. });
  30314. if (isNeighbour || pano.noNeighbour && disSquareMap.get(pano) < 200) {
  30315. //在靠近孤立点时可以通行。但是不好把握这个距离,太远的话很多地方都会不小心到孤立点,太近的话可能永远到不了。
  30316. return true;
  30317. }
  30318. }
  30319. /* (pano)=>{ //防止不小心穿越地板到下一层, 尽量走楼梯,实在没有楼梯或楼梯漫游点稀疏的话就通过楼层按钮。
  30320. let dis = getHeightDis(pano)
  30321. //console.log('getHeightDis',pano.id,dis)
  30322. if(dis < 3){//不能超过最大高度差( 最大高度差暂定为接近一层楼的高度。)(最好的解决方案是设置漫游可行)
  30323. return true
  30324. }else{
  30325. return this.isNeighbour(this.currentPano, pano)
  30326. }
  30327. } */];
  30328. if (!byKey) {
  30329. request.push(Images360.filters.inPanoDirection(this.position, this.getDirection(), option1 /* , true */)); //垂直方向上再稍微限制一下, 要接近视线方向,避免点击前方时因无路而到下一楼。但不能太高,否则楼梯上稍微朝下点击都到不了上方。之所以使用视线方向是因为镜头方向比鼠标方向目的性更强。
  30330. }
  30331. var list = [
  30332. //决胜项目
  30333. pano => {
  30334. return -disSquareMap.get(pano);
  30335. }, Images360.scoreFunctions[o](this.position, direction, true), pano => {
  30336. var neighbour = this.isNeighbour(this.currentPano, pano, {
  30337. dontCompute: true,
  30338. isNeighbour: true
  30339. }); //不计算的
  30340. return neighbour ? directionFactor : 0;
  30341. }
  30342. /* (pano)=>{//尽量不穿越地板到下一层
  30343. let dis = getHeightDis(pano)
  30344. return -dis * directionFactor * 0.1;
  30345. }, */
  30346. /* (pano)=>{ //尽量在一个建筑内行走,这样不易穿墙
  30347. let score = 0
  30348. if(entity ){
  30349. if(!entity.panos.includes(pano) ) score -= directionFactor * 0.01; //不能设置太高,否则会走不进大房间的小房间中,因为容易穿过小房间的一个门到另一个门外
  30350. if(!floor.panos.includes(pano)) {//避免穿楼层
  30351. let heightDiff = Math.abs(pano.position.z - this.position.z);
  30352. if(heightDiff > 2){
  30353. score -= directionFactor * 0.1 * heightDiff;
  30354. }
  30355. }
  30356. }
  30357. return score
  30358. } */];
  30359. if (!byKey && viewer.inputHandler.intersect && this.currentPano) {
  30360. //方便上下楼, 考虑panos之间的角度差
  30361. var pos1 = this.currentPano.floorPosition;
  30362. var vec1 = new Vector3().subVectors(viewer.inputHandler.intersect.location, pos1).normalize(); //应该只有atPano时才会执行到这吧?
  30363. list.push(function (pano) {
  30364. var pos2 = pano.floorPosition;
  30365. var vec2 = pos2.clone().sub(pos1).normalize();
  30366. return vec2.dot(vec1) * directionFactor * 4;
  30367. });
  30368. }
  30369. this.findRankedByScore(t, request, list, panoSet);
  30370. //console.log( 'costTime:',Date.now() - startTime)
  30371. return panoSet.pano;
  30372. }
  30373. findRankedByScore(e, t, i, n) {
  30374. n && (n.candidates = null,
  30375. //candidates 缓存顺序--如果需要打印的话
  30376. n.pano = null), e || (e = 0);
  30377. var r = Common.sortByScore(this.panos, t, i);
  30378. //console.log('findRankedByScore', r && r.map(u=>u.item.id + '| ' + math.toPrecision(u.score,4) + " | " + math.toPrecision(u.scores,4)))
  30379. return !r || 0 === r.length || e >= r.length ? null : (n && (n.candidates = r, n.pano = r[e].item), r[e].item);
  30380. }
  30381. updateClosestPano(intersect, state) {
  30382. //hover到的pano 大多数时候是null
  30383. var pano;
  30384. if (intersect instanceof Panorama) {
  30385. //漫游模式
  30386. pano = state ? intersect : null;
  30387. } else {
  30388. if (this.isAtPano() || this.bumping) {
  30389. return;
  30390. } else {
  30391. var filterFuncs = [];
  30392. intersect = intersect && intersect.location;
  30393. if (!intersect) return;
  30394. var sortFuncs = Potree.settings.editType != 'pano' ? [Images360.sortFunctions.floorDisSquaredToPoint(intersect)] : [Images360.sortFunctions.disSquaredToPoint(intersect)];
  30395. pano = Common.find(this.panos, filterFuncs, sortFuncs);
  30396. }
  30397. }
  30398. if (pano != this.closestPano) {
  30399. pano && (this.isPanoHover = !0);
  30400. this.closestPanoChanging(this.closestPano, pano); // 高亮marker
  30401. //console.log('closestPano '+ (pano ? pano.id : 'null' ))
  30402. this.closestPano = pano;
  30403. } else {
  30404. this.isPanoHover = !1;
  30405. }
  30406. }
  30407. closestPanoChanging(oldPano, newPano) {
  30408. if (!Potree.settings.ifShowMarker) return;
  30409. oldPano && oldPano.hoverOff({
  30410. byImages360: true
  30411. });
  30412. newPano && newPano.hoverOn({
  30413. byImages360: true
  30414. });
  30415. }
  30416. getTileDirection() {
  30417. //根据不同dataset的来存储
  30418. var vectorForward = viewer.scene.view.direction.clone();
  30419. var vectorForwards = viewer.scene.pointclouds.concat(viewer.objs.children.filter(e => e.panos)).map(e => {
  30420. var inv = new Matrix4().copy(e.rotateMatrix).invert(); //乘上dataset的旋转的反转
  30421. var direction = vectorForward.clone().applyMatrix4(inv);
  30422. return {
  30423. datasetId: e.dataset_id,
  30424. direction: math.convertVector.ZupToYup(direction)
  30425. };
  30426. });
  30427. //return vectorForwards[0].direction
  30428. return {
  30429. datasetsLocal: vectorForwards,
  30430. vectorForward
  30431. };
  30432. }
  30433. update() {
  30434. //if(this.tileDownloader.started){
  30435. var vectorForwards = this.getTileDirection();
  30436. //vectorForwards = vectorForwards[0].direction
  30437. this.updateTileDownloader(tileArr, vectorForwards);
  30438. this.updatePanoRenderer(vectorForwards);
  30439. //}
  30440. this.updateZoomPano();
  30441. }
  30442. updateTileDownloader(t, vectorForward) {
  30443. var i = this.nextPano || this.currentPano;
  30444. if (i) {
  30445. this.tileDownloader.tilePrioritizer.updateCriteria(i, viewer.scene.view.position.clone(), vectorForward, t.length > 0 ? t : null), this.tileDownloader.processPriorityQueue = !0;
  30446. }
  30447. }
  30448. updatePanoRenderer(vectorForward) {
  30449. var i = this.nextPano || this.currentPano;
  30450. if (i) {
  30451. if (this.panoRenderer.hasQueuedTiles() && i) {
  30452. this.panoRenderer.updateDirection(vectorForward);
  30453. }
  30454. }
  30455. }
  30456. //等待部分加载完
  30457. checkAndWaitForTiledPanoLoad(pano, basePanoSize, callback1, callback2, progressCallback, iswait, isclear, l) {
  30458. //console.log('checkAndWaitForTiledPanoLoad',pano.id)
  30459. if (!pano) {
  30460. console.error("Player.checkAndWaitForTiledPanoLoad() -> Cannot load texture for null pano.");
  30461. }
  30462. var vectorForward = this.getTileDirection();
  30463. if (!pano.isLoaded(basePanoSize)) {
  30464. iswait && viewer.waitForLoad(pano, function () {
  30465. //发送loading
  30466. return pano.isLoaded(basePanoSize);
  30467. });
  30468. /* var fov = {//test for direction 预加载的边缘有一丢丢不准确,尤其在相机倾斜时(4dkk也是)。
  30469. hFov: cameraLight.getHFOVForCamera(viewer.scene.getActiveCamera() ),
  30470. vFov: viewer.scene.getActiveCamera().fov
  30471. }//原先是null,不要求方向 */
  30472. var fov = null; //若不为null的话,因为可能可见范围的tile下载过了从而无法触发下载,然后得不到下载成功的消息,怎么办
  30473. pano.loadTiledPano( /* 1024 */basePanoSize, vectorForward, fov, isclear, l, null).done(function (e, t) {
  30474. callback1 && callback1(e, t);
  30475. }.bind(this)).fail(function (msg) {
  30476. callback2 && callback2(msg);
  30477. }.bind(this)).progress(function (e, t, i) {
  30478. progressCallback && progressCallback(e, t, i);
  30479. }.bind(this));
  30480. return !0;
  30481. }
  30482. }
  30483. fitPanoTowardPoint(o) {
  30484. //寻找最适合的点位
  30485. var point = o.point,
  30486. //相机最佳位置
  30487. target = o.target || o.point,
  30488. //实际要看的位置
  30489. require = o.require || [],
  30490. rank = o.rank || [],
  30491. force = o.force,
  30492. getAll = o.getAll,
  30493. bestDistance = o.bestDistance || 0,
  30494. sameFloor = o.sameFloor,
  30495. maxDis = o.maxDis,
  30496. dir = o.dir;
  30497. var camera = viewer.scene.getActiveCamera();
  30498. if (target && !dir) {
  30499. dir = new Vector3().subVectors(target, point).normalize();
  30500. }
  30501. var atFloor = sameFloor && viewer.modules.SiteModel.pointInWhichEntity(point, 'floor');
  30502. //if(o.floor)require.push(Panorama.filters.atFloor(o.floor))
  30503. var checkIntersect = o.checkIntersect;
  30504. var base = Math.max(300, viewer.bound.boundSize.length() * 3);
  30505. if (o.boundSphere) {
  30506. //只接受boundSphere
  30507. var aspect = 1; //size.x / size.y
  30508. var dis;
  30509. if (camera.aspect > aspect) {
  30510. //视野更宽则用bound的纵向来决定
  30511. dis = /* size.y */o.boundSphere.radius /* / 2 */ / MathUtils.degToRad(camera.fov / 2);
  30512. } else {
  30513. var hfov = cameraLight.getHFOVForCamera(camera, true);
  30514. dis = /* size.x */o.boundSphere.radius /* / 2 */ / (hfov / 2);
  30515. }
  30516. bestDistance = dis; //*0.8
  30517. }
  30518. var disSquareMap = new Map();
  30519. var bestDisSquared = bestDistance * bestDistance;
  30520. var maxDisSquared = maxDis && maxDis * maxDis;
  30521. this.panos.forEach(pano => {
  30522. var dis2 = pano.position.distanceToSquared(target); //距离目标点
  30523. disSquareMap.set(pano, dis2);
  30524. });
  30525. var panos = this.panos.sort((p1, p2) => {
  30526. return disSquareMap.get(p1) - disSquareMap.get(p2);
  30527. });
  30528. if (maxDisSquared) {
  30529. //热点超过最大距离不可见的
  30530. var panos2 = [],
  30531. _pano,
  30532. i = 0;
  30533. while (_pano = panos[i], disSquareMap.get(_pano) < maxDisSquared) {
  30534. panos2.push(_pano);
  30535. i++;
  30536. }
  30537. if (panos2.length == 0) return {
  30538. pano: _pano,
  30539. msg: 'tooFar'
  30540. }; //全部都大于maxDis, 就返回最近的
  30541. panos = panos2;
  30542. }
  30543. rank.push(pano => {
  30544. var dis1 = Math.abs(pano.position.distanceToSquared(point) - bestDisSquared); //距离最佳位置
  30545. disSquareMap.set(pano, dis1);
  30546. if (!target) {
  30547. return -dis1;
  30548. } else {
  30549. var dis2 = disSquareMap.get(pano);
  30550. if (o.gotoBestView) {
  30551. //忽略和当前视线的角度
  30552. return -(dis1 + dis2 * 0.3);
  30553. }
  30554. var vec2 = new Vector3().subVectors(target, pano.position).normalize();
  30555. var cos = dir.dot(vec2);
  30556. //let result = (- dis1 - Math.pow(dis2 , 1.5)) / (cos + 2) // cos+2是为了调整到1-3,
  30557. var result = (dis1 + dis2 * 0.3) * (-1 + cos * 0.9); //尽量贴近最佳位置的角度, 或贴近相机原来的角度 。尽量靠近最佳观测点,并且优先选择靠近目标点的位置.(注意cos的乘数不能太接近1,否则容易只考虑角度)
  30558. //Potree.Log(pano.id, dis1, dis2, cos, result,{font:{toFixed:2,fontSize:10}})
  30559. return result;
  30560. }
  30561. //注:热点最好加上法线信息,这样可以多加一个限制,尽量顺着热点像展示的方向。
  30562. }, pano => {
  30563. var score = 0;
  30564. if (pano.depthTex && checkIntersect) {
  30565. var intersect = !!viewer.ifPointBlockedByIntersect(target, pano.id, true); //viewer.inputHandler.ifBlockedByIntersect({point:target, margin:0.1, cameraPos:pano})
  30566. if (intersect) {
  30567. score = 0;
  30568. } else {
  30569. score = base * 2;
  30570. }
  30571. } else {
  30572. score = base * 1.5; //没加载好的话,不管了 , 几乎当做无遮挡,否则容易到不了最近点
  30573. }
  30574. return score;
  30575. });
  30576. var g = Common.sortByScore(panos, require, rank);
  30577. // console.log(g)
  30578. /* let result1 = g && g.slice(0, 10)
  30579. if(result1){
  30580. g = Common.sortByScore(result1, [], [(e)=>{//避免遮挡
  30581. let pano = e.item;
  30582. let score = 0, log = ''
  30583. if(atFloor && atFloor.panos.includes(pano)){//如果不在任何一楼呢?
  30584. score += 600, log+='atFloor'
  30585. }
  30586. return {score, log}
  30587. }]);
  30588. if(g){
  30589. g.forEach(e=>{e.item = e.item.item})
  30590. }
  30591. console.log(g)
  30592. } */
  30593. var pano = g && g.length > 0 && g[0].item;
  30594. if (pano && checkIntersect) {
  30595. var intersect = !!viewer.ifPointBlockedByIntersect(target, pano.id, true);
  30596. if (intersect) {
  30597. return {
  30598. pano,
  30599. msg: 'sheltered'
  30600. };
  30601. }
  30602. }
  30603. //if(getAll)return g;
  30604. return pano;
  30605. //注:深度图有的位置会不准确,以至于会算出错误的遮挡、选择错误的pano,解决办法只能是移动下热点到更好的位置
  30606. }
  30607. //---------------scroll zoom ------------------------------------------
  30608. /* zoomIn = function() { //放大
  30609. this.zoomBy(1 + this.zoomSpeed);
  30610. }
  30611. zoomOut = function() {//缩小
  30612. this.zoomBy(1 - this.zoomSpeed);
  30613. } */
  30614. zoomBy(e, pointer) {
  30615. //以倍数
  30616. this.zoomTo(this.zoomLevel * e, pointer);
  30617. }
  30618. zoomTo(zoomLevel, pointer) {
  30619. //缩放到某绝对zoomLevel
  30620. var zoom = Potree.settings.zoom;
  30621. if (zoom.enabled) {
  30622. zoomLevel = MathUtils.clamp(zoomLevel, zoom.min, zoom.max);
  30623. //console.log(zoomLevel)
  30624. if (zoomLevel == this.zoomLevel) return;
  30625. this.zoomLevel = zoomLevel;
  30626. if (Potree.settings.panoZoomByPointer) {
  30627. //定点缩放:使当前鼠标所在的位置缩放后不变
  30628. var view = viewer.scene.view;
  30629. var originDir = viewer.scene.view.direction;
  30630. var oldPointerDir = viewer.inputHandler.getMouseDirection(pointer).direction;
  30631. viewer.setFOV(Potree.config.view.fov * (1 / this.zoomLevel));
  30632. var newPointerDir = viewer.inputHandler.getMouseDirection(pointer).direction;
  30633. view.direction = oldPointerDir; //获取一下鼠标所在位置的yaw 和 pitch
  30634. var oldPitch = view.pitch,
  30635. oldYaw = view.yaw;
  30636. view.direction = newPointerDir;
  30637. var newPitch = view.pitch,
  30638. newYaw = view.yaw;
  30639. view.direction = originDir; //还原
  30640. viewer.scene.view.pitch -= newPitch - oldPitch;
  30641. viewer.scene.view.yaw -= newYaw - oldYaw;
  30642. } else {
  30643. viewer.setFOV(Potree.config.view.fov * (1 / this.zoomLevel));
  30644. }
  30645. }
  30646. }
  30647. zoomFovTo(fov) {
  30648. //通过fov来算zoomLevel
  30649. var zoomLevel = Potree.config.view.fov /* this.baseFov */ / fov;
  30650. this.zoomTo(zoomLevel);
  30651. }
  30652. smoothZoomTo(aimLevel) {
  30653. var dur = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  30654. var currentLevel = this.zoomLevel;
  30655. if (currentLevel == aimLevel) return;
  30656. var fun = progress => {
  30657. //progress > 1 && (progress = 1)
  30658. var level = currentLevel * (1 - progress) + aimLevel * progress;
  30659. this.zoomTo(level, !0);
  30660. };
  30661. transitions.start(fun, dur, null, null, 0, easing['easeInOutQuad']);
  30662. }
  30663. updateZoomPano() {
  30664. if (!this.panoRenderer.zoomPanoRenderingDisabled && Potree.settings.displayMode == 'showPanos') {
  30665. var currentPano = this.currentPano;
  30666. if (currentPano) {
  30667. var levelThreshold1 = Potree.settings.navTileClass == '1k' ? 1.3 : 1.7,
  30668. levelThreshold2 = 2;
  30669. var t = this.zoomLevel > levelThreshold1,
  30670. n = !(this.flying && this.nextPano && this.nextPano !== this.currentPano),
  30671. r = t && n;
  30672. this.tileDownloader.tilePrioritizer.setZoomingActive(r);
  30673. this.panoRenderer.setZoomingActive(r, currentPano, !0);
  30674. var o = (pano, ifZoom) => {
  30675. this.panoRenderer.resetRenderStatus(pano.id, !1, !0, this.qualityManager.getMaxNavPanoSize());
  30676. this.panoRenderer.clearAllQueuedUploadsForPano(pano.id);
  30677. this.panoRenderer.renderPanoTiles(pano.id, null, !1, !1);
  30678. pano.setZoomed(ifZoom);
  30679. };
  30680. if (r && (!currentPano.zoomed || this.qualityManager.zoomLevelResolution && this.qualityManager.zoomLevelResolution != '4k')) {
  30681. //needZoom
  30682. currentPano.zoomed || o(currentPano, !0);
  30683. if (Potree.settings.navTileClass == '1k' && Potree.settings.tileClass != '1k' && this.zoomLevel < levelThreshold2) {
  30684. this.panoRenderer.enableHighQuality(function () {
  30685. //开启2k
  30686. if (Potree.settings.tileClass != '4k') o(currentPano, !0);
  30687. }.bind(this));
  30688. } else {
  30689. this.panoRenderer.enableUltraHighQualityMode(function () {
  30690. //开启4k getMaxZoomPanoSize
  30691. this.qualityManager.useUltraHighResolutionPanos && (Potree.settings.zoom.max = Potree.config.ultraHighQualityMaxZoom);
  30692. o(currentPano, !0);
  30693. }.bind(this));
  30694. }
  30695. } else {
  30696. !t && currentPano.zoomed && o(currentPano, !1);
  30697. }
  30698. if (r && Potree.settings.navTileClass == '1k' && Potree.settings.tileClass == '4k') {
  30699. //目前只有手机端navTileClass == '1k' (分三个梯度)
  30700. var change = zoomedFlag => {
  30701. this.qualityManager.updateMaximums(); //更新maxZoomPanoSize
  30702. this.panoRenderer.setupZoomRenderTarget(); //更新renderTarget
  30703. //currentPano.setZoomed(t);//更新uniforms贴图
  30704. };
  30705. this.qualityManager.zoomLevelResolution = this.zoomLevel >= levelThreshold2 ? '4k' : this.zoomLevel > levelThreshold1 ? '2k' : '1k';
  30706. if (this.oldZoomLevel < levelThreshold2 && this.zoomLevel >= levelThreshold2) {
  30707. //1k/2k-4k
  30708. change();
  30709. o(currentPano, t);
  30710. } else if (this.oldZoomLevel <= levelThreshold1 && this.zoomLevel > levelThreshold1) {
  30711. //1k-2k
  30712. change();
  30713. } else if (this.oldZoomLevel > levelThreshold2 && this.zoomLevel <= levelThreshold2) {
  30714. //4k-2k/1k
  30715. change();
  30716. o(currentPano, t);
  30717. } else if (this.oldZoomLevel > levelThreshold1 && this.zoomLevel <= levelThreshold1) {
  30718. //2k-1k
  30719. change();
  30720. }
  30721. this.oldZoomLevel = this.zoomLevel;
  30722. }
  30723. }
  30724. }
  30725. }
  30726. //--------------------
  30727. addHighMapCube() {
  30728. //创建8*8的tile cube 主要因手机版崩溃 要在电脑端测试得设置maxRenderTargetSize
  30729. if (Potree.settings.tileClass == '4k' && this.qualityManager.maxRenderTargetSize == 2048) {
  30730. var geo = new PlaneGeometry(1, 1, 1, 1);
  30731. var cube = new Object3D();
  30732. cube.tiles = [];
  30733. for (var cubeIndex = 0; cubeIndex < 6; cubeIndex++) {
  30734. var face = new Object3D();
  30735. for (var i = 0; i < 8; i++) {
  30736. for (var j = 0; j < 8; j++) {
  30737. var tile = new Mesh(geo, new MeshBasicMaterial({
  30738. //side:THREE.DoubleSide
  30739. transparent: true,
  30740. opacity: 0.4,
  30741. depthTest: false
  30742. }));
  30743. tile.position.set(i - 3.5, j - 3.5, -4);
  30744. if (Potree.settings.isTest) {
  30745. var colorHue = Math.random();
  30746. tile.material.color = new Color().setHSL(colorHue, 0.6, 0.7);
  30747. /* tile.scoreLabel = new TextSprite( {
  30748. backgroundColor: { r: 0, g: 0, b: 0, a: 0 },
  30749. textColor: { r: 0, g: 0, b: 0, a: 1 },
  30750. borderRadius: 15,
  30751. renderOrder: 50, fontsize : 13,
  30752. text: '' ,
  30753. dontFixOrient:true
  30754. })
  30755. tile.scoreLabel.sprite.material.side = 2;
  30756. tile.scoreLabel.rotation.x = Math.PI
  30757. tile.add(tile.scoreLabel) */
  30758. }
  30759. tile.visible = false;
  30760. tile.tileX = i;
  30761. tile.tileY = j;
  30762. tile.cubeFace = cubeIndex;
  30763. //tile.renderOrder = RenderOrder.highTileCube
  30764. cube.tiles.push(tile);
  30765. face.add(tile);
  30766. }
  30767. }
  30768. switch (cubeIndex) {
  30769. case GLCubeFaces$3.GL_TEXTURE_CUBE_MAP_POSITIVE_X:
  30770. face.rotation.set(0, Math.PI / 2, 0);
  30771. break;
  30772. case GLCubeFaces$3.GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
  30773. face.rotation.set(0, -Math.PI / 2, 0);
  30774. break;
  30775. case GLCubeFaces$3.GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
  30776. var rot1 = new Quaternion().setFromAxisAngle(new Vector3(0, 1, 0), Math.PI);
  30777. var rot2 = new Quaternion().setFromAxisAngle(new Vector3(1, 0, 0), Math.PI / 2);
  30778. face.quaternion.copy(rot1).multiply(rot2);
  30779. //face.rotation.set(Math.PI/2,0,0);
  30780. break;
  30781. case GLCubeFaces$3.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
  30782. //face.rotation.set(-Math.PI/2,0,0);
  30783. var rot1 = new Quaternion().setFromAxisAngle(new Vector3(0, 1, 0), Math.PI);
  30784. var rot2 = new Quaternion().setFromAxisAngle(new Vector3(1, 0, 0), -Math.PI / 2);
  30785. face.quaternion.copy(rot1).multiply(rot2);
  30786. break;
  30787. case GLCubeFaces$3.GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
  30788. face.rotation.set(0, Math.PI, 0);
  30789. break;
  30790. case GLCubeFaces$3.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
  30791. face.rotation.set(0, 0, 0);
  30792. }
  30793. face.scale.set(1, -1, 1);
  30794. face.cubeFace = cubeIndex;
  30795. cube.add(face);
  30796. }
  30797. cube.name = 'highMapCube';
  30798. this.highMapCube = cube;
  30799. viewer.scene.scene.add(cube);
  30800. {
  30801. var s = 0.1;
  30802. cube.scale.set(s, s, s);
  30803. } //注:由于原本的mesh上加了深度贴图,可能距离镜头比这里的近。凡是在cube以内的部分都会挡住cube导致模糊。但是应该不常见吧(另外到天空的边缘也是很近)。姑且depthTest=false
  30804. this.highMapCube.visible = false;
  30805. Potree.Utils.setObjectLayers(this.highMapCube, 'sceneObjects' /* 'skybox' */); //因它的深度是错误的,故不在skybox层渲染,影响edlRT, 而在renderOverlay时渲染覆盖。
  30806. //console.warn('addHighMapCube')
  30807. viewer.addEventListener('update', () => {
  30808. if (this.highMapCube.visibleTiles) {
  30809. this.updateTiles(); //逐步将visibleTiles加载完
  30810. }
  30811. });
  30812. viewer.addEventListener('camera_changed', e => {
  30813. if (e.viewport == viewer.mainViewport) {
  30814. //重新获取visibleTiles
  30815. Common.intervalTool.isWaiting('update4kTiles', () => {
  30816. var vectorForward = this.getDirection();
  30817. this.updateTiles(vectorForward);
  30818. }, 500);
  30819. }
  30820. });
  30821. }
  30822. }
  30823. isHighMapLoaded(cubeFace, tileX, tileY) {
  30824. var tile = this.highMapCube.children[cubeFace].children[tileX * 8 + tileY];
  30825. return !!tile.material.map;
  30826. }
  30827. updateTiles(direction) {
  30828. if (!this.highMapCube || !this.highMapCube.visible) return;
  30829. if (this.highMapCube.tiles.filter(e => e.image).length <= 10) return; //加载的太少了
  30830. //performance.mark('updateTiles-start')
  30831. if (direction) {
  30832. var camera = viewer.mainViewport.camera;
  30833. var hfov = cameraLight.getHFOVForCamera(camera, true) / 2;
  30834. var vfov = MathUtils.degToRad(camera.fov) / 2;
  30835. /* let hcos = Math.cos(hfov / 2)
  30836. let vcos = Math.cos(vfov / 2) */
  30837. var list = this.highMapCube.tiles;
  30838. list.forEach(e => {
  30839. //屏幕外的不显示
  30840. var pos = e.getWorldPosition(new Vector3());
  30841. var dir = new Vector3().subVectors(pos, this.highMapCube.position).normalize();
  30842. var hcos_ = dir.clone().setZ(direction.z).normalize().dot(direction); //在direction的斜面上水平角度差
  30843. var hRad = Math.acos(hcos_);
  30844. var vRad = -200;
  30845. if ( /* hRad > hfov + 0.08 */hRad / hfov > 1.5) {
  30846. e.score = -100;
  30847. } else {
  30848. vRad = Math.abs(Math.acos(dir.z) - Math.acos(direction.z));
  30849. if ( /* vRad > vfov + 0.08 */vRad / vfov > 1.5) {
  30850. e.score = -100;
  30851. } else {
  30852. e.score = -(hRad / hfov + vRad / vfov);
  30853. }
  30854. }
  30855. e.scores = hRad.toFixed(3) + ', ' + vRad.toFixed(3);
  30856. if (e.score == -100) {
  30857. this.resetTile(e);
  30858. }
  30859. });
  30860. this.highMapCube.visibleTiles = list.filter(e => e.score > -100);
  30861. //list.forEach(e=>e.scoreLabel.setText(e.scores))
  30862. }
  30863. var needRecover = this.highMapCube.visibleTiles.filter(e => !e.material.map);
  30864. if (needRecover.length) {
  30865. var maxCount = Common.getBestCount('4kmaxTileRecover', 0, 2, 1.5, 6, false, 2);
  30866. var count = 0;
  30867. console.log(maxCount);
  30868. needRecover.forEach((e, i) => {
  30869. //只更新若干个,因为太耗时了, 其余的等下帧更新
  30870. if (count >= maxCount) return;
  30871. var r = this.recoverTile(e);
  30872. if (r) count++;
  30873. });
  30874. }
  30875. }
  30876. getHighImage(image, cubeFace, tileX, tileY) {
  30877. var tile = this.highMapCube.children[cubeFace].children[tileX * 8 + tileY];
  30878. tile.image = image; //先记录下来
  30879. }
  30880. updateHighMap(image, cubeFace, tileX, tileY) {
  30881. //console.warn('updateHighMap')
  30882. var tile = this.highMapCube.children[cubeFace].children[tileX * 8 + tileY];
  30883. if (image) tile.image = image; //先记录下来
  30884. if (tile.material.map) return;
  30885. if (this.highMapCube.visibleTiles && !this.highMapCube.visibleTiles.includes(tile) /* this.highMapCube.texLoadedCount >= this.getMaxTileCount() */) {
  30886. return;
  30887. }
  30888. //简易创建贴图
  30889. /* var tex = this.$app.core.get('SceneRenderer').initSizedTexture2D(512, THREE.ClampToEdgeWrapping)
  30890. //var loaded = this.$app.core.get('Player').model.isHighMapLoaded(tile.cubeFace, tile.tileX, tile.tileY)
  30891. this.$app.core.get('SceneRenderer').uploadTexture2D(image, tex, 0, 0, 512, 512) //只替换tex对应的img,不新建
  30892. */
  30893. var tex = new Texture();
  30894. tex.image = image;
  30895. tex.flipY = false;
  30896. tex.wrapS = tex.wrapT = ClampToEdgeWrapping;
  30897. tex.generateMipmaps = false;
  30898. tex.minFilter = LinearFilter;
  30899. tex.needsUpdate = true;
  30900. tile.material.map = tex;
  30901. tile.material.opacity = 1;
  30902. tile.material.transparent = false;
  30903. tile.visible = true;
  30904. tile.material.needsUpdate = true; //发现每次开始放大但还未放大到4k时也会把之前加载过的4k加载
  30905. }
  30906. recoverTile(tile) {
  30907. if (tile.material.map) return;
  30908. if (tile.image) {
  30909. this.updateHighMap(tile.image, tile.cubeFace, tile.tileX, tile.tileY);
  30910. return true;
  30911. } else {
  30912. //console.log('no image')
  30913. }
  30914. }
  30915. resetTile(tile, kill) {
  30916. if (kill) {
  30917. //完全消灭
  30918. tile.image = null;
  30919. }
  30920. var map = tile.material.map;
  30921. if (map) {
  30922. map.dispose(); //这句执行了以后,h.__webglTexture一直就是undefined
  30923. map.loaded = !1;
  30924. map.version = 0;
  30925. //保底再执行一下这个,类似app.sceneRenderer.deallocateCubeTexture(tile.material.map)
  30926. var h = viewer.renderer.properties.get(map);
  30927. //console.log('__webglTexture',!!h.__webglTexture)
  30928. viewer.renderer.getContext().deleteTexture(h.__webglTexture);
  30929. tile.material.map = null;
  30930. tile.material.needsUpdate = true;
  30931. tile.visible = false;
  30932. //this.highMapCube.texLoadedCount --
  30933. //console.log('resetTile'/* , tile.cubeFace, tile.tileX, tile.tileY */)
  30934. }
  30935. }
  30936. resetHighMap() {
  30937. if (!this.highMapCube) return;
  30938. this.highMapCube.children.forEach(e => e.children.forEach(tile => {
  30939. this.resetTile(tile, true);
  30940. }));
  30941. //this.highMapCube.texLoadedCount = 0
  30942. this.highMapCube.visibleTiles = null;
  30943. this.hideHighMap();
  30944. //console.log('resetHighMap')
  30945. }
  30946. setHighMap(pano) {
  30947. if (!this.highMapCube) return;
  30948. this.highMapCube.position.copy(pano.position);
  30949. //可以利用第0个pano查看,其 rotation4dkk是(_x: 0, _y: -1.5707963267948966, _z: 0 )而手动旋转至(_x:1.5707963, _y: -1.57079, _z: 0)时才正确,说明要在4dkk的旋转基础上,绕x轴转90度,(也就是转成navvis坐标系), 然后得到YupToZup的函数写法的
  30950. this.highMapCube.quaternion.copy(math.convertQuaternion.YupToZup(pano.quaternion4dkk));
  30951. //乘上数据集整体的旋转:
  30952. var modelRotQua = new Quaternion().setFromRotationMatrix(pano.pointcloud.rotateMatrix);
  30953. this.highMapCube.quaternion.premultiply(modelRotQua);
  30954. }
  30955. showHighMap() {
  30956. if (!this.highMapCube) return;
  30957. //console.warn('showHighMap')
  30958. this.highMapCube.visible = true;
  30959. }
  30960. hideHighMap() {
  30961. if (!this.highMapCube) return;
  30962. //console.warn('hideHighMap')
  30963. this.highMapCube.visible = false;
  30964. }
  30965. //缩小后继续显示cube呢还是不显示? 不显示的话,就要把cube上的复制到renderTarget上……会不会又崩溃,or没加载的显示???
  30966. addPanoData(data, pointcloud) {
  30967. //加载漫游点
  30968. //data[0].file_id = '00019'
  30969. if (data.data) data = data.data;
  30970. if (data.length == 0) console.error(pointcloud.dataset_id + ' 没有漫游点');
  30971. //data = data.sort(function(a,b){return a.id-b.id})
  30972. data.forEach(info => {
  30973. //if(Potree.fileServer){
  30974. info.id = this.panos.length; //把info的id的一长串数字改简单点
  30975. info.pointcloud = pointcloud;
  30976. //}
  30977. var pano = new Panorama(info, this);
  30978. pano.addEventListener('dispose', e => {
  30979. if (this.closestPano == pano) this.closestPano = null;
  30980. });
  30981. this.panos.push(pano);
  30982. this.neighbourMap[info.id] = {};
  30983. pano.label && Potree.Utils.setObjectLayers(pano.label, 'bothMapAndScene');
  30984. pano.label2 && Potree.Utils.setObjectLayers(pano.label2, 'bothMapAndScene');
  30985. if (Potree.settings.editType == 'pano') {
  30986. Potree.settings.datasetsPanos[datasetId].panos.push(pano);
  30987. }
  30988. });
  30989. }
  30990. loadDone() {
  30991. Potree.Utils.setObjectLayers(this.node, 'sceneObjects');
  30992. this.tileDownloader.setPanoData(this.panos, []);
  30993. {
  30994. var minSize = new Vector3(1, 1, 1);
  30995. this.bound = math.getBoundByPoints(this.panos.map(e => e.position), minSize);
  30996. viewer.scene.pointclouds.forEach(pointcloud => pointcloud.getPanosBound());
  30997. }
  30998. if (viewer.scene.pointclouds.some(e => e.panos.length == 0)) {
  30999. //console.warn('存在数据集没有pano');
  31000. viewer.hasNoPanoDataset = true;
  31001. }
  31002. }
  31003. getPano(value) {
  31004. var typeName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'id';
  31005. //默认找的是id,也可以是sid、uuid
  31006. return this.panos.find(p => p[typeName] == value);
  31007. }
  31008. }
  31009. ;
  31010. //判断当前点是否加载了全景图
  31011. Images360.prototype.checkAndWaitForPanoLoad = function () {
  31012. var isLoadedPanos = {},
  31013. LoadedTimePanos = {},
  31014. loadedCallback = {},
  31015. //add
  31016. maxTime = 5e3;
  31017. var withinTime = function withinTime() {
  31018. for (var panoId in isLoadedPanos) if (isLoadedPanos.hasOwnProperty(panoId) && isLoadedPanos[panoId]) {
  31019. var differTime = performance.now() - LoadedTimePanos[panoId];
  31020. if (differTime < maxTime) return !0;
  31021. }
  31022. return !1;
  31023. };
  31024. return function (pano, basePanoSize, doneFun1, doneFun2, progressCallback, iswait, isclear, p) {
  31025. loadedCallback[pano.id] = doneFun1; //add 因为有可能之前请求的没加doneFun1, 如果加载好就执行最新的doneFun1
  31026. if (withinTime()) {
  31027. //距离上次请求时间很近
  31028. //console.log(11)
  31029. return !0; //这里感觉应该是!1
  31030. }
  31031. var changeMode = e => {
  31032. if (e.mode == 'showPointCloud') {
  31033. console.warn('切到点云模式了,就删除loadedCallback记录', pano.id); //否则再次转为showPanos会被withinTime阻拦
  31034. delete isLoadedPanos[pano.id];
  31035. viewer.cancelLoad(pano);
  31036. loadedCallback[pano.id] && loadedCallback[pano.id](); //可以飞行了
  31037. doneFun2 && doneFun2();
  31038. this.removeEventListener('requestMode', changeMode);
  31039. }
  31040. };
  31041. this.addEventListener('requestMode', changeMode);
  31042. var callback1 = (param1, param2) => {
  31043. setTimeout(() => {
  31044. isLoadedPanos[pano.id] = !1;
  31045. loadedCallback[pano.id] && loadedCallback[pano.id](param1, param2);
  31046. this.removeEventListener('requestMode', changeMode);
  31047. }, 1);
  31048. };
  31049. var callback2 = param => {
  31050. //没有看到有传doneFun2的
  31051. setTimeout(() => {
  31052. isLoadedPanos[pano.id] = !1;
  31053. doneFun2 && doneFun2(param);
  31054. }, 1);
  31055. };
  31056. try {
  31057. null !== iswait && void 0 !== iswait || (iswait = !0);
  31058. isLoadedPanos[pano.id] = this.checkAndWaitForTiledPanoLoad(pano, basePanoSize, callback1, callback2, progressCallback, iswait, isclear, p);
  31059. //true代表没加载好
  31060. isLoadedPanos[pano.id] && (LoadedTimePanos[pano.id] = performance.now());
  31061. return isLoadedPanos[pano.id];
  31062. } catch (msg) {
  31063. isLoadedPanos[pano.id] = !1;
  31064. LoadedTimePanos[pano.id] = performance.now() - maxTime;
  31065. throw msg;
  31066. }
  31067. };
  31068. }(); //加载全景图的流程:请求下载当前点的最低分辨率图(不过有可能已经下载了),并且请求uploadTile渲染当前漫游点,若tile都upload完(先6个)会发送消息,LoadComplete 从而回调成功。
  31069. Images360.prototype.getNeighbours = function () {
  31070. //逐渐自动获取neighbours。 200个点差不多在半分钟内算完
  31071. var lastIndex, inited; //标记上次查询到哪,防止重新sortByScore
  31072. return function (interacted) {
  31073. if (!this.currentPano || viewer.mainViewport.view.isFlying() || viewer.lastFrameChanged || viewer.inputHandler.drag /* interacted */) {
  31074. //拖拽时不更新,否则移动端卡
  31075. return lastIndex = 0;
  31076. }
  31077. var nearPanos = this.tileDownloader.tilePrioritizer.nearPanos;
  31078. if (!nearPanos) return;
  31079. //let startTime = Date.now()
  31080. var panos = [this.currentPano, ...nearPanos];
  31081. this.depthSampler.updateNearPanos(panos);
  31082. var maxWaitDur = browser.isMobile() ? 40 : 60;
  31083. var changeCount = 0,
  31084. maxChangeTex = browser.isMobile() ? 1 : 3,
  31085. getCount = 0;
  31086. var changeTexCount = () => {
  31087. changeCount++;
  31088. };
  31089. var median = Potree.timeCollect.depthSamChangeImg.median;
  31090. var ifOverTime = () => {
  31091. var is = changeCount >= maxChangeTex || changeCount * median + getCount * 0.01 > maxWaitDur; //不换贴图也要一丢丢计算时间
  31092. /* if(is){
  31093. console.log('OverTime, changeCount', changeCount)
  31094. } */
  31095. return is;
  31096. };
  31097. this.depthSampler.addEventListener('changeImg', changeTexCount);
  31098. outer: for (var i = lastIndex, j = panos.length; i < j; i++) {
  31099. var pano = panos[i];
  31100. var others = panos.slice(i + 1, j);
  31101. lastIndex = i;
  31102. if (!pano.pointcloud.hasDepthTex && i > 0) break; //点云的情况下最好不改相机位置,因为其他位置点云还没加载完,所以不判断当前点以外的漫游点
  31103. var g = Common.sortByScore(others, [], [Images360.scoreFunctions.distanceSquared(pano.position)]);
  31104. for (var a = 0, b = g.length; a < b; a++) {
  31105. var item = g[a];
  31106. if (item.item == pano) continue;
  31107. if (this.neighbourMap[pano.id][item.item.id] != void 0 && this.neighbourMap[item.item.id][pano.id] != void 0 /* this.isNeighbour(pano,item.item,{dontCompute:true}) != void 0 */) continue; //确定结果了就不需要算
  31108. //console.log('check isNeighbour', pano.id, item.item.id)
  31109. var byCloud = !pano.pointcloud.hasDepthTex;
  31110. var result = this.isNeighbour(pano, item.item, {
  31111. onlyUseTex: !byCloud,
  31112. computeDirFirst: true,
  31113. computeTwoDir: true
  31114. }); //计算
  31115. if (result != void 0) {
  31116. //计算了 (byTex时其实并不一定)
  31117. //console.log('提前计算neighbor', pano.id, item.item.id)
  31118. this.dispatchEvent({
  31119. type: 'getNeighbourAuto',
  31120. panos: [pano, item.item]
  31121. });
  31122. if (byCloud) {
  31123. //只计算一次
  31124. //console.log('提前计算neighbor byCloud', result, pano.id, item.item.id)
  31125. break outer;
  31126. }
  31127. getCount++;
  31128. if (ifOverTime()) {
  31129. break outer;
  31130. }
  31131. }
  31132. }
  31133. lastIndex = i + 1; //这轮结束
  31134. }
  31135. /* if(changeCount){
  31136. console.log( 'changeCount', changeCount)
  31137. } */
  31138. this.depthSampler.removeEventListener('changeImg', changeTexCount);
  31139. if (!inited) {
  31140. inited = true;
  31141. this.addEventListener('loadedDepthImg', e => {
  31142. //console.log('loadedDepthImg',e.pano)
  31143. lastIndex = 0; //主要针对刚打开场景第一个点有杂点时单向不成功,要立即进一步双向计算ifShelter
  31144. });
  31145. }
  31146. /* let costTime = Date.now() - startTime
  31147. costTime > maxWaitDur && console.log( 'costTime:',costTime) */
  31148. };
  31149. }();
  31150. Images360.filters = {
  31151. inPanoDirection: function inPanoDirection(pos, dir, i, log) {
  31152. //pano在mouse的方向上
  31153. return function (pano) {
  31154. var r = pano.floorPosition.clone().sub(pos).normalize();
  31155. var o = pano.position.clone().sub(pos).normalize();
  31156. log && console.log('dire', pano.id, r.dot(dir), o.dot(dir));
  31157. return r.dot(dir) > i || o.dot(dir) > i;
  31158. };
  31159. },
  31160. inFloorDirection: function inFloorDirection(pos, dir, min, log) {
  31161. //pano在mouse的水平方向上
  31162. return function (pano) {
  31163. var vec = new Vector2().subVectors(pano.floorPosition, pos).normalize();
  31164. var dir_ = new Vector2().copy(dir).normalize();
  31165. log && console.log('dire', pano.id, vec.dot(dir_));
  31166. return vec.dot(dir_) > min;
  31167. /* var i = pano.floorPosition.clone().sub(pos).setZ(0).normalize();//改成在xz方向上,否则点击墙面不会移动
  31168. return i.dot(dir.clone().setZ(0)) > min */
  31169. };
  31170. },
  31171. isNotBehindNormal: function isNotBehindNormal(e, t) {
  31172. var i = new Vector3();
  31173. return t = t.clone(), function (n) {
  31174. var r = i.copy(n.position).sub(e).normalize();
  31175. return r.dot(t) > 0;
  31176. };
  31177. },
  31178. isCloseEnoughTo: function isCloseEnoughTo(e, t) {
  31179. return function (i) {
  31180. //因为marker可能比地面高,所以识别范围要比marker看起来更近一些。(因为投影到地板的位置比marker更近)
  31181. return e.distanceTo(i.floorPosition) < t; //许钟文
  31182. };
  31183. },
  31184. not: function not(e) {
  31185. return function (t) {
  31186. return t !== e;
  31187. };
  31188. },
  31189. isEnabled: function isEnabled() {
  31190. return function (t) {
  31191. return t.enabled;
  31192. };
  31193. },
  31194. isVisible: function isVisible() {
  31195. return function (t) {
  31196. return t.visible;
  31197. };
  31198. }
  31199. };
  31200. Images360.scoreFunctions = {
  31201. direction: function direction(curPos, dir, ifLog) {
  31202. return function (pano) {
  31203. var pos1 = /* pano.floorPosition */pano.position; //旧:改为权重放在marker上,这样对有斜坡的更准确,如上楼, 但这样近距离的pano角度就会向下了,以致于走不到
  31204. var n = pos1.clone().sub(curPos).normalize();
  31205. //ifLog && console.log('direction', pano.id, n.dot(dir) * directionFactor )
  31206. return n.dot(dir) * directionFactor;
  31207. };
  31208. },
  31209. distance: function distance(pos1) {
  31210. var r = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
  31211. var ifLog = arguments.length > 2 ? arguments[2] : undefined;
  31212. if (pos1.position) pos1 = pos1.position;
  31213. return function (pano) {
  31214. //许钟文 改
  31215. var pos2 = pano.position.clone();
  31216. //ifLog && console.log('distance', pano.id, pos1.distance(pos2) * -1 )
  31217. return pos1.distanceTo(pos2) * -1 * r;
  31218. };
  31219. },
  31220. distanceSquared: function distanceSquared(pos1) {
  31221. var r = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
  31222. if (pos1.position) pos1 = pos1.position;
  31223. return function (pano) {
  31224. //许钟文 改
  31225. var pos2 = pano.position.clone();
  31226. return pos1.distanceToSquared(pos2) * -1 * r;
  31227. };
  31228. },
  31229. angle: function angle(e, t) {
  31230. return function (i) {
  31231. var n = i.position.clone().sub(e).normalize();
  31232. return n.angleTo(t) * Potree.config.navigation.angleFactor;
  31233. };
  31234. }
  31235. };
  31236. Images360.sortFunctions = {
  31237. //排序函数,涉及到两个item相减
  31238. floorDisSquaredToPoint: function floorDisSquaredToPoint(e) {
  31239. return function (t, i) {
  31240. return t.floorPosition.distanceToSquared(e) - i.floorPosition.distanceToSquared(e);
  31241. };
  31242. },
  31243. disSquaredToPoint: function disSquaredToPoint(e) {
  31244. return function (t, i) {
  31245. return t.position.distanceToSquared(e) - i.position.distanceToSquared(e);
  31246. };
  31247. }
  31248. };
  31249. Images360.prototype.updateCube = function () {
  31250. //增加细分的版本,且垂直方向上取中位数 侧边多条
  31251. var minDis = 0.2; //pano和墙距离不能小于相机的near
  31252. var height = 1; //准确计算的话要分别计算两个pano的地面、天花板之间的俯仰角,和pano之间的还不一样。这里统一假设一个比较小的高度,因高度越大 maxSinAlpha 越大
  31253. var minTanBeta = minDis / height; /* (pano0.position.z - pano0.floorPosition.z) */
  31254. var minBeta = Math.atan(minTanBeta);
  31255. var maxSinAlpha = Math.cos(minBeta); // 注:beta = Math/2 - alpha
  31256. var skyHeight = 50;
  31257. return function (pano0, pano1) {
  31258. if (Potree.settings.displayMode != 'showPanos' || pano0 == pano1 || this.cubePanos.some(e => e.pano == pano0 && e.matrix.equals(pano0.pointcloud.matrix)) && (!pano1 || this.cubePanos.some(e => e.pano == pano1 && e.matrix.equals(pano1.pointcloud.matrix)))) return;
  31259. this.cubePanos = [{
  31260. pano: pano0,
  31261. matrix: pano0.pointcloud.matrix.clone()
  31262. }, {
  31263. pano: pano1,
  31264. matrix: pano1 && pano1.pointcloud.matrix.clone()
  31265. }];
  31266. viewer.addTimeMark('updateCube', 'start');
  31267. //console.log('updateCube',pano0.id, pano1&&pano1.id)
  31268. var useBound = (bound, size) => {
  31269. size = size || bound.getSize(new Vector3());
  31270. var center = bound.getCenter(new Vector3());
  31271. size.max(new Vector3(HighMapCubeWidth, HighMapCubeWidth, HighMapCubeWidth));
  31272. this.cube.geometry = new BoxBufferGeometry(1, 1, 1, 1);
  31273. this.cube.scale.copy(size);
  31274. this.cube.position.copy(center);
  31275. if (Potree.settings.testCube) {
  31276. this.cubeTest.geometry = this.cube.geometry;
  31277. this.cubeTest.scale.copy(size);
  31278. this.cubeTest.position.copy(center);
  31279. }
  31280. return 'useBound';
  31281. };
  31282. var getPanoBound = (pano, dis) => {
  31283. //因漫游点可能在点云外部,如室外平地,所以需要union进漫游点
  31284. var panoBound = new Box3();
  31285. panoBound.expandByPoint(pano.position);
  31286. var margin = dis ? Math.max(dis * 0.1, 10) : 10;
  31287. panoBound.expandByVector(new Vector3(margin, margin, margin)); //give pano a margin 。 随着bound扩大,margin要相应扩大,否则当距离很远时看起来就像没有
  31288. return pano.pointcloud.bound.clone().union(panoBound);
  31289. };
  31290. this.cube.geometry.dispose();
  31291. if (pano1) {
  31292. //过渡
  31293. var dontAddSides;
  31294. var dis = pano0.position.distanceTo(pano1.position);
  31295. if (dis == 0) return;
  31296. var sinAlpha = Math.abs(pano0.position.z - pano1.position.z) / dis; //俯仰角的sin,随角度增大而增大 0-1
  31297. var score = (1 + sinAlpha * 20) * dis; //score越大创建的mesh越不适合
  31298. var isNeighbour = this.isNeighbour(pano0, pano1);
  31299. //console.log(pano0.id, pano1.id, maxSinAlpha.toFixed(2), sinAlpha.toFixed(2), score.toFixed(2), isNeighbour)
  31300. if (sinAlpha > maxSinAlpha || !pano0.pointcloud.hasDepthTex || !pano1.pointcloud.hasDepthTex || (isNeighbour ? score > 100 : score > 50)) {
  31301. var bound = getPanoBound(pano0, dis).union(getPanoBound(pano1, dis));
  31302. var size = bound.getSize(new Vector3());
  31303. var max = Math.max(size.x, size.y, size.z);
  31304. size.set(max, max, max); //距离太远的数据集,过渡会畸变。所以扩大skybox,且为立方体
  31305. return useBound(bound, size);
  31306. } else if (isNeighbour ? score > 70 : score > 15) {
  31307. dontAddSides = true; //pano间有阻挡时得到的side点可能使通道变窄,所以去掉。
  31308. }
  31309. //俯仰角增大时可能不在同一楼层,算出来的mesh不太好,所以更倾向直接使用cube,或去除side。
  31310. var half = browser.isMobile() ? 4 : 8; //自行输入 (点云计算的慢,还不准)
  31311. var count1 = 2 * half; //偶数个 每个pano向 外dir 个数
  31312. //奇数个的好处:在窄空间内能探测到最远距离,坏处是前方有尖角。偶数个的坏处就是可能检测距离太近。
  31313. var getDir = (angle_, vec) => {
  31314. //旋转获得水平向量
  31315. var rotMat = new Matrix4().makeRotationZ(angle_);
  31316. return vec.clone().applyMatrix4(rotMat);
  31317. };
  31318. var getFar = (dir, pano, origin, height) => {
  31319. //获取在这个方向上和墙体intersect的距离
  31320. //在垂直方向上分出多个方向,取一个最可能的接近真实的距离
  31321. var maxH = 40,
  31322. minH = 2,
  31323. minR = 0.5,
  31324. maxR = 2;
  31325. height = height == void 0 ? Math.min(skyHeight, pano.ceilZ - pano.floorPosition.z) : height;
  31326. //let r = height (maxH - minH)* 0.14 // 高度越小,角度越小
  31327. //let r = minR + ( maxR - minR) * THREE.Math.clamp((height - minH) / (maxH - minH),0,1) //THREE.Math.smoothstep(currentDis, op.nearBound, op.farBound);
  31328. var r = math.linearClamp(height, [minH, maxH], [minR, maxR]);
  31329. var getZ = deg => {
  31330. deg *= r;
  31331. deg = MathUtils.clamp(deg, 1, 80);
  31332. return Math.tan(MathUtils.degToRad(deg));
  31333. };
  31334. var dirs_; //注意:角度太大会碰到天花板或地板,越远越容易碰到, 在地下停车场就会伸展不开。 更多取接近0度的,否则围墙矮一点就会取到远处。
  31335. dirs_ = [15, 8, 3, -1, -5];
  31336. dirs_ = dirs_.map(deg => dir.clone().setZ(getZ(deg)).normalize());
  31337. var max = 50;
  31338. var count2 = dirs_.length;
  31339. var disArr = dirs_.map((dir_, i) => {
  31340. var intersect = this.getIntersect(pano, dir_, origin);
  31341. var projectLen = intersect && intersect.distance ? dir_.dot(dir) * intersect.distance : max; //得到project在dir的长度
  31342. return projectLen; //得水平距离
  31343. });
  31344. //console.log(pano ? pano.id : 'side','disArr', disArr.slice(0))
  31345. disArr.sort((a, b) => {
  31346. return b - a;
  31347. }); //从大到小
  31348. //console.log(pano ? pano.id : 'side','disArr', disArr)
  31349. var dis = disArr[Math.floor(count2 / 2 - 0.5)]; //对半、取前(中位数)
  31350. return dis;
  31351. };
  31352. var sideCount = [0, 0];
  31353. var addPos = (pano, vec) => {
  31354. //添加这个pano这一侧向外半圆的顶点
  31355. //添加pano位置对应的最高点最低点:
  31356. var minZ, maxZ;
  31357. minZ = pano.floorPosition.z;
  31358. maxZ = pano.getCeilHeight();
  31359. if (maxZ == Infinity) maxZ = skyHeight + pano.position.z; //maxZ = Math.max(skyHeight, maxZ)
  31360. [maxZ, minZ].forEach(z => {
  31361. posArr.push(pano.position.clone().setZ(z));
  31362. });
  31363. //在画面上线条从左往右数
  31364. var angle = Math.PI / (count1 - 1);
  31365. var dirs = []; //平分这半边180度
  31366. for (var i = 0; i < count1; i++) {
  31367. dirs.push(getDir(Math.PI / 2 - i * angle, vec)); //正的在左边
  31368. }
  31369. var dirs2 = dirs.map(dir => {
  31370. return {
  31371. dir,
  31372. dis: getFar(dir, pano)
  31373. };
  31374. });
  31375. //剔除那些突然间离相机很近的dir。有可能是拍摄的人、或者杆子、树
  31376. /* dirs2.forEach((e,i)=>{
  31377. console.log(i, e.dis)
  31378. let smallThanBefore = ()=>{
  31379. return dirs2[i-1].dis / e.dis > maxRatio
  31380. }
  31381. let smallThanAfter = ()=>{
  31382. return dirs2[i+1].dis / e.dis > maxRatio
  31383. }
  31384. if(i>0 && i<count1-1 && smallThanBefore() && smallThanAfter()){//比左右两边都小很多
  31385. e.disB = (dirs2[i-1].dis + dirs2[i+1].dis) / 2 //平均数
  31386. console.log('两者之间',i,e.disB)
  31387. }else if(i==count1-1 && smallThanBefore() ) {//比前者小很多
  31388. e.disB = dirs2[i-1].dis * 0.8
  31389. console.log('smallThanBefore', i, e.disB)
  31390. }else if(i==0 && smallThanAfter() ){//比后者小很多
  31391. e.disB = dirs2[i+1].dis * 0.8
  31392. console.log('smallThanAftere', i, e.disB)
  31393. }
  31394. }) */
  31395. var maxRatio1 = 3,
  31396. maxRatio2 = 8; //超过maxRatio1就要加入判断,而最终结果的设限其实是maxRatio2
  31397. var minWidth = 0.5;
  31398. var computeWidth = (start, end) => {
  31399. start += 1; //不包含start和end
  31400. var count = end - start;
  31401. var dis = 0;
  31402. for (var m = start; m < end; m++) {
  31403. //得平均数
  31404. dis += dirs2[m].dis;
  31405. }
  31406. dis /= count;
  31407. var angle = Math.PI / (count1 - 1) * count / 2;
  31408. var width = dis * Math.tan(angle); //得到block的半宽度
  31409. return width;
  31410. };
  31411. var changeDis = (start, end) => {
  31412. //不包含start
  31413. start += 1; //不包含start和end
  31414. for (var m = start; m < end; m++) {
  31415. dirs2[m].disB = dirs2[end].dis * 0.8;
  31416. //console.log('changeDis', m, dirs2[m].disB)
  31417. }
  31418. };
  31419. var start = -1;
  31420. for (var _i = 0; _i < count1; _i++) {
  31421. //遍历时将左边dis比之小很多且宽度较小的改大
  31422. //console.log(i, dirs2[i].dis)
  31423. var j = _i - 1;
  31424. var ratios = 0;
  31425. while (j > start && dirs2[_i].dis / dirs2[j].dis > maxRatio1) {
  31426. ratios += dirs2[_i].dis / dirs2[j].dis;
  31427. j--;
  31428. }
  31429. var count = _i - j - 1;
  31430. ratios /= count;
  31431. if (count > 0 && computeWidth(j, _i) < minWidth * ratios / maxRatio2) {
  31432. //怎么感觉好像改成了视觉宽度小于某个值即可,那直接用count好了?
  31433. changeDis(j, _i);
  31434. start = _i; //在此之前的修改过,之后不用再判断
  31435. }
  31436. /* if(count > 0 && (count == 1 || computeWidth(j,i)<minWidth)){//若只有一个不用判断宽度直接修改
  31437. changeDis(j,i)
  31438. start = i //在此之前的修改过,之后不用再判断
  31439. } */
  31440. }
  31441. dirs2.forEach((e, index) => {
  31442. var dir = e.dir.clone().multiplyScalar(e.disB || e.dis);
  31443. [maxZ, minZ].forEach(z => {
  31444. posArr.push(pano.position.clone().setZ(z).add(dir)); //获取到外墙点
  31445. });
  31446. });
  31447. };
  31448. var addSide = () => {
  31449. //两个漫游点间两边各加一些侧线
  31450. //中点处的
  31451. var top0 = pano0.ceilZ == Infinity ? pano0.position.z + skyHeight : pano0.ceilZ;
  31452. var top1 = pano1.ceilZ == Infinity ? pano1.position.z + skyHeight : pano1.ceilZ;
  31453. var midMaxZ = (top0 + top1) / 2;
  31454. var midMinZ = (pano0.floorPosition.z + pano1.floorPosition.z) / 2;
  31455. var mid = new Vector3().addVectors(pano0.position, pano1.position).multiplyScalar(0.5);
  31456. if (!dontAddSides) {
  31457. if (pano0.pointcloud.hasDepthTex && pano0.pointcloud.hasDepthTex) {
  31458. var panos = [pano0, pano1];
  31459. var vecs = [vec.clone().negate(), vec];
  31460. var axis = [[-1, 1], [1, -1]];
  31461. var dis2d = new Vector2().subVectors(pano0.position, pano1.position).length(); //水平上的距离
  31462. var maxDis = 50,
  31463. _minDis = 0.5,
  31464. minR = 0.2,
  31465. maxR = 1.2;
  31466. //let r = maxR - ( maxR - minR) * THREE.Math.clamp((dis2d - minDis) / (maxDis - minDis),0,1) //dis2d越大,角度要越小 //THREE.Math.smoothstep(currentDis, op.nearBound, op.farBound);
  31467. var r = math.linearClamp(dis2d, [_minDis, maxDis], [maxR, minR]);
  31468. //console.log('dis2d',dis2d,'r',r)
  31469. var angles = (browser.isMobile() /* || dis2d<4 */ ? [60] : [50, 70] /* [35,65] */).map(deg => {
  31470. //正的在左边 尽量能够平分中间这段墙体。 (角度为从中心向外)
  31471. var angle = MathUtils.clamp(deg * r, 5, 80);
  31472. //console.log('angle',angle)
  31473. return MathUtils.degToRad(angle);
  31474. });
  31475. axis.forEach((axis_, index0) => {
  31476. var disToSides = [];
  31477. var accordingPano = index0 == 0 ? pano0 : pano1; //根据离该点在vec方向上的距离顺序来存顶点
  31478. panos.forEach((pano, index) => {
  31479. var dirs = angles.map(angle => getDir(axis_[index] * angle, vecs[index])); //一侧的若干角度
  31480. dirs.forEach((dir_, i) => {
  31481. var dis1 = getFar(dir_, pano);
  31482. var disToPano2d = dis1 * Math.cos(angles[i]);
  31483. if (disToPano2d < dis2d) {
  31484. //超过的话都到另一半pano的半圆了,不计入。(角度越小越容易超过)
  31485. var disToSide = dis1 * Math.sin(angles[i]);
  31486. if (pano != accordingPano) {
  31487. disToPano2d = dis2d - disToPano2d; //反一下
  31488. }
  31489. dir_.multiplyScalar(dis1);
  31490. disToSides.push({
  31491. disToSide,
  31492. disToPano2d,
  31493. pano,
  31494. dir_
  31495. });
  31496. } else {
  31497. //console.log('超过',index0,index,i)
  31498. }
  31499. });
  31500. });
  31501. if (disToSides.length) {
  31502. //disToSides.sort((a,b)=>{return b-a});//从大到小
  31503. //由距离accordingPano的近到远:
  31504. disToSides.sort((a, b) => {
  31505. return a.disToPano2d - b.disToPano2d;
  31506. });
  31507. //console.log('disToSides', index0, disToSides)
  31508. if (disToSides.length == 1 && disToSides[0].disToSide < 0.5) {
  31509. disToSides = []; //如果太近直接去除
  31510. }
  31511. disToSides.forEach(e => {
  31512. //求z
  31513. var ratio = e.disToPano2d / dis2d;
  31514. var r = accordingPano == pano0 ? 1 - ratio : ratio;
  31515. var sideMaxZ_ = top0 * r + top1 * (1 - r);
  31516. var sideMinZ_ = pano0.floorPosition.z * r + pano1.floorPosition.z * (1 - r);
  31517. [sideMaxZ_, sideMinZ_].forEach(z => {
  31518. posArr.push(e.pano.position.clone().setZ(z).add(e.dir_)); //是直接使用最长dis的那个intersect点好还是mid
  31519. });
  31520. });
  31521. }
  31522. sideCount[index0] = disToSides.length; //记录侧边个数
  31523. });
  31524. } else {
  31525. //这段针对点云时,仅测试才会执行到
  31526. sideCount = [1, 1];
  31527. var sideDirs = [getDir(Math.PI / 2, vec), getDir(-Math.PI / 2, vec)];
  31528. sideDirs.forEach((dir_, index) => {
  31529. var dis = getFar(dir_, null, mid, midMaxZ - midMinZ); //直接从中点求两侧的距离
  31530. dir_.multiplyScalar( /* Math.max( */dis /* , sideDis[index]) */);
  31531. [midMaxZ, midMinZ].forEach(z => {
  31532. posArr.push(mid.clone().setZ(z).add(dir_));
  31533. });
  31534. });
  31535. }
  31536. }
  31537. //中心:
  31538. [midMaxZ, midMinZ].forEach(z => {
  31539. posArr.push(mid.clone().setZ(z));
  31540. });
  31541. };
  31542. //positions存放顺序:pano的每边的 zMax和zMin 、count1个dir的点 ;侧边的点 ;连接处顶底的中点
  31543. var addFaces = () => {
  31544. var getPI = function getPI(index, posType, panoIndex) {
  31545. //获取顶点序号
  31546. return 2 + (count1 * 2 + 2) * panoIndex + index * 2 + (posType == 'top' ? 0 : 1);
  31547. };
  31548. var getSidePI = function getSidePI(index, posType, panoIndex) {
  31549. //获取侧边顶点序号
  31550. if (panoIndex == 1) index += sideCount[0];
  31551. return getPI(index, posType, 2) - 2;
  31552. };
  31553. var getPanoPI = function getPanoPI(posType, panoIndex) {
  31554. //获取pano处对应的点序号
  31555. return getPI(-1, posType, panoIndex);
  31556. };
  31557. var topCenter = posArr.length - 2; //最后添加的两个中心点
  31558. var btmCenter = posArr.length - 1;
  31559. for (var i = 0; i < 2; i++) {
  31560. for (var index = 1; index < count1; index++) {
  31561. //pano外侧半圆围墙
  31562. faceArr.push([getPI(index, 'top', i), getPI(index - 1, 'btm', i), getPI(index - 1, 'top', i)],
  31563. //加入一块四方面
  31564. [getPI(index, 'top', i), getPI(index, 'btm', i), getPI(index - 1, 'btm', i)]);
  31565. faceArr.push([getPI(index, 'top', i), getPI(index - 1, 'top', i), getPanoPI('top', i)]); //天花板扇形
  31566. faceArr.push([getPI(index, 'btm', i), getPI(index - 1, 'btm', i), getPanoPI('btm', i)]); //地板扇形
  31567. }
  31568. var j = (i + 1) % 2; //另一个pano
  31569. //侧边
  31570. for (var u = 0; u <= sideCount[i]; u++) {
  31571. //侧边每个四方的左上右上左下右下四个点
  31572. var pLT = u == 0 ? getPI(0, 'top', i) : getSidePI(u - 1, 'top', i);
  31573. var pRT = u == sideCount[i] ? getPI(count1 - 1, 'top', j) : getSidePI(u, 'top', i);
  31574. var pLB = u == 0 ? getPI(0, 'btm', i) : getSidePI(u - 1, 'btm', i);
  31575. var pRB = u == sideCount[i] ? getPI(count1 - 1, 'btm', j) : getSidePI(u, 'btm', i);
  31576. faceArr.push([pLT, pLB, pRB], [pLT, pRB, pRT]); //外侧四方面
  31577. faceArr.push([pLT, topCenter, pRT], [pLB, btmCenter, pRB]); //顶部和底部到整体中心的扇形(由于点的顺序是根据和两个pano的距离,因此到中心的夹角并没按顺序排列,所以可能会重叠)
  31578. if (i == 0) {
  31579. //只需要算一次
  31580. //顶部和底部中心与两个pano边构成的三角形
  31581. if (u == 0) {
  31582. faceArr.push([pLT, getPI(count1 - 1, 'top', i), topCenter], [pLB, getPI(count1 - 1, 'btm', i), btmCenter]);
  31583. }
  31584. //不能用else 因为当length==0时u==0也==sideCount[i],此时就是要两个面
  31585. if (u == sideCount[i]) {
  31586. faceArr.push([pRT, getPI(0, 'top', j), topCenter], [pRB, getPI(0, 'btm', j), btmCenter]);
  31587. }
  31588. }
  31589. }
  31590. }
  31591. };
  31592. var posArr = [];
  31593. var faceArr = [];
  31594. //两点连线的水平向量
  31595. var vec = new Vector3().subVectors(pano0.position, pano1.position).setZ(0).normalize();
  31596. /* let sideDis0 = */
  31597. addPos(pano0, vec);
  31598. /* let sideDis1 = */
  31599. addPos(pano1, vec.clone().negate());
  31600. addSide();
  31601. addFaces();
  31602. //MeshDraw.updateGeometry(this.cube.geometry, posArr, faceArr)
  31603. var geo = MeshDraw.createGeometry(posArr, faceArr);
  31604. this.cube.geometry = geo;
  31605. this.cube.scale.set(1, 1, 1);
  31606. this.cube.position.set(0, 0, 0);
  31607. if (Potree.settings.testCube) {
  31608. this.cubeTest.geometry = geo;
  31609. this.cubeTest.scale.set(1, 1, 1);
  31610. this.cubeTest.position.set(0, 0, 0);
  31611. }
  31612. } else {
  31613. useBound(getPanoBound(pano0));
  31614. }
  31615. viewer.addTimeMark('updateCube', 'end');
  31616. return true;
  31617. /*
  31618. 关于卡顿:
  31619. 即使使用cube,若scale设置为只容纳两个pano,也会卡顿。但也是有的卡有的不卡。
  31620. 若按照原先的复杂geo,一般在平直的街道上行走流畅,经过拐弯或者复杂区域较卡。减小geo复杂度没有什么作用。
  31621. 注: 修改skybox,若不准的话,会遮住其他mesh,比如marker。尤其在没有深度贴图时。
  31622. 耗时: chrome: 20+ ,但是firefox:500+ 咋回事 ? iphonex safari: 40+
  31623. */
  31624. };
  31625. }();
  31626. /*
  31627. viewer.images360.flyToPano(viewer.images360.getPano('1765955963253690368|70','sid'))
  31628. viewer.images360.flyToPano(viewer.images360.lastPano)
  31629. */
  31630. /**
  31631. * @author alteredq / http://alteredqualia.com/
  31632. *
  31633. * Full-screen textured quad shader
  31634. */
  31635. var CopyShader = {
  31636. uniforms: {
  31637. "tDiffuse": {
  31638. value: null
  31639. },
  31640. "opacity": {
  31641. value: 1.0
  31642. }
  31643. },
  31644. vertexShader: ["varying vec2 vUv;", "void main() {", "vUv = uv;", "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", "}"].join("\n"),
  31645. fragmentShader: ["uniform float opacity;", "uniform sampler2D tDiffuse;", "varying vec2 vUv;", "void main() {", "vec4 texel = texture2D( tDiffuse, vUv );",
  31646. //如果开启premultipliedAlpha用这个,否则用注释的
  31647. "gl_FragColor = opacity * texel;",
  31648. //"gl_FragColor = texture2D( tDiffuse, vUv );",
  31649. //"gl_FragColor.a *= opacity;",
  31650. "}"].join("\n")
  31651. };
  31652. /**
  31653. * @author alteredq / http://alteredqualia.com/
  31654. */
  31655. var Pass = function Pass() {
  31656. // if set to true, the pass is processed by the composer
  31657. this.enabled = true;
  31658. // if set to true, the pass indicates to swap read and write buffer after rendering
  31659. this.needsSwap = true;
  31660. // if set to true, the pass clears its buffer before rendering
  31661. this.clear = false;
  31662. // if set to true, the result of the pass is rendered to screen
  31663. this.renderToScreen = false;
  31664. };
  31665. Object.assign(Pass.prototype, {
  31666. setSize: function setSize(width, height) {},
  31667. render: function render(renderer, writeBuffer, readBuffer, delta, maskActive) {
  31668. console.error('THREE.Pass: .render() must be implemented in derived pass.');
  31669. }
  31670. });
  31671. var ShaderPass = function ShaderPass(shader, textureID) {
  31672. Pass.call(this);
  31673. this.textureID = textureID !== undefined ? textureID : "tDiffuse";
  31674. if (shader instanceof ShaderMaterial) {
  31675. this.uniforms = shader.uniforms;
  31676. this.material = shader;
  31677. } else if (shader) {
  31678. this.uniforms = UniformsUtils.clone(shader.uniforms);
  31679. this.material = new ShaderMaterial({
  31680. defines: Object.assign({}, shader.defines),
  31681. uniforms: this.uniforms,
  31682. vertexShader: shader.vertexShader,
  31683. fragmentShader: shader.fragmentShader,
  31684. transparent: true //add
  31685. });
  31686. }
  31687. this.camera = new OrthographicCamera(-1, 1, 1, -1, 0, 1);
  31688. this.scene = new Scene();
  31689. this.quad = new Mesh(new PlaneBufferGeometry(2, 2), null);
  31690. this.quad.frustumCulled = false; // Avoid getting clipped
  31691. this.scene.add(this.quad);
  31692. };
  31693. ShaderPass.prototype = Object.assign(Object.create(Pass.prototype), {
  31694. constructor: ShaderPass,
  31695. render: function render(scene, camera, viewports, renderer, writeBuffer, readBuffer, delta, maskActive) {
  31696. var oldTarget = renderer.getRenderTarget();
  31697. /* if(this.readTarget){ //add
  31698. readBuffer = oldTarget
  31699. } */
  31700. if (this.uniforms[this.textureID]) {
  31701. this.uniforms[this.textureID].value = readBuffer.texture;
  31702. }
  31703. this.quad.material = this.material;
  31704. if (this.renderToScreen) {
  31705. renderer.render(this.scene, this.camera);
  31706. } else {
  31707. renderer.setRenderTarget(writeBuffer);
  31708. if (this.clear) renderer.clear();
  31709. renderer.render(this.scene, this.camera);
  31710. renderer.setRenderTarget(oldTarget);
  31711. }
  31712. }
  31713. });
  31714. // Copied from three.js: WebGLRenderer.js
  31715. function paramThreeToGL$1(_gl, p) {
  31716. var extension;
  31717. if (p === RepeatWrapping) return _gl.REPEAT;
  31718. if (p === ClampToEdgeWrapping) return _gl.CLAMP_TO_EDGE;
  31719. if (p === MirroredRepeatWrapping) return _gl.MIRRORED_REPEAT;
  31720. if (p === NearestFilter) return _gl.NEAREST;
  31721. if (p === NearestMipMapNearestFilter) return _gl.NEAREST_MIPMAP_NEAREST;
  31722. if (p === NearestMipMapLinearFilter) return _gl.NEAREST_MIPMAP_LINEAR;
  31723. if (p === LinearFilter) return _gl.LINEAR;
  31724. if (p === LinearMipMapNearestFilter) return _gl.LINEAR_MIPMAP_NEAREST;
  31725. if (p === LinearMipMapLinearFilter) return _gl.LINEAR_MIPMAP_LINEAR;
  31726. if (p === UnsignedByteType) return _gl.UNSIGNED_BYTE;
  31727. if (p === UnsignedShort4444Type) return _gl.UNSIGNED_SHORT_4_4_4_4;
  31728. if (p === UnsignedShort5551Type) return _gl.UNSIGNED_SHORT_5_5_5_1;
  31729. if (p === UnsignedShort565Type) return _gl.UNSIGNED_SHORT_5_6_5;
  31730. if (p === ByteType) return _gl.BYTE;
  31731. if (p === ShortType) return _gl.SHORT;
  31732. if (p === UnsignedShortType) return _gl.UNSIGNED_SHORT;
  31733. if (p === IntType) return _gl.INT;
  31734. if (p === UnsignedIntType) return _gl.UNSIGNED_INT;
  31735. if (p === FloatType) return _gl.FLOAT;
  31736. if (p === HalfFloatType) {
  31737. extension = extensions.get('OES_texture_half_float');
  31738. if (extension !== null) return extension.HALF_FLOAT_OES;
  31739. }
  31740. if (p === AlphaFormat) return _gl.ALPHA;
  31741. if (p === RGBFormat) return _gl.RGB;
  31742. if (p === RGBAFormat) return _gl.RGBA;
  31743. if (p === LuminanceFormat) return _gl.LUMINANCE;
  31744. if (p === LuminanceAlphaFormat) return _gl.LUMINANCE_ALPHA;
  31745. if (p === DepthFormat) return _gl.DEPTH_COMPONENT;
  31746. if (p === DepthStencilFormat) return _gl.DEPTH_STENCIL;
  31747. if (p === AddEquation) return _gl.FUNC_ADD;
  31748. if (p === SubtractEquation) return _gl.FUNC_SUBTRACT;
  31749. if (p === ReverseSubtractEquation) return _gl.FUNC_REVERSE_SUBTRACT;
  31750. if (p === ZeroFactor) return _gl.ZERO;
  31751. if (p === OneFactor) return _gl.ONE;
  31752. if (p === SrcColorFactor) return _gl.SRC_COLOR;
  31753. if (p === OneMinusSrcColorFactor) return _gl.ONE_MINUS_SRC_COLOR;
  31754. if (p === SrcAlphaFactor) return _gl.SRC_ALPHA;
  31755. if (p === OneMinusSrcAlphaFactor) return _gl.ONE_MINUS_SRC_ALPHA;
  31756. if (p === DstAlphaFactor) return _gl.DST_ALPHA;
  31757. if (p === OneMinusDstAlphaFactor) return _gl.ONE_MINUS_DST_ALPHA;
  31758. if (p === DstColorFactor) return _gl.DST_COLOR;
  31759. if (p === OneMinusDstColorFactor) return _gl.ONE_MINUS_DST_COLOR;
  31760. if (p === SrcAlphaSaturateFactor) return _gl.SRC_ALPHA_SATURATE;
  31761. if (p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format || p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format) {
  31762. extension = extensions.get('WEBGL_compressed_texture_s3tc');
  31763. if (extension !== null) {
  31764. if (p === RGB_S3TC_DXT1_Format) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  31765. if (p === RGBA_S3TC_DXT1_Format$1) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  31766. if (p === RGBA_S3TC_DXT3_Format) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  31767. if (p === RGBA_S3TC_DXT5_Format$1) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  31768. }
  31769. }
  31770. if (p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format || p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format) {
  31771. extension = extensions.get('WEBGL_compressed_texture_pvrtc');
  31772. if (extension !== null) {
  31773. if (p === RGB_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  31774. if (p === RGB_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  31775. if (p === RGBA_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  31776. if (p === RGBA_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  31777. }
  31778. }
  31779. if (p === RGB_ETC1_Format) {
  31780. extension = extensions.get('WEBGL_compressed_texture_etc1');
  31781. if (extension !== null) return extension.COMPRESSED_RGB_ETC1_WEBGL;
  31782. }
  31783. if (p === MinEquation || p === MaxEquation) {
  31784. extension = extensions.get('EXT_blend_minmax');
  31785. if (extension !== null) {
  31786. if (p === MinEquation) return extension.MIN_EXT;
  31787. if (p === MaxEquation) return extension.MAX_EXT;
  31788. }
  31789. }
  31790. if (p === UnsignedInt248Type) {
  31791. extension = extensions.get('WEBGL_depth_texture');
  31792. if (extension !== null) return extension.UNSIGNED_INT_24_8_WEBGL;
  31793. }
  31794. return 0;
  31795. }
  31796. ;
  31797. var attributeLocations$1 = {
  31798. "position": {
  31799. name: "position",
  31800. location: 0
  31801. },
  31802. "color": {
  31803. name: "color",
  31804. location: 1
  31805. },
  31806. "rgba": {
  31807. name: "color",
  31808. location: 1
  31809. },
  31810. "intensity": {
  31811. name: "intensity",
  31812. location: 2
  31813. },
  31814. "classification": {
  31815. name: "classification",
  31816. location: 3
  31817. },
  31818. "returnNumber": {
  31819. name: "returnNumber",
  31820. location: 4
  31821. },
  31822. "return number": {
  31823. name: "returnNumber",
  31824. location: 4
  31825. },
  31826. "returns": {
  31827. name: "returnNumber",
  31828. location: 4
  31829. },
  31830. "numberOfReturns": {
  31831. name: "numberOfReturns",
  31832. location: 5
  31833. },
  31834. "number of returns": {
  31835. name: "numberOfReturns",
  31836. location: 5
  31837. },
  31838. "pointSourceID": {
  31839. name: "pointSourceID",
  31840. location: 6
  31841. },
  31842. "source id": {
  31843. name: "pointSourceID",
  31844. location: 6
  31845. },
  31846. "point source id": {
  31847. name: "pointSourceID",
  31848. location: 6
  31849. },
  31850. "indices": {
  31851. name: "indices",
  31852. location: 7
  31853. },
  31854. "normal": {
  31855. name: "normal",
  31856. location: 8
  31857. },
  31858. "spacing": {
  31859. name: "spacing",
  31860. location: 9
  31861. },
  31862. "gps-time": {
  31863. name: "gpsTime",
  31864. location: 10
  31865. },
  31866. "aExtra": {
  31867. name: "aExtra",
  31868. location: 11
  31869. }
  31870. };
  31871. class Shader$1 {
  31872. constructor(gl, name, vsSource, fsSource) {
  31873. this.gl = gl;
  31874. this.name = name;
  31875. this.vsSource = vsSource;
  31876. this.fsSource = fsSource;
  31877. this.cache = new Map();
  31878. this.vs = null;
  31879. this.fs = null;
  31880. this.program = null;
  31881. this.uniformLocations = {};
  31882. this.attributeLocations = {};
  31883. this.uniformBlockIndices = {};
  31884. this.uniformBlocks = {};
  31885. this.uniforms = {};
  31886. this.update(vsSource, fsSource);
  31887. }
  31888. update(vsSource, fsSource) {
  31889. this.vsSource = vsSource;
  31890. this.fsSource = fsSource;
  31891. this.linkProgram();
  31892. }
  31893. compileShader(shader, source) {
  31894. var gl = this.gl;
  31895. gl.shaderSource(shader, source);
  31896. gl.compileShader(shader);
  31897. var success = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  31898. if (!success) {
  31899. var info = gl.getShaderInfoLog(shader);
  31900. var numberedSource = source.split("\n").map((a, i) => "".concat(i + 1).padEnd(5) + a).join("\n");
  31901. throw "could not compile shader ".concat(this.name, ": ").concat(info, ", \n").concat(numberedSource);
  31902. }
  31903. }
  31904. linkProgram() {
  31905. var tStart = performance.now();
  31906. var gl = this.gl;
  31907. this.uniformLocations = {};
  31908. this.attributeLocations = {};
  31909. this.uniforms = {};
  31910. gl.useProgram(null);
  31911. var cached = this.cache.get("".concat(this.vsSource, ", ").concat(this.fsSource));
  31912. if (cached) {
  31913. this.program = cached.program;
  31914. this.vs = cached.vs;
  31915. this.fs = cached.fs;
  31916. this.attributeLocations = cached.attributeLocations;
  31917. this.uniformLocations = cached.uniformLocations;
  31918. this.uniformBlocks = cached.uniformBlocks;
  31919. this.uniforms = cached.uniforms;
  31920. return;
  31921. } else {
  31922. this.vs = gl.createShader(gl.VERTEX_SHADER);
  31923. this.fs = gl.createShader(gl.FRAGMENT_SHADER);
  31924. this.program = gl.createProgram();
  31925. if (!gl.isProgram(this.program)) {
  31926. //创建失败 开启多个页面可能会,原因是webglcontextlost
  31927. //console.error('创建program失败');
  31928. viewer.dispatchEvent('webglError', {
  31929. msg: 'potreeRenderer创建program失败'
  31930. });
  31931. console.log(this.vs);
  31932. console.log(this.fs);
  31933. return;
  31934. }
  31935. for (var name of Object.keys(attributeLocations$1)) {
  31936. var location = attributeLocations$1[name].location;
  31937. var glslName = attributeLocations$1[name].name;
  31938. gl.bindAttribLocation(this.program, location, glslName);
  31939. }
  31940. this.compileShader(this.vs, this.vsSource);
  31941. this.compileShader(this.fs, this.fsSource);
  31942. var program = this.program;
  31943. gl.attachShader(program, this.vs);
  31944. gl.attachShader(program, this.fs);
  31945. gl.linkProgram(program);
  31946. gl.detachShader(program, this.vs);
  31947. gl.detachShader(program, this.fs);
  31948. // 检测当前程序链接状态
  31949. var success = gl.getProgramParameter(program, gl.LINK_STATUS);
  31950. if (!success) {
  31951. var info = gl.getProgramInfoLog(program);
  31952. throw "could not link program ".concat(this.name, ": ").concat(info);
  31953. }
  31954. {
  31955. // attribute locations
  31956. var numAttributes = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
  31957. for (var i = 0; i < numAttributes; i++) {
  31958. var attribute = gl.getActiveAttrib(program, i);
  31959. var _location = gl.getAttribLocation(program, attribute.name);
  31960. this.attributeLocations[attribute.name] = _location;
  31961. }
  31962. }
  31963. {
  31964. // uniform locations
  31965. var numUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
  31966. for (var _i = 0; _i < numUniforms; _i++) {
  31967. var uniform = gl.getActiveUniform(program, _i);
  31968. var _location2 = gl.getUniformLocation(program, uniform.name);
  31969. this.uniformLocations[uniform.name] = _location2;
  31970. this.uniforms[uniform.name] = {
  31971. location: _location2,
  31972. value: null
  31973. };
  31974. }
  31975. }
  31976. // uniform blocks
  31977. if (typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext) {
  31978. //WebGL2RenderingContext在mac的safari14以下是没有定义的
  31979. var numBlocks = gl.getProgramParameter(program, gl.ACTIVE_UNIFORM_BLOCKS);
  31980. for (var _i2 = 0; _i2 < numBlocks; _i2++) {
  31981. var blockName = gl.getActiveUniformBlockName(program, _i2);
  31982. var blockIndex = gl.getUniformBlockIndex(program, blockName);
  31983. this.uniformBlockIndices[blockName] = blockIndex;
  31984. gl.uniformBlockBinding(program, blockIndex, blockIndex);
  31985. var dataSize = gl.getActiveUniformBlockParameter(program, blockIndex, gl.UNIFORM_BLOCK_DATA_SIZE);
  31986. var uBuffer = gl.createBuffer();
  31987. gl.bindBuffer(gl.UNIFORM_BUFFER, uBuffer);
  31988. gl.bufferData(gl.UNIFORM_BUFFER, dataSize, gl.DYNAMIC_READ);
  31989. gl.bindBufferBase(gl.UNIFORM_BUFFER, blockIndex, uBuffer);
  31990. gl.bindBuffer(gl.UNIFORM_BUFFER, null);
  31991. this.uniformBlocks[blockName] = {
  31992. name: blockName,
  31993. index: blockIndex,
  31994. dataSize: dataSize,
  31995. buffer: uBuffer
  31996. };
  31997. }
  31998. }
  31999. var _cached = {
  32000. program: this.program,
  32001. vs: this.vs,
  32002. fs: this.fs,
  32003. attributeLocations: this.attributeLocations,
  32004. uniformLocations: this.uniformLocations,
  32005. uniforms: this.uniforms,
  32006. uniformBlocks: this.uniformBlocks
  32007. };
  32008. this.cache.set("".concat(this.vsSource, ", ").concat(this.fsSource), _cached);
  32009. }
  32010. var tEnd = performance.now();
  32011. var duration = tEnd - tStart;
  32012. //console.log(`shader compile duration: ${duration.toFixed(3)}`);
  32013. }
  32014. setUniformMatrix4(name, value) {
  32015. var gl = this.gl;
  32016. var location = this.uniformLocations[name];
  32017. if (location == null) {
  32018. return;
  32019. }
  32020. var tmp = new Float32Array(value.elements);
  32021. gl.uniformMatrix4fv(location, false, tmp);
  32022. }
  32023. setUniform1f(name, value) {
  32024. var gl = this.gl;
  32025. var uniform = this.uniforms[name];
  32026. if (uniform === undefined) {
  32027. return;
  32028. }
  32029. if (uniform.value === value) {
  32030. return;
  32031. }
  32032. uniform.value = value;
  32033. gl.uniform1f(uniform.location, value);
  32034. }
  32035. setUniformBoolean(name, value) {
  32036. var gl = this.gl;
  32037. var uniform = this.uniforms[name];
  32038. if (uniform === undefined) {
  32039. return;
  32040. }
  32041. if (uniform.value === value) {
  32042. return;
  32043. }
  32044. uniform.value = value;
  32045. gl.uniform1i(uniform.location, value);
  32046. }
  32047. setUniformTexture(name, value) {
  32048. var gl = this.gl;
  32049. var location = this.uniformLocations[name];
  32050. if (location == null) {
  32051. return;
  32052. }
  32053. gl.uniform1i(location, value);
  32054. }
  32055. setUniform2f(name, value) {
  32056. var gl = this.gl;
  32057. var location = this.uniformLocations[name];
  32058. if (location == null) {
  32059. return;
  32060. }
  32061. gl.uniform2f(location, value[0], value[1]);
  32062. }
  32063. setUniform3f(name, value) {
  32064. var gl = this.gl;
  32065. var location = this.uniformLocations[name];
  32066. if (location == null) {
  32067. return;
  32068. }
  32069. gl.uniform3f(location, value[0], value[1], value[2]);
  32070. }
  32071. setUniform(name, value) {
  32072. if (value.constructor === Matrix4) {
  32073. this.setUniformMatrix4(name, value);
  32074. } else if (typeof value === "number") {
  32075. this.setUniform1f(name, value);
  32076. } else if (typeof value === "boolean") {
  32077. this.setUniformBoolean(name, value);
  32078. } else if (value instanceof WebGLTexture$1) {
  32079. this.setUniformTexture(name, value);
  32080. } else if (value instanceof Array) {
  32081. if (value.length === 2) {
  32082. this.setUniform2f(name, value);
  32083. } else if (value.length === 3) {
  32084. this.setUniform3f(name, value);
  32085. }
  32086. } else {
  32087. console.error("unhandled uniform type: ", name, value);
  32088. }
  32089. }
  32090. setUniform1i(name, value) {
  32091. var gl = this.gl;
  32092. var location = this.uniformLocations[name];
  32093. if (location == null) {
  32094. return;
  32095. }
  32096. gl.uniform1i(location, value);
  32097. }
  32098. }
  32099. ;
  32100. class WebGLTexture$1 {
  32101. constructor(gl, texture, threeRenderer) {
  32102. this.gl = gl;
  32103. this.texture = texture;
  32104. if (texture.image && !(texture.image instanceof Image) && !texture.isCanvasTexture && !texture.isDataTexture) {
  32105. //renderTarget的texture在创建renderTarget时已经初始化过 见setupRenderTarget
  32106. this.id = threeRenderer.properties.get(texture).__webglTexture || gl.createTexture();
  32107. this.isFromRenderTarget = true;
  32108. } else {
  32109. this.id = gl.createTexture();
  32110. }
  32111. this.target = gl.TEXTURE_2D;
  32112. this.version = -1;
  32113. this.update(texture);
  32114. }
  32115. update() {
  32116. if (!this.texture.image) {
  32117. this.version = this.texture.version;
  32118. return;
  32119. }
  32120. //if(this.isFromRenderTarget)return //没找到怎么update。 在three.js里的uploadTexture没找到。 这里会报错,可能是 state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null ),类似depthTex的写法
  32121. var gl = this.gl;
  32122. var texture = this.texture;
  32123. if (this.version === texture.version) {
  32124. return;
  32125. }
  32126. this.target = gl.TEXTURE_2D;
  32127. gl.bindTexture(this.target, this.id);
  32128. var level = 0;
  32129. var internalFormat = paramThreeToGL$1(gl, texture.format);
  32130. var width = texture.image.width;
  32131. var height = texture.image.height;
  32132. var border = 0;
  32133. var srcFormat = internalFormat;
  32134. var srcType = paramThreeToGL$1(gl, texture.type);
  32135. var data;
  32136. gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, texture.flipY);
  32137. gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha);
  32138. gl.pixelStorei(gl.UNPACK_ALIGNMENT, texture.unpackAlignment);
  32139. if (texture instanceof DataTexture) {
  32140. data = texture.image.data;
  32141. gl.texParameteri(this.target, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  32142. gl.texParameteri(this.target, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  32143. gl.texParameteri(this.target, gl.TEXTURE_MAG_FILTER, paramThreeToGL$1(gl, texture.magFilter));
  32144. gl.texParameteri(this.target, gl.TEXTURE_MIN_FILTER, paramThreeToGL$1(gl, texture.minFilter));
  32145. gl.texImage2D(this.target, level, internalFormat, width, height, border, srcFormat, srcType, data);
  32146. } else if (texture instanceof CanvasTexture || texture instanceof Texture) {
  32147. data = texture.image;
  32148. gl.texParameteri(this.target, gl.TEXTURE_WRAP_S, paramThreeToGL$1(gl, texture.wrapS));
  32149. gl.texParameteri(this.target, gl.TEXTURE_WRAP_T, paramThreeToGL$1(gl, texture.wrapT));
  32150. gl.texParameteri(this.target, gl.TEXTURE_MAG_FILTER, paramThreeToGL$1(gl, texture.magFilter));
  32151. gl.texParameteri(this.target, gl.TEXTURE_MIN_FILTER, paramThreeToGL$1(gl, texture.minFilter));
  32152. if (this.isFromRenderTarget) {
  32153. //咋写?
  32154. //gl.texImage2D( 3553, 0, internalFormat, width, height, 0, srcFormat, srcType, null )
  32155. //console.log('isFromRenderTarget')
  32156. } else {
  32157. gl.texImage2D(this.target, level, internalFormat, internalFormat, srcType, data); //这个参数怎么跟我查的不一样呢
  32158. }
  32159. if (texture instanceof Texture) {
  32160. gl.generateMipmap(gl.TEXTURE_2D);
  32161. }
  32162. }
  32163. gl.bindTexture(this.target, null);
  32164. this.version = texture.version;
  32165. }
  32166. }
  32167. ;
  32168. class WebGLBuffer$1 {
  32169. constructor() {
  32170. this.numElements = 0;
  32171. this.vao = null;
  32172. this.vbos = new Map();
  32173. }
  32174. }
  32175. ;
  32176. class Renderer$1 {
  32177. constructor(threeRenderer) {
  32178. this.threeRenderer = threeRenderer;
  32179. this.gl = this.threeRenderer.getContext();
  32180. this.buffers = new Map();
  32181. this.shaders = new Map();
  32182. this.textures = new Map();
  32183. this.glTypeMapping = new Map();
  32184. this.glTypeMapping.set(Float32Array, this.gl.FLOAT);
  32185. this.glTypeMapping.set(Uint8Array, this.gl.UNSIGNED_BYTE);
  32186. this.glTypeMapping.set(Uint16Array, this.gl.UNSIGNED_SHORT);
  32187. this.toggle = 0;
  32188. }
  32189. deleteBuffer(geometry) {
  32190. var gl = this.gl;
  32191. var webglBuffer = this.buffers.get(geometry);
  32192. if (webglBuffer != null) {
  32193. for (var attributeName in geometry.attributes) {
  32194. gl.deleteBuffer(webglBuffer.vbos.get(attributeName).handle);
  32195. }
  32196. this.buffers.delete(geometry);
  32197. }
  32198. }
  32199. createBuffer(geometry) {
  32200. var gl = this.gl;
  32201. var webglBuffer = new WebGLBuffer$1();
  32202. webglBuffer.vao = gl.createVertexArray();
  32203. webglBuffer.numElements = geometry.attributes.position.count;
  32204. gl.bindVertexArray(webglBuffer.vao);
  32205. for (var attributeName in geometry.attributes) {
  32206. var bufferAttribute = geometry.attributes[attributeName];
  32207. var vbo = gl.createBuffer();
  32208. gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
  32209. gl.bufferData(gl.ARRAY_BUFFER, bufferAttribute.array, gl.STATIC_DRAW);
  32210. var normalized = bufferAttribute.normalized;
  32211. var type = this.glTypeMapping.get(bufferAttribute.array.constructor);
  32212. if (attributeLocations$1[attributeName] === undefined) {
  32213. //attributeLocation = attributeLocations["aExtra"];
  32214. } else {
  32215. var attributeLocation = attributeLocations$1[attributeName].location;
  32216. gl.vertexAttribPointer(attributeLocation, bufferAttribute.itemSize, type, normalized, 0, 0);
  32217. gl.enableVertexAttribArray(attributeLocation);
  32218. }
  32219. webglBuffer.vbos.set(attributeName, {
  32220. handle: vbo,
  32221. name: attributeName,
  32222. count: bufferAttribute.count,
  32223. itemSize: bufferAttribute.itemSize,
  32224. type: geometry.attributes.position.array.constructor,
  32225. version: 0
  32226. });
  32227. }
  32228. gl.bindBuffer(gl.ARRAY_BUFFER, null);
  32229. gl.bindVertexArray(null);
  32230. var disposeHandler = event => {
  32231. this.deleteBuffer(geometry);
  32232. geometry.removeEventListener("dispose", disposeHandler);
  32233. };
  32234. geometry.addEventListener("dispose", disposeHandler);
  32235. return webglBuffer;
  32236. }
  32237. updateBuffer(geometry) {
  32238. var gl = this.gl;
  32239. var webglBuffer = this.buffers.get(geometry);
  32240. gl.bindVertexArray(webglBuffer.vao);
  32241. for (var attributeName in geometry.attributes) {
  32242. var bufferAttribute = geometry.attributes[attributeName];
  32243. var normalized = bufferAttribute.normalized;
  32244. var type = this.glTypeMapping.get(bufferAttribute.array.constructor);
  32245. var vbo = null;
  32246. if (!webglBuffer.vbos.has(attributeName)) {
  32247. vbo = gl.createBuffer();
  32248. webglBuffer.vbos.set(attributeName, {
  32249. handle: vbo,
  32250. name: attributeName,
  32251. count: bufferAttribute.count,
  32252. itemSize: bufferAttribute.itemSize,
  32253. type: geometry.attributes.position.array.constructor,
  32254. version: bufferAttribute.version
  32255. });
  32256. } else {
  32257. vbo = webglBuffer.vbos.get(attributeName).handle;
  32258. webglBuffer.vbos.get(attributeName).version = bufferAttribute.version;
  32259. }
  32260. gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
  32261. gl.bufferData(gl.ARRAY_BUFFER, bufferAttribute.array, gl.STATIC_DRAW);
  32262. if (attributeLocations$1[attributeName] === undefined) {
  32263. //attributeLocation = attributeLocations["aExtra"];
  32264. } else {
  32265. var attributeLocation = attributeLocations$1[attributeName].location;
  32266. gl.vertexAttribPointer(attributeLocation, bufferAttribute.itemSize, type, normalized, 0, 0);
  32267. gl.enableVertexAttribArray(attributeLocation);
  32268. }
  32269. }
  32270. gl.bindBuffer(gl.ARRAY_BUFFER, null);
  32271. gl.bindVertexArray(null);
  32272. }
  32273. traverse(scene) {
  32274. var octrees = [];
  32275. var stack = [scene];
  32276. while (stack.length > 0) {
  32277. var node = stack.pop();
  32278. if (node instanceof PointCloudTree) {
  32279. octrees.push(node);
  32280. continue;
  32281. }
  32282. var visibleChildren = node.children.filter(c => c.visible);
  32283. stack.push(...visibleChildren);
  32284. }
  32285. var result = {
  32286. octrees: octrees
  32287. };
  32288. return result;
  32289. }
  32290. renderNodes(octree, nodes, visibilityTextureData, camera, target, shader, params) {
  32291. var _this = this;
  32292. viewer.addTimeMark('renderNodes', 'start');
  32293. var gl = this.gl;
  32294. var material = params.material ? params.material : octree.material;
  32295. var shadowMaps = params.shadowMaps == null ? [] : params.shadowMaps;
  32296. var view = camera.matrixWorldInverse;
  32297. if (params.viewOverride) {
  32298. view = params.viewOverride;
  32299. }
  32300. var worldView = new Matrix4();
  32301. var mat4holder = new Float32Array(16);
  32302. var i = 0;
  32303. //---------从renderOctree搬到这----
  32304. shader.setUniform1f("size", material.usePanoMap ? Potree.config.material.absolutePanoramaSize * Math.min(window.devicePixelRatio, 2) : material.size); //usePanoMap时控制在不大不小的范围内感觉较好,考虑到有的点云稀疏,用大一点的点
  32305. shader.setUniform1f("uOpacity", material.usePanoMap ? 1 : material.opacity);
  32306. shader.setUniform3f("uColor", material.color.toArray());
  32307. var currentTextureBindingPoint = params.currentTextureBindingPoint;
  32308. if (material.pointSizeType >= 0 /* && window.needvisibilityTexture */) {
  32309. if (material.pointSizeType === PointSizeType.ADAPTIVE || material.activeAttributeName === "level of detail") {
  32310. var vnNodes = params.vnTextureNodes != null ? params.vnTextureNodes : nodes;
  32311. visibilityTextureData = octree.computeVisibilityTextureData(vnNodes, camera);
  32312. var vnt = material.visibleNodesTexture;
  32313. var data = vnt.image.data;
  32314. data.set(visibilityTextureData.data);
  32315. vnt.needsUpdate = true;
  32316. var webGLTexture = this.textures.get(vnt);
  32317. webGLTexture.update(); //不加这个会闪烁
  32318. var vnWebGLTexture = this.textures.get(material.visibleNodesTexture); //不知道为什么这段从renderOctree中移过来,会崩溃。暂时不移动了
  32319. if (vnWebGLTexture) {
  32320. shader.setUniform1i("visibleNodes", currentTextureBindingPoint);
  32321. gl.activeTexture(gl.TEXTURE0 + currentTextureBindingPoint);
  32322. gl.bindTexture(vnWebGLTexture.target, vnWebGLTexture.id);
  32323. currentTextureBindingPoint++;
  32324. }
  32325. }
  32326. }
  32327. /* if (material.pointSizeType >= 0) {
  32328. if (material.pointSizeType === PointSizeType.ADAPTIVE ||
  32329. material.activeAttributeName === "level of detail") {
  32330. let vnNodes = (params.vnTextureNodes != null) ? params.vnTextureNodes : nodes;
  32331. visibilityTextureData = octree.computeVisibilityTextureData(vnNodes, camera);
  32332. const vnt = material.visibleNodesTexture;
  32333. const data = vnt.image.data;
  32334. data.set(visibilityTextureData.data);
  32335. vnt.needsUpdate = true;
  32336. }
  32337. } */
  32338. var transparent = false;
  32339. if (params.transparent !== undefined) {
  32340. transparent = params.transparent && material.opacity < 1;
  32341. } else {
  32342. transparent = material.usePanoMap ? false : material.useFilterByNormal || material.opacity < 1; //add useFilterByNormal
  32343. }
  32344. if (transparent) {
  32345. gl.enable(gl.BLEND);
  32346. if (params.notAdditiveBlending) {
  32347. gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA); //NormalBlending
  32348. /* gl.enable(gl.DEPTH_TEST);
  32349. gl.depthMask(true); //如果不开启depthWrite, 深度会错乱。 */ //无解
  32350. gl.disable(gl.DEPTH_TEST);
  32351. gl.depthMask(true);
  32352. } else {
  32353. gl.blendFunc(gl.SRC_ALPHA, gl.ONE); //AdditiveBlending 原本
  32354. gl.disable(gl.DEPTH_TEST);
  32355. gl.depthMask(false);
  32356. }
  32357. } else {
  32358. gl.disable(gl.BLEND);
  32359. gl.depthMask(true);
  32360. gl.enable(gl.DEPTH_TEST);
  32361. }
  32362. if (params.blendFunc !== undefined) {
  32363. gl.enable(gl.BLEND);
  32364. gl.blendFunc(...params.blendFunc);
  32365. }
  32366. if (params.depthTest !== undefined) {
  32367. if (params.depthTest === true) {
  32368. gl.enable(gl.DEPTH_TEST);
  32369. } else {
  32370. gl.disable(gl.DEPTH_TEST);
  32371. }
  32372. }
  32373. if (params.depthWrite !== undefined) {
  32374. if (params.depthWrite === true) {
  32375. gl.depthMask(true);
  32376. } else {
  32377. gl.depthMask(false);
  32378. }
  32379. }
  32380. //---------------------------------
  32381. var _loop = function _loop() {
  32382. if (exports.debug.allowedNodes !== undefined) {
  32383. if (!exports.debug.allowedNodes.includes(node.name)) {
  32384. return 1; // continue
  32385. }
  32386. }
  32387. var world = node.sceneNode.matrixWorld;
  32388. worldView.multiplyMatrices(view, world);
  32389. if (visibilityTextureData) {
  32390. var vnStart = visibilityTextureData.offsets.get(node);
  32391. //console.log('vnStart',vnStart)
  32392. shader.setUniform1f("uVNStart", vnStart);
  32393. }
  32394. var level = node.getLevel();
  32395. if (node.debug) {
  32396. shader.setUniform("uDebug", true);
  32397. } else {
  32398. shader.setUniform("uDebug", false);
  32399. }
  32400. // let isLeaf = false;
  32401. // if(node instanceof PointCloudOctreeNode){
  32402. // isLeaf = Object.keys(node.children).length === 0;
  32403. // }else if(node instanceof PointCloudArena4DNode){
  32404. // isLeaf = node.geometryNode.isLeaf;
  32405. // }
  32406. // shader.setUniform("uIsLeafNode", isLeaf);
  32407. // let isLeaf = node.children.filter(n => n != null).length === 0;
  32408. // if(!isLeaf){
  32409. // continue;
  32410. // }
  32411. // TODO consider passing matrices in an array to avoid uniformMatrix4fv overhead
  32412. var lModel = shader.uniformLocations["modelMatrix"];
  32413. if (lModel) {
  32414. mat4holder.set(world.elements);
  32415. gl.uniformMatrix4fv(lModel, false, mat4holder);
  32416. }
  32417. var lModelView = shader.uniformLocations["modelViewMatrix"];
  32418. //mat4holder.set(worldView.elements);
  32419. // faster then set in chrome 63
  32420. for (var j = 0; j < 16; j++) {
  32421. mat4holder[j] = worldView.elements[j];
  32422. }
  32423. gl.uniformMatrix4fv(lModelView, false, mat4holder);
  32424. {
  32425. // Clip Polygons
  32426. if (material.clipPolygons && material.clipPolygons.length > 0) {
  32427. var clipPolygonVCount = [];
  32428. var worldViewProjMatrices = [];
  32429. for (var clipPolygon of material.clipPolygons) {
  32430. var _view = clipPolygon.viewMatrix;
  32431. var proj = clipPolygon.projMatrix;
  32432. var worldViewProj = proj.clone().multiply(_view).multiply(world);
  32433. clipPolygonVCount.push(clipPolygon.markers.length);
  32434. worldViewProjMatrices.push(worldViewProj);
  32435. }
  32436. var flattenedMatrices = [].concat(...worldViewProjMatrices.map(m => m.elements));
  32437. var flattenedVertices = new Array(8 * 3 * material.clipPolygons.length);
  32438. for (var _i3 = 0; _i3 < material.clipPolygons.length; _i3++) {
  32439. var _clipPolygon = material.clipPolygons[_i3];
  32440. for (var _j = 0; _j < _clipPolygon.markers.length; _j++) {
  32441. flattenedVertices[_i3 * 24 + (_j * 3 + 0)] = _clipPolygon.markers[_j].position.x;
  32442. flattenedVertices[_i3 * 24 + (_j * 3 + 1)] = _clipPolygon.markers[_j].position.y;
  32443. flattenedVertices[_i3 * 24 + (_j * 3 + 2)] = _clipPolygon.markers[_j].position.z;
  32444. }
  32445. }
  32446. var lClipPolygonVCount = shader.uniformLocations["uClipPolygonVCount[0]"];
  32447. gl.uniform1iv(lClipPolygonVCount, clipPolygonVCount);
  32448. var lClipPolygonVP = shader.uniformLocations["uClipPolygonWVP[0]"];
  32449. gl.uniformMatrix4fv(lClipPolygonVP, false, flattenedMatrices);
  32450. var lClipPolygons = shader.uniformLocations["uClipPolygonVertices[0]"];
  32451. gl.uniform3fv(lClipPolygons, flattenedVertices);
  32452. }
  32453. }
  32454. //shader.setUniformMatrix4("modelMatrix", world);
  32455. //shader.setUniformMatrix4("modelViewMatrix", worldView);
  32456. shader.setUniform1f("uLevel", level);
  32457. shader.setUniform1f("levelPercent", octree.nodeMaxLevel ? level / octree.nodeMaxLevel : 0.5); //xzw add
  32458. shader.setUniform1f("uNodeSpacing", node.geometryNode.estimatedSpacing);
  32459. shader.setUniform1f("uPCIndex", i);
  32460. // uBBSize
  32461. if (shadowMaps.length > 0) {
  32462. var lShadowMap = shader.uniformLocations["uShadowMap[0]"];
  32463. shader.setUniform3f("uShadowColor", material.uniforms.uShadowColor.value);
  32464. var bindingStart = 5;
  32465. var bindingPoints = new Array(shadowMaps.length).fill(bindingStart).map((a, i) => a + i);
  32466. gl.uniform1iv(lShadowMap, bindingPoints);
  32467. for (var _i4 = 0; _i4 < shadowMaps.length; _i4++) {
  32468. var shadowMap = shadowMaps[_i4];
  32469. var bindingPoint = bindingPoints[_i4];
  32470. var glTexture = _this.threeRenderer.properties.get(shadowMap.target.texture).__webglTexture;
  32471. gl.activeTexture(gl["TEXTURE".concat(bindingPoint)]);
  32472. gl.bindTexture(gl.TEXTURE_2D, glTexture);
  32473. }
  32474. {
  32475. var worldViewMatrices = shadowMaps.map(sm => sm.camera.matrixWorldInverse).map(view => new Matrix4().multiplyMatrices(view, world));
  32476. var _flattenedMatrices = [].concat(...worldViewMatrices.map(c => c.elements));
  32477. var lWorldView = shader.uniformLocations["uShadowWorldView[0]"];
  32478. gl.uniformMatrix4fv(lWorldView, false, _flattenedMatrices);
  32479. }
  32480. {
  32481. var _flattenedMatrices2 = [].concat(...shadowMaps.map(sm => sm.camera.projectionMatrix.elements));
  32482. var lProj = shader.uniformLocations["uShadowProj[0]"];
  32483. gl.uniformMatrix4fv(lProj, false, _flattenedMatrices2);
  32484. }
  32485. }
  32486. var geometry = node.geometryNode.geometry;
  32487. if (geometry.attributes["gps-time"]) {
  32488. var bufferAttribute = geometry.attributes["gps-time"];
  32489. var attGPS = octree.getAttribute("gps-time");
  32490. var initialRange = attGPS.initialRange;
  32491. var initialRangeSize = initialRange[1] - initialRange[0];
  32492. var globalRange = attGPS.range;
  32493. var globalRangeSize = globalRange[1] - globalRange[0];
  32494. var scale = initialRangeSize / globalRangeSize;
  32495. var offset = -(globalRange[0] - initialRange[0]) / initialRangeSize;
  32496. scale = Number.isNaN(scale) ? 1 : scale;
  32497. offset = Number.isNaN(offset) ? 0 : offset;
  32498. shader.setUniform1f("uGpsScale", scale);
  32499. shader.setUniform1f("uGpsOffset", offset);
  32500. //shader.setUniform2f("uFilterGPSTimeClipRange", [-Infinity, Infinity]);
  32501. var uFilterGPSTimeClipRange = material.uniforms.uFilterGPSTimeClipRange.value;
  32502. // let gpsCliPRangeMin = uFilterGPSTimeClipRange[0]
  32503. // let gpsCliPRangeMax = uFilterGPSTimeClipRange[1]
  32504. // shader.setUniform2f("uFilterGPSTimeClipRange", [gpsCliPRangeMin, gpsCliPRangeMax]);
  32505. var normalizedClipRange = [(uFilterGPSTimeClipRange[0] - globalRange[0]) / globalRangeSize, (uFilterGPSTimeClipRange[1] - globalRange[0]) / globalRangeSize];
  32506. shader.setUniform2f("uFilterGPSTimeClipRange", normalizedClipRange);
  32507. // // ranges in full gps coordinate system
  32508. // const globalRange = attGPS.range;
  32509. // const bufferRange = bufferAttribute.potree.range;
  32510. // // ranges in [0, 1]
  32511. // // normalizedGlobalRange = [0, 1]
  32512. // // normalizedBufferRange: norm buffer within norm global range e.g. [0.2, 0.8]
  32513. // const globalWidth = globalRange[1] - globalRange[0];
  32514. // const normalizedBufferRange = [
  32515. // (bufferRange[0] - globalRange[0]) / globalWidth,
  32516. // (bufferRange[1] - globalRange[0]) / globalWidth,
  32517. // ];
  32518. // shader.setUniform2f("uNormalizedGpsBufferRange", normalizedBufferRange);
  32519. // let uFilterGPSTimeClipRange = material.uniforms.uFilterGPSTimeClipRange.value;
  32520. // let gpsCliPRangeMin = uFilterGPSTimeClipRange[0]
  32521. // let gpsCliPRangeMax = uFilterGPSTimeClipRange[1]
  32522. // shader.setUniform2f("uFilterGPSTimeClipRange", [gpsCliPRangeMin, gpsCliPRangeMax]);
  32523. // shader.setUniform1f("uGpsScale", bufferAttribute.potree.scale);
  32524. // shader.setUniform1f("uGpsOffset", bufferAttribute.potree.offset);
  32525. }
  32526. {
  32527. var uFilterReturnNumberRange = material.uniforms.uFilterReturnNumberRange.value;
  32528. var uFilterNumberOfReturnsRange = material.uniforms.uFilterNumberOfReturnsRange.value;
  32529. var uFilterPointSourceIDClipRange = material.uniforms.uFilterPointSourceIDClipRange.value;
  32530. shader.setUniform2f("uFilterReturnNumberRange", uFilterReturnNumberRange);
  32531. shader.setUniform2f("uFilterNumberOfReturnsRange", uFilterNumberOfReturnsRange);
  32532. shader.setUniform2f("uFilterPointSourceIDClipRange", uFilterPointSourceIDClipRange);
  32533. }
  32534. var webglBuffer = null;
  32535. if (!_this.buffers.has(geometry)) {
  32536. webglBuffer = _this.createBuffer(geometry);
  32537. _this.buffers.set(geometry, webglBuffer);
  32538. } else {
  32539. webglBuffer = _this.buffers.get(geometry);
  32540. for (var attributeName in geometry.attributes) {
  32541. var attribute = geometry.attributes[attributeName];
  32542. if (attribute.version > webglBuffer.vbos.get(attributeName).version) {
  32543. _this.updateBuffer(geometry);
  32544. }
  32545. }
  32546. }
  32547. gl.bindVertexArray(webglBuffer.vao);
  32548. var isExtraAttribute = attributeLocations$1[material.activeAttributeName] === undefined && Object.keys(geometry.attributes).includes(material.activeAttributeName);
  32549. if (isExtraAttribute) {
  32550. var attributeLocation = attributeLocations$1["aExtra"].location;
  32551. for (var _attributeName in geometry.attributes) {
  32552. var _bufferAttribute = geometry.attributes[_attributeName];
  32553. var _vbo = webglBuffer.vbos.get(_attributeName);
  32554. gl.bindBuffer(gl.ARRAY_BUFFER, _vbo.handle);
  32555. gl.disableVertexAttribArray(attributeLocation);
  32556. }
  32557. var attName = material.activeAttributeName;
  32558. var _bufferAttribute2 = geometry.attributes[attName];
  32559. var vbo = webglBuffer.vbos.get(attName);
  32560. if (_bufferAttribute2 !== undefined && vbo !== undefined) {
  32561. var type = _this.glTypeMapping.get(_bufferAttribute2.array.constructor);
  32562. var normalized = _bufferAttribute2.normalized;
  32563. gl.bindBuffer(gl.ARRAY_BUFFER, vbo.handle);
  32564. gl.vertexAttribPointer(attributeLocation, _bufferAttribute2.itemSize, type, normalized, 0, 0);
  32565. gl.enableVertexAttribArray(attributeLocation);
  32566. }
  32567. {
  32568. var attExtra = octree.pcoGeometry.pointAttributes.attributes.find(a => a.name === attName);
  32569. var range = material.getRange(attName);
  32570. if (!range) {
  32571. range = attExtra.range;
  32572. }
  32573. if (!range) {
  32574. range = [0, 1];
  32575. }
  32576. var _initialRange = attExtra.initialRange;
  32577. var _initialRangeSize = _initialRange[1] - _initialRange[0];
  32578. var _globalRange = range;
  32579. var _globalRangeSize = _globalRange[1] - _globalRange[0];
  32580. var _scale = _initialRangeSize / _globalRangeSize;
  32581. var _offset = -(_globalRange[0] - _initialRange[0]) / _initialRangeSize;
  32582. _scale = Number.isNaN(_scale) ? 1 : _scale;
  32583. _offset = Number.isNaN(_offset) ? 0 : _offset;
  32584. shader.setUniform1f("uExtraScale", _scale);
  32585. shader.setUniform1f("uExtraOffset", _offset);
  32586. }
  32587. } else {
  32588. for (var _attributeName2 in geometry.attributes) {
  32589. var _bufferAttribute3 = geometry.attributes[_attributeName2];
  32590. var _vbo2 = webglBuffer.vbos.get(_attributeName2);
  32591. if (attributeLocations$1[_attributeName2] !== undefined) {
  32592. var _attributeLocation = attributeLocations$1[_attributeName2].location;
  32593. var _type = _this.glTypeMapping.get(_bufferAttribute3.array.constructor);
  32594. var _normalized = _bufferAttribute3.normalized;
  32595. gl.bindBuffer(gl.ARRAY_BUFFER, _vbo2.handle);
  32596. gl.vertexAttribPointer(_attributeLocation, _bufferAttribute3.itemSize, _type, _normalized, 0, 0);
  32597. gl.enableVertexAttribArray(_attributeLocation);
  32598. }
  32599. }
  32600. }
  32601. var numPoints = webglBuffer.numElements;
  32602. gl.drawArrays(gl.POINTS, 0, numPoints);
  32603. //gl.drawArrays(gl.TRIANGLES, 0, numPoints);
  32604. i++;
  32605. };
  32606. for (var node of nodes) {
  32607. if (_loop()) continue;
  32608. }
  32609. gl.bindVertexArray(null);
  32610. viewer.addTimeMark('renderNodes', 'end');
  32611. }
  32612. renderOctree(octrees, nodes, camera, target) {
  32613. var params = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
  32614. viewer.addTimeMark('renderOctree', 'start');
  32615. var octree;
  32616. if (octrees instanceof Array) {
  32617. octree = octrees[0];
  32618. } else {
  32619. octree = octrees;
  32620. octrees = [octree];
  32621. }
  32622. var gl = this.gl;
  32623. var material = params.material ? params.material : octree.material;
  32624. var shadowMaps = params.shadowMaps == null ? [] : params.shadowMaps;
  32625. var view = camera.matrixWorldInverse;
  32626. var viewInv = camera.matrixWorld;
  32627. if (params.viewOverride) {
  32628. view = params.viewOverride;
  32629. viewInv = view.clone().invert();
  32630. }
  32631. var proj = camera.projectionMatrix;
  32632. var projInv = proj.clone().invert();
  32633. //let worldView = new THREE.Matrix4();
  32634. var shader = null;
  32635. var visibilityTextureData = null;
  32636. var currentTextureBindingPoint = 0;
  32637. /* if (material.pointSizeType >= 0) {//最好搬到renderNodes
  32638. if (material.pointSizeType === PointSizeType.ADAPTIVE ||
  32639. material.activeAttributeName === "level of detail") {
  32640. let vnNodes = (params.vnTextureNodes != null) ? params.vnTextureNodes : nodes;
  32641. visibilityTextureData = octree.computeVisibilityTextureData(vnNodes, camera);
  32642. const vnt = material.visibleNodesTexture;
  32643. const data = vnt.image.data;
  32644. data.set(visibilityTextureData.data);
  32645. vnt.needsUpdate = true;
  32646. }
  32647. }
  32648. */
  32649. {
  32650. // UPDATE SHADER AND TEXTURES
  32651. if (!this.shaders.has(material)) {
  32652. var [vs, fs] = [material.vertexShader, material.fragmentShader];
  32653. var _shader = new Shader$1(gl, "pointcloud", vs, fs);
  32654. this.shaders.set(material, _shader);
  32655. }
  32656. shader = this.shaders.get(material);
  32657. if (material.shaderNeedsUpdate) {
  32658. var [_vs, _fs] = [material.vertexShader, material.fragmentShader];
  32659. var numSnapshots = material.snapEnabled ? material.numSnapshots : 0;
  32660. var num_in_clipboxes = material.clipBoxes_in && material.clipBoxes_in.length ? material.clipBoxes_in.length : 0;
  32661. var num_out_clipboxes = material.clipBoxes_out && material.clipBoxes_out.length ? material.clipBoxes_out.length : 0;
  32662. var num_highlightBox = material.highlightBoxes && material.highlightBoxes.length ? material.highlightBoxes.length : 0;
  32663. var numClipSpheres = params.clipSpheres && params.clipSpheres.length ? params.clipSpheres.length : 0;
  32664. var numClipPolygons = material.clipPolygons && material.clipPolygons.length ? material.clipPolygons.length : 0;
  32665. var defines = ["#define num_shadowmaps ".concat(shadowMaps.length), "#define num_snapshots ".concat(numSnapshots), "#define num_in_clipboxes ".concat(num_in_clipboxes), //改
  32666. "#define num_out_clipboxes ".concat(num_out_clipboxes), //改
  32667. "#define num_highlightBox ".concat(num_highlightBox), //改
  32668. "#define num_clipspheres ".concat(numClipSpheres), "#define num_prism ".concat(material.prisms.pointsCount ? material.prisms.length : 0), //土方量数 如果num_prism>0,prismPointCountSum为0 会报错 :array size must be greater than zero
  32669. "#define prismPointCountSum ".concat(material.prisms.pointsCount), //点总个数
  32670. "#define prism_maxPointsCount ".concat(material.prisms.maxPointsCount) //单个prism最大点个数 (如果define也能传递个数数组,就不用再uniform里传了,呜 )
  32671. ];
  32672. //add:-----------
  32673. if (material.bigClipInBox) {
  32674. //裁剪下载
  32675. defines.push('#define bigClipInBox');
  32676. }
  32677. if (material.usePanoMap) {
  32678. defines.push("#define usePanoMap");
  32679. }
  32680. if (material.useFilterByNormal) {
  32681. defines.push("#define use_filter_by_normal");
  32682. //Potree.settings.editType == 'pano' ? defines.push("#define attenuated_opacity2") : defines.push("#define attenuated_opacity");
  32683. }
  32684. if (material.uniforms.baseHeightAreaMap.value) {
  32685. //根据模型高亮土方
  32686. defines.push('#define showBaseHeight');
  32687. }
  32688. //---------------
  32689. if (octree.pcoGeometry.root.isLoaded()) {
  32690. var attributes = octree.pcoGeometry.root.geometry.attributes;
  32691. if (attributes["gps-time"]) {
  32692. defines.push("#define clip_gps_enabled");
  32693. }
  32694. if (attributes["return number"]) {
  32695. defines.push("#define clip_return_number_enabled");
  32696. }
  32697. if (attributes["number of returns"]) {
  32698. defines.push("#define clip_number_of_returns_enabled");
  32699. }
  32700. if (attributes["source id"] || attributes["point source id"]) {
  32701. defines.push("#define clip_point_source_id_enabled");
  32702. }
  32703. }
  32704. var definesString = defines.join("\n");
  32705. var vsVersionIndex = _vs.indexOf("#version ");
  32706. var fsVersionIndex = _fs.indexOf("#version ");
  32707. if (vsVersionIndex >= 0) {
  32708. _vs = _vs.replace(/(#version .*)/, "$1\n".concat(definesString));
  32709. } else {
  32710. _vs = "".concat(definesString, "\n").concat(_vs);
  32711. }
  32712. if (fsVersionIndex >= 0) {
  32713. _fs = _fs.replace(/(#version .*)/, "$1\n".concat(definesString));
  32714. } else {
  32715. _fs = "".concat(definesString, "\n").concat(_fs);
  32716. }
  32717. shader.update(_vs, _fs);
  32718. material.shaderNeedsUpdate = false;
  32719. }
  32720. for (var uniformName of Object.keys(material.uniforms)) {
  32721. var uniform = material.uniforms[uniformName];
  32722. if (uniform.type == "t") {
  32723. var texture = uniform.value;
  32724. if (!texture) {
  32725. continue;
  32726. }
  32727. //add
  32728. if (uniformName == 'pano0Map' || uniformName == 'pano1Map') {
  32729. //属于cubeTex,另外设置
  32730. continue;
  32731. }
  32732. /* if(texture.image && !(texture.image instanceof Image) && !(texture instanceof THREE.CanvasTexture)){
  32733. //renderTarget的texture在创建renderTarget时已经初始化过 见setupRenderTarget
  32734. continue
  32735. } */
  32736. if (!this.textures.has(texture) || texture.needsRebuild) {
  32737. var webglTexture = new WebGLTexture$1(gl, texture, this.threeRenderer);
  32738. this.textures.set(texture, webglTexture);
  32739. delete texture.needsRebuild; //renderTarget在resize后会触发dispose, 然后 _gl.deleteTexture( textureProperties.__webglTexture )所以需要重新建立
  32740. }
  32741. var webGLTexture = this.textures.get(texture);
  32742. webGLTexture.update();
  32743. }
  32744. }
  32745. }
  32746. gl.useProgram(shader.program);
  32747. /* let transparent = false;
  32748. if(params.transparent !== undefined){
  32749. transparent = params.transparent && material.opacity < 1;
  32750. }else{
  32751. transparent = material.usePanoMap ? false : (material.useFilterByNormal || material.opacity < 1); //add useFilterByNormal
  32752. }
  32753. if (transparent){
  32754. gl.enable(gl.BLEND);
  32755. if(params.notAdditiveBlending){
  32756. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA ); //NormalBlending
  32757. gl.enable(gl.DEPTH_TEST);
  32758. gl.depthMask(true); //如果不开启depthWrite,深度会错乱。
  32759. }else{
  32760. gl.blendFunc(gl.SRC_ALPHA, gl.ONE); //AdditiveBlending 原本
  32761. gl.disable(gl.DEPTH_TEST);
  32762. gl.depthMask(false);
  32763. }
  32764. } else {
  32765. gl.disable(gl.BLEND);
  32766. gl.depthMask(true);
  32767. gl.enable(gl.DEPTH_TEST);
  32768. }
  32769. if(params.blendFunc !== undefined){
  32770. gl.enable(gl.BLEND);
  32771. gl.blendFunc(...params.blendFunc);
  32772. }
  32773. if(params.depthTest !== undefined){
  32774. if(params.depthTest === true){
  32775. gl.enable(gl.DEPTH_TEST);
  32776. }else{
  32777. gl.disable(gl.DEPTH_TEST);
  32778. }
  32779. }
  32780. if(params.depthWrite !== undefined){
  32781. if(params.depthWrite === true){
  32782. gl.depthMask(true);
  32783. }else{
  32784. gl.depthMask(false);
  32785. }
  32786. } */
  32787. {
  32788. // UPDATE UNIFORMS
  32789. shader.setUniformMatrix4("projectionMatrix", proj);
  32790. shader.setUniformMatrix4("viewMatrix", view);
  32791. shader.setUniformMatrix4("uViewInv", viewInv);
  32792. shader.setUniformMatrix4("uProjInv", projInv);
  32793. /* let screenWidth = target ? target.width : material.screenWidth;
  32794. let screenHeight = target ? target.height : material.screenHeight;
  32795. shader.setUniform1f("uScreenWidth", screenWidth);
  32796. shader.setUniform1f("uScreenHeight", screenHeight); */
  32797. shader.setUniform2f('resolution', material.resolution.toArray());
  32798. shader.setUniform1f("fov", Math.PI * camera.fov / 180);
  32799. shader.setUniform1f("near", camera.near);
  32800. shader.setUniform1f("far", camera.far);
  32801. if (camera instanceof OrthographicCamera) {
  32802. shader.setUniform("uUseOrthographicCamera", true);
  32803. shader.setUniform("uOrthoWidth", (camera.right - camera.left) / camera.zoom); //改
  32804. shader.setUniform("uOrthoHeight", camera.top - camera.bottom);
  32805. } else {
  32806. shader.setUniform("uUseOrthographicCamera", false);
  32807. }
  32808. /* if(material.clipBoxes.length + material.clipPolygons.length === 0){//改
  32809. shader.setUniform1i("clipTask", ClipTask.NONE);
  32810. }else{
  32811. shader.setUniform1i("clipTask", material.clipTask);
  32812. }
  32813. shader.setUniform1i("clipMethod", material.clipMethod);*/
  32814. //改
  32815. if (material.clipBoxes_in && material.clipBoxes_in.length > 0) {
  32816. //let flattenedMatrices = [].concat(...material.clipBoxes.map(c => c.inverse.elements));
  32817. var lClipBoxes = shader.uniformLocations["clipBoxes_in[0]"];
  32818. gl.uniformMatrix4fv(lClipBoxes, false, material.uniforms.clipBoxes_in.value);
  32819. }
  32820. if (material.clipBoxes_out && material.clipBoxes_out.length > 0) {
  32821. //add
  32822. var lClipBoxes2 = shader.uniformLocations["clipBoxes_out[0]"];
  32823. gl.uniformMatrix4fv(lClipBoxes2, false, material.uniforms.clipBoxes_out.value);
  32824. }
  32825. if (material.highlightBoxes && material.highlightBoxes.length > 0) {
  32826. //add
  32827. var boxes_highlight = shader.uniformLocations["boxes_highlight[0]"];
  32828. gl.uniformMatrix4fv(boxes_highlight, false, material.uniforms.boxes_highlight.value);
  32829. }
  32830. if (material.bigClipInBox) {
  32831. //add
  32832. shader.setUniformMatrix4("clipBoxBig_in", material.uniforms.clipBoxBig_in.value);
  32833. }
  32834. if (material.uniforms.baseHeightAreaMap.value) {
  32835. //根据模型高亮土方
  32836. var baseHeightBoundZ = shader.uniformLocations["baseHeightBoundZ"];
  32837. gl.uniform2f(baseHeightBoundZ, ...material.uniforms.baseHeightBoundZ.value.toArray());
  32838. var baseHeightBoundXY = shader.uniformLocations["baseHeightBoundXY"];
  32839. gl.uniform4f(baseHeightBoundXY, ...material.uniforms.baseHeightBoundXY.value.toArray());
  32840. }
  32841. if (material.prisms.length) {
  32842. var prismList = shader.uniformLocations["prismList[0]"];
  32843. gl.uniformMatrix3fv(prismList, false, material.uniforms.prismList.value);
  32844. var prismPoints = shader.uniformLocations["prismPoints[0]"];
  32845. gl.uniform2fv(prismPoints, material.uniforms.prismPoints.value);
  32846. }
  32847. // TODO CLIPSPHERES
  32848. if (params.clipSpheres && params.clipSpheres.length > 0) {
  32849. var clipSpheres = params.clipSpheres;
  32850. var matrices = [];
  32851. for (var clipSphere of clipSpheres) {
  32852. //let mScale = new THREE.Matrix4().makeScale(...clipSphere.scale.toArray());
  32853. //let mTranslate = new THREE.Matrix4().makeTranslation(...clipSphere.position.toArray());
  32854. //let clipToWorld = new THREE.Matrix4().multiplyMatrices(mTranslate, mScale);
  32855. var clipToWorld = clipSphere.matrixWorld;
  32856. var viewToWorld = camera.matrixWorld;
  32857. var worldToClip = clipToWorld.clone().invert();
  32858. var viewToClip = new Matrix4().multiplyMatrices(worldToClip, viewToWorld);
  32859. matrices.push(viewToClip);
  32860. }
  32861. var flattenedMatrices = [].concat(...matrices.map(matrix => matrix.elements));
  32862. var lClipSpheres = shader.uniformLocations["uClipSpheres[0]"];
  32863. gl.uniformMatrix4fv(lClipSpheres, false, flattenedMatrices);
  32864. //const lClipSpheres = shader.uniformLocations["uClipSpheres[0]"];
  32865. //gl.uniformMatrix4fv(lClipSpheres, false, material.uniforms.clipSpheres.value);
  32866. }
  32867. shader.setUniform1f("orthoMaxSize", material.uniforms.orthoMaxSize.value);
  32868. shader.setUniform1f("maxSize", material.uniforms.maxSize.value);
  32869. shader.setUniform1f("minSize", material.uniforms.minSize.value);
  32870. // uniform float uPCIndex
  32871. shader.setUniform1f("uOctreeSpacing", material.spacing);
  32872. shader.setUniform("uOctreeSize", material.uniforms.octreeSize.value);
  32873. shader.setUniform2f("elevationRange", material.elevationRange);
  32874. shader.setUniform2f("intensityRange", material.intensityRange);
  32875. shader.setUniform3f("uIntensity_gbc", [material.intensityGamma, material.intensityBrightness, material.intensityContrast]);
  32876. shader.setUniform3f("uRGB_gbc", [material.rgbGamma, material.rgbBrightness, material.rgbContrast]);
  32877. shader.setUniform1f("uTransition", material.transition);
  32878. shader.setUniform1f("wRGB", material.weightRGB);
  32879. shader.setUniform1f("wIntensity", material.weightIntensity);
  32880. shader.setUniform1f("wElevation", material.weightElevation);
  32881. shader.setUniform1f("wClassification", material.weightClassification);
  32882. shader.setUniform1f("wReturnNumber", material.weightReturnNumber);
  32883. shader.setUniform1f("wSourceID", material.weightSourceID);
  32884. shader.setUniform("backfaceCulling", material.uniforms.backfaceCulling.value);
  32885. //==========================
  32886. //gl.TEXTURE_CUBE_MAP: 34067
  32887. //gl.TEXTURE0=33984 , vnWebGLTexture.target=gl.TEXTURE_2D = 3353
  32888. /* let vnWebGLTexture = this.textures.get(material.visibleNodesTexture);//最好搬到renderNodes
  32889. if(vnWebGLTexture){
  32890. shader.setUniform1i("visibleNodes", currentTextureBindingPoint); //为何之前写的是"visibleNodesTexture",但和"visibleNodes"效果相同?可shader里只有"visibleNodes"
  32891. gl.activeTexture(gl.TEXTURE0 + currentTextureBindingPoint);
  32892. gl.bindTexture(vnWebGLTexture.target, vnWebGLTexture.id);
  32893. currentTextureBindingPoint++;
  32894. } */
  32895. var gradientTexture = this.textures.get(material.gradientTexture);
  32896. shader.setUniform1i("gradient", currentTextureBindingPoint);
  32897. gl.activeTexture(gl.TEXTURE0 + currentTextureBindingPoint);
  32898. gl.bindTexture(gradientTexture.target, gradientTexture.id);
  32899. currentTextureBindingPoint++;
  32900. var repeat = material.elevationGradientRepeat;
  32901. if (repeat === ElevationGradientRepeat.REPEAT) {
  32902. gl.texParameteri(gradientTexture.target, gl.TEXTURE_WRAP_S, gl.REPEAT);
  32903. gl.texParameteri(gradientTexture.target, gl.TEXTURE_WRAP_T, gl.REPEAT);
  32904. } else if (repeat === ElevationGradientRepeat.MIRRORED_REPEAT) {
  32905. gl.texParameteri(gradientTexture.target, gl.TEXTURE_WRAP_S, gl.MIRRORED_REPEAT);
  32906. gl.texParameteri(gradientTexture.target, gl.TEXTURE_WRAP_T, gl.MIRRORED_REPEAT);
  32907. } else {
  32908. gl.texParameteri(gradientTexture.target, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  32909. gl.texParameteri(gradientTexture.target, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  32910. }
  32911. currentTextureBindingPoint++;
  32912. var classificationTexture = this.textures.get(material.classificationTexture);
  32913. shader.setUniform1i("classificationLUT", currentTextureBindingPoint);
  32914. gl.activeTexture(gl.TEXTURE0 + currentTextureBindingPoint);
  32915. gl.bindTexture(classificationTexture.target, classificationTexture.id);
  32916. currentTextureBindingPoint++;
  32917. /* let matcapTexture = this.textures.get(material.matcapTexture);
  32918. shader.setUniform1i("matcapTextureUniform", currentTextureBindingPoint);
  32919. gl.activeTexture(gl.TEXTURE0 + currentTextureBindingPoint);
  32920. gl.bindTexture(matcapTexture.target, matcapTexture.id);
  32921. currentTextureBindingPoint++; */
  32922. var baseHeightAreaMap = material.uniforms.baseHeightAreaMap.value;
  32923. if (baseHeightAreaMap) {
  32924. //根据模型高亮土方
  32925. var map = this.textures.get(baseHeightAreaMap);
  32926. shader.setUniform1i("baseHeightAreaMap", currentTextureBindingPoint);
  32927. gl.activeTexture(gl.TEXTURE0 + currentTextureBindingPoint);
  32928. gl.bindTexture(map.target, map.id);
  32929. currentTextureBindingPoint++;
  32930. }
  32931. if (material.snapEnabled === true) {
  32932. {
  32933. var lSnapshot = shader.uniformLocations["uSnapshot[0]"];
  32934. var lSnapshotDepth = shader.uniformLocations["uSnapshotDepth[0]"];
  32935. var bindingStart = currentTextureBindingPoint;
  32936. var lSnapshotBindingPoints = new Array(5).fill(bindingStart).map((a, i) => a + i);
  32937. var lSnapshotDepthBindingPoints = new Array(5).fill(1 + Math.max(...lSnapshotBindingPoints)).map((a, i) => a + i);
  32938. currentTextureBindingPoint = 1 + Math.max(...lSnapshotDepthBindingPoints);
  32939. gl.uniform1iv(lSnapshot, lSnapshotBindingPoints);
  32940. gl.uniform1iv(lSnapshotDepth, lSnapshotDepthBindingPoints);
  32941. for (var i = 0; i < 5; i++) {
  32942. var _texture = material.uniforms["uSnapshot"].value[i];
  32943. var textureDepth = material.uniforms["uSnapshotDepth"].value[i];
  32944. if (!_texture) {
  32945. break;
  32946. }
  32947. var snapTexture = this.threeRenderer.properties.get(_texture).__webglTexture;
  32948. var snapTextureDepth = this.threeRenderer.properties.get(textureDepth).__webglTexture;
  32949. var bindingPoint = lSnapshotBindingPoints[i];
  32950. var depthBindingPoint = lSnapshotDepthBindingPoints[i];
  32951. gl.activeTexture(gl["TEXTURE".concat(bindingPoint)]);
  32952. gl.bindTexture(gl.TEXTURE_2D, snapTexture);
  32953. gl.activeTexture(gl["TEXTURE".concat(depthBindingPoint)]);
  32954. gl.bindTexture(gl.TEXTURE_2D, snapTextureDepth);
  32955. }
  32956. }
  32957. {
  32958. var _flattenedMatrices3 = [].concat(...material.uniforms.uSnapView.value.map(c => c.elements));
  32959. var lSnapView = shader.uniformLocations["uSnapView[0]"];
  32960. gl.uniformMatrix4fv(lSnapView, false, _flattenedMatrices3);
  32961. }
  32962. {
  32963. var _flattenedMatrices4 = [].concat(...material.uniforms.uSnapProj.value.map(c => c.elements));
  32964. var lSnapProj = shader.uniformLocations["uSnapProj[0]"];
  32965. gl.uniformMatrix4fv(lSnapProj, false, _flattenedMatrices4);
  32966. }
  32967. {
  32968. var _flattenedMatrices5 = [].concat(...material.uniforms.uSnapProjInv.value.map(c => c.elements));
  32969. var lSnapProjInv = shader.uniformLocations["uSnapProjInv[0]"];
  32970. gl.uniformMatrix4fv(lSnapProjInv, false, _flattenedMatrices5);
  32971. }
  32972. {
  32973. var _flattenedMatrices6 = [].concat(...material.uniforms.uSnapViewInv.value.map(c => c.elements));
  32974. var lSnapViewInv = shader.uniformLocations["uSnapViewInv[0]"];
  32975. gl.uniformMatrix4fv(lSnapViewInv, false, _flattenedMatrices6);
  32976. }
  32977. }
  32978. //=============add===========
  32979. if (material.usePanoMap) {
  32980. //为什么pointsize失效
  32981. shader.setUniform1f("progress", material.uniforms.progress.value);
  32982. shader.setUniform1f("easeInOutRatio", material.uniforms.easeInOutRatio.value);
  32983. shader.setUniform3f("pano0Position", material.uniforms.pano0Position.value.toArray());
  32984. shader.setUniform3f("pano1Position", material.uniforms.pano1Position.value.toArray());
  32985. shader.setUniform('pano0Matrix', material.uniforms.pano0Matrix.value);
  32986. shader.setUniform('pano1Matrix', material.uniforms.pano1Matrix.value);
  32987. var pano0Map = material.uniforms.pano0Map.value;
  32988. if (pano0Map) {
  32989. this.threeRenderer._textures.safeSetTextureCube(pano0Map, ++currentTextureBindingPoint);
  32990. shader.setUniform1i('pano0Map', currentTextureBindingPoint);
  32991. }
  32992. var pano1Map = material.uniforms.pano1Map.value;
  32993. if (pano1Map) {
  32994. this.threeRenderer._textures.safeSetTextureCube(pano1Map, ++currentTextureBindingPoint);
  32995. shader.setUniform1i('pano1Map', currentTextureBindingPoint);
  32996. }
  32997. //注: three.js我添加了个 _textures, safeSetTextureCube里主要就是activeTexture和bindTexture
  32998. }
  32999. }
  33000. viewer.addTimeMark('renderOctree', 'end');
  33001. params.currentTextureBindingPoint = ++currentTextureBindingPoint;
  33002. octrees.forEach(octree => {
  33003. this.renderNodes(octree, nodes || octree.visibleNodes, visibilityTextureData, camera, target, shader, params);
  33004. });
  33005. gl.activeTexture(gl.TEXTURE2);
  33006. gl.bindTexture(gl.TEXTURE_2D, null);
  33007. gl.activeTexture(gl.TEXTURE0);
  33008. //gl.bindTexture(gl.TEXTURE_2D, null); //add
  33009. //add 恢复为不透明(否则renderToCubeMap时的贴图会被渲染成高亮的颜色)
  33010. gl.disable(gl.BLEND);
  33011. gl.depthMask(true);
  33012. gl.enable(gl.DEPTH_TEST);
  33013. //DEPTH_TEST等需要恢复吗
  33014. }
  33015. render(scene, camera) {
  33016. var target = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  33017. var params = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  33018. var gl = this.gl;
  33019. // PREPARE
  33020. if (target != null) {
  33021. this.threeRenderer.setRenderTarget(target);
  33022. }
  33023. //camera.updateProjectionMatrix();
  33024. // camera.matrixWorldInverse.invert(camera.matrixWorld);
  33025. var traversalResult = this.traverse(scene);
  33026. //排序
  33027. if (params.notAdditiveBlending) {
  33028. //add
  33029. traversalResult.octrees.forEach(tree => {
  33030. if (tree.material.opacity == 1) {
  33031. tree._z = Infinity; //不透明的先渲染
  33032. } else {
  33033. var center = tree.boundCenter ? tree.boundCenter.clone() : tree.boundingBox.getCenter(tree.boundCenter).applyMatrix4(tree.matrixWorld);
  33034. center.project(camera);
  33035. tree._z = center.z;
  33036. }
  33037. });
  33038. traversalResult.octrees.sort((tree1, tree2) => {
  33039. return tree2._z - tree1._z; //降序 (-1 朝外)。 离屏幕近的后渲染
  33040. });
  33041. }
  33042. // RENDER
  33043. var mat = params.material || traversalResult.octrees[0].material;
  33044. if (Potree.settings.cloudSameMat && viewer.scene.volumes.length == 0 && mat.pointSizeType != PointSizeType.ADAPTIVE && mat.activeAttributeName != "level of detail") {
  33045. this.renderOctree(traversalResult.octrees, null, camera, target, params); //所有点云除了个别属性需要在shader中更新,其他都使用第一个点云的材质
  33046. } else for (var octree of traversalResult.octrees) {
  33047. for (var _octree of traversalResult.octrees) {
  33048. this.renderOctree(_octree, _octree.visibleNodes, camera, target, params);
  33049. }
  33050. }
  33051. //if (octree material.pointSizeType === PointSizeType.ADAPTIVE || material.activeAttributeName === "level of detail") {
  33052. // CLEANUP
  33053. gl.activeTexture(gl.TEXTURE1);
  33054. gl.bindTexture(gl.TEXTURE_2D, null);
  33055. gl.bindBuffer(gl.ARRAY_BUFFER, null);
  33056. gl.bindVertexArray(null);
  33057. this.threeRenderer.resetState();
  33058. }
  33059. }
  33060. ;
  33061. /*
  33062. 中东的链接http://indoor.popsmart.cn:8094/zdoblh-yz/?vlon=5.14&vlat=-0.13&fov=100.0&pc=true&lon=121.61136592&lat=29.87855579&z=16.577
  33063. geometry: 有的attributes: 属性是:
  33064. classification:
  33065. color:
  33066. indices:
  33067. normal:
  33068. position:
  33069. 最好有个spacing
  33070. */
  33071. /* const mapHeight = -1000;//要比点云低。最低
  33072. const cameraHeight = 1000; //最高 */
  33073. var panosHeight = config$1.map.mapHeight + 100; //要比点云低 (marker)
  33074. var cursorHeight = 0; //比地图高就行
  33075. var routeLayerHeight = config$1.map.mapHeight + 105;
  33076. var texLoader$5 = new TextureLoader();
  33077. var planeGeo$1 = new PlaneBufferGeometry(1, 1);
  33078. var markerSize = 1;
  33079. var initCameraFeildWidth = 50;
  33080. var panoMarkerMats;
  33081. class MapViewer extends ViewerBase {
  33082. constructor(dom) {
  33083. super(dom, {
  33084. clearColor: Potree.config.mapBG,
  33085. name: 'mapViewer',
  33086. antialias: true
  33087. });
  33088. this.visible = true;
  33089. this.initScene();
  33090. this.needRender_ = false;
  33091. this.mapLayer = new MapLayer(this, this.viewports[0]);
  33092. this.scene.add(this.mapLayer.sceneGroup);
  33093. this.mapLayer.sceneGroup.position.setZ(Potree.config.map.mapHeight);
  33094. this.mapRatio = 0.5;
  33095. this.splitDir = 'leftRight';
  33096. this.renderMeasure = false;
  33097. //因context的preserveDrawingBuffer为false之后,canvas渲染多个viewport时会自动clear,所以若不渲染就会是空的。所以没有变化时就直接拷贝buffer好了。
  33098. this.copyPass = new ShaderPass(CopyShader);
  33099. this.copyBuffer = new WebGLRenderTarget(100, 100, {
  33100. minFilter: LinearFilter,
  33101. magFilter: LinearFilter,
  33102. format: RGBAFormat,
  33103. stencilBuffer: false
  33104. });
  33105. viewer.addEventListener("camera_changed", e => {
  33106. var needUpdateCursor;
  33107. if (e.viewport == viewer.mainViewport) {
  33108. needUpdateCursor = true;
  33109. } else if (e.viewport == this.viewports[0]) {
  33110. //attachedToViewer
  33111. needUpdateCursor = true;
  33112. this.mapChanged = true;
  33113. this.updateWhenAtViewer();
  33114. e.changeInfo.projectionChanged && this.setViewLimit();
  33115. }
  33116. needUpdateCursor && this.updateCursor();
  33117. });
  33118. this.addEventListener("camera_changed", e => {
  33119. e.changeInfo.projectionChanged && this.setViewLimit();
  33120. });
  33121. //viewer.addEventListener("global_mousemove", this.updateWhenAtViewer.bind(this)) //鼠标移动时reticule也动,所以直接就needRender
  33122. /* viewer.reticule.addEventListener('update',(e)=>{
  33123. if(this.attachedToViewer)this.needRender = true
  33124. }) */
  33125. viewer.scene.addEventListener("360_images_added", this.addPanos.bind(this));
  33126. viewer.addEventListener("loadPointCloudDone", this.initProjection.bind(this));
  33127. this.addEventListener('global_click', e => {
  33128. if (!e.isTouch && e.button != MOUSE.LEFT) return;
  33129. this.updateClosestPano(e.intersect);
  33130. });
  33131. this.addEventListener('add', e => {
  33132. //添加其他mesh
  33133. this.scene.add(e.object);
  33134. if (e.name == 'route') {
  33135. e.object.position.z = routeLayerHeight;
  33136. }
  33137. Potree.Utils.setObjectLayers(e.object, 'mapObjects');
  33138. });
  33139. viewer.addEventListener('allLoaded', () => {
  33140. this.setViewLimit('standard');
  33141. });
  33142. if (!Potree.settings.isOfficial) {
  33143. var domRoot = viewer.renderer.domElement.parentElement;
  33144. var elAttach = $("<input type='button' value='map绑定'></input>");
  33145. elAttach.css({
  33146. position: "absolute",
  33147. right: '80%',
  33148. bottom: '20px',
  33149. zIndex: "10000",
  33150. fontSize: '1em',
  33151. color: "black",
  33152. background: 'rgba(255,255,255,0.8)'
  33153. });
  33154. var state = false;
  33155. elAttach.on("click", () => {
  33156. state = !state;
  33157. this.attachToMainViewer(state, 'measure');
  33158. elAttach.val(state ? 'map分离' : 'map绑定');
  33159. });
  33160. domRoot.appendChild(elAttach[0]);
  33161. }
  33162. }
  33163. get needRender() {
  33164. return this.needRender_;
  33165. }
  33166. set needRender(n) {
  33167. this.needRender_ = n;
  33168. n && (this.viewports[0].needRender = true); //使attachedToViewer时在renderDefault中可渲染
  33169. }
  33170. get mapChanged() {
  33171. return this.mapChanged_;
  33172. }
  33173. set mapChanged(c) {
  33174. //镜头移动、地图内容改变都会为true
  33175. this.mapChanged_ = c;
  33176. c && (this.needRender = true);
  33177. }
  33178. waitLoadDone(callback) {
  33179. //确保加载完后执行
  33180. var timer; //等待一段时间看有没有新加载的tile,如果超过这个时间没有就不等了,算加载结束
  33181. var pauseCountDown = () => {
  33182. //重新等待加载结束,中断倒计时
  33183. clearTimeout(timer);
  33184. //console.log('pauseCountDown')
  33185. };
  33186. var freshCountDown = () => {
  33187. //刷新倒计时
  33188. //console.log('freshCountDown')
  33189. clearTimeout(timer);
  33190. timer = setTimeout(() => {
  33191. this.mapLayer.removeEventListener('loadDone', freshCountDown);
  33192. this.mapLayer.removeEventListener('startLoad', pauseCountDown);
  33193. callback();
  33194. }, document.hidden ? 5000 : 500);
  33195. };
  33196. this.mapLayer.addEventListener('loadDone', freshCountDown);
  33197. this.mapLayer.addEventListener('startLoad', pauseCountDown);
  33198. if (this.mapLayer.loadingInProgress == 0) {
  33199. freshCountDown();
  33200. }
  33201. }
  33202. addListener(images360) {
  33203. images360.addEventListener('flyToPano', e => {
  33204. var toPano = e.toPano;
  33205. if (toPano.dontMoveMap) return;
  33206. /* transitions.start(lerp.vector(this.view.position, toPano.pano.position.clone().setZ(cameraHeight),
  33207. (pos, progress)=>{
  33208. }), toPano.duration, null, 0, easing[toPano.easeName] ); */
  33209. var boundSize; // = new THREE.Vector2(10,10)
  33210. this.moveTo(toPano.pano.position.clone().setZ(Potree.config.map.cameraHeight), boundSize, toPano.duration, null, toPano.easeName);
  33211. });
  33212. }
  33213. initProjection() {
  33214. this.started = true;
  33215. this.mapLayer.initProjection();
  33216. }
  33217. initScene() {
  33218. var w = initCameraFeildWidth;
  33219. var width = this.renderArea.clientWidth;
  33220. var height = this.renderArea.clientHeight;
  33221. //let aspect = width / height
  33222. this.camera = new OrthographicCamera(-width / 2, width / 2, height / 2, -height / 2 /* -w/2, w/2, w/2/aspect, -w/2/aspect */, 0.01, 10000);
  33223. this.camera.zoom = width / w; //zoom越大视野越小
  33224. //this.camera.position.set(0,0,10);
  33225. this.camera.up.set(0, 0, 1);
  33226. //this.camera.lookAt(new THREE.Vector3())
  33227. //this.camera.updateMatrixWorld()
  33228. this.view = new ExtendView();
  33229. this.view.position.set(0, 0, Potree.config.map.cameraHeight);
  33230. this.view.lookAt(0, 0, 0);
  33231. var viewport = new Viewport(this.view, this.camera, {
  33232. left: 0,
  33233. bottom: 0,
  33234. width: 1,
  33235. height: 1,
  33236. name: 'mapViewport'
  33237. });
  33238. viewport.axis = ["x", "y"];
  33239. viewport.axisSign = [1, 1];
  33240. viewport.noPointcloud = true; //不要渲染点云
  33241. viewport.render = this.render.bind(this); //标志给mainView渲染
  33242. //viewport.unableDepth = true //depthBasicMaterial等在此viewport中不开启depth
  33243. viewport.addEventListener('resize', () => {
  33244. this.copyBuffer.setSize(viewport.resolution2.x, viewport.resolution2.y);
  33245. //this.cloudBuffer && this.cloudBuffer.setSize(viewport.resolution2.x, viewport.resolution2.y)
  33246. });
  33247. this.viewports = [viewport];
  33248. this.controls = new FirstPersonControls(this, this.viewports[0]);
  33249. this.controls.setEnable(true);
  33250. this.scene = new Scene();
  33251. this.inputHandler = new InputHandler(this, this.scene);
  33252. this.inputHandler.name = 'mapInputHandler';
  33253. //this.inputHandler.addInputListener(this.controls);
  33254. this.inputHandler.registerInteractiveScene(this.scene); //interactiveScenes
  33255. this.viewports[0].interactiveScenes = this.inputHandler.interactiveScenes; //供viewer的inputHandler使用
  33256. var cursor = new Mesh(planeGeo$1, new MeshBasicMaterial({
  33257. transparent: true,
  33258. opacity: 0.9,
  33259. depthTest: false,
  33260. //防止透明冲突
  33261. map: texLoader$5.load(Potree.resourcePath + '/textures/pic_location128.png')
  33262. }));
  33263. cursor.position.set(0, 0, cursorHeight);
  33264. this.cursor = cursor;
  33265. this.scene.add(cursor);
  33266. Potree.Utils.setObjectLayers(this.scene, 'mapObjects');
  33267. }
  33268. setViewLimit(state) {
  33269. //设置边界,当编辑空间模型等时要解禁
  33270. if (!state) state = this.limitBoundState;
  33271. if (!state) return;
  33272. this.limitBoundState = state;
  33273. var setting = Potree.config.OrthoCameraLimit[state];
  33274. if (setting) {
  33275. this.camera.zoomLimit = $.extend({}, setting.zoom);
  33276. var lonlatCenter = viewer.transform.lonlatToLocal.inverse([0, 0]);
  33277. var minY = viewer.transform.lonlatToLocal.forward([lonlatCenter[0], -90 + setting.latPad])[1]; //屏幕边界的bound
  33278. var maxY = viewer.transform.lonlatToLocal.forward([lonlatCenter[0], 90 - setting.latPad])[1];
  33279. /*this.view.limitBound = new THREE.Box3(
  33280. new THREE.Vector3(setting.xBound[0], minY, Potree.config.map.cameraHeight),
  33281. new THREE.Vector3(setting.xBound[1], maxY, 1 / 0)
  33282. ) */
  33283. var halfHeight = this.viewports[0].resolution.y / 2 / this.camera.zoom; //屏幕所占高度的一半
  33284. var halfWidth = this.viewports[0].resolution.x / 2 / this.camera.zoom;
  33285. this.view.limitBound = new Box3(new Vector3(setting.xBound[0] + halfWidth, minY + halfHeight, Potree.config.map.cameraHeight), new Vector3(setting.xBound[1] - halfWidth, maxY - halfHeight, 1 / 0));
  33286. } else {
  33287. this.view.limitBound = null;
  33288. this.camera.zoomLimit = null;
  33289. }
  33290. }
  33291. updateCursor() {
  33292. //console.log('pos', viewer.mainViewport.camera.position.toArray() )
  33293. var scale = math.getScaleForConstantSize({
  33294. //规定下最小最大像素
  33295. minSize: 80,
  33296. maxSize: 200,
  33297. nearBound: initCameraFeildWidth * 0.1,
  33298. farBound: initCameraFeildWidth * 2,
  33299. camera: this.camera,
  33300. position: this.cursor.getWorldPosition(new Vector3()),
  33301. resolution: this.viewports[0].resolution //2
  33302. });
  33303. this.cursor.scale.set(scale, scale, scale); //当地图缩放时
  33304. this.cursor.position.copy(viewer.mainViewport.camera.position).setZ(cursorHeight); //当场景镜头旋转移动时
  33305. this.cursor.rotation.z = viewer.mainViewport.view.yaw;
  33306. this.needRender = true;
  33307. }
  33308. addPanos(e) {
  33309. var panosGroup = new Object3D();
  33310. panosGroup.name = 'markers';
  33311. panoMarkerMats = {
  33312. default: new MeshBasicMaterial({
  33313. transparent: true,
  33314. opacity: 0.5,
  33315. map: texLoader$5.load(Potree.resourcePath + '/textures/map_marker.png')
  33316. }),
  33317. selected: new MeshBasicMaterial({
  33318. transparent: true,
  33319. opacity: 1,
  33320. map: texLoader$5.load(Potree.resourcePath + '/textures/map_marker.png')
  33321. })
  33322. };
  33323. e.images.panos.forEach(pano => {
  33324. pano.mapMarker = new Mesh(planeGeo$1, panoMarkerMats.default);
  33325. pano.mapMarker.position.copy(pano.position).setZ(0);
  33326. pano.mapMarker.scale.set(markerSize, markerSize, markerSize);
  33327. pano.mapMarker.name = 'mapMarker';
  33328. panosGroup.add(pano.mapMarker);
  33329. var mouseover = e => {
  33330. if (!e.byMap) {
  33331. pano.mapMarker.material = panoMarkerMats.selected;
  33332. if (!e.byMainView) pano.dispatchEvent({
  33333. type: "hoverOn",
  33334. byMap: true
  33335. });
  33336. this.needRender = true;
  33337. }
  33338. };
  33339. var mouseleave = e => {
  33340. if (!e.byMap) {
  33341. pano.mapMarker.material = panoMarkerMats.default;
  33342. if (!e.byMainView) pano.dispatchEvent({
  33343. type: "hoverOff",
  33344. byMap: true
  33345. });
  33346. this.needRender = true;
  33347. }
  33348. };
  33349. pano.mapMarker.addEventListener('mouseover', mouseover);
  33350. pano.mapMarker.addEventListener('mouseleave', mouseleave);
  33351. pano.addEventListener('hoverOn', mouseover);
  33352. pano.addEventListener('hoverOff', mouseleave);
  33353. var onclick = e => {
  33354. viewer.images360.flyToPano(pano);
  33355. };
  33356. pano.mapMarker.addEventListener('click', onclick);
  33357. pano.addEventListener('isVisible', e => {
  33358. //是否显示该点的mesh(不显示也能走)
  33359. //console.log('panoMarker isVisible', pano.id, e.visible)
  33360. Potree.Utils.updateVisible(pano.mapMarker, 'panoVisible', e.visible);
  33361. this.needRender = true;
  33362. });
  33363. pano.addEventListener('rePos', e => {
  33364. pano.mapMarker.position.copy(pano.position).setZ(0);
  33365. });
  33366. });
  33367. this.scene.add(panosGroup);
  33368. panosGroup.position.z = panosHeight;
  33369. this.panosGroup = panosGroup;
  33370. Potree.Utils.setObjectLayers(panosGroup, 'mapObjects');
  33371. /* e.images.on('markersDisplayChange', (show)=>{
  33372. panosGroup.visible = show
  33373. this.needRender = true
  33374. }) */
  33375. //-------
  33376. //this.fitPanosToViewport()
  33377. this.initFitView();
  33378. }
  33379. updateClosestPano(intersect) {
  33380. if (viewer.images360.flying) return;
  33381. intersect = intersect && intersect.orthoIntersect;
  33382. if (!intersect) return;
  33383. intersect = intersect.clone().setZ(0);
  33384. var minDis = 20; //距离鼠标不能太远
  33385. var filterFuncs = [Images360.filters.isEnabled(), Images360.filters.isVisible(),
  33386. //只走显示的点,否则会走到别的层
  33387. pano => {
  33388. return pano.position.clone().setZ(0).distanceTo(intersect) < minDis;
  33389. }];
  33390. var pano = Common.find(viewer.images360.panos, filterFuncs, [Images360.sortFunctions.floorDisSquaredToPoint(intersect)]);
  33391. if (pano && pano != viewer.images360.currentPano) {
  33392. viewer.images360.flyToPano(pano);
  33393. }
  33394. }
  33395. fitPanosToViewport() {
  33396. //使所有漫游点占满viewport
  33397. //var w = viewer.bound.boundSize.x;
  33398. var boundSize = viewer.images360.bound.size.clone().multiplyScalar(1.1);
  33399. boundSize.max(new Vector3(4, 4, 4));
  33400. var endPosition = viewer.images360.bound.center.clone();
  33401. this.moveTo(endPosition, boundSize, 0);
  33402. }
  33403. fitToPointcloud(pointcloud) {
  33404. var duration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 400;
  33405. var boundSize = pointcloud.bound.getSize(new Vector3()); /* .multiplyScalar(1.1); */
  33406. boundSize.max(new Vector3(4, 4, 4));
  33407. var endPosition = pointcloud.bound.getCenter(new Vector3());
  33408. this.moveTo(endPosition, boundSize, duration); //给点duration去变化 否则地图放大后所占的还是很小
  33409. }
  33410. initFitView() {
  33411. var dis = 5,
  33412. px = 70; //地图上px像素长度代表的距离为dis //px是手动缩放到5m后发现是这个长度
  33413. var zoom = px / dis;
  33414. this.camera.zoom = zoom;
  33415. this.moveTo(viewer.images360.position /* viewer.images360.bound.center */);
  33416. this.camera.updateProjectionMatrix();
  33417. }
  33418. fitToDatasets(datasets) {
  33419. var bound = new Box3();
  33420. datasets.forEach(e => bound.union(e.bound));
  33421. var center = bound.getCenter(new Vector3());
  33422. var size = bound.getSize(new Vector3());
  33423. this.moveTo(center, size, 200); //给duration是为了顺应视口大小改变,缓冲
  33424. }
  33425. moveTo(endPosition, boundSize) {
  33426. var duration = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  33427. var margin = arguments.length > 3 ? arguments[3] : undefined;
  33428. var easeName = arguments.length > 4 ? arguments[4] : undefined;
  33429. var callback = arguments.length > 5 ? arguments[5] : undefined;
  33430. //前两个参数有xy即可
  33431. endPosition = new Vector3(endPosition.x, endPosition.y, Potree.config.map.cameraHeight);
  33432. this.view.moveOrthoCamera(this.viewports[0], {
  33433. endPosition,
  33434. boundSize,
  33435. margin,
  33436. callback
  33437. }, duration, easeName);
  33438. /* let endZoom, startZoom = this.camera.zoom
  33439. //修改相机为bound中心,这样能看到全部(宽度范围内)
  33440. this.view.setView({ position:endPosition, duration,
  33441. callback:()=>{//done
  33442. },
  33443. onUpdate:(progress)=>{
  33444. if(boundSize){
  33445. let aspect = boundSize.x / boundSize.y
  33446. let w, h;
  33447. if(this.camera.aspect > aspect){//视野更宽则用bound的纵向来决定
  33448. h = boundSize.y
  33449. //w = h * this.camera.aspect
  33450. endZoom = this.viewports[0].resolution.y / h
  33451. }else{
  33452. w = boundSize.x;
  33453. //h = w / this.camera.aspect
  33454. endZoom = this.viewports[0].resolution.x / w
  33455. }
  33456. //onUpdate时更新endzoom是因为画布大小可能更改
  33457. this.camera.zoom = endZoom * progress + startZoom * (1 - progress)
  33458. this.camera.updateProjectionMatrix()
  33459. }
  33460. },
  33461. Easing:easeName
  33462. }) */
  33463. }
  33464. updateWhenAtViewer(e) {
  33465. //两个触发来源: 1 camera_changed时 2 mapLayer.needUpdate时。 render在viewer中执行
  33466. if (this.attachedToViewer) {
  33467. if (this.started) this.mapLayer.update();
  33468. this.needRender = true;
  33469. }
  33470. }
  33471. update(delta, areaSize) {
  33472. if (!this.visible && !this.attachedToViewer) return;
  33473. if (this.attachedToViewer) {
  33474. if (this.mapLayer.needUpdate) {
  33475. this.updateWhenAtViewer();
  33476. }
  33477. return;
  33478. }
  33479. this.updateScreenSize();
  33480. this.controls.update(delta);
  33481. this.view.applyToCamera(this.camera);
  33482. var changed = this.cameraChanged();
  33483. if (this.started && (changed || this.mapLayer.needUpdate)) this.mapLayer.update();
  33484. if (changed /*|| || this.needRender */) {
  33485. /* this.dispatchEvent({
  33486. type: "camera_changed",
  33487. camera: this.camera,
  33488. viewport : this.viewports[0]
  33489. }) */
  33490. this.mapChanged = true;
  33491. this.needRender = true;
  33492. this.updateCursor(); //更改大小
  33493. }
  33494. this.render();
  33495. }
  33496. attachToMainViewer(state, desc) {
  33497. var mapRatio = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0.5;
  33498. var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  33499. //转移到viewer中。测量时展示or截图需要
  33500. if (!Potree.settings.isOfficial) this.renderArea.style.display = state ? 'none' : 'block';
  33501. if (state) {
  33502. this.enabledOld = this.enabled;
  33503. this.enabled = true;
  33504. if (mapRatio != 'dontSet') {
  33505. this.changeSplitScreenDir(options.dir, mapRatio);
  33506. if (this.attachedToViewer) {
  33507. //this.fitPanosToViewport()
  33508. viewer.updateScreenSize({
  33509. forceUpdateSize: true
  33510. });
  33511. return;
  33512. }
  33513. viewer.viewports = [viewer.mainViewport, viewer.mapViewer.viewports[0]]; //因为mainViewer的相机变化会触发map的变化,所以先渲染mainViewer
  33514. }
  33515. if (desc == 'measure') this.inputHandler.registerInteractiveScene(viewer.measuringTool.scene); //虽然用的是viewer的inputHandler,但借用了this.inputHandler的interactiveScenes
  33516. else if (desc == 'split4Screens') {
  33517. this.inputHandler.registerInteractiveScene(viewer.scene.scene);
  33518. }
  33519. } else {
  33520. if (!this.attachedToViewer) return;
  33521. viewer.mainViewport.left = 0;
  33522. viewer.mainViewport.bottom = 0;
  33523. viewer.mainViewport.width = 1;
  33524. viewer.mainViewport.height = 1;
  33525. this.viewports[0].width = 1;
  33526. this.viewports[0].bottom = 0;
  33527. this.viewports[0].height = 1;
  33528. this.viewports[0].left = 0;
  33529. this.renderMeasure || this.inputHandler.unregisterInteractiveScene(viewer.measuringTool.scene);
  33530. this.inputHandler.unregisterInteractiveScene(viewer.scene.scene);
  33531. viewer.viewports = [viewer.mainViewport];
  33532. this.updateScreenSize({
  33533. forceUpdateSize: true
  33534. }); //更新相机projectionMatrix
  33535. }
  33536. //if(desc == 'measure')this.renderMeasure = state
  33537. this.attachedToViewer = state;
  33538. viewer.updateScreenSize({
  33539. forceUpdateSize: true
  33540. });
  33541. //mapRatio != 'dontSet' && !options.dontFit && this.moveTo(...)//要写在updateScreenSize后面,因为要根据视图大小来fit
  33542. if (options.moveToCurrentPos) {
  33543. var boundSize = new Vector2(10, 10);
  33544. var duration = 1000;
  33545. this.moveTo(viewer.images360.position.clone(), boundSize, duration);
  33546. }
  33547. this.needRender = true;
  33548. }
  33549. setDrawMeasure(draw) {
  33550. this.renderMeasure = !!draw;
  33551. if (draw) {
  33552. this.inputHandler.registerInteractiveScene(viewer.measuringTool.scene);
  33553. } else {
  33554. this.inputHandler.unregisterInteractiveScene(viewer.measuringTool.scene);
  33555. }
  33556. }
  33557. changeSplitScreenDir(dir, mapRatio) {
  33558. //左右 | 上下
  33559. //if(!dir || dir == this.dir)return
  33560. if (dir) this.splitDir = dir;
  33561. this.updateSplitSize(mapRatio);
  33562. /* if(this.attachedToViewer){ //如果已经分屏了,中途修改方向的话……
  33563. this.updateSplitSize()
  33564. } */
  33565. }
  33566. updateSplitSize(mapRatio) {
  33567. if (mapRatio != void 0) this.mapRatio = mapRatio;
  33568. //console.log(this.mapRatio)
  33569. if (this.splitDir == 'leftRight') {
  33570. //地图在左方
  33571. viewer.mainViewport.left = this.mapRatio;
  33572. viewer.mainViewport.width = 1 - this.mapRatio;
  33573. this.viewports[0].width = this.mapRatio;
  33574. viewer.mainViewport.bottom = this.viewports[0].bottom = 0;
  33575. viewer.mainViewport.height = this.viewports[0].height = 1;
  33576. } else if (this.splitDir == 'upDown') {
  33577. //地图在下方
  33578. viewer.mainViewport.bottom = this.mapRatio;
  33579. viewer.mainViewport.height = 1 - this.mapRatio;
  33580. this.viewports[0].height = this.mapRatio;
  33581. viewer.mainViewport.left = this.viewports[0].left = 0;
  33582. viewer.mainViewport.width = this.viewports[0].width = 1;
  33583. }
  33584. if (this.attachedToViewer) {
  33585. viewer.updateScreenSize({
  33586. forceUpdateSize: true
  33587. });
  33588. }
  33589. }
  33590. render1() {
  33591. var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  33592. //viewer的preserveDrawingBuffer为false时的版本
  33593. var needCopy, waitCopy;
  33594. if (!this.visible && !this.attachedToViewer || !this.needRender && !params.force) {
  33595. if (this.attachedToViewer) {
  33596. needCopy = true;
  33597. } else {
  33598. return;
  33599. }
  33600. }
  33601. waitCopy = this.attachedToViewer && this.needRender && !params.force; //是否写入到copyBuffer。双屏时,若needRender就拷贝到copyBuffer中,双屏时就直接使用copyBuffer。 四屏时因渲染点云会每帧都渲染,所以不需要缓存。
  33602. var renderer = params.renderer || this.renderer;
  33603. if (waitCopy) {
  33604. this.copyBuffer.setSize(params.viewport.resolution2.x, params.viewport.resolution2.y);
  33605. renderer.setRenderTarget(this.copyBuffer);
  33606. } else if (params.target) {
  33607. renderer.setRenderTarget(params.target);
  33608. }
  33609. /* if(params.resize){
  33610. this.emitResizeMsg(new THREE.Vector2(params.width,params.height, viewport:params.viewport))
  33611. } */
  33612. params.clear ? params.clear() : renderer.clear();
  33613. if (!needCopy || waitCopy) {
  33614. //重绘
  33615. viewer.dispatchEvent({
  33616. type: "render.begin",
  33617. viewer: this,
  33618. viewport: this.viewports[0],
  33619. params
  33620. });
  33621. Potree.Utils.setCameraLayers(this.camera, ['map', 'mapObjects', 'bothMapAndScene']);
  33622. if (this.mapGradientBG) {
  33623. //渲染背景
  33624. viewer.scene.cameraBG.layers.set(Potree.config.renderLayers.bg);
  33625. renderer.render(viewer.scene.scene, viewer.scene.cameraBG);
  33626. }
  33627. renderer.render(this.scene, this.camera);
  33628. renderer.render(viewer.scene.scene, this.camera);
  33629. //测量线等
  33630. //params.renderOverlay && params.renderOverlay( $.extend({}, params, { isMap:true }))
  33631. renderer.setRenderTarget(params.target || null);
  33632. }
  33633. if (needCopy || waitCopy) {
  33634. //使用缓存 ----当viewer的preserveDrawingBuffer为false的话,使用buffer
  33635. this.copyPass.render(null, null, null, renderer, params.target || null, this.copyBuffer);
  33636. }
  33637. this.needRender = false;
  33638. return true;
  33639. }
  33640. clear(params) {
  33641. if (this.transparentBG) {
  33642. this.renderer.setClearColor(0x000000, 0);
  33643. } else {
  33644. this.renderer.setClearColor(Potree.config.mapBG, 1);
  33645. }
  33646. (params.renderer || this.renderer).clear();
  33647. }
  33648. //拆成两次渲染,一个地图一个其他物体,且地图渲染后保存在buffer中,只有当地图变化后才重渲染。
  33649. render() {
  33650. var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  33651. if (!this.visible && !this.attachedToViewer || !this.needRender && !params.force) {
  33652. //注意:mapViewer.needRender的权重高于它的viewport的needRender,也就是说,当attachedToViewer时,viewer即使needRender, mapViewer也不一定会渲染。
  33653. return;
  33654. }
  33655. viewer.addTimeMark('mapRender', 'start');
  33656. var renderer = params.renderer || this.renderer;
  33657. if (this.mapChanged) {
  33658. //渲染地图背景
  33659. renderer.setRenderTarget(this.copyBuffer);
  33660. params.clear ? params.clear(params) : this.clear(params);
  33661. if (this.mapGradientBG) {
  33662. //渲染背景
  33663. viewer.scene.cameraBG.layers.set(Potree.config.renderLayers.bg);
  33664. renderer.render(viewer.scene.scene, viewer.scene.cameraBG);
  33665. }
  33666. Potree.Utils.setCameraLayers(this.camera, ['map']);
  33667. renderer.render(this.scene, this.camera);
  33668. params.renderBG && params.renderBG(this.viewports[0]);
  33669. this.mapChanged = false;
  33670. renderer.setRenderTarget(params.target || null);
  33671. }
  33672. params.clear ? params.clear(params) : this.clear(params);
  33673. this.copyPass.render(null, null, null, renderer, params.target || null, this.copyBuffer); //拷贝地图背景
  33674. renderer.clearDepth(); //防止地图遮挡其他物体
  33675. //绘制其他物体
  33676. Potree.Utils.setCameraLayers(this.camera, ['mapObjects', 'bothMapAndScene', 'light']);
  33677. viewer.dispatchEvent({
  33678. type: "render.begin",
  33679. viewer: this,
  33680. viewport: this.viewports[0],
  33681. params
  33682. });
  33683. this.attachedToViewer || this.renderCloud || renderer.render(viewer.scene.scene, this.camera); //类同renderOverlay
  33684. renderer.render(this.scene, this.camera);
  33685. if (!this.attachedToViewer && this.renderMeasure) {
  33686. //在未attach到主页面时也要渲染测量线
  33687. viewer.dispatchEvent({
  33688. type: "render.pass.perspective_overlay",
  33689. camera: this.camera,
  33690. viewport: this.viewports[0],
  33691. renderer
  33692. });
  33693. }
  33694. renderer.setRenderTarget(null);
  33695. this.needRender = false;
  33696. viewer.addTimeMark('mapRender', 'end');
  33697. return true;
  33698. }
  33699. renderOverlay() {
  33700. //偶尔需要绘制测量线
  33701. viewer.renderOverlay({
  33702. camera: this.camera,
  33703. viewport: this.viewports[0],
  33704. renderer: this.renderer
  33705. });
  33706. }
  33707. setRenderCloud() {
  33708. var _this = this;
  33709. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  33710. //使利用viewer的渲染来渲染点云 (如果点云不旋转其实也可以贴floorplan……)
  33711. this.renderPointcloud = true;
  33712. this.viewports[0].noPointcloud = false;
  33713. this.viewports[0].background = 'none'; //防止renderBG绘制skybox
  33714. var oldMapRender = this.render,
  33715. oldMapClear = this.clear;
  33716. var pRenderer = new Renderer$1(this.renderer); //必须重新创建一个点云渲染器,否则和旧的webgl冲突
  33717. this.render = function () {
  33718. var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  33719. if (!_this.visible && !_this.attachedToViewer || !_this.needRender && !params.force) {
  33720. //注意:mapViewer.needRender的权重高于它的viewport的needRender,也就是说,当attachedToViewer时,viewer即使needRender, mapViewer也不一定会渲染。
  33721. return;
  33722. }
  33723. if (!options.renderMeasure) {
  33724. viewer.scene.measurements.forEach(e => Potree.Utils.updateVisible(e, 'renderCloudAtMap', false));
  33725. }
  33726. viewer.renderDefault({
  33727. viewports: _this.viewports,
  33728. camera: _this.camera,
  33729. renderer: _this.renderer,
  33730. render: oldMapRender,
  33731. clear: oldMapClear,
  33732. pRenderer
  33733. });
  33734. viewer.scene.measurements.forEach(e => Potree.Utils.updateVisible(e, 'renderCloudAtMap', true));
  33735. };
  33736. }
  33737. //本来想用mainViewer渲染点云在target上再贴过来的,但是失败了,可能因为不同的renderer不能互通。
  33738. /* setRenderCloud(){
  33739. this.renderCloud = true
  33740. this.cloudBuffer = new THREE.WebGLRenderTarget( 300, 200 , {
  33741. minFilter: THREE.LinearFilter,
  33742. magFilter: THREE.LinearFilter,
  33743. format: THREE.RGBAFormat,
  33744. //stencilBuffer: false,
  33745. });
  33746. } */
  33747. }
  33748. /*
  33749. 渲染顺序:
  33750. 地图
  33751. 背景Overlay
  33752. 地图scene的物体,如cursor、 marker
  33753. 点云(如果有)
  33754. overlay,两层:第一层:viewer的scene中bothMapAndScene的如reticule. 第二层:如测量线(attachToMainViewer时才渲染)
  33755. */
  33756. //本地调试地图白屏是因为代码自动更新了 但没刷新
  33757. class U {
  33758. static toVector3(v, offset) {
  33759. return new Vector3().fromArray(v, offset || 0);
  33760. }
  33761. static toBox3(b) {
  33762. return new Box3(U.toVector3(b), U.toVector3(b, 3));
  33763. }
  33764. static findDim(schema, name) {
  33765. var dim = schema.find(dim => dim.name == name);
  33766. if (!dim) throw new Error('Failed to find ' + name + ' in schema');
  33767. return dim;
  33768. }
  33769. static sphereFrom(b) {
  33770. return b.getBoundingSphere(new Sphere());
  33771. }
  33772. }
  33773. ;
  33774. class PointCloudEptGeometry {
  33775. constructor(url, info) {
  33776. var version = info.version;
  33777. var schema = info.schema;
  33778. var bounds = info.bounds;
  33779. var boundsConforming = info.boundsConforming;
  33780. var xyz = [U.findDim(schema, 'X'), U.findDim(schema, 'Y'), U.findDim(schema, 'Z')];
  33781. var scale = xyz.map(d => d.scale || 1);
  33782. var offset = xyz.map(d => d.offset || 0);
  33783. this.eptScale = U.toVector3(scale);
  33784. this.eptOffset = U.toVector3(offset);
  33785. this.url = url;
  33786. this.info = info;
  33787. this.type = 'ept';
  33788. this.schema = schema;
  33789. this.span = info.span || info.ticks;
  33790. this.boundingBox = U.toBox3(bounds);
  33791. this.tightBoundingBox = U.toBox3(boundsConforming);
  33792. this.offset = U.toVector3([0, 0, 0]);
  33793. this.boundingSphere = U.sphereFrom(this.boundingBox);
  33794. this.tightBoundingSphere = U.sphereFrom(this.tightBoundingBox);
  33795. this.version = new Potree.Version('1.7');
  33796. this.projection = null;
  33797. this.fallbackProjection = null;
  33798. if (info.srs && info.srs.horizontal) {
  33799. this.projection = info.srs.authority + ':' + info.srs.horizontal;
  33800. }
  33801. if (info.srs.wkt) {
  33802. if (!this.projection) this.projection = info.srs.wkt;else this.fallbackProjection = info.srs.wkt;
  33803. }
  33804. {
  33805. // TODO [mschuetz]: named projections that proj4 can't handle seem to cause problems.
  33806. // remove them for now
  33807. try {
  33808. proj4(this.projection);
  33809. } catch (e) {
  33810. this.projection = null;
  33811. }
  33812. }
  33813. {
  33814. var attributes = new PointAttributes();
  33815. attributes.add(PointAttribute.POSITION_CARTESIAN);
  33816. attributes.add(new PointAttribute("rgba", PointAttributeTypes.DATA_TYPE_UINT8, 4));
  33817. attributes.add(new PointAttribute("intensity", PointAttributeTypes.DATA_TYPE_UINT16, 1));
  33818. attributes.add(new PointAttribute("classification", PointAttributeTypes.DATA_TYPE_UINT8, 1));
  33819. attributes.add(new PointAttribute("gps-time", PointAttributeTypes.DATA_TYPE_DOUBLE, 1));
  33820. attributes.add(new PointAttribute("returnNumber", PointAttributeTypes.DATA_TYPE_UINT8, 1));
  33821. attributes.add(new PointAttribute("number of returns", PointAttributeTypes.DATA_TYPE_UINT8, 1));
  33822. attributes.add(new PointAttribute("return number", PointAttributeTypes.DATA_TYPE_UINT8, 1));
  33823. attributes.add(new PointAttribute("source id", PointAttributeTypes.DATA_TYPE_UINT16, 1));
  33824. this.pointAttributes = attributes;
  33825. }
  33826. this.spacing = (this.boundingBox.max.x - this.boundingBox.min.x) / this.span;
  33827. var hierarchyType = info.hierarchyType || 'json';
  33828. var dataType = info.dataType;
  33829. if (dataType == 'laszip') {
  33830. this.loader = new Potree.EptLaszipLoader();
  33831. } else if (dataType == 'binary') {
  33832. this.loader = new Potree.EptBinaryLoader();
  33833. } else if (dataType == 'zstandard') {
  33834. this.loader = new Potree.EptZstandardLoader();
  33835. } else {
  33836. throw new Error('Could not read data type: ' + dataType);
  33837. }
  33838. }
  33839. }
  33840. ;
  33841. class EptKey {
  33842. constructor(ept, b, d, x, y, z) {
  33843. this.ept = ept;
  33844. this.b = b;
  33845. this.d = d;
  33846. this.x = x || 0;
  33847. this.y = y || 0;
  33848. this.z = z || 0;
  33849. }
  33850. name() {
  33851. return this.d + '-' + this.x + '-' + this.y + '-' + this.z;
  33852. }
  33853. step(a, b, c) {
  33854. var min = this.b.min.clone();
  33855. var max = this.b.max.clone();
  33856. var dst = new Vector3().subVectors(max, min);
  33857. if (a) min.x += dst.x / 2;else max.x -= dst.x / 2;
  33858. if (b) min.y += dst.y / 2;else max.y -= dst.y / 2;
  33859. if (c) min.z += dst.z / 2;else max.z -= dst.z / 2;
  33860. return new Potree.EptKey(this.ept, new Box3(min, max), this.d + 1, this.x * 2 + a, this.y * 2 + b, this.z * 2 + c);
  33861. }
  33862. children() {
  33863. var result = [];
  33864. for (var a = 0; a < 2; ++a) {
  33865. for (var b = 0; b < 2; ++b) {
  33866. for (var c = 0; c < 2; ++c) {
  33867. var add = this.step(a, b, c).name();
  33868. if (!result.includes(add)) result = result.concat(add);
  33869. }
  33870. }
  33871. }
  33872. return result;
  33873. }
  33874. }
  33875. class PointCloudEptGeometryNode extends PointCloudTreeNode {
  33876. constructor(ept, b, d, x, y, z) {
  33877. super();
  33878. this.ept = ept;
  33879. this.key = new Potree.EptKey(this.ept, b || this.ept.boundingBox, d || 0, x, y, z);
  33880. this.id = PointCloudEptGeometryNode.IDCount++;
  33881. this.geometry = null;
  33882. this.boundingBox = this.key.b;
  33883. this.tightBoundingBox = this.boundingBox;
  33884. this.spacing = this.ept.spacing / Math.pow(2, this.key.d);
  33885. this.boundingSphere = U.sphereFrom(this.boundingBox);
  33886. // These are set during hierarchy loading.
  33887. this.hasChildren = false;
  33888. this.children = {};
  33889. this.numPoints = -1;
  33890. this.level = this.key.d;
  33891. this.loaded = false;
  33892. this.loading = false;
  33893. this.oneTimeDisposeHandlers = [];
  33894. var k = this.key;
  33895. this.name = this.toPotreeName(k.d, k.x, k.y, k.z);
  33896. this.index = parseInt(this.name.charAt(this.name.length - 1));
  33897. }
  33898. isGeometryNode() {
  33899. return true;
  33900. }
  33901. getLevel() {
  33902. return this.level;
  33903. }
  33904. isTreeNode() {
  33905. return false;
  33906. }
  33907. isLoaded() {
  33908. return this.loaded;
  33909. }
  33910. getBoundingSphere() {
  33911. return this.boundingSphere;
  33912. }
  33913. getBoundingBox() {
  33914. return this.boundingBox;
  33915. }
  33916. url() {
  33917. return this.ept.url + 'ept-data/' + this.filename();
  33918. }
  33919. getNumPoints() {
  33920. return this.numPoints;
  33921. }
  33922. filename() {
  33923. return this.key.name();
  33924. }
  33925. getChildren() {
  33926. var children = [];
  33927. for (var i = 0; i < 8; i++) {
  33928. if (this.children[i]) {
  33929. children.push(this.children[i]);
  33930. }
  33931. }
  33932. return children;
  33933. }
  33934. addChild(child) {
  33935. this.children[child.index] = child;
  33936. child.parent = this;
  33937. }
  33938. load() {
  33939. if (this.loaded || this.loading) return;
  33940. if (Potree.numNodesLoading >= Potree.maxNodesLoading) return;
  33941. this.loading = true;
  33942. ++Potree.numNodesLoading;
  33943. if (this.numPoints == -1) this.loadHierarchy();
  33944. this.loadPoints();
  33945. }
  33946. loadPoints() {
  33947. this.ept.loader.load(this);
  33948. }
  33949. async loadHierarchy() {
  33950. var nodes = {};
  33951. nodes[this.filename()] = this;
  33952. this.hasChildren = false;
  33953. var eptHierarchyFile = "".concat(this.ept.url, "ept-hierarchy/").concat(this.filename(), ".json");
  33954. var response = await fetch(eptHierarchyFile);
  33955. var hier = await response.json();
  33956. // Since we want to traverse top-down, and 10 comes
  33957. // lexicographically before 9 (for example), do a deep sort.
  33958. var keys = Object.keys(hier).sort((a, b) => {
  33959. var [da, xa, ya, za] = a.split('-').map(n => parseInt(n, 10));
  33960. var [db, xb, yb, zb] = b.split('-').map(n => parseInt(n, 10));
  33961. if (da < db) return -1;
  33962. if (da > db) return 1;
  33963. if (xa < xb) return -1;
  33964. if (xa > xb) return 1;
  33965. if (ya < yb) return -1;
  33966. if (ya > yb) return 1;
  33967. if (za < zb) return -1;
  33968. if (za > zb) return 1;
  33969. return 0;
  33970. });
  33971. keys.forEach(v => {
  33972. var [d, x, y, z] = v.split('-').map(n => parseInt(n, 10));
  33973. var a = x & 1,
  33974. b = y & 1,
  33975. c = z & 1;
  33976. var parentName = d - 1 + '-' + (x >> 1) + '-' + (y >> 1) + '-' + (z >> 1);
  33977. var parentNode = nodes[parentName];
  33978. if (!parentNode) return;
  33979. parentNode.hasChildren = true;
  33980. var key = parentNode.key.step(a, b, c);
  33981. var node = new Potree.PointCloudEptGeometryNode(this.ept, key.b, key.d, key.x, key.y, key.z);
  33982. node.level = d;
  33983. node.numPoints = hier[v];
  33984. parentNode.addChild(node);
  33985. nodes[key.name()] = node;
  33986. });
  33987. }
  33988. doneLoading(bufferGeometry, tightBoundingBox, np, mean) {
  33989. bufferGeometry.boundingBox = this.boundingBox;
  33990. this.geometry = bufferGeometry;
  33991. this.tightBoundingBox = tightBoundingBox;
  33992. this.numPoints = np;
  33993. this.mean = mean;
  33994. this.loaded = true;
  33995. this.loading = false;
  33996. --Potree.numNodesLoading;
  33997. }
  33998. toPotreeName(d, x, y, z) {
  33999. var name = 'r';
  34000. for (var i = 0; i < d; ++i) {
  34001. var shift = d - i - 1;
  34002. var mask = 1 << shift;
  34003. var step = 0;
  34004. if (x & mask) step += 4;
  34005. if (y & mask) step += 2;
  34006. if (z & mask) step += 1;
  34007. name += step;
  34008. }
  34009. return name;
  34010. }
  34011. dispose() {
  34012. if (this.geometry && this.parent != null) {
  34013. this.geometry.dispose();
  34014. this.geometry = null;
  34015. this.loaded = false;
  34016. // this.dispatchEvent( { type: 'dispose' } );
  34017. for (var i = 0; i < this.oneTimeDisposeHandlers.length; i++) {
  34018. var handler = this.oneTimeDisposeHandlers[i];
  34019. handler();
  34020. }
  34021. this.oneTimeDisposeHandlers = [];
  34022. }
  34023. }
  34024. }
  34025. PointCloudEptGeometryNode.IDCount = 0;
  34026. class ExtendPointCloudOctree extends PointCloudOctree {
  34027. constructor(geometry, material) {
  34028. material = material || new ExtendPointCloudMaterial();
  34029. super(geometry, material);
  34030. //xzw move from material 。 adaptive_point_size才使用
  34031. /* this.visibleNodesTexture = Utils.generateDataTexture(2048, 1, new THREE.Color(0xffffff));
  34032. this.visibleNodesTexture.minFilter = THREE.NearestFilter;
  34033. this.visibleNodesTexture.magFilter = THREE.NearestFilter; */
  34034. this.boundingBox = this.pcoGeometry.tightBoundingBox; //this.pcoGeometry.boundingBox; //boundingBox是正方体,所以换掉
  34035. this.boundingSphere = this.boundingBox.getBoundingSphere(new Sphere());
  34036. this.nodeMaxLevel = 0; //add
  34037. if (!this.pcoGeometry.loader.version.equalOrHigher('1.5')) {
  34038. //las 一级一级增长的,但是testNodeMaxLevel时需要大于0
  34039. this.nodeMaxLevel = 1; //add
  34040. }
  34041. this.maxLevel = Infinity;
  34042. this.temp = {
  34043. sizeFitToLevel: {},
  34044. opacity: {}
  34045. }; //add
  34046. //add
  34047. this.panos = [];
  34048. this.matrixAutoUpdate = false; //最好禁止updateMatrix 直接使用matrixWorld
  34049. this.orientationUser = 0;
  34050. this.translateUser = new Vector3();
  34051. this.rotateMatrix = new Matrix4();
  34052. this.transformMatrix = new Matrix4(); // 数据集的变化矩阵
  34053. this.transformInvMatrix = new Matrix4();
  34054. /* this.transformMatrix2 = new THREE.Matrix4;// 数据集的变化矩阵
  34055. this.transformInvMatrix2 = new THREE.Matrix4; */
  34056. this.rotateInvMatrix = new Matrix4();
  34057. this.material.spacing = this.pcoGeometry.spacing; //初始化一下 以便于设置pointsize
  34058. this.nodeMaxLevelPredict = this.predictNodeMaxLevel(); //预测maxNodeLevel
  34059. this.testMaxNodeCount = this.testMaxNodeCount2 = 0;
  34060. this._visible = true;
  34061. this.pcoGeometry.addEventListener('updateNodeMaxLevel', this.updateNodeMaxLevel.bind(this));
  34062. this.isPointcloud = true; //add
  34063. }
  34064. /*
  34065. 注释:node的level从最大的box 0开始。
  34066. 且加载任意一个node必定也会加载它的所有祖先。(如visibleNodes中有一个level为4,则一定有3,2,1,0)
  34067. visibleNodes就是所有可见的node,比如:
  34068. 如果相机在0这个位置朝下,这时候的visibleNodes中只有一个level为0的node;
  34069. 而如果朝上看,上方的几个node如果在视野中占据足够大的位置的话,就会加载。
  34070. 如果相机在2这个位置朝上,这时候的visibleNodes中所包含的level为: 0,1,2
  34071. ________________
  34072. | | | |
  34073. |__2| | |
  34074. | 1 | 1 |
  34075. |_______|_______|
  34076. | |
  34077. | |
  34078. | 0 |
  34079. |_______________|
  34080. 查看box可在potree中开启
  34081. */
  34082. updateNodeMaxLevel(e) {
  34083. //目前点云包含node的最高level
  34084. var level = Math.max(e.level, this.nodeMaxLevel);
  34085. if (level != this.nodeMaxLevel) {
  34086. this.nodeMaxLevel = level;
  34087. //viewer.dispatchEvent({type:'updateNodeMaxLevel', pointcloud: this, nodeMaxLevel:level})
  34088. Potree.settings.isOfficial || console.log('updateNodeMaxLevel ' + this.dataset_id + " : " + this.nodeMaxLevel);
  34089. setTimeout(() => {
  34090. this.setPointLevel(); //重新计算 延迟是因为testNodeMax会变回旧的
  34091. }, 1);
  34092. if (!Potree.settings.sizeFitToLevel) {
  34093. this.changePointSize();
  34094. }
  34095. }
  34096. } //注:在没有加载到真实的 nodeMaxLevel之前,点云会显示得偏大
  34097. //panoEdit时比预测值小很多?
  34098. testMaxNodeLevel(camera) {
  34099. //手动使maxLevel达到最高,从而迫使updateNodeMaxLevel。 因为Potree.settings.pointDensity 不为 'high'时,maxLevel不是所加载的最高,就很容易加载不出下一个层级,导致无法知道nodeMaxLevel
  34100. if (this.testMaxNodeLevelDone) return;
  34101. //if(this.nodeMaxLevel > this.nodeMaxLevelPredict.min )return
  34102. if (this.nodeMaxLevel == 0) return true;
  34103. if (camera.type == "OrthographicCamera" || this.testMaxNodeCount < 50) {
  34104. if (!Potree.Utils.isInsideFrustum(this.bound, camera)) {
  34105. return true;
  34106. }
  34107. } else if (!viewer.atDatasets.includes(this)) return true; //否则老远就count++
  34108. var levels = this.visibleNodes.map(e => e.getLevel());
  34109. var actMaxLevel = Math.max.apply(null, levels); //实际加载到的最高的node level
  34110. if (actMaxLevel < this.maxLevel) return true; // 还没加载到能加载到的最高。 但在细节设置较低时,排除作用微弱。
  34111. //尝试加载出更高级的level
  34112. var old = this.maxLevel;
  34113. this.maxLevel = 12;
  34114. //var visibleNodes1 = this.visibleNodes.map(e=>e.getLevel())
  34115. //console.log('visibleNodes1',visibleNodes1)
  34116. Potree.updatePointClouds([this], viewer.scene.getActiveCamera(), viewer.mainViewport.resolution);
  34117. //不在camera可视范围内还是加载不出来。即使临时修改位置
  34118. var visibleNodes2 = this.visibleNodes.map(e => e.getLevel());
  34119. //console.log('visibleNodes2',visibleNodes2)
  34120. this.maxLevel = old;
  34121. this.testMaxNodeCount++;
  34122. viewer.testMaxNodeCount++;
  34123. //console.log('testMaxNodeCount', this.dataset_id, this.testMaxNodeCount, 'nodeMaxLevel', this.nodeMaxLevel )
  34124. if (this.testMaxNodeCount == Potree.config.testNodeCount1) {
  34125. //差不多等当前所在数据集nodeMaxLevel加载出来
  34126. this.changePointSize(); //重新更新一下大小。因之前用的是nodeMaxLevelPredict (防止刚开始因nodeMaxLevel没涨完,导致过大的点云突然出现
  34127. }
  34128. if (this.testMaxNodeCount > 100) {
  34129. console.log('testMaxNodeLevel次数超出,强制结束:', this.dataset_id, this.nodeMaxLevel, this.nodeMaxLevelPredict.min);
  34130. this.testMaxNodeLevelDone = 'moreThanMaxCount';
  34131. return; //在可以看见点云的情况下,超时,有可能是预测的max是错的
  34132. }
  34133. if (this.nodeMaxLevel < this.nodeMaxLevelPredict.min) return true; //仍需要继续testMaxNodeLevel
  34134. this.testMaxNodeCount2++; // 已经> this.nodeMaxLevelPredict.min 后,开始计数。因为min可能低于真实nodeMaxLevel所以要再试几次
  34135. if (this.testMaxNodeCount2 < 50) return true; //再试几次 ( 主要是细节调得低时需要多测几次才加载到
  34136. this.testMaxNodeLevelDone = true;
  34137. }
  34138. updateMatrixWorld(force) {
  34139. //add
  34140. super.updateMatrixWorld(force);
  34141. this.matrixWorldInverse = this.matrixWorld.clone().invert();
  34142. }
  34143. setPointLevel() {
  34144. var pointDensity = Potree.settings.pointDensity;
  34145. var config = Potree.config.pointDensity[pointDensity];
  34146. if (!config) return;
  34147. /* if(this.testingMaxLevel){
  34148. this.maxLevel = 12;//先加载到最大的直到测试完毕。由于5个level为一组来加载,所以如果写4最高能加载到5,如果写5最高能加载到下一个级别的最高也就是10
  34149. //console.log('maxLevel: '+e.maxLevel + ' testingMaxLevel中 ' )
  34150. }else{ */
  34151. var percent = config.percentByUser && Potree.settings.UserDensityPercent != void 0 ? Potree.settings.UserDensityPercent : config.maxLevelPercent;
  34152. this.maxLevel = Math.round(percent * this.nodeMaxLevel);
  34153. //console.log('maxLevel: '+e.maxLevel + ', density : '+Potree.settings.pointDensity, ", percent :"+percent);
  34154. if (Potree.settings.sizeFitToLevel) {
  34155. this.changePointSize();
  34156. }
  34157. this.changePointOpacity();
  34158. //}
  34159. viewer.dealBeforeRender || viewer.dispatchEvent('content_changed');
  34160. }
  34161. //预测可能的nodeMaxLevel:
  34162. predictNodeMaxLevel() {
  34163. //预测maxNodeLevel。 可能只适用于我们相机拍的点云
  34164. var spacing = {
  34165. min: 0.005,
  34166. max: 0.014
  34167. }; //最小节的两点间的距离 ,获得方法:spacing / Math.pow(2, nodeMaxLevel)。 目前观测的我们自己拍的这个数值的范围大概是这样
  34168. var min = Math.log2(this.material.spacing / spacing.max); //有见过最大是0.01368
  34169. var max = Math.log2(this.material.spacing / spacing.min); //大部分是 0.006
  34170. //console.log('predictNodeMaxLevel:', this.name , min, max )
  34171. //只对深时相机,其他相机不准
  34172. return {
  34173. min,
  34174. max
  34175. };
  34176. }
  34177. getHighestNodeSpacing() {
  34178. return this.material.spacing / Math.pow(2, this.nodeMaxLevel); //前提是这个nodeMaxLevel是准确的
  34179. }
  34180. updateMaterial(material, visibleNodes, camera, renderer, resolution) {
  34181. //改
  34182. material.fov = camera.fov * (Math.PI / 180);
  34183. /* material.screenWidth = renderer.domElement.clientWidth;
  34184. material.screenHeight = renderer.domElement.clientHeight; */
  34185. material.resolution = resolution;
  34186. material.spacing = this.pcoGeometry.spacing; // * Math.max(this.scale.x, this.scale.y, this.scale.z);
  34187. material.near = camera.near;
  34188. material.far = camera.far;
  34189. material.uniforms.octreeSize.value = this.pcoGeometry.boundingBox.getSize(new Vector3()).x;
  34190. }
  34191. pick(viewer, viewport, camera, ray) {
  34192. var params = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
  34193. //改
  34194. var renderer = viewer.renderer;
  34195. var pRenderer = viewer.pRenderer;
  34196. viewer.addTimeMark('pick', 'start');
  34197. var getVal = (a, b) => a != void 0 ? a : b;
  34198. var pickWindowSize = params.pickWindowSize; //拾取像素边长,越小越精准,但点云稀疏的话可能容易出现识别不到的情况。 另外左下侧会有缝隙无法识别到,缝隙大小和这个值有关//突然发现pickWindowSize在一百以内的变化对pick费时影响甚微,1和100差1毫秒不到,但400时会多4毫秒
  34199. if (pickWindowSize == void 0) {
  34200. if (Potree.settings.displayMode == 'showPanos') {
  34201. pickWindowSize = 50;
  34202. } else {
  34203. var r0 = this.nodeMaxLevel > 0 ? this.maxLevel / this.nodeMaxLevel : 0.5;
  34204. pickWindowSize = MathUtils.clamp(Math.round((1.1 - r0) * 80), 15, 100);
  34205. }
  34206. }
  34207. if (camera.type == 'OrthographicCamera') {
  34208. var cameraDir = new Vector3(0, 0, -1).applyQuaternion(camera.quaternion);
  34209. pickWindowSize *= 4; //pointsize比较大时截取太小会没多少点可以选
  34210. }
  34211. var pickOutsideClipRegion = getVal(params.pickOutsideClipRegion, false);
  34212. var size = viewport ? viewport.resolution : renderer.getSize(new Vector2());
  34213. var width = Math.ceil(getVal(params.width, size.width)); //renderTarget大小。影响识别精度
  34214. var height = Math.ceil(getVal(params.height, size.height));
  34215. var screenshot = () => {
  34216. if (window.testScreen) {
  34217. var dataUrl = Potree.Utils.renderTargetToDataUrl(pickState.renderTarget, width, height, renderer);
  34218. Potree.Common.downloadFile(dataUrl, 'screenshot.png');
  34219. window.testScreen = 0;
  34220. }
  34221. };
  34222. var pointSizeType = getVal(params.pointSizeType, this.material.pointSizeType);
  34223. var pointSize = getVal(params.pointSize, this.material.size);
  34224. var nodes = this.nodesOnRay(this.visibleNodes, ray);
  34225. if (nodes.length === 0) {
  34226. return null;
  34227. }
  34228. //console.log('nodes.length != 0', this.name)
  34229. if (!this.pickState) {
  34230. var scene = new Scene();
  34231. var material = new ExtendPointCloudMaterial();
  34232. material.activeAttributeName = "indices"; //indices
  34233. var renderTarget = new WebGLRenderTarget(1, 1, {
  34234. minFilter: LinearFilter,
  34235. magFilter: NearestFilter,
  34236. format: RGBAFormat
  34237. });
  34238. this.pickState = {
  34239. renderTarget: renderTarget,
  34240. material: material,
  34241. scene: scene
  34242. };
  34243. }
  34244. ;
  34245. var pickState = this.pickState;
  34246. var pickMaterial = pickState.material;
  34247. {
  34248. // update pick material
  34249. pickMaterial.pointSizeType = pointSizeType;
  34250. //pickMaterial.shape = this.material.shape;
  34251. pickMaterial.shape = Potree.PointShape.PARABOLOID;
  34252. pickMaterial.uniforms.uFilterReturnNumberRange.value = this.material.uniforms.uFilterReturnNumberRange.value;
  34253. pickMaterial.uniforms.uFilterNumberOfReturnsRange.value = this.material.uniforms.uFilterNumberOfReturnsRange.value;
  34254. pickMaterial.uniforms.uFilterGPSTimeClipRange.value = this.material.uniforms.uFilterGPSTimeClipRange.value;
  34255. pickMaterial.uniforms.uFilterPointSourceIDClipRange.value = this.material.uniforms.uFilterPointSourceIDClipRange.value;
  34256. pickMaterial.size = pointSize;
  34257. pickMaterial.uniforms.minSize.value = this.material.uniforms.minSize.value;
  34258. pickMaterial.uniforms.maxSize.value = this.material.uniforms.maxSize.value;
  34259. pickMaterial.classification = this.material.classification;
  34260. pickMaterial.recomputeClassification();
  34261. //pickClipped判断转移到上一层函数
  34262. var {
  34263. bigClipInBox,
  34264. clipBoxes_in,
  34265. clipBoxes_out
  34266. } = this.material;
  34267. pickMaterial.setClipBoxes(bigClipInBox, clipBoxes_in, clipBoxes_out, []);
  34268. this.updateMaterial(pickMaterial, nodes, camera, renderer, new Vector2(width, height));
  34269. }
  34270. pickState.renderTarget.setSize(width, height); //仅绘制屏幕大小的,而不乘以devicePixelRatio
  34271. var pixelPos = new Vector2(params.x, params.y);
  34272. var gl = renderer.getContext();
  34273. //规定渲染范围,只渲染一小块
  34274. /* renderer.setScissorTest(true);
  34275. gl.enable(gl.SCISSOR_TEST);
  34276. gl.scissor(
  34277. parseInt(pixelPos.x - (pickWindowSize - 1) / 2),
  34278. parseInt(pixelPos.y - (pickWindowSize - 1) / 2),
  34279. parseInt(pickWindowSize), parseInt(pickWindowSize));
  34280. */ //---这段没用
  34281. pickState.renderTarget.scissor.set(parseInt(pixelPos.x - (pickWindowSize - 1) / 2), parseInt(pixelPos.y - (pickWindowSize - 1) / 2), parseInt(pickWindowSize), parseInt(pickWindowSize));
  34282. pickState.renderTarget.scissorTest = true;
  34283. renderer.state.buffers.depth.setTest(pickMaterial.depthTest);
  34284. renderer.state.buffers.depth.setMask(pickMaterial.depthWrite);
  34285. renderer.state.setBlending(NoBlending);
  34286. {
  34287. // RENDER
  34288. renderer.setRenderTarget(pickState.renderTarget);
  34289. gl.clearColor(0, 0, 0, 0);
  34290. //renderer.clear(true, true, true);
  34291. var tmp = this.material;
  34292. this.material = pickMaterial;
  34293. pRenderer.renderOctree(this, nodes, camera, pickState.renderTarget); //只绘制ray pick到的部分nodes
  34294. screenshot();
  34295. this.material = tmp;
  34296. }
  34297. var clamp = (number, min, max) => Math.min(Math.max(min, number), max);
  34298. var x = parseInt(clamp(pixelPos.x - (pickWindowSize - 1) / 2, 0, width));
  34299. var y = parseInt(clamp(pixelPos.y - (pickWindowSize - 1) / 2, 0, height));
  34300. /* let w = parseInt(Math.min(x + pickWindowSize, width) - x);
  34301. let h = parseInt(Math.min(y + pickWindowSize, height) - y); */
  34302. var pixelCount = pickWindowSize * pickWindowSize; //w * h;
  34303. var buffer = new Uint8Array(4 * pixelCount);
  34304. //w<pickWindowSize会报错
  34305. gl.readPixels(x, y, pickWindowSize, pickWindowSize, gl.RGBA, gl.UNSIGNED_BYTE, buffer); //这句花费最多时间 pc:2-4, 即使只有1*1像素
  34306. renderer.clear(true, true, true); //绘制完就clear否则download的图会有上次的轨迹
  34307. renderer.setRenderTarget(null);
  34308. renderer.state.reset();
  34309. renderer.setScissorTest(false);
  34310. gl.disable(gl.SCISSOR_TEST);
  34311. var pixels = buffer;
  34312. var ibuffer = new Uint32Array(buffer.buffer); //四个数整合成一个
  34313. // find closest hit inside pixelWindow boundaries
  34314. var min = Number.MAX_VALUE;
  34315. var hits = [],
  34316. hits2 = [],
  34317. rSquare;
  34318. if (!params.all) {
  34319. var r = MathUtils.clamp(Math.floor(pickWindowSize / 2), 1, 40);
  34320. rSquare = r * r;
  34321. }
  34322. for (var u = 0; u < pickWindowSize; u++) {
  34323. for (var v = 0; v < pickWindowSize; v++) {
  34324. var offset = u + v * pickWindowSize;
  34325. var distance = Math.pow(u - (pickWindowSize - 1) / 2, 2) + Math.pow(v - (pickWindowSize - 1) / 2, 2);
  34326. var pcIndex = pixels[4 * offset + 3]; //nodes index(第四位)
  34327. pixels[4 * offset + 3] = 0; //去除nodes index后剩下的是index(前三位)
  34328. var pIndex = ibuffer[offset]; //index
  34329. if (!(pcIndex === 0 && pIndex === 0) && pcIndex !== undefined && pIndex !== undefined) {
  34330. var hit = {
  34331. pIndex: pIndex,
  34332. pcIndex: pcIndex,
  34333. distanceToCenter: distance
  34334. };
  34335. if (params.all) {
  34336. hits.push(hit);
  34337. } else {
  34338. if (hits.length > 0) {
  34339. //最后选取的是最靠近鼠标的那个pick
  34340. if (distance < hits[0].distanceToCenter) {
  34341. hits[0] = hit;
  34342. }
  34343. } else {
  34344. hits.push(hit);
  34345. }
  34346. if (distance < rSquare) hits2.push(hit); //add
  34347. }
  34348. }
  34349. }
  34350. }
  34351. if (!params.all && Potree.settings.pickFrontPointRatio) {
  34352. if (hits2.length) {
  34353. //add
  34354. hits = hits2;
  34355. }
  34356. }
  34357. // { // DEBUG: show panel with pick image
  34358. // let img = Utils.pixelsArrayToImage(buffer, w, h);
  34359. // let screenshot = img.src;
  34360. // if(!this.debugDIV){
  34361. // this.debugDIV = $(`
  34362. // <div id="pickDebug"
  34363. // style="position: absolute;
  34364. // right: 400px; width: 300px;
  34365. // bottom: 44px; width: 300px;
  34366. // z-index: 1000;
  34367. // "></div>`);
  34368. // $(document.body).append(this.debugDIV);
  34369. // }
  34370. // this.debugDIV.empty();
  34371. // this.debugDIV.append($(`<img src="${screenshot}"
  34372. // style="transform: scaleY(-1); width: 300px"/>`));
  34373. // //$(this.debugWindow.document).append($(`<img src="${screenshot}"/>`));
  34374. // //this.debugWindow.document.write('<img src="'+screenshot+'"/>');
  34375. // }
  34376. for (var _hit of hits) {
  34377. var point = {};
  34378. if (!nodes[_hit.pcIndex]) {
  34379. return null;
  34380. }
  34381. var node = nodes[_hit.pcIndex];
  34382. var pc = node.sceneNode;
  34383. var geometry = node.geometryNode.geometry;
  34384. var _loop = function _loop() {
  34385. var attribute = geometry.attributes[attributeName];
  34386. if (attributeName === 'position') {
  34387. var _x = attribute.array[3 * _hit.pIndex + 0];
  34388. var _y = attribute.array[3 * _hit.pIndex + 1];
  34389. var z = attribute.array[3 * _hit.pIndex + 2];
  34390. var position = new Vector3(_x, _y, z);
  34391. position.applyMatrix4(pc.matrixWorld);
  34392. point[attributeName] = position;
  34393. //add
  34394. if (!params.all && Potree.settings.pickFrontPointRatio) {
  34395. if (camera.type == 'OrthographicCamera') {
  34396. var vec = new Vector3().subVectors(position, camera.position);
  34397. _hit.disSquare = vec.projectOnVector(cameraDir).length(); //只考虑到相机的垂直距离
  34398. } else {
  34399. _hit.disSquare = camera.position.distanceTo(position);
  34400. }
  34401. }
  34402. } else if (attributeName === 'indices') {} else {
  34403. var values = attribute.array.slice(attribute.itemSize * _hit.pIndex, attribute.itemSize * (_hit.pIndex + 1));
  34404. if (attribute.potree) {
  34405. var {
  34406. scale,
  34407. offset: _offset
  34408. } = attribute.potree;
  34409. values = values.map(v => v / scale + _offset);
  34410. }
  34411. point[attributeName] = values;
  34412. //debugger;
  34413. //if (values.itemSize === 1) {
  34414. // point[attribute.name] = values.array[hit.pIndex];
  34415. //} else {
  34416. // let value = [];
  34417. // for (let j = 0; j < values.itemSize; j++) {
  34418. // value.push(values.array[values.itemSize * hit.pIndex + j]);
  34419. // }
  34420. // point[attribute.name] = value;
  34421. //}
  34422. }
  34423. };
  34424. for (var attributeName in geometry.attributes) {
  34425. _loop();
  34426. }
  34427. _hit.point = point;
  34428. }
  34429. viewer.addTimeMark('pick', 'end');
  34430. if (params.all) {
  34431. return hits.map(hit => hit.point);
  34432. } else {
  34433. if (hits.length === 0) {
  34434. return null;
  34435. } else {
  34436. if (Potree.settings.pickFrontPointRatio == 0) {
  34437. //如果不需要选偏离镜头近的,就要离中心近的即可
  34438. //console.log(hits[0], hits2, pixelPos)
  34439. return hits[0].point;
  34440. }
  34441. //为了防止透过点云缝隙,选到后排的点云,将选取的位置离相机的距离考虑进去。倾向选择离相机近、且离鼠标位置近的点。(否则按照原方案只选离鼠标位置最近的,可能从高楼不小心走到下层,导航选点也是)
  34442. var sorted1 = hits.sort((a, b) => a.disSquare - b.disSquare).slice();
  34443. var nearest = sorted1[0]; //return nearest.point; //直接用最近点 在点云稀疏时不太跟手,如地面上,最近点往往在鼠标下方
  34444. hits.forEach(hit => {
  34445. var disDiff = hit.disSquare - nearest.disSquare; //和最近点的偏差
  34446. hit.disDiff = disDiff;
  34447. hit.score = -hit.distanceToCenter - disDiff * Potree.settings.pickFrontPointRatio;
  34448. });
  34449. var sorted2 = hits.sort((a, b) => b.score - a.score);
  34450. //console.log(sorted2[0].point.position.z )
  34451. return sorted2[0].point;
  34452. }
  34453. }
  34454. }
  34455. // 设置点大小
  34456. changePointSize(num, sizeFitToLevel) {
  34457. var size, nodeMaxLevel;
  34458. var dontRender = viewer.dealBeforeRender;
  34459. if (this.material.pointSizeType != PointSizeType.ATTENUATED) {
  34460. num && (size = num / Potree.config.material.realPointSize / 1.3);
  34461. } else {
  34462. var num_ = num;
  34463. if (num_ == void 0) {
  34464. num_ = this.temp.pointSize;
  34465. } else {
  34466. this.temp.pointSize = num_;
  34467. }
  34468. num_ = num_ / (Potree.config.material.realPointSize / Potree.config.material.pointSize); //兼容
  34469. //num_ = Math.pow(num_, 1.05) * 5
  34470. nodeMaxLevel = this.testMaxNodeCount >= Potree.config.testNodeCount1 ? this.nodeMaxLevel : Math.max(this.nodeMaxLevel, this.nodeMaxLevelPredict.max); //防止刚开始因nodeMaxLevel没涨完,导致过大的点云突然出现
  34471. if (sizeFitToLevel || Potree.settings.sizeFitToLevel) {
  34472. //按照点云质量来调整的版本: 近似将pointSizeType换成ADAPTIVE
  34473. var str = this.temp.pointSize + ':' + this.maxLevel + ':' + nodeMaxLevel;
  34474. var value = this.temp.sizeFitToLevel[str]; //储存。防止每次渲染(反复切换density)都要算。
  34475. if (value) {
  34476. size = value;
  34477. } else {
  34478. if (this.maxLevel == Infinity) return;
  34479. var base = this.material.spacing / Math.pow(2, this.maxLevel); //点云大小在level为0时设置为spacing,每长一级,大小就除以2. (不同场景还是会有偏差)
  34480. var r = nodeMaxLevel > 0 ? this.maxLevel / nodeMaxLevel : 0.5; //越大,越精细,需要越缩小
  34481. base *= nodeMaxLevel > 0 ? Math.max(0.1, Math.pow(r, 3 * r + 0.3)) : 0.1; //低质量的缩小点,因为视觉上看太大了。navvis是不铺满的,我们也留一点缝隙(但是ortho是不用缩小的,如果能分开判断就好了)
  34482. //base *= nodeMaxLevel > 0 ? Math.max(0.1, Math.pow(this.maxLevel / nodeMaxLevel, 1.1)) : 0.1 //低质量的缩小点,因为视觉上看太大了。navvis是不铺满的,我们也留一点缝隙(但是ortho是不用缩小的,如果能分开判断就好了)
  34483. size = base * 20 * num_; /* * window.devicePixelRatio */
  34484. //在t-8BCqxQAr93 会议室 和 t-e2Kb2iU 隧道 两个场景里调节,因为它们的spacing相差较大,观察会议室墙壁的龟裂程度
  34485. this.temp.sizeFitToLevel[str] = size;
  34486. }
  34487. } else {
  34488. /* let base = 0.007; */var _base = this.material.spacing / Math.pow(2, nodeMaxLevel); //点云大小在level为0时设置为spacing,每长一级,大小就除以2
  34489. //base的数值理论上应该是右侧算出来的,但发现有的场景nodeMaxLevel和nodeMaxLevelPredict差别较大的点云显示也过大,而直接换成固定值反而可以适应所有场景。该固定值来源于 getHighestNodeSpacing 最小值,修改了下。(会不会是我们的相机其实该值是固定的,根据该值算出的spacing才是有误差的? 如果换了相机是否要改值?)
  34490. //2022-12-21又换回非固定值。因为有的场景如SS-t-t01myDqnfE的两个数据集密集程度差别很大,应该将稀疏点云的大小设置的大些。 但是这样的缺点是两个数据集因相接处有大有小无法融合。
  34491. size = _base * 20 * num_; /* * window.devicePixelRatio */
  34492. }
  34493. }
  34494. //console.log('changePointSize:' + this.dataset_id + ' , num: ' + (num && num.toPrecision(3)) + ' , size: ' + size.toPrecision(3), 'nodeMaxLevel', nodeMaxLevel.toPrecision(3), 'testMaxNodeCount',this.testMaxNodeCount /* this.material.spacing */)
  34495. if (size) {
  34496. if (Potree.settings.sortCloudMat) {
  34497. //被废弃,不给material分组了
  34498. this.size = size;
  34499. this.material.size = size;
  34500. } else {
  34501. this.material.size = size;
  34502. }
  34503. }
  34504. dontRender || viewer.dispatchEvent('content_changed');
  34505. }
  34506. // 设置点透明度
  34507. changePointOpacity(num, canMoreThanOne) {
  34508. //num:0-1 navvis用的是亮度
  34509. if (num == void 0) {
  34510. num = this.temp.pointOpacity;
  34511. } else {
  34512. this.temp.pointOpacity = num;
  34513. }
  34514. var dontRender = viewer.dealBeforeRender; //在执行beforeRender时更改的话不要发送content_changed 尤其分屏
  34515. if (Potree.settings.notAdditiveBlending) {
  34516. return this.material.opacity = num;
  34517. }
  34518. var opacity;
  34519. if (num == 1) {
  34520. opacity = 1;
  34521. } else {
  34522. var str = (Potree.settings.sizeFitToLevel ? 'sizeFit:' : '') + (canMoreThanOne ? 'canMoreThanOne:' : '') + this.temp.pointOpacity + ':' + this.maxLevel + ':' + this.nodeMaxLevel;
  34523. var value = this.temp.opacity[str]; //储存。防止每次渲染(反复切换density)都要算。
  34524. if (value) {
  34525. opacity = value;
  34526. } else {
  34527. if (Potree.settings.sizeFitToLevel) {
  34528. //按照点云质量来调整的版本:
  34529. var base = this.material.spacing / Math.pow(1.7, this.maxLevel); //随着level提高,点云重叠几率增多
  34530. var minBase = this.material.spacing / Math.pow(1.7, this.nodeMaxLevel);
  34531. var ratio = Math.min(1 / base, 1 / minBase / 3); //ratio为一个能使opacity不大于1 的 乘量,minBase要除以一个数,该数调越大减弱效果越强。level越低opacity和面板越接,level越高效果越弱,以减免过度重叠后的亮度。
  34532. opacity = base * ratio * num;
  34533. if (!canMoreThanOne) {
  34534. opacity = MathUtils.clamp(opacity, 0, 0.999); //到1就不透明了(可能出现一段一样)
  34535. }
  34536. } else {
  34537. var _base2 = this.material.spacing / Math.pow(2, this.maxLevel);
  34538. var _minBase = this.material.spacing / Math.pow(2, this.nodeMaxLevel);
  34539. //console.log(1 / base, 1 / minBase / 6)
  34540. var _ratio = Math.min(1 / _base2, 1 / _minBase / 3); //ratio为一个能使opacity不大于1 的 乘量,minBase要除以一个数,该数调越大减弱效果越强。level越低opacity和面板越接,level越高效果越弱,以减免过度重叠后的亮度。
  34541. opacity = _base2 * _ratio * num;
  34542. if (!canMoreThanOne) {
  34543. opacity = MathUtils.clamp(opacity, 0, 0.999); //到1就不透明了(可能出现一段一样)
  34544. }
  34545. }
  34546. this.temp.opacity[str] = opacity;
  34547. }
  34548. //缺点:防止颜色过亮主要是相机离远时,当在漫游点处由于离点云太近,可能会导致高质量点云看起来很暗。
  34549. }
  34550. //console.log('changePointOpacity ' + this.dataset_id + ', num : ' + num + ' , opacity : ' + this.material.opacity) //检查是否做到了低质量时num==opacity,中质量opacity稍小于num,高质量更小
  34551. if (Potree.settings.sortCloudMat) {
  34552. this.opacity = opacity;
  34553. this.material.opacity = opacity;
  34554. } else {
  34555. this.material.opacity = opacity;
  34556. }
  34557. dontRender || viewer.dispatchEvent('content_changed');
  34558. }
  34559. updateBound() {
  34560. var boundingBox_ = this.pcoGeometry.tightBoundingBox.clone().applyMatrix4(this.matrixWorld); //tightBoundingBox是点云原始的bound,但经过(绕z)旋转后bound有所改变,比之前体积更大。
  34561. this.bound = boundingBox_;
  34562. this.bound2 = this.getBoundWithPanos();
  34563. }
  34564. getBoundWithPanos() {
  34565. //确保panoBound在内的bound
  34566. var bound = this.bound.clone();
  34567. this.panos.forEach(pano => {
  34568. var panoBound = new Box3();
  34569. panoBound.expandByPoint(pano.position);
  34570. panoBound.expandByVector(new Vector3(1, 1, 1)); //give pano a margin
  34571. bound.union(panoBound);
  34572. });
  34573. return bound;
  34574. }
  34575. getPanosBound() {
  34576. //仅由所有pano构成的bound
  34577. if (this.panos.length > 0) {
  34578. var minSize = new Vector3(1, 1, 1);
  34579. this.panosBound = math.getBoundByPoints(this.panos.map(e => e.position), minSize);
  34580. } else {
  34581. this.panosBound = null;
  34582. }
  34583. }
  34584. getUnrotBoundPoint(type) {
  34585. //获取没有旋转的tightBounding的水平四个点
  34586. //如果alighment支持任意轴旋转,水平面上看到的可能就是六边形了,失去意义,到时候不能用这个。也可以若只绕z旋转, 使用tightBoundingBox,否则bound
  34587. var bound = this.pcoGeometry.tightBoundingBox;
  34588. if (type == 'all') {
  34589. return [new Vector3(bound.min.x, bound.min.y, bound.min.z), new Vector3(bound.max.x, bound.min.y, bound.min.z), new Vector3(bound.max.x, bound.max.y, bound.min.z), new Vector3(bound.min.x, bound.max.y, bound.min.z), new Vector3(bound.min.x, bound.min.y, bound.max.z), new Vector3(bound.max.x, bound.min.y, bound.max.z), new Vector3(bound.max.x, bound.max.y, bound.max.z), new Vector3(bound.min.x, bound.max.y, bound.max.z)].map(e => e.applyMatrix4(this.matrixWorld));
  34590. } else return [new Vector3(bound.min.x, bound.min.y, 0), new Vector3(bound.max.x, bound.min.y, 0), new Vector3(bound.max.x, bound.max.y, 0), new Vector3(bound.min.x, bound.max.y, 0)].map(e => e.applyMatrix4(this.matrixWorld));
  34591. }
  34592. getVolume() {
  34593. /* var points = this.getUnrotBoundPoint() -----在只绕z轴旋转时这么写也行
  34594. var area = Math.abs(math.getArea(points))
  34595. return area * (this.bound.max.z - this.bound.min.z) */
  34596. var bound = this.pcoGeometry.tightBoundingBox.clone();
  34597. var size = bound.getSize(new Vector3());
  34598. return size.x * size.y * size.z;
  34599. }
  34600. ifContainsPoint(pos) {
  34601. //pos是否坐落于tightBound内
  34602. /* if(!this.bound || !this.bound.containsPoint(pos))return ---这样写也行
  34603. var points = this.getUnrotBoundPoint()
  34604. return math.isPointInArea(points, null, pos) */
  34605. //要把tightBoundingBox想象成一个volumeBox
  34606. var box = this.pcoGeometry.tightBoundingBox;
  34607. var center = box.getCenter(new Vector3());
  34608. var size = box.getSize(new Vector3());
  34609. var boxMatrix = new Matrix4().setPosition(center.x, center.y, center.z);
  34610. boxMatrix.scale(size);
  34611. boxMatrix.premultiply(this.matrixWorld);
  34612. return Potree.Utils.isIntersectBox(pos, boxMatrix);
  34613. }
  34614. intersectBox(boxWorldMatrix) {
  34615. var boxM = boxWorldMatrix.clone().premultiply(this.matrixWorld.clone().invert()); //box乘上点云逆矩阵 (因为点云的忽略掉其matrixWorld, 为了保持相对位置不变,box要左乘matrixWorld的逆)(因第一个参数bound不好变形,第二个参数box可以)
  34616. return Potree.Utils.isIntersectBox(this.pcoGeometry.tightBoundingBox, boxM);
  34617. }
  34618. }
  34619. class ProfileData {
  34620. constructor(profile) {
  34621. this.profile = profile;
  34622. this.segments = [];
  34623. this.boundingBox = new Box3();
  34624. for (var i = 0; i < profile.points.length - 1; i++) {
  34625. var start = profile.points[i];
  34626. var end = profile.points[i + 1];
  34627. var startGround = new Vector3(start.x, start.y, 0);
  34628. var endGround = new Vector3(end.x, end.y, 0);
  34629. var center = new Vector3().addVectors(endGround, startGround).multiplyScalar(0.5);
  34630. var length = startGround.distanceTo(endGround);
  34631. var side = new Vector3().subVectors(endGround, startGround).normalize();
  34632. var up = new Vector3(0, 0, 1);
  34633. var forward = new Vector3().crossVectors(side, up).normalize();
  34634. var N = forward;
  34635. var cutPlane = new Plane().setFromNormalAndCoplanarPoint(N, startGround);
  34636. var halfPlane = new Plane().setFromNormalAndCoplanarPoint(side, center);
  34637. var segment = {
  34638. start: start,
  34639. end: end,
  34640. cutPlane: cutPlane,
  34641. halfPlane: halfPlane,
  34642. length: length,
  34643. points: new Points$1()
  34644. };
  34645. this.segments.push(segment);
  34646. }
  34647. }
  34648. size() {
  34649. var size = 0;
  34650. for (var segment of this.segments) {
  34651. size += segment.points.numPoints;
  34652. }
  34653. return size;
  34654. }
  34655. }
  34656. ;
  34657. class ProfileRequest {
  34658. constructor(pointcloud, profile, maxDepth, callback) {
  34659. this.pointcloud = pointcloud;
  34660. this.profile = profile;
  34661. this.maxDepth = maxDepth || Number.MAX_VALUE;
  34662. this.callback = callback;
  34663. this.temporaryResult = new ProfileData(this.profile);
  34664. this.pointsServed = 0;
  34665. this.highestLevelServed = 0;
  34666. this.priorityQueue = new BinaryHeap(function (x) {
  34667. return 1 / x.weight;
  34668. });
  34669. this.initialize();
  34670. }
  34671. initialize() {
  34672. this.priorityQueue.push({
  34673. node: this.pointcloud.pcoGeometry.root,
  34674. weight: Infinity
  34675. });
  34676. }
  34677. // traverse the node and add intersecting descendants to queue
  34678. traverse(node) {
  34679. var stack = [];
  34680. for (var i = 0; i < 8; i++) {
  34681. var child = node.children[i];
  34682. if (child && this.pointcloud.nodeIntersectsProfile(child, this.profile)) {
  34683. stack.push(child);
  34684. }
  34685. }
  34686. while (stack.length > 0) {
  34687. var _node = stack.pop();
  34688. var weight = _node.boundingSphere.radius;
  34689. this.priorityQueue.push({
  34690. node: _node,
  34691. weight: weight
  34692. });
  34693. // add children that intersect the cutting plane
  34694. if (_node.level < this.maxDepth) {
  34695. for (var _i = 0; _i < 8; _i++) {
  34696. var _child = _node.children[_i];
  34697. if (_child && this.pointcloud.nodeIntersectsProfile(_child, this.profile)) {
  34698. stack.push(_child);
  34699. }
  34700. }
  34701. }
  34702. }
  34703. }
  34704. update() {
  34705. if (!this.updateGeneratorInstance) {
  34706. this.updateGeneratorInstance = this.updateGenerator();
  34707. }
  34708. var result = this.updateGeneratorInstance.next();
  34709. if (result.done) {
  34710. this.updateGeneratorInstance = null;
  34711. }
  34712. }
  34713. *updateGenerator() {
  34714. // load nodes in queue
  34715. // if hierarchy expands, also load nodes from expanded hierarchy
  34716. // once loaded, add data to this.points and remove node from queue
  34717. // only evaluate 1-50 nodes per frame to maintain responsiveness
  34718. var start = performance.now();
  34719. var maxNodesPerUpdate = 1;
  34720. var intersectedNodes = [];
  34721. for (var i = 0; i < Math.min(maxNodesPerUpdate, this.priorityQueue.size()); i++) {
  34722. var element = this.priorityQueue.pop();
  34723. var node = element.node;
  34724. if (node.level > this.maxDepth) {
  34725. continue;
  34726. }
  34727. if (node.loaded) {
  34728. // add points to result
  34729. intersectedNodes.push(node);
  34730. exports.lru.touch(node);
  34731. this.highestLevelServed = Math.max(node.getLevel(), this.highestLevelServed);
  34732. var geom = node.pcoGeometry;
  34733. var hierarchyStepSize = geom ? geom.hierarchyStepSize : 1;
  34734. var doTraverse = node.getLevel() === 0 || node.level % hierarchyStepSize === 0 && node.hasChildren;
  34735. if (doTraverse) {
  34736. this.traverse(node);
  34737. }
  34738. } else {
  34739. node.load();
  34740. this.priorityQueue.push(element);
  34741. }
  34742. }
  34743. if (intersectedNodes.length > 0) {
  34744. for (var done of this.getPointsInsideProfile(intersectedNodes, this.temporaryResult)) {
  34745. if (!done) {
  34746. //console.log("updateGenerator yields");
  34747. yield false;
  34748. }
  34749. }
  34750. if (this.temporaryResult.size() > 100) {
  34751. this.pointsServed += this.temporaryResult.size();
  34752. this.callback.onProgress({
  34753. request: this,
  34754. points: this.temporaryResult
  34755. });
  34756. this.temporaryResult = new ProfileData(this.profile);
  34757. }
  34758. }
  34759. if (this.priorityQueue.size() === 0) {
  34760. // we're done! inform callback and remove from pending requests
  34761. if (this.temporaryResult.size() > 0) {
  34762. this.pointsServed += this.temporaryResult.size();
  34763. this.callback.onProgress({
  34764. request: this,
  34765. points: this.temporaryResult
  34766. });
  34767. this.temporaryResult = new ProfileData(this.profile);
  34768. }
  34769. this.callback.onFinish({
  34770. request: this
  34771. });
  34772. var index = this.pointcloud.profileRequests.indexOf(this);
  34773. if (index >= 0) {
  34774. this.pointcloud.profileRequests.splice(index, 1);
  34775. }
  34776. }
  34777. yield true;
  34778. }
  34779. *getAccepted(numPoints, node, matrix, segment, segmentDir, points, totalMileage) {
  34780. var checkpoint = performance.now();
  34781. var accepted = new Uint32Array(numPoints);
  34782. var mileage = new Float64Array(numPoints);
  34783. var acceptedPositions = new Float32Array(numPoints * 3);
  34784. var numAccepted = 0;
  34785. var pos = new Vector3();
  34786. var svp = new Vector3();
  34787. var view = new Float32Array(node.geometry.attributes.position.array);
  34788. for (var i = 0; i < numPoints; i++) {
  34789. pos.set(view[i * 3 + 0], view[i * 3 + 1], view[i * 3 + 2]);
  34790. pos.applyMatrix4(matrix);
  34791. var distance = Math.abs(segment.cutPlane.distanceToPoint(pos));
  34792. var centerDistance = Math.abs(segment.halfPlane.distanceToPoint(pos));
  34793. if (distance < this.profile.width / 2 && centerDistance < segment.length / 2) {
  34794. svp.subVectors(pos, segment.start);
  34795. var localMileage = segmentDir.dot(svp);
  34796. accepted[numAccepted] = i;
  34797. mileage[numAccepted] = localMileage + totalMileage;
  34798. points.boundingBox.expandByPoint(pos);
  34799. pos.sub(this.pointcloud.position);
  34800. acceptedPositions[3 * numAccepted + 0] = pos.x;
  34801. acceptedPositions[3 * numAccepted + 1] = pos.y;
  34802. acceptedPositions[3 * numAccepted + 2] = pos.z;
  34803. numAccepted++;
  34804. }
  34805. if (i % 1000 === 0) {
  34806. var duration = performance.now() - checkpoint;
  34807. if (duration > 4) {
  34808. //console.log(`getAccepted yield after ${duration}ms`);
  34809. yield false;
  34810. checkpoint = performance.now();
  34811. }
  34812. }
  34813. }
  34814. accepted = accepted.subarray(0, numAccepted);
  34815. mileage = mileage.subarray(0, numAccepted);
  34816. acceptedPositions = acceptedPositions.subarray(0, numAccepted * 3);
  34817. //let end = performance.now();
  34818. //let duration = end - start;
  34819. //console.log("accepted duration ", duration)
  34820. //console.log(`getAccepted finished`);
  34821. yield [accepted, mileage, acceptedPositions];
  34822. }
  34823. *getPointsInsideProfile(nodes, target) {
  34824. var checkpoint = performance.now();
  34825. var totalMileage = 0;
  34826. var pointsProcessed = 0;
  34827. for (var segment of target.segments) {
  34828. for (var node of nodes) {
  34829. var numPoints = node.numPoints;
  34830. var geometry = node.geometry;
  34831. if (!numPoints) {
  34832. continue;
  34833. }
  34834. {
  34835. // skip if current node doesn't intersect current segment
  34836. var bbWorld = node.boundingBox.clone().applyMatrix4(this.pointcloud.matrixWorld);
  34837. var bsWorld = bbWorld.getBoundingSphere(new Sphere());
  34838. var start = new Vector3(segment.start.x, segment.start.y, bsWorld.center.z);
  34839. var end = new Vector3(segment.end.x, segment.end.y, bsWorld.center.z);
  34840. var closest = new Line3(start, end).closestPointToPoint(bsWorld.center, true, new Vector3());
  34841. var distance = closest.distanceTo(bsWorld.center);
  34842. var intersects = distance < bsWorld.radius + target.profile.width;
  34843. if (!intersects) {
  34844. continue;
  34845. }
  34846. }
  34847. //{// DEBUG
  34848. // console.log(node.name);
  34849. // let boxHelper = new Potree.Box3Helper(node.getBoundingBox());
  34850. // boxHelper.matrixAutoUpdate = false;
  34851. // boxHelper.matrix.copy(viewer.scene.pointclouds[0].matrixWorld);
  34852. // viewer.scene.scene.add(boxHelper);
  34853. //}
  34854. var sv = new Vector3().subVectors(segment.end, segment.start).setZ(0);
  34855. var segmentDir = sv.clone().normalize();
  34856. var points = new Points$1();
  34857. var nodeMatrix = new Matrix4().makeTranslation(...node.boundingBox.min.toArray());
  34858. var matrix = new Matrix4().multiplyMatrices(this.pointcloud.matrixWorld, nodeMatrix);
  34859. pointsProcessed = pointsProcessed + numPoints;
  34860. var accepted = null;
  34861. var mileage = null;
  34862. var acceptedPositions = null;
  34863. for (var result of this.getAccepted(numPoints, node, matrix, segment, segmentDir, points, totalMileage)) {
  34864. if (!result) {
  34865. var _duration = performance.now() - checkpoint;
  34866. //console.log(`getPointsInsideProfile yield after ${duration}ms`);
  34867. yield false;
  34868. checkpoint = performance.now();
  34869. } else {
  34870. [accepted, mileage, acceptedPositions] = result;
  34871. }
  34872. }
  34873. var duration = performance.now() - checkpoint;
  34874. if (duration > 4) {
  34875. //console.log(`getPointsInsideProfile yield after ${duration}ms`);
  34876. yield false;
  34877. checkpoint = performance.now();
  34878. }
  34879. points.data.position = acceptedPositions;
  34880. var relevantAttributes = Object.keys(geometry.attributes).filter(a => !["position", "indices"].includes(a));
  34881. for (var attributeName of relevantAttributes) {
  34882. var attribute = geometry.attributes[attributeName];
  34883. var numElements = attribute.array.length / numPoints;
  34884. if (numElements !== parseInt(numElements)) {
  34885. debugger;
  34886. }
  34887. var Type = attribute.array.constructor;
  34888. var filteredBuffer = new Type(numElements * accepted.length);
  34889. var source = attribute.array;
  34890. var _target = filteredBuffer;
  34891. for (var i = 0; i < accepted.length; i++) {
  34892. var index = accepted[i];
  34893. var _start = index * numElements;
  34894. var _end = _start + numElements;
  34895. var sub = source.subarray(_start, _end);
  34896. _target.set(sub, i * numElements);
  34897. }
  34898. points.data[attributeName] = filteredBuffer;
  34899. }
  34900. points.data['mileage'] = mileage;
  34901. points.numPoints = accepted.length;
  34902. segment.points.add(points);
  34903. }
  34904. totalMileage += segment.length;
  34905. }
  34906. for (var _segment of target.segments) {
  34907. target.boundingBox.union(_segment.points.boundingBox);
  34908. }
  34909. //console.log(`getPointsInsideProfile finished`);
  34910. yield true;
  34911. }
  34912. finishLevelThenCancel() {
  34913. if (this.cancelRequested) {
  34914. return;
  34915. }
  34916. this.maxDepth = this.highestLevelServed;
  34917. this.cancelRequested = true;
  34918. //console.log(`maxDepth: ${this.maxDepth}`);
  34919. }
  34920. cancel() {
  34921. this.callback.onCancel();
  34922. this.priorityQueue = new BinaryHeap(function (x) {
  34923. return 1 / x.weight;
  34924. });
  34925. var index = this.pointcloud.profileRequests.indexOf(this);
  34926. if (index >= 0) {
  34927. this.pointcloud.profileRequests.splice(index, 1);
  34928. }
  34929. }
  34930. }
  34931. class WorkerPool {
  34932. constructor() {
  34933. this.workers = {};
  34934. }
  34935. getWorker(url) {
  34936. if (!this.workers[url]) {
  34937. this.workers[url] = [];
  34938. }
  34939. if (this.workers[url].length === 0) {
  34940. var _worker = new Worker(url);
  34941. this.workers[url].push(_worker);
  34942. }
  34943. var worker = this.workers[url].pop();
  34944. return worker;
  34945. }
  34946. returnWorker(url, worker) {
  34947. this.workers[url].push(worker);
  34948. }
  34949. }
  34950. ;
  34951. function createPointcloudData(pointcloud) {
  34952. var material = pointcloud.material;
  34953. var ranges = [];
  34954. for (var [name, value] of material.ranges) {
  34955. ranges.push({
  34956. name: name,
  34957. value: value
  34958. });
  34959. }
  34960. if (typeof material.elevationRange[0] === "number") {
  34961. ranges.push({
  34962. name: "elevationRange",
  34963. value: material.elevationRange
  34964. });
  34965. }
  34966. if (typeof material.intensityRange[0] === "number") {
  34967. ranges.push({
  34968. name: "intensityRange",
  34969. value: material.intensityRange
  34970. });
  34971. }
  34972. var pointSizeTypeName = Object.entries(Potree.PointSizeType).find(e => e[1] === material.pointSizeType)[0];
  34973. var jsonMaterial = {
  34974. activeAttributeName: material.activeAttributeName,
  34975. ranges: ranges,
  34976. size: material.size,
  34977. minSize: material.minSize,
  34978. pointSizeType: pointSizeTypeName,
  34979. matcap: material.matcap
  34980. };
  34981. var pcdata = {
  34982. name: pointcloud.name,
  34983. url: pointcloud.pcoGeometry.url,
  34984. position: pointcloud.position.toArray(),
  34985. rotation: pointcloud.rotation.toArray(),
  34986. scale: pointcloud.scale.toArray(),
  34987. material: jsonMaterial
  34988. };
  34989. return pcdata;
  34990. }
  34991. function createProfileData(profile) {
  34992. var data = {
  34993. uuid: profile.uuid,
  34994. name: profile.name,
  34995. points: profile.points.map(p => p.toArray()),
  34996. height: profile.height,
  34997. width: profile.width
  34998. };
  34999. return data;
  35000. }
  35001. function createVolumeData(volume) {
  35002. var data = {
  35003. uuid: volume.uuid,
  35004. type: volume.constructor.name,
  35005. name: volume.name,
  35006. position: volume.position.toArray(),
  35007. rotation: volume.rotation.toArray(),
  35008. scale: volume.scale.toArray(),
  35009. visible: volume.visible,
  35010. clip: volume.clip
  35011. };
  35012. return data;
  35013. }
  35014. function createCameraAnimationData(animation) {
  35015. var controlPoints = animation.controlPoints.map(cp => {
  35016. var cpdata = {
  35017. position: cp.position.toArray(),
  35018. target: cp.target.toArray()
  35019. };
  35020. return cpdata;
  35021. });
  35022. var data = {
  35023. uuid: animation.uuid,
  35024. name: animation.name,
  35025. duration: animation.duration,
  35026. t: animation.t,
  35027. curveType: animation.curveType,
  35028. visible: animation.visible,
  35029. controlPoints: controlPoints
  35030. };
  35031. return data;
  35032. }
  35033. function createMeasurementData(measurement) {
  35034. var data = {
  35035. uuid: measurement.uuid,
  35036. name: measurement.name,
  35037. points: measurement.points.map(p => p.position.toArray()),
  35038. showDistances: measurement.showDistances,
  35039. showCoordinates: measurement.showCoordinates,
  35040. showArea: measurement.showArea,
  35041. closed: measurement.closed,
  35042. showAngles: measurement.showAngles,
  35043. showHeight: measurement.showHeight,
  35044. showCircle: measurement.showCircle,
  35045. showAzimuth: measurement.showAzimuth,
  35046. showEdges: measurement.showEdges,
  35047. color: measurement.color.toArray()
  35048. };
  35049. return data;
  35050. }
  35051. function createOrientedImagesData(images) {
  35052. var data = {
  35053. cameraParamsPath: images.cameraParamsPath,
  35054. imageParamsPath: images.imageParamsPath
  35055. };
  35056. return data;
  35057. }
  35058. function createGeopackageData(geopackage) {
  35059. var data = {
  35060. path: geopackage.path
  35061. };
  35062. return data;
  35063. }
  35064. function createAnnotationData(annotation) {
  35065. var data = {
  35066. uuid: annotation.uuid,
  35067. title: annotation.title.toString(),
  35068. description: annotation.description,
  35069. position: annotation.position.toArray(),
  35070. offset: annotation.offset.toArray(),
  35071. children: []
  35072. };
  35073. if (annotation.cameraPosition) {
  35074. data.cameraPosition = annotation.cameraPosition.toArray();
  35075. }
  35076. if (annotation.cameraTarget) {
  35077. data.cameraTarget = annotation.cameraTarget.toArray();
  35078. }
  35079. if (typeof annotation.radius !== "undefined") {
  35080. data.radius = annotation.radius;
  35081. }
  35082. return data;
  35083. }
  35084. function createAnnotationsData(viewer) {
  35085. var map = new Map();
  35086. viewer.scene.annotations.traverseDescendants(a => {
  35087. var aData = createAnnotationData(a);
  35088. map.set(a, aData);
  35089. });
  35090. for (var [annotation, data] of map) {
  35091. for (var child of annotation.children) {
  35092. var childData = map.get(child);
  35093. data.children.push(childData);
  35094. }
  35095. }
  35096. var annotations = viewer.scene.annotations.children.map(a => map.get(a));
  35097. return annotations;
  35098. }
  35099. function createSettingsData(viewer) {
  35100. return {
  35101. pointBudget: viewer.getPointBudget(),
  35102. fov: viewer.getFOV(),
  35103. edlEnabled: viewer.getEDLEnabled(),
  35104. edlRadius: viewer.getEDLRadius(),
  35105. edlStrength: viewer.getEDLStrength(),
  35106. background: viewer.getBackground(),
  35107. minNodeSize: viewer.getMinNodeSize(),
  35108. showBoundingBoxes: viewer.getShowBoundingBox()
  35109. };
  35110. }
  35111. function createSceneContentData(viewer) {
  35112. var data = [];
  35113. var potreeObjects = [];
  35114. viewer.scene.scene.traverse(node => {
  35115. if (node.potree) {
  35116. potreeObjects.push(node);
  35117. }
  35118. });
  35119. for (var object of potreeObjects) {
  35120. if (object.potree.file) {
  35121. var saveObject = {
  35122. file: object.potree.file
  35123. };
  35124. data.push(saveObject);
  35125. }
  35126. }
  35127. return data;
  35128. }
  35129. function createViewData(viewer) {
  35130. var view = viewer.scene.view;
  35131. var data = {
  35132. position: view.position.toArray(),
  35133. target: view.getPivot().toArray()
  35134. };
  35135. return data;
  35136. }
  35137. function createClassificationData(viewer) {
  35138. var classifications = viewer.classifications;
  35139. var data = classifications;
  35140. return data;
  35141. }
  35142. function saveProject(viewer) {
  35143. var scene = viewer.scene;
  35144. var data = {
  35145. type: "Potree",
  35146. version: 1.7,
  35147. settings: createSettingsData(viewer),
  35148. view: createViewData(viewer),
  35149. classification: createClassificationData(viewer),
  35150. pointclouds: scene.pointclouds.map(createPointcloudData),
  35151. measurements: scene.measurements.map(createMeasurementData),
  35152. volumes: scene.volumes.map(createVolumeData),
  35153. cameraAnimations: scene.cameraAnimations.map(createCameraAnimationData),
  35154. profiles: scene.profiles.map(createProfileData),
  35155. annotations: createAnnotationsData(viewer),
  35156. orientedImages: scene.orientedImages.map(createOrientedImagesData),
  35157. geopackages: scene.geopackages.map(createGeopackageData)
  35158. // objects: createSceneContentData(viewer),
  35159. };
  35160. return data;
  35161. }
  35162. class ControlPoint {
  35163. constructor() {
  35164. this.position = new Vector3(0, 0, 0);
  35165. this.target = new Vector3(0, 0, 0);
  35166. this.positionHandle = null;
  35167. this.targetHandle = null;
  35168. }
  35169. }
  35170. ;
  35171. class CameraAnimation extends EventDispatcher$1 {
  35172. constructor(viewer) {
  35173. super();
  35174. this.viewer = viewer;
  35175. this.selectedElement = null;
  35176. this.controlPoints = [];
  35177. this.uuid = MathUtils.generateUUID();
  35178. this.node = new Object3D();
  35179. this.node.name = "camera animation";
  35180. this.viewer.scene.scene.add(this.node);
  35181. this.frustum = this.createFrustum();
  35182. this.node.add(this.frustum);
  35183. this.name = "Camera Animation";
  35184. this.duration = 5;
  35185. this.t = 0;
  35186. // "centripetal", "chordal", "catmullrom"
  35187. this.curveType = "centripetal";
  35188. this.visible = true;
  35189. this.createUpdateHook();
  35190. this.createPath();
  35191. }
  35192. static defaultFromView(viewer) {
  35193. var animation = new CameraAnimation(viewer);
  35194. var camera = viewer.scene.getActiveCamera();
  35195. var target = viewer.scene.view.getPivot();
  35196. var cpCenter = new Vector3(0.3 * camera.position.x + 0.7 * target.x, 0.3 * camera.position.y + 0.7 * target.y, 0.3 * camera.position.z + 0.7 * target.z);
  35197. var targetCenter = new Vector3(0.05 * camera.position.x + 0.95 * target.x, 0.05 * camera.position.y + 0.95 * target.y, 0.05 * camera.position.z + 0.95 * target.z);
  35198. var r = camera.position.distanceTo(target) * 0.3;
  35199. //const dir = target.clone().sub(camera.position).normalize();
  35200. var angle = Utils.computeAzimuth(camera.position, target);
  35201. var n = 5;
  35202. for (var i = 0; i < n; i++) {
  35203. var u = 1.5 * Math.PI * (i / n) + angle;
  35204. var dx = r * Math.cos(u);
  35205. var dy = r * Math.sin(u);
  35206. var cpPos = [cpCenter.x + dx, cpCenter.y + dy, cpCenter.z];
  35207. var targetPos = [targetCenter.x + dx * 0.1, targetCenter.y + dy * 0.1, targetCenter.z];
  35208. var cp = animation.createControlPoint();
  35209. cp.position.set(...cpPos);
  35210. cp.target.set(...targetPos);
  35211. }
  35212. return animation;
  35213. }
  35214. createUpdateHook() {
  35215. var viewer = this.viewer;
  35216. viewer.addEventListener("update", () => {
  35217. var camera = viewer.scene.getActiveCamera();
  35218. var {
  35219. width,
  35220. height
  35221. } = viewer.renderer.getSize(new Vector2());
  35222. this.node.visible = this.visible;
  35223. for (var cp of this.controlPoints) {
  35224. {
  35225. // position
  35226. var projected = cp.position.clone().project(camera);
  35227. var visible = this.visible && projected.z < 1 && projected.z > -1;
  35228. if (visible) {
  35229. var x = width * (projected.x * 0.5 + 0.5);
  35230. var y = height - height * (projected.y * 0.5 + 0.5);
  35231. cp.positionHandle.svg.style.left = x - cp.positionHandle.svg.clientWidth / 2;
  35232. cp.positionHandle.svg.style.top = y - cp.positionHandle.svg.clientHeight / 2;
  35233. cp.positionHandle.svg.style.display = "";
  35234. } else {
  35235. cp.positionHandle.svg.style.display = "none";
  35236. }
  35237. }
  35238. {
  35239. // target
  35240. var _projected = cp.target.clone().project(camera);
  35241. var _visible = this.visible && _projected.z < 1 && _projected.z > -1;
  35242. if (_visible) {
  35243. var _x = width * (_projected.x * 0.5 + 0.5);
  35244. var _y = height - height * (_projected.y * 0.5 + 0.5);
  35245. cp.targetHandle.svg.style.left = _x - cp.targetHandle.svg.clientWidth / 2;
  35246. cp.targetHandle.svg.style.top = _y - cp.targetHandle.svg.clientHeight / 2;
  35247. cp.targetHandle.svg.style.display = "";
  35248. } else {
  35249. cp.targetHandle.svg.style.display = "none";
  35250. }
  35251. }
  35252. }
  35253. this.line.material.resolution.set(width, height);
  35254. this.updatePath();
  35255. {
  35256. // frustum
  35257. var frame = this.at(this.t);
  35258. var frustum = this.frustum;
  35259. frustum.position.copy(frame.position);
  35260. frustum.lookAt(...frame.target.toArray());
  35261. frustum.scale.set(20, 20, 20);
  35262. frustum.material.resolution.set(width, height);
  35263. }
  35264. });
  35265. }
  35266. createControlPoint(index) {
  35267. if (index === undefined) {
  35268. index = this.controlPoints.length;
  35269. }
  35270. var cp = new ControlPoint();
  35271. if (this.controlPoints.length >= 2 && index === 0) {
  35272. var cp1 = this.controlPoints[0];
  35273. var cp2 = this.controlPoints[1];
  35274. var dir = cp1.position.clone().sub(cp2.position).multiplyScalar(0.5);
  35275. cp.position.copy(cp1.position).add(dir);
  35276. var tDir = cp1.target.clone().sub(cp2.target).multiplyScalar(0.5);
  35277. cp.target.copy(cp1.target).add(tDir);
  35278. } else if (this.controlPoints.length >= 2 && index === this.controlPoints.length) {
  35279. var _cp2 = this.controlPoints[this.controlPoints.length - 2];
  35280. var _cp3 = this.controlPoints[this.controlPoints.length - 1];
  35281. var _dir = _cp3.position.clone().sub(_cp2.position).multiplyScalar(0.5);
  35282. cp.position.copy(_cp2.position).add(_dir);
  35283. var _tDir = _cp3.target.clone().sub(_cp2.target).multiplyScalar(0.5);
  35284. cp.target.copy(_cp3.target).add(_tDir);
  35285. } else if (this.controlPoints.length >= 2) {
  35286. var _cp4 = this.controlPoints[index - 1];
  35287. var _cp5 = this.controlPoints[index];
  35288. cp.position.copy(_cp4.position.clone().add(_cp5.position).multiplyScalar(0.5));
  35289. cp.target.copy(_cp4.target.clone().add(_cp5.target).multiplyScalar(0.5));
  35290. }
  35291. // cp.position.copy(viewer.scene.view.position);
  35292. // cp.target.copy(viewer.scene.view.getPivot());
  35293. cp.positionHandle = this.createHandle(cp.position);
  35294. cp.targetHandle = this.createHandle(cp.target);
  35295. this.controlPoints.splice(index, 0, cp);
  35296. this.dispatchEvent({
  35297. type: "controlpoint_added",
  35298. controlpoint: cp
  35299. });
  35300. return cp;
  35301. }
  35302. removeControlPoint(cp) {
  35303. this.controlPoints = this.controlPoints.filter(_cp => _cp !== cp);
  35304. this.dispatchEvent({
  35305. type: "controlpoint_removed",
  35306. controlpoint: cp
  35307. });
  35308. cp.positionHandle.svg.remove();
  35309. cp.targetHandle.svg.remove();
  35310. // TODO destroy cp
  35311. }
  35312. createPath() {
  35313. {
  35314. // position
  35315. var geometry = new LineGeometry();
  35316. var material = new LineMaterial({
  35317. color: 0x00ff00,
  35318. dashSize: 5,
  35319. gapSize: 2,
  35320. linewidth: 2,
  35321. resolution: new Vector2(1000, 1000)
  35322. });
  35323. var line = new Line2(geometry, material);
  35324. this.line = line;
  35325. this.node.add(line);
  35326. }
  35327. {
  35328. // target
  35329. var _geometry = new LineGeometry();
  35330. var _material = new LineMaterial({
  35331. color: 0x0000ff,
  35332. dashSize: 5,
  35333. gapSize: 2,
  35334. linewidth: 2,
  35335. resolution: new Vector2(1000, 1000)
  35336. });
  35337. var _line = new Line2(_geometry, _material);
  35338. this.targetLine = _line;
  35339. this.node.add(_line);
  35340. }
  35341. }
  35342. createFrustum() {
  35343. var f = 0.3;
  35344. var positions = [0, 0, 0, -f, -f, +1, 0, 0, 0, f, -f, +1, 0, 0, 0, f, f, +1, 0, 0, 0, -f, f, +1, -f, -f, +1, f, -f, +1, f, -f, +1, f, f, +1, f, f, +1, -f, f, +1, -f, f, +1, -f, -f, +1];
  35345. var geometry = new LineGeometry();
  35346. geometry.setPositions(positions);
  35347. geometry.verticesNeedUpdate = true;
  35348. geometry.computeBoundingSphere();
  35349. var material = new LineMaterial({
  35350. color: 0xff0000,
  35351. linewidth: 2,
  35352. resolution: new Vector2(1000, 1000)
  35353. });
  35354. var line = new Line2(geometry, material);
  35355. line.computeLineDistances();
  35356. return line;
  35357. }
  35358. updatePath() {
  35359. {
  35360. // positions
  35361. var positions = this.controlPoints.map(cp => cp.position);
  35362. var first = positions[0];
  35363. var curve = new CatmullRomCurve3(positions);
  35364. curve.curveType = this.curveType;
  35365. var n = 100;
  35366. var curvePositions = [];
  35367. for (var k = 0; k <= n; k++) {
  35368. var t = k / n;
  35369. var position = curve.getPoint(t).sub(first);
  35370. curvePositions.push(position.x, position.y, position.z);
  35371. }
  35372. this.line.geometry.setPositions(curvePositions);
  35373. this.line.geometry.verticesNeedUpdate = true;
  35374. this.line.geometry.computeBoundingSphere();
  35375. this.line.position.copy(first);
  35376. this.line.computeLineDistances();
  35377. this.cameraCurve = curve;
  35378. }
  35379. {
  35380. // targets
  35381. var _positions = this.controlPoints.map(cp => cp.target);
  35382. var _first = _positions[0];
  35383. var _curve = new CatmullRomCurve3(_positions);
  35384. _curve.curveType = this.curveType;
  35385. var _n = 100;
  35386. var _curvePositions = [];
  35387. for (var _k = 0; _k <= _n; _k++) {
  35388. var _t = _k / _n;
  35389. var _position = _curve.getPoint(_t).sub(_first);
  35390. _curvePositions.push(_position.x, _position.y, _position.z);
  35391. }
  35392. this.targetLine.geometry.setPositions(_curvePositions);
  35393. this.targetLine.geometry.verticesNeedUpdate = true;
  35394. this.targetLine.geometry.computeBoundingSphere();
  35395. this.targetLine.position.copy(_first);
  35396. this.targetLine.computeLineDistances();
  35397. this.targetCurve = _curve;
  35398. }
  35399. }
  35400. at(t) {
  35401. if (t > 1) {
  35402. t = 1;
  35403. } else if (t < 0) {
  35404. t = 0;
  35405. }
  35406. var camPos = this.cameraCurve.getPointAt(t);
  35407. var target = this.targetCurve.getPointAt(t);
  35408. var frame = {
  35409. position: camPos,
  35410. target: target
  35411. };
  35412. return frame;
  35413. }
  35414. set(t) {
  35415. this.t = t;
  35416. }
  35417. createHandle(vector) {
  35418. var svgns = "http://www.w3.org/2000/svg";
  35419. var svg = document.createElementNS(svgns, "svg");
  35420. svg.setAttribute("width", "2em");
  35421. svg.setAttribute("height", "2em");
  35422. svg.setAttribute("position", "absolute");
  35423. svg.style.left = "50px";
  35424. svg.style.top = "50px";
  35425. svg.style.position = "absolute";
  35426. svg.style.zIndex = "10000";
  35427. var circle = document.createElementNS(svgns, 'circle');
  35428. circle.setAttributeNS(null, 'cx', "1em");
  35429. circle.setAttributeNS(null, 'cy', "1em");
  35430. circle.setAttributeNS(null, 'r', "0.5em");
  35431. circle.setAttributeNS(null, 'style', 'fill: red; stroke: black; stroke-width: 0.2em;');
  35432. svg.appendChild(circle);
  35433. var element = this.viewer.renderer.domElement.parentElement;
  35434. element.appendChild(svg);
  35435. var startDrag = evt => {
  35436. this.selectedElement = svg;
  35437. document.addEventListener("mousemove", drag);
  35438. };
  35439. var endDrag = evt => {
  35440. this.selectedElement = null;
  35441. document.removeEventListener("mousemove", drag);
  35442. };
  35443. var drag = evt => {
  35444. if (this.selectedElement) {
  35445. evt.preventDefault();
  35446. var rect = viewer.renderer.domElement.getBoundingClientRect();
  35447. var x = evt.clientX - rect.x;
  35448. var y = evt.clientY - rect.y;
  35449. var {
  35450. width,
  35451. height
  35452. } = this.viewer.renderer.getSize(new Vector2());
  35453. var camera = this.viewer.scene.getActiveCamera();
  35454. //const cp = this.controlPoints.find(cp => cp.handle.svg === svg);
  35455. var projected = vector.clone().project(camera);
  35456. projected.x = (x / width - 0.5) / 0.5;
  35457. projected.y = (-(y - height) / height - 0.5) / 0.5;
  35458. var unprojected = projected.clone().unproject(camera);
  35459. vector.set(unprojected.x, unprojected.y, unprojected.z);
  35460. }
  35461. };
  35462. svg.addEventListener('mousedown', startDrag);
  35463. svg.addEventListener('mouseup', endDrag);
  35464. var handle = {
  35465. svg: svg
  35466. };
  35467. return handle;
  35468. }
  35469. setVisible(visible) {
  35470. this.node.visible = visible;
  35471. var display = visible ? "" : "none";
  35472. for (var cp of this.controlPoints) {
  35473. cp.positionHandle.svg.style.display = display;
  35474. cp.targetHandle.svg.style.display = display;
  35475. }
  35476. this.visible = visible;
  35477. }
  35478. setDuration(duration) {
  35479. this.duration = duration;
  35480. }
  35481. getDuration(duration) {
  35482. return this.duration;
  35483. }
  35484. play() {
  35485. var tStart = performance.now();
  35486. var duration = this.duration;
  35487. var originalyVisible = this.visible;
  35488. this.setVisible(false);
  35489. var onUpdate = delta => {
  35490. var tNow = performance.now();
  35491. var elapsed = (tNow - tStart) / 1000;
  35492. var t = elapsed / duration;
  35493. this.set(t);
  35494. var frame = this.at(t);
  35495. viewer.scene.view.position.copy(frame.position);
  35496. viewer.scene.view.lookAt(frame.target);
  35497. if (t > 1) {
  35498. this.setVisible(originalyVisible);
  35499. this.viewer.removeEventListener("update", onUpdate);
  35500. }
  35501. };
  35502. this.viewer.addEventListener("update", onUpdate);
  35503. }
  35504. }
  35505. function loadPointCloud(viewer, data) {
  35506. var loadMaterial = target => {
  35507. if (data.material) {
  35508. if (data.material.activeAttributeName != null) {
  35509. target.activeAttributeName = data.material.activeAttributeName;
  35510. }
  35511. if (data.material.ranges != null) {
  35512. for (var range of data.material.ranges) {
  35513. if (range.name === "elevationRange") {
  35514. target.elevationRange = range.value;
  35515. } else if (range.name === "intensityRange") {
  35516. target.intensityRange = range.value;
  35517. } else {
  35518. target.setRange(range.name, range.value);
  35519. }
  35520. }
  35521. }
  35522. if (data.material.size != null) {
  35523. target.size = data.material.size;
  35524. }
  35525. if (data.material.minSize != null) {
  35526. target.minSize = data.material.minSize;
  35527. }
  35528. if (data.material.pointSizeType != null) {
  35529. target.pointSizeType = PointSizeType[data.material.pointSizeType];
  35530. }
  35531. if (data.material.matcap != null) {
  35532. target.matcap = data.material.matcap;
  35533. }
  35534. } else if (data.activeAttributeName != null) {
  35535. target.activeAttributeName = data.activeAttributeName;
  35536. } else {
  35537. // no material data
  35538. }
  35539. };
  35540. var promise = new Promise(resolve => {
  35541. var names = viewer.scene.pointclouds.map(p => p.name);
  35542. var alreadyExists = names.includes(data.name);
  35543. if (alreadyExists) {
  35544. resolve();
  35545. return;
  35546. }
  35547. Potree.loadPointCloud(data.url, data.name, e => {
  35548. var {
  35549. pointcloud
  35550. } = e;
  35551. pointcloud.position.set(...data.position);
  35552. pointcloud.rotation.set(...data.rotation);
  35553. pointcloud.scale.set(...data.scale);
  35554. loadMaterial(pointcloud.material);
  35555. viewer.scene.addPointCloud(pointcloud);
  35556. resolve(pointcloud);
  35557. });
  35558. });
  35559. return promise;
  35560. }
  35561. function loadMeasurement(viewer, data) {
  35562. var duplicate = viewer.scene.measurements.find(measure => measure.uuid === data.uuid);
  35563. if (duplicate) {
  35564. return;
  35565. }
  35566. var measure = new Measure();
  35567. measure.uuid = data.uuid;
  35568. measure.name = data.name;
  35569. measure.showDistances = data.showDistances;
  35570. measure.showCoordinates = data.showCoordinates;
  35571. measure.showArea = data.showArea;
  35572. measure.closed = data.closed;
  35573. measure.showAngles = data.showAngles;
  35574. measure.showHeight = data.showHeight;
  35575. measure.showCircle = data.showCircle;
  35576. measure.showAzimuth = data.showAzimuth;
  35577. measure.showEdges = data.showEdges;
  35578. // color
  35579. for (var point of data.points) {
  35580. var pos = new Vector3(...point);
  35581. measure.addMarker(pos);
  35582. }
  35583. viewer.scene.addMeasurement(measure);
  35584. }
  35585. function loadVolume(viewer, data) {
  35586. var duplicate = viewer.scene.volumes.find(volume => volume.uuid === data.uuid);
  35587. if (duplicate) {
  35588. return;
  35589. }
  35590. var volume = new Potree[data.type]();
  35591. volume.uuid = data.uuid;
  35592. volume.name = data.name;
  35593. volume.position.set(...data.position);
  35594. volume.rotation.set(...data.rotation);
  35595. volume.scale.set(...data.scale);
  35596. volume.visible = data.visible;
  35597. volume.clip = data.clip;
  35598. viewer.scene.addVolume(volume);
  35599. }
  35600. function loadCameraAnimation(viewer, data) {
  35601. var duplicate = viewer.scene.cameraAnimations.find(a => a.uuid === data.uuid);
  35602. if (duplicate) {
  35603. return;
  35604. }
  35605. var animation = new CameraAnimation(viewer);
  35606. animation.uuid = data.uuid;
  35607. animation.name = data.name;
  35608. animation.duration = data.duration;
  35609. animation.t = data.t;
  35610. animation.curveType = data.curveType;
  35611. animation.visible = data.visible;
  35612. animation.controlPoints = [];
  35613. for (var cpdata of data.controlPoints) {
  35614. var cp = animation.createControlPoint();
  35615. cp.position.set(...cpdata.position);
  35616. cp.target.set(...cpdata.target);
  35617. }
  35618. viewer.scene.addCameraAnimation(animation);
  35619. }
  35620. function loadOrientedImages(viewer, images) {
  35621. var {
  35622. cameraParamsPath,
  35623. imageParamsPath
  35624. } = images;
  35625. var duplicate = viewer.scene.orientedImages.find(i => i.imageParamsPath === imageParamsPath);
  35626. if (duplicate) {
  35627. return;
  35628. }
  35629. Potree.OrientedImageLoader.load(cameraParamsPath, imageParamsPath, viewer).then(images => {
  35630. viewer.scene.addOrientedImages(images);
  35631. });
  35632. }
  35633. function loadGeopackage(viewer, geopackage) {
  35634. var path = geopackage.path;
  35635. var duplicate = viewer.scene.geopackages.find(i => i.path === path);
  35636. if (duplicate) {
  35637. return;
  35638. }
  35639. var projection = viewer.getProjection();
  35640. proj4.defs("WGS84", "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs");
  35641. proj4.defs("pointcloud", projection);
  35642. var transform = proj4("WGS84", "pointcloud");
  35643. var params = {
  35644. transform: transform
  35645. };
  35646. Potree.GeoPackageLoader.loadUrl(path, params).then(data => {
  35647. viewer.scene.addGeopackage(data);
  35648. });
  35649. }
  35650. function loadSettings(viewer, data) {
  35651. if (!data) {
  35652. return;
  35653. }
  35654. viewer.setPointBudget(data.pointBudget);
  35655. viewer.setFOV(data.fov);
  35656. viewer.setEDLEnabled(data.edlEnabled);
  35657. viewer.setEDLRadius(data.edlRadius);
  35658. viewer.setEDLStrength(data.edlStrength);
  35659. viewer.setBackground(data.background);
  35660. viewer.setMinNodeSize(data.minNodeSize);
  35661. viewer.setShowBoundingBox(data.showBoundingBoxes);
  35662. }
  35663. function loadView(viewer, view) {
  35664. viewer.scene.view.position.set(...view.position);
  35665. viewer.scene.view.lookAt(...view.target);
  35666. }
  35667. function loadAnnotationItem(item) {
  35668. var annotation = new Annotation({
  35669. position: item.position,
  35670. title: item.title,
  35671. cameraPosition: item.cameraPosition,
  35672. cameraTarget: item.cameraTarget
  35673. });
  35674. annotation.description = item.description;
  35675. annotation.uuid = item.uuid;
  35676. if (item.offset) {
  35677. annotation.offset.set(...item.offset);
  35678. }
  35679. return annotation;
  35680. }
  35681. function loadAnnotations(viewer, data) {
  35682. if (!data) {
  35683. return;
  35684. }
  35685. var findDuplicate = item => {
  35686. var duplicate = null;
  35687. viewer.scene.annotations.traverse(a => {
  35688. if (a.uuid === item.uuid) {
  35689. duplicate = a;
  35690. }
  35691. });
  35692. return duplicate;
  35693. };
  35694. var traverse = (item, parent) => {
  35695. var duplicate = findDuplicate(item);
  35696. if (duplicate) {
  35697. return;
  35698. }
  35699. var annotation = loadAnnotationItem(item);
  35700. for (var childItem of item.children) {
  35701. traverse(childItem, annotation);
  35702. }
  35703. parent.add(annotation);
  35704. };
  35705. for (var item of data) {
  35706. traverse(item, viewer.scene.annotations);
  35707. }
  35708. }
  35709. function loadProfile(viewer, data) {
  35710. var {
  35711. name,
  35712. points
  35713. } = data;
  35714. var duplicate = viewer.scene.profiles.find(profile => profile.uuid === data.uuid);
  35715. if (duplicate) {
  35716. return;
  35717. }
  35718. var profile = new Potree.Profile();
  35719. profile.name = name;
  35720. profile.uuid = data.uuid;
  35721. profile.setWidth(data.width);
  35722. for (var point of points) {
  35723. profile.addMarker(new Vector3(...point));
  35724. }
  35725. viewer.scene.addProfile(profile);
  35726. }
  35727. function loadClassification(viewer, data) {
  35728. if (!data) {
  35729. return;
  35730. }
  35731. var classifications = data;
  35732. viewer.setClassifications(classifications);
  35733. }
  35734. async function loadProject(viewer, data) {
  35735. if (data.type !== "Potree") {
  35736. console.error("not a valid Potree project");
  35737. return;
  35738. }
  35739. loadSettings(viewer, data.settings);
  35740. loadView(viewer, data.view);
  35741. var pointcloudPromises = [];
  35742. for (var pointcloud of data.pointclouds) {
  35743. var promise = loadPointCloud(viewer, pointcloud);
  35744. pointcloudPromises.push(promise);
  35745. }
  35746. for (var measure of data.measurements) {
  35747. loadMeasurement(viewer, measure);
  35748. }
  35749. for (var volume of data.volumes) {
  35750. loadVolume(viewer, volume);
  35751. }
  35752. for (var animation of data.cameraAnimations) {
  35753. loadCameraAnimation(viewer, animation);
  35754. }
  35755. for (var profile of data.profiles) {
  35756. loadProfile(viewer, profile);
  35757. }
  35758. if (data.orientedImages) {
  35759. for (var images of data.orientedImages) {
  35760. loadOrientedImages(viewer, images);
  35761. }
  35762. }
  35763. loadAnnotations(viewer, data.annotations);
  35764. loadClassification(viewer, data.classification);
  35765. // need to load at least one point cloud that defines the scene projection,
  35766. // before we can load stuff in other projections such as geopackages
  35767. //await Promise.any(pointcloudPromises); // (not yet supported)
  35768. Utils.waitAny(pointcloudPromises).then(() => {
  35769. if (data.geopackages) {
  35770. for (var geopackage of data.geopackages) {
  35771. loadGeopackage(viewer, geopackage);
  35772. }
  35773. }
  35774. });
  35775. await Promise.all(pointcloudPromises);
  35776. }
  35777. //
  35778. // Algorithm by Christian Boucheny
  35779. // shader code taken and adapted from CloudCompare
  35780. //
  35781. // see
  35782. // https://github.com/cloudcompare/trunk/tree/master/plugins/qEDL/shaders/EDL
  35783. // http://www.kitware.com/source/home/post/9
  35784. // https://tel.archives-ouvertes.fr/tel-00438464/document p. 115+ (french)
  35785. class EyeDomeLightingMaterial extends RawShaderMaterial {
  35786. //base
  35787. constructor() {
  35788. var parameters = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  35789. super();
  35790. var uniforms = {
  35791. screenWidth: {
  35792. type: 'f',
  35793. value: 0
  35794. },
  35795. screenHeight: {
  35796. type: 'f',
  35797. value: 0
  35798. },
  35799. edlStrength: {
  35800. type: 'f',
  35801. value: 1.0
  35802. },
  35803. uNear: {
  35804. type: 'f',
  35805. value: 1.0
  35806. },
  35807. uFar: {
  35808. type: 'f',
  35809. value: 1.0
  35810. },
  35811. radius: {
  35812. type: 'f',
  35813. value: 1.0
  35814. },
  35815. neighbours: {
  35816. type: '2fv',
  35817. value: []
  35818. },
  35819. depthMap: {
  35820. type: 't',
  35821. value: null
  35822. },
  35823. uEDLColor: {
  35824. type: 't',
  35825. value: null
  35826. },
  35827. uEDLDepth: {
  35828. type: 't',
  35829. value: null
  35830. },
  35831. opacity: {
  35832. type: 'f',
  35833. value: 1.0
  35834. },
  35835. uProj: {
  35836. type: "Matrix4fv",
  35837. value: []
  35838. }
  35839. };
  35840. this.setValues({
  35841. uniforms: uniforms,
  35842. vertexShader: this.getDefines() + Shaders['edl.vs'],
  35843. fragmentShader: this.getDefines() + Shaders['edl.fs'],
  35844. lights: false
  35845. });
  35846. this.neighbourCount = 8;
  35847. }
  35848. getDefines() {
  35849. var defines = '';
  35850. defines += '#define NEIGHBOUR_COUNT ' + this.neighbourCount + '\n';
  35851. return defines;
  35852. }
  35853. updateShaderSource() {
  35854. var vs = this.getDefines() + Shaders['edl.vs'];
  35855. var fs = this.getDefines() + Shaders['edl.fs'];
  35856. this.setValues({
  35857. vertexShader: vs,
  35858. fragmentShader: fs
  35859. });
  35860. this.uniforms.neighbours.value = this.neighbours;
  35861. this.needsUpdate = true;
  35862. }
  35863. get neighbourCount() {
  35864. return this._neighbourCount;
  35865. }
  35866. set neighbourCount(value) {
  35867. if (this._neighbourCount !== value) {
  35868. //周围八个格子
  35869. this._neighbourCount = value;
  35870. this.neighbours = new Float32Array(this._neighbourCount * 2);
  35871. for (var c = 0; c < this._neighbourCount; c++) {
  35872. this.neighbours[2 * c + 0] = Math.cos(2 * c * Math.PI / this._neighbourCount);
  35873. this.neighbours[2 * c + 1] = Math.sin(2 * c * Math.PI / this._neighbourCount);
  35874. }
  35875. this.updateShaderSource();
  35876. }
  35877. }
  35878. }
  35879. /**
  35880. * laslaz code taken and adapted from plas.io js-laslaz
  35881. * http://plas.io/
  35882. * https://github.com/verma/plasio
  35883. *
  35884. * Thanks to Uday Verma and Howard Butler
  35885. *
  35886. */
  35887. class LasLazLoader {
  35888. constructor(version, extension) {
  35889. if (typeof version === 'string') {
  35890. this.version = new Version(version);
  35891. } else {
  35892. this.version = version;
  35893. }
  35894. this.extension = extension;
  35895. }
  35896. static progressCB() {}
  35897. load(node, callback) {
  35898. if (node.loaded) {
  35899. return;
  35900. }
  35901. var url = node.getURL();
  35902. if (this.version.equalOrHigher('1.4')) {
  35903. url += ".".concat(this.extension);
  35904. }
  35905. var xhr = XHRFactory.createXMLHttpRequest();
  35906. xhr.open('GET', url, true);
  35907. xhr.responseType = 'arraybuffer';
  35908. xhr.overrideMimeType('text/plain; charset=x-user-defined');
  35909. xhr.onreadystatechange = () => {
  35910. if (xhr.readyState === 4) {
  35911. if (xhr.status === 200 || xhr.status === 0) {
  35912. var buffer = xhr.response;
  35913. this.parse(node, buffer, callback);
  35914. } else {
  35915. console.log('Failed to load file! HTTP status: ' + xhr.status + ', file: ' + url);
  35916. }
  35917. }
  35918. };
  35919. xhr.send(null);
  35920. }
  35921. async parse(node, buffer, callback) {
  35922. //add callback
  35923. var lf = new LASFile(buffer);
  35924. var handler = new LasLazBatcher(node);
  35925. try {
  35926. await lf.open();
  35927. lf.isOpen = true;
  35928. } catch (e) {
  35929. console.log("failed to open file. :(");
  35930. return;
  35931. }
  35932. var header = await lf.getHeader();
  35933. var skip = 1;
  35934. var totalRead = 0;
  35935. var totalToRead = skip <= 1 ? header.pointsCount : header.pointsCount / skip;
  35936. var hasMoreData = true;
  35937. while (hasMoreData) {
  35938. var data = await lf.readData(1000 * 1000, 0, skip);
  35939. handler.push(new LASDecoder(data.buffer, header.pointsFormatId, header.pointsStructSize, data.count, header.scale, header.offset, header.mins, header.maxs));
  35940. totalRead += data.count;
  35941. LasLazLoader.progressCB(totalRead / totalToRead);
  35942. hasMoreData = data.hasMoreData;
  35943. }
  35944. header.totalRead = totalRead;
  35945. header.versionAsString = lf.versionAsString;
  35946. header.isCompressed = lf.isCompressed;
  35947. LasLazLoader.progressCB(1);
  35948. try {
  35949. await lf.close();
  35950. lf.isOpen = false;
  35951. } catch (e) {
  35952. console.error("failed to close las/laz file!!!");
  35953. throw e;
  35954. }
  35955. callback(); //add
  35956. }
  35957. handle(node, url) {}
  35958. }
  35959. ;
  35960. class LasLazBatcher {
  35961. constructor(node) {
  35962. this.node = node;
  35963. }
  35964. push(lasBuffer) {
  35965. var workerPath = Potree.scriptPath + '/workers/LASDecoderWorker.js';
  35966. var worker = Potree.workerPool.getWorker(workerPath);
  35967. var node = this.node;
  35968. var pointAttributes = node.pcoGeometry.pointAttributes;
  35969. worker.onmessage = e => {
  35970. var geometry = new BufferGeometry();
  35971. var numPoints = lasBuffer.pointsCount;
  35972. var positions = new Float32Array(e.data.position);
  35973. var colors = new Uint8Array(e.data.color);
  35974. var intensities = new Float32Array(e.data.intensity);
  35975. var classifications = new Uint8Array(e.data.classification);
  35976. var returnNumbers = new Uint8Array(e.data.returnNumber);
  35977. var numberOfReturns = new Uint8Array(e.data.numberOfReturns);
  35978. var pointSourceIDs = new Uint16Array(e.data.pointSourceID);
  35979. var indices = new Uint8Array(e.data.indices);
  35980. geometry.setAttribute('position', new BufferAttribute(positions, 3));
  35981. geometry.setAttribute('color', new BufferAttribute(colors, 4, true));
  35982. geometry.setAttribute('intensity', new BufferAttribute(intensities, 1));
  35983. geometry.setAttribute('classification', new BufferAttribute(classifications, 1));
  35984. geometry.setAttribute('return number', new BufferAttribute(returnNumbers, 1));
  35985. geometry.setAttribute('number of returns', new BufferAttribute(numberOfReturns, 1));
  35986. geometry.setAttribute('source id', new BufferAttribute(pointSourceIDs, 1));
  35987. geometry.setAttribute('indices', new BufferAttribute(indices, 4));
  35988. geometry.attributes.indices.normalized = true;
  35989. var _loop = function _loop(key) {
  35990. var range = e.data.ranges[key];
  35991. var attribute = pointAttributes.attributes.find(a => a.name === key);
  35992. attribute.range[0] = Math.min(attribute.range[0], range[0]);
  35993. attribute.range[1] = Math.max(attribute.range[1], range[1]);
  35994. };
  35995. for (var key in e.data.ranges) {
  35996. _loop(key);
  35997. }
  35998. var tightBoundingBox = new Box3(new Vector3().fromArray(e.data.tightBoundingBox.min), new Vector3().fromArray(e.data.tightBoundingBox.max));
  35999. geometry.boundingBox = this.node.boundingBox;
  36000. this.node.tightBoundingBox = tightBoundingBox;
  36001. this.node.geometry = geometry;
  36002. this.node.numPoints = numPoints;
  36003. this.node.loaded = true;
  36004. this.node.loading = false;
  36005. Potree.numNodesLoading--;
  36006. this.node.mean = new Vector3(...e.data.mean);
  36007. Potree.workerPool.returnWorker(workerPath, worker);
  36008. };
  36009. var message = {
  36010. buffer: lasBuffer.arrayb,
  36011. numPoints: lasBuffer.pointsCount,
  36012. pointSize: lasBuffer.pointSize,
  36013. pointFormatID: 2,
  36014. scale: lasBuffer.scale,
  36015. offset: lasBuffer.offset,
  36016. mins: lasBuffer.mins,
  36017. maxs: lasBuffer.maxs
  36018. };
  36019. worker.postMessage(message, [message.buffer]);
  36020. }
  36021. }
  36022. function parseAttributes(cloudjs) {
  36023. var version = new Version(cloudjs.version);
  36024. var replacements = {
  36025. "COLOR_PACKED": "rgba",
  36026. "RGBA": "rgba",
  36027. "INTENSITY": "intensity",
  36028. "CLASSIFICATION": "classification",
  36029. "GPS_TIME": "gps-time"
  36030. };
  36031. var replaceOldNames = old => {
  36032. if (replacements[old]) {
  36033. return replacements[old];
  36034. } else {
  36035. return old;
  36036. }
  36037. };
  36038. var pointAttributes = [];
  36039. if (version.upTo('1.7')) {
  36040. for (var attributeName of cloudjs.pointAttributes) {
  36041. var oldAttribute = PointAttribute[attributeName];
  36042. var attribute = {
  36043. name: oldAttribute.name,
  36044. size: oldAttribute.byteSize,
  36045. elements: oldAttribute.numElements,
  36046. elementSize: oldAttribute.byteSize / oldAttribute.numElements,
  36047. type: oldAttribute.type.name,
  36048. description: ""
  36049. };
  36050. pointAttributes.push(attribute);
  36051. }
  36052. } else {
  36053. pointAttributes.push(...cloudjs.pointAttributes);
  36054. }
  36055. {
  36056. var attributes = new PointAttributes();
  36057. var typeConversion = {
  36058. int8: PointAttributeTypes.DATA_TYPE_INT8,
  36059. int16: PointAttributeTypes.DATA_TYPE_INT16,
  36060. int32: PointAttributeTypes.DATA_TYPE_INT32,
  36061. int64: PointAttributeTypes.DATA_TYPE_INT64,
  36062. uint8: PointAttributeTypes.DATA_TYPE_UINT8,
  36063. uint16: PointAttributeTypes.DATA_TYPE_UINT16,
  36064. uint32: PointAttributeTypes.DATA_TYPE_UINT32,
  36065. uint64: PointAttributeTypes.DATA_TYPE_UINT64,
  36066. double: PointAttributeTypes.DATA_TYPE_DOUBLE,
  36067. float: PointAttributeTypes.DATA_TYPE_FLOAT
  36068. };
  36069. for (var jsAttribute of pointAttributes) {
  36070. if (jsAttribute.name == void 0) {
  36071. //add 有的是这个,也有的不是(点云编辑页的)
  36072. var attribute_ = PointAttribute[jsAttribute];
  36073. attributes.add(attribute_);
  36074. continue;
  36075. }
  36076. var name = replaceOldNames(jsAttribute.name);
  36077. var type = typeConversion[jsAttribute.type];
  36078. var numElements = jsAttribute.elements;
  36079. var description = jsAttribute.description;
  36080. var _attribute = new PointAttribute(name, type, numElements);
  36081. attributes.add(_attribute);
  36082. }
  36083. {
  36084. // check if it has normals
  36085. var hasNormals = pointAttributes.find(a => a.name === "NormalX") !== undefined && pointAttributes.find(a => a.name === "NormalY") !== undefined && pointAttributes.find(a => a.name === "NormalZ") !== undefined;
  36086. if (hasNormals) {
  36087. var vector = {
  36088. name: "NORMAL",
  36089. attributes: ["NormalX", "NormalY", "NormalZ"]
  36090. };
  36091. attributes.addVector(vector);
  36092. }
  36093. }
  36094. return attributes;
  36095. }
  36096. }
  36097. function lasLazAttributes(fMno) {
  36098. var attributes = new PointAttributes();
  36099. attributes.add(PointAttribute.POSITION_CARTESIAN);
  36100. attributes.add(new PointAttribute("rgba", PointAttributeTypes.DATA_TYPE_UINT8, 4));
  36101. attributes.add(new PointAttribute("intensity", PointAttributeTypes.DATA_TYPE_UINT16, 1));
  36102. attributes.add(new PointAttribute("classification", PointAttributeTypes.DATA_TYPE_UINT8, 1));
  36103. attributes.add(new PointAttribute("gps-time", PointAttributeTypes.DATA_TYPE_DOUBLE, 1));
  36104. attributes.add(new PointAttribute("number of returns", PointAttributeTypes.DATA_TYPE_UINT8, 1));
  36105. attributes.add(new PointAttribute("return number", PointAttributeTypes.DATA_TYPE_UINT8, 1));
  36106. attributes.add(new PointAttribute("source id", PointAttributeTypes.DATA_TYPE_UINT16, 1));
  36107. //attributes.add(new PointAttribute("pointSourceID", PointAttributeTypes.DATA_TYPE_INT8, 4));
  36108. return attributes;
  36109. }
  36110. class POCLoader {
  36111. static load(url, timeStamp, callback) {
  36112. //add timeStamp
  36113. try {
  36114. var pco = new PointCloudOctreeGeometry();
  36115. pco.timeStamp = timeStamp;
  36116. pco.url = url;
  36117. var xhr = XHRFactory.createXMLHttpRequest();
  36118. xhr.open('GET', url + '?m=' + timeStamp, true);
  36119. xhr.onreadystatechange = function () {
  36120. if (xhr.readyState === 4 && (xhr.status === 200 || xhr.status === 0)) {
  36121. var fMno = JSON.parse(xhr.responseText);
  36122. var version = new Version(fMno.version);
  36123. // assume octreeDir is absolute if it starts with http
  36124. if (fMno.octreeDir.indexOf('http') === 0) {
  36125. pco.octreeDir = fMno.octreeDir;
  36126. } else {
  36127. pco.octreeDir = url + '/../' + fMno.octreeDir;
  36128. }
  36129. pco.spacing = fMno.spacing;
  36130. pco.hierarchyStepSize = fMno.hierarchyStepSize;
  36131. pco.pointAttributes = fMno.pointAttributes;
  36132. var min = new Vector3(fMno.boundingBox.lx, fMno.boundingBox.ly, fMno.boundingBox.lz);
  36133. var max = new Vector3(fMno.boundingBox.ux, fMno.boundingBox.uy, fMno.boundingBox.uz);
  36134. var boundingBox = new Box3(min, max);
  36135. var tightBoundingBox = boundingBox.clone();
  36136. if (fMno.tightBoundingBox) {
  36137. //这个才是真实的bounding,前面那个bounding的size是个正方体,似乎取了最长边作为边长
  36138. tightBoundingBox.min.copy(new Vector3(fMno.tightBoundingBox.lx, fMno.tightBoundingBox.ly, fMno.tightBoundingBox.lz));
  36139. tightBoundingBox.max.copy(new Vector3(fMno.tightBoundingBox.ux, fMno.tightBoundingBox.uy, fMno.tightBoundingBox.uz));
  36140. }
  36141. var offset = min.clone(); //将成为点云的position,被我用作旋转中心(但在点云中不那么居中,navvis也是这样, 这样可能是为了让模型在这数据的bounding上)
  36142. boundingBox.min.sub(offset); //点云的真实坐标的min都是0,0,0吗(我看案例是,因绕角落旋转,也就是原点)
  36143. boundingBox.max.sub(offset);
  36144. tightBoundingBox.min.sub(offset);
  36145. tightBoundingBox.max.sub(offset);
  36146. //改
  36147. //pco.projection = fMno.projection || "+proj=somerc +lat_0=46.95240555555556 +lon_0=7.439583333333333 +k_0=1 +x_0=2600000 +y_0=1200000 +ellps=bessel +towgs84=674.374,15.056,405.346,0,0,0,0 +units=m +no_defs ",
  36148. //"+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs" //给地图
  36149. pco.boundingBox = boundingBox;
  36150. pco.tightBoundingBox = tightBoundingBox;
  36151. pco.boundingSphere = boundingBox.getBoundingSphere(new Sphere());
  36152. pco.tightBoundingSphere = tightBoundingBox.getBoundingSphere(new Sphere());
  36153. pco.offset = offset;
  36154. if (fMno.pointAttributes === 'LAS') {
  36155. pco.loader = new LasLazLoader(fMno.version, "las");
  36156. pco.pointAttributes = lasLazAttributes(fMno);
  36157. } else if (fMno.pointAttributes === 'LAZ') {
  36158. pco.loader = new LasLazLoader(fMno.version, "laz");
  36159. pco.pointAttributes = lasLazAttributes(fMno);
  36160. } else {
  36161. pco.loader = new BinaryLoader(fMno.version, boundingBox, fMno.scale);
  36162. pco.pointAttributes = parseAttributes(fMno);
  36163. }
  36164. var nodes = {};
  36165. {
  36166. // load root
  36167. var name = 'r';
  36168. var root = new PointCloudOctreeGeometryNode(name, pco, boundingBox);
  36169. root.level = 0;
  36170. root.hasChildren = true;
  36171. root.spacing = pco.spacing;
  36172. if (version.upTo('1.5')) {
  36173. root.numPoints = fMno.hierarchy[0][1];
  36174. } else {
  36175. root.numPoints = 0;
  36176. }
  36177. pco.root = root;
  36178. pco.root.load();
  36179. nodes[name] = root;
  36180. }
  36181. // load remaining hierarchy
  36182. if (version.upTo('1.4')) {
  36183. for (var i = 1; i < fMno.hierarchy.length; i++) {
  36184. var _name = fMno.hierarchy[i][0];
  36185. var numPoints = fMno.hierarchy[i][1];
  36186. var index = parseInt(_name.charAt(_name.length - 1));
  36187. var parentName = _name.substring(0, _name.length - 1);
  36188. var parentNode = nodes[parentName];
  36189. var level = _name.length - 1;
  36190. //let boundingBox = POCLoader.createChildAABB(parentNode.boundingBox, index);
  36191. var _boundingBox = Utils.createChildAABB(parentNode.boundingBox, index);
  36192. var node = new PointCloudOctreeGeometryNode(_name, pco, _boundingBox);
  36193. node.level = level;
  36194. node.numPoints = numPoints;
  36195. node.spacing = pco.spacing / Math.pow(2, level);
  36196. parentNode.addChild(node);
  36197. nodes[_name] = node;
  36198. }
  36199. }
  36200. pco.nodes = nodes;
  36201. callback(pco);
  36202. }
  36203. };
  36204. xhr.send(null);
  36205. } catch (e) {
  36206. console.log("loading failed: '" + url + "'");
  36207. console.log(e);
  36208. callback();
  36209. }
  36210. }
  36211. loadPointAttributes(mno) {
  36212. var fpa = mno.pointAttributes;
  36213. var pa = new PointAttributes();
  36214. for (var i = 0; i < fpa.length; i++) {
  36215. var pointAttribute = PointAttribute[fpa[i]];
  36216. pa.add(pointAttribute);
  36217. }
  36218. return pa;
  36219. }
  36220. createChildAABB(aabb, index) {
  36221. var min = aabb.min.clone();
  36222. var max = aabb.max.clone();
  36223. var size = new Vector3().subVectors(max, min);
  36224. if ((index & 0b0001) > 0) {
  36225. min.z += size.z / 2;
  36226. } else {
  36227. max.z -= size.z / 2;
  36228. }
  36229. if ((index & 0b0010) > 0) {
  36230. min.y += size.y / 2;
  36231. } else {
  36232. max.y -= size.y / 2;
  36233. }
  36234. if ((index & 0b0100) > 0) {
  36235. min.x += size.x / 2;
  36236. } else {
  36237. max.x -= size.x / 2;
  36238. }
  36239. return new Box3(min, max);
  36240. }
  36241. }
  36242. class OctreeGeometry {
  36243. constructor() {
  36244. this.url = null;
  36245. this.spacing = 0;
  36246. this.boundingBox = null;
  36247. this.root = null;
  36248. this.pointAttributes = null;
  36249. this.loader = null;
  36250. }
  36251. }
  36252. ;
  36253. class OctreeGeometryNode {
  36254. constructor(name, octreeGeometry, boundingBox) {
  36255. this.id = OctreeGeometryNode.IDCount++;
  36256. this.name = name;
  36257. this.index = parseInt(name.charAt(name.length - 1));
  36258. this.octreeGeometry = octreeGeometry;
  36259. this.boundingBox = boundingBox;
  36260. this.boundingSphere = boundingBox.getBoundingSphere(new Sphere());
  36261. this.children = {};
  36262. this.numPoints = 0;
  36263. this.level = null;
  36264. this.oneTimeDisposeHandlers = [];
  36265. }
  36266. isGeometryNode() {
  36267. return true;
  36268. }
  36269. getLevel() {
  36270. return this.level;
  36271. }
  36272. isTreeNode() {
  36273. return false;
  36274. }
  36275. isLoaded() {
  36276. return this.loaded;
  36277. }
  36278. getBoundingSphere() {
  36279. return this.boundingSphere;
  36280. }
  36281. getBoundingBox() {
  36282. return this.boundingBox;
  36283. }
  36284. getChildren() {
  36285. var children = [];
  36286. for (var i = 0; i < 8; i++) {
  36287. if (this.children[i]) {
  36288. children.push(this.children[i]);
  36289. }
  36290. }
  36291. return children;
  36292. }
  36293. getBoundingBox() {
  36294. return this.boundingBox;
  36295. }
  36296. load() {
  36297. if (Potree.numNodesLoading >= Potree.maxNodesLoading) {
  36298. return;
  36299. }
  36300. this.octreeGeometry.loader.load(this);
  36301. }
  36302. getNumPoints() {
  36303. return this.numPoints;
  36304. }
  36305. dispose() {
  36306. if (this.geometry && this.parent != null) {
  36307. this.geometry.dispose();
  36308. this.geometry = null;
  36309. this.loaded = false;
  36310. // this.dispatchEvent( { type: 'dispose' } );
  36311. for (var i = 0; i < this.oneTimeDisposeHandlers.length; i++) {
  36312. var handler = this.oneTimeDisposeHandlers[i];
  36313. handler();
  36314. }
  36315. this.oneTimeDisposeHandlers = [];
  36316. }
  36317. }
  36318. }
  36319. ;
  36320. OctreeGeometryNode.IDCount = 0;
  36321. // let loadedNodes = new Set();
  36322. class NodeLoader {
  36323. constructor(url) {
  36324. this.url = url;
  36325. }
  36326. async load(node) {
  36327. if (node.loaded || node.loading) {
  36328. return;
  36329. }
  36330. node.loading = true;
  36331. Potree.numNodesLoading++;
  36332. // console.log(node.name, node.numPoints);
  36333. // if(loadedNodes.has(node.name)){
  36334. // // debugger;
  36335. // }
  36336. // loadedNodes.add(node.name);
  36337. try {
  36338. if (node.nodeType === 2) {
  36339. await this.loadHierarchy(node);
  36340. }
  36341. var {
  36342. byteOffset,
  36343. byteSize
  36344. } = node;
  36345. var urlOctree = "".concat(this.url, "/../octree.bin");
  36346. var first = byteOffset;
  36347. var last = byteOffset + byteSize - 1n;
  36348. var buffer;
  36349. if (byteSize === 0n) {
  36350. buffer = new ArrayBuffer(0);
  36351. console.warn("loaded node with 0 bytes: ".concat(node.name));
  36352. } else {
  36353. var response = await fetch(urlOctree, {
  36354. headers: {
  36355. 'content-type': 'multipart/byteranges',
  36356. 'Range': "bytes=".concat(first, "-").concat(last)
  36357. }
  36358. });
  36359. buffer = await response.arrayBuffer();
  36360. }
  36361. var workerPath;
  36362. if (this.metadata.encoding === "BROTLI") {
  36363. workerPath = Potree.scriptPath + '/workers/2.0/DecoderWorker_brotli.js';
  36364. } else {
  36365. workerPath = Potree.scriptPath + '/workers/2.0/DecoderWorker.js';
  36366. }
  36367. var worker = Potree.workerPool.getWorker(workerPath);
  36368. worker.onmessage = function (e) {
  36369. var data = e.data;
  36370. var buffers = data.attributeBuffers;
  36371. Potree.workerPool.returnWorker(workerPath, worker);
  36372. var geometry = new BufferGeometry();
  36373. for (var property in buffers) {
  36374. var _buffer = buffers[property].buffer;
  36375. if (property === "position") {
  36376. geometry.setAttribute('position', new BufferAttribute(new Float32Array(_buffer), 3));
  36377. } else if (property === "rgba") {
  36378. geometry.setAttribute('rgba', new BufferAttribute(new Uint8Array(_buffer), 4, true));
  36379. } else if (property === "NORMAL") {
  36380. //geometry.setAttribute('rgba', new THREE.BufferAttribute(new Uint8Array(buffer), 4, true));
  36381. geometry.setAttribute('normal', new BufferAttribute(new Float32Array(_buffer), 3));
  36382. } else if (property === "INDICES") {
  36383. var bufferAttribute = new BufferAttribute(new Uint8Array(_buffer), 4);
  36384. bufferAttribute.normalized = true;
  36385. geometry.setAttribute('indices', bufferAttribute);
  36386. } else {
  36387. var _bufferAttribute = new BufferAttribute(new Float32Array(_buffer), 1);
  36388. var batchAttribute = buffers[property].attribute;
  36389. _bufferAttribute.potree = {
  36390. offset: buffers[property].offset,
  36391. scale: buffers[property].scale,
  36392. preciseBuffer: buffers[property].preciseBuffer,
  36393. range: batchAttribute.range
  36394. };
  36395. geometry.setAttribute(property, _bufferAttribute);
  36396. }
  36397. }
  36398. // indices ??
  36399. node.density = data.density;
  36400. node.geometry = geometry;
  36401. node.loaded = true;
  36402. node.loading = false;
  36403. Potree.numNodesLoading--;
  36404. };
  36405. var pointAttributes = node.octreeGeometry.pointAttributes;
  36406. var scale = node.octreeGeometry.scale;
  36407. var box = node.boundingBox;
  36408. var min = node.octreeGeometry.offset.clone().add(box.min);
  36409. var size = box.max.clone().sub(box.min);
  36410. var max = min.clone().add(size);
  36411. var numPoints = node.numPoints;
  36412. var offset = node.octreeGeometry.loader.offset;
  36413. var message = {
  36414. name: node.name,
  36415. buffer: buffer,
  36416. pointAttributes: pointAttributes,
  36417. scale: scale,
  36418. min: min,
  36419. max: max,
  36420. size: size,
  36421. offset: offset,
  36422. numPoints: numPoints
  36423. };
  36424. worker.postMessage(message, [message.buffer]);
  36425. } catch (e) {
  36426. node.loaded = false;
  36427. node.loading = false;
  36428. Potree.numNodesLoading--;
  36429. console.log("failed to load ".concat(node.name));
  36430. console.log(e);
  36431. console.log("trying again!");
  36432. }
  36433. }
  36434. parseHierarchy(node, buffer) {
  36435. var view = new DataView(buffer);
  36436. var tStart = performance.now();
  36437. var bytesPerNode = 22;
  36438. var numNodes = buffer.byteLength / bytesPerNode;
  36439. var octree = node.octreeGeometry;
  36440. // let nodes = [node];
  36441. var nodes = new Array(numNodes);
  36442. nodes[0] = node;
  36443. var nodePos = 1;
  36444. for (var i = 0; i < numNodes; i++) {
  36445. var current = nodes[i];
  36446. var type = view.getUint8(i * bytesPerNode + 0);
  36447. var childMask = view.getUint8(i * bytesPerNode + 1);
  36448. var numPoints = view.getUint32(i * bytesPerNode + 2, true);
  36449. var byteOffset = view.getBigInt64(i * bytesPerNode + 6, true);
  36450. var byteSize = view.getBigInt64(i * bytesPerNode + 14, true);
  36451. // if(byteSize === 0n){
  36452. // // debugger;
  36453. // }
  36454. if (current.nodeType === 2) {
  36455. // replace proxy with real node
  36456. current.byteOffset = byteOffset;
  36457. current.byteSize = byteSize;
  36458. current.numPoints = numPoints;
  36459. } else if (type === 2) {
  36460. // load proxy
  36461. current.hierarchyByteOffset = byteOffset;
  36462. current.hierarchyByteSize = byteSize;
  36463. current.numPoints = numPoints;
  36464. } else {
  36465. // load real node
  36466. current.byteOffset = byteOffset;
  36467. current.byteSize = byteSize;
  36468. current.numPoints = numPoints;
  36469. }
  36470. if (current.byteSize === 0n) {
  36471. // workaround for issue #1125
  36472. // some inner nodes erroneously report >0 points even though have 0 points
  36473. // however, they still report a byteSize of 0, so based on that we now set node.numPoints to 0
  36474. current.numPoints = 0;
  36475. }
  36476. current.nodeType = type;
  36477. if (current.nodeType === 2) {
  36478. continue;
  36479. }
  36480. for (var childIndex = 0; childIndex < 8; childIndex++) {
  36481. var childExists = (1 << childIndex & childMask) !== 0;
  36482. if (!childExists) {
  36483. continue;
  36484. }
  36485. var childName = current.name + childIndex;
  36486. var childAABB = createChildAABB(current.boundingBox, childIndex);
  36487. var child = new OctreeGeometryNode(childName, octree, childAABB);
  36488. child.name = childName;
  36489. child.spacing = current.spacing / 2;
  36490. child.level = current.level + 1;
  36491. current.children[childIndex] = child;
  36492. child.parent = current;
  36493. // nodes.push(child);
  36494. nodes[nodePos] = child;
  36495. nodePos++;
  36496. }
  36497. // if((i % 500) === 0){
  36498. // yield;
  36499. // }
  36500. }
  36501. var duration = performance.now() - tStart;
  36502. // if(duration > 20){
  36503. // let msg = `duration: ${duration}ms, numNodes: ${numNodes}`;
  36504. // console.log(msg);
  36505. // }
  36506. }
  36507. async loadHierarchy(node) {
  36508. var {
  36509. hierarchyByteOffset,
  36510. hierarchyByteSize
  36511. } = node;
  36512. var hierarchyPath = "".concat(this.url, "/../hierarchy.bin");
  36513. var first = hierarchyByteOffset;
  36514. var last = first + hierarchyByteSize - 1n;
  36515. var response = await fetch(hierarchyPath, {
  36516. headers: {
  36517. 'content-type': 'multipart/byteranges',
  36518. 'Range': "bytes=".concat(first, "-").concat(last)
  36519. }
  36520. });
  36521. var buffer = await response.arrayBuffer();
  36522. this.parseHierarchy(node, buffer);
  36523. // let promise = new Promise((resolve) => {
  36524. // let generator = this.parseHierarchy(node, buffer);
  36525. // let repeatUntilDone = () => {
  36526. // let result = generator.next();
  36527. // if(result.done){
  36528. // resolve();
  36529. // }else{
  36530. // requestAnimationFrame(repeatUntilDone);
  36531. // }
  36532. // };
  36533. // repeatUntilDone();
  36534. // });
  36535. // await promise;
  36536. }
  36537. }
  36538. var tmpVec3 = new Vector3();
  36539. function createChildAABB(aabb, index) {
  36540. var min = aabb.min.clone();
  36541. var max = aabb.max.clone();
  36542. var size = tmpVec3.subVectors(max, min);
  36543. if ((index & 0b0001) > 0) {
  36544. min.z += size.z / 2;
  36545. } else {
  36546. max.z -= size.z / 2;
  36547. }
  36548. if ((index & 0b0010) > 0) {
  36549. min.y += size.y / 2;
  36550. } else {
  36551. max.y -= size.y / 2;
  36552. }
  36553. if ((index & 0b0100) > 0) {
  36554. min.x += size.x / 2;
  36555. } else {
  36556. max.x -= size.x / 2;
  36557. }
  36558. return new Box3(min, max);
  36559. }
  36560. var typenameTypeattributeMap = {
  36561. "double": PointAttributeTypes.DATA_TYPE_DOUBLE,
  36562. "float": PointAttributeTypes.DATA_TYPE_FLOAT,
  36563. "int8": PointAttributeTypes.DATA_TYPE_INT8,
  36564. "uint8": PointAttributeTypes.DATA_TYPE_UINT8,
  36565. "int16": PointAttributeTypes.DATA_TYPE_INT16,
  36566. "uint16": PointAttributeTypes.DATA_TYPE_UINT16,
  36567. "int32": PointAttributeTypes.DATA_TYPE_INT32,
  36568. "uint32": PointAttributeTypes.DATA_TYPE_UINT32,
  36569. "int64": PointAttributeTypes.DATA_TYPE_INT64,
  36570. "uint64": PointAttributeTypes.DATA_TYPE_UINT64
  36571. };
  36572. class OctreeLoader {
  36573. static parseAttributes(jsonAttributes) {
  36574. var attributes = new PointAttributes();
  36575. var replacements = {
  36576. "rgb": "rgba"
  36577. };
  36578. for (var jsonAttribute of jsonAttributes) {
  36579. var {
  36580. name,
  36581. description,
  36582. size,
  36583. numElements,
  36584. elementSize,
  36585. min,
  36586. max
  36587. } = jsonAttribute;
  36588. var type = typenameTypeattributeMap[jsonAttribute.type];
  36589. var potreeAttributeName = replacements[name] ? replacements[name] : name;
  36590. var attribute = new PointAttribute(potreeAttributeName, type, numElements);
  36591. if (numElements === 1) {
  36592. attribute.range = [min[0], max[0]];
  36593. } else {
  36594. attribute.range = [min, max];
  36595. }
  36596. if (name === "gps-time") {
  36597. // HACK: Guard against bad gpsTime range in metadata, see potree/potree#909
  36598. if (attribute.range[0] === attribute.range[1]) {
  36599. attribute.range[1] += 1;
  36600. }
  36601. }
  36602. attribute.initialRange = attribute.range;
  36603. attributes.add(attribute);
  36604. }
  36605. {
  36606. // check if it has normals
  36607. var hasNormals = attributes.attributes.find(a => a.name === "NormalX") !== undefined && attributes.attributes.find(a => a.name === "NormalY") !== undefined && attributes.attributes.find(a => a.name === "NormalZ") !== undefined;
  36608. if (hasNormals) {
  36609. var vector = {
  36610. name: "NORMAL",
  36611. attributes: ["NormalX", "NormalY", "NormalZ"]
  36612. };
  36613. attributes.addVector(vector);
  36614. }
  36615. }
  36616. return attributes;
  36617. }
  36618. static async load(url) {
  36619. var response = await fetch(url);
  36620. var metadata = await response.json();
  36621. var attributes = OctreeLoader.parseAttributes(metadata.attributes);
  36622. var loader = new NodeLoader(url);
  36623. loader.metadata = metadata;
  36624. loader.attributes = attributes;
  36625. loader.scale = metadata.scale;
  36626. loader.offset = metadata.offset;
  36627. var octree = new OctreeGeometry();
  36628. octree.url = url;
  36629. octree.spacing = metadata.spacing;
  36630. octree.scale = metadata.scale;
  36631. // let aPosition = metadata.attributes.find(a => a.name === "position");
  36632. // octree
  36633. var min = new Vector3(...metadata.boundingBox.min);
  36634. var max = new Vector3(...metadata.boundingBox.max);
  36635. var boundingBox = new Box3(min, max);
  36636. var offset = min.clone();
  36637. boundingBox.min.sub(offset);
  36638. boundingBox.max.sub(offset);
  36639. octree.projection = metadata.projection;
  36640. octree.boundingBox = boundingBox;
  36641. octree.tightBoundingBox = boundingBox.clone();
  36642. octree.boundingSphere = boundingBox.getBoundingSphere(new Sphere());
  36643. octree.tightBoundingSphere = boundingBox.getBoundingSphere(new Sphere());
  36644. octree.offset = offset;
  36645. octree.pointAttributes = OctreeLoader.parseAttributes(metadata.attributes);
  36646. octree.loader = loader;
  36647. var root = new OctreeGeometryNode("r", octree, boundingBox);
  36648. root.level = 0;
  36649. root.nodeType = 2;
  36650. root.hierarchyByteOffset = 0n;
  36651. root.hierarchyByteSize = BigInt(metadata.hierarchy.firstChunkSize);
  36652. root.hasChildren = false;
  36653. root.spacing = octree.spacing;
  36654. root.byteOffset = 0;
  36655. octree.root = root;
  36656. loader.load(root);
  36657. var result = {
  36658. geometry: octree
  36659. };
  36660. return result;
  36661. }
  36662. }
  36663. ;
  36664. /**
  36665. * @author Connor Manning
  36666. */
  36667. class EptLoader {
  36668. static async load(file, callback) {
  36669. var response = await fetch(file);
  36670. var json = await response.json();
  36671. var url = file.substr(0, file.lastIndexOf('ept.json'));
  36672. var geometry = new Potree.PointCloudEptGeometry(url, json);
  36673. var root = new Potree.PointCloudEptGeometryNode(geometry);
  36674. geometry.root = root;
  36675. geometry.root.load();
  36676. callback(geometry);
  36677. }
  36678. }
  36679. ;
  36680. class EptBinaryLoader {
  36681. extension() {
  36682. return '.bin';
  36683. }
  36684. workerPath() {
  36685. return Potree.scriptPath + '/workers/EptBinaryDecoderWorker.js';
  36686. }
  36687. load(node) {
  36688. if (node.loaded) return;
  36689. var url = node.url() + this.extension();
  36690. var xhr = XHRFactory.createXMLHttpRequest();
  36691. xhr.open('GET', url, true);
  36692. xhr.responseType = 'arraybuffer';
  36693. xhr.overrideMimeType('text/plain; charset=x-user-defined');
  36694. xhr.onreadystatechange = () => {
  36695. if (xhr.readyState === 4) {
  36696. if (xhr.status === 200) {
  36697. var buffer = xhr.response;
  36698. this.parse(node, buffer);
  36699. } else {
  36700. console.log('Failed ' + url + ': ' + xhr.status);
  36701. }
  36702. }
  36703. };
  36704. try {
  36705. xhr.send(null);
  36706. } catch (e) {
  36707. console.log('Failed request: ' + e);
  36708. }
  36709. }
  36710. parse(node, buffer) {
  36711. var workerPath = this.workerPath();
  36712. var worker = Potree.workerPool.getWorker(workerPath);
  36713. worker.onmessage = function (e) {
  36714. var g = new BufferGeometry();
  36715. var numPoints = e.data.numPoints;
  36716. var position = new Float32Array(e.data.position);
  36717. g.setAttribute('position', new BufferAttribute(position, 3));
  36718. var indices = new Uint8Array(e.data.indices);
  36719. g.setAttribute('indices', new BufferAttribute(indices, 4));
  36720. if (e.data.color) {
  36721. var color = new Uint8Array(e.data.color);
  36722. g.setAttribute('color', new BufferAttribute(color, 4, true));
  36723. }
  36724. if (e.data.intensity) {
  36725. var intensity = new Float32Array(e.data.intensity);
  36726. g.setAttribute('intensity', new BufferAttribute(intensity, 1));
  36727. }
  36728. if (e.data.classification) {
  36729. var classification = new Uint8Array(e.data.classification);
  36730. g.setAttribute('classification', new BufferAttribute(classification, 1));
  36731. }
  36732. if (e.data.returnNumber) {
  36733. var returnNumber = new Uint8Array(e.data.returnNumber);
  36734. g.setAttribute('return number', new BufferAttribute(returnNumber, 1));
  36735. }
  36736. if (e.data.numberOfReturns) {
  36737. var numberOfReturns = new Uint8Array(e.data.numberOfReturns);
  36738. g.setAttribute('number of returns', new BufferAttribute(numberOfReturns, 1));
  36739. }
  36740. if (e.data.pointSourceId) {
  36741. var pointSourceId = new Uint16Array(e.data.pointSourceId);
  36742. g.setAttribute('source id', new BufferAttribute(pointSourceId, 1));
  36743. }
  36744. g.attributes.indices.normalized = true;
  36745. var tightBoundingBox = new Box3(new Vector3().fromArray(e.data.tightBoundingBox.min), new Vector3().fromArray(e.data.tightBoundingBox.max));
  36746. node.doneLoading(g, tightBoundingBox, numPoints, new Vector3(...e.data.mean));
  36747. Potree.workerPool.returnWorker(workerPath, worker);
  36748. };
  36749. var toArray = v => [v.x, v.y, v.z];
  36750. var message = {
  36751. buffer: buffer,
  36752. schema: node.ept.schema,
  36753. scale: node.ept.eptScale,
  36754. offset: node.ept.eptOffset,
  36755. mins: toArray(node.key.b.min)
  36756. };
  36757. worker.postMessage(message, [message.buffer]);
  36758. }
  36759. }
  36760. ;
  36761. /**
  36762. * laslaz code taken and adapted from plas.io js-laslaz
  36763. * http://plas.io/
  36764. * https://github.com/verma/plasio
  36765. *
  36766. * Thanks to Uday Verma and Howard Butler
  36767. *
  36768. */
  36769. class EptLaszipLoader {
  36770. load(node) {
  36771. if (node.loaded) return;
  36772. var url = node.url() + '.laz';
  36773. var xhr = XHRFactory.createXMLHttpRequest();
  36774. xhr.open('GET', url, true);
  36775. xhr.responseType = 'arraybuffer';
  36776. xhr.overrideMimeType('text/plain; charset=x-user-defined');
  36777. xhr.onreadystatechange = () => {
  36778. if (xhr.readyState === 4) {
  36779. if (xhr.status === 200) {
  36780. var buffer = xhr.response;
  36781. this.parse(node, buffer);
  36782. } else {
  36783. console.log('Failed ' + url + ': ' + xhr.status);
  36784. }
  36785. }
  36786. };
  36787. xhr.send(null);
  36788. }
  36789. async parse(node, buffer) {
  36790. var lf = new LASFile(buffer);
  36791. var handler = new EptLazBatcher(node);
  36792. try {
  36793. await lf.open();
  36794. lf.isOpen = true;
  36795. var header = await lf.getHeader();
  36796. {
  36797. var i = 0;
  36798. var toArray = v => [v.x, v.y, v.z];
  36799. var mins = toArray(node.key.b.min);
  36800. var maxs = toArray(node.key.b.max);
  36801. var hasMoreData = true;
  36802. while (hasMoreData) {
  36803. var data = await lf.readData(1000000, 0, 1);
  36804. var d = new LASDecoder(data.buffer, header.pointsFormatId, header.pointsStructSize, data.count, header.scale, header.offset, mins, maxs);
  36805. d.extraBytes = header.extraBytes;
  36806. d.pointsFormatId = header.pointsFormatId;
  36807. handler.push(d);
  36808. i += data.count;
  36809. hasMoreData = data.hasMoreData;
  36810. }
  36811. header.totalRead = i;
  36812. header.versionAsString = lf.versionAsString;
  36813. header.isCompressed = lf.isCompressed;
  36814. await lf.close();
  36815. lf.isOpen = false;
  36816. }
  36817. } catch (err) {
  36818. console.error('Error reading LAZ:', err);
  36819. if (lf.isOpen) {
  36820. await lf.close();
  36821. lf.isOpen = false;
  36822. }
  36823. throw err;
  36824. }
  36825. }
  36826. }
  36827. ;
  36828. class EptLazBatcher {
  36829. constructor(node) {
  36830. this.node = node;
  36831. }
  36832. push(las) {
  36833. var workerPath = Potree.scriptPath + '/workers/EptLaszipDecoderWorker.js';
  36834. var worker = Potree.workerPool.getWorker(workerPath);
  36835. worker.onmessage = e => {
  36836. var g = new BufferGeometry();
  36837. var numPoints = las.pointsCount;
  36838. var positions = new Float32Array(e.data.position);
  36839. var colors = new Uint8Array(e.data.color);
  36840. var intensities = new Float32Array(e.data.intensity);
  36841. var classifications = new Uint8Array(e.data.classification);
  36842. var returnNumbers = new Uint8Array(e.data.returnNumber);
  36843. var numberOfReturns = new Uint8Array(e.data.numberOfReturns);
  36844. var pointSourceIDs = new Uint16Array(e.data.pointSourceID);
  36845. var indices = new Uint8Array(e.data.indices);
  36846. var gpsTime = new Float32Array(e.data.gpsTime);
  36847. g.setAttribute('position', new BufferAttribute(positions, 3));
  36848. g.setAttribute('rgba', new BufferAttribute(colors, 4, true));
  36849. g.setAttribute('intensity', new BufferAttribute(intensities, 1));
  36850. g.setAttribute('classification', new BufferAttribute(classifications, 1));
  36851. g.setAttribute('return number', new BufferAttribute(returnNumbers, 1));
  36852. g.setAttribute('number of returns', new BufferAttribute(numberOfReturns, 1));
  36853. g.setAttribute('source id', new BufferAttribute(pointSourceIDs, 1));
  36854. g.setAttribute('indices', new BufferAttribute(indices, 4));
  36855. g.setAttribute('gpsTime', new BufferAttribute(gpsTime, 1));
  36856. this.node.gpsTime = e.data.gpsMeta;
  36857. g.attributes.indices.normalized = true;
  36858. var tightBoundingBox = new Box3(new Vector3().fromArray(e.data.tightBoundingBox.min), new Vector3().fromArray(e.data.tightBoundingBox.max));
  36859. this.node.doneLoading(g, tightBoundingBox, numPoints, new Vector3(...e.data.mean));
  36860. Potree.workerPool.returnWorker(workerPath, worker);
  36861. };
  36862. var message = {
  36863. buffer: las.arrayb,
  36864. numPoints: las.pointsCount,
  36865. pointSize: las.pointSize,
  36866. pointFormatID: las.pointsFormatId,
  36867. scale: las.scale,
  36868. offset: las.offset,
  36869. mins: las.mins,
  36870. maxs: las.maxs
  36871. };
  36872. worker.postMessage(message, [message.buffer]);
  36873. }
  36874. }
  36875. ;
  36876. class EptZstandardLoader extends EptBinaryLoader {
  36877. extension() {
  36878. return '.zst';
  36879. }
  36880. workerPath() {
  36881. return Potree.scriptPath + '/workers/EptZstandardDecoderWorker.js';
  36882. }
  36883. }
  36884. ;
  36885. class ShapefileLoader {
  36886. constructor() {
  36887. this.transform = null;
  36888. }
  36889. async load(path, color) {
  36890. var matLine = new LineMaterial({
  36891. color: color || 0xff0000,
  36892. lineWidth: 3,
  36893. // in pixels
  36894. resolution: new Vector2(1000, 1000),
  36895. dashed: false
  36896. });
  36897. var features = await this.loadShapefileFeatures(path);
  36898. var node = new Object3D();
  36899. var jump = 0;
  36900. for (var feature of features) {
  36901. //5是碎的
  36902. //if(feature.geometry.type!= 'MultiLineString' || ++jump != 5) continue
  36903. var fnode = this.featureToSceneNode(feature, matLine);
  36904. fnode && node.add(fnode);
  36905. }
  36906. var setResolution = (x, y) => {
  36907. matLine.resolution.set(x, y);
  36908. };
  36909. var result = {
  36910. features: features,
  36911. node: node,
  36912. setResolution: setResolution
  36913. };
  36914. return result;
  36915. }
  36916. featureToSceneNode(feature, matLine) {
  36917. //console.log(feature)
  36918. var geometry = feature.geometry;
  36919. var color = new Color(1, 1, 1);
  36920. var transform = this.transform;
  36921. if (transform === null) {
  36922. transform = {
  36923. forward: v => v
  36924. };
  36925. }
  36926. if (geometry.type === "Point") {
  36927. var sg = new SphereGeometry(1, 18, 18);
  36928. var sm = new MeshNormalMaterial();
  36929. var s = new Mesh(sg, sm);
  36930. var [long, lat] = geometry.coordinates;
  36931. var pos = transform.forward([long, lat]);
  36932. s.position.set(...pos, 20);
  36933. s.scale.set(10, 10, 10);
  36934. return s;
  36935. } else if (geometry.type === "LineString") {
  36936. var coordinates = [];
  36937. var min = new Vector3(Infinity, Infinity, Infinity);
  36938. for (var i = 0; i < geometry.coordinates.length; i++) {
  36939. var [_long, _lat] = geometry.coordinates[i];
  36940. var _pos = transform.forward([_long, _lat]);
  36941. min.x = Math.min(min.x, _pos[0]);
  36942. min.y = Math.min(min.y, _pos[1]);
  36943. min.z = Math.min(min.z, 20);
  36944. coordinates.push(..._pos, 20);
  36945. if (i > 0 && i < geometry.coordinates.length - 1) {
  36946. coordinates.push(..._pos, 20);
  36947. }
  36948. }
  36949. for (var _i = 0; _i < coordinates.length; _i += 3) {
  36950. coordinates[_i + 0] -= min.x;
  36951. coordinates[_i + 1] -= min.y;
  36952. coordinates[_i + 2] -= min.z;
  36953. }
  36954. var lineGeometry = new LineGeometry();
  36955. lineGeometry.setPositions(coordinates);
  36956. var line = new Line2(lineGeometry, matLine);
  36957. line.computeLineDistances();
  36958. line.scale.set(1, 1, 1);
  36959. line.position.copy(min);
  36960. return line;
  36961. } else if (geometry.type === "MultiLineString") {
  36962. //xzw add 江门的那个文件
  36963. var _coordinates = [];
  36964. //console.warn('MultiLineString') //多组连续线段,组之间不连续
  36965. var _min = new Vector3(Infinity, Infinity, Infinity);
  36966. var _loop = function _loop() {
  36967. var points = geometry.coordinates[_i2]; //有时候是两个点有时候多个
  36968. var coordinateSlice = [];
  36969. points.forEach(point => {
  36970. var [long, lat] = point;
  36971. var pos = transform.forward([long, lat]);
  36972. _min.x = Math.min(_min.x, pos[0]);
  36973. _min.y = Math.min(_min.y, pos[1]);
  36974. _min.z = Math.min(_min.z, 20);
  36975. coordinateSlice.push(new Vector3(pos[0], pos[1], 20));
  36976. });
  36977. _coordinates.push(coordinateSlice);
  36978. };
  36979. for (var _i2 = 0; _i2 < geometry.coordinates.length; _i2++) {
  36980. _loop();
  36981. }
  36982. _coordinates.forEach(coordinateSlice => coordinateSlice.forEach(point => point.sub(_min)));
  36983. var _line = LineDraw.createFatLine(_coordinates, {
  36984. uncontinuous: true,
  36985. mat: matLine
  36986. /* color: 0xff0000,
  36987. dashSize: 0.5,
  36988. gapSize: 0.2,
  36989. lineWidth: config$1.measure.lineWidth, */
  36990. });
  36991. _line.position.copy(_min);
  36992. return _line;
  36993. } else if (geometry.type === "Polygon") {
  36994. for (var pc of geometry.coordinates) {
  36995. var _coordinates2 = [];
  36996. var _min2 = new Vector3(Infinity, Infinity, Infinity);
  36997. for (var _i3 = 0; _i3 < pc.length; _i3++) {
  36998. var [_long2, _lat2] = pc[_i3];
  36999. var _pos2 = transform.forward([_long2, _lat2]);
  37000. _min2.x = Math.min(_min2.x, _pos2[0]);
  37001. _min2.y = Math.min(_min2.y, _pos2[1]);
  37002. _min2.z = Math.min(_min2.z, 20);
  37003. _coordinates2.push(..._pos2, 20);
  37004. if (_i3 > 0 && _i3 < pc.length - 1) {
  37005. _coordinates2.push(..._pos2, 20);
  37006. }
  37007. }
  37008. for (var _i4 = 0; _i4 < _coordinates2.length; _i4 += 3) {
  37009. _coordinates2[_i4 + 0] -= _min2.x;
  37010. _coordinates2[_i4 + 1] -= _min2.y;
  37011. _coordinates2[_i4 + 2] -= _min2.z;
  37012. }
  37013. var _lineGeometry = new LineGeometry();
  37014. _lineGeometry.setPositions(_coordinates2);
  37015. var _line2 = new Line2(_lineGeometry, matLine);
  37016. _line2.computeLineDistances();
  37017. _line2.scale.set(1, 1, 1);
  37018. _line2.position.copy(_min2);
  37019. return _line2;
  37020. }
  37021. } else {
  37022. console.log("unhandled feature: ", geometry.type);
  37023. }
  37024. function getLine(coordinates) {}
  37025. }
  37026. async loadShapefileFeatures(file) {
  37027. var features = [];
  37028. if (file.split('.').pop() == 'shp') {
  37029. var source = await shapefile.open(file);
  37030. while (true) {
  37031. var result = await source.read();
  37032. if (result.done) {
  37033. break;
  37034. }
  37035. if (result.value && result.value.type === 'Feature' && result.value.geometry !== undefined) {
  37036. features.push(result.value);
  37037. }
  37038. }
  37039. return features;
  37040. } else if (file.split('.').pop() == 'json') {
  37041. return new Promise((resolve, reject) => {
  37042. Potree.loadFile(file, {/* returnText:true */}, data => {
  37043. console.log(data);
  37044. resolve(data.features);
  37045. });
  37046. });
  37047. }
  37048. }
  37049. }
  37050. ;
  37051. var defaultColors = {
  37052. "landuse": [0.5, 0.5, 0.5],
  37053. "natural": [0.0, 1.0, 0.0],
  37054. "places": [1.0, 0.0, 1.0],
  37055. "points": [0.0, 1.0, 1.0],
  37056. "roads": [1.0, 1.0, 0.0],
  37057. "waterways": [0.0, 0.0, 1.0],
  37058. "default": [0.9, 0.6, 0.1]
  37059. };
  37060. function getColor(feature) {
  37061. var color = defaultColors[feature];
  37062. if (!color) {
  37063. color = defaultColors["default"];
  37064. }
  37065. return color;
  37066. }
  37067. class Geopackage$1 {
  37068. constructor() {
  37069. this.path = null;
  37070. this.node = null;
  37071. }
  37072. }
  37073. ;
  37074. class GeoPackageLoader {
  37075. constructor() {}
  37076. static async loadUrl(url, params) {
  37077. await Promise.all([Utils.loadScript("".concat(Potree.scriptPath, "/lazylibs/geopackage/geopackage.js")), Utils.loadScript("".concat(Potree.scriptPath, "/lazylibs/sql.js/sql-wasm.js"))]);
  37078. var result = await fetch(url);
  37079. var buffer = await result.arrayBuffer();
  37080. params = params || {};
  37081. params.source = url;
  37082. return GeoPackageLoader.loadBuffer(buffer, params);
  37083. }
  37084. static async loadBuffer(buffer, params) {
  37085. await Promise.all([Utils.loadScript("".concat(Potree.scriptPath, "/lazylibs/geopackage/geopackage.js")), Utils.loadScript("".concat(Potree.scriptPath, "/lazylibs/sql.js/sql-wasm.js"))]);
  37086. params = params || {};
  37087. var resolver = async resolve => {
  37088. var transform = params.transform;
  37089. if (!transform) {
  37090. transform = {
  37091. forward: arg => arg
  37092. };
  37093. }
  37094. var wasmPath = "".concat(Potree.scriptPath, "/lazylibs/sql.js/sql-wasm.wasm");
  37095. var SQL = await initSqlJs({
  37096. locateFile: filename => wasmPath
  37097. });
  37098. var u8 = new Uint8Array(buffer);
  37099. var data = await geopackage.open(u8);
  37100. window.data = data;
  37101. var geopackageNode = new Object3D();
  37102. geopackageNode.name = params.source;
  37103. geopackageNode.potree = {
  37104. source: params.source
  37105. };
  37106. var geo = new Geopackage$1();
  37107. geo.path = params.source;
  37108. geo.node = geopackageNode;
  37109. var tables = data.getTables();
  37110. for (var table of tables.features) {
  37111. var dao = data.getFeatureDao(table);
  37112. var boundingBox = dao.getBoundingBox();
  37113. boundingBox = boundingBox.projectBoundingBox(dao.projection, 'EPSG:4326');
  37114. var geoJson = data.queryForGeoJSONFeaturesInTable(table, boundingBox);
  37115. var matLine = new LineMaterial({
  37116. color: new Color().setRGB(...getColor(table)),
  37117. linewidth: 2,
  37118. resolution: new Vector2(1000, 1000),
  37119. dashed: false
  37120. });
  37121. var node = new Object3D();
  37122. node.name = table;
  37123. geo.node.add(node);
  37124. for (var [index, feature] of Object.entries(geoJson)) {
  37125. //const featureNode = GeoPackageLoader.featureToSceneNode(feature, matLine, transform);
  37126. var featureNode = GeoPackageLoader.featureToSceneNode(feature, matLine, dao.projection, transform);
  37127. node.add(featureNode);
  37128. }
  37129. }
  37130. resolve(geo);
  37131. };
  37132. return new Promise(resolver);
  37133. }
  37134. static featureToSceneNode(feature, matLine, geopackageProjection, transform) {
  37135. var geometry = feature.geometry;
  37136. var color = new Color(1, 1, 1);
  37137. if (feature.geometry.type === "Point") {
  37138. var sg = new SphereGeometry(1, 18, 18);
  37139. var sm = new MeshNormalMaterial();
  37140. var s = new Mesh(sg, sm);
  37141. var [long, lat] = geometry.coordinates;
  37142. var pos = transform.forward(geopackageProjection.forward([long, lat]));
  37143. s.position.set(...pos, 20);
  37144. s.scale.set(10, 10, 10);
  37145. return s;
  37146. } else if (geometry.type === "LineString") {
  37147. var coordinates = [];
  37148. var min = new Vector3(Infinity, Infinity, Infinity);
  37149. for (var i = 0; i < geometry.coordinates.length; i++) {
  37150. var [_long, _lat] = geometry.coordinates[i];
  37151. var _pos = transform.forward(geopackageProjection.forward([_long, _lat]));
  37152. min.x = Math.min(min.x, _pos[0]);
  37153. min.y = Math.min(min.y, _pos[1]);
  37154. min.z = Math.min(min.z, 20);
  37155. coordinates.push(..._pos, 20);
  37156. if (i > 0 && i < geometry.coordinates.length - 1) {
  37157. coordinates.push(..._pos, 20);
  37158. }
  37159. }
  37160. for (var _i = 0; _i < coordinates.length; _i += 3) {
  37161. coordinates[_i + 0] -= min.x;
  37162. coordinates[_i + 1] -= min.y;
  37163. coordinates[_i + 2] -= min.z;
  37164. }
  37165. var lineGeometry = new LineGeometry();
  37166. lineGeometry.setPositions(coordinates);
  37167. var line = new Line2(lineGeometry, matLine);
  37168. line.computeLineDistances();
  37169. line.scale.set(1, 1, 1);
  37170. line.position.copy(min);
  37171. return line;
  37172. } else if (geometry.type === "Polygon") {
  37173. for (var pc of geometry.coordinates) {
  37174. var _coordinates = [];
  37175. var _min = new Vector3(Infinity, Infinity, Infinity);
  37176. for (var _i2 = 0; _i2 < pc.length; _i2++) {
  37177. var [_long2, _lat2] = pc[_i2];
  37178. var _pos2 = transform.forward(geopackageProjection.forward([_long2, _lat2]));
  37179. _min.x = Math.min(_min.x, _pos2[0]);
  37180. _min.y = Math.min(_min.y, _pos2[1]);
  37181. _min.z = Math.min(_min.z, 20);
  37182. _coordinates.push(..._pos2, 20);
  37183. if (_i2 > 0 && _i2 < pc.length - 1) {
  37184. _coordinates.push(..._pos2, 20);
  37185. }
  37186. }
  37187. for (var _i3 = 0; _i3 < _coordinates.length; _i3 += 3) {
  37188. _coordinates[_i3 + 0] -= _min.x;
  37189. _coordinates[_i3 + 1] -= _min.y;
  37190. _coordinates[_i3 + 2] -= _min.z;
  37191. }
  37192. var _lineGeometry = new LineGeometry();
  37193. _lineGeometry.setPositions(_coordinates);
  37194. var _line = new Line2(_lineGeometry, matLine);
  37195. _line.computeLineDistances();
  37196. _line.scale.set(1, 1, 1);
  37197. _line.position.copy(_min);
  37198. return _line;
  37199. }
  37200. } else {
  37201. console.log("unhandled feature: ", feature);
  37202. }
  37203. }
  37204. }
  37205. ;
  37206. class ClipVolume extends Object3D {
  37207. constructor(args) {
  37208. super();
  37209. this.constructor.counter = this.constructor.counter === undefined ? 0 : this.constructor.counter + 1;
  37210. this.name = "clip_volume_" + this.constructor.counter;
  37211. var alpha = args.alpha || 0;
  37212. var beta = args.beta || 0;
  37213. var gamma = args.gamma || 0;
  37214. this.rotation.x = alpha;
  37215. this.rotation.y = beta;
  37216. this.rotation.z = gamma;
  37217. this.clipOffset = 0.001;
  37218. this.clipRotOffset = 1;
  37219. var boxGeometry = new BoxGeometry(1, 1, 1);
  37220. boxGeometry.computeBoundingBox();
  37221. var boxFrameGeometry = new Geometry();
  37222. {
  37223. // bottom
  37224. boxFrameGeometry.vertices.push(new Vector3(-0.5, -0.5, 0.5));
  37225. boxFrameGeometry.vertices.push(new Vector3(0.5, -0.5, 0.5));
  37226. boxFrameGeometry.vertices.push(new Vector3(0.5, -0.5, 0.5));
  37227. boxFrameGeometry.vertices.push(new Vector3(0.5, -0.5, -0.5));
  37228. boxFrameGeometry.vertices.push(new Vector3(0.5, -0.5, -0.5));
  37229. boxFrameGeometry.vertices.push(new Vector3(-0.5, -0.5, -0.5));
  37230. boxFrameGeometry.vertices.push(new Vector3(-0.5, -0.5, -0.5));
  37231. boxFrameGeometry.vertices.push(new Vector3(-0.5, -0.5, 0.5));
  37232. // top
  37233. boxFrameGeometry.vertices.push(new Vector3(-0.5, 0.5, 0.5));
  37234. boxFrameGeometry.vertices.push(new Vector3(0.5, 0.5, 0.5));
  37235. boxFrameGeometry.vertices.push(new Vector3(0.5, 0.5, 0.5));
  37236. boxFrameGeometry.vertices.push(new Vector3(0.5, 0.5, -0.5));
  37237. boxFrameGeometry.vertices.push(new Vector3(0.5, 0.5, -0.5));
  37238. boxFrameGeometry.vertices.push(new Vector3(-0.5, 0.5, -0.5));
  37239. boxFrameGeometry.vertices.push(new Vector3(-0.5, 0.5, -0.5));
  37240. boxFrameGeometry.vertices.push(new Vector3(-0.5, 0.5, 0.5));
  37241. // sides
  37242. boxFrameGeometry.vertices.push(new Vector3(-0.5, -0.5, 0.5));
  37243. boxFrameGeometry.vertices.push(new Vector3(-0.5, 0.5, 0.5));
  37244. boxFrameGeometry.vertices.push(new Vector3(0.5, -0.5, 0.5));
  37245. boxFrameGeometry.vertices.push(new Vector3(0.5, 0.5, 0.5));
  37246. boxFrameGeometry.vertices.push(new Vector3(0.5, -0.5, -0.5));
  37247. boxFrameGeometry.vertices.push(new Vector3(0.5, 0.5, -0.5));
  37248. boxFrameGeometry.vertices.push(new Vector3(-0.5, -0.5, -0.5));
  37249. boxFrameGeometry.vertices.push(new Vector3(-0.5, 0.5, -0.5));
  37250. boxFrameGeometry.colors.push(new Vector3(1, 1, 1));
  37251. }
  37252. var planeFrameGeometry = new Geometry();
  37253. {
  37254. // middle line
  37255. planeFrameGeometry.vertices.push(new Vector3(-0.5, -0.5, 0.0));
  37256. planeFrameGeometry.vertices.push(new Vector3(-0.5, 0.5, 0.0));
  37257. planeFrameGeometry.vertices.push(new Vector3(0.5, 0.5, 0.0));
  37258. planeFrameGeometry.vertices.push(new Vector3(0.5, -0.5, 0.0));
  37259. planeFrameGeometry.vertices.push(new Vector3(-0.5, 0.5, 0.0));
  37260. planeFrameGeometry.vertices.push(new Vector3(0.5, 0.5, 0.0));
  37261. planeFrameGeometry.vertices.push(new Vector3(-0.5, -0.5, 0.0));
  37262. planeFrameGeometry.vertices.push(new Vector3(0.5, -0.5, 0.0));
  37263. }
  37264. this.dimension = new Vector3(1, 1, 1);
  37265. this.material = new MeshBasicMaterial({
  37266. color: 0x00ff00,
  37267. transparent: true,
  37268. opacity: 0.3,
  37269. depthTest: true,
  37270. depthWrite: false
  37271. });
  37272. this.box = new Mesh(boxGeometry, this.material);
  37273. this.box.geometry.computeBoundingBox();
  37274. this.boundingBox = this.box.geometry.boundingBox;
  37275. this.add(this.box);
  37276. this.frame = new LineSegments(boxFrameGeometry, new LineBasicMaterial({
  37277. color: 0x000000
  37278. }));
  37279. this.add(this.frame);
  37280. this.planeFrame = new LineSegments(planeFrameGeometry, new LineBasicMaterial({
  37281. color: 0xff0000
  37282. }));
  37283. this.add(this.planeFrame);
  37284. // set default thickness
  37285. this.setScaleZ(0.1);
  37286. // create local coordinate system
  37287. var createArrow = (name, direction, color) => {
  37288. var material = new MeshBasicMaterial({
  37289. color: color,
  37290. depthTest: false,
  37291. depthWrite: false
  37292. });
  37293. var shaftGeometry = new Geometry();
  37294. shaftGeometry.vertices.push(new Vector3(0, 0, 0));
  37295. shaftGeometry.vertices.push(new Vector3(0, 1, 0));
  37296. var shaftMaterial = new LineBasicMaterial({
  37297. color: color,
  37298. depthTest: false,
  37299. depthWrite: false,
  37300. transparent: true
  37301. });
  37302. var shaft = new Line(shaftGeometry, shaftMaterial);
  37303. shaft.name = name + "_shaft";
  37304. var headGeometry = new CylinderGeometry(0, 0.04, 0.1, 10, 1, false);
  37305. var headMaterial = material;
  37306. var head = new Mesh(headGeometry, headMaterial);
  37307. head.name = name + "_head";
  37308. head.position.y = 1;
  37309. var arrow = new Object3D();
  37310. arrow.name = name;
  37311. arrow.add(shaft);
  37312. arrow.add(head);
  37313. return arrow;
  37314. };
  37315. this.arrowX = createArrow("arrow_x", new Vector3(1, 0, 0), 0xFF0000);
  37316. this.arrowY = createArrow("arrow_y", new Vector3(0, 1, 0), 0x00FF00);
  37317. this.arrowZ = createArrow("arrow_z", new Vector3(0, 0, 1), 0x0000FF);
  37318. this.arrowX.rotation.z = -Math.PI / 2;
  37319. this.arrowZ.rotation.x = Math.PI / 2;
  37320. this.arrowX.visible = false;
  37321. this.arrowY.visible = false;
  37322. this.arrowZ.visible = false;
  37323. this.add(this.arrowX);
  37324. this.add(this.arrowY);
  37325. this.add(this.arrowZ);
  37326. {
  37327. // event listeners
  37328. this.addEventListener("ui_select", e => {
  37329. this.arrowX.visible = true;
  37330. this.arrowY.visible = true;
  37331. this.arrowZ.visible = true;
  37332. });
  37333. this.addEventListener("ui_deselect", e => {
  37334. this.arrowX.visible = false;
  37335. this.arrowY.visible = false;
  37336. this.arrowZ.visible = false;
  37337. });
  37338. this.addEventListener("select", e => {
  37339. var scene_header = $("#" + this.name + " .scene_header");
  37340. if (!scene_header.next().is(":visible")) {
  37341. scene_header.click();
  37342. }
  37343. });
  37344. this.addEventListener("deselect", e => {
  37345. var scene_header = $("#" + this.name + " .scene_header");
  37346. if (scene_header.next().is(":visible")) {
  37347. scene_header.click();
  37348. }
  37349. });
  37350. }
  37351. this.update();
  37352. }
  37353. setClipOffset(offset) {
  37354. this.clipOffset = offset;
  37355. }
  37356. setClipRotOffset(offset) {
  37357. this.clipRotOffset = offset;
  37358. }
  37359. setScaleX(x) {
  37360. this.box.scale.x = x;
  37361. this.frame.scale.x = x;
  37362. this.planeFrame.scale.x = x;
  37363. }
  37364. setScaleY(y) {
  37365. this.box.scale.y = y;
  37366. this.frame.scale.y = y;
  37367. this.planeFrame.scale.y = y;
  37368. }
  37369. setScaleZ(z) {
  37370. this.box.scale.z = z;
  37371. this.frame.scale.z = z;
  37372. this.planeFrame.scale.z = z;
  37373. }
  37374. offset(args) {
  37375. var cs = args.cs || null;
  37376. var axis = args.axis || null;
  37377. var dir = args.dir || null;
  37378. if (!cs || !axis || !dir) return;
  37379. if (axis === "x") {
  37380. if (cs === "local") {
  37381. this.position.add(this.localX.clone().multiplyScalar(dir * this.clipOffset));
  37382. } else if (cs === "global") {
  37383. this.position.x = this.position.x + dir * this.clipOffset;
  37384. }
  37385. } else if (axis === "y") {
  37386. if (cs === "local") {
  37387. this.position.add(this.localY.clone().multiplyScalar(dir * this.clipOffset));
  37388. } else if (cs === "global") {
  37389. this.position.y = this.position.y + dir * this.clipOffset;
  37390. }
  37391. } else if (axis === "z") {
  37392. if (cs === "local") {
  37393. this.position.add(this.localZ.clone().multiplyScalar(dir * this.clipOffset));
  37394. } else if (cs === "global") {
  37395. this.position.z = this.position.z + dir * this.clipOffset;
  37396. }
  37397. }
  37398. this.dispatchEvent({
  37399. "type": "clip_volume_changed",
  37400. "viewer": viewer,
  37401. "volume": this
  37402. });
  37403. }
  37404. rotate(args) {
  37405. var cs = args.cs || null;
  37406. var axis = args.axis || null;
  37407. var dir = args.dir || null;
  37408. if (!cs || !axis || !dir) return;
  37409. if (cs === "local") {
  37410. if (axis === "x") {
  37411. this.rotateOnAxis(new Vector3(1, 0, 0), dir * this.clipRotOffset * Math.PI / 180);
  37412. } else if (axis === "y") {
  37413. this.rotateOnAxis(new Vector3(0, 1, 0), dir * this.clipRotOffset * Math.PI / 180);
  37414. } else if (axis === "z") {
  37415. this.rotateOnAxis(new Vector3(0, 0, 1), dir * this.clipRotOffset * Math.PI / 180);
  37416. }
  37417. } else if (cs === "global") {
  37418. var rotaxis = new Vector4(1, 0, 0, 0);
  37419. if (axis === "y") {
  37420. rotaxis = new Vector4(0, 1, 0, 0);
  37421. } else if (axis === "z") {
  37422. rotaxis = new Vector4(0, 0, 1, 0);
  37423. }
  37424. this.updateMatrixWorld();
  37425. var invM = newthis.matrixWorld.clone().invert();
  37426. rotaxis = rotaxis.applyMatrix4(invM).normalize();
  37427. rotaxis = new Vector3(rotaxis.x, rotaxis.y, rotaxis.z);
  37428. this.rotateOnAxis(rotaxis, dir * this.clipRotOffset * Math.PI / 180);
  37429. }
  37430. this.updateLocalSystem();
  37431. this.dispatchEvent({
  37432. "type": "clip_volume_changed",
  37433. "viewer": viewer,
  37434. "volume": this
  37435. });
  37436. }
  37437. update() {
  37438. this.boundingBox = this.box.geometry.boundingBox;
  37439. this.boundingSphere = this.boundingBox.getBoundingSphere(new Sphere());
  37440. this.box.visible = false;
  37441. this.updateLocalSystem();
  37442. }
  37443. updateLocalSystem() {
  37444. // extract local coordinate axes
  37445. var rotQuat = this.getWorldQuaternion();
  37446. this.localX = new Vector3(1, 0, 0).applyQuaternion(rotQuat).normalize();
  37447. this.localY = new Vector3(0, 1, 0).applyQuaternion(rotQuat).normalize();
  37448. this.localZ = new Vector3(0, 0, 1).applyQuaternion(rotQuat).normalize();
  37449. }
  37450. raycast(raycaster, intersects) {
  37451. var is = [];
  37452. this.box.raycast(raycaster, is);
  37453. if (is.length > 0) {
  37454. var I = is[0];
  37455. intersects.push({
  37456. distance: I.distance,
  37457. object: this,
  37458. point: I.point.clone()
  37459. });
  37460. }
  37461. }
  37462. }
  37463. ;
  37464. //这个文件只是clipping polygon的,没用到
  37465. class ClippingTool extends EventDispatcher$1 {
  37466. constructor(viewer) {
  37467. super();
  37468. this.viewer = viewer;
  37469. this.maxPolygonVertices = 8;
  37470. this.addEventListener("start_inserting_clipping_volume", e => {
  37471. this.viewer.dispatchEvent({
  37472. type: "cancel_insertions"
  37473. });
  37474. });
  37475. this.sceneMarker = new Scene();
  37476. this.sceneVolume = new Scene();
  37477. this.sceneVolume.name = "scene_clip_volume";
  37478. this.viewer.inputHandler.registerInteractiveScene(this.sceneVolume);
  37479. this.onRemove = e => {
  37480. this.sceneVolume.remove(e.volume);
  37481. };
  37482. this.onAdd = e => {
  37483. this.sceneVolume.add(e.volume);
  37484. };
  37485. this.viewer.inputHandler.addEventListener("delete", e => {
  37486. var volumes = e.selection.filter(e => e instanceof ClipVolume);
  37487. volumes.forEach(e => this.viewer.scene.removeClipVolume(e));
  37488. var polyVolumes = e.selection.filter(e => e instanceof PolygonClipVolume);
  37489. polyVolumes.forEach(e => this.viewer.scene.removePolygonClipVolume(e));
  37490. });
  37491. }
  37492. setScene(scene) {
  37493. if (this.scene === scene) {
  37494. return;
  37495. }
  37496. if (this.scene) {
  37497. this.scene.removeEventListeners("clip_volume_added", this.onAdd);
  37498. this.scene.removeEventListeners("clip_volume_removed", this.onRemove);
  37499. this.scene.removeEventListeners("polygon_clip_volume_added", this.onAdd);
  37500. this.scene.removeEventListeners("polygon_clip_volume_removed", this.onRemove);
  37501. }
  37502. this.scene = scene;
  37503. this.scene.addEventListener("clip_volume_added", this.onAdd);
  37504. this.scene.addEventListener("clip_volume_removed", this.onRemove);
  37505. this.scene.addEventListener("polygon_clip_volume_added", this.onAdd);
  37506. this.scene.addEventListener("polygon_clip_volume_removed", this.onRemove);
  37507. }
  37508. startInsertion() {
  37509. var args = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  37510. var type = args.type || null;
  37511. if (!type) return null;
  37512. var domElement = this.viewer.renderer.domElement;
  37513. var canvasSize = this.viewer.renderer.getSize(new Vector2());
  37514. var svg = $("\n\t\t<svg height=\"".concat(canvasSize.height, "\" width=\"").concat(canvasSize.width, "\" style=\"position:absolute; pointer-events: none\">\n\n\t\t\t<defs>\n\t\t\t\t <marker id=\"diamond\" markerWidth=\"24\" markerHeight=\"24\" refX=\"12\" refY=\"12\"\n\t\t\t\t\t\tmarkerUnits=\"userSpaceOnUse\">\n\t\t\t\t\t<circle cx=\"12\" cy=\"12\" r=\"6\" fill=\"white\" stroke=\"black\" stroke-width=\"3\"/>\n\t\t\t\t</marker>\n\t\t\t</defs>\n\n\t\t\t<polyline fill=\"none\" stroke=\"black\" \n\t\t\t\tstyle=\"stroke:rgb(0, 0, 0);\n\t\t\t\tstroke-width:6;\"\n\t\t\t\tstroke-dasharray=\"9, 6\"\n\t\t\t\tstroke-dashoffset=\"2\"\n\t\t\t\t/>\n\n\t\t\t<polyline fill=\"none\" stroke=\"black\" \n\t\t\t\tstyle=\"stroke:rgb(255, 255, 255);\n\t\t\t\tstroke-width:2;\"\n\t\t\t\tstroke-dasharray=\"5, 10\"\n\t\t\t\tmarker-start=\"url(#diamond)\" \n\t\t\t\tmarker-mid=\"url(#diamond)\" \n\t\t\t\tmarker-end=\"url(#diamond)\" \n\t\t\t\t/>\n\t\t</svg>"));
  37515. $(domElement.parentElement).append(svg);
  37516. var polyClipVol = new PolygonClipVolume(this.viewer.scene.getActiveCamera().clone());
  37517. this.dispatchEvent({
  37518. "type": "start_inserting_clipping_volume"
  37519. });
  37520. this.viewer.scene.addPolygonClipVolume(polyClipVol);
  37521. this.sceneMarker.add(polyClipVol);
  37522. var cancel = {
  37523. callback: null
  37524. };
  37525. var insertionCallback = e => {
  37526. if (e.button === MOUSE.LEFT) {
  37527. polyClipVol.addMarker();
  37528. // SVC Screen Line
  37529. svg.find("polyline").each((index, target) => {
  37530. var newPoint = svg[0].createSVGPoint();
  37531. newPoint.x = e.offsetX;
  37532. newPoint.y = e.offsetY;
  37533. var polyline = target.points.appendItem(newPoint);
  37534. });
  37535. if (polyClipVol.markers.length > this.maxPolygonVertices) {
  37536. cancel.callback();
  37537. }
  37538. this.viewer.inputHandler.startDragging(polyClipVol.markers[polyClipVol.markers.length - 1]);
  37539. } else if (e.button === MOUSE.RIGHT) {
  37540. cancel.callback(e);
  37541. }
  37542. };
  37543. cancel.callback = e => {
  37544. //let first = svg.find("polyline")[0].points[0];
  37545. //svg.find("polyline").each((index, target) => {
  37546. // let newPoint = svg[0].createSVGPoint();
  37547. // newPoint.x = first.x;
  37548. // newPoint.y = first.y;
  37549. // let polyline = target.points.appendItem(newPoint);
  37550. //});
  37551. svg.remove();
  37552. if (polyClipVol.markers.length > 3) {
  37553. polyClipVol.removeLastMarker();
  37554. polyClipVol.initialized = true;
  37555. } else {
  37556. this.viewer.scene.removePolygonClipVolume(polyClipVol);
  37557. }
  37558. this.viewer.renderer.domElement.removeEventListener("mouseup", insertionCallback, true);
  37559. this.viewer.removeEventListener("cancel_insertions", cancel.callback);
  37560. this.viewer.inputHandler.enabled = true;
  37561. };
  37562. this.viewer.addEventListener("cancel_insertions", cancel.callback);
  37563. this.viewer.renderer.domElement.addEventListener("mouseup", insertionCallback, true);
  37564. this.viewer.inputHandler.enabled = false;
  37565. polyClipVol.addMarker();
  37566. this.viewer.inputHandler.startDragging(polyClipVol.markers[polyClipVol.markers.length - 1]);
  37567. return polyClipVol;
  37568. }
  37569. update() {}
  37570. }
  37571. ;
  37572. var GeoTIFF = function (exports) {
  37573. 'use strict';
  37574. var Endianness = new Enum({
  37575. LITTLE: "II",
  37576. BIG: "MM"
  37577. });
  37578. var Type = new Enum({
  37579. BYTE: {
  37580. value: 1,
  37581. bytes: 1
  37582. },
  37583. ASCII: {
  37584. value: 2,
  37585. bytes: 1
  37586. },
  37587. SHORT: {
  37588. value: 3,
  37589. bytes: 2
  37590. },
  37591. LONG: {
  37592. value: 4,
  37593. bytes: 4
  37594. },
  37595. RATIONAL: {
  37596. value: 5,
  37597. bytes: 8
  37598. },
  37599. SBYTE: {
  37600. value: 6,
  37601. bytes: 1
  37602. },
  37603. UNDEFINED: {
  37604. value: 7,
  37605. bytes: 1
  37606. },
  37607. SSHORT: {
  37608. value: 8,
  37609. bytes: 2
  37610. },
  37611. SLONG: {
  37612. value: 9,
  37613. bytes: 4
  37614. },
  37615. SRATIONAL: {
  37616. value: 10,
  37617. bytes: 8
  37618. },
  37619. FLOAT: {
  37620. value: 11,
  37621. bytes: 4
  37622. },
  37623. DOUBLE: {
  37624. value: 12,
  37625. bytes: 8
  37626. }
  37627. });
  37628. var Tag = new Enum({
  37629. IMAGE_WIDTH: 256,
  37630. IMAGE_HEIGHT: 257,
  37631. BITS_PER_SAMPLE: 258,
  37632. COMPRESSION: 259,
  37633. PHOTOMETRIC_INTERPRETATION: 262,
  37634. STRIP_OFFSETS: 273,
  37635. ORIENTATION: 274,
  37636. SAMPLES_PER_PIXEL: 277,
  37637. ROWS_PER_STRIP: 278,
  37638. STRIP_BYTE_COUNTS: 279,
  37639. X_RESOLUTION: 282,
  37640. Y_RESOLUTION: 283,
  37641. PLANAR_CONFIGURATION: 284,
  37642. RESOLUTION_UNIT: 296,
  37643. SOFTWARE: 305,
  37644. COLOR_MAP: 320,
  37645. SAMPLE_FORMAT: 339,
  37646. MODEL_PIXEL_SCALE: 33550,
  37647. // [GeoTIFF] TYPE: double N: 3
  37648. MODEL_TIEPOINT: 33922,
  37649. // [GeoTIFF] TYPE: double N: 6 * NUM_TIEPOINTS
  37650. GEO_KEY_DIRECTORY: 34735,
  37651. // [GeoTIFF] TYPE: short N: >= 4
  37652. GEO_DOUBLE_PARAMS: 34736,
  37653. // [GeoTIFF] TYPE: short N: variable
  37654. GEO_ASCII_PARAMS: 34737 // [GeoTIFF] TYPE: ascii N: variable
  37655. });
  37656. var typeMapping = new Map([[Type.BYTE, Uint8Array], [Type.ASCII, Uint8Array], [Type.SHORT, Uint16Array], [Type.LONG, Uint32Array], [Type.RATIONAL, Uint32Array], [Type.SBYTE, Int8Array], [Type.UNDEFINED, Uint8Array], [Type.SSHORT, Int16Array], [Type.SLONG, Int32Array], [Type.SRATIONAL, Int32Array], [Type.FLOAT, Float32Array], [Type.DOUBLE, Float64Array]]);
  37657. class IFDEntry {
  37658. constructor(tag, type, count, offset, value) {
  37659. this.tag = tag;
  37660. this.type = type;
  37661. this.count = count;
  37662. this.offset = offset;
  37663. this.value = value;
  37664. }
  37665. }
  37666. class Image {
  37667. constructor() {
  37668. this.width = 0;
  37669. this.height = 0;
  37670. this.buffer = null;
  37671. this.metadata = [];
  37672. }
  37673. }
  37674. class Reader {
  37675. constructor() {}
  37676. static read(data) {
  37677. var endiannessTag = String.fromCharCode(...Array.from(data.slice(0, 2)));
  37678. var endianness = Endianness.fromValue(endiannessTag);
  37679. var tiffCheckTag = data.readUInt8(2);
  37680. if (tiffCheckTag !== 42) {
  37681. throw new Error("not a valid tiff file");
  37682. }
  37683. var offsetToFirstIFD = data.readUInt32LE(4);
  37684. console.log("offsetToFirstIFD", offsetToFirstIFD);
  37685. var ifds = [];
  37686. var IFDsRead = false;
  37687. var currentIFDOffset = offsetToFirstIFD;
  37688. var i = 0;
  37689. while (IFDsRead || i < 100) {
  37690. console.log("currentIFDOffset", currentIFDOffset);
  37691. var numEntries = data.readUInt16LE(currentIFDOffset);
  37692. var nextIFDOffset = data.readUInt32LE(currentIFDOffset + 2 + numEntries * 12);
  37693. console.log("next offset: ", currentIFDOffset + 2 + numEntries * 12);
  37694. var entryBuffer = data.slice(currentIFDOffset + 2, currentIFDOffset + 2 + 12 * numEntries);
  37695. for (var _i = 0; _i < numEntries; _i++) {
  37696. var tag = Tag.fromValue(entryBuffer.readUInt16LE(_i * 12));
  37697. var type = Type.fromValue(entryBuffer.readUInt16LE(_i * 12 + 2));
  37698. var count = entryBuffer.readUInt32LE(_i * 12 + 4);
  37699. var offsetOrValue = entryBuffer.readUInt32LE(_i * 12 + 8);
  37700. var valueBytes = type.bytes * count;
  37701. var value = void 0;
  37702. if (valueBytes <= 4) {
  37703. value = offsetOrValue;
  37704. } else {
  37705. var valueBuffer = new Uint8Array(valueBytes);
  37706. valueBuffer.set(data.slice(offsetOrValue, offsetOrValue + valueBytes));
  37707. var ArrayType = typeMapping.get(type);
  37708. value = new ArrayType(valueBuffer.buffer);
  37709. if (type === Type.ASCII) {
  37710. value = String.fromCharCode(...value);
  37711. }
  37712. }
  37713. var ifd = new IFDEntry(tag, type, count, offsetOrValue, value);
  37714. ifds.push(ifd);
  37715. }
  37716. console.log("nextIFDOffset", nextIFDOffset);
  37717. if (nextIFDOffset === 0) {
  37718. break;
  37719. }
  37720. currentIFDOffset = nextIFDOffset;
  37721. i++;
  37722. }
  37723. var ifdForTag = tag => {
  37724. for (var entry of ifds) {
  37725. if (entry.tag === tag) {
  37726. return entry;
  37727. }
  37728. }
  37729. return null;
  37730. };
  37731. var width = ifdForTag(Tag.IMAGE_WIDTH, ifds).value;
  37732. var height = ifdForTag(Tag.IMAGE_HEIGHT, ifds).value;
  37733. var compression = ifdForTag(Tag.COMPRESSION, ifds).value;
  37734. var rowsPerStrip = ifdForTag(Tag.ROWS_PER_STRIP, ifds).value;
  37735. var ifdStripOffsets = ifdForTag(Tag.STRIP_OFFSETS, ifds);
  37736. var ifdStripByteCounts = ifdForTag(Tag.STRIP_BYTE_COUNTS, ifds);
  37737. var numStrips = Math.ceil(height / rowsPerStrip);
  37738. var stripByteCounts = [];
  37739. for (var _i2 = 0; _i2 < ifdStripByteCounts.count; _i2++) {
  37740. var _type = ifdStripByteCounts.type;
  37741. var offset = ifdStripByteCounts.offset + _i2 * _type.bytes;
  37742. var _value = void 0;
  37743. if (_type === Type.SHORT) {
  37744. _value = data.readUInt16LE(offset);
  37745. } else if (_type === Type.LONG) {
  37746. _value = data.readUInt32LE(offset);
  37747. }
  37748. stripByteCounts.push(_value);
  37749. }
  37750. var stripOffsets = [];
  37751. for (var _i3 = 0; _i3 < ifdStripOffsets.count; _i3++) {
  37752. var _type2 = ifdStripOffsets.type;
  37753. var _offset = ifdStripOffsets.offset + _i3 * _type2.bytes;
  37754. var _value2 = void 0;
  37755. if (_type2 === Type.SHORT) {
  37756. _value2 = data.readUInt16LE(_offset);
  37757. } else if (_type2 === Type.LONG) {
  37758. _value2 = data.readUInt32LE(_offset);
  37759. }
  37760. stripOffsets.push(_value2);
  37761. }
  37762. var imageBuffer = new Uint8Array(width * height * 3);
  37763. var linesProcessed = 0;
  37764. for (var _i4 = 0; _i4 < numStrips; _i4++) {
  37765. var stripOffset = stripOffsets[_i4];
  37766. var stripBytes = stripByteCounts[_i4];
  37767. var stripData = data.slice(stripOffset, stripOffset + stripBytes);
  37768. var lineBytes = width * 3;
  37769. for (var y = 0; y < rowsPerStrip; y++) {
  37770. var line = stripData.slice(y * lineBytes, y * lineBytes + lineBytes);
  37771. imageBuffer.set(line, linesProcessed * lineBytes);
  37772. if (line.length === lineBytes) {
  37773. linesProcessed++;
  37774. } else {
  37775. break;
  37776. }
  37777. }
  37778. }
  37779. console.log("width: ".concat(width));
  37780. console.log("height: ".concat(height));
  37781. console.log("numStrips: ".concat(numStrips));
  37782. console.log("stripByteCounts", stripByteCounts.join(", "));
  37783. console.log("stripOffsets", stripOffsets.join(", "));
  37784. var image = new Image();
  37785. image.width = width;
  37786. image.height = height;
  37787. image.buffer = imageBuffer;
  37788. image.metadata = ifds;
  37789. return image;
  37790. }
  37791. }
  37792. class Exporter {
  37793. constructor() {}
  37794. static toTiffBuffer(image) {
  37795. var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  37796. var offsetToFirstIFD = 8;
  37797. var headerBuffer = new Uint8Array([0x49, 0x49, 42, 0, offsetToFirstIFD, 0, 0, 0]);
  37798. var [width, height] = [image.width, image.height];
  37799. var ifds = [new IFDEntry(Tag.IMAGE_WIDTH, Type.SHORT, 1, null, width), new IFDEntry(Tag.IMAGE_HEIGHT, Type.SHORT, 1, null, height), new IFDEntry(Tag.BITS_PER_SAMPLE, Type.SHORT, 4, null, new Uint16Array([8, 8, 8, 8])), new IFDEntry(Tag.COMPRESSION, Type.SHORT, 1, null, 1), new IFDEntry(Tag.PHOTOMETRIC_INTERPRETATION, Type.SHORT, 1, null, 2), new IFDEntry(Tag.ORIENTATION, Type.SHORT, 1, null, 1), new IFDEntry(Tag.SAMPLES_PER_PIXEL, Type.SHORT, 1, null, 4), new IFDEntry(Tag.ROWS_PER_STRIP, Type.LONG, 1, null, height), new IFDEntry(Tag.STRIP_BYTE_COUNTS, Type.LONG, 1, null, width * height * 3), new IFDEntry(Tag.PLANAR_CONFIGURATION, Type.SHORT, 1, null, 1), new IFDEntry(Tag.RESOLUTION_UNIT, Type.SHORT, 1, null, 1), new IFDEntry(Tag.SOFTWARE, Type.ASCII, 6, null, "......"), new IFDEntry(Tag.STRIP_OFFSETS, Type.LONG, 1, null, null), new IFDEntry(Tag.X_RESOLUTION, Type.RATIONAL, 1, null, new Uint32Array([1, 1])), new IFDEntry(Tag.Y_RESOLUTION, Type.RATIONAL, 1, null, new Uint32Array([1, 1]))];
  37800. if (params.ifdEntries) {
  37801. ifds.push(...params.ifdEntries);
  37802. }
  37803. var valueOffset = offsetToFirstIFD + 2 + ifds.length * 12 + 4;
  37804. // create 12 byte buffer for each ifd and variable length buffers for ifd values
  37805. var ifdEntryBuffers = new Map();
  37806. var ifdValueBuffers = new Map();
  37807. for (var ifd of ifds) {
  37808. var entryBuffer = new ArrayBuffer(12);
  37809. var entryView = new DataView(entryBuffer);
  37810. var valueBytes = ifd.type.bytes * ifd.count;
  37811. entryView.setUint16(0, ifd.tag.value, true);
  37812. entryView.setUint16(2, ifd.type.value, true);
  37813. entryView.setUint32(4, ifd.count, true);
  37814. if (ifd.count === 1 && ifd.type.bytes <= 4) {
  37815. entryView.setUint32(8, ifd.value, true);
  37816. } else {
  37817. entryView.setUint32(8, valueOffset, true);
  37818. var valueBuffer = new Uint8Array(ifd.count * ifd.type.bytes);
  37819. if (ifd.type === Type.ASCII) {
  37820. valueBuffer.set(new Uint8Array(ifd.value.split("").map(c => c.charCodeAt(0))));
  37821. } else {
  37822. valueBuffer.set(new Uint8Array(ifd.value.buffer));
  37823. }
  37824. ifdValueBuffers.set(ifd.tag, valueBuffer);
  37825. valueOffset = valueOffset + valueBuffer.byteLength;
  37826. }
  37827. ifdEntryBuffers.set(ifd.tag, entryBuffer);
  37828. }
  37829. var imageBufferOffset = valueOffset;
  37830. new DataView(ifdEntryBuffers.get(Tag.STRIP_OFFSETS)).setUint32(8, imageBufferOffset, true);
  37831. var concatBuffers = buffers => {
  37832. var totalLength = buffers.reduce((sum, buffer) => sum + buffer.byteLength, 0);
  37833. var merged = new Uint8Array(totalLength);
  37834. var offset = 0;
  37835. for (var buffer of buffers) {
  37836. merged.set(new Uint8Array(buffer), offset);
  37837. offset += buffer.byteLength;
  37838. }
  37839. return merged;
  37840. };
  37841. var ifdBuffer = concatBuffers([new Uint16Array([ifds.length]), ...ifdEntryBuffers.values(), new Uint32Array([0])]);
  37842. var ifdValueBuffer = concatBuffers([...ifdValueBuffers.values()]);
  37843. var tiffBuffer = concatBuffers([headerBuffer, ifdBuffer, ifdValueBuffer, image.buffer]);
  37844. return {
  37845. width: width,
  37846. height: height,
  37847. buffer: tiffBuffer
  37848. };
  37849. }
  37850. }
  37851. exports.Tag = Tag;
  37852. exports.Type = Type;
  37853. exports.IFDEntry = IFDEntry;
  37854. exports.Image = Image;
  37855. exports.Reader = Reader;
  37856. exports.Exporter = Exporter;
  37857. return exports;
  37858. }({});
  37859. class Message {
  37860. constructor(content) {
  37861. this.content = content;
  37862. var closeIcon = "".concat(exports.resourcePath, "/icons/close.svg");
  37863. this.element = $("\n\t\t\t<div class=\"potree_message\">\n\t\t\t\t<span name=\"content_container\" style=\"flex-grow: 1; padding: 5px\"></span>\n\t\t\t\t<img name=\"close\" src=\"".concat(closeIcon, "\" class=\"button-icon\" style=\"width: 16px; height: 16px;\">\n\t\t\t</div>"));
  37864. this.elClose = this.element.find("img[name=close]");
  37865. this.elContainer = this.element.find("span[name=content_container]");
  37866. if (typeof content === "string") {
  37867. this.elContainer.append($("<span>".concat(content, "</span>")));
  37868. } else {
  37869. this.elContainer.append(content);
  37870. }
  37871. }
  37872. setMessage(content) {
  37873. this.elContainer.empty();
  37874. if (typeof content === "string") {
  37875. this.elContainer.append($("<span>".concat(content, "</span>")));
  37876. } else {
  37877. this.elContainer.append(content);
  37878. }
  37879. }
  37880. }
  37881. class PointCloudSM {
  37882. constructor(potreeRenderer) {
  37883. this.potreeRenderer = potreeRenderer;
  37884. this.threeRenderer = this.potreeRenderer.threeRenderer;
  37885. this.target = new WebGLRenderTarget(2 * 1024, 2 * 1024, {
  37886. minFilter: LinearFilter,
  37887. magFilter: LinearFilter,
  37888. format: RGBAFormat,
  37889. type: FloatType
  37890. });
  37891. this.target.depthTexture = new DepthTexture();
  37892. this.target.depthTexture.type = UnsignedIntType;
  37893. //this.threeRenderer.setClearColor(0x000000, 1);
  37894. this.threeRenderer.setClearColor(0xff0000, 1);
  37895. //HACK? removed while moving to three.js 109
  37896. //this.threeRenderer.clearTarget(this.target, true, true, true);
  37897. {
  37898. var oldTarget = this.threeRenderer.getRenderTarget();
  37899. this.threeRenderer.setRenderTarget(this.target);
  37900. this.threeRenderer.clear(true, true, true);
  37901. this.threeRenderer.setRenderTarget(oldTarget);
  37902. }
  37903. }
  37904. setLight(light) {
  37905. this.light = light;
  37906. var fov = 180 * light.angle / Math.PI;
  37907. var aspect = light.shadow.mapSize.width / light.shadow.mapSize.height;
  37908. var near = 0.1;
  37909. var far = light.distance === 0 ? 10000 : light.distance;
  37910. this.camera = new PerspectiveCamera(fov, aspect, near, far);
  37911. this.camera.up.set(0, 0, 1);
  37912. this.camera.position.copy(light.position);
  37913. var target = new Vector3().subVectors(light.position, light.getWorldDirection(new Vector3()));
  37914. this.camera.lookAt(target);
  37915. this.camera.updateProjectionMatrix();
  37916. this.camera.updateMatrix();
  37917. this.camera.updateMatrixWorld();
  37918. this.camera.matrixWorldInverse.copy(this.camera.matrixWorld).invert();
  37919. }
  37920. setSize(width, height) {
  37921. if (this.target.width !== width || this.target.height !== height) {
  37922. this.target.dispose();
  37923. }
  37924. this.target.setSize(width, height);
  37925. }
  37926. render(scene, camera) {
  37927. this.threeRenderer.setClearColor(0x000000, 1);
  37928. var oldTarget = this.threeRenderer.getRenderTarget();
  37929. this.threeRenderer.setRenderTarget(this.target);
  37930. this.threeRenderer.clear(true, true, true);
  37931. this.potreeRenderer.render(scene, this.camera, this.target, {});
  37932. this.threeRenderer.setRenderTarget(oldTarget);
  37933. }
  37934. }
  37935. class Label extends EventDispatcher {
  37936. constructor() {
  37937. var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  37938. super();
  37939. this.position = o.pos;
  37940. this.text = o.text || '';
  37941. this.elem = $('<div class="hide"><a></a></div>');
  37942. o.className && this.elem.addClass(o.className);
  37943. this.elem.find('a').html(this.text);
  37944. $("#potree_labels").append(this.elem);
  37945. this.pos2d = new Vector3();
  37946. this.dom = o.dom || viewer.renderArea;
  37947. this.camera = o.camera || viewer.scene.getActiveCamera();
  37948. var update = e => {
  37949. this.update(e);
  37950. };
  37951. viewer.addEventListener('camera_changed', update);
  37952. this.addEventListener('dispose', () => {
  37953. viewer.removeEventListener('camera_changed', update);
  37954. this.dispose();
  37955. });
  37956. }
  37957. update() {
  37958. if (!this.position || this.elem.hasClass('unvisible')) return;
  37959. var p = Utils.getPos2d(this.position, viewer.mainViewport, this.dom);
  37960. if (!p.trueSide) {
  37961. this.elem.addClass("hide");
  37962. return;
  37963. }
  37964. this.elem.css({
  37965. left: p.pos.x + 'px',
  37966. top: p.pos.y + 'px'
  37967. });
  37968. this.elem.removeClass("hide");
  37969. this.pos2d = p.vector;
  37970. }
  37971. setVisible(visi) {
  37972. if (!visi) {
  37973. this.elem.addClass("unvisible");
  37974. } else {
  37975. this.elem.removeClass("unvisible");
  37976. this.update();
  37977. }
  37978. }
  37979. setText(text) {
  37980. this.text = text || '';
  37981. this.elem.find('a').html(this.text);
  37982. }
  37983. setPos(pos) {
  37984. this.position = pos;
  37985. }
  37986. dispose() {
  37987. this.elem.remove();
  37988. this.removeAllListeners();
  37989. }
  37990. }
  37991. //THREE.Vector2.name1 = 'ctrlPolygon'
  37992. var verticalLine = new Line3();
  37993. //控制点和边的合集。具有可以拖拽修改的功能,拖拽时能防止线相交。
  37994. class ctrlPolygon extends Object3D {
  37995. constructor(type, prop) {
  37996. super();
  37997. this.type = type;
  37998. this.maxMarkers = Number.MAX_SAFE_INTEGER;
  37999. this.transformData(prop);
  38000. for (var i in prop) {
  38001. this[i] = prop[i];
  38002. }
  38003. if ((this.atPlane || this.showArea) && this.closed && this.dimension == '2d') {
  38004. this.areaPlane = this.createAreaPlane();
  38005. this.add(this.areaPlane);
  38006. }
  38007. //数据--刚开始一定是空的
  38008. this.points = [];
  38009. //mesh 不一定有
  38010. this.markers = [];
  38011. this.edges = [];
  38012. this.center;
  38013. }
  38014. initData(prop) {
  38015. //开始加数据
  38016. prop.dataset_points && (this.dataset_points = prop.dataset_points);
  38017. prop.datasetId && (this.datasetId = prop.datasetId);
  38018. prop.points_datasets && (this.points_datasets = prop.points_datasets);
  38019. if (Potree.settings.editType == 'merge' || this.measureType == 'MulDistance Ring') {
  38020. //融合页面没有地图,measure的不需要指定datasetId,每个点都有各自的datasetId,跟着各自的模型走
  38021. if (this.dataset_points) {
  38022. this.dataset_points = this.dataset_points.map(e => {
  38023. return e && new Vector3().copy(e);
  38024. });
  38025. prop.points = this.dataset_points.map((p, i) => {
  38026. return Potree.Utils.datasetPosTransform({
  38027. fromDataset: true,
  38028. datasetId: this.points_datasets[i],
  38029. position: p
  38030. });
  38031. });
  38032. if (prop.points.some(e => e == void 0)) {
  38033. return false;
  38034. }
  38035. } else {
  38036. this.dataset_points = [];
  38037. }
  38038. }
  38039. if (prop.points) {
  38040. for (var p of prop.points) {
  38041. var pos = new Vector3().copy(p);
  38042. this.addMarker({
  38043. point: pos
  38044. });
  38045. }
  38046. if (Potree.settings.editType != 'merge' && this.measureType != 'MulDistance Ring') {
  38047. if (this.datasetId != void 0) {
  38048. //初始化位置
  38049. if (this.dataset_points) {
  38050. this.dataset_points = this.dataset_points.map(e => {
  38051. return e && new Vector3().copy(e);
  38052. });
  38053. this.transformByPointcloud(); //根据dataset_points和this.datasetId生成points
  38054. }
  38055. } else {
  38056. if (prop.dataset_points && prop.dataset_points.some(e => e != void 0)) {
  38057. console.error('存在测量线的datasetId为空而dataset_points有值,请检查并删除:' + this.sid); //存在过的bug,原因未知,可能是后台处理dataset时替换的错误:http://192.168.0.21/index.php?m=bug&f=view&bugID=23601
  38058. console.log(this);
  38059. }
  38060. }
  38061. }
  38062. this.facePlane = this.getFacePlane();
  38063. this.getPoint2dInfo(this.points);
  38064. this.update({
  38065. ifUpdateMarkers: true
  38066. });
  38067. //this.dragChange(new THREE.Vector3().copy(prop.points[prop.points.length-1]), prop.points.length-1);
  38068. this.setSelected(false);
  38069. this.markers.forEach(marker => {
  38070. marker.dispatchEvent('addHoverEvent');
  38071. });
  38072. return true;
  38073. }
  38074. }
  38075. addMarker() {
  38076. var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  38077. var index = o.index == void 0 ? this.points.length : o.index; //要当第几个
  38078. this.points = [...this.points.slice(0, index), o.point.clone(), ...this.points.slice(index, this.points.length)];
  38079. //this.points.push(o.point);
  38080. if ('dataset_point' in o) {
  38081. //需要增加,可能是null
  38082. this.dataset_points = this.dataset_points ? [...this.dataset_points.slice(0, index), o.dataset_point && o.dataset_point.clone(), ...this.dataset_points.slice(index, this.dataset_points.length)] : null; //如果原本是null,新加的应该也是
  38083. }
  38084. if ('points_dataset' in o) {
  38085. this.points_datasets = [...this.points_datasets.slice(0, index), o.points_dataset, ...this.points_datasets.slice(index, this.points_datasets.length)];
  38086. }
  38087. if (o.marker) {
  38088. this.add(o.marker);
  38089. this.markers = [...this.markers.slice(0, index), o.marker, ...this.markers.slice(index, this.markers.length)];
  38090. this.updateMarker(o.marker, o.point);
  38091. o.marker.addEventListener('drag', this.dragMarker.bind(this), {
  38092. importance: 2
  38093. });
  38094. o.marker.addEventListener('drop', this.dropMarker.bind(this), {
  38095. importance: 2
  38096. });
  38097. o.marker.createTime = Date.now();
  38098. var addHoverEvent = e => {
  38099. var mouseover = e => {
  38100. this.setMarkerSelected(e.object, 'hover', 'single');
  38101. viewer.dispatchEvent({
  38102. type: "CursorChange",
  38103. action: "add",
  38104. name: "markerMove"
  38105. });
  38106. };
  38107. var mouseleave = e => {
  38108. this.setMarkerSelected(e.object, 'unhover', 'single');
  38109. viewer.dispatchEvent({
  38110. type: "CursorChange",
  38111. action: "remove",
  38112. name: "markerMove"
  38113. });
  38114. };
  38115. o.marker.addEventListener('mouseover', mouseover);
  38116. o.marker.addEventListener('mouseleave', mouseleave);
  38117. o.marker.addEventListener('startDragging', e => {
  38118. //for mobile
  38119. this.setMarkerSelected(o.marker, 'hover', 'single');
  38120. this.dispatchEvent('startDragging');
  38121. });
  38122. o.marker.addEventListener('drop', e => {
  38123. //for mobile
  38124. this.setMarkerSelected(o.marker, 'unhover', 'single');
  38125. });
  38126. o.marker.removeEventListener('addHoverEvent', addHoverEvent);
  38127. };
  38128. o.marker.addEventListener('addHoverEvent', addHoverEvent); //当非isNew时才添加事件
  38129. if (!this.isNew) {
  38130. o.marker.dispatchEvent('addHoverEvent');
  38131. }
  38132. }
  38133. if (o.edge) {
  38134. this.add(o.edge);
  38135. this.edges = [...this.edges.slice(0, index), o.edge, ...this.edges.slice(index, this.edges.length)];
  38136. }
  38137. }
  38138. dragMarker(e) {
  38139. var I, atMap;
  38140. if (e.hoverViewport != e.drag.dragViewport) {
  38141. //不能使用e.dragViewport,要使用drag中的,因为drag中存储的要一直继承下来,不因mouseup了而改变。
  38142. viewer.dispatchEvent({
  38143. type: "CursorChange",
  38144. action: "add",
  38145. name: "polygon_AtWrongPlace"
  38146. });
  38147. return;
  38148. }
  38149. if (e.drag.pointerDelta.length() == 0 && !this.isNew) {
  38150. //部分设备(华为matePad11)在touchstart后立即执行了touchmove,导致marker立即移动,需要屏蔽..(刚创建时也会是0)
  38151. return;
  38152. }
  38153. viewer.dispatchEvent({
  38154. type: "CursorChange",
  38155. action: "remove",
  38156. name: "polygon_AtWrongPlace"
  38157. });
  38158. atMap = e.drag.dragViewport.name == 'mapViewport';
  38159. if (atMap && this.unableDragAtMap) {
  38160. e.drag.object = null; //取消拖拽
  38161. return;
  38162. }
  38163. e.drag.object.isDragging = true;
  38164. I = e.intersect && (e.intersect.adsorption ? e.intersect.location : e.intersect.orthoIntersect || e.intersect.location);
  38165. if (viewer.inputHandler.pressedKeys[18] || Potree.settings.dragPolyBeyondPoint && !I) {
  38166. //alt dragPolyBeyondPoint可以平移拖拽到无点的地方---测试用
  38167. var i = this.markers.indexOf(e.drag.object);
  38168. I = this.points[i].clone();
  38169. var projected = I.clone().project(e.drag.dragViewport.camera);
  38170. projected.x = e.pointer.x;
  38171. projected.y = e.pointer.y;
  38172. var unprojected = projected.clone().unproject(e.drag.dragViewport.camera);
  38173. I.copy(unprojected);
  38174. }
  38175. if (I) {
  38176. var _i = this.markers.indexOf(e.drag.object);
  38177. if (_i !== -1) {
  38178. this.dragChange(I.clone(), _i, atMap);
  38179. if (this.points_datasets) {
  38180. if (e.intersect) {
  38181. if (e.intersect.pointcloud) this.points_datasets[_i] = e.intersect.pointcloud.dataset_id;else if (e.intersect.object) this.points_datasets[_i] = e.intersect.object.dataset_id;else {
  38182. //地图
  38183. if (this.measureType == 'MulDistance Ring') {
  38184. //因为它的每个point跟着各自的dataset走,而不是整体的dataset
  38185. var pointcloud = viewer.findClosestDatasetOnMap(I) || viewer.scene.pointclouds[0];
  38186. this.points_datasets[_i] = pointcloud.dataset_id;
  38187. } else this.points_datasets[_i] = null;
  38188. }
  38189. }
  38190. }
  38191. }
  38192. this.editStateChange(true);
  38193. return true;
  38194. }
  38195. }
  38196. dragChange(intersectPos, i, atMap) {
  38197. var len = this.markers.length;
  38198. var oldPoint = this.points[i];
  38199. if (atMap) {
  38200. intersectPos.setZ(oldPoint.z); //在地图上拖拽,不改变其高度。
  38201. }
  38202. var location = intersectPos.clone();
  38203. if (this.faceDirection && this.maxMarkers == 2 && len == 2) {
  38204. //add 固定方向的点不直接拖拽
  38205. var p1 = this.markers[0].position;
  38206. if (this.faceDirection == 'horizontal') {
  38207. var projectPos = location.clone().setZ(p1.z);
  38208. } else {
  38209. var projectPos = p1.clone().setZ(location.z);
  38210. }
  38211. //var p2 = p1.clone().add(this.direction)
  38212. //var projectPos = math.getFootPoint(location, p1, p2)
  38213. LineDraw.updateLine(this.guideLine, [location, projectPos]);
  38214. location = projectPos;
  38215. this.guideLine.visible = true;
  38216. } else if (len > 1) {
  38217. var points = this.points.map(e => e.clone());
  38218. points[i].copy(location); //算normal需要提前确认point
  38219. //若为定义了面朝向的矩形
  38220. if (this.faceDirection == 'horizontal') {
  38221. if (len == 2) {
  38222. location.setZ(points[0].z);
  38223. }
  38224. if (!this.facePlane) {
  38225. //一个点就能确定面
  38226. this.facePlane = new Plane().setFromNormalAndCoplanarPoint(new Vector3(0, 0, 1), this.points[0]);
  38227. }
  38228. } else if (this.faceDirection == 'vertical') {
  38229. //当有两个点时, 有两个方向的可能
  38230. if (len == 2) {
  38231. if (this.isRect) {
  38232. var _vec = points[0].clone().sub(location);
  38233. if (Math.sqrt(_vec.x * _vec.x + _vec.y * _vec.y) > Math.abs(_vec.z)) {
  38234. //水平(高度差小于水平距离时)
  38235. location.setZ(points[0].z);
  38236. //this.cannotConfirmNormal = false;//能确定面为水平方向
  38237. } else {
  38238. //垂直 (当两点一样时也属于这种)
  38239. location.setX(points[0].x);
  38240. location.setY(points[0].y);
  38241. //this.cannotConfirmNormal = true; //不能确定面,因第三点可绕着纵轴线自由移动
  38242. }
  38243. }
  38244. } else {
  38245. {
  38246. //判断cannotConfirmNormal. 如果前几段都在竖直线上,就不能固定出面方向。
  38247. this.cannotConfirmNormal = true;
  38248. var max = this.isRect ? 1 : len - 2;
  38249. for (var _i2 = 0; _i2 < max; _i2++) {
  38250. var _p = points[_i2].clone();
  38251. var _p2 = points[_i2 + 1].clone();
  38252. var _vec2 = _p.sub(_p2);
  38253. if (_vec2.x != 0 || _vec2.y != 0) {
  38254. this.cannotConfirmNormal = false;
  38255. break;
  38256. }
  38257. }
  38258. }
  38259. if (!this.facePlane || this.cannotConfirmNormal) {
  38260. //三个点且为水平方向时,计算面
  38261. var points_ = points.map(e => new Vector2(e.x, e.y));
  38262. var points2 = getDifferentPoint(points_, 2);
  38263. if (points2) {
  38264. var normal = math.getNormal2d({
  38265. p1: points2[0],
  38266. p2: points2[1]
  38267. });
  38268. normal = new Vector3(normal.x, normal.y, 0);
  38269. this.facePlane = new Plane().setFromNormalAndCoplanarPoint(normal, this.points[0]);
  38270. }
  38271. }
  38272. }
  38273. }
  38274. if (len > 2) {
  38275. if (!this.faceDirection && this.showArea) {
  38276. if (len == 3 || this.isRect) this.cannotConfirmNormal = true; //当第三个点固定后(有四个点时)才能固定面
  38277. if (!this.facePlane || this.cannotConfirmNormal) {
  38278. var points3 = getDifferentPoint(points, 3); //只有找到三个不同的点算拥有面和area
  38279. if (points3) {
  38280. this.facePlane = new Plane().setFromCoplanarPoints(...points3);
  38281. }
  38282. }
  38283. }
  38284. if (this.atPlane && this.facePlane && !this.cannotConfirmNormal) {
  38285. //之后加的点一定要在面上
  38286. if (atMap) {
  38287. //地图上用垂直线,得到和面的交点。
  38288. verticalLine.set(location.clone().setZ(100000), location.clone().setZ(-100000)); //确保长度范围覆盖所有测量面
  38289. location = this.facePlane.intersectLine(verticalLine, new Vector3());
  38290. if (!location) return;
  38291. } else {
  38292. location = this.facePlane.projectPoint(intersectPos, new Vector3());
  38293. }
  38294. }
  38295. points[i].copy(location); //再copy确认一次
  38296. if (len == 3 && this.faceDirection == 'horizontal' && this.closed) {
  38297. //normal方向还不确定 会影响label在里侧还是外侧
  38298. var facePlane = new Plane().setFromCoplanarPoints(...points);
  38299. if (facePlane.normal.z && facePlane.normal.z * this.facePlane.normal.z < 0) {
  38300. this.facePlane.normal.z *= -1, this.facePlane.constant *= -1;
  38301. //console.log(this.facePlane.normal, this.facePlane.constant)
  38302. }
  38303. }
  38304. if (this.isRect) {
  38305. //是矩形 (即使没有faceDirection也能执行)
  38306. //根据前两个点计算当前和下一个点
  38307. var p1 = points[(i - 2 + len) % len];
  38308. var p2 = points[(i - 1 + len) % len];
  38309. if (p1.equals(p2)) {
  38310. //意外情况:重复点两次 ( bug点,改了好多遍)
  38311. if (this.faceDirection == 'vertical') {
  38312. p2.add(new Vector3(0, 0, 0.0001));
  38313. } else {
  38314. p2.add(new Vector3(0, 0.0001, 0));
  38315. }
  38316. }
  38317. //p3 : location
  38318. var foot = math.getFootPoint(location, p1, p2); //p2 修改p2到垂足的位置
  38319. var vec = foot.clone().sub(location);
  38320. var p4 = p1.clone().sub(vec);
  38321. points[(i - 1 + len) % len].copy(foot);
  38322. points[(i + 1) % len].copy(p4);
  38323. this.setPosition((i - 1 + len) % len, foot); //p2
  38324. this.setPosition((i + 1) % len, p4);
  38325. }
  38326. this.getPoint2dInfo(points);
  38327. var isIntersectSelf = this.atPlane && this.closed && !this.isRect && this.point2dInfo && this.intersectSelf(this.point2dInfo.points2d); //检测相交
  38328. this.isIntersectSelf = isIntersectSelf;
  38329. if (isIntersectSelf) {
  38330. //not-allowed
  38331. if (!this.isNew && isIntersectSelf == 'lastLine') this.isIntersectSelf = 'all'; //已经画好了就不用特别对待最后一条线
  38332. if (this.isIntersectSelf == 'lastLine') {
  38333. Potree.Utils.updateVisible(this.areaPlane, 'intersectLastLine', false);
  38334. Potree.Utils.updateVisible(this.areaLabel, 'intersectLastLine', false);
  38335. } else {
  38336. viewer.dispatchEvent({
  38337. type: "CursorChange",
  38338. action: "add",
  38339. name: "polygon_isIntersectSelf"
  38340. });
  38341. return;
  38342. }
  38343. }
  38344. if (!this.isIntersectSelf) {
  38345. this.areaPlane && Potree.Utils.updateVisible(this.areaPlane, 'intersectLastLine', true);
  38346. this.areaLabel && Potree.Utils.updateVisible(this.areaLabel, 'intersectLastLine', true);
  38347. }
  38348. if (!this.isIntersectSelf || this.isIntersectSelf == 'lastLine') {
  38349. viewer.dispatchEvent({
  38350. type: "CursorChange",
  38351. action: "remove",
  38352. name: "polygon_isIntersectSelf"
  38353. });
  38354. }
  38355. }
  38356. var showGuideLine = len > 1 && (this.faceDirection || len > 3);
  38357. if (showGuideLine && this.guideLine) {
  38358. LineDraw.updateLine(this.guideLine, [intersectPos, location]);
  38359. this.guideLine.visible = true;
  38360. }
  38361. //console.log(this.points.map(e=>e.toArray()))
  38362. }
  38363. if (this.restrictArea) {
  38364. var holes = this.restrictArea.holes.concat(this.restrictArea.parentHoles);
  38365. var holesPoints = holes.filter(e => e != this && e.points.length > 2).map(e => e.points);
  38366. if (!math.isPointInArea(this.restrictArea.points, holesPoints, location)) {
  38367. viewer.dispatchEvent({
  38368. type: "CursorChange",
  38369. action: "add",
  38370. name: "polygon_AtWrongPlace"
  38371. });
  38372. this.isAtWrongPlace = true;
  38373. return;
  38374. }
  38375. //就不处理相交线了。 有个缺点:floor上的hole可以限制room,但hole不受room限制,会导致room的marker被框在hole里而动不了。只能去调整hole了
  38376. }
  38377. viewer.dispatchEvent({
  38378. type: "CursorChange",
  38379. action: "remove",
  38380. name: "polygon_AtWrongPlace"
  38381. });
  38382. this.isAtWrongPlace = false;
  38383. this.setPosition(i, location);
  38384. this.update({
  38385. index: this.isRect ? null : i
  38386. });
  38387. this.dispatchEvent({
  38388. type: 'dragChange',
  38389. index: i
  38390. });
  38391. }
  38392. dropMarker(e) {
  38393. //console.log('dropMarker')
  38394. if (this.isNew && e.pressDistance > Potree.config.clickMaxDragDis) {
  38395. //拖拽的话返回
  38396. return this.continueDrag(null, e);
  38397. }
  38398. if (e.hoverViewport != e.drag.dragViewport) {
  38399. //copy from dragMarker, for sitemodel, only mapViewport can be dropped
  38400. return this.continueDrag(null, e);
  38401. }
  38402. if (e.isTouch) {
  38403. if (e.hoverViewport != viewer.mainViewport && this.unableDragAtMap) {
  38404. viewer.dispatchEvent({
  38405. type: 'reticule_forbit',
  38406. v: true
  38407. });
  38408. //console.log('reticule_forbit',true)
  38409. return this.continueDrag(null, e);
  38410. } else {
  38411. viewer.dispatchEvent({
  38412. type: 'reticule_forbit',
  38413. v: false
  38414. });
  38415. //console.log('reticule_forbit',false)
  38416. }
  38417. this.isNew && this.dragMarker(e); //isNew触屏点击时必须先更新下点,因为指尖不在屏幕上时没更新。但对已经创建的marker点击时不应该更新
  38418. }
  38419. if (e.button != MOUSE.RIGHT && (
  38420. //右键click的话继续执行,因为会停止
  38421. this.isIntersectSelf == 'all' && this.isNew //有线相交了
  38422. || this.isAtWrongPlace && this.isNew || !e.isAtDomElement && this.isNew //如果是刚添加时在其他dom点击, 不要响应
  38423. || e.hoverViewport != viewer.mainViewport && this.unableDragAtMap //垂直的测量线不允许在地图上放点
  38424. || this.isNew && !getDifferentPoint(this.points, this.points.length) //不允许和之前的点相同, 但这句在点云稀疏时会导致难结束
  38425. )) {
  38426. return this.continueDrag(null, e);
  38427. }
  38428. //console.log('drop marker' )
  38429. var i = this.markers.indexOf(e.drag.object);
  38430. if (i !== -1) {
  38431. this.dispatchEvent({
  38432. 'type': 'marker_dropped',
  38433. 'index': i
  38434. });
  38435. if (this.markers.length > 2 && this.facePlane) this.cannotConfirmNormal = false;
  38436. this.guideLine && (this.guideLine.visible = false);
  38437. }
  38438. this.setMarkerSelected(e.drag.object, 'unhover', 'single');
  38439. this.editStateChange(false);
  38440. e.drag.endDragFun && e.drag.endDragFun(e); // addmarker
  38441. //if(this.changeCallBack)this.changeCallBack()
  38442. return true;
  38443. }
  38444. getFacePlane() {
  38445. //最普通一种get方法,根据顶点。且假设所有点已经共面,且不重合
  38446. if ( /* !this.atPlane || */this.points.length < 3) return;
  38447. /* this.facePlane = new THREE.Plane().setFromCoplanarPoints(...this.points.slice(0,3) ) */
  38448. var facePlane = this.facePlane;
  38449. if (!this.atPlane || !facePlane) {
  38450. //多折线 没有实时更新facePlane所以重新算
  38451. var normal = new Vector3(),
  38452. len = this.points.length - 2;
  38453. for (var i = 0; i < len; i++) {
  38454. //获取normal的顺序方法必须和setFromCoplanarPoints一致
  38455. var vec0 = new Vector3().subVectors(this.points[i + 2], this.points[i + 1]);
  38456. var vec1 = new Vector3().subVectors(this.points[i], this.points[i + 1]);
  38457. var nor = vec0.cross(vec1).normalize();
  38458. normal.add(nor);
  38459. }
  38460. normal.normalize();
  38461. facePlane = new Plane().setFromNormalAndCoplanarPoint(normal, this.points[0]);
  38462. }
  38463. return facePlane;
  38464. }
  38465. getPoint2dInfo(points) {
  38466. //在更新areaplane之前必须更新过point2dInfo (针对所有点在同一平面上的)
  38467. if (this.facePlane && (this.atPlane || Potree.settings.areaAtNotPlane)) {
  38468. var facePlane = this.getFacePlane();
  38469. var originPoint0 = points[0].clone();
  38470. var qua = math.getQuaBetween2Vector(facePlane.normal, new Vector3(0, 0, 1), new Vector3(0, 0, 1));
  38471. var points2d = points.map(e => e.clone().applyQuaternion(qua));
  38472. this.point2dInfo = {
  38473. originPoint0,
  38474. points2d,
  38475. quaInverse: qua.clone().invert()
  38476. };
  38477. }
  38478. }
  38479. setPosition(index, position) {
  38480. //拖拽后设置位置
  38481. var point = this.points[index];
  38482. point.copy(position);
  38483. /* if(this.datasetId){
  38484. this.dataset_points[index] = Potree.Utils.datasetPosTransform({toDataset:true, datasetId:this.datasetId, position:point.clone()})
  38485. } */
  38486. /* if(Potree.settings.editType == 'merge'){
  38487. this.dataset_points[index] = Potree.Utils.datasetPosTransform({toDataset:true,this.points_datasets[i], position:point.clone()})
  38488. } */
  38489. var marker = this.markers[index];
  38490. this.updateMarker(marker, point);
  38491. }
  38492. updateMarker(marker, pos) {
  38493. marker.position.copy(pos);
  38494. marker.waitUpdate();
  38495. }
  38496. intersectSelf(points2d) {
  38497. //add
  38498. var len = points2d.length;
  38499. for (var i = 0; i < len; i++) {
  38500. for (var j = i + 2; j < len; j++) {
  38501. if (Math.abs(j - len - i) < 2) continue; //不和邻边比
  38502. var p1 = points2d[i];
  38503. var p2 = points2d[i + 1];
  38504. var p3 = points2d[j];
  38505. var p4 = points2d[(j + 1) % len];
  38506. if (p1.equals(p2) || p3.equals(p4) || p1.equals(p3) || p2.equals(p3) || p1.equals(p4) || p2.equals(p4)) continue;
  38507. var line1 = [p1, p2];
  38508. var line2 = [p3, p4];
  38509. var intersect = math.isLineIntersect(line1, line2, false, 0.001);
  38510. if (intersect) {
  38511. if (i == len - 1 || j == len - 1) {
  38512. //最后一条线。如果还没绘制完,最后的线还没定下,可被允许继续绘制,但无法显示面积。
  38513. return 'lastLine';
  38514. } else {
  38515. return 'all';
  38516. }
  38517. break;
  38518. }
  38519. }
  38520. }
  38521. }
  38522. removeMarker(index) {
  38523. this.points.splice(index, 1);
  38524. var marker = this.markers[index];
  38525. //this.remove(marker);
  38526. this.markers.splice(index, 1);
  38527. marker.dispose();
  38528. var edgeIndex = index; //(index === 0) ? 0 : (index - 1);
  38529. var edge = this.edges[edgeIndex];
  38530. if (edge) {
  38531. this.remove(edge);
  38532. this.edges.splice(edgeIndex, 1);
  38533. edge.geometry.dispose();
  38534. }
  38535. this.point2dInfo && this.point2dInfo.points2d.splice(index, 1); //add
  38536. this.dispatchEvent({
  38537. type: 'removeMarker',
  38538. index,
  38539. marker
  38540. });
  38541. }
  38542. createAreaPlane(mat) {
  38543. var geometry = new Geometry();
  38544. var mesh = new Mesh(geometry, mat);
  38545. return mesh;
  38546. }
  38547. updateAreaPlane() {
  38548. this.areaPlane.geometry.dispose();
  38549. if (this.points.length > 2) {
  38550. if (this.isPrism) {
  38551. var z = this.horizonZ || 0;
  38552. var points2d = this.points.map(e => e.clone().setZ(z));
  38553. this.areaPlane.geometry = MeshDraw.getShapeGeo(points2d); //z=0
  38554. var center = math.getCenterOfGravityPoint(points2d); //重心
  38555. this.areaPlaneCenter = new Vector3(center.x, center.y, z);
  38556. this.areaPlane.position.z = z;
  38557. } else if (this.point2dInfo) {
  38558. if (Potree.settings.areaAtNotPlane) {
  38559. //测点不在同一平面的面积. (缺点:容易出现三角缺块, 以及搭错线导致超出理想边界外。在平面上n个点能构成n-2个三角形,但空间中更多个,所以若要指定出类似平面那样n-2个三角形是有多种可能的。故暂不开放。 用d3.Delaunay结果更差) //测试桥面 SG-arqnGgAR7om&formal
  38560. //参考 http://indoor.popsmart.cn:8084/sxswsw-sx/ 找到场景中面积测量线的方法:window.scene.children[18].children[0].material.color.r = 1
  38561. var geometry = new Geometry();
  38562. var faceArray = [],
  38563. triangles = ShapeUtils.triangulateShape(this.point2dInfo.points2d, []); //因为它只关注xy平面,垂直画就容易错,所以用转到平面的points2d来识别三角。
  38564. if (triangles.length == 0) return;
  38565. this._area = 0;
  38566. for (var i = 0; i < triangles.length; i++) {
  38567. faceArray[i] = new Face3(triangles[i][0], triangles[i][1], triangles[i][2]);
  38568. var nor = new Vector3().crossVectors(new Vector3().subVectors(this.points[triangles[i][0]], this.points[triangles[i][2]]), new Vector3().subVectors(this.points[triangles[i][1]], this.points[triangles[i][2]]));
  38569. this._area += nor.length() / 2;
  38570. nor.normalize();
  38571. faceArray[i].normal.copy(nor);
  38572. }
  38573. geometry.vertices = this.points;
  38574. geometry.faces = faceArray;
  38575. this.areaPlane.geometry = new BufferGeometry().fromGeometry(geometry); //不知道为何不转为bufferGeometry显示不出
  38576. //this.center
  38577. //参考getFacePlane 在这里建立_normal?
  38578. } else {
  38579. //if(this.point2dInfo){//旧的。 之前的规定点要在同一平面
  38580. this.areaPlane.geometry = MeshDraw.getShapeGeo(this.point2dInfo.points2d);
  38581. var _center = math.getCenterOfGravityPoint(this.point2dInfo.points2d); //重心
  38582. var firstPos = this.point2dInfo.points2d[0].clone();
  38583. firstPos.z = 0; //因为shape只读取了xy,所以位移下, 再算出最终位置,得到差距
  38584. firstPos.applyQuaternion(this.point2dInfo.quaInverse);
  38585. var vec = this.point2dInfo.originPoint0.clone().sub(firstPos);
  38586. _center = new Vector3(_center.x, _center.y, 0);
  38587. _center.applyQuaternion(this.point2dInfo.quaInverse);
  38588. this.areaPlane.quaternion.copy(this.point2dInfo.quaInverse);
  38589. this.areaPlane.position.copy(vec);
  38590. _center.add(vec);
  38591. this.center = _center;
  38592. //}
  38593. }
  38594. }
  38595. } else {
  38596. this.areaPlane.geometry = new Geometry();
  38597. }
  38598. }
  38599. getIndex(index, add) {
  38600. var lastIndex = this.points.length - 1;
  38601. if (add == -1) return index === 0 ? lastIndex : index - 1;else if (add == 1) return index + 1 > lastIndex ? 0 : index + 1;
  38602. }
  38603. update() {
  38604. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  38605. if (this.points.length === 0) {
  38606. return;
  38607. }
  38608. //performance.mark('measureUpdate-start')
  38609. var lastIndex = this.points.length - 1;
  38610. if (options.index != void 0) {
  38611. //更新第几个点
  38612. this.updateMarker(this.markers[options.index], this.points[options.index]);
  38613. var previousIndex = this.getIndex(options.index, -1);
  38614. var nextIndex = this.getIndex(options.index, +1);
  38615. if (this.closed || nextIndex != 0) LineDraw.updateLine(this.edges[options.index], [this.points[options.index], this.points[nextIndex]]);
  38616. if (this.closed || previousIndex != lastIndex) LineDraw.updateLine(this.edges[previousIndex], [this.points[options.index], this.points[previousIndex]]);
  38617. } else {
  38618. for (var index = 0; index <= lastIndex; index++) {
  38619. var _nextIndex = this.getIndex(index, +1);
  38620. var _previousIndex = this.getIndex(index, -1);
  38621. var point = this.points[index];
  38622. var nextPoint = this.points[_nextIndex];
  38623. var previousPoint = this.points[_previousIndex];
  38624. if (options.ifUpdateMarkers) {
  38625. this.updateMarker(this.markers[index], point);
  38626. }
  38627. if (!this.closed && _nextIndex == 0) break; //add
  38628. {
  38629. var edge = this.edges[index];
  38630. if (edge) {
  38631. LineDraw.updateLine(edge, [point, nextPoint]);
  38632. }
  38633. }
  38634. }
  38635. }
  38636. if (this.areaPlane) {
  38637. this.updateAreaPlane();
  38638. }
  38639. //this.dispatchEvent({type:'update'})
  38640. viewer.dispatchEvent('content_changed');
  38641. viewer.mapViewer && viewer.mapViewer.dispatchEvent('content_changed'); //暂时先这么都通知
  38642. //performance.mark('measureUpdate-end')
  38643. //let measure = performance.measure('measure-','measureUpdate-start', 'measureUpdate-end' );
  38644. //console.log('update-time', measure.duration)
  38645. }
  38646. createPrismLines(color) {
  38647. this.lineMesh = LineDraw.createLine([], {
  38648. color
  38649. });
  38650. this.lineMesh.name = 'PrismLines';
  38651. this.add(this.lineMesh);
  38652. }
  38653. updatePrismLines() {
  38654. if (!this.lineMesh) return;
  38655. var positions = [];
  38656. var length = this.points.length;
  38657. this.points.forEach((point, index) => {
  38658. //竖线:
  38659. positions.push(point.clone().setZ(this.zMin), point.clone().setZ(this.zMax));
  38660. //横线
  38661. var nextPoint = this.points[(index + 1) % length];
  38662. if (!nextPoint) return; //when length==1
  38663. positions.push(point.clone().setZ(this.zMax), nextPoint.clone().setZ(this.zMax)); //上横线
  38664. positions.push(point.clone().setZ(this.zMin), nextPoint.clone().setZ(this.zMin)); //下横线
  38665. });
  38666. LineDraw.moveLine(this.lineMesh, positions);
  38667. viewer.dispatchEvent('content_changed');
  38668. }
  38669. dispose() {
  38670. //add
  38671. this.parent.remove(this);
  38672. this.markers.forEach(e => e.dispose());
  38673. this.edges.forEach(e => e.geometry.dispose());
  38674. }
  38675. reDraw() {
  38676. var restMarkerCount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  38677. //重新开始画
  38678. var pointCount = this.points.length - restMarkerCount; // restMarkerCount为需要留下的marker数量
  38679. while (pointCount > 0) {
  38680. this.removeMarker(--pointCount);
  38681. }
  38682. this.point2dInfo = null;
  38683. this.facePlane = null;
  38684. }
  38685. setMarkerSelected() {}
  38686. editStateChange(state) {
  38687. if (!state) {
  38688. viewer.dispatchEvent({
  38689. type: "CursorChange",
  38690. action: "remove",
  38691. name: "polygon_isIntersectSelf"
  38692. });
  38693. viewer.dispatchEvent({
  38694. type: "CursorChange",
  38695. action: "remove",
  38696. name: "polygon_AtWrongPlace"
  38697. });
  38698. viewer.dispatchEvent({
  38699. type: 'reticule_forbit',
  38700. v: false
  38701. });
  38702. this.markers.forEach(e => e.isDragging = false);
  38703. }
  38704. }
  38705. transformData(prop) {
  38706. var pick = (defaul, alternative) => {
  38707. if (defaul != null) {
  38708. return defaul;
  38709. } else {
  38710. return alternative;
  38711. }
  38712. };
  38713. prop.showDistances = prop.showDistances === null ? true : prop.showDistances;
  38714. prop.showArea = pick(prop.showArea, false);
  38715. prop.showAngles = pick(prop.showAngles, false);
  38716. prop.showCoordinates = pick(prop.showCoordinates, false);
  38717. prop.showHeight = pick(prop.showHeight, false);
  38718. prop.showCircle = pick(prop.showCircle, false);
  38719. prop.showAzimuth = pick(prop.showAzimuth, false);
  38720. prop.showEdges = pick(prop.showEdges, true);
  38721. prop.closed = pick(prop.closed, false);
  38722. prop.maxMarkers = pick(prop.maxMarkers, Infinity);
  38723. prop.direction = prop.direction; //add
  38724. prop.type = prop.type;
  38725. prop.showGuideLine = pick(prop.showGuideLine, false);
  38726. prop.isRect = pick(prop.isRect, false);
  38727. }
  38728. setSelected() {}
  38729. continueDrag(marker, e) {
  38730. var object = marker || e.drag.object;
  38731. object.isDragging = true;
  38732. this.editStateChange(true);
  38733. var timer = setTimeout(() => {
  38734. //等 drag=null之后 //右键拖拽结束后需要重新得到drag
  38735. if (this.parent && object.parent && object.isDragging) {
  38736. //console.log('continueDrag')
  38737. viewer.inputHandler.startDragging(object, {
  38738. endDragFun: e.drag.endDragFun,
  38739. notPressMouse: e.drag.notPressMouse,
  38740. dragViewport: e.drag.dragViewport
  38741. });
  38742. }
  38743. }, 1);
  38744. return timer;
  38745. }
  38746. }
  38747. function getDifferentPoint(points, count) {
  38748. //for facePlane
  38749. var result = [];
  38750. for (var i = 0; i < points.length; i++) {
  38751. var p = points[i];
  38752. if (result.find(e => e.equals(p))) continue;else result.push(p);
  38753. if (result.length == count) break;
  38754. }
  38755. if (result.length == count) return result;
  38756. }
  38757. var texLoader$6 = new TextureLoader();
  38758. var defaultColor$1 = new Color(config$1.measure.default.color);
  38759. var highlightColor = new Color(config$1.measure.highlight.color);
  38760. var color = new Color(config$1.measure.color);
  38761. var textColor = new Color(config$1.measure.textColor);
  38762. var markerMats;
  38763. var lineMats;
  38764. var planeMats;
  38765. var textSizeRatio = math.linearClamp(window.outerWidth * window.outerHeight, [360 * 720, 1920 * 1080], [0.7, 1]); //pc字显示大一些 用
  38766. var lineDepthInfo = {
  38767. clipDistance: 15,
  38768. //4,//消失距离
  38769. occlusionDistance: 3 //1,//变为backColor距离
  38770. };
  38771. var markerMapShrink = browser.isMobile() ? 0.4 : 0.8; //触屏需要更大的热区
  38772. var markerSizeInfo = {
  38773. width2d: 18 / markerMapShrink // nearBound : 1.5, farBound : 15,
  38774. };
  38775. /* const markerSizeInfo = {
  38776. minSize : 10 , maxSize : 15 , nearBound : 1.5, farBound : 15,
  38777. } */
  38778. var labelSizeInfo = {
  38779. width2d: 200
  38780. };
  38781. var mainLabelProp = {
  38782. //backgroundColor: {r: defaultColor.r*255, g: defaultColor.g*255, b: defaultColor.b*255, a:config.measure.default.opacity},
  38783. backgroundColor: {
  38784. r: 0,
  38785. g: 0,
  38786. b: 0,
  38787. a: 0
  38788. },
  38789. textColor: {
  38790. r: textColor.r * 255,
  38791. g: textColor.g * 255,
  38792. b: textColor.b * 255,
  38793. a: 1.0
  38794. },
  38795. textBorderColor: {
  38796. r: 255,
  38797. g: 255,
  38798. b: 255,
  38799. a: 1.0
  38800. },
  38801. textBorderThick: 3,
  38802. fontsize: 15 * textSizeRatio,
  38803. borderRadius: 12,
  38804. margin: {
  38805. x: 20,
  38806. y: 4
  38807. },
  38808. renderOrder: Potree.config.renderOrders.measureLabel,
  38809. pickOrder: Potree.config.renderOrders.measureLabel,
  38810. disToLine: -0.15,
  38811. useDepth: true,
  38812. // 2023.10 尽量不让数字被挡住
  38813. clipDistance: 10,
  38814. //消失距离
  38815. occlusionDistance: 10,
  38816. //变为backColor距离
  38817. maxOcclusionFactor: 0.3,
  38818. maxClipFactor: 0.8
  38819. };
  38820. var subLabelProp = {
  38821. backgroundColor: {
  38822. r: 255,
  38823. g: 255,
  38824. b: 255,
  38825. a: 0
  38826. },
  38827. textColor: {
  38828. r: textColor.r * 255,
  38829. g: textColor.g * 255,
  38830. b: textColor.b * 255,
  38831. a: 1.0
  38832. },
  38833. textBorderColor: {
  38834. r: 255,
  38835. g: 255,
  38836. b: 255,
  38837. a: 1.0
  38838. },
  38839. textBorderThick: 3,
  38840. fontsize: 14 * textSizeRatio,
  38841. renderOrder: Potree.config.renderOrders.measureLabelSub,
  38842. pickOrder: Potree.config.renderOrders.measureLabelSub,
  38843. disToLine: -0.13
  38844. };
  38845. var angle = MathUtils.degToRad(5); //显示水平垂直辅助线的最小角度
  38846. var guideShowMinAngle = {
  38847. min: angle,
  38848. max: Math.PI / 2 - angle
  38849. };
  38850. class Measure$1 extends ctrlPolygon {
  38851. constructor(prop) {
  38852. prop.dimension = '2d';
  38853. super('measure', prop);
  38854. this.constructor.counter = this.constructor.counter === undefined ? 0 : this.constructor.counter + 1;
  38855. this.name = this.measureType + this.constructor.counter; //'Measure_' + this.constructor.counter;
  38856. this.markerLabels = [];
  38857. this.edgeLabels = [];
  38858. this.angleLabels = [];
  38859. this.coordinateLabels = [];
  38860. this.area = {
  38861. value: 0,
  38862. string: ''
  38863. };
  38864. if (this.showArea) {
  38865. this.areaLabel = this.createAreaLabel();
  38866. this.add(this.areaLabel);
  38867. }
  38868. //add:
  38869. if (this.atPlane || this.faceDirection) {
  38870. //是一个平面上的话
  38871. this.createGuideLine();
  38872. }
  38873. if (this.measureType == 'Distance' /* || this.measureType.includes('MulDistance') */) {
  38874. this.createHorVerGuideLine();
  38875. }
  38876. this.selectStates = {};
  38877. this.setUnitSystem(prop.unit || viewer.unitConvert.UnitService.defaultSystem);
  38878. Potree.Utils.setObjectLayers(this, 'measure');
  38879. if (this.measureType == 'MulDistance' || this.measureType == 'Hor MulDistance' || this.measureType == 'Ver MulDistance') {
  38880. //this.showTotalDis = true
  38881. this.totalDisLabel = this.createTotalDisLabel();
  38882. this.add(this.totalDisLabel);
  38883. }
  38884. //addMarkers:
  38885. this.initData(prop);
  38886. this.pointsPos2d = new Map(); //屏幕上的二维坐标
  38887. this.points_datasets || (this.points_datasets = []); //存每个点是哪个数据集
  38888. this.addEventListener('marker_dropped', e => {
  38889. this.updateDatasetBelong(e.index);
  38890. });
  38891. this.addEventListener('isVisible', () => {
  38892. viewer.mapViewer && viewer.mapViewer.dispatchEvent({
  38893. type: 'content_changed'
  38894. });
  38895. });
  38896. this.lastDropTime = 0;
  38897. }
  38898. initData(prop) {
  38899. var makeIt = super.initData(prop);
  38900. if (makeIt) {
  38901. this.edges.forEach(edge => {
  38902. edge.dispatchEvent('addHoverEvent');
  38903. });
  38904. } else {
  38905. this.failBuilded = true;
  38906. }
  38907. }
  38908. updateDatasetBelong(changeIndex) {
  38909. //更新所属数据集
  38910. if (Potree.settings.editType == "merge" || this.measureType == 'MulDistance Ring') {
  38911. //点直接跟着数据集走,不用找整体的datasetId
  38912. this.dataset_points[changeIndex] = Potree.Utils.datasetPosTransform({
  38913. toDataset: true,
  38914. datasetId: this.points_datasets[changeIndex],
  38915. position: this.points[changeIndex].clone()
  38916. });
  38917. return;
  38918. }
  38919. var old = this.datasetId;
  38920. var maxCount = {
  38921. id: null,
  38922. count: 0
  38923. };
  38924. var datasets = {};
  38925. this.points_datasets.forEach(e => {
  38926. if (e == void 0) return;
  38927. if (datasets[e]) {
  38928. datasets[e]++;
  38929. } else {
  38930. datasets[e] = 1;
  38931. }
  38932. });
  38933. for (var i in datasets) {
  38934. if (datasets[i] > maxCount.count) {
  38935. maxCount = {
  38936. id: i,
  38937. count: datasets[i]
  38938. };
  38939. }
  38940. }
  38941. this.datasetId = maxCount.count > 0 ? maxCount.id : null;
  38942. //if(this.datasetId != old){
  38943. //this.dispatchEvent({type:'changeDatasetId'})
  38944. if (this.datasetId == void 0) {
  38945. this.dataset_points = null; //可能为空或[null,null...]
  38946. } else {
  38947. this.dataset_points = this.points.map(e => {
  38948. return Potree.Utils.datasetPosTransform({
  38949. toDataset: true,
  38950. datasetId: this.datasetId,
  38951. position: e.clone()
  38952. });
  38953. });
  38954. }
  38955. //}
  38956. }
  38957. transformByPointcloud() {
  38958. //每次移动点云 or 加载测量线时要获取一下当前position //有地图时
  38959. if (this.datasetId == void 0) return;
  38960. this.points = this.dataset_points.map(e => {
  38961. return Potree.Utils.datasetPosTransform({
  38962. fromDataset: true,
  38963. datasetId: this.datasetId,
  38964. position: e.clone()
  38965. });
  38966. });
  38967. this.getPoint2dInfo(this.points);
  38968. this.update({
  38969. ifUpdateMarkers: true
  38970. });
  38971. this.setSelected(false); //隐藏edgelabel
  38972. }
  38973. update() {
  38974. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  38975. if (options.index == -1) return;
  38976. super.update(options);
  38977. if (this.showCoordinates && this.points.length > 0) {
  38978. var position = this.points[0];
  38979. this.markers[0].position.copy(position);
  38980. {
  38981. // coordinate labels
  38982. var coordinateLabel = this.coordinateLabels[0];
  38983. var pos = [position.toArray()];
  38984. if (viewer.transform) {
  38985. var lonlat = viewer.transform.lonlatToLocal.inverse(position.toArray());
  38986. var EPSG4550 = viewer.transform.lonlatTo4550.forward(lonlat);
  38987. pos.push(lonlat, EPSG4550);
  38988. }
  38989. //let msg = position.toArray().map(p => Utils.addCommas(p.toFixed(2))).join(" / ");
  38990. var msg = pos.map(a => a.map(p => Utils.addCommas(p.toFixed(10))).join(", ")).join("<br>");
  38991. coordinateLabel.setText(msg);
  38992. coordinateLabel.setPos(position);
  38993. coordinateLabel.setVisible(true); //this.showCoordinates;
  38994. }
  38995. return;
  38996. }
  38997. var setEdgeLabel = (label, p1, p2, distance) => {
  38998. //设置label位置和字
  38999. this.setEdgeLabelPos(label, p1, p2);
  39000. distance = distance == void 0 ? p1.distanceTo(p2) : distance;
  39001. //var text = viewer.unitConvert.convert(distance, 'distance', Potree.settings.precision, this.unitSystem, 1 , true)//distance要传0.1 这个factor
  39002. var text = this.getConvertString(distance, 'distance');
  39003. label.setText(text);
  39004. return distance;
  39005. };
  39006. /* let setEdgeLabel = (label,p1,p2,distance)=>{//设置label位置和字
  39007. this.setEdgeLabelPos(label,p1,p2)
  39008. distance = distance == void 0 ? p1.distanceTo(p2) : distance;
  39009. var text = this.labelText || viewer.unitConvert.convert(distance, 'distance', Potree.settings.precision , this.unitSystem, 0.001 , true, true)//distance要传0.1 这个factor
  39010. label.setText(text)
  39011. } */
  39012. var lastIndex = this.points.length - 1;
  39013. var setLabel = index => {
  39014. var previousIndex = this.getIndex(index, -1);
  39015. var nextIndex = this.getIndex(index, +1);
  39016. var previousPoint = this.points[previousIndex];
  39017. var point = this.points[index];
  39018. var nextPoint = this.points[nextIndex];
  39019. if (this.showDistances) {
  39020. // edge labels
  39021. var edgeLabel = this.edgeLabels[index];
  39022. var distance = point.distanceTo(nextPoint);
  39023. this.edges[index].distance_ = distance;
  39024. edgeLabel.shouldVisi = (index < lastIndex || this.isRect || this.closed && !this.isNew) && distance > 0;
  39025. //this.closed || edgeLabel.setVisible(edgeLabel.shouldVisi) //closed的在setEdgesDisplay中设置
  39026. Utils.updateVisible(edgeLabel, 'shouldVisi', edgeLabel.shouldVisi, 2);
  39027. if (edgeLabel.shouldVisi) {
  39028. edgeLabel.lineDir = new Vector3().subVectors(point, nextPoint).normalize(); //[point,nextPoint]
  39029. setEdgeLabel(edgeLabel, point, nextPoint, distance);
  39030. }
  39031. }
  39032. };
  39033. if (options.index != void 0) {
  39034. //更新第几个点
  39035. setLabel(options.index);
  39036. var previousIndex = this.getIndex(options.index, -1);
  39037. setLabel(previousIndex);
  39038. } else {
  39039. for (var index = 0; index <= lastIndex; index++) {
  39040. setLabel(index);
  39041. }
  39042. }
  39043. if (Potree.config.measure.mulLabelHideFaraway) {
  39044. this.measureType == 'MulDistance' && this.clearEdgeLabelVisi();
  39045. }
  39046. if (this.measureType == 'Distance' && this.points.length > 1) {
  39047. //设置水平垂直辅助线
  39048. var pTop, pBtm;
  39049. if (this.points[0].z > this.points[1].z) {
  39050. pTop = this.points[0];
  39051. pBtm = this.points[1];
  39052. } else {
  39053. pTop = this.points[1];
  39054. pBtm = this.points[0];
  39055. }
  39056. var projectPos = new Vector3(pTop.x, pTop.y, pBtm.z); //两条guideline的交点
  39057. {
  39058. //倾斜角度太小的时候不显示
  39059. var tan = pTop.distanceTo(projectPos) / pBtm.distanceTo(projectPos);
  39060. var _angle = Math.atan(tan);
  39061. this.shouldShowHorVerGuide = _angle > guideShowMinAngle.min && _angle < guideShowMinAngle.max;
  39062. }
  39063. LineDraw.updateLine(this.verGuideEdge, [pTop, projectPos]);
  39064. LineDraw.updateLine(this.horGuideEdge, [pBtm, projectPos]);
  39065. setEdgeLabel(this.verEdgeLabel, pTop, projectPos);
  39066. setEdgeLabel(this.horEdgeLabel, pBtm, projectPos);
  39067. this.verGuideEdge.visible = this.horGuideEdge.visible = this.shouldShowHorVerGuide;
  39068. this.verEdgeLabel.visible = this.horEdgeLabel.visible = this.shouldShowHorVerGuide;
  39069. }
  39070. if (this.showArea && this.points.length > 2) {
  39071. // update area
  39072. var _msg = this.getArea().string;
  39073. this.areaLabel.setPos(this.getCenter('areaPlaneCenter'));
  39074. this.areaLabel.setText(_msg);
  39075. Utils.updateVisible(this.areaLabel, 'setVisible', true); //this.areaLabel.setVisible(true)
  39076. }
  39077. if (this.totalDisLabel) {
  39078. this.ifShowTotalDis();
  39079. Utils.updateVisible(this.totalDisLabel, 'setVisible', this.showTotalDis);
  39080. this.edgeLabels.forEach(e => Utils.updateVisible(e, 'showTotalDis', !this.showTotalDis));
  39081. if (this.showTotalDis) {
  39082. var dis = this.getTotalDistance();
  39083. var _msg2 = this.getConvertString(dis, 'distance');
  39084. this.center = null;
  39085. this.center = this.getCenter();
  39086. this.totalDisLabel.setPos(this.center);
  39087. this.totalDisLabel.setText(_msg2);
  39088. }
  39089. }
  39090. }
  39091. getArea() {
  39092. var area;
  39093. if (this._area != void 0) {
  39094. area = this._area;
  39095. } else if (this.point2dInfo) {
  39096. area = Math.abs(math.getArea(this.point2dInfo.points2d)); //this.getArea();
  39097. } else {
  39098. //mulDistance Ring 2d面
  39099. area = Math.abs(math.getArea(this.points));
  39100. }
  39101. var msg = this.getConvertString(area, 'area');
  39102. //let msg = viewer.unitConvert.convert(area, 'area', Potree.settings.precision, this.unitSystem/* , 0.1 */ )
  39103. this.area = {
  39104. value: area,
  39105. string: msg
  39106. };
  39107. return this.area;
  39108. }
  39109. getConvertString(num, type) {
  39110. return viewer.unitConvert.convert(num, type, Potree.settings.precision, this.unitSystem, true, {
  39111. 'imperial': {
  39112. minFactor: 0.01
  39113. },
  39114. 'metric': {
  39115. minFactor: 0.01
  39116. }
  39117. });
  39118. }
  39119. ifShowTotalDis() {
  39120. var show = this.points.length > 2;
  39121. if (show) {
  39122. var maxDis = 0.15;
  39123. var lastIndex = this.points.length - 1;
  39124. for (var i = 0; i < lastIndex; i++) {
  39125. var len = this.edges[i].distance_;
  39126. if (len > maxDis) {
  39127. show = false;
  39128. break;
  39129. }
  39130. }
  39131. }
  39132. this.showTotalDis = show;
  39133. /* 连续测量:
  39134. 1. ≥2次测量,单个距离<15cm时,居中显示总长, hover、选中时显示每段长度
  39135. 2. 若连续测量的线段中,大于等于1段超出15cm,所有线段均显示长度
  39136. -------------------
  39137. */
  39138. }
  39139. clearEdgeLabelVisi() {
  39140. //修改点位置后清空,下次render时会自动getEdgeLabelVisi
  39141. var lastIndex = this.points.length - 1;
  39142. for (var index = 0; index <= lastIndex; index++) {
  39143. if (!this.closed && index == lastIndex) continue;
  39144. var edgeLabel = this.edgeLabels[index];
  39145. edgeLabel.visiMap.clear();
  39146. }
  39147. }
  39148. getEdgeLabelVisi(viewport) {
  39149. //获取多折线的edgelabel在不同视图里的可见性。要保证任何时候label能出现的线最小二维长度一致
  39150. var camera = viewport.camera;
  39151. var lastIndex = this.points.length - 1;
  39152. /* let pos2ds = this.points.map(point=> point.clone().project(camera) ) //即使只是旋转也会变动,尤其是转到屏幕外后变为显示。所以不用这种
  39153. let minDis = 0.01; */
  39154. var minDis = 0.02,
  39155. minAngleRatio = 0.07,
  39156. minAngle;
  39157. var vecs;
  39158. var forceShow;
  39159. if (camera.type == 'OrthographicCamera') {
  39160. minDis *= Math.pow(camera.top / camera.zoom, 2);
  39161. //console.log(minDis)
  39162. } else {
  39163. if (Potree.settings.displayMode == 'showPanos' && viewer.images360.zoomLevel == Potree.settings.zoom.max) {
  39164. forceShow = true; //当zoom到最大时强制显示,避免有的线太短永远显示不出长度
  39165. } else {
  39166. vecs = this.points.map(point => new Vector3().subVectors(point, camera.position).normalize());
  39167. minAngleRatio /= viewport.resolution.y / 1000 / textSizeRatio; //角度占fov最小比率
  39168. minAngle = minAngleRatio * MathUtils.degToRad(camera.fov);
  39169. }
  39170. }
  39171. for (var index = 0; index <= lastIndex; index++) {
  39172. if (!this.closed && index == lastIndex) continue;
  39173. var edgeLabel = this.edgeLabels[index];
  39174. var nextIndex = index + 1 > lastIndex ? 0 : index + 1;
  39175. var previousIndex = index === 0 ? lastIndex : index - 1;
  39176. var point = this.points[index];
  39177. var nextPoint = this.points[nextIndex];
  39178. /* let point2d = pos2ds[index];
  39179. let nextPoint2d = pos2ds[nextIndex];
  39180. let dis2d = point2d.distanceToSquared(nextPoint2d)
  39181. let v = dis2d > minDis //可见长度太小,为避免拥挤,不显示
  39182. edgeLabel.visiMap.set(camera, v) */
  39183. var v = void 0;
  39184. if (forceShow) {
  39185. v = true;
  39186. } else if (camera.type == 'OrthographicCamera') {
  39187. var vec = new Vector3().subVectors(point, nextPoint);
  39188. var projVec = vec.projectOnPlane(viewport.view.direction);
  39189. v = projVec.lengthSq() > minDis;
  39190. } else {
  39191. var vec0 = vecs[index];
  39192. var vec1 = vecs[nextIndex];
  39193. v = Math.acos(vec0.dot(vec1)) > minAngle; //角度过小代表可见长度太小,为避免拥挤,不显示
  39194. }
  39195. edgeLabel.visiMap.set(camera, v);
  39196. }
  39197. }
  39198. setEdgeLabelPos(label, p1, p2) {
  39199. //调整label的位置,使倾斜后看起来在线的中心,而不要挡住端点
  39200. var center = new Vector3().addVectors(p1, p2).multiplyScalar(0.5);
  39201. return label.setPos(center);
  39202. if (label.lineDir && label.lineDir.length() > 0) {
  39203. if (viewer.mainViewport.camera.type == 'OrthographicCamera') {
  39204. label.setPos(center);
  39205. } else {
  39206. //根据视线和线的夹角(后又加入相机和两个端点距离差)来决定标签偏移位置。+
  39207. var eyePos = viewer.mainViewport.camera.position;
  39208. var dir = viewer.mainViewport.view.direction; //new THREE.Vector3().subVectors(center,eyePos).normalize()
  39209. /*let centerDir = new THREE.Vector3().subVectors(center,eyePos).normalize()
  39210. if(centerDir.dot(dir)<0){//中点在相机后方,就不设置
  39211. label.setPos(center)
  39212. return
  39213. } */
  39214. var cos = dir.dot(label.lineDir);
  39215. var nearPoint = cos > 0 ? p2 : p1; //近端点。
  39216. var far = cos > 0 ? p1 : p2; //远端点。
  39217. var nearPointDir = new Vector3().subVectors(nearPoint, eyePos); //.normalize()
  39218. //使label在中点和近端点中变化, 近端点可能到了相机后方,需要投影到相机所在平面上
  39219. if (nearPointDir.dot(dir) < 0) {
  39220. //近端点到了相机后方,前移。
  39221. //let hfov = cameraLight.getHFOVForCamera(viewer.mainViewport.camera , true ); //暂且只看水平fov
  39222. //if(nearPointDir.dot(dir)<Math.cos(hfov/2)){//近端点在镜头外,前移。 --但是这个就得把点转化成在镜头边缘而非左右两边(camDirPlane上)
  39223. var ray = new Raycaster();
  39224. ray.set(nearPoint, cos > 0 ? label.lineDir : label.lineDir.clone().negate());
  39225. var camDirPlane = new Plane().setFromNormalAndCoplanarPoint(dir, eyePos);
  39226. nearPoint = ray.ray.intersectPlane(camDirPlane, new Vector3());
  39227. if (!nearPoint) {
  39228. //线是垂直的,视线是水平的时候
  39229. return label.setPos(center);
  39230. }
  39231. }
  39232. //防止离远了之后也偏移很多,但远了之后相机到端点vec和到中点的vec的夹角接近,不需要怎么偏移的。
  39233. var dis1 = nearPoint.distanceToSquared(eyePos);
  39234. var dis2 = far.distanceToSquared(eyePos);
  39235. var diff = Math.abs(dis1 / dis2);
  39236. diff < 1 && (diff = 1 / diff);
  39237. diff = math.linearClamp(diff, [0, 30], [0, 1]);
  39238. var efficiency = 0.7; // 0-1 数值越高,r越容易接近1或-1,label越容易在倾斜后靠近近端点。
  39239. //let r = 0.5*efficiency*cos + 0.5
  39240. var r = 0.5 * efficiency * diff * cos + 0.5;
  39241. r = MathUtils.clamp(r, 0.1, 0.9);
  39242. //视线越接近线的方向,标签应该越往近端点偏移,防止看起来几乎在远端。
  39243. if (cos > 0) {
  39244. center = p1.clone().multiplyScalar(1 - r).add(nearPoint.clone().multiplyScalar(r)); //label在线上滑动,使尽量保持在视觉中心
  39245. } else {
  39246. center = nearPoint.clone().multiplyScalar(1 - r).add(p2.clone().multiplyScalar(r)); //label在线上滑动,使尽量保持在视觉中心
  39247. }
  39248. label.setPos(center);
  39249. }
  39250. //归零
  39251. //this.orient2dInfo = null
  39252. //this.markers.forEach(e=>e.needsUpdate=true)
  39253. } else {
  39254. label.setPos(center);
  39255. }
  39256. }
  39257. cloneMarker(cloneIndex, index) {
  39258. return this.addMarker({
  39259. index,
  39260. point: this.points[cloneIndex],
  39261. dataset_point: this.dataset_points && this.dataset_points[cloneIndex],
  39262. points_dataset: this.points_datasets[cloneIndex]
  39263. });
  39264. }
  39265. addMarker() {
  39266. var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  39267. var index = o.index == void 0 ? this.points.length : o.index; //要当第几个
  39268. var marker = new Sprite$2({
  39269. mat: this.getMarkerMaterial('default'),
  39270. sizeInfo: markerSizeInfo,
  39271. name: "measure_point"
  39272. });
  39273. Potree.Utils.setObjectLayers(marker, 'measure');
  39274. marker.pickOrder = marker.renderOrder = Potree.config.renderOrders.measureMarker;
  39275. marker.markerSelectStates = {};
  39276. marker.addEventListener('startDragging', e => {
  39277. /* if(e.drag.dragViewport.name == 'MainView') */viewer.inputHandler.dispatchEvent({
  39278. type: 'measuring',
  39279. v: true,
  39280. cause: 'startDragging',
  39281. situation: 'dragging',
  39282. object: this
  39283. });
  39284. //add for 调试,方便后期增加点
  39285. if (!this.isNew && viewer.inputHandler.pressedKeys['M'.charCodeAt(0)] && this.points.length < this.maxMarkers) {
  39286. viewer.measuringTool.history.beforeChange(this);
  39287. var curIndex = this.markers.indexOf(marker);
  39288. this.cloneMarker(curIndex, curIndex + 1);
  39289. }
  39290. this.isNew || viewer.measuringTool.history.beforeChange(this);
  39291. });
  39292. marker.addEventListener('drop', e => {
  39293. if (e.button != MOUSE.LEFT) return;
  39294. viewer.inputHandler.dispatchEvent({
  39295. type: 'measuring',
  39296. v: false,
  39297. cause: 'stopDragging',
  39298. situation: 'dragging',
  39299. object: this
  39300. });
  39301. this.lastDropTime = Date.now();
  39302. if (Potree.settings.adsorption) {
  39303. this.isNew || viewer.viewports.forEach(viewport => {
  39304. this.getPointsPos2d(viewport, true); //forceUpdate
  39305. });
  39306. }
  39307. this.isNew || viewer.measuringTool.history.afterChange(this);
  39308. });
  39309. marker.addEventListener('click', () => {
  39310. if (viewer.measuringTool.editMode == 'delPoint') {
  39311. /* if(this.points.length == this.minMarkers){//--前端去重绘
  39312. viewer.scene.removeMeasurement(this)
  39313. }else{ */
  39314. viewer.measuringTool.history.beforeChange(this);
  39315. var _index = this.markers.indexOf(marker);
  39316. this.removeMarker(_index);
  39317. viewer.measuringTool.history.afterChange(this);
  39318. this.dispatchEvent('changed');
  39319. //}
  39320. }
  39321. });
  39322. //marker.measure = this
  39323. var edge;
  39324. {
  39325. // edges
  39326. edge = LineDraw.createFatLine([], {
  39327. mat: this.getLineMat('edgeDefault')
  39328. });
  39329. edge.pickOrder = 0;
  39330. Potree.Utils.setObjectLayers(edge, 'measure');
  39331. var addHoverEvent = () => {
  39332. //当非isNew时才添加事件
  39333. var mouseover = e => {
  39334. /* if(this.measureType == 'MulDistance'){
  39335. } */
  39336. this.setSelected(true, 'edge');
  39337. };
  39338. var mouseleave = e => {
  39339. this.setSelected(false, 'edge');
  39340. };
  39341. edge.addEventListener('mouseover', mouseover);
  39342. edge.addEventListener('mouseleave', mouseleave);
  39343. edge.removeEventListener('addHoverEvent', addHoverEvent);
  39344. edge.addEventListener('click', e => {
  39345. var now = Date.now();
  39346. if (now - this.lastDropTime < 100) return; //防止拖拽marker时误触导致focus, 以及点到marker不focus
  39347. if (viewer.measuringTool.editMode == 'addPoint' && this.points.length < this.maxMarkers) {
  39348. viewer.measuringTool.history.beforeChange(this);
  39349. var _index2 = this.edges.indexOf(edge) + 1;
  39350. var nextIndex = _index2 % this.edges.length;
  39351. var point = math.getFootPoint(e.hoveredElement.point, this.points[_index2 - 1], this.points[nextIndex]);
  39352. this.addMarker({
  39353. index: _index2,
  39354. point,
  39355. dataset_point: this.dataset_points && new Vector3(),
  39356. //初始化
  39357. points_dataset: this.points_datasets[_index2 - 1] //使用前一个的
  39358. });
  39359. this.updateDatasetBelong(_index2); //获取dataset_point
  39360. viewer.measuringTool.history.afterChange(this);
  39361. this.dispatchEvent('changed');
  39362. //this.update({})
  39363. } else {
  39364. this.isNew || viewer.measuringTool.isAdding || viewer.focusOnObject(this, 'measure'); //正在添加测量线时不要focus其他线(容易误触)
  39365. }
  39366. });
  39367. };
  39368. edge.addEventListener('addHoverEvent', addHoverEvent);
  39369. if (!this.isNew) {
  39370. edge.dispatchEvent('addHoverEvent');
  39371. }
  39372. }
  39373. super.addMarker(Object.assign(o, {
  39374. index,
  39375. marker,
  39376. edge
  39377. }));
  39378. if (this.showEdges) {
  39379. // edge labels
  39380. var edgeLabel = this.createEdgeLabel('edgeLabel', !this.closed);
  39381. this.edgeLabels = [...this.edgeLabels.slice(0, index), edgeLabel, ...this.edgeLabels.slice(index, this.edgeLabels.length)];
  39382. }
  39383. if (this.showCoordinates) {
  39384. // coordinate labels
  39385. var coordinateLabel = new Label({
  39386. className: 'measure_pointPos',
  39387. camera: viewer.scene.getActiveCamera()
  39388. });
  39389. coordinateLabel.setVisible(false);
  39390. this.coordinateLabels.push(coordinateLabel);
  39391. }
  39392. var event = {
  39393. type: 'marker_added',
  39394. measurement: this,
  39395. marker: marker
  39396. };
  39397. this.dispatchEvent(event);
  39398. //this.setMarker(this.points.length - 1, point);
  39399. this.update({
  39400. index
  39401. }); //更新一下倒数第二条线
  39402. return marker; //add
  39403. }
  39404. editStateChange(state) {
  39405. //主要针对edgeLabels显示切换,编辑时显示
  39406. super.editStateChange(state);
  39407. if (!state) {
  39408. this.editStateTimer = setTimeout(() => {
  39409. if (!this.isEditing) {
  39410. this.dispatchEvent({
  39411. type: 'editStateChange',
  39412. state: false
  39413. });
  39414. this.setEdgesDisplay(false);
  39415. this.areaPlane && Potree.Utils.updateVisible(this.areaPlane, 'intersectLastLine', true);
  39416. this.areaLabel && Potree.Utils.updateVisible(this.areaLabel, 'intersectLastLine', true);
  39417. }
  39418. }, 100);
  39419. } else {
  39420. if (!this.isEditing) {
  39421. this.dispatchEvent({
  39422. type: 'editStateChange',
  39423. state: true
  39424. });
  39425. this.setEdgesDisplay(true);
  39426. clearTimeout(this.editStateTimer);
  39427. }
  39428. }
  39429. this.isEditing = state;
  39430. }
  39431. setMarkerSelected(marker, state, hoverObject) {
  39432. //console.warn(marker.id , state, hoverObject)
  39433. marker.markerSelectStates[hoverObject] = state;
  39434. var absoluteState = false;
  39435. for (var i in marker.markerSelectStates) {
  39436. if (marker.markerSelectStates[i] == 'hover') {
  39437. absoluteState = true;
  39438. break;
  39439. }
  39440. }
  39441. if (absoluteState) {
  39442. marker.material = this.getMarkerMaterial('select');
  39443. marker.renderOrder = marker.pickOrder = Potree.config.renderOrders.measureMarker + 1;
  39444. } else {
  39445. marker.material = this.getMarkerMaterial('default');
  39446. marker.renderOrder = marker.pickOrder = Potree.config.renderOrders.measureMarker;
  39447. }
  39448. marker.selected = absoluteState;
  39449. viewer.mapViewer && viewer.mapViewer.dispatchEvent('content_changed');
  39450. viewer.dispatchEvent('content_changed');
  39451. }
  39452. setEdgesDisplay(state, ignoreGuideLine) {
  39453. this.closed && this.edgeLabels.forEach(e => Utils.updateVisible(e, 'hover', state));
  39454. if (this.totalDisLabel && !viewer.screenshoting) {
  39455. this.edgeLabels.forEach(e => Utils.updateVisible(e, 'hover', state, 1, state ? 'add' : 'cancel'));
  39456. Utils.updateVisible(this.totalDisLabel, 'hover', !state);
  39457. }
  39458. if (!ignoreGuideLine && this.measureType == 'Distance') {
  39459. this.horEdgeLabel.visible = this.verEdgeLabel.visible = this.horGuideEdge.visible = this.verGuideEdge.visible = !!(state && this.shouldShowHorVerGuide);
  39460. }
  39461. }
  39462. setSelected(state, hoverObject) {
  39463. //add
  39464. //console.log('setSelected',state, hoverObject)
  39465. var absoluteState = !!state;
  39466. if (hoverObject) {
  39467. //如果没有hoverObject且state为false 就强制取消选中态
  39468. this.selectStates[hoverObject] = state;
  39469. for (var i in this.selectStates) {
  39470. if (this.selectStates[i]) {
  39471. absoluteState = true;
  39472. break;
  39473. }
  39474. }
  39475. }
  39476. if (absoluteState) {
  39477. this.markers.forEach(e => this.setMarkerSelected(e, 'hover', 'selectAll'));
  39478. this.edges.forEach(e => {
  39479. e.renderOrder = Potree.config.renderOrders.lines + 1;
  39480. e.material = this.getLineMat('edgeSelect');
  39481. });
  39482. this.areaPlane && (this.areaPlane.material = planeMats.selected);
  39483. //this.areaLabel && this.areaLabel.elem.addClass('highLight')
  39484. //this.closed || this.edgeLabels.forEach(e=>e.elem.addClass('highLight') )
  39485. this.setEdgesDisplay(true, hoverObject == "screenshot");
  39486. this.areaLabel && setLabelHightState(this.areaLabel, true);
  39487. this.closed || this.edgeLabels.forEach(e => setLabelHightState(e, true));
  39488. } else {
  39489. this.markers.forEach(e => this.setMarkerSelected(e, 'unhover', 'selectAll'));
  39490. this.edges.forEach(e => e.material = this.getLineMat('edgeDefault'));
  39491. this.areaPlane && (this.areaPlane.material = planeMats.default);
  39492. this.setEdgesDisplay(false, hoverObject == "screenshot");
  39493. //this.areaLabel && this.areaLabel.elem.removeClass('highLight')
  39494. //this.closed || this.edgeLabels.forEach(e=>e.elem.removeClass('highLight') )
  39495. this.areaLabel && setLabelHightState(this.areaLabel, false);
  39496. this.closed || this.edgeLabels.forEach(e => setLabelHightState(e, false));
  39497. }
  39498. this.selected = absoluteState;
  39499. if (hoverObject != 'byList') {
  39500. //this.bus && this.bus.emit('highlight', this.selected)
  39501. this.dispatchEvent({
  39502. type: 'highlight',
  39503. state: this.selected
  39504. }); //列表高亮
  39505. }
  39506. viewer.dispatchEvent('content_changed');
  39507. viewer.mapViewer && viewer.mapViewer.dispatchEvent('content_changed');
  39508. }
  39509. removeMarker(index) {
  39510. super.removeMarker(index);
  39511. this.points_datasets.splice(index, 1);
  39512. this.dataset_points && this.dataset_points.splice(index, 1);
  39513. this.coordinateLabels.splice(index, 1);
  39514. var edgeIndex = index; //(index === 0) ? 0 : (index - 1);
  39515. if (this.edgeLabels[edgeIndex]) {
  39516. this.edgeLabels[edgeIndex].dispose();
  39517. this.edgeLabels.splice(edgeIndex, 1);
  39518. }
  39519. this.update({
  39520. index: this.getIndex(index, -1)
  39521. });
  39522. this.dispatchEvent({
  39523. type: 'marker_removed',
  39524. measurement: this
  39525. });
  39526. }
  39527. setPosition(index, position) {
  39528. super.setPosition(index, position);
  39529. var event = {
  39530. type: 'marker_moved',
  39531. measure: this,
  39532. index: index,
  39533. position: position.clone()
  39534. };
  39535. this.dispatchEvent(event);
  39536. }
  39537. dispose() {
  39538. //add
  39539. var labels = this.edgeLabels.concat(this.coordinateLabels);
  39540. this.areaLabel && labels.push(this.areaLabel);
  39541. labels.forEach(e => e.dispose());
  39542. super.dispose();
  39543. this.dispatchEvent('disposed');
  39544. }
  39545. getTotalDistance() {
  39546. if (this.points.length === 0) {
  39547. return 0;
  39548. }
  39549. var distance = 0;
  39550. for (var i = 1; i < this.points.length; i++) {
  39551. var prev = this.points[i - 1];
  39552. var curr = this.points[i];
  39553. var d = prev.distanceTo(curr);
  39554. distance += d;
  39555. }
  39556. if (this.closed && this.points.length > 1) {
  39557. var first = this.points[0];
  39558. var last = this.points[this.points.length - 1];
  39559. var _d = last.distanceTo(first);
  39560. distance += _d;
  39561. }
  39562. return distance;
  39563. }
  39564. getAngleBetweenLines(cornerPoint, point1, point2) {
  39565. var v1 = new Vector3().subVectors(point1, cornerPoint);
  39566. var v2 = new Vector3().subVectors(point2, cornerPoint);
  39567. // avoid the error printed by threejs if denominator is 0
  39568. var denominator = Math.sqrt(v1.lengthSq() * v2.lengthSq());
  39569. if (denominator === 0) {
  39570. return 0;
  39571. } else {
  39572. return v1.angleTo(v2);
  39573. }
  39574. }
  39575. getAngle(index) {
  39576. if (this.points.length < 3 || index >= this.points.length) {
  39577. return 0;
  39578. }
  39579. var previous = index === 0 ? this.points[this.points.length - 1] : this.points[index - 1];
  39580. var point = this.points[index];
  39581. var next = this.points[(index + 1) % this.points.length];
  39582. return this.getAngleBetweenLines(point, previous, next);
  39583. }
  39584. getCenter(type) {
  39585. if (this.center) {
  39586. return this.center.clone();
  39587. } else {
  39588. var center = this.points.reduce(function (total, currentValue) {
  39589. return total.add(currentValue);
  39590. }, new Vector3());
  39591. this.points.length && center.multiplyScalar(1 / this.points.length);
  39592. return center; //求不出重心呜呜
  39593. }
  39594. }
  39595. // updateAzimuth(){
  39596. // // if(this.points.length !== 2){
  39597. // // return;
  39598. // // }
  39599. // // const azimuth = this.azimuth;
  39600. // // const [p0, p1] = this.points;
  39601. // // const r = p0.distanceTo(p1);
  39602. // }
  39603. createGuideLine() {
  39604. //add 辅助线
  39605. var guideLine = LineDraw.createFatLine([], {
  39606. mat: this.getLineMat('guide')
  39607. });
  39608. guideLine.visible = false;
  39609. this.guideLine = guideLine;
  39610. this.add(guideLine);
  39611. }
  39612. createHorVerGuideLine() {
  39613. //创建水平与垂直辅助线,仅距离测量有。
  39614. var verGuideEdge = LineDraw.createFatLine([], {
  39615. mat: this.getLineMat('guide')
  39616. });
  39617. verGuideEdge.visible = false;
  39618. this.verGuideEdge = verGuideEdge;
  39619. verGuideEdge.name = 'verGuideEdge';
  39620. var horGuideEdge = LineDraw.createFatLine([], {
  39621. mat: this.getLineMat('guide')
  39622. });
  39623. horGuideEdge.visible = false;
  39624. horGuideEdge.name = 'horGuideEdge';
  39625. this.horGuideEdge = horGuideEdge;
  39626. this.add(this.verGuideEdge);
  39627. this.add(this.horGuideEdge);
  39628. //label:
  39629. this.verEdgeLabel = this.createEdgeLabel('verGuideEdge');
  39630. this.horEdgeLabel = this.createEdgeLabel('horGuideEdge');
  39631. }
  39632. createEdgeLabel(name, hasHoverEvent) {
  39633. var inf = {
  39634. sizeInfo: labelSizeInfo,
  39635. name: name || 'edgeLabel'
  39636. };
  39637. if (name && name.includes('Guide')) {
  39638. inf.fontsize = 12;
  39639. }
  39640. var edgeLabel = new TextSprite$2($.extend({}, hasHoverEvent ? mainLabelProp : subLabelProp, inf));
  39641. if (hasHoverEvent) {
  39642. edgeLabel.addEventListener('mouseover', () => {
  39643. this.setSelected(true, 'edgeLabel');
  39644. });
  39645. edgeLabel.addEventListener('mouseleave', () => {
  39646. this.setSelected(false, 'edgeLabel');
  39647. });
  39648. edgeLabel.addEventListener('click', () => {
  39649. this.isNew || viewer.measuringTool.isAdding || viewer.focusOnObject(this, 'measure');
  39650. });
  39651. }
  39652. edgeLabel.visible = false;
  39653. edgeLabel.measure = this;
  39654. edgeLabel.sprite.material.depthTestWhenPick = true;
  39655. Potree.Utils.setObjectLayers(edgeLabel, 'measure');
  39656. this.add(edgeLabel);
  39657. if (this.measureType == 'MulDistance') {
  39658. edgeLabel.visiMap = new Map();
  39659. }
  39660. return edgeLabel;
  39661. }
  39662. createAreaLabel() {
  39663. var areaLabel = this.createCenterLabel('areaLabel');
  39664. return areaLabel;
  39665. }
  39666. createTotalDisLabel() {
  39667. var totalDisLabel = this.createCenterLabel('totalDisLabel');
  39668. return totalDisLabel;
  39669. }
  39670. createCenterLabel(name) {
  39671. var centerLabel = new TextSprite$2($.extend({}, mainLabelProp, {
  39672. sizeInfo: labelSizeInfo,
  39673. name,
  39674. disToLine: 0,
  39675. fontsize: 16 * textSizeRatio
  39676. }));
  39677. centerLabel.addEventListener('mouseover', () => {
  39678. this.isNew || this.setSelected(true, 'centerLabel');
  39679. });
  39680. centerLabel.addEventListener('mouseleave', () => {
  39681. this.isNew || this.setSelected(false, 'centerLabel');
  39682. });
  39683. centerLabel.addEventListener('click', () => {
  39684. this.isNew || viewer.measuringTool.isAdding || viewer.focusOnObject(this, 'measure');
  39685. });
  39686. Potree.Utils.setObjectLayers(centerLabel, 'measure');
  39687. Utils.updateVisible(centerLabel, 'setVisible', false);
  39688. return centerLabel;
  39689. }
  39690. getMarkerMaterial(type) {
  39691. if (!markerMats) {
  39692. markerMats = {
  39693. default: new DepthBasicMaterial($.extend({}, lineDepthInfo, {
  39694. transparent: !0,
  39695. opacity: 1,
  39696. map: texLoader$6.load(Potree.resourcePath + '/textures/pic_point_s32.png'),
  39697. useDepth: true,
  39698. mapScale: markerMapShrink
  39699. })),
  39700. select: new MeshBasicMaterial({
  39701. transparent: !0,
  39702. opacity: 1,
  39703. depthTest: false,
  39704. map: texLoader$6.load(Potree.resourcePath + '/textures/pic_point32.png' /* , null, null, { antialias: false } */)
  39705. })
  39706. };
  39707. Measure$1.markerMats = markerMats;
  39708. markerMats.select.map.repeat.set(1 / markerMapShrink, 1 / markerMapShrink);
  39709. markerMats.select.map.offset.set((markerMapShrink - 1) / 2 / markerMapShrink, (markerMapShrink - 1) / 2 / markerMapShrink);
  39710. //markerMats.select.map.offset.set( -1.1 , -1.1 )
  39711. }
  39712. return markerMats[type];
  39713. }
  39714. getLineMat(type) {
  39715. if (!Measure$1.lineMats) {
  39716. Measure$1.lineMats = {
  39717. edgeDefault: LineDraw.createFatLineMat($.extend({}, lineDepthInfo, {
  39718. color: config$1.measure.default.color,
  39719. lineWidth: config$1.measure.lineWidth,
  39720. useDepth: true,
  39721. dashWithDepth: true,
  39722. // 只在被遮住的部分显示虚线,因为实线容易挡住label
  39723. dashed: true,
  39724. dashSize: 0.04,
  39725. gapSize: 0.04,
  39726. transparent: true,
  39727. opacity: config$1.measure.default.opacity,
  39728. depthTestWhenPick: true
  39729. })),
  39730. edgeSelect: LineDraw.createFatLineMat($.extend({}, lineDepthInfo, {
  39731. color: config$1.measure.highlight.color,
  39732. //'#f0ff00',
  39733. dashSize: 0.5,
  39734. gapSize: 0.2,
  39735. lineWidth: config$1.measure.lineWidth,
  39736. transparent: true,
  39737. opacity: config$1.measure.highlight.opacity
  39738. })),
  39739. guide: LineDraw.createFatLineMat($.extend({}, lineDepthInfo, {
  39740. color: config$1.measure.guide.color,
  39741. dashSize: 0.1,
  39742. gapSize: 0.02,
  39743. dashed: true,
  39744. lineWidth: config$1.measure.lineWidth / 2
  39745. }))
  39746. };
  39747. }
  39748. return Measure$1.lineMats[type];
  39749. }
  39750. createAreaPlane() {
  39751. planeMats || (planeMats = {
  39752. default: new DepthBasicMaterial($.extend({}, lineDepthInfo, {
  39753. color: color,
  39754. side: DoubleSide,
  39755. opacity: 0.2,
  39756. transparent: true,
  39757. useDepth: true
  39758. })),
  39759. selected: new MeshBasicMaterial({
  39760. color: color,
  39761. side: DoubleSide,
  39762. opacity: 0.3,
  39763. transparent: true
  39764. //wireframe:true
  39765. })
  39766. }, Measure$1.planeMats = planeMats);
  39767. return super.createAreaPlane(planeMats.default);
  39768. }
  39769. raycast(raycaster, intersects) {
  39770. for (var i = 0; i < this.points.length; i++) {
  39771. var marker = this.markers[i];
  39772. marker.raycast(raycaster, intersects);
  39773. }
  39774. // recalculate distances because they are not necessarely correct
  39775. // for scaled objects.
  39776. // see https://github.com/mrdoob/three.js/issues/5827
  39777. // TODO: remove this once the bug has been fixed
  39778. for (var _i = 0; _i < intersects.length; _i++) {
  39779. var I = intersects[_i];
  39780. I.distance = raycaster.ray.origin.distanceTo(I.point);
  39781. }
  39782. intersects.sort(function (a, b) {
  39783. return a.distance - b.distance;
  39784. });
  39785. }
  39786. getPointsPos2d(viewport, update) {
  39787. //获取屏幕上的二维坐标
  39788. var ps = this.pointsPos2d.get(viewport);
  39789. if (update || !ps) {
  39790. var points = this.points.map(e => {
  39791. var p = Potree.Utils.getPos2d(e, viewport, viewer.renderArea);
  39792. p.pos3d = e.clone(), p.object = this;
  39793. return p;
  39794. });
  39795. this.pointsPos2d.set(viewport, points);
  39796. console.log('updatePointsPos2d', this.uuid, viewport.name);
  39797. }
  39798. return this.pointsPos2d.get(viewport);
  39799. }
  39800. transformData(prop) {
  39801. if (prop.measureType == 'Point') {
  39802. prop.showCoordinates = true, prop.closed = true, prop.maxMarkers = 1, prop.minMarkers = 1;
  39803. } else if (prop.measureType == 'Distance') {
  39804. prop.showDistances = true, prop.showEdges = true, prop.maxMarkers = 2, prop.minMarkers = 2;
  39805. } else if (prop.measureType == 'MulDistance') {
  39806. prop.showDistances = true, prop.showEdges = true, prop.minMarkers = 2;
  39807. } else if (prop.measureType == 'MulDistance Ring') {
  39808. prop.showDistances = true, prop.showEdges = true, prop.showArea = true, prop.closed = true, prop.minMarkers = 3;
  39809. } else if (prop.measureType == 'Ver MulDistance') {
  39810. prop.showDistances = true, prop.atPlane = true, prop.showEdges = true, prop.minMarkers = 2;
  39811. prop.faceDirection = "vertical";
  39812. prop.unableDragAtMap = true;
  39813. } else if (prop.measureType == 'Hor MulDistance') {
  39814. prop.showDistances = true, prop.atPlane = true, prop.showEdges = true, prop.minMarkers = 2;
  39815. prop.faceDirection = "horizontal";
  39816. } else if (prop.measureType == 'Ver Distance') {
  39817. prop.showDistances = true, prop.showEdges = true, prop.maxMarkers = 2, prop.minMarkers = 2, prop.faceDirection = "vertical";
  39818. prop.unableDragAtMap = true;
  39819. } else if (prop.measureType == 'Hor Distance') {
  39820. prop.showDistances = true, prop.showEdges = true, prop.maxMarkers = 2, prop.minMarkers = 2, prop.faceDirection = "horizontal";
  39821. } else if (prop.measureType == 'Area') {
  39822. prop.showDistances = true, Potree.settings.areaAtNotPlane || (prop.atPlane = true);
  39823. prop.showEdges = true, prop.closed = true, prop.minMarkers = 3;
  39824. } else if (prop.measureType == 'Hor Area') {
  39825. prop.showDistances = true, prop.atPlane = true, prop.showEdges = true, prop.closed = true, prop.minMarkers = 3;
  39826. prop.faceDirection = "horizontal";
  39827. } else if (prop.measureType == 'Ver Area') {
  39828. prop.showDistances = true, prop.atPlane = true, prop.showEdges = true, prop.closed = true, prop.minMarkers = 3;
  39829. prop.faceDirection = "vertical";
  39830. prop.unableDragAtMap = true;
  39831. } else if (prop.measureType == 'Rect Area') {
  39832. prop.showDistances = true, prop.atPlane = true, prop.showEdges = true, prop.closed = true, prop.minMarkers = 4;
  39833. prop.maxMarkers = 4;
  39834. } else if (prop.measureType == 'Hor Rect Area') {
  39835. prop.showDistances = true, prop.atPlane = true, prop.showEdges = true, prop.closed = true, prop.minMarkers = 4;
  39836. prop.maxMarkers = 4;
  39837. prop.isRect = true;
  39838. prop.faceDirection = "horizontal";
  39839. } else if (prop.measureType == 'Ver Rect Area') {
  39840. prop.showDistances = true, prop.atPlane = true, prop.showEdges = true, prop.closed = true, prop.minMarkers = 4;
  39841. prop.maxMarkers = 4;
  39842. prop.isRect = true;
  39843. prop.faceDirection = "vertical";
  39844. prop.unableDragAtMap = true;
  39845. }
  39846. if (prop.atPlane && prop.closed) {
  39847. //atPlane在同一平面上
  39848. prop.showArea = true;
  39849. }
  39850. super.transformData(prop);
  39851. }
  39852. setUnitSystem(unitSystem) {
  39853. //console.log(this.name +':' +this.unitSystem)
  39854. if (unitSystem != this.unitSystem) {
  39855. if (unitSystem == "metric") {} else if (unitSystem == 'imperial') {}
  39856. this.unitSystem = unitSystem;
  39857. this.update();
  39858. }
  39859. }
  39860. reDraw() {
  39861. var restMarkerCount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  39862. //重新开始画
  39863. super.reDraw(restMarkerCount);
  39864. if (this.measureType == 'Distance') {
  39865. this.shouldShowHorVerGuide = false;
  39866. this.setEdgesDisplay(false);
  39867. }
  39868. if (this.showArea) {
  39869. this.area = {
  39870. value: 0
  39871. };
  39872. this.areaLabel && Utils.updateVisible(this.areaLabel, 'setVisible', false);
  39873. }
  39874. if (this.totalDisLabel && this.showTotalDis) {
  39875. Utils.updateVisible(this.totalDisLabel, 'setVisible', false);
  39876. }
  39877. viewer.inputHandler.dispatchEvent({
  39878. type: 'measuring',
  39879. v: true,
  39880. cause: 'reDraw',
  39881. object: this,
  39882. situation: 'dragging'
  39883. });
  39884. }
  39885. }
  39886. function setLabelHightState(label, state) {
  39887. if (state) {
  39888. var _color = new Color(Potree.config.measure.highlight.color);
  39889. //label.sprite.material.opacity = config.measure.highlight.opacity
  39890. //label.setBackgroundColor({r:255*color.r, g:255*color.g, b:255*color.b, a:config.measure.highlight.opacity})
  39891. label.sprite.material.useDepth = false;
  39892. //label.textColor = {r: this.color.r*255, g: this.color.g*255, b: this.color.b*255, a: 1}
  39893. } else {
  39894. //label.setBackgroundColor({r: this.color.r*255, g: this.color.g*255, b: this.color.b*255, a:config.measure.default.opacity})
  39895. label.sprite.material.useDepth = true;
  39896. //label.sprite.material.opacity = 0.98
  39897. //label.textColor = {r: 255, g: 255, b: 255, a: 1}
  39898. }
  39899. label.updateTexture();
  39900. }
  39901. /* function setLabelHightState(label, state){
  39902. if(state){
  39903. label.setBackgroundColor({r: highlightColor.r*255, g: highlightColor.g*255, b: highlightColor.b*255, a:config.measure.highlight.labelOpacity})
  39904. label.sprite.material.useDepth = false;
  39905. }else{
  39906. label.setBackgroundColor(mainLabelProp.backgroundColor)
  39907. label.sprite.material.useDepth = true
  39908. }
  39909. label.updateTexture()
  39910. //label.sprite.material.needsUpdate = true
  39911. }
  39912. */
  39913. function createCircleRadiusLabel$1() {
  39914. var circleRadiusLabel = new TextSprite$2("");
  39915. circleRadiusLabel.setTextColor({
  39916. r: 140,
  39917. g: 250,
  39918. b: 140,
  39919. a: 1.0
  39920. });
  39921. circleRadiusLabel.setBorderColor({
  39922. r: 0,
  39923. g: 0,
  39924. b: 0,
  39925. a: 1.0
  39926. });
  39927. circleRadiusLabel.setBackgroundColor({
  39928. r: 0,
  39929. g: 0,
  39930. b: 0,
  39931. a: 1.0
  39932. });
  39933. circleRadiusLabel.fontsize = 16;
  39934. circleRadiusLabel.material.depthTest = false;
  39935. circleRadiusLabel.material.opacity = 1;
  39936. circleRadiusLabel.visible = false;
  39937. return circleRadiusLabel;
  39938. }
  39939. function createCircleRadiusLine$1() {
  39940. /* const lineGeometry = new LineGeometry();
  39941. lineGeometry.setPositions([
  39942. 0, 0, 0,
  39943. 0, 0, 0,
  39944. ]);
  39945. const lineMaterial = new LineMaterial({
  39946. color: 0xff0000,
  39947. lineWidth: 2,
  39948. resolution: new THREE.Vector2(1000, 1000),
  39949. gapSize: 1,
  39950. dashed: true,
  39951. });
  39952. lineMaterial.depthTest = false;
  39953. const circleRadiusLine = new Line2(lineGeometry, lineMaterial);*/
  39954. var circleRadiusLine = LineDraw.createFatLine([], {
  39955. color: 0xff0000,
  39956. dashSize: 0.5,
  39957. gapSize: 0.2,
  39958. lineWidth: config$1.measure.lineWidth
  39959. });
  39960. circleRadiusLine.visible = false;
  39961. return circleRadiusLine;
  39962. }
  39963. function createCircleLine$1() {
  39964. var coordinates = [];
  39965. var n = 128;
  39966. for (var i = 0; i <= n; i++) {
  39967. var u0 = 2 * Math.PI * (i / n);
  39968. var u1 = 2 * Math.PI * (i + 1) / n;
  39969. var p0 = new Vector3(Math.cos(u0), Math.sin(u0), 0);
  39970. var p1 = new Vector3(Math.cos(u1), Math.sin(u1), 0);
  39971. coordinates.push(p0, p1);
  39972. }
  39973. /* const geometry = new LineGeometry();
  39974. geometry.setPositions(coordinates);
  39975. const material = new LineMaterial({
  39976. color: 0xff0000,
  39977. dashSize: 5,
  39978. gapSize: 2,
  39979. lineWidth: 2,
  39980. resolution: new THREE.Vector2(1000, 1000),
  39981. });
  39982. material.depthTest = false;
  39983. const circleLine = new Line2(geometry, material);
  39984. circleLine.visible = false;
  39985. circleLine.computeLineDistances();*/
  39986. var circleLine = LineDraw.createFatLine(coordinates, {
  39987. color: 0xff0000,
  39988. dashSize: 0.5,
  39989. gapSize: 0.2,
  39990. lineWidth: config$1.measure.lineWidth
  39991. });
  39992. return circleLine;
  39993. }
  39994. /* function createCircleCenter(){
  39995. const sg = new THREE.markerGeometry(1, 32, 32);
  39996. const sm = new THREE.MeshNormalMaterial();
  39997. const circleCenter = new THREE.Mesh(sg, sm);
  39998. circleCenter.visible = false;
  39999. return circleCenter;
  40000. } */
  40001. function createLine$1() {
  40002. var line = LineDraw.createFatLine([], {
  40003. color: 0xff0000,
  40004. dashSize: 0.5,
  40005. gapSize: 0.2,
  40006. lineWidth: config$1.measure.lineWidth
  40007. });
  40008. return line;
  40009. }
  40010. function createCircle$1() {
  40011. var coordinates = [];
  40012. var n = 128;
  40013. for (var i = 0; i <= n; i++) {
  40014. var u0 = 2 * Math.PI * (i / n);
  40015. var u1 = 2 * Math.PI * (i + 1) / n;
  40016. var p0 = new Vector3(Math.cos(u0), Math.sin(u0), 0);
  40017. var p1 = new Vector3(Math.cos(u1), Math.sin(u1), 0);
  40018. coordinates.push(p0, p1);
  40019. }
  40020. var line = LineDraw.createFatLine(coordinates, {
  40021. color: 0xff0000,
  40022. dashSize: 0.5,
  40023. gapSize: 0.2,
  40024. lineWidth: config$1.measure.lineWidth
  40025. });
  40026. return line;
  40027. }
  40028. /* function createAzimuth(){
  40029. const azimuth = {
  40030. label: null,
  40031. center: null,
  40032. target: null,
  40033. north: null,
  40034. centerToNorth: null,
  40035. centerToTarget: null,
  40036. centerToTargetground: null,
  40037. targetgroundToTarget: null,
  40038. circle: null,
  40039. node: null,
  40040. };
  40041. const sg = new THREE.markerGeometry(1, 32, 32);
  40042. const sm = new THREE.MeshNormalMaterial();
  40043. {
  40044. const label = new TextSprite("");
  40045. label.setTextColor({r: 140, g: 250, b: 140, a: 1.0});
  40046. label.setBorderColor({r: 0, g: 0, b: 0, a: 1.0});
  40047. label.setBackgroundColor({r: 0, g: 0, b: 0, a: 1.0});
  40048. label.fontsize = 16;
  40049. label.material.depthTest = false;
  40050. label.material.opacity = 1;
  40051. azimuth.label = label;
  40052. }
  40053. azimuth.center = new THREE.Mesh(sg, sm);
  40054. azimuth.target = new THREE.Mesh(sg, sm);
  40055. azimuth.north = new THREE.Mesh(sg, sm);
  40056. azimuth.centerToNorth = createLine();
  40057. azimuth.centerToTarget = createLine();
  40058. azimuth.centerToTargetground = createLine();
  40059. azimuth.targetgroundToTarget = createLine();
  40060. azimuth.circle = createCircle();
  40061. azimuth.node = new THREE.Object3D();
  40062. azimuth.node.add(
  40063. azimuth.centerToNorth,
  40064. azimuth.centerToTarget,
  40065. azimuth.centerToTargetground,
  40066. azimuth.targetgroundToTarget,
  40067. azimuth.circle,
  40068. azimuth.label,
  40069. azimuth.center,
  40070. azimuth.target,
  40071. azimuth.north,
  40072. );
  40073. return azimuth;
  40074. } */
  40075. /*
  40076. 按alt鼠标滚轮或WS键放慢。
  40077. 按Alt键可以平行屏幕拖拽点。&dragPolyBeyondPoint 后缀在拖拽到无点云区域也是此效果。
  40078. 按M键拖拽点可以复制出当前点
  40079. */
  40080. class History extends EventDispatcher {
  40081. constructor(o) {
  40082. super();
  40083. this.undoList = [];
  40084. this.redoList = [];
  40085. this.applyData = o.applyData; //应用数据的方法
  40086. this.getData = o.getData; //获取数据的方法
  40087. this.dataBefore;
  40088. (o.viewer || viewer).inputHandler.addEventListener('keydown', e => {
  40089. if (e.keyCode == 90 && e.event.ctrlKey) {
  40090. //Z
  40091. this.undo();
  40092. } else if (e.keyCode == 89 && e.event.ctrlKey) {
  40093. //Y
  40094. this.redo();
  40095. }
  40096. });
  40097. }
  40098. undo() {
  40099. //回退
  40100. var length = this.undoList.length;
  40101. if (length > 0) {
  40102. var unExist;
  40103. var last = this.undoList.pop();
  40104. this.applyData && (unExist = !this.applyData(last.before));
  40105. unExist || this.redoList.push(last);
  40106. unExist && this.undo(); //找不到就回退下一个。
  40107. this.dispatchEvent('undo');
  40108. //console.log('undo',last)
  40109. }
  40110. }
  40111. redo() {
  40112. //撤销回退
  40113. var length = this.undoList.length;
  40114. var last = this.redoList.pop();
  40115. if (last) {
  40116. //注意:每行的顺序不能乱
  40117. this.undoList.push(last);
  40118. this.applyData && this.applyData(last.after);
  40119. this.dispatchEvent('redo');
  40120. //console.log('redo',last)
  40121. }
  40122. }
  40123. beforeChange(o) {
  40124. //在变化之前(可能执行好几次直到变化完,但只有第一次有效)。 o的内容完全根据getData怎么定义
  40125. if (!this.dataBefore) {
  40126. var data = this.getData(o);
  40127. data && (this.dataBefore = data);
  40128. }
  40129. }
  40130. afterChange(o) {
  40131. //变化结束,从beforeChange到此算一次操作。
  40132. if (this.dataBefore) {
  40133. this.writeIn({
  40134. before: this.dataBefore,
  40135. after: this.getData(o)
  40136. }); //写入某物体变化前和变化后的状态
  40137. this.dataBefore = null;
  40138. }
  40139. }
  40140. writeIn(data) {
  40141. this.redoList.length = 0; //一旦录入新的操作,就不允许undo了
  40142. this.undoList.push(data);
  40143. //console.log('新增undo', data)
  40144. }
  40145. clear() {
  40146. this.redoList.length = 0;
  40147. this.undoList.length = 0;
  40148. this.dataBefore = null;
  40149. }
  40150. }
  40151. var areaPlaneMats = {};
  40152. class Prism extends Measure$1 {
  40153. constructor(args) {
  40154. args.isPrism = true;
  40155. super(args);
  40156. this.volumeInfo = {};
  40157. this.needsCompute = true;
  40158. /*this.createPrismLines(new THREE.Color('#FFF') )
  40159. this.lineMesh.material.transparent = true
  40160. this.lineMesh.material.opacity = 0.5
  40161. Potree.Utils.setObjectLayers(this.lineMesh, 'measure' ) */
  40162. this.setClipBox();
  40163. this.setTopOrBtm('zMin');
  40164. this.setTopOrBtm('zMax');
  40165. this.setHorizonHeight('btm');
  40166. var update = () => {
  40167. this.setHorizonHeight(this.horizonType, true); //更新
  40168. this.needsCompute = true;
  40169. this.getBound();
  40170. this.dispatchEvent('updated');
  40171. };
  40172. this.addEventListener('marker_dropped' /* 'marker_moved' */, update);
  40173. this.addEventListener('changeByHistory', update);
  40174. this.addEventListener('changed', update);
  40175. /* this.addEventListener('createDone',()=>{
  40176. this.setHorizonHeight()//更新
  40177. this.updateAreaPlane()
  40178. }) */
  40179. this.updateAreaPlane();
  40180. this.getBound();
  40181. this.addEventListener('needsCompute', () => {
  40182. this.needsCompute = true;
  40183. }, 10);
  40184. //Potree.Utils.setObjectLayers(this.lineMesh, 'bothMapAndScene' )
  40185. }
  40186. set needsCompute(state) {
  40187. if (state == 'byVolume') {
  40188. this.needsCompute_ = this.volumeInfo.Vupper == void 0;
  40189. } else {
  40190. this.needsCompute_ = !!state;
  40191. //console.error('needsCompute', state)
  40192. }
  40193. }
  40194. get needsCompute() {
  40195. return this.needsCompute_;
  40196. }
  40197. setHorizonHeight(v) {
  40198. var old = this.horizonZ;
  40199. if (typeof v == 'number') {
  40200. this.horizonType = 'number';
  40201. this.horizonZ = v;
  40202. } else {
  40203. if (v) {
  40204. this.horizonType = v;
  40205. }
  40206. if (!this.horizonType) this.horizonType = 'btm';
  40207. if (this.horizonType == 'number') return;
  40208. var zs = this.points.map(p => p.z).sort((a, b) => a - b);
  40209. this.horizonZ = this.horizonType == 'btm' ? zs[0] : zs[this.points.length - 1];
  40210. }
  40211. //this.horizonZ = THREE.Math.clamp(this.horizonZ, this.zMin, this.zMax )
  40212. if (this.horizonZ != old) {
  40213. this.needsCompute = true;
  40214. this.update(); //update areaPlane and areaLabel pos
  40215. this.dispatchEvent('horizonZChanged');
  40216. }
  40217. //console.log(this.horizonZ)
  40218. }
  40219. setBaseModel(model, modelHaventLoad) {
  40220. //三种状态:使用model、使用基准高度、 什么都没有(不允许计算、不高亮、等待模型上传)
  40221. this.baseModel = model;
  40222. this.modelHaventLoad = modelHaventLoad;
  40223. Potree.Utils.updateVisible(this.areaPlane, 'unuseHorizonH', !model && !modelHaventLoad);
  40224. }
  40225. setClipBox(boxes) {
  40226. //clipBoxes_out
  40227. this.clipBoxes = boxes || [];
  40228. }
  40229. setTopOrBtm(name, v) {
  40230. if (v != void 0) {
  40231. this[name] = v;
  40232. this.updatePrismLines();
  40233. } else {
  40234. this[name] = viewer.bound.boundingBox[name == 'zMin' ? 'min' : 'max'].z;
  40235. }
  40236. this.getBound();
  40237. this.needsCompute = true;
  40238. }
  40239. getBound() {
  40240. var bound = Potree.math.getBound(this.points);
  40241. bound.min.z = this.zMin;
  40242. bound.max.z = this.zMax;
  40243. this.prismBound = bound;
  40244. }
  40245. setVolumeInfo(volumeInfo) {
  40246. this.volumeInfo = volumeInfo;
  40247. this.getVolumeString();
  40248. this.needsCompute = false; //但得到的不一定是对的可能 检查下
  40249. }
  40250. getVolumeString() {
  40251. if (!this.volumeInfo || this.volumeInfo.Vupper == void 0) return;
  40252. this.VupperString = this.getConvertString(this.volumeInfo.Vupper, 'volume', true);
  40253. this.VlowerString = this.getConvertString(this.volumeInfo.Vlower, 'volume', true);
  40254. this.highestString = this.getConvertString(this.volumeInfo.highest, 'distance', true);
  40255. this.lowestString = this.getConvertString(this.volumeInfo.lowest, 'distance', true);
  40256. }
  40257. getConvertString(num, type, restrictUnit) {
  40258. if (!restrictUnit) return super.getConvertString(num, type);
  40259. return viewer.unitConvert.convert(num, type, Potree.settings.precision, this.unitSystem, null, {
  40260. //在pdf里的高度要统一单位
  40261. 'imperial': {
  40262. restrictUnit: 'Foot'
  40263. },
  40264. //ft
  40265. 'metric': {
  40266. restrictUnit: 'Meter'
  40267. }
  40268. });
  40269. }
  40270. setUnitSystem(unitSystem) {
  40271. var old = this.unitSystem;
  40272. super.setUnitSystem(unitSystem);
  40273. if (unitSystem != old) {
  40274. this.getVolumeString();
  40275. }
  40276. }
  40277. getCenter(type) {
  40278. if (type == 'areaPlaneCenter') {
  40279. //areaPlane中心
  40280. return this.areaPlaneCenter;
  40281. }
  40282. return super.getCenter(); //点的中心
  40283. }
  40284. update() {
  40285. super.update.apply(this, arguments);
  40286. this.updatePrismLines();
  40287. }
  40288. getTransformationMatrix(pointcloud) {
  40289. //剪裁矩阵
  40290. var invMatrix = new Matrix4();
  40291. //把当前z移动到-0.5 ~ 0.5所需要的变换
  40292. var minZ = this.zMin; //viewer.bound.boundingBox.min.z
  40293. var maxZ = this.zMax; //viewer.bound.boundingBox.max.z
  40294. var s = 1 / (maxZ - minZ);
  40295. var pos = new Vector3(0, 0, -0.5 - minZ * s),
  40296. scale = new Vector3(1, 1, s);
  40297. invMatrix.compose(pos, new Quaternion(), scale); //先缩放后位移
  40298. return new Matrix4().multiplyMatrices(invMatrix, pointcloud.transformMatrix).transpose();
  40299. }
  40300. changeStyleForScreenshot(state) {
  40301. var {
  40302. hideLabel,
  40303. showName
  40304. } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  40305. //截图前变一下外观。根据高度变化颜色
  40306. var config = Potree.settings.prismHeightColor;
  40307. var color; //, lineWidth = this.edges[0].material.lineWidth
  40308. if (this.volumeInfo.Vupper > 0.01 && this.volumeInfo.Vlower > 0.01) {
  40309. color = config.every.color;
  40310. } else if (this.volumeInfo.Vupper > this.volumeInfo.Vlower) {
  40311. for (var i = config.dig.length - 1; i >= 0; i--) {
  40312. if (this.volumeInfo.Vupper >= config.dig[i].min) {
  40313. color = config.dig[i].color;
  40314. break;
  40315. }
  40316. }
  40317. } else {
  40318. for (var _i = config.fill.length - 1; _i >= 0; _i--) {
  40319. if (this.volumeInfo.Vlower >= config.fill[_i].min) {
  40320. color = config.fill[_i].color;
  40321. break;
  40322. }
  40323. }
  40324. }
  40325. color = new Color(color[0] / 255, color[1] / 255, color[2] / 255);
  40326. var name = color.getHexString();
  40327. if (state) {
  40328. Potree.Utils.updateVisible(this.areaPlane, 'screenshot', true, 2, 'add'); //强制显示
  40329. var mat = areaPlaneMats[name];
  40330. if (!mat) {
  40331. mat = new MeshBasicMaterial({
  40332. color,
  40333. transparent: true,
  40334. opacity: 0.6,
  40335. side: DoubleSide
  40336. });
  40337. areaPlaneMats[name] = mat;
  40338. }
  40339. this.oldAreaPlaneMat = this.areaPlane.material;
  40340. this.areaPlane.material = mat;
  40341. if (hideLabel) {
  40342. Potree.Utils.updateVisible(this.areaLabel, 'screenshot-single', false);
  40343. }
  40344. if (showName) {
  40345. this.areaLabel.setText([this.name, this.area.string]);
  40346. /* let btm = this.areaPlaneCenter.clone().setY(this.prismBound.min.y) //置于土方2d块底部
  40347. this.areaLabel.setPos(btm)
  40348. this.areaLabel.sprite.position.y = -0.25 */
  40349. }
  40350. this.markers.forEach(marker => Potree.Utils.updateVisible(marker, 'screenshot-Prism', false));
  40351. this.edges.forEach(edge => Potree.Utils.updateVisible(edge, 'screenshot-Prism', false));
  40352. //Potree.Utils.updateVisible(this.lineMesh,'screenshot-Prism',false)
  40353. this.styleRecover = () => {
  40354. this.areaPlane.material = this.oldAreaPlaneMat;
  40355. if (hideLabel) {
  40356. Potree.Utils.updateVisible(this.areaLabel, 'screenshot-single', true);
  40357. }
  40358. if (showName) {
  40359. this.areaLabel.setText(this.area.string);
  40360. /* this.areaLabel.setPos(this.areaPlaneCenter)
  40361. this.areaLabel.sprite.position.y = 0 */
  40362. }
  40363. this.markers.forEach(marker => Potree.Utils.updateVisible(marker, 'screenshot-Prism', true));
  40364. this.edges.forEach(edge => Potree.Utils.updateVisible(edge, 'screenshot-Prism', true));
  40365. //Potree.Utils.updateVisible(this.lineMesh,'screenshot-Prism',true)
  40366. this.styleRecover = null;
  40367. };
  40368. } else {
  40369. this.styleRecover && this.styleRecover();
  40370. Potree.Utils.updateVisible(this.areaPlane, 'screenshot', false, 2, 'cancel');
  40371. }
  40372. }
  40373. dispose() {
  40374. super.dispose();
  40375. this.clipBoxes.forEach(e => viewer.scene.removeVolume(e));
  40376. }
  40377. setEditState(state) {
  40378. //编辑页面or截图
  40379. state = !!state;
  40380. this.editing = state;
  40381. this.dontHighlight = !state;
  40382. this.clipBoxes.forEach(box => {
  40383. Potree.Utils.updateVisible(box, 'hidden', state), box.clip = state;
  40384. });
  40385. }
  40386. /* {
  40387. fill: [
  40388. {color: [236, 213, 143, 1], min: 0, max: 5},
  40389. {color: [223, 118, 21, 1], min: 5, max: 10},
  40390. // 没有min表示大于
  40391. {color: [186, 57, 57, 1], min: 10}
  40392. ],
  40393. dig: [
  40394. {color: [144, 193, 190, 1], min: 0, max: 5},
  40395. {color: [76, 155, 211, 1], min: 5, max: 10},
  40396. // 没有min表示大于
  40397. {color: [79, 76, 211, 1], min: 10}
  40398. ],
  40399. // 填挖并存
  40400. every: { color: [49, 200, 181, 1] }
  40401. } */
  40402. }
  40403. class MeasuringTool extends EventDispatcher {
  40404. constructor(viewer) {
  40405. super();
  40406. this.viewer = viewer;
  40407. this.renderer = viewer.renderer;
  40408. this.viewer.addEventListener('start_inserting_measurement', e => {
  40409. this.viewer.dispatchEvent({
  40410. type: 'cancel_insertions'
  40411. });
  40412. });
  40413. this.showLabels = true;
  40414. this.scene = new Scene();
  40415. this.scene.name = 'scene_measurement';
  40416. //this.light = new THREE.PointLight(0xffffff, 1.0);
  40417. //this.scene.add(this.light);
  40418. this.viewer.inputHandler.registerInteractiveScene(this.scene);
  40419. this.history = new History({
  40420. applyData: data => {
  40421. if (data.measure.parent && data.measure.visible) {
  40422. data = Potree.Common.CloneObject(data); //避免使用后更改数据又被使用
  40423. data.measure.reDraw();
  40424. data.measure.initData(data);
  40425. data.measure.isNew = data.isNew;
  40426. data.measure.dispatchEvent('changeByHistory');
  40427. /* if(data.measure.isPrism){
  40428. data.measure.needsCompute = data.needsCompute
  40429. } */
  40430. data.measure.facePlane = data.facePlane && data.facePlane.clone();
  40431. data.measure.cannotConfirmNormal = data.cannotConfirmNormal;
  40432. return true;
  40433. }
  40434. },
  40435. getData: measure => {
  40436. var data = {
  40437. measure,
  40438. points: measure.points.map(e => e.clone()),
  40439. dataset_points: measure.dataset_points ? measure.dataset_points.map(e => e && e.clone()) : null,
  40440. points_datasets: measure.points_datasets.slice(),
  40441. datasetId: measure.datasetId,
  40442. isNew: measure.isNew,
  40443. facePlane: measure.facePlane && measure.facePlane.clone(),
  40444. cannotConfirmNormal: measure.cannotConfirmNormal
  40445. };
  40446. /* if(measure.isPrism){ //没用
  40447. data.volumeInfo = measure.volumeInfo
  40448. data.needsCompute = measure.needsCompute
  40449. //但不记录其他信息
  40450. } */
  40451. return data;
  40452. }
  40453. }),
  40454. //this.scene = viewer.overlay//
  40455. this.onRemove = e => {
  40456. e.measurement.dispose(); /* this.scene.remove(e.measurement); */
  40457. };
  40458. this.onAdd = e => {
  40459. this.scene.add(e.measurement);
  40460. };
  40461. for (var measurement of viewer.scene.measurements) {
  40462. this.onAdd({
  40463. measurement: measurement
  40464. });
  40465. }
  40466. viewer.addEventListener('camera_changed', this.update.bind(this), {
  40467. importance: 10
  40468. }); //优先级高于sprite
  40469. if (Potree.config.measure.mulLabelHideFaraway) {
  40470. viewer.addEventListener("raycaster", this.beforeDraw.bind(this), {
  40471. importance: 10
  40472. }); //before render
  40473. viewer.addEventListener("render.begin", this.beforeDraw.bind(this), {
  40474. importance: 10
  40475. }); //before render
  40476. viewer.addEventListener("render.begin2", this.beforeDraw.bind(this), {
  40477. importance: 10
  40478. });
  40479. }
  40480. //viewer.addEventListener("update", this.update.bind(this));
  40481. viewer.addEventListener("render.pass.perspective_overlay", this.render.bind(this));
  40482. viewer.addEventListener("scene_changed", this.onSceneChange.bind(this));
  40483. viewer.scene.addEventListener('measurement_added', this.onAdd);
  40484. viewer.scene.addEventListener('measurement_removed', this.onRemove);
  40485. viewer.addEventListener('resize', this.setSize.bind(this));
  40486. }
  40487. onSceneChange(e) {
  40488. if (e.oldScene) {
  40489. e.oldScene.removeEventListener('measurement_added', this.onAdd);
  40490. e.oldScene.removeEventListener('measurement_removed', this.onRemove);
  40491. }
  40492. e.scene.addEventListener('measurement_added', this.onAdd);
  40493. e.scene.addEventListener('measurement_removed', this.onRemove);
  40494. }
  40495. createMeasureFromData(data) {
  40496. //add
  40497. var measure = data.measureType == 'MulDistance Ring' ? new Prism(data) : new Measure$1(data);
  40498. if (measure.failBuilded) {
  40499. return;
  40500. }
  40501. viewer.scene.addMeasurement(measure);
  40502. if (measure.guideLine) measure.guideLine.visible = false;
  40503. return measure;
  40504. }
  40505. beforeDraw(e) {
  40506. if (e.viewport.name == 'mapViewport' && !viewer.mapViewer.attachedToViewer) return; //no measures
  40507. viewer.scene.measurements.forEach(measure => {
  40508. if (measure.measureType != 'MulDistance' || (measure.isNew ? measure.points.length < 4 : measure.points.length < 3)) return;
  40509. var lastIndex = measure.points.length - 1;
  40510. for (var index = 0; index <= lastIndex; index++) {
  40511. if (!measure.closed && index == lastIndex) continue;
  40512. var edgeLabel = measure.edgeLabels[index];
  40513. var v = edgeLabel.visiMap.get(e.viewport.camera);
  40514. if (v == void 0) {
  40515. return measure.getEdgeLabelVisi(e.viewport);
  40516. }
  40517. Potree.Utils.updateVisible(edgeLabel, 'tooFar', v === false ? false : true);
  40518. }
  40519. });
  40520. }
  40521. update(e) {
  40522. /* viewer.scene.measurements.forEach(measure=>{
  40523. if(measure.measureType != 'MulDistance' || (measure.isNew ? measure.points.length<4 : measure.points.length<3)) return
  40524. }) */
  40525. if (viewer.inputHandler.measuring && Potree.settings.adsorption) {
  40526. viewer.scene.measurements.forEach(measure => {
  40527. measure.getPointsPos2d(e.viewport, true);
  40528. });
  40529. }
  40530. if (Potree.config.measure.mulLabelHideFaraway) {
  40531. if (e.changeInfo.projectionChanged || e.viewport.camera.type == 'PerspectiveCamera' && e.changeInfo.positionChanged) {
  40532. //for MulDistance
  40533. viewer.scene.measurements.forEach(measure => {
  40534. if (measure.measureType != 'MulDistance' || (measure.isNew ? measure.points.length < 4 : measure.points.length < 3)) return;
  40535. measure.getEdgeLabelVisi(e.viewport);
  40536. return;
  40537. var lastIndex = measure.points.length - 1;
  40538. for (var index = 0; index <= lastIndex; index++) {
  40539. if (!measure.closed && index == lastIndex) continue;
  40540. var nextIndex = index + 1 > lastIndex ? 0 : index + 1;
  40541. var previousIndex = index === 0 ? lastIndex : index - 1;
  40542. var point = measure.points[index];
  40543. var nextPoint = measure.points[nextIndex];
  40544. var previousPoint = measure.points[previousIndex];
  40545. var point2d = new Vector2().copy(pos2ds[index]);
  40546. var nextPoint2d = new Vector2().copy(pos2ds[nextIndex]);
  40547. if (measure.showDistances || measure.labelText) {
  40548. // edge labels
  40549. var edgeLabel = measure.edgeLabels[index];
  40550. if (edgeLabel.visible) {
  40551. measure.setEdgeLabelPos(edgeLabel, point, nextPoint);
  40552. }
  40553. }
  40554. }
  40555. });
  40556. }
  40557. }
  40558. return;
  40559. var camera = this.viewer.scene.getActiveCamera();
  40560. var domElement = this.renderer.domElement;
  40561. var measurements = this.viewer.scene.measurements;
  40562. // make size independant of distance
  40563. var mainLabels = [],
  40564. subLabels = [];
  40565. for (var measure of measurements) {
  40566. measure.lengthUnit = this.viewer.lengthUnit;
  40567. measure.lengthUnitDisplay = this.viewer.lengthUnitDisplay;
  40568. //measure.update();
  40569. updateAzimuth(this.viewer, measure);
  40570. /* [...measure.markers, ...measure.edgeLabels, measure.areaLabel].forEach(e=>{
  40571. e && e.update()
  40572. }); */
  40573. // labels
  40574. /* let labels = measure.edgeLabels.concat(measure.angleLabels);
  40575. for(let label of labels){
  40576. label.update()
  40577. if(label.elem.hasClass('sub')){
  40578. subLabels.push(label)
  40579. }else{
  40580. mainLabels.push(label)
  40581. }
  40582. }
  40583. // coordinate labels
  40584. for (let j = 0; j < measure.coordinateLabels.length; j++) {
  40585. let label = measure.coordinateLabels[j];
  40586. label.update()
  40587. mainLabels.push(label)
  40588. }
  40589. if(measure.showArea){ // area label
  40590. let label = measure.areaLabel;
  40591. label.update()
  40592. mainLabels.push(label)
  40593. } */
  40594. /* if(measure.showCircle){ // radius label
  40595. let label = measure.circleRadiusLabel;
  40596. let distance = label.position.distanceTo(camera.position);
  40597. let pr = Utils.projectedRadius(1, camera, distance, clientWidth, clientHeight);
  40598. let scale = (70 / pr);
  40599. label.scale.set(scale, scale, scale);
  40600. } */
  40601. if (!this.showLabels) {
  40602. var labels = [...measure.sphereLabels, ...measure.angleLabels, measure.circleRadiusLabel];
  40603. for (var label of labels) {
  40604. label.visible = false;
  40605. }
  40606. }
  40607. }
  40608. //this.updateLabelZIndex([{labels:subLabels},{labels:mainLabels}])
  40609. }
  40610. setSize(e) {//e.resolution
  40611. /* if(Measure.lineMats){
  40612. for(var m in Measure.lineMats){
  40613. Measure.lineMats[m].resolution.set(e.canvasWidth, e.canvasHeight);
  40614. }
  40615. }
  40616. if(Measure.sphereMats){
  40617. for(var s in Measure.sphereMats){
  40618. Measure.sphereMats[s].uniforms.resolution.value.set(e.canvasWidth, e.canvasHeight);
  40619. }
  40620. }
  40621. for (let measure of this.viewer.scene.measurements) {
  40622. measure.edgeLabels.concat(measure.areaLabel).forEach(label=>{
  40623. label.sprite.material.uniforms.resolution.value.set(e.canvasWidth, e.canvasHeight);
  40624. })
  40625. } */
  40626. }
  40627. updateLabelZIndex(group) {
  40628. //[{labels:[]},{}] 顺序按照z-index低到高
  40629. group.forEach((e, i) => {
  40630. e.base = group[i - 1] ? group[i - 1].base + group[i - 1].labels.length : 0;
  40631. var labels = e.labels.sort((a, b) => {
  40632. return b.pos2d.z - a.pos2d.z;
  40633. });
  40634. labels.forEach((label, index) => {
  40635. $(label.elem).css('z-index', e.base + index);
  40636. });
  40637. });
  40638. }
  40639. changeEditMode(mode) {
  40640. viewer.dispatchEvent({
  40641. type: "CursorChange",
  40642. action: "remove",
  40643. name: "addPoint"
  40644. });
  40645. viewer.dispatchEvent({
  40646. type: "CursorChange",
  40647. action: "remove",
  40648. name: "delPoint"
  40649. });
  40650. if (mode) {
  40651. if (mode == 'addPoint') {
  40652. viewer.dispatchEvent({
  40653. type: "CursorChange",
  40654. action: "add",
  40655. name: "addPoint"
  40656. });
  40657. } else {
  40658. viewer.dispatchEvent({
  40659. type: "CursorChange",
  40660. action: "add",
  40661. name: "delPoint"
  40662. });
  40663. }
  40664. }
  40665. this.editMode = mode;
  40666. }
  40667. editStateChange(e) {
  40668. //console.log("editStateChange" , e.state)
  40669. var state = e.state;
  40670. if (!state) {
  40671. state = viewer.scene.measurements.some(e => e.isEditing);
  40672. }
  40673. if (state) {
  40674. viewer.dispatchEvent({
  40675. type: "measureMovePoint"
  40676. }); //重新激活reticule状态
  40677. } else {
  40678. viewer.dispatchEvent({
  40679. type: "endMeasureMove"
  40680. });
  40681. }
  40682. //this.editing =
  40683. }
  40684. startInsertion() {
  40685. var _this = this;
  40686. var args = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  40687. var callback = arguments.length > 1 ? arguments[1] : undefined;
  40688. var cancelFun = arguments.length > 2 ? arguments[2] : undefined;
  40689. var domElement = this.viewer.renderer.domElement;
  40690. var measure = args.measureType == 'MulDistance Ring' ? new Prism(args) : new Measure$1(args);
  40691. this.scene.add(measure);
  40692. measure.isNew = true;
  40693. this.viewer.dispatchEvent({
  40694. type: 'start_inserting_measurement',
  40695. measure: measure
  40696. });
  40697. measure.addEventListener('editStateChange', this.editStateChange.bind(this));
  40698. measure.editStateChange(true);
  40699. var timer;
  40700. this.isAdding = true;
  40701. var endDragFun = e => {
  40702. var length = measure.points.length;
  40703. if (e.button == MOUSE.LEFT || e.isTouch) {
  40704. if (length >= measure.maxMarkers) {
  40705. _end({
  40706. finish: true
  40707. });
  40708. } else {
  40709. this.history.beforeChange(measure);
  40710. var marker = measure.cloneMarker(length - 1, length);
  40711. if (args.isRect && measure.markers.length == 3) {
  40712. //marker全可见
  40713. measure.cloneMarker(0, 3);
  40714. } else {
  40715. measure.markers[length].visible = false;
  40716. measure.edges[length].visible = false;
  40717. }
  40718. measure.edges[length - 1].visible = true;
  40719. measure.markers[length - 1].visible = true;
  40720. marker.isDragging = true;
  40721. this.history.afterChange(measure);
  40722. measure.continueDrag(marker, e);
  40723. }
  40724. } else if (e.button === MOUSE.RIGHT) {
  40725. //触屏怎么取消?
  40726. if (e.pressDistance < Potree.config.clickMaxDragDis) {
  40727. //非拖拽的话
  40728. var isIntersectSelf = measure.atPlane && measure.closed && !measure.isRect && measure.point2dInfo && measure.intersectSelf(measure.point2dInfo.points2d.slice(0, measure.point2dInfo.points2d.length - 1)); //检测除了最后一个点的相交情况
  40729. if (!isIntersectSelf) _end(e);else measure.continueDrag(null, e);
  40730. } else measure.continueDrag(null, e);
  40731. }
  40732. };
  40733. var _end = function end() {
  40734. var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  40735. //确定、结束
  40736. if (!measure.isNew) return;
  40737. if (args.minMarkers != void 0) {
  40738. if (!e.finish && measure.markers.length <= args.minMarkers) {
  40739. //右键 当个数不够时取消
  40740. //this.viewer.scene.removeMeasurement(measure)
  40741. //重新开始画
  40742. if (measure.markers.length > 0) {
  40743. measure.markers[0].removeEventListener('mousedown', _end);
  40744. measure.reDraw();
  40745. _this.viewer.addEventListener('global_click', click, {
  40746. importance: 10
  40747. });
  40748. measure.editStateChange(true);
  40749. }
  40750. return;
  40751. /* if(!Potree.settings.isOfficial) this.viewer.scene.removeMeasurement(measure)
  40752. else if(e.drag){ //正式版本不允许右键退出, 继续
  40753. continueDrag(e.drag.object)
  40754. measure.editStateChange(true)
  40755. return
  40756. } */
  40757. }
  40758. }
  40759. var lastMarker = measure.markers[measure.markers.length - 1];
  40760. if ( /* !e.finish&& */measure.markers.length > args.minMarkers) {
  40761. measure.removeMarker(measure.points.length - 1);
  40762. measure.markers[0].removeEventListener('mouseover', mouseover);
  40763. measure.markers[0].removeEventListener('mouseleave', mouseleave);
  40764. measure.markers[0].removeEventListener('click' /* 'mousedown' */, Exit);
  40765. if (e.byClickMarker && measure.markers.length > args.minMarkers) {
  40766. //通过点击第一个marker而结束的话,会多一个marker。但点击marker后可能会因为和它坐标一致而没有添加成功,就不删,根据添加的时间来判断。
  40767. var delta = Date.now() - lastMarker.createTime;
  40768. //console.log('delta',delta)
  40769. if (delta < 10) {
  40770. //刚生成的,说明点击后新增了一个marker
  40771. measure.removeMarker(measure.points.length - 1);
  40772. }
  40773. }
  40774. }
  40775. measure.isNew = false;
  40776. var length = measure.points.length;
  40777. if (length) {
  40778. measure.markers[length - 1].visible = true;
  40779. measure.edges[length - 1].visible = !!measure.closed;
  40780. measure.markers.forEach(marker => {
  40781. marker.dispatchEvent('addHoverEvent');
  40782. });
  40783. measure.edges.forEach(edge => {
  40784. edge.dispatchEvent('addHoverEvent');
  40785. });
  40786. measure.update(); //update last edgeLabel
  40787. }
  40788. clearTimeout(timer);
  40789. _this.viewer.removeEventListener('cancel_insertions', Exit);
  40790. //pressExit && this.viewer.inputHandler.removeEventListener('keydown', pressExit);
  40791. _this.viewer.removeEventListener('global_click', click);
  40792. _this.viewer.removeEventListener('global_mousemove', ifAtWrongPlace);
  40793. viewer.dispatchEvent({
  40794. type: "CursorChange",
  40795. action: "remove",
  40796. name: "polygon_AtWrongPlace"
  40797. });
  40798. viewer.inputHandler.dispatchEvent({
  40799. type: 'measuring',
  40800. v: false,
  40801. cause: 'stopInsertion',
  40802. situation: 'adding',
  40803. object: measure
  40804. });
  40805. //var isIntersectSelf = measure.atPlane && measure.closed && !measure.isRect && measure.point2dInfo && measure.intersectSelf(measure.point2dInfo.points2d.slice(0,measure.point2dInfo.points2d.length-1))//检测除了最后一个点的相交情况
  40806. var isIntersectSelf = measure.atPlane && measure.closed && !measure.isRect && measure.point2dInfo && measure.intersectSelf(measure.point2dInfo.points2d);
  40807. if (isIntersectSelf) return cancelFun && cancelFun(); //请求删除,不重建
  40808. e.remove || callback && callback();
  40809. /* this.viewer.dispatchEvent({
  40810. type: 'finish_inserting_measurement',
  40811. measure: measure
  40812. }); */
  40813. _this.isAdding = false;
  40814. measure.dispatchEvent('createDone');
  40815. };
  40816. measure.addEventListener('finish', _end); //完成
  40817. var Exit = e => {
  40818. //强制退出
  40819. if (e.measure && e.measure != measure || !viewer.scene.measurements.includes(measure) || !measure.isNew) {
  40820. return; //若指定了退出的measure但和该measure不一致,就返回
  40821. }
  40822. if (e.remove || e.type == 'cancel_insertions') {
  40823. viewer.scene.removeMeasurement(measure);
  40824. }
  40825. measure.editStateChange(false);
  40826. measure.cannotConfirmNormal = false; //一些dropMarker中的句子
  40827. measure.guideLine && (measure.guideLine.visible = false);
  40828. /*
  40829. if(this.viewer.inputHandler.drag && !e.remove ){//还未触发drop的话
  40830. this.viewer.inputHandler.drag.object.dispatchEvent({ //这句会导致又增一个marker
  40831. type: 'drop',
  40832. drag: this.viewer.inputHandler.drag,
  40833. viewer: this.viewer,
  40834. pressDistance:0,
  40835. button : THREE.MOUSE.RIGHT
  40836. });
  40837. } else {*/ //未结束时添加新的measure时会触发
  40838. _end({
  40839. finish: true,
  40840. remove: e.remove,
  40841. byClickMarker: e.type == 'click'
  40842. });
  40843. //}
  40844. this.viewer.inputHandler.drag && (this.viewer.inputHandler.drag.object = null);
  40845. };
  40846. this.viewer.addEventListener('cancel_insertions', Exit);
  40847. /*let pressExit
  40848. if(!Potree.settings.isOfficial){
  40849. pressExit = (e)=>{
  40850. if(e.keyCode == 27){//Esc
  40851. //Exit()
  40852. //怎么模拟右键???//现由前端发出
  40853. }
  40854. }
  40855. this.viewer.inputHandler.addEventListener('keydown', pressExit)
  40856. } */
  40857. var mouseover = e => {
  40858. measure.setMarkerSelected(e.object, 'hover', 'single');
  40859. };
  40860. var mouseleave = e => {
  40861. measure.setMarkerSelected(e.object, 'unhover', 'single');
  40862. };
  40863. var click = e => {
  40864. //一旦点击就立刻增加两marker
  40865. if (ifAtWrongPlace(e)) return;
  40866. if (e.clickElement) return; //如点击label时focusOnObject
  40867. if (e.button === MOUSE.RIGHT) return;
  40868. //console.log('measure clicked33', !!e.intersectPoint)
  40869. //var I = e.intersectPoint && (e.intersectPoint.orthoIntersect || e.intersectPoint.location)
  40870. var I = e.intersect && (e.intersect.orthoIntersect || e.intersect.location);
  40871. if (!I) {
  40872. return measure.dispatchEvent('intersectNoPointcloud');
  40873. }
  40874. var atMap = e.drag.dragViewport.name == 'mapViewport';
  40875. //在地图上测量的首个点按楼层高度(暂时先只按mainViewport相机高度吧,但navvis是按楼层,画在楼层的地面上,可能因为平面图显示的是楼层近地面),
  40876. if (atMap) {
  40877. I = I.clone().setZ(viewer.mainViewport.camera.position.z);
  40878. }
  40879. var marker = measure.addMarker({
  40880. point: I
  40881. });
  40882. marker.isDragging = true;
  40883. this.viewer.inputHandler.startDragging(marker, {
  40884. endDragFun,
  40885. notPressMouse: true
  40886. }); //notPressMouse代表不是通过按下鼠标来拖拽
  40887. e.drag = this.viewer.inputHandler.drag;
  40888. /* e.drag.endDragFun = endDragFun
  40889. e.drag.notPressMouse = true */
  40890. //if(!measure.dragMarker(e) || !measure.dropMarker(e))return
  40891. measure.dragMarker(e);
  40892. measure.dropMarker(e);
  40893. if (measure.maxMarkers > 1) {
  40894. measure.markers[1].visible = false;
  40895. measure.edges[1].visible = false;
  40896. }
  40897. if (measure.closed && !measure.isRect) {
  40898. measure.markers[0].addEventListener('mouseover', mouseover);
  40899. measure.markers[0].addEventListener('mouseleave', mouseleave);
  40900. measure.markers[0].addEventListener('click' /* 'mousedown' */, Exit); //点击到第一个marker就结束
  40901. }
  40902. this.viewer.removeEventListener('global_click', click); ///* global_drop */
  40903. //console.log('measure clicked')
  40904. e.consume && e.consume();
  40905. return {
  40906. stopContinue: true
  40907. }; //防止继续执行别的侦听,如flytopano
  40908. };
  40909. //点击第n下拥有n+1个marker, n>0
  40910. viewer.inputHandler.dispatchEvent({
  40911. type: 'measuring',
  40912. v: true,
  40913. cause: 'startInsertion',
  40914. situation: 'adding',
  40915. object: measure
  40916. });
  40917. this.viewer.addEventListener('global_click', click, {
  40918. importance: 10
  40919. }); //add importance
  40920. var ifAtWrongPlace = e => {
  40921. if (measure.unableDragAtMap && e.hoverViewport.name == 'mapViewport') {
  40922. if (e.isTouch) {
  40923. viewer.dispatchEvent({
  40924. type: 'reticule_forbit',
  40925. v: true
  40926. });
  40927. } else {
  40928. viewer.dispatchEvent({
  40929. type: "CursorChange",
  40930. action: "add",
  40931. name: "polygon_AtWrongPlace"
  40932. });
  40933. }
  40934. return true;
  40935. } else {
  40936. if (e.isTouch) {
  40937. viewer.dispatchEvent({
  40938. type: 'reticule_forbit',
  40939. v: false
  40940. });
  40941. } else {
  40942. viewer.dispatchEvent({
  40943. type: "CursorChange",
  40944. action: "remove",
  40945. name: "polygon_AtWrongPlace"
  40946. });
  40947. }
  40948. }
  40949. };
  40950. if (measure.unableDragAtMap) {
  40951. this.viewer.addEventListener('global_mousemove', ifAtWrongPlace);
  40952. }
  40953. var changeByHistory = e => {
  40954. if (!measure.isNew) return;
  40955. var marker = measure.markers[measure.points.length - 1];
  40956. this.viewer.inputHandler.startDragging(marker, {
  40957. endDragFun,
  40958. notPressMouse: true
  40959. });
  40960. var I = viewer.inputHandler.intersect && (viewer.inputHandler.intersect.orthoIntersect || viewer.inputHandler.intersect.location);
  40961. if (I) {
  40962. measure.dragChange(I.clone(), measure.points.length - 1); //使最后一个点在鼠标处
  40963. }
  40964. /* if(measure.markers.length == 1){
  40965. Common.updateVisible(marker, ,false)
  40966. } */
  40967. args.isRect || (measure.edges[measure.points.length - 1].visible = false);
  40968. //measure.continueDrag(measure.markers[measure.points.length-1], o )
  40969. };
  40970. measure.addEventListener('changeByHistory', changeByHistory);
  40971. this.viewer.scene.addMeasurement(measure);
  40972. return measure;
  40973. }
  40974. render() {
  40975. var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  40976. if (this.scene.children.filter(e => e.visible).length == 0) return;
  40977. var renderer = o.renderer || this.viewer.renderer;
  40978. Potree.Utils.setCameraLayers(o.camera, ['measure']);
  40979. /* if(o.screenshot && this.viewer.fxaaPass.enabled){ //抗锯齿
  40980. this.viewer.ssaaRenderPass.sampleLevel = 4
  40981. this.viewer.composer.render(this.scene, o.camera );
  40982. }else{ */
  40983. viewer.dispatchEvent({
  40984. type: "render.begin2",
  40985. name: 'measure',
  40986. viewport: o.viewport,
  40987. renderer: o.renderer
  40988. });
  40989. renderer.render(this.scene, o.camera);
  40990. //}
  40991. }
  40992. }
  40993. ;
  40994. function updateAzimuth(viewer, measure) {
  40995. if (!measure.showAzimuth) return;
  40996. var azimuth = measure.azimuth;
  40997. var isOkay = measure.points.length === 2;
  40998. azimuth.node.visible = isOkay;
  40999. if (!azimuth.node.visible) {
  41000. return;
  41001. }
  41002. var camera = viewer.scene.getActiveCamera();
  41003. var renderAreaSize = viewer.renderer.getSize(new Vector2());
  41004. var width = renderAreaSize.width;
  41005. var height = renderAreaSize.height;
  41006. var [p0, p1] = measure.points;
  41007. var r = p0.position.distanceTo(p1.position);
  41008. var northVec = Utils.getNorthVec(p0.position, r, viewer.getProjection());
  41009. var northPos = p0.position.clone().add(northVec);
  41010. azimuth.center.position.copy(p0.position);
  41011. azimuth.center.scale.set(2, 2, 2);
  41012. azimuth.center.visible = false;
  41013. // azimuth.target.visible = false;
  41014. {
  41015. // north
  41016. azimuth.north.position.copy(northPos);
  41017. azimuth.north.scale.set(2, 2, 2);
  41018. var _distance = azimuth.north.position.distanceTo(camera.position);
  41019. var _pr = Utils.projectedRadius(1, camera, _distance, width, height);
  41020. var _scale = 5 / _pr;
  41021. azimuth.north.scale.set(_scale, _scale, _scale);
  41022. }
  41023. {
  41024. // target
  41025. azimuth.target.position.copy(p1.position);
  41026. azimuth.target.position.z = azimuth.north.position.z;
  41027. var _distance2 = azimuth.target.position.distanceTo(camera.position);
  41028. var _pr2 = Utils.projectedRadius(1, camera, _distance2, width, height);
  41029. var _scale2 = 5 / _pr2;
  41030. azimuth.target.scale.set(_scale2, _scale2, _scale2);
  41031. }
  41032. azimuth.circle.position.copy(p0.position);
  41033. azimuth.circle.scale.set(r, r, r);
  41034. azimuth.circle.material.resolution.set(width, height);
  41035. // to target
  41036. azimuth.centerToTarget.geometry.setPositions([0, 0, 0, ...p1.position.clone().sub(p0.position).toArray()]);
  41037. azimuth.centerToTarget.position.copy(p0.position);
  41038. azimuth.centerToTarget.geometry.verticesNeedUpdate = true;
  41039. azimuth.centerToTarget.geometry.computeBoundingSphere();
  41040. azimuth.centerToTarget.computeLineDistances();
  41041. azimuth.centerToTarget.material.resolution.set(width, height);
  41042. // to target ground
  41043. azimuth.centerToTargetground.geometry.setPositions([0, 0, 0, p1.position.x - p0.position.x, p1.position.y - p0.position.y, 0]);
  41044. azimuth.centerToTargetground.position.copy(p0.position);
  41045. azimuth.centerToTargetground.geometry.verticesNeedUpdate = true;
  41046. azimuth.centerToTargetground.geometry.computeBoundingSphere();
  41047. azimuth.centerToTargetground.computeLineDistances();
  41048. azimuth.centerToTargetground.material.resolution.set(width, height);
  41049. // to north
  41050. azimuth.centerToNorth.geometry.setPositions([0, 0, 0, northPos.x - p0.position.x, northPos.y - p0.position.y, 0]);
  41051. azimuth.centerToNorth.position.copy(p0.position);
  41052. azimuth.centerToNorth.geometry.verticesNeedUpdate = true;
  41053. azimuth.centerToNorth.geometry.computeBoundingSphere();
  41054. azimuth.centerToNorth.computeLineDistances();
  41055. azimuth.centerToNorth.material.resolution.set(width, height);
  41056. // label
  41057. var radians = Utils.computeAzimuth(p0.position, p1.position, viewer.getProjection());
  41058. var degrees = MathUtils.radToDeg(radians);
  41059. if (degrees < 0) {
  41060. degrees = 360 + degrees;
  41061. }
  41062. var txtDegrees = "".concat(degrees.toFixed(2), "\xB0");
  41063. var labelDir = northPos.clone().add(p1.position).multiplyScalar(0.5).sub(p0.position);
  41064. if (labelDir.length() > 0) {
  41065. labelDir.z = 0;
  41066. labelDir.normalize();
  41067. var labelVec = labelDir.clone().multiplyScalar(r);
  41068. var labelPos = p0.position.clone().add(labelVec);
  41069. azimuth.label.position.copy(labelPos);
  41070. }
  41071. azimuth.label.setText(txtDegrees);
  41072. var distance = azimuth.label.position.distanceTo(camera.position);
  41073. var pr = Utils.projectedRadius(1, camera, distance, width, height);
  41074. var scale = 70 / pr;
  41075. azimuth.label.scale.set(scale, scale, scale);
  41076. }
  41077. class ProfileTool extends EventDispatcher$1 {
  41078. constructor(viewer) {
  41079. super();
  41080. this.viewer = viewer;
  41081. this.renderer = viewer.renderer;
  41082. this.addEventListener('start_inserting_profile', e => {
  41083. this.viewer.dispatchEvent({
  41084. type: 'cancel_insertions'
  41085. });
  41086. });
  41087. this.scene = new Scene();
  41088. this.scene.name = 'scene_profile';
  41089. this.light = new PointLight(0xffffff, 1.0);
  41090. this.scene.add(this.light);
  41091. this.viewer.inputHandler.registerInteractiveScene(this.scene);
  41092. this.onRemove = e => this.scene.remove(e.profile);
  41093. this.onAdd = e => this.scene.add(e.profile);
  41094. for (var profile of viewer.scene.profiles) {
  41095. this.onAdd({
  41096. profile: profile
  41097. });
  41098. }
  41099. viewer.addEventListener("update", this.update.bind(this));
  41100. viewer.addEventListener("render.pass.perspective_overlay", this.render.bind(this));
  41101. viewer.addEventListener("scene_changed", this.onSceneChange.bind(this));
  41102. viewer.scene.addEventListener('profile_added', this.onAdd);
  41103. viewer.scene.addEventListener('profile_removed', this.onRemove);
  41104. }
  41105. onSceneChange(e) {
  41106. if (e.oldScene) {
  41107. e.oldScene.removeEventListeners('profile_added', this.onAdd);
  41108. e.oldScene.removeEventListeners('profile_removed', this.onRemove);
  41109. }
  41110. e.scene.addEventListener('profile_added', this.onAdd);
  41111. e.scene.addEventListener('profile_removed', this.onRemove);
  41112. }
  41113. startInsertion() {
  41114. var args = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  41115. var domElement = this.viewer.renderer.domElement;
  41116. var profile = new Profile();
  41117. profile.name = args.name || 'Profile';
  41118. this.dispatchEvent({
  41119. type: 'start_inserting_profile',
  41120. profile: profile
  41121. });
  41122. this.scene.add(profile);
  41123. var cancel = {
  41124. callback: null
  41125. };
  41126. var insertionCallback = e => {
  41127. if (e.button === MOUSE.LEFT) {
  41128. if (profile.points.length <= 1) {
  41129. var camera = this.viewer.scene.getActiveCamera();
  41130. var distance = camera.position.distanceTo(profile.points[0]);
  41131. var clientSize = this.viewer.renderer.getSize(new Vector2());
  41132. var pr = Utils.projectedRadius(1, camera, distance, clientSize.width, clientSize.height);
  41133. var width = 10 / pr;
  41134. profile.setWidth(width);
  41135. }
  41136. profile.addMarker(profile.points[profile.points.length - 1].clone());
  41137. this.viewer.inputHandler.startDragging(profile.spheres[profile.spheres.length - 1]);
  41138. } else if (e.button === MOUSE.RIGHT) {
  41139. cancel.callback();
  41140. }
  41141. };
  41142. cancel.callback = e => {
  41143. profile.removeMarker(profile.points.length - 1);
  41144. domElement.removeEventListener('mouseup', insertionCallback, false);
  41145. this.viewer.removeEventListener('cancel_insertions', cancel.callback);
  41146. };
  41147. this.viewer.addEventListener('cancel_insertions', cancel.callback);
  41148. domElement.addEventListener('mouseup', insertionCallback, false);
  41149. profile.addMarker(new Vector3(0, 0, 0));
  41150. this.viewer.inputHandler.startDragging(profile.spheres[profile.spheres.length - 1]);
  41151. this.viewer.scene.addProfile(profile);
  41152. return profile;
  41153. }
  41154. update() {
  41155. var camera = this.viewer.scene.getActiveCamera();
  41156. var profiles = this.viewer.scene.profiles;
  41157. var renderAreaSize = this.viewer.renderer.getSize(new Vector2());
  41158. var clientWidth = renderAreaSize.width;
  41159. var clientHeight = renderAreaSize.height;
  41160. this.light.position.copy(camera.position);
  41161. // make size independant of distance
  41162. for (var profile of profiles) {
  41163. for (var sphere of profile.spheres) {
  41164. var distance = camera.position.distanceTo(sphere.getWorldPosition(new Vector3()));
  41165. var pr = Utils.projectedRadius(1, camera, distance, clientWidth, clientHeight);
  41166. var scale = 15 / pr;
  41167. sphere.scale.set(scale, scale, scale);
  41168. }
  41169. }
  41170. }
  41171. render() {
  41172. this.viewer.renderer.render(this.scene, this.viewer.scene.getActiveCamera());
  41173. }
  41174. }
  41175. class ScreenBoxSelectTool extends EventDispatcher$1 {
  41176. constructor(viewer) {
  41177. super();
  41178. this.viewer = viewer;
  41179. this.scene = new Scene();
  41180. viewer.addEventListener("update", this.update.bind(this));
  41181. viewer.addEventListener("render.pass.perspective_overlay", this.render.bind(this));
  41182. viewer.addEventListener("scene_changed", this.onSceneChange.bind(this));
  41183. }
  41184. onSceneChange(scene) {
  41185. console.log("scene changed");
  41186. }
  41187. startInsertion() {
  41188. var domElement = this.viewer.renderer.domElement;
  41189. var volume = new BoxVolume();
  41190. volume.position.set(12345, 12345, 12345);
  41191. volume.showVolumeLabel = false;
  41192. volume.visible = false;
  41193. volume.update();
  41194. this.viewer.scene.addVolume(volume);
  41195. this.importance = 10;
  41196. var selectionBox = $("<div style=\"position: absolute; border: 2px solid white; pointer-events: none; border-style:dashed\"></div>");
  41197. $(domElement.parentElement).append(selectionBox);
  41198. selectionBox.css("right", "10px");
  41199. selectionBox.css("bottom", "10px");
  41200. var drag = e => {
  41201. volume.visible = true;
  41202. var mStart = e.drag.start;
  41203. var mEnd = e.drag.end;
  41204. var box2D = new Box2();
  41205. box2D.expandByPoint(mStart);
  41206. box2D.expandByPoint(mEnd);
  41207. selectionBox.css("left", "".concat(box2D.min.x, "px"));
  41208. selectionBox.css("top", "".concat(box2D.min.y, "px"));
  41209. selectionBox.css("width", "".concat(box2D.max.x - box2D.min.x, "px"));
  41210. selectionBox.css("height", "".concat(box2D.max.y - box2D.min.y, "px"));
  41211. var camera = e.viewer.scene.getActiveCamera();
  41212. var size = e.viewer.renderer.getSize(new Vector2());
  41213. var frustumSize = new Vector2(camera.right - camera.left, camera.top - camera.bottom);
  41214. var screenCentroid = new Vector2().addVectors(e.drag.end, e.drag.start).multiplyScalar(0.5);
  41215. var ray = Utils.mouseToRay(screenCentroid, camera, size.width, size.height);
  41216. var diff = new Vector2().subVectors(e.drag.end, e.drag.start);
  41217. diff.divide(size).multiply(frustumSize);
  41218. volume.position.copy(ray.origin);
  41219. volume.up.copy(camera.up);
  41220. volume.rotation.copy(camera.rotation);
  41221. volume.scale.set(diff.x, diff.y, 1000 * 100);
  41222. e.consume();
  41223. };
  41224. var drop = e => {
  41225. this.importance = 0;
  41226. $(selectionBox).remove();
  41227. this.viewer.inputHandler.deselectAll();
  41228. this.viewer.inputHandler.toggleSelection(volume);
  41229. var camera = e.viewer.scene.getActiveCamera();
  41230. var size = e.viewer.renderer.getSize(new Vector2());
  41231. var screenCentroid = new Vector2().addVectors(e.drag.end, e.drag.start).multiplyScalar(0.5);
  41232. var ray = Utils.mouseToRay(screenCentroid, camera, size.width, size.height);
  41233. var line = new Line3(ray.origin, new Vector3().addVectors(ray.origin, ray.direction));
  41234. this.removeEventListener("drag", drag);
  41235. this.removeEventListener("drop", drop);
  41236. var allPointsNear = [];
  41237. var allPointsFar = [];
  41238. // TODO support more than one point cloud
  41239. for (var pointcloud of this.viewer.scene.pointclouds) {
  41240. if (!pointcloud.visible) {
  41241. continue;
  41242. }
  41243. var volCam = camera.clone();
  41244. volCam.left = -volume.scale.x / 2;
  41245. volCam.right = +volume.scale.x / 2;
  41246. volCam.top = +volume.scale.y / 2;
  41247. volCam.bottom = -volume.scale.y / 2;
  41248. volCam.near = -volume.scale.z / 2;
  41249. volCam.far = +volume.scale.z / 2;
  41250. volCam.rotation.copy(volume.rotation);
  41251. volCam.position.copy(volume.position);
  41252. volCam.updateMatrix();
  41253. volCam.updateMatrixWorld();
  41254. volCam.updateProjectionMatrix();
  41255. volCam.matrixWorldInverse.copy(volCam.matrixWorld).invert();
  41256. var _ray = new Ray(volCam.getWorldPosition(new Vector3()), volCam.getWorldDirection(new Vector3()));
  41257. var rayInverse = new Ray(_ray.origin.clone().add(_ray.direction.clone().multiplyScalar(volume.scale.z)), _ray.direction.clone().multiplyScalar(-1));
  41258. var pickerSettings = {
  41259. width: 8,
  41260. height: 8,
  41261. pickWindowSize: 8,
  41262. all: true,
  41263. pickClipped: true,
  41264. pointSizeType: PointSizeType.FIXED,
  41265. pointSize: 1
  41266. };
  41267. var pointsNear = pointcloud.pick(viewer, volCam, _ray, pickerSettings);
  41268. volCam.rotateX(Math.PI);
  41269. volCam.updateMatrix();
  41270. volCam.updateMatrixWorld();
  41271. volCam.updateProjectionMatrix();
  41272. volCam.matrixWorldInverse.copy(volCam.matrixWorld).invert();
  41273. var pointsFar = pointcloud.pick(viewer, volCam, rayInverse, pickerSettings);
  41274. allPointsNear.push(...pointsNear);
  41275. allPointsFar.push(...pointsFar);
  41276. }
  41277. if (allPointsNear.length > 0 && allPointsFar.length > 0) {
  41278. var viewLine = new Line3(ray.origin, new Vector3().addVectors(ray.origin, ray.direction));
  41279. var closestOnLine = allPointsNear.map(p => viewLine.closestPointToPoint(p.position, false, new Vector3()));
  41280. var closest = closestOnLine.sort((a, b) => ray.origin.distanceTo(a) - ray.origin.distanceTo(b))[0];
  41281. var farthestOnLine = allPointsFar.map(p => viewLine.closestPointToPoint(p.position, false, new Vector3()));
  41282. var farthest = farthestOnLine.sort((a, b) => ray.origin.distanceTo(b) - ray.origin.distanceTo(a))[0];
  41283. var distance = closest.distanceTo(farthest);
  41284. var centroid = new Vector3().addVectors(closest, farthest).multiplyScalar(0.5);
  41285. volume.scale.z = distance * 1.1;
  41286. volume.position.copy(centroid);
  41287. }
  41288. volume.clip = true;
  41289. };
  41290. this.addEventListener("drag", drag);
  41291. this.addEventListener("drop", drop);
  41292. viewer.inputHandler.addInputListener(this);
  41293. return volume;
  41294. }
  41295. update(e) {
  41296. //console.log(e.delta)
  41297. }
  41298. render() {
  41299. this.viewer.renderer.render(this.scene, this.viewer.scene.getActiveCamera());
  41300. }
  41301. }
  41302. class SpotLightHelper$1 extends Object3D {
  41303. constructor(light, color) {
  41304. super();
  41305. this.light = light;
  41306. this.color = color;
  41307. //this.up.set(0, 0, 1);
  41308. this.updateMatrix();
  41309. this.updateMatrixWorld();
  41310. {
  41311. // SPHERE
  41312. var sg = new SphereGeometry(1, 32, 32);
  41313. var sm = new MeshNormalMaterial();
  41314. this.sphere = new Mesh(sg, sm);
  41315. this.sphere.scale.set(0.5, 0.5, 0.5);
  41316. this.add(this.sphere);
  41317. }
  41318. {
  41319. // LINES
  41320. var positions = new Float32Array([+0, +0, +0, +0, +0, -1, +0, +0, +0, -1, -1, -1, +0, +0, +0, +1, -1, -1, +0, +0, +0, +1, +1, -1, +0, +0, +0, -1, +1, -1, -1, -1, -1, +1, -1, -1, +1, -1, -1, +1, +1, -1, +1, +1, -1, -1, +1, -1, -1, +1, -1, -1, -1, -1]);
  41321. var geometry = new BufferGeometry();
  41322. geometry.setAttribute("position", new BufferAttribute(positions, 3));
  41323. var material = new LineBasicMaterial();
  41324. this.frustum = new LineSegments(geometry, material);
  41325. this.add(this.frustum);
  41326. }
  41327. this.update();
  41328. }
  41329. update() {
  41330. this.light.updateMatrix();
  41331. this.light.updateMatrixWorld();
  41332. var position = this.light.position;
  41333. var target = new Vector3().addVectors(this.light.position, this.light.getWorldDirection(new Vector3()).multiplyScalar(-1));
  41334. var quat = new Quaternion().setFromRotationMatrix(new Matrix4().lookAt(position, target, new Vector3(0, 0, 1)));
  41335. this.setRotationFromQuaternion(quat);
  41336. this.position.copy(position);
  41337. var coneLength = this.light.distance > 0 ? this.light.distance : 1000;
  41338. var coneWidth = coneLength * Math.tan(this.light.angle * 0.5);
  41339. this.frustum.scale.set(coneWidth, coneWidth, coneLength);
  41340. }
  41341. }
  41342. //问题:如何转换到世界坐标?(缩放方向有bug。)
  41343. //add-------------------------------------
  41344. var OpaWhenNotSelect = 0.6;
  41345. var ScaleRatio = 3;
  41346. var OutlineColor = 0x666666;
  41347. //----------------------------------------
  41348. var hideFocusHandles = true; //add
  41349. class TransformationTool extends EventDispatcher {
  41350. constructor(viewer) {
  41351. super();
  41352. this.viewer = viewer;
  41353. this.modesEnabled = {}; //add
  41354. this.style = 'singleMode'; //建mesh时按照singleModes建的
  41355. this.scene = new Scene();
  41356. this.selection = [];
  41357. this.pivot = new Vector3();
  41358. this.dragging = false;
  41359. this.showPickVolumes = false;
  41360. this.viewer.inputHandler.registerInteractiveScene(this.scene);
  41361. this.viewer.inputHandler.addEventListener('selection_changed', e => {
  41362. /* for(let selected of this.selection){ //若不删除,应该会穿过选中的物体选到别的而不是取消选择
  41363. this.viewer.inputHandler.blacklist.delete(selected);
  41364. } */
  41365. this.selection = e.selection;
  41366. /* for(let selected of this.selection){
  41367. this.viewer.inputHandler.blacklist.add(selected);
  41368. } */
  41369. });
  41370. this.viewer.addEventListener('global_touchstart', e => {
  41371. //add
  41372. this.update();
  41373. });
  41374. this.viewer.addEventListener('global_mousemove', e => {
  41375. //add
  41376. this.onPointerMove();
  41377. });
  41378. var red = Potree.config.axis.x.color;
  41379. var green = Potree.config.axis.y.color;
  41380. var blue = Potree.config.axis.z.color;
  41381. var white = Potree.config.axis.xyz.color;
  41382. this.activeHandle = null;
  41383. this.scaleHandles = {
  41384. "scale.x+": {
  41385. name: "scale.x+",
  41386. node: new Object3D(),
  41387. color: red,
  41388. alignment: [+1, +0, +0]
  41389. },
  41390. "scale.x-": {
  41391. name: "scale.x-",
  41392. node: new Object3D(),
  41393. color: red,
  41394. alignment: [-1, +0, +0]
  41395. },
  41396. "scale.y+": {
  41397. name: "scale.y+",
  41398. node: new Object3D(),
  41399. color: green,
  41400. alignment: [+0, +1, +0]
  41401. },
  41402. "scale.y-": {
  41403. name: "scale.y-",
  41404. node: new Object3D(),
  41405. color: green,
  41406. alignment: [+0, -1, +0]
  41407. },
  41408. "scale.z+": {
  41409. name: "scale.z+",
  41410. node: new Object3D(),
  41411. color: blue,
  41412. alignment: [+0, +0, +1]
  41413. },
  41414. "scale.z-": {
  41415. name: "scale.z-",
  41416. node: new Object3D(),
  41417. color: blue,
  41418. alignment: [+0, +0, -1]
  41419. },
  41420. "lines": {
  41421. name: 'lines',
  41422. node: new Object3D(),
  41423. dontScale: true
  41424. } //add
  41425. };
  41426. this.focusHandles = {
  41427. "focus.x+": {
  41428. name: "focus.x+",
  41429. node: new Object3D(),
  41430. color: red,
  41431. alignment: [+1, +0, +0]
  41432. },
  41433. "focus.x-": {
  41434. name: "focus.x-",
  41435. node: new Object3D(),
  41436. color: red,
  41437. alignment: [-1, +0, +0]
  41438. },
  41439. "focus.y+": {
  41440. name: "focus.y+",
  41441. node: new Object3D(),
  41442. color: green,
  41443. alignment: [+0, +1, +0]
  41444. },
  41445. "focus.y-": {
  41446. name: "focus.y-",
  41447. node: new Object3D(),
  41448. color: green,
  41449. alignment: [+0, -1, +0]
  41450. },
  41451. "focus.z+": {
  41452. name: "focus.z+",
  41453. node: new Object3D(),
  41454. color: blue,
  41455. alignment: [+0, +0, +1]
  41456. },
  41457. "focus.z-": {
  41458. name: "focus.z-",
  41459. node: new Object3D(),
  41460. color: blue,
  41461. alignment: [+0, +0, -1]
  41462. }
  41463. };
  41464. this.translationHandles = {
  41465. "translation.x": {
  41466. name: "translation.x",
  41467. node: new Object3D(),
  41468. color: red,
  41469. alignment: [1, 0, 0]
  41470. },
  41471. "translation.y": {
  41472. name: "translation.y",
  41473. node: new Object3D(),
  41474. color: green,
  41475. alignment: [0, 1, 0]
  41476. },
  41477. "translation.z": {
  41478. name: "translation.z",
  41479. node: new Object3D(),
  41480. color: blue,
  41481. alignment: [0, 0, 1]
  41482. },
  41483. //add
  41484. 'translation.xyz': {
  41485. name: "translation.xyz",
  41486. node: new Object3D(),
  41487. color: white,
  41488. alignment: [0, 0, 0],
  41489. alignment2: [1, 1, 1]
  41490. },
  41491. 'translation.plane.xy': {
  41492. name: "translation.plane.xy",
  41493. node: new Object3D(),
  41494. color: blue,
  41495. alignment: [0, 0, 1],
  41496. alignment2: [1, 1, 0]
  41497. },
  41498. 'translation.plane.yz': {
  41499. name: "translation.plane.yz",
  41500. node: new Object3D(),
  41501. color: red,
  41502. alignment: [1, 0, 0],
  41503. alignment2: [0, 1, 1]
  41504. },
  41505. 'translation.plane.xz': {
  41506. name: "translation.plane.xz",
  41507. node: new Object3D(),
  41508. color: green,
  41509. alignment: [0, 1, 0],
  41510. alignment2: [1, 0, 1]
  41511. }
  41512. };
  41513. this.rotationHandles = {
  41514. "rotation.x": {
  41515. name: "rotation.x",
  41516. node: new Object3D(),
  41517. color: red,
  41518. alignment: [1, 0, 0]
  41519. },
  41520. "rotation.y": {
  41521. name: "rotation.y",
  41522. node: new Object3D(),
  41523. color: green,
  41524. alignment: [0, 1, 0]
  41525. },
  41526. "rotation.z": {
  41527. name: "rotation.z",
  41528. node: new Object3D(),
  41529. color: blue,
  41530. alignment: [0, 0, 1]
  41531. }
  41532. };
  41533. this.handles = Object.assign({}, this.scaleHandles, hideFocusHandles ? {} : this.focusHandles, this.translationHandles, this.rotationHandles);
  41534. this.pickVolumes = [];
  41535. this.initializeScaleHandles();
  41536. this.initializeFocusHandles();
  41537. this.initializeTranslationHandles();
  41538. this.initializeRotationHandles();
  41539. var boxFrameGeometry = new Geometry();
  41540. {
  41541. // bottom
  41542. boxFrameGeometry.vertices.push(new Vector3(-0.5, -0.5, 0.5));
  41543. boxFrameGeometry.vertices.push(new Vector3(0.5, -0.5, 0.5));
  41544. boxFrameGeometry.vertices.push(new Vector3(0.5, -0.5, 0.5));
  41545. boxFrameGeometry.vertices.push(new Vector3(0.5, -0.5, -0.5));
  41546. boxFrameGeometry.vertices.push(new Vector3(0.5, -0.5, -0.5));
  41547. boxFrameGeometry.vertices.push(new Vector3(-0.5, -0.5, -0.5));
  41548. boxFrameGeometry.vertices.push(new Vector3(-0.5, -0.5, -0.5));
  41549. boxFrameGeometry.vertices.push(new Vector3(-0.5, -0.5, 0.5));
  41550. // top
  41551. boxFrameGeometry.vertices.push(new Vector3(-0.5, 0.5, 0.5));
  41552. boxFrameGeometry.vertices.push(new Vector3(0.5, 0.5, 0.5));
  41553. boxFrameGeometry.vertices.push(new Vector3(0.5, 0.5, 0.5));
  41554. boxFrameGeometry.vertices.push(new Vector3(0.5, 0.5, -0.5));
  41555. boxFrameGeometry.vertices.push(new Vector3(0.5, 0.5, -0.5));
  41556. boxFrameGeometry.vertices.push(new Vector3(-0.5, 0.5, -0.5));
  41557. boxFrameGeometry.vertices.push(new Vector3(-0.5, 0.5, -0.5));
  41558. boxFrameGeometry.vertices.push(new Vector3(-0.5, 0.5, 0.5));
  41559. // sides
  41560. boxFrameGeometry.vertices.push(new Vector3(-0.5, -0.5, 0.5));
  41561. boxFrameGeometry.vertices.push(new Vector3(-0.5, 0.5, 0.5));
  41562. boxFrameGeometry.vertices.push(new Vector3(0.5, -0.5, 0.5));
  41563. boxFrameGeometry.vertices.push(new Vector3(0.5, 0.5, 0.5));
  41564. boxFrameGeometry.vertices.push(new Vector3(0.5, -0.5, -0.5));
  41565. boxFrameGeometry.vertices.push(new Vector3(0.5, 0.5, -0.5));
  41566. boxFrameGeometry.vertices.push(new Vector3(-0.5, -0.5, -0.5));
  41567. boxFrameGeometry.vertices.push(new Vector3(-0.5, 0.5, -0.5));
  41568. }
  41569. this.frame = new LineSegments(boxFrameGeometry, new LineBasicMaterial({
  41570. color: 0xffff00
  41571. }));
  41572. this.scene.add(this.frame);
  41573. //------------------add-----------------------
  41574. this.setModeEnable(['scale', 'translation', 'rotation']);
  41575. Potree.Utils.setObjectLayers(this.scene, 'transformationTool');
  41576. this.scene.traverse(e => {
  41577. e.pickDontCheckDis = true; //pick时不需要识别是否在点云之上
  41578. });
  41579. {
  41580. var exist = object => {
  41581. //是否没被删除(暂时不考虑换了parent)
  41582. while (object.parent) {
  41583. object = object.parent;
  41584. }
  41585. if (object instanceof Scene) {
  41586. return true;
  41587. }
  41588. };
  41589. this.history = new History({
  41590. //也可以写到全局,但需要加个判断物品是否存在的函数
  41591. applyData: data => {
  41592. if (exist(data.object)) {
  41593. //viewer.scene.volumes.includes(data.box) //或许还要识别是否matrixAuto
  41594. data.matrix.decompose(data.object.position, data.object.quaternion, data.object.scale);
  41595. this.dispatchEvent('changeByHistory');
  41596. viewer.dispatchEvent('content_changed');
  41597. return true;
  41598. }
  41599. },
  41600. getData: data => {
  41601. return data;
  41602. }
  41603. });
  41604. this.addEventListener('transformed', e => {
  41605. var object = viewer.transformationTool.selection[0];
  41606. this.history.beforeChange({
  41607. object,
  41608. matrix: e.matrixBefore.clone()
  41609. });
  41610. this.viewer.dispatchEvent('content_changed');
  41611. });
  41612. this.addEventListener('stopDrag', e => {
  41613. var object = viewer.transformationTool.selection[0];
  41614. object && this.history.afterChange({
  41615. object,
  41616. matrix: object.matrix.clone()
  41617. });
  41618. });
  41619. /* viewer.inputHandler.addEventListener('keydown', (e)=>{
  41620. if(e.keyCode == 90 && e.event.ctrlKey){//Z
  41621. this.history.undo()
  41622. }else if(e.keyCode == 89 && e.event.ctrlKey){//Y
  41623. this.history.redo()
  41624. }
  41625. }) */
  41626. }
  41627. }
  41628. setModeEnable() {
  41629. var enableModes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  41630. //xzw add
  41631. var length = 0;
  41632. ['translation', 'scale', 'rotation'].forEach(mode => {
  41633. var handels = this[mode + 'Handles'];
  41634. var enable = enableModes.includes(mode);
  41635. for (var o in handels) {
  41636. Potree.Utils.updateVisible(handels[o].node, 'modeForce', !!enable);
  41637. }
  41638. this.modesEnabled[mode] = !!enable;
  41639. enable && length++;
  41640. });
  41641. if (this.style == 'singleMode' && length > 1) {
  41642. this.changeStyle('mixedModes');
  41643. } else if (this.style == 'mixedModes' && length == 1) {
  41644. this.changeStyle('singleMode');
  41645. }
  41646. }
  41647. changeStyle(style) {
  41648. // 切换单个mode & 多个mode混合 风格(因多个混合比较拥挤,需要做调整)
  41649. var s1 = style == 'singleMode' ? 30 : 25;
  41650. var s2 = style == 'singleMode' ? 15 : 10;
  41651. ['x', 'y', 'z'].forEach(axis => {
  41652. this.translationHandles['translation.' + axis].node.children.forEach(mesh => {
  41653. if (mesh.name.includes('arrow')) {
  41654. Potree.Utils.updateVisible(mesh, 'modeStyle', style == 'singleMode');
  41655. } else if (mesh.name.includes('handle')) {
  41656. mesh.material.lineWidth = style == 'singleMode' ? 5 : 7;
  41657. }
  41658. });
  41659. this.rotationHandles['rotation.' + axis].translateNode.scale.set(s1, s1, s1);
  41660. });
  41661. ['xy', 'yz', 'xz'].forEach(axis => {
  41662. var handle = this.translationHandles['translation.plane.' + axis];
  41663. handle.node.children[0].scale.set(s2, s2, s2);
  41664. handle.node.children[0].position.fromArray(handle.alignment2).multiplyScalar(s2 * 1.5);
  41665. });
  41666. Potree.Utils.updateVisible(this.scaleHandles['lines'].node, 'modeStyle', style == 'singleMode');
  41667. this.style = style;
  41668. }
  41669. initializeTranslationHandles() {
  41670. var _this = this;
  41671. //大改
  41672. var boxGeometry = new BoxGeometry(1, 1, 1);
  41673. var length = 100,
  41674. arrowRadius = 4,
  41675. arrowHeight = 10;
  41676. var arrowGeometry = new CylinderBufferGeometry(0, arrowRadius, arrowHeight, 12, 1, false); //add 箭头朝(0,1,0)
  41677. var arrowInitialQua = new Quaternion().setFromAxisAngle(new Vector3(1, 0, 0), -Math.PI / 2); //先将qua旋转到朝向0,0,-1, 因为一般quaternion不设置时默认表示朝向0,0,-1,
  41678. var octahedronGeometry = new OctahedronBufferGeometry(5, 0);
  41679. var planeGeometry = new PlaneBufferGeometry(1, 1);
  41680. var _loop = function _loop(handleName) {
  41681. var handle = _this.handles[handleName];
  41682. var node = handle.node;
  41683. _this.scene.add(node);
  41684. node.name = handleName; //add
  41685. var alignment = new Vector3(...handle.alignment);
  41686. var geometry,
  41687. mesh,
  41688. pickVolume,
  41689. meshScale,
  41690. pickScale,
  41691. rotation,
  41692. position,
  41693. lookAtPoint,
  41694. hasPick = true,
  41695. meshPickable = false,
  41696. renderOrder;
  41697. var matProp = {
  41698. color: handle.color,
  41699. opacity: OpaWhenNotSelect,
  41700. transparent: true,
  41701. side: handleName.includes('plane') ? DoubleSide : FrontSide
  41702. };
  41703. var material = new MeshBasicMaterial(matProp);
  41704. var pickMaterial = new MeshNormalMaterial({
  41705. opacity: 0.2,
  41706. transparent: true,
  41707. visible: _this.showPickVolumes
  41708. });
  41709. if (handleName.includes('xyz')) {
  41710. geometry = octahedronGeometry;
  41711. meshPickable = true;
  41712. renderOrder = 12;
  41713. } else if (handleName.includes('plane')) {
  41714. geometry = planeGeometry;
  41715. meshPickable = true;
  41716. position = new Vector3(...handle.alignment2);
  41717. lookAtPoint = alignment;
  41718. if (handleName.includes('xy')) {} else if (handleName.includes('yz')) {} else if (handleName.includes('xz')) {}
  41719. } else {
  41720. geometry = boxGeometry;
  41721. var point = new Vector3(0, 0, length / 2); //new THREE.Vector3().copy(alignment).multiplyScalar(length/2)
  41722. mesh = LineDraw.createFatLine([point, point.clone().negate()], {
  41723. lineWidth: 6,
  41724. mat: new LineDraw.createFatLineMat(matProp)
  41725. });
  41726. lookAtPoint = alignment;
  41727. renderOrder = 10;
  41728. pickScale = new Vector3(4, 4, length + arrowHeight * 2); //pickScale = new THREE.Vector3(4, 4, 1.2)
  41729. {
  41730. var arrow = new Mesh(arrowGeometry, material);
  41731. arrow.name = "".concat(handleName, ".arrow");
  41732. arrow.renderOrder = 11;
  41733. arrow.position.set(...handle.alignment).multiplyScalar(length / 2 + arrowHeight / 2);
  41734. arrow.lookAt(0, 0, 0);
  41735. node.add(arrow);
  41736. var arrow2 = arrow.clone();
  41737. arrow2.position.negate();
  41738. arrow2.lookAt(0, 0, 0);
  41739. node.add(arrow2);
  41740. arrow.quaternion.multiply(arrowInitialQua); //乘上初始旋转
  41741. arrow2.quaternion.multiply(arrowInitialQua);
  41742. }
  41743. }
  41744. mesh || (mesh = new Mesh(geometry, material));
  41745. mesh.name = "".concat(handleName, ".handle");
  41746. node.add(mesh);
  41747. renderOrder && (mesh.renderOrder = renderOrder);
  41748. meshScale && mesh.scale.copy(meshScale);
  41749. rotation && mesh.rotation.copy(rotation);
  41750. lookAtPoint && mesh.lookAt(lookAtPoint);
  41751. position && mesh.position.copy(position);
  41752. if (!meshPickable && hasPick) {
  41753. pickVolume = new Mesh(geometry, pickMaterial);
  41754. pickScale && pickVolume.scale.copy(pickScale);
  41755. } else if (hasPick && meshPickable) {
  41756. pickVolume = mesh;
  41757. }
  41758. if (pickVolume) {
  41759. if (mesh != pickVolume) {
  41760. mesh.add(pickVolume);
  41761. pickVolume.name = "".concat(handleName, ".pick_volume");
  41762. } else {
  41763. pickVolume.name += ' & pick_volume';
  41764. }
  41765. pickVolume.handle = handleName;
  41766. _this.pickVolumes.push(pickVolume);
  41767. }
  41768. node.setOpacity = target => {
  41769. if (handleName.includes('plane')) {
  41770. var more = 1.5; //减掉更多,使min更低,max还是1
  41771. target = 1 - (1 - target) * more;
  41772. }
  41773. var opacity = {
  41774. x: material.opacity
  41775. };
  41776. var t = new TWEEN.Tween(opacity).to({
  41777. x: target
  41778. }, 0);
  41779. t.onUpdate(() => {
  41780. mesh.visible = opacity.x > 0;
  41781. pickVolume && (pickVolume.visible = opacity.x > 0);
  41782. material.opacity = opacity.x;
  41783. mesh.material.opacity = opacity.x;
  41784. //outlineMaterial.opacity = opacity.x;
  41785. pickMaterial.opacity = opacity.x * 0.5;
  41786. });
  41787. t.start();
  41788. };
  41789. pickVolume.addEventListener("drag", e => {
  41790. _this.dragTranslationHandle(e);
  41791. });
  41792. pickVolume.addEventListener("drop", e => {
  41793. _this.dropTranslationHandle(e);
  41794. });
  41795. };
  41796. for (var handleName of Object.keys(this.translationHandles)) {
  41797. _loop(handleName);
  41798. }
  41799. }
  41800. initializeScaleHandles() {
  41801. var _this2 = this;
  41802. var sgSphere = new SphereGeometry(1, 32, 32);
  41803. var sgLowPolySphere = new SphereGeometry(1, 16, 16);
  41804. var _loop2 = function _loop2() {
  41805. var handle = _this2.scaleHandles[handleName];
  41806. var node = handle.node;
  41807. node.name = handleName; //add
  41808. _this2.scene.add(node);
  41809. if (handleName == 'lines') {
  41810. //add
  41811. ['x', 'y', 'z'].forEach(axis => {
  41812. var handle1_ = _this2.scaleHandles['scale.' + axis + '+'];
  41813. var handle2_ = _this2.scaleHandles['scale.' + axis + '-'];
  41814. var line = LineDraw.createFatLine([new Vector3().fromArray(handle1_.alignment).multiplyScalar(0.5), new Vector3().fromArray(handle2_.alignment).multiplyScalar(0.5)], {
  41815. color: handle1_.color,
  41816. lineWidth: 4
  41817. } // , dontAlwaysSeen:true
  41818. );
  41819. node.add(line);
  41820. });
  41821. node.setOpacity = opacity => {
  41822. opacity *= 0.6;
  41823. node.children.forEach(e => e.material.opacity = opacity);
  41824. };
  41825. return 1; // continue
  41826. }
  41827. node.position.set(...handle.alignment).multiplyScalar(0.5);
  41828. var material = new MeshBasicMaterial({
  41829. color: handle.color,
  41830. side: DoubleSide,
  41831. //xzw add
  41832. opacity: OpaWhenNotSelect,
  41833. transparent: true
  41834. });
  41835. var outlineMaterial = new MeshBasicMaterial({
  41836. color: OutlineColor,
  41837. side: BackSide,
  41838. opacity: OpaWhenNotSelect,
  41839. transparent: true
  41840. });
  41841. var pickMaterial = new MeshNormalMaterial({
  41842. opacity: 0.2,
  41843. transparent: true,
  41844. side: DoubleSide,
  41845. //xzw add for orthoCam, 缩小画面时因球体放大导致到相机背面去了而看不到球体正面
  41846. visible: _this2.showPickVolumes
  41847. });
  41848. var sphere = new Mesh(sgSphere, material);
  41849. sphere.scale.set(5, 5, 5);
  41850. sphere.name = "".concat(handleName, ".handle");
  41851. node.add(sphere);
  41852. sphere.renderOrder = 10;
  41853. /* let outline = new THREE.Mesh(sgSphere, outlineMaterial);
  41854. outline.scale.set(1.1, 1.1, 1.1);
  41855. outline.name = `${handleName}.outline`;
  41856. sphere.add(outline); */
  41857. var pickSphere = new Mesh(sgLowPolySphere, pickMaterial);
  41858. pickSphere.name = "".concat(handleName, ".pick_volume");
  41859. pickSphere.scale.set(1.5, 1.5, 1.5);
  41860. sphere.add(pickSphere);
  41861. pickSphere.handle = handleName;
  41862. _this2.pickVolumes.push(pickSphere);
  41863. node.setOpacity = target => {
  41864. var opacity = {
  41865. x: material.opacity
  41866. };
  41867. var t = new TWEEN.Tween(opacity).to({
  41868. x: target
  41869. }, 0); //xzw改 原100毫秒,因为太慢容易选错
  41870. t.onUpdate(() => {
  41871. sphere.visible = opacity.x > 0;
  41872. pickSphere.visible = opacity.x > 0;
  41873. material.opacity = opacity.x;
  41874. outlineMaterial.opacity = opacity.x;
  41875. pickSphere.material.opacity = opacity.x * 0.5;
  41876. });
  41877. t.start();
  41878. };
  41879. pickSphere.addEventListener("drag", e => _this2.dragScaleHandle(e));
  41880. pickSphere.addEventListener("drop", e => _this2.dropScaleHandle(e));
  41881. pickSphere.addEventListener("mouseover", e => {
  41882. //node.setOpacity(1);
  41883. });
  41884. pickSphere.addEventListener("click", e => {
  41885. //e.consume();
  41886. });
  41887. pickSphere.addEventListener("mouseleave", e => {
  41888. //node.setOpacity(OpaWhenNotSelect);
  41889. });
  41890. };
  41891. for (var handleName of Object.keys(this.scaleHandles)) {
  41892. if (_loop2()) continue;
  41893. }
  41894. }
  41895. initializeRotationHandles() {
  41896. var _this3 = this;
  41897. var boldAdjust = 2.3;
  41898. var torusGeometry = new TorusGeometry(1.3, boldAdjust * 0.015, 8, 64, Math.PI / 2);
  41899. //let outlineGeometry = new THREE.TorusGeometry(1, boldAdjust * 0.018, 8, 64, Math.PI / 2);
  41900. var pickGeometry = new TorusGeometry(1.3, boldAdjust * 0.06, 6, 4, Math.PI / 2);
  41901. var _loop3 = function _loop3() {
  41902. var handle = _this3.handles[handleName];
  41903. var node = handle.node;
  41904. _this3.scene.add(node);
  41905. node.name = handleName; //add
  41906. var material = new MeshBasicMaterial({
  41907. color: handle.color,
  41908. opacity: OpaWhenNotSelect,
  41909. transparent: true
  41910. });
  41911. /* let outlineMaterial = new THREE.MeshBasicMaterial({
  41912. color: OutlineColor,
  41913. side: THREE.BackSide,
  41914. opacity: OpaWhenNotSelect,
  41915. transparent: true
  41916. }); */
  41917. var pickMaterial = new MeshNormalMaterial({
  41918. opacity: 0.2,
  41919. transparent: true,
  41920. visible: _this3.showPickVolumes
  41921. });
  41922. var box = new Mesh(torusGeometry, material);
  41923. box.name = "".concat(handleName, ".handle");
  41924. box.scale.set(30, 30, 30);
  41925. box.lookAt(new Vector3(...handle.alignment));
  41926. node.add(box);
  41927. handle.translateNode = box;
  41928. /* let outline = new THREE.Mesh(outlineGeometry, outlineMaterial);
  41929. outline.name = `${handleName}.outline`;
  41930. outline.scale.set(1, 1, 1);
  41931. outline.renderOrder = 0;
  41932. box.add(outline);
  41933. */
  41934. var pickVolume = new Mesh(pickGeometry, pickMaterial);
  41935. pickVolume.name = "".concat(handleName, ".pick_volume");
  41936. pickVolume.scale.set(1, 1, 1);
  41937. pickVolume.handle = handleName;
  41938. box.add(pickVolume);
  41939. _this3.pickVolumes.push(pickVolume);
  41940. node.setOpacity = target => {
  41941. var opacity = {
  41942. x: material.opacity
  41943. };
  41944. var t = new TWEEN.Tween(opacity).to({
  41945. x: target
  41946. }, 0);
  41947. t.onUpdate(() => {
  41948. box.visible = opacity.x > 0;
  41949. pickVolume.visible = opacity.x > 0;
  41950. material.opacity = opacity.x;
  41951. //outlineMaterial.opacity = opacity.x;
  41952. pickMaterial.opacity = opacity.x * 0.5;
  41953. });
  41954. t.start();
  41955. };
  41956. //pickVolume.addEventListener("mouseover", (e) => {
  41957. // //let a = this.viewer.scene.getActiveCamera().getWorldDirection(new THREE.Vector3()).dot(pickVolume.getWorldDirection(new THREE.Vector3()));
  41958. // console.log(pickVolume.getWorldDirection(new THREE.Vector3()));
  41959. //});
  41960. pickVolume.addEventListener("drag", e => {
  41961. _this3.dragRotationHandle(e);
  41962. });
  41963. pickVolume.addEventListener("drop", e => {
  41964. _this3.dropRotationHandle(e);
  41965. });
  41966. };
  41967. for (var handleName of Object.keys(this.rotationHandles)) {
  41968. _loop3();
  41969. }
  41970. }
  41971. initializeFocusHandles() {
  41972. var _this4 = this;
  41973. if (hideFocusHandles) return; //add
  41974. //let sgBox = new THREE.BoxGeometry(1, 1, 1);
  41975. var sgPlane = new PlaneGeometry(4, 4, 1, 1);
  41976. var sgLowPolySphere = new SphereGeometry(1, 16, 16);
  41977. var texture = new TextureLoader().load("".concat(exports.resourcePath, "/icons/eye_2.png"));
  41978. var _loop4 = function _loop4() {
  41979. var handle = _this4.focusHandles[handleName];
  41980. var node = handle.node;
  41981. _this4.scene.add(node);
  41982. var align = handle.alignment;
  41983. node.name = handleName; //add
  41984. //node.lookAt(new THREE.Vector3().addVectors(node.position, new THREE.Vector3(...align)));
  41985. node.lookAt(new Vector3(...align));
  41986. var off = 0.8;
  41987. if (align[0] === 1) {
  41988. node.position.set(1, off, -off).multiplyScalar(0.5);
  41989. node.rotation.z = Math.PI / 2;
  41990. } else if (align[0] === -1) {
  41991. node.position.set(-1, -off, -off).multiplyScalar(0.5);
  41992. node.rotation.z = Math.PI / 2;
  41993. } else if (align[1] === 1) {
  41994. node.position.set(-off, 1, -off).multiplyScalar(0.5);
  41995. node.rotation.set(Math.PI / 2, Math.PI, 0.0);
  41996. } else if (align[1] === -1) {
  41997. node.position.set(off, -1, -off).multiplyScalar(0.5);
  41998. node.rotation.set(Math.PI / 2, 0.0, 0.0);
  41999. } else if (align[2] === 1) {
  42000. node.position.set(off, off, 1).multiplyScalar(0.5);
  42001. } else if (align[2] === -1) {
  42002. node.position.set(-off, off, -1).multiplyScalar(0.5);
  42003. }
  42004. var material = new MeshBasicMaterial({
  42005. color: handle.color,
  42006. opacity: 0,
  42007. transparent: true,
  42008. map: texture
  42009. });
  42010. //let outlineMaterial = new THREE.MeshBasicMaterial({
  42011. // color: 0x000000,
  42012. // side: THREE.BackSide,
  42013. // opacity: 0,
  42014. // transparent: true});
  42015. var pickMaterial = new MeshNormalMaterial({
  42016. //opacity: 0,
  42017. transparent: true,
  42018. visible: _this4.showPickVolumes
  42019. });
  42020. var box = new Mesh(sgPlane, material);
  42021. box.name = "".concat(handleName, ".handle");
  42022. box.scale.set(1.5, 1.5, 1.5);
  42023. box.position.set(0, 0, 0);
  42024. box.visible = false;
  42025. node.add(box);
  42026. //handle.focusNode = box;
  42027. //let outline = new THREE.Mesh(sgPlane, outlineMaterial);
  42028. //outline.scale.set(1.4, 1.4, 1.4);
  42029. //outline.name = `${handleName}.outline`;
  42030. //box.add(outline);
  42031. var pickSphere = new Mesh(sgLowPolySphere, pickMaterial);
  42032. pickSphere.name = "".concat(handleName, ".pick_volume");
  42033. pickSphere.scale.set(2, 2, 2);
  42034. box.add(pickSphere);
  42035. pickSphere.handle = handleName;
  42036. _this4.pickVolumes.push(pickSphere);
  42037. node.setOpacity = target => {
  42038. var opacity = {
  42039. x: material.opacity
  42040. };
  42041. var t = new TWEEN.Tween(opacity).to({
  42042. x: target
  42043. }, 0);
  42044. t.onUpdate(() => {
  42045. pickSphere.visible = opacity.x > 0;
  42046. box.visible = opacity.x > 0;
  42047. material.opacity = opacity.x;
  42048. //outlineMaterial.opacity = opacity.x;
  42049. pickSphere.material.opacity = opacity.x * 0.5;
  42050. });
  42051. t.start();
  42052. };
  42053. //pickSphere.addEventListener("drag", e => {});
  42054. pickSphere.addEventListener("mouseup", e => {
  42055. //e.consume();
  42056. });
  42057. pickSphere.addEventListener("mousedown", e => {
  42058. //e.consume();
  42059. });
  42060. pickSphere.addEventListener("click", e => {
  42061. //e.consume();
  42062. var selected = _this4.selection[0];
  42063. var maxScale = Math.max(...selected.scale.toArray());
  42064. var minScale = Math.min(...selected.scale.toArray());
  42065. var handleLength = Math.abs(selected.scale.dot(new Vector3(...handle.alignment)));
  42066. var alignment = new Vector3(...handle.alignment).multiplyScalar(2 * maxScale / handleLength);
  42067. alignment.applyMatrix4(selected.matrixWorld);
  42068. var newCamPos = alignment;
  42069. var newCamTarget = selected.getWorldPosition(new Vector3());
  42070. Utils.moveTo(_this4.viewer.scene, newCamPos, newCamTarget);
  42071. });
  42072. pickSphere.addEventListener("mouseover", e => {
  42073. //box.setOpacity(1);
  42074. });
  42075. pickSphere.addEventListener("mouseleave", e => {
  42076. //box.setOpacity(OpaWhenNotSelect);
  42077. });
  42078. };
  42079. for (var handleName of Object.keys(this.focusHandles)) {
  42080. _loop4();
  42081. }
  42082. }
  42083. dragRotationHandle(e) {
  42084. var drag = e.drag;
  42085. var handle = this.activeHandle;
  42086. var camera = this.viewer.mainViewport.camera; //this.viewer.scene.getActiveCamera();
  42087. if (!handle || !handle.name.includes('rotation')) {
  42088. return;
  42089. }
  42090. ;
  42091. var localNormal = new Vector3(...handle.alignment);
  42092. var n = new Vector3();
  42093. n.copy(new Vector4(...localNormal.toArray(), 0).applyMatrix4(handle.node.matrixWorld));
  42094. n.normalize();
  42095. if (!drag.intersectionStart) {
  42096. //this.viewer.scene.scene.remove(this.debug);
  42097. //this.debug = new THREE.Object3D();
  42098. //this.viewer.scene.scene.add(this.debug);
  42099. //Utils.debugSphere(this.debug, drag.location, 3, 0xaaaaaa);
  42100. //let debugEnd = drag.location.clone().add(n.clone().multiplyScalar(20));
  42101. //Utils.debugLine(this.debug, drag.location, debugEnd, 0xff0000);
  42102. drag.intersectionStart = drag.location;
  42103. drag.objectStart = drag.object.getWorldPosition(new Vector3());
  42104. drag.handle = handle;
  42105. var plane = new Plane().setFromNormalAndCoplanarPoint(n, drag.intersectionStart);
  42106. drag.dragPlane = plane;
  42107. drag.pivot = drag.intersectionStart;
  42108. } else {
  42109. handle = drag.handle;
  42110. }
  42111. if (!drag.dragPlane) return; //xzw add 因有时候没有
  42112. this.dragging = true;
  42113. var pointer = this.viewer.inputHandler.pointer;
  42114. var domElement = this.viewer.renderer.domElement;
  42115. var ray = Utils.mouseToRay(pointer, camera, domElement.clientWidth, domElement.clientHeight);
  42116. var I = ray.intersectPlane(drag.dragPlane, new Vector3());
  42117. if (I) {
  42118. var center = this.scene.getWorldPosition(new Vector3()); //bounding中心
  42119. var from = drag.pivot;
  42120. var to = I;
  42121. var v1 = from.clone().sub(center).normalize();
  42122. var v2 = to.clone().sub(center).normalize();
  42123. var angle = Math.acos(v1.dot(v2));
  42124. var sign = Math.sign(v1.cross(v2).dot(n));
  42125. angle = angle * sign;
  42126. if (Number.isNaN(angle)) {
  42127. return;
  42128. }
  42129. var matrixBefore = this.selection[0].matrix.clone();
  42130. var normal = new Vector3(...handle.alignment);
  42131. for (var selection of this.selection) {
  42132. //直接修改matrix,使整体绕boundingBox中心旋转。 xzw
  42133. var quaternion = selection.quaternion.clone();
  42134. var diffQua = new Quaternion().setFromAxisAngle(normal, angle); //变化量,参考 selection.rotateOnAxis(normal, angle);
  42135. var moveToZero = new Matrix4().setPosition(center.clone().negate()); //先将boundingBox中心(整体)移动到原点
  42136. var rotM = new Matrix4().makeRotationFromQuaternion(quaternion.clone().inverse().premultiply(diffQua).premultiply(quaternion)); //再旋转。根据selection.rotateOnAxis,应该是旧的qua 右乘 diffQua,所以先用invert消掉旧的qua
  42137. var moveBack = new Matrix4().setPosition(center.clone()); //移动回去,使boundingBox中心位置还原
  42138. selection.matrix.premultiply(moveToZero).premultiply(rotM).premultiply(moveBack);
  42139. selection.matrix.decompose(selection.position, selection.quaternion, selection.scale); //记录 (scale基本不变)
  42140. selection.updateMatrixWorld(); //xzw add 保险起见立即update
  42141. selection.dispatchEvent({
  42142. type: "orientation_changed",
  42143. object: selection
  42144. });
  42145. selection.dispatchEvent({
  42146. //当boundingBox中心不在原点时
  42147. type: "position_changed",
  42148. object: selection
  42149. });
  42150. }
  42151. this.dispatchEvent({
  42152. type: 'transformed',
  42153. changeType: ['orientation'],
  42154. matrixBefore
  42155. }); //add
  42156. drag.pivot = I;
  42157. }
  42158. }
  42159. dropRotationHandle(e) {
  42160. this.dragging = false;
  42161. this.setActiveHandle(null);
  42162. this.dispatchEvent({
  42163. type: 'stopDrag',
  42164. handle: 'rotation'
  42165. }); //add
  42166. }
  42167. dragTranslationHandle(e) {
  42168. //---大改,参考transformControls,为了加上xyz xy yz xz 这四个方向的变换。 (但感觉好像plane上有丢丢延迟?是因为drag延迟还是worldmatrix没更新)
  42169. var drag = e.drag;
  42170. var handle = this.activeHandle;
  42171. var camera = this.viewer.mainViewport.camera; //this.viewer.scene.getActiveCamera();
  42172. if (handle && handle.name.includes('translation') && this.selection[0]) {
  42173. var posWorld = this.scene.getWorldPosition(new Vector3()); //bounding中心
  42174. if (!drag.intersectionStart) {
  42175. drag.intersectionStart = drag.location;
  42176. drag.worldPositionStart = this.selection[0].getWorldPosition(new Vector3());
  42177. drag.objectQua = this.selection[0].quaternion.clone(); //不考虑父级
  42178. drag.objectQuaInv = drag.objectQua.clone().invert();
  42179. this.dragging = true;
  42180. }
  42181. if (drag.intersectionStart) {
  42182. var pointer = this.viewer.inputHandler.pointer;
  42183. var ray = Utils.mouseToRay(pointer, camera);
  42184. //方向滑动所在面
  42185. var normal;
  42186. var axisName = handle.name.split('.').pop();
  42187. if (axisName == 'xyz') {
  42188. // 平行于屏幕滑动
  42189. normal = viewer.mainViewport.view.direction;
  42190. } else {
  42191. var alignVector = new Vector3();
  42192. normal = new Vector3();
  42193. var unitX = new Vector3(1, 0, 0).applyQuaternion(drag.objectQua);
  42194. var unitY = new Vector3(0, 1, 0).applyQuaternion(drag.objectQua);
  42195. var unitZ = new Vector3(0, 0, 1).applyQuaternion(drag.objectQua);
  42196. switch (axisName) {
  42197. case 'x':
  42198. alignVector.copy(viewer.mainViewport.view.direction).cross(unitX);
  42199. normal.copy(unitX).cross(alignVector);
  42200. break;
  42201. case 'y':
  42202. alignVector.copy(viewer.mainViewport.view.direction).cross(unitY);
  42203. normal.copy(unitY).cross(alignVector);
  42204. break;
  42205. case 'z':
  42206. alignVector.copy(viewer.mainViewport.view.direction).cross(unitZ);
  42207. normal.copy(unitZ).cross(alignVector);
  42208. break;
  42209. case 'xy':
  42210. normal.copy(unitZ);
  42211. break;
  42212. case 'yz':
  42213. normal.copy(unitX);
  42214. break;
  42215. case 'xz':
  42216. normal.copy(unitY);
  42217. break;
  42218. } //参考transformControls.使跟手
  42219. }
  42220. drag.dragPlane = new Plane().setFromNormalAndCoplanarPoint(normal, posWorld /* drag.worldPositionStart */); //过center的与视线垂直的平面
  42221. var I = ray.intersectPlane(drag.dragPlane, new Vector3());
  42222. if (I) {
  42223. var offset = new Vector3().subVectors(I, drag.worldPositionStart);
  42224. //let offset = new THREE.Vector3().subVectors(iOnLine, drag.worldPositionStart);
  42225. if (!drag.pointStart) {
  42226. drag.pointStart = offset;
  42227. } else {
  42228. drag.pointEnd = offset;
  42229. var diff = new Vector3().subVectors(drag.pointEnd, drag.pointStart);
  42230. diff.applyQuaternion(drag.objectQuaInv); // 得到在该物体local空间上的offset
  42231. if (!handle.name.includes('x')) diff.x = 0;
  42232. if (!handle.name.includes('y')) diff.y = 0;
  42233. if (!handle.name.includes('z')) diff.z = 0;
  42234. //恢复为world offset
  42235. diff.applyQuaternion(drag.objectQua);
  42236. //-------------
  42237. var matrixBefore = this.selection[0].matrix.clone();
  42238. this.selection[0].position.copy(diff).add(drag.worldPositionStart);
  42239. for (var selection of this.selection) {
  42240. selection.updateMatrixWorld(); //xzw add 保险起见立即update
  42241. selection.dispatchEvent({
  42242. type: "position_changed",
  42243. object: selection
  42244. });
  42245. }
  42246. this.dispatchEvent({
  42247. type: 'transformed',
  42248. changeType: ['position'],
  42249. matrixBefore
  42250. }); //add
  42251. }
  42252. }
  42253. }
  42254. }
  42255. }
  42256. dropTranslationHandle(e) {
  42257. this.dragging = false;
  42258. this.setActiveHandle(null);
  42259. this.dispatchEvent({
  42260. type: 'stopDrag',
  42261. handle: 'translation'
  42262. }); //add
  42263. }
  42264. dropScaleHandle(e) {
  42265. this.dragging = false;
  42266. this.setActiveHandle(null);
  42267. this.dispatchEvent({
  42268. type: 'stopDrag',
  42269. handle: 'scale'
  42270. }); //add
  42271. }
  42272. dragScaleHandle(e) {
  42273. var drag = e.drag;
  42274. var handle = this.activeHandle;
  42275. if (!handle || !handle.name.includes('scale')) return;
  42276. var camera = this.viewer.mainViewport.camera; //this.viewer.scene.getActiveCamera();
  42277. if (!drag.intersectionStart) {
  42278. drag.intersectionStart = drag.location;
  42279. drag.objectStart = drag.object.getWorldPosition(new Vector3());
  42280. drag.handle = handle;
  42281. var start = drag.intersectionStart;
  42282. var dir = new Vector4(...handle.alignment, 0).applyMatrix4(this.scene.matrixWorld);
  42283. var end = new Vector3().addVectors(start, dir);
  42284. var line = new Line3(start.clone(), end.clone());
  42285. drag.line = line;
  42286. var normal;
  42287. if (camera.type == 'OrthographicCamera') {
  42288. //xzw add
  42289. normal = new Vector3(0, 0, -1).applyQuaternion(camera.quaternion);
  42290. } else {
  42291. var camOnLine = line.closestPointToPoint(camera.position, false, new Vector3());
  42292. normal = new Vector3().subVectors(camera.position, camOnLine);
  42293. }
  42294. var plane = new Plane().setFromNormalAndCoplanarPoint(normal, drag.intersectionStart); //过轴线的一个能铺满屏幕的平面
  42295. drag.dragPlane = plane;
  42296. drag.pivot = drag.intersectionStart;
  42297. //Utils.debugSphere(viewer.scene.scene, drag.pivot, 0.05);
  42298. } else {
  42299. handle = drag.handle;
  42300. }
  42301. this.dragging = true;
  42302. if (drag.dragPlane) {
  42303. //xzw add 因有时候没有
  42304. var pointer = this.viewer.inputHandler.pointer;
  42305. var domElement = this.viewer.renderer.domElement;
  42306. var ray = Utils.mouseToRay(pointer, camera, domElement.clientWidth, domElement.clientHeight);
  42307. var I = ray.intersectPlane(drag.dragPlane, new Vector3());
  42308. if (I) {
  42309. var iOnLine = drag.line.closestPointToPoint(I, false, new Vector3());
  42310. var direction = handle.alignment.reduce((a, v) => a + v, 0);
  42311. var toObjectSpace = this.selection[0].matrixWorld.clone().invert();
  42312. var iOnLineOS = iOnLine.clone().applyMatrix4(toObjectSpace);
  42313. var pivotOS = drag.pivot.clone().applyMatrix4(toObjectSpace);
  42314. var diffOS = new Vector3().subVectors(iOnLineOS, pivotOS);
  42315. var dragDirectionOS = diffOS.clone().normalize();
  42316. if (iOnLine.distanceTo(drag.pivot) === 0) {
  42317. dragDirectionOS.set(0, 0, 0);
  42318. }
  42319. var dragDirection = dragDirectionOS.dot(new Vector3(...handle.alignment));
  42320. var alignment = new Vector3(...handle.alignment);
  42321. var diff = new Vector3().subVectors(iOnLine, drag.pivot);
  42322. var diffScale = alignment.clone().multiplyScalar(diff.length() * direction * dragDirection);
  42323. //let diffPosition = diff.clone().multiplyScalar(0.5); //这个仅当bound包含原点才准确。
  42324. var matrixBefore = this.selection[0].matrix.clone();
  42325. for (var selection of this.selection) {
  42326. //xzw 改:否则不跟手
  42327. var {
  42328. min,
  42329. max
  42330. } = selection.boundingBox;
  42331. var fixPoint = alignment.x != 0 ? (alignment.x > 0 ? min : max).clone().setY(0).setZ(0) :
  42332. //要保证另一边不能移动
  42333. alignment.y != 0 ? (alignment.y > 0 ? min : max).clone().setX(0).setZ(0) : (alignment.z > 0 ? min : max).clone().setX(0).setY(0);
  42334. var fixPointBefore = fixPoint.clone().applyMatrix4(selection.matrixWorld);
  42335. var size = selection.boundingBox.getSize(new Vector3());
  42336. var diffScale_ = diffScale.clone().divide(size);
  42337. size.x == 0 && (diffScale_.x = 0); //add 若为0,不改此轴大小
  42338. size.y == 0 && (diffScale_.y = 0);
  42339. size.z == 0 && (diffScale_.z = 0);
  42340. selection.scale.add(diffScale_);
  42341. selection.scale.max(new Vector3(0.1, 0.1, 0.1));
  42342. //selection.position.add(diffPosition);
  42343. selection.updateMatrixWorld();
  42344. var fixPointAfter = fixPoint.clone().applyMatrix4(this.selection[0].matrixWorld);
  42345. selection.position.sub(new Vector3().subVectors(fixPointAfter, fixPointBefore)); //保证另一边不能移动所需要的位移
  42346. selection.updateMatrixWorld(); //xzw add 保险起见立即update
  42347. selection.dispatchEvent({
  42348. type: "position_changed",
  42349. object: selection
  42350. });
  42351. selection.dispatchEvent({
  42352. type: "scale_changed",
  42353. object: selection
  42354. });
  42355. }
  42356. this.dispatchEvent({
  42357. type: 'transformed',
  42358. changeType: ['position', 'scale'],
  42359. matrixBefore
  42360. }); //add
  42361. drag.pivot.copy(iOnLine);
  42362. //Utils.debugSphere(viewer.scene.scene, drag.pivot, 0.05);
  42363. }
  42364. }
  42365. }
  42366. setActiveHandle(handle) {
  42367. if (this.dragging) {
  42368. return;
  42369. }
  42370. if (this.activeHandle === handle) {
  42371. return;
  42372. }
  42373. this.activeHandle = handle;
  42374. if (handle === null) {
  42375. for (var handleName of Object.keys(this.handles)) {
  42376. var _handle = this.handles[handleName];
  42377. _handle.node.setOpacity(0);
  42378. }
  42379. }
  42380. viewer.dispatchEvent({
  42381. type: 'CursorChange',
  42382. action: this.activeHandle ? 'add' : 'remove',
  42383. name: 'hoverTranHandle'
  42384. });
  42385. if (!hideFocusHandles) {
  42386. for (var _handleName of Object.keys(this.focusHandles)) {
  42387. var _handle2 = this.focusHandles[_handleName];
  42388. if (this.activeHandle === _handle2) {
  42389. _handle2.node.setOpacity(1.0);
  42390. } else {
  42391. _handle2.node.setOpacity(OpaWhenNotSelect);
  42392. }
  42393. }
  42394. }
  42395. for (var _handleName2 of Object.keys(this.translationHandles)) {
  42396. var _handle3 = this.translationHandles[_handleName2];
  42397. if (this.activeHandle === _handle3) {
  42398. _handle3.node.setOpacity(1.0);
  42399. } else {
  42400. _handle3.node.setOpacity(OpaWhenNotSelect);
  42401. }
  42402. }
  42403. for (var _handleName3 of Object.keys(this.rotationHandles)) {
  42404. var _handle4 = this.rotationHandles[_handleName3];
  42405. //if(this.activeHandle === handle){
  42406. // handle.node.setOpacity(1.0);
  42407. //}else{
  42408. // handle.node.setOpacity(OpaWhenNotSelect)
  42409. //}
  42410. _handle4.node.setOpacity(OpaWhenNotSelect);
  42411. }
  42412. for (var _handleName4 of Object.keys(this.scaleHandles)) {
  42413. var _handle5 = this.scaleHandles[_handleName4];
  42414. if (this.activeHandle === _handle5) {
  42415. _handle5.node.setOpacity(1.0);
  42416. if (!hideFocusHandles) {
  42417. var relatedFocusHandle = this.focusHandles[_handle5.name.replace("scale", "focus")];
  42418. var relatedFocusNode = relatedFocusHandle.node;
  42419. relatedFocusNode.setOpacity(OpaWhenNotSelect);
  42420. }
  42421. for (var translationHandleName of Object.keys(this.translationHandles)) {
  42422. var translationHandle = this.translationHandles[translationHandleName];
  42423. translationHandle.node.setOpacity(OpaWhenNotSelect);
  42424. }
  42425. //let relatedTranslationHandle = this.translationHandles[
  42426. // handle.name.replace("scale", "translation").replace(/[+-]/g, "")];
  42427. //let relatedTranslationNode = relatedTranslationHandle.node;
  42428. //relatedTranslationNode.setOpacity(OpaWhenNotSelect);
  42429. } else {
  42430. _handle5.node.setOpacity(OpaWhenNotSelect);
  42431. }
  42432. }
  42433. if (handle) {
  42434. handle.node.setOpacity(1.0);
  42435. }
  42436. viewer.dispatchEvent('content_changed');
  42437. }
  42438. update() {
  42439. if (this.selection.length === 1) {
  42440. this.scene.visible = true;
  42441. this.scene.updateMatrix();
  42442. this.scene.updateMatrixWorld();
  42443. var selected = this.selection[0];
  42444. //selected.updateMatrixWorld();//add 否则scale的sphere抖动
  42445. var world = selected.matrixWorld;
  42446. var camera = this.viewer.mainViewport.camera; //this.viewer.scene.getActiveCamera();
  42447. var domElement = this.viewer.renderer.domElement;
  42448. var center = selected.boundingBox.getCenter(new Vector3()).clone().applyMatrix4(selected.matrixWorld);
  42449. var scale = selected.boundingBox.getSize(new Vector3()).multiply(selected.scale);
  42450. scale.max(new Vector3(.1, .1, .1)); //xzw add 如果是plane,没有厚度,会导致该tool消失
  42451. this.scene.scale.copy(scale);
  42452. this.scene.position.copy(center);
  42453. this.scene.rotation.copy(selected.rotation); //这里只考虑当前子级的scale rotation
  42454. //如果是世界坐标 (缩放方向有bug。)
  42455. /*
  42456. let boundingBox = selected.boundingBox.clone().applyMatrix4(selected.matrixWorld);
  42457. let center = boundingBox.getCenter(new THREE.Vector3())
  42458. this.scene.position.copy(center);
  42459. this.scene.scale.copy(boundingBox.getSize(new THREE.Vector3()));
  42460. */
  42461. this.scene.updateMatrixWorld();
  42462. {
  42463. // adjust rotation handles
  42464. if (!this.dragging) {
  42465. if (this.modesEnabled.rotation || this.modesEnabled.translation) {
  42466. var tWorld = this.scene.matrixWorld;
  42467. var tObject = tWorld.clone().invert();
  42468. var camObjectPos = camera.getWorldPosition(new Vector3()).applyMatrix4(tObject);
  42469. if (this.modesEnabled.translation) {
  42470. //add
  42471. ['xy', 'yz', 'xz'].forEach(axis => {
  42472. var handle = this.translationHandles["translation.plane." + axis];
  42473. var pos = handle.node.children[0].position;
  42474. camObjectPos.x && (pos.x = Math.sign(camObjectPos.x) * Math.abs(pos.x));
  42475. camObjectPos.y && (pos.y = Math.sign(camObjectPos.y) * Math.abs(pos.y));
  42476. camObjectPos.z && (pos.z = Math.sign(camObjectPos.z) * Math.abs(pos.z));
  42477. });
  42478. }
  42479. if (this.modesEnabled.rotation) {
  42480. var above = camObjectPos.z > 0;
  42481. var below = !above;
  42482. var PI_HALF = Math.PI / 2;
  42483. var x = this.rotationHandles["rotation.x"].node.rotation;
  42484. var y = this.rotationHandles["rotation.y"].node.rotation;
  42485. var z = this.rotationHandles["rotation.z"].node.rotation;
  42486. x.order = "ZYX";
  42487. y.order = "ZYX";
  42488. if (above) {
  42489. if (camObjectPos.x > 0 && camObjectPos.y > 0) {
  42490. x.x = 1 * PI_HALF;
  42491. y.y = 3 * PI_HALF;
  42492. z.z = 0 * PI_HALF;
  42493. } else if (camObjectPos.x < 0 && camObjectPos.y > 0) {
  42494. x.x = 1 * PI_HALF;
  42495. y.y = 2 * PI_HALF;
  42496. z.z = 1 * PI_HALF;
  42497. } else if (camObjectPos.x < 0 && camObjectPos.y < 0) {
  42498. x.x = 2 * PI_HALF;
  42499. y.y = 2 * PI_HALF;
  42500. z.z = 2 * PI_HALF;
  42501. } else if (camObjectPos.x > 0 && camObjectPos.y < 0) {
  42502. x.x = 2 * PI_HALF;
  42503. y.y = 3 * PI_HALF;
  42504. z.z = 3 * PI_HALF;
  42505. }
  42506. } else if (below) {
  42507. if (camObjectPos.x > 0 && camObjectPos.y > 0) {
  42508. x.x = 0 * PI_HALF;
  42509. y.y = 0 * PI_HALF;
  42510. z.z = 0 * PI_HALF;
  42511. } else if (camObjectPos.x < 0 && camObjectPos.y > 0) {
  42512. x.x = 0 * PI_HALF;
  42513. y.y = 1 * PI_HALF;
  42514. z.z = 1 * PI_HALF;
  42515. } else if (camObjectPos.x < 0 && camObjectPos.y < 0) {
  42516. x.x = 3 * PI_HALF;
  42517. y.y = 1 * PI_HALF;
  42518. z.z = 2 * PI_HALF;
  42519. } else if (camObjectPos.x > 0 && camObjectPos.y < 0) {
  42520. x.x = 3 * PI_HALF;
  42521. y.y = 0 * PI_HALF;
  42522. z.z = 3 * PI_HALF;
  42523. }
  42524. }
  42525. }
  42526. }
  42527. }
  42528. // adjust scale of components
  42529. for (var handleName of Object.keys(this.handles)) {
  42530. var handle = this.handles[handleName];
  42531. var node = handle.node;
  42532. //xzw add:---- -当该轴正对相机时隐藏。(主要针对ortho类型camera。
  42533. if (!Potree.Utils.getObjVisiByReason(node, 'modeForce')) continue;
  42534. var alignment = handle.alignment;
  42535. if (alignment && (!handleName.includes('rotation') || camera.type == 'OrthographicCamera')) {
  42536. //旋转的话正常都应该显示
  42537. var normal = void 0;
  42538. var dir = new Vector3(...alignment).applyQuaternion(this.scene.quaternion);
  42539. if (camera.type == 'OrthographicCamera') {
  42540. normal = new Vector3(0, 0, -1).applyQuaternion(camera.quaternion);
  42541. } else {
  42542. normal = new Vector3().subVectors(center, camera.position).normalize();
  42543. }
  42544. var ifOnLine = void 0;
  42545. if (handleName.includes('rotation') || handleName.includes('plane')) {
  42546. // 旋转轴和视线垂直时隐藏
  42547. ifOnLine = Math.abs(dir.dot(normal)) < 0.1;
  42548. } else {
  42549. ifOnLine = Math.abs(dir.dot(normal)) > 0.995;
  42550. }
  42551. Potree.Utils.updateVisible(node, 'faceToCamHide', !ifOnLine);
  42552. } else {
  42553. Potree.Utils.updateVisible(node, 'faceToCamHide', true);
  42554. }
  42555. if (!node.visible) continue;
  42556. //------------------------------------------------------------------------
  42557. if (handle.dontScale) continue; //add
  42558. var handlePos = node.getWorldPosition(new Vector3());
  42559. var distance = handlePos.distanceTo(camera.position);
  42560. var pr = Utils.projectedRadius(1, camera, distance, domElement.clientWidth, domElement.clientHeight);
  42561. var ws = node.parent.getWorldScale(new Vector3());
  42562. var s = ScaleRatio / pr;
  42563. var _scale = new Vector3(s, s, s).divide(ws);
  42564. var rot = new Matrix4().makeRotationFromEuler(node.rotation); //需要使用到旋转,所以我把设置scale的移到旋转后了,否则在视图上下旋转的分界线处rotateHandel会被拉长从而闪烁。
  42565. var rotInv = rot.clone().invert();
  42566. _scale.applyMatrix4(rotInv);
  42567. _scale.x = Math.abs(_scale.x);
  42568. _scale.y = Math.abs(_scale.y);
  42569. _scale.z = Math.abs(_scale.z);
  42570. node.scale.copy(_scale);
  42571. }
  42572. }
  42573. } else {
  42574. this.scene.visible = false;
  42575. }
  42576. }
  42577. onPointerMove() {
  42578. var pointer = this.viewer.inputHandler.pointer;
  42579. var camera = this.viewer.mainViewport.camera;
  42580. if (this.selection.length === 1 && !this.dragging) {
  42581. //xzw 添加dragging条件
  42582. var ray = Utils.mouseToRay(pointer, camera);
  42583. var raycaster = new Raycaster(ray.origin, ray.direction);
  42584. raycaster.layers.enableAll(); //add
  42585. var pickVolumes = this.pickVolumes.filter(v => {
  42586. var mode = v.handle.split('.')[0];
  42587. if (!this.modesEnabled[mode]) return;
  42588. return v.parent.parent.visible; //可能被隐藏该轴
  42589. });
  42590. var intersects = raycaster.intersectObjects(pickVolumes, true);
  42591. intersects = intersects.sort(function (a, b) {
  42592. var order2 = b.object.renderOrder || 0;
  42593. var order1 = a.object.renderOrder || 0;
  42594. return order2 - order1;
  42595. }); // 降序
  42596. if (intersects.length > 0) {
  42597. var I = intersects[0];
  42598. var handleName = I.object.handle;
  42599. //console.log(handleName)
  42600. this.setActiveHandle(this.handles[handleName]);
  42601. } else {
  42602. this.setActiveHandle(null);
  42603. }
  42604. }
  42605. }
  42606. }
  42607. ;
  42608. /*
  42609. note:
  42610. transformationTool.scene会跟随选中物体,其scale就是boundingbox的大小。因此transformationTool.frame这个框也会跟着缩放
  42611. */
  42612. var boxOpacity = {
  42613. hovered: 0.1,
  42614. selected: 0.2
  42615. };
  42616. var LineOpacity = {
  42617. default: 0.6,
  42618. selected: 1
  42619. };
  42620. var colors = {
  42621. 2: 0x2ee4ce,
  42622. //0x00ff80, //可见
  42623. 3: 0xffc23b,
  42624. //0xff3158, //不可见
  42625. 4: 0xffffff //
  42626. };
  42627. class Volume$1 extends Object3D {
  42628. constructor() {
  42629. var args = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  42630. super();
  42631. if (this.constructor.name === "Volume") {
  42632. console.warn("Can't create object of class Volume directly. Use classes BoxVolume or SphereVolume instead.");
  42633. }
  42634. this._clip = args.clip || false;
  42635. this._visible = true;
  42636. //this.showVolumeLabel = true;
  42637. this._modifiable = args.modifiable || true;
  42638. {
  42639. // event listeners
  42640. this.addEventListener('select', e => {
  42641. //console.log('select')
  42642. this.setSelected(true);
  42643. });
  42644. this.addEventListener('deselect', e => {
  42645. //console.log('deselect')
  42646. this.setSelected(false);
  42647. });
  42648. this.addEventListener('mouseover', e => {
  42649. this.hovered = true;
  42650. this.update();
  42651. });
  42652. this.addEventListener('mouseleave', e => {
  42653. this.hovered = false;
  42654. this.update();
  42655. });
  42656. }
  42657. }
  42658. setSelected(state) {
  42659. //add
  42660. this.selected = !!state;
  42661. this.update();
  42662. }
  42663. get visible() {
  42664. return this._visible;
  42665. }
  42666. set visible(value) {
  42667. if (this._visible !== value) {
  42668. this._visible = value;
  42669. this.dispatchEvent({
  42670. type: "visibility_changed",
  42671. object: this
  42672. });
  42673. }
  42674. }
  42675. getVolume() {
  42676. console.warn("override this in subclass");
  42677. }
  42678. update() {}
  42679. raycast(raycaster, intersects) {}
  42680. get clip() {
  42681. return this._clip;
  42682. }
  42683. set clip(value) {
  42684. if (this._clip !== value) {
  42685. this._clip = value;
  42686. this.update();
  42687. this.dispatchEvent({
  42688. type: "clip_changed",
  42689. object: this
  42690. });
  42691. }
  42692. }
  42693. get modifieable() {
  42694. return this._modifiable;
  42695. }
  42696. set modifieable(value) {
  42697. this._modifiable = value;
  42698. this.update();
  42699. }
  42700. }
  42701. ;
  42702. class BoxVolume$1 extends Volume$1 {
  42703. constructor() {
  42704. var args = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  42705. super(args);
  42706. this.constructor.counter = this.constructor.counter === undefined ? 0 : this.constructor.counter + 1;
  42707. this.name = 'box_' + this.constructor.counter;
  42708. this.clipTask = args.clipTask || Potree.ClipTask.SHOW_INSIDE; //add
  42709. this.showBox = true;
  42710. var boxGeometry = new BoxGeometry(1, 1, 1);
  42711. boxGeometry.computeBoundingBox();
  42712. var boxFrameGeometry = new Geometry();
  42713. var Vector3$1 = Vector3;
  42714. {
  42715. boxFrameGeometry.vertices.push(
  42716. // bottom
  42717. new Vector3$1(-0.5, -0.5, 0.5), new Vector3$1(0.5, -0.5, 0.5), new Vector3$1(0.5, -0.5, 0.5), new Vector3$1(0.5, -0.5, -0.5), new Vector3$1(0.5, -0.5, -0.5), new Vector3$1(-0.5, -0.5, -0.5), new Vector3$1(-0.5, -0.5, -0.5), new Vector3$1(-0.5, -0.5, 0.5),
  42718. // top
  42719. new Vector3$1(-0.5, 0.5, 0.5), new Vector3$1(0.5, 0.5, 0.5), new Vector3$1(0.5, 0.5, 0.5), new Vector3$1(0.5, 0.5, -0.5), new Vector3$1(0.5, 0.5, -0.5), new Vector3$1(-0.5, 0.5, -0.5), new Vector3$1(-0.5, 0.5, -0.5), new Vector3$1(-0.5, 0.5, 0.5),
  42720. // sides
  42721. new Vector3$1(-0.5, -0.5, 0.5), new Vector3$1(-0.5, 0.5, 0.5), new Vector3$1(0.5, -0.5, 0.5), new Vector3$1(0.5, 0.5, 0.5), new Vector3$1(0.5, -0.5, -0.5), new Vector3$1(0.5, 0.5, -0.5), new Vector3$1(-0.5, -0.5, -0.5), new Vector3$1(-0.5, 0.5, -0.5));
  42722. }
  42723. this.material = new DepthBasicMaterial({
  42724. color: colors[this.clipTask],
  42725. side: DoubleSide,
  42726. transparent: true,
  42727. opacity: boxOpacity.hovered,
  42728. depthTest: true,
  42729. depthWrite: false,
  42730. useDepth: true,
  42731. clipDistance: 2,
  42732. //消失距离
  42733. occlusionDistance: 0.1,
  42734. //变为backColor距离
  42735. maxClipFactor: 0.9
  42736. });
  42737. this.box = new Mesh(boxGeometry, this.material);
  42738. this.box.geometry.computeBoundingBox();
  42739. this.boundingBox = this.box.geometry.boundingBox;
  42740. this.add(this.box);
  42741. //this.frame = new THREE.LineSegments(boxFrameGeometry, new THREE.LineBasicMaterial({color: colors[this.clipTask], opacity:LineOpacity.default/* 0xff2050 */}));
  42742. this.frame = LineDraw.createFatLine(boxFrameGeometry.vertices, {
  42743. color: colors[this.clipTask],
  42744. opacity: LineOpacity.default,
  42745. lineWidth: 1,
  42746. dontAlwaysSeen: true
  42747. });
  42748. // this.frame.mode = THREE.Lines;
  42749. this.add(this.frame);
  42750. this.update();
  42751. }
  42752. update() {
  42753. this.boundingBox = this.box.geometry.boundingBox;
  42754. this.boundingSphere = this.boundingBox.getBoundingSphere(new Sphere());
  42755. Potree.Utils.updateVisible(this.box, 'selected', (this.selected || this.hovered) && this.showBox);
  42756. this.box.material.opacity = this.selected ? boxOpacity.selected : boxOpacity.hovered;
  42757. this.box.material.color.set(colors[this.clipTask]);
  42758. this.frame.material.color.set(colors[this.clipTask]);
  42759. this.frame.material.opacity = this.selected ? LineOpacity.selected : LineOpacity.default;
  42760. this.frame.material.lineWidth = this.selected ? 2 : 1;
  42761. }
  42762. raycast(raycaster, intersects) {
  42763. var is = [];
  42764. this.box.raycast(raycaster, is);
  42765. if (is.length > 0) {
  42766. var I = is[0];
  42767. intersects.push({
  42768. distance: I.distance,
  42769. object: this,
  42770. point: I.point.clone()
  42771. });
  42772. }
  42773. }
  42774. getVolume() {
  42775. return Math.abs(this.scale.x * this.scale.y * this.scale.z);
  42776. }
  42777. }
  42778. ;
  42779. class SphereVolume$2 extends Volume$1 {
  42780. constructor() {
  42781. var args = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  42782. super(args);
  42783. this.constructor.counter = this.constructor.counter === undefined ? 0 : this.constructor.counter + 1;
  42784. this.name = 'sphere_' + this.constructor.counter;
  42785. var sphereGeometry = new SphereGeometry(1, 32, 32);
  42786. sphereGeometry.computeBoundingBox();
  42787. this.material = new MeshBasicMaterial({
  42788. color: 0x00ff00,
  42789. transparent: true,
  42790. opacity: 0.3,
  42791. depthTest: true,
  42792. depthWrite: false
  42793. });
  42794. this.sphere = new Mesh(sphereGeometry, this.material);
  42795. this.sphere.visible = false;
  42796. this.sphere.geometry.computeBoundingBox();
  42797. this.boundingBox = this.sphere.geometry.boundingBox;
  42798. this.add(this.sphere);
  42799. this.label.visible = false;
  42800. var frameGeometry = new Geometry();
  42801. {
  42802. var steps = 64;
  42803. var uSegments = 8;
  42804. var vSegments = 5;
  42805. var r = 1;
  42806. for (var uSegment = 0; uSegment < uSegments; uSegment++) {
  42807. var alpha = uSegment / uSegments * Math.PI * 2;
  42808. var dirx = Math.cos(alpha);
  42809. var diry = Math.sin(alpha);
  42810. for (var i = 0; i <= steps; i++) {
  42811. var v = i / steps * Math.PI * 2;
  42812. var vNext = v + 2 * Math.PI / steps;
  42813. var height = Math.sin(v);
  42814. var xyAmount = Math.cos(v);
  42815. var heightNext = Math.sin(vNext);
  42816. var xyAmountNext = Math.cos(vNext);
  42817. var vertex = new Vector3(dirx * xyAmount, diry * xyAmount, height);
  42818. frameGeometry.vertices.push(vertex);
  42819. var vertexNext = new Vector3(dirx * xyAmountNext, diry * xyAmountNext, heightNext);
  42820. frameGeometry.vertices.push(vertexNext);
  42821. }
  42822. }
  42823. // creates rings at poles, just because it's easier to implement
  42824. for (var vSegment = 0; vSegment <= vSegments + 1; vSegment++) {
  42825. //let height = (vSegment / (vSegments + 1)) * 2 - 1; // -1 to 1
  42826. var uh = vSegment / (vSegments + 1); // -1 to 1
  42827. uh = (1 - uh) * (-Math.PI / 2) + uh * (Math.PI / 2);
  42828. var _height = Math.sin(uh);
  42829. console.log(uh, _height);
  42830. for (var _i = 0; _i <= steps; _i++) {
  42831. var u = _i / steps * Math.PI * 2;
  42832. var uNext = u + 2 * Math.PI / steps;
  42833. var _dirx = Math.cos(u);
  42834. var _diry = Math.sin(u);
  42835. var dirxNext = Math.cos(uNext);
  42836. var diryNext = Math.sin(uNext);
  42837. var _xyAmount = Math.sqrt(1 - _height * _height);
  42838. var _vertex = new Vector3(_dirx * _xyAmount, _diry * _xyAmount, _height);
  42839. frameGeometry.vertices.push(_vertex);
  42840. var _vertexNext = new Vector3(dirxNext * _xyAmount, diryNext * _xyAmount, _height);
  42841. frameGeometry.vertices.push(_vertexNext);
  42842. }
  42843. }
  42844. }
  42845. this.frame = new LineSegments(frameGeometry, new LineBasicMaterial({
  42846. color: 0x000000
  42847. }));
  42848. this.add(this.frame);
  42849. var frameMaterial = new MeshBasicMaterial({
  42850. wireframe: true,
  42851. color: 0x000000
  42852. });
  42853. this.frame = new Mesh(sphereGeometry, frameMaterial);
  42854. //this.add(this.frame);
  42855. //this.frame = new THREE.LineSegments(boxFrameGeometry, new THREE.LineBasicMaterial({color: 0x000000}));
  42856. // this.frame.mode = THREE.Lines;
  42857. //this.add(this.frame);
  42858. this.update();
  42859. }
  42860. update() {
  42861. this.boundingBox = this.sphere.geometry.boundingBox;
  42862. this.boundingSphere = this.boundingBox.getBoundingSphere(new Sphere());
  42863. //if (this._clip) {
  42864. // this.sphere.visible = false;
  42865. // this.label.visible = false;
  42866. //} else {
  42867. // this.sphere.visible = true;
  42868. // this.label.visible = this.showVolumeLabel;
  42869. //}
  42870. }
  42871. raycast(raycaster, intersects) {
  42872. var is = [];
  42873. this.sphere.raycast(raycaster, is);
  42874. if (is.length > 0) {
  42875. var I = is[0];
  42876. intersects.push({
  42877. distance: I.distance,
  42878. object: this,
  42879. point: I.point.clone()
  42880. });
  42881. }
  42882. }
  42883. // see https://en.wikipedia.org/wiki/Ellipsoid#Volume
  42884. getVolume() {
  42885. return 4 / 3 * Math.PI * this.scale.x * this.scale.y * this.scale.z;
  42886. }
  42887. }
  42888. ;
  42889. function _OverloadYield(e, d) {
  42890. this.v = e, this.k = d;
  42891. }
  42892. function _applyDecoratedDescriptor(i, e, r, n, l) {
  42893. var a = {};
  42894. return Object.keys(n).forEach(function (i) {
  42895. a[i] = n[i];
  42896. }), a.enumerable = !!a.enumerable, a.configurable = !!a.configurable, ("value" in a || a.initializer) && (a.writable = !0), a = r.slice().reverse().reduce(function (r, n) {
  42897. return n(i, e, r) || r;
  42898. }, a), l && void 0 !== a.initializer && (a.value = a.initializer ? a.initializer.call(l) : void 0, a.initializer = void 0), void 0 === a.initializer ? (Object.defineProperty(i, e, a), null) : a;
  42899. }
  42900. function _applyDecs2311(e, t, n, r, o, i) {
  42901. var a,
  42902. c,
  42903. u,
  42904. s,
  42905. f,
  42906. l,
  42907. p,
  42908. d = Symbol.metadata || Symbol.for("Symbol.metadata"),
  42909. m = Object.defineProperty,
  42910. h = Object.create,
  42911. y = [h(null), h(null)],
  42912. v = t.length;
  42913. function g(t, n, r) {
  42914. return function (o, i) {
  42915. n && (i = o, o = e);
  42916. for (var a = 0; a < t.length; a++) i = t[a].apply(o, r ? [i] : []);
  42917. return r ? i : o;
  42918. };
  42919. }
  42920. function b(e, t, n, r) {
  42921. if ("function" != typeof e && (r || void 0 !== e)) throw new TypeError(t + " must " + (n || "be") + " a function" + (r ? "" : " or undefined"));
  42922. return e;
  42923. }
  42924. function applyDec(e, t, n, r, o, i, u, s, f, l, p) {
  42925. function d(e) {
  42926. if (!p(e)) throw new TypeError("Attempted to access private element on non-instance");
  42927. }
  42928. var h = [].concat(t[0]),
  42929. v = t[3],
  42930. w = !u,
  42931. D = 1 === o,
  42932. S = 3 === o,
  42933. j = 4 === o,
  42934. E = 2 === o;
  42935. function I(t, n, r) {
  42936. return function (o, i) {
  42937. return n && (i = o, o = e), r && r(o), P[t].call(o, i);
  42938. };
  42939. }
  42940. if (!w) {
  42941. var P = {},
  42942. k = [],
  42943. F = S ? "get" : j || D ? "set" : "value";
  42944. if (f ? (l || D ? P = {
  42945. get: _setFunctionName(function () {
  42946. return v(this);
  42947. }, r, "get"),
  42948. set: function (e) {
  42949. t[4](this, e);
  42950. }
  42951. } : P[F] = v, l || _setFunctionName(P[F], r, E ? "" : F)) : l || (P = Object.getOwnPropertyDescriptor(e, r)), !l && !f) {
  42952. if ((c = y[+s][r]) && 7 != (c ^ o)) throw Error("Decorating two elements with the same name (" + P[F].name + ") is not supported yet");
  42953. y[+s][r] = o < 3 ? 1 : o;
  42954. }
  42955. }
  42956. for (var N = e, O = h.length - 1; O >= 0; O -= n ? 2 : 1) {
  42957. var T = b(h[O], "A decorator", "be", !0),
  42958. z = n ? h[O - 1] : void 0,
  42959. A = {},
  42960. H = {
  42961. kind: ["field", "accessor", "method", "getter", "setter", "class"][o],
  42962. name: r,
  42963. metadata: a,
  42964. addInitializer: function (e, t) {
  42965. if (e.v) throw new TypeError("attempted to call addInitializer after decoration was finished");
  42966. b(t, "An initializer", "be", !0), i.push(t);
  42967. }.bind(null, A)
  42968. };
  42969. if (w) c = T.call(z, N, H), A.v = 1, b(c, "class decorators", "return") && (N = c);else if (H.static = s, H.private = f, c = H.access = {
  42970. has: f ? p.bind() : function (e) {
  42971. return r in e;
  42972. }
  42973. }, j || (c.get = f ? E ? function (e) {
  42974. return d(e), P.value;
  42975. } : I("get", 0, d) : function (e) {
  42976. return e[r];
  42977. }), E || S || (c.set = f ? I("set", 0, d) : function (e, t) {
  42978. e[r] = t;
  42979. }), N = T.call(z, D ? {
  42980. get: P.get,
  42981. set: P.set
  42982. } : P[F], H), A.v = 1, D) {
  42983. if ("object" == typeof N && N) (c = b(N.get, "accessor.get")) && (P.get = c), (c = b(N.set, "accessor.set")) && (P.set = c), (c = b(N.init, "accessor.init")) && k.unshift(c);else if (void 0 !== N) throw new TypeError("accessor decorators must return an object with get, set, or init properties or undefined");
  42984. } else b(N, (l ? "field" : "method") + " decorators", "return") && (l ? k.unshift(N) : P[F] = N);
  42985. }
  42986. return o < 2 && u.push(g(k, s, 1), g(i, s, 0)), l || w || (f ? D ? u.splice(-1, 0, I("get", s), I("set", s)) : u.push(E ? P[F] : b.call.bind(P[F])) : m(e, r, P)), N;
  42987. }
  42988. function w(e) {
  42989. return m(e, d, {
  42990. configurable: !0,
  42991. enumerable: !0,
  42992. value: a
  42993. });
  42994. }
  42995. return void 0 !== i && (a = i[d]), a = h(null == a ? null : a), f = [], l = function (e) {
  42996. e && f.push(g(e));
  42997. }, p = function (t, r) {
  42998. for (var i = 0; i < n.length; i++) {
  42999. var a = n[i],
  43000. c = a[1],
  43001. l = 7 & c;
  43002. if ((8 & c) == t && !l == r) {
  43003. var p = a[2],
  43004. d = !!a[3],
  43005. m = 16 & c;
  43006. applyDec(t ? e : e.prototype, a, m, d ? "#" + p : _toPropertyKey(p), l, l < 2 ? [] : t ? s = s || [] : u = u || [], f, !!t, d, r, t && d ? function (t) {
  43007. return _checkInRHS(t) === e;
  43008. } : o);
  43009. }
  43010. }
  43011. }, p(8, 0), p(0, 0), p(8, 1), p(0, 1), l(u), l(s), c = f, v || w(e), {
  43012. e: c,
  43013. get c() {
  43014. var n = [];
  43015. return v && [w(e = applyDec(e, [t], r, e.name, 5, n)), g(n, 1)];
  43016. }
  43017. };
  43018. }
  43019. function _arrayLikeToArray(r, a) {
  43020. (null == a || a > r.length) && (a = r.length);
  43021. for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
  43022. return n;
  43023. }
  43024. function _arrayWithHoles(r) {
  43025. if (Array.isArray(r)) return r;
  43026. }
  43027. function _arrayWithoutHoles(r) {
  43028. if (Array.isArray(r)) return _arrayLikeToArray(r);
  43029. }
  43030. function _assertClassBrand(e, t, n) {
  43031. if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n;
  43032. throw new TypeError("Private element is not present on this object");
  43033. }
  43034. function _assertThisInitialized(e) {
  43035. if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  43036. return e;
  43037. }
  43038. function _asyncGeneratorDelegate(t) {
  43039. var e = {},
  43040. n = !1;
  43041. function pump(e, r) {
  43042. return n = !0, r = new Promise(function (n) {
  43043. n(t[e](r));
  43044. }), {
  43045. done: !1,
  43046. value: new _OverloadYield(r, 1)
  43047. };
  43048. }
  43049. return e["undefined" != typeof Symbol && Symbol.iterator || "@@iterator"] = function () {
  43050. return this;
  43051. }, e.next = function (t) {
  43052. return n ? (n = !1, t) : pump("next", t);
  43053. }, "function" == typeof t.throw && (e.throw = function (t) {
  43054. if (n) throw n = !1, t;
  43055. return pump("throw", t);
  43056. }), "function" == typeof t.return && (e.return = function (t) {
  43057. return n ? (n = !1, t) : pump("return", t);
  43058. }), e;
  43059. }
  43060. function _asyncIterator(r) {
  43061. var n,
  43062. t,
  43063. o,
  43064. e = 2;
  43065. for ("undefined" != typeof Symbol && (t = Symbol.asyncIterator, o = Symbol.iterator); e--;) {
  43066. if (t && null != (n = r[t])) return n.call(r);
  43067. if (o && null != (n = r[o])) return new AsyncFromSyncIterator(n.call(r));
  43068. t = "@@asyncIterator", o = "@@iterator";
  43069. }
  43070. throw new TypeError("Object is not async iterable");
  43071. }
  43072. function AsyncFromSyncIterator(r) {
  43073. function AsyncFromSyncIteratorContinuation(r) {
  43074. if (Object(r) !== r) return Promise.reject(new TypeError(r + " is not an object."));
  43075. var n = r.done;
  43076. return Promise.resolve(r.value).then(function (r) {
  43077. return {
  43078. value: r,
  43079. done: n
  43080. };
  43081. });
  43082. }
  43083. return AsyncFromSyncIterator = function (r) {
  43084. this.s = r, this.n = r.next;
  43085. }, AsyncFromSyncIterator.prototype = {
  43086. s: null,
  43087. n: null,
  43088. next: function () {
  43089. return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments));
  43090. },
  43091. return: function (r) {
  43092. var n = this.s.return;
  43093. return void 0 === n ? Promise.resolve({
  43094. value: r,
  43095. done: !0
  43096. }) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments));
  43097. },
  43098. throw: function (r) {
  43099. var n = this.s.return;
  43100. return void 0 === n ? Promise.reject(r) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments));
  43101. }
  43102. }, new AsyncFromSyncIterator(r);
  43103. }
  43104. function asyncGeneratorStep(n, t, e, r, o, a, c) {
  43105. try {
  43106. var i = n[a](c),
  43107. u = i.value;
  43108. } catch (n) {
  43109. return void e(n);
  43110. }
  43111. i.done ? t(u) : Promise.resolve(u).then(r, o);
  43112. }
  43113. function _asyncToGenerator(n) {
  43114. return function () {
  43115. var t = this,
  43116. e = arguments;
  43117. return new Promise(function (r, o) {
  43118. var a = n.apply(t, e);
  43119. function _next(n) {
  43120. asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
  43121. }
  43122. function _throw(n) {
  43123. asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
  43124. }
  43125. _next(void 0);
  43126. });
  43127. };
  43128. }
  43129. function _awaitAsyncGenerator(e) {
  43130. return new _OverloadYield(e, 0);
  43131. }
  43132. function _callSuper(t, o, e) {
  43133. return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
  43134. }
  43135. function _checkInRHS(e) {
  43136. if (Object(e) !== e) throw TypeError("right-hand side of 'in' should be an object, got " + (null !== e ? typeof e : "null"));
  43137. return e;
  43138. }
  43139. function _checkPrivateRedeclaration(e, t) {
  43140. if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object");
  43141. }
  43142. function _classCallCheck(a, n) {
  43143. if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
  43144. }
  43145. function _classNameTDZError(e) {
  43146. throw new ReferenceError('Class "' + e + '" cannot be referenced in computed property keys.');
  43147. }
  43148. function _classPrivateFieldGet2(s, a) {
  43149. return s.get(_assertClassBrand(s, a));
  43150. }
  43151. function _classPrivateFieldInitSpec(e, t, a) {
  43152. _checkPrivateRedeclaration(e, t), t.set(e, a);
  43153. }
  43154. function _classPrivateFieldLooseBase(e, t) {
  43155. if (!{}.hasOwnProperty.call(e, t)) throw new TypeError("attempted to use private field on non-instance");
  43156. return e;
  43157. }
  43158. var id = 0;
  43159. function _classPrivateFieldLooseKey(e) {
  43160. return "__private_" + id++ + "_" + e;
  43161. }
  43162. function _classPrivateFieldSet2(s, a, r) {
  43163. return s.set(_assertClassBrand(s, a), r), r;
  43164. }
  43165. function _classPrivateGetter(s, r, a) {
  43166. return a(_assertClassBrand(s, r));
  43167. }
  43168. function _classPrivateMethodInitSpec(e, a) {
  43169. _checkPrivateRedeclaration(e, a), a.add(e);
  43170. }
  43171. function _classPrivateSetter(s, r, a, t) {
  43172. return r(_assertClassBrand(s, a), t), t;
  43173. }
  43174. function _classStaticPrivateMethodGet(s, a, t) {
  43175. return _assertClassBrand(a, s), t;
  43176. }
  43177. function _construct(t, e, r) {
  43178. if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments);
  43179. var o = [null];
  43180. o.push.apply(o, e);
  43181. var p = new (t.bind.apply(t, o))();
  43182. return r && _setPrototypeOf(p, r.prototype), p;
  43183. }
  43184. function _defineProperties(e, r) {
  43185. for (var t = 0; t < r.length; t++) {
  43186. var o = r[t];
  43187. o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
  43188. }
  43189. }
  43190. function _createClass(e, r, t) {
  43191. return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
  43192. writable: !1
  43193. }), e;
  43194. }
  43195. function _createForOfIteratorHelper(r, e) {
  43196. var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
  43197. if (!t) {
  43198. if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
  43199. t && (r = t);
  43200. var n = 0,
  43201. F = function () {};
  43202. return {
  43203. s: F,
  43204. n: function () {
  43205. return n >= r.length ? {
  43206. done: !0
  43207. } : {
  43208. done: !1,
  43209. value: r[n++]
  43210. };
  43211. },
  43212. e: function (r) {
  43213. throw r;
  43214. },
  43215. f: F
  43216. };
  43217. }
  43218. throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  43219. }
  43220. var o,
  43221. a = !0,
  43222. u = !1;
  43223. return {
  43224. s: function () {
  43225. t = t.call(r);
  43226. },
  43227. n: function () {
  43228. var r = t.next();
  43229. return a = r.done, r;
  43230. },
  43231. e: function (r) {
  43232. u = !0, o = r;
  43233. },
  43234. f: function () {
  43235. try {
  43236. a || null == t.return || t.return();
  43237. } finally {
  43238. if (u) throw o;
  43239. }
  43240. }
  43241. };
  43242. }
  43243. function _createForOfIteratorHelperLoose(r, e) {
  43244. var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
  43245. if (t) return (t = t.call(r)).next.bind(t);
  43246. if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
  43247. t && (r = t);
  43248. var o = 0;
  43249. return function () {
  43250. return o >= r.length ? {
  43251. done: !0
  43252. } : {
  43253. done: !1,
  43254. value: r[o++]
  43255. };
  43256. };
  43257. }
  43258. throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  43259. }
  43260. function _createSuper(t) {
  43261. var r = _isNativeReflectConstruct();
  43262. return function () {
  43263. var e,
  43264. o = _getPrototypeOf(t);
  43265. if (r) {
  43266. var s = _getPrototypeOf(this).constructor;
  43267. e = Reflect.construct(o, arguments, s);
  43268. } else e = o.apply(this, arguments);
  43269. return _possibleConstructorReturn(this, e);
  43270. };
  43271. }
  43272. function _decorate(e, r, t, i) {
  43273. var o = _getDecoratorsApi();
  43274. if (i) for (var n = 0; n < i.length; n++) o = i[n](o);
  43275. var s = r(function (e) {
  43276. o.initializeInstanceElements(e, a.elements);
  43277. }, t),
  43278. a = o.decorateClass(_coalesceClassElements(s.d.map(_createElementDescriptor)), e);
  43279. return o.initializeClassElements(s.F, a.elements), o.runClassFinishers(s.F, a.finishers);
  43280. }
  43281. function _getDecoratorsApi() {
  43282. _getDecoratorsApi = function () {
  43283. return e;
  43284. };
  43285. var e = {
  43286. elementsDefinitionOrder: [["method"], ["field"]],
  43287. initializeInstanceElements: function (e, r) {
  43288. ["method", "field"].forEach(function (t) {
  43289. r.forEach(function (r) {
  43290. r.kind === t && "own" === r.placement && this.defineClassElement(e, r);
  43291. }, this);
  43292. }, this);
  43293. },
  43294. initializeClassElements: function (e, r) {
  43295. var t = e.prototype;
  43296. ["method", "field"].forEach(function (i) {
  43297. r.forEach(function (r) {
  43298. var o = r.placement;
  43299. if (r.kind === i && ("static" === o || "prototype" === o)) {
  43300. var n = "static" === o ? e : t;
  43301. this.defineClassElement(n, r);
  43302. }
  43303. }, this);
  43304. }, this);
  43305. },
  43306. defineClassElement: function (e, r) {
  43307. var t = r.descriptor;
  43308. if ("field" === r.kind) {
  43309. var i = r.initializer;
  43310. t = {
  43311. enumerable: t.enumerable,
  43312. writable: t.writable,
  43313. configurable: t.configurable,
  43314. value: void 0 === i ? void 0 : i.call(e)
  43315. };
  43316. }
  43317. Object.defineProperty(e, r.key, t);
  43318. },
  43319. decorateClass: function (e, r) {
  43320. var t = [],
  43321. i = [],
  43322. o = {
  43323. static: [],
  43324. prototype: [],
  43325. own: []
  43326. };
  43327. if (e.forEach(function (e) {
  43328. this.addElementPlacement(e, o);
  43329. }, this), e.forEach(function (e) {
  43330. if (!_hasDecorators(e)) return t.push(e);
  43331. var r = this.decorateElement(e, o);
  43332. t.push(r.element), t.push.apply(t, r.extras), i.push.apply(i, r.finishers);
  43333. }, this), !r) return {
  43334. elements: t,
  43335. finishers: i
  43336. };
  43337. var n = this.decorateConstructor(t, r);
  43338. return i.push.apply(i, n.finishers), n.finishers = i, n;
  43339. },
  43340. addElementPlacement: function (e, r, t) {
  43341. var i = r[e.placement];
  43342. if (!t && -1 !== i.indexOf(e.key)) throw new TypeError("Duplicated element (" + e.key + ")");
  43343. i.push(e.key);
  43344. },
  43345. decorateElement: function (e, r) {
  43346. for (var t = [], i = [], o = e.decorators, n = o.length - 1; n >= 0; n--) {
  43347. var s = r[e.placement];
  43348. s.splice(s.indexOf(e.key), 1);
  43349. var a = this.fromElementDescriptor(e),
  43350. l = this.toElementFinisherExtras((0, o[n])(a) || a);
  43351. e = l.element, this.addElementPlacement(e, r), l.finisher && i.push(l.finisher);
  43352. var c = l.extras;
  43353. if (c) {
  43354. for (var p = 0; p < c.length; p++) this.addElementPlacement(c[p], r);
  43355. t.push.apply(t, c);
  43356. }
  43357. }
  43358. return {
  43359. element: e,
  43360. finishers: i,
  43361. extras: t
  43362. };
  43363. },
  43364. decorateConstructor: function (e, r) {
  43365. for (var t = [], i = r.length - 1; i >= 0; i--) {
  43366. var o = this.fromClassDescriptor(e),
  43367. n = this.toClassDescriptor((0, r[i])(o) || o);
  43368. if (void 0 !== n.finisher && t.push(n.finisher), void 0 !== n.elements) {
  43369. e = n.elements;
  43370. for (var s = 0; s < e.length - 1; s++) for (var a = s + 1; a < e.length; a++) if (e[s].key === e[a].key && e[s].placement === e[a].placement) throw new TypeError("Duplicated element (" + e[s].key + ")");
  43371. }
  43372. }
  43373. return {
  43374. elements: e,
  43375. finishers: t
  43376. };
  43377. },
  43378. fromElementDescriptor: function (e) {
  43379. var r = {
  43380. kind: e.kind,
  43381. key: e.key,
  43382. placement: e.placement,
  43383. descriptor: e.descriptor
  43384. };
  43385. return Object.defineProperty(r, Symbol.toStringTag, {
  43386. value: "Descriptor",
  43387. configurable: !0
  43388. }), "field" === e.kind && (r.initializer = e.initializer), r;
  43389. },
  43390. toElementDescriptors: function (e) {
  43391. if (void 0 !== e) return _toArray(e).map(function (e) {
  43392. var r = this.toElementDescriptor(e);
  43393. return this.disallowProperty(e, "finisher", "An element descriptor"), this.disallowProperty(e, "extras", "An element descriptor"), r;
  43394. }, this);
  43395. },
  43396. toElementDescriptor: function (e) {
  43397. var r = e.kind + "";
  43398. if ("method" !== r && "field" !== r) throw new TypeError('An element descriptor\'s .kind property must be either "method" or "field", but a decorator created an element descriptor with .kind "' + r + '"');
  43399. var t = _toPropertyKey(e.key),
  43400. i = e.placement + "";
  43401. if ("static" !== i && "prototype" !== i && "own" !== i) throw new TypeError('An element descriptor\'s .placement property must be one of "static", "prototype" or "own", but a decorator created an element descriptor with .placement "' + i + '"');
  43402. var o = e.descriptor;
  43403. this.disallowProperty(e, "elements", "An element descriptor");
  43404. var n = {
  43405. kind: r,
  43406. key: t,
  43407. placement: i,
  43408. descriptor: Object.assign({}, o)
  43409. };
  43410. return "field" !== r ? this.disallowProperty(e, "initializer", "A method descriptor") : (this.disallowProperty(o, "get", "The property descriptor of a field descriptor"), this.disallowProperty(o, "set", "The property descriptor of a field descriptor"), this.disallowProperty(o, "value", "The property descriptor of a field descriptor"), n.initializer = e.initializer), n;
  43411. },
  43412. toElementFinisherExtras: function (e) {
  43413. return {
  43414. element: this.toElementDescriptor(e),
  43415. finisher: _optionalCallableProperty(e, "finisher"),
  43416. extras: this.toElementDescriptors(e.extras)
  43417. };
  43418. },
  43419. fromClassDescriptor: function (e) {
  43420. var r = {
  43421. kind: "class",
  43422. elements: e.map(this.fromElementDescriptor, this)
  43423. };
  43424. return Object.defineProperty(r, Symbol.toStringTag, {
  43425. value: "Descriptor",
  43426. configurable: !0
  43427. }), r;
  43428. },
  43429. toClassDescriptor: function (e) {
  43430. var r = e.kind + "";
  43431. if ("class" !== r) throw new TypeError('A class descriptor\'s .kind property must be "class", but a decorator created a class descriptor with .kind "' + r + '"');
  43432. this.disallowProperty(e, "key", "A class descriptor"), this.disallowProperty(e, "placement", "A class descriptor"), this.disallowProperty(e, "descriptor", "A class descriptor"), this.disallowProperty(e, "initializer", "A class descriptor"), this.disallowProperty(e, "extras", "A class descriptor");
  43433. var t = _optionalCallableProperty(e, "finisher");
  43434. return {
  43435. elements: this.toElementDescriptors(e.elements),
  43436. finisher: t
  43437. };
  43438. },
  43439. runClassFinishers: function (e, r) {
  43440. for (var t = 0; t < r.length; t++) {
  43441. var i = (0, r[t])(e);
  43442. if (void 0 !== i) {
  43443. if ("function" != typeof i) throw new TypeError("Finishers must return a constructor.");
  43444. e = i;
  43445. }
  43446. }
  43447. return e;
  43448. },
  43449. disallowProperty: function (e, r, t) {
  43450. if (void 0 !== e[r]) throw new TypeError(t + " can't have a ." + r + " property.");
  43451. }
  43452. };
  43453. return e;
  43454. }
  43455. function _createElementDescriptor(e) {
  43456. var r,
  43457. t = _toPropertyKey(e.key);
  43458. "method" === e.kind ? r = {
  43459. value: e.value,
  43460. writable: !0,
  43461. configurable: !0,
  43462. enumerable: !1
  43463. } : "get" === e.kind ? r = {
  43464. get: e.value,
  43465. configurable: !0,
  43466. enumerable: !1
  43467. } : "set" === e.kind ? r = {
  43468. set: e.value,
  43469. configurable: !0,
  43470. enumerable: !1
  43471. } : "field" === e.kind && (r = {
  43472. configurable: !0,
  43473. writable: !0,
  43474. enumerable: !0
  43475. });
  43476. var i = {
  43477. kind: "field" === e.kind ? "field" : "method",
  43478. key: t,
  43479. placement: e.static ? "static" : "field" === e.kind ? "own" : "prototype",
  43480. descriptor: r
  43481. };
  43482. return e.decorators && (i.decorators = e.decorators), "field" === e.kind && (i.initializer = e.value), i;
  43483. }
  43484. function _coalesceGetterSetter(e, r) {
  43485. void 0 !== e.descriptor.get ? r.descriptor.get = e.descriptor.get : r.descriptor.set = e.descriptor.set;
  43486. }
  43487. function _coalesceClassElements(e) {
  43488. for (var r = [], isSameElement = function (e) {
  43489. return "method" === e.kind && e.key === o.key && e.placement === o.placement;
  43490. }, t = 0; t < e.length; t++) {
  43491. var i,
  43492. o = e[t];
  43493. if ("method" === o.kind && (i = r.find(isSameElement))) {
  43494. if (_isDataDescriptor(o.descriptor) || _isDataDescriptor(i.descriptor)) {
  43495. if (_hasDecorators(o) || _hasDecorators(i)) throw new ReferenceError("Duplicated methods (" + o.key + ") can't be decorated.");
  43496. i.descriptor = o.descriptor;
  43497. } else {
  43498. if (_hasDecorators(o)) {
  43499. if (_hasDecorators(i)) throw new ReferenceError("Decorators can't be placed on different accessors with for the same property (" + o.key + ").");
  43500. i.decorators = o.decorators;
  43501. }
  43502. _coalesceGetterSetter(o, i);
  43503. }
  43504. } else r.push(o);
  43505. }
  43506. return r;
  43507. }
  43508. function _hasDecorators(e) {
  43509. return e.decorators && e.decorators.length;
  43510. }
  43511. function _isDataDescriptor(e) {
  43512. return void 0 !== e && !(void 0 === e.value && void 0 === e.writable);
  43513. }
  43514. function _optionalCallableProperty(e, r) {
  43515. var t = e[r];
  43516. if (void 0 !== t && "function" != typeof t) throw new TypeError("Expected '" + r + "' to be a function");
  43517. return t;
  43518. }
  43519. function _defaults(e, r) {
  43520. for (var t = Object.getOwnPropertyNames(r), o = 0; o < t.length; o++) {
  43521. var n = t[o],
  43522. a = Object.getOwnPropertyDescriptor(r, n);
  43523. a && a.configurable && void 0 === e[n] && Object.defineProperty(e, n, a);
  43524. }
  43525. return e;
  43526. }
  43527. function _defineAccessor(e, r, n, t) {
  43528. var c = {
  43529. configurable: !0,
  43530. enumerable: !0
  43531. };
  43532. return c[e] = t, Object.defineProperty(r, n, c);
  43533. }
  43534. function _defineProperty(e, r, t) {
  43535. return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
  43536. value: t,
  43537. enumerable: !0,
  43538. configurable: !0,
  43539. writable: !0
  43540. }) : e[r] = t, e;
  43541. }
  43542. function _extends() {
  43543. return _extends = Object.assign ? Object.assign.bind() : function (n) {
  43544. for (var e = 1; e < arguments.length; e++) {
  43545. var t = arguments[e];
  43546. for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
  43547. }
  43548. return n;
  43549. }, _extends.apply(null, arguments);
  43550. }
  43551. function _get() {
  43552. return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) {
  43553. var p = _superPropBase(e, t);
  43554. if (p) {
  43555. var n = Object.getOwnPropertyDescriptor(p, t);
  43556. return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value;
  43557. }
  43558. }, _get.apply(null, arguments);
  43559. }
  43560. function _getPrototypeOf(t) {
  43561. return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
  43562. return t.__proto__ || Object.getPrototypeOf(t);
  43563. }, _getPrototypeOf(t);
  43564. }
  43565. function _identity(t) {
  43566. return t;
  43567. }
  43568. function _importDeferProxy(e) {
  43569. var t = null,
  43570. constValue = function (e) {
  43571. return function () {
  43572. return e;
  43573. };
  43574. },
  43575. proxy = function (r) {
  43576. return function (n, o, f) {
  43577. return null === t && (t = e()), r(t, o, f);
  43578. };
  43579. };
  43580. return new Proxy({}, {
  43581. defineProperty: constValue(!1),
  43582. deleteProperty: constValue(!1),
  43583. get: proxy(Reflect.get),
  43584. getOwnPropertyDescriptor: proxy(Reflect.getOwnPropertyDescriptor),
  43585. getPrototypeOf: constValue(null),
  43586. isExtensible: constValue(!1),
  43587. has: proxy(Reflect.has),
  43588. ownKeys: proxy(Reflect.ownKeys),
  43589. preventExtensions: constValue(!0),
  43590. set: constValue(!1),
  43591. setPrototypeOf: constValue(!1)
  43592. });
  43593. }
  43594. function _inherits(t, e) {
  43595. if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
  43596. t.prototype = Object.create(e && e.prototype, {
  43597. constructor: {
  43598. value: t,
  43599. writable: !0,
  43600. configurable: !0
  43601. }
  43602. }), Object.defineProperty(t, "prototype", {
  43603. writable: !1
  43604. }), e && _setPrototypeOf(t, e);
  43605. }
  43606. function _inheritsLoose(t, o) {
  43607. t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o);
  43608. }
  43609. function _initializerDefineProperty(e, i, r, l) {
  43610. r && Object.defineProperty(e, i, {
  43611. enumerable: r.enumerable,
  43612. configurable: r.configurable,
  43613. writable: r.writable,
  43614. value: r.initializer ? r.initializer.call(l) : void 0
  43615. });
  43616. }
  43617. function _initializerWarningHelper(r, e) {
  43618. throw Error("Decorating class property failed. Please ensure that transform-class-properties is enabled and runs after the decorators transform.");
  43619. }
  43620. function _instanceof(n, e) {
  43621. return null != e && "undefined" != typeof Symbol && e[Symbol.hasInstance] ? !!e[Symbol.hasInstance](n) : n instanceof e;
  43622. }
  43623. function _interopRequireDefault(e) {
  43624. return e && e.__esModule ? e : {
  43625. default: e
  43626. };
  43627. }
  43628. function _getRequireWildcardCache(e) {
  43629. if ("function" != typeof WeakMap) return null;
  43630. var r = new WeakMap(),
  43631. t = new WeakMap();
  43632. return (_getRequireWildcardCache = function (e) {
  43633. return e ? t : r;
  43634. })(e);
  43635. }
  43636. function _interopRequireWildcard(e, r) {
  43637. if (!r && e && e.__esModule) return e;
  43638. if (null === e || "object" != typeof e && "function" != typeof e) return {
  43639. default: e
  43640. };
  43641. var t = _getRequireWildcardCache(r);
  43642. if (t && t.has(e)) return t.get(e);
  43643. var n = {
  43644. __proto__: null
  43645. },
  43646. a = Object.defineProperty && Object.getOwnPropertyDescriptor;
  43647. for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
  43648. var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
  43649. i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u];
  43650. }
  43651. return n.default = e, t && t.set(e, n), n;
  43652. }
  43653. function _isNativeFunction(t) {
  43654. try {
  43655. return -1 !== Function.toString.call(t).indexOf("[native code]");
  43656. } catch (n) {
  43657. return "function" == typeof t;
  43658. }
  43659. }
  43660. function _isNativeReflectConstruct() {
  43661. try {
  43662. var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
  43663. } catch (t) {}
  43664. return (_isNativeReflectConstruct = function () {
  43665. return !!t;
  43666. })();
  43667. }
  43668. function _iterableToArray(r) {
  43669. if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
  43670. }
  43671. function _iterableToArrayLimit(r, l) {
  43672. var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
  43673. if (null != t) {
  43674. var e,
  43675. n,
  43676. i,
  43677. u,
  43678. a = [],
  43679. f = !0,
  43680. o = !1;
  43681. try {
  43682. if (i = (t = t.call(r)).next, 0 === l) {
  43683. if (Object(t) !== t) return;
  43684. f = !1;
  43685. } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
  43686. } catch (r) {
  43687. o = !0, n = r;
  43688. } finally {
  43689. try {
  43690. if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
  43691. } finally {
  43692. if (o) throw n;
  43693. }
  43694. }
  43695. return a;
  43696. }
  43697. }
  43698. var REACT_ELEMENT_TYPE;
  43699. function _jsx(e, r, E, l) {
  43700. REACT_ELEMENT_TYPE || (REACT_ELEMENT_TYPE = "function" == typeof Symbol && Symbol.for && Symbol.for("react.element") || 60103);
  43701. var o = e && e.defaultProps,
  43702. n = arguments.length - 3;
  43703. if (r || 0 === n || (r = {
  43704. children: void 0
  43705. }), 1 === n) r.children = l;else if (n > 1) {
  43706. for (var t = Array(n), f = 0; f < n; f++) t[f] = arguments[f + 3];
  43707. r.children = t;
  43708. }
  43709. if (r && o) for (var i in o) void 0 === r[i] && (r[i] = o[i]);else r || (r = o || {});
  43710. return {
  43711. $$typeof: REACT_ELEMENT_TYPE,
  43712. type: e,
  43713. key: void 0 === E ? null : "" + E,
  43714. ref: null,
  43715. props: r,
  43716. _owner: null
  43717. };
  43718. }
  43719. function _maybeArrayLike(r, a, e) {
  43720. if (a && !Array.isArray(a) && "number" == typeof a.length) {
  43721. var y = a.length;
  43722. return _arrayLikeToArray(a, void 0 !== e && e < y ? e : y);
  43723. }
  43724. return r(a, e);
  43725. }
  43726. function _newArrowCheck(n, r) {
  43727. if (n !== r) throw new TypeError("Cannot instantiate an arrow function");
  43728. }
  43729. function _nonIterableRest() {
  43730. throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  43731. }
  43732. function _nonIterableSpread() {
  43733. throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  43734. }
  43735. function _nullishReceiverError(r) {
  43736. throw new TypeError("Cannot set property of null or undefined.");
  43737. }
  43738. function _objectDestructuringEmpty(t) {
  43739. if (null == t) throw new TypeError("Cannot destructure " + t);
  43740. }
  43741. function ownKeys(e, r) {
  43742. var t = Object.keys(e);
  43743. if (Object.getOwnPropertySymbols) {
  43744. var o = Object.getOwnPropertySymbols(e);
  43745. r && (o = o.filter(function (r) {
  43746. return Object.getOwnPropertyDescriptor(e, r).enumerable;
  43747. })), t.push.apply(t, o);
  43748. }
  43749. return t;
  43750. }
  43751. function _objectSpread2(e) {
  43752. for (var r = 1; r < arguments.length; r++) {
  43753. var t = null != arguments[r] ? arguments[r] : {};
  43754. r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
  43755. _defineProperty(e, r, t[r]);
  43756. }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
  43757. Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
  43758. });
  43759. }
  43760. return e;
  43761. }
  43762. function _objectWithoutProperties(e, t) {
  43763. if (null == e) return {};
  43764. var o,
  43765. r,
  43766. i = _objectWithoutPropertiesLoose(e, t);
  43767. if (Object.getOwnPropertySymbols) {
  43768. var s = Object.getOwnPropertySymbols(e);
  43769. for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
  43770. }
  43771. return i;
  43772. }
  43773. function _objectWithoutPropertiesLoose(r, e) {
  43774. if (null == r) return {};
  43775. var t = {};
  43776. for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
  43777. if (e.includes(n)) continue;
  43778. t[n] = r[n];
  43779. }
  43780. return t;
  43781. }
  43782. function _possibleConstructorReturn(t, e) {
  43783. if (e && ("object" == typeof e || "function" == typeof e)) return e;
  43784. if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
  43785. return _assertThisInitialized(t);
  43786. }
  43787. function _readOnlyError(r) {
  43788. throw new TypeError('"' + r + '" is read-only');
  43789. }
  43790. function _regeneratorRuntime() {
  43791. "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
  43792. _regeneratorRuntime = function () {
  43793. return e;
  43794. };
  43795. var t,
  43796. e = {},
  43797. r = Object.prototype,
  43798. n = r.hasOwnProperty,
  43799. o = Object.defineProperty || function (t, e, r) {
  43800. t[e] = r.value;
  43801. },
  43802. i = "function" == typeof Symbol ? Symbol : {},
  43803. a = i.iterator || "@@iterator",
  43804. c = i.asyncIterator || "@@asyncIterator",
  43805. u = i.toStringTag || "@@toStringTag";
  43806. function define(t, e, r) {
  43807. return Object.defineProperty(t, e, {
  43808. value: r,
  43809. enumerable: !0,
  43810. configurable: !0,
  43811. writable: !0
  43812. }), t[e];
  43813. }
  43814. try {
  43815. define({}, "");
  43816. } catch (t) {
  43817. define = function (t, e, r) {
  43818. return t[e] = r;
  43819. };
  43820. }
  43821. function wrap(t, e, r, n) {
  43822. var i = e && e.prototype instanceof Generator ? e : Generator,
  43823. a = Object.create(i.prototype),
  43824. c = new Context(n || []);
  43825. return o(a, "_invoke", {
  43826. value: makeInvokeMethod(t, r, c)
  43827. }), a;
  43828. }
  43829. function tryCatch(t, e, r) {
  43830. try {
  43831. return {
  43832. type: "normal",
  43833. arg: t.call(e, r)
  43834. };
  43835. } catch (t) {
  43836. return {
  43837. type: "throw",
  43838. arg: t
  43839. };
  43840. }
  43841. }
  43842. e.wrap = wrap;
  43843. var h = "suspendedStart",
  43844. l = "suspendedYield",
  43845. f = "executing",
  43846. s = "completed",
  43847. y = {};
  43848. function Generator() {}
  43849. function GeneratorFunction() {}
  43850. function GeneratorFunctionPrototype() {}
  43851. var p = {};
  43852. define(p, a, function () {
  43853. return this;
  43854. });
  43855. var d = Object.getPrototypeOf,
  43856. v = d && d(d(values([])));
  43857. v && v !== r && n.call(v, a) && (p = v);
  43858. var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
  43859. function defineIteratorMethods(t) {
  43860. ["next", "throw", "return"].forEach(function (e) {
  43861. define(t, e, function (t) {
  43862. return this._invoke(e, t);
  43863. });
  43864. });
  43865. }
  43866. function AsyncIterator(t, e) {
  43867. function invoke(r, o, i, a) {
  43868. var c = tryCatch(t[r], t, o);
  43869. if ("throw" !== c.type) {
  43870. var u = c.arg,
  43871. h = u.value;
  43872. return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
  43873. invoke("next", t, i, a);
  43874. }, function (t) {
  43875. invoke("throw", t, i, a);
  43876. }) : e.resolve(h).then(function (t) {
  43877. u.value = t, i(u);
  43878. }, function (t) {
  43879. return invoke("throw", t, i, a);
  43880. });
  43881. }
  43882. a(c.arg);
  43883. }
  43884. var r;
  43885. o(this, "_invoke", {
  43886. value: function (t, n) {
  43887. function callInvokeWithMethodAndArg() {
  43888. return new e(function (e, r) {
  43889. invoke(t, n, e, r);
  43890. });
  43891. }
  43892. return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
  43893. }
  43894. });
  43895. }
  43896. function makeInvokeMethod(e, r, n) {
  43897. var o = h;
  43898. return function (i, a) {
  43899. if (o === f) throw Error("Generator is already running");
  43900. if (o === s) {
  43901. if ("throw" === i) throw a;
  43902. return {
  43903. value: t,
  43904. done: !0
  43905. };
  43906. }
  43907. for (n.method = i, n.arg = a;;) {
  43908. var c = n.delegate;
  43909. if (c) {
  43910. var u = maybeInvokeDelegate(c, n);
  43911. if (u) {
  43912. if (u === y) continue;
  43913. return u;
  43914. }
  43915. }
  43916. if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
  43917. if (o === h) throw o = s, n.arg;
  43918. n.dispatchException(n.arg);
  43919. } else "return" === n.method && n.abrupt("return", n.arg);
  43920. o = f;
  43921. var p = tryCatch(e, r, n);
  43922. if ("normal" === p.type) {
  43923. if (o = n.done ? s : l, p.arg === y) continue;
  43924. return {
  43925. value: p.arg,
  43926. done: n.done
  43927. };
  43928. }
  43929. "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
  43930. }
  43931. };
  43932. }
  43933. function maybeInvokeDelegate(e, r) {
  43934. var n = r.method,
  43935. o = e.iterator[n];
  43936. if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
  43937. var i = tryCatch(o, e.iterator, r.arg);
  43938. if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
  43939. var a = i.arg;
  43940. return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
  43941. }
  43942. function pushTryEntry(t) {
  43943. var e = {
  43944. tryLoc: t[0]
  43945. };
  43946. 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
  43947. }
  43948. function resetTryEntry(t) {
  43949. var e = t.completion || {};
  43950. e.type = "normal", delete e.arg, t.completion = e;
  43951. }
  43952. function Context(t) {
  43953. this.tryEntries = [{
  43954. tryLoc: "root"
  43955. }], t.forEach(pushTryEntry, this), this.reset(!0);
  43956. }
  43957. function values(e) {
  43958. if (e || "" === e) {
  43959. var r = e[a];
  43960. if (r) return r.call(e);
  43961. if ("function" == typeof e.next) return e;
  43962. if (!isNaN(e.length)) {
  43963. var o = -1,
  43964. i = function next() {
  43965. for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
  43966. return next.value = t, next.done = !0, next;
  43967. };
  43968. return i.next = i;
  43969. }
  43970. }
  43971. throw new TypeError(typeof e + " is not iterable");
  43972. }
  43973. return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
  43974. value: GeneratorFunctionPrototype,
  43975. configurable: !0
  43976. }), o(GeneratorFunctionPrototype, "constructor", {
  43977. value: GeneratorFunction,
  43978. configurable: !0
  43979. }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
  43980. var e = "function" == typeof t && t.constructor;
  43981. return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
  43982. }, e.mark = function (t) {
  43983. return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
  43984. }, e.awrap = function (t) {
  43985. return {
  43986. __await: t
  43987. };
  43988. }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
  43989. return this;
  43990. }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
  43991. void 0 === i && (i = Promise);
  43992. var a = new AsyncIterator(wrap(t, r, n, o), i);
  43993. return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
  43994. return t.done ? t.value : a.next();
  43995. });
  43996. }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
  43997. return this;
  43998. }), define(g, "toString", function () {
  43999. return "[object Generator]";
  44000. }), e.keys = function (t) {
  44001. var e = Object(t),
  44002. r = [];
  44003. for (var n in e) r.push(n);
  44004. return r.reverse(), function next() {
  44005. for (; r.length;) {
  44006. var t = r.pop();
  44007. if (t in e) return next.value = t, next.done = !1, next;
  44008. }
  44009. return next.done = !0, next;
  44010. };
  44011. }, e.values = values, Context.prototype = {
  44012. constructor: Context,
  44013. reset: function (e) {
  44014. if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
  44015. },
  44016. stop: function () {
  44017. this.done = !0;
  44018. var t = this.tryEntries[0].completion;
  44019. if ("throw" === t.type) throw t.arg;
  44020. return this.rval;
  44021. },
  44022. dispatchException: function (e) {
  44023. if (this.done) throw e;
  44024. var r = this;
  44025. function handle(n, o) {
  44026. return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
  44027. }
  44028. for (var o = this.tryEntries.length - 1; o >= 0; --o) {
  44029. var i = this.tryEntries[o],
  44030. a = i.completion;
  44031. if ("root" === i.tryLoc) return handle("end");
  44032. if (i.tryLoc <= this.prev) {
  44033. var c = n.call(i, "catchLoc"),
  44034. u = n.call(i, "finallyLoc");
  44035. if (c && u) {
  44036. if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
  44037. if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
  44038. } else if (c) {
  44039. if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
  44040. } else {
  44041. if (!u) throw Error("try statement without catch or finally");
  44042. if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
  44043. }
  44044. }
  44045. }
  44046. },
  44047. abrupt: function (t, e) {
  44048. for (var r = this.tryEntries.length - 1; r >= 0; --r) {
  44049. var o = this.tryEntries[r];
  44050. if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
  44051. var i = o;
  44052. break;
  44053. }
  44054. }
  44055. i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
  44056. var a = i ? i.completion : {};
  44057. return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
  44058. },
  44059. complete: function (t, e) {
  44060. if ("throw" === t.type) throw t.arg;
  44061. return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
  44062. },
  44063. finish: function (t) {
  44064. for (var e = this.tryEntries.length - 1; e >= 0; --e) {
  44065. var r = this.tryEntries[e];
  44066. if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
  44067. }
  44068. },
  44069. catch: function (t) {
  44070. for (var e = this.tryEntries.length - 1; e >= 0; --e) {
  44071. var r = this.tryEntries[e];
  44072. if (r.tryLoc === t) {
  44073. var n = r.completion;
  44074. if ("throw" === n.type) {
  44075. var o = n.arg;
  44076. resetTryEntry(r);
  44077. }
  44078. return o;
  44079. }
  44080. }
  44081. throw Error("illegal catch attempt");
  44082. },
  44083. delegateYield: function (e, r, n) {
  44084. return this.delegate = {
  44085. iterator: values(e),
  44086. resultName: r,
  44087. nextLoc: n
  44088. }, "next" === this.method && (this.arg = t), y;
  44089. }
  44090. }, e;
  44091. }
  44092. function set(e, r, t, o) {
  44093. return set = "undefined" != typeof Reflect && Reflect.set ? Reflect.set : function (e, r, t, o) {
  44094. var f,
  44095. i = _superPropBase(e, r);
  44096. if (i) {
  44097. if ((f = Object.getOwnPropertyDescriptor(i, r)).set) return f.set.call(o, t), !0;
  44098. if (!f.writable) return !1;
  44099. }
  44100. if (f = Object.getOwnPropertyDescriptor(o, r)) {
  44101. if (!f.writable) return !1;
  44102. f.value = t, Object.defineProperty(o, r, f);
  44103. } else _defineProperty(o, r, t);
  44104. return !0;
  44105. }, set(e, r, t, o);
  44106. }
  44107. function _set(e, r, t, o, f) {
  44108. if (!set(e, r, t, o || e) && f) throw new TypeError("failed to set property");
  44109. return t;
  44110. }
  44111. function _setFunctionName(e, t, n) {
  44112. "symbol" == typeof t && (t = (t = t.description) ? "[" + t + "]" : "");
  44113. try {
  44114. Object.defineProperty(e, "name", {
  44115. configurable: !0,
  44116. value: n ? n + " " + t : t
  44117. });
  44118. } catch (e) {}
  44119. return e;
  44120. }
  44121. function _setPrototypeOf(t, e) {
  44122. return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
  44123. return t.__proto__ = e, t;
  44124. }, _setPrototypeOf(t, e);
  44125. }
  44126. function _skipFirstGeneratorNext(t) {
  44127. return function () {
  44128. var r = t.apply(this, arguments);
  44129. return r.next(), r;
  44130. };
  44131. }
  44132. function _slicedToArray(r, e) {
  44133. return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
  44134. }
  44135. function _superPropBase(t, o) {
  44136. for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t)););
  44137. return t;
  44138. }
  44139. function _superPropGet(t, e, r, o) {
  44140. var p = _get(_getPrototypeOf(1 & o ? t.prototype : t), e, r);
  44141. return 2 & o ? function (t) {
  44142. return p.apply(r, t);
  44143. } : p;
  44144. }
  44145. function _superPropSet(t, e, o, r, p, f) {
  44146. return _set(_getPrototypeOf(f ? t.prototype : t), e, o, r, p);
  44147. }
  44148. function _taggedTemplateLiteral(e, t) {
  44149. return t || (t = e.slice(0)), Object.freeze(Object.defineProperties(e, {
  44150. raw: {
  44151. value: Object.freeze(t)
  44152. }
  44153. }));
  44154. }
  44155. function _taggedTemplateLiteralLoose(e, t) {
  44156. return t || (t = e.slice(0)), e.raw = t, e;
  44157. }
  44158. function _tdz(e) {
  44159. throw new ReferenceError(e + " is not defined - temporal dead zone");
  44160. }
  44161. function _temporalRef(r, e) {
  44162. return r === _temporalUndefined ? _tdz(e) : r;
  44163. }
  44164. function _temporalUndefined() {}
  44165. function _toArray(r) {
  44166. return _arrayWithHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableRest();
  44167. }
  44168. function _toConsumableArray(r) {
  44169. return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
  44170. }
  44171. function _toPrimitive(t, r) {
  44172. if ("object" != typeof t || !t) return t;
  44173. var e = t[Symbol.toPrimitive];
  44174. if (void 0 !== e) {
  44175. var i = e.call(t, r || "default");
  44176. if ("object" != typeof i) return i;
  44177. throw new TypeError("@@toPrimitive must return a primitive value.");
  44178. }
  44179. return ("string" === r ? String : Number)(t);
  44180. }
  44181. function _toPropertyKey(t) {
  44182. var i = _toPrimitive(t, "string");
  44183. return "symbol" == typeof i ? i : i + "";
  44184. }
  44185. function _toSetter(t, e, n) {
  44186. e || (e = []);
  44187. var r = e.length++;
  44188. return Object.defineProperty({}, "_", {
  44189. set: function (o) {
  44190. e[r] = o, t.apply(n, e);
  44191. }
  44192. });
  44193. }
  44194. function _typeof(o) {
  44195. "@babel/helpers - typeof";
  44196. return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
  44197. return typeof o;
  44198. } : function (o) {
  44199. return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
  44200. }, _typeof(o);
  44201. }
  44202. function _unsupportedIterableToArray(r, a) {
  44203. if (r) {
  44204. if ("string" == typeof r) return _arrayLikeToArray(r, a);
  44205. var t = {}.toString.call(r).slice(8, -1);
  44206. return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
  44207. }
  44208. }
  44209. function _usingCtx() {
  44210. var r = "function" == typeof SuppressedError ? SuppressedError : function (r, e) {
  44211. var n = Error();
  44212. return n.name = "SuppressedError", n.error = r, n.suppressed = e, n;
  44213. },
  44214. e = {},
  44215. n = [];
  44216. function using(r, e) {
  44217. if (null != e) {
  44218. if (Object(e) !== e) throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
  44219. if (r) var o = e[Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")];
  44220. if (void 0 === o && (o = e[Symbol.dispose || Symbol.for("Symbol.dispose")], r)) var t = o;
  44221. if ("function" != typeof o) throw new TypeError("Object is not disposable.");
  44222. t && (o = function () {
  44223. try {
  44224. t.call(e);
  44225. } catch (r) {
  44226. return Promise.reject(r);
  44227. }
  44228. }), n.push({
  44229. v: e,
  44230. d: o,
  44231. a: r
  44232. });
  44233. } else r && n.push({
  44234. d: e,
  44235. a: r
  44236. });
  44237. return e;
  44238. }
  44239. return {
  44240. e: e,
  44241. u: using.bind(null, !1),
  44242. a: using.bind(null, !0),
  44243. d: function () {
  44244. var o,
  44245. t = this.e,
  44246. s = 0;
  44247. function next() {
  44248. for (; o = n.pop();) try {
  44249. if (!o.a && 1 === s) return s = 0, n.push(o), Promise.resolve().then(next);
  44250. if (o.d) {
  44251. var r = o.d.call(o.v);
  44252. if (o.a) return s |= 2, Promise.resolve(r).then(next, err);
  44253. } else s |= 1;
  44254. } catch (r) {
  44255. return err(r);
  44256. }
  44257. if (1 === s) return t !== e ? Promise.reject(t) : Promise.resolve();
  44258. if (t !== e) throw t;
  44259. }
  44260. function err(n) {
  44261. return t = t !== e ? new r(n, t) : n, next();
  44262. }
  44263. return next();
  44264. }
  44265. };
  44266. }
  44267. function _wrapAsyncGenerator(e) {
  44268. return function () {
  44269. return new AsyncGenerator(e.apply(this, arguments));
  44270. };
  44271. }
  44272. function AsyncGenerator(e) {
  44273. var r, t;
  44274. function resume(r, t) {
  44275. try {
  44276. var n = e[r](t),
  44277. o = n.value,
  44278. u = o instanceof _OverloadYield;
  44279. Promise.resolve(u ? o.v : o).then(function (t) {
  44280. if (u) {
  44281. var i = "return" === r ? "return" : "next";
  44282. if (!o.k || t.done) return resume(i, t);
  44283. t = e[i](t).value;
  44284. }
  44285. settle(n.done ? "return" : "normal", t);
  44286. }, function (e) {
  44287. resume("throw", e);
  44288. });
  44289. } catch (e) {
  44290. settle("throw", e);
  44291. }
  44292. }
  44293. function settle(e, n) {
  44294. switch (e) {
  44295. case "return":
  44296. r.resolve({
  44297. value: n,
  44298. done: !0
  44299. });
  44300. break;
  44301. case "throw":
  44302. r.reject(n);
  44303. break;
  44304. default:
  44305. r.resolve({
  44306. value: n,
  44307. done: !1
  44308. });
  44309. }
  44310. (r = r.next) ? resume(r.key, r.arg) : t = null;
  44311. }
  44312. this._invoke = function (e, n) {
  44313. return new Promise(function (o, u) {
  44314. var i = {
  44315. key: e,
  44316. arg: n,
  44317. resolve: o,
  44318. reject: u,
  44319. next: null
  44320. };
  44321. t ? t = t.next = i : (r = t = i, resume(e, n));
  44322. });
  44323. }, "function" != typeof e.return && (this.return = void 0);
  44324. }
  44325. AsyncGenerator.prototype["function" == typeof Symbol && Symbol.asyncIterator || "@@asyncIterator"] = function () {
  44326. return this;
  44327. }, AsyncGenerator.prototype.next = function (e) {
  44328. return this._invoke("next", e);
  44329. }, AsyncGenerator.prototype.throw = function (e) {
  44330. return this._invoke("throw", e);
  44331. }, AsyncGenerator.prototype.return = function (e) {
  44332. return this._invoke("return", e);
  44333. };
  44334. function _wrapNativeSuper(t) {
  44335. var r = "function" == typeof Map ? new Map() : void 0;
  44336. return _wrapNativeSuper = function (t) {
  44337. if (null === t || !_isNativeFunction(t)) return t;
  44338. if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function");
  44339. if (void 0 !== r) {
  44340. if (r.has(t)) return r.get(t);
  44341. r.set(t, Wrapper);
  44342. }
  44343. function Wrapper() {
  44344. return _construct(t, arguments, _getPrototypeOf(this).constructor);
  44345. }
  44346. return Wrapper.prototype = Object.create(t.prototype, {
  44347. constructor: {
  44348. value: Wrapper,
  44349. enumerable: !1,
  44350. writable: !0,
  44351. configurable: !0
  44352. }
  44353. }), _setPrototypeOf(Wrapper, t);
  44354. }, _wrapNativeSuper(t);
  44355. }
  44356. function _wrapRegExp() {
  44357. _wrapRegExp = function (e, r) {
  44358. return new BabelRegExp(e, void 0, r);
  44359. };
  44360. var e = RegExp.prototype,
  44361. r = new WeakMap();
  44362. function BabelRegExp(e, t, p) {
  44363. var o = RegExp(e, t);
  44364. return r.set(o, p || r.get(e)), _setPrototypeOf(o, BabelRegExp.prototype);
  44365. }
  44366. function buildGroups(e, t) {
  44367. var p = r.get(t);
  44368. return Object.keys(p).reduce(function (r, t) {
  44369. var o = p[t];
  44370. if ("number" == typeof o) r[t] = e[o];else {
  44371. for (var i = 0; void 0 === e[o[i]] && i + 1 < o.length;) i++;
  44372. r[t] = e[o[i]];
  44373. }
  44374. return r;
  44375. }, Object.create(null));
  44376. }
  44377. return _inherits(BabelRegExp, RegExp), BabelRegExp.prototype.exec = function (r) {
  44378. var t = e.exec.call(this, r);
  44379. if (t) {
  44380. t.groups = buildGroups(t, this);
  44381. var p = t.indices;
  44382. p && (p.groups = buildGroups(p, this));
  44383. }
  44384. return t;
  44385. }, BabelRegExp.prototype[Symbol.replace] = function (t, p) {
  44386. if ("string" == typeof p) {
  44387. var o = r.get(this);
  44388. return e[Symbol.replace].call(this, t, p.replace(/\$<([^>]+)>/g, function (e, r) {
  44389. var t = o[r];
  44390. return "$" + (Array.isArray(t) ? t.join("$") : t);
  44391. }));
  44392. }
  44393. if ("function" == typeof p) {
  44394. var i = this;
  44395. return e[Symbol.replace].call(this, t, function () {
  44396. var e = arguments;
  44397. return "object" != typeof e[e.length - 1] && (e = [].slice.call(e)).push(buildGroups(e, i)), p.apply(this, e);
  44398. });
  44399. }
  44400. return e[Symbol.replace].call(this, t, p);
  44401. }, _wrapRegExp.apply(this, arguments);
  44402. }
  44403. function _writeOnlyError(r) {
  44404. throw new TypeError('"' + r + '" is write-only');
  44405. }
  44406. function _AwaitValue(t) {
  44407. this.wrapped = t;
  44408. }
  44409. function old_createMetadataMethodsForProperty(e, t, a, r) {
  44410. return {
  44411. getMetadata: function (o) {
  44412. old_assertNotFinished(r, "getMetadata"), old_assertMetadataKey(o);
  44413. var i = e[o];
  44414. if (void 0 !== i) if (1 === t) {
  44415. var n = i.public;
  44416. if (void 0 !== n) return n[a];
  44417. } else if (2 === t) {
  44418. var l = i.private;
  44419. if (void 0 !== l) return l.get(a);
  44420. } else if (Object.hasOwnProperty.call(i, "constructor")) return i.constructor;
  44421. },
  44422. setMetadata: function (o, i) {
  44423. old_assertNotFinished(r, "setMetadata"), old_assertMetadataKey(o);
  44424. var n = e[o];
  44425. if (void 0 === n && (n = e[o] = {}), 1 === t) {
  44426. var l = n.public;
  44427. void 0 === l && (l = n.public = {}), l[a] = i;
  44428. } else if (2 === t) {
  44429. var s = n.priv;
  44430. void 0 === s && (s = n.private = new Map()), s.set(a, i);
  44431. } else n.constructor = i;
  44432. }
  44433. };
  44434. }
  44435. function old_convertMetadataMapToFinal(e, t) {
  44436. var a = e[Symbol.metadata || Symbol.for("Symbol.metadata")],
  44437. r = Object.getOwnPropertySymbols(t);
  44438. if (0 !== r.length) {
  44439. for (var o = 0; o < r.length; o++) {
  44440. var i = r[o],
  44441. n = t[i],
  44442. l = a ? a[i] : null,
  44443. s = n.public,
  44444. c = l ? l.public : null;
  44445. s && c && Object.setPrototypeOf(s, c);
  44446. var d = n.private;
  44447. if (d) {
  44448. var u = Array.from(d.values()),
  44449. f = l ? l.private : null;
  44450. f && (u = u.concat(f)), n.private = u;
  44451. }
  44452. l && Object.setPrototypeOf(n, l);
  44453. }
  44454. a && Object.setPrototypeOf(t, a), e[Symbol.metadata || Symbol.for("Symbol.metadata")] = t;
  44455. }
  44456. }
  44457. function old_createAddInitializerMethod(e, t) {
  44458. return function (a) {
  44459. old_assertNotFinished(t, "addInitializer"), old_assertCallable(a, "An initializer"), e.push(a);
  44460. };
  44461. }
  44462. function old_memberDec(e, t, a, r, o, i, n, l, s) {
  44463. var c;
  44464. switch (i) {
  44465. case 1:
  44466. c = "accessor";
  44467. break;
  44468. case 2:
  44469. c = "method";
  44470. break;
  44471. case 3:
  44472. c = "getter";
  44473. break;
  44474. case 4:
  44475. c = "setter";
  44476. break;
  44477. default:
  44478. c = "field";
  44479. }
  44480. var d,
  44481. u,
  44482. f = {
  44483. kind: c,
  44484. name: l ? "#" + t : _toPropertyKey(t),
  44485. isStatic: n,
  44486. isPrivate: l
  44487. },
  44488. p = {
  44489. v: !1
  44490. };
  44491. if (0 !== i && (f.addInitializer = old_createAddInitializerMethod(o, p)), l) {
  44492. d = 2, u = Symbol(t);
  44493. var v = {};
  44494. 0 === i ? (v.get = a.get, v.set = a.set) : 2 === i ? v.get = function () {
  44495. return a.value;
  44496. } : (1 !== i && 3 !== i || (v.get = function () {
  44497. return a.get.call(this);
  44498. }), 1 !== i && 4 !== i || (v.set = function (e) {
  44499. a.set.call(this, e);
  44500. })), f.access = v;
  44501. } else d = 1, u = t;
  44502. try {
  44503. return e(s, Object.assign(f, old_createMetadataMethodsForProperty(r, d, u, p)));
  44504. } finally {
  44505. p.v = !0;
  44506. }
  44507. }
  44508. function old_assertNotFinished(e, t) {
  44509. if (e.v) throw Error("attempted to call " + t + " after decoration was finished");
  44510. }
  44511. function old_assertMetadataKey(e) {
  44512. if ("symbol" != typeof e) throw new TypeError("Metadata keys must be symbols, received: " + e);
  44513. }
  44514. function old_assertCallable(e, t) {
  44515. if ("function" != typeof e) throw new TypeError(t + " must be a function");
  44516. }
  44517. function old_assertValidReturnValue(e, t) {
  44518. var a = typeof t;
  44519. if (1 === e) {
  44520. if ("object" !== a || null === t) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
  44521. void 0 !== t.get && old_assertCallable(t.get, "accessor.get"), void 0 !== t.set && old_assertCallable(t.set, "accessor.set"), void 0 !== t.init && old_assertCallable(t.init, "accessor.init"), void 0 !== t.initializer && old_assertCallable(t.initializer, "accessor.initializer");
  44522. } else if ("function" !== a) throw new TypeError((0 === e ? "field" : 10 === e ? "class" : "method") + " decorators must return a function or void 0");
  44523. }
  44524. function old_getInit(e) {
  44525. var t;
  44526. return null == (t = e.init) && (t = e.initializer) && void 0 !== console && console.warn(".initializer has been renamed to .init as of March 2022"), t;
  44527. }
  44528. function old_applyMemberDec(e, t, a, r, o, i, n, l, s) {
  44529. var c,
  44530. d,
  44531. u,
  44532. f,
  44533. p,
  44534. v,
  44535. y,
  44536. h = a[0];
  44537. if (n ? (0 === o || 1 === o ? (c = {
  44538. get: a[3],
  44539. set: a[4]
  44540. }, u = "get") : 3 === o ? (c = {
  44541. get: a[3]
  44542. }, u = "get") : 4 === o ? (c = {
  44543. set: a[3]
  44544. }, u = "set") : c = {
  44545. value: a[3]
  44546. }, 0 !== o && (1 === o && _setFunctionName(a[4], "#" + r, "set"), _setFunctionName(a[3], "#" + r, u))) : 0 !== o && (c = Object.getOwnPropertyDescriptor(t, r)), 1 === o ? f = {
  44547. get: c.get,
  44548. set: c.set
  44549. } : 2 === o ? f = c.value : 3 === o ? f = c.get : 4 === o && (f = c.set), "function" == typeof h) void 0 !== (p = old_memberDec(h, r, c, l, s, o, i, n, f)) && (old_assertValidReturnValue(o, p), 0 === o ? d = p : 1 === o ? (d = old_getInit(p), v = p.get || f.get, y = p.set || f.set, f = {
  44550. get: v,
  44551. set: y
  44552. }) : f = p);else for (var m = h.length - 1; m >= 0; m--) {
  44553. var b;
  44554. void 0 !== (p = old_memberDec(h[m], r, c, l, s, o, i, n, f)) && (old_assertValidReturnValue(o, p), 0 === o ? b = p : 1 === o ? (b = old_getInit(p), v = p.get || f.get, y = p.set || f.set, f = {
  44555. get: v,
  44556. set: y
  44557. }) : f = p, void 0 !== b && (void 0 === d ? d = b : "function" == typeof d ? d = [d, b] : d.push(b)));
  44558. }
  44559. if (0 === o || 1 === o) {
  44560. if (void 0 === d) d = function (e, t) {
  44561. return t;
  44562. };else if ("function" != typeof d) {
  44563. var g = d;
  44564. d = function (e, t) {
  44565. for (var a = t, r = 0; r < g.length; r++) a = g[r].call(e, a);
  44566. return a;
  44567. };
  44568. } else {
  44569. var _ = d;
  44570. d = function (e, t) {
  44571. return _.call(e, t);
  44572. };
  44573. }
  44574. e.push(d);
  44575. }
  44576. 0 !== o && (1 === o ? (c.get = f.get, c.set = f.set) : 2 === o ? c.value = f : 3 === o ? c.get = f : 4 === o && (c.set = f), n ? 1 === o ? (e.push(function (e, t) {
  44577. return f.get.call(e, t);
  44578. }), e.push(function (e, t) {
  44579. return f.set.call(e, t);
  44580. })) : 2 === o ? e.push(f) : e.push(function (e, t) {
  44581. return f.call(e, t);
  44582. }) : Object.defineProperty(t, r, c));
  44583. }
  44584. function old_applyMemberDecs(e, t, a, r, o) {
  44585. for (var i, n, l = new Map(), s = new Map(), c = 0; c < o.length; c++) {
  44586. var d = o[c];
  44587. if (Array.isArray(d)) {
  44588. var u,
  44589. f,
  44590. p,
  44591. v = d[1],
  44592. y = d[2],
  44593. h = d.length > 3,
  44594. m = v >= 5;
  44595. if (m ? (u = t, f = r, 0 != (v -= 5) && (p = n = n || [])) : (u = t.prototype, f = a, 0 !== v && (p = i = i || [])), 0 !== v && !h) {
  44596. var b = m ? s : l,
  44597. g = b.get(y) || 0;
  44598. if (!0 === g || 3 === g && 4 !== v || 4 === g && 3 !== v) throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + y);
  44599. !g && v > 2 ? b.set(y, v) : b.set(y, !0);
  44600. }
  44601. old_applyMemberDec(e, u, d, y, v, m, h, f, p);
  44602. }
  44603. }
  44604. old_pushInitializers(e, i), old_pushInitializers(e, n);
  44605. }
  44606. function old_pushInitializers(e, t) {
  44607. t && e.push(function (e) {
  44608. for (var a = 0; a < t.length; a++) t[a].call(e);
  44609. return e;
  44610. });
  44611. }
  44612. function old_applyClassDecs(e, t, a, r) {
  44613. if (r.length > 0) {
  44614. for (var o = [], i = t, n = t.name, l = r.length - 1; l >= 0; l--) {
  44615. var s = {
  44616. v: !1
  44617. };
  44618. try {
  44619. var c = Object.assign({
  44620. kind: "class",
  44621. name: n,
  44622. addInitializer: old_createAddInitializerMethod(o, s)
  44623. }, old_createMetadataMethodsForProperty(a, 0, n, s)),
  44624. d = r[l](i, c);
  44625. } finally {
  44626. s.v = !0;
  44627. }
  44628. void 0 !== d && (old_assertValidReturnValue(10, d), i = d);
  44629. }
  44630. e.push(i, function () {
  44631. for (var e = 0; e < o.length; e++) o[e].call(i);
  44632. });
  44633. }
  44634. }
  44635. function _applyDecs(e, t, a) {
  44636. var r = [],
  44637. o = {},
  44638. i = {};
  44639. return old_applyMemberDecs(r, e, i, o, t), old_convertMetadataMapToFinal(e.prototype, i), old_applyClassDecs(r, e, o, a), old_convertMetadataMapToFinal(e, o), r;
  44640. }
  44641. function applyDecs2203Factory() {
  44642. function createAddInitializerMethod(e, t) {
  44643. return function (r) {
  44644. !function (e, t) {
  44645. if (e.v) throw Error("attempted to call addInitializer after decoration was finished");
  44646. }(t), assertCallable(r, "An initializer"), e.push(r);
  44647. };
  44648. }
  44649. function memberDec(e, t, r, a, n, i, s, o) {
  44650. var c;
  44651. switch (n) {
  44652. case 1:
  44653. c = "accessor";
  44654. break;
  44655. case 2:
  44656. c = "method";
  44657. break;
  44658. case 3:
  44659. c = "getter";
  44660. break;
  44661. case 4:
  44662. c = "setter";
  44663. break;
  44664. default:
  44665. c = "field";
  44666. }
  44667. var l,
  44668. u,
  44669. f = {
  44670. kind: c,
  44671. name: s ? "#" + t : t,
  44672. static: i,
  44673. private: s
  44674. },
  44675. p = {
  44676. v: !1
  44677. };
  44678. 0 !== n && (f.addInitializer = createAddInitializerMethod(a, p)), 0 === n ? s ? (l = r.get, u = r.set) : (l = function () {
  44679. return this[t];
  44680. }, u = function (e) {
  44681. this[t] = e;
  44682. }) : 2 === n ? l = function () {
  44683. return r.value;
  44684. } : (1 !== n && 3 !== n || (l = function () {
  44685. return r.get.call(this);
  44686. }), 1 !== n && 4 !== n || (u = function (e) {
  44687. r.set.call(this, e);
  44688. })), f.access = l && u ? {
  44689. get: l,
  44690. set: u
  44691. } : l ? {
  44692. get: l
  44693. } : {
  44694. set: u
  44695. };
  44696. try {
  44697. return e(o, f);
  44698. } finally {
  44699. p.v = !0;
  44700. }
  44701. }
  44702. function assertCallable(e, t) {
  44703. if ("function" != typeof e) throw new TypeError(t + " must be a function");
  44704. }
  44705. function assertValidReturnValue(e, t) {
  44706. var r = typeof t;
  44707. if (1 === e) {
  44708. if ("object" !== r || null === t) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
  44709. void 0 !== t.get && assertCallable(t.get, "accessor.get"), void 0 !== t.set && assertCallable(t.set, "accessor.set"), void 0 !== t.init && assertCallable(t.init, "accessor.init");
  44710. } else if ("function" !== r) throw new TypeError((0 === e ? "field" : 10 === e ? "class" : "method") + " decorators must return a function or void 0");
  44711. }
  44712. function applyMemberDec(e, t, r, a, n, i, s, o) {
  44713. var c,
  44714. l,
  44715. u,
  44716. f,
  44717. p,
  44718. d,
  44719. h = r[0];
  44720. if (s ? c = 0 === n || 1 === n ? {
  44721. get: r[3],
  44722. set: r[4]
  44723. } : 3 === n ? {
  44724. get: r[3]
  44725. } : 4 === n ? {
  44726. set: r[3]
  44727. } : {
  44728. value: r[3]
  44729. } : 0 !== n && (c = Object.getOwnPropertyDescriptor(t, a)), 1 === n ? u = {
  44730. get: c.get,
  44731. set: c.set
  44732. } : 2 === n ? u = c.value : 3 === n ? u = c.get : 4 === n && (u = c.set), "function" == typeof h) void 0 !== (f = memberDec(h, a, c, o, n, i, s, u)) && (assertValidReturnValue(n, f), 0 === n ? l = f : 1 === n ? (l = f.init, p = f.get || u.get, d = f.set || u.set, u = {
  44733. get: p,
  44734. set: d
  44735. }) : u = f);else for (var v = h.length - 1; v >= 0; v--) {
  44736. var g;
  44737. void 0 !== (f = memberDec(h[v], a, c, o, n, i, s, u)) && (assertValidReturnValue(n, f), 0 === n ? g = f : 1 === n ? (g = f.init, p = f.get || u.get, d = f.set || u.set, u = {
  44738. get: p,
  44739. set: d
  44740. }) : u = f, void 0 !== g && (void 0 === l ? l = g : "function" == typeof l ? l = [l, g] : l.push(g)));
  44741. }
  44742. if (0 === n || 1 === n) {
  44743. if (void 0 === l) l = function (e, t) {
  44744. return t;
  44745. };else if ("function" != typeof l) {
  44746. var y = l;
  44747. l = function (e, t) {
  44748. for (var r = t, a = 0; a < y.length; a++) r = y[a].call(e, r);
  44749. return r;
  44750. };
  44751. } else {
  44752. var m = l;
  44753. l = function (e, t) {
  44754. return m.call(e, t);
  44755. };
  44756. }
  44757. e.push(l);
  44758. }
  44759. 0 !== n && (1 === n ? (c.get = u.get, c.set = u.set) : 2 === n ? c.value = u : 3 === n ? c.get = u : 4 === n && (c.set = u), s ? 1 === n ? (e.push(function (e, t) {
  44760. return u.get.call(e, t);
  44761. }), e.push(function (e, t) {
  44762. return u.set.call(e, t);
  44763. })) : 2 === n ? e.push(u) : e.push(function (e, t) {
  44764. return u.call(e, t);
  44765. }) : Object.defineProperty(t, a, c));
  44766. }
  44767. function pushInitializers(e, t) {
  44768. t && e.push(function (e) {
  44769. for (var r = 0; r < t.length; r++) t[r].call(e);
  44770. return e;
  44771. });
  44772. }
  44773. return function (e, t, r) {
  44774. var a = [];
  44775. return function (e, t, r) {
  44776. for (var a, n, i = new Map(), s = new Map(), o = 0; o < r.length; o++) {
  44777. var c = r[o];
  44778. if (Array.isArray(c)) {
  44779. var l,
  44780. u,
  44781. f = c[1],
  44782. p = c[2],
  44783. d = c.length > 3,
  44784. h = f >= 5;
  44785. if (h ? (l = t, 0 != (f -= 5) && (u = n = n || [])) : (l = t.prototype, 0 !== f && (u = a = a || [])), 0 !== f && !d) {
  44786. var v = h ? s : i,
  44787. g = v.get(p) || 0;
  44788. if (!0 === g || 3 === g && 4 !== f || 4 === g && 3 !== f) throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + p);
  44789. !g && f > 2 ? v.set(p, f) : v.set(p, !0);
  44790. }
  44791. applyMemberDec(e, l, c, p, f, h, d, u);
  44792. }
  44793. }
  44794. pushInitializers(e, a), pushInitializers(e, n);
  44795. }(a, e, t), function (e, t, r) {
  44796. if (r.length > 0) {
  44797. for (var a = [], n = t, i = t.name, s = r.length - 1; s >= 0; s--) {
  44798. var o = {
  44799. v: !1
  44800. };
  44801. try {
  44802. var c = r[s](n, {
  44803. kind: "class",
  44804. name: i,
  44805. addInitializer: createAddInitializerMethod(a, o)
  44806. });
  44807. } finally {
  44808. o.v = !0;
  44809. }
  44810. void 0 !== c && (assertValidReturnValue(10, c), n = c);
  44811. }
  44812. e.push(n, function () {
  44813. for (var e = 0; e < a.length; e++) a[e].call(n);
  44814. });
  44815. }
  44816. }(a, e, r), a;
  44817. };
  44818. }
  44819. var applyDecs2203Impl;
  44820. function _applyDecs2203(e, t, r) {
  44821. return (applyDecs2203Impl = applyDecs2203Impl || applyDecs2203Factory())(e, t, r);
  44822. }
  44823. function applyDecs2203RFactory() {
  44824. function createAddInitializerMethod(e, t) {
  44825. return function (r) {
  44826. !function (e, t) {
  44827. if (e.v) throw Error("attempted to call addInitializer after decoration was finished");
  44828. }(t), assertCallable(r, "An initializer"), e.push(r);
  44829. };
  44830. }
  44831. function memberDec(e, t, r, n, a, i, o, s) {
  44832. var c;
  44833. switch (a) {
  44834. case 1:
  44835. c = "accessor";
  44836. break;
  44837. case 2:
  44838. c = "method";
  44839. break;
  44840. case 3:
  44841. c = "getter";
  44842. break;
  44843. case 4:
  44844. c = "setter";
  44845. break;
  44846. default:
  44847. c = "field";
  44848. }
  44849. var l,
  44850. u,
  44851. f = {
  44852. kind: c,
  44853. name: o ? "#" + t : _toPropertyKey(t),
  44854. static: i,
  44855. private: o
  44856. },
  44857. p = {
  44858. v: !1
  44859. };
  44860. 0 !== a && (f.addInitializer = createAddInitializerMethod(n, p)), 0 === a ? o ? (l = r.get, u = r.set) : (l = function () {
  44861. return this[t];
  44862. }, u = function (e) {
  44863. this[t] = e;
  44864. }) : 2 === a ? l = function () {
  44865. return r.value;
  44866. } : (1 !== a && 3 !== a || (l = function () {
  44867. return r.get.call(this);
  44868. }), 1 !== a && 4 !== a || (u = function (e) {
  44869. r.set.call(this, e);
  44870. })), f.access = l && u ? {
  44871. get: l,
  44872. set: u
  44873. } : l ? {
  44874. get: l
  44875. } : {
  44876. set: u
  44877. };
  44878. try {
  44879. return e(s, f);
  44880. } finally {
  44881. p.v = !0;
  44882. }
  44883. }
  44884. function assertCallable(e, t) {
  44885. if ("function" != typeof e) throw new TypeError(t + " must be a function");
  44886. }
  44887. function assertValidReturnValue(e, t) {
  44888. var r = typeof t;
  44889. if (1 === e) {
  44890. if ("object" !== r || null === t) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
  44891. void 0 !== t.get && assertCallable(t.get, "accessor.get"), void 0 !== t.set && assertCallable(t.set, "accessor.set"), void 0 !== t.init && assertCallable(t.init, "accessor.init");
  44892. } else if ("function" !== r) throw new TypeError((0 === e ? "field" : 10 === e ? "class" : "method") + " decorators must return a function or void 0");
  44893. }
  44894. function applyMemberDec(e, t, r, n, a, i, o, s) {
  44895. var c,
  44896. l,
  44897. u,
  44898. f,
  44899. p,
  44900. d,
  44901. h,
  44902. v = r[0];
  44903. if (o ? (0 === a || 1 === a ? (c = {
  44904. get: r[3],
  44905. set: r[4]
  44906. }, u = "get") : 3 === a ? (c = {
  44907. get: r[3]
  44908. }, u = "get") : 4 === a ? (c = {
  44909. set: r[3]
  44910. }, u = "set") : c = {
  44911. value: r[3]
  44912. }, 0 !== a && (1 === a && _setFunctionName(r[4], "#" + n, "set"), _setFunctionName(r[3], "#" + n, u))) : 0 !== a && (c = Object.getOwnPropertyDescriptor(t, n)), 1 === a ? f = {
  44913. get: c.get,
  44914. set: c.set
  44915. } : 2 === a ? f = c.value : 3 === a ? f = c.get : 4 === a && (f = c.set), "function" == typeof v) void 0 !== (p = memberDec(v, n, c, s, a, i, o, f)) && (assertValidReturnValue(a, p), 0 === a ? l = p : 1 === a ? (l = p.init, d = p.get || f.get, h = p.set || f.set, f = {
  44916. get: d,
  44917. set: h
  44918. }) : f = p);else for (var g = v.length - 1; g >= 0; g--) {
  44919. var y;
  44920. void 0 !== (p = memberDec(v[g], n, c, s, a, i, o, f)) && (assertValidReturnValue(a, p), 0 === a ? y = p : 1 === a ? (y = p.init, d = p.get || f.get, h = p.set || f.set, f = {
  44921. get: d,
  44922. set: h
  44923. }) : f = p, void 0 !== y && (void 0 === l ? l = y : "function" == typeof l ? l = [l, y] : l.push(y)));
  44924. }
  44925. if (0 === a || 1 === a) {
  44926. if (void 0 === l) l = function (e, t) {
  44927. return t;
  44928. };else if ("function" != typeof l) {
  44929. var m = l;
  44930. l = function (e, t) {
  44931. for (var r = t, n = 0; n < m.length; n++) r = m[n].call(e, r);
  44932. return r;
  44933. };
  44934. } else {
  44935. var b = l;
  44936. l = function (e, t) {
  44937. return b.call(e, t);
  44938. };
  44939. }
  44940. e.push(l);
  44941. }
  44942. 0 !== a && (1 === a ? (c.get = f.get, c.set = f.set) : 2 === a ? c.value = f : 3 === a ? c.get = f : 4 === a && (c.set = f), o ? 1 === a ? (e.push(function (e, t) {
  44943. return f.get.call(e, t);
  44944. }), e.push(function (e, t) {
  44945. return f.set.call(e, t);
  44946. })) : 2 === a ? e.push(f) : e.push(function (e, t) {
  44947. return f.call(e, t);
  44948. }) : Object.defineProperty(t, n, c));
  44949. }
  44950. function applyMemberDecs(e, t) {
  44951. for (var r, n, a = [], i = new Map(), o = new Map(), s = 0; s < t.length; s++) {
  44952. var c = t[s];
  44953. if (Array.isArray(c)) {
  44954. var l,
  44955. u,
  44956. f = c[1],
  44957. p = c[2],
  44958. d = c.length > 3,
  44959. h = f >= 5;
  44960. if (h ? (l = e, 0 != (f -= 5) && (u = n = n || [])) : (l = e.prototype, 0 !== f && (u = r = r || [])), 0 !== f && !d) {
  44961. var v = h ? o : i,
  44962. g = v.get(p) || 0;
  44963. if (!0 === g || 3 === g && 4 !== f || 4 === g && 3 !== f) throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + p);
  44964. !g && f > 2 ? v.set(p, f) : v.set(p, !0);
  44965. }
  44966. applyMemberDec(a, l, c, p, f, h, d, u);
  44967. }
  44968. }
  44969. return pushInitializers(a, r), pushInitializers(a, n), a;
  44970. }
  44971. function pushInitializers(e, t) {
  44972. t && e.push(function (e) {
  44973. for (var r = 0; r < t.length; r++) t[r].call(e);
  44974. return e;
  44975. });
  44976. }
  44977. return function (e, t, r) {
  44978. return {
  44979. e: applyMemberDecs(e, t),
  44980. get c() {
  44981. return function (e, t) {
  44982. if (t.length > 0) {
  44983. for (var r = [], n = e, a = e.name, i = t.length - 1; i >= 0; i--) {
  44984. var o = {
  44985. v: !1
  44986. };
  44987. try {
  44988. var s = t[i](n, {
  44989. kind: "class",
  44990. name: a,
  44991. addInitializer: createAddInitializerMethod(r, o)
  44992. });
  44993. } finally {
  44994. o.v = !0;
  44995. }
  44996. void 0 !== s && (assertValidReturnValue(10, s), n = s);
  44997. }
  44998. return [n, function () {
  44999. for (var e = 0; e < r.length; e++) r[e].call(n);
  45000. }];
  45001. }
  45002. }(e, r);
  45003. }
  45004. };
  45005. };
  45006. }
  45007. function _applyDecs2203R(e, t, r) {
  45008. return (_applyDecs2203R = applyDecs2203RFactory())(e, t, r);
  45009. }
  45010. function applyDecs2301Factory() {
  45011. function createAddInitializerMethod(e, t) {
  45012. return function (r) {
  45013. !function (e, t) {
  45014. if (e.v) throw Error("attempted to call addInitializer after decoration was finished");
  45015. }(t), assertCallable(r, "An initializer"), e.push(r);
  45016. };
  45017. }
  45018. function assertInstanceIfPrivate(e, t) {
  45019. if (!e(t)) throw new TypeError("Attempted to access private element on non-instance");
  45020. }
  45021. function memberDec(e, t, r, n, a, i, s, o, c) {
  45022. var u;
  45023. switch (a) {
  45024. case 1:
  45025. u = "accessor";
  45026. break;
  45027. case 2:
  45028. u = "method";
  45029. break;
  45030. case 3:
  45031. u = "getter";
  45032. break;
  45033. case 4:
  45034. u = "setter";
  45035. break;
  45036. default:
  45037. u = "field";
  45038. }
  45039. var l,
  45040. f,
  45041. p = {
  45042. kind: u,
  45043. name: s ? "#" + t : _toPropertyKey(t),
  45044. static: i,
  45045. private: s
  45046. },
  45047. d = {
  45048. v: !1
  45049. };
  45050. if (0 !== a && (p.addInitializer = createAddInitializerMethod(n, d)), s || 0 !== a && 2 !== a) {
  45051. if (2 === a) l = function (e) {
  45052. return assertInstanceIfPrivate(c, e), r.value;
  45053. };else {
  45054. var h = 0 === a || 1 === a;
  45055. (h || 3 === a) && (l = s ? function (e) {
  45056. return assertInstanceIfPrivate(c, e), r.get.call(e);
  45057. } : function (e) {
  45058. return r.get.call(e);
  45059. }), (h || 4 === a) && (f = s ? function (e, t) {
  45060. assertInstanceIfPrivate(c, e), r.set.call(e, t);
  45061. } : function (e, t) {
  45062. r.set.call(e, t);
  45063. });
  45064. }
  45065. } else l = function (e) {
  45066. return e[t];
  45067. }, 0 === a && (f = function (e, r) {
  45068. e[t] = r;
  45069. });
  45070. var v = s ? c.bind() : function (e) {
  45071. return t in e;
  45072. };
  45073. p.access = l && f ? {
  45074. get: l,
  45075. set: f,
  45076. has: v
  45077. } : l ? {
  45078. get: l,
  45079. has: v
  45080. } : {
  45081. set: f,
  45082. has: v
  45083. };
  45084. try {
  45085. return e(o, p);
  45086. } finally {
  45087. d.v = !0;
  45088. }
  45089. }
  45090. function assertCallable(e, t) {
  45091. if ("function" != typeof e) throw new TypeError(t + " must be a function");
  45092. }
  45093. function assertValidReturnValue(e, t) {
  45094. var r = typeof t;
  45095. if (1 === e) {
  45096. if ("object" !== r || null === t) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
  45097. void 0 !== t.get && assertCallable(t.get, "accessor.get"), void 0 !== t.set && assertCallable(t.set, "accessor.set"), void 0 !== t.init && assertCallable(t.init, "accessor.init");
  45098. } else if ("function" !== r) throw new TypeError((0 === e ? "field" : 10 === e ? "class" : "method") + " decorators must return a function or void 0");
  45099. }
  45100. function curryThis2(e) {
  45101. return function (t) {
  45102. e(this, t);
  45103. };
  45104. }
  45105. function applyMemberDec(e, t, r, n, a, i, s, o, c) {
  45106. var u,
  45107. l,
  45108. f,
  45109. p,
  45110. d,
  45111. h,
  45112. v,
  45113. y,
  45114. g = r[0];
  45115. if (s ? (0 === a || 1 === a ? (u = {
  45116. get: (d = r[3], function () {
  45117. return d(this);
  45118. }),
  45119. set: curryThis2(r[4])
  45120. }, f = "get") : 3 === a ? (u = {
  45121. get: r[3]
  45122. }, f = "get") : 4 === a ? (u = {
  45123. set: r[3]
  45124. }, f = "set") : u = {
  45125. value: r[3]
  45126. }, 0 !== a && (1 === a && _setFunctionName(u.set, "#" + n, "set"), _setFunctionName(u[f || "value"], "#" + n, f))) : 0 !== a && (u = Object.getOwnPropertyDescriptor(t, n)), 1 === a ? p = {
  45127. get: u.get,
  45128. set: u.set
  45129. } : 2 === a ? p = u.value : 3 === a ? p = u.get : 4 === a && (p = u.set), "function" == typeof g) void 0 !== (h = memberDec(g, n, u, o, a, i, s, p, c)) && (assertValidReturnValue(a, h), 0 === a ? l = h : 1 === a ? (l = h.init, v = h.get || p.get, y = h.set || p.set, p = {
  45130. get: v,
  45131. set: y
  45132. }) : p = h);else for (var m = g.length - 1; m >= 0; m--) {
  45133. var b;
  45134. void 0 !== (h = memberDec(g[m], n, u, o, a, i, s, p, c)) && (assertValidReturnValue(a, h), 0 === a ? b = h : 1 === a ? (b = h.init, v = h.get || p.get, y = h.set || p.set, p = {
  45135. get: v,
  45136. set: y
  45137. }) : p = h, void 0 !== b && (void 0 === l ? l = b : "function" == typeof l ? l = [l, b] : l.push(b)));
  45138. }
  45139. if (0 === a || 1 === a) {
  45140. if (void 0 === l) l = function (e, t) {
  45141. return t;
  45142. };else if ("function" != typeof l) {
  45143. var I = l;
  45144. l = function (e, t) {
  45145. for (var r = t, n = 0; n < I.length; n++) r = I[n].call(e, r);
  45146. return r;
  45147. };
  45148. } else {
  45149. var w = l;
  45150. l = function (e, t) {
  45151. return w.call(e, t);
  45152. };
  45153. }
  45154. e.push(l);
  45155. }
  45156. 0 !== a && (1 === a ? (u.get = p.get, u.set = p.set) : 2 === a ? u.value = p : 3 === a ? u.get = p : 4 === a && (u.set = p), s ? 1 === a ? (e.push(function (e, t) {
  45157. return p.get.call(e, t);
  45158. }), e.push(function (e, t) {
  45159. return p.set.call(e, t);
  45160. })) : 2 === a ? e.push(p) : e.push(function (e, t) {
  45161. return p.call(e, t);
  45162. }) : Object.defineProperty(t, n, u));
  45163. }
  45164. function applyMemberDecs(e, t, r) {
  45165. for (var n, a, i, s = [], o = new Map(), c = new Map(), u = 0; u < t.length; u++) {
  45166. var l = t[u];
  45167. if (Array.isArray(l)) {
  45168. var f,
  45169. p,
  45170. d = l[1],
  45171. h = l[2],
  45172. v = l.length > 3,
  45173. y = d >= 5,
  45174. g = r;
  45175. if (y ? (f = e, 0 != (d -= 5) && (p = a = a || []), v && !i && (i = function (t) {
  45176. return _checkInRHS(t) === e;
  45177. }), g = i) : (f = e.prototype, 0 !== d && (p = n = n || [])), 0 !== d && !v) {
  45178. var m = y ? c : o,
  45179. b = m.get(h) || 0;
  45180. if (!0 === b || 3 === b && 4 !== d || 4 === b && 3 !== d) throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + h);
  45181. !b && d > 2 ? m.set(h, d) : m.set(h, !0);
  45182. }
  45183. applyMemberDec(s, f, l, h, d, y, v, p, g);
  45184. }
  45185. }
  45186. return pushInitializers(s, n), pushInitializers(s, a), s;
  45187. }
  45188. function pushInitializers(e, t) {
  45189. t && e.push(function (e) {
  45190. for (var r = 0; r < t.length; r++) t[r].call(e);
  45191. return e;
  45192. });
  45193. }
  45194. return function (e, t, r, n) {
  45195. return {
  45196. e: applyMemberDecs(e, t, n),
  45197. get c() {
  45198. return function (e, t) {
  45199. if (t.length > 0) {
  45200. for (var r = [], n = e, a = e.name, i = t.length - 1; i >= 0; i--) {
  45201. var s = {
  45202. v: !1
  45203. };
  45204. try {
  45205. var o = t[i](n, {
  45206. kind: "class",
  45207. name: a,
  45208. addInitializer: createAddInitializerMethod(r, s)
  45209. });
  45210. } finally {
  45211. s.v = !0;
  45212. }
  45213. void 0 !== o && (assertValidReturnValue(10, o), n = o);
  45214. }
  45215. return [n, function () {
  45216. for (var e = 0; e < r.length; e++) r[e].call(n);
  45217. }];
  45218. }
  45219. }(e, r);
  45220. }
  45221. };
  45222. };
  45223. }
  45224. function _applyDecs2301(e, t, r, n) {
  45225. return (_applyDecs2301 = applyDecs2301Factory())(e, t, r, n);
  45226. }
  45227. function _applyDecs2305(e, t, r, n, o, a) {
  45228. function i(e, t, r) {
  45229. return function (n, o) {
  45230. return r && r(n), e[t].call(n, o);
  45231. };
  45232. }
  45233. function c(e, t) {
  45234. for (var r = 0; r < e.length; r++) e[r].call(t);
  45235. return t;
  45236. }
  45237. function s(e, t, r, n) {
  45238. if ("function" != typeof e && (n || void 0 !== e)) throw new TypeError(t + " must " + (r || "be") + " a function" + (n ? "" : " or undefined"));
  45239. return e;
  45240. }
  45241. function applyDec(e, t, r, n, o, a, c, u, l, f, p, d, h) {
  45242. function m(e) {
  45243. if (!h(e)) throw new TypeError("Attempted to access private element on non-instance");
  45244. }
  45245. var y,
  45246. v = t[0],
  45247. g = t[3],
  45248. b = !u;
  45249. if (!b) {
  45250. r || Array.isArray(v) || (v = [v]);
  45251. var w = {},
  45252. S = [],
  45253. A = 3 === o ? "get" : 4 === o || d ? "set" : "value";
  45254. f ? (p || d ? w = {
  45255. get: _setFunctionName(function () {
  45256. return g(this);
  45257. }, n, "get"),
  45258. set: function (e) {
  45259. t[4](this, e);
  45260. }
  45261. } : w[A] = g, p || _setFunctionName(w[A], n, 2 === o ? "" : A)) : p || (w = Object.getOwnPropertyDescriptor(e, n));
  45262. }
  45263. for (var P = e, j = v.length - 1; j >= 0; j -= r ? 2 : 1) {
  45264. var D = v[j],
  45265. E = r ? v[j - 1] : void 0,
  45266. I = {},
  45267. O = {
  45268. kind: ["field", "accessor", "method", "getter", "setter", "class"][o],
  45269. name: n,
  45270. metadata: a,
  45271. addInitializer: function (e, t) {
  45272. if (e.v) throw Error("attempted to call addInitializer after decoration was finished");
  45273. s(t, "An initializer", "be", !0), c.push(t);
  45274. }.bind(null, I)
  45275. };
  45276. try {
  45277. if (b) (y = s(D.call(E, P, O), "class decorators", "return")) && (P = y);else {
  45278. var k, F;
  45279. O.static = l, O.private = f, f ? 2 === o ? k = function (e) {
  45280. return m(e), w.value;
  45281. } : (o < 4 && (k = i(w, "get", m)), 3 !== o && (F = i(w, "set", m))) : (k = function (e) {
  45282. return e[n];
  45283. }, (o < 2 || 4 === o) && (F = function (e, t) {
  45284. e[n] = t;
  45285. }));
  45286. var N = O.access = {
  45287. has: f ? h.bind() : function (e) {
  45288. return n in e;
  45289. }
  45290. };
  45291. if (k && (N.get = k), F && (N.set = F), P = D.call(E, d ? {
  45292. get: w.get,
  45293. set: w.set
  45294. } : w[A], O), d) {
  45295. if ("object" == typeof P && P) (y = s(P.get, "accessor.get")) && (w.get = y), (y = s(P.set, "accessor.set")) && (w.set = y), (y = s(P.init, "accessor.init")) && S.push(y);else if (void 0 !== P) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
  45296. } else s(P, (p ? "field" : "method") + " decorators", "return") && (p ? S.push(P) : w[A] = P);
  45297. }
  45298. } finally {
  45299. I.v = !0;
  45300. }
  45301. }
  45302. return (p || d) && u.push(function (e, t) {
  45303. for (var r = S.length - 1; r >= 0; r--) t = S[r].call(e, t);
  45304. return t;
  45305. }), p || b || (f ? d ? u.push(i(w, "get"), i(w, "set")) : u.push(2 === o ? w[A] : i.call.bind(w[A])) : Object.defineProperty(e, n, w)), P;
  45306. }
  45307. function u(e, t) {
  45308. return Object.defineProperty(e, Symbol.metadata || Symbol.for("Symbol.metadata"), {
  45309. configurable: !0,
  45310. enumerable: !0,
  45311. value: t
  45312. });
  45313. }
  45314. if (arguments.length >= 6) var l = a[Symbol.metadata || Symbol.for("Symbol.metadata")];
  45315. var f = Object.create(null == l ? null : l),
  45316. p = function (e, t, r, n) {
  45317. var o,
  45318. a,
  45319. i = [],
  45320. s = function (t) {
  45321. return _checkInRHS(t) === e;
  45322. },
  45323. u = new Map();
  45324. function l(e) {
  45325. e && i.push(c.bind(null, e));
  45326. }
  45327. for (var f = 0; f < t.length; f++) {
  45328. var p = t[f];
  45329. if (Array.isArray(p)) {
  45330. var d = p[1],
  45331. h = p[2],
  45332. m = p.length > 3,
  45333. y = 16 & d,
  45334. v = !!(8 & d),
  45335. g = 0 == (d &= 7),
  45336. b = h + "/" + v;
  45337. if (!g && !m) {
  45338. var w = u.get(b);
  45339. if (!0 === w || 3 === w && 4 !== d || 4 === w && 3 !== d) throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + h);
  45340. u.set(b, !(d > 2) || d);
  45341. }
  45342. applyDec(v ? e : e.prototype, p, y, m ? "#" + h : _toPropertyKey(h), d, n, v ? a = a || [] : o = o || [], i, v, m, g, 1 === d, v && m ? s : r);
  45343. }
  45344. }
  45345. return l(o), l(a), i;
  45346. }(e, t, o, f);
  45347. return r.length || u(e, f), {
  45348. e: p,
  45349. get c() {
  45350. var t = [];
  45351. return r.length && [u(applyDec(e, [r], n, e.name, 5, f, t), f), c.bind(null, t, e)];
  45352. }
  45353. };
  45354. }
  45355. function _classApplyDescriptorDestructureSet(e, t) {
  45356. if (t.set) return "__destrObj" in t || (t.__destrObj = {
  45357. set value(r) {
  45358. t.set.call(e, r);
  45359. }
  45360. }), t.__destrObj;
  45361. if (!t.writable) throw new TypeError("attempted to set read only private field");
  45362. return t;
  45363. }
  45364. function _classApplyDescriptorGet(e, t) {
  45365. return t.get ? t.get.call(e) : t.value;
  45366. }
  45367. function _classApplyDescriptorSet(e, t, l) {
  45368. if (t.set) t.set.call(e, l);else {
  45369. if (!t.writable) throw new TypeError("attempted to set read only private field");
  45370. t.value = l;
  45371. }
  45372. }
  45373. function _classCheckPrivateStaticAccess(s, a, r) {
  45374. return _assertClassBrand(a, s, r);
  45375. }
  45376. function _classCheckPrivateStaticFieldDescriptor(t, e) {
  45377. if (void 0 === t) throw new TypeError("attempted to " + e + " private static field before its declaration");
  45378. }
  45379. function _classExtractFieldDescriptor(e, t) {
  45380. return _classPrivateFieldGet2(t, e);
  45381. }
  45382. function _classPrivateFieldDestructureSet(e, t) {
  45383. var r = _classPrivateFieldGet2(t, e);
  45384. return _classApplyDescriptorDestructureSet(e, r);
  45385. }
  45386. function _classPrivateFieldGet(e, t) {
  45387. var r = _classPrivateFieldGet2(t, e);
  45388. return _classApplyDescriptorGet(e, r);
  45389. }
  45390. function _classPrivateFieldSet(e, t, r) {
  45391. var s = _classPrivateFieldGet2(t, e);
  45392. return _classApplyDescriptorSet(e, s, r), r;
  45393. }
  45394. function _classPrivateMethodGet(s, a, r) {
  45395. return _assertClassBrand(a, s), r;
  45396. }
  45397. function _classPrivateMethodSet() {
  45398. throw new TypeError("attempted to reassign private method");
  45399. }
  45400. function _classStaticPrivateFieldDestructureSet(t, r, s) {
  45401. return _assertClassBrand(r, t), _classCheckPrivateStaticFieldDescriptor(s, "set"), _classApplyDescriptorDestructureSet(t, s);
  45402. }
  45403. function _classStaticPrivateFieldSpecGet(t, s, r) {
  45404. return _assertClassBrand(s, t), _classCheckPrivateStaticFieldDescriptor(r, "get"), _classApplyDescriptorGet(t, r);
  45405. }
  45406. function _classStaticPrivateFieldSpecSet(s, t, r, e) {
  45407. return _assertClassBrand(t, s), _classCheckPrivateStaticFieldDescriptor(r, "set"), _classApplyDescriptorSet(s, r, e), e;
  45408. }
  45409. function _classStaticPrivateMethodSet() {
  45410. throw new TypeError("attempted to set read only static private field");
  45411. }
  45412. function _defineEnumerableProperties(e, r) {
  45413. for (var t in r) {
  45414. var n = r[t];
  45415. n.configurable = n.enumerable = !0, "value" in n && (n.writable = !0), Object.defineProperty(e, t, n);
  45416. }
  45417. if (Object.getOwnPropertySymbols) for (var a = Object.getOwnPropertySymbols(r), b = 0; b < a.length; b++) {
  45418. var i = a[b];
  45419. (n = r[i]).configurable = n.enumerable = !0, "value" in n && (n.writable = !0), Object.defineProperty(e, i, n);
  45420. }
  45421. return e;
  45422. }
  45423. function dispose_SuppressedError(r, e) {
  45424. return "undefined" != typeof SuppressedError ? dispose_SuppressedError = SuppressedError : (dispose_SuppressedError = function (r, e) {
  45425. this.suppressed = e, this.error = r, this.stack = Error().stack;
  45426. }, dispose_SuppressedError.prototype = Object.create(Error.prototype, {
  45427. constructor: {
  45428. value: dispose_SuppressedError,
  45429. writable: !0,
  45430. configurable: !0
  45431. }
  45432. })), new dispose_SuppressedError(r, e);
  45433. }
  45434. function _dispose(r, e, s) {
  45435. function next() {
  45436. for (; r.length > 0;) try {
  45437. var o = r.pop(),
  45438. p = o.d.call(o.v);
  45439. if (o.a) return Promise.resolve(p).then(next, err);
  45440. } catch (r) {
  45441. return err(r);
  45442. }
  45443. if (s) throw e;
  45444. }
  45445. function err(r) {
  45446. return e = s ? new dispose_SuppressedError(e, r) : r, s = !0, next();
  45447. }
  45448. return next();
  45449. }
  45450. function _objectSpread(e) {
  45451. for (var r = 1; r < arguments.length; r++) {
  45452. var t = null != arguments[r] ? Object(arguments[r]) : {},
  45453. o = Object.keys(t);
  45454. "function" == typeof Object.getOwnPropertySymbols && o.push.apply(o, Object.getOwnPropertySymbols(t).filter(function (e) {
  45455. return Object.getOwnPropertyDescriptor(t, e).enumerable;
  45456. })), o.forEach(function (r) {
  45457. _defineProperty(e, r, t[r]);
  45458. });
  45459. }
  45460. return e;
  45461. }
  45462. function _using(o, n, e) {
  45463. if (null == n) return n;
  45464. if (Object(n) !== n) throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
  45465. if (e) var r = n[Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")];
  45466. if (null == r && (r = n[Symbol.dispose || Symbol.for("Symbol.dispose")]), "function" != typeof r) throw new TypeError("Property [Symbol.dispose] is not a function.");
  45467. return o.push({
  45468. v: n,
  45469. d: r,
  45470. a: e
  45471. }), n;
  45472. }
  45473. var _SplatBuffer, _PlyParser;
  45474. /*
  45475. let Ray$1 = THREE.Ray, Plane = THREE.Plane, MathUtils = THREE.MathUtils, EventDispatcher = THREE.EventDispatcher,
  45476. Vector3 = THREE.Vector3, MOUSE = THREE.MOUSE, TOUCH = THREE.TOUCH, Quaternion = THREE.Quaternion,
  45477. Spherical = THREE.Spherical, Vector2 = THREE.Vector2
  45478. */
  45479. //加
  45480. {
  45481. var _tables = /*@__PURE__*/_generateTables();
  45482. function _generateTables() {
  45483. // float32 to float16 helpers
  45484. var buffer = new ArrayBuffer(4);
  45485. var floatView = new Float32Array(buffer);
  45486. var uint32View = new Uint32Array(buffer);
  45487. var baseTable = new Uint32Array(512);
  45488. var shiftTable = new Uint32Array(512);
  45489. for (var i = 0; i < 256; ++i) {
  45490. var e = i - 127;
  45491. // very small number (0, -0)
  45492. if (e < -27) {
  45493. baseTable[i] = 0x0000;
  45494. baseTable[i | 0x100] = 0x8000;
  45495. shiftTable[i] = 24;
  45496. shiftTable[i | 0x100] = 24;
  45497. // small number (denorm)
  45498. } else if (e < -14) {
  45499. baseTable[i] = 0x0400 >> -e - 14;
  45500. baseTable[i | 0x100] = 0x0400 >> -e - 14 | 0x8000;
  45501. shiftTable[i] = -e - 1;
  45502. shiftTable[i | 0x100] = -e - 1;
  45503. // normal number
  45504. } else if (e <= 15) {
  45505. baseTable[i] = e + 15 << 10;
  45506. baseTable[i | 0x100] = e + 15 << 10 | 0x8000;
  45507. shiftTable[i] = 13;
  45508. shiftTable[i | 0x100] = 13;
  45509. // large number (Infinity, -Infinity)
  45510. } else if (e < 128) {
  45511. baseTable[i] = 0x7c00;
  45512. baseTable[i | 0x100] = 0xfc00;
  45513. shiftTable[i] = 24;
  45514. shiftTable[i | 0x100] = 24;
  45515. // stay (NaN, Infinity, -Infinity)
  45516. } else {
  45517. baseTable[i] = 0x7c00;
  45518. baseTable[i | 0x100] = 0xfc00;
  45519. shiftTable[i] = 13;
  45520. shiftTable[i | 0x100] = 13;
  45521. }
  45522. }
  45523. // float16 to float32 helpers
  45524. var mantissaTable = new Uint32Array(2048);
  45525. var exponentTable = new Uint32Array(64);
  45526. var offsetTable = new Uint32Array(64);
  45527. for (var _i = 1; _i < 1024; ++_i) {
  45528. var m = _i << 13; // zero pad mantissa bits
  45529. var _e = 0; // zero exponent
  45530. // normalized
  45531. while ((m & 0x00800000) === 0) {
  45532. m <<= 1;
  45533. _e -= 0x00800000; // decrement exponent
  45534. }
  45535. m &= ~0x00800000; // clear leading 1 bit
  45536. _e += 0x38800000; // adjust bias
  45537. mantissaTable[_i] = m | _e;
  45538. }
  45539. for (var _i2 = 1024; _i2 < 2048; ++_i2) {
  45540. mantissaTable[_i2] = 0x38000000 + (_i2 - 1024 << 13);
  45541. }
  45542. for (var _i3 = 1; _i3 < 31; ++_i3) {
  45543. exponentTable[_i3] = _i3 << 23;
  45544. }
  45545. exponentTable[31] = 0x47800000;
  45546. exponentTable[32] = 0x80000000;
  45547. for (var _i4 = 33; _i4 < 63; ++_i4) {
  45548. exponentTable[_i4] = 0x80000000 + (_i4 - 32 << 23);
  45549. }
  45550. exponentTable[63] = 0xc7800000;
  45551. for (var _i5 = 1; _i5 < 64; ++_i5) {
  45552. if (_i5 !== 32) {
  45553. offsetTable[_i5] = 1024;
  45554. }
  45555. }
  45556. return {
  45557. floatView: floatView,
  45558. uint32View: uint32View,
  45559. baseTable: baseTable,
  45560. shiftTable: shiftTable,
  45561. mantissaTable: mantissaTable,
  45562. exponentTable: exponentTable,
  45563. offsetTable: offsetTable
  45564. };
  45565. }
  45566. // float32 to float16
  45567. /* function toHalfFloat( val ) {
  45568. if ( Math.abs( val ) > 65504 ) console.warn( 'THREE.DataUtils.toHalfFloat(): Value out of range.' );
  45569. val = clamp( val, - 65504, 65504 );
  45570. _tables.floatView[ 0 ] = val;
  45571. const f = _tables.uint32View[ 0 ];
  45572. const e = ( f >> 23 ) & 0x1ff;
  45573. return _tables.baseTable[ e ] + ( ( f & 0x007fffff ) >> _tables.shiftTable[ e ] );
  45574. } */
  45575. // float16 to float32
  45576. function _fromHalfFloat(val) {
  45577. var m = val >> 10;
  45578. _tables.uint32View[0] = _tables.mantissaTable[_tables.offsetTable[m] + (val & 0x3ff)] + _tables.exponentTable[m];
  45579. return _tables.floatView[0];
  45580. }
  45581. /*
  45582. THREE.DataUtils = {
  45583. toHalfFloat: toHalfFloat,
  45584. fromHalfFloat: fromHalfFloat,
  45585. };
  45586. */
  45587. DataUtils.fromHalfFloat = _fromHalfFloat;
  45588. }
  45589. //---------------------------------------------------
  45590. /**
  45591. * AbortablePromise: A quick & dirty wrapper for JavaScript's Promise class that allows the underlying
  45592. * asynchronous operation to be cancelled. It is only meant for simple situations where no complex promise
  45593. * chaining or merging occurs. It needs a significant amount of work to truly replicate the full
  45594. * functionality of JavaScript's Promise class. Look at Util.fetchWithProgress() for example usage.
  45595. *
  45596. * This class was primarily added to allow splat scene downloads to be cancelled. It has not been tested
  45597. * very thoroughly and the implementation is kinda janky. If you can at all help it, please avoid using it :)
  45598. */
  45599. class AbortablePromise {
  45600. constructor(promiseFunc, abortHandler) {
  45601. var promiseResolve;
  45602. var promiseReject;
  45603. this.promise = new Promise((resolve, reject) => {
  45604. promiseResolve = resolve.bind(this);
  45605. promiseReject = reject.bind(this);
  45606. });
  45607. var resolve = function resolve() {
  45608. promiseResolve(...arguments);
  45609. };
  45610. var reject = error => {
  45611. promiseReject(error);
  45612. };
  45613. promiseFunc(resolve.bind(this), reject.bind(this));
  45614. this.abortHandler = abortHandler;
  45615. this.id = AbortablePromise.idGen++;
  45616. }
  45617. then(onResolve) {
  45618. return new AbortablePromise((resolve, reject) => {
  45619. this.promise = this.promise.then(function () {
  45620. var onResolveResult = onResolve(...arguments);
  45621. if (onResolveResult instanceof Promise || onResolveResult instanceof AbortablePromise) {
  45622. onResolveResult.then(function () {
  45623. resolve(...arguments);
  45624. });
  45625. } else {
  45626. resolve(onResolveResult);
  45627. }
  45628. }).catch(error => {
  45629. reject(error);
  45630. });
  45631. }, this.abortHandler);
  45632. }
  45633. catch(onFail) {
  45634. return new AbortablePromise(resolve => {
  45635. this.promise = this.promise.then(function () {
  45636. resolve(...arguments);
  45637. }).catch(onFail);
  45638. }, this.abortHandler);
  45639. }
  45640. abort() {
  45641. if (this.abortHandler) this.abortHandler();
  45642. }
  45643. }
  45644. _defineProperty(AbortablePromise, "idGen", 0);
  45645. class AbortedPromiseError extends Error {
  45646. constructor(msg) {
  45647. super(msg);
  45648. }
  45649. }
  45650. var floatToHalf = function () {
  45651. var floatView = new Float32Array(1);
  45652. var int32View = new Int32Array(floatView.buffer);
  45653. return function (val) {
  45654. floatView[0] = val;
  45655. var x = int32View[0];
  45656. var bits = x >> 16 & 0x8000;
  45657. var m = x >> 12 & 0x07ff;
  45658. var e = x >> 23 & 0xff;
  45659. if (e < 103) return bits;
  45660. if (e > 142) {
  45661. bits |= 0x7c00;
  45662. bits |= (e == 255 ? 0 : 1) && x & 0x007fffff;
  45663. return bits;
  45664. }
  45665. if (e < 113) {
  45666. m |= 0x0800;
  45667. bits |= (m >> 114 - e) + (m >> 113 - e & 1);
  45668. return bits;
  45669. }
  45670. bits |= e - 112 << 10 | m >> 1;
  45671. bits += m & 1;
  45672. return bits;
  45673. };
  45674. }();
  45675. var uintEncodedFloat = function () {
  45676. var floatView = new Float32Array(1);
  45677. var int32View = new Int32Array(floatView.buffer);
  45678. return function (f) {
  45679. floatView[0] = f;
  45680. return int32View[0];
  45681. };
  45682. }();
  45683. var rgbaToInteger = function rgbaToInteger(r, g, b, a) {
  45684. return r + (g << 8) + (b << 16) + (a << 24);
  45685. };
  45686. var rgbaArrayToInteger = function rgbaArrayToInteger(arr, offset) {
  45687. return arr[offset] + (arr[offset + 1] << 8) + (arr[offset + 2] << 16) + (arr[offset + 3] << 24);
  45688. };
  45689. var fetchWithProgress = function fetchWithProgress(path, onProgress) {
  45690. var saveChunks = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
  45691. var abortController = new AbortController();
  45692. var signal = abortController.signal;
  45693. var aborted = false;
  45694. var rejectFunc = null;
  45695. var abortHandler = () => {
  45696. abortController.abort();
  45697. rejectFunc(new AbortedPromiseError('Fetch aborted.'));
  45698. aborted = true;
  45699. };
  45700. return new AbortablePromise((resolve, reject) => {
  45701. rejectFunc = reject;
  45702. fetch(path, {
  45703. signal
  45704. }).then(async data => {
  45705. var reader = data.body.getReader();
  45706. var bytesDownloaded = 0;
  45707. var _fileSize = data.headers.get('Content-Length');
  45708. var fileSize = _fileSize ? parseInt(_fileSize) : undefined;
  45709. var chunks = [];
  45710. while (!aborted) {
  45711. try {
  45712. var {
  45713. value: chunk,
  45714. done
  45715. } = await reader.read();
  45716. if (done) {
  45717. if (onProgress) {
  45718. onProgress(100, '100%', chunk, fileSize);
  45719. }
  45720. if (saveChunks) {
  45721. var buffer = new Blob(chunks).arrayBuffer();
  45722. resolve(buffer);
  45723. } else {
  45724. resolve();
  45725. }
  45726. break;
  45727. }
  45728. bytesDownloaded += chunk.length;
  45729. var percent = void 0;
  45730. var percentLabel = void 0;
  45731. if (fileSize !== undefined) {
  45732. percent = bytesDownloaded / fileSize * 100;
  45733. percentLabel = "".concat(percent.toFixed(2), "%");
  45734. }
  45735. if (saveChunks) chunks.push(chunk);
  45736. if (onProgress) {
  45737. var cancelSaveChucnks = onProgress(percent, percentLabel, chunk, fileSize);
  45738. if (cancelSaveChucnks) saveChunks = false;
  45739. }
  45740. } catch (error) {
  45741. reject(error);
  45742. break;
  45743. }
  45744. }
  45745. });
  45746. }, abortHandler);
  45747. };
  45748. var clamp = function clamp(val, min, max) {
  45749. return Math.max(Math.min(val, max), min);
  45750. };
  45751. var getCurrentTime = function getCurrentTime() {
  45752. return performance.now() / 1000;
  45753. };
  45754. var disposeAllMeshes = object3D => {
  45755. if (object3D.geometry) {
  45756. object3D.geometry.dispose();
  45757. object3D.geometry = null;
  45758. }
  45759. if (object3D.material) {
  45760. object3D.material.dispose();
  45761. object3D.material = null;
  45762. }
  45763. if (object3D.children) {
  45764. for (var child of object3D.children) {
  45765. disposeAllMeshes(child);
  45766. }
  45767. }
  45768. };
  45769. var delayedExecute = (func, fast) => {
  45770. return new Promise(resolve => {
  45771. window.setTimeout(() => {
  45772. resolve(func());
  45773. }, fast ? 1 : 50);
  45774. });
  45775. };
  45776. var getSphericalHarmonicsComponentCountForDegree = function getSphericalHarmonicsComponentCountForDegree() {
  45777. var sphericalHarmonicsDegree = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  45778. switch (sphericalHarmonicsDegree) {
  45779. case 1:
  45780. return 9;
  45781. case 2:
  45782. return 24;
  45783. }
  45784. return 0;
  45785. };
  45786. var BASE_COMPONENT_COUNT = 14;
  45787. class UncompressedSplatArray {
  45788. constructor() {
  45789. var sphericalHarmonicsDegree = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  45790. this.sphericalHarmonicsDegree = sphericalHarmonicsDegree;
  45791. this.sphericalHarmonicsCount = getSphericalHarmonicsComponentCountForDegree(this.sphericalHarmonicsDegree);
  45792. this.componentCount = this.sphericalHarmonicsCount + BASE_COMPONENT_COUNT;
  45793. this.defaultSphericalHarmonics = new Array(this.sphericalHarmonicsCount).fill(0);
  45794. this.splats = [];
  45795. this.splatCount = 0;
  45796. }
  45797. static createSplat() {
  45798. var sphericalHarmonicsDegree = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  45799. var baseSplat = [0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0];
  45800. var shEntries = getSphericalHarmonicsComponentCountForDegree(sphericalHarmonicsDegree);
  45801. for (var i = 0; i < shEntries; i++) baseSplat.push(0);
  45802. return baseSplat;
  45803. }
  45804. addSplat(splat) {
  45805. this.splats.push(splat);
  45806. this.splatCount++;
  45807. }
  45808. getSplat(index) {
  45809. return this.splats[index];
  45810. }
  45811. addDefaultSplat() {
  45812. var newSplat = UncompressedSplatArray.createSplat(this.sphericalHarmonicsDegree);
  45813. this.addSplat(newSplat);
  45814. return newSplat;
  45815. }
  45816. addSplatFromComonents(x, y, z, scale0, scale1, scale2, rot0, rot1, rot2, rot3, r, g, b, opacity) {
  45817. var newSplat = [x, y, z, scale0, scale1, scale2, rot0, rot1, rot2, rot3, r, g, b, opacity, ...this.defaultSphericalHarmonics];
  45818. for (var i = 0; i < (arguments.length <= 14 ? 0 : arguments.length - 14) && i < this.sphericalHarmonicsCount; i++) {
  45819. newSplat[i] = i + 14 < 14 || arguments.length <= i + 14 ? undefined : arguments[i + 14];
  45820. }
  45821. this.addSplat(newSplat);
  45822. return newSplat;
  45823. }
  45824. addSplatFromArray(src, srcIndex) {
  45825. var srcSplat = src.splats[srcIndex];
  45826. var newSplat = UncompressedSplatArray.createSplat(this.sphericalHarmonicsDegree);
  45827. for (var i = 0; i < this.componentCount && i < srcSplat.length; i++) {
  45828. newSplat[i] = srcSplat[i];
  45829. }
  45830. this.addSplat(newSplat);
  45831. }
  45832. }
  45833. _defineProperty(UncompressedSplatArray, "OFFSET", {
  45834. X: 0,
  45835. Y: 1,
  45836. Z: 2,
  45837. SCALE0: 3,
  45838. SCALE1: 4,
  45839. SCALE2: 5,
  45840. ROTATION0: 6,
  45841. ROTATION1: 7,
  45842. ROTATION2: 8,
  45843. ROTATION3: 9,
  45844. FDC0: 10,
  45845. FDC1: 11,
  45846. FDC2: 12,
  45847. OPACITY: 13,
  45848. FRC0: 14,
  45849. FRC1: 15,
  45850. FRC2: 16,
  45851. FRC3: 17,
  45852. FRC4: 18,
  45853. FRC5: 19,
  45854. FRC6: 20,
  45855. FRC7: 21,
  45856. FRC8: 22,
  45857. FRC9: 23,
  45858. FRC10: 24,
  45859. FRC11: 25,
  45860. FRC12: 26,
  45861. FRC13: 27,
  45862. FRC14: 28,
  45863. FRC15: 29,
  45864. FRC16: 30,
  45865. FRC17: 31,
  45866. FRC18: 32,
  45867. FRC19: 33,
  45868. FRC20: 34,
  45869. FRC21: 35,
  45870. FRC22: 36,
  45871. FRC23: 37
  45872. });
  45873. var toHalfFloat = DataUtils.toHalfFloat.bind(DataUtils);
  45874. var toUint8 = v => {
  45875. return Math.floor(v * 128) + 128;
  45876. };
  45877. var fromUint8 = v => {
  45878. return v / 255 * 2.0 - 1.0;
  45879. };
  45880. //xzw 改 暂时没用到 需要更新版本
  45881. var fromHalfFloat = DataUtils.fromHalfFloat.bind(DataUtils);
  45882. var fromHalfFloatToUint8 = v => {
  45883. return Math.floor(fromHalfFloat(v) * 128) + 128;
  45884. };
  45885. var toUncompressedFloat = function toUncompressedFloat(f, compressionLevel) {
  45886. var isSH = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  45887. if (compressionLevel === 0) {
  45888. return f;
  45889. } else if (compressionLevel === 1 || compressionLevel === 2 && !isSH) {
  45890. return DataUtils.fromHalfFloat(f);
  45891. } else if (compressionLevel === 2) {
  45892. return fromUint8(f);
  45893. }
  45894. };
  45895. var dataViewFloatForCompressionLevel = function dataViewFloatForCompressionLevel(dataView, floatIndex, compressionLevel) {
  45896. var isSH = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  45897. if (compressionLevel === 0) {
  45898. return dataView.getFloat32(floatIndex * 4, true);
  45899. } else if (compressionLevel === 1 || compressionLevel === 2 && !isSH) {
  45900. return dataView.getUint16(floatIndex * 2, true);
  45901. } else {
  45902. return dataView.getUint8(floatIndex, true);
  45903. }
  45904. };
  45905. /**
  45906. * SplatBuffer: Container for splat data from a single scene/file and capable of (mediocre) compression.
  45907. */
  45908. class SplatBuffer {
  45909. constructor(bufferData) {
  45910. var secLoadedCountsToMax = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  45911. _defineProperty(this, "getSplatScaleAndRotation", function () {
  45912. var scaleMatrix = new Matrix4();
  45913. var rotationMatrix = new Matrix4();
  45914. var tempMatrix = new Matrix4();
  45915. var tempPosition = new Vector3();
  45916. var scale = new Vector3();
  45917. var rotation = new Quaternion();
  45918. return function (index, outScale, outRotation, transform) {
  45919. var sectionIndex = this.globalSplatIndexToSectionMap[index];
  45920. var section = this.sections[sectionIndex];
  45921. var localSplatIndex = index - section.splatCountOffset;
  45922. var srcSplatScalesBase = section.bytesPerSplat * localSplatIndex + SplatBuffer.CompressionLevels[this.compressionLevel].ScaleOffsetBytes;
  45923. var dataView = new DataView(this.bufferData, section.dataBase + srcSplatScalesBase);
  45924. scale.set(toUncompressedFloat(dataViewFloatForCompressionLevel(dataView, 0, this.compressionLevel), this.compressionLevel), toUncompressedFloat(dataViewFloatForCompressionLevel(dataView, 1, this.compressionLevel), this.compressionLevel), toUncompressedFloat(dataViewFloatForCompressionLevel(dataView, 2, this.compressionLevel), this.compressionLevel));
  45925. rotation.set(toUncompressedFloat(dataViewFloatForCompressionLevel(dataView, 4, this.compressionLevel), this.compressionLevel), toUncompressedFloat(dataViewFloatForCompressionLevel(dataView, 5, this.compressionLevel), this.compressionLevel), toUncompressedFloat(dataViewFloatForCompressionLevel(dataView, 6, this.compressionLevel), this.compressionLevel), toUncompressedFloat(dataViewFloatForCompressionLevel(dataView, 3, this.compressionLevel), this.compressionLevel));
  45926. if (transform) {
  45927. scaleMatrix.makeScale(scale.x, scale.y, scale.z);
  45928. rotationMatrix.makeRotationFromQuaternion(rotation);
  45929. tempMatrix.copy(scaleMatrix).multiply(rotationMatrix).multiply(transform);
  45930. tempMatrix.decompose(tempPosition, outRotation, outScale);
  45931. } else {
  45932. outScale.copy(scale);
  45933. outRotation.copy(rotation);
  45934. }
  45935. };
  45936. }());
  45937. _defineProperty(this, "fillSphericalHarmonicsArray", function () {
  45938. var sphericalHarmonicVectors = [];
  45939. for (var i = 0; i < 15; i++) {
  45940. sphericalHarmonicVectors[i] = new Vector3();
  45941. }
  45942. var tempMatrix3 = new Matrix3();
  45943. var sh11 = [];
  45944. var sh12 = [];
  45945. var sh13 = [];
  45946. var sh21 = [];
  45947. var sh22 = [];
  45948. var sh23 = [];
  45949. var sh24 = [];
  45950. var sh25 = [];
  45951. var shIn1 = [];
  45952. var shIn2 = [];
  45953. var shIn3 = [];
  45954. var shIn4 = [];
  45955. var shIn5 = [];
  45956. var shOut1 = [];
  45957. var shOut2 = [];
  45958. var shOut3 = [];
  45959. var shOut4 = [];
  45960. var shOut5 = [];
  45961. var noop = v => v;
  45962. var set3 = (array, val1, val2, val3) => {
  45963. array[0] = val1;
  45964. array[1] = val2;
  45965. array[2] = val3;
  45966. };
  45967. var set3FromArray = (array, srcDestView, stride, srcBase, compressionLevel) => {
  45968. array[0] = dataViewFloatForCompressionLevel(srcDestView, srcBase, compressionLevel, true);
  45969. array[1] = dataViewFloatForCompressionLevel(srcDestView, srcBase + stride, compressionLevel, true);
  45970. array[2] = dataViewFloatForCompressionLevel(srcDestView, srcBase + stride + stride, compressionLevel, true);
  45971. };
  45972. var copy3 = (srcArray, destArray) => {
  45973. destArray[0] = srcArray[0];
  45974. destArray[1] = srcArray[1];
  45975. destArray[2] = srcArray[2];
  45976. };
  45977. var setOutput3 = (srcArray, destArray, destBase, conversionFunc) => {
  45978. destArray[destBase] = conversionFunc(srcArray[0]);
  45979. destArray[destBase + 1] = conversionFunc(srcArray[1]);
  45980. destArray[destBase + 2] = conversionFunc(srcArray[2]);
  45981. };
  45982. var toUncompressedFloatArray3 = (src, dest, compressionLevel) => {
  45983. dest[0] = toUncompressedFloat(src[0], compressionLevel, true);
  45984. dest[1] = toUncompressedFloat(src[1], compressionLevel, true);
  45985. dest[2] = toUncompressedFloat(src[2], compressionLevel, true);
  45986. return dest;
  45987. };
  45988. return function (outSphericalHarmonicsArray, outSphericalHarmonicsDegree, transform, srcFrom, srcTo, destFrom, desiredOutputCompressionLevel) {
  45989. var splatCount = this.splatCount;
  45990. srcFrom = srcFrom || 0;
  45991. srcTo = srcTo || splatCount - 1;
  45992. if (destFrom === undefined) destFrom = srcFrom;
  45993. if (transform && outSphericalHarmonicsDegree >= 1) {
  45994. tempMatrix3.setFromMatrix4(transform);
  45995. set3(sh11, tempMatrix3.elements[4], -tempMatrix3.elements[7], tempMatrix3.elements[1]);
  45996. set3(sh12, -tempMatrix3.elements[5], tempMatrix3.elements[8], -tempMatrix3.elements[2]);
  45997. set3(sh13, tempMatrix3.elements[3], -tempMatrix3.elements[6], tempMatrix3.elements[0]);
  45998. }
  45999. for (var _i6 = srcFrom; _i6 <= srcTo; _i6++) {
  46000. var sectionIndex = this.globalSplatIndexToSectionMap[_i6];
  46001. var section = this.sections[sectionIndex];
  46002. outSphericalHarmonicsDegree = Math.min(outSphericalHarmonicsDegree, section.sphericalHarmonicsDegree);
  46003. var outSphericalHarmonicsComponentsCount = getSphericalHarmonicsComponentCountForDegree(outSphericalHarmonicsDegree);
  46004. var localSplatIndex = _i6 - section.splatCountOffset;
  46005. var srcSplatSHBase = section.bytesPerSplat * localSplatIndex + SplatBuffer.CompressionLevels[this.compressionLevel].SphericalHarmonicsOffsetBytes;
  46006. var dataView = new DataView(this.bufferData, section.dataBase + srcSplatSHBase);
  46007. var shDestBase = (_i6 - srcFrom + destFrom) * outSphericalHarmonicsComponentsCount;
  46008. var compressionLevelForOutputConversion = transform ? 0 : this.compressionLevel;
  46009. var outputConversionFunc = noop;
  46010. if (compressionLevelForOutputConversion !== desiredOutputCompressionLevel) {
  46011. if (compressionLevelForOutputConversion === 1) {
  46012. if (desiredOutputCompressionLevel === 0) outputConversionFunc = fromHalfFloat;else if (desiredOutputCompressionLevel == 2) outputConversionFunc = fromHalfFloatToUint8;
  46013. } else if (compressionLevelForOutputConversion === 0) {
  46014. if (desiredOutputCompressionLevel === 1) outputConversionFunc = toHalfFloat;else if (desiredOutputCompressionLevel == 2) outputConversionFunc = toUint8;
  46015. }
  46016. }
  46017. if (outSphericalHarmonicsDegree >= 1) {
  46018. set3FromArray(shIn1, dataView, 3, 0, this.compressionLevel);
  46019. set3FromArray(shIn2, dataView, 3, 1, this.compressionLevel);
  46020. set3FromArray(shIn3, dataView, 3, 2, this.compressionLevel);
  46021. if (transform) {
  46022. toUncompressedFloatArray3(shIn1, shIn1, this.compressionLevel);
  46023. toUncompressedFloatArray3(shIn2, shIn2, this.compressionLevel);
  46024. toUncompressedFloatArray3(shIn3, shIn3, this.compressionLevel);
  46025. SplatBuffer.rotateSphericalHarmonics3(shIn1, shIn2, shIn3, sh11, sh12, sh13, shOut1, shOut2, shOut3);
  46026. } else {
  46027. copy3(shIn1, shOut1);
  46028. copy3(shIn2, shOut2);
  46029. copy3(shIn3, shOut3);
  46030. }
  46031. setOutput3(shOut1, outSphericalHarmonicsArray, shDestBase, outputConversionFunc);
  46032. setOutput3(shOut2, outSphericalHarmonicsArray, shDestBase + 3, outputConversionFunc);
  46033. setOutput3(shOut3, outSphericalHarmonicsArray, shDestBase + 6, outputConversionFunc);
  46034. if (outSphericalHarmonicsDegree >= 2) {
  46035. set3FromArray(shIn1, dataView, 5, 9, this.compressionLevel);
  46036. set3FromArray(shIn2, dataView, 5, 10, this.compressionLevel);
  46037. set3FromArray(shIn3, dataView, 5, 11, this.compressionLevel);
  46038. set3FromArray(shIn4, dataView, 5, 12, this.compressionLevel);
  46039. set3FromArray(shIn5, dataView, 5, 13, this.compressionLevel);
  46040. if (transform) {
  46041. toUncompressedFloatArray3(shIn1, shIn1, this.compressionLevel);
  46042. toUncompressedFloatArray3(shIn2, shIn2, this.compressionLevel);
  46043. toUncompressedFloatArray3(shIn3, shIn3, this.compressionLevel);
  46044. toUncompressedFloatArray3(shIn4, shIn4, this.compressionLevel);
  46045. toUncompressedFloatArray3(shIn5, shIn5, this.compressionLevel);
  46046. SplatBuffer.rotateSphericalHarmonics5(shIn1, shIn2, shIn3, shIn4, shIn5, sh11, sh12, sh13, sh21, sh22, sh23, sh24, sh25, shOut1, shOut2, shOut3, shOut4, shOut5);
  46047. } else {
  46048. copy3(shIn1, shOut1);
  46049. copy3(shIn2, shOut2);
  46050. copy3(shIn3, shOut3);
  46051. copy3(shIn4, shOut4);
  46052. copy3(shIn5, shOut5);
  46053. }
  46054. setOutput3(shOut1, outSphericalHarmonicsArray, shDestBase + 9, outputConversionFunc);
  46055. setOutput3(shOut2, outSphericalHarmonicsArray, shDestBase + 12, outputConversionFunc);
  46056. setOutput3(shOut3, outSphericalHarmonicsArray, shDestBase + 15, outputConversionFunc);
  46057. setOutput3(shOut4, outSphericalHarmonicsArray, shDestBase + 18, outputConversionFunc);
  46058. setOutput3(shOut5, outSphericalHarmonicsArray, shDestBase + 21, outputConversionFunc);
  46059. }
  46060. }
  46061. }
  46062. };
  46063. }());
  46064. this.constructFromBuffer(bufferData, secLoadedCountsToMax);
  46065. }
  46066. getSplatCount() {
  46067. return this.splatCount;
  46068. }
  46069. getMaxSplatCount() {
  46070. return this.maxSplatCount;
  46071. }
  46072. getMinSphericalHarmonicsDegree() {
  46073. var minSphericalHarmonicsDegree = 0;
  46074. for (var i = 0; i < this.sections.length; i++) {
  46075. var section = this.sections[i];
  46076. if (i === 0 || section.sphericalHarmonicsDegree < minSphericalHarmonicsDegree) {
  46077. minSphericalHarmonicsDegree = section.sphericalHarmonicsDegree;
  46078. }
  46079. }
  46080. return minSphericalHarmonicsDegree;
  46081. }
  46082. getBucketIndex(section, localSplatIndex) {
  46083. var bucketIndex;
  46084. var maxSplatIndexInFullBuckets = section.fullBucketCount * section.bucketSize;
  46085. if (localSplatIndex < maxSplatIndexInFullBuckets) {
  46086. bucketIndex = Math.floor(localSplatIndex / section.bucketSize);
  46087. } else {
  46088. var bucketSplatIndex = maxSplatIndexInFullBuckets;
  46089. bucketIndex = section.fullBucketCount;
  46090. var partiallyFullBucketIndex = 0;
  46091. while (bucketSplatIndex < section.splatCount) {
  46092. var currentPartiallyFilledBucketSize = section.partiallyFilledBucketLengths[partiallyFullBucketIndex];
  46093. if (localSplatIndex >= bucketSplatIndex && localSplatIndex < bucketSplatIndex + currentPartiallyFilledBucketSize) {
  46094. break;
  46095. }
  46096. bucketSplatIndex += currentPartiallyFilledBucketSize;
  46097. bucketIndex++;
  46098. partiallyFullBucketIndex++;
  46099. }
  46100. }
  46101. return bucketIndex;
  46102. }
  46103. getSplatCenter(globalSplatIndex, outCenter, transform) {
  46104. var sectionIndex = this.globalSplatIndexToSectionMap[globalSplatIndex];
  46105. var section = this.sections[sectionIndex];
  46106. var localSplatIndex = globalSplatIndex - section.splatCountOffset;
  46107. var srcSplatCentersBase = section.bytesPerSplat * localSplatIndex;
  46108. var dataView = new DataView(this.bufferData, section.dataBase + srcSplatCentersBase);
  46109. var x = dataViewFloatForCompressionLevel(dataView, 0, this.compressionLevel);
  46110. var y = dataViewFloatForCompressionLevel(dataView, 1, this.compressionLevel);
  46111. var z = dataViewFloatForCompressionLevel(dataView, 2, this.compressionLevel);
  46112. if (this.compressionLevel >= 1) {
  46113. var bucketIndex = this.getBucketIndex(section, localSplatIndex);
  46114. var bucketBase = bucketIndex * SplatBuffer.BucketStorageSizeFloats;
  46115. var sf = section.compressionScaleFactor;
  46116. var sr = section.compressionScaleRange;
  46117. outCenter.x = (x - sr) * sf + section.bucketArray[bucketBase];
  46118. outCenter.y = (y - sr) * sf + section.bucketArray[bucketBase + 1];
  46119. outCenter.z = (z - sr) * sf + section.bucketArray[bucketBase + 2];
  46120. } else {
  46121. outCenter.x = x;
  46122. outCenter.y = y;
  46123. outCenter.z = z;
  46124. }
  46125. if (transform) outCenter.applyMatrix4(transform);
  46126. }
  46127. getSplatColor(globalSplatIndex, outColor) {
  46128. var sectionIndex = this.globalSplatIndexToSectionMap[globalSplatIndex];
  46129. var section = this.sections[sectionIndex];
  46130. var localSplatIndex = globalSplatIndex - section.splatCountOffset;
  46131. var srcSplatColorsBase = section.bytesPerSplat * localSplatIndex + SplatBuffer.CompressionLevels[this.compressionLevel].ColorOffsetBytes;
  46132. var splatColorsArray = new Uint8Array(this.bufferData, section.dataBase + srcSplatColorsBase, 4);
  46133. outColor.set(splatColorsArray[0], splatColorsArray[1], splatColorsArray[2], splatColorsArray[3]);
  46134. }
  46135. fillSplatCenterArray(outCenterArray, transform, srcFrom, srcTo, destFrom) {
  46136. var splatCount = this.splatCount;
  46137. srcFrom = srcFrom || 0;
  46138. srcTo = srcTo || splatCount - 1;
  46139. if (destFrom === undefined) destFrom = srcFrom;
  46140. var center = new Vector3();
  46141. for (var i = srcFrom; i <= srcTo; i++) {
  46142. var sectionIndex = this.globalSplatIndexToSectionMap[i];
  46143. var section = this.sections[sectionIndex];
  46144. var localSplatIndex = i - section.splatCountOffset;
  46145. var centerDestBase = (i - srcFrom + destFrom) * SplatBuffer.CenterComponentCount;
  46146. var srcSplatCentersBase = section.bytesPerSplat * localSplatIndex;
  46147. var dataView = new DataView(this.bufferData, section.dataBase + srcSplatCentersBase);
  46148. var x = dataViewFloatForCompressionLevel(dataView, 0, this.compressionLevel);
  46149. var y = dataViewFloatForCompressionLevel(dataView, 1, this.compressionLevel);
  46150. var z = dataViewFloatForCompressionLevel(dataView, 2, this.compressionLevel);
  46151. if (this.compressionLevel >= 1) {
  46152. var bucketIndex = this.getBucketIndex(section, localSplatIndex);
  46153. var bucketBase = bucketIndex * SplatBuffer.BucketStorageSizeFloats;
  46154. var sf = section.compressionScaleFactor;
  46155. var sr = section.compressionScaleRange;
  46156. center.x = (x - sr) * sf + section.bucketArray[bucketBase];
  46157. center.y = (y - sr) * sf + section.bucketArray[bucketBase + 1];
  46158. center.z = (z - sr) * sf + section.bucketArray[bucketBase + 2];
  46159. } else {
  46160. center.x = x;
  46161. center.y = y;
  46162. center.z = z;
  46163. }
  46164. if (transform) {
  46165. center.applyMatrix4(transform);
  46166. }
  46167. outCenterArray[centerDestBase] = center.x;
  46168. outCenterArray[centerDestBase + 1] = center.y;
  46169. outCenterArray[centerDestBase + 2] = center.z;
  46170. }
  46171. }
  46172. fillSplatCovarianceArray(covarianceArray, transform, srcFrom, srcTo, destFrom, desiredOutputCompressionLevel) {
  46173. var splatCount = this.splatCount;
  46174. var scale = new Vector3();
  46175. var rotation = new Quaternion();
  46176. srcFrom = srcFrom || 0;
  46177. srcTo = srcTo || splatCount - 1;
  46178. if (destFrom === undefined) destFrom = srcFrom;
  46179. for (var i = srcFrom; i <= srcTo; i++) {
  46180. var sectionIndex = this.globalSplatIndexToSectionMap[i];
  46181. var section = this.sections[sectionIndex];
  46182. var localSplatIndex = i - section.splatCountOffset;
  46183. var covarianceDestBase = (i - srcFrom + destFrom) * SplatBuffer.CovarianceComponentCount;
  46184. var srcSplatScalesBase = section.bytesPerSplat * localSplatIndex + SplatBuffer.CompressionLevels[this.compressionLevel].ScaleOffsetBytes;
  46185. var dataView = new DataView(this.bufferData, section.dataBase + srcSplatScalesBase);
  46186. scale.set(toUncompressedFloat(dataViewFloatForCompressionLevel(dataView, 0, this.compressionLevel), this.compressionLevel), toUncompressedFloat(dataViewFloatForCompressionLevel(dataView, 1, this.compressionLevel), this.compressionLevel), toUncompressedFloat(dataViewFloatForCompressionLevel(dataView, 2, this.compressionLevel), this.compressionLevel));
  46187. rotation.set(toUncompressedFloat(dataViewFloatForCompressionLevel(dataView, 4, this.compressionLevel), this.compressionLevel), toUncompressedFloat(dataViewFloatForCompressionLevel(dataView, 5, this.compressionLevel), this.compressionLevel), toUncompressedFloat(dataViewFloatForCompressionLevel(dataView, 6, this.compressionLevel), this.compressionLevel), toUncompressedFloat(dataViewFloatForCompressionLevel(dataView, 3, this.compressionLevel), this.compressionLevel));
  46188. SplatBuffer.computeCovariance(scale, rotation, transform, covarianceArray, covarianceDestBase, desiredOutputCompressionLevel);
  46189. }
  46190. }
  46191. fillSplatColorArray(outColorArray, minimumAlpha, srcFrom, srcTo, destFrom) {
  46192. var splatCount = this.splatCount;
  46193. srcFrom = srcFrom || 0;
  46194. srcTo = srcTo || splatCount - 1;
  46195. if (destFrom === undefined) destFrom = srcFrom;
  46196. for (var i = srcFrom; i <= srcTo; i++) {
  46197. var sectionIndex = this.globalSplatIndexToSectionMap[i];
  46198. var section = this.sections[sectionIndex];
  46199. var localSplatIndex = i - section.splatCountOffset;
  46200. var colorDestBase = (i - srcFrom + destFrom) * SplatBuffer.ColorComponentCount;
  46201. var srcSplatColorsBase = section.bytesPerSplat * localSplatIndex + SplatBuffer.CompressionLevels[this.compressionLevel].ColorOffsetBytes;
  46202. var dataView = new Uint8Array(this.bufferData, section.dataBase + srcSplatColorsBase);
  46203. var alpha = dataView[3];
  46204. alpha = alpha >= minimumAlpha ? alpha : 0;
  46205. outColorArray[colorDestBase] = dataView[0];
  46206. outColorArray[colorDestBase + 1] = dataView[1];
  46207. outColorArray[colorDestBase + 2] = dataView[2];
  46208. outColorArray[colorDestBase + 3] = alpha;
  46209. }
  46210. }
  46211. static parseHeader(buffer) {
  46212. var headerArrayUint8 = new Uint8Array(buffer, 0, SplatBuffer.HeaderSizeBytes);
  46213. var headerArrayUint16 = new Uint16Array(buffer, 0, SplatBuffer.HeaderSizeBytes / 2);
  46214. var headerArrayUint32 = new Uint32Array(buffer, 0, SplatBuffer.HeaderSizeBytes / 4);
  46215. var headerArrayFloat32 = new Float32Array(buffer, 0, SplatBuffer.HeaderSizeBytes / 4);
  46216. var versionMajor = headerArrayUint8[0];
  46217. var versionMinor = headerArrayUint8[1];
  46218. var maxSectionCount = headerArrayUint32[1];
  46219. var sectionCount = headerArrayUint32[2];
  46220. var maxSplatCount = headerArrayUint32[3];
  46221. var splatCount = headerArrayUint32[4];
  46222. var compressionLevel = headerArrayUint16[10];
  46223. var sceneCenter = new Vector3(headerArrayFloat32[6], headerArrayFloat32[7], headerArrayFloat32[8]);
  46224. return {
  46225. versionMajor,
  46226. versionMinor,
  46227. maxSectionCount,
  46228. sectionCount,
  46229. maxSplatCount,
  46230. splatCount,
  46231. compressionLevel,
  46232. sceneCenter
  46233. };
  46234. }
  46235. static writeHeaderCountsToBuffer(sectionCount, splatCount, buffer) {
  46236. var headerArrayUint32 = new Uint32Array(buffer, 0, SplatBuffer.HeaderSizeBytes / 4);
  46237. headerArrayUint32[2] = sectionCount;
  46238. headerArrayUint32[4] = splatCount;
  46239. }
  46240. static writeHeaderToBuffer(header, buffer) {
  46241. var headerArrayUint8 = new Uint8Array(buffer, 0, SplatBuffer.HeaderSizeBytes);
  46242. var headerArrayUint16 = new Uint16Array(buffer, 0, SplatBuffer.HeaderSizeBytes / 2);
  46243. var headerArrayUint32 = new Uint32Array(buffer, 0, SplatBuffer.HeaderSizeBytes / 4);
  46244. var headerArrayFloat32 = new Float32Array(buffer, 0, SplatBuffer.HeaderSizeBytes / 4);
  46245. headerArrayUint8[0] = header.versionMajor;
  46246. headerArrayUint8[1] = header.versionMinor;
  46247. headerArrayUint8[2] = 0; // unused for now
  46248. headerArrayUint8[3] = 0; // unused for now
  46249. headerArrayUint32[1] = header.maxSectionCount;
  46250. headerArrayUint32[2] = header.sectionCount;
  46251. headerArrayUint32[3] = header.maxSplatCount;
  46252. headerArrayUint32[4] = header.splatCount;
  46253. headerArrayUint16[10] = header.compressionLevel;
  46254. headerArrayFloat32[6] = header.sceneCenter.x;
  46255. headerArrayFloat32[7] = header.sceneCenter.y;
  46256. headerArrayFloat32[8] = header.sceneCenter.z;
  46257. }
  46258. static parseSectionHeaders(header, buffer) {
  46259. var offset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  46260. var secLoadedCountsToMax = arguments.length > 3 ? arguments[3] : undefined;
  46261. var compressionLevel = header.compressionLevel;
  46262. var maxSectionCount = header.maxSectionCount;
  46263. var sectionHeaderArrayUint16 = new Uint16Array(buffer, offset, maxSectionCount * SplatBuffer.SectionHeaderSizeBytes / 2);
  46264. var sectionHeaderArrayUint32 = new Uint32Array(buffer, offset, maxSectionCount * SplatBuffer.SectionHeaderSizeBytes / 4);
  46265. var sectionHeaderArrayFloat32 = new Float32Array(buffer, offset, maxSectionCount * SplatBuffer.SectionHeaderSizeBytes / 4);
  46266. var sectionHeaders = [];
  46267. var sectionHeaderBase = 0;
  46268. var sectionHeaderBaseUint16 = sectionHeaderBase / 2;
  46269. var sectionHeaderBaseUint32 = sectionHeaderBase / 4;
  46270. var sectionBase = SplatBuffer.HeaderSizeBytes + header.maxSectionCount * SplatBuffer.SectionHeaderSizeBytes;
  46271. var splatCountOffset = 0;
  46272. for (var i = 0; i < maxSectionCount; i++) {
  46273. var maxSplatCount = sectionHeaderArrayUint32[sectionHeaderBaseUint32 + 1];
  46274. var bucketSize = sectionHeaderArrayUint32[sectionHeaderBaseUint32 + 2];
  46275. var bucketCount = sectionHeaderArrayUint32[sectionHeaderBaseUint32 + 3];
  46276. var bucketBlockSize = sectionHeaderArrayFloat32[sectionHeaderBaseUint32 + 4];
  46277. var halfBucketBlockSize = bucketBlockSize / 2.0;
  46278. var bucketStorageSizeBytes = sectionHeaderArrayUint16[sectionHeaderBaseUint16 + 10];
  46279. var compressionScaleRange = sectionHeaderArrayUint32[sectionHeaderBaseUint32 + 6] || SplatBuffer.CompressionLevels[compressionLevel].ScaleRange;
  46280. var fullBucketCount = sectionHeaderArrayUint32[sectionHeaderBaseUint32 + 8];
  46281. var partiallyFilledBucketCount = sectionHeaderArrayUint32[sectionHeaderBaseUint32 + 9];
  46282. var bucketsMetaDataSizeBytes = partiallyFilledBucketCount * 4;
  46283. var bucketsStorageSizeBytes = bucketStorageSizeBytes * bucketCount + bucketsMetaDataSizeBytes;
  46284. var sphericalHarmonicsDegree = sectionHeaderArrayUint16[sectionHeaderBaseUint16 + 20];
  46285. var {
  46286. bytesPerSplat
  46287. } = SplatBuffer.calculateComponentStorage(compressionLevel, sphericalHarmonicsDegree);
  46288. var splatDataStorageSizeBytes = bytesPerSplat * maxSplatCount;
  46289. var storageSizeBytes = splatDataStorageSizeBytes + bucketsStorageSizeBytes;
  46290. var sectionHeader = {
  46291. bytesPerSplat: bytesPerSplat,
  46292. splatCountOffset: splatCountOffset,
  46293. splatCount: secLoadedCountsToMax ? maxSplatCount : 0,
  46294. maxSplatCount: maxSplatCount,
  46295. bucketSize: bucketSize,
  46296. bucketCount: bucketCount,
  46297. bucketBlockSize: bucketBlockSize,
  46298. halfBucketBlockSize: halfBucketBlockSize,
  46299. bucketStorageSizeBytes: bucketStorageSizeBytes,
  46300. bucketsStorageSizeBytes: bucketsStorageSizeBytes,
  46301. splatDataStorageSizeBytes: splatDataStorageSizeBytes,
  46302. storageSizeBytes: storageSizeBytes,
  46303. compressionScaleRange: compressionScaleRange,
  46304. compressionScaleFactor: halfBucketBlockSize / compressionScaleRange,
  46305. base: sectionBase,
  46306. bucketsBase: sectionBase + bucketsMetaDataSizeBytes,
  46307. dataBase: sectionBase + bucketsStorageSizeBytes,
  46308. fullBucketCount: fullBucketCount,
  46309. partiallyFilledBucketCount: partiallyFilledBucketCount,
  46310. sphericalHarmonicsDegree: sphericalHarmonicsDegree
  46311. };
  46312. sectionHeaders[i] = sectionHeader;
  46313. sectionBase += storageSizeBytes;
  46314. sectionHeaderBase += SplatBuffer.SectionHeaderSizeBytes;
  46315. sectionHeaderBaseUint16 = sectionHeaderBase / 2;
  46316. sectionHeaderBaseUint32 = sectionHeaderBase / 4;
  46317. splatCountOffset += maxSplatCount;
  46318. }
  46319. return sectionHeaders;
  46320. }
  46321. static writeSectionHeaderToBuffer(sectionHeader, compressionLevel, buffer) {
  46322. var offset = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
  46323. var sectionHeadeArrayUint16 = new Uint16Array(buffer, offset, SplatBuffer.SectionHeaderSizeBytes / 2);
  46324. var sectionHeadeArrayUint32 = new Uint32Array(buffer, offset, SplatBuffer.SectionHeaderSizeBytes / 4);
  46325. var sectionHeadeArrayFloat32 = new Float32Array(buffer, offset, SplatBuffer.SectionHeaderSizeBytes / 4);
  46326. sectionHeadeArrayUint32[0] = sectionHeader.splatCount;
  46327. sectionHeadeArrayUint32[1] = sectionHeader.maxSplatCount;
  46328. sectionHeadeArrayUint32[2] = compressionLevel >= 1 ? sectionHeader.bucketSize : 0;
  46329. sectionHeadeArrayUint32[3] = compressionLevel >= 1 ? sectionHeader.bucketCount : 0;
  46330. sectionHeadeArrayFloat32[4] = compressionLevel >= 1 ? sectionHeader.bucketBlockSize : 0.0;
  46331. sectionHeadeArrayUint16[10] = compressionLevel >= 1 ? SplatBuffer.BucketStorageSizeBytes : 0;
  46332. sectionHeadeArrayUint32[6] = compressionLevel >= 1 ? sectionHeader.compressionScaleRange : 0;
  46333. sectionHeadeArrayUint32[7] = sectionHeader.storageSizeBytes;
  46334. sectionHeadeArrayUint32[8] = compressionLevel >= 1 ? sectionHeader.fullBucketCount : 0;
  46335. sectionHeadeArrayUint32[9] = compressionLevel >= 1 ? sectionHeader.partiallyFilledBucketCount : 0;
  46336. sectionHeadeArrayUint16[20] = sectionHeader.sphericalHarmonicsDegree;
  46337. }
  46338. static writeSectionHeaderSplatCountToBuffer(splatCount, buffer) {
  46339. var offset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  46340. var sectionHeadeArrayUint32 = new Uint32Array(buffer, offset, SplatBuffer.SectionHeaderSizeBytes / 4);
  46341. sectionHeadeArrayUint32[0] = splatCount;
  46342. }
  46343. constructFromBuffer(bufferData, secLoadedCountsToMax) {
  46344. this.bufferData = bufferData;
  46345. this.globalSplatIndexToLocalSplatIndexMap = [];
  46346. this.globalSplatIndexToSectionMap = [];
  46347. var header = SplatBuffer.parseHeader(this.bufferData);
  46348. this.versionMajor = header.versionMajor;
  46349. this.versionMinor = header.versionMinor;
  46350. this.maxSectionCount = header.maxSectionCount;
  46351. this.sectionCount = secLoadedCountsToMax ? header.maxSectionCount : 0;
  46352. this.maxSplatCount = header.maxSplatCount;
  46353. this.splatCount = secLoadedCountsToMax ? header.maxSplatCount : 0;
  46354. this.compressionLevel = header.compressionLevel;
  46355. this.sceneCenter = new Vector3().copy(header.sceneCenter);
  46356. this.sections = SplatBuffer.parseSectionHeaders(header, this.bufferData, SplatBuffer.HeaderSizeBytes, secLoadedCountsToMax);
  46357. this.linkBufferArrays();
  46358. this.buildMaps();
  46359. }
  46360. static calculateComponentStorage(compressionLevel, sphericalHarmonicsDegree) {
  46361. var bytesPerCenter = SplatBuffer.CompressionLevels[compressionLevel].BytesPerCenter;
  46362. var bytesPerScale = SplatBuffer.CompressionLevels[compressionLevel].BytesPerScale;
  46363. var bytesPerRotation = SplatBuffer.CompressionLevels[compressionLevel].BytesPerRotation;
  46364. var bytesPerColor = SplatBuffer.CompressionLevels[compressionLevel].BytesPerColor;
  46365. var sphericalHarmonicsComponentsPerSplat = getSphericalHarmonicsComponentCountForDegree(sphericalHarmonicsDegree);
  46366. var sphericalHarmonicsBytesPerSplat = SplatBuffer.CompressionLevels[compressionLevel].BytesPerSphericalHarmonicsComponent * sphericalHarmonicsComponentsPerSplat;
  46367. var bytesPerSplat = bytesPerCenter + bytesPerScale + bytesPerRotation + bytesPerColor + sphericalHarmonicsBytesPerSplat;
  46368. return {
  46369. bytesPerCenter,
  46370. bytesPerScale,
  46371. bytesPerRotation,
  46372. bytesPerColor,
  46373. sphericalHarmonicsComponentsPerSplat,
  46374. sphericalHarmonicsBytesPerSplat,
  46375. bytesPerSplat
  46376. };
  46377. }
  46378. linkBufferArrays() {
  46379. for (var i = 0; i < this.maxSectionCount; i++) {
  46380. var section = this.sections[i];
  46381. section.bucketArray = new Float32Array(this.bufferData, section.bucketsBase, section.bucketCount * SplatBuffer.BucketStorageSizeFloats);
  46382. if (section.partiallyFilledBucketCount > 0) {
  46383. section.partiallyFilledBucketLengths = new Uint32Array(this.bufferData, section.base, section.partiallyFilledBucketCount);
  46384. }
  46385. }
  46386. }
  46387. buildMaps() {
  46388. var cumulativeSplatCount = 0;
  46389. for (var i = 0; i < this.maxSectionCount; i++) {
  46390. var section = this.sections[i];
  46391. for (var j = 0; j < section.maxSplatCount; j++) {
  46392. var globalSplatIndex = cumulativeSplatCount + j;
  46393. this.globalSplatIndexToLocalSplatIndexMap[globalSplatIndex] = j;
  46394. this.globalSplatIndexToSectionMap[globalSplatIndex] = i;
  46395. }
  46396. cumulativeSplatCount += section.maxSplatCount;
  46397. }
  46398. }
  46399. updateLoadedCounts(newSectionCount, newSplatCount) {
  46400. SplatBuffer.writeHeaderCountsToBuffer(newSectionCount, newSplatCount, this.bufferData);
  46401. this.sectionCount = newSectionCount;
  46402. this.splatCount = newSplatCount;
  46403. }
  46404. updateSectionLoadedCounts(sectionIndex, newSplatCount) {
  46405. var sectionHeaderOffset = SplatBuffer.HeaderSizeBytes + SplatBuffer.SectionHeaderSizeBytes * sectionIndex;
  46406. SplatBuffer.writeSectionHeaderSplatCountToBuffer(newSplatCount, this.bufferData, sectionHeaderOffset);
  46407. this.sections[sectionIndex].splatCount = newSplatCount;
  46408. }
  46409. static generateFromUncompressedSplatArrays(splatArrays, minimumAlpha, compressionLevel, sceneCenter, blockSize, bucketSize) {
  46410. var options = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : [];
  46411. var copyBetweenBuffers = function copyBetweenBuffers(srcBuffer, srcOffset, destBuffer, destOffset) {
  46412. var byteCount = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
  46413. var src = new Uint8Array(srcBuffer, srcOffset);
  46414. var dest = new Uint8Array(destBuffer, destOffset);
  46415. for (var i = 0; i < byteCount; i++) {
  46416. dest[i] = src[i];
  46417. }
  46418. };
  46419. var sphericalHarmonicsDegree = 0;
  46420. for (var sa = 0; sa < splatArrays.length; sa++) {
  46421. var splatArray = splatArrays[sa];
  46422. if (sa === 0 || splatArray.sphericalHarmonicsDegree < sphericalHarmonicsDegree) {
  46423. if (sa > 0 && splatArray.sphericalHarmonicsDegree !== sphericalHarmonicsDegree) {
  46424. var msg = 'SplatBuffer::generateFromUncompressedSplatArrays() -> ' + 'all splat arrays must have the same spherical harmonics degree.';
  46425. throw new Error(msg);
  46426. }
  46427. sphericalHarmonicsDegree = splatArray.sphericalHarmonicsDegree;
  46428. }
  46429. }
  46430. var {
  46431. bytesPerCenter,
  46432. bytesPerScale,
  46433. bytesPerRotation,
  46434. bytesPerColor,
  46435. sphericalHarmonicsComponentsPerSplat,
  46436. sphericalHarmonicsBytesPerSplat,
  46437. bytesPerSplat
  46438. } = SplatBuffer.calculateComponentStorage(compressionLevel, sphericalHarmonicsDegree);
  46439. var compressionScaleRange = SplatBuffer.CompressionLevels[compressionLevel].ScaleRange;
  46440. var sectionBuffers = [];
  46441. var sectionHeaderBuffers = [];
  46442. var totalSplatCount = 0;
  46443. var tempRotation = new Quaternion();
  46444. for (var _sa = 0; _sa < splatArrays.length; _sa++) {
  46445. var _splatArray = splatArrays[_sa];
  46446. var sectionOptions = options[_sa] || {};
  46447. var sectionBlockSize = (sectionOptions.blockSizeFactor || 1) * (blockSize || SplatBuffer.BucketBlockSize);
  46448. var sectionBucketSize = Math.ceil((sectionOptions.bucketSizeFactor || 1) * (bucketSize || SplatBuffer.BucketSize));
  46449. var validSplats = new UncompressedSplatArray(sphericalHarmonicsDegree);
  46450. for (var i = 0; i < _splatArray.splatCount; i++) {
  46451. var targetSplat = _splatArray.splats[i];
  46452. var alpha = void 0;
  46453. if (targetSplat[UncompressedSplatArray.OFFSET.OPACITY]) {
  46454. alpha = targetSplat[UncompressedSplatArray.OFFSET.OPACITY];
  46455. } else {
  46456. alpha = 255;
  46457. }
  46458. if (alpha >= minimumAlpha) {
  46459. validSplats.addSplat(targetSplat);
  46460. }
  46461. }
  46462. var bucketInfo = SplatBuffer.computeBucketsForUncompressedSplatArray(validSplats, sectionBlockSize, sectionBucketSize);
  46463. var fullBucketCount = bucketInfo.fullBuckets.length;
  46464. var partiallyFullBucketLengths = bucketInfo.partiallyFullBuckets.map(bucket => bucket.splats.length);
  46465. var partiallyFilledBucketCount = partiallyFullBucketLengths.length;
  46466. var buckets = [...bucketInfo.fullBuckets, ...bucketInfo.partiallyFullBuckets];
  46467. var sectionDataSizeBytes = validSplats.splats.length * bytesPerSplat;
  46468. var bucketMetaDataSizeBytes = partiallyFilledBucketCount * 4;
  46469. var bucketDataBytes = compressionLevel >= 1 ? buckets.length * SplatBuffer.BucketStorageSizeBytes + bucketMetaDataSizeBytes : 0;
  46470. var sectionSizeBytes = sectionDataSizeBytes + bucketDataBytes;
  46471. var sectionBuffer = new ArrayBuffer(sectionSizeBytes);
  46472. var blockHalfSize = sectionBlockSize / 2.0;
  46473. var compressionScaleFactor = compressionScaleRange / blockHalfSize;
  46474. var doubleCompressionScaleRange = compressionScaleRange * 2 + 1;
  46475. var tempCenterBuffer = new ArrayBuffer(bytesPerCenter);
  46476. var tempScaleBuffer = new ArrayBuffer(bytesPerScale);
  46477. var tempRotationBuffer = new ArrayBuffer(bytesPerRotation);
  46478. var tempColorBuffer = new ArrayBuffer(bytesPerColor);
  46479. var tempSHBuffer = new ArrayBuffer(sphericalHarmonicsBytesPerSplat);
  46480. var bucketCenter = new Vector3();
  46481. var bucketCenterDelta = new Vector3();
  46482. var outSplatCount = 0;
  46483. for (var b = 0; b < buckets.length; b++) {
  46484. var bucket = buckets[b];
  46485. bucketCenter.fromArray(bucket.center);
  46486. for (var _i7 = 0; _i7 < bucket.splats.length; _i7++) {
  46487. var row = bucket.splats[_i7];
  46488. var _targetSplat = validSplats.splats[row];
  46489. var centerBase = bucketDataBytes + outSplatCount * bytesPerSplat;
  46490. var scaleBase = centerBase + bytesPerCenter;
  46491. var rotationBase = scaleBase + bytesPerScale;
  46492. var colorBase = rotationBase + bytesPerRotation;
  46493. var sphericalHarmonicsBase = colorBase + bytesPerColor;
  46494. if (compressionLevel === 0) {
  46495. var center = new Float32Array(sectionBuffer, centerBase, SplatBuffer.CenterComponentCount);
  46496. var rot = new Float32Array(sectionBuffer, rotationBase, SplatBuffer.RotationComponentCount);
  46497. var scale = new Float32Array(sectionBuffer, scaleBase, SplatBuffer.ScaleComponentCount);
  46498. if (_targetSplat[UncompressedSplatArray.OFFSET.SCALE0] !== undefined) {
  46499. tempRotation.set(_targetSplat[UncompressedSplatArray.OFFSET.ROTATION0], _targetSplat[UncompressedSplatArray.OFFSET.ROTATION1], _targetSplat[UncompressedSplatArray.OFFSET.ROTATION2], _targetSplat[UncompressedSplatArray.OFFSET.ROTATION3]);
  46500. tempRotation.normalize();
  46501. rot.set([tempRotation.x, tempRotation.y, tempRotation.z, tempRotation.w]);
  46502. scale.set([_targetSplat[UncompressedSplatArray.OFFSET.SCALE0], _targetSplat[UncompressedSplatArray.OFFSET.SCALE1], _targetSplat[UncompressedSplatArray.OFFSET.SCALE2]]);
  46503. } else {
  46504. rot.set([1.0, 0.0, 0.0, 0.0]);
  46505. scale.set([0.01, 0.01, 0.01]);
  46506. }
  46507. center.set([_targetSplat[UncompressedSplatArray.OFFSET.X], _targetSplat[UncompressedSplatArray.OFFSET.Y], _targetSplat[UncompressedSplatArray.OFFSET.Z]]);
  46508. if (sphericalHarmonicsDegree > 0) {
  46509. var shOut = new Float32Array(sectionBuffer, sphericalHarmonicsBase, sphericalHarmonicsComponentsPerSplat);
  46510. if (sphericalHarmonicsDegree >= 1) {
  46511. for (var s = 0; s < 9; s++) shOut[s] = _targetSplat[UncompressedSplatArray.OFFSET.FRC0 + s];
  46512. if (sphericalHarmonicsDegree >= 2) {
  46513. for (var _s = 0; _s < 15; _s++) shOut[_s + 9] = _targetSplat[UncompressedSplatArray.OFFSET.FRC9 + _s];
  46514. }
  46515. }
  46516. }
  46517. } else {
  46518. var _center = new Uint16Array(tempCenterBuffer, 0, SplatBuffer.CenterComponentCount);
  46519. var _rot = new Uint16Array(tempRotationBuffer, 0, SplatBuffer.RotationComponentCount);
  46520. var _scale = new Uint16Array(tempScaleBuffer, 0, SplatBuffer.ScaleComponentCount);
  46521. if (_targetSplat[UncompressedSplatArray.OFFSET.SCALE0] !== undefined) {
  46522. tempRotation.set(_targetSplat[UncompressedSplatArray.OFFSET.ROTATION0], _targetSplat[UncompressedSplatArray.OFFSET.ROTATION1], _targetSplat[UncompressedSplatArray.OFFSET.ROTATION2], _targetSplat[UncompressedSplatArray.OFFSET.ROTATION3]);
  46523. tempRotation.normalize();
  46524. _rot.set([toHalfFloat(tempRotation.x), toHalfFloat(tempRotation.y), toHalfFloat(tempRotation.z), toHalfFloat(tempRotation.w)]);
  46525. _scale.set([toHalfFloat(_targetSplat[UncompressedSplatArray.OFFSET.SCALE0]), toHalfFloat(_targetSplat[UncompressedSplatArray.OFFSET.SCALE1]), toHalfFloat(_targetSplat[UncompressedSplatArray.OFFSET.SCALE2])]);
  46526. } else {
  46527. _rot.set([toHalfFloat(1.), 0, 0, 0]);
  46528. _scale.set([toHalfFloat(0.01), toHalfFloat(0.01), toHalfFloat(0.01)]);
  46529. }
  46530. bucketCenterDelta.set(_targetSplat[UncompressedSplatArray.OFFSET.X], _targetSplat[UncompressedSplatArray.OFFSET.Y], _targetSplat[UncompressedSplatArray.OFFSET.Z]).sub(bucketCenter);
  46531. bucketCenterDelta.x = Math.round(bucketCenterDelta.x * compressionScaleFactor) + compressionScaleRange;
  46532. bucketCenterDelta.x = clamp(bucketCenterDelta.x, 0, doubleCompressionScaleRange);
  46533. bucketCenterDelta.y = Math.round(bucketCenterDelta.y * compressionScaleFactor) + compressionScaleRange;
  46534. bucketCenterDelta.y = clamp(bucketCenterDelta.y, 0, doubleCompressionScaleRange);
  46535. bucketCenterDelta.z = Math.round(bucketCenterDelta.z * compressionScaleFactor) + compressionScaleRange;
  46536. bucketCenterDelta.z = clamp(bucketCenterDelta.z, 0, doubleCompressionScaleRange);
  46537. _center.set([bucketCenterDelta.x, bucketCenterDelta.y, bucketCenterDelta.z]);
  46538. if (sphericalHarmonicsDegree > 0) {
  46539. var SHArrayType = compressionLevel === 1 ? Uint16Array : Uint8Array;
  46540. var bytesPerSHComponent = compressionLevel === 1 ? 2 : 1;
  46541. var _shOut = new SHArrayType(tempSHBuffer, 0, sphericalHarmonicsComponentsPerSplat);
  46542. if (sphericalHarmonicsDegree >= 1) {
  46543. for (var _s2 = 0; _s2 < 9; _s2++) {
  46544. var srcVal = _targetSplat[UncompressedSplatArray.OFFSET.FRC0 + _s2];
  46545. _shOut[_s2] = compressionLevel === 1 ? toHalfFloat(srcVal) : toUint8(srcVal);
  46546. }
  46547. var degree1ByteCount = 9 * bytesPerSHComponent;
  46548. copyBetweenBuffers(_shOut.buffer, 0, sectionBuffer, sphericalHarmonicsBase, degree1ByteCount);
  46549. if (sphericalHarmonicsDegree >= 2) {
  46550. for (var _s3 = 0; _s3 < 15; _s3++) {
  46551. var _srcVal = _targetSplat[UncompressedSplatArray.OFFSET.FRC9 + _s3];
  46552. _shOut[_s3 + 9] = compressionLevel === 1 ? toHalfFloat(_srcVal) : toUint8(_srcVal);
  46553. }
  46554. var degree2ByteCount = 15 * bytesPerSHComponent;
  46555. copyBetweenBuffers(_shOut.buffer, degree1ByteCount, sectionBuffer, sphericalHarmonicsBase + degree1ByteCount, degree2ByteCount);
  46556. }
  46557. }
  46558. }
  46559. copyBetweenBuffers(_center.buffer, 0, sectionBuffer, centerBase, 6);
  46560. copyBetweenBuffers(_scale.buffer, 0, sectionBuffer, scaleBase, 6);
  46561. copyBetweenBuffers(_rot.buffer, 0, sectionBuffer, rotationBase, 8);
  46562. }
  46563. var rgba = new Uint8ClampedArray(tempColorBuffer, 0, 4);
  46564. if (_targetSplat[UncompressedSplatArray.OFFSET.FDC0] !== undefined) {
  46565. rgba.set([_targetSplat[UncompressedSplatArray.OFFSET.FDC0], _targetSplat[UncompressedSplatArray.OFFSET.FDC1], _targetSplat[UncompressedSplatArray.OFFSET.FDC2]]);
  46566. } else {
  46567. rgba.set([255, 0, 0]);
  46568. }
  46569. if (_targetSplat[UncompressedSplatArray.OFFSET.OPACITY] !== undefined) {
  46570. rgba[3] = _targetSplat[UncompressedSplatArray.OFFSET.OPACITY];
  46571. } else {
  46572. rgba[3] = 255;
  46573. }
  46574. copyBetweenBuffers(rgba.buffer, 0, sectionBuffer, colorBase, 4);
  46575. outSplatCount++;
  46576. }
  46577. }
  46578. totalSplatCount += outSplatCount;
  46579. if (compressionLevel >= 1) {
  46580. var bucketMetaDataArray = new Uint32Array(sectionBuffer, 0, partiallyFullBucketLengths.length * 4);
  46581. for (var pfb = 0; pfb < partiallyFullBucketLengths.length; pfb++) {
  46582. bucketMetaDataArray[pfb] = partiallyFullBucketLengths[pfb];
  46583. }
  46584. var bucketArray = new Float32Array(sectionBuffer, bucketMetaDataSizeBytes, buckets.length * SplatBuffer.BucketStorageSizeFloats);
  46585. for (var _b = 0; _b < buckets.length; _b++) {
  46586. var _bucket = buckets[_b];
  46587. var base = _b * 3;
  46588. bucketArray[base] = _bucket.center[0];
  46589. bucketArray[base + 1] = _bucket.center[1];
  46590. bucketArray[base + 2] = _bucket.center[2];
  46591. }
  46592. }
  46593. sectionBuffers.push(sectionBuffer);
  46594. var sectionHeaderBuffer = new ArrayBuffer(SplatBuffer.SectionHeaderSizeBytes);
  46595. SplatBuffer.writeSectionHeaderToBuffer({
  46596. maxSplatCount: outSplatCount,
  46597. splatCount: outSplatCount,
  46598. bucketSize: sectionBucketSize,
  46599. bucketCount: buckets.length,
  46600. bucketBlockSize: sectionBlockSize,
  46601. compressionScaleRange: compressionScaleRange,
  46602. storageSizeBytes: sectionSizeBytes,
  46603. fullBucketCount: fullBucketCount,
  46604. partiallyFilledBucketCount: partiallyFilledBucketCount,
  46605. sphericalHarmonicsDegree: sphericalHarmonicsDegree
  46606. }, compressionLevel, sectionHeaderBuffer, 0);
  46607. sectionHeaderBuffers.push(sectionHeaderBuffer);
  46608. }
  46609. var sectionsCumulativeSizeBytes = 0;
  46610. for (var _sectionBuffer of sectionBuffers) sectionsCumulativeSizeBytes += _sectionBuffer.byteLength;
  46611. var unifiedBufferSize = SplatBuffer.HeaderSizeBytes + SplatBuffer.SectionHeaderSizeBytes * sectionBuffers.length + sectionsCumulativeSizeBytes;
  46612. var unifiedBuffer = new ArrayBuffer(unifiedBufferSize);
  46613. SplatBuffer.writeHeaderToBuffer({
  46614. versionMajor: 0,
  46615. versionMinor: 1,
  46616. maxSectionCount: sectionBuffers.length,
  46617. sectionCount: sectionBuffers.length,
  46618. maxSplatCount: totalSplatCount,
  46619. splatCount: totalSplatCount,
  46620. compressionLevel: compressionLevel,
  46621. sceneCenter: sceneCenter
  46622. }, unifiedBuffer);
  46623. var currentUnifiedBase = SplatBuffer.HeaderSizeBytes;
  46624. for (var _sectionHeaderBuffer of sectionHeaderBuffers) {
  46625. new Uint8Array(unifiedBuffer, currentUnifiedBase, SplatBuffer.SectionHeaderSizeBytes).set(new Uint8Array(_sectionHeaderBuffer));
  46626. currentUnifiedBase += SplatBuffer.SectionHeaderSizeBytes;
  46627. }
  46628. for (var _sectionBuffer2 of sectionBuffers) {
  46629. new Uint8Array(unifiedBuffer, currentUnifiedBase, _sectionBuffer2.byteLength).set(new Uint8Array(_sectionBuffer2));
  46630. currentUnifiedBase += _sectionBuffer2.byteLength;
  46631. }
  46632. var splatBuffer = new SplatBuffer(unifiedBuffer);
  46633. return splatBuffer;
  46634. }
  46635. static computeBucketsForUncompressedSplatArray(splatArray, blockSize, bucketSize) {
  46636. var splatCount = splatArray.splatCount;
  46637. var halfBlockSize = blockSize / 2.0;
  46638. var min = new Vector3();
  46639. var max = new Vector3();
  46640. for (var i = 0; i < splatCount; i++) {
  46641. var targetSplat = splatArray.splats[i];
  46642. var center = [targetSplat[UncompressedSplatArray.OFFSET.X], targetSplat[UncompressedSplatArray.OFFSET.Y], targetSplat[UncompressedSplatArray.OFFSET.Z]];
  46643. if (i === 0 || center[0] < min.x) min.x = center[0];
  46644. if (i === 0 || center[0] > max.x) max.x = center[0];
  46645. if (i === 0 || center[1] < min.y) min.y = center[1];
  46646. if (i === 0 || center[1] > max.y) max.y = center[1];
  46647. if (i === 0 || center[2] < min.z) min.z = center[2];
  46648. if (i === 0 || center[2] > max.z) max.z = center[2];
  46649. }
  46650. var dimensions = new Vector3().copy(max).sub(min);
  46651. var yBlocks = Math.ceil(dimensions.y / blockSize);
  46652. var zBlocks = Math.ceil(dimensions.z / blockSize);
  46653. var blockCenter = new Vector3();
  46654. var fullBuckets = [];
  46655. var partiallyFullBuckets = {};
  46656. for (var _i8 = 0; _i8 < splatCount; _i8++) {
  46657. var _targetSplat2 = splatArray.splats[_i8];
  46658. var _center2 = [_targetSplat2[UncompressedSplatArray.OFFSET.X], _targetSplat2[UncompressedSplatArray.OFFSET.Y], _targetSplat2[UncompressedSplatArray.OFFSET.Z]];
  46659. var xBlock = Math.floor((_center2[0] - min.x) / blockSize);
  46660. var yBlock = Math.floor((_center2[1] - min.y) / blockSize);
  46661. var zBlock = Math.floor((_center2[2] - min.z) / blockSize);
  46662. blockCenter.x = xBlock * blockSize + min.x + halfBlockSize;
  46663. blockCenter.y = yBlock * blockSize + min.y + halfBlockSize;
  46664. blockCenter.z = zBlock * blockSize + min.z + halfBlockSize;
  46665. var bucketId = xBlock * (yBlocks * zBlocks) + yBlock * zBlocks + zBlock;
  46666. var bucket = partiallyFullBuckets[bucketId];
  46667. if (!bucket) {
  46668. partiallyFullBuckets[bucketId] = bucket = {
  46669. 'splats': [],
  46670. 'center': blockCenter.toArray()
  46671. };
  46672. }
  46673. bucket.splats.push(_i8);
  46674. if (bucket.splats.length >= bucketSize) {
  46675. fullBuckets.push(bucket);
  46676. partiallyFullBuckets[bucketId] = null;
  46677. }
  46678. }
  46679. var partiallyFullBucketArray = [];
  46680. for (var _bucketId in partiallyFullBuckets) {
  46681. if (partiallyFullBuckets.hasOwnProperty(_bucketId)) {
  46682. var _bucket2 = partiallyFullBuckets[_bucketId];
  46683. if (_bucket2) {
  46684. partiallyFullBucketArray.push(_bucket2);
  46685. }
  46686. }
  46687. }
  46688. return {
  46689. 'fullBuckets': fullBuckets,
  46690. 'partiallyFullBuckets': partiallyFullBucketArray
  46691. };
  46692. }
  46693. }
  46694. _SplatBuffer = SplatBuffer;
  46695. _defineProperty(SplatBuffer, "CurrentMajorVersion", 0);
  46696. _defineProperty(SplatBuffer, "CurrentMinorVersion", 1);
  46697. _defineProperty(SplatBuffer, "CenterComponentCount", 3);
  46698. _defineProperty(SplatBuffer, "ScaleComponentCount", 3);
  46699. _defineProperty(SplatBuffer, "RotationComponentCount", 4);
  46700. _defineProperty(SplatBuffer, "ColorComponentCount", 4);
  46701. _defineProperty(SplatBuffer, "CovarianceComponentCount", 6);
  46702. _defineProperty(SplatBuffer, "SplatScaleOffsetFloat", 3);
  46703. _defineProperty(SplatBuffer, "SplatRotationOffsetFloat", 6);
  46704. _defineProperty(SplatBuffer, "CompressionLevels", {
  46705. 0: {
  46706. BytesPerCenter: 12,
  46707. BytesPerScale: 12,
  46708. BytesPerRotation: 16,
  46709. BytesPerColor: 4,
  46710. ScaleOffsetBytes: 12,
  46711. RotationffsetBytes: 24,
  46712. ColorOffsetBytes: 40,
  46713. SphericalHarmonicsOffsetBytes: 44,
  46714. ScaleRange: 1,
  46715. BytesPerSphericalHarmonicsComponent: 4,
  46716. SphericalHarmonicsOffsetFloat: 11,
  46717. SphericalHarmonicsDegrees: {
  46718. 0: {
  46719. BytesPerSplat: 44
  46720. },
  46721. 1: {
  46722. BytesPerSplat: 80
  46723. },
  46724. 2: {
  46725. BytesPerSplat: 140
  46726. }
  46727. }
  46728. },
  46729. 1: {
  46730. BytesPerCenter: 6,
  46731. BytesPerScale: 6,
  46732. BytesPerRotation: 8,
  46733. BytesPerColor: 4,
  46734. ScaleOffsetBytes: 6,
  46735. RotationffsetBytes: 12,
  46736. ColorOffsetBytes: 20,
  46737. SphericalHarmonicsOffsetBytes: 24,
  46738. ScaleRange: 32767,
  46739. BytesPerSphericalHarmonicsComponent: 2,
  46740. SphericalHarmonicsOffsetFloat: 12,
  46741. SphericalHarmonicsDegrees: {
  46742. 0: {
  46743. BytesPerSplat: 24
  46744. },
  46745. 1: {
  46746. BytesPerSplat: 42
  46747. },
  46748. 2: {
  46749. BytesPerSplat: 72
  46750. }
  46751. }
  46752. },
  46753. 2: {
  46754. BytesPerCenter: 6,
  46755. BytesPerScale: 6,
  46756. BytesPerRotation: 8,
  46757. BytesPerColor: 4,
  46758. ScaleOffsetBytes: 6,
  46759. RotationffsetBytes: 12,
  46760. ColorOffsetBytes: 20,
  46761. SphericalHarmonicsOffsetBytes: 24,
  46762. ScaleRange: 32767,
  46763. BytesPerSphericalHarmonicsComponent: 1,
  46764. SphericalHarmonicsOffsetFloat: 12,
  46765. SphericalHarmonicsDegrees: {
  46766. 0: {
  46767. BytesPerSplat: 24
  46768. },
  46769. 1: {
  46770. BytesPerSplat: 33
  46771. },
  46772. 2: {
  46773. BytesPerSplat: 48
  46774. }
  46775. }
  46776. }
  46777. });
  46778. _defineProperty(SplatBuffer, "CovarianceSizeFloats", 6);
  46779. _defineProperty(SplatBuffer, "HeaderSizeBytes", 4096);
  46780. _defineProperty(SplatBuffer, "SectionHeaderSizeBytes", 1024);
  46781. _defineProperty(SplatBuffer, "BucketStorageSizeBytes", 12);
  46782. _defineProperty(SplatBuffer, "BucketStorageSizeFloats", 3);
  46783. _defineProperty(SplatBuffer, "BucketBlockSize", 5.0);
  46784. _defineProperty(SplatBuffer, "BucketSize", 256);
  46785. _defineProperty(SplatBuffer, "computeCovariance", function () {
  46786. //通过旋转和缩放计算协方差(决定姿态)得到6个数
  46787. var tempMatrix4 = new Matrix4();
  46788. var scaleMatrix = new Matrix3();
  46789. var rotationMatrix = new Matrix3();
  46790. var covarianceMatrix = new Matrix3();
  46791. var transformedCovariance = new Matrix3();
  46792. var transform3x3 = new Matrix3();
  46793. var transform3x3Transpose = new Matrix3();
  46794. return function (scale, rotation, transform, outCovariance) {
  46795. var outOffset = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
  46796. var desiredOutputCompressionLevel = arguments.length > 5 ? arguments[5] : undefined;
  46797. tempMatrix4.makeScale(scale.x, scale.y, scale.z);
  46798. scaleMatrix.setFromMatrix4(tempMatrix4);
  46799. tempMatrix4.makeRotationFromQuaternion(rotation);
  46800. rotationMatrix.setFromMatrix4(tempMatrix4);
  46801. covarianceMatrix.copy(rotationMatrix).multiply(scaleMatrix);
  46802. transformedCovariance.copy(covarianceMatrix).transpose().premultiply(covarianceMatrix); //为什么要乘以自己的转置呀?
  46803. if (transform) {
  46804. //场景的整体transform
  46805. transform3x3.setFromMatrix4(transform);
  46806. transform3x3Transpose.copy(transform3x3).transpose();
  46807. transformedCovariance.multiply(transform3x3Transpose);
  46808. transformedCovariance.premultiply(transform3x3);
  46809. }
  46810. if (desiredOutputCompressionLevel >= 1) {
  46811. //压缩
  46812. outCovariance[outOffset] = toHalfFloat(transformedCovariance.elements[0]);
  46813. outCovariance[outOffset + 1] = toHalfFloat(transformedCovariance.elements[3]);
  46814. outCovariance[outOffset + 2] = toHalfFloat(transformedCovariance.elements[6]);
  46815. outCovariance[outOffset + 3] = toHalfFloat(transformedCovariance.elements[4]);
  46816. outCovariance[outOffset + 4] = toHalfFloat(transformedCovariance.elements[7]);
  46817. outCovariance[outOffset + 5] = toHalfFloat(transformedCovariance.elements[8]);
  46818. } else {
  46819. outCovariance[outOffset] = transformedCovariance.elements[0];
  46820. outCovariance[outOffset + 1] = transformedCovariance.elements[3];
  46821. outCovariance[outOffset + 2] = transformedCovariance.elements[6];
  46822. outCovariance[outOffset + 3] = transformedCovariance.elements[4];
  46823. outCovariance[outOffset + 4] = transformedCovariance.elements[7];
  46824. outCovariance[outOffset + 5] = transformedCovariance.elements[8];
  46825. }
  46826. };
  46827. }());
  46828. _defineProperty(SplatBuffer, "dot3", (v1, v2, v3, transformRow, outArray) => {
  46829. outArray[0] = outArray[1] = outArray[2] = 0;
  46830. var t0 = transformRow[0];
  46831. var t1 = transformRow[1];
  46832. var t2 = transformRow[2];
  46833. _SplatBuffer.addInto3(v1[0] * t0, v1[1] * t0, v1[2] * t0, outArray);
  46834. _SplatBuffer.addInto3(v2[0] * t1, v2[1] * t1, v2[2] * t1, outArray);
  46835. _SplatBuffer.addInto3(v3[0] * t2, v3[1] * t2, v3[2] * t2, outArray);
  46836. });
  46837. _defineProperty(SplatBuffer, "addInto3", (val1, val2, val3, destArray) => {
  46838. destArray[0] = destArray[0] + val1;
  46839. destArray[1] = destArray[1] + val2;
  46840. destArray[2] = destArray[2] + val3;
  46841. });
  46842. _defineProperty(SplatBuffer, "dot5", (v1, v2, v3, v4, v5, transformRow, outArray) => {
  46843. outArray[0] = outArray[1] = outArray[2] = 0;
  46844. var t0 = transformRow[0];
  46845. var t1 = transformRow[1];
  46846. var t2 = transformRow[2];
  46847. var t3 = transformRow[3];
  46848. var t4 = transformRow[4];
  46849. _SplatBuffer.addInto3(v1[0] * t0, v1[1] * t0, v1[2] * t0, outArray);
  46850. _SplatBuffer.addInto3(v2[0] * t1, v2[1] * t1, v2[2] * t1, outArray);
  46851. _SplatBuffer.addInto3(v3[0] * t2, v3[1] * t2, v3[2] * t2, outArray);
  46852. _SplatBuffer.addInto3(v4[0] * t3, v4[1] * t3, v4[2] * t3, outArray);
  46853. _SplatBuffer.addInto3(v5[0] * t4, v5[1] * t4, v5[2] * t4, outArray);
  46854. });
  46855. _defineProperty(SplatBuffer, "rotateSphericalHarmonics3", (in1, in2, in3, tsh11, tsh12, tsh13, out1, out2, out3) => {
  46856. _SplatBuffer.dot3(in1, in2, in3, tsh11, out1);
  46857. _SplatBuffer.dot3(in1, in2, in3, tsh12, out2);
  46858. _SplatBuffer.dot3(in1, in2, in3, tsh13, out3);
  46859. });
  46860. _defineProperty(SplatBuffer, "rotateSphericalHarmonics5", (in1, in2, in3, in4, in5, tsh11, tsh12, tsh13, tsh21, tsh22, tsh23, tsh24, tsh25, out1, out2, out3, out4, out5) => {
  46861. var kSqrt0104 = Math.sqrt(1.0 / 4.0);
  46862. var kSqrt0304 = Math.sqrt(3.0 / 4.0);
  46863. var kSqrt0103 = Math.sqrt(1.0 / 3.0);
  46864. var kSqrt0403 = Math.sqrt(4.0 / 3.0);
  46865. var kSqrt0112 = Math.sqrt(1.0 / 12.0);
  46866. tsh21[0] = kSqrt0104 * (tsh13[2] * tsh11[0] + tsh13[0] * tsh11[2] + (tsh11[2] * tsh13[0] + tsh11[0] * tsh13[2]));
  46867. tsh21[1] = tsh13[1] * tsh11[0] + tsh11[1] * tsh13[0];
  46868. tsh21[2] = kSqrt0304 * (tsh13[1] * tsh11[1] + tsh11[1] * tsh13[1]);
  46869. tsh21[3] = tsh13[1] * tsh11[2] + tsh11[1] * tsh13[2];
  46870. tsh21[4] = kSqrt0104 * (tsh13[2] * tsh11[2] - tsh13[0] * tsh11[0] + (tsh11[2] * tsh13[2] - tsh11[0] * tsh13[0]));
  46871. _SplatBuffer.dot5(in1, in2, in3, in4, in5, tsh21, out1);
  46872. tsh22[0] = kSqrt0104 * (tsh12[2] * tsh11[0] + tsh12[0] * tsh11[2] + (tsh11[2] * tsh12[0] + tsh11[0] * tsh12[2]));
  46873. tsh22[1] = tsh12[1] * tsh11[0] + tsh11[1] * tsh12[0];
  46874. tsh22[2] = kSqrt0304 * (tsh12[1] * tsh11[1] + tsh11[1] * tsh12[1]);
  46875. tsh22[3] = tsh12[1] * tsh11[2] + tsh11[1] * tsh12[2];
  46876. tsh22[4] = kSqrt0104 * (tsh12[2] * tsh11[2] - tsh12[0] * tsh11[0] + (tsh11[2] * tsh12[2] - tsh11[0] * tsh12[0]));
  46877. _SplatBuffer.dot5(in1, in2, in3, in4, in5, tsh22, out2);
  46878. tsh23[0] = kSqrt0103 * (tsh12[2] * tsh12[0] + tsh12[0] * tsh12[2]) + -kSqrt0112 * (tsh13[2] * tsh13[0] + tsh13[0] * tsh13[2] + (tsh11[2] * tsh11[0] + tsh11[0] * tsh11[2]));
  46879. tsh23[1] = kSqrt0403 * tsh12[1] * tsh12[0] + -kSqrt0103 * (tsh13[1] * tsh13[0] + tsh11[1] * tsh11[0]);
  46880. tsh23[2] = tsh12[1] * tsh12[1] + -kSqrt0104 * (tsh13[1] * tsh13[1] + tsh11[1] * tsh11[1]);
  46881. tsh23[3] = kSqrt0403 * tsh12[1] * tsh12[2] + -kSqrt0103 * (tsh13[1] * tsh13[2] + tsh11[1] * tsh11[2]);
  46882. tsh23[4] = kSqrt0103 * (tsh12[2] * tsh12[2] - tsh12[0] * tsh12[0]) + -kSqrt0112 * (tsh13[2] * tsh13[2] - tsh13[0] * tsh13[0] + (tsh11[2] * tsh11[2] - tsh11[0] * tsh11[0]));
  46883. _SplatBuffer.dot5(in1, in2, in3, in4, in5, tsh23, out3);
  46884. tsh24[0] = kSqrt0104 * (tsh12[2] * tsh13[0] + tsh12[0] * tsh13[2] + (tsh13[2] * tsh12[0] + tsh13[0] * tsh12[2]));
  46885. tsh24[1] = tsh12[1] * tsh13[0] + tsh13[1] * tsh12[0];
  46886. tsh24[2] = kSqrt0304 * (tsh12[1] * tsh13[1] + tsh13[1] * tsh12[1]);
  46887. tsh24[3] = tsh12[1] * tsh13[2] + tsh13[1] * tsh12[2];
  46888. tsh24[4] = kSqrt0104 * (tsh12[2] * tsh13[2] - tsh12[0] * tsh13[0] + (tsh13[2] * tsh12[2] - tsh13[0] * tsh12[0]));
  46889. _SplatBuffer.dot5(in1, in2, in3, in4, in5, tsh24, out4);
  46890. tsh25[0] = kSqrt0104 * (tsh13[2] * tsh13[0] + tsh13[0] * tsh13[2] - (tsh11[2] * tsh11[0] + tsh11[0] * tsh11[2]));
  46891. tsh25[1] = tsh13[1] * tsh13[0] - tsh11[1] * tsh11[0];
  46892. tsh25[2] = kSqrt0304 * (tsh13[1] * tsh13[1] - tsh11[1] * tsh11[1]);
  46893. tsh25[3] = tsh13[1] * tsh13[2] - tsh11[1] * tsh11[2];
  46894. tsh25[4] = kSqrt0104 * (tsh13[2] * tsh13[2] - tsh13[0] * tsh13[0] - (tsh11[2] * tsh11[2] - tsh11[0] * tsh11[0]));
  46895. _SplatBuffer.dot5(in1, in2, in3, in4, in5, tsh25, out5);
  46896. });
  46897. var HeaderMagicBytes = new Uint8Array([112, 108, 121, 10]);
  46898. var HeaderEndTokenBytes = new Uint8Array([10, 101, 110, 100, 95, 104, 101, 97, 100, 101, 114, 10]);
  46899. var HeaderEndToken = 'end_header';
  46900. var DataTypeMap = new Map([['char', Int8Array], ['uchar', Uint8Array], ['short', Int16Array], ['ushort', Uint16Array], ['int', Int32Array], ['uint', Uint32Array], ['float', Float32Array], ['double', Float64Array]]);
  46901. var unpackUnorm = (value, bits) => {
  46902. var t = (1 << bits) - 1;
  46903. return (value & t) / t;
  46904. };
  46905. var unpack111011 = (result, value) => {
  46906. result.x = unpackUnorm(value >>> 21, 11);
  46907. result.y = unpackUnorm(value >>> 11, 10);
  46908. result.z = unpackUnorm(value, 11);
  46909. };
  46910. var unpack8888 = (result, value) => {
  46911. result.x = unpackUnorm(value >>> 24, 8);
  46912. result.y = unpackUnorm(value >>> 16, 8);
  46913. result.z = unpackUnorm(value >>> 8, 8);
  46914. result.w = unpackUnorm(value, 8);
  46915. };
  46916. // unpack quaternion with 2,10,10,10 format (largest element, 3x10bit element)
  46917. var unpackRot = (result, value) => {
  46918. var norm = 1.0 / (Math.sqrt(2) * 0.5);
  46919. var a = (unpackUnorm(value >>> 20, 10) - 0.5) * norm;
  46920. var b = (unpackUnorm(value >>> 10, 10) - 0.5) * norm;
  46921. var c = (unpackUnorm(value, 10) - 0.5) * norm;
  46922. var m = Math.sqrt(1.0 - (a * a + b * b + c * c));
  46923. switch (value >>> 30) {
  46924. case 0:
  46925. result.set(m, a, b, c);
  46926. break;
  46927. case 1:
  46928. result.set(a, m, b, c);
  46929. break;
  46930. case 2:
  46931. result.set(a, b, m, c);
  46932. break;
  46933. case 3:
  46934. result.set(a, b, c, m);
  46935. break;
  46936. }
  46937. };
  46938. var lerp$1 = (a, b, t) => {
  46939. return a * (1 - t) + b * t;
  46940. };
  46941. var getElementPropStorage = (element, name) => {
  46942. var _element$properties$f;
  46943. return (_element$properties$f = element.properties.find(p => p.name === name && p.storage)) === null || _element$properties$f === void 0 ? void 0 : _element$properties$f.storage;
  46944. };
  46945. class CompressedPlyParser {
  46946. static decodeHeaderText(headerText) {
  46947. var element;
  46948. var chunkElement;
  46949. var vertexElement;
  46950. var headerLines = headerText.split('\n').filter(line => !line.startsWith('comment '));
  46951. var bytesPerSplat = 0;
  46952. var done = false;
  46953. for (var i = 1; i < headerLines.length; ++i) {
  46954. var words = headerLines[i].split(' ');
  46955. switch (words[0]) {
  46956. case 'format':
  46957. if (words[1] !== 'binary_little_endian') {
  46958. throw new Error('Unsupported ply format');
  46959. }
  46960. break;
  46961. case 'element':
  46962. element = {
  46963. name: words[1],
  46964. count: parseInt(words[2], 10),
  46965. properties: [],
  46966. storageSizeBytes: 0
  46967. };
  46968. if (element.name === 'chunk') chunkElement = element;else if (element.name === 'vertex') vertexElement = element;
  46969. break;
  46970. case 'property':
  46971. {
  46972. if (!DataTypeMap.has(words[1])) {
  46973. throw new Error("Unrecognized property data type '".concat(words[1], "' in ply header"));
  46974. }
  46975. var StorageType = DataTypeMap.get(words[1]);
  46976. var storageSizeByes = StorageType.BYTES_PER_ELEMENT * element.count;
  46977. if (element.name === 'vertex') bytesPerSplat += StorageType.BYTES_PER_ELEMENT;
  46978. element.properties.push({
  46979. type: words[1],
  46980. name: words[2],
  46981. storage: null,
  46982. byteSize: StorageType.BYTES_PER_ELEMENT,
  46983. storageSizeByes: storageSizeByes
  46984. });
  46985. element.storageSizeBytes += storageSizeByes;
  46986. break;
  46987. }
  46988. case HeaderEndToken:
  46989. done = true;
  46990. break;
  46991. default:
  46992. throw new Error("Unrecognized header value '".concat(words[0], "' in ply header"));
  46993. }
  46994. if (done) break;
  46995. }
  46996. return {
  46997. 'chunkElement': chunkElement,
  46998. 'vertexElement': vertexElement,
  46999. 'bytesPerSplat': bytesPerSplat,
  47000. 'headerSizeBytes': headerText.indexOf(HeaderEndToken) + HeaderEndToken.length + 1
  47001. };
  47002. }
  47003. static decodeHeader(plyBuffer) {
  47004. /**
  47005. * Searches for the first occurrence of a sequence within a buffer.
  47006. * @example
  47007. * find(new Uint8Array([1, 2, 3, 4]), new Uint8Array([3, 4])); // 2
  47008. * @param {Uint8Array} buf - The buffer in which to search.
  47009. * @param {Uint8Array} search - The sequence to search for.
  47010. * @return {number} The index of the first occurrence of the search sequence in the buffer, or -1 if not found.
  47011. */
  47012. var find = (buf, search) => {
  47013. var endIndex = buf.length - search.length;
  47014. var i;
  47015. var j;
  47016. for (i = 0; i <= endIndex; ++i) {
  47017. for (j = 0; j < search.length; ++j) {
  47018. if (buf[i + j] !== search[j]) {
  47019. break;
  47020. }
  47021. }
  47022. if (j === search.length) {
  47023. return i;
  47024. }
  47025. }
  47026. return -1;
  47027. };
  47028. /**
  47029. * Checks if array 'a' starts with the same elements as array 'b'.
  47030. * @example
  47031. * startsWith(new Uint8Array([1, 2, 3, 4]), new Uint8Array([1, 2])); // true
  47032. * @param {Uint8Array} a - The array to check against.
  47033. * @param {Uint8Array} b - The array of elements to look for at the start of 'a'.
  47034. * @return {boolean} - True if 'a' starts with all elements of 'b', otherwise false.
  47035. */
  47036. var startsWith = (a, b) => {
  47037. if (a.length < b.length) {
  47038. return false;
  47039. }
  47040. for (var i = 0; i < b.length; ++i) {
  47041. if (a[i] !== b[i]) {
  47042. return false;
  47043. }
  47044. }
  47045. return true;
  47046. };
  47047. var buf = new Uint8Array(plyBuffer);
  47048. var endHeaderTokenOffset;
  47049. if (buf.length >= HeaderMagicBytes.length && !startsWith(buf, HeaderMagicBytes)) {
  47050. throw new Error('Invalid PLY header');
  47051. }
  47052. endHeaderTokenOffset = find(buf, HeaderEndTokenBytes);
  47053. if (endHeaderTokenOffset === -1) {
  47054. throw new Error('End of PLY header not found');
  47055. }
  47056. var headerText = new TextDecoder('ascii').decode(buf.slice(0, endHeaderTokenOffset));
  47057. var {
  47058. chunkElement,
  47059. vertexElement,
  47060. bytesPerSplat
  47061. } = CompressedPlyParser.decodeHeaderText(headerText);
  47062. return {
  47063. 'headerSizeBytes': endHeaderTokenOffset + HeaderEndTokenBytes.length,
  47064. 'bytesPerSplat': bytesPerSplat,
  47065. 'chunkElement': chunkElement,
  47066. 'vertexElement': vertexElement
  47067. };
  47068. }
  47069. static readElementData(element, readBuffer, readOffset, fromIndex, toIndex) {
  47070. var propertyFilter = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : null;
  47071. var dataView = readBuffer instanceof DataView ? readBuffer : new DataView(readBuffer);
  47072. fromIndex = fromIndex || 0;
  47073. toIndex = toIndex || element.count - 1;
  47074. for (var e = fromIndex; e <= toIndex; ++e) {
  47075. for (var j = 0; j < element.properties.length; ++j) {
  47076. var property = element.properties[j];
  47077. var StorageType = DataTypeMap.get(property.type);
  47078. var requiredStorageSizeBytes = StorageType.BYTES_PER_ELEMENT * element.count;
  47079. if ((!property.storage || property.storage.byteLength < requiredStorageSizeBytes) && (!propertyFilter || propertyFilter(property.name))) {
  47080. property.storage = new StorageType(element.count);
  47081. }
  47082. if (property.storage) {
  47083. switch (property.type) {
  47084. case 'char':
  47085. property.storage[e] = dataView.getInt8(readOffset);
  47086. break;
  47087. case 'uchar':
  47088. property.storage[e] = dataView.getUint8(readOffset);
  47089. break;
  47090. case 'short':
  47091. property.storage[e] = dataView.getInt16(readOffset, true);
  47092. break;
  47093. case 'ushort':
  47094. property.storage[e] = dataView.getUint16(readOffset, true);
  47095. break;
  47096. case 'int':
  47097. property.storage[e] = dataView.getInt32(readOffset, true);
  47098. break;
  47099. case 'uint':
  47100. property.storage[e] = dataView.getUint32(readOffset, true);
  47101. break;
  47102. case 'float':
  47103. property.storage[e] = dataView.getFloat32(readOffset, true);
  47104. break;
  47105. case 'double':
  47106. property.storage[e] = dataView.getFloat64(readOffset, true);
  47107. break;
  47108. }
  47109. }
  47110. readOffset += property.byteSize;
  47111. }
  47112. }
  47113. return readOffset;
  47114. }
  47115. static readPly(plyBuffer) {
  47116. var propertyFilter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  47117. var header = CompressedPlyParser.decodeHeader(plyBuffer);
  47118. var readIndex = CompressedPlyParser.readElementData(header.chunkElement, plyBuffer, header.headerSizeBytes, null, null, propertyFilter);
  47119. CompressedPlyParser.readElementData(header.vertexElement, plyBuffer, readIndex, null, null, propertyFilter);
  47120. return {
  47121. 'chunkElement': header.chunkElement,
  47122. 'vertexElement': header.vertexElement
  47123. };
  47124. }
  47125. static getElementStorageArrays(chunkElement, vertexElement) {
  47126. var minX = getElementPropStorage(chunkElement, 'min_x');
  47127. var minY = getElementPropStorage(chunkElement, 'min_y');
  47128. var minZ = getElementPropStorage(chunkElement, 'min_z');
  47129. var maxX = getElementPropStorage(chunkElement, 'max_x');
  47130. var maxY = getElementPropStorage(chunkElement, 'max_y');
  47131. var maxZ = getElementPropStorage(chunkElement, 'max_z');
  47132. var minScaleX = getElementPropStorage(chunkElement, 'min_scale_x');
  47133. var minScaleY = getElementPropStorage(chunkElement, 'min_scale_y');
  47134. var minScaleZ = getElementPropStorage(chunkElement, 'min_scale_z');
  47135. var maxScaleX = getElementPropStorage(chunkElement, 'max_scale_x');
  47136. var maxScaleY = getElementPropStorage(chunkElement, 'max_scale_y');
  47137. var maxScaleZ = getElementPropStorage(chunkElement, 'max_scale_z');
  47138. var position = getElementPropStorage(vertexElement, 'packed_position');
  47139. var rotation = getElementPropStorage(vertexElement, 'packed_rotation');
  47140. var scale = getElementPropStorage(vertexElement, 'packed_scale');
  47141. var color = getElementPropStorage(vertexElement, 'packed_color');
  47142. return {
  47143. positionExtremes: {
  47144. minX,
  47145. maxX,
  47146. minY,
  47147. maxY,
  47148. minZ,
  47149. maxZ
  47150. },
  47151. scaleExtremes: {
  47152. minScaleX,
  47153. maxScaleX,
  47154. minScaleY,
  47155. maxScaleY,
  47156. minScaleZ,
  47157. maxScaleZ
  47158. },
  47159. position,
  47160. rotation,
  47161. scale,
  47162. color
  47163. };
  47164. }
  47165. static parseToUncompressedSplatBufferSection(chunkElement, vertexElement, fromIndex, toIndex, chunkSplatIndexOffset, vertexDataBuffer, veretxReadOffset, outBuffer, outOffset) {
  47166. var propertyFilter = arguments.length > 9 && arguments[9] !== undefined ? arguments[9] : null;
  47167. CompressedPlyParser.readElementData(vertexElement, vertexDataBuffer, veretxReadOffset, fromIndex, toIndex, propertyFilter);
  47168. var outBytesPerCenter = SplatBuffer.CompressionLevels[0].BytesPerCenter;
  47169. var outBytesPerScale = SplatBuffer.CompressionLevels[0].BytesPerScale;
  47170. var outBytesPerRotation = SplatBuffer.CompressionLevels[0].BytesPerRotation;
  47171. var outBytesPerSplat = SplatBuffer.CompressionLevels[0].SphericalHarmonicsDegrees[0].BytesPerSplat;
  47172. var {
  47173. positionExtremes,
  47174. scaleExtremes,
  47175. position,
  47176. rotation,
  47177. scale,
  47178. color
  47179. } = CompressedPlyParser.getElementStorageArrays(chunkElement, vertexElement);
  47180. var OFFSET = UncompressedSplatArray.OFFSET;
  47181. var tempSplat = UncompressedSplatArray.createSplat();
  47182. for (var i = fromIndex; i <= toIndex; ++i) {
  47183. CompressedPlyParser.decompressSplat(i, chunkSplatIndexOffset, position, positionExtremes, scale, scaleExtremes, rotation, color, tempSplat);
  47184. var outBase = i * outBytesPerSplat + outOffset;
  47185. var outCenter = new Float32Array(outBuffer, outBase, 3);
  47186. var outScale = new Float32Array(outBuffer, outBase + outBytesPerCenter, 3);
  47187. var outRotation = new Float32Array(outBuffer, outBase + outBytesPerCenter + outBytesPerScale, 4);
  47188. var outColor = new Uint8Array(outBuffer, outBase + outBytesPerCenter + outBytesPerScale + outBytesPerRotation, 4);
  47189. outCenter[0] = tempSplat[OFFSET.X];
  47190. outCenter[1] = tempSplat[OFFSET.Y];
  47191. outCenter[2] = tempSplat[OFFSET.Z];
  47192. outScale[0] = tempSplat[OFFSET.SCALE0];
  47193. outScale[1] = tempSplat[OFFSET.SCALE1];
  47194. outScale[2] = tempSplat[OFFSET.SCALE2];
  47195. outRotation[0] = tempSplat[OFFSET.ROTATION0];
  47196. outRotation[1] = tempSplat[OFFSET.ROTATION1];
  47197. outRotation[2] = tempSplat[OFFSET.ROTATION2];
  47198. outRotation[3] = tempSplat[OFFSET.ROTATION3];
  47199. outColor[0] = tempSplat[OFFSET.FDC0];
  47200. outColor[1] = tempSplat[OFFSET.FDC1];
  47201. outColor[2] = tempSplat[OFFSET.FDC2];
  47202. outColor[3] = tempSplat[OFFSET.OPACITY];
  47203. }
  47204. }
  47205. static parseToUncompressedSplatArray(plyBuffer) {
  47206. var {
  47207. chunkElement,
  47208. vertexElement
  47209. } = CompressedPlyParser.readPly(plyBuffer);
  47210. var splatArray = new UncompressedSplatArray();
  47211. var {
  47212. positionExtremes,
  47213. scaleExtremes,
  47214. position,
  47215. rotation,
  47216. scale,
  47217. color
  47218. } = CompressedPlyParser.getElementStorageArrays(chunkElement, vertexElement);
  47219. for (var i = 0; i < vertexElement.count; ++i) {
  47220. splatArray.addDefaultSplat();
  47221. var newSplat = splatArray.getSplat(splatArray.splatCount - 1);
  47222. CompressedPlyParser.decompressSplat(i, 0, position, positionExtremes, scale, scaleExtremes, rotation, color, newSplat);
  47223. }
  47224. var mat = new Matrix4();
  47225. mat.identity();
  47226. return splatArray;
  47227. }
  47228. }
  47229. _defineProperty(CompressedPlyParser, "decompressSplat", function () {
  47230. var p = new Vector3();
  47231. var r = new Quaternion();
  47232. var s = new Vector3();
  47233. var c = new Vector4();
  47234. var OFFSET = UncompressedSplatArray.OFFSET;
  47235. return function (index, chunkSplatIndexOffset, positionArray, positionExtremes, scaleArray, scaleExtremes, rotationArray, colorArray, outSplat) {
  47236. outSplat = outSplat || UncompressedSplatArray.createSplat();
  47237. var chunkIndex = Math.floor((chunkSplatIndexOffset + index) / 256);
  47238. unpack111011(p, positionArray[index]);
  47239. unpackRot(r, rotationArray[index]);
  47240. unpack111011(s, scaleArray[index]);
  47241. unpack8888(c, colorArray[index]);
  47242. outSplat[OFFSET.X] = lerp$1(positionExtremes.minX[chunkIndex], positionExtremes.maxX[chunkIndex], p.x);
  47243. outSplat[OFFSET.Y] = lerp$1(positionExtremes.minY[chunkIndex], positionExtremes.maxY[chunkIndex], p.y);
  47244. outSplat[OFFSET.Z] = lerp$1(positionExtremes.minZ[chunkIndex], positionExtremes.maxZ[chunkIndex], p.z);
  47245. outSplat[OFFSET.ROTATION0] = r.x;
  47246. outSplat[OFFSET.ROTATION1] = r.y;
  47247. outSplat[OFFSET.ROTATION2] = r.z;
  47248. outSplat[OFFSET.ROTATION3] = r.w;
  47249. outSplat[OFFSET.SCALE0] = Math.exp(lerp$1(scaleExtremes.minScaleX[chunkIndex], scaleExtremes.maxScaleX[chunkIndex], s.x));
  47250. outSplat[OFFSET.SCALE1] = Math.exp(lerp$1(scaleExtremes.minScaleY[chunkIndex], scaleExtremes.maxScaleY[chunkIndex], s.y));
  47251. outSplat[OFFSET.SCALE2] = Math.exp(lerp$1(scaleExtremes.minScaleZ[chunkIndex], scaleExtremes.maxScaleZ[chunkIndex], s.z));
  47252. outSplat[OFFSET.FDC0] = clamp(Math.floor(c.x * 255), 0, 255);
  47253. outSplat[OFFSET.FDC1] = clamp(Math.floor(c.y * 255), 0, 255);
  47254. outSplat[OFFSET.FDC2] = clamp(Math.floor(c.z * 255), 0, 255);
  47255. outSplat[OFFSET.OPACITY] = clamp(Math.floor(c.w * 255), 0, 255);
  47256. return outSplat;
  47257. };
  47258. }());
  47259. class PlyParser {
  47260. static checkTextForEndHeader(endHeaderTestText) {
  47261. if (endHeaderTestText.includes(PlyParser.HeaderEndToken)) {
  47262. return true;
  47263. }
  47264. return false;
  47265. }
  47266. static checkBufferForEndHeader(buffer, searchOfset, chunkSize, decoder) {
  47267. var endHeaderTestChunk = new Uint8Array(buffer, Math.max(0, searchOfset - chunkSize), chunkSize);
  47268. var endHeaderTestText = decoder.decode(endHeaderTestChunk);
  47269. return PlyParser.checkTextForEndHeader(endHeaderTestText);
  47270. }
  47271. static decodeHeaderText(headerText) {
  47272. var headerLines = headerText.split('\n');
  47273. var prunedLines = [];
  47274. var splatCount = 0;
  47275. var propertyTypes = {};
  47276. var compressed = false;
  47277. for (var i = 0; i < headerLines.length; i++) {
  47278. var line = headerLines[i].trim();
  47279. prunedLines.push(line);
  47280. if (line.startsWith('element chunk') || line.match(/[A-Za-z]*packed_[A-Za-z]*/)) {
  47281. compressed = true;
  47282. } else if (line.startsWith('element vertex')) {
  47283. var splatCountMatch = line.match(/\d+/);
  47284. if (splatCountMatch) {
  47285. splatCount = parseInt(splatCountMatch[0]);
  47286. }
  47287. } else if (line.startsWith('property')) {
  47288. var propertyMatch = line.match(/(\w+)\s+(\w+)\s+(\w+)/);
  47289. if (propertyMatch) {
  47290. var propertyType = propertyMatch[2];
  47291. var propertyName = propertyMatch[3];
  47292. propertyTypes[propertyName] = propertyType;
  47293. }
  47294. } else if (line === PlyParser.HeaderEndToken) {
  47295. break;
  47296. }
  47297. }
  47298. var bytesPerSplat = 0;
  47299. var fieldOffsets = {};
  47300. var fieldSize = {
  47301. 'double': 8,
  47302. 'int': 4,
  47303. 'uint': 4,
  47304. 'float': 4,
  47305. 'short': 2,
  47306. 'ushort': 2,
  47307. 'uchar': 1
  47308. };
  47309. var fieldNames = [];
  47310. for (var fieldName in propertyTypes) {
  47311. if (propertyTypes.hasOwnProperty(fieldName)) {
  47312. fieldNames.push(fieldName);
  47313. var type = propertyTypes[fieldName];
  47314. fieldOffsets[fieldName] = bytesPerSplat;
  47315. bytesPerSplat += fieldSize[type];
  47316. }
  47317. }
  47318. var sphericalHarmonicsFieldCount = 0;
  47319. var sphericalHarmonicsCoefficientsPerChannel = 0;
  47320. for (var _fieldName of fieldNames) {
  47321. if (_fieldName.startsWith('f_rest')) sphericalHarmonicsFieldCount++;
  47322. }
  47323. sphericalHarmonicsCoefficientsPerChannel = sphericalHarmonicsFieldCount / 3;
  47324. var sphericalHarmonicsDegree = 0;
  47325. if (sphericalHarmonicsCoefficientsPerChannel >= 3) sphericalHarmonicsDegree = 1;
  47326. if (sphericalHarmonicsCoefficientsPerChannel >= 8) sphericalHarmonicsDegree = 2;
  47327. var sphericalHarmonicsDegree1Fields = [];
  47328. if (sphericalHarmonicsDegree >= 1) {
  47329. for (var rgb = 0; rgb < 3; rgb++) {
  47330. for (var _i9 = 0; _i9 < 3; _i9++) {
  47331. sphericalHarmonicsDegree1Fields.push('f_rest_' + (_i9 + sphericalHarmonicsCoefficientsPerChannel * rgb));
  47332. }
  47333. }
  47334. }
  47335. var sphericalHarmonicsDegree2Fields = [];
  47336. if (sphericalHarmonicsDegree >= 2) {
  47337. for (var _rgb = 0; _rgb < 3; _rgb++) {
  47338. for (var _i10 = 0; _i10 < 5; _i10++) {
  47339. sphericalHarmonicsDegree2Fields.push('f_rest_' + (_i10 + sphericalHarmonicsCoefficientsPerChannel * _rgb + 3));
  47340. }
  47341. }
  47342. }
  47343. return {
  47344. 'splatCount': splatCount,
  47345. 'propertyTypes': propertyTypes,
  47346. 'compressed': compressed,
  47347. 'headerText': headerText,
  47348. 'headerLines': prunedLines,
  47349. 'headerSizeBytes': headerText.indexOf(PlyParser.HeaderEndToken) + PlyParser.HeaderEndToken.length + 1,
  47350. 'bytesPerSplat': bytesPerSplat,
  47351. 'fieldOffsets': fieldOffsets,
  47352. 'sphericalHarmonicsDegree': sphericalHarmonicsDegree,
  47353. 'sphericalHarmonicsCoefficientsPerChannel': sphericalHarmonicsCoefficientsPerChannel,
  47354. 'sphericalHarmonicsDegree1Fields': sphericalHarmonicsDegree1Fields,
  47355. 'sphericalHarmonicsDegree2Fields': sphericalHarmonicsDegree2Fields
  47356. };
  47357. }
  47358. static decodeHeadeFromBuffer(plyBuffer) {
  47359. var decoder = new TextDecoder();
  47360. var headerOffset = 0;
  47361. var headerText = '';
  47362. var readChunkSize = 100;
  47363. while (true) {
  47364. if (headerOffset + readChunkSize >= plyBuffer.byteLength) {
  47365. throw new Error('End of file reached while searching for end of header');
  47366. }
  47367. var headerChunk = new Uint8Array(plyBuffer, headerOffset, readChunkSize);
  47368. headerText += decoder.decode(headerChunk);
  47369. headerOffset += readChunkSize;
  47370. if (PlyParser.checkBufferForEndHeader(plyBuffer, headerOffset, readChunkSize * 2, decoder)) {
  47371. break;
  47372. }
  47373. }
  47374. return PlyParser.decodeHeaderText(headerText);
  47375. }
  47376. static findVertexData(plyBuffer, header) {
  47377. return new DataView(plyBuffer, header.headerSizeBytes);
  47378. }
  47379. static readRawVertexFast(vertexData, offset, fieldOffsets, propertiesToRead, propertyTypes, outVertex) {
  47380. var rawVertex = outVertex || {};
  47381. for (var property of propertiesToRead) {
  47382. var propertyType = propertyTypes[property];
  47383. if (propertyType === 'float') {
  47384. rawVertex[property] = vertexData.getFloat32(offset + fieldOffsets[property], true);
  47385. } else if (propertyType === 'double') {
  47386. //xzw add! 因为我试过一个ply的坐标是double
  47387. rawVertex[property] = vertexData.getFloat64(offset + fieldOffsets[property], true);
  47388. } else if (propertyType === 'uchar') {
  47389. rawVertex[property] = vertexData.getUint8(offset + fieldOffsets[property]) / 255.0;
  47390. }
  47391. }
  47392. }
  47393. static parseToUncompressedSplatBufferSection(header, fromSplat, toSplat, vertexData, vertexDataOffset, toBuffer, toOffset) {
  47394. var outSphericalHarmonicsDegree = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : 0;
  47395. outSphericalHarmonicsDegree = Math.min(outSphericalHarmonicsDegree, header.sphericalHarmonicsDegree);
  47396. var outBytesPerCenter = SplatBuffer.CompressionLevels[0].BytesPerCenter;
  47397. var outBytesPerScale = SplatBuffer.CompressionLevels[0].BytesPerScale;
  47398. var outBytesPerRotation = SplatBuffer.CompressionLevels[0].BytesPerRotation;
  47399. var outBytesPerColor = SplatBuffer.CompressionLevels[0].BytesPerColor;
  47400. var outBytesPerSplat = SplatBuffer.CompressionLevels[0].SphericalHarmonicsDegrees[outSphericalHarmonicsDegree].BytesPerSplat;
  47401. for (var i = fromSplat; i <= toSplat; i++) {
  47402. var parsedSplat = PlyParser.parseToUncompressedSplat(vertexData, i, header, vertexDataOffset, outSphericalHarmonicsDegree);
  47403. var outBase = i * outBytesPerSplat + toOffset;
  47404. var outCenter = new Float32Array(toBuffer, outBase, 3);
  47405. var outScale = new Float32Array(toBuffer, outBase + outBytesPerCenter, 3);
  47406. var outRotation = new Float32Array(toBuffer, outBase + outBytesPerCenter + outBytesPerScale, 4);
  47407. var outColor = new Uint8Array(toBuffer, outBase + outBytesPerCenter + outBytesPerScale + outBytesPerRotation, 4);
  47408. outCenter[0] = parsedSplat[UncompressedSplatArray.OFFSET.X];
  47409. outCenter[1] = parsedSplat[UncompressedSplatArray.OFFSET.Y];
  47410. outCenter[2] = parsedSplat[UncompressedSplatArray.OFFSET.Z];
  47411. outScale[0] = parsedSplat[UncompressedSplatArray.OFFSET.SCALE0];
  47412. outScale[1] = parsedSplat[UncompressedSplatArray.OFFSET.SCALE1];
  47413. outScale[2] = parsedSplat[UncompressedSplatArray.OFFSET.SCALE2];
  47414. outRotation[0] = parsedSplat[UncompressedSplatArray.OFFSET.ROTATION0];
  47415. outRotation[1] = parsedSplat[UncompressedSplatArray.OFFSET.ROTATION1];
  47416. outRotation[2] = parsedSplat[UncompressedSplatArray.OFFSET.ROTATION2];
  47417. outRotation[3] = parsedSplat[UncompressedSplatArray.OFFSET.ROTATION3];
  47418. outColor[0] = parsedSplat[UncompressedSplatArray.OFFSET.FDC0];
  47419. outColor[1] = parsedSplat[UncompressedSplatArray.OFFSET.FDC1];
  47420. outColor[2] = parsedSplat[UncompressedSplatArray.OFFSET.FDC2];
  47421. outColor[3] = parsedSplat[UncompressedSplatArray.OFFSET.OPACITY];
  47422. if (outSphericalHarmonicsDegree >= 1) {
  47423. var outSphericalHarmonics = new Float32Array(toBuffer, outBase + outBytesPerCenter + outBytesPerScale + outBytesPerRotation + outBytesPerColor, parsedSplat.sphericalHarmonicsCount);
  47424. for (var _i11 = 0; _i11 <= 8; _i11++) {
  47425. outSphericalHarmonics[_i11] = parsedSplat[UncompressedSplatArray.OFFSET.FRC0 + _i11];
  47426. }
  47427. if (outSphericalHarmonicsDegree >= 2) {
  47428. for (var _i12 = 9; _i12 <= 23; _i12++) {
  47429. outSphericalHarmonics[_i12] = parsedSplat[UncompressedSplatArray.OFFSET.FRC0 + _i12];
  47430. }
  47431. }
  47432. }
  47433. }
  47434. }
  47435. static parseToUncompressedSplatArray(plyBuffer) {
  47436. var outSphericalHarmonicsDegree = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  47437. var header = PlyParser.decodeHeadeFromBuffer(plyBuffer);
  47438. if (header.compressed) {
  47439. return CompressedPlyParser.parseToUncompressedSplatArray(plyBuffer);
  47440. } else {
  47441. var splatCount = header.splatCount;
  47442. var vertexData = PlyParser.findVertexData(plyBuffer, header);
  47443. // TODO: Eventually properly support multiple degree spherical harmonics
  47444. // figure out the SH degree from the number of coefficients
  47445. /* let nRestCoeffs = 0;
  47446. for (const propertyName in header.propertyTypes) {
  47447. if (propertyName.startsWith('f_rest_')) {
  47448. nRestCoeffs += 1;
  47449. }
  47450. }
  47451. const nCoeffsPerColor = nRestCoeffs / 3;*/
  47452. // const sphericalHarmonicsDegree = Math.sqrt(nCoeffsPerColor + 1) - 1;
  47453. // const sphericalHarmonicsDegree = 0;
  47454. // console.log('Detected degree', sphericalHarmonicsDegree, 'with ', nCoeffsPerColor, 'coefficients per color');
  47455. // figure out the order in which spherical harmonics should be read
  47456. /* const shFeatureOrder = [];
  47457. for (let rgb = 0; rgb < 3; ++rgb) {
  47458. shFeatureOrder.push(`f_dc_${rgb}`);
  47459. }
  47460. for (let i = 0; i < nCoeffsPerColor; ++i) {
  47461. for (let rgb = 0; rgb < 3; ++rgb) {
  47462. shFeatureOrder.push(`f_rest_${rgb * nCoeffsPerColor + i}`);
  47463. }
  47464. }*/
  47465. var splatArray = new UncompressedSplatArray(outSphericalHarmonicsDegree);
  47466. for (var row = 0; row < splatCount; row++) {
  47467. var newSplat = PlyParser.parseToUncompressedSplat(vertexData, row, header, 0, outSphericalHarmonicsDegree);
  47468. splatArray.addSplat(newSplat);
  47469. }
  47470. return splatArray;
  47471. }
  47472. }
  47473. }
  47474. _PlyParser = PlyParser;
  47475. _defineProperty(PlyParser, "HeaderEndToken", 'end_header');
  47476. _defineProperty(PlyParser, "BaseFields", ['scale_0', 'scale_1', 'scale_2', 'rot_0', 'rot_1', 'rot_2', 'rot_3', 'x', 'y', 'z', 'f_dc_0', 'f_dc_1', 'f_dc_2', 'red', 'green', 'blue', 'opacity']);
  47477. _defineProperty(PlyParser, "SphericalHarmonicsFields", Array.from(Array(45)).map((e, i) => "f_rest_".concat(i)));
  47478. _defineProperty(PlyParser, "Fields", [[..._PlyParser.BaseFields], [..._PlyParser.BaseFields, ..._PlyParser.SphericalHarmonicsFields]]);
  47479. _defineProperty(PlyParser, "parseToUncompressedSplat", function () {
  47480. var rawVertex = {};
  47481. var tempRotation = new Quaternion();
  47482. return function (vertexData, row, header) {
  47483. var vertexDataOffset = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
  47484. var outSphericalHarmonicsDegree = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
  47485. outSphericalHarmonicsDegree = Math.min(outSphericalHarmonicsDegree, header.sphericalHarmonicsDegree);
  47486. _PlyParser.readRawVertexFast(vertexData, row * header.bytesPerSplat + vertexDataOffset, header.fieldOffsets, _PlyParser.Fields[outSphericalHarmonicsDegree > 0 ? 1 : 0], header.propertyTypes, rawVertex);
  47487. var newSplat = UncompressedSplatArray.createSplat(outSphericalHarmonicsDegree);
  47488. if (rawVertex['scale_0'] !== undefined) {
  47489. newSplat[UncompressedSplatArray.OFFSET.SCALE0] = Math.exp(rawVertex['scale_0']);
  47490. newSplat[UncompressedSplatArray.OFFSET.SCALE1] = Math.exp(rawVertex['scale_1']);
  47491. newSplat[UncompressedSplatArray.OFFSET.SCALE2] = Math.exp(rawVertex['scale_2']);
  47492. } else {
  47493. newSplat[UncompressedSplatArray.OFFSET.SCALE0] = 0.01;
  47494. newSplat[UncompressedSplatArray.OFFSET.SCALE1] = 0.01;
  47495. newSplat[UncompressedSplatArray.OFFSET.SCALE2] = 0.01;
  47496. }
  47497. if (rawVertex['f_dc_0'] !== undefined) {
  47498. var SH_C0 = 0.28209479177387814;
  47499. newSplat[UncompressedSplatArray.OFFSET.FDC0] = (0.5 + SH_C0 * rawVertex['f_dc_0']) * 255;
  47500. newSplat[UncompressedSplatArray.OFFSET.FDC1] = (0.5 + SH_C0 * rawVertex['f_dc_1']) * 255;
  47501. newSplat[UncompressedSplatArray.OFFSET.FDC2] = (0.5 + SH_C0 * rawVertex['f_dc_2']) * 255;
  47502. } else if (rawVertex['red'] !== undefined) {
  47503. newSplat[UncompressedSplatArray.OFFSET.FDC0] = rawVertex['red'] * 255;
  47504. newSplat[UncompressedSplatArray.OFFSET.FDC1] = rawVertex['green'] * 255;
  47505. newSplat[UncompressedSplatArray.OFFSET.FDC2] = rawVertex['blue'] * 255;
  47506. } else {
  47507. newSplat[UncompressedSplatArray.OFFSET.FDC0] = 0;
  47508. newSplat[UncompressedSplatArray.OFFSET.FDC1] = 0;
  47509. newSplat[UncompressedSplatArray.OFFSET.FDC2] = 0;
  47510. }
  47511. if (rawVertex['opacity'] !== undefined) {
  47512. newSplat[UncompressedSplatArray.OFFSET.OPACITY] = 1 / (1 + Math.exp(-rawVertex['opacity'])) * 255;
  47513. } else {
  47514. //xzw add
  47515. newSplat[UncompressedSplatArray.OFFSET.OPACITY] = 1;
  47516. }
  47517. newSplat[UncompressedSplatArray.OFFSET.FDC0] = clamp(Math.floor(newSplat[UncompressedSplatArray.OFFSET.FDC0]), 0, 255);
  47518. newSplat[UncompressedSplatArray.OFFSET.FDC1] = clamp(Math.floor(newSplat[UncompressedSplatArray.OFFSET.FDC1]), 0, 255);
  47519. newSplat[UncompressedSplatArray.OFFSET.FDC2] = clamp(Math.floor(newSplat[UncompressedSplatArray.OFFSET.FDC2]), 0, 255);
  47520. newSplat[UncompressedSplatArray.OFFSET.OPACITY] = clamp(Math.floor(newSplat[UncompressedSplatArray.OFFSET.OPACITY]), 0, 255);
  47521. if (outSphericalHarmonicsDegree >= 1) {
  47522. if (rawVertex['f_rest_0'] !== undefined) {
  47523. for (var i = 0; i < 9; i++) {
  47524. newSplat[UncompressedSplatArray.OFFSET.FRC0 + i] = rawVertex[header.sphericalHarmonicsDegree1Fields[i]];
  47525. }
  47526. if (outSphericalHarmonicsDegree >= 2) {
  47527. for (var _i23 = 0; _i23 < 15; _i23++) {
  47528. newSplat[UncompressedSplatArray.OFFSET.FRC9 + _i23] = rawVertex[header.sphericalHarmonicsDegree2Fields[_i23]];
  47529. }
  47530. }
  47531. } else {
  47532. newSplat[UncompressedSplatArray.OFFSET.FRC0] = 0;
  47533. newSplat[UncompressedSplatArray.OFFSET.FRC1] = 0;
  47534. newSplat[UncompressedSplatArray.OFFSET.FRC2] = 0;
  47535. }
  47536. }
  47537. if (rawVertex['rot_0'] == void 0) {
  47538. //xzw add 表现为任何方向都是圆形 sprite
  47539. tempRotation.set(0, 0, 0, 1);
  47540. } else {
  47541. tempRotation.set(rawVertex['rot_0'], rawVertex['rot_1'], rawVertex['rot_2'], rawVertex['rot_3']);
  47542. tempRotation.normalize();
  47543. }
  47544. newSplat[UncompressedSplatArray.OFFSET.ROTATION0] = tempRotation.x;
  47545. newSplat[UncompressedSplatArray.OFFSET.ROTATION1] = tempRotation.y;
  47546. newSplat[UncompressedSplatArray.OFFSET.ROTATION2] = tempRotation.z;
  47547. newSplat[UncompressedSplatArray.OFFSET.ROTATION3] = tempRotation.w;
  47548. newSplat[UncompressedSplatArray.OFFSET.X] = rawVertex['x'];
  47549. newSplat[UncompressedSplatArray.OFFSET.Y] = rawVertex['y'];
  47550. newSplat[UncompressedSplatArray.OFFSET.Z] = rawVertex['z'];
  47551. return newSplat;
  47552. };
  47553. }());
  47554. class SplatPartitioner {
  47555. constructor(sectionCount, sectionFilters, groupingParameters, partitionGenerator) {
  47556. this.sectionCount = sectionCount;
  47557. this.sectionFilters = sectionFilters;
  47558. this.groupingParameters = groupingParameters;
  47559. this.partitionGenerator = partitionGenerator;
  47560. }
  47561. partitionUncompressedSplatArray(splatArray) {
  47562. var groupingParameters;
  47563. var sectionCount;
  47564. var sectionFilters;
  47565. if (this.partitionGenerator) {
  47566. var results = this.partitionGenerator(splatArray);
  47567. groupingParameters = results.groupingParameters;
  47568. sectionCount = results.sectionCount;
  47569. sectionFilters = results.sectionFilters;
  47570. } else {
  47571. groupingParameters = this.groupingParameters;
  47572. sectionCount = this.sectionCount;
  47573. sectionFilters = this.sectionFilters;
  47574. }
  47575. var newArrays = [];
  47576. for (var s = 0; s < sectionCount; s++) {
  47577. var sectionSplats = new UncompressedSplatArray(splatArray.sphericalHarmonicsDegree);
  47578. var sectionFilter = sectionFilters[s];
  47579. for (var i = 0; i < splatArray.splatCount; i++) {
  47580. if (sectionFilter(i)) {
  47581. sectionSplats.addSplatFromArray(splatArray, i);
  47582. }
  47583. }
  47584. newArrays.push(sectionSplats);
  47585. }
  47586. return {
  47587. splatArrays: newArrays,
  47588. parameters: groupingParameters
  47589. };
  47590. }
  47591. static getStandardPartitioner() {
  47592. var partitionSize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  47593. var sceneCenter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Vector3();
  47594. var blockSize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : SplatBuffer.BucketBlockSize;
  47595. var bucketSize = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : SplatBuffer.BucketSize;
  47596. var partitionGenerator = splatArray => {
  47597. if (partitionSize <= 0) partitionSize = splatArray.splatCount;
  47598. var centerA = new Vector3();
  47599. var centerB = new Vector3();
  47600. var clampDistance = 0.5;
  47601. var clampPoint = point => {
  47602. point.x = Math.floor(point.x / clampDistance) * clampDistance;
  47603. point.y = Math.floor(point.y / clampDistance) * clampDistance;
  47604. point.z = Math.floor(point.z / clampDistance) * clampDistance;
  47605. };
  47606. splatArray.splats.sort((a, b) => {
  47607. centerA.set(a[UncompressedSplatArray.OFFSET.X], a[UncompressedSplatArray.OFFSET.Y], a[UncompressedSplatArray.OFFSET.Z]).sub(sceneCenter);
  47608. clampPoint(centerA);
  47609. var centerADist = centerA.lengthSq();
  47610. centerB.set(b[UncompressedSplatArray.OFFSET.X], b[UncompressedSplatArray.OFFSET.Y], b[UncompressedSplatArray.OFFSET.Z]).sub(sceneCenter);
  47611. clampPoint(centerB);
  47612. var centerBDist = centerB.lengthSq();
  47613. if (centerADist > centerBDist) return 1;else return -1;
  47614. });
  47615. var sectionFilters = [];
  47616. var groupingParameters = [];
  47617. partitionSize = Math.min(splatArray.splatCount, partitionSize);
  47618. var patitionCount = Math.ceil(splatArray.splatCount / partitionSize);
  47619. var currentStartSplat = 0;
  47620. var _loop = function _loop() {
  47621. var startSplat = currentStartSplat;
  47622. sectionFilters.push(splatIndex => {
  47623. return splatIndex >= startSplat && splatIndex < startSplat + partitionSize;
  47624. });
  47625. groupingParameters.push({
  47626. 'blocksSize': blockSize,
  47627. 'bucketSize': bucketSize
  47628. });
  47629. currentStartSplat += partitionSize;
  47630. };
  47631. for (var i = 0; i < patitionCount; i++) {
  47632. _loop();
  47633. }
  47634. return {
  47635. 'sectionCount': sectionFilters.length,
  47636. sectionFilters,
  47637. groupingParameters
  47638. };
  47639. };
  47640. return new SplatPartitioner(undefined, undefined, undefined, partitionGenerator);
  47641. }
  47642. }
  47643. class SplatBufferGenerator {
  47644. constructor(splatPartitioner, alphaRemovalThreshold, compressionLevel, sectionSize, sceneCenter, blockSize, bucketSize) {
  47645. this.splatPartitioner = splatPartitioner;
  47646. this.alphaRemovalThreshold = alphaRemovalThreshold;
  47647. this.compressionLevel = compressionLevel;
  47648. this.sectionSize = sectionSize;
  47649. this.sceneCenter = sceneCenter ? new Vector3().copy(sceneCenter) : undefined;
  47650. this.blockSize = blockSize;
  47651. this.bucketSize = bucketSize;
  47652. }
  47653. generateFromUncompressedSplatArray(splatArray) {
  47654. var partitionResults = this.splatPartitioner.partitionUncompressedSplatArray(splatArray);
  47655. return SplatBuffer.generateFromUncompressedSplatArrays(partitionResults.splatArrays, this.alphaRemovalThreshold, this.compressionLevel, this.sceneCenter, this.blockSize, this.bucketSize, partitionResults.parameters);
  47656. }
  47657. static getStandardGenerator() {
  47658. var alphaRemovalThreshold = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
  47659. var compressionLevel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
  47660. var sectionSize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  47661. var sceneCenter = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : new Vector3();
  47662. var blockSize = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : SplatBuffer.BucketBlockSize;
  47663. var bucketSize = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : SplatBuffer.BucketSize;
  47664. var splatPartitioner = SplatPartitioner.getStandardPartitioner(sectionSize, sceneCenter, blockSize, bucketSize);
  47665. return new SplatBufferGenerator(splatPartitioner, alphaRemovalThreshold, compressionLevel, sectionSize, sceneCenter, blockSize, bucketSize);
  47666. }
  47667. }
  47668. var LoaderStatus = {
  47669. 'Downloading': 0,
  47670. 'Processing': 1,
  47671. 'Done': 2
  47672. };
  47673. class Constants {}
  47674. _defineProperty(Constants, "DepthMapRange", 1 << 16);
  47675. _defineProperty(Constants, "MemoryPageSize", 65536);
  47676. _defineProperty(Constants, "BytesPerFloat", 4);
  47677. _defineProperty(Constants, "BytesPerInt", 4);
  47678. _defineProperty(Constants, "MaxScenes", 32);
  47679. _defineProperty(Constants, "StreamingSectionSize", 524288);
  47680. function storeChunksInBuffer(chunks, buffer) {
  47681. var inBytes = 0;
  47682. for (var chunk of chunks) inBytes += chunk.sizeBytes;
  47683. if (!buffer || buffer.byteLength < inBytes) {
  47684. buffer = new ArrayBuffer(inBytes);
  47685. }
  47686. var offset = 0;
  47687. for (var _chunk of chunks) {
  47688. new Uint8Array(buffer, offset, _chunk.sizeBytes).set(_chunk.data);
  47689. offset += _chunk.sizeBytes;
  47690. }
  47691. return buffer;
  47692. }
  47693. class PlyLoader {
  47694. static loadFromURL(fileName, onProgress, streamLoadData, onStreamedSectionProgress, minimumAlpha, compressionLevel) {
  47695. var outSphericalHarmonicsDegree = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 0;
  47696. var sectionSize = arguments.length > 7 ? arguments[7] : undefined;
  47697. var sceneCenter = arguments.length > 8 ? arguments[8] : undefined;
  47698. var blockSize = arguments.length > 9 ? arguments[9] : undefined;
  47699. var bucketSize = arguments.length > 10 ? arguments[10] : undefined;
  47700. var streamedSectionSizeBytes = Constants.StreamingSectionSize;
  47701. var splatDataOffsetBytes = SplatBuffer.HeaderSizeBytes + SplatBuffer.SectionHeaderSizeBytes;
  47702. var sectionCount = 1;
  47703. var streamBufferIn;
  47704. var streamBufferOut;
  47705. var streamedSplatBuffer;
  47706. var compressedPlyHeaderChunksBuffer;
  47707. var maxSplatCount = 0;
  47708. var splatCount = 0;
  47709. var headerLoaded = false;
  47710. var readyToLoadSplatData = false;
  47711. var compressed = false;
  47712. var streamLoadCompleteResolver;
  47713. var streamLoadPromise = new Promise(resolve => {
  47714. streamLoadCompleteResolver = resolve;
  47715. });
  47716. var numBytesStreamed = 0;
  47717. var numBytesParsed = 0;
  47718. var numBytesDownloaded = 0;
  47719. var headerText = '';
  47720. var header = null;
  47721. var chunks = [];
  47722. var textDecoder = new TextDecoder();
  47723. var localOnProgress = (percent, percentLabel, chunkData) => {
  47724. var loadComplete = percent >= 100;
  47725. if (streamLoadData) {
  47726. if (chunkData) {
  47727. chunks.push({
  47728. 'data': chunkData,
  47729. 'sizeBytes': chunkData.byteLength,
  47730. 'startBytes': numBytesDownloaded,
  47731. 'endBytes': numBytesDownloaded + chunkData.byteLength
  47732. });
  47733. numBytesDownloaded += chunkData.byteLength;
  47734. }
  47735. if (!headerLoaded) {
  47736. headerText += textDecoder.decode(chunkData);
  47737. if (PlyParser.checkTextForEndHeader(headerText)) {
  47738. header = PlyParser.decodeHeaderText(headerText);
  47739. outSphericalHarmonicsDegree = Math.min(outSphericalHarmonicsDegree, header.sphericalHarmonicsDegree);
  47740. compressed = header.compressed;
  47741. if (compressed) {
  47742. header = CompressedPlyParser.decodeHeaderText(headerText);
  47743. maxSplatCount = header.vertexElement.count;
  47744. } else {
  47745. maxSplatCount = header.splatCount;
  47746. readyToLoadSplatData = true;
  47747. }
  47748. var shDescriptor = SplatBuffer.CompressionLevels[0].SphericalHarmonicsDegrees[outSphericalHarmonicsDegree];
  47749. var splatBufferSizeBytes = splatDataOffsetBytes + shDescriptor.BytesPerSplat * maxSplatCount;
  47750. streamBufferOut = new ArrayBuffer(splatBufferSizeBytes);
  47751. SplatBuffer.writeHeaderToBuffer({
  47752. versionMajor: SplatBuffer.CurrentMajorVersion,
  47753. versionMinor: SplatBuffer.CurrentMinorVersion,
  47754. maxSectionCount: sectionCount,
  47755. sectionCount: sectionCount,
  47756. maxSplatCount: maxSplatCount,
  47757. splatCount: splatCount,
  47758. compressionLevel: 0,
  47759. sceneCenter: new Vector3()
  47760. }, streamBufferOut);
  47761. numBytesStreamed = header.headerSizeBytes;
  47762. numBytesParsed = header.headerSizeBytes;
  47763. headerLoaded = true;
  47764. }
  47765. } else if (compressed && !readyToLoadSplatData) {
  47766. var sizeRequiredForHeaderAndChunks = header.headerSizeBytes + header.chunkElement.storageSizeBytes;
  47767. compressedPlyHeaderChunksBuffer = storeChunksInBuffer(chunks, compressedPlyHeaderChunksBuffer);
  47768. if (compressedPlyHeaderChunksBuffer.byteLength >= sizeRequiredForHeaderAndChunks) {
  47769. CompressedPlyParser.readElementData(header.chunkElement, compressedPlyHeaderChunksBuffer, header.headerSizeBytes);
  47770. numBytesStreamed = sizeRequiredForHeaderAndChunks;
  47771. numBytesParsed = sizeRequiredForHeaderAndChunks;
  47772. readyToLoadSplatData = true;
  47773. }
  47774. }
  47775. if (headerLoaded && readyToLoadSplatData) {
  47776. if (chunks.length > 0) {
  47777. streamBufferIn = storeChunksInBuffer(chunks, streamBufferIn);
  47778. var bytesLoadedSinceLastStreamedSection = numBytesDownloaded - numBytesStreamed;
  47779. if (bytesLoadedSinceLastStreamedSection > streamedSectionSizeBytes || loadComplete) {
  47780. var numBytesToProcess = numBytesDownloaded - numBytesParsed;
  47781. var addedSplatCount = Math.floor(numBytesToProcess / header.bytesPerSplat);
  47782. var numBytesToParse = addedSplatCount * header.bytesPerSplat;
  47783. var numBytesLeftOver = numBytesToProcess - numBytesToParse;
  47784. var newSplatCount = splatCount + addedSplatCount;
  47785. var parsedDataViewOffset = numBytesParsed - chunks[0].startBytes;
  47786. var dataToParse = new DataView(streamBufferIn, parsedDataViewOffset, numBytesToParse);
  47787. var _shDescriptor = SplatBuffer.CompressionLevels[0].SphericalHarmonicsDegrees[outSphericalHarmonicsDegree];
  47788. var outOffset = splatCount * _shDescriptor.BytesPerSplat + splatDataOffsetBytes;
  47789. if (compressed) {
  47790. CompressedPlyParser.parseToUncompressedSplatBufferSection(header.chunkElement, header.vertexElement, 0, addedSplatCount - 1, splatCount, dataToParse, 0, streamBufferOut, outOffset);
  47791. } else {
  47792. PlyParser.parseToUncompressedSplatBufferSection(header, 0, addedSplatCount - 1, dataToParse, 0, streamBufferOut, outOffset, outSphericalHarmonicsDegree);
  47793. }
  47794. splatCount = newSplatCount;
  47795. if (!streamedSplatBuffer) {
  47796. SplatBuffer.writeSectionHeaderToBuffer({
  47797. maxSplatCount: maxSplatCount,
  47798. splatCount: splatCount,
  47799. bucketSize: 0,
  47800. bucketCount: 0,
  47801. bucketBlockSize: 0,
  47802. compressionScaleRange: 0,
  47803. storageSizeBytes: 0,
  47804. fullBucketCount: 0,
  47805. partiallyFilledBucketCount: 0,
  47806. sphericalHarmonicsDegree: outSphericalHarmonicsDegree
  47807. }, 0, streamBufferOut, SplatBuffer.HeaderSizeBytes);
  47808. streamedSplatBuffer = new SplatBuffer(streamBufferOut, false);
  47809. }
  47810. streamedSplatBuffer.updateLoadedCounts(1, splatCount);
  47811. onStreamedSectionProgress(streamedSplatBuffer, loadComplete);
  47812. numBytesStreamed += streamedSectionSizeBytes;
  47813. numBytesParsed += numBytesToParse;
  47814. if (numBytesLeftOver === 0) {
  47815. chunks = [];
  47816. } else {
  47817. var keepChunks = [];
  47818. var keepSize = 0;
  47819. for (var i = chunks.length - 1; i >= 0; i--) {
  47820. var chunk = chunks[i];
  47821. keepSize += chunk.sizeBytes;
  47822. keepChunks.unshift(chunk);
  47823. if (keepSize >= numBytesLeftOver) break;
  47824. }
  47825. chunks = keepChunks;
  47826. }
  47827. }
  47828. }
  47829. if (loadComplete) {
  47830. streamLoadCompleteResolver(streamedSplatBuffer);
  47831. }
  47832. }
  47833. }
  47834. if (onProgress) onProgress(percent, percentLabel, LoaderStatus.Downloading);
  47835. };
  47836. return fetchWithProgress(fileName, localOnProgress, !streamLoadData).then(plyFileData => {
  47837. if (onProgress) onProgress(0, '0%', LoaderStatus.Processing);
  47838. var loadPromise = streamLoadData ? streamLoadPromise : PlyLoader.loadFromFileData(plyFileData, minimumAlpha, compressionLevel, outSphericalHarmonicsDegree, sectionSize, sceneCenter, blockSize, bucketSize);
  47839. return loadPromise.then(splatBuffer => {
  47840. if (onProgress) onProgress(100, '100%', LoaderStatus.Done);
  47841. return splatBuffer;
  47842. });
  47843. });
  47844. }
  47845. static loadFromFileData(plyFileData, minimumAlpha, compressionLevel) {
  47846. var outSphericalHarmonicsDegree = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
  47847. var sectionSize = arguments.length > 4 ? arguments[4] : undefined;
  47848. var sceneCenter = arguments.length > 5 ? arguments[5] : undefined;
  47849. var blockSize = arguments.length > 6 ? arguments[6] : undefined;
  47850. var bucketSize = arguments.length > 7 ? arguments[7] : undefined;
  47851. return delayedExecute(() => {
  47852. return PlyParser.parseToUncompressedSplatArray(plyFileData, outSphericalHarmonicsDegree);
  47853. }).then(splatArray => {
  47854. var splatBufferGenerator = SplatBufferGenerator.getStandardGenerator(minimumAlpha, compressionLevel, sectionSize, sceneCenter, blockSize, bucketSize);
  47855. return splatBufferGenerator.generateFromUncompressedSplatArray(splatArray);
  47856. });
  47857. }
  47858. }
  47859. class SplatParser {
  47860. static parseToUncompressedSplatBufferSection(fromSplat, toSplat, fromBuffer, fromOffset, toBuffer, toOffset) {
  47861. var outBytesPerCenter = SplatBuffer.CompressionLevels[0].BytesPerCenter;
  47862. var outBytesPerScale = SplatBuffer.CompressionLevels[0].BytesPerScale;
  47863. var outBytesPerRotation = SplatBuffer.CompressionLevels[0].BytesPerRotation;
  47864. var outBytesPerSplat = SplatBuffer.CompressionLevels[0].SphericalHarmonicsDegrees[0].BytesPerSplat;
  47865. for (var i = fromSplat; i <= toSplat; i++) {
  47866. var inBase = i * SplatParser.RowSizeBytes + fromOffset;
  47867. var inCenter = new Float32Array(fromBuffer, inBase, 3);
  47868. var inScale = new Float32Array(fromBuffer, inBase + SplatParser.CenterSizeBytes, 3);
  47869. var inColor = new Uint8Array(fromBuffer, inBase + SplatParser.CenterSizeBytes + SplatParser.ScaleSizeBytes, 4);
  47870. var inRotation = new Uint8Array(fromBuffer, inBase + SplatParser.CenterSizeBytes + SplatParser.ScaleSizeBytes + SplatParser.RotationSizeBytes, 4);
  47871. var quat = new Quaternion((inRotation[1] - 128) / 128, (inRotation[2] - 128) / 128, (inRotation[3] - 128) / 128, (inRotation[0] - 128) / 128);
  47872. quat.normalize();
  47873. var outBase = i * outBytesPerSplat + toOffset;
  47874. var outCenter = new Float32Array(toBuffer, outBase, 3);
  47875. var outScale = new Float32Array(toBuffer, outBase + outBytesPerCenter, 3);
  47876. var outRotation = new Float32Array(toBuffer, outBase + outBytesPerCenter + outBytesPerScale, 4);
  47877. var outColor = new Uint8Array(toBuffer, outBase + outBytesPerCenter + outBytesPerScale + outBytesPerRotation, 4);
  47878. outCenter[0] = inCenter[0];
  47879. outCenter[1] = inCenter[1];
  47880. outCenter[2] = inCenter[2];
  47881. outScale[0] = inScale[0];
  47882. outScale[1] = inScale[1];
  47883. outScale[2] = inScale[2];
  47884. outRotation[0] = quat.w;
  47885. outRotation[1] = quat.x;
  47886. outRotation[2] = quat.y;
  47887. outRotation[3] = quat.z;
  47888. outColor[0] = inColor[0];
  47889. outColor[1] = inColor[1];
  47890. outColor[2] = inColor[2];
  47891. outColor[3] = inColor[3];
  47892. }
  47893. }
  47894. static parseStandardSplatToUncompressedSplatArray(inBuffer) {
  47895. // Standard .splat row layout:
  47896. // XYZ - Position (Float32)
  47897. // XYZ - Scale (Float32)
  47898. // RGBA - colors (uint8)
  47899. // IJKL - quaternion/rot (uint8)
  47900. var splatCount = inBuffer.byteLength / SplatParser.RowSizeBytes;
  47901. var splatArray = new UncompressedSplatArray();
  47902. for (var i = 0; i < splatCount; i++) {
  47903. var inBase = i * SplatParser.RowSizeBytes;
  47904. var inCenter = new Float32Array(inBuffer, inBase, 3);
  47905. var inScale = new Float32Array(inBuffer, inBase + SplatParser.CenterSizeBytes, 3);
  47906. var inColor = new Uint8Array(inBuffer, inBase + SplatParser.CenterSizeBytes + SplatParser.ScaleSizeBytes, 4);
  47907. var inRotation = new Uint8Array(inBuffer, inBase + SplatParser.CenterSizeBytes + SplatParser.ScaleSizeBytes + SplatParser.ColorSizeBytes, 4);
  47908. var quat = new Quaternion((inRotation[1] - 128) / 128, (inRotation[2] - 128) / 128, (inRotation[3] - 128) / 128, (inRotation[0] - 128) / 128);
  47909. quat.normalize();
  47910. splatArray.addSplatFromComonents(inCenter[0], inCenter[1], inCenter[2], inScale[0], inScale[1], inScale[2], quat.w, quat.x, quat.y, quat.z, inColor[0], inColor[1], inColor[2], inColor[3]);
  47911. }
  47912. return splatArray;
  47913. }
  47914. }
  47915. _defineProperty(SplatParser, "RowSizeBytes", 32);
  47916. _defineProperty(SplatParser, "CenterSizeBytes", 12);
  47917. _defineProperty(SplatParser, "ScaleSizeBytes", 12);
  47918. _defineProperty(SplatParser, "RotationSizeBytes", 4);
  47919. _defineProperty(SplatParser, "ColorSizeBytes", 4);
  47920. class SplatLoader {
  47921. static loadFromURL(fileName, onProgress, streamLoadData, onStreamedSectionProgress, minimumAlpha, compressionLevel, optimizeSplatData, sectionSize, sceneCenter, blockSize, bucketSize) {
  47922. var splatDataOffsetBytes = SplatBuffer.HeaderSizeBytes + SplatBuffer.SectionHeaderSizeBytes;
  47923. var streamSectionSizeBytes = Constants.StreamingSectionSize;
  47924. var sectionCount = 1;
  47925. var streamBufferIn;
  47926. var streamBufferOut;
  47927. var streamSplatBuffer;
  47928. var maxSplatCount = 0;
  47929. var splatCount = 0;
  47930. var streamLoadCompleteResolver;
  47931. var streamLoadPromise = new Promise(resolve => {
  47932. streamLoadCompleteResolver = resolve;
  47933. });
  47934. var numBytesStreamed = 0;
  47935. var numBytesLoaded = 0;
  47936. var chunks = [];
  47937. var localOnProgress = (percent, percentStr, chunk, fileSize) => {
  47938. var loadComplete = percent >= 100;
  47939. if (!fileSize) streamLoadData = false;
  47940. if (streamLoadData) {
  47941. if (!streamBufferIn) {
  47942. maxSplatCount = fileSize / SplatParser.RowSizeBytes;
  47943. streamBufferIn = new ArrayBuffer(fileSize);
  47944. var bytesPerSplat = SplatBuffer.CompressionLevels[0].SphericalHarmonicsDegrees[0].BytesPerSplat;
  47945. var splatBufferSizeBytes = splatDataOffsetBytes + bytesPerSplat * maxSplatCount;
  47946. streamBufferOut = new ArrayBuffer(splatBufferSizeBytes);
  47947. SplatBuffer.writeHeaderToBuffer({
  47948. versionMajor: SplatBuffer.CurrentMajorVersion,
  47949. versionMinor: SplatBuffer.CurrentMinorVersion,
  47950. maxSectionCount: sectionCount,
  47951. sectionCount: sectionCount,
  47952. maxSplatCount: maxSplatCount,
  47953. splatCount: splatCount,
  47954. compressionLevel: 0,
  47955. sceneCenter: new Vector3()
  47956. }, streamBufferOut);
  47957. }
  47958. if (chunk) {
  47959. chunks.push(chunk);
  47960. new Uint8Array(streamBufferIn, numBytesLoaded, chunk.byteLength).set(new Uint8Array(chunk));
  47961. numBytesLoaded += chunk.byteLength;
  47962. var bytesLoadedSinceLastSection = numBytesLoaded - numBytesStreamed;
  47963. if (bytesLoadedSinceLastSection > streamSectionSizeBytes || loadComplete) {
  47964. var bytesToUpdate = loadComplete ? bytesLoadedSinceLastSection : streamSectionSizeBytes;
  47965. var addedSplatCount = bytesToUpdate / SplatParser.RowSizeBytes;
  47966. var newSplatCount = splatCount + addedSplatCount;
  47967. SplatParser.parseToUncompressedSplatBufferSection(splatCount, newSplatCount - 1, streamBufferIn, 0, streamBufferOut, splatDataOffsetBytes);
  47968. splatCount = newSplatCount;
  47969. if (!streamSplatBuffer) {
  47970. SplatBuffer.writeSectionHeaderToBuffer({
  47971. maxSplatCount: maxSplatCount,
  47972. splatCount: splatCount,
  47973. bucketSize: 0,
  47974. bucketCount: 0,
  47975. bucketBlockSize: 0,
  47976. compressionScaleRange: 0,
  47977. storageSizeBytes: 0,
  47978. fullBucketCount: 0,
  47979. partiallyFilledBucketCount: 0
  47980. }, 0, streamBufferOut, SplatBuffer.HeaderSizeBytes);
  47981. streamSplatBuffer = new SplatBuffer(streamBufferOut, false);
  47982. }
  47983. streamSplatBuffer.updateLoadedCounts(1, splatCount);
  47984. onStreamedSectionProgress(streamSplatBuffer, loadComplete);
  47985. numBytesStreamed += streamSectionSizeBytes;
  47986. }
  47987. }
  47988. if (loadComplete) {
  47989. streamLoadCompleteResolver(streamSplatBuffer);
  47990. }
  47991. }
  47992. if (onProgress) onProgress(percent, percentStr, LoaderStatus.Downloading);
  47993. return streamLoadData;
  47994. };
  47995. return fetchWithProgress(fileName, localOnProgress, true).then(fullBuffer => {
  47996. if (onProgress) onProgress(0, '0%', LoaderStatus.Processing);
  47997. var loadPromise = streamLoadData ? streamLoadPromise : SplatLoader.loadFromFileData(fullBuffer, minimumAlpha, compressionLevel, optimizeSplatData, sectionSize, sceneCenter, blockSize, bucketSize);
  47998. return loadPromise.then(splatBuffer => {
  47999. if (onProgress) onProgress(100, '100%', LoaderStatus.Done);
  48000. return splatBuffer;
  48001. });
  48002. });
  48003. }
  48004. static loadFromFileData(splatFileData, minimumAlpha, compressionLevel, optimizeSplatData, sectionSize, sceneCenter, blockSize, bucketSize) {
  48005. return delayedExecute(() => {
  48006. var splatArray = SplatParser.parseStandardSplatToUncompressedSplatArray(splatFileData);
  48007. if (optimizeSplatData) {
  48008. var splatBufferGenerator = SplatBufferGenerator.getStandardGenerator(minimumAlpha, compressionLevel, sectionSize, sceneCenter, blockSize, bucketSize);
  48009. return splatBufferGenerator.generateFromUncompressedSplatArray(splatArray);
  48010. } else {
  48011. return SplatBuffer.generateFromUncompressedSplatArrays([splatArray], minimumAlpha, 0, new Vector3());
  48012. }
  48013. });
  48014. }
  48015. }
  48016. class KSplatLoader {
  48017. static checkVersion(buffer) {
  48018. var minVersionMajor = SplatBuffer.CurrentMajorVersion;
  48019. var minVersionMinor = SplatBuffer.CurrentMinorVersion;
  48020. var header = SplatBuffer.parseHeader(buffer);
  48021. if (header.versionMajor === minVersionMajor && header.versionMinor >= minVersionMinor || header.versionMajor > minVersionMajor) {
  48022. return true;
  48023. } else {
  48024. throw new Error("KSplat version not supported: v".concat(header.versionMajor, ".").concat(header.versionMinor, ". ") + "Minimum required: v".concat(minVersionMajor, ".").concat(minVersionMinor));
  48025. }
  48026. }
  48027. static loadFromURL(fileName, onProgress, streamLoadData, onSectionBuilt) {
  48028. var streamBuffer;
  48029. var streamSplatBuffer;
  48030. var headerBuffer;
  48031. var header;
  48032. var headerLoaded = false;
  48033. var headerLoading = false;
  48034. var sectionHeadersBuffer;
  48035. var sectionHeaders = [];
  48036. var sectionHeadersLoaded = false;
  48037. var sectionHeadersLoading = false;
  48038. var numBytesLoaded = 0;
  48039. var numBytesStreamed = 0;
  48040. var streamSectionSizeBytes = Constants.StreamingSectionSize;
  48041. var totalBytesToDownload = 0;
  48042. var loadComplete = false;
  48043. var chunks = [];
  48044. var streamLoadCompleteResolver;
  48045. var streamLoadPromise = new Promise(resolve => {
  48046. streamLoadCompleteResolver = resolve;
  48047. });
  48048. var checkAndLoadHeader = () => {
  48049. if (!headerLoaded && !headerLoading && numBytesLoaded >= SplatBuffer.HeaderSizeBytes) {
  48050. headerLoading = true;
  48051. var headerAssemblyPromise = new Blob(chunks).arrayBuffer();
  48052. headerAssemblyPromise.then(bufferData => {
  48053. headerBuffer = new ArrayBuffer(SplatBuffer.HeaderSizeBytes);
  48054. new Uint8Array(headerBuffer).set(new Uint8Array(bufferData, 0, SplatBuffer.HeaderSizeBytes));
  48055. KSplatLoader.checkVersion(headerBuffer);
  48056. headerLoading = false;
  48057. headerLoaded = true;
  48058. header = SplatBuffer.parseHeader(headerBuffer);
  48059. window.setTimeout(() => {
  48060. checkAndLoadSectionHeaders();
  48061. }, 1);
  48062. });
  48063. }
  48064. };
  48065. var queuedCheckAndLoadSectionsCount = 0;
  48066. var queueCheckAndLoadSections = () => {
  48067. if (queuedCheckAndLoadSectionsCount === 0) {
  48068. queuedCheckAndLoadSectionsCount++;
  48069. window.setTimeout(() => {
  48070. queuedCheckAndLoadSectionsCount--;
  48071. checkAndLoadSections(true);
  48072. }, 1);
  48073. }
  48074. };
  48075. var checkAndLoadSectionHeaders = () => {
  48076. var performLoad = () => {
  48077. sectionHeadersLoading = true;
  48078. var sectionHeadersAssemblyPromise = new Blob(chunks).arrayBuffer();
  48079. sectionHeadersAssemblyPromise.then(bufferData => {
  48080. sectionHeadersLoading = false;
  48081. sectionHeadersLoaded = true;
  48082. sectionHeadersBuffer = new ArrayBuffer(header.maxSectionCount * SplatBuffer.SectionHeaderSizeBytes);
  48083. new Uint8Array(sectionHeadersBuffer).set(new Uint8Array(bufferData, SplatBuffer.HeaderSizeBytes, header.maxSectionCount * SplatBuffer.SectionHeaderSizeBytes));
  48084. sectionHeaders = SplatBuffer.parseSectionHeaders(header, sectionHeadersBuffer, 0, false);
  48085. var totalSectionStorageStorageByes = 0;
  48086. for (var i = 0; i < header.maxSectionCount; i++) {
  48087. totalSectionStorageStorageByes += sectionHeaders[i].storageSizeBytes;
  48088. }
  48089. var totalStorageSizeBytes = SplatBuffer.HeaderSizeBytes + header.maxSectionCount * SplatBuffer.SectionHeaderSizeBytes + totalSectionStorageStorageByes;
  48090. if (!streamBuffer) {
  48091. streamBuffer = new ArrayBuffer(totalStorageSizeBytes);
  48092. var offset = 0;
  48093. for (var _i13 = 0; _i13 < chunks.length; _i13++) {
  48094. var chunk = chunks[_i13];
  48095. new Uint8Array(streamBuffer, offset, chunk.byteLength).set(new Uint8Array(chunk));
  48096. offset += chunk.byteLength;
  48097. }
  48098. }
  48099. totalBytesToDownload = SplatBuffer.HeaderSizeBytes + SplatBuffer.SectionHeaderSizeBytes * header.maxSectionCount;
  48100. for (var _i14 = 0; _i14 <= sectionHeaders.length && _i14 < header.maxSectionCount; _i14++) {
  48101. totalBytesToDownload += sectionHeaders[_i14].storageSizeBytes;
  48102. }
  48103. queueCheckAndLoadSections();
  48104. });
  48105. };
  48106. if (!sectionHeadersLoading && !sectionHeadersLoaded && headerLoaded && numBytesLoaded >= SplatBuffer.HeaderSizeBytes + SplatBuffer.SectionHeaderSizeBytes * header.maxSectionCount) {
  48107. performLoad();
  48108. }
  48109. };
  48110. var checkAndLoadSections = () => {
  48111. if (sectionHeadersLoaded) {
  48112. if (loadComplete) return;
  48113. loadComplete = numBytesLoaded >= totalBytesToDownload;
  48114. var bytesLoadedSinceLastSection = numBytesLoaded - numBytesStreamed;
  48115. if (bytesLoadedSinceLastSection > streamSectionSizeBytes || loadComplete) {
  48116. numBytesStreamed = numBytesLoaded;
  48117. if (!streamSplatBuffer) streamSplatBuffer = new SplatBuffer(streamBuffer, false);
  48118. var baseDataOffset = SplatBuffer.HeaderSizeBytes + SplatBuffer.SectionHeaderSizeBytes * header.maxSectionCount;
  48119. var sectionBase = 0;
  48120. var reachedSections = 0;
  48121. var loadedSplatCount = 0;
  48122. for (var i = 0; i < header.maxSectionCount; i++) {
  48123. var sectionHeader = sectionHeaders[i];
  48124. var bucketsDataOffset = sectionBase + sectionHeader.partiallyFilledBucketCount * 4 + sectionHeader.bucketStorageSizeBytes * sectionHeader.bucketCount;
  48125. var bytesRequiredToReachSectionSplatData = baseDataOffset + bucketsDataOffset;
  48126. if (numBytesLoaded >= bytesRequiredToReachSectionSplatData) {
  48127. reachedSections++;
  48128. var bytesPastSSectionSplatDataStart = numBytesLoaded - bytesRequiredToReachSectionSplatData;
  48129. var baseDescriptor = SplatBuffer.CompressionLevels[header.compressionLevel];
  48130. var shDesc = baseDescriptor.SphericalHarmonicsDegrees[sectionHeader.sphericalHarmonicsDegree];
  48131. var bytesPerSplat = shDesc.BytesPerSplat;
  48132. var loadedSplatsForSection = Math.floor(bytesPastSSectionSplatDataStart / bytesPerSplat);
  48133. loadedSplatsForSection = Math.min(loadedSplatsForSection, sectionHeader.maxSplatCount);
  48134. loadedSplatCount += loadedSplatsForSection;
  48135. streamSplatBuffer.updateLoadedCounts(reachedSections, loadedSplatCount);
  48136. streamSplatBuffer.updateSectionLoadedCounts(i, loadedSplatsForSection);
  48137. } else {
  48138. break;
  48139. }
  48140. sectionBase += sectionHeader.storageSizeBytes;
  48141. }
  48142. onSectionBuilt(streamSplatBuffer, loadComplete);
  48143. if (loadComplete) {
  48144. streamLoadCompleteResolver(streamSplatBuffer);
  48145. }
  48146. }
  48147. }
  48148. };
  48149. var localOnProgress = (percent, percentStr, chunk) => {
  48150. if (chunk) {
  48151. chunks.push(chunk);
  48152. if (streamBuffer) {
  48153. new Uint8Array(streamBuffer, numBytesLoaded, chunk.byteLength).set(new Uint8Array(chunk));
  48154. }
  48155. numBytesLoaded += chunk.byteLength;
  48156. }
  48157. if (streamLoadData) {
  48158. checkAndLoadHeader();
  48159. checkAndLoadSectionHeaders();
  48160. checkAndLoadSections();
  48161. }
  48162. if (onProgress) onProgress(percent, percentStr, LoaderStatus.Downloading);
  48163. };
  48164. return fetchWithProgress(fileName, localOnProgress, !streamLoadData).then(fullBuffer => {
  48165. if (onProgress) onProgress(0, '0%', LoaderStatus.Processing);
  48166. var loadPromise = streamLoadData ? streamLoadPromise : KSplatLoader.loadFromFileData(fullBuffer);
  48167. return loadPromise.then(splatBuffer => {
  48168. if (onProgress) onProgress(100, '100%', LoaderStatus.Done);
  48169. return splatBuffer;
  48170. });
  48171. });
  48172. }
  48173. static loadFromFileData(fileData) {
  48174. return delayedExecute(() => {
  48175. KSplatLoader.checkVersion(fileData);
  48176. return new SplatBuffer(fileData);
  48177. });
  48178. }
  48179. }
  48180. _defineProperty(KSplatLoader, "downloadFile", function () {
  48181. var downLoadLink;
  48182. return function (splatBuffer, fileName) {
  48183. var blob = new Blob([splatBuffer.bufferData], {
  48184. type: 'application/octet-stream'
  48185. });
  48186. if (!downLoadLink) {
  48187. downLoadLink = document.createElement('a');
  48188. document.body.appendChild(downLoadLink);
  48189. }
  48190. downLoadLink.download = fileName;
  48191. downLoadLink.href = URL.createObjectURL(blob);
  48192. downLoadLink.click();
  48193. };
  48194. }());
  48195. var SceneFormat = {
  48196. 'Splat': 0,
  48197. 'KSplat': 1,
  48198. 'Ply': 2
  48199. };
  48200. var sceneFormatFromPath = path => {
  48201. if (path.endsWith('.ply')) return SceneFormat.Ply;else if (path.endsWith('.splat')) return SceneFormat.Splat;else if (path.endsWith('.ksplat')) return SceneFormat.KSplat;
  48202. return null;
  48203. };
  48204. var Utils$1 = /*#__PURE__*/Object.freeze({
  48205. __proto__: null,
  48206. sceneFormatFromPath: sceneFormatFromPath
  48207. });
  48208. /*
  48209. Copyright © 2010-2024 three.js authors & Mark Kellogg
  48210. Permission is hereby granted, free of charge, to any person obtaining a copy
  48211. of this software and associated documentation files (the "Software"), to deal
  48212. in the Software without restriction, including without limitation the rights
  48213. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  48214. copies of the Software, and to permit persons to whom the Software is
  48215. furnished to do so, subject to the following conditions:
  48216. The above copyright notice and this permission notice shall be included in
  48217. all copies or substantial portions of the Software.
  48218. */
  48219. // OrbitControls performs orbiting, dollying (zooming), and panning.
  48220. // Unlike TrackballControls, it maintains the "up" direction object.up (+Y by default).
  48221. //
  48222. // Orbit - left mouse / touch: one-finger move
  48223. // Zoom - middle mouse, or mousewheel / touch: two-finger spread or squish
  48224. // Pan - right mouse, or left mouse + ctrl/meta/shiftKey, or arrow keys / touch: two-finger move
  48225. var _changeEvent = {
  48226. type: 'change'
  48227. };
  48228. var _startEvent = {
  48229. type: 'start'
  48230. };
  48231. var _endEvent = {
  48232. type: 'end'
  48233. };
  48234. var _ray$4 = new Ray();
  48235. var _plane = new Plane();
  48236. var TILT_LIMIT = Math.cos(70 * MathUtils.DEG2RAD);
  48237. class OrbitControls extends EventDispatcher {
  48238. constructor(object, domElement) {
  48239. super();
  48240. this.object = object;
  48241. this.domElement = domElement;
  48242. this.domElement.style.touchAction = 'none'; // disable touch scroll
  48243. // Set to false to disable this control
  48244. this.enabled = true;
  48245. // "target" sets the location of focus, where the object orbits around
  48246. this.target = new Vector3();
  48247. // How far you can dolly in and out ( PerspectiveCamera only )
  48248. this.minDistance = 0;
  48249. this.maxDistance = Infinity;
  48250. // How far you can zoom in and out ( OrthographicCamera only )
  48251. this.minZoom = 0;
  48252. this.maxZoom = Infinity;
  48253. // How far you can orbit vertically, upper and lower limits.
  48254. // Range is 0 to Math.PI radians.
  48255. this.minPolarAngle = 0; // radians
  48256. this.maxPolarAngle = Math.PI; // radians
  48257. // How far you can orbit horizontally, upper and lower limits.
  48258. // If set, the interval [min, max] must be a sub-interval of [- 2 PI, 2 PI], with ( max - min < 2 PI )
  48259. this.minAzimuthAngle = -Infinity; // radians
  48260. this.maxAzimuthAngle = Infinity; // radians
  48261. // Set to true to enable damping (inertia)
  48262. // If damping is enabled, you must call controls.update() in your animation loop
  48263. this.enableDamping = false;
  48264. this.dampingFactor = 0.05;
  48265. // This option actually enables dollying in and out; left as "zoom" for backwards compatibility.
  48266. // Set to false to disable zooming
  48267. this.enableZoom = true;
  48268. this.zoomSpeed = 1.0;
  48269. // Set to false to disable rotating
  48270. this.enableRotate = true;
  48271. this.rotateSpeed = 1.0;
  48272. // Set to false to disable panning
  48273. this.enablePan = true;
  48274. this.panSpeed = 1.0;
  48275. this.screenSpacePanning = true; // if false, pan orthogonal to world-space direction camera.up
  48276. this.keyPanSpeed = 7.0; // pixels moved per arrow key push
  48277. this.zoomToCursor = false;
  48278. // Set to true to automatically rotate around the target
  48279. // If auto-rotate is enabled, you must call controls.update() in your animation loop
  48280. this.autoRotate = false;
  48281. this.autoRotateSpeed = 2.0; // 30 seconds per orbit when fps is 60
  48282. // The four arrow keys
  48283. this.keys = {
  48284. LEFT: 'KeyA',
  48285. UP: 'KeyW',
  48286. RIGHT: 'KeyD',
  48287. BOTTOM: 'KeyS'
  48288. };
  48289. // Mouse buttons
  48290. this.mouseButtons = {
  48291. LEFT: MOUSE.ROTATE,
  48292. MIDDLE: MOUSE.DOLLY,
  48293. RIGHT: MOUSE.PAN
  48294. };
  48295. // Touch fingers
  48296. this.touches = {
  48297. ONE: TOUCH.ROTATE,
  48298. TWO: TOUCH.DOLLY_PAN
  48299. };
  48300. // for reset
  48301. this.target0 = this.target.clone();
  48302. this.position0 = this.object.position.clone();
  48303. this.zoom0 = this.object.zoom;
  48304. // the target DOM element for key events
  48305. this._domElementKeyEvents = null;
  48306. //
  48307. // public methods
  48308. //
  48309. this.getPolarAngle = function () {
  48310. return spherical.phi;
  48311. };
  48312. this.getAzimuthalAngle = function () {
  48313. return spherical.theta;
  48314. };
  48315. this.getDistance = function () {
  48316. return this.object.position.distanceTo(this.target);
  48317. };
  48318. this.listenToKeyEvents = function (domElement) {
  48319. domElement.addEventListener('keydown', onKeyDown);
  48320. this._domElementKeyEvents = domElement;
  48321. };
  48322. this.stopListenToKeyEvents = function () {
  48323. this._domElementKeyEvents.removeEventListener('keydown', onKeyDown);
  48324. this._domElementKeyEvents = null;
  48325. };
  48326. this.saveState = function () {
  48327. scope.target0.copy(scope.target);
  48328. scope.position0.copy(scope.object.position);
  48329. scope.zoom0 = scope.object.zoom;
  48330. };
  48331. this.reset = function () {
  48332. scope.target.copy(scope.target0);
  48333. scope.object.position.copy(scope.position0);
  48334. scope.object.zoom = scope.zoom0;
  48335. this.clearDampedRotation();
  48336. this.clearDampedPan();
  48337. scope.object.updateProjectionMatrix();
  48338. scope.dispatchEvent(_changeEvent);
  48339. scope.update();
  48340. state = STATE.NONE;
  48341. };
  48342. this.clearDampedRotation = function () {
  48343. sphericalDelta.theta = 0.0;
  48344. sphericalDelta.phi = 0.0;
  48345. };
  48346. this.clearDampedPan = function () {
  48347. panOffset.set(0, 0, 0);
  48348. };
  48349. // this method is exposed, but perhaps it would be better if we can make it private...
  48350. this.update = function () {
  48351. var offset = new Vector3();
  48352. // so camera.up is the orbit axis
  48353. var quat = new Quaternion().setFromUnitVectors(object.up, new Vector3(0, 1, 0));
  48354. var quatInverse = quat.clone().invert();
  48355. var lastPosition = new Vector3();
  48356. var lastQuaternion = new Quaternion();
  48357. var lastTargetPosition = new Vector3();
  48358. var twoPI = 2 * Math.PI;
  48359. return function update() {
  48360. quat.setFromUnitVectors(object.up, new Vector3(0, 1, 0));
  48361. quatInverse.copy(quat).invert();
  48362. var position = scope.object.position;
  48363. offset.copy(position).sub(scope.target);
  48364. // rotate offset to "y-axis-is-up" space
  48365. offset.applyQuaternion(quat);
  48366. // angle from z-axis around y-axis
  48367. spherical.setFromVector3(offset);
  48368. if (scope.autoRotate && state === STATE.NONE) {
  48369. rotateLeft(getAutoRotationAngle());
  48370. }
  48371. if (scope.enableDamping) {
  48372. spherical.theta += sphericalDelta.theta * scope.dampingFactor;
  48373. spherical.phi += sphericalDelta.phi * scope.dampingFactor;
  48374. } else {
  48375. spherical.theta += sphericalDelta.theta;
  48376. spherical.phi += sphericalDelta.phi;
  48377. }
  48378. // restrict theta to be between desired limits
  48379. var min = scope.minAzimuthAngle;
  48380. var max = scope.maxAzimuthAngle;
  48381. if (isFinite(min) && isFinite(max)) {
  48382. if (min < -Math.PI) min += twoPI;else if (min > Math.PI) min -= twoPI;
  48383. if (max < -Math.PI) max += twoPI;else if (max > Math.PI) max -= twoPI;
  48384. if (min <= max) {
  48385. spherical.theta = Math.max(min, Math.min(max, spherical.theta));
  48386. } else {
  48387. spherical.theta = spherical.theta > (min + max) / 2 ? Math.max(min, spherical.theta) : Math.min(max, spherical.theta);
  48388. }
  48389. }
  48390. // restrict phi to be between desired limits
  48391. spherical.phi = Math.max(scope.minPolarAngle, Math.min(scope.maxPolarAngle, spherical.phi));
  48392. spherical.makeSafe();
  48393. // move target to panned location
  48394. if (scope.enableDamping === true) {
  48395. scope.target.addScaledVector(panOffset, scope.dampingFactor);
  48396. } else {
  48397. scope.target.add(panOffset);
  48398. }
  48399. // adjust the camera position based on zoom only if we're not zooming to the cursor or if it's an ortho camera
  48400. // we adjust zoom later in these cases
  48401. if (scope.zoomToCursor && performCursorZoom || scope.object.isOrthographicCamera) {
  48402. spherical.radius = clampDistance(spherical.radius);
  48403. } else {
  48404. spherical.radius = clampDistance(spherical.radius * scale);
  48405. }
  48406. offset.setFromSpherical(spherical);
  48407. // rotate offset back to "camera-up-vector-is-up" space
  48408. offset.applyQuaternion(quatInverse);
  48409. position.copy(scope.target).add(offset);
  48410. scope.object.lookAt(scope.target);
  48411. if (scope.enableDamping === true) {
  48412. sphericalDelta.theta *= 1 - scope.dampingFactor;
  48413. sphericalDelta.phi *= 1 - scope.dampingFactor;
  48414. panOffset.multiplyScalar(1 - scope.dampingFactor);
  48415. } else {
  48416. sphericalDelta.set(0, 0, 0);
  48417. panOffset.set(0, 0, 0);
  48418. }
  48419. // adjust camera position
  48420. var zoomChanged = false;
  48421. if (scope.zoomToCursor && performCursorZoom) {
  48422. var newRadius = null;
  48423. if (scope.object.isPerspectiveCamera) {
  48424. // move the camera down the pointer ray
  48425. // this method avoids floating point error
  48426. var prevRadius = offset.length();
  48427. newRadius = clampDistance(prevRadius * scale);
  48428. var radiusDelta = prevRadius - newRadius;
  48429. scope.object.position.addScaledVector(dollyDirection, radiusDelta);
  48430. scope.object.updateMatrixWorld();
  48431. } else if (scope.object.isOrthographicCamera) {
  48432. // adjust the ortho camera position based on zoom changes
  48433. var mouseBefore = new Vector3(mouse.x, mouse.y, 0);
  48434. mouseBefore.unproject(scope.object);
  48435. scope.object.zoom = Math.max(scope.minZoom, Math.min(scope.maxZoom, scope.object.zoom / scale));
  48436. scope.object.updateProjectionMatrix();
  48437. zoomChanged = true;
  48438. var mouseAfter = new Vector3(mouse.x, mouse.y, 0);
  48439. mouseAfter.unproject(scope.object);
  48440. scope.object.position.sub(mouseAfter).add(mouseBefore);
  48441. scope.object.updateMatrixWorld();
  48442. newRadius = offset.length();
  48443. } else {
  48444. console.warn('WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled.');
  48445. scope.zoomToCursor = false;
  48446. }
  48447. // handle the placement of the target
  48448. if (newRadius !== null) {
  48449. if (this.screenSpacePanning) {
  48450. // position the orbit target in front of the new camera position
  48451. scope.target.set(0, 0, -1).transformDirection(scope.object.matrix).multiplyScalar(newRadius).add(scope.object.position);
  48452. } else {
  48453. // get the ray and translation plane to compute target
  48454. _ray$4.origin.copy(scope.object.position);
  48455. _ray$4.direction.set(0, 0, -1).transformDirection(scope.object.matrix);
  48456. // if the camera is 20 degrees above the horizon then don't adjust the focus target to avoid
  48457. // extremely large values
  48458. if (Math.abs(scope.object.up.dot(_ray$4.direction)) < TILT_LIMIT) {
  48459. object.lookAt(scope.target);
  48460. } else {
  48461. _plane.setFromNormalAndCoplanarPoint(scope.object.up, scope.target);
  48462. _ray$4.intersectPlane(_plane, scope.target);
  48463. }
  48464. }
  48465. }
  48466. } else if (scope.object.isOrthographicCamera) {
  48467. scope.object.zoom = Math.max(scope.minZoom, Math.min(scope.maxZoom, scope.object.zoom / scale));
  48468. scope.object.updateProjectionMatrix();
  48469. zoomChanged = true;
  48470. }
  48471. scale = 1;
  48472. performCursorZoom = false;
  48473. // update condition is:
  48474. // min(camera displacement, camera rotation in radians)^2 > EPS
  48475. // using small-angle approximation cos(x/2) = 1 - x^2 / 8
  48476. if (zoomChanged || lastPosition.distanceToSquared(scope.object.position) > EPS || 8 * (1 - lastQuaternion.dot(scope.object.quaternion)) > EPS || lastTargetPosition.distanceToSquared(scope.target) > 0) {
  48477. scope.dispatchEvent(_changeEvent);
  48478. lastPosition.copy(scope.object.position);
  48479. lastQuaternion.copy(scope.object.quaternion);
  48480. lastTargetPosition.copy(scope.target);
  48481. zoomChanged = false;
  48482. return true;
  48483. }
  48484. return false;
  48485. };
  48486. }();
  48487. this.dispose = function () {
  48488. scope.domElement.removeEventListener('contextmenu', onContextMenu);
  48489. scope.domElement.removeEventListener('pointerdown', onPointerDown);
  48490. scope.domElement.removeEventListener('pointercancel', onPointerUp);
  48491. scope.domElement.removeEventListener('wheel', onMouseWheel);
  48492. scope.domElement.removeEventListener('pointermove', onPointerMove);
  48493. scope.domElement.removeEventListener('pointerup', onPointerUp);
  48494. if (scope._domElementKeyEvents !== null) {
  48495. scope._domElementKeyEvents.removeEventListener('keydown', onKeyDown);
  48496. scope._domElementKeyEvents = null;
  48497. }
  48498. };
  48499. //
  48500. // internals
  48501. //
  48502. var scope = this;
  48503. var STATE = {
  48504. NONE: -1,
  48505. ROTATE: 0,
  48506. DOLLY: 1,
  48507. PAN: 2,
  48508. TOUCH_ROTATE: 3,
  48509. TOUCH_PAN: 4,
  48510. TOUCH_DOLLY_PAN: 5,
  48511. TOUCH_DOLLY_ROTATE: 6
  48512. };
  48513. var state = STATE.NONE;
  48514. var EPS = 0.000001;
  48515. // current position in spherical coordinates
  48516. var spherical = new Spherical();
  48517. var sphericalDelta = new Spherical();
  48518. var scale = 1;
  48519. var panOffset = new Vector3();
  48520. var rotateStart = new Vector2();
  48521. var rotateEnd = new Vector2();
  48522. var rotateDelta = new Vector2();
  48523. var panStart = new Vector2();
  48524. var panEnd = new Vector2();
  48525. var panDelta = new Vector2();
  48526. var dollyStart = new Vector2();
  48527. var dollyEnd = new Vector2();
  48528. var dollyDelta = new Vector2();
  48529. var dollyDirection = new Vector3();
  48530. var mouse = new Vector2();
  48531. var performCursorZoom = false;
  48532. var pointers = [];
  48533. var pointerPositions = {};
  48534. function getAutoRotationAngle() {
  48535. return 2 * Math.PI / 60 / 60 * scope.autoRotateSpeed;
  48536. }
  48537. function getZoomScale() {
  48538. return Math.pow(0.95, scope.zoomSpeed);
  48539. }
  48540. function rotateLeft(angle) {
  48541. sphericalDelta.theta -= angle;
  48542. }
  48543. function rotateUp(angle) {
  48544. sphericalDelta.phi -= angle;
  48545. }
  48546. var panLeft = function () {
  48547. var v = new Vector3();
  48548. return function panLeft(distance, objectMatrix) {
  48549. v.setFromMatrixColumn(objectMatrix, 0); // get X column of objectMatrix
  48550. v.multiplyScalar(-distance);
  48551. panOffset.add(v);
  48552. };
  48553. }();
  48554. var panUp = function () {
  48555. var v = new Vector3();
  48556. return function panUp(distance, objectMatrix) {
  48557. if (scope.screenSpacePanning === true) {
  48558. v.setFromMatrixColumn(objectMatrix, 1);
  48559. } else {
  48560. v.setFromMatrixColumn(objectMatrix, 0);
  48561. v.crossVectors(scope.object.up, v);
  48562. }
  48563. v.multiplyScalar(distance);
  48564. panOffset.add(v);
  48565. };
  48566. }();
  48567. // deltaX and deltaY are in pixels; right and down are positive
  48568. var pan = function () {
  48569. var offset = new Vector3();
  48570. return function pan(deltaX, deltaY) {
  48571. var element = scope.domElement;
  48572. if (scope.object.isPerspectiveCamera) {
  48573. // perspective
  48574. var position = scope.object.position;
  48575. offset.copy(position).sub(scope.target);
  48576. var targetDistance = offset.length();
  48577. // half of the fov is center to top of screen
  48578. targetDistance *= Math.tan(scope.object.fov / 2 * Math.PI / 180.0);
  48579. // we use only clientHeight here so aspect ratio does not distort speed
  48580. panLeft(2 * deltaX * targetDistance / element.clientHeight, scope.object.matrix);
  48581. panUp(2 * deltaY * targetDistance / element.clientHeight, scope.object.matrix);
  48582. } else if (scope.object.isOrthographicCamera) {
  48583. // orthographic
  48584. panLeft(deltaX * (scope.object.right - scope.object.left) / scope.object.zoom / element.clientWidth, scope.object.matrix);
  48585. panUp(deltaY * (scope.object.top - scope.object.bottom) / scope.object.zoom / element.clientHeight, scope.object.matrix);
  48586. } else {
  48587. // camera neither orthographic nor perspective
  48588. console.warn('WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.');
  48589. scope.enablePan = false;
  48590. }
  48591. };
  48592. }();
  48593. function dollyOut(dollyScale) {
  48594. if (scope.object.isPerspectiveCamera || scope.object.isOrthographicCamera) {
  48595. scale /= dollyScale;
  48596. } else {
  48597. console.warn('WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.');
  48598. scope.enableZoom = false;
  48599. }
  48600. }
  48601. function dollyIn(dollyScale) {
  48602. if (scope.object.isPerspectiveCamera || scope.object.isOrthographicCamera) {
  48603. scale *= dollyScale;
  48604. } else {
  48605. console.warn('WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.');
  48606. scope.enableZoom = false;
  48607. }
  48608. }
  48609. function updateMouseParameters(event) {
  48610. if (!scope.zoomToCursor) {
  48611. return;
  48612. }
  48613. performCursorZoom = true;
  48614. var rect = scope.domElement.getBoundingClientRect();
  48615. var x = event.clientX - rect.left;
  48616. var y = event.clientY - rect.top;
  48617. var w = rect.width;
  48618. var h = rect.height;
  48619. mouse.x = x / w * 2 - 1;
  48620. mouse.y = -(y / h) * 2 + 1;
  48621. dollyDirection.set(mouse.x, mouse.y, 1).unproject(object).sub(object.position).normalize();
  48622. }
  48623. function clampDistance(dist) {
  48624. return Math.max(scope.minDistance, Math.min(scope.maxDistance, dist));
  48625. }
  48626. //
  48627. // event callbacks - update the object state
  48628. //
  48629. function handleMouseDownRotate(event) {
  48630. rotateStart.set(event.clientX, event.clientY);
  48631. }
  48632. function handleMouseDownDolly(event) {
  48633. updateMouseParameters(event);
  48634. dollyStart.set(event.clientX, event.clientY);
  48635. }
  48636. function handleMouseDownPan(event) {
  48637. panStart.set(event.clientX, event.clientY);
  48638. }
  48639. function handleMouseMoveRotate(event) {
  48640. rotateEnd.set(event.clientX, event.clientY);
  48641. rotateDelta.subVectors(rotateEnd, rotateStart).multiplyScalar(scope.rotateSpeed);
  48642. var element = scope.domElement;
  48643. rotateLeft(2 * Math.PI * rotateDelta.x / element.clientHeight); // yes, height
  48644. rotateUp(2 * Math.PI * rotateDelta.y / element.clientHeight);
  48645. rotateStart.copy(rotateEnd);
  48646. scope.update();
  48647. }
  48648. function handleMouseMoveDolly(event) {
  48649. dollyEnd.set(event.clientX, event.clientY);
  48650. dollyDelta.subVectors(dollyEnd, dollyStart);
  48651. if (dollyDelta.y > 0) {
  48652. dollyOut(getZoomScale());
  48653. } else if (dollyDelta.y < 0) {
  48654. dollyIn(getZoomScale());
  48655. }
  48656. dollyStart.copy(dollyEnd);
  48657. scope.update();
  48658. }
  48659. function handleMouseMovePan(event) {
  48660. panEnd.set(event.clientX, event.clientY);
  48661. panDelta.subVectors(panEnd, panStart).multiplyScalar(scope.panSpeed);
  48662. pan(panDelta.x, panDelta.y);
  48663. panStart.copy(panEnd);
  48664. scope.update();
  48665. }
  48666. function handleMouseWheel(event) {
  48667. updateMouseParameters(event);
  48668. if (event.deltaY < 0) {
  48669. dollyIn(getZoomScale());
  48670. } else if (event.deltaY > 0) {
  48671. dollyOut(getZoomScale());
  48672. }
  48673. scope.update();
  48674. }
  48675. function handleKeyDown(event) {
  48676. var needsUpdate = false;
  48677. switch (event.code) {
  48678. case scope.keys.UP:
  48679. if (event.ctrlKey || event.metaKey || event.shiftKey) {
  48680. rotateUp(2 * Math.PI * scope.rotateSpeed / scope.domElement.clientHeight);
  48681. } else {
  48682. pan(0, scope.keyPanSpeed);
  48683. }
  48684. needsUpdate = true;
  48685. break;
  48686. case scope.keys.BOTTOM:
  48687. if (event.ctrlKey || event.metaKey || event.shiftKey) {
  48688. rotateUp(-2 * Math.PI * scope.rotateSpeed / scope.domElement.clientHeight);
  48689. } else {
  48690. pan(0, -scope.keyPanSpeed);
  48691. }
  48692. needsUpdate = true;
  48693. break;
  48694. case scope.keys.LEFT:
  48695. if (event.ctrlKey || event.metaKey || event.shiftKey) {
  48696. rotateLeft(2 * Math.PI * scope.rotateSpeed / scope.domElement.clientHeight);
  48697. } else {
  48698. pan(scope.keyPanSpeed, 0);
  48699. }
  48700. needsUpdate = true;
  48701. break;
  48702. case scope.keys.RIGHT:
  48703. if (event.ctrlKey || event.metaKey || event.shiftKey) {
  48704. rotateLeft(-2 * Math.PI * scope.rotateSpeed / scope.domElement.clientHeight);
  48705. } else {
  48706. pan(-scope.keyPanSpeed, 0);
  48707. }
  48708. needsUpdate = true;
  48709. break;
  48710. }
  48711. if (needsUpdate) {
  48712. // prevent the browser from scrolling on cursor keys
  48713. event.preventDefault();
  48714. scope.update();
  48715. }
  48716. }
  48717. function handleTouchStartRotate() {
  48718. if (pointers.length === 1) {
  48719. rotateStart.set(pointers[0].pageX, pointers[0].pageY);
  48720. } else {
  48721. var x = 0.5 * (pointers[0].pageX + pointers[1].pageX);
  48722. var y = 0.5 * (pointers[0].pageY + pointers[1].pageY);
  48723. rotateStart.set(x, y);
  48724. }
  48725. }
  48726. function handleTouchStartPan() {
  48727. if (pointers.length === 1) {
  48728. panStart.set(pointers[0].pageX, pointers[0].pageY);
  48729. } else {
  48730. var x = 0.5 * (pointers[0].pageX + pointers[1].pageX);
  48731. var y = 0.5 * (pointers[0].pageY + pointers[1].pageY);
  48732. panStart.set(x, y);
  48733. }
  48734. }
  48735. function handleTouchStartDolly() {
  48736. var dx = pointers[0].pageX - pointers[1].pageX;
  48737. var dy = pointers[0].pageY - pointers[1].pageY;
  48738. var distance = Math.sqrt(dx * dx + dy * dy);
  48739. dollyStart.set(0, distance);
  48740. }
  48741. function handleTouchStartDollyPan() {
  48742. if (scope.enableZoom) handleTouchStartDolly();
  48743. if (scope.enablePan) handleTouchStartPan();
  48744. }
  48745. function handleTouchStartDollyRotate() {
  48746. if (scope.enableZoom) handleTouchStartDolly();
  48747. if (scope.enableRotate) handleTouchStartRotate();
  48748. }
  48749. function handleTouchMoveRotate(event) {
  48750. if (pointers.length == 1) {
  48751. rotateEnd.set(event.pageX, event.pageY);
  48752. } else {
  48753. var position = getSecondPointerPosition(event);
  48754. var x = 0.5 * (event.pageX + position.x);
  48755. var y = 0.5 * (event.pageY + position.y);
  48756. rotateEnd.set(x, y);
  48757. }
  48758. rotateDelta.subVectors(rotateEnd, rotateStart).multiplyScalar(scope.rotateSpeed);
  48759. var element = scope.domElement;
  48760. rotateLeft(2 * Math.PI * rotateDelta.x / element.clientHeight); // yes, height
  48761. rotateUp(2 * Math.PI * rotateDelta.y / element.clientHeight);
  48762. rotateStart.copy(rotateEnd);
  48763. }
  48764. function handleTouchMovePan(event) {
  48765. if (pointers.length === 1) {
  48766. panEnd.set(event.pageX, event.pageY);
  48767. } else {
  48768. var position = getSecondPointerPosition(event);
  48769. var x = 0.5 * (event.pageX + position.x);
  48770. var y = 0.5 * (event.pageY + position.y);
  48771. panEnd.set(x, y);
  48772. }
  48773. panDelta.subVectors(panEnd, panStart).multiplyScalar(scope.panSpeed);
  48774. pan(panDelta.x, panDelta.y);
  48775. panStart.copy(panEnd);
  48776. }
  48777. function handleTouchMoveDolly(event) {
  48778. var position = getSecondPointerPosition(event);
  48779. var dx = event.pageX - position.x;
  48780. var dy = event.pageY - position.y;
  48781. var distance = Math.sqrt(dx * dx + dy * dy);
  48782. dollyEnd.set(0, distance);
  48783. dollyDelta.set(0, Math.pow(dollyEnd.y / dollyStart.y, scope.zoomSpeed));
  48784. dollyOut(dollyDelta.y);
  48785. dollyStart.copy(dollyEnd);
  48786. }
  48787. function handleTouchMoveDollyPan(event) {
  48788. if (scope.enableZoom) handleTouchMoveDolly(event);
  48789. if (scope.enablePan) handleTouchMovePan(event);
  48790. }
  48791. function handleTouchMoveDollyRotate(event) {
  48792. if (scope.enableZoom) handleTouchMoveDolly(event);
  48793. if (scope.enableRotate) handleTouchMoveRotate(event);
  48794. }
  48795. //
  48796. // event handlers - FSM: listen for events and reset state
  48797. //
  48798. function onPointerDown(event) {
  48799. if (scope.enabled === false) return;
  48800. if (pointers.length === 0) {
  48801. scope.domElement.setPointerCapture(event.pointerId);
  48802. scope.domElement.addEventListener('pointermove', onPointerMove);
  48803. scope.domElement.addEventListener('pointerup', onPointerUp);
  48804. }
  48805. //
  48806. addPointer(event);
  48807. if (event.pointerType === 'touch') {
  48808. onTouchStart(event);
  48809. } else {
  48810. onMouseDown(event);
  48811. }
  48812. }
  48813. function onPointerMove(event) {
  48814. if (scope.enabled === false) return;
  48815. if (event.pointerType === 'touch') {
  48816. onTouchMove(event);
  48817. } else {
  48818. onMouseMove(event);
  48819. }
  48820. }
  48821. function onPointerUp(event) {
  48822. removePointer(event);
  48823. if (pointers.length === 0) {
  48824. scope.domElement.releasePointerCapture(event.pointerId);
  48825. scope.domElement.removeEventListener('pointermove', onPointerMove);
  48826. scope.domElement.removeEventListener('pointerup', onPointerUp);
  48827. }
  48828. scope.dispatchEvent(_endEvent);
  48829. state = STATE.NONE;
  48830. }
  48831. function onMouseDown(event) {
  48832. var mouseAction;
  48833. switch (event.button) {
  48834. case 0:
  48835. mouseAction = scope.mouseButtons.LEFT;
  48836. break;
  48837. case 1:
  48838. mouseAction = scope.mouseButtons.MIDDLE;
  48839. break;
  48840. case 2:
  48841. mouseAction = scope.mouseButtons.RIGHT;
  48842. break;
  48843. default:
  48844. mouseAction = -1;
  48845. }
  48846. switch (mouseAction) {
  48847. case MOUSE.DOLLY:
  48848. if (scope.enableZoom === false) return;
  48849. handleMouseDownDolly(event);
  48850. state = STATE.DOLLY;
  48851. break;
  48852. case MOUSE.ROTATE:
  48853. if (event.ctrlKey || event.metaKey || event.shiftKey) {
  48854. if (scope.enablePan === false) return;
  48855. handleMouseDownPan(event);
  48856. state = STATE.PAN;
  48857. } else {
  48858. if (scope.enableRotate === false) return;
  48859. handleMouseDownRotate(event);
  48860. state = STATE.ROTATE;
  48861. }
  48862. break;
  48863. case MOUSE.PAN:
  48864. if (event.ctrlKey || event.metaKey || event.shiftKey) {
  48865. if (scope.enableRotate === false) return;
  48866. handleMouseDownRotate(event);
  48867. state = STATE.ROTATE;
  48868. } else {
  48869. if (scope.enablePan === false) return;
  48870. handleMouseDownPan(event);
  48871. state = STATE.PAN;
  48872. }
  48873. break;
  48874. default:
  48875. state = STATE.NONE;
  48876. }
  48877. if (state !== STATE.NONE) {
  48878. scope.dispatchEvent(_startEvent);
  48879. }
  48880. }
  48881. function onMouseMove(event) {
  48882. switch (state) {
  48883. case STATE.ROTATE:
  48884. if (scope.enableRotate === false) return;
  48885. handleMouseMoveRotate(event);
  48886. break;
  48887. case STATE.DOLLY:
  48888. if (scope.enableZoom === false) return;
  48889. handleMouseMoveDolly(event);
  48890. break;
  48891. case STATE.PAN:
  48892. if (scope.enablePan === false) return;
  48893. handleMouseMovePan(event);
  48894. break;
  48895. }
  48896. }
  48897. function onMouseWheel(event) {
  48898. if (scope.enabled === false || scope.enableZoom === false || state !== STATE.NONE) return;
  48899. event.preventDefault();
  48900. scope.dispatchEvent(_startEvent);
  48901. handleMouseWheel(event);
  48902. scope.dispatchEvent(_endEvent);
  48903. }
  48904. function onKeyDown(event) {
  48905. if (scope.enabled === false || scope.enablePan === false) return;
  48906. handleKeyDown(event);
  48907. }
  48908. function onTouchStart(event) {
  48909. trackPointer(event);
  48910. switch (pointers.length) {
  48911. case 1:
  48912. switch (scope.touches.ONE) {
  48913. case TOUCH.ROTATE:
  48914. if (scope.enableRotate === false) return;
  48915. handleTouchStartRotate();
  48916. state = STATE.TOUCH_ROTATE;
  48917. break;
  48918. case TOUCH.PAN:
  48919. if (scope.enablePan === false) return;
  48920. handleTouchStartPan();
  48921. state = STATE.TOUCH_PAN;
  48922. break;
  48923. default:
  48924. state = STATE.NONE;
  48925. }
  48926. break;
  48927. case 2:
  48928. switch (scope.touches.TWO) {
  48929. case TOUCH.DOLLY_PAN:
  48930. if (scope.enableZoom === false && scope.enablePan === false) return;
  48931. handleTouchStartDollyPan();
  48932. state = STATE.TOUCH_DOLLY_PAN;
  48933. break;
  48934. case TOUCH.DOLLY_ROTATE:
  48935. if (scope.enableZoom === false && scope.enableRotate === false) return;
  48936. handleTouchStartDollyRotate();
  48937. state = STATE.TOUCH_DOLLY_ROTATE;
  48938. break;
  48939. default:
  48940. state = STATE.NONE;
  48941. }
  48942. break;
  48943. default:
  48944. state = STATE.NONE;
  48945. }
  48946. if (state !== STATE.NONE) {
  48947. scope.dispatchEvent(_startEvent);
  48948. }
  48949. }
  48950. function onTouchMove(event) {
  48951. trackPointer(event);
  48952. switch (state) {
  48953. case STATE.TOUCH_ROTATE:
  48954. if (scope.enableRotate === false) return;
  48955. handleTouchMoveRotate(event);
  48956. scope.update();
  48957. break;
  48958. case STATE.TOUCH_PAN:
  48959. if (scope.enablePan === false) return;
  48960. handleTouchMovePan(event);
  48961. scope.update();
  48962. break;
  48963. case STATE.TOUCH_DOLLY_PAN:
  48964. if (scope.enableZoom === false && scope.enablePan === false) return;
  48965. handleTouchMoveDollyPan(event);
  48966. scope.update();
  48967. break;
  48968. case STATE.TOUCH_DOLLY_ROTATE:
  48969. if (scope.enableZoom === false && scope.enableRotate === false) return;
  48970. handleTouchMoveDollyRotate(event);
  48971. scope.update();
  48972. break;
  48973. default:
  48974. state = STATE.NONE;
  48975. }
  48976. }
  48977. function onContextMenu(event) {
  48978. if (scope.enabled === false) return;
  48979. event.preventDefault();
  48980. }
  48981. function addPointer(event) {
  48982. pointers.push(event);
  48983. }
  48984. function removePointer(event) {
  48985. delete pointerPositions[event.pointerId];
  48986. for (var i = 0; i < pointers.length; i++) {
  48987. if (pointers[i].pointerId == event.pointerId) {
  48988. pointers.splice(i, 1);
  48989. return;
  48990. }
  48991. }
  48992. }
  48993. function trackPointer(event) {
  48994. var position = pointerPositions[event.pointerId];
  48995. if (position === undefined) {
  48996. position = new Vector2();
  48997. pointerPositions[event.pointerId] = position;
  48998. }
  48999. position.set(event.pageX, event.pageY);
  49000. }
  49001. function getSecondPointerPosition(event) {
  49002. var pointer = event.pointerId === pointers[0].pointerId ? pointers[1] : pointers[0];
  49003. return pointerPositions[pointer.pointerId];
  49004. }
  49005. //
  49006. scope.domElement.addEventListener('contextmenu', onContextMenu);
  49007. scope.domElement.addEventListener('pointerdown', onPointerDown);
  49008. scope.domElement.addEventListener('pointercancel', onPointerUp);
  49009. scope.domElement.addEventListener('wheel', onMouseWheel, {
  49010. passive: false
  49011. });
  49012. // force an update at start
  49013. this.update();
  49014. }
  49015. }
  49016. var fadeElement = (element, out, displayStyle, duration, onComplete) => {
  49017. var startTime = performance.now();
  49018. var startOpacity = element.style.display === 'none' ? 0 : parseFloat(element.style.opacity);
  49019. if (isNaN(startOpacity)) startOpacity = 1;
  49020. var interval = window.setInterval(() => {
  49021. var currentTime = performance.now();
  49022. var elapsed = currentTime - startTime;
  49023. var t = Math.min(elapsed / duration, 1.0);
  49024. if (t > 0.999) t = 1;
  49025. var opacity;
  49026. if (out) {
  49027. opacity = (1.0 - t) * startOpacity;
  49028. if (opacity < 0.0001) opacity = 0;
  49029. } else {
  49030. opacity = (1.0 - startOpacity) * t + startOpacity;
  49031. }
  49032. if (opacity > 0) {
  49033. element.style.display = displayStyle;
  49034. element.style.opacity = opacity;
  49035. } else {
  49036. element.style.display = 'none';
  49037. }
  49038. if (t >= 1) {
  49039. if (onComplete) onComplete();
  49040. window.clearInterval(interval);
  49041. }
  49042. }, 16);
  49043. return interval;
  49044. };
  49045. var cancelFade = interval => {
  49046. window.clearInterval(interval);
  49047. };
  49048. var STANDARD_FADE_DURATION = 500;
  49049. class LoadingSpinner {
  49050. constructor(message, container) {
  49051. this.taskIDGen = 0;
  49052. this.elementID = LoadingSpinner.elementIDGen++;
  49053. this.tasks = [];
  49054. this.message = message || 'Loading...';
  49055. this.container = container || document.body;
  49056. this.spinnerContainerOuter = document.createElement('div');
  49057. this.spinnerContainerOuter.className = "spinnerOuterContainer".concat(this.elementID);
  49058. this.spinnerContainerOuter.style.display = 'none';
  49059. this.spinnerContainerPrimary = document.createElement('div');
  49060. this.spinnerContainerPrimary.className = "spinnerContainerPrimary".concat(this.elementID);
  49061. this.spinnerPrimary = document.createElement('div');
  49062. this.spinnerPrimary.classList.add("spinner".concat(this.elementID), "spinnerPrimary".concat(this.elementID));
  49063. this.messageContainerPrimary = document.createElement('div');
  49064. this.messageContainerPrimary.classList.add("messageContainer".concat(this.elementID), "messageContainerPrimary".concat(this.elementID));
  49065. this.messageContainerPrimary.innerHTML = this.message;
  49066. this.spinnerContainerMin = document.createElement('div');
  49067. this.spinnerContainerMin.className = "spinnerContainerMin".concat(this.elementID);
  49068. this.spinnerMin = document.createElement('div');
  49069. this.spinnerMin.classList.add("spinner".concat(this.elementID), "spinnerMin".concat(this.elementID));
  49070. this.messageContainerMin = document.createElement('div');
  49071. this.messageContainerMin.classList.add("messageContainer".concat(this.elementID), "messageContainerMin".concat(this.elementID));
  49072. this.messageContainerMin.innerHTML = this.message;
  49073. this.spinnerContainerPrimary.appendChild(this.spinnerPrimary);
  49074. this.spinnerContainerPrimary.appendChild(this.messageContainerPrimary);
  49075. this.spinnerContainerOuter.appendChild(this.spinnerContainerPrimary);
  49076. this.spinnerContainerMin.appendChild(this.spinnerMin);
  49077. this.spinnerContainerMin.appendChild(this.messageContainerMin);
  49078. this.spinnerContainerOuter.appendChild(this.spinnerContainerMin);
  49079. var style = document.createElement('style');
  49080. style.innerHTML = "\n\n .spinnerOuterContainer".concat(this.elementID, " {\n width: 100%;\n height: 100%;\n margin: 0;\n top: 0;\n left: 0;\n position: absolute;\n pointer-events: none;\n }\n\n .messageContainer").concat(this.elementID, " {\n height: 20px;\n font-family: arial;\n font-size: 12pt;\n color: #ffffff;\n text-align: center;\n vertical-align: middle;\n }\n\n .spinner").concat(this.elementID, " {\n padding: 15px;\n background: #07e8d6;\n z-index:99999;\n \n aspect-ratio: 1;\n border-radius: 50%;\n --_m: \n conic-gradient(#0000,#000),\n linear-gradient(#000 0 0) content-box;\n -webkit-mask: var(--_m);\n mask: var(--_m);\n -webkit-mask-composite: source-out;\n mask-composite: subtract;\n box-sizing: border-box;\n animation: load 1s linear infinite;\n }\n\n .spinnerContainerPrimary").concat(this.elementID, " {\n z-index:99999;\n background-color: rgba(128, 128, 128, 0.75);\n border: #666666 1px solid;\n border-radius: 5px;\n padding-top: 20px;\n padding-bottom: 10px;\n margin: 0;\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-80px, -80px);\n width: 180px;\n pointer-events: auto;\n }\n\n .spinnerPrimary").concat(this.elementID, " {\n width: 120px;\n margin-left: 30px;\n }\n\n .messageContainerPrimary").concat(this.elementID, " {\n padding-top: 15px;\n }\n\n .spinnerContainerMin").concat(this.elementID, " {\n z-index:99999;\n background-color: rgba(128, 128, 128, 0.75);\n border: #666666 1px solid;\n border-radius: 5px;\n padding-top: 20px;\n padding-bottom: 15px;\n margin: 0;\n position: absolute;\n bottom: 50px;\n left: 50%;\n transform: translate(-50%, 0);\n display: flex;\n flex-direction: left;\n pointer-events: auto;\n min-width: 250px;\n }\n\n .messageContainerMin").concat(this.elementID, " {\n margin-right: 15px;\n }\n\n .spinnerMin").concat(this.elementID, " {\n width: 50px;\n height: 50px;\n margin-left: 15px;\n margin-right: 25px;\n }\n\n .messageContainerMin").concat(this.elementID, " {\n padding-top: 15px;\n }\n \n @keyframes load {\n to{transform: rotate(1turn)}\n }\n\n ");
  49081. this.spinnerContainerOuter.appendChild(style);
  49082. this.container.appendChild(this.spinnerContainerOuter);
  49083. this.setMinimized(false, true);
  49084. this.fadeTransitions = [];
  49085. }
  49086. addTask(message) {
  49087. var newTask = {
  49088. 'message': message,
  49089. 'id': this.taskIDGen++
  49090. };
  49091. this.tasks.push(newTask);
  49092. this.update();
  49093. return newTask.id;
  49094. }
  49095. removeTask(id) {
  49096. var index = 0;
  49097. for (var task of this.tasks) {
  49098. if (task.id === id) {
  49099. this.tasks.splice(index, 1);
  49100. break;
  49101. }
  49102. index++;
  49103. }
  49104. this.update();
  49105. }
  49106. removeAllTasks() {
  49107. this.tasks = [];
  49108. this.update();
  49109. }
  49110. setMessageForTask(id, message) {
  49111. for (var task of this.tasks) {
  49112. if (task.id === id) {
  49113. task.message = message;
  49114. break;
  49115. }
  49116. }
  49117. this.update();
  49118. }
  49119. update() {
  49120. if (this.tasks.length > 0) {
  49121. this.show();
  49122. this.setMessage(this.tasks[this.tasks.length - 1].message);
  49123. } else {
  49124. this.hide();
  49125. }
  49126. }
  49127. show() {
  49128. this.spinnerContainerOuter.style.display = 'block';
  49129. this.visible = true;
  49130. }
  49131. hide() {
  49132. this.spinnerContainerOuter.style.display = 'none';
  49133. this.visible = false;
  49134. }
  49135. setContainer(container) {
  49136. if (this.container) {
  49137. this.container.removeChild(this.spinnerContainerOuter);
  49138. }
  49139. if (container) {
  49140. this.container = container;
  49141. this.container.appendChild(this.spinnerContainerOuter);
  49142. this.spinnerContainerOuter.style.zIndex = this.container.style.zIndex + 1;
  49143. }
  49144. }
  49145. setMinimized(minimized, instant) {
  49146. var showHideSpinner = (element, show, instant, displayStyle, fadeTransitionsIndex) => {
  49147. if (instant) {
  49148. element.style.display = show ? displayStyle : 'none';
  49149. } else {
  49150. this.fadeTransitions[fadeTransitionsIndex] = fadeElement(element, !show, displayStyle, STANDARD_FADE_DURATION, () => {
  49151. this.fadeTransitions[fadeTransitionsIndex] = null;
  49152. });
  49153. }
  49154. };
  49155. showHideSpinner(this.spinnerContainerPrimary, !minimized, instant, 'block', 0);
  49156. showHideSpinner(this.spinnerContainerMin, minimized, instant, 'flex', 1);
  49157. this.minimized = minimized;
  49158. }
  49159. setMessage(msg) {
  49160. this.messageContainerPrimary.innerHTML = msg;
  49161. this.messageContainerMin.innerHTML = msg;
  49162. }
  49163. }
  49164. _defineProperty(LoadingSpinner, "elementIDGen", 0);
  49165. class LoadingProgressBar {
  49166. constructor(container) {
  49167. this.idGen = 0;
  49168. this.tasks = [];
  49169. this.container = container || document.body;
  49170. this.progressBarContainerOuter = document.createElement('div');
  49171. this.progressBarContainerOuter.className = 'progressBarOuterContainer';
  49172. this.progressBarContainerOuter.style.display = 'none';
  49173. this.progressBarBox = document.createElement('div');
  49174. this.progressBarBox.className = 'progressBarBox';
  49175. this.progressBarBackground = document.createElement('div');
  49176. this.progressBarBackground.className = 'progressBarBackground';
  49177. this.progressBar = document.createElement('div');
  49178. this.progressBar.className = 'progressBar';
  49179. this.progressBarBackground.appendChild(this.progressBar);
  49180. this.progressBarBox.appendChild(this.progressBarBackground);
  49181. this.progressBarContainerOuter.appendChild(this.progressBarBox);
  49182. var style = document.createElement('style');
  49183. style.innerHTML = "\n\n .progressBarOuterContainer {\n width: 100%;\n height: 100%;\n margin: 0;\n top: 0;\n left: 0;\n position: absolute;\n pointer-events: none;\n }\n\n .progressBarBox {\n z-index:99999;\n padding: 7px 9px 5px 7px;\n background-color: rgba(190, 190, 190, 0.75);\n border: #555555 1px solid;\n border-radius: 15px;\n margin: 0;\n position: absolute;\n bottom: 50px;\n left: 50%;\n transform: translate(-50%, 0);\n width: 180px;\n height: 30px;\n pointer-events: auto;\n }\n\n .progressBarBackground {\n width: 100%;\n height: 25px;\n border-radius:10px;\n background-color: rgba(128, 128, 128, 0.75);\n border: #444444 1px solid;\n box-shadow: inset 0 0 10px #333333;\n }\n\n .progressBar {\n height: 25px;\n width: 0px;\n border-radius:10px;\n background-color: rgba(0, 200, 0, 0.75);\n box-shadow: inset 0 0 10px #003300;\n }\n\n ";
  49184. this.progressBarContainerOuter.appendChild(style);
  49185. this.container.appendChild(this.progressBarContainerOuter);
  49186. }
  49187. show() {
  49188. this.progressBarContainerOuter.style.display = 'block';
  49189. }
  49190. hide() {
  49191. this.progressBarContainerOuter.style.display = 'none';
  49192. }
  49193. setProgress(progress) {
  49194. this.progressBar.style.width = progress + '%';
  49195. }
  49196. setContainer(container) {
  49197. if (this.container) {
  49198. this.container.removeChild(this.progressBarContainerOuter);
  49199. }
  49200. if (container) {
  49201. this.container = container;
  49202. this.container.appendChild(this.progressBarContainerOuter);
  49203. this.progressBarContainerOuter.style.zIndex = this.container.style.zIndex + 1;
  49204. }
  49205. }
  49206. }
  49207. class InfoPanel {
  49208. constructor(container) {
  49209. _defineProperty(this, "update", function (renderDimensions, cameraPosition, cameraLookAtPosition, cameraUp, orthographicCamera, meshCursorPosition, currentFPS, splatCount, splatRenderCount, splatRenderCountPct, lastSortTime, focalAdjustment, splatScale, pointCloudMode) {
  49210. var cameraPosString = "".concat(cameraPosition.x.toFixed(5), ", ").concat(cameraPosition.y.toFixed(5), ", ").concat(cameraPosition.z.toFixed(5));
  49211. if (this.infoCells.cameraPosition.innerHTML !== cameraPosString) {
  49212. this.infoCells.cameraPosition.innerHTML = cameraPosString;
  49213. }
  49214. if (cameraLookAtPosition) {
  49215. var cla = cameraLookAtPosition;
  49216. var cameraLookAtString = "".concat(cla.x.toFixed(5), ", ").concat(cla.y.toFixed(5), ", ").concat(cla.z.toFixed(5));
  49217. if (this.infoCells.cameraLookAt.innerHTML !== cameraLookAtString) {
  49218. this.infoCells.cameraLookAt.innerHTML = cameraLookAtString;
  49219. }
  49220. }
  49221. var cameraUpString = "".concat(cameraUp.x.toFixed(5), ", ").concat(cameraUp.y.toFixed(5), ", ").concat(cameraUp.z.toFixed(5));
  49222. if (this.infoCells.cameraUp.innerHTML !== cameraUpString) {
  49223. this.infoCells.cameraUp.innerHTML = cameraUpString;
  49224. }
  49225. this.infoCells.orthographicCamera.innerHTML = orthographicCamera ? 'Orthographic' : 'Perspective';
  49226. if (meshCursorPosition) {
  49227. var cursPos = meshCursorPosition;
  49228. var cursorPosString = "".concat(cursPos.x.toFixed(5), ", ").concat(cursPos.y.toFixed(5), ", ").concat(cursPos.z.toFixed(5));
  49229. this.infoCells.cursorPosition.innerHTML = cursorPosString;
  49230. } else {
  49231. this.infoCells.cursorPosition.innerHTML = 'N/A';
  49232. }
  49233. this.infoCells.fps.innerHTML = currentFPS;
  49234. this.infoCells.renderWindow.innerHTML = "".concat(renderDimensions.x, " x ").concat(renderDimensions.y);
  49235. this.infoCells.renderSplatCount.innerHTML = "".concat(splatRenderCount, " splats out of ").concat(splatCount, " (").concat(splatRenderCountPct.toFixed(2), "%)");
  49236. this.infoCells.sortTime.innerHTML = "".concat(lastSortTime.toFixed(3), " ms");
  49237. this.infoCells.focalAdjustment.innerHTML = "".concat(focalAdjustment.toFixed(3));
  49238. this.infoCells.splatScale.innerHTML = "".concat(splatScale.toFixed(3));
  49239. this.infoCells.pointCloudMode.innerHTML = "".concat(pointCloudMode);
  49240. });
  49241. this.container = container || document.body;
  49242. this.infoCells = {};
  49243. var layout = [['Camera position', 'cameraPosition'], ['Camera look-at', 'cameraLookAt'], ['Camera up', 'cameraUp'], ['Camera mode', 'orthographicCamera'], ['Cursor position', 'cursorPosition'], ['FPS', 'fps'], ['Rendering:', 'renderSplatCount'], ['Sort time', 'sortTime'], ['Render window', 'renderWindow'], ['Focal adjustment', 'focalAdjustment'], ['Splat scale', 'splatScale'], ['Point cloud mode', 'pointCloudMode']];
  49244. this.infoPanelContainer = document.createElement('div');
  49245. var style = document.createElement('style');
  49246. style.innerHTML = "\n\n .infoPanel {\n width: 430px;\n padding: 10px;\n background-color: rgba(50, 50, 50, 0.85);\n border: #555555 2px solid;\n color: #dddddd;\n border-radius: 10px;\n z-index: 9999;\n font-family: arial;\n font-size: 11pt;\n text-align: left;\n margin: 0;\n top: 10px;\n left:10px;\n position: absolute;\n pointer-events: auto;\n }\n\n .info-panel-cell {\n margin-bottom: 5px;\n padding-bottom: 2px;\n }\n\n .label-cell {\n font-weight: bold;\n font-size: 12pt;\n width: 140px;\n }\n\n ";
  49247. this.infoPanelContainer.append(style);
  49248. this.infoPanel = document.createElement('div');
  49249. this.infoPanel.className = 'infoPanel';
  49250. var infoTable = document.createElement('div');
  49251. infoTable.style.display = 'table';
  49252. for (var layoutEntry of layout) {
  49253. var row = document.createElement('div');
  49254. row.style.display = 'table-row';
  49255. row.className = 'info-panel-row';
  49256. var labelCell = document.createElement('div');
  49257. labelCell.style.display = 'table-cell';
  49258. labelCell.innerHTML = "".concat(layoutEntry[0], ": ");
  49259. labelCell.classList.add('info-panel-cell', 'label-cell');
  49260. var spacerCell = document.createElement('div');
  49261. spacerCell.style.display = 'table-cell';
  49262. spacerCell.style.width = '10px';
  49263. spacerCell.innerHTML = ' ';
  49264. spacerCell.className = 'info-panel-cell';
  49265. var infoCell = document.createElement('div');
  49266. infoCell.style.display = 'table-cell';
  49267. infoCell.innerHTML = '';
  49268. infoCell.className = 'info-panel-cell';
  49269. this.infoCells[layoutEntry[1]] = infoCell;
  49270. row.appendChild(labelCell);
  49271. row.appendChild(spacerCell);
  49272. row.appendChild(infoCell);
  49273. infoTable.appendChild(row);
  49274. }
  49275. this.infoPanel.appendChild(infoTable);
  49276. this.infoPanelContainer.append(this.infoPanel);
  49277. this.infoPanelContainer.style.display = 'none';
  49278. this.container.appendChild(this.infoPanelContainer);
  49279. this.visible = false;
  49280. }
  49281. setContainer(container) {
  49282. if (this.container) {
  49283. this.container.removeChild(this.infoPanelContainer);
  49284. }
  49285. if (container) {
  49286. this.container = container;
  49287. this.container.appendChild(this.infoPanelContainer);
  49288. this.infoPanelContainer.style.zIndex = this.container.style.zIndex + 1;
  49289. }
  49290. }
  49291. show() {
  49292. this.infoPanelContainer.style.display = 'block';
  49293. this.visible = true;
  49294. }
  49295. hide() {
  49296. this.infoPanelContainer.style.display = 'none';
  49297. this.visible = false;
  49298. }
  49299. }
  49300. class ArrowHelper$1 extends Object3D {
  49301. constructor() {
  49302. var dir = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Vector3(0, 0, 1);
  49303. var origin = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Vector3(0, 0, 0);
  49304. var length = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
  49305. var radius = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0.1;
  49306. var color = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0xffff00;
  49307. var headLength = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : length * 0.2;
  49308. var headRadius = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : headLength * 0.2;
  49309. super();
  49310. this.type = 'ArrowHelper';
  49311. var lineGeometry = new CylinderGeometry(radius, radius, length, 32);
  49312. lineGeometry.translate(0, length / 2.0, 0);
  49313. var coneGeometry = new CylinderGeometry(0, headRadius, headLength, 32);
  49314. coneGeometry.translate(0, length, 0);
  49315. this.position.copy(origin);
  49316. this.line = new Mesh(lineGeometry, new MeshBasicMaterial({
  49317. color: color,
  49318. toneMapped: false
  49319. }));
  49320. this.line.matrixAutoUpdate = false;
  49321. this.add(this.line);
  49322. this.cone = new Mesh(coneGeometry, new MeshBasicMaterial({
  49323. color: color,
  49324. toneMapped: false
  49325. }));
  49326. this.cone.matrixAutoUpdate = false;
  49327. this.add(this.cone);
  49328. this.setDirection(dir);
  49329. }
  49330. setDirection(dir) {
  49331. if (dir.y > 0.99999) {
  49332. this.quaternion.set(0, 0, 0, 1);
  49333. } else if (dir.y < -0.99999) {
  49334. this.quaternion.set(1, 0, 0, 0);
  49335. } else {
  49336. _axis.set(dir.z, 0, -dir.x).normalize();
  49337. var radians = Math.acos(dir.y);
  49338. this.quaternion.setFromAxisAngle(_axis, radians);
  49339. }
  49340. }
  49341. setColor(color) {
  49342. this.line.material.color.set(color);
  49343. this.cone.material.color.set(color);
  49344. }
  49345. copy(source) {
  49346. super.copy(source, false);
  49347. this.line.copy(source.line);
  49348. this.cone.copy(source.cone);
  49349. return this;
  49350. }
  49351. dispose() {
  49352. this.line.geometry.dispose();
  49353. this.line.material.dispose();
  49354. this.cone.geometry.dispose();
  49355. this.cone.material.dispose();
  49356. }
  49357. }
  49358. class SceneHelper {
  49359. constructor(threeScene) {
  49360. _defineProperty(this, "updateFocusMarker", function () {
  49361. var tempPosition = new Vector3();
  49362. var tempMatrix = new Matrix4();
  49363. var toCamera = new Vector3();
  49364. return function (position, camera, viewport) {
  49365. tempMatrix.copy(camera.matrixWorld).invert();
  49366. tempPosition.copy(position).applyMatrix4(tempMatrix);
  49367. tempPosition.normalize().multiplyScalar(10);
  49368. tempPosition.applyMatrix4(camera.matrixWorld);
  49369. toCamera.copy(camera.position).sub(position);
  49370. var toCameraDistance = toCamera.length();
  49371. this.focusMarker.position.copy(position);
  49372. this.focusMarker.scale.set(toCameraDistance, toCameraDistance, toCameraDistance);
  49373. this.focusMarker.material.uniforms.realFocusPosition.value.copy(position);
  49374. this.focusMarker.material.uniforms.viewport.value.copy(viewport);
  49375. this.focusMarker.material.uniformsNeedUpdate = true;
  49376. };
  49377. }());
  49378. _defineProperty(this, "positionAndOrientControlPlane", function () {
  49379. var tempQuaternion = new Quaternion();
  49380. var defaultUp = new Vector3(0, 1, 0);
  49381. return function (position, up) {
  49382. tempQuaternion.setFromUnitVectors(defaultUp, up);
  49383. this.controlPlane.position.copy(position);
  49384. this.controlPlane.quaternion.copy(tempQuaternion);
  49385. };
  49386. }());
  49387. this.threeScene = threeScene;
  49388. this.splatRenderTarget = null;
  49389. this.renderTargetCopyQuad = null;
  49390. this.renderTargetCopyCamera = null;
  49391. this.meshCursor = null;
  49392. this.focusMarker = null;
  49393. this.controlPlane = null;
  49394. this.debugRoot = null;
  49395. this.secondaryDebugRoot = null;
  49396. }
  49397. updateSplatRenderTargetForRenderDimensions(width, height) {
  49398. this.destroySplatRendertarget();
  49399. this.splatRenderTarget = new WebGLRenderTarget(width, height, {
  49400. format: RGBAFormat,
  49401. stencilBuffer: false,
  49402. depthBuffer: true
  49403. });
  49404. this.splatRenderTarget.depthTexture = new DepthTexture(width, height);
  49405. this.splatRenderTarget.depthTexture.format = DepthFormat;
  49406. this.splatRenderTarget.depthTexture.type = UnsignedIntType;
  49407. }
  49408. destroySplatRendertarget() {
  49409. if (this.splatRenderTarget) {
  49410. this.splatRenderTarget = null;
  49411. }
  49412. }
  49413. setupRenderTargetCopyObjects() {
  49414. var uniforms = {
  49415. 'sourceColorTexture': {
  49416. 'type': 't',
  49417. 'value': null
  49418. },
  49419. 'sourceDepthTexture': {
  49420. 'type': 't',
  49421. 'value': null
  49422. }
  49423. };
  49424. var renderTargetCopyMaterial = new ShaderMaterial({
  49425. vertexShader: "\n varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = vec4( position.xy, 0.0, 1.0 ); \n }\n ",
  49426. fragmentShader: "\n #include <common>\n #include <packing>\n varying vec2 vUv;\n uniform sampler2D sourceColorTexture;\n uniform sampler2D sourceDepthTexture;\n void main() {\n vec4 color = texture2D(sourceColorTexture, vUv);\n float fragDepth = texture2D(sourceDepthTexture, vUv).x;\n gl_FragDepth = fragDepth;\n gl_FragColor = vec4(color.rgb, color.a * 2.0);\n }\n ",
  49427. uniforms: uniforms,
  49428. depthWrite: false,
  49429. depthTest: false,
  49430. transparent: true,
  49431. blending: CustomBlending,
  49432. blendSrc: SrcAlphaFactor,
  49433. blendSrcAlpha: SrcAlphaFactor,
  49434. blendDst: OneMinusSrcAlphaFactor,
  49435. blendDstAlpha: OneMinusSrcAlphaFactor
  49436. });
  49437. renderTargetCopyMaterial.extensions.fragDepth = true;
  49438. this.renderTargetCopyQuad = new Mesh(new PlaneGeometry(2, 2), renderTargetCopyMaterial);
  49439. this.renderTargetCopyCamera = new OrthographicCamera(-1, 1, 1, -1, 0, 1);
  49440. }
  49441. destroyRenderTargetCopyObjects() {
  49442. if (this.renderTargetCopyQuad) {
  49443. disposeAllMeshes(this.renderTargetCopyQuad);
  49444. this.renderTargetCopyQuad = null;
  49445. }
  49446. }
  49447. setupMeshCursor() {
  49448. if (!this.meshCursor) {
  49449. var coneGeometry = new ConeGeometry(0.5, 1.5, 32);
  49450. var coneMaterial = new MeshBasicMaterial({
  49451. color: 0xFFFFFF
  49452. });
  49453. var downArrow = new Mesh(coneGeometry, coneMaterial);
  49454. downArrow.rotation.set(0, 0, Math.PI);
  49455. downArrow.position.set(0, 1, 0);
  49456. var upArrow = new Mesh(coneGeometry, coneMaterial);
  49457. upArrow.position.set(0, -1, 0);
  49458. var leftArrow = new Mesh(coneGeometry, coneMaterial);
  49459. leftArrow.rotation.set(0, 0, Math.PI / 2.0);
  49460. leftArrow.position.set(1, 0, 0);
  49461. var rightArrow = new Mesh(coneGeometry, coneMaterial);
  49462. rightArrow.rotation.set(0, 0, -Math.PI / 2.0);
  49463. rightArrow.position.set(-1, 0, 0);
  49464. this.meshCursor = new Object3D();
  49465. this.meshCursor.add(downArrow);
  49466. this.meshCursor.add(upArrow);
  49467. this.meshCursor.add(leftArrow);
  49468. this.meshCursor.add(rightArrow);
  49469. this.meshCursor.scale.set(0.1, 0.1, 0.1);
  49470. this.threeScene.add(this.meshCursor);
  49471. this.meshCursor.visible = false;
  49472. }
  49473. }
  49474. destroyMeshCursor() {
  49475. if (this.meshCursor) {
  49476. disposeAllMeshes(this.meshCursor);
  49477. this.threeScene.remove(this.meshCursor);
  49478. this.meshCursor = null;
  49479. }
  49480. }
  49481. setMeshCursorVisibility(visible) {
  49482. this.meshCursor.visible = visible;
  49483. }
  49484. getMeschCursorVisibility() {
  49485. return this.meshCursor.visible;
  49486. }
  49487. setMeshCursorPosition(position) {
  49488. this.meshCursor.position.copy(position);
  49489. }
  49490. positionAndOrientMeshCursor(position, camera) {
  49491. this.meshCursor.position.copy(position);
  49492. this.meshCursor.up.copy(camera.up);
  49493. this.meshCursor.lookAt(camera.position);
  49494. }
  49495. setupFocusMarker() {
  49496. if (!this.focusMarker) {
  49497. var sphereGeometry = new SphereGeometry(.5, 32, 32);
  49498. var focusMarkerMaterial = SceneHelper.buildFocusMarkerMaterial();
  49499. focusMarkerMaterial.depthTest = false;
  49500. focusMarkerMaterial.depthWrite = false;
  49501. focusMarkerMaterial.transparent = true;
  49502. this.focusMarker = new Mesh(sphereGeometry, focusMarkerMaterial);
  49503. }
  49504. }
  49505. destroyFocusMarker() {
  49506. if (this.focusMarker) {
  49507. disposeAllMeshes(this.focusMarker);
  49508. this.focusMarker = null;
  49509. }
  49510. }
  49511. setFocusMarkerVisibility(visible) {
  49512. this.focusMarker.visible = visible;
  49513. }
  49514. setFocusMarkerOpacity(opacity) {
  49515. this.focusMarker.material.uniforms.opacity.value = opacity;
  49516. this.focusMarker.material.uniformsNeedUpdate = true;
  49517. }
  49518. getFocusMarkerOpacity() {
  49519. return this.focusMarker.material.uniforms.opacity.value;
  49520. }
  49521. setupControlPlane() {
  49522. if (!this.controlPlane) {
  49523. var planeGeometry = new PlaneGeometry(1, 1);
  49524. planeGeometry.rotateX(-Math.PI / 2);
  49525. var planeMaterial = new MeshBasicMaterial({
  49526. color: 0xffffff
  49527. });
  49528. planeMaterial.transparent = true;
  49529. planeMaterial.opacity = 0.6;
  49530. planeMaterial.depthTest = false;
  49531. planeMaterial.depthWrite = false;
  49532. planeMaterial.side = DoubleSide;
  49533. var planeMesh = new Mesh(planeGeometry, planeMaterial);
  49534. var arrowDir = new Vector3(0, 1, 0);
  49535. arrowDir.normalize();
  49536. var arrowOrigin = new Vector3(0, 0, 0);
  49537. var arrowLength = 0.5;
  49538. var arrowRadius = 0.01;
  49539. var arrowColor = 0x00dd00;
  49540. var arrowHelper = new ArrowHelper$1(arrowDir, arrowOrigin, arrowLength, arrowRadius, arrowColor, 0.1, 0.03);
  49541. this.controlPlane = new Object3D();
  49542. this.controlPlane.add(planeMesh);
  49543. this.controlPlane.add(arrowHelper);
  49544. }
  49545. }
  49546. destroyControlPlane() {
  49547. if (this.controlPlane) {
  49548. disposeAllMeshes(this.controlPlane);
  49549. this.controlPlane = null;
  49550. }
  49551. }
  49552. setControlPlaneVisibility(visible) {
  49553. this.controlPlane.visible = visible;
  49554. }
  49555. addDebugMeshes() {
  49556. this.debugRoot = this.createDebugMeshes();
  49557. this.secondaryDebugRoot = this.createSecondaryDebugMeshes();
  49558. this.threeScene.add(this.debugRoot);
  49559. this.threeScene.add(this.secondaryDebugRoot);
  49560. }
  49561. destroyDebugMeshes() {
  49562. for (var debugRoot of [this.debugRoot, this.secondaryDebugRoot]) {
  49563. if (debugRoot) {
  49564. disposeAllMeshes(debugRoot);
  49565. this.threeScene.remove(debugRoot);
  49566. }
  49567. }
  49568. this.debugRoot = null;
  49569. this.secondaryDebugRoot = null;
  49570. }
  49571. createDebugMeshes(renderOrder) {
  49572. var sphereGeometry = new SphereGeometry(1, 32, 32);
  49573. var debugMeshRoot = new Object3D();
  49574. var createMesh = (color, position) => {
  49575. var sphereMesh = new Mesh(sphereGeometry, SceneHelper.buildDebugMaterial(color));
  49576. sphereMesh.renderOrder = renderOrder;
  49577. debugMeshRoot.add(sphereMesh);
  49578. sphereMesh.position.fromArray(position);
  49579. };
  49580. createMesh(0xff0000, [-50, 0, 0]);
  49581. createMesh(0xff0000, [50, 0, 0]);
  49582. createMesh(0x00ff00, [0, 0, -50]);
  49583. createMesh(0x00ff00, [0, 0, 50]);
  49584. createMesh(0xffaa00, [5, 0, 5]);
  49585. return debugMeshRoot;
  49586. }
  49587. createSecondaryDebugMeshes(renderOrder) {
  49588. var boxGeometry = new BoxGeometry(3, 3, 3);
  49589. var debugMeshRoot = new Object3D();
  49590. var boxColor = 0xBBBBBB;
  49591. var createMesh = position => {
  49592. var boxMesh = new Mesh(boxGeometry, SceneHelper.buildDebugMaterial(boxColor));
  49593. boxMesh.renderOrder = renderOrder;
  49594. debugMeshRoot.add(boxMesh);
  49595. boxMesh.position.fromArray(position);
  49596. };
  49597. var separation = 10;
  49598. createMesh([-separation, 0, -separation]);
  49599. createMesh([-separation, 0, separation]);
  49600. createMesh([separation, 0, -separation]);
  49601. createMesh([separation, 0, separation]);
  49602. return debugMeshRoot;
  49603. }
  49604. static buildDebugMaterial(color) {
  49605. var vertexShaderSource = "\n #include <common>\n varying float ndcDepth;\n\n void main() {\n gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position.xyz, 1.0);\n ndcDepth = gl_Position.z / gl_Position.w;\n gl_Position.x = gl_Position.x / gl_Position.w;\n gl_Position.y = gl_Position.y / gl_Position.w;\n gl_Position.z = 0.0;\n gl_Position.w = 1.0;\n \n }\n ";
  49606. var fragmentShaderSource = "\n #include <common>\n uniform vec3 color;\n varying float ndcDepth;\n void main() {\n gl_FragDepth = (ndcDepth + 1.0) / 2.0;\n gl_FragColor = vec4(color.rgb, 0.0);\n }\n ";
  49607. var uniforms = {
  49608. 'color': {
  49609. 'type': 'v3',
  49610. 'value': new Color(color)
  49611. }
  49612. };
  49613. var material = new ShaderMaterial({
  49614. uniforms: uniforms,
  49615. vertexShader: vertexShaderSource,
  49616. fragmentShader: fragmentShaderSource,
  49617. transparent: false,
  49618. depthTest: true,
  49619. depthWrite: true,
  49620. side: FrontSide
  49621. });
  49622. material.extensions.fragDepth = true;
  49623. return material;
  49624. }
  49625. static buildFocusMarkerMaterial(color) {
  49626. var vertexShaderSource = "\n #include <common>\n\n uniform vec2 viewport;\n uniform vec3 realFocusPosition;\n\n varying vec4 ndcPosition;\n varying vec4 ndcCenter;\n varying vec4 ndcFocusPosition;\n\n void main() {\n float radius = 0.01;\n\n vec4 viewPosition = modelViewMatrix * vec4(position.xyz, 1.0);\n vec4 viewCenter = modelViewMatrix * vec4(0.0, 0.0, 0.0, 1.0);\n\n vec4 viewFocusPosition = modelViewMatrix * vec4(realFocusPosition, 1.0);\n\n ndcPosition = projectionMatrix * viewPosition;\n ndcPosition = ndcPosition * vec4(1.0 / ndcPosition.w);\n ndcCenter = projectionMatrix * viewCenter;\n ndcCenter = ndcCenter * vec4(1.0 / ndcCenter.w);\n\n ndcFocusPosition = projectionMatrix * viewFocusPosition;\n ndcFocusPosition = ndcFocusPosition * vec4(1.0 / ndcFocusPosition.w);\n\n gl_Position = projectionMatrix * viewPosition;\n\n }\n ";
  49627. var fragmentShaderSource = "\n #include <common>\n uniform vec3 color;\n uniform vec2 viewport;\n uniform float opacity;\n\n varying vec4 ndcPosition;\n varying vec4 ndcCenter;\n varying vec4 ndcFocusPosition;\n\n void main() {\n vec2 screenPosition = vec2(ndcPosition) * viewport;\n vec2 screenCenter = vec2(ndcCenter) * viewport;\n\n vec2 screenVec = screenPosition - screenCenter;\n\n float projectedRadius = length(screenVec);\n\n float lineWidth = 0.0005 * viewport.y;\n float aaRange = 0.0025 * viewport.y;\n float radius = 0.06 * viewport.y;\n float radDiff = abs(projectedRadius - radius) - lineWidth;\n float alpha = 1.0 - clamp(radDiff / 5.0, 0.0, 1.0); \n\n gl_FragColor = vec4(color.rgb, alpha * opacity);\n }\n ";
  49628. var uniforms = {
  49629. 'color': {
  49630. 'type': 'v3',
  49631. 'value': new Color(color)
  49632. },
  49633. 'realFocusPosition': {
  49634. 'type': 'v3',
  49635. 'value': new Vector3()
  49636. },
  49637. 'viewport': {
  49638. 'type': 'v2',
  49639. 'value': new Vector2()
  49640. },
  49641. 'opacity': {
  49642. 'value': 0.0
  49643. }
  49644. };
  49645. var material = new ShaderMaterial({
  49646. uniforms: uniforms,
  49647. vertexShader: vertexShaderSource,
  49648. fragmentShader: fragmentShaderSource,
  49649. transparent: true,
  49650. depthTest: false,
  49651. depthWrite: false,
  49652. side: FrontSide
  49653. });
  49654. return material;
  49655. }
  49656. dispose() {
  49657. this.destroyMeshCursor();
  49658. this.destroyFocusMarker();
  49659. this.destroyDebugMeshes();
  49660. this.destroyControlPlane();
  49661. this.destroyRenderTargetCopyObjects();
  49662. this.destroySplatRendertarget();
  49663. }
  49664. }
  49665. var VectorRight = new Vector3(1, 0, 0);
  49666. var VectorUp = new Vector3(0, 1, 0);
  49667. var VectorBackward = new Vector3(0, 0, 1);
  49668. class Ray$1 {
  49669. constructor() {
  49670. var origin = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Vector3();
  49671. var direction = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Vector3();
  49672. _defineProperty(this, "intersectBox", function () {
  49673. var planeIntersectionPoint = new Vector3();
  49674. var planeIntersectionPointArray = [];
  49675. var originArray = [];
  49676. var directionArray = [];
  49677. return function (box, outHit) {
  49678. originArray[0] = this.origin.x;
  49679. originArray[1] = this.origin.y;
  49680. originArray[2] = this.origin.z;
  49681. directionArray[0] = this.direction.x;
  49682. directionArray[1] = this.direction.y;
  49683. directionArray[2] = this.direction.z;
  49684. if (this.boxContainsPoint(box, this.origin, 0.0001)) {
  49685. if (outHit) {
  49686. outHit.origin.copy(this.origin);
  49687. outHit.normal.set(0, 0, 0);
  49688. outHit.distance = -1;
  49689. }
  49690. return true;
  49691. }
  49692. for (var i = 0; i < 3; i++) {
  49693. if (directionArray[i] == 0.0) continue;
  49694. var hitNormal = i == 0 ? VectorRight : i == 1 ? VectorUp : VectorBackward;
  49695. var extremeVec = directionArray[i] < 0 ? box.max : box.min;
  49696. var multiplier = -Math.sign(directionArray[i]);
  49697. planeIntersectionPointArray[0] = i == 0 ? extremeVec.x : i == 1 ? extremeVec.y : extremeVec.z;
  49698. var toSide = planeIntersectionPointArray[0] - originArray[i];
  49699. if (toSide * multiplier < 0) {
  49700. var idx1 = (i + 1) % 3;
  49701. var idx2 = (i + 2) % 3;
  49702. planeIntersectionPointArray[2] = directionArray[idx1] / directionArray[i] * toSide + originArray[idx1];
  49703. planeIntersectionPointArray[1] = directionArray[idx2] / directionArray[i] * toSide + originArray[idx2];
  49704. planeIntersectionPoint.set(planeIntersectionPointArray[i], planeIntersectionPointArray[idx2], planeIntersectionPointArray[idx1]);
  49705. if (this.boxContainsPoint(box, planeIntersectionPoint, 0.0001)) {
  49706. if (outHit) {
  49707. outHit.origin.copy(planeIntersectionPoint);
  49708. outHit.normal.copy(hitNormal).multiplyScalar(multiplier);
  49709. outHit.distance = planeIntersectionPoint.sub(this.origin).length();
  49710. }
  49711. return true;
  49712. }
  49713. }
  49714. }
  49715. return false;
  49716. };
  49717. }());
  49718. _defineProperty(this, "intersectSphere", function () {
  49719. var toSphereCenterVec = new Vector3();
  49720. return function (center, radius, outHit) {
  49721. toSphereCenterVec.copy(center).sub(this.origin);
  49722. var toClosestApproach = toSphereCenterVec.dot(this.direction);
  49723. var toClosestApproachSq = toClosestApproach * toClosestApproach;
  49724. var toSphereCenterSq = toSphereCenterVec.dot(toSphereCenterVec);
  49725. var diffSq = toSphereCenterSq - toClosestApproachSq;
  49726. var radiusSq = radius * radius;
  49727. if (diffSq > radiusSq) return false;
  49728. var thc = Math.sqrt(radiusSq - diffSq);
  49729. var t0 = toClosestApproach - thc;
  49730. var t1 = toClosestApproach + thc;
  49731. if (t1 < 0) return false;
  49732. var t = t0 < 0 ? t1 : t0;
  49733. if (outHit) {
  49734. outHit.origin.copy(this.origin).addScaledVector(this.direction, t);
  49735. outHit.normal.copy(outHit.origin).sub(center).normalize();
  49736. outHit.distance = t;
  49737. }
  49738. return true;
  49739. };
  49740. }());
  49741. this.origin = new Vector3();
  49742. this.direction = new Vector3();
  49743. this.setParameters(origin, direction);
  49744. }
  49745. setParameters(origin, direction) {
  49746. this.origin.copy(origin);
  49747. this.direction.copy(direction).normalize();
  49748. }
  49749. boxContainsPoint(box, point, epsilon) {
  49750. return point.x < box.min.x - epsilon || point.x > box.max.x + epsilon || point.y < box.min.y - epsilon || point.y > box.max.y + epsilon || point.z < box.min.z - epsilon || point.z > box.max.z + epsilon ? false : true;
  49751. }
  49752. }
  49753. class Hit {
  49754. constructor() {
  49755. this.origin = new Vector3();
  49756. this.normal = new Vector3();
  49757. this.distance = 0;
  49758. this.splatIndex = 0;
  49759. }
  49760. set(origin, normal, distance, splatIndex) {
  49761. this.origin.copy(origin);
  49762. this.normal.copy(normal);
  49763. this.distance = distance;
  49764. this.splatIndex = splatIndex;
  49765. }
  49766. clone() {
  49767. var hitClone = new Hit();
  49768. hitClone.origin.copy(this.origin);
  49769. hitClone.normal.copy(this.normal);
  49770. hitClone.distance = this.distance;
  49771. hitClone.splatIndex = this.splatIndex;
  49772. return hitClone;
  49773. }
  49774. }
  49775. class Raycaster$1 {
  49776. constructor(_origin, direction) {
  49777. var raycastAgainstTrueSplatEllipsoid = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  49778. _defineProperty(this, "setFromCameraAndScreenPosition", function () {
  49779. var ndcCoords = new Vector2();
  49780. return function (camera, screenPosition, screenDimensions) {
  49781. ndcCoords.x = screenPosition.x / screenDimensions.x * 2.0 - 1.0;
  49782. ndcCoords.y = (screenDimensions.y - screenPosition.y) / screenDimensions.y * 2.0 - 1.0;
  49783. if (camera.isPerspectiveCamera) {
  49784. this.ray.origin.setFromMatrixPosition(camera.matrixWorld);
  49785. this.ray.direction.set(ndcCoords.x, ndcCoords.y, 0.5).unproject(camera).sub(this.ray.origin).normalize();
  49786. this.camera = camera;
  49787. } else if (camera.isOrthographicCamera) {
  49788. this.ray.origin.set(ndcCoords.x, ndcCoords.y, (camera.near + camera.far) / (camera.near - camera.far)).unproject(camera);
  49789. this.ray.direction.set(0, 0, -1).transformDirection(camera.matrixWorld);
  49790. this.camera = camera;
  49791. } else {
  49792. throw new Error('Raycaster::setFromCameraAndScreenPosition() -> Unsupported camera type');
  49793. }
  49794. };
  49795. }());
  49796. _defineProperty(this, "intersectSplatMesh", function () {
  49797. var toLocal = new Matrix4();
  49798. var fromLocal = new Matrix4();
  49799. var sceneTransform = new Matrix4();
  49800. var localRay = new Ray$1();
  49801. var tempPoint = new Vector3();
  49802. return function (splatMesh) {
  49803. var outHits = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  49804. var splatTree = splatMesh.getSplatTree();
  49805. if (!splatTree) return;
  49806. for (var s = 0; s < splatTree.subTrees.length; s++) {
  49807. var subTree = splatTree.subTrees[s];
  49808. fromLocal.copy(splatMesh.matrixWorld);
  49809. if (splatMesh.dynamicMode) {
  49810. splatMesh.getSceneTransform(s, sceneTransform);
  49811. fromLocal.multiply(sceneTransform);
  49812. }
  49813. toLocal.copy(fromLocal).invert();
  49814. //直接在ray上乘上模型变换
  49815. localRay.origin.copy(this.ray.origin).applyMatrix4(toLocal);
  49816. localRay.direction.copy(this.ray.origin).add(this.ray.direction);
  49817. localRay.direction.applyMatrix4(toLocal).sub(localRay.origin).normalize();
  49818. var outHitsForSubTree = [];
  49819. if (subTree.rootNode) {
  49820. this.castRayAtSplatTreeNode(localRay, splatTree, subTree.rootNode, outHitsForSubTree);
  49821. }
  49822. outHitsForSubTree.forEach(hit => {
  49823. hit.origin.applyMatrix4(fromLocal);
  49824. hit.normal.applyMatrix4(fromLocal).normalize();
  49825. hit.distance = tempPoint.copy(hit.origin).sub(this.ray.origin).length();
  49826. });
  49827. outHits.push(...outHitsForSubTree);
  49828. }
  49829. outHits.sort((a, b) => {
  49830. if (a.distance > b.distance) return 1;else return -1;
  49831. });
  49832. return outHits;
  49833. };
  49834. }());
  49835. _defineProperty(this, "castRayAtSplatTreeNode", function () {
  49836. var tempColor = new Vector4();
  49837. var tempCenter = new Vector3();
  49838. var tempScale = new Vector3();
  49839. var tempRotation = new Quaternion();
  49840. var tempHit = new Hit();
  49841. var scaleEpsilon = 0.0000001;
  49842. var origin = new Vector3(0, 0, 0);
  49843. var uniformScaleMatrix = new Matrix4();
  49844. var scaleMatrix = new Matrix4();
  49845. var rotationMatrix = new Matrix4();
  49846. var toSphereSpace = new Matrix4();
  49847. var fromSphereSpace = new Matrix4();
  49848. var tempRay = new Ray$1();
  49849. return function (ray, splatTree, node) {
  49850. var outHits = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
  49851. if (!ray.intersectBox(node.boundingBox)) {
  49852. return;
  49853. }
  49854. if (node.data && node.data.indexes && node.data.indexes.length > 0) {
  49855. for (var i = 0; i < node.data.indexes.length; i++) {
  49856. var splatGlobalIndex = node.data.indexes[i];
  49857. splatTree.splatMesh.getSplatColor(splatGlobalIndex, tempColor);
  49858. splatTree.splatMesh.getSplatCenter(splatGlobalIndex, tempCenter);
  49859. splatTree.splatMesh.getSplatScaleAndRotation(splatGlobalIndex, tempScale, tempRotation);
  49860. if (tempScale.x <= scaleEpsilon || tempScale.y <= scaleEpsilon || tempScale.z <= scaleEpsilon) {
  49861. continue;
  49862. }
  49863. if (!this.raycastAgainstTrueSplatEllipsoid) {
  49864. //是只需得到近似值的意思吗
  49865. var radius = (tempScale.x + tempScale.y + tempScale.z) / 3; //椭球的平均半径
  49866. if (ray.intersectSphere(tempCenter, radius, tempHit)) {
  49867. //没细看,是pick球上哪个点?
  49868. var hitClone = tempHit.clone();
  49869. hitClone.splatIndex = splatGlobalIndex;
  49870. outHits.push(hitClone);
  49871. }
  49872. } else {
  49873. scaleMatrix.makeScale(tempScale.x, tempScale.y, tempScale.z);
  49874. rotationMatrix.makeRotationFromQuaternion(tempRotation);
  49875. var uniformScale = Math.log10(tempColor.w) * 2.0;
  49876. uniformScaleMatrix.makeScale(uniformScale, uniformScale, uniformScale);
  49877. fromSphereSpace.copy(uniformScaleMatrix).multiply(rotationMatrix).multiply(scaleMatrix);
  49878. toSphereSpace.copy(fromSphereSpace).invert();
  49879. tempRay.origin.copy(ray.origin).sub(tempCenter).applyMatrix4(toSphereSpace);
  49880. tempRay.direction.copy(ray.origin).add(ray.direction).sub(tempCenter);
  49881. tempRay.direction.applyMatrix4(toSphereSpace).sub(tempRay.origin).normalize();
  49882. if (tempRay.intersectSphere(origin, 1.0, tempHit)) {
  49883. var _hitClone = tempHit.clone();
  49884. _hitClone.splatIndex = splatGlobalIndex;
  49885. _hitClone.origin.applyMatrix4(fromSphereSpace).add(tempCenter);
  49886. outHits.push(_hitClone);
  49887. }
  49888. }
  49889. }
  49890. }
  49891. if (node.children && node.children.length > 0) {
  49892. for (var child of node.children) {
  49893. this.castRayAtSplatTreeNode(ray, splatTree, child, outHits);
  49894. }
  49895. }
  49896. return outHits;
  49897. };
  49898. }());
  49899. this.ray = new Ray$1(_origin, direction);
  49900. this.raycastAgainstTrueSplatEllipsoid = raycastAgainstTrueSplatEllipsoid;
  49901. }
  49902. }
  49903. /**
  49904. * SplatScene: Descriptor for a single splat scene managed by an instance of SplatMesh.
  49905. */
  49906. class SplatScene {
  49907. constructor(splatBuffer) {
  49908. var position = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Vector3();
  49909. var quaternion = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new Quaternion();
  49910. var scale = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : new Vector3(1, 1, 1);
  49911. var minimumAlpha = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
  49912. this.splatBuffer = splatBuffer;
  49913. this.position = position.clone();
  49914. this.quaternion = quaternion.clone();
  49915. this.scale = scale.clone();
  49916. this.transform = new Matrix4();
  49917. this.minimumAlpha = minimumAlpha;
  49918. this.updateTransform();
  49919. }
  49920. copyTransformData(otherScene) {
  49921. this.position.copy(otherScene.position);
  49922. this.quaternion.copy(otherScene.quaternion);
  49923. this.scale.copy(otherScene.scale);
  49924. this.transform.copy(otherScene.transform);
  49925. }
  49926. updateTransform() {
  49927. this.transform.compose(this.position, this.quaternion, this.scale);
  49928. }
  49929. }
  49930. /*
  49931. 将点云中的点按照八叉树的方式一层层等分存储。
  49932. 每个子节点自动向下分割,直到层数到达最大,或者其点数量小于最大容纳点数为止。
  49933. */
  49934. class SplatTreeNode {
  49935. constructor(min, max, depth, id) {
  49936. this.min = new Vector3().copy(min);
  49937. this.max = new Vector3().copy(max);
  49938. this.boundingBox = new Box3(this.min, this.max);
  49939. this.center = new Vector3().copy(this.max).sub(this.min).multiplyScalar(0.5).add(this.min);
  49940. this.depth = depth;
  49941. this.children = [];
  49942. this.data = null;
  49943. this.id = id || SplatTreeNode.idGen++;
  49944. }
  49945. }
  49946. _defineProperty(SplatTreeNode, "idGen", 0);
  49947. class SplatSubTree {
  49948. constructor(maxDepth, maxCentersPerNode) {
  49949. this.maxDepth = maxDepth;
  49950. this.maxCentersPerNode = maxCentersPerNode;
  49951. this.sceneDimensions = new Vector3();
  49952. this.sceneMin = new Vector3();
  49953. this.sceneMax = new Vector3();
  49954. this.rootNode = null;
  49955. this.nodesWithIndexes = [];
  49956. this.splatMesh = null;
  49957. }
  49958. static convertWorkerSubTreeNode(workerSubTreeNode) {
  49959. var minVector = new Vector3().fromArray(workerSubTreeNode.min);
  49960. var maxVector = new Vector3().fromArray(workerSubTreeNode.max);
  49961. var convertedNode = new SplatTreeNode(minVector, maxVector, workerSubTreeNode.depth, workerSubTreeNode.id);
  49962. if (workerSubTreeNode.data.indexes) {
  49963. convertedNode.data = {
  49964. 'indexes': []
  49965. };
  49966. for (var index of workerSubTreeNode.data.indexes) {
  49967. convertedNode.data.indexes.push(index);
  49968. }
  49969. }
  49970. if (workerSubTreeNode.children) {
  49971. for (var child of workerSubTreeNode.children) {
  49972. convertedNode.children.push(SplatSubTree.convertWorkerSubTreeNode(child));
  49973. }
  49974. }
  49975. return convertedNode;
  49976. }
  49977. static convertWorkerSubTree(workerSubTree, splatMesh) {
  49978. var convertedSubTree = new SplatSubTree(workerSubTree.maxDepth, workerSubTree.maxCentersPerNode);
  49979. convertedSubTree.sceneMin = new Vector3().fromArray(workerSubTree.sceneMin);
  49980. convertedSubTree.sceneMax = new Vector3().fromArray(workerSubTree.sceneMax);
  49981. convertedSubTree.splatMesh = splatMesh;
  49982. convertedSubTree.rootNode = SplatSubTree.convertWorkerSubTreeNode(workerSubTree.rootNode);
  49983. var visitLeavesFromNode = (node, visitFunc) => {
  49984. if (node.children.length === 0) visitFunc(node);
  49985. for (var child of node.children) {
  49986. visitLeavesFromNode(child, visitFunc);
  49987. }
  49988. };
  49989. convertedSubTree.nodesWithIndexes = [];
  49990. visitLeavesFromNode(convertedSubTree.rootNode, node => {
  49991. if (node.data && node.data.indexes && node.data.indexes.length > 0) {
  49992. convertedSubTree.nodesWithIndexes.push(node);
  49993. }
  49994. });
  49995. return convertedSubTree;
  49996. }
  49997. }
  49998. function createSplatTreeWorker(self) {
  49999. var WorkerSplatTreeNodeIDGen = 0;
  50000. class WorkerBox3 {
  50001. constructor(min, max) {
  50002. this.min = [min[0], min[1], min[2]];
  50003. this.max = [max[0], max[1], max[2]];
  50004. }
  50005. containsPoint(point) {
  50006. return point[0] >= this.min[0] && point[0] <= this.max[0] && point[1] >= this.min[1] && point[1] <= this.max[1] && point[2] >= this.min[2] && point[2] <= this.max[2];
  50007. }
  50008. }
  50009. class WorkerSplatSubTree {
  50010. constructor(maxDepth, maxCentersPerNode) {
  50011. this.maxDepth = maxDepth;
  50012. this.maxCentersPerNode = maxCentersPerNode;
  50013. this.sceneDimensions = [];
  50014. this.sceneMin = [];
  50015. this.sceneMax = [];
  50016. this.rootNode = null;
  50017. this.addedIndexes = {};
  50018. this.nodesWithIndexes = [];
  50019. this.splatMesh = null;
  50020. this.disposed = false;
  50021. }
  50022. }
  50023. class WorkerSplatTreeNode {
  50024. constructor(min, max, depth, id) {
  50025. this.min = [min[0], min[1], min[2]];
  50026. this.max = [max[0], max[1], max[2]];
  50027. this.center = [(max[0] - min[0]) * 0.5 + min[0], (max[1] - min[1]) * 0.5 + min[1], (max[2] - min[2]) * 0.5 + min[2]];
  50028. this.depth = depth;
  50029. this.children = [];
  50030. this.data = null;
  50031. this.id = id || WorkerSplatTreeNodeIDGen++;
  50032. }
  50033. }
  50034. processSplatTreeNode = function (_processSplatTreeNode) {
  50035. function processSplatTreeNode(_x, _x2, _x3, _x4) {
  50036. return _processSplatTreeNode.apply(this, arguments);
  50037. }
  50038. processSplatTreeNode.toString = function () {
  50039. return _processSplatTreeNode.toString();
  50040. };
  50041. return processSplatTreeNode;
  50042. }(function (tree, node, indexToCenter, sceneCenters) {
  50043. var splatCount = node.data.indexes.length;
  50044. if (splatCount < tree.maxCentersPerNode || node.depth > tree.maxDepth) {
  50045. //该节点停止分割
  50046. var newIndexes = [];
  50047. for (var i = 0; i < node.data.indexes.length; i++) {
  50048. if (!tree.addedIndexes[node.data.indexes[i]]) {
  50049. newIndexes.push(node.data.indexes[i]);
  50050. tree.addedIndexes[node.data.indexes[i]] = true;
  50051. }
  50052. }
  50053. node.data.indexes = newIndexes;
  50054. node.data.indexes.sort((a, b) => {
  50055. if (a > b) return 1;else return -1;
  50056. });
  50057. tree.nodesWithIndexes.push(node);
  50058. return;
  50059. }
  50060. var nodeDimensions = [node.max[0] - node.min[0], node.max[1] - node.min[1], node.max[2] - node.min[2]];
  50061. var halfDimensions = [nodeDimensions[0] * 0.5, nodeDimensions[1] * 0.5, nodeDimensions[2] * 0.5];
  50062. var nodeCenter = [node.min[0] + halfDimensions[0], node.min[1] + halfDimensions[1], node.min[2] + halfDimensions[2]];
  50063. var childrenBounds = [
  50064. //分割成八块
  50065. // top section, clockwise from upper-left (looking from above, +Y)
  50066. new WorkerBox3([nodeCenter[0] - halfDimensions[0], nodeCenter[1], nodeCenter[2] - halfDimensions[2]], [nodeCenter[0], nodeCenter[1] + halfDimensions[1], nodeCenter[2]]), new WorkerBox3([nodeCenter[0], nodeCenter[1], nodeCenter[2] - halfDimensions[2]], [nodeCenter[0] + halfDimensions[0], nodeCenter[1] + halfDimensions[1], nodeCenter[2]]), new WorkerBox3([nodeCenter[0], nodeCenter[1], nodeCenter[2]], [nodeCenter[0] + halfDimensions[0], nodeCenter[1] + halfDimensions[1], nodeCenter[2] + halfDimensions[2]]), new WorkerBox3([nodeCenter[0] - halfDimensions[0], nodeCenter[1], nodeCenter[2]], [nodeCenter[0], nodeCenter[1] + halfDimensions[1], nodeCenter[2] + halfDimensions[2]]),
  50067. // bottom section, clockwise from lower-left (looking from above, +Y)
  50068. new WorkerBox3([nodeCenter[0] - halfDimensions[0], nodeCenter[1] - halfDimensions[1], nodeCenter[2] - halfDimensions[2]], [nodeCenter[0], nodeCenter[1], nodeCenter[2]]), new WorkerBox3([nodeCenter[0], nodeCenter[1] - halfDimensions[1], nodeCenter[2] - halfDimensions[2]], [nodeCenter[0] + halfDimensions[0], nodeCenter[1], nodeCenter[2]]), new WorkerBox3([nodeCenter[0], nodeCenter[1] - halfDimensions[1], nodeCenter[2]], [nodeCenter[0] + halfDimensions[0], nodeCenter[1], nodeCenter[2] + halfDimensions[2]]), new WorkerBox3([nodeCenter[0] - halfDimensions[0], nodeCenter[1] - halfDimensions[1], nodeCenter[2]], [nodeCenter[0], nodeCenter[1], nodeCenter[2] + halfDimensions[2]])];
  50069. var splatCounts = [];
  50070. var baseIndexes = [];
  50071. for (var _i15 = 0; _i15 < childrenBounds.length; _i15++) {
  50072. splatCounts[_i15] = 0;
  50073. baseIndexes[_i15] = [];
  50074. }
  50075. var center = [0, 0, 0];
  50076. for (var _i16 = 0; _i16 < splatCount; _i16++) {
  50077. //查找每一块包含的index
  50078. var splatGlobalIndex = node.data.indexes[_i16];
  50079. var centerBase = indexToCenter[splatGlobalIndex];
  50080. center[0] = sceneCenters[centerBase];
  50081. center[1] = sceneCenters[centerBase + 1];
  50082. center[2] = sceneCenters[centerBase + 2];
  50083. for (var j = 0; j < childrenBounds.length; j++) {
  50084. if (childrenBounds[j].containsPoint(center)) {
  50085. splatCounts[j]++;
  50086. baseIndexes[j].push(splatGlobalIndex);
  50087. break; //xzw!!!! add 防止ply转的如果都是000点,就会每块都有然后不停分割下去
  50088. }
  50089. }
  50090. }
  50091. for (var _i17 = 0; _i17 < childrenBounds.length; _i17++) {
  50092. var childNode = new WorkerSplatTreeNode(childrenBounds[_i17].min, childrenBounds[_i17].max, node.depth + 1); //创建子节点
  50093. childNode.data = {
  50094. 'indexes': baseIndexes[_i17]
  50095. };
  50096. node.children.push(childNode);
  50097. }
  50098. node.data = {}; //清空自身index
  50099. for (var child of node.children) {
  50100. processSplatTreeNode(tree, child, indexToCenter, sceneCenters); //继续分割
  50101. }
  50102. return;
  50103. });
  50104. var buildSubTree = (sceneCenters, maxDepth, maxCentersPerNode) => {
  50105. var sceneMin = [0, 0, 0];
  50106. var sceneMax = [0, 0, 0];
  50107. var indexes = [];
  50108. var centerCount = Math.floor(sceneCenters.length / 4);
  50109. for (var i = 0; i < centerCount; i++) {
  50110. var base = i * 4;
  50111. var x = sceneCenters[base];
  50112. var y = sceneCenters[base + 1];
  50113. var z = sceneCenters[base + 2];
  50114. var index = Math.round(sceneCenters[base + 3]);
  50115. if (i === 0 || x < sceneMin[0]) sceneMin[0] = x;
  50116. if (i === 0 || x > sceneMax[0]) sceneMax[0] = x;
  50117. if (i === 0 || y < sceneMin[1]) sceneMin[1] = y;
  50118. if (i === 0 || y > sceneMax[1]) sceneMax[1] = y;
  50119. if (i === 0 || z < sceneMin[2]) sceneMin[2] = z;
  50120. if (i === 0 || z > sceneMax[2]) sceneMax[2] = z;
  50121. indexes.push(index);
  50122. }
  50123. var subTree = new WorkerSplatSubTree(maxDepth, maxCentersPerNode);
  50124. subTree.sceneMin = sceneMin;
  50125. subTree.sceneMax = sceneMax;
  50126. subTree.rootNode = new WorkerSplatTreeNode(subTree.sceneMin, subTree.sceneMax, 0);
  50127. subTree.rootNode.data = {
  50128. 'indexes': indexes
  50129. };
  50130. return subTree;
  50131. };
  50132. function createSplatTree(allCenters, maxDepth, maxCentersPerNode) {
  50133. var indexToCenter = [];
  50134. for (var sceneCenters of allCenters) {
  50135. var centerCount = Math.floor(sceneCenters.length / 4);
  50136. for (var i = 0; i < centerCount; i++) {
  50137. var base = i * 4;
  50138. var index = Math.round(sceneCenters[base + 3]);
  50139. indexToCenter[index] = base;
  50140. }
  50141. }
  50142. var subTrees = [];
  50143. for (var _sceneCenters of allCenters) {
  50144. var subTree = buildSubTree(_sceneCenters, maxDepth, maxCentersPerNode); //建立树
  50145. subTrees.push(subTree);
  50146. processSplatTreeNode(subTree, subTree.rootNode, indexToCenter, _sceneCenters); //开始分割
  50147. }
  50148. self.postMessage({
  50149. 'subTrees': subTrees
  50150. });
  50151. }
  50152. self.onmessage = e => {
  50153. if (e.data.process) {
  50154. createSplatTree(e.data.process.centers, e.data.process.maxDepth, e.data.process.maxCentersPerNode);
  50155. }
  50156. };
  50157. }
  50158. function workerProcessCenters(splatTreeWorker, centers, transferBuffers, maxDepth, maxCentersPerNode) {
  50159. splatTreeWorker.postMessage({
  50160. 'process': {
  50161. 'centers': centers,
  50162. 'maxDepth': maxDepth,
  50163. 'maxCentersPerNode': maxCentersPerNode
  50164. }
  50165. }, transferBuffers);
  50166. }
  50167. function checkAndCreateWorker() {
  50168. var splatTreeWorker = new Worker(URL.createObjectURL(new Blob(['(', createSplatTreeWorker.toString(), ')(self)'], {
  50169. type: 'application/javascript'
  50170. })));
  50171. return splatTreeWorker;
  50172. }
  50173. /**
  50174. * SplatTree: Octree tailored to splat data from a SplatMesh instance
  50175. */
  50176. class SplatTree {
  50177. constructor(maxDepth, maxCentersPerNode) {
  50178. /**
  50179. * Construct this instance of SplatTree from an instance of SplatMesh.
  50180. *
  50181. * @param {SplatMesh} splatMesh The instance of SplatMesh from which to construct this splat tree.
  50182. * @param {function} filterFunc Optional function to filter out unwanted splats.
  50183. * @param {function} onIndexesUpload Function to be called when the upload of splat centers to the splat tree
  50184. * builder worker starts and finishes.
  50185. * @param {function} onSplatTreeConstruction Function to be called when the conversion of the local splat tree from
  50186. * the format produced by the splat tree builder worker starts and ends.
  50187. * @return {undefined}
  50188. */
  50189. _defineProperty(this, "processSplatMesh", function (splatMesh) {
  50190. var filterFunc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : () => true;
  50191. var onIndexesUpload = arguments.length > 2 ? arguments[2] : undefined;
  50192. var onSplatTreeConstruction = arguments.length > 3 ? arguments[3] : undefined;
  50193. if (!this.splatTreeWorker) this.splatTreeWorker = checkAndCreateWorker();
  50194. this.splatMesh = splatMesh;
  50195. this.subTrees = [];
  50196. var center = new Vector3();
  50197. var addCentersForScene = (splatOffset, splatCount) => {
  50198. var sceneCenters = new Float32Array(splatCount * 4);
  50199. var addedCount = 0;
  50200. for (var i = 0; i < splatCount; i++) {
  50201. var globalSplatIndex = i + splatOffset;
  50202. if (filterFunc(globalSplatIndex)) {
  50203. splatMesh.getSplatCenter(globalSplatIndex, center);
  50204. var addBase = addedCount * 4;
  50205. sceneCenters[addBase] = center.x;
  50206. sceneCenters[addBase + 1] = center.y;
  50207. sceneCenters[addBase + 2] = center.z;
  50208. sceneCenters[addBase + 3] = globalSplatIndex;
  50209. addedCount++;
  50210. }
  50211. }
  50212. return sceneCenters;
  50213. };
  50214. return new Promise(resolve => {
  50215. var checkForEarlyExit = () => {
  50216. if (this.disposed) {
  50217. this.diposeSplatTreeWorker();
  50218. resolve();
  50219. return true;
  50220. }
  50221. return false;
  50222. };
  50223. if (onIndexesUpload) onIndexesUpload(false);
  50224. delayedExecute(() => {
  50225. if (checkForEarlyExit()) return;
  50226. var allCenters = [];
  50227. if (splatMesh.dynamicMode) {
  50228. var splatOffset = 0;
  50229. for (var s = 0; s < splatMesh.scenes.length; s++) {
  50230. var scene = splatMesh.getScene(s);
  50231. var splatCount = scene.splatBuffer.getSplatCount();
  50232. var sceneCenters = addCentersForScene(splatOffset, splatCount);
  50233. allCenters.push(sceneCenters);
  50234. splatOffset += splatCount;
  50235. }
  50236. } else {
  50237. var _sceneCenters2 = addCentersForScene(0, splatMesh.getSplatCount());
  50238. allCenters.push(_sceneCenters2);
  50239. }
  50240. this.splatTreeWorker.onmessage = e => {
  50241. if (checkForEarlyExit()) return;
  50242. if (e.data.subTrees) {
  50243. if (onSplatTreeConstruction) onSplatTreeConstruction(false);
  50244. delayedExecute(() => {
  50245. if (checkForEarlyExit()) return;
  50246. for (var workerSubTree of e.data.subTrees) {
  50247. var convertedSubTree = SplatSubTree.convertWorkerSubTree(workerSubTree, splatMesh);
  50248. this.subTrees.push(convertedSubTree);
  50249. }
  50250. this.diposeSplatTreeWorker();
  50251. if (onSplatTreeConstruction) onSplatTreeConstruction(true);
  50252. delayedExecute(() => {
  50253. resolve();
  50254. });
  50255. });
  50256. }
  50257. };
  50258. delayedExecute(() => {
  50259. if (checkForEarlyExit()) return;
  50260. if (onIndexesUpload) onIndexesUpload(true);
  50261. var transferBuffers = allCenters.map(array => array.buffer);
  50262. workerProcessCenters(this.splatTreeWorker, allCenters, transferBuffers, this.maxDepth, this.maxCentersPerNode);
  50263. });
  50264. });
  50265. });
  50266. });
  50267. this.maxDepth = maxDepth;
  50268. this.maxCentersPerNode = maxCentersPerNode;
  50269. this.subTrees = [];
  50270. this.splatMesh = null;
  50271. }
  50272. dispose() {
  50273. this.diposeSplatTreeWorker();
  50274. this.disposed = true;
  50275. }
  50276. diposeSplatTreeWorker() {
  50277. if (this.splatTreeWorker) this.splatTreeWorker.terminate();
  50278. this.splatTreeWorker = null;
  50279. }
  50280. countLeaves() {
  50281. var leafCount = 0;
  50282. this.visitLeaves(() => {
  50283. leafCount++;
  50284. });
  50285. return leafCount;
  50286. }
  50287. visitLeaves(visitFunc) {
  50288. //traverse
  50289. var visitLeavesFromNode = (node, visitFunc) => {
  50290. if (node.children.length === 0) visitFunc(node);
  50291. for (var child of node.children) {
  50292. visitLeavesFromNode(child, visitFunc);
  50293. }
  50294. };
  50295. for (var subTree of this.subTrees) {
  50296. visitLeavesFromNode(subTree.rootNode, visitFunc);
  50297. }
  50298. }
  50299. }
  50300. function WebGLExtensions$1(gl) {
  50301. var extensions = {};
  50302. function getExtension(name) {
  50303. if (extensions[name] !== undefined) {
  50304. return extensions[name];
  50305. }
  50306. var extension;
  50307. switch (name) {
  50308. case 'WEBGL_depth_texture':
  50309. extension = gl.getExtension('WEBGL_depth_texture') || gl.getExtension('MOZ_WEBGL_depth_texture') || gl.getExtension('WEBKIT_WEBGL_depth_texture');
  50310. break;
  50311. case 'EXT_texture_filter_anisotropic':
  50312. extension = gl.getExtension('EXT_texture_filter_anisotropic') || gl.getExtension('MOZ_EXT_texture_filter_anisotropic') || gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic');
  50313. break;
  50314. case 'WEBGL_compressed_texture_s3tc':
  50315. extension = gl.getExtension('WEBGL_compressed_texture_s3tc') || gl.getExtension('MOZ_WEBGL_compressed_texture_s3tc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_s3tc');
  50316. break;
  50317. case 'WEBGL_compressed_texture_pvrtc':
  50318. extension = gl.getExtension('WEBGL_compressed_texture_pvrtc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_pvrtc');
  50319. break;
  50320. default:
  50321. extension = gl.getExtension(name);
  50322. }
  50323. extensions[name] = extension;
  50324. return extension;
  50325. }
  50326. return {
  50327. has: function has(name) {
  50328. return getExtension(name) !== null;
  50329. },
  50330. init: function init(capabilities) {
  50331. if (capabilities.isWebGL2) {
  50332. getExtension('EXT_color_buffer_float');
  50333. getExtension('WEBGL_clip_cull_distance');
  50334. } else {
  50335. getExtension('WEBGL_depth_texture');
  50336. getExtension('OES_texture_float');
  50337. getExtension('OES_texture_half_float');
  50338. getExtension('OES_texture_half_float_linear');
  50339. getExtension('OES_standard_derivatives');
  50340. getExtension('OES_element_index_uint');
  50341. getExtension('OES_vertex_array_object');
  50342. getExtension('ANGLE_instanced_arrays');
  50343. }
  50344. getExtension('OES_texture_float_linear');
  50345. getExtension('EXT_color_buffer_half_float');
  50346. getExtension('WEBGL_multisampled_render_to_texture');
  50347. },
  50348. get: function get(name) {
  50349. var extension = getExtension(name);
  50350. if (extension === null) {
  50351. console.warn('THREE.WebGLRenderer: ' + name + ' extension not supported.');
  50352. }
  50353. return extension;
  50354. }
  50355. };
  50356. }
  50357. function WebGLCapabilities$1(gl, extensions, parameters) {
  50358. var maxAnisotropy;
  50359. function getMaxAnisotropy() {
  50360. if (maxAnisotropy !== undefined) return maxAnisotropy;
  50361. if (extensions.has('EXT_texture_filter_anisotropic') === true) {
  50362. var extension = extensions.get('EXT_texture_filter_anisotropic');
  50363. maxAnisotropy = gl.getParameter(extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT);
  50364. } else {
  50365. maxAnisotropy = 0;
  50366. }
  50367. return maxAnisotropy;
  50368. }
  50369. function getMaxPrecision(precision) {
  50370. if (precision === 'highp') {
  50371. if (gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.HIGH_FLOAT).precision > 0 && gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.HIGH_FLOAT).precision > 0) {
  50372. return 'highp';
  50373. }
  50374. precision = 'mediump';
  50375. }
  50376. if (precision === 'mediump') {
  50377. if (gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.MEDIUM_FLOAT).precision > 0 && gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT).precision > 0) {
  50378. return 'mediump';
  50379. }
  50380. }
  50381. return 'lowp';
  50382. }
  50383. var isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl.constructor.name === 'WebGL2RenderingContext';
  50384. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  50385. var maxPrecision = getMaxPrecision(precision);
  50386. if (maxPrecision !== precision) {
  50387. console.warn('THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.');
  50388. precision = maxPrecision;
  50389. }
  50390. var drawBuffers = isWebGL2 || extensions.has('WEBGL_draw_buffers');
  50391. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  50392. var maxTextures = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS);
  50393. var maxVertexTextures = gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS);
  50394. var maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE);
  50395. var maxCubemapSize = gl.getParameter(gl.MAX_CUBE_MAP_TEXTURE_SIZE);
  50396. var maxAttributes = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
  50397. var maxVertexUniforms = gl.getParameter(gl.MAX_VERTEX_UNIFORM_VECTORS);
  50398. var maxVaryings = gl.getParameter(gl.MAX_VARYING_VECTORS);
  50399. var maxFragmentUniforms = gl.getParameter(gl.MAX_FRAGMENT_UNIFORM_VECTORS);
  50400. var vertexTextures = maxVertexTextures > 0;
  50401. var floatFragmentTextures = isWebGL2 || extensions.has('OES_texture_float');
  50402. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  50403. var maxSamples = isWebGL2 ? gl.getParameter(gl.MAX_SAMPLES) : 0;
  50404. return {
  50405. isWebGL2: isWebGL2,
  50406. drawBuffers: drawBuffers,
  50407. getMaxAnisotropy: getMaxAnisotropy,
  50408. getMaxPrecision: getMaxPrecision,
  50409. precision: precision,
  50410. logarithmicDepthBuffer: logarithmicDepthBuffer,
  50411. maxTextures: maxTextures,
  50412. maxVertexTextures: maxVertexTextures,
  50413. maxTextureSize: maxTextureSize,
  50414. maxCubemapSize: maxCubemapSize,
  50415. maxAttributes: maxAttributes,
  50416. maxVertexUniforms: maxVertexUniforms,
  50417. maxVaryings: maxVaryings,
  50418. maxFragmentUniforms: maxFragmentUniforms,
  50419. vertexTextures: vertexTextures,
  50420. floatFragmentTextures: floatFragmentTextures,
  50421. floatVertexTextures: floatVertexTextures,
  50422. maxSamples: maxSamples
  50423. };
  50424. }
  50425. var SceneRevealMode = {
  50426. Default: 0,
  50427. Gradual: 1,
  50428. Instant: 2
  50429. };
  50430. var LogLevel = {
  50431. None: 0,
  50432. Error: 1,
  50433. Warning: 2,
  50434. Info: 3,
  50435. Debug: 4
  50436. };
  50437. var dummyGeometry = new BufferGeometry();
  50438. var dummyMaterial = new MeshBasicMaterial();
  50439. var COVARIANCES_ELEMENTS_PER_SPLAT = 6;
  50440. var CENTER_COLORS_ELEMENTS_PER_SPLAT = 4;
  50441. var COVARIANCES_ELEMENTS_PER_TEXEL = 4;
  50442. var CENTER_COLORS_ELEMENTS_PER_TEXEL = 4;
  50443. var TRANSFORM_INDEXES_ELEMENTS_PER_TEXEL = 1;
  50444. var SCENE_FADEIN_RATE_FAST = 0.012;
  50445. var SCENE_FADEIN_RATE_GRADUAL = 0.003;
  50446. var VISIBLE_REGION_EXPANSION_DELTA = 1;
  50447. /**
  50448. * SplatMesh: Container for one or more splat scenes, abstracting them into a single unified container for
  50449. * splat data. Additionally contains data structures and code to make the splat data renderable as a Three.js mesh.
  50450. */
  50451. class SplatMesh extends Mesh {
  50452. constructor() {
  50453. var dynamicMode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  50454. var halfPrecisionCovariancesOnGPU = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  50455. var devicePixelRatio = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
  50456. var enableDistancesComputationOnGPU = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
  50457. var integerBasedDistancesComputation = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
  50458. var antialiased = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
  50459. var maxScreenSpaceSplatSize = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 2048;
  50460. var logLevel = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : LogLevel.None;
  50461. var sphericalHarmonicsDegree = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : 0;
  50462. super(dummyGeometry, dummyMaterial);
  50463. // Reference to a Three.js renderer
  50464. /**
  50465. * Build an instance of SplatTree (a specialized octree) for the given splat mesh.
  50466. * @param {Array<number>} minAlphas Array of minimum splat slphas for each scene
  50467. * @param {function} onSplatTreeIndexesUpload Function to be called when the upload of splat centers to the splat tree
  50468. * builder worker starts and finishes.
  50469. * @param {function} onSplatTreeConstruction Function to be called when the conversion of the local splat tree from
  50470. * the format produced by the splat tree builder worker starts and ends.
  50471. * @return {SplatTree}
  50472. */
  50473. _defineProperty(this, "buildSplatTree", function () {
  50474. var minAlphas = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  50475. var onSplatTreeIndexesUpload = arguments.length > 1 ? arguments[1] : undefined;
  50476. var onSplatTreeConstruction = arguments.length > 2 ? arguments[2] : undefined;
  50477. return new Promise(resolve => {
  50478. this.disposeSplatTree();
  50479. // TODO: expose SplatTree constructor parameters (maximumDepth and maxCentersPerNode) so that they can
  50480. // be configured on a per-scene basis
  50481. this.baseSplatTree = new SplatTree(8, 1000);
  50482. var buildStartTime = performance.now();
  50483. var splatColor = new Vector4();
  50484. this.baseSplatTree.processSplatMesh(this, splatIndex => {
  50485. this.getSplatColor(splatIndex, splatColor);
  50486. var sceneIndex = this.getSceneIndexForSplat(splatIndex);
  50487. var minAlpha = minAlphas[sceneIndex] || 1;
  50488. return splatColor.w >= minAlpha;
  50489. }, onSplatTreeIndexesUpload, onSplatTreeConstruction).then(() => {
  50490. var buildTime = performance.now() - buildStartTime;
  50491. if (this.logLevel >= LogLevel.Info) console.log('SplatTree build: ' + buildTime + ' ms');
  50492. if (this.disposed) {
  50493. resolve();
  50494. } else {
  50495. this.splatTree = this.baseSplatTree;
  50496. this.baseSplatTree = null;
  50497. var leavesWithVertices = 0;
  50498. var avgSplatCount = 0;
  50499. var maxSplatCount = 0;
  50500. var nodeCount = 0;
  50501. this.splatTree.visitLeaves(node => {
  50502. var nodeSplatCount = node.data.indexes.length;
  50503. if (nodeSplatCount > 0) {
  50504. avgSplatCount += nodeSplatCount;
  50505. maxSplatCount = Math.max(maxSplatCount, nodeSplatCount);
  50506. nodeCount++;
  50507. leavesWithVertices++;
  50508. }
  50509. });
  50510. if (this.logLevel >= LogLevel.Info) {
  50511. console.log("SplatTree leaves: ".concat(this.splatTree.countLeaves()));
  50512. console.log("SplatTree leaves with splats:".concat(leavesWithVertices));
  50513. avgSplatCount = avgSplatCount / nodeCount;
  50514. console.log("Avg splat count per node: ".concat(avgSplatCount));
  50515. console.log("Total splat count: ".concat(this.getSplatCount()));
  50516. }
  50517. resolve();
  50518. }
  50519. });
  50520. });
  50521. });
  50522. _defineProperty(this, "updateUniforms", function () {
  50523. var viewport = new Vector2();
  50524. return function (renderDimensions, cameraFocalLengthX, cameraFocalLengthY, orthographicMode, orthographicZoom, inverseFocalAdjustment) {
  50525. var splatCount = this.getSplatCount();
  50526. if (splatCount > 0) {
  50527. viewport.set(renderDimensions.x * this.devicePixelRatio, renderDimensions.y * this.devicePixelRatio);
  50528. this.material.uniforms.viewport.value.copy(viewport);
  50529. this.material.uniforms.basisViewport.value.set(1.0 / viewport.x, 1.0 / viewport.y);
  50530. this.material.uniforms.focal.value.set(cameraFocalLengthX, cameraFocalLengthY);
  50531. this.material.uniforms.orthographicMode.value = orthographicMode ? 1 : 0;
  50532. this.material.uniforms.orthoZoom.value = orthographicZoom;
  50533. this.material.uniforms.inverseFocalAdjustment.value = inverseFocalAdjustment;
  50534. if (this.dynamicMode) {
  50535. for (var i = 0; i < this.scenes.length; i++) {
  50536. this.material.uniforms.transforms.value[i].copy(this.getScene(i).transform);
  50537. }
  50538. }
  50539. this.material.uniformsNeedUpdate = true;
  50540. }
  50541. };
  50542. }());
  50543. _defineProperty(this, "setupDistancesComputationTransformFeedback", function () {
  50544. var currentMaxSplatCount;
  50545. return function () {
  50546. var maxSplatCount = this.getMaxSplatCount();
  50547. if (!this.renderer) return;
  50548. var rebuildGPUObjects = this.lastRenderer !== this.renderer;
  50549. var rebuildBuffers = currentMaxSplatCount !== maxSplatCount;
  50550. if (!rebuildGPUObjects && !rebuildBuffers) return;
  50551. if (rebuildGPUObjects) {
  50552. this.disposeDistancesComputationGPUResources();
  50553. } else if (rebuildBuffers) {
  50554. this.disposeDistancesComputationGPUBufferResources();
  50555. }
  50556. var gl = this.renderer.getContext();
  50557. var createShader = (gl, type, source) => {
  50558. var shader = gl.createShader(type);
  50559. if (!shader) {
  50560. console.error('Fatal error: gl could not create a shader object.');
  50561. return null;
  50562. }
  50563. gl.shaderSource(shader, source);
  50564. gl.compileShader(shader);
  50565. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  50566. if (!compiled) {
  50567. var typeName = 'unknown';
  50568. if (type === gl.VERTEX_SHADER) typeName = 'vertex shader';else if (type === gl.FRAGMENT_SHADER) typeName = 'fragement shader';
  50569. var errors = gl.getShaderInfoLog(shader);
  50570. console.error('Failed to compile ' + typeName + ' with these errors:' + errors);
  50571. gl.deleteShader(shader);
  50572. return null;
  50573. }
  50574. return shader;
  50575. };
  50576. var vsSource;
  50577. if (this.integerBasedDistancesComputation) {
  50578. vsSource = "#version 300 es\n in ivec4 center;\n flat out int distance;";
  50579. if (this.dynamicMode) {
  50580. vsSource += "\n in uint transformIndex;\n uniform ivec4 transforms[".concat(Constants.MaxScenes, "];\n void main(void) {\n ivec4 transform = transforms[transformIndex];\n distance = center.x * transform.x + center.y * transform.y + center.z * transform.z + transform.w * center.w;\n }\n ");
  50581. } else {
  50582. vsSource += "\n uniform ivec3 modelViewProj;\n void main(void) {\n distance = center.x * modelViewProj.x + center.y * modelViewProj.y + center.z * modelViewProj.z;\n }\n ";
  50583. }
  50584. } else {
  50585. vsSource = "#version 300 es\n in vec4 center;\n flat out float distance;";
  50586. if (this.dynamicMode) {
  50587. vsSource += "\n in uint transformIndex;\n uniform mat4 transforms[".concat(Constants.MaxScenes, "];\n void main(void) {\n vec4 transformedCenter = transforms[transformIndex] * vec4(center.xyz, 1.0);\n distance = transformedCenter.z;\n }\n ");
  50588. } else {
  50589. vsSource += "\n uniform vec3 modelViewProj;\n void main(void) {\n distance = center.x * modelViewProj.x + center.y * modelViewProj.y + center.z * modelViewProj.z;\n }\n ";
  50590. }
  50591. }
  50592. var fsSource = "#version 300 es\n precision lowp float;\n out vec4 fragColor;\n void main(){}\n ";
  50593. var currentVao = gl.getParameter(gl.VERTEX_ARRAY_BINDING);
  50594. var currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
  50595. var currentProgramDeleted = currentProgram ? gl.getProgramParameter(currentProgram, gl.DELETE_STATUS) : false;
  50596. if (rebuildGPUObjects) {
  50597. this.distancesTransformFeedback.vao = gl.createVertexArray();
  50598. }
  50599. gl.bindVertexArray(this.distancesTransformFeedback.vao);
  50600. if (rebuildGPUObjects) {
  50601. var program = gl.createProgram();
  50602. var vertexShader = createShader(gl, gl.VERTEX_SHADER, vsSource);
  50603. var fragmentShader = createShader(gl, gl.FRAGMENT_SHADER, fsSource);
  50604. if (!vertexShader || !fragmentShader) {
  50605. throw new Error('Could not compile shaders for distances computation on GPU.');
  50606. }
  50607. gl.attachShader(program, vertexShader);
  50608. gl.attachShader(program, fragmentShader);
  50609. gl.transformFeedbackVaryings(program, ['distance'], gl.SEPARATE_ATTRIBS);
  50610. gl.linkProgram(program);
  50611. var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  50612. if (!linked) {
  50613. var error = gl.getProgramInfoLog(program);
  50614. console.error('Fatal error: Failed to link program: ' + error);
  50615. gl.deleteProgram(program);
  50616. gl.deleteShader(fragmentShader);
  50617. gl.deleteShader(vertexShader);
  50618. throw new Error('Could not link shaders for distances computation on GPU.');
  50619. }
  50620. this.distancesTransformFeedback.program = program;
  50621. this.distancesTransformFeedback.vertexShader = vertexShader;
  50622. this.distancesTransformFeedback.vertexShader = fragmentShader;
  50623. }
  50624. gl.useProgram(this.distancesTransformFeedback.program);
  50625. this.distancesTransformFeedback.centersLoc = gl.getAttribLocation(this.distancesTransformFeedback.program, 'center');
  50626. if (this.dynamicMode) {
  50627. this.distancesTransformFeedback.transformIndexesLoc = gl.getAttribLocation(this.distancesTransformFeedback.program, 'transformIndex');
  50628. for (var i = 0; i < this.scenes.length; i++) {
  50629. this.distancesTransformFeedback.transformsLocs[i] = gl.getUniformLocation(this.distancesTransformFeedback.program, "transforms[".concat(i, "]"));
  50630. }
  50631. } else {
  50632. this.distancesTransformFeedback.modelViewProjLoc = gl.getUniformLocation(this.distancesTransformFeedback.program, 'modelViewProj');
  50633. }
  50634. if (rebuildGPUObjects || rebuildBuffers) {
  50635. this.distancesTransformFeedback.centersBuffer = gl.createBuffer();
  50636. gl.bindBuffer(gl.ARRAY_BUFFER, this.distancesTransformFeedback.centersBuffer);
  50637. gl.enableVertexAttribArray(this.distancesTransformFeedback.centersLoc);
  50638. if (this.integerBasedDistancesComputation) {
  50639. gl.vertexAttribIPointer(this.distancesTransformFeedback.centersLoc, 4, gl.INT, 0, 0);
  50640. } else {
  50641. gl.vertexAttribPointer(this.distancesTransformFeedback.centersLoc, 4, gl.FLOAT, false, 0, 0);
  50642. }
  50643. if (this.dynamicMode) {
  50644. this.distancesTransformFeedback.transformIndexesBuffer = gl.createBuffer();
  50645. gl.bindBuffer(gl.ARRAY_BUFFER, this.distancesTransformFeedback.transformIndexesBuffer);
  50646. gl.enableVertexAttribArray(this.distancesTransformFeedback.transformIndexesLoc);
  50647. gl.vertexAttribIPointer(this.distancesTransformFeedback.transformIndexesLoc, 1, gl.UNSIGNED_INT, 0, 0);
  50648. }
  50649. }
  50650. if (rebuildGPUObjects || rebuildBuffers) {
  50651. this.distancesTransformFeedback.outDistancesBuffer = gl.createBuffer();
  50652. }
  50653. gl.bindBuffer(gl.ARRAY_BUFFER, this.distancesTransformFeedback.outDistancesBuffer);
  50654. gl.bufferData(gl.ARRAY_BUFFER, maxSplatCount * 4, gl.STATIC_READ);
  50655. if (rebuildGPUObjects) {
  50656. this.distancesTransformFeedback.id = gl.createTransformFeedback();
  50657. }
  50658. gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, this.distancesTransformFeedback.id);
  50659. gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, 0, this.distancesTransformFeedback.outDistancesBuffer);
  50660. if (currentProgram && currentProgramDeleted !== true) gl.useProgram(currentProgram);
  50661. if (currentVao) gl.bindVertexArray(currentVao);
  50662. this.lastRenderer = this.renderer;
  50663. currentMaxSplatCount = maxSplatCount;
  50664. };
  50665. }());
  50666. /**
  50667. * Fill 'array' with the transforms for each scene in this splat mesh.
  50668. * @param {Array} array Empty array to be filled with scene transforms. If not empty, contents will be overwritten.
  50669. */
  50670. _defineProperty(this, "fillTransformsArray", function () {
  50671. var tempArray = [];
  50672. return function (array) {
  50673. if (tempArray.length !== array.length) tempArray.length = array.length;
  50674. for (var i = 0; i < this.scenes.length; i++) {
  50675. var sceneTransform = this.getScene(i).transform;
  50676. var sceneTransformElements = sceneTransform.elements;
  50677. for (var j = 0; j < 16; j++) {
  50678. tempArray[i * 16 + j] = sceneTransformElements[j];
  50679. }
  50680. }
  50681. array.set(tempArray);
  50682. };
  50683. }());
  50684. _defineProperty(this, "computeDistancesOnGPU", function () {
  50685. var tempMatrix = new Matrix4();
  50686. return function (modelViewProjMatrix, outComputedDistances) {
  50687. if (!this.renderer) return;
  50688. // console.time("gpu_compute_distances");
  50689. var gl = this.renderer.getContext();
  50690. var currentVao = gl.getParameter(gl.VERTEX_ARRAY_BINDING);
  50691. var currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
  50692. var currentProgramDeleted = currentProgram ? gl.getProgramParameter(currentProgram, gl.DELETE_STATUS) : false;
  50693. gl.bindVertexArray(this.distancesTransformFeedback.vao);
  50694. gl.useProgram(this.distancesTransformFeedback.program);
  50695. gl.enable(gl.RASTERIZER_DISCARD);
  50696. if (this.dynamicMode) {
  50697. for (var i = 0; i < this.scenes.length; i++) {
  50698. tempMatrix.copy(this.getScene(i).transform);
  50699. tempMatrix.premultiply(modelViewProjMatrix);
  50700. if (this.integerBasedDistancesComputation) {
  50701. var iTempMatrix = SplatMesh.getIntegerMatrixArray(tempMatrix);
  50702. var iTransform = [iTempMatrix[2], iTempMatrix[6], iTempMatrix[10], iTempMatrix[14]];
  50703. gl.uniform4i(this.distancesTransformFeedback.transformsLocs[i], iTransform[0], iTransform[1], iTransform[2], iTransform[3]);
  50704. } else {
  50705. gl.uniformMatrix4fv(this.distancesTransformFeedback.transformsLocs[i], false, tempMatrix.elements);
  50706. }
  50707. }
  50708. } else {
  50709. if (this.integerBasedDistancesComputation) {
  50710. var iViewProjMatrix = SplatMesh.getIntegerMatrixArray(modelViewProjMatrix);
  50711. var iViewProj = [iViewProjMatrix[2], iViewProjMatrix[6], iViewProjMatrix[10]];
  50712. gl.uniform3i(this.distancesTransformFeedback.modelViewProjLoc, iViewProj[0], iViewProj[1], iViewProj[2]);
  50713. } else {
  50714. var viewProj = [modelViewProjMatrix.elements[2], modelViewProjMatrix.elements[6], modelViewProjMatrix.elements[10]];
  50715. gl.uniform3f(this.distancesTransformFeedback.modelViewProjLoc, viewProj[0], viewProj[1], viewProj[2]);
  50716. }
  50717. }
  50718. gl.bindBuffer(gl.ARRAY_BUFFER, this.distancesTransformFeedback.centersBuffer);
  50719. gl.enableVertexAttribArray(this.distancesTransformFeedback.centersLoc);
  50720. if (this.integerBasedDistancesComputation) {
  50721. gl.vertexAttribIPointer(this.distancesTransformFeedback.centersLoc, 4, gl.INT, 0, 0);
  50722. } else {
  50723. gl.vertexAttribPointer(this.distancesTransformFeedback.centersLoc, 4, gl.FLOAT, false, 0, 0);
  50724. }
  50725. if (this.dynamicMode) {
  50726. gl.bindBuffer(gl.ARRAY_BUFFER, this.distancesTransformFeedback.transformIndexesBuffer);
  50727. gl.enableVertexAttribArray(this.distancesTransformFeedback.transformIndexesLoc);
  50728. gl.vertexAttribIPointer(this.distancesTransformFeedback.transformIndexesLoc, 1, gl.UNSIGNED_INT, 0, 0);
  50729. }
  50730. gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, this.distancesTransformFeedback.id);
  50731. gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, 0, this.distancesTransformFeedback.outDistancesBuffer);
  50732. gl.beginTransformFeedback(gl.POINTS);
  50733. gl.drawArrays(gl.POINTS, 0, this.getSplatCount());
  50734. gl.endTransformFeedback();
  50735. gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, 0, null);
  50736. gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, null);
  50737. gl.disable(gl.RASTERIZER_DISCARD);
  50738. var sync = gl.fenceSync(gl.SYNC_GPU_COMMANDS_COMPLETE, 0);
  50739. gl.flush();
  50740. var promise = new Promise(resolve => {
  50741. var checkSync = () => {
  50742. if (this.disposed) {
  50743. resolve();
  50744. } else {
  50745. var timeout = 0;
  50746. var bitflags = 0;
  50747. var status = gl.clientWaitSync(sync, bitflags, timeout);
  50748. switch (status) {
  50749. case gl.TIMEOUT_EXPIRED:
  50750. this.computeDistancesOnGPUSyncTimeout = setTimeout(checkSync);
  50751. return this.computeDistancesOnGPUSyncTimeout;
  50752. case gl.WAIT_FAILED:
  50753. throw new Error('should never get here');
  50754. default:
  50755. this.computeDistancesOnGPUSyncTimeout = null;
  50756. gl.deleteSync(sync);
  50757. var _currentVao = gl.getParameter(gl.VERTEX_ARRAY_BINDING);
  50758. gl.bindVertexArray(this.distancesTransformFeedback.vao);
  50759. gl.bindBuffer(gl.ARRAY_BUFFER, this.distancesTransformFeedback.outDistancesBuffer);
  50760. gl.getBufferSubData(gl.ARRAY_BUFFER, 0, outComputedDistances);
  50761. gl.bindBuffer(gl.ARRAY_BUFFER, null);
  50762. if (_currentVao) gl.bindVertexArray(_currentVao);
  50763. // console.timeEnd("gpu_compute_distances");
  50764. resolve();
  50765. }
  50766. }
  50767. };
  50768. this.computeDistancesOnGPUSyncTimeout = setTimeout(checkSync);
  50769. });
  50770. if (currentProgram && currentProgramDeleted !== true) gl.useProgram(currentProgram);
  50771. if (currentVao) gl.bindVertexArray(currentVao);
  50772. return promise;
  50773. };
  50774. }());
  50775. /**
  50776. * Get the center for a splat, transformed as appropriate.
  50777. * @param {number} globalIndex Global index of splat
  50778. * @param {THREE.Vector3} outCenter THREE.Vector3 instance in which to store splat center
  50779. * @param {boolean} applySceneTransform By default, if the splat mesh is static, the transform of the scene to which the splat at
  50780. * 'globalIndex' belongs will be applied to the splat center. If 'applySceneTransform' is true,
  50781. * the scene transform will always be applied and if 'applySceneTransform' is false, the
  50782. * scene transform will never be applied. If undefined, the default behavior will apply.
  50783. */
  50784. _defineProperty(this, "getSplatCenter", function () {
  50785. var paramsObj = {};
  50786. return function (globalIndex, outCenter, applySceneTransform) {
  50787. this.getLocalSplatParameters(globalIndex, paramsObj, applySceneTransform);
  50788. paramsObj.splatBuffer.getSplatCenter(paramsObj.localIndex, outCenter, paramsObj.sceneTransform);
  50789. };
  50790. }());
  50791. /**
  50792. * Get the scale and rotation for a splat, transformed as appropriate.
  50793. * @param {number} globalIndex Global index of splat
  50794. * @param {THREE.Vector3} outScale THREE.Vector3 instance in which to store splat scale
  50795. * @param {THREE.Quaternion} outRotation THREE.Quaternion instance in which to store splat rotation
  50796. * @param {boolean} applySceneTransform By default, if the splat mesh is static, the transform of the scene to which the splat at
  50797. * 'globalIndex' belongs will be applied to the splat scale and rotation. If
  50798. * 'applySceneTransform' is true, the scene transform will always be applied and if
  50799. * 'applySceneTransform' is false, the scene transform will never be applied. If undefined,
  50800. * the default behavior will apply.
  50801. */
  50802. _defineProperty(this, "getSplatScaleAndRotation", function () {
  50803. var paramsObj = {};
  50804. return function (globalIndex, outScale, outRotation, applySceneTransform) {
  50805. this.getLocalSplatParameters(globalIndex, paramsObj, applySceneTransform);
  50806. paramsObj.splatBuffer.getSplatScaleAndRotation(paramsObj.localIndex, outScale, outRotation, paramsObj.sceneTransform);
  50807. };
  50808. }());
  50809. /**
  50810. * Get the color for a splat.
  50811. * @param {number} globalIndex Global index of splat
  50812. * @param {THREE.Vector4} outColor THREE.Vector4 instance in which to store splat color
  50813. */
  50814. _defineProperty(this, "getSplatColor", function () {
  50815. var paramsObj = {};
  50816. return function (globalIndex, outColor) {
  50817. this.getLocalSplatParameters(globalIndex, paramsObj);
  50818. paramsObj.splatBuffer.getSplatColor(paramsObj.localIndex, outColor);
  50819. };
  50820. }());
  50821. this.renderer = undefined;
  50822. // Use 16-bit floating point values when storing splat covariance data in textures, instead of 32-bit
  50823. this.halfPrecisionCovariancesOnGPU = halfPrecisionCovariancesOnGPU;
  50824. // When 'dynamicMode' is true, scenes are assumed to be non-static. Dynamic scenes are handled differently
  50825. // and certain optimizations cannot be made for them. Additionally, by default, all splat data retrieved from
  50826. // this splat mesh will not have their scene transform applied to them if the splat mesh is dynamic. That
  50827. // can be overriden via parameters to the individual functions that are used to retrieve splat data.
  50828. this.dynamicMode = dynamicMode;
  50829. // Ratio of the resolution in physical pixels to the resolution in CSS pixels for the current display device
  50830. this.devicePixelRatio = devicePixelRatio;
  50831. // Use a transform feedback to calculate splat distances from the camera
  50832. this.enableDistancesComputationOnGPU = enableDistancesComputationOnGPU;
  50833. // Use a faster integer-based approach for calculating splat distances from the camera
  50834. this.integerBasedDistancesComputation = integerBasedDistancesComputation;
  50835. // When true, will perform additional steps during rendering to address artifacts caused by the rendering of gaussians at a
  50836. // substantially different resolution than that at which they were rendered during training. This will only work correctly
  50837. // for models that were trained using a process that utilizes this compensation calculation. For more details:
  50838. // https://github.com/nerfstudio-project/gsplat/pull/117
  50839. // https://github.com/graphdeco-inria/gaussian-splatting/issues/294#issuecomment-1772688093
  50840. this.antialiased = antialiased;
  50841. // Specify the maximum clip space splat size, can help deal with large splats that get too unwieldy
  50842. this.maxScreenSpaceSplatSize = maxScreenSpaceSplatSize;
  50843. // The verbosity of console logging
  50844. this.logLevel = logLevel;
  50845. // Degree 0 means no spherical harmonics
  50846. this.sphericalHarmonicsDegree = sphericalHarmonicsDegree;
  50847. this.minSphericalHarmonicsDegree = 0;
  50848. // The individual splat scenes stored in this splat mesh, each containing their own transform
  50849. this.scenes = [];
  50850. // Special octree tailored to SplatMesh instances
  50851. this.splatTree = null;
  50852. this.baseSplatTree = null;
  50853. // Textures in which splat data will be stored for rendering
  50854. this.splatDataTextures = {};
  50855. this.distancesTransformFeedback = {
  50856. 'id': null,
  50857. 'vertexShader': null,
  50858. 'fragmentShader': null,
  50859. 'program': null,
  50860. 'centersBuffer': null,
  50861. 'transformIndexesBuffer': null,
  50862. 'outDistancesBuffer': null,
  50863. 'centersLoc': -1,
  50864. 'modelViewProjLoc': -1,
  50865. 'transformIndexesLoc': -1,
  50866. 'transformsLocs': []
  50867. };
  50868. this.globalSplatIndexToLocalSplatIndexMap = [];
  50869. this.globalSplatIndexToSceneIndexMap = [];
  50870. this.lastBuildSplatCount = 0;
  50871. this.lastBuildScenes = [];
  50872. this.lastBuildMaxSplatCount = 0;
  50873. this.lastBuildSceneCount = 0;
  50874. this.firstRenderTime = -1;
  50875. this.finalBuild = false;
  50876. this.webGLUtils = null;
  50877. this.boundingBox = new Box3();
  50878. this.calculatedSceneCenter = new Vector3();
  50879. this.maxSplatDistanceFromSceneCenter = 0;
  50880. this.visibleRegionBufferRadius = 0;
  50881. this.visibleRegionRadius = 0;
  50882. this.visibleRegionFadeStartRadius = 0;
  50883. this.visibleRegionChanging = false;
  50884. this.splatScale = 1.0;
  50885. this.pointCloudModeEnabled = false;
  50886. this.disposed = false;
  50887. this.lastRenderer = null;
  50888. this.visible = false;
  50889. }
  50890. /**
  50891. * Build the Three.js material that is used to render the splats.
  50892. * @param {number} dynamicMode If true, it means the scene geometry represented by this splat mesh is not stationary or
  50893. * that the splat count might change
  50894. * @param {boolean} antialiased If true, calculate compensation factor to deal with gaussians being rendered at a significantly
  50895. * different resolution than that of their training
  50896. * @param {number} maxScreenSpaceSplatSize The maximum clip space splat size
  50897. * @param {number} splatScale Value by which all splats are scaled in screen-space (default is 1.0)
  50898. * @param {number} pointCloudModeEnabled Render all splats as screen-space circles
  50899. * @param {number} maxSphericalHarmonicsDegree Degree of spherical harmonics to utilize in rendering splats
  50900. * @return {THREE.ShaderMaterial}
  50901. */
  50902. static buildMaterial() {
  50903. var dynamicMode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  50904. var antialiased = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  50905. var maxScreenSpaceSplatSize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2048;
  50906. var splatScale = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1.0;
  50907. var pointCloudModeEnabled = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
  50908. var maxSphericalHarmonicsDegree = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
  50909. // Contains the code to project 3D covariance to 2D and from there calculate the quad (using the eigen vectors of the
  50910. // 2D covariance) that is ultimately rasterized
  50911. var vertexShaderSource = "\n precision highp float;\n #include <common>\n\n attribute uint splatIndex;\n\n uniform highp sampler2D covariancesTexture;\n uniform highp usampler2D centersColorsTexture;\n uniform highp sampler2D sphericalHarmonicsTexture;";
  50912. if (dynamicMode) {
  50913. vertexShaderSource += "\n uniform highp usampler2D transformIndexesTexture;\n uniform highp mat4 transforms[".concat(Constants.MaxScenes, "];\n uniform vec2 transformIndexesTextureSize;\n ");
  50914. }
  50915. vertexShaderSource += "\n uniform vec2 focal;\n uniform float orthoZoom;\n uniform int orthographicMode;\n uniform int pointCloudModeEnabled;\n uniform float inverseFocalAdjustment;\n uniform vec2 viewport;\n uniform vec2 basisViewport;\n uniform vec2 covariancesTextureSize;\n uniform vec2 centersColorsTextureSize;\n uniform int sphericalHarmonicsDegree;\n uniform vec2 sphericalHarmonicsTextureSize;\n uniform int sphericalHarmonics8BitMode;\n uniform float visibleRegionRadius;\n uniform float visibleRegionFadeStartRadius;\n uniform float firstRenderTime;\n uniform float currentTime;\n uniform int fadeInComplete;\n uniform vec3 sceneCenter;\n uniform float splatScale;\n\n varying vec4 vColor;\n varying vec2 vUv;\n\n varying vec2 vPosition;\n\n const float sqrt8 = sqrt(8.0);\n const float minAlpha = 1.0 / 255.0;\n\n const vec4 encodeNorm4 = vec4(1.0 / 255.0, 1.0 / 255.0, 1.0 / 255.0, 1.0 / 255.0);\n const uvec4 mask4 = uvec4(uint(0x000000FF), uint(0x0000FF00), uint(0x00FF0000), uint(0xFF000000));\n const uvec4 shift4 = uvec4(0, 8, 16, 24);\n vec4 uintToRGBAVec (uint u) {\n uvec4 urgba = mask4 & u;\n urgba = urgba >> shift4;\n vec4 rgba = vec4(urgba) * encodeNorm4;\n return rgba;\n }\n\n vec2 getDataUV(in int stride, in int offset, in vec2 dimensions) {\n vec2 samplerUV = vec2(0.0, 0.0);\n float d = float(splatIndex * uint(stride) + uint(offset)) / dimensions.x;\n samplerUV.y = float(floor(d)) / dimensions.y;\n samplerUV.x = fract(d);\n return samplerUV;\n }\n\n vec2 getDataUVF(in uint sIndex, in float stride, in uint offset, in vec2 dimensions) {\n vec2 samplerUV = vec2(0.0, 0.0);\n float d = float(uint(float(sIndex) * stride) + offset) / dimensions.x;\n samplerUV.y = float(floor(d)) / dimensions.y;\n samplerUV.x = fract(d);\n return samplerUV;\n }\n\n const float SH_C1 = 0.4886025119029199f;\n const float[5] SH_C2 = float[](1.0925484, -1.0925484, 0.3153916, -1.0925484, 0.5462742);\n const vec3 vecOnes3 = vec3(1.0, 1.0, 1.0);\n\n void main () {\n\n uint oddOffset = splatIndex & uint(0x00000001);\n uint doubleOddOffset = oddOffset * uint(2);\n bool isEven = oddOffset == uint(0);\n uint nearestEvenIndex = splatIndex - oddOffset;\n float fOddOffset = float(oddOffset);\n\n uvec4 sampledCenterColor = texture(centersColorsTexture, getDataUV(1, 0, centersColorsTextureSize));\n vec3 splatCenter = uintBitsToFloat(uvec3(sampledCenterColor.gba));";
  50916. if (dynamicMode) {
  50917. vertexShaderSource += "\n uint transformIndex = texture(transformIndexesTexture, getDataUV(1, 0, transformIndexesTextureSize)).r;\n mat4 transform = transforms[transformIndex];\n mat4 transformModelViewMatrix = modelViewMatrix * transform;\n ";
  50918. } else {
  50919. vertexShaderSource += "mat4 transformModelViewMatrix = modelViewMatrix;";
  50920. }
  50921. vertexShaderSource += "\n vec4 viewCenter = transformModelViewMatrix * vec4(splatCenter, 1.0);\n\n vec4 clipCenter = projectionMatrix * viewCenter;\n\n float clip = 1.2 * clipCenter.w;\n if (clipCenter.z < -clip || clipCenter.x < -clip || clipCenter.x > clip || clipCenter.y < -clip || clipCenter.y > clip) {\n gl_Position = vec4(0.0, 0.0, 2.0, 1.0);\n return;\n }\n\n vPosition = position.xy;\n vColor = uintToRGBAVec(sampledCenterColor.r);\n\n ";
  50922. if (maxSphericalHarmonicsDegree >= 1) {
  50923. vertexShaderSource += " \n if (sphericalHarmonicsDegree >= 1) {\n ";
  50924. if (dynamicMode) {
  50925. vertexShaderSource += "\n mat4 mTransform = modelMatrix * transform;\n vec3 worldViewDir = normalize(splatCenter - vec3(inverse(mTransform) * vec4(cameraPosition, 1.0)));\n ";
  50926. } else {
  50927. vertexShaderSource += "\n vec3 worldViewDir = normalize(splatCenter - cameraPosition);\n ";
  50928. }
  50929. if (maxSphericalHarmonicsDegree >= 2) {
  50930. vertexShaderSource += "\n vec4 sampledSH0123 = texture(sphericalHarmonicsTexture, getDataUV(6, 0, sphericalHarmonicsTextureSize));\n vec4 sampledSH4567 = texture(sphericalHarmonicsTexture, getDataUV(6, 1, sphericalHarmonicsTextureSize));\n vec4 sampledSH891011 = texture(sphericalHarmonicsTexture, getDataUV(6, 2, sphericalHarmonicsTextureSize));\n vec3 sh1 = sampledSH0123.rgb;\n vec3 sh2 = vec3(sampledSH0123.a, sampledSH4567.rg);\n vec3 sh3 = vec3(sampledSH4567.ba, sampledSH891011.r);\n ";
  50931. } else {
  50932. vertexShaderSource += "\n vec2 shUV = getDataUVF(nearestEvenIndex, 2.5, doubleOddOffset, sphericalHarmonicsTextureSize);\n vec4 sampledSH0123 = texture(sphericalHarmonicsTexture, shUV);\n shUV = getDataUVF(nearestEvenIndex, 2.5, doubleOddOffset + uint(1), sphericalHarmonicsTextureSize);\n vec4 sampledSH4567 = texture(sphericalHarmonicsTexture, shUV);\n shUV = getDataUVF(nearestEvenIndex, 2.5, doubleOddOffset + uint(2), sphericalHarmonicsTextureSize);\n vec4 sampledSH891011 = texture(sphericalHarmonicsTexture, shUV);\n\n vec3 sh1 = vec3(sampledSH0123.rgb) * (1.0 - fOddOffset) + vec3(sampledSH0123.ba, sampledSH4567.r) * fOddOffset;\n vec3 sh2 = vec3(sampledSH0123.a, sampledSH4567.rg) * (1.0 - fOddOffset) + vec3(sampledSH4567.gba) * fOddOffset;\n vec3 sh3 = vec3(sampledSH4567.ba, sampledSH891011.r) * (1.0 - fOddOffset) + vec3(sampledSH891011.rgb) * fOddOffset;\n ";
  50933. }
  50934. vertexShaderSource += "\n if (sphericalHarmonics8BitMode == 1) {\n sh1 = sh1 * 2.0 - vecOnes3;\n sh2 = sh2 * 2.0 - vecOnes3;\n sh3 = sh3 * 2.0 - vecOnes3;\n }\n float x = worldViewDir.x;\n float y = worldViewDir.y;\n float z = worldViewDir.z;\n vColor.rgb += SH_C1 * (-sh1 * y + sh2 * z - sh3 * x);\n ";
  50935. if (maxSphericalHarmonicsDegree >= 2) {
  50936. vertexShaderSource += "\n if (sphericalHarmonicsDegree >= 2) {\n float xx = x * x;\n float yy = y * y;\n float zz = z * z;\n float xy = x * y;\n float yz = y * z;\n float xz = x * z;\n\n vec4 sampledSH12131415 = texture(sphericalHarmonicsTexture, getDataUV(6, 3, sphericalHarmonicsTextureSize));\n vec4 sampledSH16171819 = texture(sphericalHarmonicsTexture, getDataUV(6, 4, sphericalHarmonicsTextureSize));\n vec4 sampledSH20212223 = texture(sphericalHarmonicsTexture, getDataUV(6, 5, sphericalHarmonicsTextureSize));\n\n vec3 sh4 = sampledSH891011.gba;\n vec3 sh5 = sampledSH12131415.rgb;\n vec3 sh6 = vec3(sampledSH12131415.a, sampledSH16171819.rg);\n vec3 sh7 = vec3(sampledSH16171819.ba, sampledSH20212223.r);\n vec3 sh8 = sampledSH20212223.gba;\n\n if (sphericalHarmonics8BitMode == 1) {\n sh4 = sh4 * 2.0 - vecOnes3;\n sh5 = sh5 * 2.0 - vecOnes3;\n sh6 = sh6 * 2.0 - vecOnes3;\n sh7 = sh7 * 2.0 - vecOnes3;\n sh8 = sh8 * 2.0 - vecOnes3;\n }\n\n vColor.rgb +=\n (SH_C2[0] * xy) * sh4 +\n (SH_C2[1] * yz) * sh5 +\n (SH_C2[2] * (2.0 * zz - xx - yy)) * sh6 +\n (SH_C2[3] * xz) * sh7 +\n (SH_C2[4] * (xx - yy)) * sh8;\n }\n ";
  50937. }
  50938. vertexShaderSource += "\n }\n ";
  50939. }
  50940. vertexShaderSource += "\n\n vec4 sampledCovarianceA = texture(covariancesTexture,\n getDataUVF(nearestEvenIndex, 1.5, oddOffset, covariancesTextureSize));\n vec4 sampledCovarianceB = texture(covariancesTexture,\n getDataUVF(nearestEvenIndex, 1.5, oddOffset + uint(1), covariancesTextureSize));\n\n vec3 cov3D_M11_M12_M13 = vec3(sampledCovarianceA.rgb) * (1.0 - fOddOffset) +\n vec3(sampledCovarianceA.ba, sampledCovarianceB.r) * fOddOffset;\n vec3 cov3D_M22_M23_M33 = vec3(sampledCovarianceA.a, sampledCovarianceB.rg) * (1.0 - fOddOffset) +\n vec3(sampledCovarianceB.gba) * fOddOffset;\n\n // Construct the 3D covariance matrix\n mat3 Vrk = mat3(\n cov3D_M11_M12_M13.x, cov3D_M11_M12_M13.y, cov3D_M11_M12_M13.z,\n cov3D_M11_M12_M13.y, cov3D_M22_M23_M33.x, cov3D_M22_M23_M33.y,\n cov3D_M11_M12_M13.z, cov3D_M22_M23_M33.y, cov3D_M22_M23_M33.z\n );\n\n \n // Construct the Jacobian\u884C\u5217\u5F0F of the affine\u4EFF\u5C04 approximation\u903C\u8FD1 of the projection matrix. It will be used to transform the\n // 3D covariance matrix instead of using the actual projection matrix because that transformation would\n // require a non-linear component (perspective division) which would yield a non-gaussian result. (This assumes\u5047\u8BBE\n // the current projection is a perspective projection).\n //\u7FFB\u8BD1\u7ED3\u679C\uFF1A\u6784\u5EFA\u6295\u5F71\u77E9\u9635\u4EFF\u5C04\u8FD1\u4F3C\u7684\u96C5\u53EF\u6BD4\u77E9\u9635\u3002\u5B83\u5C06\u88AB\u7528\u6765\u53D8\u63623D\u534F\u65B9\u5DEE\u77E9\u9635\uFF0C\u800C\u4E0D\u662F\u76F4\u63A5\u4F7F\u7528\u5B9E\u9645\u7684\u6295\u5F71\u77E9\u9635\uFF0C\u56E0\u4E3A\u4F7F\u7528\u5B9E\u9645\u6295\u5F71\u77E9\u9635\u8FDB\u884C\u53D8\u6362\u9700\u8981\u5305\u542B\u975E\u7EBF\u6027\u6210\u5206\uFF08\u900F\u89C6\u9664\u6CD5\uFF09\uFF0C\u8FD9\u4F1A\u5BFC\u81F4\u975E\u9AD8\u65AF\u7684\u7ED3\u679C\u3002\u8FD9\u91CC\u5047\u8BBE\u5F53\u524D\u7684\u6295\u5F71\u4E3A\u900F\u89C6\u6295\u5F71\u3002\n //\u770B\u4E0D\u61C2 https://zhuanlan.zhihu.com/p/661569671\n\n \n mat3 J;\n if (orthographicMode == 1) {\n // Since the projection is linear, we don't need an approximation\n J = transpose(mat3(orthoZoom, 0.0, 0.0,\n 0.0, orthoZoom, 0.0,\n 0.0, 0.0, 0.0));\n } else {\n // Construct the Jacobian of the affine approximation of the projection matrix. It will be used to transform the\n // 3D covariance matrix instead of using the actual projection matrix because that transformation would\n // require a non-linear component (perspective division) which would yield a non-gaussian result.\n float s = 1.0 / (viewCenter.z * viewCenter.z);\n J = mat3(\n focal.x / viewCenter.z, 0., -(focal.x * viewCenter.x) * s,\n 0., focal.y / viewCenter.z, -(focal.y * viewCenter.y) * s,\n 0., 0., 0.\n );\n }\n\n // Concatenate the projection approximation with the model-view transformation\n mat3 W = transpose(mat3(transformModelViewMatrix));\n mat3 T = W * J;\n\n // Transform the 3D covariance matrix (Vrk) to compute the 2D covariance matrix\n mat3 cov2Dm = transpose(T) * Vrk * T;\n ";
  50941. if (antialiased) {
  50942. vertexShaderSource += "\n float detOrig = cov2Dm[0][0] * cov2Dm[1][1] - cov2Dm[0][1] * cov2Dm[0][1];\n cov2Dm[0][0] += 0.3;\n cov2Dm[1][1] += 0.3;\n float detBlur = cov2Dm[0][0] * cov2Dm[1][1] - cov2Dm[0][1] * cov2Dm[0][1];\n float compensation = sqrt(max(detOrig / detBlur, 0.0));\n ";
  50943. } else {
  50944. vertexShaderSource += "\n cov2Dm[0][0] += 0.3;\n cov2Dm[1][1] += 0.3;\n float compensation = 1.0;\n ";
  50945. }
  50946. vertexShaderSource += "\n\n vColor.a *= compensation;\n\n if (vColor.a < minAlpha) return;\n\n // We are interested in the upper-left 2x2 portion of the projected 3D covariance matrix because\n // we only care about the X and Y values. We want the X-diagonal, cov2Dm[0][0],\n // the Y-diagonal, cov2Dm[1][1], and the correlation between the two cov2Dm[0][1]. We don't\n // need cov2Dm[1][0] because it is a symetric matrix.\n vec3 cov2Dv = vec3(cov2Dm[0][0], cov2Dm[0][1], cov2Dm[1][1]);\n\n vec3 ndcCenter = clipCenter.xyz / clipCenter.w;\n\n // We now need to solve for the eigen-values and eigen vectors of the 2D covariance matrix\n // so that we can determine the 2D basis for the splat. This is done using the method described\n // here: https://people.math.harvard.edu/~knill/teaching/math21b2004/exhibits/2dmatrices/index.html \u516C\u5F0F\u51FA\u5904\n // After calculating the eigen-values and eigen-vectors, we calculate the basis for rendering the splat\n // by normalizing the eigen-vectors and then multiplying them by (sqrt(8) * eigen-value), which is\n // equal to scaling them by sqrt(8) standard deviations.\n //\n // This is a different approach than in the original work at INRIA. In that work they compute the\n // max extents of the projected splat in screen space to form a screen-space aligned bounding rectangle\n // which forms the geometry that is actually rasterized. The dimensions of that bounding box are 3.0\n // times the maximum eigen-value, or 3 standard deviations. They then use the inverse 2D covariance\n // matrix (called 'conic') in the CUDA rendering thread to determine fragment opacity by calculating the\n // full gaussian: exp(-0.5 * (X - mean) * conic * (X - mean)) * splat opacity\n float a = cov2Dv.x;\n float d = cov2Dv.z;\n float b = cov2Dv.y;\n float D = a * d - b * b;\n float trace = a + d; //\u8FFD\u8E2A\n float traceOver2 = 0.5 * trace;\n float term2 = sqrt(max(0.1f, traceOver2 * traceOver2 - D));\n float eigenValue1 = traceOver2 + term2; //\u7279\u5F81\u503CL1\n float eigenValue2 = traceOver2 - term2; //\u7279\u5F81\u503CL1\n\n if (pointCloudModeEnabled == 1) {// each splat is rendered as a filled circle\n eigenValue1 = eigenValue2 = 0.2;\n }\n\n if (eigenValue2 <= 0.0) return;\n\n vec2 eigenVector1 = normalize(vec2(b, eigenValue1 - a));\n // since the eigen vectors are orthogonal, we derive the second one from the first \u7531\u4E8E\u672C\u5F81\u5411\u91CF\u662F\u6B63\u4EA4\u7684\uFF0C\u56E0\u6B64\u6211\u4EEC\u4ECE\u7B2C\u4E00\u4E2A\u5BFC\u51FA\u7B2C\u4E8C\u4E2A\n vec2 eigenVector2 = vec2(eigenVector1.y, -eigenVector1.x);\n\n // We use sqrt(8) standard deviations\u504F\u5DEE instead of 3 to eliminate\u6D88\u9664 more of the splat with a very low opacity.\n vec2 basisVector1 = eigenVector1 * splatScale * min(sqrt8 * sqrt(eigenValue1), ".concat(parseInt(maxScreenSpaceSplatSize), ".0);\n vec2 basisVector2 = eigenVector2 * splatScale * min(sqrt8 * sqrt(eigenValue2), ").concat(parseInt(maxScreenSpaceSplatSize), ".0);\n\n if (fadeInComplete == 0) {\n float opacityAdjust = 1.0;\n float centerDist = length(splatCenter - sceneCenter);\n float renderTime = max(currentTime - firstRenderTime, 0.0);\n\n float fadeDistance = 0.75;\n float distanceLoadFadeInFactor = step(visibleRegionFadeStartRadius, centerDist);\n distanceLoadFadeInFactor = (1.0 - distanceLoadFadeInFactor) +\n (1.0 - clamp((centerDist - visibleRegionFadeStartRadius) / fadeDistance, 0.0, 1.0)) *\n distanceLoadFadeInFactor;\n opacityAdjust *= distanceLoadFadeInFactor;\n vColor.a *= opacityAdjust;\n }\n\n vec2 ndcOffset = vec2(vPosition.x * basisVector1 + vPosition.y * basisVector2) *\n basisViewport * 2.0 * inverseFocalAdjustment;\n\n vec4 quadPos = vec4(ndcCenter.xy + ndcOffset, ndcCenter.z , 1.0);\n gl_Position = quadPos; //\u5C06\u6574\u4E2A\u6B63\u65B9\u5F62\u505A\u4E00\u5B9A\u7684\u62C9\u4F38\u5F62\u53D8\uFF0C\u4E4B\u540E\u5728fs\u4E2D\u56E0\u4E3A\u53EA\u663E\u793A\u4E2D\u95F4\u7684\u5706\uFF0C\u6240\u4EE5\u4E5F\u5C31\u662F\u663E\u793A\u62C9\u4F38\u540E\u7684\u5706\u3002\uFF08vs\u53EA\u8BA1\u7B97\u56DB\u4E2A\u9876\u70B9\u7684\u5177\u4F53\u4F4D\u7F6E\uFF0C\u5176\u4ED6\u4F4D\u7F6E\u662F\u63D2\u503C\u5F97\u5230\u7684\uFF09\n\n // Scale the position data we send to the fragment shader\n vPosition *= sqrt8;\n }");
  50947. //面片模拟椭球,总是有厚度
  50948. var fragmentShaderSource = "\n precision highp float;\n #include <common>\n \n uniform vec3 debugColor;\n\n varying vec4 vColor;\n varying vec2 vUv;\n\n varying vec2 vPosition;\n\n void main () {\n // Compute the positional squared distance from the center of the splat to the current fragment.\n float A = dot(vPosition, vPosition);\n // Since the positional data in vPosition has been scaled by sqrt(8), the squared result will be\n // scaled by a factor of 8. If the squared result is larger than 8, it means it is outside the ellipse\n // defined by the rectangle formed by vPosition. It also means it's farther\n // away than sqrt(8) standard deviations from the mean.\n if (A > 8.0) discard; //position\u7684\u8303\u56F4\u534A\u5F84\u4E3A1\u3002\u6307\u4E00\u4E2Arectangle\u9762\u4E2D\u7684\u8303\u56F4\u3002\u692D\u5706\u5916\u7684\u5B8C\u5168\u900F\u660E\n vec3 color = vColor.rgb;\n\n // Since the rendered splat is scaled by sqrt(8), the inverse covariance matrix that is part of\n // the gaussian formula becomes the identity matrix. We're then left with (X - mean) * (X - mean),\n // and since 'mean' is zero, we have X * X, which is the same as A:\n float opacity = exp(-0.5 * A) * vColor.a; //\u5468\u56F4\u7684\u900F\u660E\u5EA6\u964D\u4F4E\n\n gl_FragColor = vec4(color.rgb, opacity);\n //\u4E0D\u77E5\u9053\u4E3A\u4F55ply\u8F6C\u8FC7\u6765\u7684vColor.a\u662F0\uFF0C(\u4F46\u662F\u5728\u5916\u9762\u8BBF\u95EE\u7684opacity\u5E76\u4E0D\u662F0), \u5BFC\u81F4\u5168\u662F\u9ED1\u8272\n }";
  50949. var uniforms = {
  50950. 'sceneCenter': {
  50951. 'type': 'v3',
  50952. 'value': new Vector3()
  50953. },
  50954. 'fadeInComplete': {
  50955. 'type': 'i',
  50956. 'value': 0
  50957. },
  50958. 'orthographicMode': {
  50959. 'type': 'i',
  50960. 'value': 0
  50961. },
  50962. 'visibleRegionFadeStartRadius': {
  50963. 'type': 'f',
  50964. 'value': 0.0
  50965. },
  50966. 'visibleRegionRadius': {
  50967. 'type': 'f',
  50968. 'value': 0.0
  50969. },
  50970. 'currentTime': {
  50971. 'type': 'f',
  50972. 'value': 0.0
  50973. },
  50974. 'firstRenderTime': {
  50975. 'type': 'f',
  50976. 'value': 0.0
  50977. },
  50978. 'covariancesTexture': {
  50979. //协方差
  50980. 'type': 't',
  50981. 'value': null
  50982. },
  50983. 'centersColorsTexture': {
  50984. 'type': 't',
  50985. 'value': null
  50986. },
  50987. 'sphericalHarmonicsTexture': {
  50988. 'type': 't',
  50989. 'value': null
  50990. },
  50991. 'focal': {
  50992. 'type': 'v2',
  50993. 'value': new Vector2()
  50994. },
  50995. 'orthoZoom': {
  50996. 'type': 'f',
  50997. 'value': 1.0
  50998. },
  50999. 'inverseFocalAdjustment': {
  51000. 'type': 'f',
  51001. 'value': 1.0
  51002. },
  51003. 'viewport': {
  51004. 'type': 'v2',
  51005. 'value': new Vector2()
  51006. },
  51007. 'basisViewport': {
  51008. 'type': 'v2',
  51009. 'value': new Vector2()
  51010. },
  51011. 'debugColor': {
  51012. 'type': 'v3',
  51013. 'value': new Color()
  51014. },
  51015. 'covariancesTextureSize': {
  51016. 'type': 'v2',
  51017. 'value': new Vector2(1024, 1024)
  51018. },
  51019. 'centersColorsTextureSize': {
  51020. 'type': 'v2',
  51021. 'value': new Vector2(1024, 1024)
  51022. },
  51023. 'sphericalHarmonicsDegree': {
  51024. 'type': 'i',
  51025. 'value': maxSphericalHarmonicsDegree
  51026. },
  51027. 'sphericalHarmonicsTextureSize': {
  51028. 'type': 'v2',
  51029. 'value': new Vector2(1024, 1024)
  51030. },
  51031. 'sphericalHarmonics8BitMode': {
  51032. 'type': 'i',
  51033. 'value': 0
  51034. },
  51035. 'splatScale': {
  51036. 'type': 'f',
  51037. 'value': splatScale
  51038. },
  51039. 'pointCloudModeEnabled': {
  51040. 'type': 'i',
  51041. 'value': pointCloudModeEnabled ? 1 : 0
  51042. }
  51043. };
  51044. if (dynamicMode) {
  51045. uniforms['transformIndexesTexture'] = {
  51046. 'type': 't',
  51047. 'value': null
  51048. };
  51049. var transformMatrices = [];
  51050. for (var i = 0; i < Constants.MaxScenes; i++) {
  51051. transformMatrices.push(new Matrix4());
  51052. }
  51053. uniforms['transforms'] = {
  51054. 'type': 'mat4',
  51055. 'value': transformMatrices
  51056. };
  51057. uniforms['transformIndexesTextureSize'] = {
  51058. 'type': 'v2',
  51059. 'value': new Vector2(1024, 1024)
  51060. };
  51061. }
  51062. var material = new ShaderMaterial({
  51063. uniforms: uniforms,
  51064. vertexShader: vertexShaderSource,
  51065. fragmentShader: fragmentShaderSource,
  51066. transparent: true,
  51067. alphaTest: 1.0,
  51068. blending: NormalBlending,
  51069. depthTest: true,
  51070. depthWrite: false,
  51071. side: DoubleSide
  51072. });
  51073. return material;
  51074. }
  51075. /**
  51076. * Build the Three.js geometry that will be used to render the splats. The geometry is instanced and is made up of
  51077. * vertices for a single quad as well as an attribute buffer for the splat indexes.
  51078. * @param {number} maxSplatCount The maximum number of splats that the geometry will need to accomodate
  51079. * @return {THREE.InstancedBufferGeometry}
  51080. */
  51081. static buildGeomtery(maxSplatCount) {
  51082. var baseGeometry = new BufferGeometry();
  51083. baseGeometry.setIndex([0, 1, 2, 0, 2, 3]);
  51084. // Vertices for the instanced quad
  51085. var positionsArray = new Float32Array(4 * 3);
  51086. var positions = new BufferAttribute(positionsArray, 3);
  51087. baseGeometry.setAttribute('position', positions);
  51088. positions.setXYZ(0, -1.0, -1.0, 0.0);
  51089. positions.setXYZ(1, -1.0, 1.0, 0.0);
  51090. positions.setXYZ(2, 1.0, 1.0, 0.0);
  51091. positions.setXYZ(3, 1.0, -1.0, 0.0);
  51092. positions.needsUpdate = true;
  51093. var geometry = new InstancedBufferGeometry().copy(baseGeometry);
  51094. // Splat index buffer
  51095. var splatIndexArray = new Uint32Array(maxSplatCount);
  51096. var splatIndexes = new InstancedBufferAttribute(splatIndexArray, 1, false);
  51097. splatIndexes.setUsage(DynamicDrawUsage);
  51098. geometry.setAttribute('splatIndex', splatIndexes);
  51099. geometry.instanceCount = 0;
  51100. return geometry;
  51101. }
  51102. /**
  51103. * Build a container for each scene managed by this splat mesh based on an instance of SplatBuffer, along with optional
  51104. * transform data (position, scale, rotation) passed to the splat mesh during the build process.
  51105. * @param {Array<THREE.Matrix4>} splatBuffers SplatBuffer instances containing splats for each scene
  51106. * @param {Array<object>} sceneOptions Array of options objects: {
  51107. *
  51108. * position (Array<number>): Position of the scene, acts as an offset from its default position, defaults to [0, 0, 0]
  51109. *
  51110. * rotation (Array<number>): Rotation of the scene represented as a quaternion, defaults to [0, 0, 0, 1]
  51111. *
  51112. * scale (Array<number>): Scene's scale, defaults to [1, 1, 1]
  51113. * }
  51114. * @return {Array<THREE.Matrix4>}
  51115. */
  51116. static buildScenes(splatBuffers, sceneOptions) {
  51117. var scenes = [];
  51118. scenes.length = splatBuffers.length;
  51119. for (var i = 0; i < splatBuffers.length; i++) {
  51120. var splatBuffer = splatBuffers[i];
  51121. var _options = sceneOptions[i] || {};
  51122. var positionArray = _options['position'] || [0, 0, 0];
  51123. var rotationArray = _options['rotation'] || [0, 0, 0, 1];
  51124. var scaleArray = _options['scale'] || [1, 1, 1];
  51125. var position = new Vector3().fromArray(positionArray);
  51126. var rotation = new Quaternion().fromArray(rotationArray);
  51127. var scale = new Vector3().fromArray(scaleArray);
  51128. scenes[i] = SplatMesh.createScene(splatBuffer, position, rotation, scale, _options.splatAlphaRemovalThreshold || 1);
  51129. }
  51130. return scenes;
  51131. }
  51132. static createScene(splatBuffer, position, rotation, scale, minimumAlpha) {
  51133. return new SplatScene(splatBuffer, position, rotation, scale, minimumAlpha);
  51134. }
  51135. /**
  51136. * Build data structures that map global splat indexes (based on a unified index across all splat buffers) to
  51137. * local data within a single scene.
  51138. * @param {Array<SplatBuffer>} splatBuffers Instances of SplatBuffer off which to build the maps
  51139. * @return {object}
  51140. */
  51141. static buildSplatIndexMaps(splatBuffers) {
  51142. var localSplatIndexMap = [];
  51143. var sceneIndexMap = [];
  51144. var totalSplatCount = 0;
  51145. for (var s = 0; s < splatBuffers.length; s++) {
  51146. var splatBuffer = splatBuffers[s];
  51147. var maxSplatCount = splatBuffer.getMaxSplatCount();
  51148. for (var i = 0; i < maxSplatCount; i++) {
  51149. localSplatIndexMap[totalSplatCount] = i;
  51150. sceneIndexMap[totalSplatCount] = s;
  51151. totalSplatCount++;
  51152. }
  51153. }
  51154. return {
  51155. localSplatIndexMap,
  51156. sceneIndexMap
  51157. };
  51158. }
  51159. /**
  51160. * Construct this instance of SplatMesh.
  51161. * @param {Array<SplatBuffer>} splatBuffers The base splat data, instances of SplatBuffer
  51162. * @param {Array<object>} sceneOptions Dynamic options for each scene {
  51163. *
  51164. * splatAlphaRemovalThreshold: Ignore any splats with an alpha less than the specified
  51165. * value (valid range: 0 - 255), defaults to 1
  51166. *
  51167. * position (Array<number>): Position of the scene, acts as an offset from its default position, defaults to [0, 0, 0]
  51168. *
  51169. * rotation (Array<number>): Rotation of the scene represented as a quaternion, defaults to [0, 0, 0, 1]
  51170. *
  51171. * scale (Array<number>): Scene's scale, defaults to [1, 1, 1]
  51172. *
  51173. * }
  51174. * @param {boolean} keepSceneTransforms For a scene that already exists and is being overwritten, this flag
  51175. * says to keep the transform from the existing scene.
  51176. * @param {boolean} finalBuild Will the splat mesh be in its final state after this build?
  51177. * @param {function} onSplatTreeIndexesUpload Function to be called when the upload of splat centers to the splat tree
  51178. * builder worker starts and finishes.
  51179. * @param {function} onSplatTreeConstruction Function to be called when the conversion of the local splat tree from
  51180. * the format produced by the splat tree builder worker starts and ends.
  51181. * @return {object} Object containing info about the splats that are updated
  51182. */
  51183. build(splatBuffers, sceneOptions) {
  51184. var keepSceneTransforms = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
  51185. var finalBuild = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  51186. var onSplatTreeIndexesUpload = arguments.length > 4 ? arguments[4] : undefined;
  51187. var onSplatTreeConstruction = arguments.length > 5 ? arguments[5] : undefined;
  51188. this.sceneOptions = sceneOptions;
  51189. this.finalBuild = finalBuild;
  51190. var maxSplatCount = SplatMesh.getTotalMaxSplatCountForSplatBuffers(splatBuffers);
  51191. var newScenes = SplatMesh.buildScenes(splatBuffers, sceneOptions);
  51192. if (keepSceneTransforms) {
  51193. for (var i = 0; i < this.scenes.length && i < newScenes.length; i++) {
  51194. var newScene = newScenes[i];
  51195. var existingScene = this.getScene(i);
  51196. newScene.copyTransformData(existingScene);
  51197. }
  51198. }
  51199. this.scenes = newScenes;
  51200. var minSphericalHarmonicsDegree = 3;
  51201. for (var splatBuffer of splatBuffers) {
  51202. var splatBufferSphericalHarmonicsDegree = splatBuffer.getMinSphericalHarmonicsDegree();
  51203. if (splatBufferSphericalHarmonicsDegree < minSphericalHarmonicsDegree) {
  51204. minSphericalHarmonicsDegree = splatBufferSphericalHarmonicsDegree;
  51205. }
  51206. }
  51207. this.minSphericalHarmonicsDegree = Math.min(minSphericalHarmonicsDegree, this.sphericalHarmonicsDegree);
  51208. var splatBuffersChanged = false;
  51209. if (splatBuffers.length !== this.lastBuildScenes.length) {
  51210. splatBuffersChanged = true;
  51211. } else {
  51212. for (var _i18 = 0; _i18 < splatBuffers.length; _i18++) {
  51213. var _splatBuffer = splatBuffers[_i18];
  51214. if (_splatBuffer !== this.lastBuildScenes[_i18].splatBuffer) {
  51215. splatBuffersChanged = true;
  51216. break;
  51217. }
  51218. }
  51219. }
  51220. var isUpdateBuild = true;
  51221. if (this.scenes.length !== 1 || this.lastBuildSceneCount !== this.scenes.length || this.lastBuildMaxSplatCount !== maxSplatCount || splatBuffersChanged) {
  51222. isUpdateBuild = false;
  51223. }
  51224. if (!isUpdateBuild) {
  51225. this.boundingBox = new Box3();
  51226. this.maxSplatDistanceFromSceneCenter = 0;
  51227. this.visibleRegionBufferRadius = 0;
  51228. this.visibleRegionRadius = 0;
  51229. this.visibleRegionFadeStartRadius = 0;
  51230. this.firstRenderTime = -1;
  51231. this.lastBuildScenes = [];
  51232. this.lastBuildSplatCount = 0;
  51233. this.lastBuildMaxSplatCount = 0;
  51234. this.disposeMeshData();
  51235. this.geometry = SplatMesh.buildGeomtery(maxSplatCount);
  51236. this.material = SplatMesh.buildMaterial(this.dynamicMode, this.antialiased, this.maxScreenSpaceSplatSize, this.splatScale, this.pointCloudModeEnabled, this.minSphericalHarmonicsDegree);
  51237. var indexMaps = SplatMesh.buildSplatIndexMaps(splatBuffers);
  51238. this.globalSplatIndexToLocalSplatIndexMap = indexMaps.localSplatIndexMap;
  51239. this.globalSplatIndexToSceneIndexMap = indexMaps.sceneIndexMap;
  51240. }
  51241. var splatCount = this.getSplatCount();
  51242. if (this.enableDistancesComputationOnGPU) this.setupDistancesComputationTransformFeedback();
  51243. var dataUpdateResults = this.refreshGPUDataFromSplatBuffers(isUpdateBuild);
  51244. for (var _i19 = 0; _i19 < this.scenes.length; _i19++) {
  51245. this.lastBuildScenes[_i19] = this.scenes[_i19];
  51246. }
  51247. this.lastBuildSplatCount = splatCount;
  51248. this.lastBuildMaxSplatCount = this.getMaxSplatCount();
  51249. this.lastBuildSceneCount = this.scenes.length;
  51250. if (finalBuild && this.scenes.length > 0) {
  51251. this.buildSplatTree(sceneOptions.map(options => options.splatAlphaRemovalThreshold || 1), onSplatTreeIndexesUpload, onSplatTreeConstruction).then(() => {
  51252. if (this.onSplatTreeReadyCallback) this.onSplatTreeReadyCallback(this.splatTree);
  51253. });
  51254. }
  51255. this.visible = this.scenes.length > 0;
  51256. return dataUpdateResults;
  51257. }
  51258. /**
  51259. * Dispose all resources held by the splat mesh
  51260. */
  51261. dispose() {
  51262. this.disposeMeshData();
  51263. this.disposeTextures();
  51264. this.disposeSplatTree();
  51265. if (this.enableDistancesComputationOnGPU) {
  51266. if (this.computeDistancesOnGPUSyncTimeout) {
  51267. clearTimeout(this.computeDistancesOnGPUSyncTimeout);
  51268. this.computeDistancesOnGPUSyncTimeout = null;
  51269. }
  51270. this.disposeDistancesComputationGPUResources();
  51271. }
  51272. this.scenes = [];
  51273. this.distancesTransformFeedback = {
  51274. 'id': null,
  51275. 'vertexShader': null,
  51276. 'fragmentShader': null,
  51277. 'program': null,
  51278. 'centersBuffer': null,
  51279. 'transformIndexesBuffer': null,
  51280. 'outDistancesBuffer': null,
  51281. 'centersLoc': -1,
  51282. 'modelViewProjLoc': -1,
  51283. 'transformIndexesLoc': -1,
  51284. 'transformsLocs': []
  51285. };
  51286. this.renderer = null;
  51287. this.globalSplatIndexToLocalSplatIndexMap = [];
  51288. this.globalSplatIndexToSceneIndexMap = [];
  51289. this.lastBuildSplatCount = 0;
  51290. this.lastBuildScenes = [];
  51291. this.lastBuildMaxSplatCount = 0;
  51292. this.lastBuildSceneCount = 0;
  51293. this.firstRenderTime = -1;
  51294. this.finalBuild = false;
  51295. this.webGLUtils = null;
  51296. this.boundingBox = new Box3();
  51297. this.calculatedSceneCenter = new Vector3();
  51298. this.maxSplatDistanceFromSceneCenter = 0;
  51299. this.visibleRegionBufferRadius = 0;
  51300. this.visibleRegionRadius = 0;
  51301. this.visibleRegionFadeStartRadius = 0;
  51302. this.visibleRegionChanging = false;
  51303. this.splatScale = 1.0;
  51304. this.pointCloudModeEnabled = false;
  51305. this.disposed = true;
  51306. this.lastRenderer = null;
  51307. this.visible = false;
  51308. }
  51309. /**
  51310. * Dispose of only the Three.js mesh resources (geometry, material, and texture)
  51311. */
  51312. disposeMeshData() {
  51313. if (this.geometry && this.geometry !== dummyGeometry) {
  51314. this.geometry.dispose();
  51315. this.geometry = null;
  51316. }
  51317. if (this.material) {
  51318. this.material.dispose();
  51319. this.material = null;
  51320. }
  51321. }
  51322. disposeTextures() {
  51323. for (var textureKey in this.splatDataTextures) {
  51324. if (this.splatDataTextures.hasOwnProperty(textureKey)) {
  51325. var textureContainer = this.splatDataTextures[textureKey];
  51326. if (textureContainer.texture) {
  51327. textureContainer.texture.dispose();
  51328. textureContainer.texture = null;
  51329. }
  51330. }
  51331. }
  51332. this.splatDataTextures = null;
  51333. }
  51334. disposeSplatTree() {
  51335. if (this.splatTree) {
  51336. this.splatTree.dispose();
  51337. this.splatTree = null;
  51338. } else if (this.baseSplatTree) {
  51339. this.baseSplatTree.dispose();
  51340. this.baseSplatTree = null;
  51341. }
  51342. }
  51343. getSplatTree() {
  51344. return this.splatTree;
  51345. }
  51346. onSplatTreeReady(callback) {
  51347. this.onSplatTreeReadyCallback = callback;
  51348. }
  51349. /**
  51350. * Get copies of data that are necessary for splat distance computation: splat center positions and splat
  51351. * scene indexes (necessary for applying dynamic scene transformations during distance computation)
  51352. * @param {*} start The index at which to start copying data
  51353. * @param {*} end The index at which to stop copying data
  51354. * @return {object}
  51355. */
  51356. getDataForDistancesComputation(start, end) {
  51357. var centers = this.integerBasedDistancesComputation ? this.getIntegerCenters(start, end, true) : this.getFloatCenters(start, end, true);
  51358. var sceneIndexes = this.getSceneIndexes(start, end);
  51359. return {
  51360. centers,
  51361. sceneIndexes
  51362. };
  51363. }
  51364. /**
  51365. * Refresh data textures and GPU buffers with splat data from the splat buffers belonging to this mesh.
  51366. * @param {boolean} sinceLastBuildOnly Specify whether or not to only update for splats that have been added since the last build.
  51367. * @return {object}
  51368. */
  51369. refreshGPUDataFromSplatBuffers(sinceLastBuildOnly) {
  51370. var splatCount = this.getSplatCount();
  51371. this.refreshDataTexturesFromSplatBuffers(sinceLastBuildOnly);
  51372. var updateStart = sinceLastBuildOnly ? this.lastBuildSplatCount : 0;
  51373. var {
  51374. centers,
  51375. sceneIndexes
  51376. } = this.getDataForDistancesComputation(updateStart, splatCount - 1);
  51377. if (this.enableDistancesComputationOnGPU) {
  51378. this.refreshGPUBuffersForDistancesComputation(centers, sceneIndexes, sinceLastBuildOnly);
  51379. }
  51380. return {
  51381. 'from': updateStart,
  51382. 'to': splatCount - 1,
  51383. 'count': splatCount - updateStart,
  51384. 'centers': centers,
  51385. 'sceneIndexes': sceneIndexes
  51386. };
  51387. }
  51388. /**
  51389. * Update the GPU buffers that are used for computing splat distances on the GPU.
  51390. * @param {Array<number>} centers Splat center positions
  51391. * @param {Array<number>} sceneIndexes Indexes of the scene to which each splat belongs
  51392. * @param {boolean} sinceLastBuildOnly Specify whether or not to only update for splats that have been added since the last build.
  51393. */
  51394. refreshGPUBuffersForDistancesComputation(centers, sceneIndexes) {
  51395. var sinceLastBuildOnly = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  51396. var offset = sinceLastBuildOnly ? this.lastBuildSplatCount : 0;
  51397. this.updateGPUCentersBufferForDistancesComputation(sinceLastBuildOnly, centers, offset);
  51398. this.updateGPUTransformIndexesBufferForDistancesComputation(sinceLastBuildOnly, sceneIndexes, offset);
  51399. }
  51400. /**
  51401. * Refresh data textures with data from the splat buffers for this mesh.
  51402. * @param {boolean} sinceLastBuildOnly Specify whether or not to only update for splats that have been added since the last build.
  51403. */
  51404. refreshDataTexturesFromSplatBuffers(sinceLastBuildOnly) {
  51405. if (!sinceLastBuildOnly) {
  51406. this.setupDataTextures();
  51407. } else {
  51408. this.updateDataTextures();
  51409. }
  51410. this.updateVisibleRegion(sinceLastBuildOnly);
  51411. }
  51412. setupDataTextures() {
  51413. var maxSplatCount = this.getMaxSplatCount();
  51414. var splatCount = this.getSplatCount();
  51415. this.disposeTextures();
  51416. var computeDataTextureSize = (elementsPerTexel, elementsPerSplatl) => {
  51417. var texSize = new Vector2(4096, 1024);
  51418. while (texSize.x * texSize.y * elementsPerTexel < maxSplatCount * elementsPerSplatl) texSize.y *= 2;
  51419. return texSize;
  51420. };
  51421. var covarianceCompressionLevel = this.getTargetCovarianceCompressionLevel();
  51422. var sphericalHarmonicsCompressionLevel = this.getTargetSphericalHarmonicsCompressionLevel();
  51423. var covariances = new Float32Array(maxSplatCount * COVARIANCES_ELEMENTS_PER_SPLAT);
  51424. var centers = new Float32Array(maxSplatCount * 3);
  51425. var colors = new Uint8Array(maxSplatCount * 4);
  51426. var SphericalHarmonicsArrayType = Float32Array;
  51427. if (sphericalHarmonicsCompressionLevel === 1) SphericalHarmonicsArrayType = Uint16Array;else if (sphericalHarmonicsCompressionLevel === 2) SphericalHarmonicsArrayType = Uint8Array;
  51428. var sphericalHarmonicsComponentCount = getSphericalHarmonicsComponentCountForDegree(this.minSphericalHarmonicsDegree);
  51429. var paddedSphericalHarmonicsComponentCount = sphericalHarmonicsComponentCount;
  51430. if (paddedSphericalHarmonicsComponentCount % 2 !== 0) paddedSphericalHarmonicsComponentCount++;
  51431. var sphericalHarmonics = this.minSphericalHarmonicsDegree ? new SphericalHarmonicsArrayType(maxSplatCount * sphericalHarmonicsComponentCount) : undefined;
  51432. this.fillSplatDataArrays(covariances, centers, colors, sphericalHarmonics, undefined, covarianceCompressionLevel, sphericalHarmonicsCompressionLevel);
  51433. // set up covariances data texture
  51434. var covTexSize = computeDataTextureSize(COVARIANCES_ELEMENTS_PER_TEXEL, 6);
  51435. var CovariancesDataType = covarianceCompressionLevel >= 1 ? Uint16Array : Float32Array;
  51436. var covariancesTextureType = covarianceCompressionLevel >= 1 ? HalfFloatType : FloatType;
  51437. var paddedCovariances = new CovariancesDataType(covTexSize.x * covTexSize.y * COVARIANCES_ELEMENTS_PER_TEXEL);
  51438. paddedCovariances.set(covariances);
  51439. var covTex = new DataTexture(paddedCovariances, covTexSize.x, covTexSize.y, RGBAFormat, covariancesTextureType);
  51440. covTex.needsUpdate = true;
  51441. this.material.uniforms.covariancesTexture.value = covTex;
  51442. this.material.uniforms.covariancesTextureSize.value.copy(covTexSize);
  51443. // set up centers/colors data texture
  51444. var centersColsTexSize = computeDataTextureSize(CENTER_COLORS_ELEMENTS_PER_TEXEL, 4);
  51445. var paddedCentersCols = new Uint32Array(centersColsTexSize.x * centersColsTexSize.y * CENTER_COLORS_ELEMENTS_PER_TEXEL);
  51446. SplatMesh.updateCenterColorsPaddedData(0, splatCount, centers, colors, paddedCentersCols);
  51447. var centersColsTex = new DataTexture(paddedCentersCols, centersColsTexSize.x, centersColsTexSize.y, RGBAIntegerFormat, UnsignedIntType);
  51448. centersColsTex.internalFormat = 'RGBA32UI';
  51449. centersColsTex.needsUpdate = true;
  51450. this.material.uniforms.centersColorsTexture.value = centersColsTex;
  51451. this.material.uniforms.centersColorsTextureSize.value.copy(centersColsTexSize);
  51452. this.material.uniformsNeedUpdate = true;
  51453. this.splatDataTextures = {
  51454. 'baseData': {
  51455. 'covariances': covariances,
  51456. 'centers': centers,
  51457. 'colors': colors,
  51458. 'sphericalHarmonics': sphericalHarmonics
  51459. },
  51460. 'covariances': {
  51461. 'data': paddedCovariances,
  51462. 'texture': covTex,
  51463. 'size': covTexSize,
  51464. 'compressionLevel': covarianceCompressionLevel
  51465. },
  51466. 'centerColors': {
  51467. 'data': paddedCentersCols,
  51468. 'texture': centersColsTex,
  51469. 'size': centersColsTexSize
  51470. }
  51471. };
  51472. if (sphericalHarmonics) {
  51473. var sphericalHarmonicsElementsPerTexel = 4;
  51474. var sphericalHarmonicsTexSize = computeDataTextureSize(sphericalHarmonicsElementsPerTexel, paddedSphericalHarmonicsComponentCount);
  51475. var paddedSHArraySize = sphericalHarmonicsTexSize.x * sphericalHarmonicsTexSize.y * sphericalHarmonicsElementsPerTexel;
  51476. var paddedSHArray = new SphericalHarmonicsArrayType(paddedSHArraySize);
  51477. for (var c = 0; c < splatCount; c++) {
  51478. var srcBase = sphericalHarmonicsComponentCount * c;
  51479. var destBase = paddedSphericalHarmonicsComponentCount * c;
  51480. for (var i = 0; i < sphericalHarmonicsComponentCount; i++) {
  51481. paddedSHArray[destBase + i] = sphericalHarmonics[srcBase + i];
  51482. }
  51483. }
  51484. var textureType = sphericalHarmonicsCompressionLevel === 2 ? UnsignedByteType : HalfFloatType;
  51485. var sphericalHarmonicsTex = new DataTexture(paddedSHArray, sphericalHarmonicsTexSize.x, sphericalHarmonicsTexSize.y, RGBAFormat, textureType);
  51486. sphericalHarmonicsTex.needsUpdate = true;
  51487. this.material.uniforms.sphericalHarmonicsTexture.value = sphericalHarmonicsTex;
  51488. this.material.uniforms.sphericalHarmonicsTextureSize.value.copy(sphericalHarmonicsTexSize);
  51489. if (sphericalHarmonicsCompressionLevel === 2) {
  51490. this.material.uniforms.sphericalHarmonics8BitMode.value = 1;
  51491. }
  51492. this.material.uniformsNeedUpdate = true;
  51493. this.splatDataTextures['sphericalHarmonics'] = {
  51494. 'componentCount': sphericalHarmonicsComponentCount,
  51495. 'paddedComponentCount': paddedSphericalHarmonicsComponentCount,
  51496. 'data': paddedSHArray,
  51497. 'texture': sphericalHarmonicsTex,
  51498. 'size': sphericalHarmonicsTexSize,
  51499. 'compressionLevel': sphericalHarmonicsCompressionLevel
  51500. };
  51501. }
  51502. if (this.dynamicMode) {
  51503. var transformIndexesTexSize = computeDataTextureSize(TRANSFORM_INDEXES_ELEMENTS_PER_TEXEL, 4);
  51504. var paddedTransformIndexes = new Uint32Array(transformIndexesTexSize.x * transformIndexesTexSize.y * TRANSFORM_INDEXES_ELEMENTS_PER_TEXEL);
  51505. for (var _c = 0; _c < splatCount; _c++) paddedTransformIndexes[_c] = this.globalSplatIndexToSceneIndexMap[_c];
  51506. var transformIndexesTexture = new DataTexture(paddedTransformIndexes, transformIndexesTexSize.x, transformIndexesTexSize.y, RedIntegerFormat, UnsignedIntType);
  51507. transformIndexesTexture.internalFormat = 'R32UI';
  51508. transformIndexesTexture.needsUpdate = true;
  51509. this.material.uniforms.transformIndexesTexture.value = transformIndexesTexture;
  51510. this.material.uniforms.transformIndexesTextureSize.value.copy(transformIndexesTexSize);
  51511. this.material.uniformsNeedUpdate = true;
  51512. this.splatDataTextures['tansformIndexes'] = {
  51513. 'data': paddedTransformIndexes,
  51514. 'texture': transformIndexesTexture,
  51515. 'size': transformIndexesTexSize
  51516. };
  51517. }
  51518. }
  51519. updateDataTextures() {
  51520. var splatCount = this.getSplatCount();
  51521. var covarianceCompressionLevel = this.splatDataTextures['covariances'].compressionLevel;
  51522. var sphericalHarmonicsTextureDesc = this.splatDataTextures['sphericalHarmonics'];
  51523. var sphericalHarmonicsCompressionLevel = sphericalHarmonicsTextureDesc ? sphericalHarmonicsTextureDesc.compressionLevel : 0;
  51524. this.fillSplatDataArrays(this.splatDataTextures.baseData.covariances, this.splatDataTextures.baseData.centers, this.splatDataTextures.baseData.colors, this.splatDataTextures.baseData.sphericalHarmonics, undefined, covarianceCompressionLevel, sphericalHarmonicsCompressionLevel, this.lastBuildSplatCount, splatCount - 1, this.lastBuildSplatCount);
  51525. var covariancesTextureDescriptor = this.splatDataTextures['covariances'];
  51526. var paddedCovariances = covariancesTextureDescriptor.data;
  51527. var covariancesTexture = covariancesTextureDescriptor.texture;
  51528. var covarancesStartSplat = this.lastBuildSplatCount * COVARIANCES_ELEMENTS_PER_SPLAT;
  51529. var covariancesEndSplat = splatCount * COVARIANCES_ELEMENTS_PER_SPLAT;
  51530. for (var i = covarancesStartSplat; i < covariancesEndSplat; i++) {
  51531. var covariance = this.splatDataTextures.baseData.covariances[i];
  51532. paddedCovariances[i] = covariance;
  51533. }
  51534. var covariancesTextureProps = this.renderer ? this.renderer.properties.get(covariancesTexture) : null;
  51535. if (!covariancesTextureProps || !covariancesTextureProps.__webglTexture) {
  51536. covariancesTexture.needsUpdate = true;
  51537. } else {
  51538. var covaranceBytesPerElement = covarianceCompressionLevel ? 2 : 4;
  51539. this.updateDataTexture(paddedCovariances, covariancesTextureDescriptor, covariancesTextureProps, COVARIANCES_ELEMENTS_PER_TEXEL, COVARIANCES_ELEMENTS_PER_SPLAT, covaranceBytesPerElement, this.lastBuildSplatCount, splatCount - 1);
  51540. }
  51541. var centerColorsTextureDescriptor = this.splatDataTextures['centerColors'];
  51542. var paddedCenterColors = centerColorsTextureDescriptor.data;
  51543. var centerColorsTexture = centerColorsTextureDescriptor.texture;
  51544. SplatMesh.updateCenterColorsPaddedData(this.lastBuildSplatCount, splatCount, this.splatDataTextures.baseData.centers, this.splatDataTextures.baseData.colors, paddedCenterColors);
  51545. var centerColorsTextureProps = this.renderer ? this.renderer.properties.get(centerColorsTexture) : null;
  51546. if (!centerColorsTextureProps || !centerColorsTextureProps.__webglTexture) {
  51547. centerColorsTexture.needsUpdate = true;
  51548. } else {
  51549. this.updateDataTexture(paddedCenterColors, centerColorsTextureDescriptor, centerColorsTextureProps, CENTER_COLORS_ELEMENTS_PER_TEXEL, CENTER_COLORS_ELEMENTS_PER_SPLAT, 4, this.lastBuildSplatCount, splatCount - 1);
  51550. }
  51551. if (this.splatDataTextures.baseData.sphericalHarmonics) {
  51552. var sphericalHarmonicsComponentCount = sphericalHarmonicsTextureDesc.componentCount;
  51553. var paddedSphericalHarmonicsComponentCount = sphericalHarmonicsTextureDesc.paddedComponentCount;
  51554. var paddedSHArray = sphericalHarmonicsTextureDesc.data;
  51555. for (var c = this.lastBuildSplatCount; c < splatCount; c++) {
  51556. var srcBase = sphericalHarmonicsComponentCount * c;
  51557. var destBase = paddedSphericalHarmonicsComponentCount * c;
  51558. for (var _i20 = 0; _i20 < sphericalHarmonicsComponentCount; _i20++) {
  51559. paddedSHArray[destBase + _i20] = this.splatDataTextures.baseData.sphericalHarmonics[srcBase + _i20];
  51560. }
  51561. }
  51562. var sphericalHarmonicsTex = sphericalHarmonicsTextureDesc.texture;
  51563. var sphericalHarmonicsTextureProps = this.renderer ? this.renderer.properties.get(sphericalHarmonicsTex) : null;
  51564. if (!sphericalHarmonicsTextureProps || !sphericalHarmonicsTextureProps.__webglTexture) {
  51565. sphericalHarmonicsTex.needsUpdate = true;
  51566. } else {
  51567. var sphericalHarmonicsElementsPerTexel = 4;
  51568. var sphericalHarmonicsBytesPerElement = 4;
  51569. if (sphericalHarmonicsCompressionLevel === 1) sphericalHarmonicsBytesPerElement = 2;else if (sphericalHarmonicsCompressionLevel === 2) sphericalHarmonicsBytesPerElement = 1;
  51570. this.updateDataTexture(paddedSHArray, sphericalHarmonicsTextureDesc, sphericalHarmonicsTextureProps, sphericalHarmonicsElementsPerTexel, paddedSphericalHarmonicsComponentCount, sphericalHarmonicsBytesPerElement, this.lastBuildSplatCount, splatCount - 1);
  51571. }
  51572. }
  51573. if (this.dynamicMode) {
  51574. var transformIndexesTexDesc = this.splatDataTextures['tansformIndexes'];
  51575. var paddedTransformIndexes = transformIndexesTexDesc.data;
  51576. for (var _c2 = this.lastBuildSplatCount; _c2 < splatCount; _c2++) {
  51577. paddedTransformIndexes[_c2] = this.globalSplatIndexToSceneIndexMap[_c2];
  51578. }
  51579. var transformIndexesTexture = transformIndexesTexDesc.texture;
  51580. var transformIndexesTextureProps = this.renderer ? this.renderer.properties.get(transformIndexesTexture) : null;
  51581. if (!transformIndexesTextureProps || !transformIndexesTextureProps.__webglTexture) {
  51582. transformIndexesTexture.needsUpdate = true;
  51583. } else {
  51584. this.updateDataTexture(paddedTransformIndexes, transformIndexesTexDesc, transformIndexesTextureProps, 1, 1, 1, this.lastBuildSplatCount, splatCount - 1);
  51585. }
  51586. }
  51587. }
  51588. getTargetCovarianceCompressionLevel() {
  51589. return this.halfPrecisionCovariancesOnGPU ? 1 : 0;
  51590. }
  51591. getTargetSphericalHarmonicsCompressionLevel() {
  51592. return Math.max(1, this.getMaximumSplatBufferCompressionLevel());
  51593. }
  51594. getMaximumSplatBufferCompressionLevel() {
  51595. var maxCompressionLevel;
  51596. for (var i = 0; i < this.scenes.length; i++) {
  51597. var scene = this.getScene(i);
  51598. var splatBuffer = scene.splatBuffer;
  51599. if (i === 0 || splatBuffer.compressionLevel > maxCompressionLevel) {
  51600. maxCompressionLevel = splatBuffer.compressionLevel;
  51601. }
  51602. }
  51603. return maxCompressionLevel;
  51604. }
  51605. getMinimumSplatBufferCompressionLevel() {
  51606. var minCompressionLevel;
  51607. for (var i = 0; i < this.scenes.length; i++) {
  51608. var scene = this.getScene(i);
  51609. var splatBuffer = scene.splatBuffer;
  51610. if (i === 0 || splatBuffer.compressionLevel < minCompressionLevel) {
  51611. minCompressionLevel = splatBuffer.compressionLevel;
  51612. }
  51613. }
  51614. return minCompressionLevel;
  51615. }
  51616. static computeTextureUpdateRegion(startSplat, endSplat, textureWidth, elementsPerTexel, elementsPerSplat) {
  51617. var texelsPerSplat = elementsPerSplat / elementsPerTexel;
  51618. var startSplatTexels = startSplat * texelsPerSplat;
  51619. var startRow = Math.floor(startSplatTexels / textureWidth);
  51620. var startRowElement = startRow * textureWidth * elementsPerTexel;
  51621. var endSplatTexels = endSplat * texelsPerSplat;
  51622. var endRow = Math.floor(endSplatTexels / textureWidth);
  51623. var endRowEndElement = endRow * textureWidth * elementsPerTexel + textureWidth * elementsPerTexel;
  51624. return {
  51625. 'dataStart': startRowElement,
  51626. 'dataEnd': endRowEndElement,
  51627. 'startRow': startRow,
  51628. 'endRow': endRow
  51629. };
  51630. }
  51631. //局部纹理刷新
  51632. updateDataTexture(paddedData, textureDesc, textureProps, elementsPerTexel, elementsPerSplat, bytesPerElement, from, to) {
  51633. var gl = this.renderer.getContext();
  51634. var updateRegion = SplatMesh.computeTextureUpdateRegion(from, to, textureDesc.size.x, elementsPerTexel, elementsPerSplat);
  51635. var updateElementCount = updateRegion.dataEnd - updateRegion.dataStart;
  51636. var updateDataView = new paddedData.constructor(paddedData.buffer, updateRegion.dataStart * bytesPerElement, updateElementCount);
  51637. var updateHeight = updateRegion.endRow - updateRegion.startRow + 1;
  51638. var dataTexture = textureDesc.texture;
  51639. var glType = this.webGLUtils.convert(dataTexture.type);
  51640. var glFormat = this.webGLUtils.convert(dataTexture.format, dataTexture.colorSpace);
  51641. var currentTexture = gl.getParameter(gl.TEXTURE_BINDING_2D);
  51642. gl.bindTexture(gl.TEXTURE_2D, textureProps.__webglTexture);
  51643. gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, updateRegion.startRow, textureDesc.size.x, updateHeight, glFormat, glType, updateDataView);
  51644. //(target, level, xoffset, yoffset, width, height, format, type, pixels);
  51645. gl.bindTexture(gl.TEXTURE_2D, currentTexture);
  51646. }
  51647. static updateCenterColorsPaddedData(to, from, centers, colors, paddedCenterColors) {
  51648. for (var c = to; c < from; c++) {
  51649. var colorsBase = c * 4;
  51650. var centersBase = c * 3;
  51651. var centerColorsBase = c * 4;
  51652. paddedCenterColors[centerColorsBase] = rgbaArrayToInteger(colors, colorsBase);
  51653. paddedCenterColors[centerColorsBase + 1] = uintEncodedFloat(centers[centersBase]);
  51654. paddedCenterColors[centerColorsBase + 2] = uintEncodedFloat(centers[centersBase + 1]);
  51655. paddedCenterColors[centerColorsBase + 3] = uintEncodedFloat(centers[centersBase + 2]);
  51656. }
  51657. }
  51658. updateVisibleRegion(sinceLastBuildOnly) {
  51659. var splatCount = this.getSplatCount();
  51660. var tempCenter = new Vector3();
  51661. if (!sinceLastBuildOnly) {
  51662. var avgCenter = new Vector3();
  51663. this.scenes.forEach(scene => {
  51664. avgCenter.add(scene.splatBuffer.sceneCenter);
  51665. });
  51666. avgCenter.multiplyScalar(1.0 / this.scenes.length);
  51667. this.calculatedSceneCenter.copy(avgCenter);
  51668. this.material.uniforms.sceneCenter.value.copy(this.calculatedSceneCenter);
  51669. this.material.uniformsNeedUpdate = true;
  51670. }
  51671. var startSplatFormMaxDistanceCalc = sinceLastBuildOnly ? this.lastBuildSplatCount : 0;
  51672. for (var i = startSplatFormMaxDistanceCalc; i < splatCount; i++) {
  51673. this.getSplatCenter(i, tempCenter, false);
  51674. var distFromCSceneCenter = tempCenter.sub(this.calculatedSceneCenter).length();
  51675. if (distFromCSceneCenter > this.maxSplatDistanceFromSceneCenter) this.maxSplatDistanceFromSceneCenter = distFromCSceneCenter;
  51676. }
  51677. if (this.maxSplatDistanceFromSceneCenter - this.visibleRegionBufferRadius > VISIBLE_REGION_EXPANSION_DELTA) {
  51678. this.visibleRegionBufferRadius = this.maxSplatDistanceFromSceneCenter;
  51679. this.visibleRegionRadius = Math.max(this.visibleRegionBufferRadius - VISIBLE_REGION_EXPANSION_DELTA, 0.0);
  51680. }
  51681. if (this.finalBuild) this.visibleRegionRadius = this.visibleRegionBufferRadius = this.maxSplatDistanceFromSceneCenter;
  51682. this.updateVisibleRegionFadeDistance();
  51683. }
  51684. updateVisibleRegionFadeDistance() {
  51685. var sceneRevealMode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : SceneRevealMode.Default;
  51686. var fastFadeRate = SCENE_FADEIN_RATE_FAST;
  51687. var gradualFadeRate = SCENE_FADEIN_RATE_GRADUAL;
  51688. var defaultFadeInRate = this.finalBuild ? fastFadeRate : gradualFadeRate;
  51689. var fadeInRate = sceneRevealMode === SceneRevealMode.Default ? defaultFadeInRate : gradualFadeRate;
  51690. this.visibleRegionFadeStartRadius = (this.visibleRegionRadius - this.visibleRegionFadeStartRadius) * fadeInRate + this.visibleRegionFadeStartRadius;
  51691. var fadeInPercentage = this.visibleRegionBufferRadius > 0 ? this.visibleRegionFadeStartRadius / this.visibleRegionBufferRadius : 0;
  51692. var fadeInComplete = fadeInPercentage > 0.99;
  51693. var shaderFadeInComplete = fadeInComplete || sceneRevealMode === SceneRevealMode.Instant ? 1 : 0;
  51694. this.material.uniforms.visibleRegionFadeStartRadius.value = this.visibleRegionFadeStartRadius;
  51695. this.material.uniforms.visibleRegionRadius.value = this.visibleRegionRadius;
  51696. this.material.uniforms.firstRenderTime.value = this.firstRenderTime;
  51697. this.material.uniforms.currentTime.value = performance.now();
  51698. this.material.uniforms.fadeInComplete.value = shaderFadeInComplete;
  51699. this.material.uniformsNeedUpdate = true;
  51700. this.visibleRegionChanging = !fadeInComplete;
  51701. }
  51702. /**
  51703. * Set the indexes of splats that should be rendered; should be sorted in desired render order.
  51704. * @param {Uint32Array} globalIndexes Sorted index list of splats to be rendered
  51705. * @param {number} renderSplatCount Total number of splats to be rendered. Necessary because we may not want to render
  51706. * every splat.
  51707. */
  51708. updateRenderIndexes(globalIndexes, renderSplatCount) {
  51709. //仅渲染前renderSplatCount个点,在前renderSplatCount的顺序是否可以打乱?
  51710. var geometry = this.geometry;
  51711. geometry.attributes.splatIndex.set(globalIndexes);
  51712. geometry.attributes.splatIndex.needsUpdate = true;
  51713. if (renderSplatCount > 0 && this.firstRenderTime === -1) this.firstRenderTime = performance.now();
  51714. geometry.instanceCount = renderSplatCount;
  51715. } //注:假设全部点都渲染的话,是无所谓index的顺序的,可以直接第0个为0,第n个为n……
  51716. /**
  51717. * Update the transforms for each scene in this splat mesh from their individual components (position,
  51718. * quaternion, and scale)
  51719. */
  51720. updateTransforms() {
  51721. for (var i = 0; i < this.scenes.length; i++) {
  51722. var scene = this.getScene(i);
  51723. scene.updateTransform();
  51724. }
  51725. }
  51726. setSplatScale() {
  51727. var splatScale = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
  51728. this.splatScale = splatScale;
  51729. this.material.uniforms.splatScale.value = splatScale;
  51730. this.material.uniformsNeedUpdate = true;
  51731. }
  51732. getSplatScale() {
  51733. return this.splatScale;
  51734. }
  51735. setPointCloudModeEnabled(enabled) {
  51736. this.pointCloudModeEnabled = enabled;
  51737. this.material.uniforms.pointCloudModeEnabled.value = enabled ? 1 : 0;
  51738. this.material.uniformsNeedUpdate = true;
  51739. }
  51740. getPointCloudModeEnabled() {
  51741. return this.pointCloudModeEnabled;
  51742. }
  51743. getSplatDataTextures() {
  51744. return this.splatDataTextures;
  51745. }
  51746. getSplatCount() {
  51747. return SplatMesh.getTotalSplatCountForScenes(this.scenes);
  51748. }
  51749. static getTotalSplatCountForScenes(scenes) {
  51750. var totalSplatCount = 0;
  51751. for (var scene of scenes) {
  51752. if (scene && scene.splatBuffer) totalSplatCount += scene.splatBuffer.getSplatCount();
  51753. }
  51754. return totalSplatCount;
  51755. }
  51756. static getTotalSplatCountForSplatBuffers(splatBuffers) {
  51757. var totalSplatCount = 0;
  51758. for (var splatBuffer of splatBuffers) totalSplatCount += splatBuffer.getSplatCount();
  51759. return totalSplatCount;
  51760. }
  51761. getMaxSplatCount() {
  51762. return SplatMesh.getTotalMaxSplatCountForScenes(this.scenes);
  51763. }
  51764. static getTotalMaxSplatCountForScenes(scenes) {
  51765. var totalSplatCount = 0;
  51766. for (var scene of scenes) {
  51767. if (scene && scene.splatBuffer) totalSplatCount += scene.splatBuffer.getMaxSplatCount();
  51768. }
  51769. return totalSplatCount;
  51770. }
  51771. static getTotalMaxSplatCountForSplatBuffers(splatBuffers) {
  51772. var totalSplatCount = 0;
  51773. for (var splatBuffer of splatBuffers) totalSplatCount += splatBuffer.getMaxSplatCount();
  51774. return totalSplatCount;
  51775. }
  51776. disposeDistancesComputationGPUResources() {
  51777. if (!this.renderer) return;
  51778. var gl = this.renderer.getContext();
  51779. if (this.distancesTransformFeedback.vao) {
  51780. gl.deleteVertexArray(this.distancesTransformFeedback.vao);
  51781. this.distancesTransformFeedback.vao = null;
  51782. }
  51783. if (this.distancesTransformFeedback.program) {
  51784. gl.deleteProgram(this.distancesTransformFeedback.program);
  51785. gl.deleteShader(this.distancesTransformFeedback.vertexShader);
  51786. gl.deleteShader(this.distancesTransformFeedback.fragmentShader);
  51787. this.distancesTransformFeedback.program = null;
  51788. this.distancesTransformFeedback.vertexShader = null;
  51789. this.distancesTransformFeedback.fragmentShader = null;
  51790. }
  51791. this.disposeDistancesComputationGPUBufferResources();
  51792. if (this.distancesTransformFeedback.id) {
  51793. gl.deleteTransformFeedback(this.distancesTransformFeedback.id);
  51794. this.distancesTransformFeedback.id = null;
  51795. }
  51796. }
  51797. disposeDistancesComputationGPUBufferResources() {
  51798. if (!this.renderer) return;
  51799. var gl = this.renderer.getContext();
  51800. if (this.distancesTransformFeedback.centersBuffer) {
  51801. this.distancesTransformFeedback.centersBuffer = null;
  51802. gl.deleteBuffer(this.distancesTransformFeedback.centersBuffer);
  51803. }
  51804. if (this.distancesTransformFeedback.outDistancesBuffer) {
  51805. gl.deleteBuffer(this.distancesTransformFeedback.outDistancesBuffer);
  51806. this.distancesTransformFeedback.outDistancesBuffer = null;
  51807. }
  51808. }
  51809. /**
  51810. * Set the Three.js renderer used by this splat mesh
  51811. * @param {THREE.WebGLRenderer} renderer Instance of THREE.WebGLRenderer
  51812. */
  51813. setRenderer(renderer) {
  51814. if (renderer !== this.renderer) {
  51815. this.renderer = renderer;
  51816. var gl = this.renderer.getContext();
  51817. var extensions = new WebGLExtensions$1(gl);
  51818. var capabilities = new WebGLCapabilities$1(gl, extensions, {});
  51819. extensions.init(capabilities);
  51820. this.webGLUtils = new WebGLUtils(gl, extensions, capabilities);
  51821. if (this.enableDistancesComputationOnGPU && this.getSplatCount() > 0) {
  51822. this.setupDistancesComputationTransformFeedback();
  51823. var {
  51824. centers: _centers,
  51825. sceneIndexes
  51826. } = this.getDataForDistancesComputation(0, this.getSplatCount() - 1);
  51827. this.refreshGPUBuffersForDistancesComputation(_centers, sceneIndexes);
  51828. }
  51829. }
  51830. }
  51831. /**
  51832. * Refresh GPU buffers used for computing splat distances with centers data from the scenes for this mesh.
  51833. * @param {boolean} isUpdate Specify whether or not to update the GPU buffer or to initialize & fill
  51834. * @param {Array<number>} centers The splat centers data
  51835. * @param {number} offsetSplats Offset in the GPU buffer at which to start updating data, specified in splats
  51836. */
  51837. updateGPUCentersBufferForDistancesComputation(isUpdate, centers, offsetSplats) {
  51838. if (!this.renderer) return;
  51839. var gl = this.renderer.getContext();
  51840. var currentVao = gl.getParameter(gl.VERTEX_ARRAY_BINDING);
  51841. gl.bindVertexArray(this.distancesTransformFeedback.vao);
  51842. var ArrayType = this.integerBasedDistancesComputation ? Uint32Array : Float32Array;
  51843. var attributeBytesPerCenter = 16;
  51844. var subBufferOffset = offsetSplats * attributeBytesPerCenter;
  51845. gl.bindBuffer(gl.ARRAY_BUFFER, this.distancesTransformFeedback.centersBuffer);
  51846. if (isUpdate) {
  51847. gl.bufferSubData(gl.ARRAY_BUFFER, subBufferOffset, centers);
  51848. } else {
  51849. var maxArray = new ArrayType(this.getMaxSplatCount() * attributeBytesPerCenter);
  51850. maxArray.set(centers);
  51851. gl.bufferData(gl.ARRAY_BUFFER, maxArray, gl.STATIC_DRAW);
  51852. }
  51853. gl.bindBuffer(gl.ARRAY_BUFFER, null);
  51854. if (currentVao) gl.bindVertexArray(currentVao);
  51855. }
  51856. /**
  51857. * Refresh GPU buffers used for pre-computing splat distances with centers data from the scenes for this mesh.
  51858. * @param {boolean} isUpdate Specify whether or not to update the GPU buffer or to initialize & fill
  51859. * @param {Array<number>} transformIndexes The splat transform indexes
  51860. * @param {number} offsetSplats Offset in the GPU buffer at which to start updating data, specified in splats
  51861. */
  51862. updateGPUTransformIndexesBufferForDistancesComputation(isUpdate, transformIndexes, offsetSplats) {
  51863. if (!this.renderer || !this.dynamicMode) return;
  51864. var gl = this.renderer.getContext();
  51865. var currentVao = gl.getParameter(gl.VERTEX_ARRAY_BINDING);
  51866. gl.bindVertexArray(this.distancesTransformFeedback.vao);
  51867. var subBufferOffset = offsetSplats * 4;
  51868. gl.bindBuffer(gl.ARRAY_BUFFER, this.distancesTransformFeedback.transformIndexesBuffer);
  51869. if (isUpdate) {
  51870. gl.bufferSubData(gl.ARRAY_BUFFER, subBufferOffset, transformIndexes);
  51871. } else {
  51872. var maxArray = new Uint32Array(this.getMaxSplatCount() * 4);
  51873. maxArray.set(transformIndexes);
  51874. gl.bufferData(gl.ARRAY_BUFFER, maxArray, gl.STATIC_DRAW);
  51875. }
  51876. gl.bindBuffer(gl.ARRAY_BUFFER, null);
  51877. if (currentVao) gl.bindVertexArray(currentVao);
  51878. }
  51879. /**
  51880. * Get a typed array containing a mapping from global splat indexes to their scene index.
  51881. * @param {number} start Starting splat index to store
  51882. * @param {number} end Ending splat index to store
  51883. * @return {Uint32Array}
  51884. */
  51885. getSceneIndexes(start, end) {
  51886. var sceneIndexes;
  51887. var fillCount = end - start + 1;
  51888. sceneIndexes = new Uint32Array(fillCount);
  51889. for (var i = start; i <= end; i++) {
  51890. sceneIndexes[i] = this.globalSplatIndexToSceneIndexMap[i];
  51891. }
  51892. return sceneIndexes;
  51893. }
  51894. /**
  51895. * Given a global splat index, return corresponding local data (splat buffer, index of splat in that splat
  51896. * buffer, and the corresponding transform)
  51897. * @param {number} globalIndex Global splat index
  51898. * @param {object} paramsObj Object in which to store local data
  51899. * @param {boolean} returnSceneTransform By default, the transform of the scene to which the splat at 'globalIndex' belongs will be
  51900. * returned via the 'sceneTransform' property of 'paramsObj' only if the splat mesh is static.
  51901. * If 'returnSceneTransform' is true, the 'sceneTransform' property will always contain the scene
  51902. * transform, and if 'returnSceneTransform' is false, the 'sceneTransform' property will always
  51903. * be null.
  51904. */
  51905. getLocalSplatParameters(globalIndex, paramsObj, returnSceneTransform) {
  51906. if (returnSceneTransform === undefined || returnSceneTransform === null) {
  51907. returnSceneTransform = this.dynamicMode ? false : true;
  51908. }
  51909. paramsObj.splatBuffer = this.getSplatBufferForSplat(globalIndex);
  51910. paramsObj.localIndex = this.getSplatLocalIndex(globalIndex);
  51911. paramsObj.sceneTransform = returnSceneTransform ? this.getSceneTransformForSplat(globalIndex) : null;
  51912. }
  51913. /**
  51914. * Fill arrays with splat data and apply transforms if appropriate. Each array is optional.
  51915. * @param {Float32Array} covariances Target storage for splat covariances
  51916. * @param {Float32Array} centers Target storage for splat centers
  51917. * @param {Uint8Array} colors Target storage for splat colors
  51918. * @param {Float32Array} sphericalHarmonics Target storage for spherical harmonics
  51919. * @param {boolean} applySceneTransform By default, scene transforms are applied to relevant splat data only if the splat mesh is
  51920. * static. If 'applySceneTransform' is true, scene transforms will always be applied and if
  51921. * it is false, they will never be applied. If undefined, the default behavior will apply.
  51922. * @param {number} covarianceCompressionLevel The compression level for covariances in the destination array
  51923. * @param {number} sphericalHarmonicsCompressionLevel The compression level for spherical harmonics in the destination array
  51924. * @param {number} srcStart The start location from which to pull source data
  51925. * @param {number} srcEnd The end location from which to pull source data
  51926. * @param {number} destStart The start location from which to write data
  51927. */
  51928. fillSplatDataArrays(covariances, centers, colors, sphericalHarmonics, applySceneTransform) {
  51929. var covarianceCompressionLevel = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
  51930. var sphericalHarmonicsCompressionLevel = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 1;
  51931. var srcStart = arguments.length > 7 ? arguments[7] : undefined;
  51932. var srcEnd = arguments.length > 8 ? arguments[8] : undefined;
  51933. var destStart = arguments.length > 9 && arguments[9] !== undefined ? arguments[9] : 0;
  51934. for (var i = 0; i < this.scenes.length; i++) {
  51935. if (applySceneTransform === undefined || applySceneTransform === null) {
  51936. applySceneTransform = this.dynamicMode ? false : true;
  51937. }
  51938. var scene = this.getScene(i);
  51939. var splatBuffer = scene.splatBuffer;
  51940. var sceneTransform = applySceneTransform ? scene.transform : null;
  51941. if (covariances) {
  51942. splatBuffer.fillSplatCovarianceArray(covariances, sceneTransform, srcStart, srcEnd, destStart, covarianceCompressionLevel);
  51943. }
  51944. if (centers) splatBuffer.fillSplatCenterArray(centers, sceneTransform, srcStart, srcEnd, destStart);
  51945. if (colors) splatBuffer.fillSplatColorArray(colors, scene.minimumAlpha, srcStart, srcEnd, destStart);
  51946. if (sphericalHarmonics) {
  51947. splatBuffer.fillSphericalHarmonicsArray(sphericalHarmonics, this.minSphericalHarmonicsDegree, sceneTransform, srcStart, srcEnd, destStart, sphericalHarmonicsCompressionLevel);
  51948. }
  51949. destStart += splatBuffer.getSplatCount();
  51950. }
  51951. }
  51952. /**
  51953. * Convert splat centers, which are floating point values, to an array of integers and multiply
  51954. * each by 1000. Centers will get transformed as appropriate before conversion to integer.
  51955. * @param {number} start The index at which to start retrieving data
  51956. * @param {number} end The index at which to stop retrieving data
  51957. * @param {boolean} padFour Enforce alignment of 4 by inserting a 1 after every 3 values
  51958. * @return {Int32Array}
  51959. */
  51960. getIntegerCenters(start, end) {
  51961. var padFour = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  51962. var splatCount = end - start + 1;
  51963. var floatCenters = new Float32Array(splatCount * 3);
  51964. this.fillSplatDataArrays(null, floatCenters, null, null, undefined, undefined, undefined, start);
  51965. var intCenters;
  51966. var componentCount = padFour ? 4 : 3;
  51967. intCenters = new Int32Array(splatCount * componentCount);
  51968. for (var i = 0; i < splatCount; i++) {
  51969. for (var t = 0; t < 3; t++) {
  51970. intCenters[i * componentCount + t] = Math.round(floatCenters[i * 3 + t] * 1000.0);
  51971. }
  51972. if (padFour) intCenters[i * componentCount + 3] = 1000;
  51973. }
  51974. return intCenters;
  51975. }
  51976. /**
  51977. * Returns an array of splat centers, transformed as appropriate, optionally padded.
  51978. * @param {number} start The index at which to start retrieving data
  51979. * @param {number} end The index at which to stop retrieving data
  51980. * @param {boolean} padFour Enforce alignment of 4 by inserting a 1 after every 3 values
  51981. * @return {Float32Array}
  51982. */
  51983. getFloatCenters(start, end) {
  51984. var padFour = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  51985. var splatCount = end - start + 1;
  51986. var floatCenters = new Float32Array(splatCount * 3);
  51987. this.fillSplatDataArrays(null, floatCenters, null, null, undefined, undefined, undefined, start);
  51988. if (!padFour) return floatCenters;
  51989. var paddedFloatCenters = new Float32Array(splatCount * 4);
  51990. for (var i = 0; i < splatCount; i++) {
  51991. for (var t = 0; t < 3; t++) {
  51992. paddedFloatCenters[i * 4 + t] = floatCenters[i * 3 + t];
  51993. }
  51994. paddedFloatCenters[i * 4 + 3] = 1.0;
  51995. }
  51996. return paddedFloatCenters;
  51997. }
  51998. /**
  51999. * Store the transform of the scene at 'sceneIndex' in 'outTransform'.
  52000. * @param {number} sceneIndex Index of the desired scene
  52001. * @param {THREE.Matrix4} outTransform Instance of THREE.Matrix4 in which to store the scene's transform
  52002. */
  52003. getSceneTransform(sceneIndex, outTransform) {
  52004. var scene = this.getScene(sceneIndex);
  52005. scene.updateTransform();
  52006. outTransform.copy(scene.transform);
  52007. }
  52008. /**
  52009. * Get the scene at 'sceneIndex'.
  52010. * @param {number} sceneIndex Index of the desired scene
  52011. * @return {SplatScene}
  52012. */
  52013. getScene(sceneIndex) {
  52014. if (sceneIndex < 0 || sceneIndex >= this.scenes.length) {
  52015. throw new Error('SplatMesh::getScene() -> Invalid scene index.');
  52016. }
  52017. return this.scenes[sceneIndex];
  52018. }
  52019. getSplatBufferForSplat(globalIndex) {
  52020. return this.getScene(this.globalSplatIndexToSceneIndexMap[globalIndex]).splatBuffer;
  52021. }
  52022. getSceneIndexForSplat(globalIndex) {
  52023. return this.globalSplatIndexToSceneIndexMap[globalIndex];
  52024. }
  52025. getSceneTransformForSplat(globalIndex) {
  52026. return this.getScene(this.globalSplatIndexToSceneIndexMap[globalIndex]).transform;
  52027. }
  52028. getSplatLocalIndex(globalIndex) {
  52029. return this.globalSplatIndexToLocalSplatIndexMap[globalIndex];
  52030. }
  52031. static getIntegerMatrixArray(matrix) {
  52032. var matrixElements = matrix.elements;
  52033. var intMatrixArray = [];
  52034. for (var i = 0; i < 16; i++) {
  52035. intMatrixArray[i] = Math.round(matrixElements[i] * 1000.0);
  52036. }
  52037. return intMatrixArray;
  52038. }
  52039. }
  52040. var SorterWasm = "AGFzbQEAAAAADAZkeWxpbmsAAAAAAAEbA2AAAGAQf39/f39/f39/f39/f39/fwBgAAF/AhIBA2VudgZtZW1vcnkCAwCAgAQDBAMAAQIHOQMRX193YXNtX2NhbGxfY3RvcnMAAAtzb3J0SW5kZXhlcwABE2Vtc2NyaXB0ZW5fdGxzX2luaXQAAgrHEAMDAAELuxAFAXwDewJ/A30CfiALIAprIQwCQCAOBEAgDQRAQfj///8HIQ5BiICAgHghDSALIAxNDQIgDCEBA0AgAyABQQJ0IgVqIAIgACAFaigCAEECdGooAgAiBTYCACAFIA4gBSAOSBshDiAFIA0gBSANShshDSABQQFqIgEgC0cNAAsMAgsgDwRAQfj///8HIQ5BiICAgHghDSALIAxNDQJBfyEPIAwhAgNAIA8gByAAIAJBAnQiFGooAgAiFUECdGooAgAiCkcEQAJ+IAX9CQIIIAggCkEGdGoiD/0JAgAgDyoCEP0gASAPKgIg/SACIA8qAjD9IAP95gEgBf0JAhggD/0JAgQgDyoCFP0gASAPKgIk/SACIA8qAjT9IAP95gH95AEgBf0JAiggD/0JAgggDyoCGP0gASAPKgIo/SACIA8qAjj9IAP95gH95AEgBf0JAjggD/0JAgwgDyoCHP0gASAPKgIs/SACIA8qAjz9IAP95gH95AEiEf0fArv9FCAR/R8Du/0iAf0MAAAAAABAj0AAAAAAAECPQCIS/fIBIhP9IQEiEJlEAAAAAAAA4ENjBEAgELAMAQtCgICAgICAgICAfwshGQJ+IBP9IQAiEJlEAAAAAAAA4ENjBEAgELAMAQtCgICAgICAgICAfwv9EiETAn4gEf0fALv9FCAR/R8Bu/0iASAS/fIBIhH9IQEiEJlEAAAAAAAA4ENjBEAgELAMAQtCgICAgICAgICAfwshGiATIBn9HgEhEgJ+IBH9IQAiEJlEAAAAAAAA4ENjBEAgELAMAQtCgICAgICAgICAfwv9EiAa/R4BIBL9DQABAgMICQoLEBESExgZGhshEiAKIQ8LIAMgFGogASAVQQR0av0AAAAgEv21ASIR/RsAIBH9GwFqIBH9GwJqIBH9GwNqIgo2AgAgCiAOIAogDkgbIQ4gCiANIAogDUobIQ0gAkEBaiICIAtHDQALDAILAn8gBSoCGLtEAAAAAABAj0CiIhCZRAAAAAAAAOBBYwRAIBCqDAELQYCAgIB4CyEKAn8gBSoCCLtEAAAAAABAj0CiIhCZRAAAAAAAAOBBYwRAIBCqDAELQYCAgIB4CyECAn8gBSoCKLtEAAAAAABAj0CiIhCZRAAAAAAAAOBBYwRAIBCqDAELQYCAgIB4CyEFQfj///8HIQ5BiICAgHghDSALIAxNDQEgAv0RIAr9HAEgBf0cAiESIAwhBQNAIAMgBUECdCICaiABIAAgAmooAgBBBHRq/QAAACAS/bUBIhH9GwAgEf0bAWogEf0bAmoiAjYCACACIA4gAiAOSBshDiACIA0gAiANShshDSAFQQFqIgUgC0cNAAsMAQsgDQRAQfj///8HIQ5BiICAgHghDSALIAxNDQEgDCEBA0AgAyABQQJ0IgVqAn8gAiAAIAVqKAIAQQJ0aioCALtEAAAAAAAAsECiIhCZRAAAAAAAAOBBYwRAIBCqDAELQYCAgIB4CyIKNgIAIAogDiAKIA5IGyEOIAogDSAKIA1KGyENIAFBAWoiASALRw0ACwwBCwJAIA9FBEAgCyAMSw0BQYiAgIB4IQ1B+P///wchDgwCC0H4////ByEOQYiAgIB4IQ0gCyAMTQ0BQX8hDyAMIQIDQCAPIAcgACACQQJ0IhRqKAIAQQJ0IhVqKAIAIgpHBEAgBf0JAgggCCAKQQZ0aiIP/QkCACAPKgIQ/SABIA8qAiD9IAIgDyoCMP0gA/3mASAF/QkCGCAP/QkCBCAPKgIU/SABIA8qAiT9IAIgDyoCNP0gA/3mAf3kASAF/QkCKCAP/QkCCCAPKgIY/SABIA8qAij9IAIgDyoCOP0gA/3mAf3kASAF/QkCOCAP/QkCDCAPKgIc/SABIA8qAiz9IAIgDyoCPP0gA/3mAf3kASERIAohDwsgAyAUagJ/IBEgASAVQQJ0IgpqKQIA/RL95gEiEv0fACAS/R8BkiARIBH9DQgJCgsMDQ4PAAAAAAAAAAAgASAKQQhyaikCAP0S/eYBIhL9HwCSIBL9HwGSu0QAAAAAAACwQKIiEJlEAAAAAAAA4EFjBEAgEKoMAQtBgICAgHgLIgo2AgAgCiAOIAogDkgbIQ4gCiANIAogDUobIQ0gAkEBaiICIAtHDQALDAELIAUqAighFiAFKgIYIRcgBSoCCCEYQfj///8HIQ5BiICAgHghDSAMIQUDQAJ/IBggASAAIAVBAnQiB2ooAgBBBHRqIgIqAgCUIBcgAioCBJSSIBYgAioCCJSSu0QAAAAAAACwQKIiEJlEAAAAAAAA4EFjBEAgEKoMAQtBgICAgHgLIQogAyAHaiAKNgIAIAogDiAKIA5IGyEOIAogDSAKIA1KGyENIAVBAWoiBSALRw0ACwsgCyAMSwRAIAlBAWuzIA2yIA6yk5UhFiAMIQ0DQAJ/IBYgAyANQQJ0aiIBKAIAIA5rspQiF4tDAAAAT10EQCAXqAwBC0GAgICAeAshCiABIAo2AgAgBCAKQQJ0aiIBIAEoAgBBAWo2AgAgDUEBaiINIAtHDQALCyAJQQJPBEAgBCgCACENQQEhDgNAIAQgDkECdGoiASABKAIAIA1qIg02AgAgDkEBaiIOIAlHDQALCyAMQQBKBEAgDCEOA0AgBiAOQQFrIgFBAnQiAmogACACaigCADYCACAOQQFKIQIgASEOIAINAAsLIAsgDEoEQCALIQ4DQCAGIAsgBCADIA5BAWsiDkECdCIBaigCAEECdGoiAigCACIFa0ECdGogACABaigCADYCACACIAVBAWs2AgAgDCAOSA0ACwsLBABBAAs=";
  52041. //sortIndexes 按照深度排序
  52042. function sortWorker(self) {
  52043. var wasmInstance;
  52044. var wasmMemory;
  52045. var useSharedMemory;
  52046. var integerBasedSort;
  52047. var dynamicMode;
  52048. var splatCount;
  52049. var indexesToSortOffset; //存储首地址
  52050. var sortedIndexesOffset;
  52051. var transformIndexesOffset;
  52052. var transformsOffset;
  52053. var precomputedDistancesOffset;
  52054. var mappedDistancesOffset;
  52055. var frequenciesOffset;
  52056. var centersOffset;
  52057. var modelViewProjOffset;
  52058. var countsZero;
  52059. var sortedIndexesOut;
  52060. var Constants;
  52061. function sort(splatSortCount, splatRenderCount, modelViewProj, usePrecomputedDistances, copyIndexesToSort, copyPrecomputedDistances, copyTransforms) {
  52062. var sortStartTime = performance.now();
  52063. if (!useSharedMemory) {
  52064. var indexesToSort = new Uint32Array(wasmMemory, indexesToSortOffset, copyIndexesToSort.byteLength / Constants.BytesPerInt);
  52065. indexesToSort.set(copyIndexesToSort);
  52066. var transforms = new Float32Array(wasmMemory, transformsOffset, copyTransforms.byteLength / Constants.BytesPerFloat);
  52067. transforms.set(copyTransforms);
  52068. if (usePrecomputedDistances) {
  52069. var precomputedDistances;
  52070. if (integerBasedSort) {
  52071. precomputedDistances = new Int32Array(wasmMemory, precomputedDistancesOffset, copyPrecomputedDistances.byteLength / Constants.BytesPerInt);
  52072. } else {
  52073. precomputedDistances = new Float32Array(wasmMemory, precomputedDistancesOffset, copyPrecomputedDistances.byteLength / Constants.BytesPerFloat);
  52074. }
  52075. precomputedDistances.set(copyPrecomputedDistances);
  52076. }
  52077. }
  52078. if (!countsZero) countsZero = new Uint32Array(Constants.DepthMapRange);
  52079. new Float32Array(wasmMemory, modelViewProjOffset, 16).set(modelViewProj); //由于新数组已经与 WebAssembly 内存关联,实际上是将 modelViewProj 的数据复制到了 WebAssembly 内存的指定位置。
  52080. new Uint32Array(wasmMemory, frequenciesOffset, Constants.DepthMapRange).set(countsZero);
  52081. wasmInstance.exports.sortIndexes(indexesToSortOffset, centersOffset, precomputedDistancesOffset, mappedDistancesOffset, frequenciesOffset, modelViewProjOffset, sortedIndexesOffset, transformIndexesOffset, transformsOffset, Constants.DepthMapRange, splatSortCount, splatRenderCount, splatCount, usePrecomputedDistances, integerBasedSort, dynamicMode);
  52082. var sortMessage = {
  52083. 'sortDone': true,
  52084. 'splatSortCount': splatSortCount,
  52085. 'splatRenderCount': splatRenderCount,
  52086. 'sortTime': 0
  52087. };
  52088. if (!useSharedMemory) {
  52089. var sortedIndexes = new Uint32Array(wasmMemory, sortedIndexesOffset, splatRenderCount);
  52090. if (!sortedIndexesOut || sortedIndexesOut.length < splatRenderCount) {
  52091. sortedIndexesOut = new Uint32Array(splatRenderCount);
  52092. }
  52093. sortedIndexesOut.set(sortedIndexes);
  52094. sortMessage.sortedIndexes = sortedIndexesOut;
  52095. }
  52096. var sortEndTime = performance.now();
  52097. sortMessage.sortTime = sortEndTime - sortStartTime;
  52098. self.postMessage(sortMessage);
  52099. }
  52100. self.onmessage = e => {
  52101. if (e.data.centers) {
  52102. //填入坐标数据
  52103. centers = e.data.centers;
  52104. transformIndexes = e.data.transformIndexes;
  52105. if (integerBasedSort) {
  52106. new Int32Array(wasmMemory, centersOffset + e.data.range.from * Constants.BytesPerInt * 4, e.data.range.count * 4).set(new Int32Array(centers));
  52107. } else {
  52108. new Float32Array(wasmMemory, centersOffset + e.data.range.from * Constants.BytesPerFloat * 4, e.data.range.count * 4).set(new Float32Array(centers));
  52109. }
  52110. if (dynamicMode) {
  52111. new Uint32Array(wasmMemory, transformIndexesOffset + e.data.range.from * 4, e.data.range.count).set(new Uint32Array(transformIndexes));
  52112. }
  52113. self.postMessage({
  52114. 'centerDataSet': true
  52115. });
  52116. } else if (e.data.sort) {
  52117. //请求sort
  52118. var renderCount = e.data.sort.splatRenderCount || 0;
  52119. var sortCount = e.data.sort.splatSortCount || 0;
  52120. var usePrecomputedDistances = e.data.sort.usePrecomputedDistances;
  52121. var copyIndexesToSort;
  52122. var copyPrecomputedDistances;
  52123. var copyTransforms;
  52124. if (!useSharedMemory) {
  52125. copyIndexesToSort = e.data.sort.indexesToSort;
  52126. copyTransforms = e.data.sort.transforms;
  52127. if (usePrecomputedDistances) copyPrecomputedDistances = e.data.sort.precomputedDistances;
  52128. }
  52129. sort(sortCount, renderCount, e.data.sort.modelViewProj, usePrecomputedDistances, copyIndexesToSort, copyPrecomputedDistances, copyTransforms);
  52130. } else if (e.data.init) {
  52131. //初始化 分配空间
  52132. // Yep, this is super hacky and gross :(
  52133. Constants = e.data.init.Constants;
  52134. splatCount = e.data.init.splatCount;
  52135. useSharedMemory = e.data.init.useSharedMemory;
  52136. integerBasedSort = e.data.init.integerBasedSort;
  52137. dynamicMode = e.data.init.dynamicMode;
  52138. var CENTERS_BYTES_PER_ENTRY = integerBasedSort ? Constants.BytesPerInt * 4 : Constants.BytesPerFloat * 4;
  52139. var sorterWasmBytes = new Uint8Array(e.data.init.sorterWasmBytes);
  52140. var matrixSize = 16 * Constants.BytesPerFloat;
  52141. var memoryRequiredForIndexesToSort = splatCount * Constants.BytesPerInt;
  52142. var memoryRequiredForCenters = splatCount * CENTERS_BYTES_PER_ENTRY;
  52143. var memoryRequiredForModelViewProjectionMatrix = matrixSize;
  52144. var memoryRequiredForPrecomputedDistances = integerBasedSort ? splatCount * Constants.BytesPerInt : splatCount * Constants.BytesPerFloat;
  52145. var memoryRequiredForMappedDistances = splatCount * Constants.BytesPerInt;
  52146. var memoryRequiredForSortedIndexes = splatCount * Constants.BytesPerInt;
  52147. var memoryRequiredForIntermediateSortBuffers = Constants.DepthMapRange * Constants.BytesPerInt * 2;
  52148. var memoryRequiredforTransformIndexes = dynamicMode ? splatCount * Constants.BytesPerInt : 0;
  52149. var memoryRequiredforTransforms = dynamicMode ? Constants.MaxScenes * matrixSize : 0;
  52150. var extraMemory = Constants.MemoryPageSize * 32;
  52151. var totalRequiredMemory = memoryRequiredForIndexesToSort + memoryRequiredForCenters + memoryRequiredForModelViewProjectionMatrix + memoryRequiredForPrecomputedDistances + memoryRequiredForMappedDistances + memoryRequiredForIntermediateSortBuffers + memoryRequiredForSortedIndexes + memoryRequiredforTransformIndexes + memoryRequiredforTransforms + extraMemory;
  52152. var totalPagesRequired = Math.floor(totalRequiredMemory / Constants.MemoryPageSize) + 1;
  52153. var sorterWasmImport = {
  52154. module: {},
  52155. env: {
  52156. memory: new WebAssembly.Memory({
  52157. initial: totalPagesRequired * 2,
  52158. //创建一个初始大小为 .. 页(每页64KiB)的内存实例
  52159. maximum: totalPagesRequired * 4,
  52160. shared: true
  52161. })
  52162. }
  52163. };
  52164. WebAssembly.compile(sorterWasmBytes).then(wasmModule => {
  52165. return WebAssembly.instantiate(wasmModule, sorterWasmImport);
  52166. }).then(instance => {
  52167. wasmInstance = instance;
  52168. indexesToSortOffset = 0;
  52169. centersOffset = indexesToSortOffset + memoryRequiredForIndexesToSort;
  52170. modelViewProjOffset = centersOffset + memoryRequiredForCenters;
  52171. precomputedDistancesOffset = modelViewProjOffset + memoryRequiredForModelViewProjectionMatrix;
  52172. mappedDistancesOffset = precomputedDistancesOffset + memoryRequiredForPrecomputedDistances;
  52173. frequenciesOffset = mappedDistancesOffset + memoryRequiredForMappedDistances;
  52174. sortedIndexesOffset = frequenciesOffset + memoryRequiredForIntermediateSortBuffers;
  52175. transformIndexesOffset = sortedIndexesOffset + memoryRequiredForSortedIndexes;
  52176. transformsOffset = transformIndexesOffset + memoryRequiredforTransformIndexes;
  52177. wasmMemory = sorterWasmImport.env.memory.buffer; //SharedArrayBuffer
  52178. if (useSharedMemory) {
  52179. self.postMessage({
  52180. 'sortSetupPhase1Complete': true,
  52181. 'indexesToSortBuffer': wasmMemory,
  52182. 'indexesToSortOffset': indexesToSortOffset,
  52183. 'sortedIndexesBuffer': wasmMemory,
  52184. //整理好的indexes
  52185. 'sortedIndexesOffset': sortedIndexesOffset,
  52186. 'precomputedDistancesBuffer': wasmMemory,
  52187. 'precomputedDistancesOffset': precomputedDistancesOffset,
  52188. 'transformsBuffer': wasmMemory,
  52189. 'transformsOffset': transformsOffset
  52190. });
  52191. } else {
  52192. self.postMessage({
  52193. 'sortSetupPhase1Complete': true
  52194. });
  52195. }
  52196. });
  52197. }
  52198. };
  52199. }
  52200. function createSortWorker(splatCount, useSharedMemory, integerBasedSort, dynamicMode) {
  52201. var worker = new Worker(URL.createObjectURL(new Blob(['(', sortWorker.toString(), ')(self)'], {
  52202. type: 'application/javascript'
  52203. })));
  52204. var sorterWasmBinaryString = atob(SorterWasm); //二进制代码
  52205. var sorterWasmBytes = new Uint8Array(sorterWasmBinaryString.length);
  52206. for (var i = 0; i < sorterWasmBinaryString.length; i++) {
  52207. sorterWasmBytes[i] = sorterWasmBinaryString.charCodeAt(i);
  52208. }
  52209. worker.postMessage({
  52210. 'init': {
  52211. 'sorterWasmBytes': sorterWasmBytes.buffer,
  52212. 'splatCount': splatCount,
  52213. 'useSharedMemory': useSharedMemory,
  52214. 'integerBasedSort': integerBasedSort,
  52215. 'dynamicMode': dynamicMode,
  52216. // Super hacky
  52217. 'Constants': {
  52218. 'BytesPerFloat': Constants.BytesPerFloat,
  52219. 'BytesPerInt': Constants.BytesPerInt,
  52220. 'DepthMapRange': Constants.DepthMapRange,
  52221. 'MemoryPageSize': Constants.MemoryPageSize,
  52222. 'MaxScenes': Constants.MaxScenes
  52223. }
  52224. }
  52225. });
  52226. return worker;
  52227. }
  52228. /*
  52229. 相关函数见 setupSortWorker updateSplatSort updateRenderIndexes addSplatBuffers
  52230. 为什么要手动排序?shader无法计算准确的深度吗
  52231. */
  52232. var WebXRMode = {
  52233. None: 0,
  52234. VR: 1,
  52235. AR: 2
  52236. };
  52237. /*
  52238. Copyright © 2010-2024 three.js authors & Mark Kellogg
  52239. Permission is hereby granted, free of charge, to any person obtaining a copy
  52240. of this software and associated documentation files (the "Software"), to deal
  52241. in the Software without restriction, including without limitation the rights
  52242. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  52243. copies of the Software, and to permit persons to whom the Software is
  52244. furnished to do so, subject to the following conditions:
  52245. The above copyright notice and this permission notice shall be included in
  52246. all copies or substantial portions of the Software.
  52247. */
  52248. class VRButton {
  52249. static createButton(renderer) {
  52250. var button = document.createElement('button');
  52251. function showEnterVR( /* device */
  52252. ) {
  52253. var currentSession = null;
  52254. async function onSessionStarted(session) {
  52255. session.addEventListener('end', onSessionEnded);
  52256. await renderer.xr.setSession(session);
  52257. button.textContent = 'EXIT VR';
  52258. currentSession = session;
  52259. }
  52260. function onSessionEnded( /* event */
  52261. ) {
  52262. currentSession.removeEventListener('end', onSessionEnded);
  52263. button.textContent = 'ENTER VR';
  52264. currentSession = null;
  52265. }
  52266. //
  52267. button.style.display = '';
  52268. button.style.cursor = 'pointer';
  52269. button.style.left = 'calc(50% - 50px)';
  52270. button.style.width = '100px';
  52271. button.textContent = 'ENTER VR';
  52272. // WebXR's requestReferenceSpace only works if the corresponding feature
  52273. // was requested at session creation time. For simplicity, just ask for
  52274. // the interesting ones as optional features, but be aware that the
  52275. // requestReferenceSpace call will fail if it turns out to be unavailable.
  52276. // ('local' is always available for immersive sessions and doesn't need to
  52277. // be requested separately.)
  52278. var sessionInit = {
  52279. optionalFeatures: ['local-floor', 'bounded-floor', 'hand-tracking', 'layers']
  52280. };
  52281. button.onmouseenter = function () {
  52282. button.style.opacity = '1.0';
  52283. };
  52284. button.onmouseleave = function () {
  52285. button.style.opacity = '0.5';
  52286. };
  52287. button.onclick = function () {
  52288. if (currentSession === null) {
  52289. navigator.xr.requestSession('immersive-vr', sessionInit).then(onSessionStarted);
  52290. } else {
  52291. currentSession.end();
  52292. if (navigator.xr.offerSession !== undefined) {
  52293. navigator.xr.offerSession('immersive-vr', sessionInit).then(onSessionStarted).catch(err => {
  52294. console.warn(err);
  52295. });
  52296. }
  52297. }
  52298. };
  52299. if (navigator.xr.offerSession !== undefined) {
  52300. navigator.xr.offerSession('immersive-vr', sessionInit).then(onSessionStarted).catch(err => {
  52301. console.warn(err);
  52302. });
  52303. }
  52304. }
  52305. function disableButton() {
  52306. button.style.display = '';
  52307. button.style.cursor = 'auto';
  52308. button.style.left = 'calc(50% - 75px)';
  52309. button.style.width = '150px';
  52310. button.onmouseenter = null;
  52311. button.onmouseleave = null;
  52312. button.onclick = null;
  52313. }
  52314. function showWebXRNotFound() {
  52315. disableButton();
  52316. button.textContent = 'VR NOT SUPPORTED';
  52317. }
  52318. function showVRNotAllowed(exception) {
  52319. disableButton();
  52320. console.warn('Exception when trying to call xr.isSessionSupported', exception);
  52321. button.textContent = 'VR NOT ALLOWED';
  52322. }
  52323. function stylizeElement(element) {
  52324. element.style.position = 'absolute';
  52325. element.style.bottom = '20px';
  52326. element.style.padding = '12px 6px';
  52327. element.style.border = '1px solid #fff';
  52328. element.style.borderRadius = '4px';
  52329. element.style.background = 'rgba(0,0,0,0.1)';
  52330. element.style.color = '#fff';
  52331. element.style.font = 'normal 13px sans-serif';
  52332. element.style.textAlign = 'center';
  52333. element.style.opacity = '0.5';
  52334. element.style.outline = 'none';
  52335. element.style.zIndex = '999';
  52336. }
  52337. if ('xr' in navigator) {
  52338. button.id = 'VRButton';
  52339. button.style.display = 'none';
  52340. stylizeElement(button);
  52341. navigator.xr.isSessionSupported('immersive-vr').then(function (supported) {
  52342. supported ? showEnterVR() : showWebXRNotFound();
  52343. if (supported && VRButton.xrSessionIsGranted) {
  52344. button.click();
  52345. }
  52346. }).catch(showVRNotAllowed);
  52347. return button;
  52348. } else {
  52349. var message = document.createElement('a');
  52350. if (window.isSecureContext === false) {
  52351. message.href = document.location.href.replace(/^http:/, 'https:');
  52352. message.innerHTML = 'WEBXR NEEDS HTTPS'; // TODO Improve message
  52353. } else {
  52354. message.href = 'https://immersiveweb.dev/';
  52355. message.innerHTML = 'WEBXR NOT AVAILABLE';
  52356. }
  52357. message.style.left = 'calc(50% - 90px)';
  52358. message.style.width = '180px';
  52359. message.style.textDecoration = 'none';
  52360. stylizeElement(message);
  52361. return message;
  52362. }
  52363. }
  52364. static registerSessionGrantedListener() {
  52365. if (typeof navigator !== 'undefined' && 'xr' in navigator) {
  52366. // WebXRViewer (based on Firefox) has a bug where addEventListener
  52367. // throws a silent exception and aborts execution entirely.
  52368. if (/WebXRViewer\//i.test(navigator.userAgent)) return;
  52369. navigator.xr.addEventListener('sessiongranted', () => {
  52370. VRButton.xrSessionIsGranted = true;
  52371. });
  52372. }
  52373. }
  52374. }
  52375. VRButton.xrSessionIsGranted = false;
  52376. VRButton.registerSessionGrantedListener();
  52377. /*
  52378. Copyright © 2010-2024 three.js authors & Mark Kellogg
  52379. Permission is hereby granted, free of charge, to any person obtaining a copy
  52380. of this software and associated documentation files (the "Software"), to deal
  52381. in the Software without restriction, including without limitation the rights
  52382. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  52383. copies of the Software, and to permit persons to whom the Software is
  52384. furnished to do so, subject to the following conditions:
  52385. The above copyright notice and this permission notice shall be included in
  52386. all copies or substantial portions of the Software.
  52387. */
  52388. class ARButton {
  52389. static createButton(renderer) {
  52390. var sessionInit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  52391. var button = document.createElement('button');
  52392. function showStartAR( /* device */
  52393. ) {
  52394. if (sessionInit.domOverlay === undefined) {
  52395. var overlay = document.createElement('div');
  52396. overlay.style.display = 'none';
  52397. document.body.appendChild(overlay);
  52398. var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
  52399. svg.setAttribute('width', 38);
  52400. svg.setAttribute('height', 38);
  52401. svg.style.position = 'absolute';
  52402. svg.style.right = '20px';
  52403. svg.style.top = '20px';
  52404. svg.addEventListener('click', function () {
  52405. currentSession.end();
  52406. });
  52407. overlay.appendChild(svg);
  52408. var path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
  52409. path.setAttribute('d', 'M 12,12 L 28,28 M 28,12 12,28');
  52410. path.setAttribute('stroke', '#fff');
  52411. path.setAttribute('stroke-width', 2);
  52412. svg.appendChild(path);
  52413. if (sessionInit.optionalFeatures === undefined) {
  52414. sessionInit.optionalFeatures = [];
  52415. }
  52416. sessionInit.optionalFeatures.push('dom-overlay');
  52417. sessionInit.domOverlay = {
  52418. root: overlay
  52419. };
  52420. }
  52421. //
  52422. var currentSession = null;
  52423. async function onSessionStarted(session) {
  52424. session.addEventListener('end', onSessionEnded);
  52425. renderer.xr.setReferenceSpaceType('local');
  52426. await renderer.xr.setSession(session);
  52427. button.textContent = 'STOP AR';
  52428. sessionInit.domOverlay.root.style.display = '';
  52429. currentSession = session;
  52430. }
  52431. function onSessionEnded( /* event */
  52432. ) {
  52433. currentSession.removeEventListener('end', onSessionEnded);
  52434. button.textContent = 'START AR';
  52435. sessionInit.domOverlay.root.style.display = 'none';
  52436. currentSession = null;
  52437. }
  52438. //
  52439. button.style.display = '';
  52440. button.style.cursor = 'pointer';
  52441. button.style.left = 'calc(50% - 50px)';
  52442. button.style.width = '100px';
  52443. button.textContent = 'START AR';
  52444. button.onmouseenter = function () {
  52445. button.style.opacity = '1.0';
  52446. };
  52447. button.onmouseleave = function () {
  52448. button.style.opacity = '0.5';
  52449. };
  52450. button.onclick = function () {
  52451. if (currentSession === null) {
  52452. navigator.xr.requestSession('immersive-ar', sessionInit).then(onSessionStarted);
  52453. } else {
  52454. currentSession.end();
  52455. if (navigator.xr.offerSession !== undefined) {
  52456. navigator.xr.offerSession('immersive-ar', sessionInit).then(onSessionStarted).catch(err => {
  52457. console.warn(err);
  52458. });
  52459. }
  52460. }
  52461. };
  52462. if (navigator.xr.offerSession !== undefined) {
  52463. navigator.xr.offerSession('immersive-ar', sessionInit).then(onSessionStarted).catch(err => {
  52464. console.warn(err);
  52465. });
  52466. }
  52467. }
  52468. function disableButton() {
  52469. button.style.display = '';
  52470. button.style.cursor = 'auto';
  52471. button.style.left = 'calc(50% - 75px)';
  52472. button.style.width = '150px';
  52473. button.onmouseenter = null;
  52474. button.onmouseleave = null;
  52475. button.onclick = null;
  52476. }
  52477. function showARNotSupported() {
  52478. disableButton();
  52479. button.textContent = 'AR NOT SUPPORTED';
  52480. }
  52481. function showARNotAllowed(exception) {
  52482. disableButton();
  52483. console.warn('Exception when trying to call xr.isSessionSupported', exception);
  52484. button.textContent = 'AR NOT ALLOWED';
  52485. }
  52486. function stylizeElement(element) {
  52487. element.style.position = 'absolute';
  52488. element.style.bottom = '20px';
  52489. element.style.padding = '12px 6px';
  52490. element.style.border = '1px solid #fff';
  52491. element.style.borderRadius = '4px';
  52492. element.style.background = 'rgba(0,0,0,0.1)';
  52493. element.style.color = '#fff';
  52494. element.style.font = 'normal 13px sans-serif';
  52495. element.style.textAlign = 'center';
  52496. element.style.opacity = '0.5';
  52497. element.style.outline = 'none';
  52498. element.style.zIndex = '999';
  52499. }
  52500. if ('xr' in navigator) {
  52501. button.id = 'ARButton';
  52502. button.style.display = 'none';
  52503. stylizeElement(button);
  52504. navigator.xr.isSessionSupported('immersive-ar').then(function (supported) {
  52505. supported ? showStartAR() : showARNotSupported();
  52506. }).catch(showARNotAllowed);
  52507. return button;
  52508. } else {
  52509. var message = document.createElement('a');
  52510. if (window.isSecureContext === false) {
  52511. message.href = document.location.href.replace(/^http:/, 'https:');
  52512. message.innerHTML = 'WEBXR NEEDS HTTPS'; // TODO Improve message
  52513. } else {
  52514. message.href = 'https://immersiveweb.dev/';
  52515. message.innerHTML = 'WEBXR NOT AVAILABLE';
  52516. }
  52517. message.style.left = 'calc(50% - 90px)';
  52518. message.style.width = '180px';
  52519. message.style.textDecoration = 'none';
  52520. stylizeElement(message);
  52521. return message;
  52522. }
  52523. }
  52524. }
  52525. var RenderMode = {
  52526. Always: 0,
  52527. OnChange: 1,
  52528. Never: 2
  52529. };
  52530. var THREE_CAMERA_FOV = 50;
  52531. var MINIMUM_DISTANCE_TO_NEW_FOCAL_POINT = .75;
  52532. var MIN_SPLAT_COUNT_TO_SHOW_SPLAT_TREE_LOADING_SPINNER = 1500000;
  52533. var FOCUS_MARKER_FADE_IN_SPEED = 10.0;
  52534. var FOCUS_MARKER_FADE_OUT_SPEED = 2.5;
  52535. var CONSECUTIVE_RENDERED_FRAMES_FOR_FPS_CALCULATION = 60;
  52536. /**
  52537. * Viewer: Manages the rendering of splat scenes. Manages an instance of SplatMesh as well as a web worker
  52538. * that performs the sort for its splats.
  52539. */
  52540. class Viewer {
  52541. constructor() {
  52542. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  52543. _defineProperty(this, "onKeyDown", function () {
  52544. var forward = new Vector3();
  52545. var tempMatrixLeft = new Matrix4();
  52546. var tempMatrixRight = new Matrix4();
  52547. return function (e) {
  52548. forward.set(0, 0, -1);
  52549. forward.transformDirection(this.camera.matrixWorld);
  52550. tempMatrixLeft.makeRotationAxis(forward, Math.PI / 128);
  52551. tempMatrixRight.makeRotationAxis(forward, -Math.PI / 128);
  52552. switch (e.code) {
  52553. case 'KeyG':
  52554. this.focalAdjustment += 0.02;
  52555. this.forceRenderNextFrame();
  52556. break;
  52557. case 'KeyF':
  52558. this.focalAdjustment -= 0.02;
  52559. this.forceRenderNextFrame();
  52560. break;
  52561. case 'ArrowLeft':
  52562. this.camera.up.transformDirection(tempMatrixLeft);
  52563. break;
  52564. case 'ArrowRight':
  52565. this.camera.up.transformDirection(tempMatrixRight);
  52566. break;
  52567. case 'KeyC':
  52568. this.showMeshCursor = !this.showMeshCursor;
  52569. break;
  52570. case 'KeyU':
  52571. this.showControlPlane = !this.showControlPlane;
  52572. break;
  52573. case 'KeyI':
  52574. this.showInfo = !this.showInfo;
  52575. if (this.showInfo) {
  52576. this.infoPanel.show();
  52577. } else {
  52578. this.infoPanel.hide();
  52579. }
  52580. break;
  52581. case 'KeyO':
  52582. if (!this.usingExternalCamera) {
  52583. this.setOrthographicMode(!this.camera.isOrthographicCamera);
  52584. }
  52585. break;
  52586. case 'KeyP':
  52587. if (!this.usingExternalCamera) {
  52588. this.splatMesh.setPointCloudModeEnabled(!this.splatMesh.getPointCloudModeEnabled());
  52589. }
  52590. break;
  52591. case 'Equal':
  52592. if (!this.usingExternalCamera) {
  52593. this.splatMesh.setSplatScale(this.splatMesh.getSplatScale() + 0.05);
  52594. }
  52595. break;
  52596. case 'Minus':
  52597. if (!this.usingExternalCamera) {
  52598. this.splatMesh.setSplatScale(Math.max(this.splatMesh.getSplatScale() - 0.05, 0.0));
  52599. }
  52600. break;
  52601. }
  52602. };
  52603. }());
  52604. _defineProperty(this, "onMouseUp", function () {
  52605. var clickOffset = new Vector2();
  52606. return function (mouse) {
  52607. clickOffset.copy(this.mousePosition).sub(this.mouseDownPosition);
  52608. var mouseUpTime = getCurrentTime();
  52609. var wasClick = mouseUpTime - this.mouseDownTime < 0.5 && clickOffset.length() < 2;
  52610. if (wasClick) {
  52611. this.onMouseClick(mouse);
  52612. }
  52613. };
  52614. }());
  52615. _defineProperty(this, "checkForFocalPointChange", function () {
  52616. var renderDimensions = new Vector2();
  52617. var toNewFocalPoint = new Vector3();
  52618. var outHits = [];
  52619. return function () {
  52620. if (!this.transitioningCameraTarget) {
  52621. this.getRenderDimensions(renderDimensions);
  52622. outHits.length = 0;
  52623. this.raycaster.setFromCameraAndScreenPosition(this.camera, this.mousePosition, renderDimensions);
  52624. this.raycaster.intersectSplatMesh(this.splatMesh, outHits);
  52625. if (outHits.length > 0) {
  52626. var hit = outHits[0];
  52627. var intersectionPoint = hit.origin;
  52628. toNewFocalPoint.copy(intersectionPoint).sub(this.camera.position);
  52629. if (toNewFocalPoint.length() > MINIMUM_DISTANCE_TO_NEW_FOCAL_POINT) {
  52630. this.previousCameraTarget.copy(this.controls.target);
  52631. this.nextCameraTarget.copy(intersectionPoint);
  52632. this.transitioningCameraTarget = true;
  52633. this.transitioningCameraTargetStartTime = getCurrentTime();
  52634. }
  52635. }
  52636. }
  52637. };
  52638. }());
  52639. _defineProperty(this, "updateSplatMesh", function () {
  52640. var renderDimensions = new Vector2();
  52641. return function () {
  52642. if (!this.splatMesh) return;
  52643. var splatCount = this.splatMesh.getSplatCount();
  52644. if (splatCount > 0) {
  52645. this.splatMesh.updateTransforms();
  52646. this.getRenderDimensions(renderDimensions);
  52647. var focalLengthX = this.camera.projectionMatrix.elements[0] * 0.5 * this.devicePixelRatio * renderDimensions.x;
  52648. var focalLengthY = this.camera.projectionMatrix.elements[5] * 0.5 * this.devicePixelRatio * renderDimensions.y;
  52649. //this.camera.projectionMatrix.elements[0] 等效于 (2 * n) / (r - l),其中n是焦距(到近裁剪面的距离)。当它乘以0.5,然后再乘以renderDimensions.x(即视口宽度)时,你得到的是 (n * 宽度) / (r - l)。由于r - l等于宽度,最终就只剩下了n,即焦距。对于cameraFocalLengthY的计算应该得出相同的结果,所以实际上我只需要向updateUniforms()函数传递一个单独的焦距值即可。(see:https://github.com/mkkellogg/GaussianSplats3D/issues/108)
  52650. var focalMultiplier = this.camera.isOrthographicCamera ? 1.0 / this.devicePixelRatio : 1.0;
  52651. var focalAdjustment = this.focalAdjustment * focalMultiplier;
  52652. var inverseFocalAdjustment = 1.0 / focalAdjustment;
  52653. this.adjustForWebXRStereo(renderDimensions);
  52654. this.splatMesh.updateUniforms(renderDimensions, focalLengthX * focalAdjustment, focalLengthY * focalAdjustment, this.camera.isOrthographicCamera, this.camera.zoom || 1.0, inverseFocalAdjustment);
  52655. }
  52656. };
  52657. }());
  52658. /**
  52659. * Add one or more instances of SplatBuffer to the SplatMesh instance managed by the viewer and set up the sorting web worker.
  52660. * This function will terminate the existing sort worker (if there is one).
  52661. */
  52662. _defineProperty(this, "addSplatBuffers", function () {
  52663. return function (splatBuffers) {
  52664. var splatBufferOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  52665. var finalBuild = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
  52666. var showLoadingUI = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
  52667. var showLoadingUIForSplatTreeBuild = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
  52668. if (this.isDisposingOrDisposed()) return Promise.resolve();
  52669. this.splatRenderReady = false;
  52670. var splatProcessingTaskId = null;
  52671. var finish = buildResults => {
  52672. if (this.isDisposingOrDisposed()) return;
  52673. if (splatProcessingTaskId !== null) {
  52674. this.loadingSpinner.removeTask(splatProcessingTaskId);
  52675. splatProcessingTaskId = null;
  52676. }
  52677. // If we aren't calculating the splat distances from the center on the GPU, the sorting worker needs splat centers and
  52678. // transform indexes so that it can calculate those distance values.
  52679. if (!this.gpuAcceleratedSort && this.sortWorker) {
  52680. this.sortWorker.postMessage({
  52681. 'centers': buildResults.centers.buffer,
  52682. 'transformIndexes': buildResults.sceneIndexes.buffer,
  52683. 'range': {
  52684. 'from': buildResults.from,
  52685. 'to': buildResults.to,
  52686. 'count': buildResults.count
  52687. }
  52688. });
  52689. }
  52690. this.splatRenderReady = true;
  52691. this.sortNeededForSceneChange = true;
  52692. };
  52693. return new Promise(resolve => {
  52694. if (showLoadingUI) {
  52695. splatProcessingTaskId = this.loadingSpinner.addTask('Processing splats...');
  52696. }
  52697. delayedExecute(() => {
  52698. if (this.isDisposingOrDisposed()) {
  52699. resolve();
  52700. } else {
  52701. var buildResults = this.addSplatBuffersToMesh(splatBuffers, splatBufferOptions, finalBuild, showLoadingUIForSplatTreeBuild);
  52702. var maxSplatCount = this.splatMesh.getMaxSplatCount();
  52703. if (this.sortWorker && this.sortWorker.maxSplatCount !== maxSplatCount) this.disposeSortWorker();
  52704. var sortWorkerSetupPromise = !this.sortWorker && maxSplatCount > 0 ? this.setupSortWorker(this.splatMesh) : Promise.resolve();
  52705. sortWorkerSetupPromise.then(() => {
  52706. finish(buildResults);
  52707. resolve();
  52708. });
  52709. }
  52710. }, true);
  52711. });
  52712. };
  52713. }());
  52714. _defineProperty(this, "shouldRender", function () {
  52715. var renderCount = 0;
  52716. var lastCameraPosition = new Vector3();
  52717. var lastCameraOrientation = new Quaternion();
  52718. var changeEpsilon = 0.0001;
  52719. return function () {
  52720. var shouldRender = false;
  52721. var cameraChanged = false;
  52722. if (this.camera) {
  52723. var cp = this.camera.position;
  52724. var co = this.camera.quaternion;
  52725. cameraChanged = Math.abs(cp.x - lastCameraPosition.x) > changeEpsilon || Math.abs(cp.y - lastCameraPosition.y) > changeEpsilon || Math.abs(cp.z - lastCameraPosition.z) > changeEpsilon || Math.abs(co.x - lastCameraOrientation.x) > changeEpsilon || Math.abs(co.y - lastCameraOrientation.y) > changeEpsilon || Math.abs(co.z - lastCameraOrientation.z) > changeEpsilon || Math.abs(co.w - lastCameraOrientation.w) > changeEpsilon;
  52726. }
  52727. shouldRender = this.renderMode !== RenderMode.Never && (renderCount === 0 || this.splatMesh.visibleRegionChanging || cameraChanged || this.renderMode === RenderMode.Always || this.dynamicMode === true || this.renderNextFrame);
  52728. if (this.camera) {
  52729. lastCameraPosition.copy(this.camera.position);
  52730. lastCameraOrientation.copy(this.camera.quaternion);
  52731. }
  52732. renderCount++;
  52733. return shouldRender;
  52734. };
  52735. }());
  52736. _defineProperty(this, "render", function () {
  52737. return function () {
  52738. if (!this.initialized || !this.splatRenderReady) return;
  52739. var hasRenderables = threeScene => {
  52740. for (var child of threeScene.children) {
  52741. if (child.visible) return true;
  52742. }
  52743. return false;
  52744. };
  52745. var oldLayer = this.camera.layers.mask;
  52746. this.camera.layers.set(0); //xzw add
  52747. var savedAuoClear = this.renderer.autoClear;
  52748. /* if (hasRenderables(this.threeScene)) {//xzw
  52749. this.renderer.render(this.threeScene, this.camera);
  52750. this.renderer.autoClear = false;
  52751. } */
  52752. this.renderer.render(this.splatMesh, this.camera);
  52753. this.renderer.autoClear = false;
  52754. if (this.sceneHelper.getFocusMarkerOpacity() > 0.0) this.renderer.render(this.sceneHelper.focusMarker, this.camera);
  52755. if (this.showControlPlane) this.renderer.render(this.sceneHelper.controlPlane, this.camera);
  52756. this.renderer.autoClear = savedAuoClear;
  52757. this.camera.layers.mask = oldLayer;
  52758. };
  52759. }());
  52760. _defineProperty(this, "updateFPS", function () {
  52761. var lastCalcTime = getCurrentTime();
  52762. var frameCount = 0;
  52763. return function () {
  52764. if (this.consecutiveRenderFrames > CONSECUTIVE_RENDERED_FRAMES_FOR_FPS_CALCULATION) {
  52765. var currentTime = getCurrentTime();
  52766. var calcDelta = currentTime - lastCalcTime;
  52767. if (calcDelta >= 1.0) {
  52768. this.currentFPS = frameCount;
  52769. frameCount = 0;
  52770. lastCalcTime = currentTime;
  52771. } else {
  52772. frameCount++;
  52773. }
  52774. } else {
  52775. this.currentFPS = null;
  52776. }
  52777. };
  52778. }());
  52779. _defineProperty(this, "updateForRendererSizeChanges", function () {
  52780. var lastRendererSize = new Vector2();
  52781. var currentRendererSize = new Vector2();
  52782. var lastCameraOrthographic;
  52783. return function () {
  52784. if (!this.usingExternalCamera) {
  52785. this.renderer.getSize(currentRendererSize);
  52786. if (lastCameraOrthographic === undefined || lastCameraOrthographic !== this.camera.isOrthographicCamera || currentRendererSize.x !== lastRendererSize.x || currentRendererSize.y !== lastRendererSize.y) {
  52787. if (this.camera.isOrthographicCamera) {
  52788. this.camera.left = -currentRendererSize.x / 2.0;
  52789. this.camera.right = currentRendererSize.x / 2.0;
  52790. this.camera.top = currentRendererSize.y / 2.0;
  52791. this.camera.bottom = -currentRendererSize.y / 2.0;
  52792. } else {
  52793. this.camera.aspect = currentRendererSize.x / currentRendererSize.y;
  52794. }
  52795. this.camera.updateProjectionMatrix();
  52796. lastRendererSize.copy(currentRendererSize);
  52797. lastCameraOrthographic = this.camera.isOrthographicCamera;
  52798. }
  52799. }
  52800. };
  52801. }());
  52802. _defineProperty(this, "timingSensitiveUpdates", function () {
  52803. var lastUpdateTime;
  52804. return function () {
  52805. var currentTime = getCurrentTime();
  52806. if (!lastUpdateTime) lastUpdateTime = currentTime;
  52807. var timeDelta = currentTime - lastUpdateTime;
  52808. this.updateCameraTransition(currentTime);
  52809. this.updateFocusMarker(timeDelta);
  52810. lastUpdateTime = currentTime;
  52811. };
  52812. }());
  52813. _defineProperty(this, "updateCameraTransition", function () {
  52814. var tempCameraTarget = new Vector3();
  52815. var toPreviousTarget = new Vector3();
  52816. var toNextTarget = new Vector3();
  52817. return function (currentTime) {
  52818. if (this.transitioningCameraTarget) {
  52819. toPreviousTarget.copy(this.previousCameraTarget).sub(this.camera.position).normalize();
  52820. toNextTarget.copy(this.nextCameraTarget).sub(this.camera.position).normalize();
  52821. var rotationAngle = Math.acos(toPreviousTarget.dot(toNextTarget));
  52822. var rotationSpeed = rotationAngle / (Math.PI / 3) * .65 + .3;
  52823. var t = rotationSpeed / rotationAngle * (currentTime - this.transitioningCameraTargetStartTime);
  52824. tempCameraTarget.copy(this.previousCameraTarget).lerp(this.nextCameraTarget, t);
  52825. this.camera.lookAt(tempCameraTarget);
  52826. this.controls.target.copy(tempCameraTarget);
  52827. if (t >= 1.0) {
  52828. this.transitioningCameraTarget = false;
  52829. }
  52830. }
  52831. };
  52832. }());
  52833. _defineProperty(this, "updateFocusMarker", function () {
  52834. var renderDimensions = new Vector2();
  52835. var wasTransitioning = false;
  52836. return function (timeDelta) {
  52837. this.getRenderDimensions(renderDimensions);
  52838. if (this.transitioningCameraTarget) {
  52839. this.sceneHelper.setFocusMarkerVisibility(true);
  52840. var currentFocusMarkerOpacity = Math.max(this.sceneHelper.getFocusMarkerOpacity(), 0.0);
  52841. var newFocusMarkerOpacity = Math.min(currentFocusMarkerOpacity + FOCUS_MARKER_FADE_IN_SPEED * timeDelta, 1.0);
  52842. this.sceneHelper.setFocusMarkerOpacity(newFocusMarkerOpacity);
  52843. this.sceneHelper.updateFocusMarker(this.nextCameraTarget, this.camera, renderDimensions);
  52844. wasTransitioning = true;
  52845. this.forceRenderNextFrame();
  52846. } else {
  52847. var _currentFocusMarkerOpacity;
  52848. if (wasTransitioning) _currentFocusMarkerOpacity = 1.0;else _currentFocusMarkerOpacity = Math.min(this.sceneHelper.getFocusMarkerOpacity(), 1.0);
  52849. if (_currentFocusMarkerOpacity > 0) {
  52850. this.sceneHelper.updateFocusMarker(this.nextCameraTarget, this.camera, renderDimensions);
  52851. var _newFocusMarkerOpacity = Math.max(_currentFocusMarkerOpacity - FOCUS_MARKER_FADE_OUT_SPEED * timeDelta, 0.0);
  52852. this.sceneHelper.setFocusMarkerOpacity(_newFocusMarkerOpacity);
  52853. if (_newFocusMarkerOpacity === 0.0) this.sceneHelper.setFocusMarkerVisibility(false);
  52854. }
  52855. if (_currentFocusMarkerOpacity > 0.0) this.forceRenderNextFrame();
  52856. wasTransitioning = false;
  52857. }
  52858. };
  52859. }());
  52860. _defineProperty(this, "updateMeshCursor", function () {
  52861. var outHits = [];
  52862. var renderDimensions = new Vector2();
  52863. return function () {
  52864. if (this.showMeshCursor) {
  52865. this.forceRenderNextFrame();
  52866. this.getRenderDimensions(renderDimensions);
  52867. outHits.length = 0;
  52868. this.raycaster.setFromCameraAndScreenPosition(this.camera, this.mousePosition, renderDimensions);
  52869. this.raycaster.intersectSplatMesh(this.splatMesh, outHits);
  52870. if (outHits.length > 0) {
  52871. this.sceneHelper.setMeshCursorVisibility(true);
  52872. this.sceneHelper.positionAndOrientMeshCursor(outHits[0].origin, this.camera);
  52873. } else {
  52874. this.sceneHelper.setMeshCursorVisibility(false);
  52875. }
  52876. } else {
  52877. if (this.sceneHelper.getMeschCursorVisibility()) this.forceRenderNextFrame();
  52878. this.sceneHelper.setMeshCursorVisibility(false);
  52879. }
  52880. };
  52881. }());
  52882. _defineProperty(this, "updateInfoPanel", function () {
  52883. var renderDimensions = new Vector2();
  52884. return function () {
  52885. if (!this.showInfo) return;
  52886. var splatCount = this.splatMesh.getSplatCount();
  52887. this.getRenderDimensions(renderDimensions);
  52888. var cameraLookAtPosition = this.controls ? this.controls.target : null;
  52889. var meshCursorPosition = this.showMeshCursor ? this.sceneHelper.meshCursor.position : null;
  52890. var splatRenderCountPct = splatCount > 0 ? this.splatRenderCount / splatCount * 100 : 0;
  52891. this.infoPanel.update(renderDimensions, this.camera.position, cameraLookAtPosition, this.camera.up, this.camera.isOrthographicCamera, meshCursorPosition, this.currentFPS || 'N/A', splatCount, this.splatRenderCount, splatRenderCountPct, this.lastSortTime, this.focalAdjustment, this.splatMesh.getSplatScale(), this.splatMesh.getPointCloudModeEnabled());
  52892. };
  52893. }());
  52894. _defineProperty(this, "updateSplatSort", function () {
  52895. var mvpMatrix = new Matrix4();
  52896. var cameraPositionArray = [];
  52897. var lastSortViewDir = new Vector3(0, 0, -1);
  52898. var sortViewDir = new Vector3(0, 0, -1);
  52899. var lastSortViewPos = new Vector3();
  52900. var sortViewOffset = new Vector3();
  52901. var queuedSorts = [];
  52902. var partialSorts = [{
  52903. 'angleThreshold': 0.55,
  52904. 'sortFractions': [0.125, 0.33333, 0.75]
  52905. }, {
  52906. 'angleThreshold': 0.65,
  52907. 'sortFractions': [0.33333, 0.66667]
  52908. }, {
  52909. 'angleThreshold': 0.8,
  52910. 'sortFractions': [0.5]
  52911. }];
  52912. return async function () {
  52913. var force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  52914. if (this.sortRunning) return;
  52915. if (this.splatMesh.getSplatCount() <= 0) return;
  52916. var angleDiff = 0;
  52917. var positionDiff = 0;
  52918. var needsRefreshForRotation = false;
  52919. var needsRefreshForPosition = false;
  52920. sortViewDir.set(0, 0, -1).applyQuaternion(this.camera.quaternion);
  52921. angleDiff = sortViewDir.dot(lastSortViewDir);
  52922. positionDiff = sortViewOffset.copy(this.camera.position).sub(lastSortViewPos).length();
  52923. if (!force) {
  52924. if (!this.sortNeededForSceneChange && !this.splatMesh.dynamicMode && queuedSorts.length === 0) {
  52925. if (angleDiff <= 0.99) needsRefreshForRotation = true;
  52926. if (positionDiff >= 1.0) needsRefreshForPosition = true;
  52927. if (!needsRefreshForRotation && !needsRefreshForPosition) return;
  52928. }
  52929. }
  52930. this.sortRunning = true;
  52931. var {
  52932. splatRenderCount,
  52933. shouldSortAll
  52934. } = this.gatherSceneNodesForSort();
  52935. this.splatRenderCount = splatRenderCount;
  52936. mvpMatrix.copy(this.camera.matrixWorld).invert();
  52937. var mvpCamera = this.perspectiveCamera || this.camera;
  52938. mvpMatrix.premultiply(mvpCamera.projectionMatrix);
  52939. mvpMatrix.multiply(this.splatMesh.matrixWorld);
  52940. if (this.gpuAcceleratedSort && (queuedSorts.length <= 1 || queuedSorts.length % 2 === 0)) {
  52941. await this.splatMesh.computeDistancesOnGPU(mvpMatrix, this.sortWorkerPrecomputedDistances);
  52942. }
  52943. if (this.splatMesh.dynamicMode || shouldSortAll) {
  52944. queuedSorts.push(this.splatRenderCount);
  52945. } else {
  52946. if (queuedSorts.length === 0) {
  52947. for (var partialSort of partialSorts) {
  52948. if (angleDiff < partialSort.angleThreshold) {
  52949. for (var sortFraction of partialSort.sortFractions) {
  52950. queuedSorts.push(Math.floor(this.splatRenderCount * sortFraction));
  52951. }
  52952. break;
  52953. }
  52954. }
  52955. queuedSorts.push(this.splatRenderCount);
  52956. }
  52957. }
  52958. var sortCount = Math.min(queuedSorts.shift(), this.splatRenderCount);
  52959. cameraPositionArray[0] = this.camera.position.x;
  52960. cameraPositionArray[1] = this.camera.position.y;
  52961. cameraPositionArray[2] = this.camera.position.z;
  52962. var sortMessage = {
  52963. 'modelViewProj': mvpMatrix.elements,
  52964. 'cameraPosition': cameraPositionArray,
  52965. 'splatRenderCount': this.splatRenderCount,
  52966. 'splatSortCount': sortCount,
  52967. 'usePrecomputedDistances': this.gpuAcceleratedSort
  52968. };
  52969. if (this.splatMesh.dynamicMode) {
  52970. this.splatMesh.fillTransformsArray(this.sortWorkerTransforms);
  52971. }
  52972. if (!this.sharedMemoryForWorkers) {
  52973. sortMessage.indexesToSort = this.sortWorkerIndexesToSort;
  52974. sortMessage.transforms = this.sortWorkerTransforms;
  52975. if (this.gpuAcceleratedSort) {
  52976. sortMessage.precomputedDistances = this.sortWorkerPrecomputedDistances;
  52977. }
  52978. }
  52979. this.sortPromise = new Promise(resolve => {
  52980. this.sortPromiseResolver = resolve;
  52981. });
  52982. this.sortWorker.postMessage({
  52983. 'sort': sortMessage
  52984. });
  52985. if (queuedSorts.length === 0) {
  52986. lastSortViewPos.copy(this.camera.position);
  52987. lastSortViewDir.copy(sortViewDir);
  52988. }
  52989. this.sortNeededForSceneChange = false;
  52990. };
  52991. }());
  52992. /**
  52993. * Determine which splats to render by checking which are inside or close to the view frustum
  52994. */
  52995. _defineProperty(this, "gatherSceneNodesForSort", function () {
  52996. var nodeRenderList = [];
  52997. var allSplatsSortBuffer = null;
  52998. var tempVectorYZ = new Vector3();
  52999. var tempVectorXZ = new Vector3();
  53000. var tempVector = new Vector3();
  53001. var modelView = new Matrix4();
  53002. var baseModelView = new Matrix4();
  53003. var sceneTransform = new Matrix4();
  53004. var renderDimensions = new Vector3();
  53005. var forward = new Vector3(0, 0, -1);
  53006. var tempMax = new Vector3();
  53007. var nodeSize = node => {
  53008. return tempMax.copy(node.max).sub(node.min).length();
  53009. };
  53010. return function () {
  53011. var gatherAllNodes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  53012. this.getRenderDimensions(renderDimensions);
  53013. var cameraFocalLength = renderDimensions.y / 2.0 / Math.tan(this.camera.fov / 2.0 * MathUtils.DEG2RAD);
  53014. var fovXOver2 = Math.atan(renderDimensions.x / 2.0 / cameraFocalLength);
  53015. var fovYOver2 = Math.atan(renderDimensions.y / 2.0 / cameraFocalLength);
  53016. var cosFovXOver2 = Math.cos(fovXOver2);
  53017. var cosFovYOver2 = Math.cos(fovYOver2);
  53018. var splatTree = this.splatMesh.getSplatTree();
  53019. if (splatTree) {
  53020. baseModelView.copy(this.camera.matrixWorld).invert();
  53021. baseModelView.multiply(this.splatMesh.matrixWorld);
  53022. var nodeRenderCount = 0;
  53023. var splatRenderCount = 0;
  53024. for (var s = 0; s < splatTree.subTrees.length; s++) {
  53025. var subTree = splatTree.subTrees[s];
  53026. modelView.copy(baseModelView);
  53027. if (this.splatMesh.dynamicMode) {
  53028. this.splatMesh.getSceneTransform(s, sceneTransform);
  53029. modelView.multiply(sceneTransform);
  53030. }
  53031. var nodeCount = subTree.nodesWithIndexes.length;
  53032. for (var i = 0; i < nodeCount; i++) {
  53033. var node = subTree.nodesWithIndexes[i];
  53034. if (!node.data || !node.data.indexes || node.data.indexes.length === 0) continue;
  53035. tempVector.copy(node.center).applyMatrix4(modelView);
  53036. var distanceToNode = tempVector.length();
  53037. tempVector.normalize();
  53038. tempVectorYZ.copy(tempVector).setX(0).normalize();
  53039. tempVectorXZ.copy(tempVector).setY(0).normalize();
  53040. var cameraAngleXZDot = forward.dot(tempVectorXZ);
  53041. var cameraAngleYZDot = forward.dot(tempVectorYZ);
  53042. var ns = nodeSize(node);
  53043. var outOfFovY = cameraAngleYZDot < cosFovYOver2 - .6; //角度超出
  53044. var outOfFovX = cameraAngleXZDot < cosFovXOver2 - .6;
  53045. if (!gatherAllNodes && (outOfFovX || outOfFovY) && distanceToNode > ns) {
  53046. continue;
  53047. }
  53048. splatRenderCount += node.data.indexes.length;
  53049. nodeRenderList[nodeRenderCount] = node;
  53050. node.data.distanceToNode = distanceToNode;
  53051. nodeRenderCount++;
  53052. }
  53053. }
  53054. nodeRenderList.length = nodeRenderCount;
  53055. nodeRenderList.sort((a, b) => {
  53056. //从近到远排序。去掉后也不影响,毕竟之后还要sort index
  53057. if (a.data.distanceToNode < b.data.distanceToNode) return -1;else return 1;
  53058. });
  53059. //将要渲染的点的index写入sortWorkerIndexesToSort的buffer
  53060. var currentByteOffset = splatRenderCount * Constants.BytesPerInt;
  53061. for (var _i21 = 0; _i21 < nodeRenderCount; _i21++) {
  53062. var _node = nodeRenderList[_i21];
  53063. var windowSizeInts = _node.data.indexes.length;
  53064. var windowSizeBytes = windowSizeInts * Constants.BytesPerInt;
  53065. var destView = new Uint32Array(this.sortWorkerIndexesToSort.buffer,
  53066. //写入sortWorkerIndexesToSort
  53067. currentByteOffset - windowSizeBytes, windowSizeInts);
  53068. destView.set(_node.data.indexes);
  53069. currentByteOffset -= windowSizeBytes;
  53070. }
  53071. return {
  53072. 'splatRenderCount': splatRenderCount,
  53073. 'shouldSortAll': false
  53074. };
  53075. } else {
  53076. var totalSplatCount = this.splatMesh.getSplatCount();
  53077. if (!allSplatsSortBuffer || allSplatsSortBuffer.length !== totalSplatCount) {
  53078. allSplatsSortBuffer = new Uint32Array(totalSplatCount);
  53079. for (var _i22 = 0; _i22 < totalSplatCount; _i22++) {
  53080. allSplatsSortBuffer[_i22] = _i22;
  53081. }
  53082. }
  53083. this.sortWorkerIndexesToSort.set(allSplatsSortBuffer);
  53084. return {
  53085. 'splatRenderCount': totalSplatCount,
  53086. 'shouldSortAll': true
  53087. };
  53088. }
  53089. };
  53090. }());
  53091. // The natural 'up' vector for viewing the scene (only has an effect when used with orbit controls and
  53092. // when the viewer uses its own camera).
  53093. if (!options.cameraUp) options.cameraUp = [0, 1, 0];
  53094. this.cameraUp = new Vector3().fromArray(options.cameraUp);
  53095. // The camera's initial position (only used when the viewer uses its own camera).
  53096. if (!options.initialCameraPosition) options.initialCameraPosition = [0, 10, 15];
  53097. this.initialCameraPosition = new Vector3().fromArray(options.initialCameraPosition);
  53098. // The initial focal point of the camera and center of the camera's orbit (only used when the viewer uses its own camera).
  53099. if (!options.initialCameraLookAt) options.initialCameraLookAt = [0, 0, 0];
  53100. this.initialCameraLookAt = new Vector3().fromArray(options.initialCameraLookAt);
  53101. // 'dropInMode' is a flag that is used internally to support the usage of the viewer as a Three.js scene object
  53102. this.dropInMode = options.dropInMode || false;
  53103. // If 'selfDrivenMode' is true, the viewer manages its own update/animation loop via requestAnimationFrame()
  53104. if (options.selfDrivenMode === undefined || options.selfDrivenMode === null) options.selfDrivenMode = true;
  53105. this.selfDrivenMode = options.selfDrivenMode && !this.dropInMode;
  53106. this.selfDrivenUpdateFunc = this.selfDrivenUpdate.bind(this);
  53107. // If 'useBuiltInControls' is true, the viewer will create its own instance of OrbitControls and attach to the camera
  53108. if (options.useBuiltInControls === undefined) options.useBuiltInControls = true;
  53109. this.useBuiltInControls = options.useBuiltInControls;
  53110. // parent element of the Three.js renderer canvas
  53111. this.rootElement = options.rootElement;
  53112. // Tells the viewer to pretend the device pixel ratio is 1, which can boost performance on devices where it is larger,
  53113. // at a small cost to visual quality
  53114. this.ignoreDevicePixelRatio = options.ignoreDevicePixelRatio || false;
  53115. this.devicePixelRatio = this.ignoreDevicePixelRatio ? 1 : window.devicePixelRatio;
  53116. // Tells the viewer to use 16-bit floating point values when storing splat covariance data in textures, instead of 32-bit
  53117. this.halfPrecisionCovariancesOnGPU = options.halfPrecisionCovariancesOnGPU || false;
  53118. // If 'threeScene' is valid, it will be rendered by the viewer along with the splat mesh
  53119. this.threeScene = options.threeScene;
  53120. // Allows for usage of an external Three.js renderer
  53121. this.renderer = options.renderer;
  53122. // Allows for usage of an external Three.js camera
  53123. this.camera = options.camera;
  53124. // If 'gpuAcceleratedSort' is true, a partially GPU-accelerated approach to sorting splats will be used.
  53125. // Currently this means pre-computing splat distances from the camera on the GPU
  53126. this.gpuAcceleratedSort = options.gpuAcceleratedSort || false;
  53127. // if 'integerBasedSort' is true, the integer version of splat centers as well as other values used to calculate
  53128. // splat distances are used instead of the float version. This speeds up computation, but introduces the possibility of
  53129. // overflow in larger scenes.
  53130. if (options.integerBasedSort === undefined || options.integerBasedSort === null) {
  53131. options.integerBasedSort = true;
  53132. }
  53133. this.integerBasedSort = options.integerBasedSort;
  53134. // If 'sharedMemoryForWorkers' is true, a SharedArrayBuffer will be used to communicate with web workers. This method
  53135. // is faster than copying memory to or from web workers, but comes with security implications as outlined here:
  53136. // https://web.dev/articles/cross-origin-isolation-guide
  53137. // If enabled, it requires specific CORS headers to be present in the response from the server that is sent when
  53138. // loading the application. More information is available in the README.
  53139. if (options.sharedMemoryForWorkers === undefined || options.sharedMemoryForWorkers === null) options.sharedMemoryForWorkers = true;
  53140. this.sharedMemoryForWorkers = options.sharedMemoryForWorkers;
  53141. // if 'dynamicScene' is true, it tells the viewer to assume scene elements are not stationary or that the number of splats in the
  53142. // scene may change. This prevents optimizations that depend on a static scene from being made. Additionally, if 'dynamicScene' is
  53143. // true it tells the splat mesh to not apply scene tranforms to splat data that is returned by functions like
  53144. // SplatMesh.getSplatCenter() by default.
  53145. this.dynamicScene = !!options.dynamicScene;
  53146. // When true, will perform additional steps during rendering to address artifacts caused by the rendering of gaussians at a
  53147. // substantially different resolution than that at which they were rendered during training. This will only work correctly
  53148. // for models that were trained using a process that utilizes this compensation calculation. For more details:
  53149. // https://github.com/nerfstudio-project/gsplat/pull/117
  53150. // https://github.com/graphdeco-inria/gaussian-splatting/issues/294#issuecomment-1772688093
  53151. this.antialiased = options.antialiased || false;
  53152. this.webXRMode = options.webXRMode || WebXRMode.None;
  53153. if (this.webXRMode !== WebXRMode.None) {
  53154. this.gpuAcceleratedSort = false;
  53155. }
  53156. this.webXRActive = false;
  53157. // if 'renderMode' is RenderMode.Always, then the viewer will rrender the scene on every update. If it is RenderMode.OnChange,
  53158. // it will only render when something in the scene has changed.
  53159. this.renderMode = options.renderMode || RenderMode.Always;
  53160. // SceneRevealMode.Default results in a nice, slow fade-in effect for progressively loaded scenes,
  53161. // and a fast fade-in for non progressively loaded scenes.
  53162. // SceneRevealMode.Gradual will force a slow fade-in for all scenes.
  53163. // SceneRevealMode.Instant will force all loaded scene data to be immediately visible.
  53164. this.sceneRevealMode = options.sceneRevealMode || SceneRevealMode.Default;
  53165. // Hacky, experimental, non-scientific parameter for tweaking focal length related calculations. For scenes with very
  53166. // small gaussians, small details, and small dimensions -- increasing this value can help improve visual quality.
  53167. this.focalAdjustment = options.focalAdjustment || 1.0;
  53168. // Specify the maximum screen-space splat size, can help deal with large splats that get too unwieldy
  53169. this.maxScreenSpaceSplatSize = options.maxScreenSpaceSplatSize || 2048;
  53170. // The verbosity of console logging
  53171. this.logLevel = options.logLevel || LogLevel.None;
  53172. // Degree of spherical harmonics to utilize in rendering splats (assuming the data is present in the splat scene).
  53173. // Valid values are 0 - 3. Default value is 0.
  53174. this.sphericalHarmonicsDegree = options.sphericalHarmonicsDegree || 0;
  53175. this.createSplatMesh();
  53176. this.controls = null;
  53177. this.perspectiveControls = null;
  53178. this.orthographicControls = null;
  53179. this.orthographicCamera = null;
  53180. this.perspectiveCamera = null;
  53181. this.showMeshCursor = false;
  53182. this.showControlPlane = false;
  53183. this.showInfo = false;
  53184. this.sceneHelper = null;
  53185. this.sortWorker = null;
  53186. this.sortRunning = false;
  53187. this.splatRenderCount = 0;
  53188. this.sortWorkerIndexesToSort = null;
  53189. this.sortWorkerSortedIndexes = null;
  53190. this.sortWorkerPrecomputedDistances = null;
  53191. this.sortWorkerTransforms = null;
  53192. this.runAfterFirstSort = [];
  53193. this.selfDrivenModeRunning = false;
  53194. this.splatRenderReady = false;
  53195. this.raycaster = new Raycaster$1();
  53196. this.infoPanel = null;
  53197. this.startInOrthographicMode = false;
  53198. this.currentFPS = 0;
  53199. this.lastSortTime = 0;
  53200. this.consecutiveRenderFrames = 0;
  53201. this.previousCameraTarget = new Vector3();
  53202. this.nextCameraTarget = new Vector3();
  53203. this.mousePosition = new Vector2();
  53204. this.mouseDownPosition = new Vector2();
  53205. this.mouseDownTime = null;
  53206. this.resizeObserver = null;
  53207. this.mouseMoveListener = null;
  53208. this.mouseDownListener = null;
  53209. this.mouseUpListener = null;
  53210. this.keyDownListener = null;
  53211. this.sortPromise = null;
  53212. this.sortPromiseResolver = null;
  53213. this.splatSceneDownloadPromises = {};
  53214. this.splatSceneDownloadAndBuildPromise = null;
  53215. this.splatSceneRemovalPromise = null;
  53216. this.loadingSpinner = new LoadingSpinner(null, this.rootElement || document.body);
  53217. this.loadingSpinner.hide();
  53218. this.loadingProgressBar = new LoadingProgressBar(this.rootElement || document.body);
  53219. this.loadingProgressBar.hide();
  53220. this.infoPanel = new InfoPanel(this.rootElement || document.body);
  53221. this.infoPanel.hide();
  53222. this.usingExternalCamera = this.dropInMode || this.camera ? true : false;
  53223. this.usingExternalRenderer = this.dropInMode || this.renderer ? true : false;
  53224. this.initialized = false;
  53225. this.disposing = false;
  53226. this.disposed = false;
  53227. if (!this.dropInMode) this.init();
  53228. }
  53229. createSplatMesh() {
  53230. this.splatMesh = new SplatMesh(this.dynamicScene, this.halfPrecisionCovariancesOnGPU, this.devicePixelRatio, this.gpuAcceleratedSort, this.integerBasedSort, this.antialiased, this.maxScreenSpaceSplatSize, this.logLevel, this.sphericalHarmonicsDegree);
  53231. this.splatMesh.frustumCulled = false;
  53232. }
  53233. init() {
  53234. if (this.initialized) return;
  53235. if (!this.rootElement) {
  53236. if (!this.usingExternalRenderer) {
  53237. this.rootElement = document.createElement('div');
  53238. this.rootElement.style.width = '100%';
  53239. this.rootElement.style.height = '100%';
  53240. this.rootElement.style.position = 'absolute';
  53241. document.body.appendChild(this.rootElement);
  53242. } else {
  53243. this.rootElement = this.renderer.domElement.parentElement || document.body;
  53244. }
  53245. }
  53246. this.setupCamera();
  53247. this.setupRenderer();
  53248. this.setupWebXR();
  53249. this.setupControls();
  53250. this.setupEventHandlers();
  53251. this.threeScene = this.threeScene || new Scene();
  53252. this.sceneHelper = new SceneHelper(this.threeScene);
  53253. this.sceneHelper.setupMeshCursor();
  53254. this.sceneHelper.setupFocusMarker();
  53255. this.sceneHelper.setupControlPlane();
  53256. this.loadingProgressBar.setContainer(this.rootElement);
  53257. this.loadingSpinner.setContainer(this.rootElement);
  53258. this.infoPanel.setContainer(this.rootElement);
  53259. this.initialized = true;
  53260. }
  53261. setupCamera() {
  53262. if (!this.usingExternalCamera) {
  53263. var renderDimensions = new Vector2();
  53264. this.getRenderDimensions(renderDimensions);
  53265. this.perspectiveCamera = new PerspectiveCamera(THREE_CAMERA_FOV, renderDimensions.x / renderDimensions.y, 0.1, 1000);
  53266. this.orthographicCamera = new OrthographicCamera(renderDimensions.x / -2, renderDimensions.x / 2, renderDimensions.y / 2, renderDimensions.y / -2, 0.1, 1000);
  53267. this.camera = this.startInOrthographicMode ? this.orthographicCamera : this.perspectiveCamera;
  53268. this.camera.position.copy(this.initialCameraPosition);
  53269. this.camera.up.copy(this.cameraUp).normalize();
  53270. this.camera.lookAt(this.initialCameraLookAt);
  53271. }
  53272. }
  53273. setupRenderer() {
  53274. if (!this.usingExternalRenderer) {
  53275. var renderDimensions = new Vector2();
  53276. this.getRenderDimensions(renderDimensions);
  53277. this.renderer = new WebGLRenderer({
  53278. antialias: false,
  53279. precision: 'highp'
  53280. });
  53281. this.renderer.setPixelRatio(this.devicePixelRatio);
  53282. this.renderer.autoClear = true;
  53283. this.renderer.setClearColor(new Color(0x000000), 0.0);
  53284. this.renderer.setSize(renderDimensions.x, renderDimensions.y);
  53285. this.resizeObserver = new ResizeObserver(() => {
  53286. this.getRenderDimensions(renderDimensions);
  53287. this.renderer.setSize(renderDimensions.x, renderDimensions.y);
  53288. this.forceRenderNextFrame();
  53289. });
  53290. this.resizeObserver.observe(this.rootElement);
  53291. this.rootElement.appendChild(this.renderer.domElement);
  53292. }
  53293. }
  53294. setupWebXR() {
  53295. if (this.webXRMode) {
  53296. if (this.webXRMode === WebXRMode.VR) {
  53297. this.rootElement.appendChild(VRButton.createButton(this.renderer));
  53298. } else if (this.webXRMode === WebXRMode.AR) {
  53299. this.rootElement.appendChild(ARButton.createButton(this.renderer));
  53300. }
  53301. this.renderer.xr.addEventListener('sessionstart', e => {
  53302. this.webXRActive = true;
  53303. });
  53304. this.renderer.xr.addEventListener('sessionend', e => {
  53305. this.webXRActive = false;
  53306. });
  53307. this.renderer.xr.enabled = true;
  53308. this.camera.position.copy(this.initialCameraPosition);
  53309. this.camera.up.copy(this.cameraUp).normalize();
  53310. this.camera.lookAt(this.initialCameraLookAt);
  53311. }
  53312. }
  53313. setupControls() {
  53314. if (this.useBuiltInControls && this.webXRMode === WebXRMode.None) {
  53315. if (!this.usingExternalCamera) {
  53316. this.perspectiveControls = new OrbitControls(this.perspectiveCamera, this.renderer.domElement);
  53317. this.orthographicControls = new OrbitControls(this.orthographicCamera, this.renderer.domElement);
  53318. } else {
  53319. if (this.camera.isOrthographicCamera) {
  53320. this.orthographicControls = new OrbitControls(this.camera, this.renderer.domElement);
  53321. } else {
  53322. this.perspectiveControls = new OrbitControls(this.camera, this.renderer.domElement);
  53323. }
  53324. }
  53325. for (var controls of [this.perspectiveControls, this.orthographicControls]) {
  53326. if (controls) {
  53327. controls.listenToKeyEvents(window);
  53328. controls.rotateSpeed = 0.5;
  53329. controls.maxPolarAngle = Math.PI * .75;
  53330. controls.minPolarAngle = 0.1;
  53331. controls.enableDamping = true;
  53332. controls.dampingFactor = 0.05;
  53333. controls.target.copy(this.initialCameraLookAt);
  53334. }
  53335. }
  53336. this.controls = this.camera.isOrthographicCamera ? this.orthographicControls : this.perspectiveControls;
  53337. }
  53338. }
  53339. setupEventHandlers() {
  53340. if (this.useBuiltInControls && this.webXRMode === WebXRMode.None) {
  53341. this.mouseMoveListener = this.onMouseMove.bind(this);
  53342. this.renderer.domElement.addEventListener('pointermove', this.mouseMoveListener, false);
  53343. this.mouseDownListener = this.onMouseDown.bind(this);
  53344. this.renderer.domElement.addEventListener('pointerdown', this.mouseDownListener, false);
  53345. this.mouseUpListener = this.onMouseUp.bind(this);
  53346. this.renderer.domElement.addEventListener('pointerup', this.mouseUpListener, false);
  53347. this.keyDownListener = this.onKeyDown.bind(this);
  53348. window.addEventListener('keydown', this.keyDownListener, false);
  53349. }
  53350. }
  53351. removeEventHandlers() {
  53352. if (this.useBuiltInControls) {
  53353. this.renderer.domElement.removeEventListener('pointermove', this.mouseMoveListener);
  53354. this.mouseMoveListener = null;
  53355. this.renderer.domElement.removeEventListener('pointerdown', this.mouseDownListener);
  53356. this.mouseDownListener = null;
  53357. this.renderer.domElement.removeEventListener('pointerup', this.mouseUpListener);
  53358. this.mouseUpListener = null;
  53359. window.removeEventListener('keydown', this.keyDownListener);
  53360. this.keyDownListener = null;
  53361. }
  53362. }
  53363. setRenderMode(renderMode) {
  53364. this.renderMode = renderMode;
  53365. }
  53366. onMouseMove(mouse) {
  53367. this.mousePosition.set(mouse.offsetX, mouse.offsetY);
  53368. }
  53369. onMouseDown() {
  53370. this.mouseDownPosition.copy(this.mousePosition);
  53371. this.mouseDownTime = getCurrentTime();
  53372. }
  53373. onMouseClick(mouse) {
  53374. this.mousePosition.set(mouse.offsetX, mouse.offsetY);
  53375. this.checkForFocalPointChange();
  53376. }
  53377. getRenderDimensions(outDimensions) {
  53378. if (this.rootElement) {
  53379. outDimensions.x = this.rootElement.offsetWidth;
  53380. outDimensions.y = this.rootElement.offsetHeight;
  53381. } else {
  53382. this.renderer.getSize(outDimensions);
  53383. }
  53384. }
  53385. setOrthographicMode(orthographicMode) {
  53386. if (orthographicMode === this.camera.isOrthographicCamera) return;
  53387. var fromCamera = this.camera;
  53388. var toCamera = orthographicMode ? this.orthographicCamera : this.perspectiveCamera;
  53389. toCamera.position.copy(fromCamera.position);
  53390. toCamera.up.copy(fromCamera.up);
  53391. toCamera.rotation.copy(fromCamera.rotation);
  53392. toCamera.quaternion.copy(fromCamera.quaternion);
  53393. toCamera.matrix.copy(fromCamera.matrix);
  53394. this.camera = toCamera;
  53395. if (this.controls) {
  53396. var resetControls = controls => {
  53397. controls.saveState();
  53398. controls.reset();
  53399. };
  53400. var fromControls = this.controls;
  53401. var toControls = orthographicMode ? this.orthographicControls : this.perspectiveControls;
  53402. resetControls(toControls);
  53403. resetControls(fromControls);
  53404. toControls.target.copy(fromControls.target);
  53405. if (orthographicMode) {
  53406. Viewer.setCameraZoomFromPosition(toCamera, fromCamera, fromControls);
  53407. } else {
  53408. Viewer.setCameraPositionFromZoom(toCamera, fromCamera, toControls);
  53409. }
  53410. this.controls = toControls;
  53411. this.camera.lookAt(this.controls.target);
  53412. }
  53413. }
  53414. adjustForWebXRStereo(renderDimensions) {
  53415. // TODO: Figure out a less hacky way to determine if stereo rendering is active
  53416. if (this.camera && this.webXRActive) {
  53417. var xrCamera = this.renderer.xr.getCamera();
  53418. var xrCameraProj00 = xrCamera.projectionMatrix.elements[0];
  53419. var cameraProj00 = this.camera.projectionMatrix.elements[0];
  53420. renderDimensions.x *= cameraProj00 / xrCameraProj00;
  53421. }
  53422. }
  53423. isLoadingOrUnloading() {
  53424. return Object.keys(this.splatSceneDownloadPromises).length > 0 || this.splatSceneDownloadAndBuildPromise !== null || this.splatSceneRemovalPromise !== null;
  53425. }
  53426. isDisposingOrDisposed() {
  53427. return this.disposing || this.disposed;
  53428. }
  53429. addSplatSceneDownloadPromise(promise) {
  53430. this.splatSceneDownloadPromises[promise.id] = promise;
  53431. }
  53432. removeSplatSceneDownloadPromise(promise) {
  53433. delete this.splatSceneDownloadPromises[promise.id];
  53434. }
  53435. setSplatSceneDownloadAndBuildPromise(promise) {
  53436. this.splatSceneDownloadAndBuildPromise = promise;
  53437. }
  53438. clearSplatSceneDownloadAndBuildPromise() {
  53439. this.splatSceneDownloadAndBuildPromise = null;
  53440. }
  53441. /**
  53442. * Add a splat scene to the viewer and display any loading UI if appropriate.
  53443. * @param {string} path Path to splat scene to be loaded
  53444. * @param {object} options {
  53445. *
  53446. * splatAlphaRemovalThreshold: Ignore any splats with an alpha less than the specified
  53447. * value (valid range: 0 - 255), defaults to 1
  53448. *
  53449. * showLoadingUI: Display a loading spinner while the scene is loading, defaults to true
  53450. *
  53451. * position (Array<number>): Position of the scene, acts as an offset from its default position, defaults to [0, 0, 0]
  53452. *
  53453. * rotation (Array<number>): Rotation of the scene represented as a quaternion, defaults to [0, 0, 0, 1]
  53454. *
  53455. * scale (Array<number>): Scene's scale, defaults to [1, 1, 1]
  53456. *
  53457. * onProgress: Function to be called as file data are received, or other processing occurs
  53458. *
  53459. * }
  53460. * @return {AbortablePromise}
  53461. */
  53462. addSplatScene(path) {
  53463. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  53464. if (this.isLoadingOrUnloading()) {
  53465. throw new Error('Cannot add splat scene while another load or unload is already in progress.');
  53466. }
  53467. if (this.isDisposingOrDisposed()) {
  53468. throw new Error('Cannot add splat scene after dispose() is called.');
  53469. }
  53470. var format = options.format !== undefined && options.format !== null ? options.format : sceneFormatFromPath(path);
  53471. var streamBuildSections = Viewer.isStreamable(format) && options.streamView;
  53472. var showLoadingUI = options.showLoadingUI !== undefined && options.showLoadingUI !== null ? options.showLoadingUI : true;
  53473. var loadingUITaskId = null;
  53474. if (showLoadingUI) {
  53475. this.loadingSpinner.removeAllTasks();
  53476. loadingUITaskId = this.loadingSpinner.addTask('Downloading...');
  53477. }
  53478. var hideLoadingUI = () => {
  53479. this.loadingProgressBar.hide();
  53480. this.loadingSpinner.removeAllTasks();
  53481. };
  53482. var onProgressUIUpdate = (percentComplete, percentCompleteLabel, loaderStatus) => {
  53483. if (showLoadingUI) {
  53484. if (loaderStatus === LoaderStatus.Downloading) {
  53485. if (percentComplete == 100) {
  53486. this.loadingSpinner.setMessageForTask(loadingUITaskId, 'Download complete!');
  53487. } else {
  53488. if (streamBuildSections) {
  53489. this.loadingSpinner.setMessageForTask(loadingUITaskId, 'Downloading splats...');
  53490. } else {
  53491. var suffix = percentCompleteLabel ? ": ".concat(percentCompleteLabel) : "...";
  53492. this.loadingSpinner.setMessageForTask(loadingUITaskId, "Downloading".concat(suffix));
  53493. }
  53494. }
  53495. } else if (loaderStatus === LoaderStatus.Processing) {
  53496. this.loadingSpinner.setMessageForTask(loadingUITaskId, 'Processing splats...');
  53497. } else {
  53498. this.loadingSpinner.setMessageForTask(loadingUITaskId, 'Ready!');
  53499. }
  53500. }
  53501. };
  53502. var downloadDone = false;
  53503. var downloadedPercentage = 0;
  53504. var splatBuffersAddedUIUpdate = (firstBuild, finalBuild) => {
  53505. if (showLoadingUI) {
  53506. if (firstBuild && streamBuildSections || finalBuild && !streamBuildSections) {
  53507. this.runAfterFirstSort.push(() => {
  53508. this.loadingSpinner.removeTask(loadingUITaskId);
  53509. if (!finalBuild && !downloadDone) this.loadingProgressBar.show();
  53510. });
  53511. }
  53512. if (streamBuildSections) {
  53513. if (finalBuild) {
  53514. downloadDone = true;
  53515. this.loadingProgressBar.hide();
  53516. } else {
  53517. this.loadingProgressBar.setProgress(downloadedPercentage);
  53518. }
  53519. }
  53520. }
  53521. };
  53522. var onProgress = (percentComplete, percentCompleteLabel, loaderStatus) => {
  53523. downloadedPercentage = percentComplete;
  53524. onProgressUIUpdate(percentComplete, percentCompleteLabel, loaderStatus);
  53525. if (options.onProgress) options.onProgress(percentComplete, percentCompleteLabel, loaderStatus);
  53526. };
  53527. var buildSection = (splatBuffer, firstBuild, finalBuild) => {
  53528. if (!streamBuildSections && options.onProgress) options.onProgress(0, '0%', LoaderStatus.Processing);
  53529. var addSplatBufferOptions = {
  53530. 'rotation': options.rotation || options.orientation,
  53531. 'position': options.position,
  53532. 'scale': options.scale,
  53533. 'splatAlphaRemovalThreshold': options.splatAlphaRemovalThreshold
  53534. };
  53535. return this.addSplatBuffers([splatBuffer], [addSplatBufferOptions], finalBuild, firstBuild && showLoadingUI, showLoadingUI).then(() => {
  53536. if (!streamBuildSections && options.onProgress) options.onProgress(100, '100%', LoaderStatus.Processing);
  53537. splatBuffersAddedUIUpdate(firstBuild, finalBuild);
  53538. });
  53539. };
  53540. var loadFunc = streamBuildSections ? this.downloadAndBuildSingleSplatSceneStreaming.bind(this) : this.downloadAndBuildSingleSplatSceneNonStreaming.bind(this);
  53541. return loadFunc(path, format, options.splatAlphaRemovalThreshold, buildSection.bind(this), onProgress, hideLoadingUI.bind(this));
  53542. }
  53543. /**
  53544. * Download a single non-streamed splat scene, convert to splat buffer and then rebuild the viewer's splat mesh
  53545. * by calling 'buildFunc'. Also sets/clears relevant instance synchronization objects, and calls appropriate functions
  53546. * on success or failure.
  53547. * @param {string} path Path to splat scene to be loaded
  53548. * @param {SceneFormat} format Format of the splat scene file
  53549. * @param {number} splatAlphaRemovalThreshold Ignore any splats with an alpha less than the specified value (valid range: 0 - 255)
  53550. * @param {function} buildFunc Function to build the viewer's splat mesh with the downloaded splat buffer
  53551. * @param {function} onProgress Function to be called as file data are received, or other processing occurs
  53552. * @param {function} onException Function to be called when exception occurs
  53553. * @return {AbortablePromise}
  53554. */
  53555. downloadAndBuildSingleSplatSceneNonStreaming(path, format, splatAlphaRemovalThreshold, buildFunc, onProgress, onException) {
  53556. var downloadPromise = this.downloadSplatSceneToSplatBuffer(path, splatAlphaRemovalThreshold, onProgress, false, undefined, format).then(splatBuffer => {
  53557. this.removeSplatSceneDownloadPromise(downloadPromise);
  53558. return buildFunc(splatBuffer, true, true).then(() => {
  53559. this.clearSplatSceneDownloadAndBuildPromise();
  53560. });
  53561. }).catch(e => {
  53562. if (onException) onException();
  53563. this.clearSplatSceneDownloadAndBuildPromise();
  53564. this.removeSplatSceneDownloadPromise(downloadPromise);
  53565. if (!(e instanceof AbortedPromiseError)) {
  53566. throw new Error("Viewer::addSplatScene -> Could not load file ".concat(path));
  53567. }
  53568. });
  53569. this.addSplatSceneDownloadPromise(downloadPromise);
  53570. this.setSplatSceneDownloadAndBuildPromise(downloadPromise);
  53571. return downloadPromise;
  53572. }
  53573. /**
  53574. * Download a single splat scene and convert to splat buffer in a streamed manner, allowing rendering as the file downloads.
  53575. * As each section is downloaded, the viewer's splat mesh is rebuilt by calling 'buildFunc'
  53576. * Also sets/clears relevant instance synchronization objects, and calls appropriate functions on success or failure.
  53577. * @param {string} path Path to splat scene to be loaded
  53578. * @param {SceneFormat} format Format of the splat scene file
  53579. * @param {number} splatAlphaRemovalThreshold Ignore any splats with an alpha less than the specified value (valid range: 0 - 255)
  53580. * @param {function} buildFunc Function to rebuild the viewer's splat mesh after a new splat buffer section is downloaded
  53581. * @param {function} onDownloadProgress Function to be called as file data are received
  53582. * @param {function} onDownloadException Function to be called when exception occurs at any point during the full download
  53583. * @return {AbortablePromise}
  53584. */
  53585. downloadAndBuildSingleSplatSceneStreaming(path, format, splatAlphaRemovalThreshold, buildFunc, onDownloadProgress, onDownloadException) {
  53586. var firstStreamedSectionDownloadAndBuildResolver;
  53587. var firstStreamedSectionDownloadAndBuildRejecter;
  53588. var splatSceneDownloadAndBuildResolver;
  53589. var splatSceneDownloadAndBuildRejecter;
  53590. var steamedSectionBuildCount = 0;
  53591. var streamedSectionBuilding = false;
  53592. var queuedStreamedSectionBuilds = [];
  53593. var checkAndBuildStreamedSections = () => {
  53594. if (queuedStreamedSectionBuilds.length > 0 && !streamedSectionBuilding && !this.isDisposingOrDisposed()) {
  53595. streamedSectionBuilding = true;
  53596. var queuedBuild = queuedStreamedSectionBuilds.shift();
  53597. buildFunc(queuedBuild.splatBuffer, queuedBuild.firstBuild, queuedBuild.finalBuild).then(() => {
  53598. streamedSectionBuilding = false;
  53599. if (queuedBuild.firstBuild) {
  53600. firstStreamedSectionDownloadAndBuildRejecter = null;
  53601. firstStreamedSectionDownloadAndBuildResolver();
  53602. } else if (queuedBuild.finalBuild) {
  53603. splatSceneDownloadAndBuildResolver();
  53604. this.clearSplatSceneDownloadAndBuildPromise();
  53605. }
  53606. if (queuedStreamedSectionBuilds.length > 0) delayedExecute(() => checkAndBuildStreamedSections());
  53607. });
  53608. }
  53609. };
  53610. var onStreamedSectionProgress = (splatBuffer, finalBuild) => {
  53611. if (!this.isDisposingOrDisposed()) {
  53612. if (finalBuild || queuedStreamedSectionBuilds.length === 0 || splatBuffer.getSplatCount() > queuedStreamedSectionBuilds[0].splatBuffer.getSplatCount()) {
  53613. queuedStreamedSectionBuilds.push({
  53614. splatBuffer,
  53615. firstBuild: steamedSectionBuildCount === 0,
  53616. finalBuild
  53617. });
  53618. steamedSectionBuildCount++;
  53619. checkAndBuildStreamedSections();
  53620. }
  53621. }
  53622. };
  53623. var splatSceneDownloadPromise = this.downloadSplatSceneToSplatBuffer(path, splatAlphaRemovalThreshold, onDownloadProgress, true, onStreamedSectionProgress, format);
  53624. var firstStreamedSectionBuildPromise = new AbortablePromise((resolver, rejecter) => {
  53625. firstStreamedSectionDownloadAndBuildResolver = resolver;
  53626. firstStreamedSectionDownloadAndBuildRejecter = rejecter;
  53627. }, splatSceneDownloadPromise.abortHandler);
  53628. var splatSceneDownloadAndBuildPromise = new AbortablePromise((resolver, rejecter) => {
  53629. splatSceneDownloadAndBuildResolver = resolver;
  53630. splatSceneDownloadAndBuildRejecter = rejecter;
  53631. });
  53632. this.addSplatSceneDownloadPromise(splatSceneDownloadPromise);
  53633. this.setSplatSceneDownloadAndBuildPromise(splatSceneDownloadAndBuildPromise);
  53634. splatSceneDownloadPromise.then(() => {
  53635. this.removeSplatSceneDownloadPromise(splatSceneDownloadPromise);
  53636. }).catch(e => {
  53637. this.clearSplatSceneDownloadAndBuildPromise();
  53638. this.removeSplatSceneDownloadPromise(splatSceneDownloadPromise);
  53639. if (!(e instanceof AbortedPromiseError)) {
  53640. splatSceneDownloadAndBuildRejecter(e);
  53641. if (firstStreamedSectionDownloadAndBuildRejecter) firstStreamedSectionDownloadAndBuildRejecter(e);
  53642. if (onDownloadException) onDownloadException(e);
  53643. }
  53644. });
  53645. return firstStreamedSectionBuildPromise;
  53646. }
  53647. /**
  53648. * Add multiple splat scenes to the viewer and display any loading UI if appropriate.
  53649. * @param {Array<object>} sceneOptions Array of per-scene options: {
  53650. *
  53651. * path: Path to splat scene to be loaded
  53652. *
  53653. * splatAlphaRemovalThreshold: Ignore any splats with an alpha less than the specified
  53654. * value (valid range: 0 - 255), defaults to 1
  53655. *
  53656. * position (Array<number>): Position of the scene, acts as an offset from its default position, defaults to [0, 0, 0]
  53657. *
  53658. * rotation (Array<number>): Rotation of the scene represented as a quaternion, defaults to [0, 0, 0, 1]
  53659. *
  53660. * scale (Array<number>): Scene's scale, defaults to [1, 1, 1]
  53661. * }
  53662. * @param {boolean} showLoadingUI Display a loading spinner while the scene is loading, defaults to true
  53663. * @param {function} onProgress Function to be called as file data are received
  53664. * @return {AbortablePromise}
  53665. */
  53666. addSplatScenes(sceneOptions) {
  53667. var showLoadingUI = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  53668. var onProgress = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
  53669. if (this.isLoadingOrUnloading()) {
  53670. throw new Error('Cannot add splat scene while another load or unload is already in progress.');
  53671. }
  53672. if (this.isDisposingOrDisposed()) {
  53673. throw new Error('Cannot add splat scene after dispose() is called.');
  53674. }
  53675. var fileCount = sceneOptions.length;
  53676. var percentComplete = [];
  53677. if (showLoadingUI) {
  53678. this.loadingSpinner.removeAllTasks();
  53679. this.loadingSpinner.show();
  53680. }
  53681. var onLoadProgress = (fileIndex, percent, percentLabel) => {
  53682. percentComplete[fileIndex] = percent;
  53683. var totalPercent = 0;
  53684. for (var i = 0; i < fileCount; i++) totalPercent += percentComplete[i] || 0;
  53685. totalPercent = totalPercent / fileCount;
  53686. percentLabel = "".concat(totalPercent.toFixed(2), "%");
  53687. if (showLoadingUI) {
  53688. this.loadingSpinner.setMessage(totalPercent == 100 ? "Download complete!" : "Downloading: ".concat(percentLabel));
  53689. }
  53690. if (onProgress) onProgress(totalPercent, percentLabel, LoaderStatus.Downloading);
  53691. };
  53692. var downloadPromises = [];
  53693. var nativeLoadPromises = [];
  53694. var abortHandlers = [];
  53695. for (var i = 0; i < sceneOptions.length; i++) {
  53696. var _options2 = sceneOptions[i];
  53697. var format = _options2.format !== undefined && _options2.format !== null ? _options2.format : sceneFormatFromPath(_options2.path);
  53698. var _downloadPromise = this.downloadSplatSceneToSplatBuffer(_options2.path, _options2.splatAlphaRemovalThreshold, onLoadProgress.bind(this, i), false, undefined, format);
  53699. abortHandlers.push(_downloadPromise.abortHandler);
  53700. downloadPromises.push(_downloadPromise);
  53701. nativeLoadPromises.push(_downloadPromise.promise);
  53702. this.addSplatSceneDownloadPromise(_downloadPromise);
  53703. }
  53704. var downloadPromise = new AbortablePromise((resolve, reject) => {
  53705. Promise.all(nativeLoadPromises).then(splatBuffers => {
  53706. if (showLoadingUI) this.loadingSpinner.hide();
  53707. if (onProgress) options.onProgress(0, '0%', LoaderStatus.Processing);
  53708. this.addSplatBuffers(splatBuffers, sceneOptions, true, showLoadingUI, showLoadingUI).then(() => {
  53709. if (onProgress) onProgress(100, '100%', LoaderStatus.Processing);
  53710. this.clearSplatSceneDownloadAndBuildPromise();
  53711. resolve();
  53712. });
  53713. }).catch(e => {
  53714. if (showLoadingUI) this.loadingSpinner.hide();
  53715. this.clearSplatSceneDownloadAndBuildPromise();
  53716. if (!(e instanceof AbortedPromiseError)) {
  53717. reject(new Error("Viewer::addSplatScenes -> Could not load one or more splat scenes."));
  53718. } else {
  53719. resolve();
  53720. }
  53721. }).finally(() => {
  53722. for (var _downloadPromise2 of downloadPromises) {
  53723. this.removeSplatSceneDownloadPromise(_downloadPromise2);
  53724. }
  53725. });
  53726. }, () => {
  53727. for (var abortHandler of abortHandlers) abortHandler();
  53728. });
  53729. this.setSplatSceneDownloadAndBuildPromise(downloadPromise);
  53730. return downloadPromise;
  53731. }
  53732. /**
  53733. * Download a splat scene and convert to SplatBuffer instance.
  53734. * @param {string} path Path to splat scene to be loaded
  53735. * @param {number} splatAlphaRemovalThreshold Ignore any splats with an alpha less than the specified
  53736. * value (valid range: 0 - 255), defaults to 1
  53737. *
  53738. * @param {function} onProgress Function to be called as file data are received
  53739. * @param {boolean} streamBuiltSections Construct file sections into splat buffers as they are downloaded
  53740. * @param {function} onSectionBuilt Function to be called when new section is added to the file
  53741. * @param {string} format File format of the scene
  53742. * @return {AbortablePromise}
  53743. */
  53744. downloadSplatSceneToSplatBuffer(path) {
  53745. var splatAlphaRemovalThreshold = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
  53746. var onProgress = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
  53747. var streamBuiltSections = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  53748. var onSectionBuilt = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : undefined;
  53749. var format = arguments.length > 5 ? arguments[5] : undefined;
  53750. if (format === SceneFormat.Splat) {
  53751. return SplatLoader.loadFromURL(path, onProgress, streamBuiltSections, onSectionBuilt, splatAlphaRemovalThreshold, 0, false);
  53752. } else if (format === SceneFormat.KSplat) {
  53753. return KSplatLoader.loadFromURL(path, onProgress, streamBuiltSections, onSectionBuilt);
  53754. } else if (format === SceneFormat.Ply) {
  53755. return PlyLoader.loadFromURL(path, onProgress, streamBuiltSections, onSectionBuilt, splatAlphaRemovalThreshold, 0, this.sphericalHarmonicsDegree);
  53756. }
  53757. return AbortablePromise.reject(new Error("Viewer::downloadSplatSceneToSplatBuffer -> File format not supported: ".concat(path)));
  53758. }
  53759. static isStreamable(format) {
  53760. return format === SceneFormat.Splat || format === SceneFormat.KSplat || format === SceneFormat.Ply;
  53761. }
  53762. /**
  53763. * Add one or more instances of SplatBuffer to the SplatMesh instance managed by the viewer. This function is additive; all splat
  53764. * buffers contained by the viewer's splat mesh before calling this function will be preserved.
  53765. * @param {Array<SplatBuffer>} splatBuffers SplatBuffer instances
  53766. * @param {Array<object>} splatBufferOptions Array of options objects: {
  53767. *
  53768. * splatAlphaRemovalThreshold: Ignore any splats with an alpha less than the specified
  53769. * value (valid range: 0 - 255), defaults to 1
  53770. *
  53771. * position (Array<number>): Position of the scene, acts as an offset from its default position, defaults to [0, 0, 0]
  53772. *
  53773. * rotation (Array<number>): Rotation of the scene represented as a quaternion, defaults to [0, 0, 0, 1]
  53774. *
  53775. * scale (Array<number>): Scene's scale, defaults to [1, 1, 1]
  53776. * }
  53777. * @param {boolean} finalBuild Will the splat mesh be in its final state after this build?
  53778. * @param {boolean} showLoadingUIForSplatTreeBuild Whether or not to show the loading spinner during construction of the splat tree.
  53779. * @return {object} Object containing info about the splats that are updated
  53780. */
  53781. addSplatBuffersToMesh(splatBuffers, splatBufferOptions) {
  53782. var finalBuild = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
  53783. var showLoadingUIForSplatTreeBuild = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  53784. if (this.isDisposingOrDisposed()) return;
  53785. var allSplatBuffers = this.splatMesh.splatBuffers || [];
  53786. var allSplatBufferOptions = this.splatMesh.splatBufferOptions || [];
  53787. allSplatBuffers.push(...splatBuffers);
  53788. allSplatBufferOptions.push(...splatBufferOptions);
  53789. if (this.renderer) this.splatMesh.setRenderer(this.renderer);
  53790. var splatOptimizingTaskId;
  53791. var onSplatTreeIndexesUpload = finished => {
  53792. if (this.isDisposingOrDisposed()) return;
  53793. var splatCount = this.splatMesh.getSplatCount();
  53794. if (showLoadingUIForSplatTreeBuild && splatCount >= MIN_SPLAT_COUNT_TO_SHOW_SPLAT_TREE_LOADING_SPINNER) {
  53795. if (!finished && !splatOptimizingTaskId) {
  53796. this.loadingSpinner.setMinimized(true, true);
  53797. splatOptimizingTaskId = this.loadingSpinner.addTask('Optimizing splats...');
  53798. }
  53799. }
  53800. };
  53801. var onSplatTreeReady = finished => {
  53802. if (this.isDisposingOrDisposed()) return;
  53803. if (finished && splatOptimizingTaskId) {
  53804. this.loadingSpinner.removeTask(splatOptimizingTaskId);
  53805. }
  53806. };
  53807. return this.splatMesh.build(allSplatBuffers, allSplatBufferOptions, true, finalBuild, onSplatTreeIndexesUpload, onSplatTreeReady);
  53808. }
  53809. /**
  53810. * Set up the splat sorting web worker.
  53811. * @param {SplatMesh} splatMesh SplatMesh instance that contains the splats to be sorted
  53812. * @return {Promise}
  53813. */
  53814. setupSortWorker(splatMesh) {
  53815. if (this.isDisposingOrDisposed()) return;
  53816. return new Promise(resolve => {
  53817. var DistancesArrayType = this.integerBasedSort ? Int32Array : Float32Array;
  53818. var splatCount = splatMesh.getSplatCount();
  53819. var maxSplatCount = splatMesh.getMaxSplatCount();
  53820. this.sortWorker = createSortWorker(maxSplatCount, this.sharedMemoryForWorkers, this.integerBasedSort, this.splatMesh.dynamicMode);
  53821. var sortCount = 0;
  53822. this.sortWorker.onmessage = e => {
  53823. if (e.data.sortDone) {
  53824. this.sortRunning = false;
  53825. if (this.sharedMemoryForWorkers) {
  53826. this.splatMesh.updateRenderIndexes(this.sortWorkerSortedIndexes, e.data.splatRenderCount);
  53827. } else {
  53828. var sortedIndexes = new Uint32Array(e.data.sortedIndexes.buffer, 0, e.data.splatRenderCount);
  53829. this.splatMesh.updateRenderIndexes(sortedIndexes, e.data.splatRenderCount);
  53830. }
  53831. this.lastSortTime = e.data.sortTime;
  53832. this.sortPromiseResolver();
  53833. this.sortPromiseResolver = null;
  53834. this.forceRenderNextFrame();
  53835. if (sortCount === 0) {
  53836. this.runAfterFirstSort.forEach(func => {
  53837. func();
  53838. });
  53839. this.runAfterFirstSort.length = 0;
  53840. }
  53841. sortCount++;
  53842. } else if (e.data.sortCanceled) {
  53843. this.sortRunning = false;
  53844. } else if (e.data.sortSetupPhase1Complete) {
  53845. //划分好共享数据
  53846. if (this.logLevel >= LogLevel.Info) console.log('Sorting web worker WASM setup complete.');
  53847. if (this.sharedMemoryForWorkers) {
  53848. this.sortWorkerSortedIndexes = new Uint32Array(e.data.sortedIndexesBuffer,
  53849. //这是以后就是每次要渲染的indexes
  53850. e.data.sortedIndexesOffset, maxSplatCount);
  53851. this.sortWorkerIndexesToSort = new Uint32Array(e.data.indexesToSortBuffer,
  53852. //准备sort的点,每次镜头改变时先选出要渲染的点,再排序
  53853. e.data.indexesToSortOffset, maxSplatCount);
  53854. this.sortWorkerPrecomputedDistances = new DistancesArrayType(e.data.precomputedDistancesBuffer, e.data.precomputedDistancesOffset, maxSplatCount);
  53855. this.sortWorkerTransforms = new Float32Array(e.data.transformsBuffer, e.data.transformsOffset, Constants.MaxScenes * 16);
  53856. } else {
  53857. this.sortWorkerIndexesToSort = new Uint32Array(maxSplatCount);
  53858. this.sortWorkerPrecomputedDistances = new DistancesArrayType(maxSplatCount);
  53859. this.sortWorkerTransforms = new Float32Array(Constants.MaxScenes * 16);
  53860. }
  53861. for (var i = 0; i < splatCount; i++) this.sortWorkerIndexesToSort[i] = i; //初始化待sort的所有index,按顺序赋值就行
  53862. this.sortWorker.maxSplatCount = maxSplatCount; //总点数
  53863. if (this.logLevel >= LogLevel.Info) {
  53864. console.log('Sorting web worker ready.');
  53865. var splatDataTextures = this.splatMesh.getSplatDataTextures();
  53866. var covariancesTextureSize = splatDataTextures.covariances.size;
  53867. var centersColorsTextureSize = splatDataTextures.centerColors.size;
  53868. console.log('Covariances texture size: ' + covariancesTextureSize.x + ' x ' + covariancesTextureSize.y);
  53869. console.log('Centers/colors texture size: ' + centersColorsTextureSize.x + ' x ' + centersColorsTextureSize.y);
  53870. }
  53871. resolve();
  53872. }
  53873. };
  53874. });
  53875. }
  53876. disposeSortWorker() {
  53877. if (this.sortWorker) this.sortWorker.terminate();
  53878. this.sortWorker = null;
  53879. this.sortPromise = null;
  53880. if (this.sortPromiseResolver) {
  53881. this.sortPromiseResolver();
  53882. this.sortPromiseResolver = null;
  53883. }
  53884. this.sortRunning = false;
  53885. }
  53886. removeSplatScene(index) {
  53887. var showLoadingUI = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  53888. if (this.isLoadingOrUnloading()) {
  53889. throw new Error('Cannot remove splat scene while another load or unload is already in progress.');
  53890. }
  53891. if (this.isDisposingOrDisposed()) {
  53892. throw new Error('Cannot remove splat scene after dispose() is called.');
  53893. }
  53894. var sortPromise;
  53895. this.splatSceneRemovalPromise = new Promise((resolve, reject) => {
  53896. var revmovalTaskId;
  53897. if (showLoadingUI) {
  53898. this.loadingSpinner.removeAllTasks();
  53899. this.loadingSpinner.show();
  53900. revmovalTaskId = this.loadingSpinner.addTask('Removing splat scene...');
  53901. }
  53902. var checkAndHideLoadingUI = () => {
  53903. if (showLoadingUI) {
  53904. this.loadingSpinner.hide();
  53905. this.loadingSpinner.removeTask(revmovalTaskId);
  53906. }
  53907. };
  53908. var onDone = error => {
  53909. checkAndHideLoadingUI();
  53910. this.splatSceneRemovalPromise = null;
  53911. if (!error) resolve();else reject(error);
  53912. };
  53913. var checkForEarlyExit = () => {
  53914. if (this.isDisposingOrDisposed()) {
  53915. onDone();
  53916. return true;
  53917. }
  53918. return false;
  53919. };
  53920. sortPromise = this.sortPromise || Promise.resolve();
  53921. sortPromise.then(() => {
  53922. if (checkForEarlyExit()) return;
  53923. var savedSplatBuffers = [];
  53924. var savedSceneOptions = [];
  53925. var savedSceneTransformComponents = [];
  53926. var savedVisibleRegionFadeStartRadius = this.splatMesh.visibleRegionFadeStartRadius;
  53927. for (var i = 0; i < this.splatMesh.scenes.length; i++) {
  53928. if (i !== index) {
  53929. var scene = this.splatMesh.scenes[i];
  53930. savedSplatBuffers.push(scene.splatBuffer);
  53931. savedSceneOptions.push(this.splatMesh.sceneOptions[i]);
  53932. savedSceneTransformComponents.push({
  53933. 'position': scene.position.clone(),
  53934. 'quaternion': scene.quaternion.clone(),
  53935. 'scale': scene.scale.clone()
  53936. });
  53937. }
  53938. }
  53939. this.disposeSortWorker();
  53940. this.splatMesh.dispose();
  53941. this.createSplatMesh();
  53942. this.addSplatBuffers(savedSplatBuffers, savedSceneOptions, true, false, true).then(() => {
  53943. if (checkForEarlyExit()) return;
  53944. checkAndHideLoadingUI();
  53945. this.splatMesh.visibleRegionFadeStartRadius = savedVisibleRegionFadeStartRadius;
  53946. this.splatMesh.scenes.forEach((scene, index) => {
  53947. scene.position.copy(savedSceneTransformComponents[index].position);
  53948. scene.quaternion.copy(savedSceneTransformComponents[index].quaternion);
  53949. scene.scale.copy(savedSceneTransformComponents[index].scale);
  53950. });
  53951. this.splatMesh.updateTransforms();
  53952. this.splatRenderReady = false;
  53953. this.updateSplatSort(true).then(() => {
  53954. if (checkForEarlyExit()) {
  53955. this.splatRenderReady = true;
  53956. return;
  53957. }
  53958. sortPromise = this.sortPromise || Promise.resolve();
  53959. sortPromise.then(() => {
  53960. this.splatRenderReady = true;
  53961. onDone();
  53962. });
  53963. });
  53964. }).catch(e => {
  53965. onDone(e);
  53966. });
  53967. });
  53968. });
  53969. return this.splatSceneRemovalPromise;
  53970. }
  53971. /**
  53972. * Start self-driven mode
  53973. */
  53974. start() {
  53975. if (this.selfDrivenMode) {
  53976. if (this.webXRMode) {
  53977. this.renderer.setAnimationLoop(this.selfDrivenUpdateFunc);
  53978. } else {
  53979. this.requestFrameId = requestAnimationFrame(this.selfDrivenUpdateFunc);
  53980. }
  53981. this.selfDrivenModeRunning = true;
  53982. } else {
  53983. throw new Error('Cannot start viewer unless it is in self driven mode.');
  53984. }
  53985. }
  53986. /**
  53987. * Stop self-driven mode
  53988. */
  53989. stop() {
  53990. if (this.selfDrivenMode && this.selfDrivenModeRunning) {
  53991. if (!this.webXRMode) {
  53992. cancelAnimationFrame(this.requestFrameId);
  53993. }
  53994. this.selfDrivenModeRunning = false;
  53995. }
  53996. }
  53997. /**
  53998. * Dispose of all resources held directly and indirectly by this viewer.
  53999. */
  54000. async dispose() {
  54001. this.disposing = true;
  54002. var waitPromises = [];
  54003. var promisesToAbort = [];
  54004. for (var promiseKey in this.splatSceneDownloadPromises) {
  54005. if (this.splatSceneDownloadPromises.hasOwnProperty(promiseKey)) {
  54006. var downloadPromiseToAbort = this.splatSceneDownloadPromises[promiseKey];
  54007. promisesToAbort.push(downloadPromiseToAbort);
  54008. waitPromises.push(downloadPromiseToAbort.promise);
  54009. }
  54010. }
  54011. if (this.sortPromise) {
  54012. waitPromises.push(this.sortPromise);
  54013. }
  54014. var disposePromise = Promise.all(waitPromises).finally(() => {
  54015. this.stop();
  54016. if (this.controls) {
  54017. this.controls.dispose();
  54018. this.controls = null;
  54019. }
  54020. if (this.splatMesh) {
  54021. this.splatMesh.dispose();
  54022. this.splatMesh = null;
  54023. }
  54024. if (this.sceneHelper) {
  54025. this.sceneHelper.dispose();
  54026. this.sceneHelper = null;
  54027. }
  54028. if (this.resizeObserver) {
  54029. this.resizeObserver.unobserve(this.rootElement);
  54030. this.resizeObserver = null;
  54031. }
  54032. this.disposeSortWorker();
  54033. this.removeEventHandlers();
  54034. this.loadingSpinner.removeAllTasks();
  54035. this.loadingSpinner.setContainer(null);
  54036. this.loadingProgressBar.hide();
  54037. this.loadingProgressBar.setContainer(null);
  54038. this.infoPanel.setContainer(null);
  54039. this.camera = null;
  54040. this.threeScene = null;
  54041. this.splatRenderReady = false;
  54042. this.initialized = false;
  54043. if (this.renderer) {
  54044. if (!this.usingExternalRenderer) {
  54045. this.rootElement.removeChild(this.renderer.domElement);
  54046. this.renderer.dispose();
  54047. }
  54048. this.renderer = null;
  54049. }
  54050. if (!this.usingExternalRenderer) {
  54051. document.body.removeChild(this.rootElement);
  54052. }
  54053. this.sortWorkerSortedIndexes = null;
  54054. this.sortWorkerIndexesToSort = null;
  54055. this.sortWorkerPrecomputedDistances = null;
  54056. this.sortWorkerTransforms = null;
  54057. this.disposed = true;
  54058. this.disposing = false;
  54059. });
  54060. promisesToAbort.forEach(toAbort => {
  54061. toAbort.abort();
  54062. });
  54063. return disposePromise;
  54064. }
  54065. selfDrivenUpdate() {
  54066. /* if (this.selfDrivenMode && !this.webXRMode) { //xzw delete
  54067. this.requestFrameId = requestAnimationFrame(this.selfDrivenUpdateFunc);
  54068. } */
  54069. this.update();
  54070. if (this.shouldRender()) {
  54071. this.render();
  54072. this.consecutiveRenderFrames++;
  54073. } else {
  54074. this.consecutiveRenderFrames = 0;
  54075. }
  54076. this.renderNextFrame = false;
  54077. }
  54078. forceRenderNextFrame() {
  54079. this.renderNextFrame = true;
  54080. }
  54081. update(renderer, camera) {
  54082. if (this.dropInMode) this.updateForDropInMode(renderer, camera);
  54083. if (!this.initialized || !this.splatRenderReady) return;
  54084. if (this.controls) {
  54085. this.controls.update();
  54086. if (this.camera.isOrthographicCamera && !this.usingExternalCamera) {
  54087. Viewer.setCameraPositionFromZoom(this.camera, this.camera, this.controls);
  54088. }
  54089. }
  54090. this.splatMesh.updateVisibleRegionFadeDistance(this.sceneRevealMode);
  54091. this.updateSplatSort();
  54092. this.updateForRendererSizeChanges();
  54093. this.updateSplatMesh();
  54094. this.updateMeshCursor();
  54095. this.updateFPS();
  54096. this.timingSensitiveUpdates();
  54097. this.updateInfoPanel();
  54098. this.updateControlPlane();
  54099. }
  54100. updateForDropInMode(renderer, camera) {
  54101. this.renderer = renderer;
  54102. if (this.splatMesh) this.splatMesh.setRenderer(this.renderer);
  54103. this.camera = camera;
  54104. if (this.controls) this.controls.object = camera;
  54105. this.init();
  54106. }
  54107. updateControlPlane() {
  54108. if (this.showControlPlane) {
  54109. this.sceneHelper.setControlPlaneVisibility(true);
  54110. this.sceneHelper.positionAndOrientControlPlane(this.controls.target, this.camera.up);
  54111. } else {
  54112. this.sceneHelper.setControlPlaneVisibility(false);
  54113. }
  54114. }
  54115. getSplatMesh() {
  54116. return this.splatMesh;
  54117. }
  54118. /**
  54119. * Get a reference to a splat scene.
  54120. * @param {number} sceneIndex The index of the scene to which the reference will be returned
  54121. * @return {SplatScene}
  54122. */
  54123. getSplatScene(sceneIndex) {
  54124. return this.splatMesh.getScene(sceneIndex);
  54125. }
  54126. isMobile() {
  54127. return navigator.userAgent.includes('Mobi');
  54128. }
  54129. }
  54130. /**
  54131. * DropInViewer: Wrapper for a Viewer instance that enables it to be added to a Three.js scene like
  54132. * any other Three.js scene object (Mesh, Object3D, etc.)
  54133. */
  54134. _defineProperty(Viewer, "setCameraPositionFromZoom", function () {
  54135. var tempVector = new Vector3();
  54136. return function (positionCamera, zoomedCamera, controls) {
  54137. var toLookAtDistance = 1 / (zoomedCamera.zoom * 0.001);
  54138. tempVector.copy(controls.target).sub(positionCamera.position).normalize().multiplyScalar(toLookAtDistance).negate();
  54139. positionCamera.position.copy(controls.target).add(tempVector);
  54140. };
  54141. }());
  54142. _defineProperty(Viewer, "setCameraZoomFromPosition", function () {
  54143. var tempVector = new Vector3();
  54144. return function (zoomCamera, positionZamera, controls) {
  54145. var toLookAtDistance = tempVector.copy(controls.target).sub(positionZamera.position).length();
  54146. zoomCamera.zoom = 1 / (toLookAtDistance * .001);
  54147. };
  54148. }());
  54149. class DropInViewer extends Group {
  54150. constructor() {
  54151. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  54152. super();
  54153. options.selfDrivenMode = false;
  54154. options.useBuiltInControls = false;
  54155. options.rootElement = null;
  54156. options.ignoreDevicePixelRatio = false;
  54157. options.dropInMode = true;
  54158. options.camera = undefined;
  54159. options.renderer = undefined;
  54160. this.viewer = new Viewer(options);
  54161. this.splatMesh = null;
  54162. this.callbackMesh = DropInViewer.createCallbackMesh();
  54163. this.add(this.callbackMesh);
  54164. this.callbackMesh.onBeforeRender = DropInViewer.onBeforeRender.bind(this, this.viewer);
  54165. }
  54166. /**
  54167. * Add a single splat scene to the viewer.
  54168. * @param {string} path Path to splat scene to be loaded
  54169. * @param {object} options {
  54170. *
  54171. * splatAlphaRemovalThreshold: Ignore any splats with an alpha less than the specified
  54172. * value (valid range: 0 - 255), defaults to 1
  54173. *
  54174. * showLoadingUI: Display a loading spinner while the scene is loading, defaults to true
  54175. *
  54176. * position (Array<number>): Position of the scene, acts as an offset from its default position, defaults to [0, 0, 0]
  54177. *
  54178. * rotation (Array<number>): Rotation of the scene represented as a quaternion, defaults to [0, 0, 0, 1]
  54179. *
  54180. * scale (Array<number>): Scene's scale, defaults to [1, 1, 1]
  54181. *
  54182. * onProgress: Function to be called as file data are received
  54183. *
  54184. * }
  54185. * @return {AbortablePromise}
  54186. */
  54187. addSplatScene(path) {
  54188. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  54189. if (options.showLoadingUI !== false) options.showLoadingUI = true;
  54190. return this.viewer.addSplatScene(path, options);
  54191. }
  54192. /**
  54193. * Add multiple splat scenes to the viewer.
  54194. * @param {Array<object>} sceneOptions Array of per-scene options: {
  54195. *
  54196. * path: Path to splat scene to be loaded
  54197. *
  54198. * splatAlphaRemovalThreshold: Ignore any splats with an alpha less than the specified
  54199. * value (valid range: 0 - 255), defaults to 1
  54200. *
  54201. * position (Array<number>): Position of the scene, acts as an offset from its default position, defaults to [0, 0, 0]
  54202. *
  54203. * rotation (Array<number>): Rotation of the scene represented as a quaternion, defaults to [0, 0, 0, 1]
  54204. *
  54205. * scale (Array<number>): Scene's scale, defaults to [1, 1, 1]
  54206. * }
  54207. * @param {boolean} showLoadingUI Display a loading spinner while the scene is loading, defaults to true
  54208. * @return {AbortablePromise}
  54209. */
  54210. addSplatScenes(sceneOptions, showLoadingUI) {
  54211. if (showLoadingUI !== false) showLoadingUI = true;
  54212. return this.viewer.addSplatScenes(sceneOptions, showLoadingUI);
  54213. }
  54214. /**
  54215. * Get a reference to a splat scene.
  54216. * @param {number} sceneIndex The index of the scene to which the reference will be returned
  54217. * @return {SplatScene}
  54218. */
  54219. getSplatScene(sceneIndex) {
  54220. return this.viewer.getSplatScene(sceneIndex);
  54221. }
  54222. removeSplatScene(index) {
  54223. return this.viewer.removeSplatScene(index);
  54224. }
  54225. dispose() {
  54226. return this.viewer.dispose();
  54227. }
  54228. static onBeforeRender(viewer, renderer, threeScene, camera) {
  54229. if (this.splatMesh !== this.viewer.splatMesh) {
  54230. if (this.splatMesh) {
  54231. this.remove(this.splatMesh);
  54232. }
  54233. this.splatMesh = this.viewer.splatMesh;
  54234. this.add(this.viewer.splatMesh);
  54235. }
  54236. viewer.update(renderer, camera);
  54237. }
  54238. static createCallbackMesh() {
  54239. var geometry = new SphereGeometry(1, 8, 8);
  54240. var material = new MeshBasicMaterial();
  54241. material.colorWrite = false;
  54242. material.depthWrite = false;
  54243. var mesh = new Mesh(geometry, material);
  54244. mesh.frustumCulled = false;
  54245. return mesh;
  54246. }
  54247. }
  54248. //2022.11.11 copyfrom : https://unpkg.com/three@0.146.0/examples/jsm/loaders/DRACOLoader.js
  54249. var _taskCache = new WeakMap();
  54250. class DRACOLoader extends Loader {
  54251. constructor(manager) {
  54252. super(manager);
  54253. this.decoderPath = '';
  54254. this.decoderConfig = {};
  54255. this.decoderBinary = null;
  54256. this.decoderPending = null;
  54257. this.workerLimit = 4;
  54258. this.workerPool = [];
  54259. this.workerNextTaskID = 1;
  54260. this.workerSourceURL = '';
  54261. this.defaultAttributeIDs = {
  54262. position: 'POSITION',
  54263. normal: 'NORMAL',
  54264. color: 'COLOR',
  54265. uv: 'TEX_COORD'
  54266. };
  54267. this.defaultAttributeTypes = {
  54268. position: 'Float32Array',
  54269. normal: 'Float32Array',
  54270. color: 'Float32Array',
  54271. uv: 'Float32Array'
  54272. };
  54273. }
  54274. setDecoderPath(path) {
  54275. this.decoderPath = path;
  54276. return this;
  54277. }
  54278. setDecoderConfig(config) {
  54279. this.decoderConfig = config;
  54280. return this;
  54281. }
  54282. setWorkerLimit(workerLimit) {
  54283. this.workerLimit = workerLimit;
  54284. return this;
  54285. }
  54286. load(url, onLoad, onProgress, onError) {
  54287. var loader = new FileLoader(this.manager);
  54288. loader.setPath(this.path);
  54289. loader.setResponseType('arraybuffer');
  54290. loader.setRequestHeader(this.requestHeader);
  54291. loader.setWithCredentials(this.withCredentials);
  54292. loader.load(url, buffer => {
  54293. this.decodeDracoFile(buffer, onLoad).catch(onError);
  54294. }, onProgress, onError);
  54295. }
  54296. decodeDracoFile(buffer, callback, attributeIDs, attributeTypes) {
  54297. var taskConfig = {
  54298. attributeIDs: attributeIDs || this.defaultAttributeIDs,
  54299. attributeTypes: attributeTypes || this.defaultAttributeTypes,
  54300. useUniqueIDs: !!attributeIDs
  54301. };
  54302. return this.decodeGeometry(buffer, taskConfig).then(callback);
  54303. }
  54304. decodeGeometry(buffer, taskConfig) {
  54305. var taskKey = JSON.stringify(taskConfig);
  54306. // Check for an existing task using this buffer. A transferred buffer cannot be transferred
  54307. // again from this thread.
  54308. if (_taskCache.has(buffer)) {
  54309. var cachedTask = _taskCache.get(buffer);
  54310. if (cachedTask.key === taskKey) {
  54311. return cachedTask.promise;
  54312. } else if (buffer.byteLength === 0) {
  54313. // Technically, it would be possible to wait for the previous task to complete,
  54314. // transfer the buffer back, and decode again with the second configuration. That
  54315. // is complex, and I don't know of any reason to decode a Draco buffer twice in
  54316. // different ways, so this is left unimplemented.
  54317. throw new Error('THREE.DRACOLoader: Unable to re-decode a buffer with different ' + 'settings. Buffer has already been transferred.');
  54318. }
  54319. }
  54320. //
  54321. var worker;
  54322. var taskID = this.workerNextTaskID++;
  54323. var taskCost = buffer.byteLength;
  54324. // Obtain a worker and assign a task, and construct a geometry instance
  54325. // when the task completes.
  54326. var geometryPending = this._getWorker(taskID, taskCost).then(_worker => {
  54327. worker = _worker;
  54328. return new Promise((resolve, reject) => {
  54329. worker._callbacks[taskID] = {
  54330. resolve,
  54331. reject
  54332. };
  54333. worker.postMessage({
  54334. type: 'decode',
  54335. id: taskID,
  54336. taskConfig,
  54337. buffer
  54338. }, [buffer]);
  54339. // this.debug();
  54340. });
  54341. }).then(message => this._createGeometry(message.geometry));
  54342. // Remove task from the task list.
  54343. // Note: replaced '.finally()' with '.catch().then()' block - iOS 11 support (#19416)
  54344. geometryPending.catch(() => true).then(() => {
  54345. if (worker && taskID) {
  54346. this._releaseTask(worker, taskID);
  54347. // this.debug();
  54348. }
  54349. });
  54350. // Cache the task result.
  54351. _taskCache.set(buffer, {
  54352. key: taskKey,
  54353. promise: geometryPending
  54354. });
  54355. return geometryPending;
  54356. }
  54357. _createGeometry(geometryData) {
  54358. var geometry = new BufferGeometry();
  54359. if (geometryData.index) {
  54360. geometry.setIndex(new BufferAttribute(geometryData.index.array, 1));
  54361. }
  54362. for (var i = 0; i < geometryData.attributes.length; i++) {
  54363. var attribute = geometryData.attributes[i];
  54364. var name = attribute.name;
  54365. var array = attribute.array;
  54366. var itemSize = attribute.itemSize;
  54367. geometry.setAttribute(name, new BufferAttribute(array, itemSize));
  54368. }
  54369. return geometry;
  54370. }
  54371. _loadLibrary(url, responseType) {
  54372. var loader = new FileLoader(this.manager);
  54373. loader.setPath(this.decoderPath);
  54374. loader.setResponseType(responseType);
  54375. loader.setWithCredentials(this.withCredentials);
  54376. return new Promise((resolve, reject) => {
  54377. loader.load(url, resolve, undefined, reject);
  54378. });
  54379. }
  54380. preload() {
  54381. this._initDecoder();
  54382. return this;
  54383. }
  54384. _initDecoder() {
  54385. if (this.decoderPending) return this.decoderPending;
  54386. var useJS = typeof WebAssembly !== 'object' || this.decoderConfig.type === 'js';
  54387. var librariesPending = [];
  54388. if (useJS) {
  54389. librariesPending.push(this._loadLibrary('draco_decoder.js', 'text'));
  54390. } else {
  54391. librariesPending.push(this._loadLibrary('draco_wasm_wrapper.js', 'text'));
  54392. librariesPending.push(this._loadLibrary('draco_decoder.wasm', 'arraybuffer'));
  54393. }
  54394. this.decoderPending = Promise.all(librariesPending).then(libraries => {
  54395. var jsContent = libraries[0];
  54396. if (!useJS) {
  54397. this.decoderConfig.wasmBinary = libraries[1];
  54398. }
  54399. var fn = DRACOWorker.toString();
  54400. var body = ['/* draco decoder */', jsContent, '', '/* worker */', fn.substring(fn.indexOf('{') + 1, fn.lastIndexOf('}'))].join('\n');
  54401. this.workerSourceURL = URL.createObjectURL(new Blob([body]));
  54402. });
  54403. return this.decoderPending;
  54404. }
  54405. _getWorker(taskID, taskCost) {
  54406. return this._initDecoder().then(() => {
  54407. if (this.workerPool.length < this.workerLimit) {
  54408. var _worker2 = new Worker(this.workerSourceURL);
  54409. _worker2._callbacks = {};
  54410. _worker2._taskCosts = {};
  54411. _worker2._taskLoad = 0;
  54412. _worker2.postMessage({
  54413. type: 'init',
  54414. decoderConfig: this.decoderConfig
  54415. });
  54416. _worker2.onmessage = function (e) {
  54417. var message = e.data;
  54418. switch (message.type) {
  54419. case 'decode':
  54420. _worker2._callbacks[message.id].resolve(message);
  54421. break;
  54422. case 'error':
  54423. _worker2._callbacks[message.id].reject(message);
  54424. break;
  54425. default:
  54426. console.error('THREE.DRACOLoader: Unexpected message, "' + message.type + '"');
  54427. }
  54428. };
  54429. this.workerPool.push(_worker2);
  54430. } else {
  54431. this.workerPool.sort(function (a, b) {
  54432. return a._taskLoad > b._taskLoad ? -1 : 1;
  54433. });
  54434. }
  54435. var worker = this.workerPool[this.workerPool.length - 1];
  54436. worker._taskCosts[taskID] = taskCost;
  54437. worker._taskLoad += taskCost;
  54438. return worker;
  54439. });
  54440. }
  54441. _releaseTask(worker, taskID) {
  54442. worker._taskLoad -= worker._taskCosts[taskID];
  54443. delete worker._callbacks[taskID];
  54444. delete worker._taskCosts[taskID];
  54445. }
  54446. debug() {
  54447. console.log('Task load: ', this.workerPool.map(worker => worker._taskLoad));
  54448. }
  54449. dispose() {
  54450. for (var i = 0; i < this.workerPool.length; ++i) {
  54451. this.workerPool[i].terminate();
  54452. }
  54453. this.workerPool.length = 0;
  54454. return this;
  54455. }
  54456. }
  54457. /* WEB WORKER */
  54458. function DRACOWorker() {
  54459. var decoderConfig;
  54460. var decoderPending;
  54461. onmessage = function onmessage(e) {
  54462. var message = e.data;
  54463. switch (message.type) {
  54464. case 'init':
  54465. decoderConfig = message.decoderConfig;
  54466. decoderPending = new Promise(function (resolve /*, reject*/) {
  54467. decoderConfig.onModuleLoaded = function (draco) {
  54468. // Module is Promise-like. Wrap before resolving to avoid loop.
  54469. resolve({
  54470. draco: draco
  54471. });
  54472. };
  54473. DracoDecoderModule(decoderConfig); // eslint-disable-line no-undef
  54474. });
  54475. break;
  54476. case 'decode':
  54477. var buffer = message.buffer;
  54478. var taskConfig = message.taskConfig;
  54479. decoderPending.then(module => {
  54480. var draco = module.draco;
  54481. var decoder = new draco.Decoder();
  54482. var decoderBuffer = new draco.DecoderBuffer();
  54483. decoderBuffer.Init(new Int8Array(buffer), buffer.byteLength);
  54484. try {
  54485. var geometry = decodeGeometry(draco, decoder, decoderBuffer, taskConfig);
  54486. var buffers = geometry.attributes.map(attr => attr.array.buffer);
  54487. if (geometry.index) buffers.push(geometry.index.array.buffer);
  54488. self.postMessage({
  54489. type: 'decode',
  54490. id: message.id,
  54491. geometry
  54492. }, buffers);
  54493. } catch (error) {
  54494. console.error(error);
  54495. self.postMessage({
  54496. type: 'error',
  54497. id: message.id,
  54498. error: error.message
  54499. });
  54500. } finally {
  54501. draco.destroy(decoderBuffer);
  54502. draco.destroy(decoder);
  54503. }
  54504. });
  54505. break;
  54506. }
  54507. };
  54508. function decodeGeometry(draco, decoder, decoderBuffer, taskConfig) {
  54509. var attributeIDs = taskConfig.attributeIDs;
  54510. var attributeTypes = taskConfig.attributeTypes;
  54511. var dracoGeometry;
  54512. var decodingStatus;
  54513. var geometryType = decoder.GetEncodedGeometryType(decoderBuffer);
  54514. if (geometryType === draco.TRIANGULAR_MESH) {
  54515. dracoGeometry = new draco.Mesh();
  54516. decodingStatus = decoder.DecodeBufferToMesh(decoderBuffer, dracoGeometry);
  54517. } else if (geometryType === draco.POINT_CLOUD) {
  54518. dracoGeometry = new draco.PointCloud();
  54519. decodingStatus = decoder.DecodeBufferToPointCloud(decoderBuffer, dracoGeometry);
  54520. } else {
  54521. throw new Error('THREE.DRACOLoader: Unexpected geometry type.');
  54522. }
  54523. if (!decodingStatus.ok() || dracoGeometry.ptr === 0) {
  54524. throw new Error('THREE.DRACOLoader: Decoding failed: ' + decodingStatus.error_msg());
  54525. }
  54526. var geometry = {
  54527. index: null,
  54528. attributes: []
  54529. };
  54530. // Gather all vertex attributes.
  54531. for (var attributeName in attributeIDs) {
  54532. var attributeType = self[attributeTypes[attributeName]];
  54533. var attribute = void 0;
  54534. var attributeID = void 0;
  54535. // A Draco file may be created with default vertex attributes, whose attribute IDs
  54536. // are mapped 1:1 from their semantic name (POSITION, NORMAL, ...). Alternatively,
  54537. // a Draco file may contain a custom set of attributes, identified by known unique
  54538. // IDs. glTF files always do the latter, and `.drc` files typically do the former.
  54539. if (taskConfig.useUniqueIDs) {
  54540. attributeID = attributeIDs[attributeName];
  54541. attribute = decoder.GetAttributeByUniqueId(dracoGeometry, attributeID);
  54542. } else {
  54543. attributeID = decoder.GetAttributeId(dracoGeometry, draco[attributeIDs[attributeName]]);
  54544. if (attributeID === -1) continue;
  54545. attribute = decoder.GetAttribute(dracoGeometry, attributeID);
  54546. }
  54547. geometry.attributes.push(decodeAttribute(draco, decoder, dracoGeometry, attributeName, attributeType, attribute));
  54548. }
  54549. // Add index.
  54550. if (geometryType === draco.TRIANGULAR_MESH) {
  54551. geometry.index = decodeIndex(draco, decoder, dracoGeometry);
  54552. }
  54553. draco.destroy(dracoGeometry);
  54554. return geometry;
  54555. }
  54556. function decodeIndex(draco, decoder, dracoGeometry) {
  54557. var numFaces = dracoGeometry.num_faces();
  54558. var numIndices = numFaces * 3;
  54559. var byteLength = numIndices * 4;
  54560. var ptr = draco._malloc(byteLength);
  54561. decoder.GetTrianglesUInt32Array(dracoGeometry, byteLength, ptr);
  54562. var index = new Uint32Array(draco.HEAPF32.buffer, ptr, numIndices).slice();
  54563. draco._free(ptr);
  54564. return {
  54565. array: index,
  54566. itemSize: 1
  54567. };
  54568. }
  54569. function decodeAttribute(draco, decoder, dracoGeometry, attributeName, attributeType, attribute) {
  54570. var numComponents = attribute.num_components();
  54571. var numPoints = dracoGeometry.num_points();
  54572. var numValues = numPoints * numComponents;
  54573. var byteLength = numValues * attributeType.BYTES_PER_ELEMENT;
  54574. var dataType = getDracoDataType(draco, attributeType);
  54575. var ptr = draco._malloc(byteLength);
  54576. decoder.GetAttributeDataArrayForAllPoints(dracoGeometry, attribute, dataType, byteLength, ptr);
  54577. var array = new attributeType(draco.HEAPF32.buffer, ptr, numValues).slice();
  54578. draco._free(ptr);
  54579. return {
  54580. name: attributeName,
  54581. array: array,
  54582. itemSize: numComponents
  54583. };
  54584. }
  54585. function getDracoDataType(draco, attributeType) {
  54586. switch (attributeType) {
  54587. case Float32Array:
  54588. return draco.DT_FLOAT32;
  54589. case Int8Array:
  54590. return draco.DT_INT8;
  54591. case Int16Array:
  54592. return draco.DT_INT16;
  54593. case Int32Array:
  54594. return draco.DT_INT32;
  54595. case Uint8Array:
  54596. return draco.DT_UINT8;
  54597. case Uint16Array:
  54598. return draco.DT_UINT16;
  54599. case Uint32Array:
  54600. return draco.DT_UINT32;
  54601. }
  54602. }
  54603. }
  54604. /**
  54605. * @author Deepkolos / https://github.com/deepkolos
  54606. */
  54607. //用于KTX2Loader
  54608. class WorkerPool$1 {
  54609. constructor() {
  54610. var pool = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 4;
  54611. this.pool = pool;
  54612. this.queue = [];
  54613. this.workers = [];
  54614. this.workersResolve = [];
  54615. this.workerStatus = 0;
  54616. }
  54617. _initWorker(workerId) {
  54618. if (!this.workers[workerId]) {
  54619. var worker = this.workerCreator();
  54620. worker.addEventListener('message', this._onMessage.bind(this, workerId));
  54621. this.workers[workerId] = worker;
  54622. }
  54623. }
  54624. _getIdleWorker() {
  54625. for (var i = 0; i < this.pool; i++) if (!(this.workerStatus & 1 << i)) return i;
  54626. return -1;
  54627. }
  54628. _onMessage(workerId, msg) {
  54629. var resolve = this.workersResolve[workerId];
  54630. resolve && resolve(msg);
  54631. if (this.queue.length) {
  54632. var {
  54633. resolve: _resolve,
  54634. msg: _msg,
  54635. transfer
  54636. } = this.queue.shift();
  54637. this.workersResolve[workerId] = _resolve;
  54638. this.workers[workerId].postMessage(_msg, transfer);
  54639. } else {
  54640. this.workerStatus ^= 1 << workerId;
  54641. }
  54642. }
  54643. setWorkerCreator(workerCreator) {
  54644. this.workerCreator = workerCreator;
  54645. }
  54646. setWorkerLimit(pool) {
  54647. this.pool = pool;
  54648. }
  54649. postMessage(msg, transfer) {
  54650. return new Promise(resolve => {
  54651. var workerId = this._getIdleWorker();
  54652. if (workerId !== -1) {
  54653. this._initWorker(workerId);
  54654. this.workerStatus |= 1 << workerId;
  54655. this.workersResolve[workerId] = resolve;
  54656. this.workers[workerId].postMessage(msg, transfer);
  54657. } else {
  54658. this.queue.push({
  54659. resolve,
  54660. msg,
  54661. transfer
  54662. });
  54663. }
  54664. });
  54665. }
  54666. dispose() {
  54667. this.workers.forEach(worker => worker.terminate());
  54668. this.workersResolve.length = 0;
  54669. this.workers.length = 0;
  54670. this.queue.length = 0;
  54671. this.workerStatus = 0;
  54672. }
  54673. }
  54674. var t = 0,
  54675. e$1 = 1,
  54676. n$1 = 2,
  54677. i$2 = 3,
  54678. s = 0,
  54679. a$1 = 0,
  54680. r = 2,
  54681. o$1 = 0,
  54682. l$1 = 1,
  54683. f = 160,
  54684. U$1 = 161,
  54685. c$1 = 162,
  54686. h$2 = 163,
  54687. _$1 = 0,
  54688. p = 1,
  54689. g = 0,
  54690. y = 1,
  54691. x$2 = 2,
  54692. u$2 = 3,
  54693. b$1 = 4,
  54694. d = 5,
  54695. m = 6,
  54696. w$1 = 7,
  54697. D = 8,
  54698. B = 9,
  54699. L = 10,
  54700. A = 11,
  54701. k = 12,
  54702. v = 13,
  54703. S$1 = 14,
  54704. I = 15,
  54705. O = 16,
  54706. T$1 = 17,
  54707. V = 18,
  54708. E = 0,
  54709. F = 1,
  54710. P = 2,
  54711. C = 3,
  54712. z = 4,
  54713. M$1 = 5,
  54714. W = 6,
  54715. N = 7,
  54716. H = 8,
  54717. K = 9,
  54718. X = 10,
  54719. j = 11,
  54720. R = 0,
  54721. Y = 1,
  54722. q = 2,
  54723. G = 13,
  54724. J = 14,
  54725. Q = 15,
  54726. Z = 128,
  54727. $$1 = 64,
  54728. tt = 32,
  54729. et = 16,
  54730. nt = 0,
  54731. it = 1,
  54732. st = 2,
  54733. at = 3,
  54734. rt = 4,
  54735. ot = 5,
  54736. lt = 6,
  54737. ft = 7,
  54738. Ut = 8,
  54739. ct = 9,
  54740. ht = 10,
  54741. _t = 13,
  54742. pt = 14,
  54743. gt = 15,
  54744. yt = 16,
  54745. xt = 17,
  54746. ut = 20,
  54747. bt = 21,
  54748. dt = 22,
  54749. mt = 23,
  54750. wt = 24,
  54751. Dt = 27,
  54752. Bt = 28,
  54753. Lt = 29,
  54754. At = 30,
  54755. kt = 31,
  54756. vt = 34,
  54757. St = 35,
  54758. It = 36,
  54759. Ot = 37,
  54760. Tt = 38,
  54761. Vt = 41,
  54762. Et = 42,
  54763. Ft = 43,
  54764. Pt = 44,
  54765. Ct = 45,
  54766. zt = 48,
  54767. Mt = 49,
  54768. Wt = 50,
  54769. Nt = 58,
  54770. Ht = 59,
  54771. Kt = 62,
  54772. Xt = 63,
  54773. jt = 64,
  54774. Rt = 65,
  54775. Yt = 68,
  54776. qt = 69,
  54777. Gt = 70,
  54778. Jt = 71,
  54779. Qt = 74,
  54780. Zt = 75,
  54781. $t = 76,
  54782. te = 77,
  54783. ee = 78,
  54784. ne = 81,
  54785. ie = 82,
  54786. se = 83,
  54787. ae = 84,
  54788. re = 85,
  54789. oe = 88,
  54790. le = 89,
  54791. fe = 90,
  54792. Ue = 91,
  54793. ce = 92,
  54794. he = 95,
  54795. _e = 96,
  54796. pe = 97,
  54797. ge = 98,
  54798. ye = 99,
  54799. xe = 100,
  54800. ue = 101,
  54801. be = 102,
  54802. de = 103,
  54803. me = 104,
  54804. we = 105,
  54805. De = 106,
  54806. Be = 107,
  54807. Le = 108,
  54808. Ae = 109,
  54809. ke = 110,
  54810. ve = 111,
  54811. Se = 112,
  54812. Ie = 113,
  54813. Oe = 114,
  54814. Te = 115,
  54815. Ve = 116,
  54816. Ee = 117,
  54817. Fe = 118,
  54818. Pe = 119,
  54819. Ce = 120,
  54820. ze = 121,
  54821. Me = 122,
  54822. We = 123,
  54823. Ne = 124,
  54824. He = 125,
  54825. Ke = 126,
  54826. Xe = 127,
  54827. je = 128,
  54828. Re = 129,
  54829. Ye = 130,
  54830. qe = 131,
  54831. Ge = 132,
  54832. Je = 133,
  54833. Qe = 134,
  54834. Ze = 135,
  54835. $e = 136,
  54836. tn = 137,
  54837. en = 138,
  54838. nn = 139,
  54839. sn = 140,
  54840. an = 141,
  54841. rn = 142,
  54842. on = 143,
  54843. ln = 144,
  54844. fn = 145,
  54845. Un = 146,
  54846. cn = 147,
  54847. hn = 148,
  54848. _n = 149,
  54849. pn = 150,
  54850. gn = 151,
  54851. yn = 152,
  54852. xn = 153,
  54853. un = 154,
  54854. bn = 155,
  54855. dn = 156,
  54856. mn = 157,
  54857. wn = 158,
  54858. Dn = 159,
  54859. Bn = 160,
  54860. Ln = 161,
  54861. An = 162,
  54862. kn = 163,
  54863. vn = 164,
  54864. Sn = 165,
  54865. In = 166,
  54866. On = 167,
  54867. Tn = 168,
  54868. Vn = 169,
  54869. En = 170,
  54870. Fn = 171,
  54871. Pn = 172,
  54872. Cn = 173,
  54873. zn = 174,
  54874. Mn = 175,
  54875. Wn = 176,
  54876. Nn = 177,
  54877. Hn = 178,
  54878. Kn = 179,
  54879. Xn = 180,
  54880. jn = 181,
  54881. Rn = 182,
  54882. Yn = 183,
  54883. qn = 184,
  54884. Gn = 1000156007,
  54885. Jn = 1000156008,
  54886. Qn = 1000156009,
  54887. Zn = 1000156010,
  54888. $n = 1000156011,
  54889. ti = 1000156017,
  54890. ei = 1000156018,
  54891. ni = 1000156019,
  54892. ii = 1000156020,
  54893. si = 1000156021,
  54894. ai = 1000054e3,
  54895. ri = 1000054001,
  54896. oi = 1000054002,
  54897. li = 1000054003,
  54898. fi = 1000054004,
  54899. Ui = 1000054005,
  54900. ci = 1000054006,
  54901. hi = 1000054007,
  54902. _i = 1000066e3,
  54903. pi = 1000066001,
  54904. gi = 1000066002,
  54905. yi = 1000066003,
  54906. xi = 1000066004,
  54907. ui = 1000066005,
  54908. bi = 1000066006,
  54909. di = 1000066007,
  54910. mi = 1000066008,
  54911. wi = 1000066009,
  54912. Di = 1000066010,
  54913. Bi = 1000066011,
  54914. Li = 1000066012,
  54915. Ai = 1000066013,
  54916. ki = 100034e4,
  54917. vi = 1000340001;
  54918. class Si {
  54919. constructor() {
  54920. this.vkFormat = 0, this.typeSize = 1, this.pixelWidth = 0, this.pixelHeight = 0, this.pixelDepth = 0, this.layerCount = 0, this.faceCount = 1, this.supercompressionScheme = 0, this.levels = [], this.dataFormatDescriptor = [{
  54921. vendorId: 0,
  54922. descriptorType: 0,
  54923. descriptorBlockSize: 0,
  54924. versionNumber: 2,
  54925. colorModel: 0,
  54926. colorPrimaries: 1,
  54927. transferFunction: 2,
  54928. flags: 0,
  54929. texelBlockDimension: [0, 0, 0, 0],
  54930. bytesPlane: [0, 0, 0, 0, 0, 0, 0, 0],
  54931. samples: []
  54932. }], this.keyValue = {}, this.globalData = null;
  54933. }
  54934. }
  54935. class Ii {
  54936. constructor(t, e, n, i) {
  54937. this._dataView = new DataView(t.buffer, t.byteOffset + e, n), this._littleEndian = i, this._offset = 0;
  54938. }
  54939. _nextUint8() {
  54940. var t = this._dataView.getUint8(this._offset);
  54941. return this._offset += 1, t;
  54942. }
  54943. _nextUint16() {
  54944. var t = this._dataView.getUint16(this._offset, this._littleEndian);
  54945. return this._offset += 2, t;
  54946. }
  54947. _nextUint32() {
  54948. var t = this._dataView.getUint32(this._offset, this._littleEndian);
  54949. return this._offset += 4, t;
  54950. }
  54951. _nextUint64() {
  54952. var t = this._dataView.getUint32(this._offset, this._littleEndian) + 2 ** 32 * this._dataView.getUint32(this._offset + 4, this._littleEndian);
  54953. return this._offset += 8, t;
  54954. }
  54955. _nextInt32() {
  54956. var t = this._dataView.getInt32(this._offset, this._littleEndian);
  54957. return this._offset += 4, t;
  54958. }
  54959. _skip(t) {
  54960. return this._offset += t, this;
  54961. }
  54962. _scan(t) {
  54963. var e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  54964. var n = this._offset;
  54965. var i = 0;
  54966. for (; this._dataView.getUint8(this._offset) !== e && i < t;) i++, this._offset++;
  54967. return i < t && this._offset++, new Uint8Array(this._dataView.buffer, this._dataView.byteOffset + n, i);
  54968. }
  54969. }
  54970. var Oi = new Uint8Array([0]),
  54971. Ti = [171, 75, 84, 88, 32, 50, 48, 187, 13, 10, 26, 10];
  54972. function Vi(t) {
  54973. return "undefined" != typeof TextEncoder ? new TextEncoder().encode(t) : Buffer.from(t);
  54974. }
  54975. function Ei(t) {
  54976. return "undefined" != typeof TextDecoder ? new TextDecoder().decode(t) : Buffer.from(t).toString("utf8");
  54977. }
  54978. function Fi(t) {
  54979. var e = 0;
  54980. for (var _n2 of t) e += _n2.byteLength;
  54981. var n = new Uint8Array(e);
  54982. var i = 0;
  54983. for (var _e2 of t) n.set(new Uint8Array(_e2), i), i += _e2.byteLength;
  54984. return n;
  54985. }
  54986. function Pi(t) {
  54987. var e = new Uint8Array(t.buffer, t.byteOffset, Ti.length);
  54988. if (e[0] !== Ti[0] || e[1] !== Ti[1] || e[2] !== Ti[2] || e[3] !== Ti[3] || e[4] !== Ti[4] || e[5] !== Ti[5] || e[6] !== Ti[6] || e[7] !== Ti[7] || e[8] !== Ti[8] || e[9] !== Ti[9] || e[10] !== Ti[10] || e[11] !== Ti[11]) throw new Error("Missing KTX 2.0 identifier.");
  54989. var n = new Si(),
  54990. i = 17 * Uint32Array.BYTES_PER_ELEMENT,
  54991. s = new Ii(t, Ti.length, i, !0);
  54992. n.vkFormat = s._nextUint32(), n.typeSize = s._nextUint32(), n.pixelWidth = s._nextUint32(), n.pixelHeight = s._nextUint32(), n.pixelDepth = s._nextUint32(), n.layerCount = s._nextUint32(), n.faceCount = s._nextUint32();
  54993. var a = s._nextUint32();
  54994. n.supercompressionScheme = s._nextUint32();
  54995. var r = s._nextUint32(),
  54996. o = s._nextUint32(),
  54997. l = s._nextUint32(),
  54998. f = s._nextUint32(),
  54999. U = s._nextUint64(),
  55000. c = s._nextUint64(),
  55001. h = new Ii(t, Ti.length + i, 3 * a * 8, !0);
  55002. for (var _e3 = 0; _e3 < a; _e3++) n.levels.push({
  55003. levelData: new Uint8Array(t.buffer, t.byteOffset + h._nextUint64(), h._nextUint64()),
  55004. uncompressedByteLength: h._nextUint64()
  55005. });
  55006. var _ = new Ii(t, r, o, !0),
  55007. p = {
  55008. vendorId: _._skip(4)._nextUint16(),
  55009. descriptorType: _._nextUint16(),
  55010. versionNumber: _._nextUint16(),
  55011. descriptorBlockSize: _._nextUint16(),
  55012. colorModel: _._nextUint8(),
  55013. colorPrimaries: _._nextUint8(),
  55014. transferFunction: _._nextUint8(),
  55015. flags: _._nextUint8(),
  55016. texelBlockDimension: [_._nextUint8(), _._nextUint8(), _._nextUint8(), _._nextUint8()],
  55017. bytesPlane: [_._nextUint8(), _._nextUint8(), _._nextUint8(), _._nextUint8(), _._nextUint8(), _._nextUint8(), _._nextUint8(), _._nextUint8()],
  55018. samples: []
  55019. },
  55020. g = (p.descriptorBlockSize / 4 - 6) / 4;
  55021. for (var _t2 = 0; _t2 < g; _t2++) {
  55022. var _e4 = {
  55023. bitOffset: _._nextUint16(),
  55024. bitLength: _._nextUint8(),
  55025. channelType: _._nextUint8(),
  55026. samplePosition: [_._nextUint8(), _._nextUint8(), _._nextUint8(), _._nextUint8()],
  55027. sampleLower: -Infinity,
  55028. sampleUpper: Infinity
  55029. };
  55030. 64 & _e4.channelType ? (_e4.sampleLower = _._nextInt32(), _e4.sampleUpper = _._nextInt32()) : (_e4.sampleLower = _._nextUint32(), _e4.sampleUpper = _._nextUint32()), p.samples[_t2] = _e4;
  55031. }
  55032. n.dataFormatDescriptor.length = 0, n.dataFormatDescriptor.push(p);
  55033. var y = new Ii(t, l, f, !0);
  55034. for (; y._offset < f;) {
  55035. var _t3 = y._nextUint32(),
  55036. _e5 = y._scan(_t3),
  55037. _i2 = Ei(_e5),
  55038. _s = y._scan(_t3 - _e5.byteLength);
  55039. n.keyValue[_i2] = _i2.match(/^ktx/i) ? Ei(_s) : _s, y._offset % 4 && y._skip(4 - y._offset % 4);
  55040. }
  55041. if (c <= 0) return n;
  55042. var x = new Ii(t, U, c, !0),
  55043. u = x._nextUint16(),
  55044. b = x._nextUint16(),
  55045. d = x._nextUint32(),
  55046. m = x._nextUint32(),
  55047. w = x._nextUint32(),
  55048. D = x._nextUint32(),
  55049. B = [];
  55050. for (var _t4 = 0; _t4 < a; _t4++) B.push({
  55051. imageFlags: x._nextUint32(),
  55052. rgbSliceByteOffset: x._nextUint32(),
  55053. rgbSliceByteLength: x._nextUint32(),
  55054. alphaSliceByteOffset: x._nextUint32(),
  55055. alphaSliceByteLength: x._nextUint32()
  55056. });
  55057. var L = U + x._offset,
  55058. A = L + d,
  55059. k = A + m,
  55060. v = k + w,
  55061. S = new Uint8Array(t.buffer, t.byteOffset + L, d),
  55062. I = new Uint8Array(t.buffer, t.byteOffset + A, m),
  55063. O = new Uint8Array(t.buffer, t.byteOffset + k, w),
  55064. T = new Uint8Array(t.buffer, t.byteOffset + v, D);
  55065. return n.globalData = {
  55066. endpointCount: u,
  55067. selectorCount: b,
  55068. imageDescs: B,
  55069. endpointsData: S,
  55070. selectorsData: I,
  55071. tablesData: O,
  55072. extendedData: T
  55073. }, n;
  55074. }
  55075. function Ci() {
  55076. return (Ci = Object.assign || function (t) {
  55077. for (var e = 1; e < arguments.length; e++) {
  55078. var n = arguments[e];
  55079. for (var i in n) Object.prototype.hasOwnProperty.call(n, i) && (t[i] = n[i]);
  55080. }
  55081. return t;
  55082. }).apply(this, arguments);
  55083. }
  55084. var zi = {
  55085. keepWriter: !1
  55086. };
  55087. function Mi(t) {
  55088. var e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  55089. e = Ci({}, zi, e);
  55090. var n = new ArrayBuffer(0);
  55091. if (t.globalData) {
  55092. var _e6 = new ArrayBuffer(20 + 5 * t.globalData.imageDescs.length * 4),
  55093. _i3 = new DataView(_e6);
  55094. _i3.setUint16(0, t.globalData.endpointCount, !0), _i3.setUint16(2, t.globalData.selectorCount, !0), _i3.setUint32(4, t.globalData.endpointsData.byteLength, !0), _i3.setUint32(8, t.globalData.selectorsData.byteLength, !0), _i3.setUint32(12, t.globalData.tablesData.byteLength, !0), _i3.setUint32(16, t.globalData.extendedData.byteLength, !0);
  55095. for (var _e7 = 0; _e7 < t.globalData.imageDescs.length; _e7++) {
  55096. var _n3 = t.globalData.imageDescs[_e7];
  55097. _i3.setUint32(20 + 5 * _e7 * 4 + 0, _n3.imageFlags, !0), _i3.setUint32(20 + 5 * _e7 * 4 + 4, _n3.rgbSliceByteOffset, !0), _i3.setUint32(20 + 5 * _e7 * 4 + 8, _n3.rgbSliceByteLength, !0), _i3.setUint32(20 + 5 * _e7 * 4 + 12, _n3.alphaSliceByteOffset, !0), _i3.setUint32(20 + 5 * _e7 * 4 + 16, _n3.alphaSliceByteLength, !0);
  55098. }
  55099. n = Fi([_e6, t.globalData.endpointsData, t.globalData.selectorsData, t.globalData.tablesData, t.globalData.extendedData]);
  55100. }
  55101. var i = [];
  55102. var s = t.keyValue;
  55103. e.keepWriter || (s = Ci({}, t.keyValue, {
  55104. KTXwriter: "KTX-Parse v0.3.1"
  55105. }));
  55106. for (var _t5 in s) {
  55107. var _e8 = s[_t5],
  55108. _n4 = Vi(_t5),
  55109. _a = "string" == typeof _e8 ? Vi(_e8) : _e8,
  55110. _r = _n4.byteLength + 1 + _a.byteLength + 1,
  55111. _o = _r % 4 ? 4 - _r % 4 : 0;
  55112. i.push(Fi([new Uint32Array([_r]), _n4, Oi, _a, Oi, new Uint8Array(_o).fill(0)]));
  55113. }
  55114. var a = Fi(i);
  55115. if (1 !== t.dataFormatDescriptor.length || 0 !== t.dataFormatDescriptor[0].descriptorType) throw new Error("Only BASICFORMAT Data Format Descriptor output supported.");
  55116. var r = t.dataFormatDescriptor[0],
  55117. o = new ArrayBuffer(28 + 16 * r.samples.length),
  55118. l = new DataView(o),
  55119. f = 24 + 16 * r.samples.length;
  55120. if (l.setUint32(0, o.byteLength, !0), l.setUint16(4, r.vendorId, !0), l.setUint16(6, r.descriptorType, !0), l.setUint16(8, r.versionNumber, !0), l.setUint16(10, f, !0), l.setUint8(12, r.colorModel), l.setUint8(13, r.colorPrimaries), l.setUint8(14, r.transferFunction), l.setUint8(15, r.flags), !Array.isArray(r.texelBlockDimension)) throw new Error("texelBlockDimension is now an array. For dimensionality `d`, set `d - 1`.");
  55121. l.setUint8(16, r.texelBlockDimension[0]), l.setUint8(17, r.texelBlockDimension[1]), l.setUint8(18, r.texelBlockDimension[2]), l.setUint8(19, r.texelBlockDimension[3]);
  55122. for (var _t6 = 0; _t6 < 8; _t6++) l.setUint8(20 + _t6, r.bytesPlane[_t6]);
  55123. for (var _t7 = 0; _t7 < r.samples.length; _t7++) {
  55124. var _e9 = r.samples[_t7],
  55125. _n5 = 28 + 16 * _t7;
  55126. if (_e9.channelID) throw new Error("channelID has been renamed to channelType.");
  55127. l.setUint16(_n5 + 0, _e9.bitOffset, !0), l.setUint8(_n5 + 2, _e9.bitLength), l.setUint8(_n5 + 3, _e9.channelType), l.setUint8(_n5 + 4, _e9.samplePosition[0]), l.setUint8(_n5 + 5, _e9.samplePosition[1]), l.setUint8(_n5 + 6, _e9.samplePosition[2]), l.setUint8(_n5 + 7, _e9.samplePosition[3]), 64 & _e9.channelType ? (l.setInt32(_n5 + 8, _e9.sampleLower, !0), l.setInt32(_n5 + 12, _e9.sampleUpper, !0)) : (l.setUint32(_n5 + 8, _e9.sampleLower, !0), l.setUint32(_n5 + 12, _e9.sampleUpper, !0));
  55128. }
  55129. var U = Ti.length + 68 + 3 * t.levels.length * 8,
  55130. c = U + o.byteLength;
  55131. var h = n.byteLength > 0 ? c + a.byteLength : 0;
  55132. h % 8 && (h += 8 - h % 8);
  55133. var _ = [],
  55134. p = new DataView(new ArrayBuffer(3 * t.levels.length * 8));
  55135. var g = (h || c + a.byteLength) + n.byteLength;
  55136. for (var _e10 = 0; _e10 < t.levels.length; _e10++) {
  55137. var _n6 = t.levels[_e10];
  55138. _.push(_n6.levelData), p.setBigUint64(24 * _e10 + 0, BigInt(g), !0), p.setBigUint64(24 * _e10 + 8, BigInt(_n6.levelData.byteLength), !0), p.setBigUint64(24 * _e10 + 16, BigInt(_n6.uncompressedByteLength), !0), g += _n6.levelData.byteLength;
  55139. }
  55140. var y = new ArrayBuffer(68),
  55141. x = new DataView(y);
  55142. return x.setUint32(0, t.vkFormat, !0), x.setUint32(4, t.typeSize, !0), x.setUint32(8, t.pixelWidth, !0), x.setUint32(12, t.pixelHeight, !0), x.setUint32(16, t.pixelDepth, !0), x.setUint32(20, t.layerCount, !0), x.setUint32(24, t.faceCount, !0), x.setUint32(28, t.levels.length, !0), x.setUint32(32, t.supercompressionScheme, !0), x.setUint32(36, U, !0), x.setUint32(40, o.byteLength, !0), x.setUint32(44, c, !0), x.setUint32(48, a.byteLength, !0), x.setBigUint64(52, BigInt(n.byteLength > 0 ? h : 0), !0), x.setBigUint64(60, BigInt(n.byteLength), !0), new Uint8Array(Fi([new Uint8Array(Ti).buffer, y, p.buffer, o, a, h > 0 ? new ArrayBuffer(h - (c + a.byteLength)) : new ArrayBuffer(0), n, ..._]));
  55143. }
  55144. /**
  55145. * @author Don McCurdy / https://www.donmccurdy.com
  55146. */
  55147. var init, instance, heap;
  55148. var importObject = {
  55149. env: {
  55150. emscripten_notify_memory_growth: function emscripten_notify_memory_growth(index) {
  55151. heap = new Uint8Array(instance.exports.memory.buffer);
  55152. }
  55153. }
  55154. };
  55155. /**
  55156. * ZSTD (Zstandard) decoder.
  55157. *
  55158. * Compiled from https://github.com/facebook/zstd/tree/dev/contrib/single_file_libs, with the
  55159. * following steps:
  55160. *
  55161. * ```
  55162. * ./combine.sh -r ../../lib -o zstddeclib.c zstddeclib-in.c
  55163. * emcc zstddeclib.c -Oz -s EXPORTED_FUNCTIONS="['_ZSTD_decompress', '_ZSTD_findDecompressedSize', '_ZSTD_isError', '_malloc', '_free']" -s ALLOW_MEMORY_GROWTH=1 -s MALLOC=emmalloc -o zstddec.wasm
  55164. * base64 zstddec.wasm > zstddec.txt
  55165. * ```
  55166. *
  55167. * The base64 string written to `zstddec.txt` is embedded as the `wasm` variable at the bottom
  55168. * of this file. The rest of this file is written by hand, in order to avoid an additional JS
  55169. * wrapper generated by Emscripten.
  55170. */
  55171. class ZSTDDecoder {
  55172. init() {
  55173. if (!init) {
  55174. init = fetch('data:application/wasm;base64,' + wasm).then(response => response.arrayBuffer()).then(arrayBuffer => WebAssembly.instantiate(arrayBuffer, importObject)).then(result => {
  55175. instance = result.instance;
  55176. importObject.env.emscripten_notify_memory_growth(0); // initialize heap.
  55177. });
  55178. }
  55179. return init;
  55180. }
  55181. decode(array) {
  55182. var uncompressedSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  55183. // Write compressed data into WASM memory.
  55184. var compressedSize = array.byteLength;
  55185. var compressedPtr = instance.exports.malloc(compressedSize);
  55186. heap.set(array, compressedPtr);
  55187. // Decompress into WASM memory.
  55188. uncompressedSize = uncompressedSize || Number(instance.exports.ZSTD_findDecompressedSize(compressedPtr, compressedSize));
  55189. var uncompressedPtr = instance.exports.malloc(uncompressedSize);
  55190. var actualSize = instance.exports.ZSTD_decompress(uncompressedPtr, uncompressedSize, compressedPtr, compressedSize);
  55191. // Read decompressed data and free WASM memory.
  55192. var dec = heap.slice(uncompressedPtr, uncompressedPtr + actualSize);
  55193. instance.exports.free(compressedPtr);
  55194. instance.exports.free(uncompressedPtr);
  55195. return dec;
  55196. }
  55197. }
  55198. /**
  55199. * BSD License
  55200. *
  55201. * For Zstandard software
  55202. *
  55203. * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. All rights reserved.
  55204. *
  55205. * Redistribution and use in source and binary forms, with or without modification,
  55206. * are permitted provided that the following conditions are met:
  55207. *
  55208. * * Redistributions of source code must retain the above copyright notice, this
  55209. * list of conditions and the following disclaimer.
  55210. *
  55211. * * Redistributions in binary form must reproduce the above copyright notice,
  55212. * this list of conditions and the following disclaimer in the documentation
  55213. * and/or other materials provided with the distribution.
  55214. *
  55215. * * Neither the name Facebook nor the names of its contributors may be used to
  55216. * endorse or promote products derived from this software without specific
  55217. * prior written permission.
  55218. *
  55219. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  55220. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  55221. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  55222. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  55223. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  55224. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  55225. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  55226. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  55227. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  55228. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  55229. */
  55230. var wasm = 'AGFzbQEAAAABpQEVYAF/AX9gAn9/AGADf39/AX9gBX9/f39/AX9gAX8AYAJ/fwF/YAR/f39/AX9gA39/fwBgBn9/f39/fwF/YAd/f39/f39/AX9gAn9/AX5gAn5+AX5gAABgBX9/f39/AGAGf39/f39/AGAIf39/f39/f38AYAl/f39/f39/f38AYAABf2AIf39/f39/f38Bf2ANf39/f39/f39/f39/fwF/YAF/AX4CJwEDZW52H2Vtc2NyaXB0ZW5fbm90aWZ5X21lbW9yeV9ncm93dGgABANpaAEFAAAFAgEFCwACAQABAgIFBQcAAwABDgsBAQcAEhMHAAUBDAQEAAANBwQCAgYCBAgDAwMDBgEACQkHBgICAAYGAgQUBwYGAwIGAAMCAQgBBwUGCgoEEQAEBAEIAwgDBQgDEA8IAAcABAUBcAECAgUEAQCAAgYJAX8BQaCgwAILB2AHBm1lbW9yeQIABm1hbGxvYwAoBGZyZWUAJgxaU1REX2lzRXJyb3IAaBlaU1REX2ZpbmREZWNvbXByZXNzZWRTaXplAFQPWlNURF9kZWNvbXByZXNzAEoGX3N0YXJ0ACQJBwEAQQELASQKussBaA8AIAAgACgCBCABajYCBAsZACAAKAIAIAAoAgRBH3F0QQAgAWtBH3F2CwgAIABBiH9LC34BBH9BAyEBIAAoAgQiA0EgTQRAIAAoAggiASAAKAIQTwRAIAAQDQ8LIAAoAgwiAiABRgRAQQFBAiADQSBJGw8LIAAgASABIAJrIANBA3YiBCABIARrIAJJIgEbIgJrIgQ2AgggACADIAJBA3RrNgIEIAAgBCgAADYCAAsgAQsUAQF/IAAgARACIQIgACABEAEgAgv3AQECfyACRQRAIABCADcCACAAQQA2AhAgAEIANwIIQbh/DwsgACABNgIMIAAgAUEEajYCECACQQRPBEAgACABIAJqIgFBfGoiAzYCCCAAIAMoAAA2AgAgAUF/ai0AACIBBEAgAEEIIAEQFGs2AgQgAg8LIABBADYCBEF/DwsgACABNgIIIAAgAS0AACIDNgIAIAJBfmoiBEEBTQRAIARBAWtFBEAgACABLQACQRB0IANyIgM2AgALIAAgAS0AAUEIdCADajYCAAsgASACakF/ai0AACIBRQRAIABBADYCBEFsDwsgAEEoIAEQFCACQQN0ams2AgQgAgsWACAAIAEpAAA3AAAgACABKQAINwAICy8BAX8gAUECdEGgHWooAgAgACgCAEEgIAEgACgCBGprQR9xdnEhAiAAIAEQASACCyEAIAFCz9bTvtLHq9lCfiAAfEIfiUKHla+vmLbem55/fgsdAQF/IAAoAgggACgCDEYEfyAAKAIEQSBGBUEACwuCBAEDfyACQYDAAE8EQCAAIAEgAhBnIAAPCyAAIAJqIQMCQCAAIAFzQQNxRQRAAkAgAkEBSARAIAAhAgwBCyAAQQNxRQRAIAAhAgwBCyAAIQIDQCACIAEtAAA6AAAgAUEBaiEBIAJBAWoiAiADTw0BIAJBA3ENAAsLAkAgA0F8cSIEQcAASQ0AIAIgBEFAaiIFSw0AA0AgAiABKAIANgIAIAIgASgCBDYCBCACIAEoAgg2AgggAiABKAIMNgIMIAIgASgCEDYCECACIAEoAhQ2AhQgAiABKAIYNgIYIAIgASgCHDYCHCACIAEoAiA2AiAgAiABKAIkNgIkIAIgASgCKDYCKCACIAEoAiw2AiwgAiABKAIwNgIwIAIgASgCNDYCNCACIAEoAjg2AjggAiABKAI8NgI8IAFBQGshASACQUBrIgIgBU0NAAsLIAIgBE8NAQNAIAIgASgCADYCACABQQRqIQEgAkEEaiICIARJDQALDAELIANBBEkEQCAAIQIMAQsgA0F8aiIEIABJBEAgACECDAELIAAhAgNAIAIgAS0AADoAACACIAEtAAE6AAEgAiABLQACOgACIAIgAS0AAzoAAyABQQRqIQEgAkEEaiICIARNDQALCyACIANJBEADQCACIAEtAAA6AAAgAUEBaiEBIAJBAWoiAiADRw0ACwsgAAsMACAAIAEpAAA3AAALQQECfyAAKAIIIgEgACgCEEkEQEEDDwsgACAAKAIEIgJBB3E2AgQgACABIAJBA3ZrIgE2AgggACABKAAANgIAQQALDAAgACABKAIANgAAC/cCAQJ/AkAgACABRg0AAkAgASACaiAASwRAIAAgAmoiBCABSw0BCyAAIAEgAhALDwsgACABc0EDcSEDAkACQCAAIAFJBEAgAwRAIAAhAwwDCyAAQQNxRQRAIAAhAwwCCyAAIQMDQCACRQ0EIAMgAS0AADoAACABQQFqIQEgAkF/aiECIANBAWoiA0EDcQ0ACwwBCwJAIAMNACAEQQNxBEADQCACRQ0FIAAgAkF/aiICaiIDIAEgAmotAAA6AAAgA0EDcQ0ACwsgAkEDTQ0AA0AgACACQXxqIgJqIAEgAmooAgA2AgAgAkEDSw0ACwsgAkUNAgNAIAAgAkF/aiICaiABIAJqLQAAOgAAIAINAAsMAgsgAkEDTQ0AIAIhBANAIAMgASgCADYCACABQQRqIQEgA0EEaiEDIARBfGoiBEEDSw0ACyACQQNxIQILIAJFDQADQCADIAEtAAA6AAAgA0EBaiEDIAFBAWohASACQX9qIgINAAsLIAAL8wICAn8BfgJAIAJFDQAgACACaiIDQX9qIAE6AAAgACABOgAAIAJBA0kNACADQX5qIAE6AAAgACABOgABIANBfWogAToAACAAIAE6AAIgAkEHSQ0AIANBfGogAToAACAAIAE6AAMgAkEJSQ0AIABBACAAa0EDcSIEaiIDIAFB/wFxQYGChAhsIgE2AgAgAyACIARrQXxxIgRqIgJBfGogATYCACAEQQlJDQAgAyABNgIIIAMgATYCBCACQXhqIAE2AgAgAkF0aiABNgIAIARBGUkNACADIAE2AhggAyABNgIUIAMgATYCECADIAE2AgwgAkFwaiABNgIAIAJBbGogATYCACACQWhqIAE2AgAgAkFkaiABNgIAIAQgA0EEcUEYciIEayICQSBJDQAgAa0iBUIghiAFhCEFIAMgBGohAQNAIAEgBTcDGCABIAU3AxAgASAFNwMIIAEgBTcDACABQSBqIQEgAkFgaiICQR9LDQALCyAACy8BAn8gACgCBCAAKAIAQQJ0aiICLQACIQMgACACLwEAIAEgAi0AAxAIajYCACADCy8BAn8gACgCBCAAKAIAQQJ0aiICLQACIQMgACACLwEAIAEgAi0AAxAFajYCACADCx8AIAAgASACKAIEEAg2AgAgARAEGiAAIAJBCGo2AgQLCAAgAGdBH3MLugUBDX8jAEEQayIKJAACfyAEQQNNBEAgCkEANgIMIApBDGogAyAEEAsaIAAgASACIApBDGpBBBAVIgBBbCAAEAMbIAAgACAESxsMAQsgAEEAIAEoAgBBAXRBAmoQECENQVQgAygAACIGQQ9xIgBBCksNABogAiAAQQVqNgIAIAMgBGoiAkF8aiEMIAJBeWohDiACQXtqIRAgAEEGaiELQQQhBSAGQQR2IQRBICAAdCIAQQFyIQkgASgCACEPQQAhAiADIQYCQANAIAlBAkggAiAPS3JFBEAgAiEHAkAgCARAA0AgBEH//wNxQf//A0YEQCAHQRhqIQcgBiAQSQR/IAZBAmoiBigAACAFdgUgBUEQaiEFIARBEHYLIQQMAQsLA0AgBEEDcSIIQQNGBEAgBUECaiEFIARBAnYhBCAHQQNqIQcMAQsLIAcgCGoiByAPSw0EIAVBAmohBQNAIAIgB0kEQCANIAJBAXRqQQA7AQAgAkEBaiECDAELCyAGIA5LQQAgBiAFQQN1aiIHIAxLG0UEQCAHKAAAIAVBB3EiBXYhBAwCCyAEQQJ2IQQLIAYhBwsCfyALQX9qIAQgAEF/anEiBiAAQQF0QX9qIgggCWsiEUkNABogBCAIcSIEQQAgESAEIABIG2shBiALCyEIIA0gAkEBdGogBkF/aiIEOwEAIAlBASAGayAEIAZBAUgbayEJA0AgCSAASARAIABBAXUhACALQX9qIQsMAQsLAn8gByAOS0EAIAcgBSAIaiIFQQN1aiIGIAxLG0UEQCAFQQdxDAELIAUgDCIGIAdrQQN0awshBSACQQFqIQIgBEUhCCAGKAAAIAVBH3F2IQQMAQsLQWwgCUEBRyAFQSBKcg0BGiABIAJBf2o2AgAgBiAFQQdqQQN1aiADawwBC0FQCyEAIApBEGokACAACwkAQQFBBSAAGwsMACAAIAEoAAA2AAALqgMBCn8jAEHwAGsiCiQAIAJBAWohDiAAQQhqIQtBgIAEIAVBf2p0QRB1IQxBACECQQEhBkEBIAV0IglBf2oiDyEIA0AgAiAORkUEQAJAIAEgAkEBdCINai8BACIHQf//A0YEQCALIAhBA3RqIAI2AgQgCEF/aiEIQQEhBwwBCyAGQQAgDCAHQRB0QRB1ShshBgsgCiANaiAHOwEAIAJBAWohAgwBCwsgACAFNgIEIAAgBjYCACAJQQN2IAlBAXZqQQNqIQxBACEAQQAhBkEAIQIDQCAGIA5GBEADQAJAIAAgCUYNACAKIAsgAEEDdGoiASgCBCIGQQF0aiICIAIvAQAiAkEBajsBACABIAUgAhAUayIIOgADIAEgAiAIQf8BcXQgCWs7AQAgASAEIAZBAnQiAmooAgA6AAIgASACIANqKAIANgIEIABBAWohAAwBCwsFIAEgBkEBdGouAQAhDUEAIQcDQCAHIA1ORQRAIAsgAkEDdGogBjYCBANAIAIgDGogD3EiAiAISw0ACyAHQQFqIQcMAQsLIAZBAWohBgwBCwsgCkHwAGokAAsjAEIAIAEQCSAAhUKHla+vmLbem55/fkLj3MqV/M7y9YV/fAsQACAAQn43AwggACABNgIACyQBAX8gAARAIAEoAgQiAgRAIAEoAgggACACEQEADwsgABAmCwsfACAAIAEgAi8BABAINgIAIAEQBBogACACQQRqNgIEC0oBAX9BoCAoAgAiASAAaiIAQX9MBEBBiCBBMDYCAEF/DwsCQCAAPwBBEHRNDQAgABBmDQBBiCBBMDYCAEF/DwtBoCAgADYCACABC9cBAQh/Qbp/IQoCQCACKAIEIgggAigCACIJaiIOIAEgAGtLDQBBbCEKIAkgBCADKAIAIgtrSw0AIAAgCWoiBCACKAIIIgxrIQ0gACABQWBqIg8gCyAJQQAQKSADIAkgC2o2AgACQAJAIAwgBCAFa00EQCANIQUMAQsgDCAEIAZrSw0CIAcgDSAFayIAaiIBIAhqIAdNBEAgBCABIAgQDxoMAgsgBCABQQAgAGsQDyEBIAIgACAIaiIINgIEIAEgAGshBAsgBCAPIAUgCEEBECkLIA4hCgsgCgubAgEBfyMAQYABayINJAAgDSADNgJ8AkAgAkEDSwRAQX8hCQwBCwJAAkACQAJAIAJBAWsOAwADAgELIAZFBEBBuH8hCQwEC0FsIQkgBS0AACICIANLDQMgACAHIAJBAnQiAmooAgAgAiAIaigCABA7IAEgADYCAEEBIQkMAwsgASAJNgIAQQAhCQwCCyAKRQRAQWwhCQwCC0EAIQkgC0UgDEEZSHINAUEIIAR0QQhqIQBBACECA0AgAiAATw0CIAJBQGshAgwAAAsAC0FsIQkgDSANQfwAaiANQfgAaiAFIAYQFSICEAMNACANKAJ4IgMgBEsNACAAIA0gDSgCfCAHIAggAxAYIAEgADYCACACIQkLIA1BgAFqJAAgCQsLACAAIAEgAhALGgsQACAALwAAIAAtAAJBEHRyCy8AAn9BuH8gAUEISQ0AGkFyIAAoAAQiAEF3Sw0AGkG4fyAAQQhqIgAgACABSxsLCwkAIAAgATsAAAsDAAELigYBBX8gACAAKAIAIgVBfnE2AgBBACAAIAVBAXZqQYQgKAIAIgQgAEYbIQECQAJAIAAoAgQiAkUNACACKAIAIgNBAXENACACQQhqIgUgA0EBdkF4aiIDQQggA0EISxtnQR9zQQJ0QYAfaiIDKAIARgRAIAMgAigCDDYCAAsgAigCCCIDBEAgAyACKAIMNgIECyACKAIMIgMEQCADIAIoAgg2AgALIAIgAigCACAAKAIAQX5xajYCAEGEICEAAkACQCABRQ0AIAEgAjYCBCABKAIAIgNBAXENASADQQF2QXhqIgNBCCADQQhLG2dBH3NBAnRBgB9qIgMoAgAgAUEIakYEQCADIAEoAgw2AgALIAEoAggiAwRAIAMgASgCDDYCBAsgASgCDCIDBEAgAyABKAIINgIAQYQgKAIAIQQLIAIgAigCACABKAIAQX5xajYCACABIARGDQAgASABKAIAQQF2akEEaiEACyAAIAI2AgALIAIoAgBBAXZBeGoiAEEIIABBCEsbZ0Efc0ECdEGAH2oiASgCACEAIAEgBTYCACACIAA2AgwgAkEANgIIIABFDQEgACAFNgIADwsCQCABRQ0AIAEoAgAiAkEBcQ0AIAJBAXZBeGoiAkEIIAJBCEsbZ0Efc0ECdEGAH2oiAigCACABQQhqRgRAIAIgASgCDDYCAAsgASgCCCICBEAgAiABKAIMNgIECyABKAIMIgIEQCACIAEoAgg2AgBBhCAoAgAhBAsgACAAKAIAIAEoAgBBfnFqIgI2AgACQCABIARHBEAgASABKAIAQQF2aiAANgIEIAAoAgAhAgwBC0GEICAANgIACyACQQF2QXhqIgFBCCABQQhLG2dBH3NBAnRBgB9qIgIoAgAhASACIABBCGoiAjYCACAAIAE2AgwgAEEANgIIIAFFDQEgASACNgIADwsgBUEBdkF4aiIBQQggAUEISxtnQR9zQQJ0QYAfaiICKAIAIQEgAiAAQQhqIgI2AgAgACABNgIMIABBADYCCCABRQ0AIAEgAjYCAAsLDgAgAARAIABBeGoQJQsLgAIBA38CQCAAQQ9qQXhxQYQgKAIAKAIAQQF2ayICEB1Bf0YNAAJAQYQgKAIAIgAoAgAiAUEBcQ0AIAFBAXZBeGoiAUEIIAFBCEsbZ0Efc0ECdEGAH2oiASgCACAAQQhqRgRAIAEgACgCDDYCAAsgACgCCCIBBEAgASAAKAIMNgIECyAAKAIMIgFFDQAgASAAKAIINgIAC0EBIQEgACAAKAIAIAJBAXRqIgI2AgAgAkEBcQ0AIAJBAXZBeGoiAkEIIAJBCEsbZ0Efc0ECdEGAH2oiAygCACECIAMgAEEIaiIDNgIAIAAgAjYCDCAAQQA2AgggAkUNACACIAM2AgALIAELtwIBA38CQAJAIABBASAAGyICEDgiAA0AAkACQEGEICgCACIARQ0AIAAoAgAiA0EBcQ0AIAAgA0EBcjYCACADQQF2QXhqIgFBCCABQQhLG2dBH3NBAnRBgB9qIgEoAgAgAEEIakYEQCABIAAoAgw2AgALIAAoAggiAQRAIAEgACgCDDYCBAsgACgCDCIBBEAgASAAKAIINgIACyACECchAkEAIQFBhCAoAgAhACACDQEgACAAKAIAQX5xNgIAQQAPCyACQQ9qQXhxIgMQHSICQX9GDQIgAkEHakF4cSIAIAJHBEAgACACaxAdQX9GDQMLAkBBhCAoAgAiAUUEQEGAICAANgIADAELIAAgATYCBAtBhCAgADYCACAAIANBAXRBAXI2AgAMAQsgAEUNAQsgAEEIaiEBCyABC7kDAQJ/IAAgA2ohBQJAIANBB0wEQANAIAAgBU8NAiAAIAItAAA6AAAgAEEBaiEAIAJBAWohAgwAAAsACyAEQQFGBEACQCAAIAJrIgZBB00EQCAAIAItAAA6AAAgACACLQABOgABIAAgAi0AAjoAAiAAIAItAAM6AAMgAEEEaiACIAZBAnQiBkHAHmooAgBqIgIQFyACIAZB4B5qKAIAayECDAELIAAgAhAMCyACQQhqIQIgAEEIaiEACwJAAkACQAJAIAUgAU0EQCAAIANqIQEgBEEBRyAAIAJrQQ9Kcg0BA0AgACACEAwgAkEIaiECIABBCGoiACABSQ0ACwwFCyAAIAFLBEAgACEBDAQLIARBAUcgACACa0EPSnINASAAIQMgAiEEA0AgAyAEEAwgBEEIaiEEIANBCGoiAyABSQ0ACwwCCwNAIAAgAhAHIAJBEGohAiAAQRBqIgAgAUkNAAsMAwsgACEDIAIhBANAIAMgBBAHIARBEGohBCADQRBqIgMgAUkNAAsLIAIgASAAa2ohAgsDQCABIAVPDQEgASACLQAAOgAAIAFBAWohASACQQFqIQIMAAALAAsLQQECfyAAIAAoArjgASIDNgLE4AEgACgCvOABIQQgACABNgK84AEgACABIAJqNgK44AEgACABIAQgA2tqNgLA4AELpgEBAX8gACAAKALs4QEQFjYCyOABIABCADcD+OABIABCADcDuOABIABBwOABakIANwMAIABBqNAAaiIBQYyAgOAANgIAIABBADYCmOIBIABCADcDiOEBIABCAzcDgOEBIABBrNABakHgEikCADcCACAAQbTQAWpB6BIoAgA2AgAgACABNgIMIAAgAEGYIGo2AgggACAAQaAwajYCBCAAIABBEGo2AgALYQEBf0G4fyEDAkAgAUEDSQ0AIAIgABAhIgFBA3YiADYCCCACIAFBAXE2AgQgAiABQQF2QQNxIgM2AgACQCADQX9qIgFBAksNAAJAIAFBAWsOAgEAAgtBbA8LIAAhAwsgAwsMACAAIAEgAkEAEC4LiAQCA38CfiADEBYhBCAAQQBBKBAQIQAgBCACSwRAIAQPCyABRQRAQX8PCwJAAkAgA0EBRg0AIAEoAAAiBkGo6r5pRg0AQXYhAyAGQXBxQdDUtMIBRw0BQQghAyACQQhJDQEgAEEAQSgQECEAIAEoAAQhASAAQQE2AhQgACABrTcDAEEADwsgASACIAMQLyIDIAJLDQAgACADNgIYQXIhAyABIARqIgVBf2otAAAiAkEIcQ0AIAJBIHEiBkUEQEFwIQMgBS0AACIFQacBSw0BIAVBB3GtQgEgBUEDdkEKaq2GIgdCA4h+IAd8IQggBEEBaiEECyACQQZ2IQMgAkECdiEFAkAgAkEDcUF/aiICQQJLBEBBACECDAELAkACQAJAIAJBAWsOAgECAAsgASAEai0AACECIARBAWohBAwCCyABIARqLwAAIQIgBEECaiEEDAELIAEgBGooAAAhAiAEQQRqIQQLIAVBAXEhBQJ+AkACQAJAIANBf2oiA0ECTQRAIANBAWsOAgIDAQtCfyAGRQ0DGiABIARqMQAADAMLIAEgBGovAACtQoACfAwCCyABIARqKAAArQwBCyABIARqKQAACyEHIAAgBTYCICAAIAI2AhwgACAHNwMAQQAhAyAAQQA2AhQgACAHIAggBhsiBzcDCCAAIAdCgIAIIAdCgIAIVBs+AhALIAMLWwEBf0G4fyEDIAIQFiICIAFNBH8gACACakF/ai0AACIAQQNxQQJ0QaAeaigCACACaiAAQQZ2IgFBAnRBsB5qKAIAaiAAQSBxIgBFaiABRSAAQQV2cWoFQbh/CwsdACAAKAKQ4gEQWiAAQQA2AqDiASAAQgA3A5DiAQu1AwEFfyMAQZACayIKJABBuH8hBgJAIAVFDQAgBCwAACIIQf8BcSEHAkAgCEF/TARAIAdBgn9qQQF2IgggBU8NAkFsIQYgB0GBf2oiBUGAAk8NAiAEQQFqIQdBACEGA0AgBiAFTwRAIAUhBiAIIQcMAwUgACAGaiAHIAZBAXZqIgQtAABBBHY6AAAgACAGQQFyaiAELQAAQQ9xOgAAIAZBAmohBgwBCwAACwALIAcgBU8NASAAIARBAWogByAKEFMiBhADDQELIAYhBEEAIQYgAUEAQTQQECEJQQAhBQNAIAQgBkcEQCAAIAZqIggtAAAiAUELSwRAQWwhBgwDBSAJIAFBAnRqIgEgASgCAEEBajYCACAGQQFqIQZBASAILQAAdEEBdSAFaiEFDAILAAsLQWwhBiAFRQ0AIAUQFEEBaiIBQQxLDQAgAyABNgIAQQFBASABdCAFayIDEBQiAXQgA0cNACAAIARqIAFBAWoiADoAACAJIABBAnRqIgAgACgCAEEBajYCACAJKAIEIgBBAkkgAEEBcXINACACIARBAWo2AgAgB0EBaiEGCyAKQZACaiQAIAYLxhEBDH8jAEHwAGsiBSQAQWwhCwJAIANBCkkNACACLwAAIQogAi8AAiEJIAIvAAQhByAFQQhqIAQQDgJAIAMgByAJIApqakEGaiIMSQ0AIAUtAAohCCAFQdgAaiACQQZqIgIgChAGIgsQAw0BIAVBQGsgAiAKaiICIAkQBiILEAMNASAFQShqIAIgCWoiAiAHEAYiCxADDQEgBUEQaiACIAdqIAMgDGsQBiILEAMNASAAIAFqIg9BfWohECAEQQRqIQZBASELIAAgAUEDakECdiIDaiIMIANqIgIgA2oiDiEDIAIhBCAMIQcDQCALIAMgEElxBEAgACAGIAVB2ABqIAgQAkECdGoiCS8BADsAACAFQdgAaiAJLQACEAEgCS0AAyELIAcgBiAFQUBrIAgQAkECdGoiCS8BADsAACAFQUBrIAktAAIQASAJLQADIQogBCAGIAVBKGogCBACQQJ0aiIJLwEAOwAAIAVBKGogCS0AAhABIAktAAMhCSADIAYgBUEQaiAIEAJBAnRqIg0vAQA7AAAgBUEQaiANLQACEAEgDS0AAyENIAAgC2oiCyAGIAVB2ABqIAgQAkECdGoiAC8BADsAACAFQdgAaiAALQACEAEgAC0AAyEAIAcgCmoiCiAGIAVBQGsgCBACQQJ0aiIHLwEAOwAAIAVBQGsgBy0AAhABIActAAMhByAEIAlqIgkgBiAFQShqIAgQAkECdGoiBC8BADsAACAFQShqIAQtAAIQASAELQADIQQgAyANaiIDIAYgBUEQaiAIEAJBAnRqIg0vAQA7AAAgBUEQaiANLQACEAEgACALaiEAIAcgCmohByAEIAlqIQQgAyANLQADaiEDIAVB2ABqEA0gBUFAaxANciAFQShqEA1yIAVBEGoQDXJFIQsMAQsLIAQgDksgByACS3INAEFsIQsgACAMSw0BIAxBfWohCQNAQQAgACAJSSAFQdgAahAEGwRAIAAgBiAFQdgAaiAIEAJBAnRqIgovAQA7AAAgBUHYAGogCi0AAhABIAAgCi0AA2oiACAGIAVB2ABqIAgQAkECdGoiCi8BADsAACAFQdgAaiAKLQACEAEgACAKLQADaiEADAEFIAxBfmohCgNAIAVB2ABqEAQgACAKS3JFBEAgACAGIAVB2ABqIAgQAkECdGoiCS8BADsAACAFQdgAaiAJLQACEAEgACAJLQADaiEADAELCwNAIAAgCk0EQCAAIAYgBUHYAGogCBACQQJ0aiIJLwEAOwAAIAVB2ABqIAktAAIQASAAIAktAANqIQAMAQsLAkAgACAMTw0AIAAgBiAFQdgAaiAIEAIiAEECdGoiDC0AADoAACAMLQADQQFGBEAgBUHYAGogDC0AAhABDAELIAUoAlxBH0sNACAFQdgAaiAGIABBAnRqLQACEAEgBSgCXEEhSQ0AIAVBIDYCXAsgAkF9aiEMA0BBACAHIAxJIAVBQGsQBBsEQCAHIAYgBUFAayAIEAJBAnRqIgAvAQA7AAAgBUFAayAALQACEAEgByAALQADaiIAIAYgBUFAayAIEAJBAnRqIgcvAQA7AAAgBUFAayAHLQACEAEgACAHLQADaiEHDAEFIAJBfmohDANAIAVBQGsQBCAHIAxLckUEQCAHIAYgBUFAayAIEAJBAnRqIgAvAQA7AAAgBUFAayAALQACEAEgByAALQADaiEHDAELCwNAIAcgDE0EQCAHIAYgBUFAayAIEAJBAnRqIgAvAQA7AAAgBUFAayAALQACEAEgByAALQADaiEHDAELCwJAIAcgAk8NACAHIAYgBUFAayAIEAIiAEECdGoiAi0AADoAACACLQADQQFGBEAgBUFAayACLQACEAEMAQsgBSgCREEfSw0AIAVBQGsgBiAAQQJ0ai0AAhABIAUoAkRBIUkNACAFQSA2AkQLIA5BfWohAgNAQQAgBCACSSAFQShqEAQbBEAgBCAGIAVBKGogCBACQQJ0aiIALwEAOwAAIAVBKGogAC0AAhABIAQgAC0AA2oiACAGIAVBKGogCBACQQJ0aiIELwEAOwAAIAVBKGogBC0AAhABIAAgBC0AA2ohBAwBBSAOQX5qIQIDQCAFQShqEAQgBCACS3JFBEAgBCAGIAVBKGogCBACQQJ0aiIALwEAOwAAIAVBKGogAC0AAhABIAQgAC0AA2ohBAwBCwsDQCAEIAJNBEAgBCAGIAVBKGogCBACQQJ0aiIALwEAOwAAIAVBKGogAC0AAhABIAQgAC0AA2ohBAwBCwsCQCAEIA5PDQAgBCAGIAVBKGogCBACIgBBAnRqIgItAAA6AAAgAi0AA0EBRgRAIAVBKGogAi0AAhABDAELIAUoAixBH0sNACAFQShqIAYgAEECdGotAAIQASAFKAIsQSFJDQAgBUEgNgIsCwNAQQAgAyAQSSAFQRBqEAQbBEAgAyAGIAVBEGogCBACQQJ0aiIALwEAOwAAIAVBEGogAC0AAhABIAMgAC0AA2oiACAGIAVBEGogCBACQQJ0aiICLwEAOwAAIAVBEGogAi0AAhABIAAgAi0AA2ohAwwBBSAPQX5qIQIDQCAFQRBqEAQgAyACS3JFBEAgAyAGIAVBEGogCBACQQJ0aiIALwEAOwAAIAVBEGogAC0AAhABIAMgAC0AA2ohAwwBCwsDQCADIAJNBEAgAyAGIAVBEGogCBACQQJ0aiIALwEAOwAAIAVBEGogAC0AAhABIAMgAC0AA2ohAwwBCwsCQCADIA9PDQAgAyAGIAVBEGogCBACIgBBAnRqIgItAAA6AAAgAi0AA0EBRgRAIAVBEGogAi0AAhABDAELIAUoAhRBH0sNACAFQRBqIAYgAEECdGotAAIQASAFKAIUQSFJDQAgBUEgNgIUCyABQWwgBUHYAGoQCiAFQUBrEApxIAVBKGoQCnEgBUEQahAKcRshCwwJCwAACwALAAALAAsAAAsACwAACwALQWwhCwsgBUHwAGokACALC7UEAQ5/IwBBEGsiBiQAIAZBBGogABAOQVQhBQJAIARB3AtJDQAgBi0ABCEHIANB8ARqQQBB7AAQECEIIAdBDEsNACADQdwJaiIJIAggBkEIaiAGQQxqIAEgAhAxIhAQA0UEQCAGKAIMIgQgB0sNASADQdwFaiEPIANBpAVqIREgAEEEaiESIANBqAVqIQEgBCEFA0AgBSICQX9qIQUgCCACQQJ0aigCAEUNAAsgAkEBaiEOQQEhBQNAIAUgDk9FBEAgCCAFQQJ0IgtqKAIAIQwgASALaiAKNgIAIAVBAWohBSAKIAxqIQoMAQsLIAEgCjYCAEEAIQUgBigCCCELA0AgBSALRkUEQCABIAUgCWotAAAiDEECdGoiDSANKAIAIg1BAWo2AgAgDyANQQF0aiINIAw6AAEgDSAFOgAAIAVBAWohBQwBCwtBACEBIANBADYCqAUgBEF/cyAHaiEJQQEhBQNAIAUgDk9FBEAgCCAFQQJ0IgtqKAIAIQwgAyALaiABNgIAIAwgBSAJanQgAWohASAFQQFqIQUMAQsLIAcgBEEBaiIBIAJrIgRrQQFqIQgDQEEBIQUgBCAIT0UEQANAIAUgDk9FBEAgBUECdCIJIAMgBEE0bGpqIAMgCWooAgAgBHY2AgAgBUEBaiEFDAELCyAEQQFqIQQMAQsLIBIgByAPIAogESADIAIgARBkIAZBAToABSAGIAc6AAYgACAGKAIENgIACyAQIQULIAZBEGokACAFC8ENAQt/IwBB8ABrIgUkAEFsIQkCQCADQQpJDQAgAi8AACEKIAIvAAIhDCACLwAEIQYgBUEIaiAEEA4CQCADIAYgCiAMampBBmoiDUkNACAFLQAKIQcgBUHYAGogAkEGaiICIAoQBiIJEAMNASAFQUBrIAIgCmoiAiAMEAYiCRADDQEgBUEoaiACIAxqIgIgBhAGIgkQAw0BIAVBEGogAiAGaiADIA1rEAYiCRADDQEgACABaiIOQX1qIQ8gBEEEaiEGQQEhCSAAIAFBA2pBAnYiAmoiCiACaiIMIAJqIg0hAyAMIQQgCiECA0AgCSADIA9JcQRAIAYgBUHYAGogBxACQQF0aiIILQAAIQsgBUHYAGogCC0AARABIAAgCzoAACAGIAVBQGsgBxACQQF0aiIILQAAIQsgBUFAayAILQABEAEgAiALOgAAIAYgBUEoaiAHEAJBAXRqIggtAAAhCyAFQShqIAgtAAEQASAEIAs6AAAgBiAFQRBqIAcQAkEBdGoiCC0AACELIAVBEGogCC0AARABIAMgCzoAACAGIAVB2ABqIAcQAkEBdGoiCC0AACELIAVB2ABqIAgtAAEQASAAIAs6AAEgBiAFQUBrIAcQAkEBdGoiCC0AACELIAVBQGsgCC0AARABIAIgCzoAASAGIAVBKGogBxACQQF0aiIILQAAIQsgBUEoaiAILQABEAEgBCALOgABIAYgBUEQaiAHEAJBAXRqIggtAAAhCyAFQRBqIAgtAAEQASADIAs6AAEgA0ECaiEDIARBAmohBCACQQJqIQIgAEECaiEAIAkgBUHYAGoQDUVxIAVBQGsQDUVxIAVBKGoQDUVxIAVBEGoQDUVxIQkMAQsLIAQgDUsgAiAMS3INAEFsIQkgACAKSw0BIApBfWohCQNAIAVB2ABqEAQgACAJT3JFBEAgBiAFQdgAaiAHEAJBAXRqIggtAAAhCyAFQdgAaiAILQABEAEgACALOgAAIAYgBUHYAGogBxACQQF0aiIILQAAIQsgBUHYAGogCC0AARABIAAgCzoAASAAQQJqIQAMAQsLA0AgBUHYAGoQBCAAIApPckUEQCAGIAVB2ABqIAcQAkEBdGoiCS0AACEIIAVB2ABqIAktAAEQASAAIAg6AAAgAEEBaiEADAELCwNAIAAgCkkEQCAGIAVB2ABqIAcQAkEBdGoiCS0AACEIIAVB2ABqIAktAAEQASAAIAg6AAAgAEEBaiEADAELCyAMQX1qIQADQCAFQUBrEAQgAiAAT3JFBEAgBiAFQUBrIAcQAkEBdGoiCi0AACEJIAVBQGsgCi0AARABIAIgCToAACAGIAVBQGsgBxACQQF0aiIKLQAAIQkgBUFAayAKLQABEAEgAiAJOgABIAJBAmohAgwBCwsDQCAFQUBrEAQgAiAMT3JFBEAgBiAFQUBrIAcQAkEBdGoiAC0AACEKIAVBQGsgAC0AARABIAIgCjoAACACQQFqIQIMAQsLA0AgAiAMSQRAIAYgBUFAayAHEAJBAXRqIgAtAAAhCiAFQUBrIAAtAAEQASACIAo6AAAgAkEBaiECDAELCyANQX1qIQADQCAFQShqEAQgBCAAT3JFBEAgBiAFQShqIAcQAkEBdGoiAi0AACEKIAVBKGogAi0AARABIAQgCjoAACAGIAVBKGogBxACQQF0aiICLQAAIQogBUEoaiACLQABEAEgBCAKOgABIARBAmohBAwBCwsDQCAFQShqEAQgBCANT3JFBEAgBiAFQShqIAcQAkEBdGoiAC0AACECIAVBKGogAC0AARABIAQgAjoAACAEQQFqIQQMAQsLA0AgBCANSQRAIAYgBUEoaiAHEAJBAXRqIgAtAAAhAiAFQShqIAAtAAEQASAEIAI6AAAgBEEBaiEEDAELCwNAIAVBEGoQBCADIA9PckUEQCAGIAVBEGogBxACQQF0aiIALQAAIQIgBUEQaiAALQABEAEgAyACOgAAIAYgBUEQaiAHEAJBAXRqIgAtAAAhAiAFQRBqIAAtAAEQASADIAI6AAEgA0ECaiEDDAELCwNAIAVBEGoQBCADIA5PckUEQCAGIAVBEGogBxACQQF0aiIALQAAIQIgBUEQaiAALQABEAEgAyACOgAAIANBAWohAwwBCwsDQCADIA5JBEAgBiAFQRBqIAcQAkEBdGoiAC0AACECIAVBEGogAC0AARABIAMgAjoAACADQQFqIQMMAQsLIAFBbCAFQdgAahAKIAVBQGsQCnEgBUEoahAKcSAFQRBqEApxGyEJDAELQWwhCQsgBUHwAGokACAJC8oCAQR/IwBBIGsiBSQAIAUgBBAOIAUtAAIhByAFQQhqIAIgAxAGIgIQA0UEQCAEQQRqIQIgACABaiIDQX1qIQQDQCAFQQhqEAQgACAET3JFBEAgAiAFQQhqIAcQAkEBdGoiBi0AACEIIAVBCGogBi0AARABIAAgCDoAACACIAVBCGogBxACQQF0aiIGLQAAIQggBUEIaiAGLQABEAEgACAIOgABIABBAmohAAwBCwsDQCAFQQhqEAQgACADT3JFBEAgAiAFQQhqIAcQAkEBdGoiBC0AACEGIAVBCGogBC0AARABIAAgBjoAACAAQQFqIQAMAQsLA0AgACADT0UEQCACIAVBCGogBxACQQF0aiIELQAAIQYgBUEIaiAELQABEAEgACAGOgAAIABBAWohAAwBCwsgAUFsIAVBCGoQChshAgsgBUEgaiQAIAILtgMBCX8jAEEQayIGJAAgBkEANgIMIAZBADYCCEFUIQQCQAJAIANBQGsiDCADIAZBCGogBkEMaiABIAIQMSICEAMNACAGQQRqIAAQDiAGKAIMIgcgBi0ABEEBaksNASAAQQRqIQogBkEAOgAFIAYgBzoABiAAIAYoAgQ2AgAgB0EBaiEJQQEhBANAIAQgCUkEQCADIARBAnRqIgEoAgAhACABIAU2AgAgACAEQX9qdCAFaiEFIARBAWohBAwBCwsgB0EBaiEHQQAhBSAGKAIIIQkDQCAFIAlGDQEgAyAFIAxqLQAAIgRBAnRqIgBBASAEdEEBdSILIAAoAgAiAWoiADYCACAHIARrIQhBACEEAkAgC0EDTQRAA0AgBCALRg0CIAogASAEakEBdGoiACAIOgABIAAgBToAACAEQQFqIQQMAAALAAsDQCABIABPDQEgCiABQQF0aiIEIAg6AAEgBCAFOgAAIAQgCDoAAyAEIAU6AAIgBCAIOgAFIAQgBToABCAEIAg6AAcgBCAFOgAGIAFBBGohAQwAAAsACyAFQQFqIQUMAAALAAsgAiEECyAGQRBqJAAgBAutAQECfwJAQYQgKAIAIABHIAAoAgBBAXYiAyABa0F4aiICQXhxQQhHcgR/IAIFIAMQJ0UNASACQQhqC0EQSQ0AIAAgACgCACICQQFxIAAgAWpBD2pBeHEiASAAa0EBdHI2AgAgASAANgIEIAEgASgCAEEBcSAAIAJBAXZqIAFrIgJBAXRyNgIAQYQgIAEgAkH/////B3FqQQRqQYQgKAIAIABGGyABNgIAIAEQJQsLygIBBX8CQAJAAkAgAEEIIABBCEsbZ0EfcyAAaUEBR2oiAUEESSAAIAF2cg0AIAFBAnRB/B5qKAIAIgJFDQADQCACQXhqIgMoAgBBAXZBeGoiBSAATwRAIAIgBUEIIAVBCEsbZ0Efc0ECdEGAH2oiASgCAEYEQCABIAIoAgQ2AgALDAMLIARBHksNASAEQQFqIQQgAigCBCICDQALC0EAIQMgAUEgTw0BA0AgAUECdEGAH2ooAgAiAkUEQCABQR5LIQIgAUEBaiEBIAJFDQEMAwsLIAIgAkF4aiIDKAIAQQF2QXhqIgFBCCABQQhLG2dBH3NBAnRBgB9qIgEoAgBGBEAgASACKAIENgIACwsgAigCACIBBEAgASACKAIENgIECyACKAIEIgEEQCABIAIoAgA2AgALIAMgAygCAEEBcjYCACADIAAQNwsgAwvhCwINfwV+IwBB8ABrIgckACAHIAAoAvDhASIINgJcIAEgAmohDSAIIAAoAoDiAWohDwJAAkAgBUUEQCABIQQMAQsgACgCxOABIRAgACgCwOABIREgACgCvOABIQ4gAEEBNgKM4QFBACEIA0AgCEEDRwRAIAcgCEECdCICaiAAIAJqQazQAWooAgA2AkQgCEEBaiEIDAELC0FsIQwgB0EYaiADIAQQBhADDQEgB0EsaiAHQRhqIAAoAgAQEyAHQTRqIAdBGGogACgCCBATIAdBPGogB0EYaiAAKAIEEBMgDUFgaiESIAEhBEEAIQwDQCAHKAIwIAcoAixBA3RqKQIAIhRCEIinQf8BcSEIIAcoAkAgBygCPEEDdGopAgAiFUIQiKdB/wFxIQsgBygCOCAHKAI0QQN0aikCACIWQiCIpyEJIBVCIIghFyAUQiCIpyECAkAgFkIQiKdB/wFxIgNBAk8EQAJAIAZFIANBGUlyRQRAIAkgB0EYaiADQSAgBygCHGsiCiAKIANLGyIKEAUgAyAKayIDdGohCSAHQRhqEAQaIANFDQEgB0EYaiADEAUgCWohCQwBCyAHQRhqIAMQBSAJaiEJIAdBGGoQBBoLIAcpAkQhGCAHIAk2AkQgByAYNwNIDAELAkAgA0UEQCACBEAgBygCRCEJDAMLIAcoAkghCQwBCwJAAkAgB0EYakEBEAUgCSACRWpqIgNBA0YEQCAHKAJEQX9qIgMgA0VqIQkMAQsgA0ECdCAHaigCRCIJIAlFaiEJIANBAUYNAQsgByAHKAJINgJMCwsgByAHKAJENgJIIAcgCTYCRAsgF6chAyALBEAgB0EYaiALEAUgA2ohAwsgCCALakEUTwRAIAdBGGoQBBoLIAgEQCAHQRhqIAgQBSACaiECCyAHQRhqEAQaIAcgB0EYaiAUQhiIp0H/AXEQCCAUp0H//wNxajYCLCAHIAdBGGogFUIYiKdB/wFxEAggFadB//8DcWo2AjwgB0EYahAEGiAHIAdBGGogFkIYiKdB/wFxEAggFqdB//8DcWo2AjQgByACNgJgIAcoAlwhCiAHIAk2AmggByADNgJkAkACQAJAIAQgAiADaiILaiASSw0AIAIgCmoiEyAPSw0AIA0gBGsgC0Egak8NAQsgByAHKQNoNwMQIAcgBykDYDcDCCAEIA0gB0EIaiAHQdwAaiAPIA4gESAQEB4hCwwBCyACIARqIQggBCAKEAcgAkERTwRAIARBEGohAgNAIAIgCkEQaiIKEAcgAkEQaiICIAhJDQALCyAIIAlrIQIgByATNgJcIAkgCCAOa0sEQCAJIAggEWtLBEBBbCELDAILIBAgAiAOayICaiIKIANqIBBNBEAgCCAKIAMQDxoMAgsgCCAKQQAgAmsQDyEIIAcgAiADaiIDNgJkIAggAmshCCAOIQILIAlBEE8EQCADIAhqIQMDQCAIIAIQByACQRBqIQIgCEEQaiIIIANJDQALDAELAkAgCUEHTQRAIAggAi0AADoAACAIIAItAAE6AAEgCCACLQACOgACIAggAi0AAzoAAyAIQQRqIAIgCUECdCIDQcAeaigCAGoiAhAXIAIgA0HgHmooAgBrIQIgBygCZCEDDAELIAggAhAMCyADQQlJDQAgAyAIaiEDIAhBCGoiCCACQQhqIgJrQQ9MBEADQCAIIAIQDCACQQhqIQIgCEEIaiIIIANJDQAMAgALAAsDQCAIIAIQByACQRBqIQIgCEEQaiIIIANJDQALCyAHQRhqEAQaIAsgDCALEAMiAhshDCAEIAQgC2ogAhshBCAFQX9qIgUNAAsgDBADDQFBbCEMIAdBGGoQBEECSQ0BQQAhCANAIAhBA0cEQCAAIAhBAnQiAmpBrNABaiACIAdqKAJENgIAIAhBAWohCAwBCwsgBygCXCEIC0G6fyEMIA8gCGsiACANIARrSw0AIAQEfyAEIAggABALIABqBUEACyABayEMCyAHQfAAaiQAIAwLkRcCFn8FfiMAQdABayIHJAAgByAAKALw4QEiCDYCvAEgASACaiESIAggACgCgOIBaiETAkACQCAFRQRAIAEhAwwBCyAAKALE4AEhESAAKALA4AEhFSAAKAK84AEhDyAAQQE2AozhAUEAIQgDQCAIQQNHBEAgByAIQQJ0IgJqIAAgAmpBrNABaigCADYCVCAIQQFqIQgMAQsLIAcgETYCZCAHIA82AmAgByABIA9rNgJoQWwhECAHQShqIAMgBBAGEAMNASAFQQQgBUEESBshFyAHQTxqIAdBKGogACgCABATIAdBxABqIAdBKGogACgCCBATIAdBzABqIAdBKGogACgCBBATQQAhBCAHQeAAaiEMIAdB5ABqIQoDQCAHQShqEARBAksgBCAXTnJFBEAgBygCQCAHKAI8QQN0aikCACIdQhCIp0H/AXEhCyAHKAJQIAcoAkxBA3RqKQIAIh5CEIinQf8BcSEJIAcoAkggBygCREEDdGopAgAiH0IgiKchCCAeQiCIISAgHUIgiKchAgJAIB9CEIinQf8BcSIDQQJPBEACQCAGRSADQRlJckUEQCAIIAdBKGogA0EgIAcoAixrIg0gDSADSxsiDRAFIAMgDWsiA3RqIQggB0EoahAEGiADRQ0BIAdBKGogAxAFIAhqIQgMAQsgB0EoaiADEAUgCGohCCAHQShqEAQaCyAHKQJUISEgByAINgJUIAcgITcDWAwBCwJAIANFBEAgAgRAIAcoAlQhCAwDCyAHKAJYIQgMAQsCQAJAIAdBKGpBARAFIAggAkVqaiIDQQNGBEAgBygCVEF/aiIDIANFaiEIDAELIANBAnQgB2ooAlQiCCAIRWohCCADQQFGDQELIAcgBygCWDYCXAsLIAcgBygCVDYCWCAHIAg2AlQLICCnIQMgCQRAIAdBKGogCRAFIANqIQMLIAkgC2pBFE8EQCAHQShqEAQaCyALBEAgB0EoaiALEAUgAmohAgsgB0EoahAEGiAHIAcoAmggAmoiCSADajYCaCAKIAwgCCAJSxsoAgAhDSAHIAdBKGogHUIYiKdB/wFxEAggHadB//8DcWo2AjwgByAHQShqIB5CGIinQf8BcRAIIB6nQf//A3FqNgJMIAdBKGoQBBogB0EoaiAfQhiIp0H/AXEQCCEOIAdB8ABqIARBBHRqIgsgCSANaiAIazYCDCALIAg2AgggCyADNgIEIAsgAjYCACAHIA4gH6dB//8DcWo2AkQgBEEBaiEEDAELCyAEIBdIDQEgEkFgaiEYIAdB4ABqIRogB0HkAGohGyABIQMDQCAHQShqEARBAksgBCAFTnJFBEAgBygCQCAHKAI8QQN0aikCACIdQhCIp0H/AXEhCyAHKAJQIAcoAkxBA3RqKQIAIh5CEIinQf8BcSEIIAcoAkggBygCREEDdGopAgAiH0IgiKchCSAeQiCIISAgHUIgiKchDAJAIB9CEIinQf8BcSICQQJPBEACQCAGRSACQRlJckUEQCAJIAdBKGogAkEgIAcoAixrIgogCiACSxsiChAFIAIgCmsiAnRqIQkgB0EoahAEGiACRQ0BIAdBKGogAhAFIAlqIQkMAQsgB0EoaiACEAUgCWohCSAHQShqEAQaCyAHKQJUISEgByAJNgJUIAcgITcDWAwBCwJAIAJFBEAgDARAIAcoAlQhCQwDCyAHKAJYIQkMAQsCQAJAIAdBKGpBARAFIAkgDEVqaiICQQNGBEAgBygCVEF/aiICIAJFaiEJDAELIAJBAnQgB2ooAlQiCSAJRWohCSACQQFGDQELIAcgBygCWDYCXAsLIAcgBygCVDYCWCAHIAk2AlQLICCnIRQgCARAIAdBKGogCBAFIBRqIRQLIAggC2pBFE8EQCAHQShqEAQaCyALBEAgB0EoaiALEAUgDGohDAsgB0EoahAEGiAHIAcoAmggDGoiGSAUajYCaCAbIBogCSAZSxsoAgAhHCAHIAdBKGogHUIYiKdB/wFxEAggHadB//8DcWo2AjwgByAHQShqIB5CGIinQf8BcRAIIB6nQf//A3FqNgJMIAdBKGoQBBogByAHQShqIB9CGIinQf8BcRAIIB+nQf//A3FqNgJEIAcgB0HwAGogBEEDcUEEdGoiDSkDCCIdNwPIASAHIA0pAwAiHjcDwAECQAJAAkAgBygCvAEiDiAepyICaiIWIBNLDQAgAyAHKALEASIKIAJqIgtqIBhLDQAgEiADayALQSBqTw0BCyAHIAcpA8gBNwMQIAcgBykDwAE3AwggAyASIAdBCGogB0G8AWogEyAPIBUgERAeIQsMAQsgAiADaiEIIAMgDhAHIAJBEU8EQCADQRBqIQIDQCACIA5BEGoiDhAHIAJBEGoiAiAISQ0ACwsgCCAdpyIOayECIAcgFjYCvAEgDiAIIA9rSwRAIA4gCCAVa0sEQEFsIQsMAgsgESACIA9rIgJqIhYgCmogEU0EQCAIIBYgChAPGgwCCyAIIBZBACACaxAPIQggByACIApqIgo2AsQBIAggAmshCCAPIQILIA5BEE8EQCAIIApqIQoDQCAIIAIQByACQRBqIQIgCEEQaiIIIApJDQALDAELAkAgDkEHTQRAIAggAi0AADoAACAIIAItAAE6AAEgCCACLQACOgACIAggAi0AAzoAAyAIQQRqIAIgDkECdCIKQcAeaigCAGoiAhAXIAIgCkHgHmooAgBrIQIgBygCxAEhCgwBCyAIIAIQDAsgCkEJSQ0AIAggCmohCiAIQQhqIgggAkEIaiICa0EPTARAA0AgCCACEAwgAkEIaiECIAhBCGoiCCAKSQ0ADAIACwALA0AgCCACEAcgAkEQaiECIAhBEGoiCCAKSQ0ACwsgCxADBEAgCyEQDAQFIA0gDDYCACANIBkgHGogCWs2AgwgDSAJNgIIIA0gFDYCBCAEQQFqIQQgAyALaiEDDAILAAsLIAQgBUgNASAEIBdrIQtBACEEA0AgCyAFSARAIAcgB0HwAGogC0EDcUEEdGoiAikDCCIdNwPIASAHIAIpAwAiHjcDwAECQAJAAkAgBygCvAEiDCAepyICaiIKIBNLDQAgAyAHKALEASIJIAJqIhBqIBhLDQAgEiADayAQQSBqTw0BCyAHIAcpA8gBNwMgIAcgBykDwAE3AxggAyASIAdBGGogB0G8AWogEyAPIBUgERAeIRAMAQsgAiADaiEIIAMgDBAHIAJBEU8EQCADQRBqIQIDQCACIAxBEGoiDBAHIAJBEGoiAiAISQ0ACwsgCCAdpyIGayECIAcgCjYCvAEgBiAIIA9rSwRAIAYgCCAVa0sEQEFsIRAMAgsgESACIA9rIgJqIgwgCWogEU0EQCAIIAwgCRAPGgwCCyAIIAxBACACaxAPIQggByACIAlqIgk2AsQBIAggAmshCCAPIQILIAZBEE8EQCAIIAlqIQYDQCAIIAIQByACQRBqIQIgCEEQaiIIIAZJDQALDAELAkAgBkEHTQRAIAggAi0AADoAACAIIAItAAE6AAEgCCACLQACOgACIAggAi0AAzoAAyAIQQRqIAIgBkECdCIGQcAeaigCAGoiAhAXIAIgBkHgHmooAgBrIQIgBygCxAEhCQwBCyAIIAIQDAsgCUEJSQ0AIAggCWohBiAIQQhqIgggAkEIaiICa0EPTARAA0AgCCACEAwgAkEIaiECIAhBCGoiCCAGSQ0ADAIACwALA0AgCCACEAcgAkEQaiECIAhBEGoiCCAGSQ0ACwsgEBADDQMgC0EBaiELIAMgEGohAwwBCwsDQCAEQQNHBEAgACAEQQJ0IgJqQazQAWogAiAHaigCVDYCACAEQQFqIQQMAQsLIAcoArwBIQgLQbp/IRAgEyAIayIAIBIgA2tLDQAgAwR/IAMgCCAAEAsgAGoFQQALIAFrIRALIAdB0AFqJAAgEAslACAAQgA3AgAgAEEAOwEIIABBADoACyAAIAE2AgwgACACOgAKC7QFAQN/IwBBMGsiBCQAIABB/wFqIgVBfWohBgJAIAMvAQIEQCAEQRhqIAEgAhAGIgIQAw0BIARBEGogBEEYaiADEBwgBEEIaiAEQRhqIAMQHCAAIQMDQAJAIARBGGoQBCADIAZPckUEQCADIARBEGogBEEYahASOgAAIAMgBEEIaiAEQRhqEBI6AAEgBEEYahAERQ0BIANBAmohAwsgBUF+aiEFAn8DQEG6fyECIAMiASAFSw0FIAEgBEEQaiAEQRhqEBI6AAAgAUEBaiEDIARBGGoQBEEDRgRAQQIhAiAEQQhqDAILIAMgBUsNBSABIARBCGogBEEYahASOgABIAFBAmohA0EDIQIgBEEYahAEQQNHDQALIARBEGoLIQUgAyAFIARBGGoQEjoAACABIAJqIABrIQIMAwsgAyAEQRBqIARBGGoQEjoAAiADIARBCGogBEEYahASOgADIANBBGohAwwAAAsACyAEQRhqIAEgAhAGIgIQAw0AIARBEGogBEEYaiADEBwgBEEIaiAEQRhqIAMQHCAAIQMDQAJAIARBGGoQBCADIAZPckUEQCADIARBEGogBEEYahAROgAAIAMgBEEIaiAEQRhqEBE6AAEgBEEYahAERQ0BIANBAmohAwsgBUF+aiEFAn8DQEG6fyECIAMiASAFSw0EIAEgBEEQaiAEQRhqEBE6AAAgAUEBaiEDIARBGGoQBEEDRgRAQQIhAiAEQQhqDAILIAMgBUsNBCABIARBCGogBEEYahAROgABIAFBAmohA0EDIQIgBEEYahAEQQNHDQALIARBEGoLIQUgAyAFIARBGGoQEToAACABIAJqIABrIQIMAgsgAyAEQRBqIARBGGoQEToAAiADIARBCGogBEEYahAROgADIANBBGohAwwAAAsACyAEQTBqJAAgAgtpAQF/An8CQAJAIAJBB00NACABKAAAQbfIwuF+Rw0AIAAgASgABDYCmOIBQWIgAEEQaiABIAIQPiIDEAMNAhogAEKBgICAEDcDiOEBIAAgASADaiACIANrECoMAQsgACABIAIQKgtBAAsLrQMBBn8jAEGAAWsiAyQAQWIhCAJAIAJBCUkNACAAQZjQAGogAUEIaiIEIAJBeGogAEGY0AAQMyIFEAMiBg0AIANBHzYCfCADIANB/ABqIANB+ABqIAQgBCAFaiAGGyIEIAEgAmoiAiAEaxAVIgUQAw0AIAMoAnwiBkEfSw0AIAMoAngiB0EJTw0AIABBiCBqIAMgBkGAC0GADCAHEBggA0E0NgJ8IAMgA0H8AGogA0H4AGogBCAFaiIEIAIgBGsQFSIFEAMNACADKAJ8IgZBNEsNACADKAJ4IgdBCk8NACAAQZAwaiADIAZBgA1B4A4gBxAYIANBIzYCfCADIANB/ABqIANB+ABqIAQgBWoiBCACIARrEBUiBRADDQAgAygCfCIGQSNLDQAgAygCeCIHQQpPDQAgACADIAZBwBBB0BEgBxAYIAQgBWoiBEEMaiIFIAJLDQAgAiAFayEFQQAhAgNAIAJBA0cEQCAEKAAAIgZBf2ogBU8NAiAAIAJBAnRqQZzQAWogBjYCACACQQFqIQIgBEEEaiEEDAELCyAEIAFrIQgLIANBgAFqJAAgCAtGAQN/IABBCGohAyAAKAIEIQJBACEAA0AgACACdkUEQCABIAMgAEEDdGotAAJBFktqIQEgAEEBaiEADAELCyABQQggAmt0C4YDAQV/Qbh/IQcCQCADRQ0AIAItAAAiBEUEQCABQQA2AgBBAUG4fyADQQFGGw8LAn8gAkEBaiIFIARBGHRBGHUiBkF/Sg0AGiAGQX9GBEAgA0EDSA0CIAUvAABBgP4BaiEEIAJBA2oMAQsgA0ECSA0BIAItAAEgBEEIdHJBgIB+aiEEIAJBAmoLIQUgASAENgIAIAVBAWoiASACIANqIgNLDQBBbCEHIABBEGogACAFLQAAIgVBBnZBI0EJIAEgAyABa0HAEEHQEUHwEiAAKAKM4QEgACgCnOIBIAQQHyIGEAMiCA0AIABBmCBqIABBCGogBUEEdkEDcUEfQQggASABIAZqIAgbIgEgAyABa0GAC0GADEGAFyAAKAKM4QEgACgCnOIBIAQQHyIGEAMiCA0AIABBoDBqIABBBGogBUECdkEDcUE0QQkgASABIAZqIAgbIgEgAyABa0GADUHgDkGQGSAAKAKM4QEgACgCnOIBIAQQHyIAEAMNACAAIAFqIAJrIQcLIAcLrQMBCn8jAEGABGsiCCQAAn9BUiACQf8BSw0AGkFUIANBDEsNABogAkEBaiELIABBBGohCUGAgAQgA0F/anRBEHUhCkEAIQJBASEEQQEgA3QiB0F/aiIMIQUDQCACIAtGRQRAAkAgASACQQF0Ig1qLwEAIgZB//8DRgRAIAkgBUECdGogAjoAAiAFQX9qIQVBASEGDAELIARBACAKIAZBEHRBEHVKGyEECyAIIA1qIAY7AQAgAkEBaiECDAELCyAAIAQ7AQIgACADOwEAIAdBA3YgB0EBdmpBA2ohBkEAIQRBACECA0AgBCALRkUEQCABIARBAXRqLgEAIQpBACEAA0AgACAKTkUEQCAJIAJBAnRqIAQ6AAIDQCACIAZqIAxxIgIgBUsNAAsgAEEBaiEADAELCyAEQQFqIQQMAQsLQX8gAg0AGkEAIQIDfyACIAdGBH9BAAUgCCAJIAJBAnRqIgAtAAJBAXRqIgEgAS8BACIBQQFqOwEAIAAgAyABEBRrIgU6AAMgACABIAVB/wFxdCAHazsBACACQQFqIQIMAQsLCyEFIAhBgARqJAAgBQvjBgEIf0FsIQcCQCACQQNJDQACQAJAAkACQCABLQAAIgNBA3EiCUEBaw4DAwEAAgsgACgCiOEBDQBBYg8LIAJBBUkNAkEDIQYgASgAACEFAn8CQAJAIANBAnZBA3EiCEF+aiIEQQFNBEAgBEEBaw0BDAILIAVBDnZB/wdxIQQgBUEEdkH/B3EhAyAIRQwCCyAFQRJ2IQRBBCEGIAVBBHZB//8AcSEDQQAMAQsgBUEEdkH//w9xIgNBgIAISw0DIAEtAARBCnQgBUEWdnIhBEEFIQZBAAshBSAEIAZqIgogAksNAgJAIANBgQZJDQAgACgCnOIBRQ0AQQAhAgNAIAJBg4ABSw0BIAJBQGshAgwAAAsACwJ/IAlBA0YEQCABIAZqIQEgAEHw4gFqIQIgACgCDCEGIAUEQCACIAMgASAEIAYQXwwCCyACIAMgASAEIAYQXQwBCyAAQbjQAWohAiABIAZqIQEgAEHw4gFqIQYgAEGo0ABqIQggBQRAIAggBiADIAEgBCACEF4MAQsgCCAGIAMgASAEIAIQXAsQAw0CIAAgAzYCgOIBIABBATYCiOEBIAAgAEHw4gFqNgLw4QEgCUECRgRAIAAgAEGo0ABqNgIMCyAAIANqIgBBiOMBakIANwAAIABBgOMBakIANwAAIABB+OIBakIANwAAIABB8OIBakIANwAAIAoPCwJ/AkACQAJAIANBAnZBA3FBf2oiBEECSw0AIARBAWsOAgACAQtBASEEIANBA3YMAgtBAiEEIAEvAABBBHYMAQtBAyEEIAEQIUEEdgsiAyAEaiIFQSBqIAJLBEAgBSACSw0CIABB8OIBaiABIARqIAMQCyEBIAAgAzYCgOIBIAAgATYC8OEBIAEgA2oiAEIANwAYIABCADcAECAAQgA3AAggAEIANwAAIAUPCyAAIAM2AoDiASAAIAEgBGo2AvDhASAFDwsCfwJAAkACQCADQQJ2QQNxQX9qIgRBAksNACAEQQFrDgIAAgELQQEhByADQQN2DAILQQIhByABLwAAQQR2DAELIAJBBEkgARAhIgJBj4CAAUtyDQFBAyEHIAJBBHYLIQIgAEHw4gFqIAEgB2otAAAgAkEgahAQIQEgACACNgKA4gEgACABNgLw4QEgB0EBaiEHCyAHC0sAIABC+erQ0OfJoeThADcDICAAQgA3AxggAELP1tO+0ser2UI3AxAgAELW64Lu6v2J9eAANwMIIABCADcDACAAQShqQQBBKBAQGgviAgICfwV+IABBKGoiASAAKAJIaiECAn4gACkDACIDQiBaBEAgACkDECIEQgeJIAApAwgiBUIBiXwgACkDGCIGQgyJfCAAKQMgIgdCEol8IAUQGSAEEBkgBhAZIAcQGQwBCyAAKQMYQsXP2bLx5brqJ3wLIAN8IQMDQCABQQhqIgAgAk0EQEIAIAEpAAAQCSADhUIbiUKHla+vmLbem55/fkLj3MqV/M7y9YV/fCEDIAAhAQwBCwsCQCABQQRqIgAgAksEQCABIQAMAQsgASgAAK1Ch5Wvr5i23puef34gA4VCF4lCz9bTvtLHq9lCfkL5893xmfaZqxZ8IQMLA0AgACACSQRAIAAxAABCxc/ZsvHluuonfiADhUILiUKHla+vmLbem55/fiEDIABBAWohAAwBCwsgA0IhiCADhULP1tO+0ser2UJ+IgNCHYggA4VC+fPd8Zn2masWfiIDQiCIIAOFC+8CAgJ/BH4gACAAKQMAIAKtfDcDAAJAAkAgACgCSCIDIAJqIgRBH00EQCABRQ0BIAAgA2pBKGogASACECAgACgCSCACaiEEDAELIAEgAmohAgJ/IAMEQCAAQShqIgQgA2ogAUEgIANrECAgACAAKQMIIAQpAAAQCTcDCCAAIAApAxAgACkAMBAJNwMQIAAgACkDGCAAKQA4EAk3AxggACAAKQMgIABBQGspAAAQCTcDICAAKAJIIQMgAEEANgJIIAEgA2tBIGohAQsgAUEgaiACTQsEQCACQWBqIQMgACkDICEFIAApAxghBiAAKQMQIQcgACkDCCEIA0AgCCABKQAAEAkhCCAHIAEpAAgQCSEHIAYgASkAEBAJIQYgBSABKQAYEAkhBSABQSBqIgEgA00NAAsgACAFNwMgIAAgBjcDGCAAIAc3AxAgACAINwMICyABIAJPDQEgAEEoaiABIAIgAWsiBBAgCyAAIAQ2AkgLCy8BAX8gAEUEQEG2f0EAIAMbDwtBun8hBCADIAFNBH8gACACIAMQEBogAwVBun8LCy8BAX8gAEUEQEG2f0EAIAMbDwtBun8hBCADIAFNBH8gACACIAMQCxogAwVBun8LC6gCAQZ/IwBBEGsiByQAIABB2OABaikDAEKAgIAQViEIQbh/IQUCQCAEQf//B0sNACAAIAMgBBBCIgUQAyIGDQAgACgCnOIBIQkgACAHQQxqIAMgAyAFaiAGGyIKIARBACAFIAYbayIGEEAiAxADBEAgAyEFDAELIAcoAgwhBCABRQRAQbp/IQUgBEEASg0BCyAGIANrIQUgAyAKaiEDAkAgCQRAIABBADYCnOIBDAELAkACQAJAIARBBUgNACAAQdjgAWopAwBCgICACFgNAAwBCyAAQQA2ApziAQwBCyAAKAIIED8hBiAAQQA2ApziASAGQRRPDQELIAAgASACIAMgBSAEIAgQOSEFDAELIAAgASACIAMgBSAEIAgQOiEFCyAHQRBqJAAgBQtnACAAQdDgAWogASACIAAoAuzhARAuIgEQAwRAIAEPC0G4fyECAkAgAQ0AIABB7OABaigCACIBBEBBYCECIAAoApjiASABRw0BC0EAIQIgAEHw4AFqKAIARQ0AIABBkOEBahBDCyACCycBAX8QVyIERQRAQUAPCyAEIAAgASACIAMgBBBLEE8hACAEEFYgAAs/AQF/AkACQAJAIAAoAqDiAUEBaiIBQQJLDQAgAUEBaw4CAAECCyAAEDBBAA8LIABBADYCoOIBCyAAKAKU4gELvAMCB38BfiMAQRBrIgkkAEG4fyEGAkAgBCgCACIIQQVBCSAAKALs4QEiBRtJDQAgAygCACIHQQFBBSAFGyAFEC8iBRADBEAgBSEGDAELIAggBUEDakkNACAAIAcgBRBJIgYQAw0AIAEgAmohCiAAQZDhAWohCyAIIAVrIQIgBSAHaiEHIAEhBQNAIAcgAiAJECwiBhADDQEgAkF9aiICIAZJBEBBuH8hBgwCCyAJKAIAIghBAksEQEFsIQYMAgsgB0EDaiEHAn8CQAJAAkAgCEEBaw4CAgABCyAAIAUgCiAFayAHIAYQSAwCCyAFIAogBWsgByAGEEcMAQsgBSAKIAVrIActAAAgCSgCCBBGCyIIEAMEQCAIIQYMAgsgACgC8OABBEAgCyAFIAgQRQsgAiAGayECIAYgB2ohByAFIAhqIQUgCSgCBEUNAAsgACkD0OABIgxCf1IEQEFsIQYgDCAFIAFrrFINAQsgACgC8OABBEBBaiEGIAJBBEkNASALEEQhDCAHKAAAIAynRw0BIAdBBGohByACQXxqIQILIAMgBzYCACAEIAI2AgAgBSABayEGCyAJQRBqJAAgBgsuACAAECsCf0EAQQAQAw0AGiABRSACRXJFBEBBYiAAIAEgAhA9EAMNARoLQQALCzcAIAEEQCAAIAAoAsTgASABKAIEIAEoAghqRzYCnOIBCyAAECtBABADIAFFckUEQCAAIAEQWwsL0QIBB38jAEEQayIGJAAgBiAENgIIIAYgAzYCDCAFBEAgBSgCBCEKIAUoAgghCQsgASEIAkACQANAIAAoAuzhARAWIQsCQANAIAQgC0kNASADKAAAQXBxQdDUtMIBRgRAIAMgBBAiIgcQAw0EIAQgB2shBCADIAdqIQMMAQsLIAYgAzYCDCAGIAQ2AggCQCAFBEAgACAFEE5BACEHQQAQA0UNAQwFCyAAIAogCRBNIgcQAw0ECyAAIAgQUCAMQQFHQQAgACAIIAIgBkEMaiAGQQhqEEwiByIDa0EAIAMQAxtBCkdyRQRAQbh/IQcMBAsgBxADDQMgAiAHayECIAcgCGohCEEBIQwgBigCDCEDIAYoAgghBAwBCwsgBiADNgIMIAYgBDYCCEG4fyEHIAQNASAIIAFrIQcMAQsgBiADNgIMIAYgBDYCCAsgBkEQaiQAIAcLRgECfyABIAAoArjgASICRwRAIAAgAjYCxOABIAAgATYCuOABIAAoArzgASEDIAAgATYCvOABIAAgASADIAJrajYCwOABCwutAgIEfwF+IwBBQGoiBCQAAkACQCACQQhJDQAgASgAAEFwcUHQ1LTCAUcNACABIAIQIiEBIABCADcDCCAAQQA2AgQgACABNgIADAELIARBGGogASACEC0iAxADBEAgACADEBoMAQsgAwRAIABBuH8QGgwBCyACIAQoAjAiA2shAiABIANqIQMDQAJAIAAgAyACIARBCGoQLCIFEAMEfyAFBSACIAVBA2oiBU8NAUG4fwsQGgwCCyAGQQFqIQYgAiAFayECIAMgBWohAyAEKAIMRQ0ACyAEKAI4BEAgAkEDTQRAIABBuH8QGgwCCyADQQRqIQMLIAQoAighAiAEKQMYIQcgAEEANgIEIAAgAyABazYCACAAIAIgBmytIAcgB0J/URs3AwgLIARBQGskAAslAQF/IwBBEGsiAiQAIAIgACABEFEgAigCACEAIAJBEGokACAAC30BBH8jAEGQBGsiBCQAIARB/wE2AggCQCAEQRBqIARBCGogBEEMaiABIAIQFSIGEAMEQCAGIQUMAQtBVCEFIAQoAgwiB0EGSw0AIAMgBEEQaiAEKAIIIAcQQSIFEAMNACAAIAEgBmogAiAGayADEDwhBQsgBEGQBGokACAFC4cBAgJ/An5BABAWIQMCQANAIAEgA08EQAJAIAAoAABBcHFB0NS0wgFGBEAgACABECIiAhADRQ0BQn4PCyAAIAEQVSIEQn1WDQMgBCAFfCIFIARUIQJCfiEEIAINAyAAIAEQUiICEAMNAwsgASACayEBIAAgAmohAAwBCwtCfiAFIAEbIQQLIAQLPwIBfwF+IwBBMGsiAiQAAn5CfiACQQhqIAAgARAtDQAaQgAgAigCHEEBRg0AGiACKQMICyEDIAJBMGokACADC40BAQJ/IwBBMGsiASQAAkAgAEUNACAAKAKI4gENACABIABB/OEBaigCADYCKCABIAApAvThATcDICAAEDAgACgCqOIBIQIgASABKAIoNgIYIAEgASkDIDcDECACIAFBEGoQGyAAQQA2AqjiASABIAEoAig2AgggASABKQMgNwMAIAAgARAbCyABQTBqJAALKgECfyMAQRBrIgAkACAAQQA2AgggAEIANwMAIAAQWCEBIABBEGokACABC4cBAQN/IwBBEGsiAiQAAkAgACgCAEUgACgCBEVzDQAgAiAAKAIINgIIIAIgACkCADcDAAJ/IAIoAgAiAQRAIAIoAghBqOMJIAERBQAMAQtBqOMJECgLIgFFDQAgASAAKQIANwL04QEgAUH84QFqIAAoAgg2AgAgARBZIAEhAwsgAkEQaiQAIAMLywEBAn8jAEEgayIBJAAgAEGBgIDAADYCtOIBIABBADYCiOIBIABBADYC7OEBIABCADcDkOIBIABBADYCpOMJIABBADYC3OIBIABCADcCzOIBIABBADYCvOIBIABBADYCxOABIABCADcCnOIBIABBpOIBakIANwIAIABBrOIBakEANgIAIAFCADcCECABQgA3AhggASABKQMYNwMIIAEgASkDEDcDACABKAIIQQh2QQFxIQIgAEEANgLg4gEgACACNgKM4gEgAUEgaiQAC3YBA38jAEEwayIBJAAgAARAIAEgAEHE0AFqIgIoAgA2AiggASAAKQK80AE3AyAgACgCACEDIAEgAigCADYCGCABIAApArzQATcDECADIAFBEGoQGyABIAEoAig2AgggASABKQMgNwMAIAAgARAbCyABQTBqJAALzAEBAX8gACABKAK00AE2ApjiASAAIAEoAgQiAjYCwOABIAAgAjYCvOABIAAgAiABKAIIaiICNgK44AEgACACNgLE4AEgASgCuNABBEAgAEKBgICAEDcDiOEBIAAgAUGk0ABqNgIMIAAgAUGUIGo2AgggACABQZwwajYCBCAAIAFBDGo2AgAgAEGs0AFqIAFBqNABaigCADYCACAAQbDQAWogAUGs0AFqKAIANgIAIABBtNABaiABQbDQAWooAgA2AgAPCyAAQgA3A4jhAQs7ACACRQRAQbp/DwsgBEUEQEFsDwsgAiAEEGAEQCAAIAEgAiADIAQgBRBhDwsgACABIAIgAyAEIAUQZQtGAQF/IwBBEGsiBSQAIAVBCGogBBAOAn8gBS0ACQRAIAAgASACIAMgBBAyDAELIAAgASACIAMgBBA0CyEAIAVBEGokACAACzQAIAAgAyAEIAUQNiIFEAMEQCAFDwsgBSAESQR/IAEgAiADIAVqIAQgBWsgABA1BUG4fwsLRgEBfyMAQRBrIgUkACAFQQhqIAQQDgJ/IAUtAAkEQCAAIAEgAiADIAQQYgwBCyAAIAEgAiADIAQQNQshACAFQRBqJAAgAAtZAQF/QQ8hAiABIABJBEAgAUEEdCAAbiECCyAAQQh2IgEgAkEYbCIAQYwIaigCAGwgAEGICGooAgBqIgJBA3YgAmogAEGACGooAgAgAEGECGooAgAgAWxqSQs3ACAAIAMgBCAFQYAQEDMiBRADBEAgBQ8LIAUgBEkEfyABIAIgAyAFaiAEIAVrIAAQMgVBuH8LC78DAQN/IwBBIGsiBSQAIAVBCGogAiADEAYiAhADRQRAIAAgAWoiB0F9aiEGIAUgBBAOIARBBGohAiAFLQACIQMDQEEAIAAgBkkgBUEIahAEGwRAIAAgAiAFQQhqIAMQAkECdGoiBC8BADsAACAFQQhqIAQtAAIQASAAIAQtAANqIgQgAiAFQQhqIAMQAkECdGoiAC8BADsAACAFQQhqIAAtAAIQASAEIAAtAANqIQAMAQUgB0F+aiEEA0AgBUEIahAEIAAgBEtyRQRAIAAgAiAFQQhqIAMQAkECdGoiBi8BADsAACAFQQhqIAYtAAIQASAAIAYtAANqIQAMAQsLA0AgACAES0UEQCAAIAIgBUEIaiADEAJBAnRqIgYvAQA7AAAgBUEIaiAGLQACEAEgACAGLQADaiEADAELCwJAIAAgB08NACAAIAIgBUEIaiADEAIiA0ECdGoiAC0AADoAACAALQADQQFGBEAgBUEIaiAALQACEAEMAQsgBSgCDEEfSw0AIAVBCGogAiADQQJ0ai0AAhABIAUoAgxBIUkNACAFQSA2AgwLIAFBbCAFQQhqEAobIQILCwsgBUEgaiQAIAILkgIBBH8jAEFAaiIJJAAgCSADQTQQCyEDAkAgBEECSA0AIAMgBEECdGooAgAhCSADQTxqIAgQIyADQQE6AD8gAyACOgA+QQAhBCADKAI8IQoDQCAEIAlGDQEgACAEQQJ0aiAKNgEAIARBAWohBAwAAAsAC0EAIQkDQCAGIAlGRQRAIAMgBSAJQQF0aiIKLQABIgtBAnRqIgwoAgAhBCADQTxqIAotAABBCHQgCGpB//8DcRAjIANBAjoAPyADIAcgC2siCiACajoAPiAEQQEgASAKa3RqIQogAygCPCELA0AgACAEQQJ0aiALNgEAIARBAWoiBCAKSQ0ACyAMIAo2AgAgCUEBaiEJDAELCyADQUBrJAALowIBCX8jAEHQAGsiCSQAIAlBEGogBUE0EAsaIAcgBmshDyAHIAFrIRADQAJAIAMgCkcEQEEBIAEgByACIApBAXRqIgYtAAEiDGsiCGsiC3QhDSAGLQAAIQ4gCUEQaiAMQQJ0aiIMKAIAIQYgCyAPTwRAIAAgBkECdGogCyAIIAUgCEE0bGogCCAQaiIIQQEgCEEBShsiCCACIAQgCEECdGooAgAiCEEBdGogAyAIayAHIA4QYyAGIA1qIQgMAgsgCUEMaiAOECMgCUEBOgAPIAkgCDoADiAGIA1qIQggCSgCDCELA0AgBiAITw0CIAAgBkECdGogCzYBACAGQQFqIQYMAAALAAsgCUHQAGokAA8LIAwgCDYCACAKQQFqIQoMAAALAAs0ACAAIAMgBCAFEDYiBRADBEAgBQ8LIAUgBEkEfyABIAIgAyAFaiAEIAVrIAAQNAVBuH8LCyMAIAA/AEEQdGtB//8DakEQdkAAQX9GBEBBAA8LQQAQAEEBCzsBAX8gAgRAA0AgACABIAJBgCAgAkGAIEkbIgMQCyEAIAFBgCBqIQEgAEGAIGohACACIANrIgINAAsLCwYAIAAQAwsLqBUJAEGICAsNAQAAAAEAAAACAAAAAgBBoAgLswYBAAAAAQAAAAIAAAACAAAAJgAAAIIAAAAhBQAASgAAAGcIAAAmAAAAwAEAAIAAAABJBQAASgAAAL4IAAApAAAALAIAAIAAAABJBQAASgAAAL4IAAAvAAAAygIAAIAAAACKBQAASgAAAIQJAAA1AAAAcwMAAIAAAACdBQAASgAAAKAJAAA9AAAAgQMAAIAAAADrBQAASwAAAD4KAABEAAAAngMAAIAAAABNBgAASwAAAKoKAABLAAAAswMAAIAAAADBBgAATQAAAB8NAABNAAAAUwQAAIAAAAAjCAAAUQAAAKYPAABUAAAAmQQAAIAAAABLCQAAVwAAALESAABYAAAA2gQAAIAAAABvCQAAXQAAACMUAABUAAAARQUAAIAAAABUCgAAagAAAIwUAABqAAAArwUAAIAAAAB2CQAAfAAAAE4QAAB8AAAA0gIAAIAAAABjBwAAkQAAAJAHAACSAAAAAAAAAAEAAAABAAAABQAAAA0AAAAdAAAAPQAAAH0AAAD9AAAA/QEAAP0DAAD9BwAA/Q8AAP0fAAD9PwAA/X8AAP3/AAD9/wEA/f8DAP3/BwD9/w8A/f8fAP3/PwD9/38A/f//AP3//wH9//8D/f//B/3//w/9//8f/f//P/3//38AAAAAAQAAAAIAAAADAAAABAAAAAUAAAAGAAAABwAAAAgAAAAJAAAACgAAAAsAAAAMAAAADQAAAA4AAAAPAAAAEAAAABEAAAASAAAAEwAAABQAAAAVAAAAFgAAABcAAAAYAAAAGQAAABoAAAAbAAAAHAAAAB0AAAAeAAAAHwAAAAMAAAAEAAAABQAAAAYAAAAHAAAACAAAAAkAAAAKAAAACwAAAAwAAAANAAAADgAAAA8AAAAQAAAAEQAAABIAAAATAAAAFAAAABUAAAAWAAAAFwAAABgAAAAZAAAAGgAAABsAAAAcAAAAHQAAAB4AAAAfAAAAIAAAACEAAAAiAAAAIwAAACUAAAAnAAAAKQAAACsAAAAvAAAAMwAAADsAAABDAAAAUwAAAGMAAACDAAAAAwEAAAMCAAADBAAAAwgAAAMQAAADIAAAA0AAAAOAAAADAAEAQeAPC1EBAAAAAQAAAAEAAAABAAAAAgAAAAIAAAADAAAAAwAAAAQAAAAEAAAABQAAAAcAAAAIAAAACQAAAAoAAAALAAAADAAAAA0AAAAOAAAADwAAABAAQcQQC4sBAQAAAAIAAAADAAAABAAAAAUAAAAGAAAABwAAAAgAAAAJAAAACgAAAAsAAAAMAAAADQAAAA4AAAAPAAAAEAAAABIAAAAUAAAAFgAAABgAAAAcAAAAIAAAACgAAAAwAAAAQAAAAIAAAAAAAQAAAAIAAAAEAAAACAAAABAAAAAgAAAAQAAAAIAAAAAAAQBBkBIL5gQBAAAAAQAAAAEAAAABAAAAAgAAAAIAAAADAAAAAwAAAAQAAAAGAAAABwAAAAgAAAAJAAAACgAAAAsAAAAMAAAADQAAAA4AAAAPAAAAEAAAAAEAAAAEAAAACAAAAAAAAAABAAEBBgAAAAAAAAQAAAAAEAAABAAAAAAgAAAFAQAAAAAAAAUDAAAAAAAABQQAAAAAAAAFBgAAAAAAAAUHAAAAAAAABQkAAAAAAAAFCgAAAAAAAAUMAAAAAAAABg4AAAAAAAEFEAAAAAAAAQUUAAAAAAABBRYAAAAAAAIFHAAAAAAAAwUgAAAAAAAEBTAAAAAgAAYFQAAAAAAABwWAAAAAAAAIBgABAAAAAAoGAAQAAAAADAYAEAAAIAAABAAAAAAAAAAEAQAAAAAAAAUCAAAAIAAABQQAAAAAAAAFBQAAACAAAAUHAAAAAAAABQgAAAAgAAAFCgAAAAAAAAULAAAAAAAABg0AAAAgAAEFEAAAAAAAAQUSAAAAIAABBRYAAAAAAAIFGAAAACAAAwUgAAAAAAADBSgAAAAAAAYEQAAAABAABgRAAAAAIAAHBYAAAAAAAAkGAAIAAAAACwYACAAAMAAABAAAAAAQAAAEAQAAACAAAAUCAAAAIAAABQMAAAAgAAAFBQAAACAAAAUGAAAAIAAABQgAAAAgAAAFCQAAACAAAAULAAAAIAAABQwAAAAAAAAGDwAAACAAAQUSAAAAIAABBRQAAAAgAAIFGAAAACAAAgUcAAAAIAADBSgAAAAgAAQFMAAAAAAAEAYAAAEAAAAPBgCAAAAAAA4GAEAAAAAADQYAIABBgBcLhwIBAAEBBQAAAAAAAAUAAAAAAAAGBD0AAAAAAAkF/QEAAAAADwX9fwAAAAAVBf3/HwAAAAMFBQAAAAAABwR9AAAAAAAMBf0PAAAAABIF/f8DAAAAFwX9/38AAAAFBR0AAAAAAAgE/QAAAAAADgX9PwAAAAAUBf3/DwAAAAIFAQAAABAABwR9AAAAAAALBf0HAAAAABEF/f8BAAAAFgX9/z8AAAAEBQ0AAAAQAAgE/QAAAAAADQX9HwAAAAATBf3/BwAAAAEFAQAAABAABgQ9AAAAAAAKBf0DAAAAABAF/f8AAAAAHAX9//8PAAAbBf3//wcAABoF/f//AwAAGQX9//8BAAAYBf3//wBBkBkLhgQBAAEBBgAAAAAAAAYDAAAAAAAABAQAAAAgAAAFBQAAAAAAAAUGAAAAAAAABQgAAAAAAAAFCQAAAAAAAAULAAAAAAAABg0AAAAAAAAGEAAAAAAAAAYTAAAAAAAABhYAAAAAAAAGGQAAAAAAAAYcAAAAAAAABh8AAAAAAAAGIgAAAAAAAQYlAAAAAAABBikAAAAAAAIGLwAAAAAAAwY7AAAAAAAEBlMAAAAAAAcGgwAAAAAACQYDAgAAEAAABAQAAAAAAAAEBQAAACAAAAUGAAAAAAAABQcAAAAgAAAFCQAAAAAAAAUKAAAAAAAABgwAAAAAAAAGDwAAAAAAAAYSAAAAAAAABhUAAAAAAAAGGAAAAAAAAAYbAAAAAAAABh4AAAAAAAAGIQAAAAAAAQYjAAAAAAABBicAAAAAAAIGKwAAAAAAAwYzAAAAAAAEBkMAAAAAAAUGYwAAAAAACAYDAQAAIAAABAQAAAAwAAAEBAAAABAAAAQFAAAAIAAABQcAAAAgAAAFCAAAACAAAAUKAAAAIAAABQsAAAAAAAAGDgAAAAAAAAYRAAAAAAAABhQAAAAAAAAGFwAAAAAAAAYaAAAAAAAABh0AAAAAAAAGIAAAAAAAEAYDAAEAAAAPBgOAAAAAAA4GA0AAAAAADQYDIAAAAAAMBgMQAAAAAAsGAwgAAAAACgYDBABBpB0L2QEBAAAAAwAAAAcAAAAPAAAAHwAAAD8AAAB/AAAA/wAAAP8BAAD/AwAA/wcAAP8PAAD/HwAA/z8AAP9/AAD//wAA//8BAP//AwD//wcA//8PAP//HwD//z8A//9/AP///wD///8B////A////wf///8P////H////z////9/AAAAAAEAAAACAAAABAAAAAAAAAACAAAABAAAAAgAAAAAAAAAAQAAAAIAAAABAAAABAAAAAQAAAAEAAAABAAAAAgAAAAIAAAACAAAAAcAAAAIAAAACQAAAAoAAAALAEGgIAsDwBBQ';
  55231. /**
  55232. * Loader for KTX 2.0 GPU Texture containers.
  55233. *
  55234. * KTX 2.0 is a container format for various GPU texture formats. The loader
  55235. * supports Basis Universal GPU textures, which can be quickly transcoded to
  55236. * a wide variety of GPU texture compression formats, as well as some
  55237. * uncompressed DataTexture and Data3DTexture formats.
  55238. *
  55239. * References:
  55240. * - KTX: http://github.khronos.org/KTX-Specification/
  55241. * - DFD: https://www.khronos.org/registry/DataFormat/specs/1.3/dataformat.1.3.html#basicdescriptor
  55242. */
  55243. var _taskCache$1 = new WeakMap();
  55244. var _activeLoaders = 0;
  55245. var _zstd;
  55246. class KTX2Loader extends Loader {
  55247. constructor(manager) {
  55248. super(manager);
  55249. this.transcoderPath = '';
  55250. this.transcoderBinary = null;
  55251. this.transcoderPending = null;
  55252. this.workerPool = new WorkerPool$1();
  55253. this.workerSourceURL = '';
  55254. this.workerConfig = null;
  55255. if (typeof MSC_TRANSCODER !== 'undefined') {
  55256. console.warn('THREE.KTX2Loader: Please update to latest "basis_transcoder".' + ' "msc_basis_transcoder" is no longer supported in three.js r125+.');
  55257. }
  55258. }
  55259. setTranscoderPath(path) {
  55260. this.transcoderPath = path;
  55261. return this;
  55262. }
  55263. setWorkerLimit(num) {
  55264. this.workerPool.setWorkerLimit(num);
  55265. return this;
  55266. }
  55267. detectSupport(renderer) {
  55268. this.workerConfig = {
  55269. astcSupported: renderer.extensions.has('WEBGL_compressed_texture_astc'),
  55270. etc1Supported: renderer.extensions.has('WEBGL_compressed_texture_etc1'),
  55271. etc2Supported: renderer.extensions.has('WEBGL_compressed_texture_etc'),
  55272. dxtSupported: renderer.extensions.has('WEBGL_compressed_texture_s3tc'),
  55273. bptcSupported: renderer.extensions.has('EXT_texture_compression_bptc'),
  55274. pvrtcSupported: renderer.extensions.has('WEBGL_compressed_texture_pvrtc') || renderer.extensions.has('WEBKIT_WEBGL_compressed_texture_pvrtc')
  55275. };
  55276. if (renderer.capabilities.isWebGL2) {
  55277. // https://github.com/mrdoob/three.js/pull/22928
  55278. this.workerConfig.etc1Supported = false;
  55279. }
  55280. return this;
  55281. }
  55282. init() {
  55283. if (!this.transcoderPending) {
  55284. // Load transcoder wrapper.
  55285. var jsLoader = new FileLoader(this.manager);
  55286. jsLoader.setPath(this.transcoderPath);
  55287. jsLoader.setWithCredentials(this.withCredentials);
  55288. var jsContent = jsLoader.loadAsync('basis_transcoder.js');
  55289. // Load transcoder WASM binary.
  55290. var binaryLoader = new FileLoader(this.manager);
  55291. binaryLoader.setPath(this.transcoderPath);
  55292. binaryLoader.setResponseType('arraybuffer');
  55293. binaryLoader.setWithCredentials(this.withCredentials);
  55294. var binaryContent = binaryLoader.loadAsync('basis_transcoder.wasm');
  55295. this.transcoderPending = Promise.all([jsContent, binaryContent]).then(_ref => {
  55296. var [jsContent, binaryContent] = _ref;
  55297. var fn = KTX2Loader.BasisWorker.toString();
  55298. var body = ['/* constants */', 'let _EngineFormat = ' + JSON.stringify(KTX2Loader.EngineFormat), 'let _TranscoderFormat = ' + JSON.stringify(KTX2Loader.TranscoderFormat), 'let _BasisFormat = ' + JSON.stringify(KTX2Loader.BasisFormat), '/* basis_transcoder.js */', jsContent, '/* worker */', fn.substring(fn.indexOf('{') + 1, fn.lastIndexOf('}'))].join('\n');
  55299. this.workerSourceURL = URL.createObjectURL(new Blob([body]));
  55300. this.transcoderBinary = binaryContent;
  55301. this.workerPool.setWorkerCreator(() => {
  55302. var worker = new Worker(this.workerSourceURL);
  55303. var transcoderBinary = this.transcoderBinary.slice(0);
  55304. worker.postMessage({
  55305. type: 'init',
  55306. config: this.workerConfig,
  55307. transcoderBinary
  55308. }, [transcoderBinary]);
  55309. return worker;
  55310. });
  55311. });
  55312. if (_activeLoaders > 0) {
  55313. // Each instance loads a transcoder and allocates workers, increasing network and memory cost.
  55314. console.warn('THREE.KTX2Loader: Multiple active KTX2 loaders may cause performance issues.' + ' Use a single KTX2Loader instance, or call .dispose() on old instances.');
  55315. }
  55316. _activeLoaders++;
  55317. }
  55318. return this.transcoderPending;
  55319. }
  55320. load(url, onLoad, onProgress, onError) {
  55321. if (this.workerConfig === null) {
  55322. throw new Error('THREE.KTX2Loader: Missing initialization with `.detectSupport( renderer )`.');
  55323. }
  55324. var loader = new FileLoader(this.manager);
  55325. loader.setResponseType('arraybuffer');
  55326. loader.setWithCredentials(this.withCredentials);
  55327. loader.load(url, buffer => {
  55328. // Check for an existing task using this buffer. A transferred buffer cannot be transferred
  55329. // again from this thread.
  55330. if (_taskCache$1.has(buffer)) {
  55331. var cachedTask = _taskCache$1.get(buffer);
  55332. return cachedTask.promise.then(onLoad).catch(onError);
  55333. }
  55334. this._createTexture(buffer).then(texture => onLoad ? onLoad(texture) : null).catch(onError);
  55335. }, onProgress, onError);
  55336. }
  55337. _createTextureFrom(transcodeResult, container) {
  55338. var {
  55339. mipmaps,
  55340. width,
  55341. height,
  55342. format,
  55343. type,
  55344. error,
  55345. dfdTransferFn,
  55346. dfdFlags
  55347. } = transcodeResult;
  55348. if (type === 'error') return Promise.reject(error);
  55349. var texture = container.layerCount > 1 ? new CompressedArrayTexture(mipmaps, width, height, container.layerCount, format, UnsignedByteType) : new CompressedTexture(mipmaps, width, height, format, UnsignedByteType);
  55350. texture.minFilter = mipmaps.length === 1 ? LinearFilter : LinearMipmapLinearFilter;
  55351. texture.magFilter = LinearFilter;
  55352. texture.generateMipmaps = false;
  55353. texture.needsUpdate = true;
  55354. texture.encoding = dfdTransferFn === x$2 ? sRGBEncoding : LinearEncoding;
  55355. texture.premultiplyAlpha = !!(dfdFlags & p);
  55356. return texture;
  55357. }
  55358. /**
  55359. * @param {ArrayBuffer} buffer
  55360. * @param {object?} config
  55361. * @return {Promise<CompressedTexture|CompressedArrayTexture|DataTexture|Data3DTexture>}
  55362. */
  55363. async _createTexture(buffer) {
  55364. var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  55365. var container = Pi(new Uint8Array(buffer));
  55366. if (container.vkFormat !== nt) {
  55367. return createDataTexture(container);
  55368. }
  55369. //
  55370. var taskConfig = config;
  55371. var texturePending = this.init().then(() => {
  55372. return this.workerPool.postMessage({
  55373. type: 'transcode',
  55374. buffer,
  55375. taskConfig: taskConfig
  55376. }, [buffer]);
  55377. }).then(e => this._createTextureFrom(e.data, container));
  55378. // Cache the task result.
  55379. _taskCache$1.set(buffer, {
  55380. promise: texturePending
  55381. });
  55382. return texturePending;
  55383. }
  55384. dispose() {
  55385. this.workerPool.dispose();
  55386. if (this.workerSourceURL) URL.revokeObjectURL(this.workerSourceURL);
  55387. _activeLoaders--;
  55388. return this;
  55389. }
  55390. }
  55391. /* CONSTANTS */
  55392. KTX2Loader.BasisFormat = {
  55393. ETC1S: 0,
  55394. UASTC_4x4: 1
  55395. };
  55396. KTX2Loader.TranscoderFormat = {
  55397. ETC1: 0,
  55398. ETC2: 1,
  55399. BC1: 2,
  55400. BC3: 3,
  55401. BC4: 4,
  55402. BC5: 5,
  55403. BC7_M6_OPAQUE_ONLY: 6,
  55404. BC7_M5: 7,
  55405. PVRTC1_4_RGB: 8,
  55406. PVRTC1_4_RGBA: 9,
  55407. ASTC_4x4: 10,
  55408. ATC_RGB: 11,
  55409. ATC_RGBA_INTERPOLATED_ALPHA: 12,
  55410. RGBA32: 13,
  55411. RGB565: 14,
  55412. BGR565: 15,
  55413. RGBA4444: 16
  55414. };
  55415. KTX2Loader.EngineFormat = {
  55416. RGBAFormat: RGBAFormat,
  55417. RGBA_ASTC_4x4_Format: RGBA_ASTC_4x4_Format,
  55418. RGBA_BPTC_Format: RGBA_BPTC_Format,
  55419. RGBA_ETC2_EAC_Format: RGBA_ETC2_EAC_Format,
  55420. RGBA_PVRTC_4BPPV1_Format: RGBA_PVRTC_4BPPV1_Format,
  55421. RGBA_S3TC_DXT5_Format: RGBA_S3TC_DXT5_Format$1,
  55422. RGB_ETC1_Format: RGB_ETC1_Format,
  55423. RGB_ETC2_Format: RGB_ETC2_Format,
  55424. RGB_PVRTC_4BPPV1_Format: RGB_PVRTC_4BPPV1_Format,
  55425. RGB_S3TC_DXT1_Format: RGB_S3TC_DXT1_Format
  55426. };
  55427. /* WEB WORKER */
  55428. KTX2Loader.BasisWorker = function () {
  55429. var config;
  55430. var transcoderPending;
  55431. var BasisModule;
  55432. var EngineFormat = _EngineFormat; // eslint-disable-line no-undef
  55433. var TranscoderFormat = _TranscoderFormat; // eslint-disable-line no-undef
  55434. var BasisFormat = _BasisFormat; // eslint-disable-line no-undef
  55435. self.addEventListener('message', function (e) {
  55436. var message = e.data;
  55437. switch (message.type) {
  55438. case 'init':
  55439. config = message.config;
  55440. init(message.transcoderBinary);
  55441. break;
  55442. case 'transcode':
  55443. transcoderPending.then(() => {
  55444. try {
  55445. var {
  55446. width,
  55447. height,
  55448. hasAlpha,
  55449. mipmaps,
  55450. format,
  55451. dfdTransferFn,
  55452. dfdFlags
  55453. } = transcode(message.buffer);
  55454. var buffers = [];
  55455. for (var i = 0; i < mipmaps.length; ++i) {
  55456. buffers.push(mipmaps[i].data.buffer);
  55457. }
  55458. self.postMessage({
  55459. type: 'transcode',
  55460. id: message.id,
  55461. width,
  55462. height,
  55463. hasAlpha,
  55464. mipmaps,
  55465. format,
  55466. dfdTransferFn,
  55467. dfdFlags
  55468. }, buffers);
  55469. } catch (error) {
  55470. console.error(error);
  55471. self.postMessage({
  55472. type: 'error',
  55473. id: message.id,
  55474. error: error.message
  55475. });
  55476. }
  55477. });
  55478. break;
  55479. }
  55480. });
  55481. function init(wasmBinary) {
  55482. transcoderPending = new Promise(resolve => {
  55483. BasisModule = {
  55484. wasmBinary,
  55485. onRuntimeInitialized: resolve
  55486. };
  55487. BASIS(BasisModule); // eslint-disable-line no-undef
  55488. }).then(() => {
  55489. BasisModule.initializeBasis();
  55490. if (BasisModule.KTX2File === undefined) {
  55491. console.warn('THREE.KTX2Loader: Please update Basis Universal transcoder.');
  55492. }
  55493. });
  55494. }
  55495. function transcode(buffer) {
  55496. var ktx2File = new BasisModule.KTX2File(new Uint8Array(buffer));
  55497. function cleanup() {
  55498. ktx2File.close();
  55499. ktx2File.delete();
  55500. }
  55501. if (!ktx2File.isValid()) {
  55502. cleanup();
  55503. throw new Error('THREE.KTX2Loader: Invalid or unsupported .ktx2 file');
  55504. }
  55505. var basisFormat = ktx2File.isUASTC() ? BasisFormat.UASTC_4x4 : BasisFormat.ETC1S;
  55506. var width = ktx2File.getWidth();
  55507. var height = ktx2File.getHeight();
  55508. var layers = ktx2File.getLayers() || 1;
  55509. var levels = ktx2File.getLevels();
  55510. var hasAlpha = ktx2File.getHasAlpha();
  55511. var dfdTransferFn = ktx2File.getDFDTransferFunc();
  55512. var dfdFlags = ktx2File.getDFDFlags();
  55513. var {
  55514. transcoderFormat,
  55515. engineFormat
  55516. } = getTranscoderFormat(basisFormat, width, height, hasAlpha);
  55517. if (!width || !height || !levels) {
  55518. cleanup();
  55519. throw new Error('THREE.KTX2Loader: Invalid texture');
  55520. }
  55521. if (!ktx2File.startTranscoding()) {
  55522. cleanup();
  55523. throw new Error('THREE.KTX2Loader: .startTranscoding failed');
  55524. }
  55525. var mipmaps = [];
  55526. for (var mip = 0; mip < levels; mip++) {
  55527. var layerMips = [];
  55528. var mipWidth = void 0,
  55529. mipHeight = void 0;
  55530. for (var layer = 0; layer < layers; layer++) {
  55531. var levelInfo = ktx2File.getImageLevelInfo(mip, layer, 0);
  55532. mipWidth = levelInfo.origWidth;
  55533. mipHeight = levelInfo.origHeight;
  55534. var dst = new Uint8Array(ktx2File.getImageTranscodedSizeInBytes(mip, layer, 0, transcoderFormat));
  55535. var status = ktx2File.transcodeImage(dst, mip, layer, 0, transcoderFormat, 0, -1, -1);
  55536. if (!status) {
  55537. cleanup();
  55538. throw new Error('THREE.KTX2Loader: .transcodeImage failed.');
  55539. }
  55540. layerMips.push(dst);
  55541. }
  55542. mipmaps.push({
  55543. data: concat(layerMips),
  55544. width: mipWidth,
  55545. height: mipHeight
  55546. });
  55547. }
  55548. cleanup();
  55549. return {
  55550. width,
  55551. height,
  55552. hasAlpha,
  55553. mipmaps,
  55554. format: engineFormat,
  55555. dfdTransferFn,
  55556. dfdFlags
  55557. };
  55558. }
  55559. //
  55560. // Optimal choice of a transcoder target format depends on the Basis format (ETC1S or UASTC),
  55561. // device capabilities, and texture dimensions. The list below ranks the formats separately
  55562. // for ETC1S and UASTC.
  55563. //
  55564. // In some cases, transcoding UASTC to RGBA32 might be preferred for higher quality (at
  55565. // significant memory cost) compared to ETC1/2, BC1/3, and PVRTC. The transcoder currently
  55566. // chooses RGBA32 only as a last resort and does not expose that option to the caller.
  55567. var FORMAT_OPTIONS = [{
  55568. if: 'astcSupported',
  55569. basisFormat: [BasisFormat.UASTC_4x4],
  55570. transcoderFormat: [TranscoderFormat.ASTC_4x4, TranscoderFormat.ASTC_4x4],
  55571. engineFormat: [EngineFormat.RGBA_ASTC_4x4_Format, EngineFormat.RGBA_ASTC_4x4_Format],
  55572. priorityETC1S: Infinity,
  55573. priorityUASTC: 1,
  55574. needsPowerOfTwo: false
  55575. }, {
  55576. if: 'bptcSupported',
  55577. basisFormat: [BasisFormat.ETC1S, BasisFormat.UASTC_4x4],
  55578. transcoderFormat: [TranscoderFormat.BC7_M5, TranscoderFormat.BC7_M5],
  55579. engineFormat: [EngineFormat.RGBA_BPTC_Format, EngineFormat.RGBA_BPTC_Format],
  55580. priorityETC1S: 3,
  55581. priorityUASTC: 2,
  55582. needsPowerOfTwo: false
  55583. }, {
  55584. if: 'dxtSupported',
  55585. basisFormat: [BasisFormat.ETC1S, BasisFormat.UASTC_4x4],
  55586. transcoderFormat: [TranscoderFormat.BC1, TranscoderFormat.BC3],
  55587. engineFormat: [EngineFormat.RGB_S3TC_DXT1_Format, EngineFormat.RGBA_S3TC_DXT5_Format],
  55588. priorityETC1S: 4,
  55589. priorityUASTC: 5,
  55590. needsPowerOfTwo: false
  55591. }, {
  55592. if: 'etc2Supported',
  55593. basisFormat: [BasisFormat.ETC1S, BasisFormat.UASTC_4x4],
  55594. transcoderFormat: [TranscoderFormat.ETC1, TranscoderFormat.ETC2],
  55595. engineFormat: [EngineFormat.RGB_ETC2_Format, EngineFormat.RGBA_ETC2_EAC_Format],
  55596. priorityETC1S: 1,
  55597. priorityUASTC: 3,
  55598. needsPowerOfTwo: false
  55599. }, {
  55600. if: 'etc1Supported',
  55601. basisFormat: [BasisFormat.ETC1S, BasisFormat.UASTC_4x4],
  55602. transcoderFormat: [TranscoderFormat.ETC1],
  55603. engineFormat: [EngineFormat.RGB_ETC1_Format],
  55604. priorityETC1S: 2,
  55605. priorityUASTC: 4,
  55606. needsPowerOfTwo: false
  55607. }, {
  55608. if: 'pvrtcSupported',
  55609. basisFormat: [BasisFormat.ETC1S, BasisFormat.UASTC_4x4],
  55610. transcoderFormat: [TranscoderFormat.PVRTC1_4_RGB, TranscoderFormat.PVRTC1_4_RGBA],
  55611. engineFormat: [EngineFormat.RGB_PVRTC_4BPPV1_Format, EngineFormat.RGBA_PVRTC_4BPPV1_Format],
  55612. priorityETC1S: 5,
  55613. priorityUASTC: 6,
  55614. needsPowerOfTwo: true
  55615. }];
  55616. var ETC1S_OPTIONS = FORMAT_OPTIONS.sort(function (a, b) {
  55617. return a.priorityETC1S - b.priorityETC1S;
  55618. });
  55619. var UASTC_OPTIONS = FORMAT_OPTIONS.sort(function (a, b) {
  55620. return a.priorityUASTC - b.priorityUASTC;
  55621. });
  55622. function getTranscoderFormat(basisFormat, width, height, hasAlpha) {
  55623. var transcoderFormat;
  55624. var engineFormat;
  55625. var options = basisFormat === BasisFormat.ETC1S ? ETC1S_OPTIONS : UASTC_OPTIONS;
  55626. for (var i = 0; i < options.length; i++) {
  55627. var opt = options[i];
  55628. if (!config[opt.if]) continue;
  55629. if (!opt.basisFormat.includes(basisFormat)) continue;
  55630. if (hasAlpha && opt.transcoderFormat.length < 2) continue;
  55631. if (opt.needsPowerOfTwo && !(isPowerOfTwo(width) && isPowerOfTwo(height))) continue;
  55632. transcoderFormat = opt.transcoderFormat[hasAlpha ? 1 : 0];
  55633. engineFormat = opt.engineFormat[hasAlpha ? 1 : 0];
  55634. return {
  55635. transcoderFormat,
  55636. engineFormat
  55637. };
  55638. }
  55639. console.warn('THREE.KTX2Loader: No suitable compressed texture format found. Decoding to RGBA32.');
  55640. transcoderFormat = TranscoderFormat.RGBA32;
  55641. engineFormat = EngineFormat.RGBAFormat;
  55642. return {
  55643. transcoderFormat,
  55644. engineFormat
  55645. };
  55646. }
  55647. function isPowerOfTwo(value) {
  55648. if (value <= 2) return true;
  55649. return (value & value - 1) === 0 && value !== 0;
  55650. }
  55651. /** Concatenates N byte arrays. */
  55652. function concat(arrays) {
  55653. var totalByteLength = 0;
  55654. for (var array of arrays) {
  55655. totalByteLength += array.byteLength;
  55656. }
  55657. var result = new Uint8Array(totalByteLength);
  55658. var byteOffset = 0;
  55659. for (var _array of arrays) {
  55660. result.set(_array, byteOffset);
  55661. byteOffset += _array.byteLength;
  55662. }
  55663. return result;
  55664. }
  55665. };
  55666. //
  55667. // DataTexture and Data3DTexture parsing.
  55668. var FORMAT_MAP = {
  55669. [Ae]: RGBAFormat,
  55670. [pe]: RGBAFormat,
  55671. [Ot]: RGBAFormat,
  55672. [Ft]: RGBAFormat,
  55673. [de]: RGFormat,
  55674. [se]: RGFormat,
  55675. [yt]: RGFormat,
  55676. [dt]: RGFormat,
  55677. [xe]: RedFormat,
  55678. [$t]: RedFormat,
  55679. [gt]: RedFormat,
  55680. [ct]: RedFormat
  55681. };
  55682. var TYPE_MAP = {
  55683. [Ae]: FloatType,
  55684. [pe]: HalfFloatType,
  55685. [Ot]: UnsignedByteType,
  55686. [Ft]: UnsignedByteType,
  55687. [de]: FloatType,
  55688. [se]: HalfFloatType,
  55689. [yt]: UnsignedByteType,
  55690. [dt]: UnsignedByteType,
  55691. [xe]: FloatType,
  55692. [$t]: HalfFloatType,
  55693. [gt]: UnsignedByteType,
  55694. [ct]: UnsignedByteType
  55695. };
  55696. var ENCODING_MAP = {
  55697. [Ft]: sRGBEncoding,
  55698. [dt]: sRGBEncoding,
  55699. [gt]: sRGBEncoding
  55700. };
  55701. async function createDataTexture(container) {
  55702. var {
  55703. vkFormat,
  55704. pixelWidth,
  55705. pixelHeight,
  55706. pixelDepth
  55707. } = container;
  55708. if (FORMAT_MAP[vkFormat] === undefined) {
  55709. throw new Error('THREE.KTX2Loader: Unsupported vkFormat.');
  55710. }
  55711. var level = container.levels[0];
  55712. var levelData;
  55713. var view;
  55714. if (container.supercompressionScheme === t) {
  55715. levelData = level.levelData;
  55716. } else if (container.supercompressionScheme === n$1) {
  55717. if (!_zstd) {
  55718. _zstd = new Promise(async resolve => {
  55719. var zstd = new ZSTDDecoder();
  55720. await zstd.init();
  55721. resolve(zstd);
  55722. });
  55723. }
  55724. levelData = (await _zstd).decode(level.levelData, level.uncompressedByteLength);
  55725. } else {
  55726. throw new Error('THREE.KTX2Loader: Unsupported supercompressionScheme.');
  55727. }
  55728. if (TYPE_MAP[vkFormat] === FloatType) {
  55729. view = new Float32Array(levelData.buffer, levelData.byteOffset, levelData.byteLength / Float32Array.BYTES_PER_ELEMENT);
  55730. } else if (TYPE_MAP[vkFormat] === HalfFloatType) {
  55731. view = new Uint16Array(levelData.buffer, levelData.byteOffset, levelData.byteLength / Uint16Array.BYTES_PER_ELEMENT);
  55732. } else {
  55733. view = levelData;
  55734. }
  55735. //
  55736. var texture = pixelDepth === 0 ? new DataTexture(view, pixelWidth, pixelHeight) : new Data3DTexture(view, pixelWidth, pixelHeight, pixelDepth);
  55737. texture.type = TYPE_MAP[vkFormat];
  55738. texture.format = FORMAT_MAP[vkFormat];
  55739. texture.encoding = ENCODING_MAP[vkFormat] || LinearEncoding;
  55740. texture.needsUpdate = true;
  55741. //
  55742. return Promise.resolve(texture);
  55743. }
  55744. // This file is part of meshoptimizer library and is distributed under the terms of MIT License.
  55745. // Copyright (C) 2016-2020, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com)
  55746. var MeshoptDecoder = function () {
  55747. "use strict";
  55748. // Built with clang version 11.0.0 (https://github.com/llvm/llvm-project.git 0160ad802e899c2922bc9b29564080c22eb0908c)
  55749. // Built from meshoptimizer 0.14
  55750. var wasm_base = "B9h9z9tFBBBF8fL9gBB9gLaaaaaFa9gEaaaB9gFaFa9gEaaaFaEMcBFFFGGGEIIILF9wFFFLEFBFKNFaFCx/IFMO/LFVK9tv9t9vq95GBt9f9f939h9z9t9f9j9h9s9s9f9jW9vq9zBBp9tv9z9o9v9wW9f9kv9j9v9kv9WvqWv94h919m9mvqBF8Z9tv9z9o9v9wW9f9kv9j9v9kv9J9u9kv94h919m9mvqBGy9tv9z9o9v9wW9f9kv9j9v9kv9J9u9kv949TvZ91v9u9jvBEn9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9P9jWBIi9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9R919hWBLn9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9F949wBKI9z9iqlBOc+x8ycGBM/qQFTa8jUUUUBCU/EBlHL8kUUUUBC9+RKGXAGCFJAI9LQBCaRKAE2BBC+gF9HQBALAEAIJHOAGlAGTkUUUBRNCUoBAG9uC/wgBZHKCUGAKCUG9JyRVAECFJRICBRcGXEXAcAF9PQFAVAFAclAcAVJAF9JyRMGXGXAG9FQBAMCbJHKC9wZRSAKCIrCEJCGrRQANCUGJRfCBRbAIRTEXGXAOATlAQ9PQBCBRISEMATAQJRIGXAS9FQBCBRtCBREEXGXAOAIlCi9PQBCBRISLMANCU/CBJAEJRKGXGXGXGXGXATAECKrJ2BBAtCKZrCEZfIBFGEBMAKhB83EBAKCNJhB83EBSEMAKAI2BIAI2BBHmCKrHYAYCE6HYy86BBAKCFJAICIJAYJHY2BBAmCIrCEZHPAPCE6HPy86BBAKCGJAYAPJHY2BBAmCGrCEZHPAPCE6HPy86BBAKCEJAYAPJHY2BBAmCEZHmAmCE6Hmy86BBAKCIJAYAmJHY2BBAI2BFHmCKrHPAPCE6HPy86BBAKCLJAYAPJHY2BBAmCIrCEZHPAPCE6HPy86BBAKCKJAYAPJHY2BBAmCGrCEZHPAPCE6HPy86BBAKCOJAYAPJHY2BBAmCEZHmAmCE6Hmy86BBAKCNJAYAmJHY2BBAI2BGHmCKrHPAPCE6HPy86BBAKCVJAYAPJHY2BBAmCIrCEZHPAPCE6HPy86BBAKCcJAYAPJHY2BBAmCGrCEZHPAPCE6HPy86BBAKCMJAYAPJHY2BBAmCEZHmAmCE6Hmy86BBAKCSJAYAmJHm2BBAI2BEHICKrHYAYCE6HYy86BBAKCQJAmAYJHm2BBAICIrCEZHYAYCE6HYy86BBAKCfJAmAYJHm2BBAICGrCEZHYAYCE6HYy86BBAKCbJAmAYJHK2BBAICEZHIAICE6HIy86BBAKAIJRISGMAKAI2BNAI2BBHmCIrHYAYCb6HYy86BBAKCFJAICNJAYJHY2BBAmCbZHmAmCb6Hmy86BBAKCGJAYAmJHm2BBAI2BFHYCIrHPAPCb6HPy86BBAKCEJAmAPJHm2BBAYCbZHYAYCb6HYy86BBAKCIJAmAYJHm2BBAI2BGHYCIrHPAPCb6HPy86BBAKCLJAmAPJHm2BBAYCbZHYAYCb6HYy86BBAKCKJAmAYJHm2BBAI2BEHYCIrHPAPCb6HPy86BBAKCOJAmAPJHm2BBAYCbZHYAYCb6HYy86BBAKCNJAmAYJHm2BBAI2BIHYCIrHPAPCb6HPy86BBAKCVJAmAPJHm2BBAYCbZHYAYCb6HYy86BBAKCcJAmAYJHm2BBAI2BLHYCIrHPAPCb6HPy86BBAKCMJAmAPJHm2BBAYCbZHYAYCb6HYy86BBAKCSJAmAYJHm2BBAI2BKHYCIrHPAPCb6HPy86BBAKCQJAmAPJHm2BBAYCbZHYAYCb6HYy86BBAKCfJAmAYJHm2BBAI2BOHICIrHYAYCb6HYy86BBAKCbJAmAYJHK2BBAICbZHIAICb6HIy86BBAKAIJRISFMAKAI8pBB83BBAKCNJAICNJ8pBB83BBAICTJRIMAtCGJRtAECTJHEAS9JQBMMGXAIQBCBRISEMGXAM9FQBANAbJ2BBRtCBRKAfREEXAEANCU/CBJAKJ2BBHTCFrCBATCFZl9zAtJHt86BBAEAGJREAKCFJHKAM9HQBMMAfCFJRfAIRTAbCFJHbAG9HQBMMABAcAG9sJANCUGJAMAG9sTkUUUBpANANCUGJAMCaJAG9sJAGTkUUUBpMAMCBAIyAcJRcAIQBMC9+RKSFMCBC99AOAIlAGCAAGCA9Ly6yRKMALCU/EBJ8kUUUUBAKM+OmFTa8jUUUUBCoFlHL8kUUUUBC9+RKGXAFCE9uHOCtJAI9LQBCaRKAE2BBHNC/wFZC/gF9HQBANCbZHVCF9LQBALCoBJCgFCUFT+JUUUBpALC84Jha83EBALC8wJha83EBALC8oJha83EBALCAJha83EBALCiJha83EBALCTJha83EBALha83ENALha83EBAEAIJC9wJRcAECFJHNAOJRMGXAF9FQBCQCbAVCF6yRSABRECBRVCBRQCBRfCBRICBRKEXGXAMAcuQBC9+RKSEMGXGXAN2BBHOC/vF9LQBALCoBJAOCIrCa9zAKJCbZCEWJHb8oGIRTAb8oGBRtGXAOCbZHbAS9PQBALAOCa9zAIJCbZCGWJ8oGBAVAbyROAb9FRbGXGXAGCG9HQBABAt87FBABCIJAO87FBABCGJAT87FBSFMAEAtjGBAECNJAOjGBAECIJATjGBMAVAbJRVALCoBJAKCEWJHmAOjGBAmATjGIALAICGWJAOjGBALCoBJAKCFJCbZHKCEWJHTAtjGBATAOjGIAIAbJRIAKCFJRKSGMGXGXAbCb6QBAQAbJAbC989zJCFJRQSFMAM1BBHbCgFZROGXGXAbCa9MQBAMCFJRMSFMAM1BFHbCgBZCOWAOCgBZqROGXAbCa9MQBAMCGJRMSFMAM1BGHbCgBZCfWAOqROGXAbCa9MQBAMCEJRMSFMAM1BEHbCgBZCdWAOqROGXAbCa9MQBAMCIJRMSFMAM2BIC8cWAOqROAMCLJRMMAOCFrCBAOCFZl9zAQJRQMGXGXAGCG9HQBABAt87FBABCIJAQ87FBABCGJAT87FBSFMAEAtjGBAECNJAQjGBAECIJATjGBMALCoBJAKCEWJHOAQjGBAOATjGIALAICGWJAQjGBALCoBJAKCFJCbZHKCEWJHOAtjGBAOAQjGIAICFJRIAKCFJRKSFMGXAOCDF9LQBALAIAcAOCbZJ2BBHbCIrHTlCbZCGWJ8oGBAVCFJHtATyROALAIAblCbZCGWJ8oGBAtAT9FHmJHtAbCbZHTyRbAT9FRTGXGXAGCG9HQBABAV87FBABCIJAb87FBABCGJAO87FBSFMAEAVjGBAECNJAbjGBAECIJAOjGBMALAICGWJAVjGBALCoBJAKCEWJHYAOjGBAYAVjGIALAICFJHICbZCGWJAOjGBALCoBJAKCFJCbZCEWJHYAbjGBAYAOjGIALAIAmJCbZHICGWJAbjGBALCoBJAKCGJCbZHKCEWJHOAVjGBAOAbjGIAKCFJRKAIATJRIAtATJRVSFMAVCBAM2BBHYyHTAOC/+F6HPJROAYCbZRtGXGXAYCIrHmQBAOCFJRbSFMAORbALAIAmlCbZCGWJ8oGBROMGXGXAtQBAbCFJRVSFMAbRVALAIAYlCbZCGWJ8oGBRbMGXGXAP9FQBAMCFJRYSFMAM1BFHYCgFZRTGXGXAYCa9MQBAMCGJRYSFMAM1BGHYCgBZCOWATCgBZqRTGXAYCa9MQBAMCEJRYSFMAM1BEHYCgBZCfWATqRTGXAYCa9MQBAMCIJRYSFMAM1BIHYCgBZCdWATqRTGXAYCa9MQBAMCLJRYSFMAMCKJRYAM2BLC8cWATqRTMATCFrCBATCFZl9zAQJHQRTMGXGXAmCb6QBAYRPSFMAY1BBHMCgFZROGXGXAMCa9MQBAYCFJRPSFMAY1BFHMCgBZCOWAOCgBZqROGXAMCa9MQBAYCGJRPSFMAY1BGHMCgBZCfWAOqROGXAMCa9MQBAYCEJRPSFMAY1BEHMCgBZCdWAOqROGXAMCa9MQBAYCIJRPSFMAYCLJRPAY2BIC8cWAOqROMAOCFrCBAOCFZl9zAQJHQROMGXGXAtCb6QBAPRMSFMAP1BBHMCgFZRbGXGXAMCa9MQBAPCFJRMSFMAP1BFHMCgBZCOWAbCgBZqRbGXAMCa9MQBAPCGJRMSFMAP1BGHMCgBZCfWAbqRbGXAMCa9MQBAPCEJRMSFMAP1BEHMCgBZCdWAbqRbGXAMCa9MQBAPCIJRMSFMAPCLJRMAP2BIC8cWAbqRbMAbCFrCBAbCFZl9zAQJHQRbMGXGXAGCG9HQBABAT87FBABCIJAb87FBABCGJAO87FBSFMAEATjGBAECNJAbjGBAECIJAOjGBMALCoBJAKCEWJHYAOjGBAYATjGIALAICGWJATjGBALCoBJAKCFJCbZCEWJHYAbjGBAYAOjGIALAICFJHICbZCGWJAOjGBALCoBJAKCGJCbZCEWJHOATjGBAOAbjGIALAIAm9FAmCb6qJHICbZCGWJAbjGBAIAt9FAtCb6qJRIAKCEJRKMANCFJRNABCKJRBAECSJREAKCbZRKAICbZRIAfCEJHfAF9JQBMMCBC99AMAc6yRKMALCoFJ8kUUUUBAKM/tIFGa8jUUUUBCTlRLC9+RKGXAFCLJAI9LQBCaRKAE2BBC/+FZC/QF9HQBALhB83ENAECFJRKAEAIJC98JREGXAF9FQBGXAGCG6QBEXGXAKAE9JQBC9+bMAK1BBHGCgFZRIGXGXAGCa9MQBAKCFJRKSFMAK1BFHGCgBZCOWAICgBZqRIGXAGCa9MQBAKCGJRKSFMAK1BGHGCgBZCfWAIqRIGXAGCa9MQBAKCEJRKSFMAK1BEHGCgBZCdWAIqRIGXAGCa9MQBAKCIJRKSFMAK2BIC8cWAIqRIAKCLJRKMALCNJAICFZCGWqHGAICGrCBAICFrCFZl9zAG8oGBJHIjGBABAIjGBABCIJRBAFCaJHFQBSGMMEXGXAKAE9JQBC9+bMAK1BBHGCgFZRIGXGXAGCa9MQBAKCFJRKSFMAK1BFHGCgBZCOWAICgBZqRIGXAGCa9MQBAKCGJRKSFMAK1BGHGCgBZCfWAIqRIGXAGCa9MQBAKCEJRKSFMAK1BEHGCgBZCdWAIqRIGXAGCa9MQBAKCIJRKSFMAK2BIC8cWAIqRIAKCLJRKMABAICGrCBAICFrCFZl9zALCNJAICFZCGWqHI8oGBJHG87FBAIAGjGBABCGJRBAFCaJHFQBMMCBC99AKAE6yRKMAKM+lLKFaF99GaG99FaG99GXGXAGCI9HQBAF9FQFEXGXGX9DBBB8/9DBBB+/ABCGJHG1BB+yAB1BBHE+yHI+L+TABCFJHL1BBHK+yHO+L+THN9DBBBB9gHVyAN9DBB/+hANAN+U9DBBBBANAVyHcAc+MHMAECa3yAI+SHIAI+UAcAMAKCa3yAO+SHcAc+U+S+S+R+VHO+U+SHN+L9DBBB9P9d9FQBAN+oRESFMCUUUU94REMAGAE86BBGXGX9DBBB8/9DBBB+/Ac9DBBBB9gyAcAO+U+SHN+L9DBBB9P9d9FQBAN+oRGSFMCUUUU94RGMALAG86BBGXGX9DBBB8/9DBBB+/AI9DBBBB9gyAIAO+U+SHN+L9DBBB9P9d9FQBAN+oRGSFMCUUUU94RGMABAG86BBABCIJRBAFCaJHFQBSGMMAF9FQBEXGXGX9DBBB8/9DBBB+/ABCIJHG8uFB+yAB8uFBHE+yHI+L+TABCGJHL8uFBHK+yHO+L+THN9DBBBB9gHVyAN9DB/+g6ANAN+U9DBBBBANAVyHcAc+MHMAECa3yAI+SHIAI+UAcAMAKCa3yAO+SHcAc+U+S+S+R+VHO+U+SHN+L9DBBB9P9d9FQBAN+oRESFMCUUUU94REMAGAE87FBGXGX9DBBB8/9DBBB+/Ac9DBBBB9gyAcAO+U+SHN+L9DBBB9P9d9FQBAN+oRGSFMCUUUU94RGMALAG87FBGXGX9DBBB8/9DBBB+/AI9DBBBB9gyAIAO+U+SHN+L9DBBB9P9d9FQBAN+oRGSFMCUUUU94RGMABAG87FBABCNJRBAFCaJHFQBMMM/SEIEaE99EaF99GXAF9FQBCBREABRIEXGXGX9D/zI818/AICKJ8uFBHLCEq+y+VHKAI8uFB+y+UHO9DB/+g6+U9DBBB8/9DBBB+/AO9DBBBB9gy+SHN+L9DBBB9P9d9FQBAN+oRVSFMCUUUU94RVMAICIJ8uFBRcAICGJ8uFBRMABALCFJCEZAEqCFWJAV87FBGXGXAKAM+y+UHN9DB/+g6+U9DBBB8/9DBBB+/AN9DBBBB9gy+SHS+L9DBBB9P9d9FQBAS+oRMSFMCUUUU94RMMABALCGJCEZAEqCFWJAM87FBGXGXAKAc+y+UHK9DB/+g6+U9DBBB8/9DBBB+/AK9DBBBB9gy+SHS+L9DBBB9P9d9FQBAS+oRcSFMCUUUU94RcMABALCaJCEZAEqCFWJAc87FBGXGX9DBBU8/AOAO+U+TANAN+U+TAKAK+U+THO9DBBBBAO9DBBBB9gy+R9DB/+g6+U9DBBB8/+SHO+L9DBBB9P9d9FQBAO+oRcSFMCUUUU94RcMABALCEZAEqCFWJAc87FBAICNJRIAECIJREAFCaJHFQBMMM9JBGXAGCGrAF9sHF9FQBEXABAB8oGBHGCNWCN91+yAGCi91CnWCUUU/8EJ+++U84GBABCIJRBAFCaJHFQBMMM9TFEaCBCB8oGUkUUBHFABCEJC98ZJHBjGUkUUBGXGXAB8/BCTWHGuQBCaREABAGlCggEJCTrXBCa6QFMAFREMAEM/lFFFaGXGXAFABqCEZ9FQBABRESFMGXGXAGCT9PQBABRESFMABREEXAEAF8oGBjGBAECIJAFCIJ8oGBjGBAECNJAFCNJ8oGBjGBAECSJAFCSJ8oGBjGBAECTJREAFCTJRFAGC9wJHGCb9LQBMMAGCI9JQBEXAEAF8oGBjGBAFCIJRFAECIJREAGC98JHGCE9LQBMMGXAG9FQBEXAEAF2BB86BBAECFJREAFCFJRFAGCaJHGQBMMABMoFFGaGXGXABCEZ9FQBABRESFMAFCgFZC+BwsN9sRIGXGXAGCT9PQBABRESFMABREEXAEAIjGBAECSJAIjGBAECNJAIjGBAECIJAIjGBAECTJREAGC9wJHGCb9LQBMMAGCI9JQBEXAEAIjGBAECIJREAGC98JHGCE9LQBMMGXAG9FQBEXAEAF86BBAECFJREAGCaJHGQBMMABMMMFBCUNMIT9kBB";
  55751. var wasm_simd = "B9h9z9tFBBBFiI9gBB9gLaaaaaFa9gEaaaB9gFaFaEMcBBFBFFGGGEILF9wFFFLEFBFKNFaFCx/aFMO/LFVK9tv9t9vq95GBt9f9f939h9z9t9f9j9h9s9s9f9jW9vq9zBBp9tv9z9o9v9wW9f9kv9j9v9kv9WvqWv94h919m9mvqBG8Z9tv9z9o9v9wW9f9kv9j9v9kv9J9u9kv94h919m9mvqBIy9tv9z9o9v9wW9f9kv9j9v9kv9J9u9kv949TvZ91v9u9jvBLn9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9P9jWBKi9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9R919hWBOn9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9F949wBNI9z9iqlBVc+N9IcIBTEM9+FLa8jUUUUBCTlRBCBRFEXCBRGCBREEXABCNJAGJAECUaAFAGrCFZHIy86BBAEAIJREAGCFJHGCN9HQBMAFCx+YUUBJAE86BBAFCEWCxkUUBJAB8pEN83EBAFCFJHFCUG9HQBMMk8lLbaE97F9+FaL978jUUUUBCU/KBlHL8kUUUUBC9+RKGXAGCFJAI9LQBCaRKAE2BBC+gF9HQBALAEAIJHOAGlAG/8cBBCUoBAG9uC/wgBZHKCUGAKCUG9JyRNAECFJRKCBRVGXEXAVAF9PQFANAFAVlAVANJAF9JyRcGXGXAG9FQBAcCbJHIC9wZHMCE9sRSAMCFWRQAICIrCEJCGrRfCBRbEXAKRTCBRtGXEXGXAOATlAf9PQBCBRKSLMALCU/CBJAtAM9sJRmATAfJRKCBREGXAMCoB9JQBAOAKlC/gB9JQBCBRIEXAmAIJREGXGXGXGXGXATAICKrJ2BBHYCEZfIBFGEBMAECBDtDMIBSEMAEAKDBBIAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnHPCGD+MFAPDQBTFtGmEYIPLdKeOnC0+G+MiDtD9OHdCEDbD8jHPAPDQBFGENVcMILKOSQfbHeD8dBh+BsxoxoUwN0AeD8dFhxoUwkwk+gUa0sHnhTkAnsHnhNkAnsHn7CgFZHiCEWCxkUUBJDBEBAiCx+YUUBJDBBBHeAeDQBBBBBBBBBBBBBBBBAnhAk7CgFZHiCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMIBAKCIJAeDeBJAiCx+YUUBJ2BBJRKSGMAEAKDBBNAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnC+P+e+8/4BDtD9OHdCbDbD8jHPAPDQBFGENVcMILKOSQfbHeD8dBh+BsxoxoUwN0AeD8dFhxoUwkwk+gUa0sHnhTkAnsHnhNkAnsHn7CgFZHiCEWCxkUUBJDBEBAiCx+YUUBJDBBBHeAeDQBBBBBBBBBBBBBBBBAnhAk7CgFZHiCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMIBAKCNJAeDeBJAiCx+YUUBJ2BBJRKSFMAEAKDBBBDMIBAKCTJRKMGXGXGXGXGXAYCGrCEZfIBFGEBMAECBDtDMITSEMAEAKDBBIAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnHPCGD+MFAPDQBTFtGmEYIPLdKeOnC0+G+MiDtD9OHdCEDbD8jHPAPDQBFGENVcMILKOSQfbHeD8dBh+BsxoxoUwN0AeD8dFhxoUwkwk+gUa0sHnhTkAnsHnhNkAnsHn7CgFZHiCEWCxkUUBJDBEBAiCx+YUUBJDBBBHeAeDQBBBBBBBBBBBBBBBBAnhAk7CgFZHiCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMITAKCIJAeDeBJAiCx+YUUBJ2BBJRKSGMAEAKDBBNAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnC+P+e+8/4BDtD9OHdCbDbD8jHPAPDQBFGENVcMILKOSQfbHeD8dBh+BsxoxoUwN0AeD8dFhxoUwkwk+gUa0sHnhTkAnsHnhNkAnsHn7CgFZHiCEWCxkUUBJDBEBAiCx+YUUBJDBBBHeAeDQBBBBBBBBBBBBBBBBAnhAk7CgFZHiCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMITAKCNJAeDeBJAiCx+YUUBJ2BBJRKSFMAEAKDBBBDMITAKCTJRKMGXGXGXGXGXAYCIrCEZfIBFGEBMAECBDtDMIASEMAEAKDBBIAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnHPCGD+MFAPDQBTFtGmEYIPLdKeOnC0+G+MiDtD9OHdCEDbD8jHPAPDQBFGENVcMILKOSQfbHeD8dBh+BsxoxoUwN0AeD8dFhxoUwkwk+gUa0sHnhTkAnsHnhNkAnsHn7CgFZHiCEWCxkUUBJDBEBAiCx+YUUBJDBBBHeAeDQBBBBBBBBBBBBBBBBAnhAk7CgFZHiCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMIAAKCIJAeDeBJAiCx+YUUBJ2BBJRKSGMAEAKDBBNAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnC+P+e+8/4BDtD9OHdCbDbD8jHPAPDQBFGENVcMILKOSQfbHeD8dBh+BsxoxoUwN0AeD8dFhxoUwkwk+gUa0sHnhTkAnsHnhNkAnsHn7CgFZHiCEWCxkUUBJDBEBAiCx+YUUBJDBBBHeAeDQBBBBBBBBBBBBBBBBAnhAk7CgFZHiCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMIAAKCNJAeDeBJAiCx+YUUBJ2BBJRKSFMAEAKDBBBDMIAAKCTJRKMGXGXGXGXGXAYCKrfIBFGEBMAECBDtDMI8wSEMAEAKDBBIAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnHPCGD+MFAPDQBTFtGmEYIPLdKeOnC0+G+MiDtD9OHdCEDbD8jHPAPDQBFGENVcMILKOSQfbHeD8dBh+BsxoxoUwN0AeD8dFhxoUwkwk+gUa0sHnhTkAnsHnhNkAnsHn7CgFZHYCEWCxkUUBJDBEBAYCx+YUUBJDBBBHeAeDQBBBBBBBBBBBBBBBBAnhAk7CgFZHYCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMI8wAKCIJAeDeBJAYCx+YUUBJ2BBJRKSGMAEAKDBBNAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnC+P+e+8/4BDtD9OHdCbDbD8jHPAPDQBFGENVcMILKOSQfbHeD8dBh+BsxoxoUwN0AeD8dFhxoUwkwk+gUa0sHnhTkAnsHnhNkAnsHn7CgFZHYCEWCxkUUBJDBEBAYCx+YUUBJDBBBHeAeDQBBBBBBBBBBBBBBBBAnhAk7CgFZHYCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMI8wAKCNJAeDeBJAYCx+YUUBJ2BBJRKSFMAEAKDBBBDMI8wAKCTJRKMAICoBJREAICUFJAM9LQFAERIAOAKlC/fB9LQBMMGXAEAM9PQBAECErRIEXGXAOAKlCi9PQBCBRKSOMAmAEJRYGXGXGXGXGXATAECKrJ2BBAICKZrCEZfIBFGEBMAYCBDtDMIBSEMAYAKDBBIAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnHPCGD+MFAPDQBTFtGmEYIPLdKeOnC0+G+MiDtD9OHdCEDbD8jHPAPDQBFGENVcMILKOSQfbHeD8dBh+BsxoxoUwN0AeD8dFhxoUwkwk+gUa0sHnhTkAnsHnhNkAnsHn7CgFZHiCEWCxkUUBJDBEBAiCx+YUUBJDBBBHeAeDQBBBBBBBBBBBBBBBBAnhAk7CgFZHiCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMIBAKCIJAeDeBJAiCx+YUUBJ2BBJRKSGMAYAKDBBNAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnC+P+e+8/4BDtD9OHdCbDbD8jHPAPDQBFGENVcMILKOSQfbHeD8dBh+BsxoxoUwN0AeD8dFhxoUwkwk+gUa0sHnhTkAnsHnhNkAnsHn7CgFZHiCEWCxkUUBJDBEBAiCx+YUUBJDBBBHeAeDQBBBBBBBBBBBBBBBBAnhAk7CgFZHiCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMIBAKCNJAeDeBJAiCx+YUUBJ2BBJRKSFMAYAKDBBBDMIBAKCTJRKMAICGJRIAECTJHEAM9JQBMMGXAK9FQBAKRTAtCFJHtCI6QGSFMMCBRKSEMGXAM9FQBALCUGJAbJREALAbJDBGBReCBRYEXAEALCU/CBJAYJHIDBIBHdCFD9tAdCFDbHPD9OD9hD9RHdAIAMJDBIBH8ZCFD9tA8ZAPD9OD9hD9RH8ZDQBTFtGmEYIPLdKeOnHpAIAQJDBIBHyCFD9tAyAPD9OD9hD9RHyAIASJDBIBH8cCFD9tA8cAPD9OD9hD9RH8cDQBTFtGmEYIPLdKeOnH8dDQBFTtGEmYILPdKOenHPAPDQBFGEBFGEBFGEBFGEAeD9uHeDyBjGBAEAGJHIAeAPAPDQILKOILKOILKOILKOD9uHeDyBjGBAIAGJHIAeAPAPDQNVcMNVcMNVcMNVcMD9uHeDyBjGBAIAGJHIAeAPAPDQSQfbSQfbSQfbSQfbD9uHeDyBjGBAIAGJHIAeApA8dDQNVi8ZcMpySQ8c8dfb8e8fHPAPDQBFGEBFGEBFGEBFGED9uHeDyBjGBAIAGJHIAeAPAPDQILKOILKOILKOILKOD9uHeDyBjGBAIAGJHIAeAPAPDQNVcMNVcMNVcMNVcMD9uHeDyBjGBAIAGJHIAeAPAPDQSQfbSQfbSQfbSQfbD9uHeDyBjGBAIAGJHIAeAdA8ZDQNiV8ZcpMyS8cQ8df8eb8fHdAyA8cDQNiV8ZcpMyS8cQ8df8eb8fH8ZDQBFTtGEmYILPdKOenHPAPDQBFGEBFGEBFGEBFGED9uHeDyBjGBAIAGJHIAeAPAPDQILKOILKOILKOILKOD9uHeDyBjGBAIAGJHIAeAPAPDQNVcMNVcMNVcMNVcMD9uHeDyBjGBAIAGJHIAeAPAPDQSQfbSQfbSQfbSQfbD9uHeDyBjGBAIAGJHIAeAdA8ZDQNVi8ZcMpySQ8c8dfb8e8fHPAPDQBFGEBFGEBFGEBFGED9uHeDyBjGBAIAGJHIAeAPAPDQILKOILKOILKOILKOD9uHeDyBjGBAIAGJHIAeAPAPDQNVcMNVcMNVcMNVcMD9uHeDyBjGBAIAGJHIAeAPAPDQSQfbSQfbSQfbSQfbD9uHeDyBjGBAIAGJREAYCTJHYAM9JQBMMAbCIJHbAG9JQBMMABAVAG9sJALCUGJAcAG9s/8cBBALALCUGJAcCaJAG9sJAG/8cBBMAcCBAKyAVJRVAKQBMC9+RKSFMCBC99AOAKlAGCAAGCA9Ly6yRKMALCU/KBJ8kUUUUBAKMNBT+BUUUBM+KmFTa8jUUUUBCoFlHL8kUUUUBC9+RKGXAFCE9uHOCtJAI9LQBCaRKAE2BBHNC/wFZC/gF9HQBANCbZHVCF9LQBALCoBJCgFCUF/8MBALC84Jha83EBALC8wJha83EBALC8oJha83EBALCAJha83EBALCiJha83EBALCTJha83EBALha83ENALha83EBAEAIJC9wJRcAECFJHNAOJRMGXAF9FQBCQCbAVCF6yRSABRECBRVCBRQCBRfCBRICBRKEXGXAMAcuQBC9+RKSEMGXGXAN2BBHOC/vF9LQBALCoBJAOCIrCa9zAKJCbZCEWJHb8oGIRTAb8oGBRtGXAOCbZHbAS9PQBALAOCa9zAIJCbZCGWJ8oGBAVAbyROAb9FRbGXGXAGCG9HQBABAt87FBABCIJAO87FBABCGJAT87FBSFMAEAtjGBAECNJAOjGBAECIJATjGBMAVAbJRVALCoBJAKCEWJHmAOjGBAmATjGIALAICGWJAOjGBALCoBJAKCFJCbZHKCEWJHTAtjGBATAOjGIAIAbJRIAKCFJRKSGMGXGXAbCb6QBAQAbJAbC989zJCFJRQSFMAM1BBHbCgFZROGXGXAbCa9MQBAMCFJRMSFMAM1BFHbCgBZCOWAOCgBZqROGXAbCa9MQBAMCGJRMSFMAM1BGHbCgBZCfWAOqROGXAbCa9MQBAMCEJRMSFMAM1BEHbCgBZCdWAOqROGXAbCa9MQBAMCIJRMSFMAM2BIC8cWAOqROAMCLJRMMAOCFrCBAOCFZl9zAQJRQMGXGXAGCG9HQBABAt87FBABCIJAQ87FBABCGJAT87FBSFMAEAtjGBAECNJAQjGBAECIJATjGBMALCoBJAKCEWJHOAQjGBAOATjGIALAICGWJAQjGBALCoBJAKCFJCbZHKCEWJHOAtjGBAOAQjGIAICFJRIAKCFJRKSFMGXAOCDF9LQBALAIAcAOCbZJ2BBHbCIrHTlCbZCGWJ8oGBAVCFJHtATyROALAIAblCbZCGWJ8oGBAtAT9FHmJHtAbCbZHTyRbAT9FRTGXGXAGCG9HQBABAV87FBABCIJAb87FBABCGJAO87FBSFMAEAVjGBAECNJAbjGBAECIJAOjGBMALAICGWJAVjGBALCoBJAKCEWJHYAOjGBAYAVjGIALAICFJHICbZCGWJAOjGBALCoBJAKCFJCbZCEWJHYAbjGBAYAOjGIALAIAmJCbZHICGWJAbjGBALCoBJAKCGJCbZHKCEWJHOAVjGBAOAbjGIAKCFJRKAIATJRIAtATJRVSFMAVCBAM2BBHYyHTAOC/+F6HPJROAYCbZRtGXGXAYCIrHmQBAOCFJRbSFMAORbALAIAmlCbZCGWJ8oGBROMGXGXAtQBAbCFJRVSFMAbRVALAIAYlCbZCGWJ8oGBRbMGXGXAP9FQBAMCFJRYSFMAM1BFHYCgFZRTGXGXAYCa9MQBAMCGJRYSFMAM1BGHYCgBZCOWATCgBZqRTGXAYCa9MQBAMCEJRYSFMAM1BEHYCgBZCfWATqRTGXAYCa9MQBAMCIJRYSFMAM1BIHYCgBZCdWATqRTGXAYCa9MQBAMCLJRYSFMAMCKJRYAM2BLC8cWATqRTMATCFrCBATCFZl9zAQJHQRTMGXGXAmCb6QBAYRPSFMAY1BBHMCgFZROGXGXAMCa9MQBAYCFJRPSFMAY1BFHMCgBZCOWAOCgBZqROGXAMCa9MQBAYCGJRPSFMAY1BGHMCgBZCfWAOqROGXAMCa9MQBAYCEJRPSFMAY1BEHMCgBZCdWAOqROGXAMCa9MQBAYCIJRPSFMAYCLJRPAY2BIC8cWAOqROMAOCFrCBAOCFZl9zAQJHQROMGXGXAtCb6QBAPRMSFMAP1BBHMCgFZRbGXGXAMCa9MQBAPCFJRMSFMAP1BFHMCgBZCOWAbCgBZqRbGXAMCa9MQBAPCGJRMSFMAP1BGHMCgBZCfWAbqRbGXAMCa9MQBAPCEJRMSFMAP1BEHMCgBZCdWAbqRbGXAMCa9MQBAPCIJRMSFMAPCLJRMAP2BIC8cWAbqRbMAbCFrCBAbCFZl9zAQJHQRbMGXGXAGCG9HQBABAT87FBABCIJAb87FBABCGJAO87FBSFMAEATjGBAECNJAbjGBAECIJAOjGBMALCoBJAKCEWJHYAOjGBAYATjGIALAICGWJATjGBALCoBJAKCFJCbZCEWJHYAbjGBAYAOjGIALAICFJHICbZCGWJAOjGBALCoBJAKCGJCbZCEWJHOATjGBAOAbjGIALAIAm9FAmCb6qJHICbZCGWJAbjGBAIAt9FAtCb6qJRIAKCEJRKMANCFJRNABCKJRBAECSJREAKCbZRKAICbZRIAfCEJHfAF9JQBMMCBC99AMAc6yRKMALCoFJ8kUUUUBAKM/tIFGa8jUUUUBCTlRLC9+RKGXAFCLJAI9LQBCaRKAE2BBC/+FZC/QF9HQBALhB83ENAECFJRKAEAIJC98JREGXAF9FQBGXAGCG6QBEXGXAKAE9JQBC9+bMAK1BBHGCgFZRIGXGXAGCa9MQBAKCFJRKSFMAK1BFHGCgBZCOWAICgBZqRIGXAGCa9MQBAKCGJRKSFMAK1BGHGCgBZCfWAIqRIGXAGCa9MQBAKCEJRKSFMAK1BEHGCgBZCdWAIqRIGXAGCa9MQBAKCIJRKSFMAK2BIC8cWAIqRIAKCLJRKMALCNJAICFZCGWqHGAICGrCBAICFrCFZl9zAG8oGBJHIjGBABAIjGBABCIJRBAFCaJHFQBSGMMEXGXAKAE9JQBC9+bMAK1BBHGCgFZRIGXGXAGCa9MQBAKCFJRKSFMAK1BFHGCgBZCOWAICgBZqRIGXAGCa9MQBAKCGJRKSFMAK1BGHGCgBZCfWAIqRIGXAGCa9MQBAKCEJRKSFMAK1BEHGCgBZCdWAIqRIGXAGCa9MQBAKCIJRKSFMAK2BIC8cWAIqRIAKCLJRKMABAICGrCBAICFrCFZl9zALCNJAICFZCGWqHI8oGBJHG87FBAIAGjGBABCGJRBAFCaJHFQBMMCBC99AKAE6yRKMAKM/dLEK97FaF97GXGXAGCI9HQBAF9FQFCBRGEXABABDBBBHECiD+rFCiD+sFD/6FHIAECND+rFCiD+sFD/6FAID/gFAECTD+rFCiD+sFD/6FHLD/gFD/kFD/lFHKCBDtD+2FHOAICUUUU94DtHND9OD9RD/kFHI9DBB/+hDYAIAID/mFAKAKD/mFALAOALAND9OD9RD/kFHIAID/mFD/kFD/kFD/jFD/nFHLD/mF9DBBX9LDYHOD/kFCgFDtD9OAECUUU94DtD9OD9QAIALD/mFAOD/kFCND+rFCU/+EDtD9OD9QAKALD/mFAOD/kFCTD+rFCUU/8ODtD9OD9QDMBBABCTJRBAGCIJHGAF9JQBSGMMAF9FQBCBRGEXABCTJHVAVDBBBHECBDtHOCUU98D8cFCUU98D8cEHND9OABDBBBHKAEDQILKOSQfbPden8c8d8e8fCggFDtD9OD/6FAKAEDQBFGENVcMTtmYi8ZpyHECTD+sFD/6FHID/gFAECTD+rFCTD+sFD/6FHLD/gFD/kFD/lFHE9DB/+g6DYALAEAOD+2FHOALCUUUU94DtHcD9OD9RD/kFHLALD/mFAEAED/mFAIAOAIAcD9OD9RD/kFHEAED/mFD/kFD/kFD/jFD/nFHID/mF9DBBX9LDYHOD/kFCTD+rFALAID/mFAOD/kFCggEDtD9OD9QHLAEAID/mFAOD/kFCaDbCBDnGCBDnECBDnKCBDnOCBDncCBDnMCBDnfCBDnbD9OHEDQNVi8ZcMpySQ8c8dfb8e8fD9QDMBBABAKAND9OALAEDQBFTtGEmYILPdKOenD9QDMBBABCAJRBAGCIJHGAF9JQBMMM/hEIGaF97FaL978jUUUUBCTlREGXAF9FQBCBRIEXAEABDBBBHLABCTJHKDBBBHODQILKOSQfbPden8c8d8e8fHNCTD+sFHVCID+rFDMIBAB9DBBU8/DY9D/zI818/DYAVCEDtD9QD/6FD/nFHVALAODQBFGENVcMTtmYi8ZpyHLCTD+rFCTD+sFD/6FD/mFHOAOD/mFAVALCTD+sFD/6FD/mFHcAcD/mFAVANCTD+rFCTD+sFD/6FD/mFHNAND/mFD/kFD/kFD/lFCBDtD+4FD/jF9DB/+g6DYHVD/mF9DBBX9LDYHLD/kFCggEDtHMD9OAcAVD/mFALD/kFCTD+rFD9QHcANAVD/mFALD/kFCTD+rFAOAVD/mFALD/kFAMD9OD9QHVDQBFTtGEmYILPdKOenHLD8dBAEDBIBDyB+t+J83EBABCNJALD8dFAEDBIBDyF+t+J83EBAKAcAVDQNVi8ZcMpySQ8c8dfb8e8fHVD8dBAEDBIBDyG+t+J83EBABCiJAVD8dFAEDBIBDyE+t+J83EBABCAJRBAICIJHIAF9JQBMMM9jFF97GXAGCGrAF9sHG9FQBCBRFEXABABDBBBHECND+rFCND+sFD/6FAECiD+sFCnD+rFCUUU/8EDtD+uFD/mFDMBBABCTJRBAFCIJHFAG9JQBMMM9TFEaCBCB8oGUkUUBHFABCEJC98ZJHBjGUkUUBGXGXAB8/BCTWHGuQBCaREABAGlCggEJCTrXBCa6QFMAFREMAEMMMFBCUNMIT9tBB";
  55752. // Uses bulk-memory and simd extensions
  55753. var detector = new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 3, 2, 0, 0, 5, 3, 1, 0, 1, 12, 1, 0, 10, 22, 2, 12, 0, 65, 0, 65, 0, 65, 0, 252, 10, 0, 0, 11, 7, 0, 65, 0, 253, 15, 26, 11]);
  55754. // Used to unpack wasm
  55755. var wasmpack = new Uint8Array([32, 0, 65, 253, 3, 1, 2, 34, 4, 106, 6, 5, 11, 8, 7, 20, 13, 33, 12, 16, 128, 9, 116, 64, 19, 113, 127, 15, 10, 21, 22, 14, 255, 66, 24, 54, 136, 107, 18, 23, 192, 26, 114, 118, 132, 17, 77, 101, 130, 144, 27, 87, 131, 44, 45, 74, 156, 154, 70, 167]);
  55756. if (typeof WebAssembly !== 'object') {
  55757. // This module requires WebAssembly to function
  55758. return {
  55759. supported: false
  55760. };
  55761. }
  55762. var wasm = wasm_base;
  55763. if (WebAssembly.validate(detector)) {
  55764. wasm = wasm_simd;
  55765. console.log("Warning: meshopt_decoder is using experimental SIMD support");
  55766. }
  55767. var instance;
  55768. var promise = WebAssembly.instantiate(unpack(wasm), {}).then(function (result) {
  55769. instance = result.instance;
  55770. instance.exports.__wasm_call_ctors();
  55771. });
  55772. function unpack(data) {
  55773. var result = new Uint8Array(data.length);
  55774. for (var i = 0; i < data.length; ++i) {
  55775. var ch = data.charCodeAt(i);
  55776. result[i] = ch > 96 ? ch - 71 : ch > 64 ? ch - 65 : ch > 47 ? ch + 4 : ch > 46 ? 63 : 62;
  55777. }
  55778. var write = 0;
  55779. for (var i = 0; i < data.length; ++i) {
  55780. result[write++] = result[i] < 60 ? wasmpack[result[i]] : (result[i] - 60) * 64 + result[++i];
  55781. }
  55782. return result.buffer.slice(0, write);
  55783. }
  55784. function decode(fun, target, count, size, source, filter) {
  55785. var sbrk = instance.exports.sbrk;
  55786. var count4 = count + 3 & ~3; // pad for SIMD filter
  55787. var tp = sbrk(count4 * size);
  55788. var sp = sbrk(source.length);
  55789. var heap = new Uint8Array(instance.exports.memory.buffer);
  55790. heap.set(source, sp);
  55791. var res = fun(tp, count, size, sp, source.length);
  55792. if (res == 0 && filter) {
  55793. filter(tp, count4, size);
  55794. }
  55795. target.set(heap.subarray(tp, tp + count * size));
  55796. sbrk(tp - sbrk(0));
  55797. if (res != 0) {
  55798. throw new Error("Malformed buffer data: " + res);
  55799. }
  55800. }
  55801. ;
  55802. var filters = {
  55803. // legacy index-based enums for glTF
  55804. 0: "",
  55805. 1: "meshopt_decodeFilterOct",
  55806. 2: "meshopt_decodeFilterQuat",
  55807. 3: "meshopt_decodeFilterExp",
  55808. // string-based enums for glTF
  55809. NONE: "",
  55810. OCTAHEDRAL: "meshopt_decodeFilterOct",
  55811. QUATERNION: "meshopt_decodeFilterQuat",
  55812. EXPONENTIAL: "meshopt_decodeFilterExp"
  55813. };
  55814. var decoders = {
  55815. // legacy index-based enums for glTF
  55816. 0: "meshopt_decodeVertexBuffer",
  55817. 1: "meshopt_decodeIndexBuffer",
  55818. 2: "meshopt_decodeIndexSequence",
  55819. // string-based enums for glTF
  55820. ATTRIBUTES: "meshopt_decodeVertexBuffer",
  55821. TRIANGLES: "meshopt_decodeIndexBuffer",
  55822. INDICES: "meshopt_decodeIndexSequence"
  55823. };
  55824. return {
  55825. ready: promise,
  55826. supported: true,
  55827. decodeVertexBuffer: function decodeVertexBuffer(target, count, size, source, filter) {
  55828. decode(instance.exports.meshopt_decodeVertexBuffer, target, count, size, source, instance.exports[filters[filter]]);
  55829. },
  55830. decodeIndexBuffer: function decodeIndexBuffer(target, count, size, source) {
  55831. decode(instance.exports.meshopt_decodeIndexBuffer, target, count, size, source);
  55832. },
  55833. decodeIndexSequence: function decodeIndexSequence(target, count, size, source) {
  55834. decode(instance.exports.meshopt_decodeIndexSequence, target, count, size, source);
  55835. },
  55836. decodeGltfBuffer: function decodeGltfBuffer(target, count, size, source, mode, filter) {
  55837. decode(instance.exports[decoders[mode]], target, count, size, source, instance.exports[filters[filter]]);
  55838. }
  55839. };
  55840. }();
  55841. var DDSLoader = function DDSLoader(manager) {
  55842. CompressedTextureLoader.call(this, manager);
  55843. };
  55844. DDSLoader.prototype = Object.assign(Object.create(CompressedTextureLoader.prototype), {
  55845. constructor: DDSLoader,
  55846. parse: function parse(buffer, loadMipmaps) {
  55847. var dds = {
  55848. mipmaps: [],
  55849. width: 0,
  55850. height: 0,
  55851. format: null,
  55852. mipmapCount: 1
  55853. };
  55854. // Adapted from @toji's DDS utils
  55855. // https://github.com/toji/webgl-texture-utils/blob/master/texture-util/dds.js
  55856. // All values and structures referenced from:
  55857. // http://msdn.microsoft.com/en-us/library/bb943991.aspx/
  55858. var DDS_MAGIC = 0x20534444;
  55859. // var DDSD_CAPS = 0x1;
  55860. // var DDSD_HEIGHT = 0x2;
  55861. // var DDSD_WIDTH = 0x4;
  55862. // var DDSD_PITCH = 0x8;
  55863. // var DDSD_PIXELFORMAT = 0x1000;
  55864. var DDSD_MIPMAPCOUNT = 0x20000;
  55865. // var DDSD_LINEARSIZE = 0x80000;
  55866. // var DDSD_DEPTH = 0x800000;
  55867. // var DDSCAPS_COMPLEX = 0x8;
  55868. // var DDSCAPS_MIPMAP = 0x400000;
  55869. // var DDSCAPS_TEXTURE = 0x1000;
  55870. var DDSCAPS2_CUBEMAP = 0x200;
  55871. var DDSCAPS2_CUBEMAP_POSITIVEX = 0x400;
  55872. var DDSCAPS2_CUBEMAP_NEGATIVEX = 0x800;
  55873. var DDSCAPS2_CUBEMAP_POSITIVEY = 0x1000;
  55874. var DDSCAPS2_CUBEMAP_NEGATIVEY = 0x2000;
  55875. var DDSCAPS2_CUBEMAP_POSITIVEZ = 0x4000;
  55876. var DDSCAPS2_CUBEMAP_NEGATIVEZ = 0x8000;
  55877. // var DDSCAPS2_VOLUME = 0x200000;
  55878. // var DDPF_ALPHAPIXELS = 0x1;
  55879. // var DDPF_ALPHA = 0x2;
  55880. var DDPF_FOURCC = 0x4;
  55881. // var DDPF_RGB = 0x40;
  55882. // var DDPF_YUV = 0x200;
  55883. // var DDPF_LUMINANCE = 0x20000;
  55884. function fourCCToInt32(value) {
  55885. return value.charCodeAt(0) + (value.charCodeAt(1) << 8) + (value.charCodeAt(2) << 16) + (value.charCodeAt(3) << 24);
  55886. }
  55887. function int32ToFourCC(value) {
  55888. return String.fromCharCode(value & 0xff, value >> 8 & 0xff, value >> 16 & 0xff, value >> 24 & 0xff);
  55889. }
  55890. function loadARGBMip(buffer, dataOffset, width, height) {
  55891. var dataLength = width * height * 4;
  55892. var srcBuffer = new Uint8Array(buffer, dataOffset, dataLength);
  55893. var byteArray = new Uint8Array(dataLength);
  55894. var dst = 0;
  55895. var src = 0;
  55896. for (var y = 0; y < height; y++) {
  55897. for (var x = 0; x < width; x++) {
  55898. var b = srcBuffer[src];
  55899. src++;
  55900. var g = srcBuffer[src];
  55901. src++;
  55902. var r = srcBuffer[src];
  55903. src++;
  55904. var a = srcBuffer[src];
  55905. src++;
  55906. byteArray[dst] = r;
  55907. dst++; //r
  55908. byteArray[dst] = g;
  55909. dst++; //g
  55910. byteArray[dst] = b;
  55911. dst++; //b
  55912. byteArray[dst] = a;
  55913. dst++; //a
  55914. }
  55915. }
  55916. return byteArray;
  55917. }
  55918. var FOURCC_DXT1 = fourCCToInt32('DXT1');
  55919. var FOURCC_DXT3 = fourCCToInt32('DXT3');
  55920. var FOURCC_DXT5 = fourCCToInt32('DXT5');
  55921. var FOURCC_ETC1 = fourCCToInt32('ETC1');
  55922. var headerLengthInt = 31; // The header length in 32 bit ints
  55923. // Offsets into the header array
  55924. var off_magic = 0;
  55925. var off_size = 1;
  55926. var off_flags = 2;
  55927. var off_height = 3;
  55928. var off_width = 4;
  55929. var off_mipmapCount = 7;
  55930. var off_pfFlags = 20;
  55931. var off_pfFourCC = 21;
  55932. var off_RGBBitCount = 22;
  55933. var off_RBitMask = 23;
  55934. var off_GBitMask = 24;
  55935. var off_BBitMask = 25;
  55936. var off_ABitMask = 26;
  55937. // var off_caps = 27;
  55938. var off_caps2 = 28;
  55939. // var off_caps3 = 29;
  55940. // var off_caps4 = 30;
  55941. // Parse header
  55942. var header = new Int32Array(buffer, 0, headerLengthInt);
  55943. if (header[off_magic] !== DDS_MAGIC) {
  55944. console.error('THREE.DDSLoader.parse: Invalid magic number in DDS header.');
  55945. return dds;
  55946. }
  55947. if (!header[off_pfFlags] & DDPF_FOURCC) {
  55948. console.error('THREE.DDSLoader.parse: Unsupported format, must contain a FourCC code.');
  55949. return dds;
  55950. }
  55951. var blockBytes;
  55952. var fourCC = header[off_pfFourCC];
  55953. var isRGBAUncompressed = false;
  55954. switch (fourCC) {
  55955. case FOURCC_DXT1:
  55956. blockBytes = 8;
  55957. dds.format = RGB_S3TC_DXT1_Format;
  55958. break;
  55959. case FOURCC_DXT3:
  55960. blockBytes = 16;
  55961. dds.format = RGBA_S3TC_DXT3_Format;
  55962. break;
  55963. case FOURCC_DXT5:
  55964. blockBytes = 16;
  55965. dds.format = RGBA_S3TC_DXT5_Format$1;
  55966. break;
  55967. case FOURCC_ETC1:
  55968. blockBytes = 8;
  55969. dds.format = RGB_ETC1_Format;
  55970. break;
  55971. default:
  55972. if (header[off_RGBBitCount] === 32 && header[off_RBitMask] & 0xff0000 && header[off_GBitMask] & 0xff00 && header[off_BBitMask] & 0xff && header[off_ABitMask] & 0xff000000) {
  55973. isRGBAUncompressed = true;
  55974. blockBytes = 64;
  55975. dds.format = RGBAFormat;
  55976. } else {
  55977. console.error('THREE.DDSLoader.parse: Unsupported FourCC code ', int32ToFourCC(fourCC));
  55978. return dds;
  55979. }
  55980. }
  55981. dds.mipmapCount = 1;
  55982. if (header[off_flags] & DDSD_MIPMAPCOUNT && loadMipmaps !== false) {
  55983. dds.mipmapCount = Math.max(1, header[off_mipmapCount]);
  55984. }
  55985. var caps2 = header[off_caps2];
  55986. dds.isCubemap = caps2 & DDSCAPS2_CUBEMAP ? true : false;
  55987. if (dds.isCubemap && (!(caps2 & DDSCAPS2_CUBEMAP_POSITIVEX) || !(caps2 & DDSCAPS2_CUBEMAP_NEGATIVEX) || !(caps2 & DDSCAPS2_CUBEMAP_POSITIVEY) || !(caps2 & DDSCAPS2_CUBEMAP_NEGATIVEY) || !(caps2 & DDSCAPS2_CUBEMAP_POSITIVEZ) || !(caps2 & DDSCAPS2_CUBEMAP_NEGATIVEZ))) {
  55988. console.error('THREE.DDSLoader.parse: Incomplete cubemap faces');
  55989. return dds;
  55990. }
  55991. dds.width = header[off_width];
  55992. dds.height = header[off_height];
  55993. var dataOffset = header[off_size] + 4;
  55994. // Extract mipmaps buffers
  55995. var faces = dds.isCubemap ? 6 : 1;
  55996. for (var face = 0; face < faces; face++) {
  55997. var width = dds.width;
  55998. var height = dds.height;
  55999. for (var i = 0; i < dds.mipmapCount; i++) {
  56000. if (isRGBAUncompressed) {
  56001. var byteArray = loadARGBMip(buffer, dataOffset, width, height);
  56002. var dataLength = byteArray.length;
  56003. } else {
  56004. var dataLength = Math.max(4, width) / 4 * Math.max(4, height) / 4 * blockBytes;
  56005. var byteArray = new Uint8Array(buffer, dataOffset, dataLength);
  56006. }
  56007. var mipmap = {
  56008. 'data': byteArray,
  56009. 'width': width,
  56010. 'height': height
  56011. };
  56012. dds.mipmaps.push(mipmap);
  56013. dataOffset += dataLength;
  56014. width = Math.max(width >> 1, 1);
  56015. height = Math.max(height >> 1, 1);
  56016. }
  56017. }
  56018. return dds;
  56019. }
  56020. });
  56021. //2022.11.11 copyfrom : https://unpkg.com/three@0.146.0/examples/jsm/loaders/GLTFLoader.js
  56022. //xzw add:----
  56023. var unknownExtensions = {};
  56024. var oldSet = MeshBasicMaterial.prototype.setValues;
  56025. MeshBasicMaterial.prototype.setValues = function (values) {
  56026. return oldSet.call(this, values);
  56027. };
  56028. class GLTFLoader extends Loader {
  56029. constructor(manager, renderer, urlPrefix) {
  56030. super(manager);
  56031. //xzw add:
  56032. this.dracoLoader = new DRACOLoader();
  56033. this.ktx2Loader = new KTX2Loader();
  56034. this.meshoptDecoder = MeshoptDecoder;
  56035. this.ddsLoader = new DDSLoader(); //这个没测过
  56036. //路径相对于index.html
  56037. this.dracoLoader.setDecoderPath(urlPrefix + 'three.js/loaders/draco/' /*or 'https://unpkg.com/three@0.144.0/examples/js/libs/draco/gltf/' 版本可升级 */); //这两个路径可以自己改。在laser的环境也要放一份这个路径
  56038. this.ktx2Loader.setTranscoderPath(urlPrefix + 'three.js/loaders/basis/' /*or 'https://unpkg.com/three@0.144.0/examples/js/libs/basis/' 版本可升级 */).detectSupport(renderer);
  56039. this.pluginCallbacks = [];
  56040. this.register(function (parser) {
  56041. return new GLTFMaterialsClearcoatExtension(parser);
  56042. });
  56043. this.register(function (parser) {
  56044. return new GLTFTextureBasisUExtension(parser);
  56045. });
  56046. this.register(function (parser) {
  56047. return new GLTFTextureWebPExtension(parser);
  56048. });
  56049. this.register(function (parser) {
  56050. return new GLTFMaterialsSheenExtension(parser);
  56051. });
  56052. this.register(function (parser) {
  56053. return new GLTFMaterialsTransmissionExtension(parser);
  56054. });
  56055. this.register(function (parser) {
  56056. return new GLTFMaterialsVolumeExtension(parser);
  56057. });
  56058. this.register(function (parser) {
  56059. return new GLTFMaterialsIorExtension(parser);
  56060. });
  56061. this.register(function (parser) {
  56062. return new GLTFMaterialsEmissiveStrengthExtension(parser);
  56063. });
  56064. this.register(function (parser) {
  56065. return new GLTFMaterialsSpecularExtension(parser);
  56066. });
  56067. this.register(function (parser) {
  56068. return new GLTFMaterialsIridescenceExtension(parser);
  56069. });
  56070. this.register(function (parser) {
  56071. return new GLTFLightsExtension(parser);
  56072. });
  56073. this.register(function (parser) {
  56074. return new GLTFMeshoptCompression(parser);
  56075. });
  56076. this.register(function (parser) {
  56077. return new GLTFMeshGpuInstancing(parser);
  56078. });
  56079. }
  56080. load(url, onLoad, onProgress, onError) {
  56081. var scope = this;
  56082. var resourcePath;
  56083. if (this.resourcePath !== '') {
  56084. resourcePath = this.resourcePath;
  56085. } else if (this.path !== '') {
  56086. resourcePath = this.path;
  56087. } else {
  56088. resourcePath = LoaderUtils.extractUrlBase(url);
  56089. }
  56090. // Tells the LoadingManager to track an extra item, which resolves after
  56091. // the model is fully loaded. This means the count of items loaded will
  56092. // be incorrect, but ensures manager.onLoad() does not fire early.
  56093. this.manager.itemStart(url);
  56094. var _onError = function _onError(e) {
  56095. if (onError) {
  56096. onError(e);
  56097. } else {
  56098. console.error(e);
  56099. }
  56100. scope.manager.itemError(url);
  56101. scope.manager.itemEnd(url);
  56102. };
  56103. var loader = new FileLoader(this.manager);
  56104. loader.setPath(this.path);
  56105. loader.setResponseType('arraybuffer');
  56106. loader.setRequestHeader(this.requestHeader);
  56107. loader.setWithCredentials(this.withCredentials);
  56108. loader.load(url, function (data) {
  56109. try {
  56110. scope.parse(data, resourcePath, function (gltf) {
  56111. onLoad(gltf);
  56112. scope.manager.itemEnd(url);
  56113. }, _onError);
  56114. } catch (e) {
  56115. _onError(e);
  56116. }
  56117. }, onProgress, _onError);
  56118. }
  56119. setDRACOLoader(dracoLoader) {
  56120. this.dracoLoader = dracoLoader;
  56121. return this;
  56122. }
  56123. setDDSLoader() {
  56124. throw new Error('THREE.GLTFLoader: "MSFT_texture_dds" no longer supported. Please update to "KHR_texture_basisu".');
  56125. }
  56126. setKTX2Loader(ktx2Loader) {
  56127. this.ktx2Loader = ktx2Loader;
  56128. return this;
  56129. }
  56130. setMeshoptDecoder(meshoptDecoder) {
  56131. this.meshoptDecoder = meshoptDecoder;
  56132. return this;
  56133. }
  56134. register(callback) {
  56135. if (this.pluginCallbacks.indexOf(callback) === -1) {
  56136. this.pluginCallbacks.push(callback);
  56137. }
  56138. return this;
  56139. }
  56140. unregister(callback) {
  56141. if (this.pluginCallbacks.indexOf(callback) !== -1) {
  56142. this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(callback), 1);
  56143. }
  56144. return this;
  56145. }
  56146. parse(data, path, onLoad, onError) {
  56147. var json;
  56148. var extensions = {};
  56149. var plugins = {};
  56150. if (typeof data === 'string') {
  56151. json = JSON.parse(data);
  56152. } else if (data instanceof ArrayBuffer) {
  56153. var magic = LoaderUtils.decodeText(new Uint8Array(data, 0, 4));
  56154. if (magic === BINARY_EXTENSION_HEADER_MAGIC) {
  56155. try {
  56156. extensions[EXTENSIONS.KHR_BINARY_GLTF] = new GLTFBinaryExtension(data);
  56157. } catch (error) {
  56158. if (onError) onError(error);
  56159. return;
  56160. }
  56161. json = JSON.parse(extensions[EXTENSIONS.KHR_BINARY_GLTF].content);
  56162. } else {
  56163. json = JSON.parse(LoaderUtils.decodeText(new Uint8Array(data)));
  56164. }
  56165. } else {
  56166. json = data;
  56167. }
  56168. if (json.asset === undefined || json.asset.version[0] < 2) {
  56169. if (onError) onError(new Error('THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.'));
  56170. return;
  56171. }
  56172. var parser = new GLTFParser(json, {
  56173. path: path || this.resourcePath || '',
  56174. crossOrigin: this.crossOrigin,
  56175. requestHeader: this.requestHeader,
  56176. manager: this.manager,
  56177. ktx2Loader: this.ktx2Loader,
  56178. meshoptDecoder: this.meshoptDecoder
  56179. });
  56180. parser.fileLoader.setRequestHeader(this.requestHeader);
  56181. for (var i = 0; i < this.pluginCallbacks.length; i++) {
  56182. var plugin = this.pluginCallbacks[i](parser);
  56183. plugins[plugin.name] = plugin;
  56184. // Workaround to avoid determining as unknown extension
  56185. // in addUnknownExtensionsToUserData().
  56186. // Remove this workaround if we move all the existing
  56187. // extension handlers to plugin system
  56188. extensions[plugin.name] = true;
  56189. }
  56190. if (json.extensionsUsed) {
  56191. for (var _i = 0; _i < json.extensionsUsed.length; ++_i) {
  56192. var extensionName = json.extensionsUsed[_i];
  56193. var extensionsRequired = json.extensionsRequired || [];
  56194. switch (extensionName) {
  56195. case EXTENSIONS.KHR_MATERIALS_UNLIT:
  56196. extensions[extensionName] = new GLTFMaterialsUnlitExtension();
  56197. break;
  56198. case EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS:
  56199. extensions[extensionName] = new GLTFMaterialsPbrSpecularGlossinessExtension();
  56200. break;
  56201. case EXTENSIONS.KHR_DRACO_MESH_COMPRESSION:
  56202. extensions[extensionName] = new GLTFDracoMeshCompressionExtension(json, this.dracoLoader);
  56203. break;
  56204. case EXTENSIONS.KHR_TEXTURE_TRANSFORM:
  56205. extensions[extensionName] = new GLTFTextureTransformExtension();
  56206. break;
  56207. case EXTENSIONS.KHR_MESH_QUANTIZATION:
  56208. extensions[extensionName] = new GLTFMeshQuantizationExtension();
  56209. break;
  56210. default:
  56211. if (extensionsRequired.indexOf(extensionName) >= 0 && plugins[extensionName] === undefined) {
  56212. if (!unknownExtensions[extensionName]) {
  56213. console.warn('GLTFLoader: Unknown extension "' + extensionName + '".', '使用默认的KHR_materials_unlit材质');
  56214. unknownExtensions[extensionName] = 1;
  56215. }
  56216. //xzw add: 默认
  56217. json.extensionsRequired = 'KHR_materials_unlit';
  56218. json.materials = [{
  56219. extensions: {
  56220. KHR_materials_unlit: {}
  56221. },
  56222. pbrMetallicRoughness: {
  56223. baseColorFactor: [1, 1, 1, 1],
  56224. baseColorTexture: {
  56225. index: 0,
  56226. texCoord: 0
  56227. },
  56228. metallicFactor: 0,
  56229. roughnessFactor: 0.5
  56230. }
  56231. }];
  56232. extensions[json.extensionsRequired] = new GLTFMaterialsUnlitExtension();
  56233. }
  56234. /*
  56235. 如原先:
  56236. json.materials = KHR_techniques_webgl:{
  56237. technique: 0,
  56238. values:{u_diffuse:{index: 0,texCoord: 0}}
  56239. }
  56240. */
  56241. }
  56242. }
  56243. }
  56244. parser.setExtensions(extensions);
  56245. parser.setPlugins(plugins);
  56246. parser.parse(onLoad, onError);
  56247. }
  56248. parseAsync(data, path) {
  56249. var scope = this;
  56250. return new Promise(function (resolve, reject) {
  56251. scope.parse(data, path, resolve, reject);
  56252. });
  56253. }
  56254. }
  56255. /* GLTFREGISTRY */
  56256. function GLTFRegistry() {
  56257. var objects = {};
  56258. return {
  56259. get: function get(key) {
  56260. return objects[key];
  56261. },
  56262. add: function add(key, object) {
  56263. objects[key] = object;
  56264. },
  56265. remove: function remove(key) {
  56266. delete objects[key];
  56267. },
  56268. removeAll: function removeAll() {
  56269. objects = {};
  56270. }
  56271. };
  56272. }
  56273. /*********************************/
  56274. /********** EXTENSIONS ***********/
  56275. /*********************************/
  56276. var EXTENSIONS = {
  56277. KHR_BINARY_GLTF: 'KHR_binary_glTF',
  56278. KHR_DRACO_MESH_COMPRESSION: 'KHR_draco_mesh_compression',
  56279. KHR_LIGHTS_PUNCTUAL: 'KHR_lights_punctual',
  56280. KHR_MATERIALS_CLEARCOAT: 'KHR_materials_clearcoat',
  56281. KHR_MATERIALS_IOR: 'KHR_materials_ior',
  56282. KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS: 'KHR_materials_pbrSpecularGlossiness',
  56283. KHR_MATERIALS_SHEEN: 'KHR_materials_sheen',
  56284. KHR_MATERIALS_SPECULAR: 'KHR_materials_specular',
  56285. KHR_MATERIALS_TRANSMISSION: 'KHR_materials_transmission',
  56286. KHR_MATERIALS_IRIDESCENCE: 'KHR_materials_iridescence',
  56287. KHR_MATERIALS_UNLIT: 'KHR_materials_unlit',
  56288. KHR_MATERIALS_VOLUME: 'KHR_materials_volume',
  56289. KHR_TEXTURE_BASISU: 'KHR_texture_basisu',
  56290. KHR_TEXTURE_TRANSFORM: 'KHR_texture_transform',
  56291. KHR_MESH_QUANTIZATION: 'KHR_mesh_quantization',
  56292. KHR_MATERIALS_EMISSIVE_STRENGTH: 'KHR_materials_emissive_strength',
  56293. EXT_TEXTURE_WEBP: 'EXT_texture_webp',
  56294. EXT_MESHOPT_COMPRESSION: 'EXT_meshopt_compression',
  56295. EXT_MESH_GPU_INSTANCING: 'EXT_mesh_gpu_instancing'
  56296. };
  56297. /**
  56298. * Punctual Lights Extension
  56299. *
  56300. * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual
  56301. */
  56302. class GLTFLightsExtension {
  56303. constructor(parser) {
  56304. this.parser = parser;
  56305. this.name = EXTENSIONS.KHR_LIGHTS_PUNCTUAL;
  56306. // Object3D instance caches
  56307. this.cache = {
  56308. refs: {},
  56309. uses: {}
  56310. };
  56311. }
  56312. _markDefs() {
  56313. var parser = this.parser;
  56314. var nodeDefs = this.parser.json.nodes || [];
  56315. for (var nodeIndex = 0, nodeLength = nodeDefs.length; nodeIndex < nodeLength; nodeIndex++) {
  56316. var nodeDef = nodeDefs[nodeIndex];
  56317. if (nodeDef.extensions && nodeDef.extensions[this.name] && nodeDef.extensions[this.name].light !== undefined) {
  56318. parser._addNodeRef(this.cache, nodeDef.extensions[this.name].light);
  56319. }
  56320. }
  56321. }
  56322. _loadLight(lightIndex) {
  56323. var parser = this.parser;
  56324. var cacheKey = 'light:' + lightIndex;
  56325. var dependency = parser.cache.get(cacheKey);
  56326. if (dependency) return dependency;
  56327. var json = parser.json;
  56328. var extensions = json.extensions && json.extensions[this.name] || {};
  56329. var lightDefs = extensions.lights || [];
  56330. var lightDef = lightDefs[lightIndex];
  56331. var lightNode;
  56332. var color = new Color(0xffffff);
  56333. if (lightDef.color !== undefined) color.fromArray(lightDef.color);
  56334. var range = lightDef.range !== undefined ? lightDef.range : 0;
  56335. switch (lightDef.type) {
  56336. case 'directional':
  56337. lightNode = new DirectionalLight(color);
  56338. lightNode.target.position.set(0, 0, -1);
  56339. lightNode.add(lightNode.target);
  56340. break;
  56341. case 'point':
  56342. lightNode = new PointLight(color);
  56343. lightNode.distance = range;
  56344. break;
  56345. case 'spot':
  56346. lightNode = new SpotLight(color);
  56347. lightNode.distance = range;
  56348. // Handle spotlight properties.
  56349. lightDef.spot = lightDef.spot || {};
  56350. lightDef.spot.innerConeAngle = lightDef.spot.innerConeAngle !== undefined ? lightDef.spot.innerConeAngle : 0;
  56351. lightDef.spot.outerConeAngle = lightDef.spot.outerConeAngle !== undefined ? lightDef.spot.outerConeAngle : Math.PI / 4.0;
  56352. lightNode.angle = lightDef.spot.outerConeAngle;
  56353. lightNode.penumbra = 1.0 - lightDef.spot.innerConeAngle / lightDef.spot.outerConeAngle;
  56354. lightNode.target.position.set(0, 0, -1);
  56355. lightNode.add(lightNode.target);
  56356. break;
  56357. default:
  56358. throw new Error('THREE.GLTFLoader: Unexpected light type: ' + lightDef.type);
  56359. }
  56360. // Some lights (e.g. spot) default to a position other than the origin. Reset the position
  56361. // here, because node-level parsing will only override position if explicitly specified.
  56362. lightNode.position.set(0, 0, 0);
  56363. lightNode.decay = 2;
  56364. if (lightDef.intensity !== undefined) lightNode.intensity = lightDef.intensity;
  56365. lightNode.name = parser.createUniqueName(lightDef.name || 'light_' + lightIndex);
  56366. dependency = Promise.resolve(lightNode);
  56367. parser.cache.add(cacheKey, dependency);
  56368. return dependency;
  56369. }
  56370. createNodeAttachment(nodeIndex) {
  56371. var self = this;
  56372. var parser = this.parser;
  56373. var json = parser.json;
  56374. var nodeDef = json.nodes[nodeIndex];
  56375. var lightDef = nodeDef.extensions && nodeDef.extensions[this.name] || {};
  56376. var lightIndex = lightDef.light;
  56377. if (lightIndex === undefined) return null;
  56378. return this._loadLight(lightIndex).then(function (light) {
  56379. return parser._getNodeRef(self.cache, lightIndex, light);
  56380. });
  56381. }
  56382. }
  56383. /**
  56384. * Unlit Materials Extension
  56385. *
  56386. * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit
  56387. */
  56388. class GLTFMaterialsUnlitExtension {
  56389. constructor() {
  56390. this.name = EXTENSIONS.KHR_MATERIALS_UNLIT;
  56391. }
  56392. getMaterialType() {
  56393. return MeshBasicMaterial;
  56394. }
  56395. extendParams(materialParams, materialDef, parser) {
  56396. var pending = [];
  56397. materialParams.color = new Color(1.0, 1.0, 1.0);
  56398. materialParams.opacity = 1.0;
  56399. var metallicRoughness = materialDef.pbrMetallicRoughness;
  56400. if (metallicRoughness) {
  56401. if (Array.isArray(metallicRoughness.baseColorFactor)) {
  56402. var array = metallicRoughness.baseColorFactor;
  56403. materialParams.color.fromArray(array);
  56404. materialParams.opacity = array[3];
  56405. }
  56406. if (metallicRoughness.baseColorTexture !== undefined) {
  56407. pending.push(parser.assignTexture(materialParams, 'map', metallicRoughness.baseColorTexture, sRGBEncoding));
  56408. }
  56409. }
  56410. return Promise.all(pending);
  56411. }
  56412. }
  56413. /**
  56414. * Materials Emissive Strength Extension
  56415. *
  56416. * Specification: https://github.com/KhronosGroup/glTF/blob/5768b3ce0ef32bc39cdf1bef10b948586635ead3/extensions/2.0/Khronos/KHR_materials_emissive_strength/README.md
  56417. */
  56418. class GLTFMaterialsEmissiveStrengthExtension {
  56419. constructor(parser) {
  56420. this.parser = parser;
  56421. this.name = EXTENSIONS.KHR_MATERIALS_EMISSIVE_STRENGTH;
  56422. }
  56423. extendMaterialParams(materialIndex, materialParams) {
  56424. var parser = this.parser;
  56425. var materialDef = parser.json.materials[materialIndex] || parser.json.materials; //xzw change
  56426. if (!materialDef.extensions || !materialDef.extensions[this.name]) {
  56427. return Promise.resolve();
  56428. }
  56429. var emissiveStrength = materialDef.extensions[this.name].emissiveStrength;
  56430. if (emissiveStrength !== undefined) {
  56431. materialParams.emissiveIntensity = emissiveStrength;
  56432. }
  56433. return Promise.resolve();
  56434. }
  56435. }
  56436. /**
  56437. * Clearcoat Materials Extension
  56438. *
  56439. * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_clearcoat
  56440. */
  56441. class GLTFMaterialsClearcoatExtension {
  56442. constructor(parser) {
  56443. this.parser = parser;
  56444. this.name = EXTENSIONS.KHR_MATERIALS_CLEARCOAT;
  56445. }
  56446. getMaterialType(materialIndex) {
  56447. var parser = this.parser;
  56448. var materialDef = parser.json.materials[materialIndex] || parser.json.materials;
  56449. if (!materialDef.extensions || !materialDef.extensions[this.name]) return null;
  56450. return MeshPhysicalMaterial;
  56451. }
  56452. extendMaterialParams(materialIndex, materialParams) {
  56453. var parser = this.parser;
  56454. var materialDef = parser.json.materials[materialIndex]; //曾因这里报错加了一句 || parser.json.materials; 但是加载的图会先变白
  56455. if (!materialDef.extensions || !materialDef.extensions[this.name]) {
  56456. return Promise.resolve();
  56457. }
  56458. var pending = [];
  56459. var extension = materialDef.extensions[this.name];
  56460. if (extension.clearcoatFactor !== undefined) {
  56461. materialParams.clearcoat = extension.clearcoatFactor;
  56462. }
  56463. if (extension.clearcoatTexture !== undefined) {
  56464. pending.push(parser.assignTexture(materialParams, 'clearcoatMap', extension.clearcoatTexture));
  56465. }
  56466. if (extension.clearcoatRoughnessFactor !== undefined) {
  56467. materialParams.clearcoatRoughness = extension.clearcoatRoughnessFactor;
  56468. }
  56469. if (extension.clearcoatRoughnessTexture !== undefined) {
  56470. pending.push(parser.assignTexture(materialParams, 'clearcoatRoughnessMap', extension.clearcoatRoughnessTexture));
  56471. }
  56472. if (extension.clearcoatNormalTexture !== undefined) {
  56473. pending.push(parser.assignTexture(materialParams, 'clearcoatNormalMap', extension.clearcoatNormalTexture));
  56474. if (extension.clearcoatNormalTexture.scale !== undefined) {
  56475. var scale = extension.clearcoatNormalTexture.scale;
  56476. materialParams.clearcoatNormalScale = new Vector2(scale, scale);
  56477. }
  56478. }
  56479. return Promise.all(pending);
  56480. }
  56481. }
  56482. /**
  56483. * Iridescence Materials Extension
  56484. *
  56485. * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_iridescence
  56486. */
  56487. class GLTFMaterialsIridescenceExtension {
  56488. constructor(parser) {
  56489. this.parser = parser;
  56490. this.name = EXTENSIONS.KHR_MATERIALS_IRIDESCENCE;
  56491. }
  56492. getMaterialType(materialIndex) {
  56493. var parser = this.parser;
  56494. var materialDef = parser.json.materials[materialIndex];
  56495. if (!materialDef.extensions || !materialDef.extensions[this.name]) return null;
  56496. return MeshPhysicalMaterial;
  56497. }
  56498. extendMaterialParams(materialIndex, materialParams) {
  56499. var parser = this.parser;
  56500. var materialDef = parser.json.materials[materialIndex];
  56501. if (!materialDef.extensions || !materialDef.extensions[this.name]) {
  56502. return Promise.resolve();
  56503. }
  56504. var pending = [];
  56505. var extension = materialDef.extensions[this.name];
  56506. if (extension.iridescenceFactor !== undefined) {
  56507. materialParams.iridescence = extension.iridescenceFactor;
  56508. }
  56509. if (extension.iridescenceTexture !== undefined) {
  56510. pending.push(parser.assignTexture(materialParams, 'iridescenceMap', extension.iridescenceTexture));
  56511. }
  56512. if (extension.iridescenceIor !== undefined) {
  56513. materialParams.iridescenceIOR = extension.iridescenceIor;
  56514. }
  56515. if (materialParams.iridescenceThicknessRange === undefined) {
  56516. materialParams.iridescenceThicknessRange = [100, 400];
  56517. }
  56518. if (extension.iridescenceThicknessMinimum !== undefined) {
  56519. materialParams.iridescenceThicknessRange[0] = extension.iridescenceThicknessMinimum;
  56520. }
  56521. if (extension.iridescenceThicknessMaximum !== undefined) {
  56522. materialParams.iridescenceThicknessRange[1] = extension.iridescenceThicknessMaximum;
  56523. }
  56524. if (extension.iridescenceThicknessTexture !== undefined) {
  56525. pending.push(parser.assignTexture(materialParams, 'iridescenceThicknessMap', extension.iridescenceThicknessTexture));
  56526. }
  56527. return Promise.all(pending);
  56528. }
  56529. }
  56530. /**
  56531. * Sheen Materials Extension
  56532. *
  56533. * Specification: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_sheen
  56534. */
  56535. class GLTFMaterialsSheenExtension {
  56536. constructor(parser) {
  56537. this.parser = parser;
  56538. this.name = EXTENSIONS.KHR_MATERIALS_SHEEN;
  56539. }
  56540. getMaterialType(materialIndex) {
  56541. var parser = this.parser;
  56542. var materialDef = parser.json.materials[materialIndex];
  56543. if (!materialDef.extensions || !materialDef.extensions[this.name]) return null;
  56544. return MeshPhysicalMaterial;
  56545. }
  56546. extendMaterialParams(materialIndex, materialParams) {
  56547. var parser = this.parser;
  56548. var materialDef = parser.json.materials[materialIndex];
  56549. if (!materialDef.extensions || !materialDef.extensions[this.name]) {
  56550. return Promise.resolve();
  56551. }
  56552. var pending = [];
  56553. materialParams.sheenColor = new Color(0, 0, 0);
  56554. materialParams.sheenRoughness = 0;
  56555. materialParams.sheen = 1;
  56556. var extension = materialDef.extensions[this.name];
  56557. if (extension.sheenColorFactor !== undefined) {
  56558. materialParams.sheenColor.fromArray(extension.sheenColorFactor);
  56559. }
  56560. if (extension.sheenRoughnessFactor !== undefined) {
  56561. materialParams.sheenRoughness = extension.sheenRoughnessFactor;
  56562. }
  56563. if (extension.sheenColorTexture !== undefined) {
  56564. pending.push(parser.assignTexture(materialParams, 'sheenColorMap', extension.sheenColorTexture, sRGBEncoding));
  56565. }
  56566. if (extension.sheenRoughnessTexture !== undefined) {
  56567. pending.push(parser.assignTexture(materialParams, 'sheenRoughnessMap', extension.sheenRoughnessTexture));
  56568. }
  56569. return Promise.all(pending);
  56570. }
  56571. }
  56572. /**
  56573. * Transmission Materials Extension
  56574. *
  56575. * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_transmission
  56576. * Draft: https://github.com/KhronosGroup/glTF/pull/1698
  56577. */
  56578. class GLTFMaterialsTransmissionExtension {
  56579. constructor(parser) {
  56580. this.parser = parser;
  56581. this.name = EXTENSIONS.KHR_MATERIALS_TRANSMISSION;
  56582. }
  56583. getMaterialType(materialIndex) {
  56584. var parser = this.parser;
  56585. var materialDef = parser.json.materials[materialIndex];
  56586. if (!materialDef.extensions || !materialDef.extensions[this.name]) return null;
  56587. return MeshPhysicalMaterial;
  56588. }
  56589. extendMaterialParams(materialIndex, materialParams) {
  56590. var parser = this.parser;
  56591. var materialDef = parser.json.materials[materialIndex];
  56592. if (!materialDef.extensions || !materialDef.extensions[this.name]) {
  56593. return Promise.resolve();
  56594. }
  56595. var pending = [];
  56596. var extension = materialDef.extensions[this.name];
  56597. if (extension.transmissionFactor !== undefined) {
  56598. materialParams.transmission = extension.transmissionFactor;
  56599. }
  56600. if (extension.transmissionTexture !== undefined) {
  56601. pending.push(parser.assignTexture(materialParams, 'transmissionMap', extension.transmissionTexture));
  56602. }
  56603. return Promise.all(pending);
  56604. }
  56605. }
  56606. /**
  56607. * Materials Volume Extension
  56608. *
  56609. * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_volume
  56610. */
  56611. class GLTFMaterialsVolumeExtension {
  56612. constructor(parser) {
  56613. this.parser = parser;
  56614. this.name = EXTENSIONS.KHR_MATERIALS_VOLUME;
  56615. }
  56616. getMaterialType(materialIndex) {
  56617. var parser = this.parser;
  56618. var materialDef = parser.json.materials[materialIndex];
  56619. if (!materialDef.extensions || !materialDef.extensions[this.name]) return null;
  56620. return MeshPhysicalMaterial;
  56621. }
  56622. extendMaterialParams(materialIndex, materialParams) {
  56623. var parser = this.parser;
  56624. var materialDef = parser.json.materials[materialIndex];
  56625. if (!materialDef.extensions || !materialDef.extensions[this.name]) {
  56626. return Promise.resolve();
  56627. }
  56628. var pending = [];
  56629. var extension = materialDef.extensions[this.name];
  56630. materialParams.thickness = extension.thicknessFactor !== undefined ? extension.thicknessFactor : 0;
  56631. if (extension.thicknessTexture !== undefined) {
  56632. pending.push(parser.assignTexture(materialParams, 'thicknessMap', extension.thicknessTexture));
  56633. }
  56634. materialParams.attenuationDistance = extension.attenuationDistance || Infinity;
  56635. var colorArray = extension.attenuationColor || [1, 1, 1];
  56636. materialParams.attenuationColor = new Color(colorArray[0], colorArray[1], colorArray[2]);
  56637. return Promise.all(pending);
  56638. }
  56639. }
  56640. /**
  56641. * Materials ior Extension
  56642. *
  56643. * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_ior
  56644. */
  56645. class GLTFMaterialsIorExtension {
  56646. constructor(parser) {
  56647. this.parser = parser;
  56648. this.name = EXTENSIONS.KHR_MATERIALS_IOR;
  56649. }
  56650. getMaterialType(materialIndex) {
  56651. var parser = this.parser;
  56652. var materialDef = parser.json.materials[materialIndex];
  56653. if (!materialDef.extensions || !materialDef.extensions[this.name]) return null;
  56654. return MeshPhysicalMaterial;
  56655. }
  56656. extendMaterialParams(materialIndex, materialParams) {
  56657. var parser = this.parser;
  56658. var materialDef = parser.json.materials[materialIndex];
  56659. if (!materialDef.extensions || !materialDef.extensions[this.name]) {
  56660. return Promise.resolve();
  56661. }
  56662. var extension = materialDef.extensions[this.name];
  56663. materialParams.ior = extension.ior !== undefined ? extension.ior : 1.5;
  56664. return Promise.resolve();
  56665. }
  56666. }
  56667. /**
  56668. * Materials specular Extension
  56669. *
  56670. * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_specular
  56671. */
  56672. class GLTFMaterialsSpecularExtension {
  56673. constructor(parser) {
  56674. this.parser = parser;
  56675. this.name = EXTENSIONS.KHR_MATERIALS_SPECULAR;
  56676. }
  56677. getMaterialType(materialIndex) {
  56678. var parser = this.parser;
  56679. var materialDef = parser.json.materials[materialIndex];
  56680. if (!materialDef.extensions || !materialDef.extensions[this.name]) return null;
  56681. return MeshPhysicalMaterial;
  56682. }
  56683. extendMaterialParams(materialIndex, materialParams) {
  56684. var parser = this.parser;
  56685. var materialDef = parser.json.materials[materialIndex];
  56686. if (!materialDef.extensions || !materialDef.extensions[this.name]) {
  56687. return Promise.resolve();
  56688. }
  56689. var pending = [];
  56690. var extension = materialDef.extensions[this.name];
  56691. materialParams.specularIntensity = extension.specularFactor !== undefined ? extension.specularFactor : 1.0;
  56692. if (extension.specularTexture !== undefined) {
  56693. pending.push(parser.assignTexture(materialParams, 'specularIntensityMap', extension.specularTexture));
  56694. }
  56695. var colorArray = extension.specularColorFactor || [1, 1, 1];
  56696. materialParams.specularColor = new Color(colorArray[0], colorArray[1], colorArray[2]);
  56697. if (extension.specularColorTexture !== undefined) {
  56698. pending.push(parser.assignTexture(materialParams, 'specularColorMap', extension.specularColorTexture, sRGBEncoding));
  56699. }
  56700. return Promise.all(pending);
  56701. }
  56702. }
  56703. /**
  56704. * BasisU Texture Extension
  56705. *
  56706. * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_texture_basisu
  56707. */
  56708. class GLTFTextureBasisUExtension {
  56709. constructor(parser) {
  56710. this.parser = parser;
  56711. this.name = EXTENSIONS.KHR_TEXTURE_BASISU;
  56712. }
  56713. loadTexture(textureIndex) {
  56714. var parser = this.parser;
  56715. var json = parser.json;
  56716. var textureDef = json.textures[textureIndex];
  56717. if (!textureDef.extensions || !textureDef.extensions[this.name]) {
  56718. return null;
  56719. }
  56720. var extension = textureDef.extensions[this.name];
  56721. var loader = parser.options.ktx2Loader;
  56722. if (!loader) {
  56723. if (json.extensionsRequired && json.extensionsRequired.indexOf(this.name) >= 0) {
  56724. throw new Error('THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures');
  56725. } else {
  56726. // Assumes that the extension is optional and that a fallback texture is present
  56727. return null;
  56728. }
  56729. }
  56730. return parser.loadTextureImage(textureIndex, extension.source, loader);
  56731. }
  56732. }
  56733. /**
  56734. * WebP Texture Extension
  56735. *
  56736. * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_texture_webp
  56737. */
  56738. class GLTFTextureWebPExtension {
  56739. constructor(parser) {
  56740. this.parser = parser;
  56741. this.name = EXTENSIONS.EXT_TEXTURE_WEBP;
  56742. this.isSupported = null;
  56743. }
  56744. loadTexture(textureIndex) {
  56745. var name = this.name;
  56746. var parser = this.parser;
  56747. var json = parser.json;
  56748. var textureDef = json.textures[textureIndex];
  56749. if (!textureDef.extensions || !textureDef.extensions[name]) {
  56750. return null;
  56751. }
  56752. var extension = textureDef.extensions[name];
  56753. var source = json.images[extension.source];
  56754. var loader = parser.textureLoader;
  56755. if (source.uri) {
  56756. var handler = parser.options.manager.getHandler(source.uri);
  56757. if (handler !== null) loader = handler;
  56758. }
  56759. return this.detectSupport().then(function (isSupported) {
  56760. if (isSupported) return parser.loadTextureImage(textureIndex, extension.source, loader);
  56761. if (json.extensionsRequired && json.extensionsRequired.indexOf(name) >= 0) {
  56762. throw new Error('THREE.GLTFLoader: WebP required by asset but unsupported.');
  56763. }
  56764. // Fall back to PNG or JPEG.
  56765. return parser.loadTexture(textureIndex);
  56766. });
  56767. }
  56768. detectSupport() {
  56769. if (!this.isSupported) {
  56770. this.isSupported = new Promise(function (resolve) {
  56771. var image = new Image();
  56772. // Lossy test image. Support for lossy images doesn't guarantee support for all
  56773. // WebP images, unfortunately.
  56774. image.src = 'data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA';
  56775. image.onload = image.onerror = function () {
  56776. resolve(image.height === 1);
  56777. };
  56778. });
  56779. }
  56780. return this.isSupported;
  56781. }
  56782. }
  56783. /**
  56784. * meshopt BufferView Compression Extension
  56785. *
  56786. * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_meshopt_compression
  56787. */
  56788. class GLTFMeshoptCompression {
  56789. constructor(parser) {
  56790. this.name = EXTENSIONS.EXT_MESHOPT_COMPRESSION;
  56791. this.parser = parser;
  56792. }
  56793. loadBufferView(index) {
  56794. var json = this.parser.json;
  56795. var bufferView = json.bufferViews[index];
  56796. if (bufferView.extensions && bufferView.extensions[this.name]) {
  56797. var extensionDef = bufferView.extensions[this.name];
  56798. var buffer = this.parser.getDependency('buffer', extensionDef.buffer);
  56799. var decoder = this.parser.options.meshoptDecoder;
  56800. if (!decoder || !decoder.supported) {
  56801. if (json.extensionsRequired && json.extensionsRequired.indexOf(this.name) >= 0) {
  56802. throw new Error('THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files');
  56803. } else {
  56804. // Assumes that the extension is optional and that fallback buffer data is present
  56805. return null;
  56806. }
  56807. }
  56808. return buffer.then(function (res) {
  56809. var byteOffset = extensionDef.byteOffset || 0;
  56810. var byteLength = extensionDef.byteLength || 0;
  56811. var count = extensionDef.count;
  56812. var stride = extensionDef.byteStride;
  56813. var source = new Uint8Array(res, byteOffset, byteLength);
  56814. if (decoder.decodeGltfBufferAsync) {
  56815. return decoder.decodeGltfBufferAsync(count, stride, source, extensionDef.mode, extensionDef.filter).then(function (res) {
  56816. return res.buffer;
  56817. });
  56818. } else {
  56819. // Support for MeshoptDecoder 0.18 or earlier, without decodeGltfBufferAsync
  56820. return decoder.ready.then(function () {
  56821. var result = new ArrayBuffer(count * stride);
  56822. decoder.decodeGltfBuffer(new Uint8Array(result), count, stride, source, extensionDef.mode, extensionDef.filter);
  56823. return result;
  56824. });
  56825. }
  56826. });
  56827. } else {
  56828. return null;
  56829. }
  56830. }
  56831. }
  56832. /**
  56833. * GPU Instancing Extension
  56834. *
  56835. * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_mesh_gpu_instancing
  56836. *
  56837. */
  56838. class GLTFMeshGpuInstancing {
  56839. constructor(parser) {
  56840. this.name = EXTENSIONS.EXT_MESH_GPU_INSTANCING;
  56841. this.parser = parser;
  56842. }
  56843. createNodeMesh(nodeIndex) {
  56844. var _this = this;
  56845. var json = this.parser.json;
  56846. var nodeDef = json.nodes[nodeIndex];
  56847. if (!nodeDef.extensions || !nodeDef.extensions[this.name] || nodeDef.mesh === undefined) {
  56848. return null;
  56849. }
  56850. var meshDef = json.meshes[nodeDef.mesh];
  56851. // No Points or Lines + Instancing support yet
  56852. for (var primitive of meshDef.primitives) {
  56853. if (primitive.mode !== WEBGL_CONSTANTS.TRIANGLES && primitive.mode !== WEBGL_CONSTANTS.TRIANGLE_STRIP && primitive.mode !== WEBGL_CONSTANTS.TRIANGLE_FAN && primitive.mode !== undefined) {
  56854. return null;
  56855. }
  56856. }
  56857. var extensionDef = nodeDef.extensions[this.name];
  56858. var attributesDef = extensionDef.attributes;
  56859. // @TODO: Can we support InstancedMesh + SkinnedMesh?
  56860. var pending = [];
  56861. var attributes = {};
  56862. var _loop = function _loop(key) {
  56863. pending.push(_this.parser.getDependency('accessor', attributesDef[key]).then(accessor => {
  56864. attributes[key] = accessor;
  56865. return attributes[key];
  56866. }));
  56867. };
  56868. for (var key in attributesDef) {
  56869. _loop(key);
  56870. }
  56871. if (pending.length < 1) {
  56872. return null;
  56873. }
  56874. pending.push(this.parser.createNodeMesh(nodeIndex));
  56875. return Promise.all(pending).then(results => {
  56876. var nodeObject = results.pop();
  56877. var meshes = nodeObject.isGroup ? nodeObject.children : [nodeObject];
  56878. var count = results[0].count; // All attribute counts should be same
  56879. var instancedMeshes = [];
  56880. for (var mesh of meshes) {
  56881. // Temporal variables
  56882. var m = new Matrix4();
  56883. var p = new Vector3();
  56884. var q = new Quaternion();
  56885. var s = new Vector3(1, 1, 1);
  56886. var instancedMesh = new InstancedMesh(mesh.geometry, mesh.material, count);
  56887. for (var i = 0; i < count; i++) {
  56888. if (attributes.TRANSLATION) {
  56889. p.fromBufferAttribute(attributes.TRANSLATION, i);
  56890. }
  56891. if (attributes.ROTATION) {
  56892. q.fromBufferAttribute(attributes.ROTATION, i);
  56893. }
  56894. if (attributes.SCALE) {
  56895. s.fromBufferAttribute(attributes.SCALE, i);
  56896. }
  56897. instancedMesh.setMatrixAt(i, m.compose(p, q, s));
  56898. }
  56899. // Add instance attributes to the geometry, excluding TRS.
  56900. for (var attributeName in attributes) {
  56901. if (attributeName !== 'TRANSLATION' && attributeName !== 'ROTATION' && attributeName !== 'SCALE') {
  56902. mesh.geometry.setAttribute(attributeName, attributes[attributeName]);
  56903. }
  56904. }
  56905. // Just in case
  56906. Object3D.prototype.copy.call(instancedMesh, mesh);
  56907. // https://github.com/mrdoob/three.js/issues/18334
  56908. instancedMesh.frustumCulled = false;
  56909. this.parser.assignFinalMaterial(instancedMesh);
  56910. instancedMeshes.push(instancedMesh);
  56911. }
  56912. if (nodeObject.isGroup) {
  56913. nodeObject.clear();
  56914. nodeObject.add(...instancedMeshes);
  56915. return nodeObject;
  56916. }
  56917. return instancedMeshes[0];
  56918. });
  56919. }
  56920. }
  56921. /* BINARY EXTENSION */
  56922. var BINARY_EXTENSION_HEADER_MAGIC = 'glTF';
  56923. var BINARY_EXTENSION_HEADER_LENGTH = 12;
  56924. var BINARY_EXTENSION_CHUNK_TYPES = {
  56925. JSON: 0x4E4F534A,
  56926. BIN: 0x004E4942
  56927. };
  56928. class GLTFBinaryExtension {
  56929. constructor(data) {
  56930. this.name = EXTENSIONS.KHR_BINARY_GLTF;
  56931. this.content = null;
  56932. this.body = null;
  56933. var headerView = new DataView(data, 0, BINARY_EXTENSION_HEADER_LENGTH);
  56934. this.header = {
  56935. magic: LoaderUtils.decodeText(new Uint8Array(data.slice(0, 4))),
  56936. version: headerView.getUint32(4, true),
  56937. length: headerView.getUint32(8, true)
  56938. };
  56939. if (this.header.magic !== BINARY_EXTENSION_HEADER_MAGIC) {
  56940. throw new Error('THREE.GLTFLoader: Unsupported glTF-Binary header.');
  56941. } else if (this.header.version < 2.0) {
  56942. throw new Error('THREE.GLTFLoader: Legacy binary file detected.');
  56943. }
  56944. var chunkContentsLength = this.header.length - BINARY_EXTENSION_HEADER_LENGTH;
  56945. var chunkView = new DataView(data, BINARY_EXTENSION_HEADER_LENGTH);
  56946. var chunkIndex = 0;
  56947. while (chunkIndex < chunkContentsLength) {
  56948. var chunkLength = chunkView.getUint32(chunkIndex, true);
  56949. chunkIndex += 4;
  56950. var chunkType = chunkView.getUint32(chunkIndex, true);
  56951. chunkIndex += 4;
  56952. if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.JSON) {
  56953. var contentArray = new Uint8Array(data, BINARY_EXTENSION_HEADER_LENGTH + chunkIndex, chunkLength);
  56954. this.content = LoaderUtils.decodeText(contentArray);
  56955. } else if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.BIN) {
  56956. var byteOffset = BINARY_EXTENSION_HEADER_LENGTH + chunkIndex;
  56957. this.body = data.slice(byteOffset, byteOffset + chunkLength);
  56958. }
  56959. // Clients must ignore chunks with unknown types.
  56960. chunkIndex += chunkLength;
  56961. }
  56962. if (this.content === null) {
  56963. throw new Error('THREE.GLTFLoader: JSON content not found.');
  56964. }
  56965. }
  56966. }
  56967. /**
  56968. * DRACO Mesh Compression Extension
  56969. *
  56970. * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression
  56971. */
  56972. class GLTFDracoMeshCompressionExtension {
  56973. constructor(json, dracoLoader) {
  56974. if (!dracoLoader) {
  56975. throw new Error('THREE.GLTFLoader: No DRACOLoader instance provided.');
  56976. }
  56977. this.name = EXTENSIONS.KHR_DRACO_MESH_COMPRESSION;
  56978. this.json = json;
  56979. this.dracoLoader = dracoLoader;
  56980. this.dracoLoader.preload();
  56981. }
  56982. decodePrimitive(primitive, parser) {
  56983. var json = this.json;
  56984. var dracoLoader = this.dracoLoader;
  56985. var bufferViewIndex = primitive.extensions[this.name].bufferView;
  56986. var gltfAttributeMap = primitive.extensions[this.name].attributes;
  56987. var threeAttributeMap = {};
  56988. var attributeNormalizedMap = {};
  56989. var attributeTypeMap = {};
  56990. for (var attributeName in gltfAttributeMap) {
  56991. var threeAttributeName = ATTRIBUTES[attributeName] || attributeName.toLowerCase();
  56992. threeAttributeMap[threeAttributeName] = gltfAttributeMap[attributeName];
  56993. }
  56994. for (var _attributeName in primitive.attributes) {
  56995. var _threeAttributeName = ATTRIBUTES[_attributeName] || _attributeName.toLowerCase();
  56996. if (gltfAttributeMap[_attributeName] !== undefined) {
  56997. var accessorDef = json.accessors[primitive.attributes[_attributeName]];
  56998. var componentType = WEBGL_COMPONENT_TYPES[accessorDef.componentType];
  56999. attributeTypeMap[_threeAttributeName] = componentType.name;
  57000. attributeNormalizedMap[_threeAttributeName] = accessorDef.normalized === true;
  57001. }
  57002. }
  57003. return parser.getDependency('bufferView', bufferViewIndex).then(function (bufferView) {
  57004. return new Promise(function (resolve) {
  57005. dracoLoader.decodeDracoFile(bufferView, function (geometry) {
  57006. for (var _attributeName2 in geometry.attributes) {
  57007. var attribute = geometry.attributes[_attributeName2];
  57008. var normalized = attributeNormalizedMap[_attributeName2];
  57009. if (normalized !== undefined) attribute.normalized = normalized;
  57010. }
  57011. resolve(geometry);
  57012. }, threeAttributeMap, attributeTypeMap);
  57013. });
  57014. });
  57015. }
  57016. }
  57017. /**
  57018. * Texture Transform Extension
  57019. *
  57020. * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_texture_transform
  57021. */
  57022. class GLTFTextureTransformExtension {
  57023. constructor() {
  57024. this.name = EXTENSIONS.KHR_TEXTURE_TRANSFORM;
  57025. }
  57026. extendTexture(texture, transform) {
  57027. if (transform.texCoord !== undefined) {
  57028. console.warn('THREE.GLTFLoader: Custom UV sets in "' + this.name + '" extension not yet supported.');
  57029. }
  57030. if (transform.offset === undefined && transform.rotation === undefined && transform.scale === undefined) {
  57031. // See https://github.com/mrdoob/three.js/issues/21819.
  57032. return texture;
  57033. }
  57034. texture = texture.clone();
  57035. if (transform.offset !== undefined) {
  57036. texture.offset.fromArray(transform.offset);
  57037. }
  57038. if (transform.rotation !== undefined) {
  57039. texture.rotation = transform.rotation;
  57040. }
  57041. if (transform.scale !== undefined) {
  57042. texture.repeat.fromArray(transform.scale);
  57043. }
  57044. texture.needsUpdate = true;
  57045. return texture;
  57046. }
  57047. }
  57048. /**
  57049. * Specular-Glossiness Extension
  57050. *
  57051. * Specification: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Archived/KHR_materials_pbrSpecularGlossiness
  57052. */
  57053. /**
  57054. * A sub class of StandardMaterial with some of the functionality
  57055. * changed via the `onBeforeCompile` callback
  57056. * @pailhead
  57057. */
  57058. class GLTFMeshStandardSGMaterial extends MeshStandardMaterial {
  57059. constructor(params) {
  57060. super();
  57061. this.isGLTFSpecularGlossinessMaterial = true;
  57062. //various chunks that need replacing
  57063. var specularMapParsFragmentChunk = ['#ifdef USE_SPECULARMAP', ' uniform sampler2D specularMap;', '#endif'].join('\n');
  57064. var glossinessMapParsFragmentChunk = ['#ifdef USE_GLOSSINESSMAP', ' uniform sampler2D glossinessMap;', '#endif'].join('\n');
  57065. var specularMapFragmentChunk = ['vec3 specularFactor = specular;', '#ifdef USE_SPECULARMAP', ' vec4 texelSpecular = texture2D( specularMap, vUv );', ' // reads channel RGB, compatible with a glTF Specular-Glossiness (RGBA) texture', ' specularFactor *= texelSpecular.rgb;', '#endif'].join('\n');
  57066. var glossinessMapFragmentChunk = ['float glossinessFactor = glossiness;', '#ifdef USE_GLOSSINESSMAP', ' vec4 texelGlossiness = texture2D( glossinessMap, vUv );', ' // reads channel A, compatible with a glTF Specular-Glossiness (RGBA) texture', ' glossinessFactor *= texelGlossiness.a;', '#endif'].join('\n');
  57067. var lightPhysicalFragmentChunk = ['PhysicalMaterial material;', 'material.diffuseColor = diffuseColor.rgb * ( 1. - max( specularFactor.r, max( specularFactor.g, specularFactor.b ) ) );', 'vec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );', 'float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );', 'material.roughness = max( 1.0 - glossinessFactor, 0.0525 ); // 0.0525 corresponds to the base mip of a 256 cubemap.', 'material.roughness += geometryRoughness;', 'material.roughness = min( material.roughness, 1.0 );', 'material.specularColor = specularFactor;'].join('\n');
  57068. var uniforms = {
  57069. specular: {
  57070. value: new Color().setHex(0xffffff)
  57071. },
  57072. glossiness: {
  57073. value: 1
  57074. },
  57075. specularMap: {
  57076. value: null
  57077. },
  57078. glossinessMap: {
  57079. value: null
  57080. }
  57081. };
  57082. this._extraUniforms = uniforms;
  57083. this.onBeforeCompile = function (shader) {
  57084. for (var uniformName in uniforms) {
  57085. shader.uniforms[uniformName] = uniforms[uniformName];
  57086. }
  57087. shader.fragmentShader = shader.fragmentShader.replace('uniform float roughness;', 'uniform vec3 specular;').replace('uniform float metalness;', 'uniform float glossiness;').replace('#include <roughnessmap_pars_fragment>', specularMapParsFragmentChunk).replace('#include <metalnessmap_pars_fragment>', glossinessMapParsFragmentChunk).replace('#include <roughnessmap_fragment>', specularMapFragmentChunk).replace('#include <metalnessmap_fragment>', glossinessMapFragmentChunk).replace('#include <lights_physical_fragment>', lightPhysicalFragmentChunk);
  57088. };
  57089. Object.defineProperties(this, {
  57090. specular: {
  57091. get: function get() {
  57092. return uniforms.specular.value;
  57093. },
  57094. set: function set(v) {
  57095. uniforms.specular.value = v;
  57096. }
  57097. },
  57098. specularMap: {
  57099. get: function get() {
  57100. return uniforms.specularMap.value;
  57101. },
  57102. set: function set(v) {
  57103. uniforms.specularMap.value = v;
  57104. if (v) {
  57105. this.defines.USE_SPECULARMAP = ''; // USE_UV is set by the renderer for specular maps
  57106. } else {
  57107. delete this.defines.USE_SPECULARMAP;
  57108. }
  57109. }
  57110. },
  57111. glossiness: {
  57112. get: function get() {
  57113. return uniforms.glossiness.value;
  57114. },
  57115. set: function set(v) {
  57116. uniforms.glossiness.value = v;
  57117. }
  57118. },
  57119. glossinessMap: {
  57120. get: function get() {
  57121. return uniforms.glossinessMap.value;
  57122. },
  57123. set: function set(v) {
  57124. uniforms.glossinessMap.value = v;
  57125. if (v) {
  57126. this.defines.USE_GLOSSINESSMAP = '';
  57127. this.defines.USE_UV = '';
  57128. } else {
  57129. delete this.defines.USE_GLOSSINESSMAP;
  57130. delete this.defines.USE_UV;
  57131. }
  57132. }
  57133. }
  57134. });
  57135. delete this.metalness;
  57136. delete this.roughness;
  57137. delete this.metalnessMap;
  57138. delete this.roughnessMap;
  57139. this.setValues(params);
  57140. }
  57141. copy(source) {
  57142. super.copy(source);
  57143. this.specularMap = source.specularMap;
  57144. this.specular.copy(source.specular);
  57145. this.glossinessMap = source.glossinessMap;
  57146. this.glossiness = source.glossiness;
  57147. delete this.metalness;
  57148. delete this.roughness;
  57149. delete this.metalnessMap;
  57150. delete this.roughnessMap;
  57151. return this;
  57152. }
  57153. }
  57154. class GLTFMaterialsPbrSpecularGlossinessExtension {
  57155. constructor() {
  57156. this.name = EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS;
  57157. this.specularGlossinessParams = ['color', 'map', 'lightMap', 'lightMapIntensity', 'aoMap', 'aoMapIntensity', 'emissive', 'emissiveIntensity', 'emissiveMap', 'bumpMap', 'bumpScale', 'normalMap', 'normalMapType', 'displacementMap', 'displacementScale', 'displacementBias', 'specularMap', 'specular', 'glossinessMap', 'glossiness', 'alphaMap', 'envMap', 'envMapIntensity'];
  57158. }
  57159. getMaterialType() {
  57160. return GLTFMeshStandardSGMaterial;
  57161. }
  57162. extendParams(materialParams, materialDef, parser) {
  57163. var pbrSpecularGlossiness = materialDef.extensions[this.name];
  57164. materialParams.color = new Color(1.0, 1.0, 1.0);
  57165. materialParams.opacity = 1.0;
  57166. var pending = [];
  57167. if (Array.isArray(pbrSpecularGlossiness.diffuseFactor)) {
  57168. var array = pbrSpecularGlossiness.diffuseFactor;
  57169. materialParams.color.fromArray(array);
  57170. materialParams.opacity = array[3];
  57171. }
  57172. if (pbrSpecularGlossiness.diffuseTexture !== undefined) {
  57173. pending.push(parser.assignTexture(materialParams, 'map', pbrSpecularGlossiness.diffuseTexture, sRGBEncoding));
  57174. }
  57175. materialParams.emissive = new Color(0.0, 0.0, 0.0);
  57176. materialParams.glossiness = pbrSpecularGlossiness.glossinessFactor !== undefined ? pbrSpecularGlossiness.glossinessFactor : 1.0;
  57177. materialParams.specular = new Color(1.0, 1.0, 1.0);
  57178. if (Array.isArray(pbrSpecularGlossiness.specularFactor)) {
  57179. materialParams.specular.fromArray(pbrSpecularGlossiness.specularFactor);
  57180. }
  57181. if (pbrSpecularGlossiness.specularGlossinessTexture !== undefined) {
  57182. var specGlossMapDef = pbrSpecularGlossiness.specularGlossinessTexture;
  57183. pending.push(parser.assignTexture(materialParams, 'glossinessMap', specGlossMapDef));
  57184. pending.push(parser.assignTexture(materialParams, 'specularMap', specGlossMapDef, sRGBEncoding));
  57185. }
  57186. return Promise.all(pending);
  57187. }
  57188. createMaterial(materialParams) {
  57189. var material = new GLTFMeshStandardSGMaterial(materialParams);
  57190. material.fog = true;
  57191. material.color = materialParams.color;
  57192. material.map = materialParams.map === undefined ? null : materialParams.map;
  57193. material.lightMap = null;
  57194. material.lightMapIntensity = 1.0;
  57195. material.aoMap = materialParams.aoMap === undefined ? null : materialParams.aoMap;
  57196. material.aoMapIntensity = 1.0;
  57197. material.emissive = materialParams.emissive;
  57198. material.emissiveIntensity = materialParams.emissiveIntensity === undefined ? 1.0 : materialParams.emissiveIntensity;
  57199. material.emissiveMap = materialParams.emissiveMap === undefined ? null : materialParams.emissiveMap;
  57200. material.bumpMap = materialParams.bumpMap === undefined ? null : materialParams.bumpMap;
  57201. material.bumpScale = 1;
  57202. material.normalMap = materialParams.normalMap === undefined ? null : materialParams.normalMap;
  57203. material.normalMapType = TangentSpaceNormalMap;
  57204. if (materialParams.normalScale) material.normalScale = materialParams.normalScale;
  57205. material.displacementMap = null;
  57206. material.displacementScale = 1;
  57207. material.displacementBias = 0;
  57208. material.specularMap = materialParams.specularMap === undefined ? null : materialParams.specularMap;
  57209. material.specular = materialParams.specular;
  57210. material.glossinessMap = materialParams.glossinessMap === undefined ? null : materialParams.glossinessMap;
  57211. material.glossiness = materialParams.glossiness;
  57212. material.alphaMap = null;
  57213. material.envMap = materialParams.envMap === undefined ? null : materialParams.envMap;
  57214. material.envMapIntensity = 1.0;
  57215. return material;
  57216. }
  57217. }
  57218. /**
  57219. * Mesh Quantization Extension
  57220. *
  57221. * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization
  57222. */
  57223. class GLTFMeshQuantizationExtension {
  57224. constructor() {
  57225. this.name = EXTENSIONS.KHR_MESH_QUANTIZATION;
  57226. }
  57227. }
  57228. /*********************************/
  57229. /********** INTERPOLATION ********/
  57230. /*********************************/
  57231. // Spline Interpolation
  57232. // Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#appendix-c-spline-interpolation
  57233. class GLTFCubicSplineInterpolant extends Interpolant {
  57234. constructor(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  57235. super(parameterPositions, sampleValues, sampleSize, resultBuffer);
  57236. }
  57237. copySampleValue_(index) {
  57238. // Copies a sample value to the result buffer. See description of glTF
  57239. // CUBICSPLINE values layout in interpolate_() function below.
  57240. var result = this.resultBuffer,
  57241. values = this.sampleValues,
  57242. valueSize = this.valueSize,
  57243. offset = index * valueSize * 3 + valueSize;
  57244. for (var i = 0; i !== valueSize; i++) {
  57245. result[i] = values[offset + i];
  57246. }
  57247. return result;
  57248. }
  57249. interpolate_(i1, t0, t, t1) {
  57250. var result = this.resultBuffer;
  57251. var values = this.sampleValues;
  57252. var stride = this.valueSize;
  57253. var stride2 = stride * 2;
  57254. var stride3 = stride * 3;
  57255. var td = t1 - t0;
  57256. var p = (t - t0) / td;
  57257. var pp = p * p;
  57258. var ppp = pp * p;
  57259. var offset1 = i1 * stride3;
  57260. var offset0 = offset1 - stride3;
  57261. var s2 = -2 * ppp + 3 * pp;
  57262. var s3 = ppp - pp;
  57263. var s0 = 1 - s2;
  57264. var s1 = s3 - pp + p;
  57265. // Layout of keyframe output values for CUBICSPLINE animations:
  57266. // [ inTangent_1, splineVertex_1, outTangent_1, inTangent_2, splineVertex_2, ... ]
  57267. for (var i = 0; i !== stride; i++) {
  57268. var p0 = values[offset0 + i + stride]; // splineVertex_k
  57269. var m0 = values[offset0 + i + stride2] * td; // outTangent_k * (t_k+1 - t_k)
  57270. var p1 = values[offset1 + i + stride]; // splineVertex_k+1
  57271. var m1 = values[offset1 + i] * td; // inTangent_k+1 * (t_k+1 - t_k)
  57272. result[i] = s0 * p0 + s1 * m0 + s2 * p1 + s3 * m1;
  57273. }
  57274. return result;
  57275. }
  57276. }
  57277. var _q = new Quaternion();
  57278. class GLTFCubicSplineQuaternionInterpolant extends GLTFCubicSplineInterpolant {
  57279. interpolate_(i1, t0, t, t1) {
  57280. var result = super.interpolate_(i1, t0, t, t1);
  57281. _q.fromArray(result).normalize().toArray(result);
  57282. return result;
  57283. }
  57284. }
  57285. /*********************************/
  57286. /********** INTERNALS ************/
  57287. /*********************************/
  57288. /* CONSTANTS */
  57289. var WEBGL_CONSTANTS = {
  57290. FLOAT: 5126,
  57291. //FLOAT_MAT2: 35674,
  57292. FLOAT_MAT3: 35675,
  57293. FLOAT_MAT4: 35676,
  57294. FLOAT_VEC2: 35664,
  57295. FLOAT_VEC3: 35665,
  57296. FLOAT_VEC4: 35666,
  57297. LINEAR: 9729,
  57298. REPEAT: 10497,
  57299. SAMPLER_2D: 35678,
  57300. POINTS: 0,
  57301. LINES: 1,
  57302. LINE_LOOP: 2,
  57303. LINE_STRIP: 3,
  57304. TRIANGLES: 4,
  57305. TRIANGLE_STRIP: 5,
  57306. TRIANGLE_FAN: 6,
  57307. UNSIGNED_BYTE: 5121,
  57308. UNSIGNED_SHORT: 5123
  57309. };
  57310. var WEBGL_COMPONENT_TYPES = {
  57311. 5120: Int8Array,
  57312. 5121: Uint8Array,
  57313. 5122: Int16Array,
  57314. 5123: Uint16Array,
  57315. 5125: Uint32Array,
  57316. 5126: Float32Array
  57317. };
  57318. var WEBGL_FILTERS = {
  57319. 9728: NearestFilter,
  57320. 9729: LinearFilter,
  57321. 9984: NearestMipmapNearestFilter,
  57322. 9985: LinearMipmapNearestFilter,
  57323. 9986: NearestMipmapLinearFilter,
  57324. 9987: LinearMipmapLinearFilter
  57325. };
  57326. var WEBGL_WRAPPINGS = {
  57327. 33071: ClampToEdgeWrapping,
  57328. 33648: MirroredRepeatWrapping,
  57329. 10497: RepeatWrapping
  57330. };
  57331. var WEBGL_TYPE_SIZES = {
  57332. 'SCALAR': 1,
  57333. 'VEC2': 2,
  57334. 'VEC3': 3,
  57335. 'VEC4': 4,
  57336. 'MAT2': 4,
  57337. 'MAT3': 9,
  57338. 'MAT4': 16
  57339. };
  57340. var ATTRIBUTES = {
  57341. POSITION: 'position',
  57342. NORMAL: 'normal',
  57343. TANGENT: 'tangent',
  57344. TEXCOORD_0: 'uv',
  57345. TEXCOORD_1: 'uv2',
  57346. COLOR_0: 'color',
  57347. WEIGHTS_0: 'skinWeight',
  57348. JOINTS_0: 'skinIndex'
  57349. };
  57350. var PATH_PROPERTIES = {
  57351. scale: 'scale',
  57352. translation: 'position',
  57353. rotation: 'quaternion',
  57354. weights: 'morphTargetInfluences'
  57355. };
  57356. var INTERPOLATION = {
  57357. CUBICSPLINE: undefined,
  57358. // We use a custom interpolant (GLTFCubicSplineInterpolation) for CUBICSPLINE tracks. Each
  57359. // keyframe track will be initialized with a default interpolation type, then modified.
  57360. LINEAR: InterpolateLinear,
  57361. STEP: InterpolateDiscrete
  57362. };
  57363. var ALPHA_MODES = {
  57364. OPAQUE: 'OPAQUE',
  57365. MASK: 'MASK',
  57366. BLEND: 'BLEND'
  57367. };
  57368. /**
  57369. * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#default-material
  57370. */
  57371. function createDefaultMaterial(cache) {
  57372. if (cache['DefaultMaterial'] === undefined) {
  57373. cache['DefaultMaterial'] = new MeshStandardMaterial({
  57374. color: 0xFFFFFF,
  57375. emissive: 0x000000,
  57376. metalness: 1,
  57377. roughness: 1,
  57378. transparent: false,
  57379. depthTest: true,
  57380. side: FrontSide
  57381. });
  57382. }
  57383. return cache['DefaultMaterial'];
  57384. }
  57385. function addUnknownExtensionsToUserData(knownExtensions, object, objectDef) {
  57386. // Add unknown glTF extensions to an object's userData.
  57387. for (var name in objectDef.extensions) {
  57388. if (knownExtensions[name] === undefined) {
  57389. object.userData.gltfExtensions = object.userData.gltfExtensions || {};
  57390. object.userData.gltfExtensions[name] = objectDef.extensions[name];
  57391. }
  57392. }
  57393. }
  57394. /**
  57395. * @param {Object3D|Material|BufferGeometry} object
  57396. * @param {GLTF.definition} gltfDef
  57397. */
  57398. function assignExtrasToUserData(object, gltfDef) {
  57399. if (gltfDef.extras !== undefined) {
  57400. if (typeof gltfDef.extras === 'object') {
  57401. Object.assign(object.userData, gltfDef.extras);
  57402. } else {
  57403. console.warn('THREE.GLTFLoader: Ignoring primitive type .extras, ' + gltfDef.extras);
  57404. }
  57405. }
  57406. }
  57407. /**
  57408. * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#morph-targets
  57409. *
  57410. * @param {BufferGeometry} geometry
  57411. * @param {Array<GLTF.Target>} targets
  57412. * @param {GLTFParser} parser
  57413. * @return {Promise<BufferGeometry>}
  57414. */
  57415. function addMorphTargets(geometry, targets, parser) {
  57416. var hasMorphPosition = false;
  57417. var hasMorphNormal = false;
  57418. var hasMorphColor = false;
  57419. for (var i = 0, il = targets.length; i < il; i++) {
  57420. var target = targets[i];
  57421. if (target.POSITION !== undefined) hasMorphPosition = true;
  57422. if (target.NORMAL !== undefined) hasMorphNormal = true;
  57423. if (target.COLOR_0 !== undefined) hasMorphColor = true;
  57424. if (hasMorphPosition && hasMorphNormal && hasMorphColor) break;
  57425. }
  57426. if (!hasMorphPosition && !hasMorphNormal && !hasMorphColor) return Promise.resolve(geometry);
  57427. var pendingPositionAccessors = [];
  57428. var pendingNormalAccessors = [];
  57429. var pendingColorAccessors = [];
  57430. for (var _i2 = 0, _il = targets.length; _i2 < _il; _i2++) {
  57431. var _target = targets[_i2];
  57432. if (hasMorphPosition) {
  57433. var pendingAccessor = _target.POSITION !== undefined ? parser.getDependency('accessor', _target.POSITION) : geometry.attributes.position;
  57434. pendingPositionAccessors.push(pendingAccessor);
  57435. }
  57436. if (hasMorphNormal) {
  57437. var _pendingAccessor = _target.NORMAL !== undefined ? parser.getDependency('accessor', _target.NORMAL) : geometry.attributes.normal;
  57438. pendingNormalAccessors.push(_pendingAccessor);
  57439. }
  57440. if (hasMorphColor) {
  57441. var _pendingAccessor2 = _target.COLOR_0 !== undefined ? parser.getDependency('accessor', _target.COLOR_0) : geometry.attributes.color;
  57442. pendingColorAccessors.push(_pendingAccessor2);
  57443. }
  57444. }
  57445. return Promise.all([Promise.all(pendingPositionAccessors), Promise.all(pendingNormalAccessors), Promise.all(pendingColorAccessors)]).then(function (accessors) {
  57446. var morphPositions = accessors[0];
  57447. var morphNormals = accessors[1];
  57448. var morphColors = accessors[2];
  57449. if (hasMorphPosition) geometry.morphAttributes.position = morphPositions;
  57450. if (hasMorphNormal) geometry.morphAttributes.normal = morphNormals;
  57451. if (hasMorphColor) geometry.morphAttributes.color = morphColors;
  57452. geometry.morphTargetsRelative = true;
  57453. return geometry;
  57454. });
  57455. }
  57456. /**
  57457. * @param {Mesh} mesh
  57458. * @param {GLTF.Mesh} meshDef
  57459. */
  57460. function updateMorphTargets(mesh, meshDef) {
  57461. mesh.updateMorphTargets();
  57462. if (meshDef.weights !== undefined) {
  57463. for (var i = 0, il = meshDef.weights.length; i < il; i++) {
  57464. mesh.morphTargetInfluences[i] = meshDef.weights[i];
  57465. }
  57466. }
  57467. // .extras has user-defined data, so check that .extras.targetNames is an array.
  57468. if (meshDef.extras && Array.isArray(meshDef.extras.targetNames)) {
  57469. var targetNames = meshDef.extras.targetNames;
  57470. if (mesh.morphTargetInfluences.length === targetNames.length) {
  57471. mesh.morphTargetDictionary = {};
  57472. for (var _i3 = 0, _il2 = targetNames.length; _i3 < _il2; _i3++) {
  57473. mesh.morphTargetDictionary[targetNames[_i3]] = _i3;
  57474. }
  57475. } else {
  57476. console.warn('THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.');
  57477. }
  57478. }
  57479. }
  57480. function createPrimitiveKey(primitiveDef) {
  57481. var dracoExtension = primitiveDef.extensions && primitiveDef.extensions[EXTENSIONS.KHR_DRACO_MESH_COMPRESSION];
  57482. var geometryKey;
  57483. if (dracoExtension) {
  57484. geometryKey = 'draco:' + dracoExtension.bufferView + ':' + dracoExtension.indices + ':' + createAttributesKey(dracoExtension.attributes);
  57485. } else {
  57486. geometryKey = primitiveDef.indices + ':' + createAttributesKey(primitiveDef.attributes) + ':' + primitiveDef.mode;
  57487. }
  57488. return geometryKey;
  57489. }
  57490. function createAttributesKey(attributes) {
  57491. var attributesKey = '';
  57492. var keys = Object.keys(attributes).sort();
  57493. for (var i = 0, il = keys.length; i < il; i++) {
  57494. attributesKey += keys[i] + ':' + attributes[keys[i]] + ';';
  57495. }
  57496. return attributesKey;
  57497. }
  57498. function getNormalizedComponentScale(constructor) {
  57499. // Reference:
  57500. // https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization#encoding-quantized-data
  57501. switch (constructor) {
  57502. case Int8Array:
  57503. return 1 / 127;
  57504. case Uint8Array:
  57505. return 1 / 255;
  57506. case Int16Array:
  57507. return 1 / 32767;
  57508. case Uint16Array:
  57509. return 1 / 65535;
  57510. default:
  57511. throw new Error('THREE.GLTFLoader: Unsupported normalized accessor component type.');
  57512. }
  57513. }
  57514. function getImageURIMimeType(uri) {
  57515. if (uri.search(/\.jpe?g($|\?)/i) > 0 || uri.search(/^data\:image\/jpeg/) === 0) return 'image/jpeg';
  57516. if (uri.search(/\.webp($|\?)/i) > 0 || uri.search(/^data\:image\/webp/) === 0) return 'image/webp';
  57517. return 'image/png';
  57518. }
  57519. /* GLTF PARSER */
  57520. class GLTFParser {
  57521. constructor() {
  57522. var json = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  57523. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  57524. this.json = json;
  57525. this.extensions = {};
  57526. this.plugins = {};
  57527. this.options = options;
  57528. // loader object cache
  57529. this.cache = new GLTFRegistry();
  57530. // associations between Three.js objects and glTF elements
  57531. this.associations = new Map();
  57532. // BufferGeometry caching
  57533. this.primitiveCache = {};
  57534. // Object3D instance caches
  57535. this.meshCache = {
  57536. refs: {},
  57537. uses: {}
  57538. };
  57539. this.cameraCache = {
  57540. refs: {},
  57541. uses: {}
  57542. };
  57543. this.lightCache = {
  57544. refs: {},
  57545. uses: {}
  57546. };
  57547. this.sourceCache = {};
  57548. this.textureCache = {};
  57549. // Track node names, to ensure no duplicates
  57550. this.nodeNamesUsed = {};
  57551. // Use an ImageBitmapLoader if imageBitmaps are supported. Moves much of the
  57552. // expensive work of uploading a texture to the GPU off the main thread.
  57553. var isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent) === true;
  57554. var isFirefox = navigator.userAgent.indexOf('Firefox') > -1;
  57555. var firefoxVersion = isFirefox ? navigator.userAgent.match(/Firefox\/([0-9]+)\./)[1] : -1;
  57556. // if ( typeof createImageBitmap === 'undefined' || isSafari || ( isFirefox && firefoxVersion < 98 ) ) {
  57557. this.textureLoader = new TextureLoader(this.options.manager);
  57558. /*} else {
  57559. //为了防止chrome出现报错 The source image could not be decoded. 导致reject,改用TextureLoader by xzw
  57560. this.textureLoader = new ImageBitmapLoader( this.options.manager );
  57561. }
  57562. */
  57563. this.textureLoader.setCrossOrigin(this.options.crossOrigin);
  57564. this.textureLoader.setRequestHeader(this.options.requestHeader);
  57565. this.fileLoader = new FileLoader(this.options.manager);
  57566. this.fileLoader.setResponseType('arraybuffer');
  57567. if (this.options.crossOrigin === 'use-credentials') {
  57568. this.fileLoader.setWithCredentials(true);
  57569. }
  57570. }
  57571. setExtensions(extensions) {
  57572. this.extensions = extensions;
  57573. }
  57574. setPlugins(plugins) {
  57575. this.plugins = plugins;
  57576. }
  57577. parse(onLoad, onError) {
  57578. var parser = this;
  57579. var json = this.json;
  57580. var extensions = this.extensions;
  57581. // Clear the loader cache
  57582. this.cache.removeAll();
  57583. // Mark the special nodes/meshes in json for efficient parse
  57584. this._invokeAll(function (ext) {
  57585. return ext._markDefs && ext._markDefs();
  57586. });
  57587. Promise.all(this._invokeAll(function (ext) {
  57588. return ext.beforeRoot && ext.beforeRoot();
  57589. })).then(function () {
  57590. return Promise.all([parser.getDependencies('scene'), parser.getDependencies('animation'), parser.getDependencies('camera')]);
  57591. }).then(function (dependencies) {
  57592. var result = {
  57593. scene: dependencies[0][json.scene || 0],
  57594. scenes: dependencies[0],
  57595. animations: dependencies[1],
  57596. cameras: dependencies[2],
  57597. asset: json.asset,
  57598. parser: parser,
  57599. userData: {}
  57600. };
  57601. addUnknownExtensionsToUserData(extensions, result, json);
  57602. assignExtrasToUserData(result, json);
  57603. Promise.all(parser._invokeAll(function (ext) {
  57604. return ext.afterRoot && ext.afterRoot(result);
  57605. })).then(function () {
  57606. onLoad(result);
  57607. });
  57608. }).catch(onError);
  57609. }
  57610. /**
  57611. * Marks the special nodes/meshes in json for efficient parse.
  57612. */
  57613. _markDefs() {
  57614. var nodeDefs = this.json.nodes || [];
  57615. var skinDefs = this.json.skins || [];
  57616. var meshDefs = this.json.meshes || [];
  57617. // Nothing in the node definition indicates whether it is a Bone or an
  57618. // Object3D. Use the skins' joint references to mark bones.
  57619. for (var skinIndex = 0, skinLength = skinDefs.length; skinIndex < skinLength; skinIndex++) {
  57620. var joints = skinDefs[skinIndex].joints;
  57621. for (var i = 0, il = joints.length; i < il; i++) {
  57622. nodeDefs[joints[i]].isBone = true;
  57623. }
  57624. }
  57625. // Iterate over all nodes, marking references to shared resources,
  57626. // as well as skeleton joints.
  57627. for (var nodeIndex = 0, nodeLength = nodeDefs.length; nodeIndex < nodeLength; nodeIndex++) {
  57628. var nodeDef = nodeDefs[nodeIndex];
  57629. if (nodeDef.mesh !== undefined) {
  57630. this._addNodeRef(this.meshCache, nodeDef.mesh);
  57631. // Nothing in the mesh definition indicates whether it is
  57632. // a SkinnedMesh or Mesh. Use the node's mesh reference
  57633. // to mark SkinnedMesh if node has skin.
  57634. if (nodeDef.skin !== undefined) {
  57635. meshDefs[nodeDef.mesh].isSkinnedMesh = true;
  57636. }
  57637. }
  57638. if (nodeDef.camera !== undefined) {
  57639. this._addNodeRef(this.cameraCache, nodeDef.camera);
  57640. }
  57641. }
  57642. }
  57643. /**
  57644. * Counts references to shared node / Object3D resources. These resources
  57645. * can be reused, or "instantiated", at multiple nodes in the scene
  57646. * hierarchy. Mesh, Camera, and Light instances are instantiated and must
  57647. * be marked. Non-scenegraph resources (like Materials, Geometries, and
  57648. * Textures) can be reused directly and are not marked here.
  57649. *
  57650. * Example: CesiumMilkTruck sample model reuses "Wheel" meshes.
  57651. */
  57652. _addNodeRef(cache, index) {
  57653. if (index === undefined) return;
  57654. if (cache.refs[index] === undefined) {
  57655. cache.refs[index] = cache.uses[index] = 0;
  57656. }
  57657. cache.refs[index]++;
  57658. }
  57659. /** Returns a reference to a shared resource, cloning it if necessary. */
  57660. _getNodeRef(cache, index, object) {
  57661. if (cache.refs[index] <= 1) return object;
  57662. var ref = object.clone();
  57663. // Propagates mappings to the cloned object, prevents mappings on the
  57664. // original object from being lost.
  57665. var updateMappings = (original, clone) => {
  57666. var mappings = this.associations.get(original);
  57667. if (mappings != null) {
  57668. this.associations.set(clone, mappings);
  57669. }
  57670. for (var [i, child] of original.children.entries()) {
  57671. updateMappings(child, clone.children[i]);
  57672. }
  57673. };
  57674. updateMappings(object, ref);
  57675. ref.name += '_instance_' + cache.uses[index]++;
  57676. return ref;
  57677. }
  57678. _invokeOne(func) {
  57679. var extensions = Object.values(this.plugins);
  57680. extensions.push(this);
  57681. for (var i = 0; i < extensions.length; i++) {
  57682. var result = func(extensions[i]);
  57683. if (result) return result;
  57684. }
  57685. return null;
  57686. }
  57687. _invokeAll(func) {
  57688. var extensions = Object.values(this.plugins);
  57689. extensions.unshift(this);
  57690. var pending = [];
  57691. for (var i = 0; i < extensions.length; i++) {
  57692. var result = func(extensions[i]);
  57693. if (result) pending.push(result);
  57694. }
  57695. return pending;
  57696. }
  57697. /**
  57698. * Requests the specified dependency asynchronously, with caching.
  57699. * @param {string} type
  57700. * @param {number} index
  57701. * @return {Promise<Object3D|Material|THREE.Texture|AnimationClip|ArrayBuffer|Object>}
  57702. */
  57703. getDependency(type, index) {
  57704. var cacheKey = type + ':' + index;
  57705. var dependency = this.cache.get(cacheKey);
  57706. if (!dependency) {
  57707. switch (type) {
  57708. case 'scene':
  57709. dependency = this.loadScene(index);
  57710. break;
  57711. case 'node':
  57712. dependency = this.loadNode(index);
  57713. break;
  57714. case 'mesh':
  57715. dependency = this._invokeOne(function (ext) {
  57716. return ext.loadMesh && ext.loadMesh(index);
  57717. });
  57718. break;
  57719. case 'accessor':
  57720. dependency = this.loadAccessor(index);
  57721. break;
  57722. case 'bufferView':
  57723. dependency = this._invokeOne(function (ext) {
  57724. return ext.loadBufferView && ext.loadBufferView(index);
  57725. });
  57726. break;
  57727. case 'buffer':
  57728. dependency = this.loadBuffer(index);
  57729. break;
  57730. case 'material':
  57731. dependency = this._invokeOne(function (ext) {
  57732. return ext.loadMaterial && ext.loadMaterial(index);
  57733. });
  57734. break;
  57735. case 'texture':
  57736. dependency = this._invokeOne(function (ext) {
  57737. return ext.loadTexture && ext.loadTexture(index);
  57738. });
  57739. break;
  57740. case 'skin':
  57741. dependency = this.loadSkin(index);
  57742. break;
  57743. case 'animation':
  57744. dependency = this._invokeOne(function (ext) {
  57745. return ext.loadAnimation && ext.loadAnimation(index);
  57746. });
  57747. break;
  57748. case 'camera':
  57749. dependency = this.loadCamera(index);
  57750. break;
  57751. default:
  57752. throw new Error('Unknown type: ' + type);
  57753. }
  57754. this.cache.add(cacheKey, dependency);
  57755. }
  57756. return dependency;
  57757. }
  57758. /**
  57759. * Requests all dependencies of the specified type asynchronously, with caching.
  57760. * @param {string} type
  57761. * @return {Promise<Array<Object>>}
  57762. */
  57763. getDependencies(type) {
  57764. var dependencies = this.cache.get(type);
  57765. if (!dependencies) {
  57766. var parser = this;
  57767. var defs = this.json[type + (type === 'mesh' ? 'es' : 's')] || [];
  57768. dependencies = Promise.all(defs.map(function (def, index) {
  57769. return parser.getDependency(type, index);
  57770. }));
  57771. this.cache.add(type, dependencies);
  57772. }
  57773. return dependencies;
  57774. }
  57775. /**
  57776. * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
  57777. * @param {number} bufferIndex
  57778. * @return {Promise<ArrayBuffer>}
  57779. */
  57780. loadBuffer(bufferIndex) {
  57781. var bufferDef = this.json.buffers[bufferIndex];
  57782. var loader = this.fileLoader;
  57783. if (bufferDef.type && bufferDef.type !== 'arraybuffer') {
  57784. throw new Error('THREE.GLTFLoader: ' + bufferDef.type + ' buffer type is not supported.');
  57785. }
  57786. // If present, GLB container is required to be the first buffer.
  57787. if (bufferDef.uri === undefined && bufferIndex === 0) {
  57788. return Promise.resolve(this.extensions[EXTENSIONS.KHR_BINARY_GLTF].body);
  57789. }
  57790. var options = this.options;
  57791. return new Promise(function (resolve, reject) {
  57792. loader.load(LoaderUtils.resolveURL(bufferDef.uri, options.path), resolve, undefined, function () {
  57793. reject(new Error('THREE.GLTFLoader: Failed to load buffer "' + bufferDef.uri + '".'));
  57794. });
  57795. });
  57796. }
  57797. /**
  57798. * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
  57799. * @param {number} bufferViewIndex
  57800. * @return {Promise<ArrayBuffer>}
  57801. */
  57802. loadBufferView(bufferViewIndex) {
  57803. var bufferViewDef = this.json.bufferViews[bufferViewIndex];
  57804. return this.getDependency('buffer', bufferViewDef.buffer).then(function (buffer) {
  57805. var byteLength = bufferViewDef.byteLength || 0;
  57806. var byteOffset = bufferViewDef.byteOffset || 0;
  57807. return buffer.slice(byteOffset, byteOffset + byteLength);
  57808. });
  57809. }
  57810. /**
  57811. * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#accessors
  57812. * @param {number} accessorIndex
  57813. * @return {Promise<BufferAttribute|InterleavedBufferAttribute>}
  57814. */
  57815. loadAccessor(accessorIndex) {
  57816. var parser = this;
  57817. var json = this.json;
  57818. var accessorDef = this.json.accessors[accessorIndex];
  57819. if (accessorDef.bufferView === undefined && accessorDef.sparse === undefined) {
  57820. // Ignore empty accessors, which may be used to declare runtime
  57821. // information about attributes coming from another source (e.g. Draco
  57822. // compression extension).
  57823. return Promise.resolve(null);
  57824. }
  57825. var pendingBufferViews = [];
  57826. if (accessorDef.bufferView !== undefined) {
  57827. pendingBufferViews.push(this.getDependency('bufferView', accessorDef.bufferView));
  57828. } else {
  57829. pendingBufferViews.push(null);
  57830. }
  57831. if (accessorDef.sparse !== undefined) {
  57832. pendingBufferViews.push(this.getDependency('bufferView', accessorDef.sparse.indices.bufferView));
  57833. pendingBufferViews.push(this.getDependency('bufferView', accessorDef.sparse.values.bufferView));
  57834. }
  57835. return Promise.all(pendingBufferViews).then(function (bufferViews) {
  57836. var bufferView = bufferViews[0];
  57837. var itemSize = WEBGL_TYPE_SIZES[accessorDef.type];
  57838. var TypedArray = WEBGL_COMPONENT_TYPES[accessorDef.componentType];
  57839. // For VEC3: itemSize is 3, elementBytes is 4, itemBytes is 12.
  57840. var elementBytes = TypedArray.BYTES_PER_ELEMENT;
  57841. var itemBytes = elementBytes * itemSize;
  57842. var byteOffset = accessorDef.byteOffset || 0;
  57843. var byteStride = accessorDef.bufferView !== undefined ? json.bufferViews[accessorDef.bufferView].byteStride : undefined;
  57844. var normalized = accessorDef.normalized === true;
  57845. var array, bufferAttribute;
  57846. // The buffer is not interleaved if the stride is the item size in bytes.
  57847. if (byteStride && byteStride !== itemBytes) {
  57848. // Each "slice" of the buffer, as defined by 'count' elements of 'byteStride' bytes, gets its own InterleavedBuffer
  57849. // This makes sure that IBA.count reflects accessor.count properly
  57850. var ibSlice = Math.floor(byteOffset / byteStride);
  57851. var ibCacheKey = 'InterleavedBuffer:' + accessorDef.bufferView + ':' + accessorDef.componentType + ':' + ibSlice + ':' + accessorDef.count;
  57852. var ib = parser.cache.get(ibCacheKey);
  57853. if (!ib) {
  57854. array = new TypedArray(bufferView, ibSlice * byteStride, accessorDef.count * byteStride / elementBytes);
  57855. // Integer parameters to IB/IBA are in array elements, not bytes.
  57856. ib = new InterleavedBuffer(array, byteStride / elementBytes);
  57857. parser.cache.add(ibCacheKey, ib);
  57858. }
  57859. bufferAttribute = new InterleavedBufferAttribute(ib, itemSize, byteOffset % byteStride / elementBytes, normalized);
  57860. } else {
  57861. if (bufferView === null) {
  57862. array = new TypedArray(accessorDef.count * itemSize);
  57863. } else {
  57864. array = new TypedArray(bufferView, byteOffset, accessorDef.count * itemSize);
  57865. }
  57866. bufferAttribute = new BufferAttribute(array, itemSize, normalized);
  57867. }
  57868. // https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#sparse-accessors
  57869. if (accessorDef.sparse !== undefined) {
  57870. var itemSizeIndices = WEBGL_TYPE_SIZES.SCALAR;
  57871. var TypedArrayIndices = WEBGL_COMPONENT_TYPES[accessorDef.sparse.indices.componentType];
  57872. var byteOffsetIndices = accessorDef.sparse.indices.byteOffset || 0;
  57873. var byteOffsetValues = accessorDef.sparse.values.byteOffset || 0;
  57874. var sparseIndices = new TypedArrayIndices(bufferViews[1], byteOffsetIndices, accessorDef.sparse.count * itemSizeIndices);
  57875. var sparseValues = new TypedArray(bufferViews[2], byteOffsetValues, accessorDef.sparse.count * itemSize);
  57876. if (bufferView !== null) {
  57877. // Avoid modifying the original ArrayBuffer, if the bufferView wasn't initialized with zeroes.
  57878. bufferAttribute = new BufferAttribute(bufferAttribute.array.slice(), bufferAttribute.itemSize, bufferAttribute.normalized);
  57879. }
  57880. for (var i = 0, il = sparseIndices.length; i < il; i++) {
  57881. var index = sparseIndices[i];
  57882. bufferAttribute.setX(index, sparseValues[i * itemSize]);
  57883. if (itemSize >= 2) bufferAttribute.setY(index, sparseValues[i * itemSize + 1]);
  57884. if (itemSize >= 3) bufferAttribute.setZ(index, sparseValues[i * itemSize + 2]);
  57885. if (itemSize >= 4) bufferAttribute.setW(index, sparseValues[i * itemSize + 3]);
  57886. if (itemSize >= 5) throw new Error('THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.');
  57887. }
  57888. }
  57889. return bufferAttribute;
  57890. });
  57891. }
  57892. /**
  57893. * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#textures
  57894. * @param {number} textureIndex
  57895. * @return {Promise<THREE.Texture>}
  57896. */
  57897. loadTexture(textureIndex) {
  57898. var json = this.json;
  57899. var options = this.options;
  57900. var textureDef = json.textures[textureIndex];
  57901. var sourceIndex = textureDef.source;
  57902. var sourceDef = json.images[sourceIndex];
  57903. var loader = this.textureLoader;
  57904. if (sourceDef.uri) {
  57905. var handler = options.manager.getHandler(sourceDef.uri);
  57906. if (handler !== null) loader = handler;
  57907. }
  57908. return this.loadTextureImage(textureIndex, sourceIndex, loader);
  57909. }
  57910. loadTextureImage(textureIndex, sourceIndex, loader) {
  57911. var parser = this;
  57912. var json = this.json;
  57913. var textureDef = json.textures[textureIndex];
  57914. var sourceDef = json.images[sourceIndex];
  57915. var cacheKey = (sourceDef.uri || sourceDef.bufferView) + ':' + textureDef.sampler;
  57916. if (this.textureCache[cacheKey]) {
  57917. // See https://github.com/mrdoob/three.js/issues/21559.
  57918. return this.textureCache[cacheKey];
  57919. }
  57920. var promise = this.loadImageSource(sourceIndex, loader).then(function (texture) {
  57921. texture.flipY = false;
  57922. texture.name = textureDef.name || sourceDef.name || '';
  57923. var samplers = json.samplers || {};
  57924. var sampler = samplers[textureDef.sampler] || {};
  57925. Potree.Utils.makeTexDontResize(texture); //add
  57926. /* //xzw 删除设置,因为已经makeTexDontResize
  57927. texture.magFilter = WEBGL_FILTERS[ sampler.magFilter ] || LinearFilter;
  57928. texture.minFilter = WEBGL_FILTERS[ sampler.minFilter ] || LinearMipmapLinearFilter;
  57929. texture.wrapS = WEBGL_WRAPPINGS[ sampler.wrapS ] || RepeatWrapping;
  57930. texture.wrapT = WEBGL_WRAPPINGS[ sampler.wrapT ] || RepeatWrapping;
  57931. */
  57932. parser.associations.set(texture, {
  57933. textures: textureIndex
  57934. });
  57935. return texture;
  57936. }).catch(function () {
  57937. return null;
  57938. });
  57939. this.textureCache[cacheKey] = promise;
  57940. return promise;
  57941. }
  57942. loadImageSource(sourceIndex, loader) {
  57943. var parser = this;
  57944. var json = this.json;
  57945. var options = this.options;
  57946. if (this.sourceCache[sourceIndex] !== undefined) {
  57947. return this.sourceCache[sourceIndex].then(texture => texture.clone());
  57948. }
  57949. var sourceDef = json.images[sourceIndex];
  57950. var URL = self.URL || self.webkitURL;
  57951. var sourceURI = sourceDef.uri || '';
  57952. var isObjectURL = false;
  57953. if (sourceDef.bufferView !== undefined) {
  57954. // Load binary image data from bufferView, if provided.
  57955. sourceURI = parser.getDependency('bufferView', sourceDef.bufferView).then(function (bufferView) {
  57956. isObjectURL = true;
  57957. var blob = new Blob([bufferView], {
  57958. type: sourceDef.mimeType
  57959. });
  57960. sourceURI = URL.createObjectURL(blob);
  57961. return sourceURI;
  57962. });
  57963. } else if (sourceDef.uri === undefined) {
  57964. throw new Error('THREE.GLTFLoader: Image ' + sourceIndex + ' is missing URI and bufferView');
  57965. }
  57966. var promise = Promise.resolve(sourceURI).then(function (sourceURI) {
  57967. return new Promise(function (resolve, reject) {
  57968. if (json.asset.generator == 'gltfpack 0.18') {
  57969. //4dkk场景的模型
  57970. var onLoad = resolve;
  57971. if (loader.isImageBitmapLoader === true) {
  57972. onLoad = function onLoad(imageBitmap) {
  57973. var texture = new Texture(imageBitmap);
  57974. texture.needsUpdate = true;
  57975. resolve(texture);
  57976. };
  57977. }
  57978. //loader.load( LoaderUtils.resolveURL( sourceURI, options.path ), onLoad, undefined, reject );
  57979. var url = parser.textureLoader.manager.resolveURL(sourceURI, options.path);
  57980. loader.load(url, onLoad, undefined, reject);
  57981. } else {
  57982. //为了防止chrome出现报错 The source image could not be decoded. 导致reject,重新写贴图加载方式: xzw //但不知道为何有的场景(如4dkk的)不成功
  57983. parser.textureLoader.load(sourceURI, tex => {
  57984. //原本:NearestMipMapNearestFilter 闪烁 有一个block文件离远了有裂缝,只能使用LinearFilter,但是这样似乎更卡,且锯齿
  57985. /* {//处理裂缝
  57986. tex.minFilter = THREE.LinearFilter
  57987. tex.generateMipmaps = false
  57988. } */
  57989. //console.log(tex.image.width, tex.image.height)
  57990. resolve(tex);
  57991. }, null, e => {
  57992. console.log('error load tex', e);
  57993. });
  57994. }
  57995. });
  57996. }).then(function (texture) {
  57997. // Clean up resources and configure Texture.
  57998. if (isObjectURL === true) {
  57999. URL.revokeObjectURL(sourceURI);
  58000. }
  58001. texture.userData = {}; //xzw add
  58002. texture.userData.mimeType = sourceDef.mimeType || getImageURIMimeType(sourceDef.uri || sourceDef.mimeType);
  58003. return texture;
  58004. }).catch(function (error) {
  58005. console.error('THREE.GLTFLoader: Couldn\'t load texture', sourceURI);
  58006. throw error;
  58007. });
  58008. this.sourceCache[sourceIndex] = promise;
  58009. return promise;
  58010. }
  58011. /**
  58012. * Asynchronously assigns a texture to the given material parameters.
  58013. * @param {Object} materialParams
  58014. * @param {string} mapName
  58015. * @param {Object} mapDef
  58016. * @return {Promise<Texture>}
  58017. */
  58018. assignTexture(materialParams, mapName, mapDef, encoding) {
  58019. var parser = this;
  58020. return this.getDependency('texture', mapDef.index).then(function (texture) {
  58021. // Materials sample aoMap from UV set 1 and other maps from UV set 0 - this can't be configured
  58022. // However, we will copy UV set 0 to UV set 1 on demand for aoMap
  58023. if (mapDef.texCoord !== undefined && mapDef.texCoord != 0 && !(mapName === 'aoMap' && mapDef.texCoord == 1)) {
  58024. console.warn('THREE.GLTFLoader: Custom UV set ' + mapDef.texCoord + ' for texture ' + mapName + ' not yet supported.');
  58025. }
  58026. if (parser.extensions[EXTENSIONS.KHR_TEXTURE_TRANSFORM]) {
  58027. var transform = mapDef.extensions !== undefined ? mapDef.extensions[EXTENSIONS.KHR_TEXTURE_TRANSFORM] : undefined;
  58028. if (transform) {
  58029. var gltfReference = parser.associations.get(texture);
  58030. texture = parser.extensions[EXTENSIONS.KHR_TEXTURE_TRANSFORM].extendTexture(texture, transform);
  58031. parser.associations.set(texture, gltfReference);
  58032. }
  58033. }
  58034. if (encoding !== undefined) {
  58035. texture.encoding = encoding;
  58036. }
  58037. materialParams[mapName] = texture;
  58038. return texture;
  58039. });
  58040. }
  58041. /**
  58042. * Assigns final material to a Mesh, Line, or Points instance. The instance
  58043. * already has a material (generated from the glTF material options alone)
  58044. * but reuse of the same glTF material may require multiple threejs materials
  58045. * to accommodate different primitive types, defines, etc. New materials will
  58046. * be created if necessary, and reused from a cache.
  58047. * @param {Object3D} mesh Mesh, Line, or Points instance.
  58048. */
  58049. assignFinalMaterial(mesh) {
  58050. var geometry = mesh.geometry;
  58051. var material = mesh.material;
  58052. var useDerivativeTangents = geometry.attributes.tangent === undefined;
  58053. var useVertexColors = geometry.attributes.color !== undefined;
  58054. var useFlatShading = geometry.attributes.normal === undefined;
  58055. if (mesh.isPoints) {
  58056. var cacheKey = 'PointsMaterial:' + material.uuid;
  58057. var pointsMaterial = this.cache.get(cacheKey);
  58058. if (!pointsMaterial) {
  58059. pointsMaterial = new PointsMaterial();
  58060. Material.prototype.copy.call(pointsMaterial, material);
  58061. pointsMaterial.color.copy(material.color);
  58062. pointsMaterial.map = material.map;
  58063. pointsMaterial.sizeAttenuation = false; // glTF spec says points should be 1px
  58064. this.cache.add(cacheKey, pointsMaterial);
  58065. }
  58066. material = pointsMaterial;
  58067. } else if (mesh.isLine) {
  58068. var _cacheKey = 'LineBasicMaterial:' + material.uuid;
  58069. var lineMaterial = this.cache.get(_cacheKey);
  58070. if (!lineMaterial) {
  58071. lineMaterial = new LineBasicMaterial();
  58072. Material.prototype.copy.call(lineMaterial, material);
  58073. lineMaterial.color.copy(material.color);
  58074. this.cache.add(_cacheKey, lineMaterial);
  58075. }
  58076. material = lineMaterial;
  58077. }
  58078. // Clone the material if it will be modified
  58079. if (useDerivativeTangents || useVertexColors || useFlatShading) {
  58080. var _cacheKey2 = 'ClonedMaterial:' + material.uuid + ':';
  58081. if (material.isGLTFSpecularGlossinessMaterial) _cacheKey2 += 'specular-glossiness:';
  58082. if (useDerivativeTangents) _cacheKey2 += 'derivative-tangents:';
  58083. if (useVertexColors) _cacheKey2 += 'vertex-colors:';
  58084. if (useFlatShading) _cacheKey2 += 'flat-shading:';
  58085. var cachedMaterial = this.cache.get(_cacheKey2);
  58086. if (!cachedMaterial) {
  58087. cachedMaterial = material.clone();
  58088. if (useVertexColors) cachedMaterial.vertexColors = true;
  58089. if (useFlatShading) cachedMaterial.flatShading = true;
  58090. if (useDerivativeTangents) {
  58091. // https://github.com/mrdoob/three.js/issues/11438#issuecomment-507003995
  58092. if (cachedMaterial.normalScale) cachedMaterial.normalScale.y *= -1;
  58093. if (cachedMaterial.clearcoatNormalScale) cachedMaterial.clearcoatNormalScale.y *= -1;
  58094. }
  58095. this.cache.add(_cacheKey2, cachedMaterial);
  58096. this.associations.set(cachedMaterial, this.associations.get(material));
  58097. }
  58098. material = cachedMaterial;
  58099. }
  58100. // workarounds for mesh and geometry
  58101. if (material.aoMap && geometry.attributes.uv2 === undefined && geometry.attributes.uv !== undefined) {
  58102. geometry.setAttribute('uv2', geometry.attributes.uv);
  58103. }
  58104. mesh.material = material;
  58105. }
  58106. getMaterialType( /* materialIndex */
  58107. ) {
  58108. return MeshStandardMaterial;
  58109. }
  58110. /**
  58111. * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#materials
  58112. * @param {number} materialIndex
  58113. * @return {Promise<Material>}
  58114. */
  58115. loadMaterial(materialIndex) {
  58116. var parser = this;
  58117. var json = this.json;
  58118. var extensions = this.extensions;
  58119. var materialDef = json.materials[materialIndex];
  58120. var materialType;
  58121. var materialParams = {};
  58122. var materialExtensions = materialDef.extensions || {};
  58123. var pending = [];
  58124. if (materialExtensions[EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS]) {
  58125. var sgExtension = extensions[EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS];
  58126. materialType = BasicMaterial; //sgExtension.getMaterialType(); //xzw 改
  58127. pending.push(sgExtension.extendParams(materialParams, materialDef, parser));
  58128. } else if (materialExtensions[EXTENSIONS.KHR_MATERIALS_UNLIT]) {
  58129. var kmuExtension = extensions[EXTENSIONS.KHR_MATERIALS_UNLIT];
  58130. materialType = BasicMaterial; //kmuExtension.getMaterialType(); //xzw 改
  58131. pending.push(kmuExtension.extendParams(materialParams, materialDef, parser));
  58132. } else {
  58133. // Specification:
  58134. // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#metallic-roughness-material
  58135. var metallicRoughness = materialDef.pbrMetallicRoughness || {};
  58136. materialParams.color = new Color(1.0, 1.0, 1.0);
  58137. materialParams.opacity = 1.0;
  58138. if (Array.isArray(metallicRoughness.baseColorFactor)) {
  58139. var array = metallicRoughness.baseColorFactor;
  58140. materialParams.color.fromArray(array);
  58141. materialParams.opacity = array[3];
  58142. }
  58143. if (metallicRoughness.baseColorTexture !== undefined) {
  58144. pending.push(parser.assignTexture(materialParams, 'map', metallicRoughness.baseColorTexture, sRGBEncoding));
  58145. }
  58146. materialParams.metalness = metallicRoughness.metallicFactor !== undefined ? metallicRoughness.metallicFactor : 1.0;
  58147. materialParams.roughness = metallicRoughness.roughnessFactor !== undefined ? metallicRoughness.roughnessFactor : 1.0;
  58148. if (metallicRoughness.metallicRoughnessTexture !== undefined) {
  58149. pending.push(parser.assignTexture(materialParams, 'metalnessMap', metallicRoughness.metallicRoughnessTexture));
  58150. pending.push(parser.assignTexture(materialParams, 'roughnessMap', metallicRoughness.metallicRoughnessTexture));
  58151. }
  58152. materialType = this._invokeOne(function (ext) {
  58153. //return BasicMaterial //2024.7放弃使用这个,因为纯色的看上去连成一片
  58154. //kmuExtension.getMaterialType(); //xzw 改
  58155. return ext.getMaterialType && ext.getMaterialType(materialIndex);
  58156. });
  58157. pending.push(Promise.all(this._invokeAll(function (ext) {
  58158. return ext.extendMaterialParams && ext.extendMaterialParams(materialIndex, materialParams);
  58159. })));
  58160. }
  58161. if (materialDef.doubleSided === true) {
  58162. materialParams.side = DoubleSide;
  58163. }
  58164. var alphaMode = materialDef.alphaMode || ALPHA_MODES.OPAQUE;
  58165. if (alphaMode === ALPHA_MODES.BLEND) {
  58166. materialParams.transparent = true;
  58167. // See: https://github.com/mrdoob/three.js/issues/17706
  58168. materialParams.depthWrite = false;
  58169. } else {
  58170. materialParams.transparent = false;
  58171. if (alphaMode === ALPHA_MODES.MASK) {
  58172. materialParams.alphaTest = materialDef.alphaCutoff !== undefined ? materialDef.alphaCutoff : 0.5;
  58173. }
  58174. }
  58175. if (materialDef.normalTexture !== undefined && materialType !== MeshBasicMaterial) {
  58176. pending.push(parser.assignTexture(materialParams, 'normalMap', materialDef.normalTexture));
  58177. materialParams.normalScale = new Vector2(1, 1);
  58178. if (materialDef.normalTexture.scale !== undefined) {
  58179. var scale = materialDef.normalTexture.scale;
  58180. materialParams.normalScale.set(scale, scale);
  58181. }
  58182. }
  58183. if (materialDef.occlusionTexture !== undefined && materialType !== MeshBasicMaterial) {
  58184. pending.push(parser.assignTexture(materialParams, 'aoMap', materialDef.occlusionTexture));
  58185. if (materialDef.occlusionTexture.strength !== undefined) {
  58186. materialParams.aoMapIntensity = materialDef.occlusionTexture.strength;
  58187. }
  58188. }
  58189. if (materialDef.emissiveFactor !== undefined && materialType !== MeshBasicMaterial) {
  58190. materialParams.emissive = new Color().fromArray(materialDef.emissiveFactor);
  58191. }
  58192. if (materialDef.emissiveTexture !== undefined && materialType !== MeshBasicMaterial) {
  58193. pending.push(parser.assignTexture(materialParams, 'emissiveMap', materialDef.emissiveTexture, sRGBEncoding));
  58194. }
  58195. return Promise.all(pending).then(function () {
  58196. var material;
  58197. if (materialType === GLTFMeshStandardSGMaterial) {
  58198. material = extensions[EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS].createMaterial(materialParams);
  58199. } else {
  58200. material = new materialType(materialParams);
  58201. }
  58202. if (materialDef.name) material.name = materialDef.name;
  58203. assignExtrasToUserData(material, materialDef);
  58204. parser.associations.set(material, {
  58205. materials: materialIndex
  58206. });
  58207. if (materialDef.extensions) addUnknownExtensionsToUserData(extensions, material, materialDef);
  58208. return material;
  58209. });
  58210. }
  58211. /** When Object3D instances are targeted by animation, they need unique names. */
  58212. createUniqueName(originalName) {
  58213. var sanitizedName = PropertyBinding.sanitizeNodeName(originalName || '');
  58214. var name = sanitizedName;
  58215. for (var i = 1; this.nodeNamesUsed[name]; ++i) {
  58216. name = sanitizedName + '_' + i;
  58217. }
  58218. this.nodeNamesUsed[name] = true;
  58219. return name;
  58220. }
  58221. /**
  58222. * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#geometry
  58223. *
  58224. * Creates BufferGeometries from primitives.
  58225. *
  58226. * @param {Array<GLTF.Primitive>} primitives
  58227. * @return {Promise<Array<BufferGeometry>>}
  58228. */
  58229. loadGeometries(primitives) {
  58230. var parser = this;
  58231. var extensions = this.extensions;
  58232. var cache = this.primitiveCache;
  58233. function createDracoPrimitive(primitive) {
  58234. return extensions[EXTENSIONS.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(primitive, parser).then(function (geometry) {
  58235. return addPrimitiveAttributes(geometry, primitive, parser);
  58236. });
  58237. }
  58238. var pending = [];
  58239. for (var i = 0, il = primitives.length; i < il; i++) {
  58240. var primitive = primitives[i];
  58241. var cacheKey = createPrimitiveKey(primitive);
  58242. // See if we've already created this geometry
  58243. var cached = cache[cacheKey];
  58244. if (cached) {
  58245. // Use the cached geometry if it exists
  58246. pending.push(cached.promise);
  58247. } else {
  58248. var geometryPromise = void 0;
  58249. if (primitive.extensions && primitive.extensions[EXTENSIONS.KHR_DRACO_MESH_COMPRESSION]) {
  58250. // Use DRACO geometry if available
  58251. geometryPromise = createDracoPrimitive(primitive);
  58252. } else {
  58253. // Otherwise create a new geometry
  58254. geometryPromise = addPrimitiveAttributes(new BufferGeometry(), primitive, parser);
  58255. }
  58256. // Cache this geometry
  58257. cache[cacheKey] = {
  58258. primitive: primitive,
  58259. promise: geometryPromise
  58260. };
  58261. pending.push(geometryPromise);
  58262. }
  58263. }
  58264. return Promise.all(pending);
  58265. }
  58266. /**
  58267. * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#meshes
  58268. * @param {number} meshIndex
  58269. * @return {Promise<Group|Mesh|SkinnedMesh>}
  58270. */
  58271. loadMesh(meshIndex) {
  58272. var parser = this;
  58273. var json = this.json;
  58274. var extensions = this.extensions;
  58275. var meshDef = json.meshes[meshIndex];
  58276. var primitives = meshDef.primitives;
  58277. var pending = [];
  58278. for (var i = 0, il = primitives.length; i < il; i++) {
  58279. var material = primitives[i].material === undefined ? createDefaultMaterial(this.cache) : this.getDependency('material', primitives[i].material);
  58280. pending.push(material);
  58281. }
  58282. pending.push(parser.loadGeometries(primitives));
  58283. return Promise.all(pending).then(function (results) {
  58284. var materials = results.slice(0, results.length - 1);
  58285. var geometries = results[results.length - 1];
  58286. var meshes = [];
  58287. for (var _i4 = 0, _il3 = geometries.length; _i4 < _il3; _i4++) {
  58288. var geometry = geometries[_i4];
  58289. var primitive = primitives[_i4];
  58290. // 1. create Mesh
  58291. var mesh = void 0;
  58292. var _material = materials[_i4];
  58293. if (primitive.mode === WEBGL_CONSTANTS.TRIANGLES || primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP || primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN || primitive.mode === undefined) {
  58294. // .isSkinnedMesh isn't in glTF spec. See ._markDefs()
  58295. mesh = meshDef.isSkinnedMesh === true ? new SkinnedMesh(geometry, _material) : new Mesh(geometry, _material);
  58296. if (mesh.isSkinnedMesh === true && !mesh.geometry.attributes.skinWeight.normalized) {
  58297. // we normalize floating point skin weight array to fix malformed assets (see #15319)
  58298. // it's important to skip this for non-float32 data since normalizeSkinWeights assumes non-normalized inputs
  58299. mesh.normalizeSkinWeights();
  58300. }
  58301. if (primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP) {
  58302. mesh.geometry = toTrianglesDrawMode(mesh.geometry, TriangleStripDrawMode);
  58303. } else if (primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN) {
  58304. mesh.geometry = toTrianglesDrawMode(mesh.geometry, TriangleFanDrawMode);
  58305. }
  58306. } else if (primitive.mode === WEBGL_CONSTANTS.LINES) {
  58307. mesh = new LineSegments(geometry, _material);
  58308. } else if (primitive.mode === WEBGL_CONSTANTS.LINE_STRIP) {
  58309. mesh = new Line(geometry, _material);
  58310. } else if (primitive.mode === WEBGL_CONSTANTS.LINE_LOOP) {
  58311. mesh = new LineLoop(geometry, _material);
  58312. } else if (primitive.mode === WEBGL_CONSTANTS.POINTS) {
  58313. mesh = new Points(geometry, _material);
  58314. } else {
  58315. throw new Error('THREE.GLTFLoader: Primitive mode unsupported: ' + primitive.mode);
  58316. }
  58317. if (Object.keys(mesh.geometry.morphAttributes).length > 0) {
  58318. updateMorphTargets(mesh, meshDef);
  58319. }
  58320. mesh.name = parser.createUniqueName(meshDef.name || 'mesh_' + meshIndex);
  58321. assignExtrasToUserData(mesh, meshDef);
  58322. if (primitive.extensions) addUnknownExtensionsToUserData(extensions, mesh, primitive);
  58323. parser.assignFinalMaterial(mesh);
  58324. meshes.push(mesh);
  58325. }
  58326. for (var _i5 = 0, _il4 = meshes.length; _i5 < _il4; _i5++) {
  58327. parser.associations.set(meshes[_i5], {
  58328. meshes: meshIndex,
  58329. primitives: _i5
  58330. });
  58331. }
  58332. if (meshes.length === 1) {
  58333. return meshes[0];
  58334. }
  58335. var group = new Group();
  58336. parser.associations.set(group, {
  58337. meshes: meshIndex
  58338. });
  58339. for (var _i6 = 0, _il5 = meshes.length; _i6 < _il5; _i6++) {
  58340. group.add(meshes[_i6]);
  58341. }
  58342. return group;
  58343. });
  58344. }
  58345. /**
  58346. * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#cameras
  58347. * @param {number} cameraIndex
  58348. * @return {Promise<THREE.Camera>}
  58349. */
  58350. loadCamera(cameraIndex) {
  58351. var camera;
  58352. var cameraDef = this.json.cameras[cameraIndex];
  58353. var params = cameraDef[cameraDef.type];
  58354. if (!params) {
  58355. console.warn('THREE.GLTFLoader: Missing camera parameters.');
  58356. return;
  58357. }
  58358. if (cameraDef.type === 'perspective') {
  58359. camera = new PerspectiveCamera(MathUtils.radToDeg(params.yfov), params.aspectRatio || 1, params.znear || 1, params.zfar || 2e6);
  58360. } else if (cameraDef.type === 'orthographic') {
  58361. camera = new OrthographicCamera(-params.xmag, params.xmag, params.ymag, -params.ymag, params.znear, params.zfar);
  58362. }
  58363. if (cameraDef.name) camera.name = this.createUniqueName(cameraDef.name);
  58364. assignExtrasToUserData(camera, cameraDef);
  58365. return Promise.resolve(camera);
  58366. }
  58367. /**
  58368. * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins
  58369. * @param {number} skinIndex
  58370. * @return {Promise<Object>}
  58371. */
  58372. loadSkin(skinIndex) {
  58373. var skinDef = this.json.skins[skinIndex];
  58374. var skinEntry = {
  58375. joints: skinDef.joints
  58376. };
  58377. if (skinDef.inverseBindMatrices === undefined) {
  58378. return Promise.resolve(skinEntry);
  58379. }
  58380. return this.getDependency('accessor', skinDef.inverseBindMatrices).then(function (accessor) {
  58381. skinEntry.inverseBindMatrices = accessor;
  58382. return skinEntry;
  58383. });
  58384. }
  58385. /**
  58386. * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#animations
  58387. * @param {number} animationIndex
  58388. * @return {Promise<AnimationClip>}
  58389. */
  58390. loadAnimation(animationIndex) {
  58391. var json = this.json;
  58392. var animationDef = json.animations[animationIndex];
  58393. var pendingNodes = [];
  58394. var pendingInputAccessors = [];
  58395. var pendingOutputAccessors = [];
  58396. var pendingSamplers = [];
  58397. var pendingTargets = [];
  58398. for (var i = 0, il = animationDef.channels.length; i < il; i++) {
  58399. var channel = animationDef.channels[i];
  58400. var sampler = animationDef.samplers[channel.sampler];
  58401. var target = channel.target;
  58402. var name = target.node;
  58403. var input = animationDef.parameters !== undefined ? animationDef.parameters[sampler.input] : sampler.input;
  58404. var output = animationDef.parameters !== undefined ? animationDef.parameters[sampler.output] : sampler.output;
  58405. pendingNodes.push(this.getDependency('node', name));
  58406. pendingInputAccessors.push(this.getDependency('accessor', input));
  58407. pendingOutputAccessors.push(this.getDependency('accessor', output));
  58408. pendingSamplers.push(sampler);
  58409. pendingTargets.push(target);
  58410. }
  58411. return Promise.all([Promise.all(pendingNodes), Promise.all(pendingInputAccessors), Promise.all(pendingOutputAccessors), Promise.all(pendingSamplers), Promise.all(pendingTargets)]).then(function (dependencies) {
  58412. var nodes = dependencies[0];
  58413. var inputAccessors = dependencies[1];
  58414. var outputAccessors = dependencies[2];
  58415. var samplers = dependencies[3];
  58416. var targets = dependencies[4];
  58417. var tracks = [];
  58418. var _loop2 = function _loop2() {
  58419. var node = nodes[_i7];
  58420. var inputAccessor = inputAccessors[_i7];
  58421. var outputAccessor = outputAccessors[_i7];
  58422. var sampler = samplers[_i7];
  58423. var target = targets[_i7];
  58424. if (node === undefined) return 1; // continue
  58425. node.updateMatrix();
  58426. var TypedKeyframeTrack;
  58427. switch (PATH_PROPERTIES[target.path]) {
  58428. case PATH_PROPERTIES.weights:
  58429. TypedKeyframeTrack = NumberKeyframeTrack;
  58430. break;
  58431. case PATH_PROPERTIES.rotation:
  58432. TypedKeyframeTrack = QuaternionKeyframeTrack;
  58433. break;
  58434. case PATH_PROPERTIES.position:
  58435. case PATH_PROPERTIES.scale:
  58436. default:
  58437. TypedKeyframeTrack = VectorKeyframeTrack;
  58438. break;
  58439. }
  58440. var targetName = node.name ? node.name : node.uuid;
  58441. var interpolation = sampler.interpolation !== undefined ? INTERPOLATION[sampler.interpolation] : InterpolateLinear;
  58442. var targetNames = [];
  58443. if (PATH_PROPERTIES[target.path] === PATH_PROPERTIES.weights) {
  58444. node.traverse(function (object) {
  58445. if (object.morphTargetInfluences) {
  58446. targetNames.push(object.name ? object.name : object.uuid);
  58447. }
  58448. });
  58449. } else {
  58450. targetNames.push(targetName);
  58451. }
  58452. var outputArray = outputAccessor.array;
  58453. if (outputAccessor.normalized) {
  58454. var scale = getNormalizedComponentScale(outputArray.constructor);
  58455. var scaled = new Float32Array(outputArray.length);
  58456. for (var j = 0, jl = outputArray.length; j < jl; j++) {
  58457. scaled[j] = outputArray[j] * scale;
  58458. }
  58459. outputArray = scaled;
  58460. }
  58461. for (var _j = 0, _jl = targetNames.length; _j < _jl; _j++) {
  58462. var track = new TypedKeyframeTrack(targetNames[_j] + '.' + PATH_PROPERTIES[target.path], inputAccessor.array, outputArray, interpolation);
  58463. // Override interpolation with custom factory method.
  58464. if (sampler.interpolation === 'CUBICSPLINE') {
  58465. track.createInterpolant = function InterpolantFactoryMethodGLTFCubicSpline(result) {
  58466. // A CUBICSPLINE keyframe in glTF has three output values for each input value,
  58467. // representing inTangent, splineVertex, and outTangent. As a result, track.getValueSize()
  58468. // must be divided by three to get the interpolant's sampleSize argument.
  58469. var interpolantType = this instanceof QuaternionKeyframeTrack ? GLTFCubicSplineQuaternionInterpolant : GLTFCubicSplineInterpolant;
  58470. return new interpolantType(this.times, this.values, this.getValueSize() / 3, result);
  58471. };
  58472. // Mark as CUBICSPLINE. `track.getInterpolation()` doesn't support custom interpolants.
  58473. track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline = true;
  58474. }
  58475. tracks.push(track);
  58476. }
  58477. };
  58478. for (var _i7 = 0, _il6 = nodes.length; _i7 < _il6; _i7++) {
  58479. if (_loop2()) continue;
  58480. }
  58481. var name = animationDef.name ? animationDef.name : 'animation_' + animationIndex;
  58482. return new AnimationClip(name, undefined, tracks);
  58483. });
  58484. }
  58485. createNodeMesh(nodeIndex) {
  58486. var json = this.json;
  58487. var parser = this;
  58488. var nodeDef = json.nodes[nodeIndex];
  58489. if (nodeDef.mesh === undefined) return null;
  58490. return parser.getDependency('mesh', nodeDef.mesh).then(function (mesh) {
  58491. var node = parser._getNodeRef(parser.meshCache, nodeDef.mesh, mesh);
  58492. // if weights are provided on the node, override weights on the mesh.
  58493. if (nodeDef.weights !== undefined) {
  58494. node.traverse(function (o) {
  58495. if (!o.isMesh) return;
  58496. for (var i = 0, il = nodeDef.weights.length; i < il; i++) {
  58497. o.morphTargetInfluences[i] = nodeDef.weights[i];
  58498. }
  58499. });
  58500. }
  58501. return node;
  58502. });
  58503. }
  58504. /**
  58505. * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#nodes-and-hierarchy
  58506. * @param {number} nodeIndex
  58507. * @return {Promise<Object3D>}
  58508. */
  58509. loadNode(nodeIndex) {
  58510. var json = this.json;
  58511. var extensions = this.extensions;
  58512. var parser = this;
  58513. var nodeDef = json.nodes[nodeIndex];
  58514. // reserve node's name before its dependencies, so the root has the intended name.
  58515. var nodeName = nodeDef.name ? parser.createUniqueName(nodeDef.name) : '';
  58516. return function () {
  58517. var pending = [];
  58518. var meshPromise = parser._invokeOne(function (ext) {
  58519. return ext.createNodeMesh && ext.createNodeMesh(nodeIndex);
  58520. });
  58521. if (meshPromise) {
  58522. pending.push(meshPromise);
  58523. }
  58524. if (nodeDef.camera !== undefined) {
  58525. pending.push(parser.getDependency('camera', nodeDef.camera).then(function (camera) {
  58526. return parser._getNodeRef(parser.cameraCache, nodeDef.camera, camera);
  58527. }));
  58528. }
  58529. parser._invokeAll(function (ext) {
  58530. return ext.createNodeAttachment && ext.createNodeAttachment(nodeIndex);
  58531. }).forEach(function (promise) {
  58532. pending.push(promise);
  58533. });
  58534. return Promise.all(pending);
  58535. }().then(function (objects) {
  58536. var node;
  58537. // .isBone isn't in glTF spec. See ._markDefs
  58538. if (nodeDef.isBone === true) {
  58539. node = new Bone();
  58540. } else if (objects.length > 1) {
  58541. node = new Group();
  58542. } else if (objects.length === 1) {
  58543. node = objects[0];
  58544. } else {
  58545. node = new Object3D();
  58546. }
  58547. if (node !== objects[0]) {
  58548. for (var i = 0, il = objects.length; i < il; i++) {
  58549. node.add(objects[i]);
  58550. }
  58551. }
  58552. if (nodeDef.name) {
  58553. node.userData.name = nodeDef.name;
  58554. node.name = nodeName;
  58555. }
  58556. assignExtrasToUserData(node, nodeDef);
  58557. if (nodeDef.extensions) addUnknownExtensionsToUserData(extensions, node, nodeDef);
  58558. if (nodeDef.matrix !== undefined) {
  58559. var matrix = new Matrix4();
  58560. matrix.fromArray(nodeDef.matrix);
  58561. node.applyMatrix4(matrix);
  58562. } else {
  58563. if (nodeDef.translation !== undefined) {
  58564. node.position.fromArray(nodeDef.translation);
  58565. }
  58566. if (nodeDef.rotation !== undefined) {
  58567. node.quaternion.fromArray(nodeDef.rotation);
  58568. }
  58569. if (nodeDef.scale !== undefined) {
  58570. node.scale.fromArray(nodeDef.scale);
  58571. }
  58572. }
  58573. if (!parser.associations.has(node)) {
  58574. parser.associations.set(node, {});
  58575. }
  58576. parser.associations.get(node).nodes = nodeIndex;
  58577. return node;
  58578. });
  58579. }
  58580. /**
  58581. * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#scenes
  58582. * @param {number} sceneIndex
  58583. * @return {Promise<Group>}
  58584. */
  58585. loadScene(sceneIndex) {
  58586. var json = this.json;
  58587. var extensions = this.extensions;
  58588. var sceneDef = this.json.scenes[sceneIndex];
  58589. var parser = this;
  58590. // Loader returns Group, not Scene.
  58591. // See: https://github.com/mrdoob/three.js/issues/18342#issuecomment-578981172
  58592. var scene = new Group();
  58593. if (sceneDef.name) scene.name = parser.createUniqueName(sceneDef.name);
  58594. assignExtrasToUserData(scene, sceneDef);
  58595. if (sceneDef.extensions) addUnknownExtensionsToUserData(extensions, scene, sceneDef);
  58596. var nodeIds = sceneDef.nodes || [];
  58597. var pending = [];
  58598. for (var i = 0, il = nodeIds.length; i < il; i++) {
  58599. pending.push(buildNodeHierarchy(nodeIds[i], scene, json, parser));
  58600. }
  58601. return Promise.all(pending).then(function () {
  58602. // Removes dangling associations, associations that reference a node that
  58603. // didn't make it into the scene.
  58604. var reduceAssociations = node => {
  58605. var reducedAssociations = new Map();
  58606. for (var [key, value] of parser.associations) {
  58607. if (key instanceof Material || key instanceof Texture) {
  58608. reducedAssociations.set(key, value);
  58609. }
  58610. }
  58611. node.traverse(node => {
  58612. var mappings = parser.associations.get(node);
  58613. if (mappings != null) {
  58614. reducedAssociations.set(node, mappings);
  58615. }
  58616. });
  58617. return reducedAssociations;
  58618. };
  58619. parser.associations = reduceAssociations(scene);
  58620. return scene;
  58621. });
  58622. }
  58623. }
  58624. function buildNodeHierarchy(nodeId, parentObject, json, parser) {
  58625. var nodeDef = json.nodes[nodeId];
  58626. return parser.getDependency('node', nodeId).then(function (node) {
  58627. if (nodeDef.skin === undefined) return node;
  58628. // build skeleton here as well
  58629. var skinEntry;
  58630. return parser.getDependency('skin', nodeDef.skin).then(function (skin) {
  58631. skinEntry = skin;
  58632. var pendingJoints = [];
  58633. for (var i = 0, il = skinEntry.joints.length; i < il; i++) {
  58634. pendingJoints.push(parser.getDependency('node', skinEntry.joints[i]));
  58635. }
  58636. return Promise.all(pendingJoints);
  58637. }).then(function (jointNodes) {
  58638. node.traverse(function (mesh) {
  58639. if (!mesh.isMesh) return;
  58640. var bones = [];
  58641. var boneInverses = [];
  58642. for (var j = 0, jl = jointNodes.length; j < jl; j++) {
  58643. var jointNode = jointNodes[j];
  58644. if (jointNode) {
  58645. bones.push(jointNode);
  58646. var mat = new Matrix4();
  58647. if (skinEntry.inverseBindMatrices !== undefined) {
  58648. mat.fromArray(skinEntry.inverseBindMatrices.array, j * 16);
  58649. }
  58650. boneInverses.push(mat);
  58651. } else {
  58652. console.warn('THREE.GLTFLoader: Joint "%s" could not be found.', skinEntry.joints[j]);
  58653. }
  58654. }
  58655. mesh.bind(new Skeleton(bones, boneInverses), mesh.matrixWorld);
  58656. });
  58657. return node;
  58658. });
  58659. }).then(function (node) {
  58660. // build node hierachy
  58661. parentObject.add(node);
  58662. var pending = [];
  58663. if (nodeDef.children) {
  58664. var children = nodeDef.children;
  58665. for (var i = 0, il = children.length; i < il; i++) {
  58666. var child = children[i];
  58667. pending.push(buildNodeHierarchy(child, node, json, parser));
  58668. }
  58669. }
  58670. return Promise.all(pending);
  58671. });
  58672. }
  58673. /**
  58674. * @param {BufferGeometry} geometry
  58675. * @param {GLTF.Primitive} primitiveDef
  58676. * @param {GLTFParser} parser
  58677. */
  58678. function computeBounds(geometry, primitiveDef, parser) {
  58679. var attributes = primitiveDef.attributes;
  58680. var box = new Box3();
  58681. if (attributes.POSITION !== undefined) {
  58682. var accessor = parser.json.accessors[attributes.POSITION];
  58683. var min = accessor.min;
  58684. var max = accessor.max;
  58685. // glTF requires 'min' and 'max', but VRM (which extends glTF) currently ignores that requirement.
  58686. if (min !== undefined && max !== undefined) {
  58687. box.set(new Vector3(min[0], min[1], min[2]), new Vector3(max[0], max[1], max[2]));
  58688. if (accessor.normalized) {
  58689. var boxScale = getNormalizedComponentScale(WEBGL_COMPONENT_TYPES[accessor.componentType]);
  58690. box.min.multiplyScalar(boxScale);
  58691. box.max.multiplyScalar(boxScale);
  58692. }
  58693. } else {
  58694. console.warn('THREE.GLTFLoader: Missing min/max properties for accessor POSITION.');
  58695. return;
  58696. }
  58697. } else {
  58698. return;
  58699. }
  58700. var targets = primitiveDef.targets;
  58701. if (targets !== undefined) {
  58702. var maxDisplacement = new Vector3();
  58703. var vector = new Vector3();
  58704. for (var i = 0, il = targets.length; i < il; i++) {
  58705. var target = targets[i];
  58706. if (target.POSITION !== undefined) {
  58707. var _accessor = parser.json.accessors[target.POSITION];
  58708. var _min = _accessor.min;
  58709. var _max = _accessor.max;
  58710. // glTF requires 'min' and 'max', but VRM (which extends glTF) currently ignores that requirement.
  58711. if (_min !== undefined && _max !== undefined) {
  58712. // we need to get max of absolute components because target weight is [-1,1]
  58713. vector.setX(Math.max(Math.abs(_min[0]), Math.abs(_max[0])));
  58714. vector.setY(Math.max(Math.abs(_min[1]), Math.abs(_max[1])));
  58715. vector.setZ(Math.max(Math.abs(_min[2]), Math.abs(_max[2])));
  58716. if (_accessor.normalized) {
  58717. var _boxScale = getNormalizedComponentScale(WEBGL_COMPONENT_TYPES[_accessor.componentType]);
  58718. vector.multiplyScalar(_boxScale);
  58719. }
  58720. // Note: this assumes that the sum of all weights is at most 1. This isn't quite correct - it's more conservative
  58721. // to assume that each target can have a max weight of 1. However, for some use cases - notably, when morph targets
  58722. // are used to implement key-frame animations and as such only two are active at a time - this results in very large
  58723. // boxes. So for now we make a box that's sometimes a touch too small but is hopefully mostly of reasonable size.
  58724. maxDisplacement.max(vector);
  58725. } else {
  58726. console.warn('THREE.GLTFLoader: Missing min/max properties for accessor POSITION.');
  58727. }
  58728. }
  58729. }
  58730. // As per comment above this box isn't conservative, but has a reasonable size for a very large number of morph targets.
  58731. box.expandByVector(maxDisplacement);
  58732. }
  58733. geometry.boundingBox = box;
  58734. var sphere = new Sphere();
  58735. box.getCenter(sphere.center);
  58736. sphere.radius = box.min.distanceTo(box.max) / 2;
  58737. geometry.boundingSphere = sphere;
  58738. }
  58739. /**
  58740. * @param {BufferGeometry} geometry
  58741. * @param {GLTF.Primitive} primitiveDef
  58742. * @param {GLTFParser} parser
  58743. * @return {Promise<BufferGeometry>}
  58744. */
  58745. function addPrimitiveAttributes(geometry, primitiveDef, parser) {
  58746. var attributes = primitiveDef.attributes;
  58747. var pending = [];
  58748. function assignAttributeAccessor(accessorIndex, attributeName) {
  58749. return parser.getDependency('accessor', accessorIndex).then(function (accessor) {
  58750. geometry.setAttribute(attributeName, accessor);
  58751. });
  58752. }
  58753. for (var gltfAttributeName in attributes) {
  58754. var threeAttributeName = ATTRIBUTES[gltfAttributeName] || gltfAttributeName.toLowerCase();
  58755. // Skip attributes already provided by e.g. Draco extension.
  58756. if (threeAttributeName in geometry.attributes) continue;
  58757. pending.push(assignAttributeAccessor(attributes[gltfAttributeName], threeAttributeName));
  58758. }
  58759. if (primitiveDef.indices !== undefined && !geometry.index) {
  58760. var accessor = parser.getDependency('accessor', primitiveDef.indices).then(function (accessor) {
  58761. geometry.setIndex(accessor);
  58762. });
  58763. pending.push(accessor);
  58764. }
  58765. assignExtrasToUserData(geometry, primitiveDef);
  58766. computeBounds(geometry, primitiveDef, parser);
  58767. return Promise.all(pending).then(function () {
  58768. return primitiveDef.targets !== undefined ? addMorphTargets(geometry, primitiveDef.targets, parser) : geometry;
  58769. });
  58770. }
  58771. /**
  58772. * @param {BufferGeometry} geometry
  58773. * @param {Number} drawMode
  58774. * @return {BufferGeometry}
  58775. */
  58776. function toTrianglesDrawMode(geometry, drawMode) {
  58777. var index = geometry.getIndex();
  58778. // generate index if not present
  58779. if (index === null) {
  58780. var indices = [];
  58781. var position = geometry.getAttribute('position');
  58782. if (position !== undefined) {
  58783. for (var i = 0; i < position.count; i++) {
  58784. indices.push(i);
  58785. }
  58786. geometry.setIndex(indices);
  58787. index = geometry.getIndex();
  58788. } else {
  58789. console.error('THREE.GLTFLoader.toTrianglesDrawMode(): Undefined position attribute. Processing not possible.');
  58790. return geometry;
  58791. }
  58792. }
  58793. //
  58794. var numberOfTriangles = index.count - 2;
  58795. var newIndices = [];
  58796. if (drawMode === TriangleFanDrawMode) {
  58797. // gl.TRIANGLE_FAN
  58798. for (var _i8 = 1; _i8 <= numberOfTriangles; _i8++) {
  58799. newIndices.push(index.getX(0));
  58800. newIndices.push(index.getX(_i8));
  58801. newIndices.push(index.getX(_i8 + 1));
  58802. }
  58803. } else {
  58804. // gl.TRIANGLE_STRIP
  58805. for (var _i9 = 0; _i9 < numberOfTriangles; _i9++) {
  58806. if (_i9 % 2 === 0) {
  58807. newIndices.push(index.getX(_i9));
  58808. newIndices.push(index.getX(_i9 + 1));
  58809. newIndices.push(index.getX(_i9 + 2));
  58810. } else {
  58811. newIndices.push(index.getX(_i9 + 2));
  58812. newIndices.push(index.getX(_i9 + 1));
  58813. newIndices.push(index.getX(_i9));
  58814. }
  58815. }
  58816. }
  58817. if (newIndices.length / 3 !== numberOfTriangles) {
  58818. console.error('THREE.GLTFLoader.toTrianglesDrawMode(): Unable to generate correct amount of triangles.');
  58819. }
  58820. // build final geometry
  58821. var newGeometry = geometry.clone();
  58822. newGeometry.setIndex(newIndices);
  58823. return newGeometry;
  58824. }
  58825. var globalThis=window;//add 有的app没有globalThis. 2023.1
  58826. var rtcCenterGlobal=false;//默认false,也就是scale.z要乘以-1
  58827. /*! *****************************************************************************
  58828. github: https://github.com/nytimes/three-loader-3dtiles
  58829. Copyright (c) Microsoft Corporation.
  58830. Permission to use, copy, modify, and/or distribute this software for any
  58831. purpose with or without fee is hereby granted.
  58832. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  58833. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  58834. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  58835. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  58836. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  58837. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  58838. PERFORMANCE OF THIS SOFTWARE.
  58839. ***************************************************************************** */var visiGeoCount=0;var maxVertexVisi=5e6;var maxTexVisi=500;var maxDepth=100;function getGpuMemoryUsage(){var win=arguments.length>0&&arguments[0]!==undefined?arguments[0]:window;//总的
  58840. var c=0;viewer.setAllTilesets(model=>{var tileset3D=model.runtime.getTileset();c+=tileset3D.gpuMemoryUsageInBytes;});if(win.parent!=win){//还有父级页面。 暂时只有子级需要考虑父级,假设父级在前台时子级已经销毁
  58841. c+=getGpuMemoryUsage(win.parent);}viewer.tiles3dMemoryUsage=c;return c;}function __awaiter(thisArg,_arguments,P,generator){function adopt(value){return value instanceof P?value:new P(function(resolve){resolve(value);});}return new(P||(P=Promise))(function(resolve,reject){function fulfilled(value){try{step(generator.next(value));}catch(e){reject(e);}}function rejected(value){try{step(generator["throw"](value));}catch(e){reject(e);}}function step(result){result.done?resolve(result.value):adopt(result.value).then(fulfilled,rejected);}step((generator=generator.apply(thisArg,_arguments||[])).next());});}function assert$7(condition,message){if(!condition){throw new Error(message||'loader assertion failed.');}}var isBrowser$2=Boolean(typeof process!=='object'||String(process)!=='[object process]'||process.browser);var matches$1=typeof process!=='undefined'&&process.version&&/v([0-9]*)/.exec(process.version);matches$1&&parseFloat(matches$1[1])||0;var VERSION$8="3.1.4";function assert$6(condition,message){if(!condition){throw new Error(message||'loaders.gl assertion failed.');}}var globals$1={self:typeof self!=='undefined'&&self,window:typeof window!=='undefined'&&window,global:typeof global!=='undefined'&&global,document:typeof document!=='undefined'&&document};var global_=globals$1.global||globals$1.self||globals$1.window||{};var isBrowser$1=typeof process!=='object'||String(process)!=='[object process]'||process.browser;var isWorker=typeof importScripts==='function';var isMobile=typeof window!=='undefined'&&typeof window.orientation!=='undefined';var matches=typeof process!=='undefined'&&process.version&&/v([0-9]*)/.exec(process.version);matches&&parseFloat(matches[1])||0;function _defineProperty$1(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else {obj[key]=value;}return obj;}class WorkerJob{constructor(jobName,workerThread){_defineProperty$1(this,"name",void 0);_defineProperty$1(this,"workerThread",void 0);_defineProperty$1(this,"isRunning",void 0);_defineProperty$1(this,"result",void 0);_defineProperty$1(this,"_resolve",void 0);_defineProperty$1(this,"_reject",void 0);this.name=jobName;this.workerThread=workerThread;this.isRunning=true;this._resolve=()=>{};this._reject=()=>{};this.result=new Promise((resolve,reject)=>{this._resolve=resolve;this._reject=reject;});}postMessage(type,payload){this.workerThread.postMessage({source:'loaders.gl',type,payload});}done(value){assert$6(this.isRunning);this.isRunning=false;this._resolve(value);}error(error){assert$6(this.isRunning);this.isRunning=false;this._reject(error);}}var workerURLCache=new Map();function getLoadableWorkerURL(props){assert$6(props.source&&!props.url||!props.source&&props.url);var workerURL=workerURLCache.get(props.source||props.url);if(!workerURL){if(props.url){workerURL=getLoadableWorkerURLFromURL(props.url);workerURLCache.set(props.url,workerURL);}if(props.source){workerURL=getLoadableWorkerURLFromSource(props.source);workerURLCache.set(props.source,workerURL);}}assert$6(workerURL);return workerURL;}function getLoadableWorkerURLFromURL(url){if(!url.startsWith('http')){return url;}var workerSource=buildScriptSource(url);return getLoadableWorkerURLFromSource(workerSource);}function getLoadableWorkerURLFromSource(workerSource){var blob=new Blob([workerSource],{type:'application/javascript'});return URL.createObjectURL(blob);}function buildScriptSource(workerUrl){return "try {\n importScripts('".concat(workerUrl,"');\n} catch (error) {\n console.error(error);\n throw error;\n}");}function getTransferList(object){var recursive=arguments.length>1&&arguments[1]!==undefined?arguments[1]:true;var transfers=arguments.length>2?arguments[2]:undefined;var transfersSet=transfers||new Set();if(!object);else if(isTransferable(object)){transfersSet.add(object);}else if(isTransferable(object.buffer)){transfersSet.add(object.buffer);}else if(ArrayBuffer.isView(object));else if(recursive&&typeof object==='object'){for(var key in object){getTransferList(object[key],recursive,transfersSet);}}return transfers===undefined?Array.from(transfersSet):[];}function isTransferable(object){if(!object){return false;}if(object instanceof ArrayBuffer){return true;}if(typeof MessagePort!=='undefined'&&object instanceof MessagePort){return true;}if(typeof ImageBitmap!=='undefined'&&object instanceof ImageBitmap){return true;}if(typeof OffscreenCanvas!=='undefined'&&object instanceof OffscreenCanvas){return true;}return false;}var NOOP=()=>{};class WorkerThread{static isSupported(){return typeof Worker!=='undefined';}constructor(props){_defineProperty$1(this,"name",void 0);_defineProperty$1(this,"source",void 0);_defineProperty$1(this,"url",void 0);_defineProperty$1(this,"terminated",false);_defineProperty$1(this,"worker",void 0);_defineProperty$1(this,"onMessage",void 0);_defineProperty$1(this,"onError",void 0);_defineProperty$1(this,"_loadableURL",'');var{name,source,url}=props;assert$6(source||url);this.name=name;this.source=source;this.url=url;this.onMessage=NOOP;this.onError=error=>console.log(error);this.worker=this._createBrowserWorker();}destroy(){this.onMessage=NOOP;this.onError=NOOP;this.worker.terminate();this.terminated=true;}get isRunning(){return Boolean(this.onMessage);}postMessage(data,transferList){transferList=transferList||getTransferList(data);this.worker.postMessage(data,transferList);}_getErrorFromErrorEvent(event){var message='Failed to load ';message+="worker ".concat(this.name," from ").concat(this.url,". ");if(event.message){message+="".concat(event.message," in ");}if(event.lineno){message+=":".concat(event.lineno,":").concat(event.colno);}return new Error(message);}_createBrowserWorker(){this._loadableURL=getLoadableWorkerURL({source:this.source,url:this.url});var worker=new Worker(this._loadableURL,{name:this.name});worker.onmessage=event=>{if(!event.data){this.onError(new Error('No data received'));}else {this.onMessage(event.data);}};worker.onerror=error=>{this.onError(this._getErrorFromErrorEvent(error));this.terminated=true;};worker.onmessageerror=event=>console.error(event);return worker;}}class WorkerPool$2{constructor(props){_defineProperty$1(this,"name",'unnamed');_defineProperty$1(this,"source",void 0);_defineProperty$1(this,"url",void 0);_defineProperty$1(this,"maxConcurrency",1);_defineProperty$1(this,"maxMobileConcurrency",1);_defineProperty$1(this,"onDebug",()=>{});_defineProperty$1(this,"reuseWorkers",true);_defineProperty$1(this,"props",{});_defineProperty$1(this,"jobQueue",[]);_defineProperty$1(this,"idleQueue",[]);_defineProperty$1(this,"count",0);_defineProperty$1(this,"isDestroyed",false);this.source=props.source;this.url=props.url;this.setProps(props);}destroy(){this.idleQueue.forEach(worker=>worker.destroy());this.isDestroyed=true;}setProps(props){this.props=_objectSpread2(_objectSpread2({},this.props),props);if(props.name!==undefined){this.name=props.name;}if(props.maxConcurrency!==undefined){this.maxConcurrency=props.maxConcurrency;}if(props.maxMobileConcurrency!==undefined){this.maxMobileConcurrency=props.maxMobileConcurrency;}if(props.reuseWorkers!==undefined){this.reuseWorkers=props.reuseWorkers;}if(props.onDebug!==undefined){this.onDebug=props.onDebug;}}async startJob(name){var onMessage=arguments.length>1&&arguments[1]!==undefined?arguments[1]:(job,type,data)=>job.done(data);var onError=arguments.length>2&&arguments[2]!==undefined?arguments[2]:(job,error)=>job.error(error);var startPromise=new Promise(onStart=>{this.jobQueue.push({name,onMessage,onError,onStart});return this;});this._startQueuedJob();return await startPromise;}async _startQueuedJob(){if(!this.jobQueue.length){return;}var workerThread=this._getAvailableWorker();if(!workerThread){return;}var queuedJob=this.jobQueue.shift();if(queuedJob){this.onDebug({message:'Starting job',name:queuedJob.name,workerThread,backlog:this.jobQueue.length});var job=new WorkerJob(queuedJob.name,workerThread);workerThread.onMessage=data=>queuedJob.onMessage(job,data.type,data.payload);workerThread.onError=error=>queuedJob.onError(job,error);queuedJob.onStart(job);try{await job.result;}finally{this.returnWorkerToQueue(workerThread);}}}returnWorkerToQueue(worker){var shouldDestroyWorker=this.isDestroyed||!this.reuseWorkers||this.count>this._getMaxConcurrency();if(shouldDestroyWorker){worker.destroy();this.count--;}else {this.idleQueue.push(worker);}if(!this.isDestroyed){this._startQueuedJob();}}_getAvailableWorker(){if(this.idleQueue.length>0){return this.idleQueue.shift()||null;}if(this.count<this._getMaxConcurrency()){this.count++;var _name="".concat(this.name.toLowerCase()," (#").concat(this.count," of ").concat(this.maxConcurrency,")");return new WorkerThread({name:_name,source:this.source,url:this.url});}return null;}_getMaxConcurrency(){return isMobile?this.maxMobileConcurrency:this.maxConcurrency;}}var DEFAULT_PROPS$3={maxConcurrency:3,maxMobileConcurrency:1,onDebug:()=>{},reuseWorkers:true};class WorkerFarm{static isSupported(){return WorkerThread.isSupported();}static getWorkerFarm(){var props=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};WorkerFarm._workerFarm=WorkerFarm._workerFarm||new WorkerFarm({});WorkerFarm._workerFarm.setProps(props);return WorkerFarm._workerFarm;}constructor(props){_defineProperty$1(this,"props",void 0);_defineProperty$1(this,"workerPools",new Map());this.props=_objectSpread2({},DEFAULT_PROPS$3);this.setProps(props);this.workerPools=new Map();}destroy(){for(var workerPool of this.workerPools.values()){workerPool.destroy();}}setProps(props){this.props=_objectSpread2(_objectSpread2({},this.props),props);for(var workerPool of this.workerPools.values()){workerPool.setProps(this._getWorkerPoolProps());}}getWorkerPool(options){var{name,source,url}=options;var workerPool=this.workerPools.get(name);if(!workerPool){workerPool=new WorkerPool$2({name,source,url});workerPool.setProps(this._getWorkerPoolProps());this.workerPools.set(name,workerPool);}return workerPool;}_getWorkerPoolProps(){return {maxConcurrency:this.props.maxConcurrency,maxMobileConcurrency:this.props.maxMobileConcurrency,reuseWorkers:this.props.reuseWorkers,onDebug:this.props.onDebug};}}_defineProperty$1(WorkerFarm,"_workerFarm",void 0);var NPM_TAG='latest';function getWorkerURL(worker){var options=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var workerOptions=options[worker.id]||{};var workerFile="".concat(worker.id,"-worker.js");var url=workerOptions.workerUrl;if(!url&&worker.id==='compression'){url=options.workerUrl;}if(options._workerType==='test'){url="modules/".concat(worker.module,"/dist/").concat(workerFile);}if(!url){var version=worker.version;if(version==='latest'){version=NPM_TAG;}var versionTag=version?"@".concat(version):'';url="https://unpkg.com/@loaders.gl/".concat(worker.module).concat(versionTag,"/dist/").concat(workerFile);}assert$6(url);return url;}function validateWorkerVersion(worker){var coreVersion=arguments.length>1&&arguments[1]!==undefined?arguments[1]:VERSION$8;assert$6(worker,'no worker provided');var workerVersion=worker.version;if(!coreVersion||!workerVersion){return false;}return true;}var ChildProcessProxy={};var node=/*#__PURE__*/Object.freeze(/*#__PURE__*/Object.assign(/*#__PURE__*/Object.create(null),ChildProcessProxy,{'default':ChildProcessProxy}));var VERSION$7="3.1.4";var loadLibraryPromises={};async function loadLibrary(libraryUrl){var moduleName=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var options=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};if(moduleName){libraryUrl=getLibraryUrl(libraryUrl,moduleName,options);}loadLibraryPromises[libraryUrl]=loadLibraryPromises[libraryUrl]||loadLibraryFromFile(libraryUrl);return await loadLibraryPromises[libraryUrl];}function getLibraryUrl(library,moduleName,options){if(library.startsWith('http')){return library;}var modules=options.modules||{};if(modules[library]){return modules[library];}if(!isBrowser$1){return "modules/".concat(moduleName,"/dist/libs/").concat(library);}if(options.CDN){assert$6(options.CDN.startsWith('http'));return "".concat(options.CDN,"/").concat(moduleName,"@").concat(VERSION$7,"/dist/libs/").concat(library);}if(isWorker){return "../src/libs/".concat(library);}return "modules/".concat(moduleName,"/src/libs/").concat(library);}async function loadLibraryFromFile(libraryUrl){if(libraryUrl.endsWith('wasm')){var _response=await fetch(libraryUrl);return await _response.arrayBuffer();}if(!isBrowser$1){try{return node&&ChildProcessProxy.requireFromFile&&(await ChildProcessProxy.requireFromFile(libraryUrl));}catch(_unused){return null;}}if(isWorker){return importScripts(libraryUrl);}var response=await fetch(libraryUrl);var scriptSource=await response.text();return loadLibraryFromString(scriptSource,libraryUrl);}function loadLibraryFromString(scriptSource,id){if(!isBrowser$1){return ChildProcessProxy.requireFromString&&ChildProcessProxy.requireFromString(scriptSource,id);}if(isWorker){eval.call(global_,scriptSource);return null;}var script=document.createElement('script');script.id=id;try{script.appendChild(document.createTextNode(scriptSource));}catch(e){script.text=scriptSource;}document.body.appendChild(script);return null;}function canParseWithWorker(loader,options){if(!WorkerFarm.isSupported()){return false;}return loader.worker&&(options===null||options===void 0?void 0:options.worker);}async function parseWithWorker(loader,data,options,context,parseOnMainThread){var name=loader.id;var url=getWorkerURL(loader,options);var workerFarm=WorkerFarm.getWorkerFarm(options);var workerPool=workerFarm.getWorkerPool({name,url});options=JSON.parse(JSON.stringify(options));var job=await workerPool.startJob('process-on-worker',onMessage.bind(null,parseOnMainThread));job.postMessage('process',{input:data,options});var result=await job.result;return await result.result;}async function onMessage(parseOnMainThread,job,type,payload){switch(type){case'done':job.done(payload);break;case'error':job.error(new Error(payload.error));break;case'process':var{id,input,options}=payload;try{var result=await parseOnMainThread(input,options);job.postMessage('done',{id,result});}catch(error){var message=error instanceof Error?error.message:'unknown error';job.postMessage('error',{id,error:message});}break;default:console.warn("parse-with-worker unknown message ".concat(type));}}function getFirstCharacters$1(data){var length=arguments.length>1&&arguments[1]!==undefined?arguments[1]:5;if(typeof data==='string'){return data.slice(0,length);}else if(ArrayBuffer.isView(data)){return getMagicString$3(data.buffer,data.byteOffset,length);}else if(data instanceof ArrayBuffer){var byteOffset=0;return getMagicString$3(data,byteOffset,length);}return '';}function getMagicString$3(arrayBuffer,byteOffset,length){if(arrayBuffer.byteLength<=byteOffset+length){return '';}var dataView=new DataView(arrayBuffer);var magic='';for(var _i=0;_i<length;_i++){magic+=String.fromCharCode(dataView.getUint8(byteOffset+_i));}return magic;}function parseJSON(string){try{return JSON.parse(string);}catch(_){throw new Error("Failed to parse JSON from data starting with \"".concat(getFirstCharacters$1(string),"\""));}}function isBuffer$1(value){return value&&typeof value==='object'&&value.isBuffer;}function bufferToArrayBuffer(buffer){if(isBuffer$1(buffer)){var typedArray=new Uint8Array(buffer.buffer,buffer.byteOffset,buffer.length);return typedArray.slice().buffer;}return buffer;}function toArrayBuffer(data){if(isBuffer$1(data)){return bufferToArrayBuffer(data);}if(data instanceof ArrayBuffer){return data;}if(ArrayBuffer.isView(data)){if(data.byteOffset===0&&data.byteLength===data.buffer.byteLength){return data.buffer;}return data.buffer.slice(data.byteOffset,data.byteOffset+data.byteLength);}if(typeof data==='string'){var text=data;var uint8Array=new TextEncoder().encode(text);return uint8Array.buffer;}if(data&&typeof data==='object'&&data._toArrayBuffer){return data._toArrayBuffer();}throw new Error('toArrayBuffer');}function compareArrayBuffers(arrayBuffer1,arrayBuffer2,byteLength){byteLength=byteLength||arrayBuffer1.byteLength;if(arrayBuffer1.byteLength<byteLength||arrayBuffer2.byteLength<byteLength){return false;}var array1=new Uint8Array(arrayBuffer1);var array2=new Uint8Array(arrayBuffer2);for(var _i2=0;_i2<array1.length;++_i2){if(array1[_i2]!==array2[_i2]){return false;}}return true;}function concatenateArrayBuffers(){for(var _len2=arguments.length,sources=new Array(_len2),_key2=0;_key2<_len2;_key2++){sources[_key2]=arguments[_key2];}var sourceArrays=sources.map(source2=>source2 instanceof ArrayBuffer?new Uint8Array(source2):source2);var byteLength=sourceArrays.reduce((length,typedArray)=>length+typedArray.byteLength,0);var result=new Uint8Array(byteLength);var offset=0;for(var sourceArray of sourceArrays){result.set(sourceArray,offset);offset+=sourceArray.byteLength;}return result.buffer;}function sliceArrayBuffer(arrayBuffer,byteOffset,byteLength){var subArray=byteLength!==undefined?new Uint8Array(arrayBuffer).subarray(byteOffset,byteOffset+byteLength):new Uint8Array(arrayBuffer).subarray(byteOffset);var arrayCopy=new Uint8Array(subArray);return arrayCopy.buffer;}function padToNBytes(byteLength,padding){assert$7(byteLength>=0);assert$7(padding>0);return byteLength+(padding-1)&~(padding-1);}function copyToArray(source,target,targetOffset){var sourceArray;if(source instanceof ArrayBuffer){sourceArray=new Uint8Array(source);}else {var srcByteOffset=source.byteOffset;var srcByteLength=source.byteLength;sourceArray=new Uint8Array(source.buffer||source.arrayBuffer,srcByteOffset,srcByteLength);}target.set(sourceArray,targetOffset);return targetOffset+padToNBytes(sourceArray.byteLength,4);}async function concatenateArrayBuffersAsync(asyncIterator){var arrayBuffers=[];var _iteratorAbruptCompletion=false;var _didIteratorError=false;var _iteratorError;try{for(var _iterator=_asyncIterator(asyncIterator),_step;_iteratorAbruptCompletion=!(_step=await _iterator.next()).done;_iteratorAbruptCompletion=false){var chunk=_step.value;{arrayBuffers.push(chunk);}}}catch(err){_didIteratorError=true;_iteratorError=err;}finally{try{if(_iteratorAbruptCompletion&&_iterator.return!=null){await _iterator.return();}}finally{if(_didIteratorError){throw _iteratorError;}}}return concatenateArrayBuffers(...arrayBuffers);}function getHiResTimestamp$1(){var timestamp;if(typeof window!=='undefined'&&window.performance){timestamp=window.performance.now();}else if(typeof process!=='undefined'&&process.hrtime){var timeParts=process.hrtime();timestamp=timeParts[0]*1000+timeParts[1]/1e6;}else {timestamp=Date.now();}return timestamp;}class Stat{constructor(name,type){_defineProperty$1(this,"name",void 0);_defineProperty$1(this,"type",void 0);_defineProperty$1(this,"sampleSize",1);_defineProperty$1(this,"time",void 0);_defineProperty$1(this,"count",void 0);_defineProperty$1(this,"samples",void 0);_defineProperty$1(this,"lastTiming",void 0);_defineProperty$1(this,"lastSampleTime",void 0);_defineProperty$1(this,"lastSampleCount",void 0);_defineProperty$1(this,"_count",0);_defineProperty$1(this,"_time",0);_defineProperty$1(this,"_samples",0);_defineProperty$1(this,"_startTime",0);_defineProperty$1(this,"_timerPending",false);this.name=name;this.type=type;this.reset();}setSampleSize(samples){this.sampleSize=samples;return this;}incrementCount(){this.addCount(1);return this;}decrementCount(){this.subtractCount(1);return this;}addCount(value){this._count+=value;this._samples++;this._checkSampling();return this;}subtractCount(value){this._count-=value;this._samples++;this._checkSampling();return this;}addTime(time){this._time+=time;this.lastTiming=time;this._samples++;this._checkSampling();return this;}timeStart(){this._startTime=getHiResTimestamp$1();this._timerPending=true;return this;}timeEnd(){if(!this._timerPending){return this;}this.addTime(getHiResTimestamp$1()-this._startTime);this._timerPending=false;this._checkSampling();return this;}getSampleAverageCount(){return this.sampleSize>0?this.lastSampleCount/this.sampleSize:0;}getSampleAverageTime(){return this.sampleSize>0?this.lastSampleTime/this.sampleSize:0;}getSampleHz(){return this.lastSampleTime>0?this.sampleSize/(this.lastSampleTime/1000):0;}getAverageCount(){return this.samples>0?this.count/this.samples:0;}getAverageTime(){return this.samples>0?this.time/this.samples:0;}getHz(){return this.time>0?this.samples/(this.time/1000):0;}reset(){this.time=0;this.count=0;this.samples=0;this.lastTiming=0;this.lastSampleTime=0;this.lastSampleCount=0;this._count=0;this._time=0;this._samples=0;this._startTime=0;this._timerPending=false;return this;}_checkSampling(){if(this._samples===this.sampleSize){this.lastSampleTime=this._time;this.lastSampleCount=this._count;this.count+=this._count;this.time+=this._time;this.samples+=this._samples;this._time=0;this._count=0;this._samples=0;}}}class Stats$1{constructor(options){_defineProperty$1(this,"id",void 0);_defineProperty$1(this,"stats",{});this.id=options.id;this.stats={};this._initializeStats(options.stats);Object.seal(this);}get(name){var type=arguments.length>1&&arguments[1]!==undefined?arguments[1]:'count';return this._getOrCreate({name,type});}get size(){return Object.keys(this.stats).length;}reset(){for(var key in this.stats){this.stats[key].reset();}return this;}forEach(fn){for(var key in this.stats){fn(this.stats[key]);}}getTable(){var table={};this.forEach(stat=>{table[stat.name]={time:stat.time||0,count:stat.count||0,average:stat.getAverageTime()||0,hz:stat.getHz()||0};});return table;}_initializeStats(){var stats=arguments.length>0&&arguments[0]!==undefined?arguments[0]:[];stats.forEach(stat=>this._getOrCreate(stat));}_getOrCreate(stat){if(!stat||!stat.name){return null;}var{name,type}=stat;if(!this.stats[name]){if(stat instanceof Stat){this.stats[name]=stat;}else {this.stats[name]=new Stat(name,type);}}return this.stats[name];}}var STAT_QUEUED_REQUESTS='Queued Requests';var STAT_ACTIVE_REQUESTS='Active Requests';var STAT_CANCELLED_REQUESTS='Cancelled Requests';var STAT_QUEUED_REQUESTS_EVER='Queued Requests Ever';var STAT_ACTIVE_REQUESTS_EVER='Active Requests Ever';var DEFAULT_PROPS$2={id:'request-scheduler',throttleRequests:true,maxRequests:6};class RequestScheduler{constructor(){var props=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};_defineProperty$1(this,"props",void 0);_defineProperty$1(this,"stats",void 0);_defineProperty$1(this,"activeRequestCount",0);_defineProperty$1(this,"requestQueue",[]);_defineProperty$1(this,"requestMap",new Map());_defineProperty$1(this,"deferredUpdate",null);this.props=_objectSpread2(_objectSpread2({},DEFAULT_PROPS$2),props);this.stats=new Stats$1({id:this.props.id});this.stats.get(STAT_QUEUED_REQUESTS);this.stats.get(STAT_ACTIVE_REQUESTS);this.stats.get(STAT_CANCELLED_REQUESTS);this.stats.get(STAT_QUEUED_REQUESTS_EVER);this.stats.get(STAT_ACTIVE_REQUESTS_EVER);}scheduleRequest(handle){var getPriority=arguments.length>1&&arguments[1]!==undefined?arguments[1]:()=>0;if(!this.props.throttleRequests){return Promise.resolve({done:()=>{}});}if(this.requestMap.has(handle)){return this.requestMap.get(handle);}var request={handle,priority:0,getPriority};var promise=new Promise(resolve=>{request.resolve=resolve;return request;});this.requestQueue.push(request);this.requestMap.set(handle,promise);this._issueNewRequests();return promise;}_issueRequest(request){var{handle,resolve}=request;var isDone=false;var done=()=>{if(!isDone){isDone=true;this.requestMap.delete(handle);this.activeRequestCount--;this._issueNewRequests();}};this.activeRequestCount++;return resolve?resolve({done}):Promise.resolve({done});}_issueNewRequests(){if(!this.deferredUpdate){this.deferredUpdate=setTimeout(()=>this._issueNewRequestsAsync(),0);}}_issueNewRequestsAsync(){this.deferredUpdate=null;var freeSlots=Math.max(this.props.maxRequests-this.activeRequestCount,0);if(freeSlots===0){return;}this._updateAllRequests();for(var _i3=0;_i3<freeSlots;++_i3){var request=this.requestQueue.shift();if(request){this._issueRequest(request);}}}_updateAllRequests(){var requestQueue=this.requestQueue;for(var _i4=0;_i4<requestQueue.length;++_i4){var request=requestQueue[_i4];if(!this._updateRequest(request)){requestQueue.splice(_i4,1);this.requestMap.delete(request.handle);_i4--;}}requestQueue.sort((a,b)=>a.priority-b.priority);}_updateRequest(request){request.priority=request.getPriority(request.handle);if(request.priority<0){request.resolve(null);return false;}return true;}}var pathPrefix='';var fileAliases={};function resolvePath(filename){for(var alias in fileAliases){if(filename.startsWith(alias)){var replacement=fileAliases[alias];filename=filename.replace(alias,replacement);}}if(!filename.startsWith('http://')&&!filename.startsWith('https://')){filename="".concat(pathPrefix).concat(filename);}return filename;}function filename(url){var slashIndex=url&&url.lastIndexOf('/');return slashIndex>=0?url.substr(slashIndex+1):'';}function dirname(url){var slashIndex=url&&url.lastIndexOf('/');return slashIndex>=0?url.substr(0,slashIndex):'';}var isBoolean=x=>typeof x==='boolean';var isFunction=x=>typeof x==='function';var isObject=x=>x!==null&&typeof x==='object';var isPureObject=x=>isObject(x)&&x.constructor==={}.constructor;var isIterable=x=>x&&typeof x[Symbol.iterator]==='function';var isAsyncIterable=x=>x&&typeof x[Symbol.asyncIterator]==='function';var isResponse=x=>typeof Response!=='undefined'&&x instanceof Response||x&&x.arrayBuffer&&x.text&&x.json;var isBlob=x=>typeof Blob!=='undefined'&&x instanceof Blob;var isBuffer=x=>x&&typeof x==='object'&&x.isBuffer;var isReadableDOMStream=x=>typeof ReadableStream!=='undefined'&&x instanceof ReadableStream||isObject(x)&&isFunction(x.tee)&&isFunction(x.cancel)&&isFunction(x.getReader);var isReadableNodeStream=x=>isObject(x)&&isFunction(x.read)&&isFunction(x.pipe)&&isBoolean(x.readable);var isReadableStream=x=>isReadableDOMStream(x)||isReadableNodeStream(x);var DATA_URL_PATTERN=/^data:([-\w.]+\/[-\w.+]+)(;|,)/;var MIME_TYPE_PATTERN=/^([-\w.]+\/[-\w.+]+)/;function parseMIMEType(mimeString){var matches=MIME_TYPE_PATTERN.exec(mimeString);if(matches){return matches[1];}return mimeString;}function parseMIMETypeFromURL(url){var matches=DATA_URL_PATTERN.exec(url);if(matches){return matches[1];}return '';}var QUERY_STRING_PATTERN=/\?.*/;function getResourceUrlAndType(resource){if(isResponse(resource)){var url=stripQueryString(resource.url||'');var contentTypeHeader=resource.headers.get('content-type')||'';return {url,type:parseMIMEType(contentTypeHeader)||parseMIMETypeFromURL(url)};}if(isBlob(resource)){return {url:stripQueryString(resource.name||''),type:resource.type||''};}if(typeof resource==='string'){return {url:stripQueryString(resource),type:parseMIMETypeFromURL(resource)};}return {url:'',type:''};}function getResourceContentLength(resource){if(isResponse(resource)){return resource.headers['content-length']||-1;}if(isBlob(resource)){return resource.size;}if(typeof resource==='string'){return resource.length;}if(resource instanceof ArrayBuffer){return resource.byteLength;}if(ArrayBuffer.isView(resource)){return resource.byteLength;}return -1;}function stripQueryString(url){return url.replace(QUERY_STRING_PATTERN,'');}async function makeResponse(resource){if(isResponse(resource)){return resource;}var headers={};var contentLength=getResourceContentLength(resource);if(contentLength>=0){headers['content-length']=String(contentLength);}var{url,type}=getResourceUrlAndType(resource);if(type){headers['content-type']=type;}var initialDataUrl=await getInitialDataUrl(resource);if(initialDataUrl){headers['x-first-bytes']=initialDataUrl;}if(typeof resource==='string'){resource=new TextEncoder().encode(resource);}var response=new Response(resource,{headers});Object.defineProperty(response,'url',{value:url});return response;}async function checkResponse(response){if(!response.ok){var message=await getResponseError(response);throw new Error(message);}}async function getResponseError(response){var message="Failed to fetch resource ".concat(response.url," (").concat(response.status,"): ");try{var contentType=response.headers.get('Content-Type');var text=response.statusText;if(contentType.includes('application/json')){text+=" ".concat(await response.text());}message+=text;message=message.length>60?"".concat(message.slice(60),"..."):message;}catch(error){}return message;}async function getInitialDataUrl(resource){var INITIAL_DATA_LENGTH=5;if(typeof resource==='string'){return "data:,".concat(resource.slice(0,INITIAL_DATA_LENGTH));}if(resource instanceof Blob){var blobSlice=resource.slice(0,5);return await new Promise(resolve=>{var reader=new FileReader();reader.onload=event=>{var _event$target;return resolve(event===null||event===void 0?void 0:(_event$target=event.target)===null||_event$target===void 0?void 0:_event$target.result);};reader.readAsDataURL(blobSlice);});}if(resource instanceof ArrayBuffer){var slice=resource.slice(0,INITIAL_DATA_LENGTH);var base64=arrayBufferToBase64(slice);return "data:base64,".concat(base64);}return null;}function arrayBufferToBase64(buffer){var binary='';var bytes=new Uint8Array(buffer);for(var _i5=0;_i5<bytes.byteLength;_i5++){binary+=String.fromCharCode(bytes[_i5]);}return btoa(binary);}async function fetchFile(url,options){if(typeof url==='string'){url=resolvePath(url);var fetchOptions=options;if(options!==null&&options!==void 0&&options.fetch&&typeof(options===null||options===void 0?void 0:options.fetch)!=='function'){fetchOptions=options.fetch;}return await fetch(url,fetchOptions);}return await makeResponse(url);}function isElectron(mockUserAgent){if(typeof window!=='undefined'&&typeof window.process==='object'&&window.process.type==='renderer'){return true;}if(typeof process!=='undefined'&&typeof process.versions==='object'&&Boolean(process.versions.electron)){return true;}var realUserAgent=typeof navigator==='object'&&typeof navigator.userAgent==='string'&&navigator.userAgent;var userAgent=mockUserAgent||realUserAgent;if(userAgent&&userAgent.indexOf('Electron')>=0){return true;}return false;}function isBrowser(){var isNode=typeof process==='object'&&String(process)==='[object process]'&&!process.browser;return !isNode||isElectron();}var globals={self:typeof self!=='undefined'&&self,window:typeof window!=='undefined'&&window,global:typeof global!=='undefined'&&global,document:typeof document!=='undefined'&&document,process:typeof process==='object'&&process};var window_=globals.window||globals.self||globals.global;var process_=globals.process||{};var VERSION$6=typeof __VERSION__!=='undefined'?__VERSION__:'untranspiled source';isBrowser();function getStorage(type){try{var storage=window[type];var x='__storage_test__';storage.setItem(x,x);storage.removeItem(x);return storage;}catch(e){return null;}}class LocalStorage{constructor(id){var defaultSettings=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var type=arguments.length>2&&arguments[2]!==undefined?arguments[2]:'sessionStorage';_defineProperty$1(this,"storage",void 0);_defineProperty$1(this,"id",void 0);_defineProperty$1(this,"config",{});this.storage=getStorage(type);this.id=id;this.config={};Object.assign(this.config,defaultSettings);this._loadConfiguration();}getConfiguration(){return this.config;}setConfiguration(configuration){this.config={};return this.updateConfiguration(configuration);}updateConfiguration(configuration){Object.assign(this.config,configuration);if(this.storage){var serialized=JSON.stringify(this.config);this.storage.setItem(this.id,serialized);}return this;}_loadConfiguration(){var configuration={};if(this.storage){var serializedConfiguration=this.storage.getItem(this.id);configuration=serializedConfiguration?JSON.parse(serializedConfiguration):{};}Object.assign(this.config,configuration);return this;}}function formatTime(ms){var formatted;if(ms<10){formatted="".concat(ms.toFixed(2),"ms");}else if(ms<100){formatted="".concat(ms.toFixed(1),"ms");}else if(ms<1000){formatted="".concat(ms.toFixed(0),"ms");}else {formatted="".concat((ms/1000).toFixed(2),"s");}return formatted;}function leftPad(string){var length=arguments.length>1&&arguments[1]!==undefined?arguments[1]:8;var padLength=Math.max(length-string.length,0);return "".concat(' '.repeat(padLength)).concat(string);}function formatImage(image,message,scale){var maxWidth=arguments.length>3&&arguments[3]!==undefined?arguments[3]:600;var imageUrl=image.src.replace(/\(/g,'%28').replace(/\)/g,'%29');if(image.width>maxWidth){scale=Math.min(scale,maxWidth/image.width);}var width=image.width*scale;var height=image.height*scale;var style=['font-size:1px;',"padding:".concat(Math.floor(height/2),"px ").concat(Math.floor(width/2),"px;"),"line-height:".concat(height,"px;"),"background:url(".concat(imageUrl,");"),"background-size:".concat(width,"px ").concat(height,"px;"),'color:transparent;'].join('');return ["".concat(message," %c+"),style];}var COLOR;(function(COLOR){COLOR[COLOR["BLACK"]=30]="BLACK";COLOR[COLOR["RED"]=31]="RED";COLOR[COLOR["GREEN"]=32]="GREEN";COLOR[COLOR["YELLOW"]=33]="YELLOW";COLOR[COLOR["BLUE"]=34]="BLUE";COLOR[COLOR["MAGENTA"]=35]="MAGENTA";COLOR[COLOR["CYAN"]=36]="CYAN";COLOR[COLOR["WHITE"]=37]="WHITE";COLOR[COLOR["BRIGHT_BLACK"]=90]="BRIGHT_BLACK";COLOR[COLOR["BRIGHT_RED"]=91]="BRIGHT_RED";COLOR[COLOR["BRIGHT_GREEN"]=92]="BRIGHT_GREEN";COLOR[COLOR["BRIGHT_YELLOW"]=93]="BRIGHT_YELLOW";COLOR[COLOR["BRIGHT_BLUE"]=94]="BRIGHT_BLUE";COLOR[COLOR["BRIGHT_MAGENTA"]=95]="BRIGHT_MAGENTA";COLOR[COLOR["BRIGHT_CYAN"]=96]="BRIGHT_CYAN";COLOR[COLOR["BRIGHT_WHITE"]=97]="BRIGHT_WHITE";})(COLOR||(COLOR={}));function getColor$1(color){return typeof color==='string'?COLOR[color.toUpperCase()]||COLOR.WHITE:color;}function addColor(string,color,background){if(!isBrowser&&typeof string==='string'){if(color){color=getColor$1(color);string="\x1B[".concat(color,"m").concat(string,"\x1B[39m");}if(background){color=getColor$1(background);string="\x1B[".concat(background+10,"m").concat(string,"\x1B[49m");}}return string;}function autobind(obj){var predefined=arguments.length>1&&arguments[1]!==undefined?arguments[1]:['constructor'];var proto=Object.getPrototypeOf(obj);var propNames=Object.getOwnPropertyNames(proto);var _loop=function _loop(key){if(typeof obj[key]==='function'){if(!predefined.find(name=>key===name)){obj[key]=obj[key].bind(obj);}}};for(var key of propNames){_loop(key);}}function assert$5(condition,message){if(!condition){throw new Error(message||'Assertion failed');}}function getHiResTimestamp(){var timestamp;if(isBrowser&&'performance'in window_){var _window$performance,_window$performance$n;timestamp=window_===null||window_===void 0?void 0:(_window$performance=window_.performance)===null||_window$performance===void 0?void 0:(_window$performance$n=_window$performance.now)===null||_window$performance$n===void 0?void 0:_window$performance$n.call(_window$performance);}else if('hrtime'in process_){var _process$hrtime;var timeParts=process_===null||process_===void 0?void 0:(_process$hrtime=process_.hrtime)===null||_process$hrtime===void 0?void 0:_process$hrtime.call(process_);timestamp=timeParts[0]*1000+timeParts[1]/1e6;}else {timestamp=Date.now();}return timestamp;}var originalConsole={debug:isBrowser?console.debug||console.log:console.log,log:console.log,info:console.info,warn:console.warn,error:console.error};var DEFAULT_SETTINGS={enabled:true,level:0};function noop$1(){}var cache={};var ONCE={once:true};class Log{constructor(){var{id}=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{id:''};_defineProperty$1(this,"id",void 0);_defineProperty$1(this,"VERSION",VERSION$6);_defineProperty$1(this,"_startTs",getHiResTimestamp());_defineProperty$1(this,"_deltaTs",getHiResTimestamp());_defineProperty$1(this,"_storage",void 0);_defineProperty$1(this,"userData",{});_defineProperty$1(this,"LOG_THROTTLE_TIMEOUT",0);this.id=id;this._storage=new LocalStorage("__probe-".concat(this.id,"__"),DEFAULT_SETTINGS);this.userData={};this.timeStamp("".concat(this.id," started"));autobind(this);Object.seal(this);}set level(newLevel){this.setLevel(newLevel);}get level(){return this.getLevel();}isEnabled(){return this._storage.config.enabled;}getLevel(){return this._storage.config.level;}getTotal(){return Number((getHiResTimestamp()-this._startTs).toPrecision(10));}getDelta(){return Number((getHiResTimestamp()-this._deltaTs).toPrecision(10));}set priority(newPriority){this.level=newPriority;}get priority(){return this.level;}getPriority(){return this.level;}enable(){var enabled=arguments.length>0&&arguments[0]!==undefined?arguments[0]:true;this._storage.updateConfiguration({enabled});return this;}setLevel(level){this._storage.updateConfiguration({level});return this;}get(setting){return this._storage.config[setting];}set(setting,value){this._storage.updateConfiguration({[setting]:value});}settings(){if(console.table){console.table(this._storage.config);}else {console.log(this._storage.config);}}assert(condition,message){assert$5(condition,message);}warn(message){return this._getLogFunction(0,message,originalConsole.warn,arguments,ONCE);}error(message){return this._getLogFunction(0,message,originalConsole.error,arguments);}deprecated(oldUsage,newUsage){return this.warn("`".concat(oldUsage,"` is deprecated and will be removed in a later version. Use `").concat(newUsage,"` instead"));}removed(oldUsage,newUsage){return this.error("`".concat(oldUsage,"` has been removed. Use `").concat(newUsage,"` instead"));}probe(logLevel,message){return this._getLogFunction(logLevel,message,originalConsole.log,arguments,{time:true,once:true});}log(logLevel,message){return this._getLogFunction(logLevel,message,originalConsole.debug,arguments);}info(logLevel,message){return this._getLogFunction(logLevel,message,console.info,arguments);}once(logLevel,message){for(var _len=arguments.length,args=new Array(_len>2?_len-2:0),_key=2;_key<_len;_key++){args[_key-2]=arguments[_key];}return this._getLogFunction(logLevel,message,originalConsole.debug||originalConsole.info,arguments,ONCE);}table(logLevel,table,columns){if(table){return this._getLogFunction(logLevel,table,console.table||noop$1,columns&&[columns],{tag:getTableHeader(table)});}return noop$1;}image(_ref){var{logLevel,priority,image,message='',scale=1}=_ref;if(!this._shouldLog(logLevel||priority)){return noop$1;}return isBrowser?logImageInBrowser({image,message,scale}):logImageInNode({image,message,scale});}time(logLevel,message){return this._getLogFunction(logLevel,message,console.time?console.time:console.info);}timeEnd(logLevel,message){return this._getLogFunction(logLevel,message,console.timeEnd?console.timeEnd:console.info);}timeStamp(logLevel,message){return this._getLogFunction(logLevel,message,console.timeStamp||noop$1);}group(logLevel,message){var opts=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{collapsed:false};var options=normalizeArguments({logLevel,message,opts});var{collapsed}=opts;options.method=(collapsed?console.groupCollapsed:console.group)||console.info;return this._getLogFunction(options);}groupCollapsed(logLevel,message){var opts=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};return this.group(logLevel,message,Object.assign({},opts,{collapsed:true}));}groupEnd(logLevel){return this._getLogFunction(logLevel,'',console.groupEnd||noop$1);}withGroup(logLevel,message,func){this.group(logLevel,message)();try{func();}finally{this.groupEnd(logLevel)();}}trace(){if(console.trace){console.trace();}}_shouldLog(logLevel){return this.isEnabled()&&this.getLevel()>=normalizeLogLevel(logLevel);}_getLogFunction(logLevel,message,method,args,opts){if(this._shouldLog(logLevel)){opts=normalizeArguments({logLevel,message,args,opts});method=method||opts.method;assert$5(method);opts.total=this.getTotal();opts.delta=this.getDelta();this._deltaTs=getHiResTimestamp();var tag=opts.tag||opts.message;if(opts.once){if(!cache[tag]){cache[tag]=getHiResTimestamp();}else {return noop$1;}}message=decorateMessage(this.id,opts.message,opts);return method.bind(console,message,...opts.args);}return noop$1;}}_defineProperty$1(Log,"VERSION",VERSION$6);function normalizeLogLevel(logLevel){if(!logLevel){return 0;}var resolvedLevel;switch(typeof logLevel){case'number':resolvedLevel=logLevel;break;case'object':resolvedLevel=logLevel.logLevel||logLevel.priority||0;break;default:return 0;}assert$5(Number.isFinite(resolvedLevel)&&resolvedLevel>=0);return resolvedLevel;}function normalizeArguments(opts){var{logLevel,message}=opts;opts.logLevel=normalizeLogLevel(logLevel);var args=opts.args?Array.from(opts.args):[];while(args.length&&args.shift()!==message){}switch(typeof logLevel){case'string':case'function':if(message!==undefined){args.unshift(message);}opts.message=logLevel;break;case'object':Object.assign(opts,logLevel);break;}if(typeof opts.message==='function'){opts.message=opts.message();}var messageType=typeof opts.message;assert$5(messageType==='string'||messageType==='object');return Object.assign(opts,{args},opts.opts);}function decorateMessage(id,message,opts){if(typeof message==='string'){var time=opts.time?leftPad(formatTime(opts.total)):'';message=opts.time?"".concat(id,": ").concat(time," ").concat(message):"".concat(id,": ").concat(message);message=addColor(message,opts.color,opts.background);}return message;}function logImageInNode(_ref2){var{image,message='',scale=1}=_ref2;var asciify=null;try{asciify=module.require('asciify-image');}catch(error){}if(asciify){return ()=>asciify(image,{fit:'box',width:"".concat(Math.round(80*scale),"%")}).then(data=>console.log(data));}return noop$1;}function logImageInBrowser(_ref3){var{image,message='',scale=1}=_ref3;if(typeof image==='string'){var img=new Image();img.onload=()=>{var args=formatImage(img,message,scale);console.log(...args);};img.src=image;return noop$1;}var element=image.nodeName||'';if(element.toLowerCase()==='img'){console.log(...formatImage(image,message,scale));return noop$1;}if(element.toLowerCase()==='canvas'){var _img=new Image();_img.onload=()=>console.log(...formatImage(_img,message,scale));_img.src=image.toDataURL();return noop$1;}return noop$1;}function getTableHeader(table){for(var key in table){for(var title in table[key]){return title||'untitled';}}return 'empty';}var probeLog=new Log({id:'loaders.gl'});class NullLog{log(){return ()=>{};}info(){return ()=>{};}warn(){return ()=>{};}error(){return ()=>{};}}class ConsoleLog{constructor(){_defineProperty$1(this,"console",void 0);this.console=console;}log(){for(var _len3=arguments.length,args=new Array(_len3),_key3=0;_key3<_len3;_key3++){args[_key3]=arguments[_key3];}return this.console.log.bind(this.console,...args);}info(){for(var _len4=arguments.length,args=new Array(_len4),_key4=0;_key4<_len4;_key4++){args[_key4]=arguments[_key4];}return this.console.info.bind(this.console,...args);}warn(){for(var _len5=arguments.length,args=new Array(_len5),_key5=0;_key5<_len5;_key5++){args[_key5]=arguments[_key5];}return this.console.warn.bind(this.console,...args);}error(){for(var _len6=arguments.length,args=new Array(_len6),_key6=0;_key6<_len6;_key6++){args[_key6]=arguments[_key6];}return this.console.error.bind(this.console,...args);}}var DEFAULT_LOADER_OPTIONS={fetch:null,mimeType:undefined,nothrow:false,log:new ConsoleLog(),CDN:'https://unpkg.com/@loaders.gl',worker:true,maxConcurrency:3,maxMobileConcurrency:1,reuseWorkers:true,_workerType:'',limit:0,_limitMB:0,batchSize:'auto',batchDebounceMs:0,metadata:false,transforms:[]};var REMOVED_LOADER_OPTIONS={throws:'nothrow',dataType:'(no longer used)',uri:'baseUri',method:'fetch.method',headers:'fetch.headers',body:'fetch.body',mode:'fetch.mode',credentials:'fetch.credentials',cache:'fetch.cache',redirect:'fetch.redirect',referrer:'fetch.referrer',referrerPolicy:'fetch.referrerPolicy',integrity:'fetch.integrity',keepalive:'fetch.keepalive',signal:'fetch.signal'};function getGlobalLoaderState(){globalThis.loaders=globalThis.loaders||{};var{loaders}=globalThis;loaders._state=loaders._state||{};return loaders._state;}var getGlobalLoaderOptions=()=>{var state=getGlobalLoaderState();state.globalOptions=state.globalOptions||_objectSpread2({},DEFAULT_LOADER_OPTIONS);return state.globalOptions;};function normalizeOptions(options,loader,loaders,url){loaders=loaders||[];loaders=Array.isArray(loaders)?loaders:[loaders];validateOptions(options,loaders);return normalizeOptionsInternal(loader,options,url);}function getFetchFunction(options,context){var globalOptions=getGlobalLoaderOptions();var fetchOptions=options||globalOptions;if(typeof fetchOptions.fetch==='function'){return fetchOptions.fetch;}if(isObject(fetchOptions.fetch)){return url=>fetchFile(url,fetchOptions);}if(context!==null&&context!==void 0&&context.fetch){return context===null||context===void 0?void 0:context.fetch;}return fetchFile;}function validateOptions(options,loaders){validateOptionsObject(options,null,DEFAULT_LOADER_OPTIONS,REMOVED_LOADER_OPTIONS,loaders);for(var loader of loaders){var idOptions=options&&options[loader.id]||{};var loaderOptions=loader.options&&loader.options[loader.id]||{};var deprecatedOptions=loader.deprecatedOptions&&loader.deprecatedOptions[loader.id]||{};validateOptionsObject(idOptions,loader.id,loaderOptions,deprecatedOptions,loaders);}}function validateOptionsObject(options,id,defaultOptions,deprecatedOptions,loaders){var loaderName=id||'Top level';var prefix=id?"".concat(id,"."):'';for(var key in options){var isSubOptions=!id&&isObject(options[key]);var isBaseUriOption=key==='baseUri'&&!id;var isWorkerUrlOption=key==='workerUrl'&&id;if(!(key in defaultOptions)&&!isBaseUriOption&&!isWorkerUrlOption){if(key in deprecatedOptions){probeLog.warn("".concat(loaderName," loader option '").concat(prefix).concat(key,"' no longer supported, use '").concat(deprecatedOptions[key],"'"))();}else if(!isSubOptions){var suggestion=findSimilarOption(key,loaders);probeLog.warn("".concat(loaderName," loader option '").concat(prefix).concat(key,"' not recognized. ").concat(suggestion))();}}}}function findSimilarOption(optionKey,loaders){var lowerCaseOptionKey=optionKey.toLowerCase();var bestSuggestion='';for(var loader of loaders){for(var key in loader.options){if(optionKey===key){return "Did you mean '".concat(loader.id,".").concat(key,"'?");}var lowerCaseKey=key.toLowerCase();var isPartialMatch=lowerCaseOptionKey.startsWith(lowerCaseKey)||lowerCaseKey.startsWith(lowerCaseOptionKey);if(isPartialMatch){bestSuggestion=bestSuggestion||"Did you mean '".concat(loader.id,".").concat(key,"'?");}}}return bestSuggestion;}function normalizeOptionsInternal(loader,options,url){var loaderDefaultOptions=loader.options||{};var mergedOptions=_objectSpread2({},loaderDefaultOptions);addUrlOptions(mergedOptions,url);if(mergedOptions.log===null){mergedOptions.log=new NullLog();}mergeNestedFields(mergedOptions,getGlobalLoaderOptions());mergeNestedFields(mergedOptions,options);return mergedOptions;}function mergeNestedFields(mergedOptions,options){for(var key in options){if(key in options){var value=options[key];if(isPureObject(value)&&isPureObject(mergedOptions[key])){mergedOptions[key]=_objectSpread2(_objectSpread2({},mergedOptions[key]),options[key]);}else {mergedOptions[key]=options[key];}}}}function addUrlOptions(options,url){if(url&&!('baseUri'in options)){options.baseUri=url;}}function isLoaderObject(loader){var _loader;if(!loader){return false;}if(Array.isArray(loader)){loader=loader[0];}var hasExtensions=Array.isArray((_loader=loader)===null||_loader===void 0?void 0:_loader.extensions);return hasExtensions;}function normalizeLoader(loader){var _loader2,_loader3;assert$7(loader,'null loader');assert$7(isLoaderObject(loader),'invalid loader');var options;if(Array.isArray(loader)){options=loader[1];loader=loader[0];loader=_objectSpread2(_objectSpread2({},loader),{},{options:_objectSpread2(_objectSpread2({},loader.options),options)});}if((_loader2=loader)!==null&&_loader2!==void 0&&_loader2.parseTextSync||(_loader3=loader)!==null&&_loader3!==void 0&&_loader3.parseText){loader.text=true;}if(!loader.text){loader.binary=true;}return loader;}var getGlobalLoaderRegistry=()=>{var state=getGlobalLoaderState();state.loaderRegistry=state.loaderRegistry||[];return state.loaderRegistry;};function getRegisteredLoaders(){return getGlobalLoaderRegistry();}var EXT_PATTERN=/\.([^.]+)$/;async function selectLoader(data){var loaders=arguments.length>1&&arguments[1]!==undefined?arguments[1]:[];var options=arguments.length>2?arguments[2]:undefined;var context=arguments.length>3?arguments[3]:undefined;if(!validHTTPResponse(data)){return null;}var loader=selectLoaderSync(data,loaders,_objectSpread2(_objectSpread2({},options),{},{nothrow:true}),context);if(loader){return loader;}if(isBlob(data)){data=await data.slice(0,10).arrayBuffer();loader=selectLoaderSync(data,loaders,options,context);}if(!loader&&!(options!==null&&options!==void 0&&options.nothrow)){throw new Error(getNoValidLoaderMessage(data));}return loader;}function selectLoaderSync(data){var loaders=arguments.length>1&&arguments[1]!==undefined?arguments[1]:[];var options=arguments.length>2?arguments[2]:undefined;var context=arguments.length>3?arguments[3]:undefined;if(!validHTTPResponse(data)){return null;}if(loaders&&!Array.isArray(loaders)){return normalizeLoader(loaders);}var candidateLoaders=[];if(loaders){candidateLoaders=candidateLoaders.concat(loaders);}if(!(options!==null&&options!==void 0&&options.ignoreRegisteredLoaders)){candidateLoaders.push(...getRegisteredLoaders());}normalizeLoaders(candidateLoaders);var loader=selectLoaderInternal(data,candidateLoaders,options,context);if(!loader&&!(options!==null&&options!==void 0&&options.nothrow)){throw new Error(getNoValidLoaderMessage(data));}return loader;}function selectLoaderInternal(data,loaders,options,context){var{url,type}=getResourceUrlAndType(data);var testUrl=url||(context===null||context===void 0?void 0:context.url);var loader=null;if(options!==null&&options!==void 0&&options.mimeType){loader=findLoaderByMIMEType(loaders,options===null||options===void 0?void 0:options.mimeType);}loader=loader||findLoaderByUrl(loaders,testUrl);loader=loader||findLoaderByMIMEType(loaders,type);loader=loader||findLoaderByInitialBytes(loaders,data);loader=loader||findLoaderByMIMEType(loaders,options===null||options===void 0?void 0:options.fallbackMimeType);return loader;}function validHTTPResponse(data){if(data instanceof Response){if(data.status===204){return false;}}return true;}function getNoValidLoaderMessage(data){var{url,type}=getResourceUrlAndType(data);var message='No valid loader found (';message+=url?"".concat(filename(url),", "):'no url provided, ';message+="MIME type: ".concat(type?"\"".concat(type,"\""):'not provided',", ");var firstCharacters=data?getFirstCharacters(data):'';message+=firstCharacters?" first bytes: \"".concat(firstCharacters,"\""):'first bytes: not available';message+=')';return message;}function normalizeLoaders(loaders){for(var loader of loaders){normalizeLoader(loader);}}function findLoaderByUrl(loaders,url){var match=url&&EXT_PATTERN.exec(url);var extension=match&&match[1];return extension?findLoaderByExtension(loaders,extension):null;}function findLoaderByExtension(loaders,extension){extension=extension.toLowerCase();for(var loader of loaders){for(var loaderExtension of loader.extensions){if(loaderExtension.toLowerCase()===extension){return loader;}}}return null;}function findLoaderByMIMEType(loaders,mimeType){for(var loader of loaders){if(loader.mimeTypes&&loader.mimeTypes.includes(mimeType)){return loader;}if(mimeType==="application/x.".concat(loader.id)){return loader;}}return null;}function findLoaderByInitialBytes(loaders,data){if(!data){return null;}for(var loader of loaders){if(typeof data==='string'){if(testDataAgainstText(data,loader)){return loader;}}else if(ArrayBuffer.isView(data)){if(testDataAgainstBinary(data.buffer,data.byteOffset,loader)){return loader;}}else if(data instanceof ArrayBuffer){var byteOffset=0;if(testDataAgainstBinary(data,byteOffset,loader)){return loader;}}}return null;}function testDataAgainstText(data,loader){if(loader.testText){return loader.testText(data);}var tests=Array.isArray(loader.tests)?loader.tests:[loader.tests];return tests.some(test=>data.startsWith(test));}function testDataAgainstBinary(data,byteOffset,loader){var tests=Array.isArray(loader.tests)?loader.tests:[loader.tests];return tests.some(test=>testBinary(data,byteOffset,loader,test));}function testBinary(data,byteOffset,loader,test){if(test instanceof ArrayBuffer){return compareArrayBuffers(test,data,test.byteLength);}switch(typeof test){case'function':return test(data,loader);case'string':var magic=getMagicString$2(data,byteOffset,test.length);return test===magic;default:return false;}}function getFirstCharacters(data){var length=arguments.length>1&&arguments[1]!==undefined?arguments[1]:5;if(typeof data==='string'){return data.slice(0,length);}else if(ArrayBuffer.isView(data)){return getMagicString$2(data.buffer,data.byteOffset,length);}else if(data instanceof ArrayBuffer){var byteOffset=0;return getMagicString$2(data,byteOffset,length);}return '';}function getMagicString$2(arrayBuffer,byteOffset,length){if(arrayBuffer.byteLength<byteOffset+length){return '';}var dataView=new DataView(arrayBuffer);var magic='';for(var _i6=0;_i6<length;_i6++){magic+=String.fromCharCode(dataView.getUint8(byteOffset+_i6));}return magic;}var DEFAULT_CHUNK_SIZE$2=256*1024;function*makeStringIterator(string,options){var chunkSize=(options===null||options===void 0?void 0:options.chunkSize)||DEFAULT_CHUNK_SIZE$2;var offset=0;var textEncoder=new TextEncoder();while(offset<string.length){var chunkLength=Math.min(string.length-offset,chunkSize);var chunk=string.slice(offset,offset+chunkLength);offset+=chunkLength;yield textEncoder.encode(chunk);}}var DEFAULT_CHUNK_SIZE$1=256*1024;function makeArrayBufferIterator(arrayBuffer){var options=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};return function*(){var{chunkSize=DEFAULT_CHUNK_SIZE$1}=options;var byteOffset=0;while(byteOffset<arrayBuffer.byteLength){var chunkByteLength=Math.min(arrayBuffer.byteLength-byteOffset,chunkSize);var chunk=new ArrayBuffer(chunkByteLength);var sourceArray=new Uint8Array(arrayBuffer,byteOffset,chunkByteLength);var chunkArray=new Uint8Array(chunk);chunkArray.set(sourceArray);byteOffset+=chunkByteLength;yield chunk;}}();}var DEFAULT_CHUNK_SIZE=1024*1024;function makeBlobIterator(_x,_x2){return _makeBlobIterator.apply(this,arguments);}function _makeBlobIterator(){_makeBlobIterator=_wrapAsyncGenerator(function*(blob,options){var chunkSize=(options===null||options===void 0?void 0:options.chunkSize)||DEFAULT_CHUNK_SIZE;var offset=0;while(offset<blob.size){var end=offset+chunkSize;var chunk=yield _awaitAsyncGenerator(blob.slice(offset,end).arrayBuffer());offset=end;yield chunk;}});return _makeBlobIterator.apply(this,arguments);}function makeStreamIterator(stream,options){return isBrowser$2?makeBrowserStreamIterator(stream,options):makeNodeStreamIterator(stream);}function makeBrowserStreamIterator(_x3,_x4){return _makeBrowserStreamIterator.apply(this,arguments);}function _makeBrowserStreamIterator(){_makeBrowserStreamIterator=_wrapAsyncGenerator(function*(stream,options){var reader=stream.getReader();var nextBatchPromise;try{while(true){var currentBatchPromise=nextBatchPromise||reader.read();if(options!==null&&options!==void 0&&options._streamReadAhead){nextBatchPromise=reader.read();}var{done,value}=yield _awaitAsyncGenerator(currentBatchPromise);if(done){return;}yield toArrayBuffer(value);}}catch(error){reader.releaseLock();}});return _makeBrowserStreamIterator.apply(this,arguments);}function makeNodeStreamIterator(_x5,_x6){return _makeNodeStreamIterator.apply(this,arguments);}function _makeNodeStreamIterator(){_makeNodeStreamIterator=_wrapAsyncGenerator(function*(stream,options){var _iteratorAbruptCompletion2=false;var _didIteratorError2=false;var _iteratorError2;try{for(var _iterator2=_asyncIterator(stream),_step2;_iteratorAbruptCompletion2=!(_step2=yield _awaitAsyncGenerator(_iterator2.next())).done;_iteratorAbruptCompletion2=false){var chunk=_step2.value;{yield toArrayBuffer(chunk);}}}catch(err){_didIteratorError2=true;_iteratorError2=err;}finally{try{if(_iteratorAbruptCompletion2&&_iterator2.return!=null){yield _awaitAsyncGenerator(_iterator2.return());}}finally{if(_didIteratorError2){throw _iteratorError2;}}}});return _makeNodeStreamIterator.apply(this,arguments);}function makeIterator(data,options){if(typeof data==='string'){return makeStringIterator(data,options);}if(data instanceof ArrayBuffer){return makeArrayBufferIterator(data,options);}if(isBlob(data)){return makeBlobIterator(data,options);}if(isReadableStream(data)){return makeStreamIterator(data,options);}if(isResponse(data)){var response=data;return makeStreamIterator(response.body,options);}throw new Error('makeIterator');}var ERR_DATA='Cannot convert supplied data type';function getArrayBufferOrStringFromDataSync(data,loader,options){if(loader.text&&typeof data==='string'){return data;}if(isBuffer(data)){data=data.buffer;}if(data instanceof ArrayBuffer){var arrayBuffer=data;if(loader.text&&!loader.binary){var textDecoder=new TextDecoder('utf8');return textDecoder.decode(arrayBuffer);}return arrayBuffer;}if(ArrayBuffer.isView(data)){if(loader.text&&!loader.binary){var _textDecoder=new TextDecoder('utf8');return _textDecoder.decode(data);}var _arrayBuffer=data.buffer;var byteLength=data.byteLength||data.length;if(data.byteOffset!==0||byteLength!==_arrayBuffer.byteLength){_arrayBuffer=_arrayBuffer.slice(data.byteOffset,data.byteOffset+byteLength);}return _arrayBuffer;}throw new Error(ERR_DATA);}async function getArrayBufferOrStringFromData(data,loader,options){var isArrayBuffer=data instanceof ArrayBuffer||ArrayBuffer.isView(data);if(typeof data==='string'||isArrayBuffer){return getArrayBufferOrStringFromDataSync(data,loader);}if(isBlob(data)){data=await makeResponse(data);}if(isResponse(data)){var response=data;await checkResponse(response);return loader.binary?await response.arrayBuffer():await response.text();}if(isReadableStream(data)){data=makeIterator(data,options);}if(isIterable(data)||isAsyncIterable(data)){return concatenateArrayBuffersAsync(data);}throw new Error(ERR_DATA);}function getLoaderContext(context,options){var previousContext=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;if(previousContext){return previousContext;}var resolvedContext=_objectSpread2({fetch:getFetchFunction(options,context)},context);if(!Array.isArray(resolvedContext.loaders)){resolvedContext.loaders=null;}return resolvedContext;}function getLoadersFromContext(loaders,context){if(!context&&loaders&&!Array.isArray(loaders)){return loaders;}var candidateLoaders;if(loaders){candidateLoaders=Array.isArray(loaders)?loaders:[loaders];}if(context&&context.loaders){var contextLoaders=Array.isArray(context.loaders)?context.loaders:[context.loaders];candidateLoaders=candidateLoaders?[...candidateLoaders,...contextLoaders]:contextLoaders;}return candidateLoaders&&candidateLoaders.length?candidateLoaders:null;}async function parse$3(data,loaders,options,context){assert$6(!context||typeof context==='object');if(loaders&&!Array.isArray(loaders)&&!isLoaderObject(loaders)){context=undefined;options=loaders;loaders=undefined;}data=await data;options=options||{};var{url}=getResourceUrlAndType(data);var typedLoaders=loaders;var candidateLoaders=getLoadersFromContext(typedLoaders,context);var loader=await selectLoader(data,candidateLoaders,options);if(!loader){return null;}options=normalizeOptions(options,loader,candidateLoaders,url);context=getLoaderContext({url,parse:parse$3,loaders:candidateLoaders},options,context);return await parseWithLoader(loader,data,options,context);}async function parseWithLoader(loader,data,options,context){validateWorkerVersion(loader);data=await getArrayBufferOrStringFromData(data,loader,options);if(loader.parseTextSync&&typeof data==='string'){options.dataType='text';return loader.parseTextSync(data,options,context,loader);}if(canParseWithWorker(loader,options)){return await parseWithWorker(loader,data,options,context,parse$3);}if(loader.parseText&&typeof data==='string'){return await loader.parseText(data,options,context,loader);}if(loader.parse){return await loader.parse(data,options,context,loader);}assert$6(!loader.parseSync);throw new Error("".concat(loader.id," loader - no parser found and worker is disabled"));}async function load(url,loaders,options,context){if(!Array.isArray(loaders)&&!isLoaderObject(loaders)){options=loaders;loaders=undefined;}var fetch=getFetchFunction(options);var data=url;if(typeof url==='string'){data=await fetch(url);}if(isBlob(url)){data=await fetch(url);}return await parse$3(data,loaders,options);}function assert$4(condition,message){if(!condition){throw new Error("math.gl assertion ".concat(message));}}var RADIANS_TO_DEGREES=1/Math.PI*180;var DEGREES_TO_RADIANS=1/180*Math.PI;var config$2={};config$2.EPSILON=1e-12;config$2.debug=false;config$2.precision=4;config$2.printTypes=false;config$2.printDegrees=false;config$2.printRowMajor=true;function round(value){return Math.round(value/config$2.EPSILON)*config$2.EPSILON;}function formatValue(value){var{precision=config$2.precision||4}=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};value=round(value);return "".concat(parseFloat(value.toPrecision(precision)));}function isArray(value){return Array.isArray(value)||ArrayBuffer.isView(value)&&!(value instanceof DataView);}function duplicateArray(array){return array.clone?array.clone():new Array(array.length);}function map$1(value,func,result){if(isArray(value)){result=result||duplicateArray(value);for(var _i7=0;_i7<result.length&&_i7<value.length;++_i7){result[_i7]=func(value[_i7],_i7,result);}return result;}return func(value);}function toRadians(degrees){return radians(degrees);}function toDegrees(radians){return degrees(radians);}function radians(degrees,result){return map$1(degrees,degrees=>degrees*DEGREES_TO_RADIANS,result);}function degrees(radians,result){return map$1(radians,radians=>radians*RADIANS_TO_DEGREES,result);}function clamp$1(value,min,max){return map$1(value,value=>Math.max(min,Math.min(max,value)));}function equals$1(a,b,epsilon){var oldEpsilon=config$2.EPSILON;if(epsilon){config$2.EPSILON=epsilon;}try{if(a===b){return true;}if(isArray(a)&&isArray(b)){if(a.length!==b.length){return false;}for(var _i8=0;_i8<a.length;++_i8){if(!equals$1(a[_i8],b[_i8])){return false;}}return true;}if(a&&a.equals){return a.equals(b);}if(b&&b.equals){return b.equals(a);}if(Number.isFinite(a)&&Number.isFinite(b)){return Math.abs(a-b)<=config$2.EPSILON*Math.max(1.0,Math.abs(a),Math.abs(b));}return false;}finally{config$2.EPSILON=oldEpsilon;}}function _extendableBuiltin(cls){function ExtendableBuiltin(){var instance=Reflect.construct(cls,Array.from(arguments));Object.setPrototypeOf(instance,Object.getPrototypeOf(this));return instance;}ExtendableBuiltin.prototype=Object.create(cls.prototype,{constructor:{value:cls,enumerable:false,writable:true,configurable:true}});if(Object.setPrototypeOf){Object.setPrototypeOf(ExtendableBuiltin,cls);}else {ExtendableBuiltin.__proto__=cls;}return ExtendableBuiltin;}class MathArray extends _extendableBuiltin(Array){get ELEMENTS(){assert$4(false);return 0;}clone(){return new this.constructor().copy(this);}from(arrayOrObject){return Array.isArray(arrayOrObject)?this.copy(arrayOrObject):this.fromObject(arrayOrObject);}fromArray(array){var offset=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;for(var _i9=0;_i9<this.ELEMENTS;++_i9){this[_i9]=array[_i9+offset];}return this.check();}to(arrayOrObject){if(arrayOrObject===this){return this;}return isArray(arrayOrObject)?this.toArray(arrayOrObject):this.toObject(arrayOrObject);}toTarget(target){return target?this.to(target):this;}toArray(){var array=arguments.length>0&&arguments[0]!==undefined?arguments[0]:[];var offset=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;for(var _i10=0;_i10<this.ELEMENTS;++_i10){array[offset+_i10]=this[_i10];}return array;}toFloat32Array(){return new Float32Array(this);}toString(){return this.formatString(config$2);}formatString(opts){var string='';for(var _i11=0;_i11<this.ELEMENTS;++_i11){string+=(_i11>0?', ':'')+formatValue(this[_i11],opts);}return "".concat(opts.printTypes?this.constructor.name:'',"[").concat(string,"]");}equals(array){if(!array||this.length!==array.length){return false;}for(var _i12=0;_i12<this.ELEMENTS;++_i12){if(!equals$1(this[_i12],array[_i12])){return false;}}return true;}exactEquals(array){if(!array||this.length!==array.length){return false;}for(var _i13=0;_i13<this.ELEMENTS;++_i13){if(this[_i13]!==array[_i13]){return false;}}return true;}negate(){for(var _i14=0;_i14<this.ELEMENTS;++_i14){this[_i14]=-this[_i14];}return this.check();}lerp(a,b,t){if(t===undefined){t=b;b=a;a=this;}for(var _i15=0;_i15<this.ELEMENTS;++_i15){var ai=a[_i15];this[_i15]=ai+t*(b[_i15]-ai);}return this.check();}min(vector){for(var _i16=0;_i16<this.ELEMENTS;++_i16){this[_i16]=Math.min(vector[_i16],this[_i16]);}return this.check();}max(vector){for(var _i17=0;_i17<this.ELEMENTS;++_i17){this[_i17]=Math.max(vector[_i17],this[_i17]);}return this.check();}clamp(minVector,maxVector){for(var _i18=0;_i18<this.ELEMENTS;++_i18){this[_i18]=Math.min(Math.max(this[_i18],minVector[_i18]),maxVector[_i18]);}return this.check();}add(){for(var _len7=arguments.length,vectors=new Array(_len7),_key7=0;_key7<_len7;_key7++){vectors[_key7]=arguments[_key7];}for(var vector of vectors){for(var _i19=0;_i19<this.ELEMENTS;++_i19){this[_i19]+=vector[_i19];}}return this.check();}subtract(){for(var _len8=arguments.length,vectors=new Array(_len8),_key8=0;_key8<_len8;_key8++){vectors[_key8]=arguments[_key8];}for(var vector of vectors){for(var _i20=0;_i20<this.ELEMENTS;++_i20){this[_i20]-=vector[_i20];}}return this.check();}scale(scale){if(Array.isArray(scale)){return this.multiply(scale);}for(var _i21=0;_i21<this.ELEMENTS;++_i21){this[_i21]*=scale;}return this.check();}sub(a){return this.subtract(a);}setScalar(a){for(var _i22=0;_i22<this.ELEMENTS;++_i22){this[_i22]=a;}return this.check();}addScalar(a){for(var _i23=0;_i23<this.ELEMENTS;++_i23){this[_i23]+=a;}return this.check();}subScalar(a){return this.addScalar(-a);}multiplyScalar(scalar){for(var _i24=0;_i24<this.ELEMENTS;++_i24){this[_i24]*=scalar;}return this.check();}divideScalar(a){return this.scale(1/a);}clampScalar(min,max){for(var _i25=0;_i25<this.ELEMENTS;++_i25){this[_i25]=Math.min(Math.max(this[_i25],min),max);}return this.check();}multiplyByScalar(scalar){return this.scale(scalar);}get elements(){return this;}check(){if(config$2.debug&&!this.validate()){throw new Error("math.gl: ".concat(this.constructor.name," some fields set to invalid numbers'"));}return this;}validate(){var valid=this.length===this.ELEMENTS;for(var _i26=0;_i26<this.ELEMENTS;++_i26){valid=valid&&Number.isFinite(this[_i26]);}return valid;}}function validateVector(v,length){if(v.length!==length){return false;}for(var _i27=0;_i27<v.length;++_i27){if(!Number.isFinite(v[_i27])){return false;}}return true;}function checkNumber(value){if(!Number.isFinite(value)){throw new Error("Invalid number ".concat(value));}return value;}function checkVector(v,length){var callerName=arguments.length>2&&arguments[2]!==undefined?arguments[2]:'';if(config$2.debug&&!validateVector(v,length)){throw new Error("math.gl: ".concat(callerName," some fields set to invalid numbers'"));}return v;}var map={};function deprecated(method,version){if(!map[method]){map[method]=true;console.warn("".concat(method," has been removed in version ").concat(version,", see upgrade guide for more information"));}}class Vector extends MathArray{get ELEMENTS(){assert$4(false);return 0;}copy(vector){assert$4(false);return this;}get x(){return this[0];}set x(value){this[0]=checkNumber(value);}get y(){return this[1];}set y(value){this[1]=checkNumber(value);}len(){return Math.sqrt(this.lengthSquared());}magnitude(){return this.len();}lengthSquared(){var length=0;for(var _i28=0;_i28<this.ELEMENTS;++_i28){length+=this[_i28]*this[_i28];}return length;}magnitudeSquared(){return this.lengthSquared();}distance(mathArray){return Math.sqrt(this.distanceSquared(mathArray));}distanceSquared(mathArray){var length=0;for(var _i29=0;_i29<this.ELEMENTS;++_i29){var dist=this[_i29]-mathArray[_i29];length+=dist*dist;}return checkNumber(length);}dot(mathArray){var product=0;for(var _i30=0;_i30<this.ELEMENTS;++_i30){product+=this[_i30]*mathArray[_i30];}return checkNumber(product);}normalize(){var length=this.magnitude();if(length!==0){for(var _i31=0;_i31<this.ELEMENTS;++_i31){this[_i31]/=length;}}return this.check();}multiply(){for(var _len9=arguments.length,vectors=new Array(_len9),_key9=0;_key9<_len9;_key9++){vectors[_key9]=arguments[_key9];}for(var vector of vectors){for(var _i32=0;_i32<this.ELEMENTS;++_i32){this[_i32]*=vector[_i32];}}return this.check();}divide(){for(var _len10=arguments.length,vectors=new Array(_len10),_key10=0;_key10<_len10;_key10++){vectors[_key10]=arguments[_key10];}for(var vector of vectors){for(var _i33=0;_i33<this.ELEMENTS;++_i33){this[_i33]/=vector[_i33];}}return this.check();}lengthSq(){return this.lengthSquared();}distanceTo(vector){return this.distance(vector);}distanceToSquared(vector){return this.distanceSquared(vector);}getComponent(i){assert$4(i>=0&&i<this.ELEMENTS,'index is out of range');return checkNumber(this[i]);}setComponent(i,value){assert$4(i>=0&&i<this.ELEMENTS,'index is out of range');this[i]=value;return this.check();}addVectors(a,b){return this.copy(a).add(b);}subVectors(a,b){return this.copy(a).subtract(b);}multiplyVectors(a,b){return this.copy(a).multiply(b);}addScaledVector(a,b){return this.add(new this.constructor(a).multiplyScalar(b));}}/**
  58842. * Common utilities
  58843. * @module glMatrix
  58844. */ // Configuration Constants
  58845. var EPSILON=0.000001;var ARRAY_TYPE=typeof Float32Array!=='undefined'?Float32Array:Array;if(!Math.hypot)Math.hypot=function(){var y=0,i=arguments.length;while(i--){y+=arguments[i]*arguments[i];}return Math.sqrt(y);};/**
  58846. * 2 Dimensional Vector
  58847. * @module vec2
  58848. */ /**
  58849. * Creates a new, empty vec2
  58850. *
  58851. * @returns {vec2} a new 2D vector
  58852. */function create$4(){var out=new ARRAY_TYPE(2);if(ARRAY_TYPE!=Float32Array){out[0]=0;out[1]=0;}return out;}/**
  58853. * Transforms the vec2 with a mat2
  58854. *
  58855. * @param {vec2} out the receiving vector
  58856. * @param {ReadonlyVec2} a the vector to transform
  58857. * @param {ReadonlyMat2} m matrix to transform with
  58858. * @returns {vec2} out
  58859. */function transformMat2(out,a,m){var x=a[0],y=a[1];out[0]=m[0]*x+m[2]*y;out[1]=m[1]*x+m[3]*y;return out;}/**
  58860. * Transforms the vec2 with a mat2d
  58861. *
  58862. * @param {vec2} out the receiving vector
  58863. * @param {ReadonlyVec2} a the vector to transform
  58864. * @param {ReadonlyMat2d} m matrix to transform with
  58865. * @returns {vec2} out
  58866. */function transformMat2d(out,a,m){var x=a[0],y=a[1];out[0]=m[0]*x+m[2]*y+m[4];out[1]=m[1]*x+m[3]*y+m[5];return out;}/**
  58867. * Transforms the vec2 with a mat3
  58868. * 3rd vector component is implicitly '1'
  58869. *
  58870. * @param {vec2} out the receiving vector
  58871. * @param {ReadonlyVec2} a the vector to transform
  58872. * @param {ReadonlyMat3} m matrix to transform with
  58873. * @returns {vec2} out
  58874. */function transformMat3$1(out,a,m){var x=a[0],y=a[1];out[0]=m[0]*x+m[3]*y+m[6];out[1]=m[1]*x+m[4]*y+m[7];return out;}/**
  58875. * Transforms the vec2 with a mat4
  58876. * 3rd vector component is implicitly '0'
  58877. * 4th vector component is implicitly '1'
  58878. *
  58879. * @param {vec2} out the receiving vector
  58880. * @param {ReadonlyVec2} a the vector to transform
  58881. * @param {ReadonlyMat4} m matrix to transform with
  58882. * @returns {vec2} out
  58883. */function transformMat4$2(out,a,m){var x=a[0];var y=a[1];out[0]=m[0]*x+m[4]*y+m[12];out[1]=m[1]*x+m[5]*y+m[13];return out;}/**
  58884. * Perform some operation over an array of vec2s.
  58885. *
  58886. * @param {Array} a the array of vectors to iterate over
  58887. * @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed
  58888. * @param {Number} offset Number of elements to skip at the beginning of the array
  58889. * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array
  58890. * @param {Function} fn Function to call for each vector in the array
  58891. * @param {Object} [arg] additional argument to pass to fn
  58892. * @returns {Array} a
  58893. * @function
  58894. */(function(){var vec=create$4();return function(a,stride,offset,count,fn,arg){var i,l;if(!stride){stride=2;}if(!offset){offset=0;}if(count){l=Math.min(count*stride+offset,a.length);}else {l=a.length;}for(i=offset;i<l;i+=stride){vec[0]=a[i];vec[1]=a[i+1];fn(vec,vec,arg);a[i]=vec[0];a[i+1]=vec[1];}return a;};})();function vec2_transformMat4AsVector(out,a,m){var x=a[0];var y=a[1];var w=m[3]*x+m[7]*y||1.0;out[0]=(m[0]*x+m[4]*y)/w;out[1]=(m[1]*x+m[5]*y)/w;return out;}function vec3_transformMat4AsVector(out,a,m){var x=a[0];var y=a[1];var z=a[2];var w=m[3]*x+m[7]*y+m[11]*z||1.0;out[0]=(m[0]*x+m[4]*y+m[8]*z)/w;out[1]=(m[1]*x+m[5]*y+m[9]*z)/w;out[2]=(m[2]*x+m[6]*y+m[10]*z)/w;return out;}function vec3_transformMat2(out,a,m){var x=a[0];var y=a[1];out[0]=m[0]*x+m[2]*y;out[1]=m[1]*x+m[3]*y;out[2]=a[2];return out;}function vec4_transformMat3(out,a,m){var x=a[0];var y=a[1];var z=a[2];out[0]=m[0]*x+m[3]*y+m[6]*z;out[1]=m[1]*x+m[4]*y+m[7]*z;out[2]=m[2]*x+m[5]*y+m[8]*z;out[3]=a[3];return out;}class Vector2$1 extends Vector{constructor(){var x=arguments.length>0&&arguments[0]!==undefined?arguments[0]:0;var y=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;super(2);if(isArray(x)&&arguments.length===1){this.copy(x);}else {if(config$2.debug){checkNumber(x);checkNumber(y);}this[0]=x;this[1]=y;}}set(x,y){this[0]=x;this[1]=y;return this.check();}copy(array){this[0]=array[0];this[1]=array[1];return this.check();}fromObject(object){if(config$2.debug){checkNumber(object.x);checkNumber(object.y);}this[0]=object.x;this[1]=object.y;return this.check();}toObject(object){object.x=this[0];object.y=this[1];return object;}get ELEMENTS(){return 2;}horizontalAngle(){return Math.atan2(this.y,this.x);}verticalAngle(){return Math.atan2(this.x,this.y);}transform(matrix4){return this.transformAsPoint(matrix4);}transformAsPoint(matrix4){transformMat4$2(this,this,matrix4);return this.check();}transformAsVector(matrix4){vec2_transformMat4AsVector(this,this,matrix4);return this.check();}transformByMatrix3(matrix3){transformMat3$1(this,this,matrix3);return this.check();}transformByMatrix2x3(matrix2x3){transformMat2d(this,this,matrix2x3);return this.check();}transformByMatrix2(matrix2){transformMat2(this,this,matrix2);return this.check();}}/**
  58895. * 3 Dimensional Vector
  58896. * @module vec3
  58897. */ /**
  58898. * Creates a new, empty vec3
  58899. *
  58900. * @returns {vec3} a new 3D vector
  58901. */function create$3(){var out=new ARRAY_TYPE(3);if(ARRAY_TYPE!=Float32Array){out[0]=0;out[1]=0;out[2]=0;}return out;}/**
  58902. * Calculates the length of a vec3
  58903. *
  58904. * @param {ReadonlyVec3} a vector to calculate length of
  58905. * @returns {Number} length of a
  58906. */function length$2(a){var x=a[0];var y=a[1];var z=a[2];return Math.hypot(x,y,z);}/**
  58907. * Creates a new vec3 initialized with the given values
  58908. *
  58909. * @param {Number} x X component
  58910. * @param {Number} y Y component
  58911. * @param {Number} z Z component
  58912. * @returns {vec3} a new 3D vector
  58913. */function fromValues(x,y,z){var out=new ARRAY_TYPE(3);out[0]=x;out[1]=y;out[2]=z;return out;}/**
  58914. * Normalize a vec3
  58915. *
  58916. * @param {vec3} out the receiving vector
  58917. * @param {ReadonlyVec3} a vector to normalize
  58918. * @returns {vec3} out
  58919. */function normalize$2(out,a){var x=a[0];var y=a[1];var z=a[2];var len=x*x+y*y+z*z;if(len>0){//TODO: evaluate use of glm_invsqrt here?
  58920. len=1/Math.sqrt(len);}out[0]=a[0]*len;out[1]=a[1]*len;out[2]=a[2]*len;return out;}/**
  58921. * Calculates the dot product of two vec3's
  58922. *
  58923. * @param {ReadonlyVec3} a the first operand
  58924. * @param {ReadonlyVec3} b the second operand
  58925. * @returns {Number} dot product of a and b
  58926. */function dot$2(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2];}/**
  58927. * Computes the cross product of two vec3's
  58928. *
  58929. * @param {vec3} out the receiving vector
  58930. * @param {ReadonlyVec3} a the first operand
  58931. * @param {ReadonlyVec3} b the second operand
  58932. * @returns {vec3} out
  58933. */function cross(out,a,b){var ax=a[0],ay=a[1],az=a[2];var bx=b[0],by=b[1],bz=b[2];out[0]=ay*bz-az*by;out[1]=az*bx-ax*bz;out[2]=ax*by-ay*bx;return out;}/**
  58934. * Transforms the vec3 with a mat4.
  58935. * 4th vector component is implicitly '1'
  58936. *
  58937. * @param {vec3} out the receiving vector
  58938. * @param {ReadonlyVec3} a the vector to transform
  58939. * @param {ReadonlyMat4} m matrix to transform with
  58940. * @returns {vec3} out
  58941. */function transformMat4$1(out,a,m){var x=a[0],y=a[1],z=a[2];var w=m[3]*x+m[7]*y+m[11]*z+m[15];w=w||1.0;out[0]=(m[0]*x+m[4]*y+m[8]*z+m[12])/w;out[1]=(m[1]*x+m[5]*y+m[9]*z+m[13])/w;out[2]=(m[2]*x+m[6]*y+m[10]*z+m[14])/w;return out;}/**
  58942. * Transforms the vec3 with a mat3.
  58943. *
  58944. * @param {vec3} out the receiving vector
  58945. * @param {ReadonlyVec3} a the vector to transform
  58946. * @param {ReadonlyMat3} m the 3x3 matrix to transform with
  58947. * @returns {vec3} out
  58948. */function transformMat3(out,a,m){var x=a[0],y=a[1],z=a[2];out[0]=x*m[0]+y*m[3]+z*m[6];out[1]=x*m[1]+y*m[4]+z*m[7];out[2]=x*m[2]+y*m[5]+z*m[8];return out;}/**
  58949. * Transforms the vec3 with a quat
  58950. * Can also be used for dual quaternions. (Multiply it with the real part)
  58951. *
  58952. * @param {vec3} out the receiving vector
  58953. * @param {ReadonlyVec3} a the vector to transform
  58954. * @param {ReadonlyQuat} q quaternion to transform with
  58955. * @returns {vec3} out
  58956. */function transformQuat$1(out,a,q){// benchmarks: https://jsperf.com/quaternion-transform-vec3-implementations-fixed
  58957. var qx=q[0],qy=q[1],qz=q[2],qw=q[3];var x=a[0],y=a[1],z=a[2];// var qvec = [qx, qy, qz];
  58958. // var uv = vec3.cross([], qvec, a);
  58959. var uvx=qy*z-qz*y,uvy=qz*x-qx*z,uvz=qx*y-qy*x;// var uuv = vec3.cross([], qvec, uv);
  58960. var uuvx=qy*uvz-qz*uvy,uuvy=qz*uvx-qx*uvz,uuvz=qx*uvy-qy*uvx;// vec3.scale(uv, uv, 2 * w);
  58961. var w2=qw*2;uvx*=w2;uvy*=w2;uvz*=w2;// vec3.scale(uuv, uuv, 2);
  58962. uuvx*=2;uuvy*=2;uuvz*=2;// return vec3.add(out, a, vec3.add(out, uv, uuv));
  58963. out[0]=x+uvx+uuvx;out[1]=y+uvy+uuvy;out[2]=z+uvz+uuvz;return out;}/**
  58964. * Rotate a 3D vector around the x-axis
  58965. * @param {vec3} out The receiving vec3
  58966. * @param {ReadonlyVec3} a The vec3 point to rotate
  58967. * @param {ReadonlyVec3} b The origin of the rotation
  58968. * @param {Number} rad The angle of rotation in radians
  58969. * @returns {vec3} out
  58970. */function rotateX$2(out,a,b,rad){var p=[],r=[];//Translate point to the origin
  58971. p[0]=a[0]-b[0];p[1]=a[1]-b[1];p[2]=a[2]-b[2];//perform rotation
  58972. r[0]=p[0];r[1]=p[1]*Math.cos(rad)-p[2]*Math.sin(rad);r[2]=p[1]*Math.sin(rad)+p[2]*Math.cos(rad);//translate to correct position
  58973. out[0]=r[0]+b[0];out[1]=r[1]+b[1];out[2]=r[2]+b[2];return out;}/**
  58974. * Rotate a 3D vector around the y-axis
  58975. * @param {vec3} out The receiving vec3
  58976. * @param {ReadonlyVec3} a The vec3 point to rotate
  58977. * @param {ReadonlyVec3} b The origin of the rotation
  58978. * @param {Number} rad The angle of rotation in radians
  58979. * @returns {vec3} out
  58980. */function rotateY$2(out,a,b,rad){var p=[],r=[];//Translate point to the origin
  58981. p[0]=a[0]-b[0];p[1]=a[1]-b[1];p[2]=a[2]-b[2];//perform rotation
  58982. r[0]=p[2]*Math.sin(rad)+p[0]*Math.cos(rad);r[1]=p[1];r[2]=p[2]*Math.cos(rad)-p[0]*Math.sin(rad);//translate to correct position
  58983. out[0]=r[0]+b[0];out[1]=r[1]+b[1];out[2]=r[2]+b[2];return out;}/**
  58984. * Rotate a 3D vector around the z-axis
  58985. * @param {vec3} out The receiving vec3
  58986. * @param {ReadonlyVec3} a The vec3 point to rotate
  58987. * @param {ReadonlyVec3} b The origin of the rotation
  58988. * @param {Number} rad The angle of rotation in radians
  58989. * @returns {vec3} out
  58990. */function rotateZ$2(out,a,b,rad){var p=[],r=[];//Translate point to the origin
  58991. p[0]=a[0]-b[0];p[1]=a[1]-b[1];p[2]=a[2]-b[2];//perform rotation
  58992. r[0]=p[0]*Math.cos(rad)-p[1]*Math.sin(rad);r[1]=p[0]*Math.sin(rad)+p[1]*Math.cos(rad);r[2]=p[2];//translate to correct position
  58993. out[0]=r[0]+b[0];out[1]=r[1]+b[1];out[2]=r[2]+b[2];return out;}/**
  58994. * Get the angle between two 3D vectors
  58995. * @param {ReadonlyVec3} a The first operand
  58996. * @param {ReadonlyVec3} b The second operand
  58997. * @returns {Number} The angle in radians
  58998. */function angle$1(a,b){var ax=a[0],ay=a[1],az=a[2],bx=b[0],by=b[1],bz=b[2],mag1=Math.sqrt(ax*ax+ay*ay+az*az),mag2=Math.sqrt(bx*bx+by*by+bz*bz),mag=mag1*mag2,cosine=mag&&dot$2(a,b)/mag;return Math.acos(Math.min(Math.max(cosine,-1),1));}/**
  58999. * Alias for {@link vec3.length}
  59000. * @function
  59001. */var len=length$2;/**
  59002. * Perform some operation over an array of vec3s.
  59003. *
  59004. * @param {Array} a the array of vectors to iterate over
  59005. * @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed
  59006. * @param {Number} offset Number of elements to skip at the beginning of the array
  59007. * @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array
  59008. * @param {Function} fn Function to call for each vector in the array
  59009. * @param {Object} [arg] additional argument to pass to fn
  59010. * @returns {Array} a
  59011. * @function
  59012. */(function(){var vec=create$3();return function(a,stride,offset,count,fn,arg){var i,l;if(!stride){stride=3;}if(!offset){offset=0;}if(count){l=Math.min(count*stride+offset,a.length);}else {l=a.length;}for(i=offset;i<l;i+=stride){vec[0]=a[i];vec[1]=a[i+1];vec[2]=a[i+2];fn(vec,vec,arg);a[i]=vec[0];a[i+1]=vec[1];a[i+2]=vec[2];}return a;};})();var ORIGIN=[0,0,0];var constants$2={};class Vector3$1 extends Vector{static get ZERO(){return constants$2.ZERO=constants$2.ZERO||Object.freeze(new Vector3$1(0,0,0,0));}constructor(){var x=arguments.length>0&&arguments[0]!==undefined?arguments[0]:0;var y=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var z=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0;super(-0,-0,-0);if(arguments.length===1&&isArray(x)){this.copy(x);}else {if(config$2.debug){checkNumber(x);checkNumber(y);checkNumber(z);}this[0]=x;this[1]=y;this[2]=z;}}set(x,y,z){this[0]=x;this[1]=y;this[2]=z;return this.check();}copy(array){this[0]=array[0];this[1]=array[1];this[2]=array[2];return this.check();}fromObject(object){if(config$2.debug){checkNumber(object.x);checkNumber(object.y);checkNumber(object.z);}this[0]=object.x;this[1]=object.y;this[2]=object.z;return this.check();}toObject(object){object.x=this[0];object.y=this[1];object.z=this[2];return object;}get ELEMENTS(){return 3;}get z(){return this[2];}set z(value){this[2]=checkNumber(value);}angle(vector){return angle$1(this,vector);}cross(vector){cross(this,this,vector);return this.check();}rotateX(_ref4){var{radians,origin=ORIGIN}=_ref4;rotateX$2(this,this,origin,radians);return this.check();}rotateY(_ref5){var{radians,origin=ORIGIN}=_ref5;rotateY$2(this,this,origin,radians);return this.check();}rotateZ(_ref6){var{radians,origin=ORIGIN}=_ref6;rotateZ$2(this,this,origin,radians);return this.check();}transform(matrix4){return this.transformAsPoint(matrix4);}transformAsPoint(matrix4){transformMat4$1(this,this,matrix4);return this.check();}transformAsVector(matrix4){vec3_transformMat4AsVector(this,this,matrix4);return this.check();}transformByMatrix3(matrix3){transformMat3(this,this,matrix3);return this.check();}transformByMatrix2(matrix2){vec3_transformMat2(this,this,matrix2);return this.check();}transformByQuaternion(quaternion){transformQuat$1(this,this,quaternion);return this.check();}}class Matrix extends MathArray{get ELEMENTS(){assert$4(false);return 0;}get RANK(){assert$4(false);return 0;}toString(){var string='[';if(config$2.printRowMajor){string+='row-major:';for(var row=0;row<this.RANK;++row){for(var col=0;col<this.RANK;++col){string+=" ".concat(this[col*this.RANK+row]);}}}else {string+='column-major:';for(var _i34=0;_i34<this.ELEMENTS;++_i34){string+=" ".concat(this[_i34]);}}string+=']';return string;}getElementIndex(row,col){return col*this.RANK+row;}getElement(row,col){return this[col*this.RANK+row];}setElement(row,col,value){this[col*this.RANK+row]=checkNumber(value);return this;}getColumn(columnIndex){var result=arguments.length>1&&arguments[1]!==undefined?arguments[1]:new Array(this.RANK).fill(-0);var firstIndex=columnIndex*this.RANK;for(var _i35=0;_i35<this.RANK;++_i35){result[_i35]=this[firstIndex+_i35];}return result;}setColumn(columnIndex,columnVector){var firstIndex=columnIndex*this.RANK;for(var _i36=0;_i36<this.RANK;++_i36){this[firstIndex+_i36]=columnVector[_i36];}return this;}}/**
  59013. * 3x3 Matrix
  59014. * @module mat3
  59015. */ /**
  59016. * Creates a new identity mat3
  59017. *
  59018. * @returns {mat3} a new 3x3 matrix
  59019. */function create$2(){var out=new ARRAY_TYPE(9);if(ARRAY_TYPE!=Float32Array){out[1]=0;out[2]=0;out[3]=0;out[5]=0;out[6]=0;out[7]=0;}out[0]=1;out[4]=1;out[8]=1;return out;}/**
  59020. * Transpose the values of a mat3
  59021. *
  59022. * @param {mat3} out the receiving matrix
  59023. * @param {ReadonlyMat3} a the source matrix
  59024. * @returns {mat3} out
  59025. */function transpose$1(out,a){// If we are transposing ourselves we can skip a few steps but have to cache some values
  59026. if(out===a){var a01=a[1],a02=a[2],a12=a[5];out[1]=a[3];out[2]=a[6];out[3]=a01;out[5]=a[7];out[6]=a02;out[7]=a12;}else {out[0]=a[0];out[1]=a[3];out[2]=a[6];out[3]=a[1];out[4]=a[4];out[5]=a[7];out[6]=a[2];out[7]=a[5];out[8]=a[8];}return out;}/**
  59027. * Inverts a mat3
  59028. *
  59029. * @param {mat3} out the receiving matrix
  59030. * @param {ReadonlyMat3} a the source matrix
  59031. * @returns {mat3} out
  59032. */function invert$2(out,a){var a00=a[0],a01=a[1],a02=a[2];var a10=a[3],a11=a[4],a12=a[5];var a20=a[6],a21=a[7],a22=a[8];var b01=a22*a11-a12*a21;var b11=-a22*a10+a12*a20;var b21=a21*a10-a11*a20;// Calculate the determinant
  59033. var det=a00*b01+a01*b11+a02*b21;if(!det){return null;}det=1.0/det;out[0]=b01*det;out[1]=(-a22*a01+a02*a21)*det;out[2]=(a12*a01-a02*a11)*det;out[3]=b11*det;out[4]=(a22*a00-a02*a20)*det;out[5]=(-a12*a00+a02*a10)*det;out[6]=b21*det;out[7]=(-a21*a00+a01*a20)*det;out[8]=(a11*a00-a01*a10)*det;return out;}/**
  59034. * Calculates the determinant of a mat3
  59035. *
  59036. * @param {ReadonlyMat3} a the source matrix
  59037. * @returns {Number} determinant of a
  59038. */function determinant$1(a){var a00=a[0],a01=a[1],a02=a[2];var a10=a[3],a11=a[4],a12=a[5];var a20=a[6],a21=a[7],a22=a[8];return a00*(a22*a11-a12*a21)+a01*(-a22*a10+a12*a20)+a02*(a21*a10-a11*a20);}/**
  59039. * Multiplies two mat3's
  59040. *
  59041. * @param {mat3} out the receiving matrix
  59042. * @param {ReadonlyMat3} a the first operand
  59043. * @param {ReadonlyMat3} b the second operand
  59044. * @returns {mat3} out
  59045. */function multiply$2(out,a,b){var a00=a[0],a01=a[1],a02=a[2];var a10=a[3],a11=a[4],a12=a[5];var a20=a[6],a21=a[7],a22=a[8];var b00=b[0],b01=b[1],b02=b[2];var b10=b[3],b11=b[4],b12=b[5];var b20=b[6],b21=b[7],b22=b[8];out[0]=b00*a00+b01*a10+b02*a20;out[1]=b00*a01+b01*a11+b02*a21;out[2]=b00*a02+b01*a12+b02*a22;out[3]=b10*a00+b11*a10+b12*a20;out[4]=b10*a01+b11*a11+b12*a21;out[5]=b10*a02+b11*a12+b12*a22;out[6]=b20*a00+b21*a10+b22*a20;out[7]=b20*a01+b21*a11+b22*a21;out[8]=b20*a02+b21*a12+b22*a22;return out;}/**
  59046. * Translate a mat3 by the given vector
  59047. *
  59048. * @param {mat3} out the receiving matrix
  59049. * @param {ReadonlyMat3} a the matrix to translate
  59050. * @param {ReadonlyVec2} v vector to translate by
  59051. * @returns {mat3} out
  59052. */function translate$1(out,a,v){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],x=v[0],y=v[1];out[0]=a00;out[1]=a01;out[2]=a02;out[3]=a10;out[4]=a11;out[5]=a12;out[6]=x*a00+y*a10+a20;out[7]=x*a01+y*a11+a21;out[8]=x*a02+y*a12+a22;return out;}/**
  59053. * Rotates a mat3 by the given angle
  59054. *
  59055. * @param {mat3} out the receiving matrix
  59056. * @param {ReadonlyMat3} a the matrix to rotate
  59057. * @param {Number} rad the angle to rotate the matrix by
  59058. * @returns {mat3} out
  59059. */function rotate$1(out,a,rad){var a00=a[0],a01=a[1],a02=a[2],a10=a[3],a11=a[4],a12=a[5],a20=a[6],a21=a[7],a22=a[8],s=Math.sin(rad),c=Math.cos(rad);out[0]=c*a00+s*a10;out[1]=c*a01+s*a11;out[2]=c*a02+s*a12;out[3]=c*a10-s*a00;out[4]=c*a11-s*a01;out[5]=c*a12-s*a02;out[6]=a20;out[7]=a21;out[8]=a22;return out;}/**
  59060. * Scales the mat3 by the dimensions in the given vec2
  59061. *
  59062. * @param {mat3} out the receiving matrix
  59063. * @param {ReadonlyMat3} a the matrix to rotate
  59064. * @param {ReadonlyVec2} v the vec2 to scale the matrix by
  59065. * @returns {mat3} out
  59066. **/function scale$3(out,a,v){var x=v[0],y=v[1];out[0]=x*a[0];out[1]=x*a[1];out[2]=x*a[2];out[3]=y*a[3];out[4]=y*a[4];out[5]=y*a[5];out[6]=a[6];out[7]=a[7];out[8]=a[8];return out;}/**
  59067. * Calculates a 3x3 matrix from the given quaternion
  59068. *
  59069. * @param {mat3} out mat3 receiving operation result
  59070. * @param {ReadonlyQuat} q Quaternion to create matrix from
  59071. *
  59072. * @returns {mat3} out
  59073. */function fromQuat$1(out,q){var x=q[0],y=q[1],z=q[2],w=q[3];var x2=x+x;var y2=y+y;var z2=z+z;var xx=x*x2;var yx=y*x2;var yy=y*y2;var zx=z*x2;var zy=z*y2;var zz=z*z2;var wx=w*x2;var wy=w*y2;var wz=w*z2;out[0]=1-yy-zz;out[3]=yx-wz;out[6]=zx+wy;out[1]=yx+wz;out[4]=1-xx-zz;out[7]=zy-wx;out[2]=zx-wy;out[5]=zy+wx;out[8]=1-xx-yy;return out;}var IDENTITY$1=Object.freeze([1,0,0,0,1,0,0,0,1]);var ZERO$1=Object.freeze([0,0,0,0,0,0,0,0,0]);var INDICES$1=Object.freeze({COL0ROW0:0,COL0ROW1:1,COL0ROW2:2,COL1ROW0:3,COL1ROW1:4,COL1ROW2:5,COL2ROW0:6,COL2ROW1:7,COL2ROW2:8});var constants$1={};class Matrix3$1 extends Matrix{static get IDENTITY(){constants$1.IDENTITY=constants$1.IDENTITY||Object.freeze(new Matrix3$1(IDENTITY$1));return constants$1.IDENTITY;}static get ZERO(){constants$1.ZERO=constants$1.ZERO||Object.freeze(new Matrix3$1(ZERO$1));return constants$1.ZERO;}get ELEMENTS(){return 9;}get RANK(){return 3;}get INDICES(){return INDICES$1;}constructor(array){super(-0,-0,-0,-0,-0,-0,-0,-0,-0);if(arguments.length===1&&Array.isArray(array)){this.copy(array);}else {this.identity();}}copy(array){this[0]=array[0];this[1]=array[1];this[2]=array[2];this[3]=array[3];this[4]=array[4];this[5]=array[5];this[6]=array[6];this[7]=array[7];this[8]=array[8];return this.check();}set(m00,m10,m20,m01,m11,m21,m02,m12,m22){this[0]=m00;this[1]=m10;this[2]=m20;this[3]=m01;this[4]=m11;this[5]=m21;this[6]=m02;this[7]=m12;this[8]=m22;return this.check();}setRowMajor(m00,m01,m02,m10,m11,m12,m20,m21,m22){this[0]=m00;this[1]=m10;this[2]=m20;this[3]=m01;this[4]=m11;this[5]=m21;this[6]=m02;this[7]=m12;this[8]=m22;return this.check();}determinant(){return determinant$1(this);}identity(){return this.copy(IDENTITY$1);}fromQuaternion(q){fromQuat$1(this,q);return this.check();}transpose(){transpose$1(this,this);return this.check();}invert(){invert$2(this,this);return this.check();}multiplyLeft(a){multiply$2(this,a,this);return this.check();}multiplyRight(a){multiply$2(this,this,a);return this.check();}rotate(radians){rotate$1(this,this,radians);return this.check();}scale(factor){if(Array.isArray(factor)){scale$3(this,this,factor);}else {scale$3(this,this,[factor,factor,factor]);}return this.check();}translate(vec){translate$1(this,this,vec);return this.check();}transform(vector,result){switch(vector.length){case 2:result=transformMat3$1(result||[-0,-0],vector,this);break;case 3:result=transformMat3(result||[-0,-0,-0],vector,this);break;case 4:result=vec4_transformMat3(result||[-0,-0,-0,-0],vector,this);break;default:throw new Error('Illegal vector');}checkVector(result,vector.length);return result;}transformVector(vector,result){deprecated('Matrix3.transformVector');return this.transform(vector,result);}transformVector2(vector,result){deprecated('Matrix3.transformVector');return this.transform(vector,result);}transformVector3(vector,result){deprecated('Matrix3.transformVector');return this.transform(vector,result);}}/**
  59074. * Set a mat4 to the identity matrix
  59075. *
  59076. * @param {mat4} out the receiving matrix
  59077. * @returns {mat4} out
  59078. */function identity$1(out){out[0]=1;out[1]=0;out[2]=0;out[3]=0;out[4]=0;out[5]=1;out[6]=0;out[7]=0;out[8]=0;out[9]=0;out[10]=1;out[11]=0;out[12]=0;out[13]=0;out[14]=0;out[15]=1;return out;}/**
  59079. * Transpose the values of a mat4
  59080. *
  59081. * @param {mat4} out the receiving matrix
  59082. * @param {ReadonlyMat4} a the source matrix
  59083. * @returns {mat4} out
  59084. */function transpose(out,a){// If we are transposing ourselves we can skip a few steps but have to cache some values
  59085. if(out===a){var a01=a[1],a02=a[2],a03=a[3];var a12=a[6],a13=a[7];var a23=a[11];out[1]=a[4];out[2]=a[8];out[3]=a[12];out[4]=a01;out[6]=a[9];out[7]=a[13];out[8]=a02;out[9]=a12;out[11]=a[14];out[12]=a03;out[13]=a13;out[14]=a23;}else {out[0]=a[0];out[1]=a[4];out[2]=a[8];out[3]=a[12];out[4]=a[1];out[5]=a[5];out[6]=a[9];out[7]=a[13];out[8]=a[2];out[9]=a[6];out[10]=a[10];out[11]=a[14];out[12]=a[3];out[13]=a[7];out[14]=a[11];out[15]=a[15];}return out;}/**
  59086. * Inverts a mat4
  59087. *
  59088. * @param {mat4} out the receiving matrix
  59089. * @param {ReadonlyMat4} a the source matrix
  59090. * @returns {mat4} out
  59091. */function invert$1(out,a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3];var a10=a[4],a11=a[5],a12=a[6],a13=a[7];var a20=a[8],a21=a[9],a22=a[10],a23=a[11];var a30=a[12],a31=a[13],a32=a[14],a33=a[15];var b00=a00*a11-a01*a10;var b01=a00*a12-a02*a10;var b02=a00*a13-a03*a10;var b03=a01*a12-a02*a11;var b04=a01*a13-a03*a11;var b05=a02*a13-a03*a12;var b06=a20*a31-a21*a30;var b07=a20*a32-a22*a30;var b08=a20*a33-a23*a30;var b09=a21*a32-a22*a31;var b10=a21*a33-a23*a31;var b11=a22*a33-a23*a32;// Calculate the determinant
  59092. var det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;if(!det){return null;}det=1.0/det;out[0]=(a11*b11-a12*b10+a13*b09)*det;out[1]=(a02*b10-a01*b11-a03*b09)*det;out[2]=(a31*b05-a32*b04+a33*b03)*det;out[3]=(a22*b04-a21*b05-a23*b03)*det;out[4]=(a12*b08-a10*b11-a13*b07)*det;out[5]=(a00*b11-a02*b08+a03*b07)*det;out[6]=(a32*b02-a30*b05-a33*b01)*det;out[7]=(a20*b05-a22*b02+a23*b01)*det;out[8]=(a10*b10-a11*b08+a13*b06)*det;out[9]=(a01*b08-a00*b10-a03*b06)*det;out[10]=(a30*b04-a31*b02+a33*b00)*det;out[11]=(a21*b02-a20*b04-a23*b00)*det;out[12]=(a11*b07-a10*b09-a12*b06)*det;out[13]=(a00*b09-a01*b07+a02*b06)*det;out[14]=(a31*b01-a30*b03-a32*b00)*det;out[15]=(a20*b03-a21*b01+a22*b00)*det;return out;}/**
  59093. * Calculates the determinant of a mat4
  59094. *
  59095. * @param {ReadonlyMat4} a the source matrix
  59096. * @returns {Number} determinant of a
  59097. */function determinant(a){var a00=a[0],a01=a[1],a02=a[2],a03=a[3];var a10=a[4],a11=a[5],a12=a[6],a13=a[7];var a20=a[8],a21=a[9],a22=a[10],a23=a[11];var a30=a[12],a31=a[13],a32=a[14],a33=a[15];var b00=a00*a11-a01*a10;var b01=a00*a12-a02*a10;var b02=a00*a13-a03*a10;var b03=a01*a12-a02*a11;var b04=a01*a13-a03*a11;var b05=a02*a13-a03*a12;var b06=a20*a31-a21*a30;var b07=a20*a32-a22*a30;var b08=a20*a33-a23*a30;var b09=a21*a32-a22*a31;var b10=a21*a33-a23*a31;var b11=a22*a33-a23*a32;// Calculate the determinant
  59098. return b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;}/**
  59099. * Multiplies two mat4s
  59100. *
  59101. * @param {mat4} out the receiving matrix
  59102. * @param {ReadonlyMat4} a the first operand
  59103. * @param {ReadonlyMat4} b the second operand
  59104. * @returns {mat4} out
  59105. */function multiply$1(out,a,b){var a00=a[0],a01=a[1],a02=a[2],a03=a[3];var a10=a[4],a11=a[5],a12=a[6],a13=a[7];var a20=a[8],a21=a[9],a22=a[10],a23=a[11];var a30=a[12],a31=a[13],a32=a[14],a33=a[15];// Cache only the current line of the second matrix
  59106. var b0=b[0],b1=b[1],b2=b[2],b3=b[3];out[0]=b0*a00+b1*a10+b2*a20+b3*a30;out[1]=b0*a01+b1*a11+b2*a21+b3*a31;out[2]=b0*a02+b1*a12+b2*a22+b3*a32;out[3]=b0*a03+b1*a13+b2*a23+b3*a33;b0=b[4];b1=b[5];b2=b[6];b3=b[7];out[4]=b0*a00+b1*a10+b2*a20+b3*a30;out[5]=b0*a01+b1*a11+b2*a21+b3*a31;out[6]=b0*a02+b1*a12+b2*a22+b3*a32;out[7]=b0*a03+b1*a13+b2*a23+b3*a33;b0=b[8];b1=b[9];b2=b[10];b3=b[11];out[8]=b0*a00+b1*a10+b2*a20+b3*a30;out[9]=b0*a01+b1*a11+b2*a21+b3*a31;out[10]=b0*a02+b1*a12+b2*a22+b3*a32;out[11]=b0*a03+b1*a13+b2*a23+b3*a33;b0=b[12];b1=b[13];b2=b[14];b3=b[15];out[12]=b0*a00+b1*a10+b2*a20+b3*a30;out[13]=b0*a01+b1*a11+b2*a21+b3*a31;out[14]=b0*a02+b1*a12+b2*a22+b3*a32;out[15]=b0*a03+b1*a13+b2*a23+b3*a33;return out;}/**
  59107. * Translate a mat4 by the given vector
  59108. *
  59109. * @param {mat4} out the receiving matrix
  59110. * @param {ReadonlyMat4} a the matrix to translate
  59111. * @param {ReadonlyVec3} v vector to translate by
  59112. * @returns {mat4} out
  59113. */function translate(out,a,v){var x=v[0],y=v[1],z=v[2];var a00,a01,a02,a03;var a10,a11,a12,a13;var a20,a21,a22,a23;if(a===out){out[12]=a[0]*x+a[4]*y+a[8]*z+a[12];out[13]=a[1]*x+a[5]*y+a[9]*z+a[13];out[14]=a[2]*x+a[6]*y+a[10]*z+a[14];out[15]=a[3]*x+a[7]*y+a[11]*z+a[15];}else {a00=a[0];a01=a[1];a02=a[2];a03=a[3];a10=a[4];a11=a[5];a12=a[6];a13=a[7];a20=a[8];a21=a[9];a22=a[10];a23=a[11];out[0]=a00;out[1]=a01;out[2]=a02;out[3]=a03;out[4]=a10;out[5]=a11;out[6]=a12;out[7]=a13;out[8]=a20;out[9]=a21;out[10]=a22;out[11]=a23;out[12]=a00*x+a10*y+a20*z+a[12];out[13]=a01*x+a11*y+a21*z+a[13];out[14]=a02*x+a12*y+a22*z+a[14];out[15]=a03*x+a13*y+a23*z+a[15];}return out;}/**
  59114. * Scales the mat4 by the dimensions in the given vec3 not using vectorization
  59115. *
  59116. * @param {mat4} out the receiving matrix
  59117. * @param {ReadonlyMat4} a the matrix to scale
  59118. * @param {ReadonlyVec3} v the vec3 to scale the matrix by
  59119. * @returns {mat4} out
  59120. **/function scale$2(out,a,v){var x=v[0],y=v[1],z=v[2];out[0]=a[0]*x;out[1]=a[1]*x;out[2]=a[2]*x;out[3]=a[3]*x;out[4]=a[4]*y;out[5]=a[5]*y;out[6]=a[6]*y;out[7]=a[7]*y;out[8]=a[8]*z;out[9]=a[9]*z;out[10]=a[10]*z;out[11]=a[11]*z;out[12]=a[12];out[13]=a[13];out[14]=a[14];out[15]=a[15];return out;}/**
  59121. * Rotates a mat4 by the given angle around the given axis
  59122. *
  59123. * @param {mat4} out the receiving matrix
  59124. * @param {ReadonlyMat4} a the matrix to rotate
  59125. * @param {Number} rad the angle to rotate the matrix by
  59126. * @param {ReadonlyVec3} axis the axis to rotate around
  59127. * @returns {mat4} out
  59128. */function rotate(out,a,rad,axis){var x=axis[0],y=axis[1],z=axis[2];var len=Math.hypot(x,y,z);var s,c,t;var a00,a01,a02,a03;var a10,a11,a12,a13;var a20,a21,a22,a23;var b00,b01,b02;var b10,b11,b12;var b20,b21,b22;if(len<EPSILON){return null;}len=1/len;x*=len;y*=len;z*=len;s=Math.sin(rad);c=Math.cos(rad);t=1-c;a00=a[0];a01=a[1];a02=a[2];a03=a[3];a10=a[4];a11=a[5];a12=a[6];a13=a[7];a20=a[8];a21=a[9];a22=a[10];a23=a[11];// Construct the elements of the rotation matrix
  59129. b00=x*x*t+c;b01=y*x*t+z*s;b02=z*x*t-y*s;b10=x*y*t-z*s;b11=y*y*t+c;b12=z*y*t+x*s;b20=x*z*t+y*s;b21=y*z*t-x*s;b22=z*z*t+c;// Perform rotation-specific matrix multiplication
  59130. out[0]=a00*b00+a10*b01+a20*b02;out[1]=a01*b00+a11*b01+a21*b02;out[2]=a02*b00+a12*b01+a22*b02;out[3]=a03*b00+a13*b01+a23*b02;out[4]=a00*b10+a10*b11+a20*b12;out[5]=a01*b10+a11*b11+a21*b12;out[6]=a02*b10+a12*b11+a22*b12;out[7]=a03*b10+a13*b11+a23*b12;out[8]=a00*b20+a10*b21+a20*b22;out[9]=a01*b20+a11*b21+a21*b22;out[10]=a02*b20+a12*b21+a22*b22;out[11]=a03*b20+a13*b21+a23*b22;if(a!==out){// If the source and destination differ, copy the unchanged last row
  59131. out[12]=a[12];out[13]=a[13];out[14]=a[14];out[15]=a[15];}return out;}/**
  59132. * Rotates a matrix by the given angle around the X axis
  59133. *
  59134. * @param {mat4} out the receiving matrix
  59135. * @param {ReadonlyMat4} a the matrix to rotate
  59136. * @param {Number} rad the angle to rotate the matrix by
  59137. * @returns {mat4} out
  59138. */function rotateX$1(out,a,rad){var s=Math.sin(rad);var c=Math.cos(rad);var a10=a[4];var a11=a[5];var a12=a[6];var a13=a[7];var a20=a[8];var a21=a[9];var a22=a[10];var a23=a[11];if(a!==out){// If the source and destination differ, copy the unchanged rows
  59139. out[0]=a[0];out[1]=a[1];out[2]=a[2];out[3]=a[3];out[12]=a[12];out[13]=a[13];out[14]=a[14];out[15]=a[15];}// Perform axis-specific matrix multiplication
  59140. out[4]=a10*c+a20*s;out[5]=a11*c+a21*s;out[6]=a12*c+a22*s;out[7]=a13*c+a23*s;out[8]=a20*c-a10*s;out[9]=a21*c-a11*s;out[10]=a22*c-a12*s;out[11]=a23*c-a13*s;return out;}/**
  59141. * Rotates a matrix by the given angle around the Y axis
  59142. *
  59143. * @param {mat4} out the receiving matrix
  59144. * @param {ReadonlyMat4} a the matrix to rotate
  59145. * @param {Number} rad the angle to rotate the matrix by
  59146. * @returns {mat4} out
  59147. */function rotateY$1(out,a,rad){var s=Math.sin(rad);var c=Math.cos(rad);var a00=a[0];var a01=a[1];var a02=a[2];var a03=a[3];var a20=a[8];var a21=a[9];var a22=a[10];var a23=a[11];if(a!==out){// If the source and destination differ, copy the unchanged rows
  59148. out[4]=a[4];out[5]=a[5];out[6]=a[6];out[7]=a[7];out[12]=a[12];out[13]=a[13];out[14]=a[14];out[15]=a[15];}// Perform axis-specific matrix multiplication
  59149. out[0]=a00*c-a20*s;out[1]=a01*c-a21*s;out[2]=a02*c-a22*s;out[3]=a03*c-a23*s;out[8]=a00*s+a20*c;out[9]=a01*s+a21*c;out[10]=a02*s+a22*c;out[11]=a03*s+a23*c;return out;}/**
  59150. * Rotates a matrix by the given angle around the Z axis
  59151. *
  59152. * @param {mat4} out the receiving matrix
  59153. * @param {ReadonlyMat4} a the matrix to rotate
  59154. * @param {Number} rad the angle to rotate the matrix by
  59155. * @returns {mat4} out
  59156. */function rotateZ$1(out,a,rad){var s=Math.sin(rad);var c=Math.cos(rad);var a00=a[0];var a01=a[1];var a02=a[2];var a03=a[3];var a10=a[4];var a11=a[5];var a12=a[6];var a13=a[7];if(a!==out){// If the source and destination differ, copy the unchanged last row
  59157. out[8]=a[8];out[9]=a[9];out[10]=a[10];out[11]=a[11];out[12]=a[12];out[13]=a[13];out[14]=a[14];out[15]=a[15];}// Perform axis-specific matrix multiplication
  59158. out[0]=a00*c+a10*s;out[1]=a01*c+a11*s;out[2]=a02*c+a12*s;out[3]=a03*c+a13*s;out[4]=a10*c-a00*s;out[5]=a11*c-a01*s;out[6]=a12*c-a02*s;out[7]=a13*c-a03*s;return out;}/**
  59159. * Returns the scaling factor component of a transformation
  59160. * matrix. If a matrix is built with fromRotationTranslationScale
  59161. * with a normalized Quaternion paramter, the returned vector will be
  59162. * the same as the scaling vector
  59163. * originally supplied.
  59164. * @param {vec3} out Vector to receive scaling factor component
  59165. * @param {ReadonlyMat4} mat Matrix to be decomposed (input)
  59166. * @return {vec3} out
  59167. */function getScaling(out,mat){var m11=mat[0];var m12=mat[1];var m13=mat[2];var m21=mat[4];var m22=mat[5];var m23=mat[6];var m31=mat[8];var m32=mat[9];var m33=mat[10];out[0]=Math.hypot(m11,m12,m13);out[1]=Math.hypot(m21,m22,m23);out[2]=Math.hypot(m31,m32,m33);return out;}/**
  59168. * Calculates a 4x4 matrix from the given quaternion
  59169. *
  59170. * @param {mat4} out mat4 receiving operation result
  59171. * @param {ReadonlyQuat} q Quaternion to create matrix from
  59172. *
  59173. * @returns {mat4} out
  59174. */function fromQuat(out,q){var x=q[0],y=q[1],z=q[2],w=q[3];var x2=x+x;var y2=y+y;var z2=z+z;var xx=x*x2;var yx=y*x2;var yy=y*y2;var zx=z*x2;var zy=z*y2;var zz=z*z2;var wx=w*x2;var wy=w*y2;var wz=w*z2;out[0]=1-yy-zz;out[1]=yx+wz;out[2]=zx-wy;out[3]=0;out[4]=yx-wz;out[5]=1-xx-zz;out[6]=zy+wx;out[7]=0;out[8]=zx+wy;out[9]=zy-wx;out[10]=1-xx-yy;out[11]=0;out[12]=0;out[13]=0;out[14]=0;out[15]=1;return out;}/**
  59175. * Generates a frustum matrix with the given bounds
  59176. *
  59177. * @param {mat4} out mat4 frustum matrix will be written into
  59178. * @param {Number} left Left bound of the frustum
  59179. * @param {Number} right Right bound of the frustum
  59180. * @param {Number} bottom Bottom bound of the frustum
  59181. * @param {Number} top Top bound of the frustum
  59182. * @param {Number} near Near bound of the frustum
  59183. * @param {Number} far Far bound of the frustum
  59184. * @returns {mat4} out
  59185. */function frustum(out,left,right,bottom,top,near,far){var rl=1/(right-left);var tb=1/(top-bottom);var nf=1/(near-far);out[0]=near*2*rl;out[1]=0;out[2]=0;out[3]=0;out[4]=0;out[5]=near*2*tb;out[6]=0;out[7]=0;out[8]=(right+left)*rl;out[9]=(top+bottom)*tb;out[10]=(far+near)*nf;out[11]=-1;out[12]=0;out[13]=0;out[14]=far*near*2*nf;out[15]=0;return out;}/**
  59186. * Generates a perspective projection matrix with the given bounds.
  59187. * Passing null/undefined/no value for far will generate infinite projection matrix.
  59188. *
  59189. * @param {mat4} out mat4 frustum matrix will be written into
  59190. * @param {number} fovy Vertical field of view in radians
  59191. * @param {number} aspect Aspect ratio. typically viewport width/height
  59192. * @param {number} near Near bound of the frustum
  59193. * @param {number} far Far bound of the frustum, can be null or Infinity
  59194. * @returns {mat4} out
  59195. */function perspective(out,fovy,aspect,near,far){var f=1.0/Math.tan(fovy/2),nf;out[0]=f/aspect;out[1]=0;out[2]=0;out[3]=0;out[4]=0;out[5]=f;out[6]=0;out[7]=0;out[8]=0;out[9]=0;out[11]=-1;out[12]=0;out[13]=0;out[15]=0;if(far!=null&&far!==Infinity){nf=1/(near-far);out[10]=(far+near)*nf;out[14]=2*far*near*nf;}else {out[10]=-1;out[14]=-2*near;}return out;}/**
  59196. * Generates a orthogonal projection matrix with the given bounds
  59197. *
  59198. * @param {mat4} out mat4 frustum matrix will be written into
  59199. * @param {number} left Left bound of the frustum
  59200. * @param {number} right Right bound of the frustum
  59201. * @param {number} bottom Bottom bound of the frustum
  59202. * @param {number} top Top bound of the frustum
  59203. * @param {number} near Near bound of the frustum
  59204. * @param {number} far Far bound of the frustum
  59205. * @returns {mat4} out
  59206. */function ortho(out,left,right,bottom,top,near,far){var lr=1/(left-right);var bt=1/(bottom-top);var nf=1/(near-far);out[0]=-2*lr;out[1]=0;out[2]=0;out[3]=0;out[4]=0;out[5]=-2*bt;out[6]=0;out[7]=0;out[8]=0;out[9]=0;out[10]=2*nf;out[11]=0;out[12]=(left+right)*lr;out[13]=(top+bottom)*bt;out[14]=(far+near)*nf;out[15]=1;return out;}/**
  59207. * Generates a look-at matrix with the given eye position, focal point, and up axis.
  59208. * If you want a matrix that actually makes an object look at another object, you should use targetTo instead.
  59209. *
  59210. * @param {mat4} out mat4 frustum matrix will be written into
  59211. * @param {ReadonlyVec3} eye Position of the viewer
  59212. * @param {ReadonlyVec3} center Point the viewer is looking at
  59213. * @param {ReadonlyVec3} up vec3 pointing up
  59214. * @returns {mat4} out
  59215. */function lookAt(out,eye,center,up){var x0,x1,x2,y0,y1,y2,z0,z1,z2,len;var eyex=eye[0];var eyey=eye[1];var eyez=eye[2];var upx=up[0];var upy=up[1];var upz=up[2];var centerx=center[0];var centery=center[1];var centerz=center[2];if(Math.abs(eyex-centerx)<EPSILON&&Math.abs(eyey-centery)<EPSILON&&Math.abs(eyez-centerz)<EPSILON){return identity$1(out);}z0=eyex-centerx;z1=eyey-centery;z2=eyez-centerz;len=1/Math.hypot(z0,z1,z2);z0*=len;z1*=len;z2*=len;x0=upy*z2-upz*z1;x1=upz*z0-upx*z2;x2=upx*z1-upy*z0;len=Math.hypot(x0,x1,x2);if(!len){x0=0;x1=0;x2=0;}else {len=1/len;x0*=len;x1*=len;x2*=len;}y0=z1*x2-z2*x1;y1=z2*x0-z0*x2;y2=z0*x1-z1*x0;len=Math.hypot(y0,y1,y2);if(!len){y0=0;y1=0;y2=0;}else {len=1/len;y0*=len;y1*=len;y2*=len;}out[0]=x0;out[1]=y0;out[2]=z0;out[3]=0;out[4]=x1;out[5]=y1;out[6]=z1;out[7]=0;out[8]=x2;out[9]=y2;out[10]=z2;out[11]=0;out[12]=-(x0*eyex+x1*eyey+x2*eyez);out[13]=-(y0*eyex+y1*eyey+y2*eyez);out[14]=-(z0*eyex+z1*eyey+z2*eyez);out[15]=1;return out;}/**
  59216. * 4 Dimensional Vector
  59217. * @module vec4
  59218. */ /**
  59219. * Creates a new, empty vec4
  59220. *
  59221. * @returns {vec4} a new 4D vector
  59222. */function create$1(){var out=new ARRAY_TYPE(4);if(ARRAY_TYPE!=Float32Array){out[0]=0;out[1]=0;out[2]=0;out[3]=0;}return out;}/**
  59223. * Adds two vec4's
  59224. *
  59225. * @param {vec4} out the receiving vector
  59226. * @param {ReadonlyVec4} a the first operand
  59227. * @param {ReadonlyVec4} b the second operand
  59228. * @returns {vec4} out
  59229. */function add$1(out,a,b){out[0]=a[0]+b[0];out[1]=a[1]+b[1];out[2]=a[2]+b[2];out[3]=a[3]+b[3];return out;}/**
  59230. * Scales a vec4 by a scalar number
  59231. *
  59232. * @param {vec4} out the receiving vector
  59233. * @param {ReadonlyVec4} a the vector to scale
  59234. * @param {Number} b amount to scale the vector by
  59235. * @returns {vec4} out
  59236. */function scale$1(out,a,b){out[0]=a[0]*b;out[1]=a[1]*b;out[2]=a[2]*b;out[3]=a[3]*b;return out;}/**
  59237. * Calculates the length of a vec4
  59238. *
  59239. * @param {ReadonlyVec4} a vector to calculate length of
  59240. * @returns {Number} length of a
  59241. */function length$1(a){var x=a[0];var y=a[1];var z=a[2];var w=a[3];return Math.hypot(x,y,z,w);}/**
  59242. * Calculates the squared length of a vec4
  59243. *
  59244. * @param {ReadonlyVec4} a vector to calculate squared length of
  59245. * @returns {Number} squared length of a
  59246. */function squaredLength$1(a){var x=a[0];var y=a[1];var z=a[2];var w=a[3];return x*x+y*y+z*z+w*w;}/**
  59247. * Normalize a vec4
  59248. *
  59249. * @param {vec4} out the receiving vector
  59250. * @param {ReadonlyVec4} a vector to normalize
  59251. * @returns {vec4} out
  59252. */function normalize$1(out,a){var x=a[0];var y=a[1];var z=a[2];var w=a[3];var len=x*x+y*y+z*z+w*w;if(len>0){len=1/Math.sqrt(len);}out[0]=x*len;out[1]=y*len;out[2]=z*len;out[3]=w*len;return out;}/**
  59253. * Calculates the dot product of two vec4's
  59254. *
  59255. * @param {ReadonlyVec4} a the first operand
  59256. * @param {ReadonlyVec4} b the second operand
  59257. * @returns {Number} dot product of a and b
  59258. */function dot$1(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3];}/**
  59259. * Performs a linear interpolation between two vec4's
  59260. *
  59261. * @param {vec4} out the receiving vector
  59262. * @param {ReadonlyVec4} a the first operand
  59263. * @param {ReadonlyVec4} b the second operand
  59264. * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
  59265. * @returns {vec4} out
  59266. */function lerp$1$1(out,a,b,t){var ax=a[0];var ay=a[1];var az=a[2];var aw=a[3];out[0]=ax+t*(b[0]-ax);out[1]=ay+t*(b[1]-ay);out[2]=az+t*(b[2]-az);out[3]=aw+t*(b[3]-aw);return out;}/**
  59267. * Transforms the vec4 with a mat4.
  59268. *
  59269. * @param {vec4} out the receiving vector
  59270. * @param {ReadonlyVec4} a the vector to transform
  59271. * @param {ReadonlyMat4} m matrix to transform with
  59272. * @returns {vec4} out
  59273. */function transformMat4(out,a,m){var x=a[0],y=a[1],z=a[2],w=a[3];out[0]=m[0]*x+m[4]*y+m[8]*z+m[12]*w;out[1]=m[1]*x+m[5]*y+m[9]*z+m[13]*w;out[2]=m[2]*x+m[6]*y+m[10]*z+m[14]*w;out[3]=m[3]*x+m[7]*y+m[11]*z+m[15]*w;return out;}/**
  59274. * Transforms the vec4 with a quat
  59275. *
  59276. * @param {vec4} out the receiving vector
  59277. * @param {ReadonlyVec4} a the vector to transform
  59278. * @param {ReadonlyQuat} q quaternion to transform with
  59279. * @returns {vec4} out
  59280. */function transformQuat(out,a,q){var x=a[0],y=a[1],z=a[2];var qx=q[0],qy=q[1],qz=q[2],qw=q[3];// calculate quat * vec
  59281. var ix=qw*x+qy*z-qz*y;var iy=qw*y+qz*x-qx*z;var iz=qw*z+qx*y-qy*x;var iw=-qx*x-qy*y-qz*z;// calculate result * inverse quat
  59282. out[0]=ix*qw+iw*-qx+iy*-qz-iz*-qy;out[1]=iy*qw+iw*-qy+iz*-qx-ix*-qz;out[2]=iz*qw+iw*-qz+ix*-qy-iy*-qx;out[3]=a[3];return out;}/**
  59283. * Perform some operation over an array of vec4s.
  59284. *
  59285. * @param {Array} a the array of vectors to iterate over
  59286. * @param {Number} stride Number of elements between the start of each vec4. If 0 assumes tightly packed
  59287. * @param {Number} offset Number of elements to skip at the beginning of the array
  59288. * @param {Number} count Number of vec4s to iterate over. If 0 iterates over entire array
  59289. * @param {Function} fn Function to call for each vector in the array
  59290. * @param {Object} [arg] additional argument to pass to fn
  59291. * @returns {Array} a
  59292. * @function
  59293. */(function(){var vec=create$1();return function(a,stride,offset,count,fn,arg){var i,l;if(!stride){stride=4;}if(!offset){offset=0;}if(count){l=Math.min(count*stride+offset,a.length);}else {l=a.length;}for(i=offset;i<l;i+=stride){vec[0]=a[i];vec[1]=a[i+1];vec[2]=a[i+2];vec[3]=a[i+3];fn(vec,vec,arg);a[i]=vec[0];a[i+1]=vec[1];a[i+2]=vec[2];a[i+3]=vec[3];}return a;};})();var IDENTITY=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);var ZERO=Object.freeze([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);var INDICES=Object.freeze({COL0ROW0:0,COL0ROW1:1,COL0ROW2:2,COL0ROW3:3,COL1ROW0:4,COL1ROW1:5,COL1ROW2:6,COL1ROW3:7,COL2ROW0:8,COL2ROW1:9,COL2ROW2:10,COL2ROW3:11,COL3ROW0:12,COL3ROW1:13,COL3ROW2:14,COL3ROW3:15});var constants={};class Matrix4$1 extends Matrix{static get IDENTITY(){constants.IDENTITY=constants.IDENTITY||Object.freeze(new Matrix4$1(IDENTITY));return constants.IDENTITY;}static get ZERO(){constants.ZERO=constants.ZERO||Object.freeze(new Matrix4$1(ZERO));return constants.ZERO;}get INDICES(){return INDICES;}get ELEMENTS(){return 16;}get RANK(){return 4;}constructor(array){super(-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0);if(arguments.length===1&&Array.isArray(array)){this.copy(array);}else {this.identity();}}copy(array){this[0]=array[0];this[1]=array[1];this[2]=array[2];this[3]=array[3];this[4]=array[4];this[5]=array[5];this[6]=array[6];this[7]=array[7];this[8]=array[8];this[9]=array[9];this[10]=array[10];this[11]=array[11];this[12]=array[12];this[13]=array[13];this[14]=array[14];this[15]=array[15];return this.check();}set(m00,m10,m20,m30,m01,m11,m21,m31,m02,m12,m22,m32,m03,m13,m23,m33){this[0]=m00;this[1]=m10;this[2]=m20;this[3]=m30;this[4]=m01;this[5]=m11;this[6]=m21;this[7]=m31;this[8]=m02;this[9]=m12;this[10]=m22;this[11]=m32;this[12]=m03;this[13]=m13;this[14]=m23;this[15]=m33;return this.check();}setRowMajor(m00,m01,m02,m03,m10,m11,m12,m13,m20,m21,m22,m23,m30,m31,m32,m33){this[0]=m00;this[1]=m10;this[2]=m20;this[3]=m30;this[4]=m01;this[5]=m11;this[6]=m21;this[7]=m31;this[8]=m02;this[9]=m12;this[10]=m22;this[11]=m32;this[12]=m03;this[13]=m13;this[14]=m23;this[15]=m33;return this.check();}toRowMajor(result){result[0]=this[0];result[1]=this[4];result[2]=this[8];result[3]=this[12];result[4]=this[1];result[5]=this[5];result[6]=this[9];result[7]=this[13];result[8]=this[2];result[9]=this[6];result[10]=this[10];result[11]=this[14];result[12]=this[3];result[13]=this[7];result[14]=this[11];result[15]=this[15];return result;}identity(){return this.copy(IDENTITY);}fromQuaternion(q){fromQuat(this,q);return this.check();}frustum(_ref7){var{left,right,bottom,top,near,far}=_ref7;if(far===Infinity){Matrix4$1._computeInfinitePerspectiveOffCenter(this,left,right,bottom,top,near);}else {frustum(this,left,right,bottom,top,near,far);}return this.check();}static _computeInfinitePerspectiveOffCenter(result,left,right,bottom,top,near){var column0Row0=2.0*near/(right-left);var column1Row1=2.0*near/(top-bottom);var column2Row0=(right+left)/(right-left);var column2Row1=(top+bottom)/(top-bottom);var column2Row2=-1.0;var column2Row3=-1.0;var column3Row2=-2.0*near;result[0]=column0Row0;result[1]=0.0;result[2]=0.0;result[3]=0.0;result[4]=0.0;result[5]=column1Row1;result[6]=0.0;result[7]=0.0;result[8]=column2Row0;result[9]=column2Row1;result[10]=column2Row2;result[11]=column2Row3;result[12]=0.0;result[13]=0.0;result[14]=column3Row2;result[15]=0.0;return result;}lookAt(eye,center,up){if(arguments.length===1){({eye,center,up}=eye);}center=center||[0,0,0];up=up||[0,1,0];lookAt(this,eye,center,up);return this.check();}ortho(_ref8){var{left,right,bottom,top,near=0.1,far=500}=_ref8;ortho(this,left,right,bottom,top,near,far);return this.check();}orthographic(_ref9){var{fovy=45*Math.PI/180,aspect=1,focalDistance=1,near=0.1,far=500}=_ref9;if(fovy>Math.PI*2){throw Error('radians');}var halfY=fovy/2;var top=focalDistance*Math.tan(halfY);var right=top*aspect;return new Matrix4$1().ortho({left:-right,right,bottom:-top,top,near,far});}perspective(){var{fovy=undefined,fov=45*Math.PI/180,aspect=1,near=0.1,far=500}=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};fovy=fovy||fov;if(fovy>Math.PI*2){throw Error('radians');}perspective(this,fovy,aspect,near,far);return this.check();}determinant(){return determinant(this);}getScale(){var result=arguments.length>0&&arguments[0]!==undefined?arguments[0]:[-0,-0,-0];result[0]=Math.sqrt(this[0]*this[0]+this[1]*this[1]+this[2]*this[2]);result[1]=Math.sqrt(this[4]*this[4]+this[5]*this[5]+this[6]*this[6]);result[2]=Math.sqrt(this[8]*this[8]+this[9]*this[9]+this[10]*this[10]);return result;}getTranslation(){var result=arguments.length>0&&arguments[0]!==undefined?arguments[0]:[-0,-0,-0];result[0]=this[12];result[1]=this[13];result[2]=this[14];return result;}getRotation(){var result=arguments.length>0&&arguments[0]!==undefined?arguments[0]:[-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0];var scaleResult=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var scale=this.getScale(scaleResult||[-0,-0,-0]);var inverseScale0=1/scale[0];var inverseScale1=1/scale[1];var inverseScale2=1/scale[2];result[0]=this[0]*inverseScale0;result[1]=this[1]*inverseScale1;result[2]=this[2]*inverseScale2;result[3]=0;result[4]=this[4]*inverseScale0;result[5]=this[5]*inverseScale1;result[6]=this[6]*inverseScale2;result[7]=0;result[8]=this[8]*inverseScale0;result[9]=this[9]*inverseScale1;result[10]=this[10]*inverseScale2;result[11]=0;result[12]=0;result[13]=0;result[14]=0;result[15]=1;return result;}getRotationMatrix3(){var result=arguments.length>0&&arguments[0]!==undefined?arguments[0]:[-0,-0,-0,-0,-0,-0,-0,-0,-0];var scaleResult=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var scale=this.getScale(scaleResult||[-0,-0,-0]);var inverseScale0=1/scale[0];var inverseScale1=1/scale[1];var inverseScale2=1/scale[2];result[0]=this[0]*inverseScale0;result[1]=this[1]*inverseScale1;result[2]=this[2]*inverseScale2;result[3]=this[4]*inverseScale0;result[4]=this[5]*inverseScale1;result[5]=this[6]*inverseScale2;result[6]=this[8]*inverseScale0;result[7]=this[9]*inverseScale1;result[8]=this[10]*inverseScale2;return result;}transpose(){transpose(this,this);return this.check();}invert(){invert$1(this,this);return this.check();}multiplyLeft(a){multiply$1(this,a,this);return this.check();}multiplyRight(a){multiply$1(this,this,a);return this.check();}rotateX(radians){rotateX$1(this,this,radians);return this.check();}rotateY(radians){rotateY$1(this,this,radians);return this.check();}rotateZ(radians){rotateZ$1(this,this,radians);return this.check();}rotateXYZ(_ref10){var[rx,ry,rz]=_ref10;return this.rotateX(rx).rotateY(ry).rotateZ(rz);}rotateAxis(radians,axis){rotate(this,this,radians,axis);return this.check();}scale(factor){if(Array.isArray(factor)){scale$2(this,this,factor);}else {scale$2(this,this,[factor,factor,factor]);}return this.check();}translate(vec){translate(this,this,vec);return this.check();}transform(vector,result){if(vector.length===4){result=transformMat4(result||[-0,-0,-0,-0],vector,this);checkVector(result,4);return result;}return this.transformAsPoint(vector,result);}transformAsPoint(vector,result){var{length}=vector;switch(length){case 2:result=transformMat4$2(result||[-0,-0],vector,this);break;case 3:result=transformMat4$1(result||[-0,-0,-0],vector,this);break;default:throw new Error('Illegal vector');}checkVector(result,vector.length);return result;}transformAsVector(vector,result){switch(vector.length){case 2:result=vec2_transformMat4AsVector(result||[-0,-0],vector,this);break;case 3:result=vec3_transformMat4AsVector(result||[-0,-0,-0],vector,this);break;default:throw new Error('Illegal vector');}checkVector(result,vector.length);return result;}makeRotationX(radians){return this.identity().rotateX(radians);}makeTranslation(x,y,z){return this.identity().translate([x,y,z]);}transformPoint(vector,result){deprecated('Matrix4.transformPoint','3.0');return this.transformAsPoint(vector,result);}transformVector(vector,result){deprecated('Matrix4.transformVector','3.0');return this.transformAsPoint(vector,result);}transformDirection(vector,result){deprecated('Matrix4.transformDirection','3.0');return this.transformAsVector(vector,result);}}/**
  59294. * Quaternion
  59295. * @module quat
  59296. */ /**
  59297. * Creates a new identity quat
  59298. *
  59299. * @returns {quat} a new quaternion
  59300. */function create(){var out=new ARRAY_TYPE(4);if(ARRAY_TYPE!=Float32Array){out[0]=0;out[1]=0;out[2]=0;}out[3]=1;return out;}/**
  59301. * Set a quat to the identity quaternion
  59302. *
  59303. * @param {quat} out the receiving quaternion
  59304. * @returns {quat} out
  59305. */function identity(out){out[0]=0;out[1]=0;out[2]=0;out[3]=1;return out;}/**
  59306. * Sets a quat from the given angle and rotation axis,
  59307. * then returns it.
  59308. *
  59309. * @param {quat} out the receiving quaternion
  59310. * @param {ReadonlyVec3} axis the axis around which to rotate
  59311. * @param {Number} rad the angle in radians
  59312. * @returns {quat} out
  59313. **/function setAxisAngle(out,axis,rad){rad=rad*0.5;var s=Math.sin(rad);out[0]=s*axis[0];out[1]=s*axis[1];out[2]=s*axis[2];out[3]=Math.cos(rad);return out;}/**
  59314. * Multiplies two quat's
  59315. *
  59316. * @param {quat} out the receiving quaternion
  59317. * @param {ReadonlyQuat} a the first operand
  59318. * @param {ReadonlyQuat} b the second operand
  59319. * @returns {quat} out
  59320. */function multiply(out,a,b){var ax=a[0],ay=a[1],az=a[2],aw=a[3];var bx=b[0],by=b[1],bz=b[2],bw=b[3];out[0]=ax*bw+aw*bx+ay*bz-az*by;out[1]=ay*bw+aw*by+az*bx-ax*bz;out[2]=az*bw+aw*bz+ax*by-ay*bx;out[3]=aw*bw-ax*bx-ay*by-az*bz;return out;}/**
  59321. * Rotates a quaternion by the given angle about the X axis
  59322. *
  59323. * @param {quat} out quat receiving operation result
  59324. * @param {ReadonlyQuat} a quat to rotate
  59325. * @param {number} rad angle (in radians) to rotate
  59326. * @returns {quat} out
  59327. */function rotateX(out,a,rad){rad*=0.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3];var bx=Math.sin(rad),bw=Math.cos(rad);out[0]=ax*bw+aw*bx;out[1]=ay*bw+az*bx;out[2]=az*bw-ay*bx;out[3]=aw*bw-ax*bx;return out;}/**
  59328. * Rotates a quaternion by the given angle about the Y axis
  59329. *
  59330. * @param {quat} out quat receiving operation result
  59331. * @param {ReadonlyQuat} a quat to rotate
  59332. * @param {number} rad angle (in radians) to rotate
  59333. * @returns {quat} out
  59334. */function rotateY(out,a,rad){rad*=0.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3];var by=Math.sin(rad),bw=Math.cos(rad);out[0]=ax*bw-az*by;out[1]=ay*bw+aw*by;out[2]=az*bw+ax*by;out[3]=aw*bw-ay*by;return out;}/**
  59335. * Rotates a quaternion by the given angle about the Z axis
  59336. *
  59337. * @param {quat} out quat receiving operation result
  59338. * @param {ReadonlyQuat} a quat to rotate
  59339. * @param {number} rad angle (in radians) to rotate
  59340. * @returns {quat} out
  59341. */function rotateZ(out,a,rad){rad*=0.5;var ax=a[0],ay=a[1],az=a[2],aw=a[3];var bz=Math.sin(rad),bw=Math.cos(rad);out[0]=ax*bw+ay*bz;out[1]=ay*bw-ax*bz;out[2]=az*bw+aw*bz;out[3]=aw*bw-az*bz;return out;}/**
  59342. * Calculates the W component of a quat from the X, Y, and Z components.
  59343. * Assumes that quaternion is 1 unit in length.
  59344. * Any existing W component will be ignored.
  59345. *
  59346. * @param {quat} out the receiving quaternion
  59347. * @param {ReadonlyQuat} a quat to calculate W component of
  59348. * @returns {quat} out
  59349. */function calculateW(out,a){var x=a[0],y=a[1],z=a[2];out[0]=x;out[1]=y;out[2]=z;out[3]=Math.sqrt(Math.abs(1.0-x*x-y*y-z*z));return out;}/**
  59350. * Performs a spherical linear interpolation between two quat
  59351. *
  59352. * @param {quat} out the receiving quaternion
  59353. * @param {ReadonlyQuat} a the first operand
  59354. * @param {ReadonlyQuat} b the second operand
  59355. * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
  59356. * @returns {quat} out
  59357. */function slerp(out,a,b,t){// benchmarks:
  59358. // http://jsperf.com/quaternion-slerp-implementations
  59359. var ax=a[0],ay=a[1],az=a[2],aw=a[3];var bx=b[0],by=b[1],bz=b[2],bw=b[3];var omega,cosom,sinom,scale0,scale1;// calc cosine
  59360. cosom=ax*bx+ay*by+az*bz+aw*bw;// adjust signs (if necessary)
  59361. if(cosom<0.0){cosom=-cosom;bx=-bx;by=-by;bz=-bz;bw=-bw;}// calculate coefficients
  59362. if(1.0-cosom>EPSILON){// standard case (slerp)
  59363. omega=Math.acos(cosom);sinom=Math.sin(omega);scale0=Math.sin((1.0-t)*omega)/sinom;scale1=Math.sin(t*omega)/sinom;}else {// "from" and "to" quaternions are very close
  59364. // ... so we can do a linear interpolation
  59365. scale0=1.0-t;scale1=t;}// calculate final values
  59366. out[0]=scale0*ax+scale1*bx;out[1]=scale0*ay+scale1*by;out[2]=scale0*az+scale1*bz;out[3]=scale0*aw+scale1*bw;return out;}/**
  59367. * Calculates the inverse of a quat
  59368. *
  59369. * @param {quat} out the receiving quaternion
  59370. * @param {ReadonlyQuat} a quat to calculate inverse of
  59371. * @returns {quat} out
  59372. */function invert(out,a){var a0=a[0],a1=a[1],a2=a[2],a3=a[3];var dot=a0*a0+a1*a1+a2*a2+a3*a3;var invDot=dot?1.0/dot:0;// TODO: Would be faster to return [0,0,0,0] immediately if dot == 0
  59373. out[0]=-a0*invDot;out[1]=-a1*invDot;out[2]=-a2*invDot;out[3]=a3*invDot;return out;}/**
  59374. * Calculates the conjugate of a quat
  59375. * If the quaternion is normalized, this function is faster than quat.inverse and produces the same result.
  59376. *
  59377. * @param {quat} out the receiving quaternion
  59378. * @param {ReadonlyQuat} a quat to calculate conjugate of
  59379. * @returns {quat} out
  59380. */function conjugate(out,a){out[0]=-a[0];out[1]=-a[1];out[2]=-a[2];out[3]=a[3];return out;}/**
  59381. * Creates a quaternion from the given 3x3 rotation matrix.
  59382. *
  59383. * NOTE: The resultant quaternion is not normalized, so you should be sure
  59384. * to renormalize the quaternion yourself where necessary.
  59385. *
  59386. * @param {quat} out the receiving quaternion
  59387. * @param {ReadonlyMat3} m rotation matrix
  59388. * @returns {quat} out
  59389. * @function
  59390. */function fromMat3(out,m){// Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes
  59391. // article "Quaternion Calculus and Fast Animation".
  59392. var fTrace=m[0]+m[4]+m[8];var fRoot;if(fTrace>0.0){// |w| > 1/2, may as well choose w > 1/2
  59393. fRoot=Math.sqrt(fTrace+1.0);// 2w
  59394. out[3]=0.5*fRoot;fRoot=0.5/fRoot;// 1/(4w)
  59395. out[0]=(m[5]-m[7])*fRoot;out[1]=(m[6]-m[2])*fRoot;out[2]=(m[1]-m[3])*fRoot;}else {// |w| <= 1/2
  59396. var i=0;if(m[4]>m[0])i=1;if(m[8]>m[i*3+i])i=2;var j=(i+1)%3;var k=(i+2)%3;fRoot=Math.sqrt(m[i*3+i]-m[j*3+j]-m[k*3+k]+1.0);out[i]=0.5*fRoot;fRoot=0.5/fRoot;out[3]=(m[j*3+k]-m[k*3+j])*fRoot;out[j]=(m[j*3+i]+m[i*3+j])*fRoot;out[k]=(m[k*3+i]+m[i*3+k])*fRoot;}return out;}/**
  59397. * Adds two quat's
  59398. *
  59399. * @param {quat} out the receiving quaternion
  59400. * @param {ReadonlyQuat} a the first operand
  59401. * @param {ReadonlyQuat} b the second operand
  59402. * @returns {quat} out
  59403. * @function
  59404. */var add=add$1;/**
  59405. * Scales a quat by a scalar number
  59406. *
  59407. * @param {quat} out the receiving vector
  59408. * @param {ReadonlyQuat} a the vector to scale
  59409. * @param {Number} b amount to scale the vector by
  59410. * @returns {quat} out
  59411. * @function
  59412. */var scale=scale$1;/**
  59413. * Calculates the dot product of two quat's
  59414. *
  59415. * @param {ReadonlyQuat} a the first operand
  59416. * @param {ReadonlyQuat} b the second operand
  59417. * @returns {Number} dot product of a and b
  59418. * @function
  59419. */var dot=dot$1;/**
  59420. * Performs a linear interpolation between two quat's
  59421. *
  59422. * @param {quat} out the receiving quaternion
  59423. * @param {ReadonlyQuat} a the first operand
  59424. * @param {ReadonlyQuat} b the second operand
  59425. * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
  59426. * @returns {quat} out
  59427. * @function
  59428. */var lerp$2=lerp$1$1;/**
  59429. * Calculates the length of a quat
  59430. *
  59431. * @param {ReadonlyQuat} a vector to calculate length of
  59432. * @returns {Number} length of a
  59433. */var length=length$1;/**
  59434. * Calculates the squared length of a quat
  59435. *
  59436. * @param {ReadonlyQuat} a vector to calculate squared length of
  59437. * @returns {Number} squared length of a
  59438. * @function
  59439. */var squaredLength=squaredLength$1;/**
  59440. * Normalize a quat
  59441. *
  59442. * @param {quat} out the receiving quaternion
  59443. * @param {ReadonlyQuat} a quaternion to normalize
  59444. * @returns {quat} out
  59445. * @function
  59446. */var normalize=normalize$1;/**
  59447. * Sets a quaternion to represent the shortest rotation from one
  59448. * vector to another.
  59449. *
  59450. * Both vectors are assumed to be unit length.
  59451. *
  59452. * @param {quat} out the receiving quaternion.
  59453. * @param {ReadonlyVec3} a the initial vector
  59454. * @param {ReadonlyVec3} b the destination vector
  59455. * @returns {quat} out
  59456. */var rotationTo=function(){var tmpvec3=create$3();var xUnitVec3=fromValues(1,0,0);var yUnitVec3=fromValues(0,1,0);return function(out,a,b){var dot=dot$2(a,b);if(dot<-0.999999){cross(tmpvec3,xUnitVec3,a);if(len(tmpvec3)<0.000001)cross(tmpvec3,yUnitVec3,a);normalize$2(tmpvec3,tmpvec3);setAxisAngle(out,tmpvec3,Math.PI);return out;}else if(dot>0.999999){out[0]=0;out[1]=0;out[2]=0;out[3]=1;return out;}else {cross(tmpvec3,a,b);out[0]=tmpvec3[0];out[1]=tmpvec3[1];out[2]=tmpvec3[2];out[3]=1+dot;return normalize(out,out);}};}();/**
  59457. * Performs a spherical linear interpolation with two control points
  59458. *
  59459. * @param {quat} out the receiving quaternion
  59460. * @param {ReadonlyQuat} a the first operand
  59461. * @param {ReadonlyQuat} b the second operand
  59462. * @param {ReadonlyQuat} c the third operand
  59463. * @param {ReadonlyQuat} d the fourth operand
  59464. * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
  59465. * @returns {quat} out
  59466. */(function(){var temp1=create();var temp2=create();return function(out,a,b,c,d,t){slerp(temp1,a,d,t);slerp(temp2,b,c,t);slerp(out,temp1,temp2,2*t*(1-t));return out;};})();/**
  59467. * Sets the specified quaternion with values corresponding to the given
  59468. * axes. Each axis is a vec3 and is expected to be unit length and
  59469. * perpendicular to all other specified axes.
  59470. *
  59471. * @param {ReadonlyVec3} view the vector representing the viewing direction
  59472. * @param {ReadonlyVec3} right the vector representing the local "right" direction
  59473. * @param {ReadonlyVec3} up the vector representing the local "up" direction
  59474. * @returns {quat} out
  59475. */(function(){var matr=create$2();return function(out,view,right,up){matr[0]=right[0];matr[3]=right[1];matr[6]=right[2];matr[1]=up[0];matr[4]=up[1];matr[7]=up[2];matr[2]=-view[0];matr[5]=-view[1];matr[8]=-view[2];return normalize(out,fromMat3(out,matr));};})();var IDENTITY_QUATERNION=[0,0,0,1];class Quaternion$1 extends MathArray{constructor(){var x=arguments.length>0&&arguments[0]!==undefined?arguments[0]:0;var y=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var z=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0;var w=arguments.length>3&&arguments[3]!==undefined?arguments[3]:1;super(-0,-0,-0,-0);if(Array.isArray(x)&&arguments.length===1){this.copy(x);}else {this.set(x,y,z,w);}}copy(array){this[0]=array[0];this[1]=array[1];this[2]=array[2];this[3]=array[3];return this.check();}set(x,y,z,w){this[0]=x;this[1]=y;this[2]=z;this[3]=w;return this.check();}fromMatrix3(m){fromMat3(this,m);return this.check();}identity(){identity(this);return this.check();}fromAxisRotation(axis,rad){setAxisAngle(this,axis,rad);return this.check();}setAxisAngle(axis,rad){return this.fromAxisRotation(axis,rad);}get ELEMENTS(){return 4;}get x(){return this[0];}set x(value){this[0]=checkNumber(value);}get y(){return this[1];}set y(value){this[1]=checkNumber(value);}get z(){return this[2];}set z(value){this[2]=checkNumber(value);}get w(){return this[3];}set w(value){this[3]=checkNumber(value);}len(){return length(this);}lengthSquared(){return squaredLength(this);}dot(a,b){if(b!==undefined){throw new Error('Quaternion.dot only takes one argument');}return dot(this,a);}rotationTo(vectorA,vectorB){rotationTo(this,vectorA,vectorB);return this.check();}add(a,b){if(b!==undefined){throw new Error('Quaternion.add only takes one argument');}add(this,this,a);return this.check();}calculateW(){calculateW(this,this);return this.check();}conjugate(){conjugate(this,this);return this.check();}invert(){invert(this,this);return this.check();}lerp(a,b,t){lerp$2(this,a,b,t);return this.check();}multiplyRight(a,b){assert$4(!b);multiply(this,this,a);return this.check();}multiplyLeft(a,b){assert$4(!b);multiply(this,a,this);return this.check();}normalize(){var length=this.len();var l=length>0?1/length:0;this[0]=this[0]*l;this[1]=this[1]*l;this[2]=this[2]*l;this[3]=this[3]*l;if(length===0){this[3]=1;}return this.check();}rotateX(rad){rotateX(this,this,rad);return this.check();}rotateY(rad){rotateY(this,this,rad);return this.check();}rotateZ(rad){rotateZ(this,this,rad);return this.check();}scale(b){scale(this,this,b);return this.check();}slerp(start,target,ratio){switch(arguments.length){case 1:({start=IDENTITY_QUATERNION,target,ratio}=arguments[0]);break;case 2:[target,ratio]=arguments;start=this;break;}slerp(this,start,target,ratio);return this.check();}transformVector4(vector){var result=arguments.length>1&&arguments[1]!==undefined?arguments[1]:vector;transformQuat(result,vector,this);return checkVector(result,4);}lengthSq(){return this.lengthSquared();}setFromAxisAngle(axis,rad){return this.setAxisAngle(axis,rad);}premultiply(a,b){return this.multiplyLeft(a,b);}multiply(a,b){return this.multiplyRight(a,b);}}var _MathUtils={EPSILON1:1e-1,EPSILON2:1e-2,EPSILON3:1e-3,EPSILON4:1e-4,EPSILON5:1e-5,EPSILON6:1e-6,EPSILON7:1e-7,EPSILON8:1e-8,EPSILON9:1e-9,EPSILON10:1e-10,EPSILON11:1e-11,EPSILON12:1e-12,EPSILON13:1e-13,EPSILON14:1e-14,EPSILON15:1e-15,EPSILON16:1e-16,EPSILON17:1e-17,EPSILON18:1e-18,EPSILON19:1e-19,EPSILON20:1e-20,PI_OVER_TWO:Math.PI/2,PI_OVER_FOUR:Math.PI/4,PI_OVER_SIX:Math.PI/6,TWO_PI:Math.PI*2};var WGS84_RADIUS_X$1=6378137.0;var WGS84_RADIUS_Y$1=6378137.0;var WGS84_RADIUS_Z$1=6356752.3142451793;var noop$2=x=>x;var scratchVector$6=new Vector3$1();function fromCartographic(cartographic,result){var map=arguments.length>2&&arguments[2]!==undefined?arguments[2]:noop$2;if(isArray(cartographic)){result[0]=map(cartographic[0]);result[1]=map(cartographic[1]);result[2]=cartographic[2];}else if('longitude'in cartographic){result[0]=map(cartographic.longitude);result[1]=map(cartographic.latitude);result[2]=cartographic.height;}else {result[0]=map(cartographic.x);result[1]=map(cartographic.y);result[2]=cartographic.z;}return result;}function fromCartographicToRadians(cartographic){var vector=arguments.length>1&&arguments[1]!==undefined?arguments[1]:scratchVector$6;return fromCartographic(cartographic,vector,config$2._cartographicRadians?noop$2:toRadians);}function toCartographic(vector,cartographic){var map=arguments.length>2&&arguments[2]!==undefined?arguments[2]:noop$2;if(isArray(cartographic)){cartographic[0]=map(vector[0]);cartographic[1]=map(vector[1]);cartographic[2]=vector[2];}else if('longitude'in cartographic){cartographic.longitude=map(vector[0]);cartographic.latitude=map(vector[1]);cartographic.height=vector[2];}else {cartographic.x=map(vector[0]);cartographic.y=map(vector[1]);cartographic.z=vector[2];}return cartographic;}function toCartographicFromRadians(vector,cartographic){return toCartographic(vector,cartographic,config$2._cartographicRadians?noop$2:toDegrees);}var scratchVector$5=new Vector3$1();var scaleToGeodeticSurfaceIntersection=new Vector3$1();var scaleToGeodeticSurfaceGradient=new Vector3$1();function scaleToGeodeticSurface(cartesian,ellipsoid){var result=arguments.length>2&&arguments[2]!==undefined?arguments[2]:new Vector3$1();var{oneOverRadii,oneOverRadiiSquared,centerToleranceSquared}=ellipsoid;scratchVector$5.from(cartesian);var positionX=cartesian.x;var positionY=cartesian.y;var positionZ=cartesian.z;var oneOverRadiiX=oneOverRadii.x;var oneOverRadiiY=oneOverRadii.y;var oneOverRadiiZ=oneOverRadii.z;var x2=positionX*positionX*oneOverRadiiX*oneOverRadiiX;var y2=positionY*positionY*oneOverRadiiY*oneOverRadiiY;var z2=positionZ*positionZ*oneOverRadiiZ*oneOverRadiiZ;var squaredNorm=x2+y2+z2;var ratio=Math.sqrt(1.0/squaredNorm);if(!Number.isFinite(ratio)){return undefined;}var intersection=scaleToGeodeticSurfaceIntersection;intersection.copy(cartesian).scale(ratio);if(squaredNorm<centerToleranceSquared){return intersection.to(result);}var oneOverRadiiSquaredX=oneOverRadiiSquared.x;var oneOverRadiiSquaredY=oneOverRadiiSquared.y;var oneOverRadiiSquaredZ=oneOverRadiiSquared.z;var gradient=scaleToGeodeticSurfaceGradient;gradient.set(intersection.x*oneOverRadiiSquaredX*2.0,intersection.y*oneOverRadiiSquaredY*2.0,intersection.z*oneOverRadiiSquaredZ*2.0);var lambda=(1.0-ratio)*cartesian.len()/(0.5*gradient.len());var correction=0.0;var xMultiplier;var yMultiplier;var zMultiplier;var func;do{lambda-=correction;xMultiplier=1.0/(1.0+lambda*oneOverRadiiSquaredX);yMultiplier=1.0/(1.0+lambda*oneOverRadiiSquaredY);zMultiplier=1.0/(1.0+lambda*oneOverRadiiSquaredZ);var xMultiplier2=xMultiplier*xMultiplier;var yMultiplier2=yMultiplier*yMultiplier;var zMultiplier2=zMultiplier*zMultiplier;var xMultiplier3=xMultiplier2*xMultiplier;var yMultiplier3=yMultiplier2*yMultiplier;var zMultiplier3=zMultiplier2*zMultiplier;func=x2*xMultiplier2+y2*yMultiplier2+z2*zMultiplier2-1.0;var denominator=x2*xMultiplier3*oneOverRadiiSquaredX+y2*yMultiplier3*oneOverRadiiSquaredY+z2*zMultiplier3*oneOverRadiiSquaredZ;var derivative=-2.0*denominator;correction=func/derivative;}while(Math.abs(func)>_MathUtils.EPSILON12);return scratchVector$5.scale([xMultiplier,yMultiplier,zMultiplier]).to(result);}var EPSILON14=1e-14;var scratchOrigin=new Vector3$1();var VECTOR_PRODUCT_LOCAL_FRAME={up:{south:'east',north:'west',west:'south',east:'north'},down:{south:'west',north:'east',west:'north',east:'south'},south:{up:'west',down:'east',west:'down',east:'up'},north:{up:'east',down:'west',west:'up',east:'down'},west:{up:'north',down:'south',north:'down',south:'up'},east:{up:'south',down:'north',north:'up',south:'down'}};var degeneratePositionLocalFrame={north:[-1,0,0],east:[0,1,0],up:[0,0,1],south:[1,0,0],west:[0,-1,0],down:[0,0,-1]};var scratchAxisVectors={east:new Vector3$1(),north:new Vector3$1(),up:new Vector3$1(),west:new Vector3$1(),south:new Vector3$1(),down:new Vector3$1()};var scratchVector1=new Vector3$1();var scratchVector2$1=new Vector3$1();var scratchVector3$1=new Vector3$1();function localFrameToFixedFrame(ellipsoid,firstAxis,secondAxis,thirdAxis,cartesianOrigin,result){var thirdAxisInferred=VECTOR_PRODUCT_LOCAL_FRAME[firstAxis]&&VECTOR_PRODUCT_LOCAL_FRAME[firstAxis][secondAxis];assert$4(thirdAxisInferred&&(!thirdAxis||thirdAxis===thirdAxisInferred));var firstAxisVector;var secondAxisVector;var thirdAxisVector;var origin=scratchOrigin.copy(cartesianOrigin);var atPole=equals$1(origin.x,0.0,EPSILON14)&&equals$1(origin.y,0.0,EPSILON14);if(atPole){var sign=Math.sign(origin.z);firstAxisVector=scratchVector1.fromArray(degeneratePositionLocalFrame[firstAxis]);if(firstAxis!=='east'&&firstAxis!=='west'){firstAxisVector.scale(sign);}secondAxisVector=scratchVector2$1.fromArray(degeneratePositionLocalFrame[secondAxis]);if(secondAxis!=='east'&&secondAxis!=='west'){secondAxisVector.scale(sign);}thirdAxisVector=scratchVector3$1.fromArray(degeneratePositionLocalFrame[thirdAxis]);if(thirdAxis!=='east'&&thirdAxis!=='west'){thirdAxisVector.scale(sign);}}else {var{up,east,north}=scratchAxisVectors;east.set(-origin.y,origin.x,0.0).normalize();ellipsoid.geodeticSurfaceNormal(origin,up);north.copy(up).cross(east);var{down,west,south}=scratchAxisVectors;down.copy(up).scale(-1);west.copy(east).scale(-1);south.copy(north).scale(-1);firstAxisVector=scratchAxisVectors[firstAxis];secondAxisVector=scratchAxisVectors[secondAxis];thirdAxisVector=scratchAxisVectors[thirdAxis];}result[0]=firstAxisVector.x;result[1]=firstAxisVector.y;result[2]=firstAxisVector.z;result[3]=0.0;result[4]=secondAxisVector.x;result[5]=secondAxisVector.y;result[6]=secondAxisVector.z;result[7]=0.0;result[8]=thirdAxisVector.x;result[9]=thirdAxisVector.y;result[10]=thirdAxisVector.z;result[11]=0.0;result[12]=origin.x;result[13]=origin.y;result[14]=origin.z;result[15]=1.0;return result;}var scratchVector$4=new Vector3$1();var scratchNormal$2=new Vector3$1();var scratchK=new Vector3$1();var scratchPosition$2=new Vector3$1();var scratchHeight=new Vector3$1();var scratchCartesian=new Vector3$1();var wgs84;class Ellipsoid{static get WGS84(){wgs84=wgs84||new Ellipsoid(WGS84_RADIUS_X$1,WGS84_RADIUS_Y$1,WGS84_RADIUS_Z$1);return wgs84;}constructor(){var x=arguments.length>0&&arguments[0]!==undefined?arguments[0]:0.0;var y=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0.0;var z=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0.0;assert$4(x>=0.0);assert$4(y>=0.0);assert$4(z>=0.0);this.radii=new Vector3$1(x,y,z);this.radiiSquared=new Vector3$1(x*x,y*y,z*z);this.radiiToTheFourth=new Vector3$1(x*x*x*x,y*y*y*y,z*z*z*z);this.oneOverRadii=new Vector3$1(x===0.0?0.0:1.0/x,y===0.0?0.0:1.0/y,z===0.0?0.0:1.0/z);this.oneOverRadiiSquared=new Vector3$1(x===0.0?0.0:1.0/(x*x),y===0.0?0.0:1.0/(y*y),z===0.0?0.0:1.0/(z*z));this.minimumRadius=Math.min(x,y,z);this.maximumRadius=Math.max(x,y,z);this.centerToleranceSquared=_MathUtils.EPSILON1;if(this.radiiSquared.z!==0){this.squaredXOverSquaredZ=this.radiiSquared.x/this.radiiSquared.z;}Object.freeze(this);}equals(right){return this===right||Boolean(right&&this.radii.equals(right.radii));}toString(){return this.radii.toString();}cartographicToCartesian(cartographic){var result=arguments.length>1&&arguments[1]!==undefined?arguments[1]:[0,0,0];var normal=scratchNormal$2;var k=scratchK;var[,,height]=cartographic;this.geodeticSurfaceNormalCartographic(cartographic,normal);k.copy(this.radiiSquared).scale(normal);var gamma=Math.sqrt(normal.dot(k));k.scale(1/gamma);normal.scale(height);k.add(normal);return k.to(result);}cartesianToCartographic(cartesian){var result=arguments.length>1&&arguments[1]!==undefined?arguments[1]:[0,0,0];scratchCartesian.from(cartesian);var point=this.scaleToGeodeticSurface(scratchCartesian,scratchPosition$2);if(!point){return undefined;}var normal=this.geodeticSurfaceNormal(point,scratchNormal$2);var h=scratchHeight;h.copy(scratchCartesian).subtract(point);var longitude=Math.atan2(normal.y,normal.x);var latitude=Math.asin(normal.z);var height=Math.sign(dot$2(h,scratchCartesian))*length$2(h);return toCartographicFromRadians([longitude,latitude,height],result);}eastNorthUpToFixedFrame(origin){var result=arguments.length>1&&arguments[1]!==undefined?arguments[1]:new Matrix4$1();return localFrameToFixedFrame(this,'east','north','up',origin,result);}localFrameToFixedFrame(firstAxis,secondAxis,thirdAxis,origin){var result=arguments.length>4&&arguments[4]!==undefined?arguments[4]:new Matrix4$1();return localFrameToFixedFrame(this,firstAxis,secondAxis,thirdAxis,origin,result);}geocentricSurfaceNormal(cartesian){var result=arguments.length>1&&arguments[1]!==undefined?arguments[1]:[0,0,0];return scratchVector$4.from(cartesian).normalize().to(result);}geodeticSurfaceNormalCartographic(cartographic){var result=arguments.length>1&&arguments[1]!==undefined?arguments[1]:[0,0,0];var cartographicVectorRadians=fromCartographicToRadians(cartographic);var longitude=cartographicVectorRadians[0];var latitude=cartographicVectorRadians[1];var cosLatitude=Math.cos(latitude);scratchVector$4.set(cosLatitude*Math.cos(longitude),cosLatitude*Math.sin(longitude),Math.sin(latitude)).normalize();return scratchVector$4.to(result);}geodeticSurfaceNormal(cartesian){var result=arguments.length>1&&arguments[1]!==undefined?arguments[1]:[0,0,0];return scratchVector$4.from(cartesian).scale(this.oneOverRadiiSquared).normalize().to(result);}scaleToGeodeticSurface(cartesian,result){return scaleToGeodeticSurface(cartesian,this,result);}scaleToGeocentricSurface(cartesian){var result=arguments.length>1&&arguments[1]!==undefined?arguments[1]:[0,0,0];scratchPosition$2.from(cartesian);var positionX=scratchPosition$2.x;var positionY=scratchPosition$2.y;var positionZ=scratchPosition$2.z;var oneOverRadiiSquared=this.oneOverRadiiSquared;var beta=1.0/Math.sqrt(positionX*positionX*oneOverRadiiSquared.x+positionY*positionY*oneOverRadiiSquared.y+positionZ*positionZ*oneOverRadiiSquared.z);return scratchPosition$2.multiplyScalar(beta).to(result);}transformPositionToScaledSpace(position){var result=arguments.length>1&&arguments[1]!==undefined?arguments[1]:[0,0,0];return scratchPosition$2.from(position).scale(this.oneOverRadii).to(result);}transformPositionFromScaledSpace(position){var result=arguments.length>1&&arguments[1]!==undefined?arguments[1]:[0,0,0];return scratchPosition$2.from(position).scale(this.radii).to(result);}getSurfaceNormalIntersectionWithZAxis(position){var buffer=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0.0;var result=arguments.length>2&&arguments[2]!==undefined?arguments[2]:[0,0,0];assert$4(equals$1(this.radii.x,this.radii.y,_MathUtils.EPSILON15));assert$4(this.radii.z>0);scratchPosition$2.from(position);var z=scratchPosition$2.z*(1-this.squaredXOverSquaredZ);if(Math.abs(z)>=this.radii.z-buffer){return undefined;}return scratchPosition$2.set(0.0,0.0,z).to(result);}}class DoublyLinkedListNode{constructor(item,previous,next){_defineProperty$1(this,"item",void 0);_defineProperty$1(this,"previous",void 0);_defineProperty$1(this,"next",void 0);this.item=item;this.previous=previous;this.next=next;}}class DoublyLinkedList{constructor(){_defineProperty$1(this,"head",null);_defineProperty$1(this,"tail",null);_defineProperty$1(this,"_length",0);}get length(){return this._length;}add(item){var node=new DoublyLinkedListNode(item,this.tail,null);if(this.tail){this.tail.next=node;this.tail=node;}else {this.head=node;this.tail=node;}++this._length;return node;}remove(node){if(!node){return;}if(node.previous&&node.next){node.previous.next=node.next;node.next.previous=node.previous;}else if(node.previous){node.previous.next=null;this.tail=node.previous;}else if(node.next){node.next.previous=null;this.head=node.next;}else {this.head=null;this.tail=null;}node.next=null;node.previous=null;--this._length;}splice(node,nextNode){if(node===nextNode){return;}this.remove(nextNode);this._insert(node,nextNode);}_insert(node,nextNode){var oldNodeNext=node.next;node.next=nextNode;if(this.tail===node){this.tail=nextNode;}else {oldNodeNext.previous=nextNode;}nextNode.next=oldNodeNext;nextNode.previous=node;++this._length;}}function defined$5(x){return x!==undefined&&x!==null;}class TilesetCache{constructor(){_defineProperty$1(this,"_list",void 0);_defineProperty$1(this,"_sentinel",void 0);_defineProperty$1(this,"_trimTiles",void 0);this._list=new DoublyLinkedList();this._sentinel=this._list.add('sentinel');this._trimTiles=false;}reset(){this._list.splice(this._list.tail,this._sentinel);}touch(tile){var node=tile._cacheNode;if(defined$5(node)){this._list.splice(this._sentinel,node);}}add(tileset,tile,addCallback){if(!defined$5(tile._cacheNode)){tile._cacheNode=this._list.add(tile);if(addCallback){addCallback(tileset,tile);}}}unloadTile(tileset,tile,unloadCallback){var node=tile._cacheNode;if(!defined$5(node)){return;}this._list.remove(node);tile._cacheNode=undefined;if(unloadCallback){unloadCallback(tileset,tile);}}unloadTiles(tileset,unloadCallback){var trimTiles=this._trimTiles;this._trimTiles=false;var list=this._list;var maximumMemoryUsageInBytes=(Potree.settings.tiles3DMaxMemory||tileset.maximumMemoryUsage)*1024*1024;var sentinel=this._sentinel;var node=list.head;/* while (node !== sentinel && (tileset.gpuMemoryUsageInBytes > maximumMemoryUsageInBytes || trimTiles)) {
  59476. const tile = node.item;
  59477. node = node.next;
  59478. this.unloadTile(tileset, tile, unloadCallback);
  59479. } */ //改
  59480. while(node!==sentinel&&(getGpuMemoryUsage()>maximumMemoryUsageInBytes||trimTiles)){var tile=node.item;node=node.next;this.unloadTile(tileset,tile,unloadCallback);if(viewer.visiVertexCount>1500000){//add: 针对部分特别精细的很卡如 https://4dkk.4dage.com/scene_view_data/SG-t-WReTBN204dQ/images/3dtiles/tileset.json
  59481. tileset.options.maximumScreenSpaceError*=1.1;tileset.options.maximumScreenSpaceError=Math.min(1000,tileset.options.maximumScreenSpaceError);}}}trim(){this._trimTiles=true;}}function calculateTransformProps(tileHeader,tile){assert$7(tileHeader);assert$7(tile);var{rtcCenter,gltfUpAxis}=tile;var{computedTransform,boundingVolume:{center}}=tileHeader;var modelMatrix=new Matrix4$1(computedTransform);if(rtcCenter){modelMatrix.translate(rtcCenter);}switch(gltfUpAxis){case'Z':break;case'Y':var rotationY=new Matrix4$1().rotateX(Math.PI/2);modelMatrix=modelMatrix.multiplyRight(rotationY);break;case'X':var rotationX=new Matrix4$1().rotateY(-Math.PI/2);modelMatrix=modelMatrix.multiplyRight(rotationX);break;}if(tile.isQuantized){modelMatrix.translate(tile.quantizedVolumeOffset).scale(tile.quantizedVolumeScale);}var cartesianOrigin=new Vector3$1(center);tile.cartesianModelMatrix=modelMatrix;tile.cartesianOrigin=cartesianOrigin;var cartographicOrigin=Ellipsoid.WGS84.cartesianToCartographic(cartesianOrigin,new Vector3$1());var fromFixedFrameMatrix=Ellipsoid.WGS84.eastNorthUpToFixedFrame(cartesianOrigin);var toFixedFrameMatrix=fromFixedFrameMatrix.invert();tile.cartographicModelMatrix=toFixedFrameMatrix.multiplyRight(modelMatrix);tile.cartographicOrigin=cartographicOrigin;if(!tile.coordinateSystem){tile.modelMatrix=tile.cartographicModelMatrix;}}var INTERSECTION=Object.freeze({OUTSIDE:-1,INTERSECTING:0,INSIDE:1});new Vector3$1();new Vector3$1();var scratchVector$3=new Vector3$1();var scratchVector2=new Vector3$1();class BoundingSphere{constructor(){var center=arguments.length>0&&arguments[0]!==undefined?arguments[0]:[0,0,0];var radius=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0.0;this.radius=-0;this.center=new Vector3$1();this.fromCenterRadius(center,radius);}fromCenterRadius(center,radius){this.center.from(center);this.radius=radius;return this;}fromCornerPoints(corner,oppositeCorner){oppositeCorner=scratchVector$3.from(oppositeCorner);this.center=new Vector3$1().from(corner).add(oppositeCorner).scale(0.5);this.radius=this.center.distance(oppositeCorner);return this;}equals(right){return this===right||Boolean(right)&&this.center.equals(right.center)&&this.radius===right.radius;}clone(){return new BoundingSphere(this.center,this.radius);}union(boundingSphere){var leftCenter=this.center;var leftRadius=this.radius;var rightCenter=boundingSphere.center;var rightRadius=boundingSphere.radius;var toRightCenter=scratchVector$3.copy(rightCenter).subtract(leftCenter);var centerSeparation=toRightCenter.magnitude();if(leftRadius>=centerSeparation+rightRadius){return this.clone();}if(rightRadius>=centerSeparation+leftRadius){return boundingSphere.clone();}var halfDistanceBetweenTangentPoints=(leftRadius+centerSeparation+rightRadius)*0.5;scratchVector2.copy(toRightCenter).scale((-leftRadius+halfDistanceBetweenTangentPoints)/centerSeparation).add(leftCenter);this.center.copy(scratchVector2);this.radius=halfDistanceBetweenTangentPoints;return this;}expand(point){point=scratchVector$3.from(point);var radius=point.subtract(this.center).magnitude();if(radius>this.radius){this.radius=radius;}return this;}transform(transform){this.center.transform(transform);var scale=getScaling(scratchVector$3,transform);this.radius=Math.max(scale[0],Math.max(scale[1],scale[2]))*this.radius;return this;}distanceSquaredTo(point){var d=this.distanceTo(point);return d*d;}distanceTo(point){point=scratchVector$3.from(point);var delta=point.subtract(this.center);return Math.max(0,delta.len()-this.radius);}intersectPlane(plane){var center=this.center;var radius=this.radius;var normal=plane.normal;var distanceToPlane=normal.dot(center)+plane.distance;if(distanceToPlane<-radius){return INTERSECTION.OUTSIDE;}if(distanceToPlane<radius){return INTERSECTION.INTERSECTING;}return INTERSECTION.INSIDE;}}var scratchVector3=new Vector3$1();var scratchOffset=new Vector3$1();var scratchVectorU=new Vector3$1();var scratchVectorV=new Vector3$1();var scratchVectorW=new Vector3$1();var scratchCorner=new Vector3$1();var scratchToCenter=new Vector3$1();var MATRIX3={COLUMN0ROW0:0,COLUMN0ROW1:1,COLUMN0ROW2:2,COLUMN1ROW0:3,COLUMN1ROW1:4,COLUMN1ROW2:5,COLUMN2ROW0:6,COLUMN2ROW1:7,COLUMN2ROW2:8};class OrientedBoundingBox{constructor(){var center=arguments.length>0&&arguments[0]!==undefined?arguments[0]:[0,0,0];var halfAxes=arguments.length>1&&arguments[1]!==undefined?arguments[1]:[0,0,0,0,0,0,0,0,0];this.center=new Vector3$1().from(center);this.halfAxes=new Matrix3$1(halfAxes);}get halfSize(){var xAxis=this.halfAxes.getColumn(0);var yAxis=this.halfAxes.getColumn(1);var zAxis=this.halfAxes.getColumn(2);return [new Vector3$1(xAxis).len(),new Vector3$1(yAxis).len(),new Vector3$1(zAxis).len()];}get quaternion(){var xAxis=this.halfAxes.getColumn(0);var yAxis=this.halfAxes.getColumn(1);var zAxis=this.halfAxes.getColumn(2);var normXAxis=new Vector3$1(xAxis).normalize();var normYAxis=new Vector3$1(yAxis).normalize();var normZAxis=new Vector3$1(zAxis).normalize();return new Quaternion$1().fromMatrix3(new Matrix3$1([...normXAxis,...normYAxis,...normZAxis]));}fromCenterHalfSizeQuaternion(center,halfSize,quaternion){var quaternionObject=new Quaternion$1(quaternion);var directionsMatrix=new Matrix3$1().fromQuaternion(quaternionObject);directionsMatrix[0]=directionsMatrix[0]*halfSize[0];directionsMatrix[1]=directionsMatrix[1]*halfSize[0];directionsMatrix[2]=directionsMatrix[2]*halfSize[0];directionsMatrix[3]=directionsMatrix[3]*halfSize[1];directionsMatrix[4]=directionsMatrix[4]*halfSize[1];directionsMatrix[5]=directionsMatrix[5]*halfSize[1];directionsMatrix[6]=directionsMatrix[6]*halfSize[2];directionsMatrix[7]=directionsMatrix[7]*halfSize[2];directionsMatrix[8]=directionsMatrix[8]*halfSize[2];this.center=new Vector3$1().from(center);this.halfAxes=directionsMatrix;return this;}clone(){return new OrientedBoundingBox(this.center,this.halfAxes);}equals(right){return this===right||Boolean(right)&&this.center.equals(right.center)&&this.halfAxes.equals(right.halfAxes);}getBoundingSphere(){var result=arguments.length>0&&arguments[0]!==undefined?arguments[0]:new BoundingSphere();var halfAxes=this.halfAxes;var u=halfAxes.getColumn(0,scratchVectorU);//前三个
  59482. var v=halfAxes.getColumn(1,scratchVectorV);var w=halfAxes.getColumn(2,scratchVectorW);var cornerVector=scratchVector3.copy(u).add(v).add(w);result.center.copy(this.center);result.radius=cornerVector.magnitude();return result;}intersectPlane(plane){var center=this.center;var normal=plane.normal;var halfAxes=this.halfAxes;var normalX=normal.x;var normalY=normal.y;var normalZ=normal.z;var radEffective=Math.abs(normalX*halfAxes[MATRIX3.COLUMN0ROW0]+normalY*halfAxes[MATRIX3.COLUMN0ROW1]+normalZ*halfAxes[MATRIX3.COLUMN0ROW2])+Math.abs(normalX*halfAxes[MATRIX3.COLUMN1ROW0]+normalY*halfAxes[MATRIX3.COLUMN1ROW1]+normalZ*halfAxes[MATRIX3.COLUMN1ROW2])+Math.abs(normalX*halfAxes[MATRIX3.COLUMN2ROW0]+normalY*halfAxes[MATRIX3.COLUMN2ROW1]+normalZ*halfAxes[MATRIX3.COLUMN2ROW2]);var distanceToPlane=normal.dot(center)+plane.distance;if(distanceToPlane<=-radEffective){return INTERSECTION.OUTSIDE;}else if(distanceToPlane>=radEffective){return INTERSECTION.INSIDE;}return INTERSECTION.INTERSECTING;//在相机frustum内
  59483. }distanceTo(point){return Math.sqrt(this.distanceSquaredTo(point));}/* distanceSquaredTo(point) {//相机到bound外壳的距离平方
  59484. let center = this.center.clone()
  59485. center.z *= -1
  59486. const offset = scratchOffset.from(point).subtract(center);
  59487. const halfAxes = this.halfAxes;
  59488. const u = halfAxes.getColumn(0, scratchVectorU);
  59489. const v = halfAxes.getColumn(1, scratchVectorV);
  59490. const w = halfAxes.getColumn(2, scratchVectorW);
  59491. u.z *= -1
  59492. v.z *= -1
  59493. w.z *= -1
  59494. const uHalf = u.magnitude();
  59495. const vHalf = v.magnitude();
  59496. const wHalf = w.magnitude();
  59497. u.normalize();
  59498. v.normalize();
  59499. w.normalize();
  59500. let distanceSquared = 0.0;
  59501. let d;
  59502. d = Math.abs(offset.dot(u)) - uHalf;
  59503. if (d > 0) {
  59504. distanceSquared += d * d;
  59505. }
  59506. d = Math.abs(offset.dot(v)) - vHalf;
  59507. if (d > 0) {
  59508. distanceSquared += d * d;
  59509. }
  59510. d = Math.abs(offset.dot(w)) - wHalf;
  59511. if (d > 0) {
  59512. distanceSquared += d * d;
  59513. }
  59514. return distanceSquared;
  59515. } */distanceSquaredTo(point){//相机到bound外壳的距离平方
  59516. var offset=scratchOffset.from(point).subtract(this.center);var halfAxes=this.halfAxes;var u=halfAxes.getColumn(0,scratchVectorU);var v=halfAxes.getColumn(1,scratchVectorV);var w=halfAxes.getColumn(2,scratchVectorW);var uHalf=u.magnitude();var vHalf=v.magnitude();var wHalf=w.magnitude();u.normalize();v.normalize();w.normalize();var distanceSquared=0.0;var d;d=Math.abs(offset.dot(u))-uHalf;if(d>0){distanceSquared+=d*d;}d=Math.abs(offset.dot(v))-vHalf;if(d>0){distanceSquared+=d*d;}d=Math.abs(offset.dot(w))-wHalf;if(d>0){distanceSquared+=d*d;}return distanceSquared;}computePlaneDistances(position,direction){var result=arguments.length>2&&arguments[2]!==undefined?arguments[2]:[-0,-0];var minDist=Number.POSITIVE_INFINITY;var maxDist=Number.NEGATIVE_INFINITY;var center=this.center;var halfAxes=this.halfAxes;var u=halfAxes.getColumn(0,scratchVectorU);var v=halfAxes.getColumn(1,scratchVectorV);var w=halfAxes.getColumn(2,scratchVectorW);var corner=scratchCorner.copy(u).add(v).add(w).add(center);var toCenter=scratchToCenter.copy(corner).subtract(position);var mag=direction.dot(toCenter);minDist=Math.min(mag,minDist);maxDist=Math.max(mag,maxDist);corner.copy(center).add(u).add(v).subtract(w);toCenter.copy(corner).subtract(position);mag=direction.dot(toCenter);minDist=Math.min(mag,minDist);maxDist=Math.max(mag,maxDist);corner.copy(center).add(u).subtract(v).add(w);toCenter.copy(corner).subtract(position);mag=direction.dot(toCenter);minDist=Math.min(mag,minDist);maxDist=Math.max(mag,maxDist);corner.copy(center).add(u).subtract(v).subtract(w);toCenter.copy(corner).subtract(position);mag=direction.dot(toCenter);minDist=Math.min(mag,minDist);maxDist=Math.max(mag,maxDist);center.copy(corner).subtract(u).add(v).add(w);toCenter.copy(corner).subtract(position);mag=direction.dot(toCenter);minDist=Math.min(mag,minDist);maxDist=Math.max(mag,maxDist);center.copy(corner).subtract(u).add(v).subtract(w);toCenter.copy(corner).subtract(position);mag=direction.dot(toCenter);minDist=Math.min(mag,minDist);maxDist=Math.max(mag,maxDist);center.copy(corner).subtract(u).subtract(v).add(w);toCenter.copy(corner).subtract(position);mag=direction.dot(toCenter);minDist=Math.min(mag,minDist);maxDist=Math.max(mag,maxDist);center.copy(corner).subtract(u).subtract(v).subtract(w);toCenter.copy(corner).subtract(position);mag=direction.dot(toCenter);minDist=Math.min(mag,minDist);maxDist=Math.max(mag,maxDist);result[0]=minDist;result[1]=maxDist;return result;}transform(transformation){this.center.transformAsPoint(transformation);var xAxis=this.halfAxes.getColumn(0,scratchVectorU);xAxis.transformAsPoint(transformation);var yAxis=this.halfAxes.getColumn(1,scratchVectorV);yAxis.transformAsPoint(transformation);var zAxis=this.halfAxes.getColumn(2,scratchVectorW);zAxis.transformAsPoint(transformation);this.halfAxes=new Matrix3$1([...xAxis,...yAxis,...zAxis]);return this;}getTransform(){throw new Error('not implemented');}}var scratchPosition$1=new Vector3$1();var scratchNormal$1=new Vector3$1();class Plane$1{constructor(){var normal=arguments.length>0&&arguments[0]!==undefined?arguments[0]:[0,0,1];var distance=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;this.normal=new Vector3$1();this.distance=-0;this.fromNormalDistance(normal,distance);}fromNormalDistance(normal,distance){assert$4(Number.isFinite(distance));this.normal.from(normal).normalize();this.distance=distance;return this;}fromPointNormal(point,normal){point=scratchPosition$1.from(point);this.normal.from(normal).normalize();var distance=-this.normal.dot(point);this.distance=distance;return this;}fromCoefficients(a,b,c,d){this.normal.set(a,b,c);assert$4(equals$1(this.normal.len(),1));this.distance=d;return this;}clone(plane){return new Plane$1(this.normal,this.distance);}equals(right){return equals$1(this.distance,right.distance)&&equals$1(this.normal,right.normal);}getPointDistance(point){return this.normal.dot(point)+this.distance;}transform(matrix4){var normal=scratchNormal$1.copy(this.normal).transformAsVector(matrix4).normalize();var point=this.normal.scale(-this.distance).transform(matrix4);return this.fromPointNormal(point,normal);}projectPointOntoPlane(point){var result=arguments.length>1&&arguments[1]!==undefined?arguments[1]:[0,0,0];point=scratchPosition$1.from(point);var pointDistance=this.getPointDistance(point);var scaledNormal=scratchNormal$1.copy(this.normal).scale(pointDistance);return point.subtract(scaledNormal).to(result);}}var faces=[new Vector3$1([1,0,0]),new Vector3$1([0,1,0]),new Vector3$1([0,0,1])];var scratchPlaneCenter=new Vector3$1();var scratchPlaneNormal$1=new Vector3$1();new Plane$1(new Vector3$1(1.0,0.0,0.0),0.0);class CullingVolume{static get MASK_OUTSIDE(){return 0xffffffff;}static get MASK_INSIDE(){return 0x00000000;}static get MASK_INDETERMINATE(){return 0x7fffffff;}constructor(){var planes=arguments.length>0&&arguments[0]!==undefined?arguments[0]:[];this.planes=planes;assert$4(this.planes.every(plane=>plane instanceof Plane$1));}fromBoundingSphere(boundingSphere){this.planes.length=2*faces.length;var center=boundingSphere.center;var radius=boundingSphere.radius;var planeIndex=0;for(var faceNormal of faces){var plane0=this.planes[planeIndex];var plane1=this.planes[planeIndex+1];if(!plane0){plane0=this.planes[planeIndex]=new Plane$1();}if(!plane1){plane1=this.planes[planeIndex+1]=new Plane$1();}var plane0Center=scratchPlaneCenter.copy(faceNormal).scale(-radius).add(center);-faceNormal.dot(plane0Center);plane0.fromPointNormal(plane0Center,faceNormal);var plane1Center=scratchPlaneCenter.copy(faceNormal).scale(radius).add(center);var negatedFaceNormal=scratchPlaneNormal$1.copy(faceNormal).negate();-negatedFaceNormal.dot(plane1Center);plane1.fromPointNormal(plane1Center,negatedFaceNormal);planeIndex+=2;}return this;}computeVisibility(boundingVolume){assert$4(boundingVolume);var intersect=INTERSECTION.INSIDE;for(var plane of this.planes){var result=boundingVolume.intersectPlane(plane);switch(result){case INTERSECTION.OUTSIDE:return INTERSECTION.OUTSIDE;case INTERSECTION.INTERSECTING:intersect=INTERSECTION.INTERSECTING;break;}}return intersect;}computeVisibilityWithPlaneMask(boundingVolume,parentPlaneMask){assert$4(boundingVolume,'boundingVolume is required.');assert$4(Number.isFinite(parentPlaneMask),'parentPlaneMask is required.');if(parentPlaneMask===CullingVolume.MASK_OUTSIDE||parentPlaneMask===CullingVolume.MASK_INSIDE){return parentPlaneMask;}var mask=CullingVolume.MASK_INSIDE;var planes=this.planes;for(var k=0;k<this.planes.length;++k){var flag=k<31?1<<k:0;if(k<31&&(parentPlaneMask&flag)===0){continue;}var plane=planes[k];var result=boundingVolume.intersectPlane(plane);if(result===INTERSECTION.OUTSIDE){return CullingVolume.MASK_OUTSIDE;}else if(result===INTERSECTION.INTERSECTING){mask|=flag;}}return mask;}}var scratchPlaneUpVector=new Vector3$1();var scratchPlaneRightVector=new Vector3$1();var scratchPlaneNearCenter=new Vector3$1();var scratchPlaneFarCenter=new Vector3$1();var scratchPlaneNormal=new Vector3$1();class PerspectiveOffCenterFrustum{constructor(){var options=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};options=_objectSpread2({near:1.0,far:500000000.0},options);this.left=options.left;this._left=undefined;this.right=options.right;this._right=undefined;this.top=options.top;this._top=undefined;this.bottom=options.bottom;this._bottom=undefined;this.near=options.near;this._near=this.near;this.far=options.far;this._far=this.far;this._cullingVolume=new CullingVolume([new Plane$1(),new Plane$1(),new Plane$1(),new Plane$1(),new Plane$1(),new Plane$1()]);this._perspectiveMatrix=new Matrix4$1();this._infinitePerspective=new Matrix4$1();}clone(){return new PerspectiveOffCenterFrustum({right:this.right,left:this.left,top:this.top,bottom:this.bottom,near:this.near,far:this.far});}equals(other){return other&&other instanceof PerspectiveOffCenterFrustum&&this.right===other.right&&this.left===other.left&&this.top===other.top&&this.bottom===other.bottom&&this.near===other.near&&this.far===other.far;}get projectionMatrix(){update$1(this);return this._perspectiveMatrix;}get infiniteProjectionMatrix(){update$1(this);return this._infinitePerspective;}computeCullingVolume(position,direction,up){assert$4(position,'position is required.');assert$4(direction,'direction is required.');assert$4(up,'up is required.');var planes=this._cullingVolume.planes;up=scratchPlaneUpVector.copy(up).normalize();var right=scratchPlaneRightVector.copy(direction).cross(up).normalize();var nearCenter=scratchPlaneNearCenter.copy(direction).multiplyByScalar(this.near).add(position);var farCenter=scratchPlaneFarCenter.copy(direction).multiplyByScalar(this.far).add(position);var normal=scratchPlaneNormal;normal.copy(right).multiplyByScalar(this.left).add(nearCenter).subtract(position).cross(up);planes[0].fromPointNormal(position,normal);normal.copy(right).multiplyByScalar(this.right).add(nearCenter).subtract(position).cross(up).negate();planes[1].fromPointNormal(position,normal);normal.copy(up).multiplyByScalar(this.bottom).add(nearCenter).subtract(position).cross(right).negate();planes[2].fromPointNormal(position,normal);normal.copy(up).multiplyByScalar(this.top).add(nearCenter).subtract(position).cross(right);planes[3].fromPointNormal(position,normal);normal=new Vector3$1().copy(direction);planes[4].fromPointNormal(nearCenter,normal);normal.negate();planes[5].fromPointNormal(farCenter,normal);return this._cullingVolume;}getPixelDimensions(drawingBufferWidth,drawingBufferHeight,distance,result){update$1(this);assert$4(Number.isFinite(drawingBufferWidth)&&Number.isFinite(drawingBufferHeight));assert$4(drawingBufferWidth>0);assert$4(drawingBufferHeight>0);assert$4(distance>0);assert$4(result);var inverseNear=1.0/this.near;var tanTheta=this.top*inverseNear;var pixelHeight=2.0*distance*tanTheta/drawingBufferHeight;tanTheta=this.right*inverseNear;var pixelWidth=2.0*distance*tanTheta/drawingBufferWidth;result.x=pixelWidth;result.y=pixelHeight;return result;}}function update$1(frustum){assert$4(Number.isFinite(frustum.right)&&Number.isFinite(frustum.left)&&Number.isFinite(frustum.top)&&Number.isFinite(frustum.bottom)&&Number.isFinite(frustum.near)&&Number.isFinite(frustum.far));var{top,bottom,right,left,near,far}=frustum;if(top!==frustum._top||bottom!==frustum._bottom||left!==frustum._left||right!==frustum._right||near!==frustum._near||far!==frustum._far){assert$4(frustum.near>0&&frustum.near<frustum.far,'near must be greater than zero and less than far.');frustum._left=left;frustum._right=right;frustum._top=top;frustum._bottom=bottom;frustum._near=near;frustum._far=far;frustum._perspectiveMatrix=new Matrix4$1().frustum({left,right,bottom,top,near,far});frustum._infinitePerspective=new Matrix4$1().frustum({left,right,bottom,top,near,far:Infinity});}}var defined$4=val=>val!==null&&typeof val!=='undefined';class PerspectiveFrustum{constructor(){var options=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};options=_objectSpread2({near:1.0,far:500000000.0,xOffset:0.0,yOffset:0.0},options);this._offCenterFrustum=new PerspectiveOffCenterFrustum();this.fov=options.fov;this._fov=undefined;this._fovy=undefined;this._sseDenominator=undefined;this.aspectRatio=options.aspectRatio;this._aspectRatio=undefined;this.near=options.near;this._near=this.near;this.far=options.far;this._far=this.far;this.xOffset=options.xOffset;this._xOffset=this.xOffset;this.yOffset=options.yOffset;this._yOffset=this.yOffset;}clone(){return new PerspectiveFrustum({aspectRatio:this.aspectRatio,fov:this.fov,near:this.near,far:this.far});}equals(other){if(!defined$4(other)||!(other instanceof PerspectiveFrustum)){return false;}update(this);update(other);return this.fov===other.fov&&this.aspectRatio===other.aspectRatio&&this.near===other.near&&this.far===other.far&&this._offCenterFrustum.equals(other._offCenterFrustum);}get projectionMatrix(){update(this);return this._offCenterFrustum.projectionMatrix;}get infiniteProjectionMatrix(){update(this);return this._offCenterFrustum.infiniteProjectionMatrix;}get fovy(){update(this);return this._fovy;}get sseDenominator(){update(this);return this._sseDenominator;}computeCullingVolume(position,direction,up){update(this);return this._offCenterFrustum.computeCullingVolume(position,direction,up);}getPixelDimensions(drawingBufferWidth,drawingBufferHeight,distance,result){update(this);return this._offCenterFrustum.getPixelDimensions(drawingBufferWidth,drawingBufferHeight,distance,result);}}function update(frustum){assert$4(Number.isFinite(frustum.fov)&&Number.isFinite(frustum.aspectRatio)&&Number.isFinite(frustum.near)&&Number.isFinite(frustum.far));var f=frustum._offCenterFrustum;if(frustum.fov!==frustum._fov||frustum.aspectRatio!==frustum._aspectRatio||frustum.near!==frustum._near||frustum.far!==frustum._far||frustum.xOffset!==frustum._xOffset||frustum.yOffset!==frustum._yOffset){assert$4(frustum.fov>=0&&frustum.fov<Math.PI);//assert$4(frustum.aspectRatio > 0);
  59517. if(frustum.aspectRatio==0){console.log(1);}assert$4(frustum.near>=0&&frustum.near<frustum.far);frustum._aspectRatio=Math.max(0.001,frustum.aspectRatio);frustum._fov=frustum.fov;frustum._fovy=frustum._aspectRatio<=1?frustum.fov:Math.atan(Math.tan(frustum.fov*0.5)/frustum._aspectRatio)*2.0;frustum._near=frustum.near;frustum._far=frustum.far;frustum._sseDenominator=2.0*Math.tan(0.5*frustum._fovy);frustum._xOffset=frustum.xOffset;frustum._yOffset=frustum.yOffset;f.top=frustum.near*Math.tan(0.5*frustum._fovy);f.bottom=-f.top;f.right=frustum._aspectRatio*f.top;f.left=-f.right;f.near=frustum.near;f.far=frustum.far;f.right+=frustum.xOffset;f.left+=frustum.xOffset;f.top+=frustum.yOffset;f.bottom+=frustum.yOffset;}}new Vector3$1();new Vector3$1();new Vector3$1();new Vector3$1();new Vector3$1();new Vector3$1();new Vector3$1();new Vector3$1();new Vector3$1();new Vector3$1();new Vector3$1();new Vector3$1();new Matrix3$1();new Matrix3$1();new Matrix3$1();new Matrix3$1();new Matrix3$1();new Vector3$1();new Vector3$1();new Vector3$1();new Vector3$1();new Vector3$1();new Matrix3$1();({diagonal:new Matrix3$1(),unitary:new Matrix3$1()});var scratchVector$2=new Vector3$1();var scratchPosition=new Vector3$1();var cullingVolume=new CullingVolume([new Plane$1(),new Plane$1(),new Plane$1(),new Plane$1(),new Plane$1(),new Plane$1()]);function getFrameState(viewport,frameNumber){var{cameraDirection,cameraUp,height}=viewport;var{metersPerUnit}=viewport.distanceScales;var viewportCenterCartographic=viewport.unprojectPosition(viewport.center);var viewportCenterCartesian=Ellipsoid.WGS84.cartographicToCartesian(viewportCenterCartographic,new Vector3$1());var enuToFixedTransform=Ellipsoid.WGS84.eastNorthUpToFixedFrame(viewportCenterCartesian);var cameraPositionCartographic=viewport.unprojectPosition(viewport.cameraPosition);var cameraPositionCartesian=Ellipsoid.WGS84.cartographicToCartesian(cameraPositionCartographic,new Vector3$1());var cameraDirectionCartesian=new Vector3$1(enuToFixedTransform.transformAsVector(new Vector3$1(cameraDirection).scale(metersPerUnit))).normalize();var cameraUpCartesian=new Vector3$1(enuToFixedTransform.transformAsVector(new Vector3$1(cameraUp).scale(metersPerUnit))).normalize();commonSpacePlanesToWGS84(viewport,viewportCenterCartesian);return {camera:{position:cameraPositionCartesian,direction:cameraDirectionCartesian,up:cameraUpCartesian},viewport,height,cullingVolume,frameNumber,sseDenominator:1.15};}function commonSpacePlanesToWGS84(viewport,viewportCenterCartesian){var frustumPlanes=viewport.getFrustumPlanes();var i=0;for(var dir in frustumPlanes){var plane=frustumPlanes[dir];var distanceToCenter=plane.normal.dot(viewport.center);scratchPosition.copy(plane.normal).scale(plane.distance-distanceToCenter).add(viewport.center);var cartographicPos=viewport.unprojectPosition(scratchPosition);var cartesianPos=Ellipsoid.WGS84.cartographicToCartesian(cartographicPos,new Vector3$1());cullingVolume.planes[i++].fromPointNormal(cartesianPos,scratchVector$2.copy(viewportCenterCartesian).subtract(cartesianPos));}}var WGS84_RADIUS_X=6378137.0;var WGS84_RADIUS_Y=6378137.0;var WGS84_RADIUS_Z=6356752.3142451793;var scratchVector$1=new Vector3$1();function getZoomFromBoundingVolume(boundingVolume){var{halfAxes,radius,width,height}=boundingVolume;if(halfAxes){var obbSize=getObbSize(halfAxes);return Math.log2(WGS84_RADIUS_Z/obbSize);}else if(radius){return Math.log2(WGS84_RADIUS_Z/radius);}else if(height&&width){var zoomX=Math.log2(WGS84_RADIUS_X/width);var zoomY=Math.log2(WGS84_RADIUS_Y/height);return (zoomX+zoomY)/2;}return 1;}function getObbSize(halfAxes){halfAxes.getColumn(0,scratchVector$1);var axeY=halfAxes.getColumn(1);var axeZ=halfAxes.getColumn(2);var farthestVertex=scratchVector$1.add(axeY).add(axeZ);var size=farthestVertex.len();return size;}var TILE_CONTENT_STATE={UNLOADED:0,LOADING:1,PROCESSING:2,READY:3,EXPIRED:4,FAILED:5};var TILE_REFINEMENT={ADD:1,REPLACE:2};var TILE_TYPE={EMPTY:'empty',SCENEGRAPH:'scenegraph',POINTCLOUD:'pointcloud',MESH:'mesh'};var TILESET_TYPE={I3S:'I3S',TILES3D:'TILES3D'};var LOD_METRIC_TYPE={GEOMETRIC_ERROR:'geometricError',MAX_SCREEN_THRESHOLD:'maxScreenThreshold'};var TILE3D_OPTIMIZATION_HINT={NOT_COMPUTED:-1,USE_OPTIMIZATION:1,SKIP_OPTIMIZATION:0};function defined$3(x){return x!==undefined&&x!==null;}var scratchScale=new Vector3$1();var scratchNorthWest=new Vector3$1();var scratchSouthEast=new Vector3$1();function createBoundingVolume(boundingVolumeHeader,transform,result){assert$7(boundingVolumeHeader,'3D Tile: boundingVolume must be defined');if(boundingVolumeHeader.box){return createBox(boundingVolumeHeader.box,transform,result);}if(boundingVolumeHeader.region){var[west,south,east,north,minHeight,maxHeight]=boundingVolumeHeader.region;var northWest=Ellipsoid.WGS84.cartographicToCartesian([degrees(west),degrees(north),minHeight],scratchNorthWest);var southEast=Ellipsoid.WGS84.cartographicToCartesian([degrees(east),degrees(south),maxHeight],scratchSouthEast);var centerInCartesian=new Vector3$1().addVectors(northWest,southEast).multiplyScalar(0.5);var radius=new Vector3$1().subVectors(northWest,southEast).len()/2.0;return createSphere([centerInCartesian[0],centerInCartesian[1],centerInCartesian[2],radius],new Matrix4$1());}if(boundingVolumeHeader.sphere){return createSphere(boundingVolumeHeader.sphere,transform,result);}throw new Error('3D Tile: boundingVolume must contain a sphere, region, or box');}function createBox(box,transform,result){var center=new Vector3$1(box[0],box[1],box[2]);result&&(result.oriCenter=center);//add
  59518. transform.transform(center,center);var origin=[];if(box.length===10){var halfSize=box.slice(3,6);var quaternion=new Quaternion$1();quaternion.fromArray(box,6);var x=new Vector3$1([1,0,0]);var y=new Vector3$1([0,1,0]);var z=new Vector3$1([0,0,1]);x.transformByQuaternion(quaternion);x.scale(halfSize[0]);y.transformByQuaternion(quaternion);y.scale(halfSize[1]);z.transformByQuaternion(quaternion);z.scale(halfSize[2]);origin=[...x.toArray(),...y.toArray(),...z.toArray()];}else {origin=[...box.slice(3,6),...box.slice(6,9),...box.slice(9,12)];}var xAxis=transform.transformAsVector(origin.slice(0,3));var yAxis=transform.transformAsVector(origin.slice(3,6));var zAxis=transform.transformAsVector(origin.slice(6,9));var halfAxes=new Matrix3$1([xAxis[0],xAxis[1],xAxis[2],yAxis[0],yAxis[1],yAxis[2],zAxis[0],zAxis[1],zAxis[2]]);//const halfAxes = new Matrix3([xAxis[0], xAxis[1], -xAxis[2], yAxis[0], yAxis[1], -yAxis[2], zAxis[0], zAxis[1], -zAxis[2]]);//改
  59519. //center.z *= -1//add
  59520. if(defined$3(result)){result.center=center;result.halfAxes=halfAxes;return result;}return new OrientedBoundingBox(center,halfAxes);}function createSphere(sphere,transform,result){var center=new Vector3$1(sphere[0],sphere[1],sphere[2]);transform.transform(center,center);var scale=transform.getScale(scratchScale);var uniformScale=Math.max(Math.max(scale[0],scale[1]),scale[2]);var radius=sphere[3]*uniformScale;if(defined$3(result)){result.center=center;result.radius=radius;return result;}return new BoundingSphere(center,radius);}new Vector3$1();new Vector3$1();new Matrix4$1();new Vector3$1();new Vector3$1();new Vector3$1();function fog(distanceToCamera,density){var scalar=distanceToCamera*density;return 1.0-Math.exp(-(scalar*scalar));}function getDynamicScreenSpaceError(tileset,distanceToCamera){if(tileset.dynamicScreenSpaceError&&tileset.dynamicScreenSpaceErrorComputedDensity){var density=tileset.dynamicScreenSpaceErrorComputedDensity;var factor=tileset.dynamicScreenSpaceErrorFactor;var dynamicError=fog(distanceToCamera,density)*factor;return dynamicError;}return 0;}function getTiles3DScreenSpaceError(tile,frameState,useParentLodMetric){var tileset=tile.tileset;var parentLodMetricValue=tile.parent&&tile.parent.lodMetricValue||tile.lodMetricValue;var lodMetricValue=useParentLodMetric?parentLodMetricValue:tile.lodMetricValue;if(lodMetricValue===0.0){return 0.0;}var distance=Math.max(tile._distanceToCamera,1e-7);var{height,sseDenominator}=frameState;var{viewDistanceScale}=tileset.options;var error=lodMetricValue*height*(viewDistanceScale||1.0)/(distance*sseDenominator);error-=getDynamicScreenSpaceError(tileset,distance);return error;}function getLodStatus(tile,frameState){if(tile.lodMetricValue===0||isNaN(tile.lodMetricValue)){return 'DIG';}var screenSize=2*getProjectedRadius(tile,frameState);if(screenSize<2){return 'OUT';}if(!tile.header.children||screenSize<=tile.lodMetricValue){return 'DRAW';}else if(tile.header.children){return 'DIG';}return 'OUT';}function getProjectedRadius(tile,frameState){var originalViewport=frameState.viewport;var ViewportClass=originalViewport.constructor;var{longitude,latitude,height,width,bearing,zoom}=originalViewport;var viewport=new ViewportClass({longitude,latitude,height,width,bearing,zoom,pitch:0});var mbsLat=tile.header.mbs[1];var mbsLon=tile.header.mbs[0];var mbsZ=tile.header.mbs[2];var mbsR=tile.header.mbs[3];var mbsCenterCartesian=[...tile.boundingVolume.center];var cameraPositionCartographic=viewport.unprojectPosition(viewport.cameraPosition);var cameraPositionCartesian=Ellipsoid.WGS84.cartographicToCartesian(cameraPositionCartographic,new Vector3$1());var toEye=new Vector3$1(cameraPositionCartesian).subtract(mbsCenterCartesian).normalize();var enuToCartesianMatrix=new Matrix4$1();Ellipsoid.WGS84.eastNorthUpToFixedFrame(mbsCenterCartesian,enuToCartesianMatrix);var cartesianToEnuMatrix=new Matrix4$1(enuToCartesianMatrix).invert();var cameraPositionEnu=new Vector3$1(cameraPositionCartesian).transform(cartesianToEnuMatrix);var projection=Math.sqrt(cameraPositionEnu[0]*cameraPositionEnu[0]+cameraPositionEnu[1]*cameraPositionEnu[1]);var extraZ=projection*projection/cameraPositionEnu[2];var extraVertexEnu=new Vector3$1([cameraPositionEnu[0],cameraPositionEnu[1],extraZ]);var extraVertexCartesian=extraVertexEnu.transform(enuToCartesianMatrix);var extraVectorCartesian=new Vector3$1(extraVertexCartesian).subtract(mbsCenterCartesian).normalize();var radiusVector=toEye.cross(extraVectorCartesian).normalize().scale(mbsR);var sphereMbsBorderVertexCartesian=new Vector3$1(mbsCenterCartesian).add(radiusVector);var sphereMbsBorderVertexCartographic=Ellipsoid.WGS84.cartesianToCartographic(sphereMbsBorderVertexCartesian);var projectedOrigin=viewport.project([mbsLon,mbsLat,mbsZ]);var projectedMbsBorderVertex=viewport.project(sphereMbsBorderVertexCartographic);var projectedRadius=new Vector3$1(projectedOrigin).subtract(projectedMbsBorderVertex).magnitude();return projectedRadius;}function get3dTilesOptions(tileset){return {assetGltfUpAxis:tileset.asset&&tileset.asset.gltfUpAxis||'Y'};}class ManagedArray{constructor(){var length=arguments.length>0&&arguments[0]!==undefined?arguments[0]:0;_defineProperty$1(this,"_map",new Map());_defineProperty$1(this,"_array",void 0);_defineProperty$1(this,"_length",void 0);this._array=new Array(length);this._length=length;}get length(){return this._length;}set length(length){this._length=length;if(length>this._array.length){this._array.length=length;}}get values(){return this._array;}get(index){assert$7(index<this._array.length);return this._array[index];}set(index,element){assert$7(index>=0);if(index>=this.length){this.length=index+1;}if(this._map.has(this._array[index])){this._map.delete(this._array[index]);}this._array[index]=element;this._map.set(element,index);}delete(element){var index=this._map.get(element);if(index>=0){this._array.splice(index,1);this._map.delete(element);this.length--;}}peek(){return this._array[this._length-1];}push(element){if(!this._map.has(element)){var index=this.length++;this._array[index]=element;this._map.set(element,index);}}pop(){var element=this._array[--this.length];this._map.delete(element);return element;}reserve(length){assert$7(length>=0);if(length>this._array.length){this._array.length=length;}}resize(length){assert$7(length>=0);this.length=length;}trim(length){if(length===null||length===undefined){length=this.length;}this._array.length=length;}reset(){this._array=[];this._map=new Map();this._length=0;}find(target){return this._map.has(target);}}var DEFAULT_PROPS$1={loadSiblings:false,skipLevelOfDetail:false,maximumScreenSpaceError:2,updateTransforms:true,onTraversalEnd:()=>{},viewportTraversersMap:{},basePath:''};class TilesetTraverser{constructor(options){_defineProperty$1(this,"options",void 0);_defineProperty$1(this,"root",void 0);_defineProperty$1(this,"requestedTiles",void 0);_defineProperty$1(this,"selectedTiles",void 0);_defineProperty$1(this,"emptyTiles",void 0);_defineProperty$1(this,"_traversalStack",void 0);_defineProperty$1(this,"_emptyTraversalStack",void 0);_defineProperty$1(this,"_frameNumber",void 0);this.options=_objectSpread2(_objectSpread2({},DEFAULT_PROPS$1),options);this._traversalStack=new ManagedArray();this._emptyTraversalStack=new ManagedArray();this._frameNumber=null;this.root=null;this.selectedTiles={};this.requestedTiles={};this.emptyTiles={};}traverse(root,frameState,options){this.root=root;this.options=_objectSpread2(_objectSpread2({},this.options),options);this.reset();this.updateTile(root,frameState);this._frameNumber=frameState.frameNumber;this.executeTraversal(root,frameState);}reset(){this.requestedTiles={};this.selectedTiles={};this.emptyTiles={};this._traversalStack.reset();this._emptyTraversalStack.reset();}executeTraversal(root,frameState){// 遍历root
  59521. var stack=this._traversalStack;root._selectionDepth=1;stack.push(root);while(stack.length>0){var tile=stack.pop();var shouldRefine=false;// !zeg改 循环遍历子tile, maxDepth用来限制可加载的最大深度
  59522. if(this.canTraverse(tile,frameState)&&(tile.depth</* this.options. */maxDepth||tile.type!='scenegraph')){//add maxDepth 是否继续遍历子集
  59523. this.updateChildTiles(tile,frameState);shouldRefine=this.updateAndPushChildren(tile,frameState,stack,tile.hasRenderContent?tile._selectionDepth+1:tile._selectionDepth);}var parent=tile.parent;var parentRefines=Boolean(!parent||parent._shouldRefine);var stoppedRefining=!shouldRefine;if(!tile.hasRenderContent){this.emptyTiles[tile.id]=tile;this.loadTile(tile,frameState);if(stoppedRefining){this.selectTile(tile,frameState);}}else if(tile.refine===TILE_REFINEMENT.ADD){this.loadTile(tile,frameState);this.selectTile(tile,frameState);}else if(tile.refine===TILE_REFINEMENT.REPLACE){this.loadTile(tile,frameState);if(stoppedRefining){this.selectTile(tile,frameState);}}this.touchTile(tile,frameState);tile._shouldRefine=shouldRefine&&parentRefines;}this.options.onTraversalEnd(frameState);}updateChildTiles(tile,frameState){var children=tile.children;for(var child of children){this.updateTile(child,frameState);}return true;}updateAndPushChildren(tile,frameState,stack,depth){var{loadSiblings,skipLevelOfDetail}=this.options;var children=tile.children;children.sort(this.compareDistanceToCamera.bind(this));var checkRefines=tile.refine===TILE_REFINEMENT.REPLACE&&tile.hasRenderContent&&!skipLevelOfDetail;var hasVisibleChild=false;var refines=true;for(var child of children){child._selectionDepth=depth;if(child.isVisibleAndInRequestVolume){if(stack.find(child)){stack.delete(child);}stack.push(child);hasVisibleChild=true;}else if(checkRefines||loadSiblings){this.loadTile(child,frameState);this.touchTile(child,frameState);}if(checkRefines){var childRefines=void 0;if(!child._inRequestVolume){childRefines=false;}else if(!child.hasRenderContent){childRefines=this.executeEmptyTraversal(child,frameState);}else {childRefines=child.contentAvailable;}refines=refines&&childRefines;if(!refines){return false;}}}if(!hasVisibleChild){refines=false;}return refines;}updateTile(tile,frameState){this.updateTileVisibility(tile,frameState);}selectTile(tile,frameState){if(this.shouldSelectTile(tile)){tile._selectedFrame=frameState.frameNumber;this.selectedTiles[tile.id]=tile;}}loadTile(tile,frameState){if(this.shouldLoadTile(tile)){tile._requestedFrame=frameState.frameNumber;tile._priority=tile._getPriority();this.requestedTiles[tile.id]=tile;}}touchTile(tile,frameState){tile.tileset._cache.touch(tile);tile._touchedFrame=frameState.frameNumber;}canTraverse(tile,frameState){var useParentMetric=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;var ignoreVisibility=arguments.length>3&&arguments[3]!==undefined?arguments[3]:false;if(!tile.hasChildren){return false;}if(tile.hasTilesetContent){return !tile.contentExpired;}if(!ignoreVisibility&&!tile.isVisibleAndInRequestVolume){return false;}return this.shouldRefine(tile,frameState,useParentMetric);}shouldLoadTile(tile){return tile.hasUnloadedContent||tile.contentExpired;}shouldSelectTile(tile){return tile.contentAvailable&&!this.options.skipLevelOfDetail;}shouldRefine(tile,frameState,useParentMetric){var screenSpaceError=tile._screenSpaceError;if(useParentMetric){screenSpaceError=tile.getScreenSpaceError(frameState,true);}return screenSpaceError>this.options.maximumScreenSpaceError;}updateTileVisibility(tile,frameState){var viewportIds=[];if(this.options.viewportTraversersMap){for(var key in this.options.viewportTraversersMap){var value=this.options.viewportTraversersMap[key];if(value===frameState.viewport.id){viewportIds.push(key);}}}else {viewportIds.push(frameState.viewport.id);}tile.updateVisibility(frameState,viewportIds);}compareDistanceToCamera(b,a){return b._distanceToCamera-a._distanceToCamera;}anyChildrenVisible(tile,frameState){var anyVisible=false;for(var child of tile.children){child.updateVisibility(frameState);anyVisible=anyVisible||child.isVisibleAndInRequestVolume;}return anyVisible;}executeEmptyTraversal(root,frameState){var allDescendantsLoaded=true;var stack=this._emptyTraversalStack;stack.push(root);while(stack.length>0&&allDescendantsLoaded){var tile=stack.pop();this.updateTile(tile,frameState);if(!tile.isVisibleAndInRequestVolume){this.loadTile(tile,frameState);}this.touchTile(tile,frameState);var traverse=!tile.hasRenderContent&&this.canTraverse(tile,frameState,false,true);if(traverse){var children=tile.children;for(var child of children){if(stack.find(child)){stack.delete(child);}stack.push(child);}}else if(!tile.contentAvailable){allDescendantsLoaded=false;}}return allDescendantsLoaded;}}var scratchVector=new Vector3$1();function defined$2(x){return x!==undefined&&x!==null;}class TileHeader{constructor(tileset,header,parentHeader){var extendedId=arguments.length>3&&arguments[3]!==undefined?arguments[3]:'';_defineProperty$1(this,"tileset",void 0);_defineProperty$1(this,"header",void 0);_defineProperty$1(this,"id",void 0);_defineProperty$1(this,"url",void 0);_defineProperty$1(this,"parent",void 0);_defineProperty$1(this,"refine",void 0);_defineProperty$1(this,"type",void 0);_defineProperty$1(this,"contentUrl",void 0);_defineProperty$1(this,"lodMetricType",void 0);_defineProperty$1(this,"lodMetricValue",void 0);_defineProperty$1(this,"boundingVolume",void 0);_defineProperty$1(this,"content",void 0);_defineProperty$1(this,"contentState",void 0);_defineProperty$1(this,"gpuMemoryUsageInBytes",void 0);_defineProperty$1(this,"children",void 0);_defineProperty$1(this,"depth",void 0);_defineProperty$1(this,"viewportIds",void 0);_defineProperty$1(this,"transform",void 0);_defineProperty$1(this,"extensions",void 0);_defineProperty$1(this,"userData",void 0);_defineProperty$1(this,"computedTransform",void 0);_defineProperty$1(this,"hasEmptyContent",void 0);_defineProperty$1(this,"hasTilesetContent",void 0);_defineProperty$1(this,"traverser",void 0);_defineProperty$1(this,"_cacheNode",void 0);_defineProperty$1(this,"_frameNumber",void 0);_defineProperty$1(this,"_lodJudge",void 0);_defineProperty$1(this,"_expireDate",void 0);_defineProperty$1(this,"_expiredContent",void 0);_defineProperty$1(this,"_shouldRefine",void 0);_defineProperty$1(this,"_distanceToCamera",void 0);_defineProperty$1(this,"_centerZDepth",void 0);_defineProperty$1(this,"_screenSpaceError",void 0);_defineProperty$1(this,"_visibilityPlaneMask",void 0);_defineProperty$1(this,"_visible",void 0);_defineProperty$1(this,"_inRequestVolume",void 0);_defineProperty$1(this,"_stackLength",void 0);_defineProperty$1(this,"_selectionDepth",void 0);_defineProperty$1(this,"_touchedFrame",void 0);_defineProperty$1(this,"_visitedFrame",void 0);_defineProperty$1(this,"_selectedFrame",void 0);_defineProperty$1(this,"_requestedFrame",void 0);_defineProperty$1(this,"_priority",void 0);_defineProperty$1(this,"_contentBoundingVolume",void 0);_defineProperty$1(this,"_viewerRequestVolume",void 0);_defineProperty$1(this,"_initialTransform",void 0);_defineProperty$1(this,"tilesetMatrix",void 0);//add
  59524. _defineProperty$1(this,"tileContent",void 0);//add
  59525. _defineProperty$1(this,"contentTransform",void 0);//add
  59526. _defineProperty$1(this,"volumeBox",void 0);//add
  59527. _defineProperty$1(this,"boundUntransformed",void 0);//add
  59528. _defineProperty$1(this,"rtcCenterState",rtcCenterGlobal);//add 初始时的状态,当mesh加载完检查下
  59529. this.header=header;this.tileset=tileset;this.id=extendedId||header.id;this.url=header.url;this.parent=parentHeader;this.refine=this._getRefine(header.refine);this.type=header.type;this.contentUrl=header.contentUrl;this.lodMetricType='geometricError';this.lodMetricValue=0;this.boundingVolume=null;this.content=null;this.contentState=TILE_CONTENT_STATE.UNLOADED;this.gpuMemoryUsageInBytes=0;this.children=[];this.hasEmptyContent=false;this.hasTilesetContent=false;this.depth=0;this.viewportIds=[];this.userData={};this.extensions=null;this._priority=0;this._touchedFrame=0;this._visitedFrame=0;this._selectedFrame=0;this._requestedFrame=0;this._screenSpaceError=0;this._cacheNode=null;this._frameNumber=null;this._cacheNode=null;this.traverser=new TilesetTraverser({});this._shouldRefine=false;this._distanceToCamera=0;this._centerZDepth=0;this._visible=undefined;this._inRequestVolume=false;this._stackLength=0;this._selectionDepth=0;this._initialTransform=new Matrix4$1();this.transform=new Matrix4$1();this._initializeLodMetric(header);this._initializeTransforms(header);this._initializeBoundingVolumes(header);this._initializeContent(header);this._initializeRenderingState(header);this._lodJudge=null;this._expireDate=null;this._expiredContent=null;Object.seal(this);}destroy(){this.header=null;}isDestroyed(){return this.header===null;}get selected(){return this._selectedFrame===this.tileset._frameNumber;}get isVisible(){return this._visible;}get isVisibleAndInRequestVolume(){var v=/* this._visible && */this.tileset.visible&&this._inRequestVolume;//用_updateBoundingVolume这个算的在相机靠近时不准确,容易缺块
  59530. if(window.tileVisi2)v=this._visible&&v;return v;}get hasRenderContent(){return !this.hasEmptyContent&&!this.hasTilesetContent;}get hasChildren(){return this.children.length>0||this.header.children&&this.header.children.length>0;}get contentReady(){return this.contentState===TILE_CONTENT_STATE.READY||this.hasEmptyContent;}get contentAvailable(){return Boolean(this.contentReady&&this.hasRenderContent||this._expiredContent&&!this.contentFailed);}get hasUnloadedContent(){return this.hasRenderContent&&this.contentUnloaded;}get contentUnloaded(){return this.contentState===TILE_CONTENT_STATE.UNLOADED;}get contentExpired(){return this.contentState===TILE_CONTENT_STATE.EXPIRED;}get contentFailed(){return this.contentState===TILE_CONTENT_STATE.FAILED;}getScreenSpaceError(frameState,useParentLodMetric){switch(this.tileset.type){case TILESET_TYPE.I3S:return getProjectedRadius(this,frameState);case TILESET_TYPE.TILES3D:return getTiles3DScreenSpaceError(this,frameState,useParentLodMetric);default:throw new Error('Unsupported tileset type');}}_getPriority(){var traverser=this.tileset._traverser;var{skipLevelOfDetail}=traverser.options;var maySkipTile=this.refine===TILE_REFINEMENT.ADD||skipLevelOfDetail;if(maySkipTile&&!this.isVisible&&this._visible!==undefined){return -1;}if(this.tileset._frameNumber-this._touchedFrame>=1){return -1;}if(this.contentState===TILE_CONTENT_STATE.UNLOADED){return -1;}var parent=this.parent;var useParentScreenSpaceError=parent&&(!maySkipTile||this._screenSpaceError===0.0||parent.hasTilesetContent);var screenSpaceError=useParentScreenSpaceError?parent._screenSpaceError:this._screenSpaceError;var rootScreenSpaceError=traverser.root?traverser.root._screenSpaceError:0.0;var v=Math.max(rootScreenSpaceError-screenSpaceError,0);if(!this._visible){v=THREE.Math.clamp(v*0.1,-0.9,100);//xzw add 因为this._visible我也令其显示所以这里降低这些的优先级
  59531. }return v;}async loadContent(){if(this.hasEmptyContent){return false;}if(this.content){return true;}var expired=this.contentExpired;if(expired){this._expireDate=null;}this.contentState=TILE_CONTENT_STATE.LOADING;var requestToken=await this.tileset._requestScheduler.scheduleRequest(this.id,this._getPriority.bind(this));if(!requestToken){this.contentState=TILE_CONTENT_STATE.UNLOADED;return false;}try{var contentUrl=this.tileset.getTileUrl(this.contentUrl)+"?_=".concat(this.tileset.options.updateTime);// !zeg改 添加version后缀 原:imageVersion
  59532. var loader=this.tileset.loader;var options=_objectSpread2(_objectSpread2({},this.tileset.loadOptions),{},{[loader.id]:_objectSpread2(_objectSpread2({},this.tileset.loadOptions[loader.id]),{},{isTileset:this.type==='json'},this._getLoaderSpecificOptions(loader.id))});this.content=await load(contentUrl,loader,options);// !zeg改
  59533. if(/* this.tileset.options. */maxDepth<this.depth&&this.type=='scenegraph'){//有的场景depth为1的不是mesh,只是json,即实际最低depth>1
  59534. this.unloadContent();return false;}if(this.tileset.options.contentLoader){await this.tileset.options.contentLoader(this);}if(this._isTileset()){this.tileset._initializeTileHeaders(this.content,this);}this.contentState=TILE_CONTENT_STATE.READY;this._onContentLoaded();return true;}catch(error){this.contentState=TILE_CONTENT_STATE.FAILED;throw error;}finally{requestToken.done();}}unloadContent(){if(this.content&&this.content.destroy){this.content.destroy();}this.content=null;if(this.header.content&&this.header.content.destroy){this.header.content.destroy();}this.header.content=null;this.contentState=TILE_CONTENT_STATE.UNLOADED;return true;}updateVisibility(frameState,viewportIds){if(this._frameNumber===frameState.frameNumber){return;}var parent=this.parent;var parentVisibilityPlaneMask=parent?parent._visibilityPlaneMask:CullingVolume.MASK_INDETERMINATE;if(this.tileset._traverser.options.updateTransforms){var parentTransform=parent?parent.computedTransform:new Matrix4$1().elements;//this.tileset.modelMatrix; 改:去掉左乘modelMatrix
  59535. this._updateTransform(parentTransform);}this._distanceToCamera=this.distanceToTile(frameState);this._screenSpaceError=this.getScreenSpaceError(frameState,false);this._visibilityPlaneMask=this.visibility(frameState,parentVisibilityPlaneMask);this._visible=this._visibilityPlaneMask!==CullingVolume.MASK_OUTSIDE;this._inRequestVolume=this.insideViewerRequestVolume(frameState);this._frameNumber=frameState.frameNumber;this.viewportIds=viewportIds;}visibility(frameState,parentVisibilityPlaneMask){var{cullingVolume}=frameState;var{boundingVolume}=this;return cullingVolume.computeVisibilityWithPlaneMask(boundingVolume,parentVisibilityPlaneMask);}contentVisibility(){return true;}distanceToTile(frameState){var boundingVolume=this.boundingVolume;return Math.sqrt(Math.max(boundingVolume.distanceSquaredTo(frameState.camera.position),0));}cameraSpaceZDepth(_ref11){var{camera}=_ref11;var boundingVolume=this.boundingVolume;scratchVector.subVectors(boundingVolume.center,camera.position);return camera.direction.dot(scratchVector);}insideViewerRequestVolume(frameState){var viewerRequestVolume=this._viewerRequestVolume;return !viewerRequestVolume||viewerRequestVolume.distanceSquaredTo(frameState.camera.position)<=0;}updateExpiration(){if(defined$2(this._expireDate)&&this.contentReady&&!this.hasEmptyContent){var now=Date.now();if(Date.lessThan(this._expireDate,now)){this.contentState=TILE_CONTENT_STATE.EXPIRED;this._expiredContent=this.content;}}}get extras(){return this.header.extras;}_initializeLodMetric(header){if('lodMetricType'in header){this.lodMetricType=header.lodMetricType;}else {this.lodMetricType=this.parent&&this.parent.lodMetricType||this.tileset.lodMetricType;console.warn("3D Tile: Required prop lodMetricType is undefined. Using parent lodMetricType");}if('lodMetricValue'in header){this.lodMetricValue=header.lodMetricValue;}else {this.lodMetricValue=this.parent&&this.parent.lodMetricValue||this.tileset.lodMetricValue;console.warn('3D Tile: Required prop lodMetricValue is undefined. Using parent lodMetricValue');}}_initializeTransforms(tileHeader){this.transform=tileHeader.transform?new Matrix4$1(tileHeader.transform):new Matrix4$1();var parent=this.parent;var tileset=this.tileset;var parentTransform=parent&&parent.computedTransform?parent.computedTransform.clone():new Matrix4$1().elements;// tileset.modelMatrix.clone(); 改:去掉左乘modelMatrix
  59536. this.computedTransform=new Matrix4$1(parentTransform).multiplyRight(this.transform);var parentInitialTransform=parent&&parent._initialTransform?parent._initialTransform.clone():new Matrix4$1();this._initialTransform=new Matrix4$1(parentInitialTransform).multiplyRight(this.transform);}_initializeBoundingVolumes(tileHeader){this._contentBoundingVolume=null;this._viewerRequestVolume=null;this._updateBoundingVolume(tileHeader);}_initializeContent(tileHeader){this.content={_tileset:this.tileset,_tile:this};this.hasEmptyContent=true;this.contentState=TILE_CONTENT_STATE.UNLOADED;this.hasTilesetContent=false;if(tileHeader.contentUrl){this.content=null;this.hasEmptyContent=false;}}_initializeRenderingState(header){this.depth=header.level||(this.parent?this.parent.depth+1:0);this._shouldRefine=false;this._distanceToCamera=0;this._centerZDepth=0;this._screenSpaceError=0;this._visibilityPlaneMask=CullingVolume.MASK_INDETERMINATE;this._visible=undefined;this._inRequestVolume=false;this._stackLength=0;this._selectionDepth=0;this._frameNumber=0;this._touchedFrame=0;this._visitedFrame=0;this._selectedFrame=0;this._requestedFrame=0;this._priority=0.0;}_getRefine(refine){return refine||this.parent&&this.parent.refine||TILE_REFINEMENT.REPLACE;}_isTileset(){return this.contentUrl.indexOf('.json')!==-1;}_onContentLoaded(){switch(this.content&&this.content.type){case'vctr':case'geom':this.tileset._traverser.disableSkipLevelOfDetail=true;break;}if(this._isTileset()){this.hasTilesetContent=true;}}_updateBoundingVolume(header){var computedTransform;/* if(header.id == 'root_0' || !header.id){
  59537. console.log('root_0')
  59538. } */if(!this.tileset.lastRootTransform){//没事过后会因_updateTransform重算
  59539. computedTransform=new Matrix4$1(this.tileset.modelMatrix).multiplyRight(this.computedTransform);//add
  59540. }else {computedTransform=new Matrix4$1(new Matrix4().multiplyMatrices(this.tileset.lastRootTransform,this.getContentTransform()).elements);}this.boundingVolume=createBoundingVolume(header.boundingVolume,computedTransform/* this.computedTransform */,this.boundingVolume);var content=header.content;if(!content){return;}if(content.boundingVolume){this._contentBoundingVolume=createBoundingVolume(content.boundingVolume,computedTransform,this._contentBoundingVolume);}if(header.viewerRequestVolume){this._viewerRequestVolume=createBoundingVolume(header.viewerRequestVolume,computedTransform,this._viewerRequestVolume);}}getBoundUntransformed(){//add 这个会在mesh加载好后才会执行
  59541. if(!this.contentTransform){console.error('?');}this.getContentTransform();var computedTransform2=new Matrix4$1(this.contentTransform.elements);this.boundUntransformed=createBoundingVolume(this.header.boundingVolume,computedTransform2,this.boundUntransformed);//add
  59542. return this.boundUntransformed;}getContentTransform(force){//add 获取该tile在创建boundingVolume时需要的matrix,不包含最外层对整体模型的变换.
  59543. var rtcCenter,contentTransform;if(this.contentTransform&&!force){//无需更新
  59544. return this.contentTransform.clone();}if(!this.tileset.tileTransInvert){this.tileset.tileTransInvert=new Matrix4$1();}this.contentTransform=new Matrix4().fromArray(this.computedTransform).premultiply(new Matrix4().fromArray(this.tileset.tileTransInvert));if(this.tileContent){rtcCenter=this.content.rtcCenter;}else {rtcCenter=this.rtcCenterState;}if(!rtcCenter){var tranM=new Matrix4();tranM.makeScale(1,1,-1);//大部分是这种情况. 就是因为这个变换才加的这个函数,之前bounding没考虑这个不准。不知道为什么原生的代码不用scaleZ
  59545. this.contentTransform.premultiply(tranM);}//如果有rtcCenter的话一开始boundingVolume不准?会不会有显示问题?
  59546. return this.contentTransform.clone();}_updateTransform(){var parentTransform=arguments.length>0&&arguments[0]!==undefined?arguments[0]:new Matrix4$1();var computedTransform=parentTransform.clone().multiplyRight(this.transform);var didTransformChange=!computedTransform.equals(this.computedTransform)||!this.tilesetMatrix||!this.tilesetMatrix.equals(this.tileset.modelMatrix);//改 后面加了两个判断,为了在模型移动后更新_updateBoundingVolume
  59547. if(!didTransformChange){return;}this.tileset.modelMatrix;this.computedTransform=computedTransform;this.tilesetMatrix=this.tileset.modelMatrix;//add 标记
  59548. this._updateBoundingVolume(this.header);}_getLoaderSpecificOptions(loaderId){switch(loaderId){case'i3s':return _objectSpread2(_objectSpread2({},this.tileset.options.i3s),{},{tile:this.header,tileset:this.tileset.tileset,isTileHeader:false});case'3d-tiles':case'cesium-ion':default:return get3dTilesOptions(this.tileset.tileset);}}}class Tileset3DTraverser extends TilesetTraverser{compareDistanceToCamera(a,b){return b._distanceToCamera===0&&a._distanceToCamera===0?b._centerZDepth-a._centerZDepth:b._distanceToCamera-a._distanceToCamera;}updateTileVisibility(tile,frameState){super.updateTileVisibility(tile,frameState);if(!tile.isVisibleAndInRequestVolume){return;}var hasChildren=tile.children.length>0;if(tile.hasTilesetContent&&hasChildren){var firstChild=tile.children[0];this.updateTileVisibility(firstChild,frameState);tile._visible=firstChild._visible;return;}if(this.meetsScreenSpaceErrorEarly(tile,frameState)){tile._visible=false;return;}var replace=tile.refine===TILE_REFINEMENT.REPLACE;var useOptimization=tile._optimChildrenWithinParent===TILE3D_OPTIMIZATION_HINT.USE_OPTIMIZATION;if(replace&&useOptimization&&hasChildren){if(!this.anyChildrenVisible(tile,frameState)){tile._visible=false;return;}}}meetsScreenSpaceErrorEarly(tile,frameState){var{parent}=tile;if(!parent||parent.hasTilesetContent||parent.refine!==TILE_REFINEMENT.ADD){return false;}return !this.shouldRefine(tile,frameState,true);}}var STATUS={REQUESTED:'REQUESTED',COMPLETED:'COMPLETED',ERROR:'ERROR'};class I3STileManager{constructor(){_defineProperty$1(this,"_statusMap",void 0);this._statusMap={};}add(request,key,callback,frameState){if(!this._statusMap[key]){this._statusMap[key]={request,callback,key,frameState,status:STATUS.REQUESTED};request().then(data=>{this._statusMap[key].status=STATUS.COMPLETED;this._statusMap[key].callback(data,frameState);}).catch(error=>{this._statusMap[key].status=STATUS.ERROR;callback(error);});}}update(key,frameState){if(this._statusMap[key]){this._statusMap[key].frameState=frameState;}}find(key){return this._statusMap[key];}}class I3STilesetTraverser extends TilesetTraverser{constructor(options){super(options);_defineProperty$1(this,"_tileManager",void 0);this._tileManager=new I3STileManager();}shouldRefine(tile,frameState){tile._lodJudge=getLodStatus(tile,frameState);return tile._lodJudge==='DIG';}updateChildTiles(tile,frameState){var _this=this;var children=tile.header.children||[];var childTiles=tile.children;var tileset=tile.tileset;var _loop2=function _loop2(child){var extendedId="".concat(child.id,"-").concat(frameState.viewport.id);var childTile=childTiles&&childTiles.find(t=>t.id===extendedId);if(!childTile){var request=()=>_this._loadTile(child.id,tileset);var cachedRequest=_this._tileManager.find(extendedId);if(!cachedRequest){if(tileset.tileset.nodePages){request=()=>tileset.tileset.nodePagesTile.formTileFromNodePages(child.id);}_this._tileManager.add(request,extendedId,header=>_this._onTileLoad(header,tile,extendedId),frameState);}else {_this._tileManager.update(extendedId,frameState);}}else if(childTile){_this.updateTile(childTile,frameState);}};for(var child of children){_loop2(child);}return false;}async _loadTile(nodeId,tileset){var{loader}=tileset;var nodeUrl=tileset.getTileUrl("".concat(tileset.url,"/nodes/").concat(nodeId));var options=_objectSpread2(_objectSpread2({},tileset.loadOptions),{},{i3s:_objectSpread2(_objectSpread2({},tileset.loadOptions.i3s),{},{isTileHeader:true,loadContent:false})});return await load(nodeUrl,loader,options);}_onTileLoad(header,tile,extendedId){var childTile=new TileHeader(tile.tileset,header,tile,extendedId);tile.children.push(childTile);var frameState=this._tileManager.find(childTile.id).frameState;this.updateTile(childTile,frameState);if(this._frameNumber===frameState.frameNumber){this.executeTraversal(childTile,frameState);}}}var DEFAULT_PROPS={description:'',ellipsoid:Ellipsoid.WGS84,modelMatrix:new Matrix4$1(),throttleRequests:true,maxRequests:64,maximumMemoryUsage:32,onTileLoad:()=>{},onTileUnload:()=>{},onTileError:()=>{},onTraversalComplete:selectedTiles=>selectedTiles,contentLoader:undefined,viewDistanceScale:1.0,maximumScreenSpaceError:8,loadTiles:true,updateTransforms:true,viewportTraversersMap:null,loadOptions:{fetch:{}},attributions:[],basePath:'',i3s:{}};var TILES_TOTAL='Tiles In Tileset(s)';var TILES_IN_MEMORY='Tiles In Memory';var TILES_IN_VIEW='Tiles In View';var TILES_RENDERABLE='Tiles To Render';var TILES_LOADED='Tiles Loaded';var TILES_LOADING='Tiles Loading';var TILES_UNLOADED='Tiles Unloaded';var TILES_LOAD_FAILED='Failed Tile Loads';var POINTS_COUNT='Points';var TILES_GPU_MEMORY='Tile Memory Use';var tilesetSid=0;//add
  59549. class Tileset3D extends EventDispatcher{//xzw add EventDispatcher
  59550. constructor(json,options){super();viewer.visiVertexCount=viewer.visiVertexCount||0;_defineProperty$1(this,"options",void 0);_defineProperty$1(this,"loadOptions",void 0);_defineProperty$1(this,"type",void 0);_defineProperty$1(this,"tileset",void 0);_defineProperty$1(this,"loader",void 0);_defineProperty$1(this,"url",void 0);_defineProperty$1(this,"basePath",void 0);_defineProperty$1(this,"modelMatrix",void 0);_defineProperty$1(this,"ellipsoid",void 0);_defineProperty$1(this,"lodMetricType",void 0);_defineProperty$1(this,"lodMetricValue",void 0);_defineProperty$1(this,"refine",void 0);_defineProperty$1(this,"root",void 0);_defineProperty$1(this,"roots",void 0);_defineProperty$1(this,"asset",void 0);_defineProperty$1(this,"description",void 0);_defineProperty$1(this,"properties",void 0);_defineProperty$1(this,"extras",void 0);_defineProperty$1(this,"attributions",void 0);_defineProperty$1(this,"credits",void 0);_defineProperty$1(this,"stats",void 0);_defineProperty$1(this,"traverseCounter",void 0);_defineProperty$1(this,"geometricError",void 0);_defineProperty$1(this,"selectedTiles",void 0);_defineProperty$1(this,"cartographicCenter",void 0);_defineProperty$1(this,"cartesianCenter",void 0);_defineProperty$1(this,"zoom",void 0);_defineProperty$1(this,"boundingVolume",void 0);_defineProperty$1(this,"gpuMemoryUsageInBytes",void 0);_defineProperty$1(this,"dynamicScreenSpaceErrorComputedDensity",void 0);_defineProperty$1(this,"_traverser",void 0);_defineProperty$1(this,"_cache",void 0);_defineProperty$1(this,"_requestScheduler",void 0);_defineProperty$1(this,"_frameNumber",void 0);_defineProperty$1(this,"_queryParamsString",void 0);_defineProperty$1(this,"_queryParams",void 0);_defineProperty$1(this,"_extensionsUsed",void 0);_defineProperty$1(this,"_tiles",void 0);_defineProperty$1(this,"_pendingCount",void 0);_defineProperty$1(this,"lastUpdatedVieports",void 0);_defineProperty$1(this,"_requestedTiles",void 0);_defineProperty$1(this,"_emptyTiles",void 0);_defineProperty$1(this,"frameStateData",void 0);_defineProperty$1(this,"maximumMemoryUsage",void 0);_defineProperty$1(this,"visible",true);//add
  59551. assert$7(json);this.options=_objectSpread2(_objectSpread2({},DEFAULT_PROPS),options);this.tileset=json;this.loader=json.loader;this.type=json.type;this.url=json.url;this.basePath=json.basePath||dirname(this.url);this.modelMatrix=this.options.modelMatrix;this.ellipsoid=this.options.ellipsoid;this.lodMetricType=json.lodMetricType;this.lodMetricValue=json.lodMetricValue;this.refine=json.root.refine;this.loadOptions=this.options.loadOptions||{};this.root=null;this.roots={};this.cartographicCenter=null;this.cartesianCenter=null;this.zoom=1;this.boundingVolume=null;this.traverseCounter=0;this.geometricError=0;this._traverser=this._initializeTraverser();this._cache=new TilesetCache();this._requestScheduler=new RequestScheduler({throttleRequests:this.options.throttleRequests,maxRequests:this.options.maxRequests});this._frameNumber=0;this._pendingCount=0;this._tiles={};this.selectedTiles=[];this._emptyTiles=[];this._requestedTiles=[];this.frameStateData={};this.lastUpdatedVieports=null;this._queryParams={};this._queryParamsString='';this.maximumMemoryUsage=this.options.maximumMemoryUsage||32;this.gpuMemoryUsageInBytes=0;this.stats=new Stats$1({id:this.url});this._initializeStats();this._extensionsUsed=undefined;this.dynamicScreenSpaceErrorComputedDensity=0.0;this.extras=null;this.asset={};this.credits={};this.description=this.options.description||'';this._initializeTileSet(json);}destroy(){this._destroy();}isLoaded(){return this._pendingCount===0&&this._frameNumber!==0;}get tiles(){return Object.values(this._tiles);}get frameNumber(){return this._frameNumber;}get queryParams(){if(!this._queryParamsString){this._queryParamsString=getQueryParamString(this._queryParams);}return this._queryParamsString;}setProps(props){this.options=_objectSpread2(_objectSpread2({},this.options),props);}setOptions(options){this.options=_objectSpread2(_objectSpread2({},this.options),options);}getTileUrl(tilePath){var isDataUrl=tilePath.startsWith('data:');tilePath=Potree.Common.dealURL(tilePath);//add 去除'+'
  59552. if(isDataUrl){return tilePath;}return "".concat(tilePath).concat(this.queryParams);}hasExtension(extensionName){return Boolean(this._extensionsUsed&&this._extensionsUsed.indexOf(extensionName)>-1);}update(viewports){if('loadTiles'in this.options&&!this.options.loadTiles){return;}if(this.traverseCounter>0){return;}if(!viewports&&this.lastUpdatedVieports){viewports=this.lastUpdatedVieports;}else {this.lastUpdatedVieports=viewports;}if(!(viewports instanceof Array)){viewports=[viewports];}this._cache.reset();this._frameNumber++;this.traverseCounter=viewports.length;var viewportsToTraverse=[];for(var viewport of viewports){var id=viewport.id;if(this._needTraverse(id)){viewportsToTraverse.push(id);}else {this.traverseCounter--;}}for(var _viewport of viewports){var _id=_viewport.id;if(!this.roots[_id]){this.roots[_id]=this._initializeTileHeaders(this.tileset,null);}if(!viewportsToTraverse.includes(_id)){continue;}var frameState=getFrameState(_viewport,this._frameNumber);this._traverser.traverse(this.roots[_id],frameState,this.options);}}_needTraverse(viewportId){var traverserId=viewportId;if(this.options.viewportTraversersMap){traverserId=this.options.viewportTraversersMap[viewportId];}if(traverserId!==viewportId){return false;}return true;}_onTraversalEnd(frameState){var id=frameState.viewport.id;if(!this.frameStateData[id]){this.frameStateData[id]={selectedTiles:[],_requestedTiles:[],_emptyTiles:[]};}var currentFrameStateData=this.frameStateData[id];var selectedTiles=Object.values(this._traverser.selectedTiles);currentFrameStateData.selectedTiles=selectedTiles;currentFrameStateData._requestedTiles=Object.values(this._traverser.requestedTiles);currentFrameStateData._emptyTiles=Object.values(this._traverser.emptyTiles);this.traverseCounter--;if(this.traverseCounter>0){return;}this._updateTiles();}_updateTiles(){this.selectedTiles=[];this._requestedTiles=[];this._emptyTiles=[];for(var frameStateKey in this.frameStateData){var frameStateDataValue=this.frameStateData[frameStateKey];this.selectedTiles=this.selectedTiles.concat(frameStateDataValue.selectedTiles);this._requestedTiles=this._requestedTiles.concat(frameStateDataValue._requestedTiles);this._emptyTiles=this._emptyTiles.concat(frameStateDataValue._emptyTiles);}this.selectedTiles=this.options.onTraversalComplete(this.selectedTiles);for(var tile of this.selectedTiles){this._tiles[tile.id]=tile;}this._loadTiles();this._unloadTiles();this._updateStats();}_tilesChanged(oldSelectedTiles,selectedTiles){if(oldSelectedTiles.length!==selectedTiles.length){return true;}var set1=new Set(oldSelectedTiles.map(t=>t.id));var set2=new Set(selectedTiles.map(t=>t.id));var changed=oldSelectedTiles.filter(x=>!set2.has(x.id)).length>0;changed=changed||selectedTiles.filter(x=>!set1.has(x.id)).length>0;return changed;}_loadTiles(){for(var tile of this._requestedTiles){if(tile.contentUnloaded){this._loadTile(tile);}}}_unloadTiles(){this._cache.unloadTiles(this,(tileset,tile)=>tileset._unloadTile(tile));}_updateStats(){var tilesRenderable=0;var pointsRenderable=0;for(var tile of this.selectedTiles){if(tile.contentAvailable&&tile.content){tilesRenderable++;if(tile.content.pointCount){pointsRenderable+=tile.content.pointCount;}}}this.stats.get(TILES_IN_VIEW).count=this.selectedTiles.length;this.stats.get(TILES_RENDERABLE).count=tilesRenderable;this.stats.get(POINTS_COUNT).count=pointsRenderable;}_initializeTileSet(tilesetJson){this.root=this._initializeTileHeaders(tilesetJson,null);if(this.type===TILESET_TYPE.TILES3D){this._initializeCesiumTileset(tilesetJson);}if(this.type===TILESET_TYPE.I3S){this._initializeI3STileset();}this._calculateViewProps();}_calculateViewProps(){var root=this.root;assert$7(root);var{center}=root.boundingVolume;if(!center){console.warn('center was not pre-calculated for the root tile');this.cartographicCenter=new Vector3$1();this.zoom=1;return;}this.cartographicCenter=Ellipsoid.WGS84.cartesianToCartographic(center,new Vector3$1());this.cartesianCenter=center;this.zoom=getZoomFromBoundingVolume(root.boundingVolume);}_initializeStats(){this.stats.get(TILES_TOTAL);this.stats.get(TILES_LOADING);this.stats.get(TILES_IN_MEMORY);this.stats.get(TILES_IN_VIEW);this.stats.get(TILES_RENDERABLE);this.stats.get(TILES_LOADED);this.stats.get(TILES_UNLOADED);this.stats.get(TILES_LOAD_FAILED);this.stats.get(POINTS_COUNT,'memory');this.stats.get(TILES_GPU_MEMORY,'memory');}_initializeTileHeaders(tilesetJson,parentTileHeader){var rootTile=new TileHeader(this,tilesetJson.root,parentTileHeader,parentTileHeader==void 0&&'root_'+tilesetSid++);if(parentTileHeader){parentTileHeader.children.push(rootTile);rootTile.depth=parentTileHeader.depth+1;}if(this.type===TILESET_TYPE.TILES3D){var _stack=[];_stack.push(rootTile);while(_stack.length>0){var tile=_stack.pop();this.stats.get(TILES_TOTAL).incrementCount();var children=tile.header.children||[];// !zeg改
  59553. if(tile.depth</* this.options. */maxDepth){for(var childHeader of children){var childTile=new TileHeader(this,childHeader,tile);tile.children.push(childTile);childTile.depth=tile.depth+1;_stack.push(childTile);}}window.maxTileDepth=Math.max(window.maxTileDepth||0,tile.depth);}}return rootTile;}_initializeTraverser(){var TraverserClass;var type=this.type;switch(type){case TILESET_TYPE.TILES3D:TraverserClass=Tileset3DTraverser;break;case TILESET_TYPE.I3S:TraverserClass=I3STilesetTraverser;break;default:TraverserClass=TilesetTraverser;}return new TraverserClass({basePath:this.basePath,onTraversalEnd:this._onTraversalEnd.bind(this)});}_destroyTileHeaders(parentTile){this._destroySubtree(parentTile);}async _loadTile(tile){var loaded;try{this._onStartTileLoading();loaded=await tile.loadContent();}catch(error){this._onTileLoadError(tile,error);}finally{this._onEndTileLoading(tile);//
  59554. this._onTileLoad(tile,loaded);}}_onTileLoadError(tile,error){this.stats.get(TILES_LOAD_FAILED).incrementCount();var message=error.message||error.toString();var url=tile.url;console.error("A 3D tile failed to load: ".concat(tile.url," ").concat(message));this.options.onTileError(tile,message,url);}_onTileLoad(tile,loaded){if(!loaded){return;}if(tile&&tile.content){calculateTransformProps(tile,tile.content);}this._addTileToCache(tile);this.options.onTileLoad(tile);}_onStartTileLoading(){this._pendingCount++;this.stats.get(TILES_LOADING).incrementCount();}_onEndTileLoading(tile){this._pendingCount--;this.stats.get(TILES_LOADING).decrementCount();this.dispatchEvent({type:'endTileLoading',tile,loadingCount:this._pendingCount});// !zeg改
  59555. }_addTileToCache(tile){this._cache.add(this,tile,tileset=>tileset._updateCacheStats(tile));}_updateCacheStats(tile){this.stats.get(TILES_LOADED).incrementCount();this.stats.get(TILES_IN_MEMORY).incrementCount();this.gpuMemoryUsageInBytes+=tile.content.byteLength||0;this.stats.get(TILES_GPU_MEMORY).count=this.gpuMemoryUsageInBytes;}_unloadTile(tile){this.gpuMemoryUsageInBytes-=tile.content&&tile.content.byteLength||0;this.stats.get(TILES_IN_MEMORY).decrementCount();this.stats.get(TILES_UNLOADED).incrementCount();this.stats.get(TILES_GPU_MEMORY).count=this.gpuMemoryUsageInBytes;this.options.onTileUnload(tile);tile.unloadContent();}_destroy(){var stack=[];if(this.root){stack.push(this.root);}while(stack.length>0){var tile=stack.pop();for(var child of tile.children){stack.push(child);}this._destroyTile(tile);}this.root=null;}_destroySubtree(tile){var root=tile;var stack=[];stack.push(root);while(stack.length>0){tile=stack.pop();for(var child of tile.children){stack.push(child);}if(tile!==root){this._destroyTile(tile);}}root.children=[];}_destroyTile(tile){this._cache.unloadTile(this,tile);this._unloadTile(tile);tile.destroy();}_initializeCesiumTileset(tilesetJson){this.asset=tilesetJson.asset;if(!this.asset){throw new Error('Tileset must have an asset property.');}if(this.asset.version!=='0.0'&&this.asset.version!=='1.0'){throw new Error('The tileset must be 3D Tiles version 0.0 or 1.0.');}if('tilesetVersion'in this.asset){this._queryParams.v=this.asset.tilesetVersion;}this.credits={attributions:this.options.attributions||[]};this.description=this.options.description||'';this.properties=tilesetJson.properties;this.geometricError=tilesetJson.geometricError;this._extensionsUsed=tilesetJson.extensionsUsed;this.extras=tilesetJson.extras;}_initializeI3STileset(){if(this.loadOptions.i3s&&'token'in this.loadOptions.i3s){this._queryParams.token=this.loadOptions.i3s.token;}}}function getQueryParamString(queryParams){var queryParamStrings=[];for(var key of Object.keys(queryParams)){queryParamStrings.push("".concat(key,"=").concat(queryParams[key]));}switch(queryParamStrings.length){case 0:return '';case 1:return "?".concat(queryParamStrings[0]);default:return "?".concat(queryParamStrings.join('&'));}}var VERSION$5="3.1.4";var TILE3D_TYPE={COMPOSITE:'cmpt',POINT_CLOUD:'pnts',BATCHED_3D_MODEL:'b3dm',INSTANCED_3D_MODEL:'i3dm',GEOMETRY:'geom',VECTOR:'vect',GLTF:'glTF'};function getStringFromArrayBuffer(arrayBuffer,byteOffset,byteLength){assert$7(arrayBuffer instanceof ArrayBuffer);var textDecoder=new TextDecoder('utf8');var typedArray=new Uint8Array(arrayBuffer,byteOffset,byteLength);var string=textDecoder.decode(typedArray);return string;}function getMagicString$1(arrayBuffer){var byteOffset=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var dataView=new DataView(arrayBuffer);return "".concat(String.fromCharCode(dataView.getUint8(byteOffset+0))).concat(String.fromCharCode(dataView.getUint8(byteOffset+1))).concat(String.fromCharCode(dataView.getUint8(byteOffset+2))).concat(String.fromCharCode(dataView.getUint8(byteOffset+3)));}var VERSION$4="3.1.4";var DEFAULT_DRACO_OPTIONS={draco:{decoderType:typeof WebAssembly==='object'?'wasm':'js',libraryPath:'libs/',extraAttributes:{},attributeNameEntry:undefined}};var DracoLoader$1={name:'Draco',id:'draco',module:'draco',shapes:['mesh'],version:VERSION$4,worker:true,extensions:['drc'],mimeTypes:['application/octet-stream'],binary:true,tests:['DRACO'],options:DEFAULT_DRACO_OPTIONS};function getMeshBoundingBox(attributes){var minX=Infinity;var minY=Infinity;var minZ=Infinity;var maxX=-Infinity;var maxY=-Infinity;var maxZ=-Infinity;var positions=attributes.POSITION?attributes.POSITION.value:[];var len=positions&&positions.length;for(var _i37=0;_i37<len;_i37+=3){var x=positions[_i37];var y=positions[_i37+1];var z=positions[_i37+2];minX=x<minX?x:minX;minY=y<minY?y:minY;minZ=z<minZ?z:minZ;maxX=x>maxX?x:maxX;maxY=y>maxY?y:maxY;maxZ=z>maxZ?z:maxZ;}return [[minX,minY,minZ],[maxX,maxY,maxZ]];}function assert$3(condition,message){if(!condition){throw new Error(message||'loader assertion failed.');}}class Schema{constructor(fields,metadata){_defineProperty$1(this,"fields",void 0);_defineProperty$1(this,"metadata",void 0);assert$3(Array.isArray(fields));checkNames(fields);this.fields=fields;this.metadata=metadata||new Map();}compareTo(other){if(this.metadata!==other.metadata){return false;}if(this.fields.length!==other.fields.length){return false;}for(var _i38=0;_i38<this.fields.length;++_i38){if(!this.fields[_i38].compareTo(other.fields[_i38])){return false;}}return true;}select(){var nameMap=Object.create(null);for(var _len11=arguments.length,columnNames=new Array(_len11),_key11=0;_key11<_len11;_key11++){columnNames[_key11]=arguments[_key11];}for(var _name2 of columnNames){nameMap[_name2]=true;}var selectedFields=this.fields.filter(field=>nameMap[field.name]);return new Schema(selectedFields,this.metadata);}selectAt(){for(var _len12=arguments.length,columnIndices=new Array(_len12),_key12=0;_key12<_len12;_key12++){columnIndices[_key12]=arguments[_key12];}var selectedFields=columnIndices.map(index=>this.fields[index]).filter(Boolean);return new Schema(selectedFields,this.metadata);}assign(schemaOrFields){var fields;var metadata=this.metadata;if(schemaOrFields instanceof Schema){var otherSchema=schemaOrFields;fields=otherSchema.fields;metadata=mergeMaps(mergeMaps(new Map(),this.metadata),otherSchema.metadata);}else {fields=schemaOrFields;}var fieldMap=Object.create(null);for(var field of this.fields){fieldMap[field.name]=field;}for(var _field of fields){fieldMap[_field.name]=_field;}var mergedFields=Object.values(fieldMap);return new Schema(mergedFields,metadata);}}function checkNames(fields){var usedNames={};for(var field of fields){if(usedNames[field.name]){console.warn('Schema: duplicated field name',field.name,field);}usedNames[field.name]=true;}}function mergeMaps(m1,m2){return new Map([...(m1||new Map()),...(m2||new Map())]);}class Field{constructor(name,type){var nullable=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;var metadata=arguments.length>3&&arguments[3]!==undefined?arguments[3]:new Map();_defineProperty$1(this,"name",void 0);_defineProperty$1(this,"type",void 0);_defineProperty$1(this,"nullable",void 0);_defineProperty$1(this,"metadata",void 0);this.name=name;this.type=type;this.nullable=nullable;this.metadata=metadata;}get typeId(){return this.type&&this.type.typeId;}clone(){return new Field(this.name,this.type,this.nullable,this.metadata);}compareTo(other){return this.name===other.name&&this.type===other.type&&this.nullable===other.nullable&&this.metadata===other.metadata;}toString(){return "".concat(this.type).concat(this.nullable?', nullable':'').concat(this.metadata?", metadata: ".concat(this.metadata):'');}}var Type;(function(Type){Type[Type["NONE"]=0]="NONE";Type[Type["Null"]=1]="Null";Type[Type["Int"]=2]="Int";Type[Type["Float"]=3]="Float";Type[Type["Binary"]=4]="Binary";Type[Type["Utf8"]=5]="Utf8";Type[Type["Bool"]=6]="Bool";Type[Type["Decimal"]=7]="Decimal";Type[Type["Date"]=8]="Date";Type[Type["Time"]=9]="Time";Type[Type["Timestamp"]=10]="Timestamp";Type[Type["Interval"]=11]="Interval";Type[Type["List"]=12]="List";Type[Type["Struct"]=13]="Struct";Type[Type["Union"]=14]="Union";Type[Type["FixedSizeBinary"]=15]="FixedSizeBinary";Type[Type["FixedSizeList"]=16]="FixedSizeList";Type[Type["Map"]=17]="Map";Type[Type["Dictionary"]=-1]="Dictionary";Type[Type["Int8"]=-2]="Int8";Type[Type["Int16"]=-3]="Int16";Type[Type["Int32"]=-4]="Int32";Type[Type["Int64"]=-5]="Int64";Type[Type["Uint8"]=-6]="Uint8";Type[Type["Uint16"]=-7]="Uint16";Type[Type["Uint32"]=-8]="Uint32";Type[Type["Uint64"]=-9]="Uint64";Type[Type["Float16"]=-10]="Float16";Type[Type["Float32"]=-11]="Float32";Type[Type["Float64"]=-12]="Float64";Type[Type["DateDay"]=-13]="DateDay";Type[Type["DateMillisecond"]=-14]="DateMillisecond";Type[Type["TimestampSecond"]=-15]="TimestampSecond";Type[Type["TimestampMillisecond"]=-16]="TimestampMillisecond";Type[Type["TimestampMicrosecond"]=-17]="TimestampMicrosecond";Type[Type["TimestampNanosecond"]=-18]="TimestampNanosecond";Type[Type["TimeSecond"]=-19]="TimeSecond";Type[Type["TimeMillisecond"]=-20]="TimeMillisecond";Type[Type["TimeMicrosecond"]=-21]="TimeMicrosecond";Type[Type["TimeNanosecond"]=-22]="TimeNanosecond";Type[Type["DenseUnion"]=-23]="DenseUnion";Type[Type["SparseUnion"]=-24]="SparseUnion";Type[Type["IntervalDayTime"]=-25]="IntervalDayTime";Type[Type["IntervalYearMonth"]=-26]="IntervalYearMonth";})(Type||(Type={}));var _Symbol$toStringTag,_Symbol$toStringTag2,_Symbol$toStringTag7;class DataType{static isNull(x){return x&&x.typeId===Type.Null;}static isInt(x){return x&&x.typeId===Type.Int;}static isFloat(x){return x&&x.typeId===Type.Float;}static isBinary(x){return x&&x.typeId===Type.Binary;}static isUtf8(x){return x&&x.typeId===Type.Utf8;}static isBool(x){return x&&x.typeId===Type.Bool;}static isDecimal(x){return x&&x.typeId===Type.Decimal;}static isDate(x){return x&&x.typeId===Type.Date;}static isTime(x){return x&&x.typeId===Type.Time;}static isTimestamp(x){return x&&x.typeId===Type.Timestamp;}static isInterval(x){return x&&x.typeId===Type.Interval;}static isList(x){return x&&x.typeId===Type.List;}static isStruct(x){return x&&x.typeId===Type.Struct;}static isUnion(x){return x&&x.typeId===Type.Union;}static isFixedSizeBinary(x){return x&&x.typeId===Type.FixedSizeBinary;}static isFixedSizeList(x){return x&&x.typeId===Type.FixedSizeList;}static isMap(x){return x&&x.typeId===Type.Map;}static isDictionary(x){return x&&x.typeId===Type.Dictionary;}get typeId(){return Type.NONE;}compareTo(other){return this===other;}}_Symbol$toStringTag=Symbol.toStringTag;class Int extends DataType{constructor(isSigned,bitWidth){super();_defineProperty$1(this,"isSigned",void 0);_defineProperty$1(this,"bitWidth",void 0);this.isSigned=isSigned;this.bitWidth=bitWidth;}get typeId(){return Type.Int;}get[_Symbol$toStringTag](){return 'Int';}toString(){return "".concat(this.isSigned?'I':'Ui',"nt").concat(this.bitWidth);}}class Int8 extends Int{constructor(){super(true,8);}}class Int16 extends Int{constructor(){super(true,16);}}class Int32 extends Int{constructor(){super(true,32);}}class Uint8 extends Int{constructor(){super(false,8);}}class Uint16 extends Int{constructor(){super(false,16);}}class Uint32 extends Int{constructor(){super(false,32);}}var Precision={HALF:16,SINGLE:32,DOUBLE:64};_Symbol$toStringTag2=Symbol.toStringTag;class Float extends DataType{constructor(precision){super();_defineProperty$1(this,"precision",void 0);this.precision=precision;}get typeId(){return Type.Float;}get[_Symbol$toStringTag2](){return 'Float';}toString(){return "Float".concat(this.precision);}}class Float32 extends Float{constructor(){super(Precision.SINGLE);}}class Float64 extends Float{constructor(){super(Precision.DOUBLE);}}_Symbol$toStringTag7=Symbol.toStringTag;class FixedSizeList extends DataType{constructor(listSize,child){super();_defineProperty$1(this,"listSize",void 0);_defineProperty$1(this,"children",void 0);this.listSize=listSize;this.children=[child];}get typeId(){return Type.FixedSizeList;}get valueType(){return this.children[0].type;}get valueField(){return this.children[0];}get[_Symbol$toStringTag7](){return 'FixedSizeList';}toString(){return "FixedSizeList[".concat(this.listSize,"]<").concat(this.valueType,">");}}function getArrowTypeFromTypedArray(array){switch(array.constructor){case Int8Array:return new Int8();case Uint8Array:return new Uint8();case Int16Array:return new Int16();case Uint16Array:return new Uint16();case Int32Array:return new Int32();case Uint32Array:return new Uint32();case Float32Array:return new Float32();case Float64Array:return new Float64();default:throw new Error('array type not supported');}}function deduceMeshField(attributeName,attribute,optionalMetadata){var type=getArrowTypeFromTypedArray(attribute.value);var metadata=optionalMetadata?optionalMetadata:makeMeshAttributeMetadata(attribute);var field=new Field(attributeName,new FixedSizeList(attribute.size,new Field('value',type)),false,metadata);return field;}function makeMeshAttributeMetadata(attribute){var result=new Map();if('byteOffset'in attribute){result.set('byteOffset',attribute.byteOffset.toString(10));}if('byteStride'in attribute){result.set('byteStride',attribute.byteStride.toString(10));}if('normalized'in attribute){result.set('normalized',attribute.normalized.toString());}return result;}function getDracoSchema(attributes,loaderData,indices){var metadataMap=makeMetadata(loaderData.metadata);var fields=[];var namedLoaderDataAttributes=transformAttributesLoaderData(loaderData.attributes);for(var attributeName in attributes){var attribute=attributes[attributeName];var field=getArrowFieldFromAttribute(attributeName,attribute,namedLoaderDataAttributes[attributeName]);fields.push(field);}if(indices){var indicesField=getArrowFieldFromAttribute('indices',indices);fields.push(indicesField);}return new Schema(fields,metadataMap);}function transformAttributesLoaderData(loaderData){var result={};for(var key in loaderData){var dracoAttribute=loaderData[key];result[dracoAttribute.name||'undefined']=dracoAttribute;}return result;}function getArrowFieldFromAttribute(attributeName,attribute,loaderData){var metadataMap=loaderData?makeMetadata(loaderData.metadata):undefined;var field=deduceMeshField(attributeName,attribute,metadataMap);return field;}function makeMetadata(metadata){var metadataMap=new Map();for(var key in metadata){metadataMap.set("".concat(key,".string"),JSON.stringify(metadata[key]));}return metadataMap;}var DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP={POSITION:'POSITION',NORMAL:'NORMAL',COLOR:'COLOR_0',TEX_COORD:'TEXCOORD_0'};var DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP={1:Int8Array,2:Uint8Array,3:Int16Array,4:Uint16Array,5:Int32Array,6:Uint32Array,9:Float32Array};var INDEX_ITEM_SIZE=4;class DracoParser{constructor(draco){_defineProperty$1(this,"draco",void 0);_defineProperty$1(this,"decoder",void 0);_defineProperty$1(this,"metadataQuerier",void 0);this.draco=draco;this.decoder=new this.draco.Decoder();this.metadataQuerier=new this.draco.MetadataQuerier();}destroy(){this.draco.destroy(this.decoder);this.draco.destroy(this.metadataQuerier);}parseSync(arrayBuffer){var options=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var buffer=new this.draco.DecoderBuffer();buffer.Init(new Int8Array(arrayBuffer),arrayBuffer.byteLength);this._disableAttributeTransforms(options);var geometry_type=this.decoder.GetEncodedGeometryType(buffer);var dracoGeometry=geometry_type===this.draco.TRIANGULAR_MESH?new this.draco.Mesh():new this.draco.PointCloud();try{var dracoStatus;switch(geometry_type){case this.draco.TRIANGULAR_MESH:dracoStatus=this.decoder.DecodeBufferToMesh(buffer,dracoGeometry);break;case this.draco.POINT_CLOUD:dracoStatus=this.decoder.DecodeBufferToPointCloud(buffer,dracoGeometry);break;default:throw new Error('DRACO: Unknown geometry type.');}if(!dracoStatus.ok()||!dracoGeometry.ptr){var message="DRACO decompression failed: ".concat(dracoStatus.error_msg());throw new Error(message);}var loaderData=this._getDracoLoaderData(dracoGeometry,geometry_type,options);var geometry=this._getMeshData(dracoGeometry,loaderData,options);var boundingBox=getMeshBoundingBox(geometry.attributes);var schema=getDracoSchema(geometry.attributes,loaderData,geometry.indices);var data=_objectSpread2(_objectSpread2({loader:'draco',loaderData,header:{vertexCount:dracoGeometry.num_points(),boundingBox}},geometry),{},{schema});return data;}finally{this.draco.destroy(buffer);if(dracoGeometry){this.draco.destroy(dracoGeometry);}}}_getDracoLoaderData(dracoGeometry,geometry_type,options){var metadata=this._getTopLevelMetadata(dracoGeometry);var attributes=this._getDracoAttributes(dracoGeometry,options);return {geometry_type,num_attributes:dracoGeometry.num_attributes(),num_points:dracoGeometry.num_points(),num_faces:dracoGeometry instanceof this.draco.Mesh?dracoGeometry.num_faces():0,metadata,attributes};}_getDracoAttributes(dracoGeometry,options){var dracoAttributes={};for(var attributeId=0;attributeId<dracoGeometry.num_attributes();attributeId++){var dracoAttribute=this.decoder.GetAttribute(dracoGeometry,attributeId);var metadata=this._getAttributeMetadata(dracoGeometry,attributeId);dracoAttributes[dracoAttribute.unique_id()]={unique_id:dracoAttribute.unique_id(),attribute_type:dracoAttribute.attribute_type(),data_type:dracoAttribute.data_type(),num_components:dracoAttribute.num_components(),byte_offset:dracoAttribute.byte_offset(),byte_stride:dracoAttribute.byte_stride(),normalized:dracoAttribute.normalized(),attribute_index:attributeId,metadata};var quantization=this._getQuantizationTransform(dracoAttribute,options);if(quantization){dracoAttributes[dracoAttribute.unique_id()].quantization_transform=quantization;}var octahedron=this._getOctahedronTransform(dracoAttribute,options);if(octahedron){dracoAttributes[dracoAttribute.unique_id()].octahedron_transform=octahedron;}}return dracoAttributes;}_getMeshData(dracoGeometry,loaderData,options){var attributes=this._getMeshAttributes(loaderData,dracoGeometry,options);var positionAttribute=attributes.POSITION;if(!positionAttribute){throw new Error('DRACO: No position attribute found.');}if(dracoGeometry instanceof this.draco.Mesh){switch(options.topology){case'triangle-strip':return {topology:'triangle-strip',mode:4,attributes,indices:{value:this._getTriangleStripIndices(dracoGeometry),size:1}};case'triangle-list':default:return {topology:'triangle-list',mode:5,attributes,indices:{value:this._getTriangleListIndices(dracoGeometry),size:1}};}}return {topology:'point-list',mode:0,attributes};}_getMeshAttributes(loaderData,dracoGeometry,options){var attributes={};for(var loaderAttribute of Object.values(loaderData.attributes)){var attributeName=this._deduceAttributeName(loaderAttribute,options);loaderAttribute.name=attributeName;var{value,size}=this._getAttributeValues(dracoGeometry,loaderAttribute);attributes[attributeName]={value,size,byteOffset:loaderAttribute.byte_offset,byteStride:loaderAttribute.byte_stride,normalized:loaderAttribute.normalized};}return attributes;}_getTriangleListIndices(dracoGeometry){var numFaces=dracoGeometry.num_faces();var numIndices=numFaces*3;var byteLength=numIndices*INDEX_ITEM_SIZE;var ptr=this.draco._malloc(byteLength);try{this.decoder.GetTrianglesUInt32Array(dracoGeometry,byteLength,ptr);return new Uint32Array(this.draco.HEAPF32.buffer,ptr,numIndices).slice();}finally{this.draco._free(ptr);}}_getTriangleStripIndices(dracoGeometry){var dracoArray=new this.draco.DracoInt32Array();try{this.decoder.GetTriangleStripsFromMesh(dracoGeometry,dracoArray);return getUint32Array(dracoArray);}finally{this.draco.destroy(dracoArray);}}_getAttributeValues(dracoGeometry,attribute){var TypedArrayCtor=DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP[attribute.data_type];var numComponents=attribute.num_components;var numPoints=dracoGeometry.num_points();var numValues=numPoints*numComponents;var byteLength=numValues*TypedArrayCtor.BYTES_PER_ELEMENT;var dataType=getDracoDataType(this.draco,TypedArrayCtor);var value;var ptr=this.draco._malloc(byteLength);try{var dracoAttribute=this.decoder.GetAttribute(dracoGeometry,attribute.attribute_index);this.decoder.GetAttributeDataArrayForAllPoints(dracoGeometry,dracoAttribute,dataType,byteLength,ptr);value=new TypedArrayCtor(this.draco.HEAPF32.buffer,ptr,numValues).slice();}finally{this.draco._free(ptr);}return {value,size:numComponents};}_deduceAttributeName(attribute,options){var uniqueId=attribute.unique_id;for(var[attributeName,attributeUniqueId]of Object.entries(options.extraAttributes||{})){if(attributeUniqueId===uniqueId){return attributeName;}}var thisAttributeType=attribute.attribute_type;for(var dracoAttributeConstant in DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP){var attributeType=this.draco[dracoAttributeConstant];if(attributeType===thisAttributeType){return DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP[dracoAttributeConstant];}}var entryName=options.attributeNameEntry||'name';if(attribute.metadata[entryName]){return attribute.metadata[entryName].string;}return "CUSTOM_ATTRIBUTE_".concat(uniqueId);}_getTopLevelMetadata(dracoGeometry){var dracoMetadata=this.decoder.GetMetadata(dracoGeometry);return this._getDracoMetadata(dracoMetadata);}_getAttributeMetadata(dracoGeometry,attributeId){var dracoMetadata=this.decoder.GetAttributeMetadata(dracoGeometry,attributeId);return this._getDracoMetadata(dracoMetadata);}_getDracoMetadata(dracoMetadata){if(!dracoMetadata||!dracoMetadata.ptr){return {};}var result={};var numEntries=this.metadataQuerier.NumEntries(dracoMetadata);for(var entryIndex=0;entryIndex<numEntries;entryIndex++){var entryName=this.metadataQuerier.GetEntryName(dracoMetadata,entryIndex);result[entryName]=this._getDracoMetadataField(dracoMetadata,entryName);}return result;}_getDracoMetadataField(dracoMetadata,entryName){var dracoArray=new this.draco.DracoInt32Array();try{this.metadataQuerier.GetIntEntryArray(dracoMetadata,entryName,dracoArray);var intArray=getInt32Array(dracoArray);return {int:this.metadataQuerier.GetIntEntry(dracoMetadata,entryName),string:this.metadataQuerier.GetStringEntry(dracoMetadata,entryName),double:this.metadataQuerier.GetDoubleEntry(dracoMetadata,entryName),intArray};}finally{this.draco.destroy(dracoArray);}}_disableAttributeTransforms(options){var{quantizedAttributes=[],octahedronAttributes=[]}=options;var skipAttributes=[...quantizedAttributes,...octahedronAttributes];for(var dracoAttributeName of skipAttributes){this.decoder.SkipAttributeTransform(this.draco[dracoAttributeName]);}}_getQuantizationTransform(dracoAttribute,options){var{quantizedAttributes=[]}=options;var attribute_type=dracoAttribute.attribute_type();var skip=quantizedAttributes.map(type=>this.decoder[type]).includes(attribute_type);if(skip){var transform=new this.draco.AttributeQuantizationTransform();try{if(transform.InitFromAttribute(dracoAttribute)){return {quantization_bits:transform.quantization_bits(),range:transform.range(),min_values:new Float32Array([1,2,3]).map(i=>transform.min_value(i))};}}finally{this.draco.destroy(transform);}}return null;}_getOctahedronTransform(dracoAttribute,options){var{octahedronAttributes=[]}=options;var attribute_type=dracoAttribute.attribute_type();var octahedron=octahedronAttributes.map(type=>this.decoder[type]).includes(attribute_type);if(octahedron){var transform=new this.draco.AttributeQuantizationTransform();try{if(transform.InitFromAttribute(dracoAttribute)){return {quantization_bits:transform.quantization_bits()};}}finally{this.draco.destroy(transform);}}return null;}}function getDracoDataType(draco,attributeType){switch(attributeType){case Float32Array:return draco.DT_FLOAT32;case Int8Array:return draco.DT_INT8;case Int16Array:return draco.DT_INT16;case Int32Array:return draco.DT_INT32;case Uint8Array:return draco.DT_UINT8;case Uint16Array:return draco.DT_UINT16;case Uint32Array:return draco.DT_UINT32;default:return draco.DT_INVALID;}}function getInt32Array(dracoArray){var numValues=dracoArray.size();var intArray=new Int32Array(numValues);for(var _i39=0;_i39<numValues;_i39++){intArray[_i39]=dracoArray.GetValue(_i39);}return intArray;}function getUint32Array(dracoArray){var numValues=dracoArray.size();var intArray=new Int32Array(numValues);for(var _i40=0;_i40<numValues;_i40++){intArray[_i40]=dracoArray.GetValue(_i40);}return intArray;}var DRACO_VERSION='1.4.1';var DRACO_JS_DECODER_URL="https://www.gstatic.com/draco/versioned/decoders/".concat(DRACO_VERSION,"/draco_decoder.js");var DRACO_WASM_WRAPPER_URL="https://www.gstatic.com/draco/versioned/decoders/".concat(DRACO_VERSION,"/draco_wasm_wrapper.js");var DRACO_WASM_DECODER_URL="https://www.gstatic.com/draco/versioned/decoders/".concat(DRACO_VERSION,"/draco_decoder.wasm");var loadDecoderPromise;async function loadDracoDecoderModule(options){var modules=options.modules||{};if(modules.draco3d){loadDecoderPromise=loadDecoderPromise||modules.draco3d.createDecoderModule({}).then(draco=>{return {draco};});}else {loadDecoderPromise=loadDecoderPromise||loadDracoDecoder(options);}return await loadDecoderPromise;}async function loadDracoDecoder(options){var DracoDecoderModule;var wasmBinary;switch(options.draco&&options.draco.decoderType){case'js':DracoDecoderModule=await loadLibrary(DRACO_JS_DECODER_URL,'draco',options);break;case'wasm':default:[DracoDecoderModule,wasmBinary]=await Promise.all([await loadLibrary(DRACO_WASM_WRAPPER_URL,'draco',options),await loadLibrary(DRACO_WASM_DECODER_URL,'draco',options)]);}DracoDecoderModule=DracoDecoderModule||globalThis.DracoDecoderModule;return await initializeDracoDecoder(DracoDecoderModule,wasmBinary);}function initializeDracoDecoder(DracoDecoderModule,wasmBinary){var options={};if(wasmBinary){options.wasmBinary=wasmBinary;}return new Promise(resolve=>{DracoDecoderModule(_objectSpread2(_objectSpread2({},options),{},{onModuleLoaded:draco=>resolve({draco})}));});}var DracoLoader=_objectSpread2(_objectSpread2({},DracoLoader$1),{},{parse:parse$2});async function parse$2(arrayBuffer,options){var{draco}=await loadDracoDecoderModule(options);var dracoParser=new DracoParser(draco);try{return dracoParser.parseSync(arrayBuffer,options===null||options===void 0?void 0:options.draco);}finally{dracoParser.destroy();}}var GL_PRIMITIVE_MODE={POINTS:0x0000,LINES:0x0001,LINE_LOOP:0x0002,LINE_STRIP:0x0003,TRIANGLES:0x0004,TRIANGLE_STRIP:0x0005,TRIANGLE_FAN:0x0006};var GL_TYPE={BYTE:5120,UNSIGNED_BYTE:5121,SHORT:5122,UNSIGNED_SHORT:5123,INT:5124,UNSIGNED_INT:5125,FLOAT:5126,DOUBLE:5130};var GL$1=_objectSpread2(_objectSpread2({},GL_PRIMITIVE_MODE),GL_TYPE);var GL_TYPE_TO_ARRAY_TYPE={[GL_TYPE.DOUBLE]:Float64Array,[GL_TYPE.FLOAT]:Float32Array,[GL_TYPE.UNSIGNED_SHORT]:Uint16Array,[GL_TYPE.UNSIGNED_INT]:Uint32Array,[GL_TYPE.UNSIGNED_BYTE]:Uint8Array,[GL_TYPE.BYTE]:Int8Array,[GL_TYPE.SHORT]:Int16Array,[GL_TYPE.INT]:Int32Array};var NAME_TO_GL_TYPE={DOUBLE:GL_TYPE.DOUBLE,FLOAT:GL_TYPE.FLOAT,UNSIGNED_SHORT:GL_TYPE.UNSIGNED_SHORT,UNSIGNED_INT:GL_TYPE.UNSIGNED_INT,UNSIGNED_BYTE:GL_TYPE.UNSIGNED_BYTE,BYTE:GL_TYPE.BYTE,SHORT:GL_TYPE.SHORT,INT:GL_TYPE.INT};var ERR_TYPE_CONVERSION='Failed to convert GL type';class GLType{static fromTypedArray(arrayOrType){arrayOrType=ArrayBuffer.isView(arrayOrType)?arrayOrType.constructor:arrayOrType;for(var glType in GL_TYPE_TO_ARRAY_TYPE){var ArrayType=GL_TYPE_TO_ARRAY_TYPE[glType];if(ArrayType===arrayOrType){return glType;}}throw new Error(ERR_TYPE_CONVERSION);}static fromName(name){var glType=NAME_TO_GL_TYPE[name];if(!glType){throw new Error(ERR_TYPE_CONVERSION);}return glType;}static getArrayType(glType){switch(glType){case GL_TYPE.UNSIGNED_SHORT_5_6_5:case GL_TYPE.UNSIGNED_SHORT_4_4_4_4:case GL_TYPE.UNSIGNED_SHORT_5_5_5_1:return Uint16Array;default:var ArrayType=GL_TYPE_TO_ARRAY_TYPE[glType];if(!ArrayType){throw new Error(ERR_TYPE_CONVERSION);}return ArrayType;}}static getByteSize(glType){var ArrayType=GLType.getArrayType(glType);return ArrayType.BYTES_PER_ELEMENT;}static validate(glType){return Boolean(GLType.getArrayType(glType));}static createTypedArray(glType,buffer){var byteOffset=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0;var length=arguments.length>3?arguments[3]:undefined;if(length===undefined){length=(buffer.byteLength-byteOffset)/GLType.getByteSize(glType);}var ArrayType=GLType.getArrayType(glType);return new ArrayType(buffer,byteOffset,length);}}function assert$2(condition,message){if(!condition){throw new Error("math.gl assertion failed. ".concat(message));}}function decodeRGB565(rgb565){var target=arguments.length>1&&arguments[1]!==undefined?arguments[1]:[0,0,0];var r5=rgb565>>11&31;var g6=rgb565>>5&63;var b5=rgb565&31;target[0]=r5<<3;target[1]=g6<<2;target[2]=b5<<3;return target;}new Vector2$1();new Vector3$1();new Vector2$1();new Vector2$1();function fromSNorm(value){var rangeMaximum=arguments.length>1&&arguments[1]!==undefined?arguments[1]:255;return clamp$1(value,0.0,rangeMaximum)/rangeMaximum*2.0-1.0;}function signNotZero(value){return value<0.0?-1.0:1.0;}function octDecodeInRange(x,y,rangeMax,result){assert$2(result);if(x<0||x>rangeMax||y<0||y>rangeMax){throw new Error("x and y must be unsigned normalized integers between 0 and ".concat(rangeMax));}result.x=fromSNorm(x,rangeMax);result.y=fromSNorm(y,rangeMax);result.z=1.0-(Math.abs(result.x)+Math.abs(result.y));if(result.z<0.0){var oldVX=result.x;result.x=(1.0-Math.abs(result.y))*signNotZero(oldVX);result.y=(1.0-Math.abs(oldVX))*signNotZero(result.y);}return result.normalize();}function octDecode(x,y,result){return octDecodeInRange(x,y,255,result);}class Tile3DFeatureTable{constructor(featureTableJson,featureTableBinary){_defineProperty$1(this,"json",void 0);_defineProperty$1(this,"buffer",void 0);_defineProperty$1(this,"featuresLength",0);_defineProperty$1(this,"_cachedTypedArrays",{});this.json=featureTableJson;this.buffer=featureTableBinary;}getExtension(extensionName){return this.json.extensions&&this.json.extensions[extensionName];}hasProperty(propertyName){return Boolean(this.json[propertyName]);}getGlobalProperty(propertyName){var componentType=arguments.length>1&&arguments[1]!==undefined?arguments[1]:GL$1.UNSIGNED_INT;var componentLength=arguments.length>2&&arguments[2]!==undefined?arguments[2]:1;var jsonValue=this.json[propertyName];if(jsonValue&&Number.isFinite(jsonValue.byteOffset)){return this._getTypedArrayFromBinary(propertyName,componentType,componentLength,1,jsonValue.byteOffset);}return jsonValue;}getPropertyArray(propertyName,componentType,componentLength){var jsonValue=this.json[propertyName];if(jsonValue&&Number.isFinite(jsonValue.byteOffset)){if('componentType'in jsonValue){componentType=GLType.fromName(jsonValue.componentType);}return this._getTypedArrayFromBinary(propertyName,componentType,componentLength,this.featuresLength,jsonValue.byteOffset);}return this._getTypedArrayFromArray(propertyName,componentType,jsonValue);}getProperty(propertyName,componentType,componentLength,featureId,result){var jsonValue=this.json[propertyName];if(!jsonValue){return jsonValue;}var typedArray=this.getPropertyArray(propertyName,componentType,componentLength);if(componentLength===1){return typedArray[featureId];}for(var _i41=0;_i41<componentLength;++_i41){result[_i41]=typedArray[componentLength*featureId+_i41];}return result;}_getTypedArrayFromBinary(propertyName,componentType,componentLength,count,byteOffset){var cachedTypedArrays=this._cachedTypedArrays;var typedArray=cachedTypedArrays[propertyName];if(!typedArray){typedArray=GLType.createTypedArray(componentType,this.buffer.buffer,this.buffer.byteOffset+byteOffset,count*componentLength);cachedTypedArrays[propertyName]=typedArray;}return typedArray;}_getTypedArrayFromArray(propertyName,componentType,array){var cachedTypedArrays=this._cachedTypedArrays;var typedArray=cachedTypedArrays[propertyName];if(!typedArray){typedArray=GLType.createTypedArray(componentType,array);cachedTypedArrays[propertyName]=typedArray;}return typedArray;}}var COMPONENTS_PER_ATTRIBUTE={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16};var UNPACKER={SCALAR:(values,i)=>values[i],VEC2:(values,i)=>[values[2*i+0],values[2*i+1]],VEC3:(values,i)=>[values[3*i+0],values[3*i+1],values[3*i+2]],VEC4:(values,i)=>[values[4*i+0],values[4*i+1],values[4*i+2],values[4*i+3]],MAT2:(values,i)=>[values[4*i+0],values[4*i+1],values[4*i+2],values[4*i+3]],MAT3:(values,i)=>[values[9*i+0],values[9*i+1],values[9*i+2],values[9*i+3],values[9*i+4],values[9*i+5],values[9*i+6],values[9*i+7],values[9*i+8]],MAT4:(values,i)=>[values[16*i+0],values[16*i+1],values[16*i+2],values[16*i+3],values[16*i+4],values[16*i+5],values[16*i+6],values[16*i+7],values[16*i+8],values[16*i+9],values[16*i+10],values[16*i+11],values[16*i+12],values[16*i+13],values[16*i+14],values[16*i+15]]};var PACKER={SCALAR:(x,values,i)=>{values[i]=x;},VEC2:(x,values,i)=>{values[2*i+0]=x[0];values[2*i+1]=x[1];},VEC3:(x,values,i)=>{values[3*i+0]=x[0];values[3*i+1]=x[1];values[3*i+2]=x[2];},VEC4:(x,values,i)=>{values[4*i+0]=x[0];values[4*i+1]=x[1];values[4*i+2]=x[2];values[4*i+3]=x[3];},MAT2:(x,values,i)=>{values[4*i+0]=x[0];values[4*i+1]=x[1];values[4*i+2]=x[2];values[4*i+3]=x[3];},MAT3:(x,values,i)=>{values[9*i+0]=x[0];values[9*i+1]=x[1];values[9*i+2]=x[2];values[9*i+3]=x[3];values[9*i+4]=x[4];values[9*i+5]=x[5];values[9*i+6]=x[6];values[9*i+7]=x[7];values[9*i+8]=x[8];values[9*i+9]=x[9];},MAT4:(x,values,i)=>{values[16*i+0]=x[0];values[16*i+1]=x[1];values[16*i+2]=x[2];values[16*i+3]=x[3];values[16*i+4]=x[4];values[16*i+5]=x[5];values[16*i+6]=x[6];values[16*i+7]=x[7];values[16*i+8]=x[8];values[16*i+9]=x[9];values[16*i+10]=x[10];values[16*i+11]=x[11];values[16*i+12]=x[12];values[16*i+13]=x[13];values[16*i+14]=x[14];values[16*i+15]=x[15];}};function createTypedArrayFromAccessor(tile3DAccessor,buffer,byteOffset,length){var{componentType}=tile3DAccessor;assert$7(tile3DAccessor.componentType);var type=typeof componentType==='string'?GLType.fromName(componentType):componentType;var size=COMPONENTS_PER_ATTRIBUTE[tile3DAccessor.type];var unpacker=UNPACKER[tile3DAccessor.type];var packer=PACKER[tile3DAccessor.type];byteOffset+=tile3DAccessor.byteOffset;var values=GLType.createTypedArray(type,buffer,byteOffset,size*length);return {values,type,size,unpacker,packer};}var defined$1=x=>x!==undefined;function initializeHierarchy(batchTable,jsonHeader,binaryBody){if(!jsonHeader){return null;}var hierarchy=batchTable.getExtension('3DTILES_batch_table_hierarchy');var legacyHierarchy=jsonHeader.HIERARCHY;if(legacyHierarchy){console.warn('3D Tile Parser: HIERARCHY is deprecated. Use 3DTILES_batch_table_hierarchy.');jsonHeader.extensions=jsonHeader.extensions||{};jsonHeader.extensions['3DTILES_batch_table_hierarchy']=legacyHierarchy;hierarchy=legacyHierarchy;}if(!hierarchy){return null;}return initializeHierarchyValues(hierarchy,binaryBody);}function initializeHierarchyValues(hierarchyJson,binaryBody){var i;var classId;var binaryAccessor;var instancesLength=hierarchyJson.instancesLength;var classes=hierarchyJson.classes;var classIds=hierarchyJson.classIds;var parentCounts=hierarchyJson.parentCounts;var parentIds=hierarchyJson.parentIds;var parentIdsLength=instancesLength;if(defined$1(classIds.byteOffset)){classIds.componentType=defaultValue(classIds.componentType,GL.UNSIGNED_SHORT);classIds.type=AttributeType.SCALAR;binaryAccessor=getBinaryAccessor(classIds);classIds=binaryAccessor.createArrayBufferView(binaryBody.buffer,binaryBody.byteOffset+classIds.byteOffset,instancesLength);}var parentIndexes;if(defined$1(parentCounts)){if(defined$1(parentCounts.byteOffset)){parentCounts.componentType=defaultValue(parentCounts.componentType,GL.UNSIGNED_SHORT);parentCounts.type=AttributeType.SCALAR;binaryAccessor=getBinaryAccessor(parentCounts);parentCounts=binaryAccessor.createArrayBufferView(binaryBody.buffer,binaryBody.byteOffset+parentCounts.byteOffset,instancesLength);}parentIndexes=new Uint16Array(instancesLength);parentIdsLength=0;for(i=0;i<instancesLength;++i){parentIndexes[i]=parentIdsLength;parentIdsLength+=parentCounts[i];}}if(defined$1(parentIds)&&defined$1(parentIds.byteOffset)){parentIds.componentType=defaultValue(parentIds.componentType,GL.UNSIGNED_SHORT);parentIds.type=AttributeType.SCALAR;binaryAccessor=getBinaryAccessor(parentIds);parentIds=binaryAccessor.createArrayBufferView(binaryBody.buffer,binaryBody.byteOffset+parentIds.byteOffset,parentIdsLength);}var classesLength=classes.length;for(i=0;i<classesLength;++i){var classInstancesLength=classes[i].length;var properties=classes[i].instances;var binaryProperties=getBinaryProperties(classInstancesLength,properties,binaryBody);classes[i].instances=combine(binaryProperties,properties);}var classCounts=new Array(classesLength).fill(0);var classIndexes=new Uint16Array(instancesLength);for(i=0;i<instancesLength;++i){classId=classIds[i];classIndexes[i]=classCounts[classId];++classCounts[classId];}var hierarchy={classes,classIds,classIndexes,parentCounts,parentIndexes,parentIds};validateHierarchy(hierarchy);return hierarchy;}function traverseHierarchy(hierarchy,instanceIndex,endConditionCallback){if(!hierarchy){return;}var parentCounts=hierarchy.parentCounts;var parentIds=hierarchy.parentIds;if(parentIds){return endConditionCallback(hierarchy,instanceIndex);}if(parentCounts>0){return traverseHierarchyMultipleParents(hierarchy,instanceIndex,endConditionCallback);}return traverseHierarchySingleParent(hierarchy,instanceIndex,endConditionCallback);}function traverseHierarchyMultipleParents(hierarchy,instanceIndex,endConditionCallback){var classIds=hierarchy.classIds;var parentCounts=hierarchy.parentCounts;var parentIds=hierarchy.parentIds;var parentIndexes=hierarchy.parentIndexes;var instancesLength=classIds.length;var visited=scratchVisited;visited.length=Math.max(visited.length,instancesLength);var visitedMarker=++marker;var stack=scratchStack;stack.length=0;stack.push(instanceIndex);while(stack.length>0){instanceIndex=stack.pop();if(visited[instanceIndex]===visitedMarker){continue;}visited[instanceIndex]=visitedMarker;var result=endConditionCallback(hierarchy,instanceIndex);if(defined$1(result)){return result;}var parentCount=parentCounts[instanceIndex];var parentIndex=parentIndexes[instanceIndex];for(var _i42=0;_i42<parentCount;++_i42){var parentId=parentIds[parentIndex+_i42];if(parentId!==instanceIndex){stack.push(parentId);}}}return null;}function traverseHierarchySingleParent(hierarchy,instanceIndex,endConditionCallback){var hasParent=true;while(hasParent){var result=endConditionCallback(hierarchy,instanceIndex);if(defined$1(result)){return result;}var parentId=hierarchy.parentIds[instanceIndex];hasParent=parentId!==instanceIndex;instanceIndex=parentId;}throw new Error('traverseHierarchySingleParent');}function validateHierarchy(hierarchy){var classIds=hierarchy.classIds;var instancesLength=classIds.length;for(var _i43=0;_i43<instancesLength;++_i43){validateInstance(hierarchy,_i43,stack);}}function validateInstance(hierarchy,instanceIndex,stack){var parentCounts=hierarchy.parentCounts;var parentIds=hierarchy.parentIds;var parentIndexes=hierarchy.parentIndexes;var classIds=hierarchy.classIds;var instancesLength=classIds.length;if(!defined$1(parentIds)){return;}assert(instanceIndex<instancesLength,"Parent index ".concat(instanceIndex," exceeds the total number of instances: ").concat(instancesLength));assert(stack.indexOf(instanceIndex)===-1,'Circular dependency detected in the batch table hierarchy.');stack.push(instanceIndex);var parentCount=defined$1(parentCounts)?parentCounts[instanceIndex]:1;var parentIndex=defined$1(parentCounts)?parentIndexes[instanceIndex]:instanceIndex;for(var _i44=0;_i44<parentCount;++_i44){var parentId=parentIds[parentIndex+_i44];if(parentId!==instanceIndex){validateInstance(hierarchy,parentId,stack);}}stack.pop(instanceIndex);}function defined(x){return x!==undefined&&x!==null;}var clone=(x,y)=>x;var IGNORED_PROPERTY_FIELDS={HIERARCHY:true,extensions:true,extras:true};class Tile3DBatchTableParser{constructor(json,binary,featureCount){var options=arguments.length>3&&arguments[3]!==undefined?arguments[3]:{};var _this$json;_defineProperty$1(this,"json",void 0);_defineProperty$1(this,"binary",void 0);_defineProperty$1(this,"featureCount",void 0);_defineProperty$1(this,"_extensions",void 0);_defineProperty$1(this,"_properties",void 0);_defineProperty$1(this,"_binaryProperties",void 0);_defineProperty$1(this,"_hierarchy",void 0);assert$7(featureCount>=0);this.json=json||{};this.binary=binary;this.featureCount=featureCount;this._extensions=((_this$json=this.json)===null||_this$json===void 0?void 0:_this$json.extensions)||{};this._properties={};for(var propertyName in this.json){if(!IGNORED_PROPERTY_FIELDS[propertyName]){this._properties[propertyName]=this.json[propertyName];}}this._binaryProperties=this._initializeBinaryProperties();if(options['3DTILES_batch_table_hierarchy']){this._hierarchy=initializeHierarchy(this,this.json,this.binary);}}getExtension(extensionName){return this.json&&this.json.extensions&&this.json.extensions[extensionName];}memorySizeInBytes(){return 0;}isClass(batchId,className){this._checkBatchId(batchId);assert$7(typeof className==='string',className);if(this._hierarchy){var result=traverseHierarchy(this._hierarchy,batchId,(hierarchy,instanceIndex)=>{var classId=hierarchy.classIds[instanceIndex];var instanceClass=hierarchy.classes[classId];return instanceClass.name===className;});return defined(result);}return false;}isExactClass(batchId,className){assert$7(typeof className==='string',className);return this.getExactClassName(batchId)===className;}getExactClassName(batchId){this._checkBatchId(batchId);if(this._hierarchy){var classId=this._hierarchy.classIds[batchId];var instanceClass=this._hierarchy.classes[classId];return instanceClass.name;}return undefined;}hasProperty(batchId,name){this._checkBatchId(batchId);assert$7(typeof name==='string',name);return defined(this._properties[name])||this._hasPropertyInHierarchy(batchId,name);}getPropertyNames(batchId,results){this._checkBatchId(batchId);results=defined(results)?results:[];results.length=0;var propertyNames=Object.keys(this._properties);results.push(...propertyNames);if(this._hierarchy){this._getPropertyNamesInHierarchy(batchId,results);}return results;}getProperty(batchId,name){this._checkBatchId(batchId);assert$7(typeof name==='string',name);if(this._binaryProperties){var binaryProperty=this._binaryProperties[name];if(defined(binaryProperty)){return this._getBinaryProperty(binaryProperty,batchId);}}var propertyValues=this._properties[name];if(defined(propertyValues)){return clone(propertyValues[batchId]);}if(this._hierarchy){var hierarchyProperty=this._getHierarchyProperty(batchId,name);if(defined(hierarchyProperty)){return hierarchyProperty;}}return undefined;}setProperty(batchId,name,value){var featureCount=this.featureCount;this._checkBatchId(batchId);assert$7(typeof name==='string',name);if(this._binaryProperties){var binaryProperty=this._binaryProperties[name];if(binaryProperty){this._setBinaryProperty(binaryProperty,batchId,value);return;}}if(this._hierarchy){if(this._setHierarchyProperty(this,batchId,name,value)){return;}}var propertyValues=this._properties[name];if(!defined(propertyValues)){this._properties[name]=new Array(featureCount);propertyValues=this._properties[name];}propertyValues[batchId]=clone(value);}_checkBatchId(batchId){var valid=batchId>=0&&batchId<this.featureCount;if(!valid){throw new Error('batchId not in range [0, featureCount - 1].');}}_getBinaryProperty(binaryProperty,index){return binaryProperty.unpack(binaryProperty.typedArray,index);}_setBinaryProperty(binaryProperty,index,value){binaryProperty.pack(value,binaryProperty.typedArray,index);}_initializeBinaryProperties(){var binaryProperties=null;for(var _name3 in this._properties){var property=this._properties[_name3];var binaryProperty=this._initializeBinaryProperty(_name3,property);if(binaryProperty){binaryProperties=binaryProperties||{};binaryProperties[_name3]=binaryProperty;}}return binaryProperties;}_initializeBinaryProperty(name,property){if('byteOffset'in property){var tile3DAccessor=property;assert$7(this.binary,"Property ".concat(name," requires a batch table binary."));assert$7(tile3DAccessor.type,"Property ".concat(name," requires a type."));var accessor=createTypedArrayFromAccessor(tile3DAccessor,this.binary.buffer,this.binary.byteOffset|0,this.featureCount);return {typedArray:accessor.values,componentCount:accessor.size,unpack:accessor.unpacker,pack:accessor.packer};}return null;}_hasPropertyInHierarchy(batchId,name){if(!this._hierarchy){return false;}var result=traverseHierarchy(this._hierarchy,batchId,(hierarchy,instanceIndex)=>{var classId=hierarchy.classIds[instanceIndex];var instances=hierarchy.classes[classId].instances;return defined(instances[name]);});return defined(result);}_getPropertyNamesInHierarchy(batchId,results){traverseHierarchy(this._hierarchy,batchId,(hierarchy,instanceIndex)=>{var classId=hierarchy.classIds[instanceIndex];var instances=hierarchy.classes[classId].instances;for(var _name4 in instances){if(instances.hasOwnProperty(_name4)){if(results.indexOf(_name4)===-1){results.push(_name4);}}}});}_getHierarchyProperty(batchId,name){return traverseHierarchy(this._hierarchy,batchId,(hierarchy,instanceIndex)=>{var classId=hierarchy.classIds[instanceIndex];var instanceClass=hierarchy.classes[classId];var indexInClass=hierarchy.classIndexes[instanceIndex];var propertyValues=instanceClass.instances[name];if(defined(propertyValues)){if(defined(propertyValues.typedArray)){return this._getBinaryProperty(propertyValues,indexInClass);}return clone(propertyValues[indexInClass]);}return null;});}_setHierarchyProperty(batchTable,batchId,name,value){var result=traverseHierarchy(this._hierarchy,batchId,(hierarchy,instanceIndex)=>{var classId=hierarchy.classIds[instanceIndex];var instanceClass=hierarchy.classes[classId];var indexInClass=hierarchy.classIndexes[instanceIndex];var propertyValues=instanceClass.instances[name];if(defined(propertyValues)){assert$7(instanceIndex===batchId,"Inherited property \"".concat(name,"\" is read-only."));if(defined(propertyValues.typedArray)){this._setBinaryProperty(propertyValues,indexInClass,value);}else {propertyValues[indexInClass]=clone(value);}return true;}return false;});return defined(result);}}var SIZEOF_UINT32$1=4;function parse3DTileHeaderSync(tile,arrayBuffer){var byteOffset=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0;var view=new DataView(arrayBuffer);tile.magic=view.getUint32(byteOffset,true);byteOffset+=SIZEOF_UINT32$1;tile.version=view.getUint32(byteOffset,true);byteOffset+=SIZEOF_UINT32$1;tile.byteLength=view.getUint32(byteOffset,true);byteOffset+=SIZEOF_UINT32$1;if(tile.version!==1){throw new Error("3D Tile Version ".concat(tile.version," not supported"));}return byteOffset;}var SIZEOF_UINT32=4;var DEPRECATION_WARNING='b3dm tile in legacy format.';function parse3DTileTablesHeaderSync(tile,arrayBuffer,byteOffset){var view=new DataView(arrayBuffer);var batchLength;tile.header=tile.header||{};var featureTableJsonByteLength=view.getUint32(byteOffset,true);byteOffset+=SIZEOF_UINT32;var featureTableBinaryByteLength=view.getUint32(byteOffset,true);byteOffset+=SIZEOF_UINT32;var batchTableJsonByteLength=view.getUint32(byteOffset,true);byteOffset+=SIZEOF_UINT32;var batchTableBinaryByteLength=view.getUint32(byteOffset,true);byteOffset+=SIZEOF_UINT32;if(batchTableJsonByteLength>=570425344){byteOffset-=SIZEOF_UINT32*2;batchLength=featureTableJsonByteLength;batchTableJsonByteLength=featureTableBinaryByteLength;batchTableBinaryByteLength=0;featureTableJsonByteLength=0;featureTableBinaryByteLength=0;console.warn(DEPRECATION_WARNING);}else if(batchTableBinaryByteLength>=570425344){byteOffset-=SIZEOF_UINT32;batchLength=batchTableJsonByteLength;batchTableJsonByteLength=featureTableJsonByteLength;batchTableBinaryByteLength=featureTableBinaryByteLength;featureTableJsonByteLength=0;featureTableBinaryByteLength=0;console.warn(DEPRECATION_WARNING);}tile.header.featureTableJsonByteLength=featureTableJsonByteLength;tile.header.featureTableBinaryByteLength=featureTableBinaryByteLength;tile.header.batchTableJsonByteLength=batchTableJsonByteLength;tile.header.batchTableBinaryByteLength=batchTableBinaryByteLength;tile.header.batchLength=batchLength;return byteOffset;}function parse3DTileTablesSync(tile,arrayBuffer,byteOffset,options){byteOffset=parse3DTileFeatureTable(tile,arrayBuffer,byteOffset);byteOffset=parse3DTileBatchTable(tile,arrayBuffer,byteOffset);return byteOffset;}function parse3DTileFeatureTable(tile,arrayBuffer,byteOffset,options){var{featureTableJsonByteLength,featureTableBinaryByteLength,batchLength}=tile.header;tile.featureTableJson={BATCH_LENGTH:batchLength||0};if(featureTableJsonByteLength>0){var featureTableString=getStringFromArrayBuffer(arrayBuffer,byteOffset,featureTableJsonByteLength);tile.featureTableJson=JSON.parse(featureTableString);}byteOffset+=featureTableJsonByteLength;tile.featureTableBinary=new Uint8Array(arrayBuffer,byteOffset,featureTableBinaryByteLength);byteOffset+=featureTableBinaryByteLength;return byteOffset;}function parse3DTileBatchTable(tile,arrayBuffer,byteOffset,options){var{batchTableJsonByteLength,batchTableBinaryByteLength}=tile.header;if(batchTableJsonByteLength>0){var batchTableString=getStringFromArrayBuffer(arrayBuffer,byteOffset,batchTableJsonByteLength);tile.batchTableJson=JSON.parse(batchTableString);byteOffset+=batchTableJsonByteLength;if(batchTableBinaryByteLength>0){tile.batchTableBinary=new Uint8Array(arrayBuffer,byteOffset,batchTableBinaryByteLength);tile.batchTableBinary=new Uint8Array(tile.batchTableBinary);byteOffset+=batchTableBinaryByteLength;}}return byteOffset;}function normalize3DTileColorAttribute(tile,colors,batchTable){if(!colors&&(!tile||!tile.batchIds||!batchTable)){return null;}var{batchIds,isRGB565,pointCount}=tile;if(batchIds&&batchTable){var colorArray=new Uint8ClampedArray(pointCount*3);for(var _i45=0;_i45<pointCount;_i45++){var batchId=batchIds[_i45];var dimensions=batchTable.getProperty(batchId,'dimensions');var color=dimensions.map(d=>d*255);colorArray[_i45*3]=color[0];colorArray[_i45*3+1]=color[1];colorArray[_i45*3+2]=color[2];}return {type:GL$1.UNSIGNED_BYTE,value:colorArray,size:3,normalized:true};}if(isRGB565){var _colorArray=new Uint8ClampedArray(pointCount*3);for(var _i46=0;_i46<pointCount;_i46++){var _color=decodeRGB565(colors[_i46]);_colorArray[_i46*3]=_color[0];_colorArray[_i46*3+1]=_color[1];_colorArray[_i46*3+2]=_color[2];}return {type:GL$1.UNSIGNED_BYTE,value:_colorArray,size:3,normalized:true};}if(colors&&colors.length===pointCount*3){return {type:GL$1.UNSIGNED_BYTE,value:colors,size:3,normalized:true};}return {type:GL$1.UNSIGNED_BYTE,value:colors,size:4,normalized:true};}var scratchNormal=new Vector3$1();function normalize3DTileNormalAttribute(tile,normals){if(!normals){return null;}if(tile.isOctEncoded16P){var decodedArray=new Float32Array(tile.pointsLength*3);for(var _i47=0;_i47<tile.pointsLength;_i47++){octDecode(normals[_i47*2],normals[_i47*2+1],scratchNormal);scratchNormal.toArray(decodedArray,_i47*3);}return {type:GL$1.FLOAT,size:2,value:decodedArray};}return {type:GL$1.FLOAT,size:2,value:normals};}function normalize3DTilePositionAttribute(tile,positions,options){if(!tile.isQuantized){return positions;}if(options['3d-tiles']&&options['3d-tiles'].decodeQuantizedPositions){tile.isQuantized=false;return decodeQuantizedPositions(tile,positions);}return {type:GL$1.UNSIGNED_SHORT,value:positions,size:3,normalized:true};}function decodeQuantizedPositions(tile,positions){var scratchPosition=new Vector3$1();var decodedArray=new Float32Array(tile.pointCount*3);for(var _i48=0;_i48<tile.pointCount;_i48++){scratchPosition.set(positions[_i48*3],positions[_i48*3+1],positions[_i48*3+2]).scale(1/tile.quantizedRange).multiply(tile.quantizedVolumeScale).add(tile.quantizedVolumeOffset).toArray(decodedArray,_i48*3);}return decodedArray;}async function parsePointCloud3DTile(tile,arrayBuffer,byteOffset,options,context){byteOffset=parse3DTileHeaderSync(tile,arrayBuffer,byteOffset);byteOffset=parse3DTileTablesHeaderSync(tile,arrayBuffer,byteOffset);byteOffset=parse3DTileTablesSync(tile,arrayBuffer,byteOffset);initializeTile(tile);var{featureTable,batchTable}=parsePointCloudTables(tile);await parseDraco(tile,featureTable,batchTable,options,context);parsePositions(tile,featureTable,options);parseColors(tile,featureTable,batchTable);parseNormals(tile,featureTable);return byteOffset;}function initializeTile(tile){tile.attributes={positions:null,colors:null,normals:null,batchIds:null};tile.isQuantized=false;tile.isTranslucent=false;tile.isRGB565=false;tile.isOctEncoded16P=false;}function parsePointCloudTables(tile){var featureTable=new Tile3DFeatureTable(tile.featureTableJson,tile.featureTableBinary);var pointsLength=featureTable.getGlobalProperty('POINTS_LENGTH');if(!Number.isFinite(pointsLength)){throw new Error('POINTS_LENGTH must be defined');}featureTable.featuresLength=pointsLength;tile.featuresLength=pointsLength;tile.pointsLength=pointsLength;tile.pointCount=pointsLength;tile.rtcCenter=featureTable.getGlobalProperty('RTC_CENTER',GL$1.FLOAT,3);var batchTable=parseBatchIds(tile,featureTable);return {featureTable,batchTable};}function parsePositions(tile,featureTable,options){if(!tile.attributes.positions){if(featureTable.hasProperty('POSITION')){tile.attributes.positions=featureTable.getPropertyArray('POSITION',GL$1.FLOAT,3);}else if(featureTable.hasProperty('POSITION_QUANTIZED')){var positions=featureTable.getPropertyArray('POSITION_QUANTIZED',GL$1.UNSIGNED_SHORT,3);tile.isQuantized=true;tile.quantizedRange=(1<<16)-1;tile.quantizedVolumeScale=featureTable.getGlobalProperty('QUANTIZED_VOLUME_SCALE',GL$1.FLOAT,3);if(!tile.quantizedVolumeScale){throw new Error('QUANTIZED_VOLUME_SCALE must be defined for quantized positions.');}tile.quantizedVolumeOffset=featureTable.getGlobalProperty('QUANTIZED_VOLUME_OFFSET',GL$1.FLOAT,3);if(!tile.quantizedVolumeOffset){throw new Error('QUANTIZED_VOLUME_OFFSET must be defined for quantized positions.');}tile.attributes.positions=normalize3DTilePositionAttribute(tile,positions,options);}}if(!tile.attributes.positions){throw new Error('Either POSITION or POSITION_QUANTIZED must be defined.');}}function parseColors(tile,featureTable,batchTable){if(!tile.attributes.colors){var colors=null;if(featureTable.hasProperty('RGBA')){colors=featureTable.getPropertyArray('RGBA',GL$1.UNSIGNED_BYTE,4);tile.isTranslucent=true;}else if(featureTable.hasProperty('RGB')){colors=featureTable.getPropertyArray('RGB',GL$1.UNSIGNED_BYTE,3);}else if(featureTable.hasProperty('RGB565')){colors=featureTable.getPropertyArray('RGB565',GL$1.UNSIGNED_SHORT,1);tile.isRGB565=true;}tile.attributes.colors=normalize3DTileColorAttribute(tile,colors,batchTable);}if(featureTable.hasProperty('CONSTANT_RGBA')){tile.constantRGBA=featureTable.getGlobalProperty('CONSTANT_RGBA',GL$1.UNSIGNED_BYTE,4);}}function parseNormals(tile,featureTable){if(!tile.attributes.normals){var normals=null;if(featureTable.hasProperty('NORMAL')){normals=featureTable.getPropertyArray('NORMAL',GL$1.FLOAT,3);}else if(featureTable.hasProperty('NORMAL_OCT16P')){normals=featureTable.getPropertyArray('NORMAL_OCT16P',GL$1.UNSIGNED_BYTE,2);tile.isOctEncoded16P=true;}tile.attributes.normals=normalize3DTileNormalAttribute(tile,normals);}}function parseBatchIds(tile,featureTable){var batchTable=null;if(!tile.batchIds&&featureTable.hasProperty('BATCH_ID')){tile.batchIds=featureTable.getPropertyArray('BATCH_ID',GL$1.UNSIGNED_SHORT,1);if(tile.batchIds){var batchFeatureLength=featureTable.getGlobalProperty('BATCH_LENGTH');if(!batchFeatureLength){throw new Error('Global property: BATCH_LENGTH must be defined when BATCH_ID is defined.');}var{batchTableJson,batchTableBinary}=tile;batchTable=new Tile3DBatchTableParser(batchTableJson,batchTableBinary,batchFeatureLength);}}return batchTable;}async function parseDraco(tile,featureTable,batchTable,options,context){var dracoBuffer;var dracoFeatureTableProperties;var dracoBatchTableProperties;var batchTableDraco=tile.batchTableJson&&tile.batchTableJson.extensions&&tile.batchTableJson.extensions['3DTILES_draco_point_compression'];if(batchTableDraco){dracoBatchTableProperties=batchTableDraco.properties;}var featureTableDraco=featureTable.getExtension('3DTILES_draco_point_compression');if(featureTableDraco){dracoFeatureTableProperties=featureTableDraco.properties;var dracoByteOffset=featureTableDraco.byteOffset;var dracoByteLength=featureTableDraco.byteLength;if(!dracoFeatureTableProperties||!Number.isFinite(dracoByteOffset)||!dracoByteLength){throw new Error('Draco properties, byteOffset, and byteLength must be defined');}dracoBuffer=tile.featureTableBinary.slice(dracoByteOffset,dracoByteOffset+dracoByteLength);tile.hasPositions=Number.isFinite(dracoFeatureTableProperties.POSITION);tile.hasColors=Number.isFinite(dracoFeatureTableProperties.RGB)||Number.isFinite(dracoFeatureTableProperties.RGBA);tile.hasNormals=Number.isFinite(dracoFeatureTableProperties.NORMAL);tile.hasBatchIds=Number.isFinite(dracoFeatureTableProperties.BATCH_ID);tile.isTranslucent=Number.isFinite(dracoFeatureTableProperties.RGBA);}if(!dracoBuffer){return true;}var dracoData={buffer:dracoBuffer,properties:_objectSpread2(_objectSpread2({},dracoFeatureTableProperties),dracoBatchTableProperties),featureTableProperties:dracoFeatureTableProperties,batchTableProperties:dracoBatchTableProperties,dequantizeInShader:false};return await loadDraco(tile,dracoData,options,context);}async function loadDraco(tile,dracoData,options,context){var{parse}=context;var dracoOptions=_objectSpread2(_objectSpread2({},options),{},{draco:_objectSpread2(_objectSpread2({},options.draco),{},{extraAttributes:dracoData.batchTableProperties||{}})});delete dracoOptions['3d-tiles'];var data=await parse(dracoData.buffer,DracoLoader,dracoOptions);var decodedPositions=data.attributes.POSITION&&data.attributes.POSITION.value;var decodedColors=data.attributes.COLOR_0&&data.attributes.COLOR_0.value;var decodedNormals=data.attributes.NORMAL&&data.attributes.NORMAL.value;var decodedBatchIds=data.attributes.BATCH_ID&&data.attributes.BATCH_ID.value;var isQuantizedDraco=decodedPositions&&data.attributes.POSITION.value.quantization;var isOctEncodedDraco=decodedNormals&&data.attributes.NORMAL.value.quantization;if(isQuantizedDraco){var quantization=data.POSITION.data.quantization;var range=quantization.range;tile.quantizedVolumeScale=new Vector3$1(range,range,range);tile.quantizedVolumeOffset=new Vector3$1(quantization.minValues);tile.quantizedRange=(1<<quantization.quantizationBits)-1.0;tile.isQuantizedDraco=true;}if(isOctEncodedDraco){tile.octEncodedRange=(1<<data.NORMAL.data.quantization.quantizationBits)-1.0;tile.isOctEncodedDraco=true;}var batchTableAttributes={};if(dracoData.batchTableProperties){for(var attributeName of Object.keys(dracoData.batchTableProperties)){if(data.attributes[attributeName]&&data.attributes[attributeName].value){batchTableAttributes[attributeName.toLowerCase()]=data.attributes[attributeName].value;}}}tile.attributes=_objectSpread2({positions:decodedPositions,colors:normalize3DTileColorAttribute(tile,decodedColors,undefined),normals:decodedNormals,batchIds:decodedBatchIds},batchTableAttributes);}var VERSION$3="3.1.4";var VERSION$2="3.1.4";var VERSION$1="3.1.4";var BASIS_CDN_ENCODER_WASM="https://unpkg.com/@loaders.gl/textures@".concat(VERSION$1,"/dist/libs/basis_encoder.wasm");var BASIS_CDN_ENCODER_JS="https://unpkg.com/@loaders.gl/textures@".concat(VERSION$1,"/dist/libs/basis_encoder.js");var loadBasisTranscoderPromise;async function loadBasisTrascoderModule(options){var modules=options.modules||{};if(modules.basis){return modules.basis;}loadBasisTranscoderPromise=loadBasisTranscoderPromise||loadBasisTrascoder(options);return await loadBasisTranscoderPromise;}async function loadBasisTrascoder(options){var BASIS=null;var wasmBinary=null;[BASIS,wasmBinary]=await Promise.all([await loadLibrary('basis_transcoder.js','textures',options),await loadLibrary('basis_transcoder.wasm','textures',options)]);BASIS=BASIS||globalThis.BASIS;return await initializeBasisTrascoderModule(BASIS,wasmBinary);}function initializeBasisTrascoderModule(BasisModule,wasmBinary){var options={};if(wasmBinary){options.wasmBinary=wasmBinary;}return new Promise(resolve=>{BasisModule(options).then(module=>{var{BasisFile,initializeBasis}=module;initializeBasis();resolve({BasisFile});});});}var loadBasisEncoderPromise;async function loadBasisEncoderModule(options){var modules=options.modules||{};if(modules.basisEncoder){return modules.basisEncoder;}loadBasisEncoderPromise=loadBasisEncoderPromise||loadBasisEncoder(options);return await loadBasisEncoderPromise;}async function loadBasisEncoder(options){var BASIS_ENCODER=null;var wasmBinary=null;[BASIS_ENCODER,wasmBinary]=await Promise.all([await loadLibrary(BASIS_CDN_ENCODER_JS,'textures',options),await loadLibrary(BASIS_CDN_ENCODER_WASM,'textures',options)]);BASIS_ENCODER=BASIS_ENCODER||globalThis.BASIS;return await initializeBasisEncoderModule(BASIS_ENCODER,wasmBinary);}function initializeBasisEncoderModule(BasisEncoderModule,wasmBinary){var options={};if(wasmBinary){options.wasmBinary=wasmBinary;}return new Promise(resolve=>{BasisEncoderModule(options).then(module=>{var{BasisFile,KTX2File,initializeBasis,BasisEncoder}=module;initializeBasis();resolve({BasisFile,KTX2File,BasisEncoder});});});}var GL_EXTENSIONS_CONSTANTS={COMPRESSED_RGB_S3TC_DXT1_EXT:0x83f0,COMPRESSED_RGBA_S3TC_DXT1_EXT:0x83f1,COMPRESSED_RGBA_S3TC_DXT3_EXT:0x83f2,COMPRESSED_RGBA_S3TC_DXT5_EXT:0x83f3,COMPRESSED_R11_EAC:0x9270,COMPRESSED_SIGNED_R11_EAC:0x9271,COMPRESSED_RG11_EAC:0x9272,COMPRESSED_SIGNED_RG11_EAC:0x9273,COMPRESSED_RGB8_ETC2:0x9274,COMPRESSED_RGBA8_ETC2_EAC:0x9275,COMPRESSED_SRGB8_ETC2:0x9276,COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:0x9277,COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:0x9278,COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:0x9279,COMPRESSED_RGB_PVRTC_4BPPV1_IMG:0x8c00,COMPRESSED_RGBA_PVRTC_4BPPV1_IMG:0x8c02,COMPRESSED_RGB_PVRTC_2BPPV1_IMG:0x8c01,COMPRESSED_RGBA_PVRTC_2BPPV1_IMG:0x8c03,COMPRESSED_RGB_ETC1_WEBGL:0x8d64,COMPRESSED_RGB_ATC_WEBGL:0x8c92,COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL:0x8c93,COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL:0x87ee,COMPRESSED_RGBA_ASTC_4X4_KHR:0x93b0,COMPRESSED_RGBA_ASTC_5X4_KHR:0x93b1,COMPRESSED_RGBA_ASTC_5X5_KHR:0x93b2,COMPRESSED_RGBA_ASTC_6X5_KHR:0x93b3,COMPRESSED_RGBA_ASTC_6X6_KHR:0x93b4,COMPRESSED_RGBA_ASTC_8X5_KHR:0x93b5,COMPRESSED_RGBA_ASTC_8X6_KHR:0x93b6,COMPRESSED_RGBA_ASTC_8X8_KHR:0x93b7,COMPRESSED_RGBA_ASTC_10X5_KHR:0x93b8,COMPRESSED_RGBA_ASTC_10X6_KHR:0x93b9,COMPRESSED_RGBA_ASTC_10X8_KHR:0x93ba,COMPRESSED_RGBA_ASTC_10X10_KHR:0x93bb,COMPRESSED_RGBA_ASTC_12X10_KHR:0x93bc,COMPRESSED_RGBA_ASTC_12X12_KHR:0x93bd,COMPRESSED_SRGB8_ALPHA8_ASTC_4X4_KHR:0x93d0,COMPRESSED_SRGB8_ALPHA8_ASTC_5X4_KHR:0x93d1,COMPRESSED_SRGB8_ALPHA8_ASTC_5X5_KHR:0x93d2,COMPRESSED_SRGB8_ALPHA8_ASTC_6X5_KHR:0x93d3,COMPRESSED_SRGB8_ALPHA8_ASTC_6X6_KHR:0x93d4,COMPRESSED_SRGB8_ALPHA8_ASTC_8X5_KHR:0x93d5,COMPRESSED_SRGB8_ALPHA8_ASTC_8X6_KHR:0x93d6,COMPRESSED_SRGB8_ALPHA8_ASTC_8X8_KHR:0x93d7,COMPRESSED_SRGB8_ALPHA8_ASTC_10X5_KHR:0x93d8,COMPRESSED_SRGB8_ALPHA8_ASTC_10X6_KHR:0x93d9,COMPRESSED_SRGB8_ALPHA8_ASTC_10X8_KHR:0x93da,COMPRESSED_SRGB8_ALPHA8_ASTC_10X10_KHR:0x93db,COMPRESSED_SRGB8_ALPHA8_ASTC_12X10_KHR:0x93dc,COMPRESSED_SRGB8_ALPHA8_ASTC_12X12_KHR:0x93dd,COMPRESSED_RED_RGTC1_EXT:0x8dbb,COMPRESSED_SIGNED_RED_RGTC1_EXT:0x8dbc,COMPRESSED_RED_GREEN_RGTC2_EXT:0x8dbd,COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT:0x8dbe,COMPRESSED_SRGB_S3TC_DXT1_EXT:0x8c4c,COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:0x8c4d,COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:0x8c4e,COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:0x8c4f};var BROWSER_PREFIXES=['','WEBKIT_','MOZ_'];var WEBGL_EXTENSIONS={WEBGL_compressed_texture_s3tc:'dxt',WEBGL_compressed_texture_s3tc_srgb:'dxt-srgb',WEBGL_compressed_texture_etc1:'etc1',WEBGL_compressed_texture_etc:'etc2',WEBGL_compressed_texture_pvrtc:'pvrtc',WEBGL_compressed_texture_atc:'atc',WEBGL_compressed_texture_astc:'astc',EXT_texture_compression_rgtc:'rgtc'};var formats=null;function getSupportedGPUTextureFormats(gl){if(!formats){gl=gl||getWebGLContext()||undefined;formats=new Set();for(var prefix of BROWSER_PREFIXES){for(var extension in WEBGL_EXTENSIONS){if(gl&&gl.getExtension("".concat(prefix).concat(extension))){var gpuTextureFormat=WEBGL_EXTENSIONS[extension];formats.add(gpuTextureFormat);}}}}return formats;}function getWebGLContext(){try{var canvas=document.createElement('canvas');return canvas.getContext('webgl');}catch(error){return null;}}var n$2,i$3,s$1,a$2,r$1,o$2,l$2,f$1;!function(t){t[t.NONE=0]="NONE",t[t.BASISLZ=1]="BASISLZ",t[t.ZSTD=2]="ZSTD",t[t.ZLIB=3]="ZLIB";}(n$2||(n$2={})),function(t){t[t.BASICFORMAT=0]="BASICFORMAT";}(i$3||(i$3={})),function(t){t[t.UNSPECIFIED=0]="UNSPECIFIED",t[t.ETC1S=163]="ETC1S",t[t.UASTC=166]="UASTC";}(s$1||(s$1={})),function(t){t[t.UNSPECIFIED=0]="UNSPECIFIED",t[t.SRGB=1]="SRGB";}(a$2||(a$2={})),function(t){t[t.UNSPECIFIED=0]="UNSPECIFIED",t[t.LINEAR=1]="LINEAR",t[t.SRGB=2]="SRGB",t[t.ITU=3]="ITU",t[t.NTSC=4]="NTSC",t[t.SLOG=5]="SLOG",t[t.SLOG2=6]="SLOG2";}(r$1||(r$1={})),function(t){t[t.ALPHA_STRAIGHT=0]="ALPHA_STRAIGHT",t[t.ALPHA_PREMULTIPLIED=1]="ALPHA_PREMULTIPLIED";}(o$2||(o$2={})),function(t){t[t.RGB=0]="RGB",t[t.RRR=3]="RRR",t[t.GGG=4]="GGG",t[t.AAA=15]="AAA";}(l$2||(l$2={})),function(t){t[t.RGB=0]="RGB",t[t.RGBA=3]="RGBA",t[t.RRR=4]="RRR",t[t.RRRG=5]="RRRG";}(f$1||(f$1={}));var KTX2_ID=[0xab,0x4b,0x54,0x58,0x20,0x32,0x30,0xbb,0x0d,0x0a,0x1a,0x0a];function isKTX(data){var id=new Uint8Array(data);var notKTX=id.byteLength<KTX2_ID.length||id[0]!==KTX2_ID[0]||id[1]!==KTX2_ID[1]||id[2]!==KTX2_ID[2]||id[3]!==KTX2_ID[3]||id[4]!==KTX2_ID[4]||id[5]!==KTX2_ID[5]||id[6]!==KTX2_ID[6]||id[7]!==KTX2_ID[7]||id[8]!==KTX2_ID[8]||id[9]!==KTX2_ID[9]||id[10]!==KTX2_ID[10]||id[11]!==KTX2_ID[11];return !notKTX;}var OutputFormat={etc1:{basisFormat:0,compressed:true,format:GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_ETC1_WEBGL},etc2:{basisFormat:1,compressed:true},bc1:{basisFormat:2,compressed:true,format:GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT},bc3:{basisFormat:3,compressed:true,format:GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT},bc4:{basisFormat:4,compressed:true},bc5:{basisFormat:5,compressed:true},'bc7-m6-opaque-only':{basisFormat:6,compressed:true},'bc7-m5':{basisFormat:7,compressed:true},'pvrtc1-4-rgb':{basisFormat:8,compressed:true,format:GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_4BPPV1_IMG},'pvrtc1-4-rgba':{basisFormat:9,compressed:true,format:GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG},'astc-4x4':{basisFormat:10,compressed:true,format:GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_4X4_KHR},'atc-rgb':{basisFormat:11,compressed:true},'atc-rgba-interpolated-alpha':{basisFormat:12,compressed:true},rgba32:{basisFormat:13,compressed:false},rgb565:{basisFormat:14,compressed:false},bgr565:{basisFormat:15,compressed:false},rgba4444:{basisFormat:16,compressed:false}};async function parseBasis(data,options){if(options.basis.containerFormat==='auto'){if(isKTX(data)){var fileConstructors=await loadBasisEncoderModule(options);return parseKTX2File(fileConstructors.KTX2File,data,options);}var{BasisFile}=await loadBasisTrascoderModule(options);return parseBasisFile(BasisFile,data,options);}switch(options.basis.module){case'encoder':var _fileConstructors=await loadBasisEncoderModule(options);switch(options.basis.containerFormat){case'ktx2':return parseKTX2File(_fileConstructors.KTX2File,data,options);case'basis':default:return parseBasisFile(_fileConstructors.BasisFile,data,options);}case'transcoder':default:var{BasisFile:_BasisFile}=await loadBasisTrascoderModule(options);return parseBasisFile(_BasisFile,data,options);}}function parseBasisFile(BasisFile,data,options){var basisFile=new BasisFile(new Uint8Array(data));try{if(!basisFile.startTranscoding()){return null;}var imageCount=basisFile.getNumImages();var images=[];for(var imageIndex=0;imageIndex<imageCount;imageIndex++){var levelsCount=basisFile.getNumLevels(imageIndex);var levels=[];for(var levelIndex=0;levelIndex<levelsCount;levelIndex++){levels.push(transcodeImage(basisFile,imageIndex,levelIndex,options));}images.push(levels);}return images;}finally{basisFile.close();basisFile.delete();}}function transcodeImage(basisFile,imageIndex,levelIndex,options){var width=basisFile.getImageWidth(imageIndex,levelIndex);var height=basisFile.getImageHeight(imageIndex,levelIndex);var hasAlpha=basisFile.getHasAlpha();var{compressed,format,basisFormat}=getBasisOptions(options,hasAlpha);var decodedSize=basisFile.getImageTranscodedSizeInBytes(imageIndex,levelIndex,basisFormat);var decodedData=new Uint8Array(decodedSize);if(!basisFile.transcodeImage(decodedData,imageIndex,levelIndex,basisFormat,0,0)){return null;}return {width,height,data:decodedData,compressed,hasAlpha,format};}function parseKTX2File(KTX2File,data,options){var ktx2File=new KTX2File(new Uint8Array(data));try{if(!ktx2File.startTranscoding()){return null;}var levelsCount=ktx2File.getLevels();var levels=[];for(var levelIndex=0;levelIndex<levelsCount;levelIndex++){levels.push(transcodeKTX2Image(ktx2File,levelIndex,options));break;}return levels;}finally{ktx2File.close();ktx2File.delete();}}function transcodeKTX2Image(ktx2File,levelIndex,options){var{alphaFlag,height,width}=ktx2File.getImageLevelInfo(levelIndex,0,0);var{compressed,format,basisFormat}=getBasisOptions(options,alphaFlag);var decodedSize=ktx2File.getImageTranscodedSizeInBytes(levelIndex,0,0,basisFormat);var decodedData=new Uint8Array(decodedSize);if(!ktx2File.transcodeImage(decodedData,levelIndex,0,0,basisFormat,0,-1,-1)){return null;}return {width,height,data:decodedData,compressed,alphaFlag,format};}function getBasisOptions(options,hasAlpha){var format=options&&options.basis&&options.basis.format;if(format==='auto'){format=selectSupportedBasisFormat();}if(typeof format==='object'){format=hasAlpha?format.alpha:format.noAlpha;}format=format.toLowerCase();return OutputFormat[format];}function selectSupportedBasisFormat(){var supportedFormats=getSupportedGPUTextureFormats();if(supportedFormats.has('astc')){return 'astc-4x4';}else if(supportedFormats.has('dxt')){return {alpha:'bc3',noAlpha:'bc1'};}else if(supportedFormats.has('pvrtc')){return {alpha:'pvrtc1-4-rgba',noAlpha:'pvrtc1-4-rgb'};}else if(supportedFormats.has('etc1')){return 'etc1';}else if(supportedFormats.has('etc2')){return 'etc2';}return 'rgb565';}var BasisWorkerLoader={name:'Basis',id:'basis',module:'textures',version:VERSION$2,worker:true,extensions:['basis','ktx2'],mimeTypes:['application/octet-stream','image/ktx2'],tests:['sB'],binary:true,options:{basis:{format:'auto',libraryPath:'libs/',containerFormat:'auto',module:'transcoder'}}};var BasisLoader=_objectSpread2(_objectSpread2({},BasisWorkerLoader),{},{parse:parseBasis});var VERSION="3.1.4";var{_parseImageNode}=globalThis;var IMAGE_SUPPORTED=typeof Image!=='undefined';var IMAGE_BITMAP_SUPPORTED=typeof ImageBitmap!=='undefined';var NODE_IMAGE_SUPPORTED=Boolean(_parseImageNode);var DATA_SUPPORTED=isBrowser$2?true:NODE_IMAGE_SUPPORTED;function isImageTypeSupported(type){switch(type){case'auto':return IMAGE_BITMAP_SUPPORTED||IMAGE_SUPPORTED||DATA_SUPPORTED;case'imagebitmap':return IMAGE_BITMAP_SUPPORTED;case'image':return IMAGE_SUPPORTED;case'data':return DATA_SUPPORTED;default:throw new Error("@loaders.gl/images: image ".concat(type," not supported in this environment"));}}function getDefaultImageType(){if(IMAGE_BITMAP_SUPPORTED){return 'imagebitmap';}if(IMAGE_SUPPORTED){return 'image';}if(DATA_SUPPORTED){return 'data';}throw new Error('Install \'@loaders.gl/polyfills\' to parse images under Node.js');}function getImageType(image){var format=getImageTypeOrNull(image);if(!format){throw new Error('Not an image');}return format;}function getImageData(image){switch(getImageType(image)){case'data':return image;case'image':case'imagebitmap':var canvas=document.createElement('canvas');var context=canvas.getContext('2d');if(!context){throw new Error('getImageData');}canvas.width=image.width;canvas.height=image.height;context.drawImage(image,0,0);return context.getImageData(0,0,image.width,image.height);default:throw new Error('getImageData');}}function getImageTypeOrNull(image){if(typeof ImageBitmap!=='undefined'&&image instanceof ImageBitmap){return 'imagebitmap';}if(typeof Image!=='undefined'&&image instanceof Image){return 'image';}if(image&&typeof image==='object'&&image.data&&image.width&&image.height){return 'data';}return null;}var SVG_DATA_URL_PATTERN=/^data:image\/svg\+xml/;var SVG_URL_PATTERN=/\.svg((\?|#).*)?$/;function isSVG(url){return url&&(SVG_DATA_URL_PATTERN.test(url)||SVG_URL_PATTERN.test(url));}function getBlobOrSVGDataUrl(arrayBuffer,url){if(isSVG(url)){var textDecoder=new TextDecoder();var xmlText=textDecoder.decode(arrayBuffer);try{if(typeof unescape==='function'&&typeof encodeURIComponent==='function'){xmlText=unescape(encodeURIComponent(xmlText));}}catch(error){throw new Error(error.message);}var src="data:image/svg+xml;base64,".concat(btoa(xmlText));return src;}return getBlob(arrayBuffer,url);}function getBlob(arrayBuffer,url){if(isSVG(url)){throw new Error('SVG cannot be parsed directly to imagebitmap');}return new Blob([new Uint8Array(arrayBuffer)]);}async function parseToImage(arrayBuffer,options,url){var blobOrDataUrl=getBlobOrSVGDataUrl(arrayBuffer,url);var URL=self.URL||self.webkitURL;var objectUrl=typeof blobOrDataUrl!=='string'&&URL.createObjectURL(blobOrDataUrl);try{return await loadToImage(objectUrl||blobOrDataUrl,options);}finally{if(objectUrl){URL.revokeObjectURL(objectUrl);}}}async function loadToImage(url,options){var image=new Image();image.src=url;if(options.image&&options.image.decode&&image.decode){await image.decode();return image;}return await new Promise((resolve,reject)=>{try{image.onload=()=>resolve(image);image.onerror=err=>reject(new Error("Could not load image ".concat(url,": ").concat(err)));}catch(error){reject(error);}});}var EMPTY_OBJECT={};var imagebitmapOptionsSupported=true;async function parseToImageBitmap(arrayBuffer,options,url){var blob;if(isSVG(url)){var image=await parseToImage(arrayBuffer,options,url);blob=image;}else {blob=getBlob(arrayBuffer,url);}var imagebitmapOptions=options&&options.imagebitmap;return await safeCreateImageBitmap(blob,imagebitmapOptions);}async function safeCreateImageBitmap(blob){var imagebitmapOptions=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;if(isEmptyObject(imagebitmapOptions)||!imagebitmapOptionsSupported){imagebitmapOptions=null;}if(imagebitmapOptions){try{return await createImageBitmap(blob,imagebitmapOptions);}catch(error){console.warn(error);imagebitmapOptionsSupported=false;}}return await createImageBitmap(blob);}function isEmptyObject(object){for(var key in object||EMPTY_OBJECT){return false;}return true;}var BIG_ENDIAN=false;var LITTLE_ENDIAN=true;function getBinaryImageMetadata(binaryData){var dataView=toDataView(binaryData);return getPngMetadata(dataView)||getJpegMetadata(dataView)||getGifMetadata(dataView)||getBmpMetadata(dataView);}function getPngMetadata(binaryData){var dataView=toDataView(binaryData);var isPng=dataView.byteLength>=24&&dataView.getUint32(0,BIG_ENDIAN)===0x89504e47;if(!isPng){return null;}return {mimeType:'image/png',width:dataView.getUint32(16,BIG_ENDIAN),height:dataView.getUint32(20,BIG_ENDIAN)};}function getGifMetadata(binaryData){var dataView=toDataView(binaryData);var isGif=dataView.byteLength>=10&&dataView.getUint32(0,BIG_ENDIAN)===0x47494638;if(!isGif){return null;}return {mimeType:'image/gif',width:dataView.getUint16(6,LITTLE_ENDIAN),height:dataView.getUint16(8,LITTLE_ENDIAN)};}function getBmpMetadata(binaryData){var dataView=toDataView(binaryData);var isBmp=dataView.byteLength>=14&&dataView.getUint16(0,BIG_ENDIAN)===0x424d&&dataView.getUint32(2,LITTLE_ENDIAN)===dataView.byteLength;if(!isBmp){return null;}return {mimeType:'image/bmp',width:dataView.getUint32(18,LITTLE_ENDIAN),height:dataView.getUint32(22,LITTLE_ENDIAN)};}function getJpegMetadata(binaryData){var dataView=toDataView(binaryData);var isJpeg=dataView.byteLength>=3&&dataView.getUint16(0,BIG_ENDIAN)===0xffd8&&dataView.getUint8(2)===0xff;if(!isJpeg){return null;}var{tableMarkers,sofMarkers}=getJpegMarkers();var i=2;while(i+9<dataView.byteLength){var _marker=dataView.getUint16(i,BIG_ENDIAN);if(sofMarkers.has(_marker)){return {mimeType:'image/jpeg',height:dataView.getUint16(i+5,BIG_ENDIAN),width:dataView.getUint16(i+7,BIG_ENDIAN)};}if(!tableMarkers.has(_marker)){return null;}i+=2;i+=dataView.getUint16(i,BIG_ENDIAN);}return null;}function getJpegMarkers(){var tableMarkers=new Set([0xffdb,0xffc4,0xffcc,0xffdd,0xfffe]);for(var _i49=0xffe0;_i49<0xfff0;++_i49){tableMarkers.add(_i49);}var sofMarkers=new Set([0xffc0,0xffc1,0xffc2,0xffc3,0xffc5,0xffc6,0xffc7,0xffc9,0xffca,0xffcb,0xffcd,0xffce,0xffcf,0xffde]);return {tableMarkers,sofMarkers};}function toDataView(data){if(data instanceof DataView){return data;}if(ArrayBuffer.isView(data)){return new DataView(data.buffer);}if(data instanceof ArrayBuffer){return new DataView(data);}throw new Error('toDataView');}async function parseToNodeImage(arrayBuffer,options){var{mimeType}=getBinaryImageMetadata(arrayBuffer)||{};var _parseImageNode=globalThis._parseImageNode;assert$7(_parseImageNode);return await _parseImageNode(arrayBuffer,mimeType);}async function parseImage(arrayBuffer,options,context){options=options||{};var imageOptions=options.image||{};var imageType=imageOptions.type||'auto';var{url}=context||{};var loadType=getLoadableImageType(imageType);var image;switch(loadType){case'imagebitmap':image=await parseToImageBitmap(arrayBuffer,options,url);break;case'image':image=await parseToImage(arrayBuffer,options,url);break;case'data':image=await parseToNodeImage(arrayBuffer);break;default:assert$7(false);}if(imageType==='data'){image=getImageData(image);}return image;}function getLoadableImageType(type){switch(type){case'auto':case'data':return getDefaultImageType();default:isImageTypeSupported(type);return type;}}var EXTENSIONS$1=['png','jpg','jpeg','gif','webp','bmp','ico','svg'];var MIME_TYPES=['image/png','image/jpeg','image/gif','image/webp','image/bmp','image/vnd.microsoft.icon','image/svg+xml'];var DEFAULT_IMAGE_LOADER_OPTIONS={image:{type:'auto',decode:true}};var ImageLoader$1={id:'image',module:'images',name:'Images',version:VERSION,mimeTypes:MIME_TYPES,extensions:EXTENSIONS$1,parse:parseImage,tests:[arrayBuffer=>Boolean(getBinaryImageMetadata(new DataView(arrayBuffer)))],options:DEFAULT_IMAGE_LOADER_OPTIONS};var NODE_FORMAT_SUPPORT=['image/png','image/jpeg','image/gif'];var mimeTypeSupported={};function _isImageFormatSupported(mimeType){if(mimeTypeSupported[mimeType]===undefined){mimeTypeSupported[mimeType]=checkFormatSupport(mimeType);}return mimeTypeSupported[mimeType];}function checkFormatSupport(mimeType){switch(mimeType){case'image/webp':return checkWebPSupport();case'image/svg':return isBrowser$2;default:if(!isBrowser$2){var{_parseImageNode:_parseImageNode2}=globalThis;return Boolean(_parseImageNode2)&&NODE_FORMAT_SUPPORT.includes(mimeType);}return true;}}function checkWebPSupport(){if(!isBrowser$2){return false;}try{var element=document.createElement('canvas');return element.toDataURL('image/webp').indexOf('data:image/webp')===0;}catch(_unused2){return false;}}function assert$1(condition,message){if(!condition){throw new Error(message||'assert failed: gltf');}}function resolveUrl(url,options){var absolute=url.startsWith('data:')||url.startsWith('http:')||url.startsWith('https:');if(absolute){return url;}var baseUrl=options.baseUri||options.uri;if(!baseUrl){throw new Error("'baseUri' must be provided to resolve relative url ".concat(url));}return baseUrl.substr(0,baseUrl.lastIndexOf('/')+1)+url;}function getTypedArrayForBufferView(json,buffers,bufferViewIndex){var bufferView=json.bufferViews[bufferViewIndex];assert$1(bufferView);var bufferIndex=bufferView.buffer;var binChunk=buffers[bufferIndex];assert$1(binChunk);var byteOffset=(bufferView.byteOffset||0)+binChunk.byteOffset;return new Uint8Array(binChunk.arrayBuffer,byteOffset,bufferView.byteLength);}var TYPES=['SCALAR','VEC2','VEC3','VEC4'];var ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT=[[Int8Array,5120],[Uint8Array,5121],[Int16Array,5122],[Uint16Array,5123],[Uint32Array,5125],[Float32Array,5126],[Float64Array,5130]];var ARRAY_TO_COMPONENT_TYPE=new Map(ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT);var ATTRIBUTE_TYPE_TO_COMPONENTS={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16};var ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};var ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array};function getAccessorTypeFromSize(size){var type=TYPES[size-1];return type||TYPES[0];}function getComponentTypeFromArray(typedArray){var componentType=ARRAY_TO_COMPONENT_TYPE.get(typedArray.constructor);if(!componentType){throw new Error('Illegal typed array');}return componentType;}function getAccessorArrayTypeAndLength(accessor,bufferView){var ArrayType=ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY[accessor.componentType];var components=ATTRIBUTE_TYPE_TO_COMPONENTS[accessor.type];var bytesPerComponent=ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE[accessor.componentType];var length=accessor.count*components;var byteLength=accessor.count*components*bytesPerComponent;assert$1(byteLength>=0&&byteLength<=bufferView.byteLength);return {ArrayType,length,byteLength};}var DEFAULT_GLTF_JSON={asset:{version:'2.0',generator:'loaders.gl'},buffers:[]};class GLTFScenegraph{constructor(gltf){_defineProperty$1(this,"gltf",void 0);_defineProperty$1(this,"sourceBuffers",void 0);_defineProperty$1(this,"byteLength",void 0);this.gltf=gltf||{json:_objectSpread2({},DEFAULT_GLTF_JSON),buffers:[]};this.sourceBuffers=[];this.byteLength=0;if(this.gltf.buffers&&this.gltf.buffers[0]){this.byteLength=this.gltf.buffers[0].byteLength;this.sourceBuffers=[this.gltf.buffers[0]];}}get json(){return this.gltf.json;}getApplicationData(key){var data=this.json[key];return data;}getExtraData(key){var extras=this.json.extras||{};return extras[key];}getExtension(extensionName){var isExtension=this.getUsedExtensions().find(name=>name===extensionName);var extensions=this.json.extensions||{};return isExtension?extensions[extensionName]||true:null;}getRequiredExtension(extensionName){var isRequired=this.getRequiredExtensions().find(name=>name===extensionName);return isRequired?this.getExtension(extensionName):null;}getRequiredExtensions(){return this.json.extensionsRequired||[];}getUsedExtensions(){return this.json.extensionsUsed||[];}getObjectExtension(object,extensionName){var extensions=object.extensions||{};return extensions[extensionName];}getScene(index){return this.getObject('scenes',index);}getNode(index){return this.getObject('nodes',index);}getSkin(index){return this.getObject('skins',index);}getMesh(index){return this.getObject('meshes',index);}getMaterial(index){return this.getObject('materials',index);}getAccessor(index){return this.getObject('accessors',index);}getTexture(index){return this.getObject('textures',index);}getSampler(index){return this.getObject('samplers',index);}getImage(index){return this.getObject('images',index);}getBufferView(index){return this.getObject('bufferViews',index);}getBuffer(index){return this.getObject('buffers',index);}getObject(array,index){if(typeof index==='object'){return index;}var object=this.json[array]&&this.json[array][index];if(!object){throw new Error("glTF file error: Could not find ".concat(array,"[").concat(index,"]"));}return object;}getTypedArrayForBufferView(bufferView){bufferView=this.getBufferView(bufferView);var bufferIndex=bufferView.buffer;var binChunk=this.gltf.buffers[bufferIndex];assert$1(binChunk);var byteOffset=(bufferView.byteOffset||0)+binChunk.byteOffset;return new Uint8Array(binChunk.arrayBuffer,byteOffset,bufferView.byteLength);}getTypedArrayForAccessor(accessor){accessor=this.getAccessor(accessor);var bufferView=this.getBufferView(accessor.bufferView);var buffer=this.getBuffer(bufferView.buffer);var arrayBuffer=buffer.data;var{ArrayType,length}=getAccessorArrayTypeAndLength(accessor,bufferView);var byteOffset=bufferView.byteOffset+accessor.byteOffset;return new ArrayType(arrayBuffer,byteOffset,length);}getTypedArrayForImageData(image){image=this.getAccessor(image);var bufferView=this.getBufferView(image.bufferView);var buffer=this.getBuffer(bufferView.buffer);var arrayBuffer=buffer.data;var byteOffset=bufferView.byteOffset||0;return new Uint8Array(arrayBuffer,byteOffset,bufferView.byteLength);}addApplicationData(key,data){this.json[key]=data;return this;}addExtraData(key,data){this.json.extras=this.json.extras||{};this.json.extras[key]=data;return this;}addObjectExtension(object,extensionName,data){object.extensions=object.extensions||{};object.extensions[extensionName]=data;this.registerUsedExtension(extensionName);return this;}setObjectExtension(object,extensionName,data){var extensions=object.extensions||{};extensions[extensionName]=data;}removeObjectExtension(object,extensionName){var extensions=object.extensions||{};var extension=extensions[extensionName];delete extensions[extensionName];return extension;}addExtension(extensionName){var extensionData=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};assert$1(extensionData);this.json.extensions=this.json.extensions||{};this.json.extensions[extensionName]=extensionData;this.registerUsedExtension(extensionName);return extensionData;}addRequiredExtension(extensionName){var extensionData=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};assert$1(extensionData);this.addExtension(extensionName,extensionData);this.registerRequiredExtension(extensionName);return extensionData;}registerUsedExtension(extensionName){this.json.extensionsUsed=this.json.extensionsUsed||[];if(!this.json.extensionsUsed.find(ext=>ext===extensionName)){this.json.extensionsUsed.push(extensionName);}}registerRequiredExtension(extensionName){this.registerUsedExtension(extensionName);this.json.extensionsRequired=this.json.extensionsRequired||[];if(!this.json.extensionsRequired.find(ext=>ext===extensionName)){this.json.extensionsRequired.push(extensionName);}}removeExtension(extensionName){if(this.json.extensionsRequired){this._removeStringFromArray(this.json.extensionsRequired,extensionName);}if(this.json.extensionsUsed){this._removeStringFromArray(this.json.extensionsUsed,extensionName);}if(this.json.extensions){delete this.json.extensions[extensionName];}}setDefaultScene(sceneIndex){this.json.scene=sceneIndex;}addScene(scene){var{nodeIndices}=scene;this.json.scenes=this.json.scenes||[];this.json.scenes.push({nodes:nodeIndices});return this.json.scenes.length-1;}addNode(node){var{meshIndex,matrix}=node;this.json.nodes=this.json.nodes||[];var nodeData={mesh:meshIndex};if(matrix){nodeData.matrix=matrix;}this.json.nodes.push(nodeData);return this.json.nodes.length-1;}addMesh(mesh){var{attributes,indices,material,mode=4}=mesh;var accessors=this._addAttributes(attributes);var glTFMesh={primitives:[{attributes:accessors,mode}]};if(indices){var indicesAccessor=this._addIndices(indices);glTFMesh.primitives[0].indices=indicesAccessor;}if(Number.isFinite(material)){glTFMesh.primitives[0].material=material;}this.json.meshes=this.json.meshes||[];this.json.meshes.push(glTFMesh);return this.json.meshes.length-1;}addPointCloud(attributes){var accessorIndices=this._addAttributes(attributes);var glTFMesh={primitives:[{attributes:accessorIndices,mode:0}]};this.json.meshes=this.json.meshes||[];this.json.meshes.push(glTFMesh);return this.json.meshes.length-1;}addImage(imageData,mimeTypeOpt){var metadata=getBinaryImageMetadata(imageData);var mimeType=mimeTypeOpt||(metadata===null||metadata===void 0?void 0:metadata.mimeType);var bufferViewIndex=this.addBufferView(imageData);var glTFImage={bufferView:bufferViewIndex,mimeType};this.json.images=this.json.images||[];this.json.images.push(glTFImage);return this.json.images.length-1;}addBufferView(buffer){var byteLength=buffer.byteLength;assert$1(Number.isFinite(byteLength));this.sourceBuffers=this.sourceBuffers||[];this.sourceBuffers.push(buffer);var glTFBufferView={buffer:0,byteOffset:this.byteLength,byteLength};this.byteLength+=padToNBytes(byteLength,4);this.json.bufferViews=this.json.bufferViews||[];this.json.bufferViews.push(glTFBufferView);return this.json.bufferViews.length-1;}addAccessor(bufferViewIndex,accessor){var glTFAccessor={bufferView:bufferViewIndex,type:getAccessorTypeFromSize(accessor.size),componentType:accessor.componentType,count:accessor.count,max:accessor.max,min:accessor.min};this.json.accessors=this.json.accessors||[];this.json.accessors.push(glTFAccessor);return this.json.accessors.length-1;}addBinaryBuffer(sourceBuffer){var accessor=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{size:3};var bufferViewIndex=this.addBufferView(sourceBuffer);var minMax={min:accessor.min,max:accessor.max};if(!minMax.min||!minMax.max){minMax=this._getAccessorMinMax(sourceBuffer,accessor.size);}var accessorDefaults={size:accessor.size,componentType:getComponentTypeFromArray(sourceBuffer),count:Math.round(sourceBuffer.length/accessor.size),min:minMax.min,max:minMax.max};return this.addAccessor(bufferViewIndex,Object.assign(accessorDefaults,accessor));}addTexture(texture){var{imageIndex}=texture;var glTFTexture={source:imageIndex};this.json.textures=this.json.textures||[];this.json.textures.push(glTFTexture);return this.json.textures.length-1;}addMaterial(pbrMaterialInfo){this.json.materials=this.json.materials||[];this.json.materials.push(pbrMaterialInfo);return this.json.materials.length-1;}createBinaryChunk(){var _this$json,_this$json$buffers;this.gltf.buffers=[];var totalByteLength=this.byteLength;var arrayBuffer=new ArrayBuffer(totalByteLength);var targetArray=new Uint8Array(arrayBuffer);var dstByteOffset=0;for(var sourceBuffer of this.sourceBuffers||[]){dstByteOffset=copyToArray(sourceBuffer,targetArray,dstByteOffset);}if((_this$json=this.json)!==null&&_this$json!==void 0&&(_this$json$buffers=_this$json.buffers)!==null&&_this$json$buffers!==void 0&&_this$json$buffers[0]){this.json.buffers[0].byteLength=totalByteLength;}else {this.json.buffers=[{byteLength:totalByteLength}];}this.gltf.binary=arrayBuffer;this.sourceBuffers=[arrayBuffer];}_removeStringFromArray(array,string){var found=true;while(found){var index=array.indexOf(string);if(index>-1){array.splice(index,1);}else {found=false;}}}_addAttributes(){var attributes=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var result={};for(var attributeKey in attributes){var attributeData=attributes[attributeKey];var attrName=this._getGltfAttributeName(attributeKey);var accessor=this.addBinaryBuffer(attributeData.value,attributeData);result[attrName]=accessor;}return result;}_addIndices(indices){return this.addBinaryBuffer(indices,{size:1});}_getGltfAttributeName(attributeName){switch(attributeName.toLowerCase()){case'position':case'positions':case'vertices':return 'POSITION';case'normal':case'normals':return 'NORMAL';case'color':case'colors':return 'COLOR_0';case'texcoord':case'texcoords':return 'TEXCOORD_0';default:return attributeName;}}_getAccessorMinMax(buffer,size){var result={min:null,max:null};if(buffer.length<size){return result;}result.min=[];result.max=[];var initValues=buffer.subarray(0,size);for(var value of initValues){result.min.push(value);result.max.push(value);}for(var index=size;index<buffer.length;index+=size){for(var componentIndex=0;componentIndex<size;componentIndex++){result.min[0+componentIndex]=Math.min(result.min[0+componentIndex],buffer[index+componentIndex]);result.max[0+componentIndex]=Math.max(result.max[0+componentIndex],buffer[index+componentIndex]);}}return result;}}var isWebAssemblySupported=typeof WebAssembly!=='object';var wasm_base='B9h9z9tFBBBF8fL9gBB9gLaaaaaFa9gEaaaB9gFaFa9gEaaaFaEMcBFFFGGGEIIILF9wFFFLEFBFKNFaFCx/IFMO/LFVK9tv9t9vq95GBt9f9f939h9z9t9f9j9h9s9s9f9jW9vq9zBBp9tv9z9o9v9wW9f9kv9j9v9kv9WvqWv94h919m9mvqBF8Z9tv9z9o9v9wW9f9kv9j9v9kv9J9u9kv94h919m9mvqBGy9tv9z9o9v9wW9f9kv9j9v9kv9J9u9kv949TvZ91v9u9jvBEn9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9P9jWBIi9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9R919hWBLn9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9F949wBKI9z9iqlBOc+x8ycGBM/qQFTa8jUUUUBCU/EBlHL8kUUUUBC9+RKGXAGCFJAI9LQBCaRKAE2BBC+gF9HQBALAEAIJHOAGlAGTkUUUBRNCUoBAG9uC/wgBZHKCUGAKCUG9JyRVAECFJRICBRcGXEXAcAF9PQFAVAFAclAcAVJAF9JyRMGXGXAG9FQBAMCbJHKC9wZRSAKCIrCEJCGrRQANCUGJRfCBRbAIRTEXGXAOATlAQ9PQBCBRISEMATAQJRIGXAS9FQBCBRtCBREEXGXAOAIlCi9PQBCBRISLMANCU/CBJAEJRKGXGXGXGXGXATAECKrJ2BBAtCKZrCEZfIBFGEBMAKhB83EBAKCNJhB83EBSEMAKAI2BIAI2BBHmCKrHYAYCE6HYy86BBAKCFJAICIJAYJHY2BBAmCIrCEZHPAPCE6HPy86BBAKCGJAYAPJHY2BBAmCGrCEZHPAPCE6HPy86BBAKCEJAYAPJHY2BBAmCEZHmAmCE6Hmy86BBAKCIJAYAmJHY2BBAI2BFHmCKrHPAPCE6HPy86BBAKCLJAYAPJHY2BBAmCIrCEZHPAPCE6HPy86BBAKCKJAYAPJHY2BBAmCGrCEZHPAPCE6HPy86BBAKCOJAYAPJHY2BBAmCEZHmAmCE6Hmy86BBAKCNJAYAmJHY2BBAI2BGHmCKrHPAPCE6HPy86BBAKCVJAYAPJHY2BBAmCIrCEZHPAPCE6HPy86BBAKCcJAYAPJHY2BBAmCGrCEZHPAPCE6HPy86BBAKCMJAYAPJHY2BBAmCEZHmAmCE6Hmy86BBAKCSJAYAmJHm2BBAI2BEHICKrHYAYCE6HYy86BBAKCQJAmAYJHm2BBAICIrCEZHYAYCE6HYy86BBAKCfJAmAYJHm2BBAICGrCEZHYAYCE6HYy86BBAKCbJAmAYJHK2BBAICEZHIAICE6HIy86BBAKAIJRISGMAKAI2BNAI2BBHmCIrHYAYCb6HYy86BBAKCFJAICNJAYJHY2BBAmCbZHmAmCb6Hmy86BBAKCGJAYAmJHm2BBAI2BFHYCIrHPAPCb6HPy86BBAKCEJAmAPJHm2BBAYCbZHYAYCb6HYy86BBAKCIJAmAYJHm2BBAI2BGHYCIrHPAPCb6HPy86BBAKCLJAmAPJHm2BBAYCbZHYAYCb6HYy86BBAKCKJAmAYJHm2BBAI2BEHYCIrHPAPCb6HPy86BBAKCOJAmAPJHm2BBAYCbZHYAYCb6HYy86BBAKCNJAmAYJHm2BBAI2BIHYCIrHPAPCb6HPy86BBAKCVJAmAPJHm2BBAYCbZHYAYCb6HYy86BBAKCcJAmAYJHm2BBAI2BLHYCIrHPAPCb6HPy86BBAKCMJAmAPJHm2BBAYCbZHYAYCb6HYy86BBAKCSJAmAYJHm2BBAI2BKHYCIrHPAPCb6HPy86BBAKCQJAmAPJHm2BBAYCbZHYAYCb6HYy86BBAKCfJAmAYJHm2BBAI2BOHICIrHYAYCb6HYy86BBAKCbJAmAYJHK2BBAICbZHIAICb6HIy86BBAKAIJRISFMAKAI8pBB83BBAKCNJAICNJ8pBB83BBAICTJRIMAtCGJRtAECTJHEAS9JQBMMGXAIQBCBRISEMGXAM9FQBANAbJ2BBRtCBRKAfREEXAEANCU/CBJAKJ2BBHTCFrCBATCFZl9zAtJHt86BBAEAGJREAKCFJHKAM9HQBMMAfCFJRfAIRTAbCFJHbAG9HQBMMABAcAG9sJANCUGJAMAG9sTkUUUBpANANCUGJAMCaJAG9sJAGTkUUUBpMAMCBAIyAcJRcAIQBMC9+RKSFMCBC99AOAIlAGCAAGCA9Ly6yRKMALCU/EBJ8kUUUUBAKM+OmFTa8jUUUUBCoFlHL8kUUUUBC9+RKGXAFCE9uHOCtJAI9LQBCaRKAE2BBHNC/wFZC/gF9HQBANCbZHVCF9LQBALCoBJCgFCUFT+JUUUBpALC84Jha83EBALC8wJha83EBALC8oJha83EBALCAJha83EBALCiJha83EBALCTJha83EBALha83ENALha83EBAEAIJC9wJRcAECFJHNAOJRMGXAF9FQBCQCbAVCF6yRSABRECBRVCBRQCBRfCBRICBRKEXGXAMAcuQBC9+RKSEMGXGXAN2BBHOC/vF9LQBALCoBJAOCIrCa9zAKJCbZCEWJHb8oGIRTAb8oGBRtGXAOCbZHbAS9PQBALAOCa9zAIJCbZCGWJ8oGBAVAbyROAb9FRbGXGXAGCG9HQBABAt87FBABCIJAO87FBABCGJAT87FBSFMAEAtjGBAECNJAOjGBAECIJATjGBMAVAbJRVALCoBJAKCEWJHmAOjGBAmATjGIALAICGWJAOjGBALCoBJAKCFJCbZHKCEWJHTAtjGBATAOjGIAIAbJRIAKCFJRKSGMGXGXAbCb6QBAQAbJAbC989zJCFJRQSFMAM1BBHbCgFZROGXGXAbCa9MQBAMCFJRMSFMAM1BFHbCgBZCOWAOCgBZqROGXAbCa9MQBAMCGJRMSFMAM1BGHbCgBZCfWAOqROGXAbCa9MQBAMCEJRMSFMAM1BEHbCgBZCdWAOqROGXAbCa9MQBAMCIJRMSFMAM2BIC8cWAOqROAMCLJRMMAOCFrCBAOCFZl9zAQJRQMGXGXAGCG9HQBABAt87FBABCIJAQ87FBABCGJAT87FBSFMAEAtjGBAECNJAQjGBAECIJATjGBMALCoBJAKCEWJHOAQjGBAOATjGIALAICGWJAQjGBALCoBJAKCFJCbZHKCEWJHOAtjGBAOAQjGIAICFJRIAKCFJRKSFMGXAOCDF9LQBALAIAcAOCbZJ2BBHbCIrHTlCbZCGWJ8oGBAVCFJHtATyROALAIAblCbZCGWJ8oGBAtAT9FHmJHtAbCbZHTyRbAT9FRTGXGXAGCG9HQBABAV87FBABCIJAb87FBABCGJAO87FBSFMAEAVjGBAECNJAbjGBAECIJAOjGBMALAICGWJAVjGBALCoBJAKCEWJHYAOjGBAYAVjGIALAICFJHICbZCGWJAOjGBALCoBJAKCFJCbZCEWJHYAbjGBAYAOjGIALAIAmJCbZHICGWJAbjGBALCoBJAKCGJCbZHKCEWJHOAVjGBAOAbjGIAKCFJRKAIATJRIAtATJRVSFMAVCBAM2BBHYyHTAOC/+F6HPJROAYCbZRtGXGXAYCIrHmQBAOCFJRbSFMAORbALAIAmlCbZCGWJ8oGBROMGXGXAtQBAbCFJRVSFMAbRVALAIAYlCbZCGWJ8oGBRbMGXGXAP9FQBAMCFJRYSFMAM1BFHYCgFZRTGXGXAYCa9MQBAMCGJRYSFMAM1BGHYCgBZCOWATCgBZqRTGXAYCa9MQBAMCEJRYSFMAM1BEHYCgBZCfWATqRTGXAYCa9MQBAMCIJRYSFMAM1BIHYCgBZCdWATqRTGXAYCa9MQBAMCLJRYSFMAMCKJRYAM2BLC8cWATqRTMATCFrCBATCFZl9zAQJHQRTMGXGXAmCb6QBAYRPSFMAY1BBHMCgFZROGXGXAMCa9MQBAYCFJRPSFMAY1BFHMCgBZCOWAOCgBZqROGXAMCa9MQBAYCGJRPSFMAY1BGHMCgBZCfWAOqROGXAMCa9MQBAYCEJRPSFMAY1BEHMCgBZCdWAOqROGXAMCa9MQBAYCIJRPSFMAYCLJRPAY2BIC8cWAOqROMAOCFrCBAOCFZl9zAQJHQROMGXGXAtCb6QBAPRMSFMAP1BBHMCgFZRbGXGXAMCa9MQBAPCFJRMSFMAP1BFHMCgBZCOWAbCgBZqRbGXAMCa9MQBAPCGJRMSFMAP1BGHMCgBZCfWAbqRbGXAMCa9MQBAPCEJRMSFMAP1BEHMCgBZCdWAbqRbGXAMCa9MQBAPCIJRMSFMAPCLJRMAP2BIC8cWAbqRbMAbCFrCBAbCFZl9zAQJHQRbMGXGXAGCG9HQBABAT87FBABCIJAb87FBABCGJAO87FBSFMAEATjGBAECNJAbjGBAECIJAOjGBMALCoBJAKCEWJHYAOjGBAYATjGIALAICGWJATjGBALCoBJAKCFJCbZCEWJHYAbjGBAYAOjGIALAICFJHICbZCGWJAOjGBALCoBJAKCGJCbZCEWJHOATjGBAOAbjGIALAIAm9FAmCb6qJHICbZCGWJAbjGBAIAt9FAtCb6qJRIAKCEJRKMANCFJRNABCKJRBAECSJREAKCbZRKAICbZRIAfCEJHfAF9JQBMMCBC99AMAc6yRKMALCoFJ8kUUUUBAKM/tIFGa8jUUUUBCTlRLC9+RKGXAFCLJAI9LQBCaRKAE2BBC/+FZC/QF9HQBALhB83ENAECFJRKAEAIJC98JREGXAF9FQBGXAGCG6QBEXGXAKAE9JQBC9+bMAK1BBHGCgFZRIGXGXAGCa9MQBAKCFJRKSFMAK1BFHGCgBZCOWAICgBZqRIGXAGCa9MQBAKCGJRKSFMAK1BGHGCgBZCfWAIqRIGXAGCa9MQBAKCEJRKSFMAK1BEHGCgBZCdWAIqRIGXAGCa9MQBAKCIJRKSFMAK2BIC8cWAIqRIAKCLJRKMALCNJAICFZCGWqHGAICGrCBAICFrCFZl9zAG8oGBJHIjGBABAIjGBABCIJRBAFCaJHFQBSGMMEXGXAKAE9JQBC9+bMAK1BBHGCgFZRIGXGXAGCa9MQBAKCFJRKSFMAK1BFHGCgBZCOWAICgBZqRIGXAGCa9MQBAKCGJRKSFMAK1BGHGCgBZCfWAIqRIGXAGCa9MQBAKCEJRKSFMAK1BEHGCgBZCdWAIqRIGXAGCa9MQBAKCIJRKSFMAK2BIC8cWAIqRIAKCLJRKMABAICGrCBAICFrCFZl9zALCNJAICFZCGWqHI8oGBJHG87FBAIAGjGBABCGJRBAFCaJHFQBMMCBC99AKAE6yRKMAKM+lLKFaF99GaG99FaG99GXGXAGCI9HQBAF9FQFEXGXGX9DBBB8/9DBBB+/ABCGJHG1BB+yAB1BBHE+yHI+L+TABCFJHL1BBHK+yHO+L+THN9DBBBB9gHVyAN9DBB/+hANAN+U9DBBBBANAVyHcAc+MHMAECa3yAI+SHIAI+UAcAMAKCa3yAO+SHcAc+U+S+S+R+VHO+U+SHN+L9DBBB9P9d9FQBAN+oRESFMCUUUU94REMAGAE86BBGXGX9DBBB8/9DBBB+/Ac9DBBBB9gyAcAO+U+SHN+L9DBBB9P9d9FQBAN+oRGSFMCUUUU94RGMALAG86BBGXGX9DBBB8/9DBBB+/AI9DBBBB9gyAIAO+U+SHN+L9DBBB9P9d9FQBAN+oRGSFMCUUUU94RGMABAG86BBABCIJRBAFCaJHFQBSGMMAF9FQBEXGXGX9DBBB8/9DBBB+/ABCIJHG8uFB+yAB8uFBHE+yHI+L+TABCGJHL8uFBHK+yHO+L+THN9DBBBB9gHVyAN9DB/+g6ANAN+U9DBBBBANAVyHcAc+MHMAECa3yAI+SHIAI+UAcAMAKCa3yAO+SHcAc+U+S+S+R+VHO+U+SHN+L9DBBB9P9d9FQBAN+oRESFMCUUUU94REMAGAE87FBGXGX9DBBB8/9DBBB+/Ac9DBBBB9gyAcAO+U+SHN+L9DBBB9P9d9FQBAN+oRGSFMCUUUU94RGMALAG87FBGXGX9DBBB8/9DBBB+/AI9DBBBB9gyAIAO+U+SHN+L9DBBB9P9d9FQBAN+oRGSFMCUUUU94RGMABAG87FBABCNJRBAFCaJHFQBMMM/SEIEaE99EaF99GXAF9FQBCBREABRIEXGXGX9D/zI818/AICKJ8uFBHLCEq+y+VHKAI8uFB+y+UHO9DB/+g6+U9DBBB8/9DBBB+/AO9DBBBB9gy+SHN+L9DBBB9P9d9FQBAN+oRVSFMCUUUU94RVMAICIJ8uFBRcAICGJ8uFBRMABALCFJCEZAEqCFWJAV87FBGXGXAKAM+y+UHN9DB/+g6+U9DBBB8/9DBBB+/AN9DBBBB9gy+SHS+L9DBBB9P9d9FQBAS+oRMSFMCUUUU94RMMABALCGJCEZAEqCFWJAM87FBGXGXAKAc+y+UHK9DB/+g6+U9DBBB8/9DBBB+/AK9DBBBB9gy+SHS+L9DBBB9P9d9FQBAS+oRcSFMCUUUU94RcMABALCaJCEZAEqCFWJAc87FBGXGX9DBBU8/AOAO+U+TANAN+U+TAKAK+U+THO9DBBBBAO9DBBBB9gy+R9DB/+g6+U9DBBB8/+SHO+L9DBBB9P9d9FQBAO+oRcSFMCUUUU94RcMABALCEZAEqCFWJAc87FBAICNJRIAECIJREAFCaJHFQBMMM9JBGXAGCGrAF9sHF9FQBEXABAB8oGBHGCNWCN91+yAGCi91CnWCUUU/8EJ+++U84GBABCIJRBAFCaJHFQBMMM9TFEaCBCB8oGUkUUBHFABCEJC98ZJHBjGUkUUBGXGXAB8/BCTWHGuQBCaREABAGlCggEJCTrXBCa6QFMAFREMAEM/lFFFaGXGXAFABqCEZ9FQBABRESFMGXGXAGCT9PQBABRESFMABREEXAEAF8oGBjGBAECIJAFCIJ8oGBjGBAECNJAFCNJ8oGBjGBAECSJAFCSJ8oGBjGBAECTJREAFCTJRFAGC9wJHGCb9LQBMMAGCI9JQBEXAEAF8oGBjGBAFCIJRFAECIJREAGC98JHGCE9LQBMMGXAG9FQBEXAEAF2BB86BBAECFJREAFCFJRFAGCaJHGQBMMABMoFFGaGXGXABCEZ9FQBABRESFMAFCgFZC+BwsN9sRIGXGXAGCT9PQBABRESFMABREEXAEAIjGBAECSJAIjGBAECNJAIjGBAECIJAIjGBAECTJREAGC9wJHGCb9LQBMMAGCI9JQBEXAEAIjGBAECIJREAGC98JHGCE9LQBMMGXAG9FQBEXAEAF86BBAECFJREAGCaJHGQBMMABMMMFBCUNMIT9kBB';var wasm_simd='B9h9z9tFBBBF8dL9gBB9gLaaaaaFa9gEaaaB9gGaaB9gFaFaEQSBBFBFFGEGEGIILF9wFFFLEFBFKNFaFCx/aFMO/LFVK9tv9t9vq95GBt9f9f939h9z9t9f9j9h9s9s9f9jW9vq9zBBp9tv9z9o9v9wW9f9kv9j9v9kv9WvqWv94h919m9mvqBG8Z9tv9z9o9v9wW9f9kv9j9v9kv9J9u9kv94h919m9mvqBIy9tv9z9o9v9wW9f9kv9j9v9kv9J9u9kv949TvZ91v9u9jvBLn9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9P9jWBKi9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9R919hWBNn9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9F949wBcI9z9iqlBMc/j9JSIBTEM9+FLa8jUUUUBCTlRBCBRFEXCBRGCBREEXABCNJAGJAECUaAFAGrCFZHIy86BBAEAIJREAGCFJHGCN9HQBMAFCx+YUUBJAE86BBAFCEWCxkUUBJAB8pEN83EBAFCFJHFCUG9HQBMMkRIbaG97FaK978jUUUUBCU/KBlHL8kUUUUBC9+RKGXAGCFJAI9LQBCaRKAE2BBC+gF9HQBALAEAIJHOAGlAG/8cBBCUoBAG9uC/wgBZHKCUGAKCUG9JyRNAECFJRKCBRVGXEXAVAF9PQFANAFAVlAVANJAF9JyRcGXGXAG9FQBAcCbJHIC9wZHMCE9sRSAMCFWRQAICIrCEJCGrRfCBRbEXAKRTCBRtGXEXGXAOATlAf9PQBCBRKSLMALCU/CBJAtAM9sJRmATAfJRKCBREGXAMCoB9JQBAOAKlC/gB9JQBCBRIEXAmAIJREGXGXGXGXGXATAICKrJ2BBHYCEZfIBFGEBMAECBDtDMIBSEMAEAKDBBIAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnHPCGD+MFAPDQBTFtGmEYIPLdKeOnC0+G+MiDtD9OHdCEDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBAeCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMIBAKCIJAnDeBJAeCx+YUUBJ2BBJRKSGMAEAKDBBNAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnC+P+e+8/4BDtD9OHdCbDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBAeCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMIBAKCNJAnDeBJAeCx+YUUBJ2BBJRKSFMAEAKDBBBDMIBAKCTJRKMGXGXGXGXGXAYCGrCEZfIBFGEBMAECBDtDMITSEMAEAKDBBIAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnHPCGD+MFAPDQBTFtGmEYIPLdKeOnC0+G+MiDtD9OHdCEDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBAeCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMITAKCIJAnDeBJAeCx+YUUBJ2BBJRKSGMAEAKDBBNAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnC+P+e+8/4BDtD9OHdCbDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBAeCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMITAKCNJAnDeBJAeCx+YUUBJ2BBJRKSFMAEAKDBBBDMITAKCTJRKMGXGXGXGXGXAYCIrCEZfIBFGEBMAECBDtDMIASEMAEAKDBBIAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnHPCGD+MFAPDQBTFtGmEYIPLdKeOnC0+G+MiDtD9OHdCEDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBAeCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMIAAKCIJAnDeBJAeCx+YUUBJ2BBJRKSGMAEAKDBBNAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnC+P+e+8/4BDtD9OHdCbDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBAeCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMIAAKCNJAnDeBJAeCx+YUUBJ2BBJRKSFMAEAKDBBBDMIAAKCTJRKMGXGXGXGXGXAYCKrfIBFGEBMAECBDtDMI8wSEMAEAKDBBIAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnHPCGD+MFAPDQBTFtGmEYIPLdKeOnC0+G+MiDtD9OHdCEDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HYCEWCxkUUBJDBEBAYCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HYCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMI8wAKCIJAnDeBJAYCx+YUUBJ2BBJRKSGMAEAKDBBNAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnC+P+e+8/4BDtD9OHdCbDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HYCEWCxkUUBJDBEBAYCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HYCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMI8wAKCNJAnDeBJAYCx+YUUBJ2BBJRKSFMAEAKDBBBDMI8wAKCTJRKMAICoBJREAICUFJAM9LQFAERIAOAKlC/fB9LQBMMGXAEAM9PQBAECErRIEXGXAOAKlCi9PQBCBRKSOMAmAEJRYGXGXGXGXGXATAECKrJ2BBAICKZrCEZfIBFGEBMAYCBDtDMIBSEMAYAKDBBIAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnHPCGD+MFAPDQBTFtGmEYIPLdKeOnC0+G+MiDtD9OHdCEDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBAeCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMIBAKCIJAnDeBJAeCx+YUUBJ2BBJRKSGMAYAKDBBNAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnC+P+e+8/4BDtD9OHdCbDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBAeCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMIBAKCNJAnDeBJAeCx+YUUBJ2BBJRKSFMAYAKDBBBDMIBAKCTJRKMAICGJRIAECTJHEAM9JQBMMGXAK9FQBAKRTAtCFJHtCI6QGSFMMCBRKSEMGXAM9FQBALCUGJAbJREALAbJDBGBRnCBRYEXAEALCU/CBJAYJHIDBIBHdCFD9tAdCFDbHPD9OD9hD9RHdAIAMJDBIBHiCFD9tAiAPD9OD9hD9RHiDQBTFtGmEYIPLdKeOnH8ZAIAQJDBIBHpCFD9tApAPD9OD9hD9RHpAIASJDBIBHyCFD9tAyAPD9OD9hD9RHyDQBTFtGmEYIPLdKeOnH8cDQBFTtGEmYILPdKOenHPAPDQBFGEBFGEBFGEBFGEAnD9uHnDyBjGBAEAGJHIAnAPAPDQILKOILKOILKOILKOD9uHnDyBjGBAIAGJHIAnAPAPDQNVcMNVcMNVcMNVcMD9uHnDyBjGBAIAGJHIAnAPAPDQSQfbSQfbSQfbSQfbD9uHnDyBjGBAIAGJHIAnA8ZA8cDQNVi8ZcMpySQ8c8dfb8e8fHPAPDQBFGEBFGEBFGEBFGED9uHnDyBjGBAIAGJHIAnAPAPDQILKOILKOILKOILKOD9uHnDyBjGBAIAGJHIAnAPAPDQNVcMNVcMNVcMNVcMD9uHnDyBjGBAIAGJHIAnAPAPDQSQfbSQfbSQfbSQfbD9uHnDyBjGBAIAGJHIAnAdAiDQNiV8ZcpMyS8cQ8df8eb8fHdApAyDQNiV8ZcpMyS8cQ8df8eb8fHiDQBFTtGEmYILPdKOenHPAPDQBFGEBFGEBFGEBFGED9uHnDyBjGBAIAGJHIAnAPAPDQILKOILKOILKOILKOD9uHnDyBjGBAIAGJHIAnAPAPDQNVcMNVcMNVcMNVcMD9uHnDyBjGBAIAGJHIAnAPAPDQSQfbSQfbSQfbSQfbD9uHnDyBjGBAIAGJHIAnAdAiDQNVi8ZcMpySQ8c8dfb8e8fHPAPDQBFGEBFGEBFGEBFGED9uHnDyBjGBAIAGJHIAnAPAPDQILKOILKOILKOILKOD9uHnDyBjGBAIAGJHIAnAPAPDQNVcMNVcMNVcMNVcMD9uHnDyBjGBAIAGJHIAnAPAPDQSQfbSQfbSQfbSQfbD9uHnDyBjGBAIAGJREAYCTJHYAM9JQBMMAbCIJHbAG9JQBMMABAVAG9sJALCUGJAcAG9s/8cBBALALCUGJAcCaJAG9sJAG/8cBBMAcCBAKyAVJRVAKQBMC9+RKSFMCBC99AOAKlAGCAAGCA9Ly6yRKMALCU/KBJ8kUUUUBAKMNBT+BUUUBM+KmFTa8jUUUUBCoFlHL8kUUUUBC9+RKGXAFCE9uHOCtJAI9LQBCaRKAE2BBHNC/wFZC/gF9HQBANCbZHVCF9LQBALCoBJCgFCUF/8MBALC84Jha83EBALC8wJha83EBALC8oJha83EBALCAJha83EBALCiJha83EBALCTJha83EBALha83ENALha83EBAEAIJC9wJRcAECFJHNAOJRMGXAF9FQBCQCbAVCF6yRSABRECBRVCBRQCBRfCBRICBRKEXGXAMAcuQBC9+RKSEMGXGXAN2BBHOC/vF9LQBALCoBJAOCIrCa9zAKJCbZCEWJHb8oGIRTAb8oGBRtGXAOCbZHbAS9PQBALAOCa9zAIJCbZCGWJ8oGBAVAbyROAb9FRbGXGXAGCG9HQBABAt87FBABCIJAO87FBABCGJAT87FBSFMAEAtjGBAECNJAOjGBAECIJATjGBMAVAbJRVALCoBJAKCEWJHmAOjGBAmATjGIALAICGWJAOjGBALCoBJAKCFJCbZHKCEWJHTAtjGBATAOjGIAIAbJRIAKCFJRKSGMGXGXAbCb6QBAQAbJAbC989zJCFJRQSFMAM1BBHbCgFZROGXGXAbCa9MQBAMCFJRMSFMAM1BFHbCgBZCOWAOCgBZqROGXAbCa9MQBAMCGJRMSFMAM1BGHbCgBZCfWAOqROGXAbCa9MQBAMCEJRMSFMAM1BEHbCgBZCdWAOqROGXAbCa9MQBAMCIJRMSFMAM2BIC8cWAOqROAMCLJRMMAOCFrCBAOCFZl9zAQJRQMGXGXAGCG9HQBABAt87FBABCIJAQ87FBABCGJAT87FBSFMAEAtjGBAECNJAQjGBAECIJATjGBMALCoBJAKCEWJHOAQjGBAOATjGIALAICGWJAQjGBALCoBJAKCFJCbZHKCEWJHOAtjGBAOAQjGIAICFJRIAKCFJRKSFMGXAOCDF9LQBALAIAcAOCbZJ2BBHbCIrHTlCbZCGWJ8oGBAVCFJHtATyROALAIAblCbZCGWJ8oGBAtAT9FHmJHtAbCbZHTyRbAT9FRTGXGXAGCG9HQBABAV87FBABCIJAb87FBABCGJAO87FBSFMAEAVjGBAECNJAbjGBAECIJAOjGBMALAICGWJAVjGBALCoBJAKCEWJHYAOjGBAYAVjGIALAICFJHICbZCGWJAOjGBALCoBJAKCFJCbZCEWJHYAbjGBAYAOjGIALAIAmJCbZHICGWJAbjGBALCoBJAKCGJCbZHKCEWJHOAVjGBAOAbjGIAKCFJRKAIATJRIAtATJRVSFMAVCBAM2BBHYyHTAOC/+F6HPJROAYCbZRtGXGXAYCIrHmQBAOCFJRbSFMAORbALAIAmlCbZCGWJ8oGBROMGXGXAtQBAbCFJRVSFMAbRVALAIAYlCbZCGWJ8oGBRbMGXGXAP9FQBAMCFJRYSFMAM1BFHYCgFZRTGXGXAYCa9MQBAMCGJRYSFMAM1BGHYCgBZCOWATCgBZqRTGXAYCa9MQBAMCEJRYSFMAM1BEHYCgBZCfWATqRTGXAYCa9MQBAMCIJRYSFMAM1BIHYCgBZCdWATqRTGXAYCa9MQBAMCLJRYSFMAMCKJRYAM2BLC8cWATqRTMATCFrCBATCFZl9zAQJHQRTMGXGXAmCb6QBAYRPSFMAY1BBHMCgFZROGXGXAMCa9MQBAYCFJRPSFMAY1BFHMCgBZCOWAOCgBZqROGXAMCa9MQBAYCGJRPSFMAY1BGHMCgBZCfWAOqROGXAMCa9MQBAYCEJRPSFMAY1BEHMCgBZCdWAOqROGXAMCa9MQBAYCIJRPSFMAYCLJRPAY2BIC8cWAOqROMAOCFrCBAOCFZl9zAQJHQROMGXGXAtCb6QBAPRMSFMAP1BBHMCgFZRbGXGXAMCa9MQBAPCFJRMSFMAP1BFHMCgBZCOWAbCgBZqRbGXAMCa9MQBAPCGJRMSFMAP1BGHMCgBZCfWAbqRbGXAMCa9MQBAPCEJRMSFMAP1BEHMCgBZCdWAbqRbGXAMCa9MQBAPCIJRMSFMAPCLJRMAP2BIC8cWAbqRbMAbCFrCBAbCFZl9zAQJHQRbMGXGXAGCG9HQBABAT87FBABCIJAb87FBABCGJAO87FBSFMAEATjGBAECNJAbjGBAECIJAOjGBMALCoBJAKCEWJHYAOjGBAYATjGIALAICGWJATjGBALCoBJAKCFJCbZCEWJHYAbjGBAYAOjGIALAICFJHICbZCGWJAOjGBALCoBJAKCGJCbZCEWJHOATjGBAOAbjGIALAIAm9FAmCb6qJHICbZCGWJAbjGBAIAt9FAtCb6qJRIAKCEJRKMANCFJRNABCKJRBAECSJREAKCbZRKAICbZRIAfCEJHfAF9JQBMMCBC99AMAc6yRKMALCoFJ8kUUUUBAKM/tIFGa8jUUUUBCTlRLC9+RKGXAFCLJAI9LQBCaRKAE2BBC/+FZC/QF9HQBALhB83ENAECFJRKAEAIJC98JREGXAF9FQBGXAGCG6QBEXGXAKAE9JQBC9+bMAK1BBHGCgFZRIGXGXAGCa9MQBAKCFJRKSFMAK1BFHGCgBZCOWAICgBZqRIGXAGCa9MQBAKCGJRKSFMAK1BGHGCgBZCfWAIqRIGXAGCa9MQBAKCEJRKSFMAK1BEHGCgBZCdWAIqRIGXAGCa9MQBAKCIJRKSFMAK2BIC8cWAIqRIAKCLJRKMALCNJAICFZCGWqHGAICGrCBAICFrCFZl9zAG8oGBJHIjGBABAIjGBABCIJRBAFCaJHFQBSGMMEXGXAKAE9JQBC9+bMAK1BBHGCgFZRIGXGXAGCa9MQBAKCFJRKSFMAK1BFHGCgBZCOWAICgBZqRIGXAGCa9MQBAKCGJRKSFMAK1BGHGCgBZCfWAIqRIGXAGCa9MQBAKCEJRKSFMAK1BEHGCgBZCdWAIqRIGXAGCa9MQBAKCIJRKSFMAK2BIC8cWAIqRIAKCLJRKMABAICGrCBAICFrCFZl9zALCNJAICFZCGWqHI8oGBJHG87FBAIAGjGBABCGJRBAFCaJHFQBMMCBC99AKAE6yRKMAKM/xLGEaK978jUUUUBCAlHE8kUUUUBGXGXAGCI9HQBGXAFC98ZHI9FQBABRGCBRLEXAGAGDBBBHKCiD+rFCiD+sFD/6FHOAKCND+rFCiD+sFD/6FAOD/gFAKCTD+rFCiD+sFD/6FHND/gFD/kFD/lFHVCBDtD+2FHcAOCUUUU94DtHMD9OD9RD/kFHO9DBB/+hDYAOAOD/mFAVAVD/mFANAcANAMD9OD9RD/kFHOAOD/mFD/kFD/kFD/jFD/nFHND/mF9DBBX9LDYHcD/kFCgFDtD9OAKCUUU94DtD9OD9QAOAND/mFAcD/kFCND+rFCU/+EDtD9OD9QAVAND/mFAcD/kFCTD+rFCUU/8ODtD9OD9QDMBBAGCTJRGALCIJHLAI9JQBMMAIAF9PQFAEAFCEZHLCGWHGqCBCTAGl/8MBAEABAICGWJHIAG/8cBBGXAL9FQBAEAEDBIBHKCiD+rFCiD+sFD/6FHOAKCND+rFCiD+sFD/6FAOD/gFAKCTD+rFCiD+sFD/6FHND/gFD/kFD/lFHVCBDtD+2FHcAOCUUUU94DtHMD9OD9RD/kFHO9DBB/+hDYAOAOD/mFAVAVD/mFANAcANAMD9OD9RD/kFHOAOD/mFD/kFD/kFD/jFD/nFHND/mF9DBBX9LDYHcD/kFCgFDtD9OAKCUUU94DtD9OD9QAOAND/mFAcD/kFCND+rFCU/+EDtD9OD9QAVAND/mFAcD/kFCTD+rFCUU/8ODtD9OD9QDMIBMAIAEAG/8cBBSFMABAFC98ZHGT+HUUUBAGAF9PQBAEAFCEZHICEWHLJCBCAALl/8MBAEABAGCEWJHGAL/8cBBAEAIT+HUUUBAGAEAL/8cBBMAECAJ8kUUUUBM+yEGGaO97GXAF9FQBCBRGEXABCTJHEAEDBBBHICBDtHLCUU98D8cFCUU98D8cEHKD9OABDBBBHOAIDQILKOSQfbPden8c8d8e8fCggFDtD9OD/6FAOAIDQBFGENVcMTtmYi8ZpyHICTD+sFD/6FHND/gFAICTD+rFCTD+sFD/6FHVD/gFD/kFD/lFHI9DB/+g6DYAVAIALD+2FHLAVCUUUU94DtHcD9OD9RD/kFHVAVD/mFAIAID/mFANALANAcD9OD9RD/kFHIAID/mFD/kFD/kFD/jFD/nFHND/mF9DBBX9LDYHLD/kFCTD+rFAVAND/mFALD/kFCggEDtD9OD9QHVAIAND/mFALD/kFCaDbCBDnGCBDnECBDnKCBDnOCBDncCBDnMCBDnfCBDnbD9OHIDQNVi8ZcMpySQ8c8dfb8e8fD9QDMBBABAOAKD9OAVAIDQBFTtGEmYILPdKOenD9QDMBBABCAJRBAGCIJHGAF9JQBMMM94FEa8jUUUUBCAlHE8kUUUUBABAFC98ZHIT+JUUUBGXAIAF9PQBAEAFCEZHLCEWHFJCBCAAFl/8MBAEABAICEWJHBAF/8cBBAEALT+JUUUBABAEAF/8cBBMAECAJ8kUUUUBM/hEIGaF97FaL978jUUUUBCTlRGGXAF9FQBCBREEXAGABDBBBHIABCTJHLDBBBHKDQILKOSQfbPden8c8d8e8fHOCTD+sFHNCID+rFDMIBAB9DBBU8/DY9D/zI818/DYANCEDtD9QD/6FD/nFHNAIAKDQBFGENVcMTtmYi8ZpyHICTD+rFCTD+sFD/6FD/mFHKAKD/mFANAICTD+sFD/6FD/mFHVAVD/mFANAOCTD+rFCTD+sFD/6FD/mFHOAOD/mFD/kFD/kFD/lFCBDtD+4FD/jF9DB/+g6DYHND/mF9DBBX9LDYHID/kFCggEDtHcD9OAVAND/mFAID/kFCTD+rFD9QHVAOAND/mFAID/kFCTD+rFAKAND/mFAID/kFAcD9OD9QHNDQBFTtGEmYILPdKOenHID8dBAGDBIBDyB+t+J83EBABCNJAID8dFAGDBIBDyF+t+J83EBALAVANDQNVi8ZcMpySQ8c8dfb8e8fHND8dBAGDBIBDyG+t+J83EBABCiJAND8dFAGDBIBDyE+t+J83EBABCAJRBAECIJHEAF9JQBMMM/3FGEaF978jUUUUBCoBlREGXAGCGrAF9sHIC98ZHL9FQBCBRGABRFEXAFAFDBBBHKCND+rFCND+sFD/6FAKCiD+sFCnD+rFCUUU/8EDtD+uFD/mFDMBBAFCTJRFAGCIJHGAL9JQBMMGXALAI9PQBAEAICEZHGCGWHFqCBCoBAFl/8MBAEABALCGWJHLAF/8cBBGXAG9FQBAEAEDBIBHKCND+rFCND+sFD/6FAKCiD+sFCnD+rFCUUU/8EDtD+uFD/mFDMIBMALAEAF/8cBBMM9TFEaCBCB8oGUkUUBHFABCEJC98ZJHBjGUkUUBGXGXAB8/BCTWHGuQBCaREABAGlCggEJCTrXBCa6QFMAFREMAEMMMFBCUNMIT9tBB';var detector=new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,3,2,0,0,5,3,1,0,1,12,1,0,10,22,2,12,0,65,0,65,0,65,0,252,10,0,0,11,7,0,65,0,253,15,26,11]);var wasmpack=new Uint8Array([32,0,65,253,3,1,2,34,4,106,6,5,11,8,7,20,13,33,12,16,128,9,116,64,19,113,127,15,10,21,22,14,255,66,24,54,136,107,18,23,192,26,114,118,132,17,77,101,130,144,27,87,131,44,45,74,156,154,70,167]);var FILTERS={0:'',1:'meshopt_decodeFilterOct',2:'meshopt_decodeFilterQuat',3:'meshopt_decodeFilterExp',NONE:'',OCTAHEDRAL:'meshopt_decodeFilterOct',QUATERNION:'meshopt_decodeFilterQuat',EXPONENTIAL:'meshopt_decodeFilterExp'};var DECODERS={0:'meshopt_decodeVertexBuffer',1:'meshopt_decodeIndexBuffer',2:'meshopt_decodeIndexSequence',ATTRIBUTES:'meshopt_decodeVertexBuffer',TRIANGLES:'meshopt_decodeIndexBuffer',INDICES:'meshopt_decodeIndexSequence'};function isMeshoptSupported(){return isWebAssemblySupported;}async function meshoptDecodeGltfBuffer(target,count,size,source,mode){var filter=arguments.length>5&&arguments[5]!==undefined?arguments[5]:'NONE';var instance=await loadWasmInstance();decode$5(instance,instance.exports[DECODERS[mode]],target,count,size,source,instance.exports[FILTERS[filter||'NONE']]);}var wasmPromise;async function loadWasmInstance(){if(!wasmPromise){wasmPromise=loadWasmModule();}return wasmPromise;}async function loadWasmModule(){var wasm=wasm_base;if(WebAssembly.validate(detector)){wasm=wasm_simd;console.log('Warning: meshopt_decoder is using experimental SIMD support');}var result=await WebAssembly.instantiate(unpack(wasm),{});await result.instance.exports.__wasm_call_ctors();return result.instance;}function unpack(data){var result=new Uint8Array(data.length);for(var _i50=0;_i50<data.length;++_i50){var ch=data.charCodeAt(_i50);result[_i50]=ch>96?ch-71:ch>64?ch-65:ch>47?ch+4:ch>46?63:62;}var write=0;for(var _i51=0;_i51<data.length;++_i51){result[write++]=result[_i51]<60?wasmpack[result[_i51]]:(result[_i51]-60)*64+result[++_i51];}return result.buffer.slice(0,write);}function decode$5(instance,fun,target,count,size,source,filter){var sbrk=instance.exports.sbrk;var count4=count+3&~3;var tp=sbrk(count4*size);var sp=sbrk(source.length);var heap=new Uint8Array(instance.exports.memory.buffer);heap.set(source,sp);var res=fun(tp,count,size,sp,source.length);if(res===0&&filter){filter(tp,count4,size);}target.set(heap.subarray(tp,tp+count*size));sbrk(tp-sbrk(0));if(res!==0){throw new Error("Malformed buffer data: ".concat(res));}}var EXT_MESHOPT_COMPRESSION='EXT_meshopt_compression';var name$6=EXT_MESHOPT_COMPRESSION;function preprocess$4(gltfData){var scenegraph=new GLTFScenegraph(gltfData);if(scenegraph.getRequiredExtensions().includes(EXT_MESHOPT_COMPRESSION)&&!isMeshoptSupported()){throw new Error("gltf: Required extension ".concat(EXT_MESHOPT_COMPRESSION," not supported by browser"));}}async function decode$4(gltfData,options){var _options$gltf;var scenegraph=new GLTFScenegraph(gltfData);if(!(options!==null&&options!==void 0&&(_options$gltf=options.gltf)!==null&&_options$gltf!==void 0&&_options$gltf.decompressMeshes)){return;}var promises=[];for(var bufferViewIndex of gltfData.json.bufferViews||[]){promises.push(decodeMeshoptBufferView(scenegraph,bufferViewIndex));}await Promise.all(promises);scenegraph.removeExtension(EXT_MESHOPT_COMPRESSION);}async function decodeMeshoptBufferView(scenegraph,bufferView){var meshoptExtension=scenegraph.getObjectExtension(bufferView,EXT_MESHOPT_COMPRESSION);if(meshoptExtension){var buffer=bufferView.buffer;var{byteOffset=0,byteLength=0,byteStride,count,mode,filter='NONE'}=meshoptExtension;var source=new Uint8Array(buffer,byteOffset,byteLength);var result=new ArrayBuffer(count*byteStride);await meshoptDecodeGltfBuffer(new Uint8Array(result),count,byteStride,source,mode,filter);return result;}return null;}var EXT_meshopt_compression=/*#__PURE__*/Object.freeze({__proto__:null,name:name$6,preprocess:preprocess$4,decode:decode$4});var EXT_TEXTURE_WEBP='EXT_texture_webp';var name$5=EXT_TEXTURE_WEBP;function preprocess$3(gltfData,options){var scenegraph=new GLTFScenegraph(gltfData);if(!_isImageFormatSupported('image/webp')){if(scenegraph.getRequiredExtensions().includes(EXT_TEXTURE_WEBP)){throw new Error("gltf: Required extension ".concat(EXT_TEXTURE_WEBP," not supported by browser"));}return;}var{json}=scenegraph;for(var texture of json.textures||[]){var extension=scenegraph.getObjectExtension(texture,EXT_TEXTURE_WEBP);if(extension){texture.source=extension.source;}scenegraph.removeObjectExtension(texture,EXT_TEXTURE_WEBP);}scenegraph.removeExtension(EXT_TEXTURE_WEBP);}var EXT_texture_webp=/*#__PURE__*/Object.freeze({__proto__:null,name:name$5,preprocess:preprocess$3});var KHR_TEXTURE_BASISU='KHR_texture_basisu';var name$4=KHR_TEXTURE_BASISU;function preprocess$2(gltfData,options){var scene=new GLTFScenegraph(gltfData);var{json}=scene;for(var texture of json.textures||[]){var extension=scene.getObjectExtension(texture,KHR_TEXTURE_BASISU);if(extension){texture.source=extension.source;}scene.removeObjectExtension(texture,KHR_TEXTURE_BASISU);}scene.removeExtension(KHR_TEXTURE_BASISU);}var KHR_texture_basisu=/*#__PURE__*/Object.freeze({__proto__:null,name:name$4,preprocess:preprocess$2});function getGLTFAccessors(attributes){var accessors={};for(var _name5 in attributes){var attribute=attributes[_name5];if(_name5!=='indices'){var glTFAccessor=getGLTFAccessor(attribute);accessors[_name5]=glTFAccessor;}}return accessors;}function getGLTFAccessor(attribute){var{buffer,size,count}=getAccessorData(attribute);var glTFAccessor={value:buffer,size,byteOffset:0,count,type:getAccessorTypeFromSize(size),componentType:getComponentTypeFromArray(buffer)};return glTFAccessor;}function getAccessorData(attribute){var buffer=attribute;var size=1;var count=0;if(attribute&&attribute.value){buffer=attribute.value;size=attribute.size||1;}if(buffer){if(!ArrayBuffer.isView(buffer)){buffer=toTypedArray(buffer,Float32Array);}count=buffer.length/size;}return {buffer,size,count};}function toTypedArray(array,ArrayType){var convertTypedArrays=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;if(!array){return null;}if(Array.isArray(array)){return new ArrayType(array);}if(convertTypedArrays&&!(array instanceof ArrayType)){return new ArrayType(array);}return array;}var KHR_DRACO_MESH_COMPRESSION='KHR_draco_mesh_compression';var name$3=KHR_DRACO_MESH_COMPRESSION;function preprocess$1(gltfData,options,context){var scenegraph=new GLTFScenegraph(gltfData);for(var primitive of makeMeshPrimitiveIterator(scenegraph)){if(scenegraph.getObjectExtension(primitive,KHR_DRACO_MESH_COMPRESSION));}}async function decode$3(gltfData,options,context){var _options$gltf;if(!(options!==null&&options!==void 0&&(_options$gltf=options.gltf)!==null&&_options$gltf!==void 0&&_options$gltf.decompressMeshes)){return;}var scenegraph=new GLTFScenegraph(gltfData);var promises=[];for(var primitive of makeMeshPrimitiveIterator(scenegraph)){if(scenegraph.getObjectExtension(primitive,KHR_DRACO_MESH_COMPRESSION)){promises.push(decompressPrimitive(scenegraph,primitive,options,context));}}await Promise.all(promises);scenegraph.removeExtension(KHR_DRACO_MESH_COMPRESSION);}function encode$3(gltfData){var options=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var scenegraph=new GLTFScenegraph(gltfData);for(var mesh of scenegraph.json.meshes||[]){compressMesh(mesh);scenegraph.addRequiredExtension(KHR_DRACO_MESH_COMPRESSION);}}async function decompressPrimitive(scenegraph,primitive,options,context){var dracoExtension=scenegraph.getObjectExtension(primitive,KHR_DRACO_MESH_COMPRESSION);if(!dracoExtension){return;}var buffer=scenegraph.getTypedArrayForBufferView(dracoExtension.bufferView);var bufferCopy=sliceArrayBuffer(buffer.buffer,buffer.byteOffset);var{parse}=context;var dracoOptions=_objectSpread2({},options);delete dracoOptions['3d-tiles'];var decodedData=await parse(bufferCopy,DracoLoader,dracoOptions,context);var decodedAttributes=getGLTFAccessors(decodedData.attributes);for(var[attributeName,decodedAttribute]of Object.entries(decodedAttributes)){if(attributeName in primitive.attributes){var accessorIndex=primitive.attributes[attributeName];var accessor=scenegraph.getAccessor(accessorIndex);if(accessor!==null&&accessor!==void 0&&accessor.min&&accessor!==null&&accessor!==void 0&&accessor.max){decodedAttribute.min=accessor.min;decodedAttribute.max=accessor.max;}}}primitive.attributes=decodedAttributes;if(decodedData.indices){primitive.indices=getGLTFAccessor(decodedData.indices);}checkPrimitive(primitive);}function compressMesh(attributes,indices){var mode=arguments.length>2&&arguments[2]!==undefined?arguments[2]:4;var options=arguments.length>3?arguments[3]:undefined;var context=arguments.length>4?arguments[4]:undefined;var _context$parseSync;if(!options.DracoWriter){throw new Error('options.gltf.DracoWriter not provided');}var compressedData=options.DracoWriter.encodeSync({attributes});var decodedData=context===null||context===void 0?void 0:(_context$parseSync=context.parseSync)===null||_context$parseSync===void 0?void 0:_context$parseSync.call(context,{attributes});var fauxAccessors=options._addFauxAttributes(decodedData.attributes);var bufferViewIndex=options.addBufferView(compressedData);var glTFMesh={primitives:[{attributes:fauxAccessors,mode,extensions:{[KHR_DRACO_MESH_COMPRESSION]:{bufferView:bufferViewIndex,attributes:fauxAccessors}}}]};return glTFMesh;}function checkPrimitive(primitive){if(!primitive.attributes&&Object.keys(primitive.attributes).length>0){throw new Error('glTF: Empty primitive detected: Draco decompression failure?');}}function*makeMeshPrimitiveIterator(scenegraph){for(var mesh of scenegraph.json.meshes||[]){for(var primitive of mesh.primitives){yield primitive;}}}var KHR_draco_mesh_compression=/*#__PURE__*/Object.freeze({__proto__:null,name:name$3,preprocess:preprocess$1,decode:decode$3,encode:encode$3});var KHR_LIGHTS_PUNCTUAL='KHR_lights_punctual';var name$2=KHR_LIGHTS_PUNCTUAL;async function decode$2(gltfData){var gltfScenegraph=new GLTFScenegraph(gltfData);var{json}=gltfScenegraph;var extension=gltfScenegraph.getExtension(KHR_LIGHTS_PUNCTUAL);if(extension){gltfScenegraph.json.lights=extension.lights;gltfScenegraph.removeExtension(KHR_LIGHTS_PUNCTUAL);}for(var _node of json.nodes||[]){var nodeExtension=gltfScenegraph.getObjectExtension(_node,KHR_LIGHTS_PUNCTUAL);if(nodeExtension){_node.light=nodeExtension.light;}gltfScenegraph.removeObjectExtension(_node,KHR_LIGHTS_PUNCTUAL);}}async function encode$2(gltfData){var gltfScenegraph=new GLTFScenegraph(gltfData);var{json}=gltfScenegraph;if(json.lights){var extension=gltfScenegraph.addExtension(KHR_LIGHTS_PUNCTUAL);assert$1(!extension.lights);extension.lights=json.lights;delete json.lights;}if(gltfScenegraph.json.lights){for(var light of gltfScenegraph.json.lights){var _node2=light.node;gltfScenegraph.addObjectExtension(_node2,KHR_LIGHTS_PUNCTUAL,light);}delete gltfScenegraph.json.lights;}}var KHR_lights_punctual=/*#__PURE__*/Object.freeze({__proto__:null,name:name$2,decode:decode$2,encode:encode$2});var KHR_MATERIALS_UNLIT='KHR_materials_unlit';var name$1=KHR_MATERIALS_UNLIT;async function decode$1(gltfData){var gltfScenegraph=new GLTFScenegraph(gltfData);var{json}=gltfScenegraph;gltfScenegraph.removeExtension(KHR_MATERIALS_UNLIT);for(var material of json.materials||[]){var extension=material.extensions&&material.extensions.KHR_materials_unlit;if(extension){material.unlit=true;}gltfScenegraph.removeObjectExtension(material,KHR_MATERIALS_UNLIT);}}function encode$1(gltfData){var gltfScenegraph=new GLTFScenegraph(gltfData);var{json}=gltfScenegraph;if(gltfScenegraph.materials){for(var material of json.materials||[]){if(material.unlit){delete material.unlit;gltfScenegraph.addObjectExtension(material,KHR_MATERIALS_UNLIT,{});gltfScenegraph.addExtension(KHR_MATERIALS_UNLIT);}}}}var KHR_materials_unlit=/*#__PURE__*/Object.freeze({__proto__:null,name:name$1,decode:decode$1,encode:encode$1});var KHR_TECHNIQUES_WEBGL='KHR_techniques_webgl';var name$7=KHR_TECHNIQUES_WEBGL;async function decode(gltfData){var gltfScenegraph=new GLTFScenegraph(gltfData);var{json}=gltfScenegraph;var extension=gltfScenegraph.getExtension(KHR_TECHNIQUES_WEBGL);if(extension){var techniques=resolveTechniques(extension,gltfScenegraph);for(var material of json.materials||[]){var materialExtension=gltfScenegraph.getObjectExtension(material,KHR_TECHNIQUES_WEBGL);if(materialExtension){material.technique=Object.assign({},materialExtension,techniques[materialExtension.technique]);material.technique.values=resolveValues(material.technique,gltfScenegraph);}gltfScenegraph.removeObjectExtension(material,KHR_TECHNIQUES_WEBGL);}gltfScenegraph.removeExtension(KHR_TECHNIQUES_WEBGL);}}async function encode(gltfData,options){}function resolveTechniques(techniquesExtension,gltfScenegraph){var{programs=[],shaders=[],techniques=[]}=techniquesExtension;var textDecoder=new TextDecoder();shaders.forEach(shader=>{if(Number.isFinite(shader.bufferView)){shader.code=textDecoder.decode(gltfScenegraph.getTypedArrayForBufferView(shader.bufferView));}else {throw new Error('KHR_techniques_webgl: no shader code');}});programs.forEach(program=>{program.fragmentShader=shaders[program.fragmentShader];program.vertexShader=shaders[program.vertexShader];});techniques.forEach(technique=>{technique.program=programs[technique.program];});return techniques;}function resolveValues(technique,gltfScenegraph){var values=Object.assign({},technique.values);Object.keys(technique.uniforms||{}).forEach(uniform=>{if(technique.uniforms[uniform].value&&!(uniform in values)){values[uniform]=technique.uniforms[uniform].value;}});Object.keys(values).forEach(uniform=>{if(typeof values[uniform]==='object'&&values[uniform].index!==undefined){values[uniform].texture=gltfScenegraph.getTexture(values[uniform].index);}});return values;}var KHR_techniques_webgl=/*#__PURE__*/Object.freeze({__proto__:null,name:name$7,decode:decode,encode:encode});var EXTENSIONS$2=[EXT_meshopt_compression,EXT_texture_webp,KHR_texture_basisu,KHR_draco_mesh_compression,KHR_lights_punctual,KHR_materials_unlit,KHR_techniques_webgl];function preprocessExtensions(gltf){var options=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var context=arguments.length>2?arguments[2]:undefined;var extensions=EXTENSIONS$2.filter(extension=>useExtension(extension.name,options));for(var extension of extensions){var _extension$preprocess;(_extension$preprocess=extension.preprocess)===null||_extension$preprocess===void 0?void 0:_extension$preprocess.call(extension,gltf,options,context);}}async function decodeExtensions(gltf){var options=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var context=arguments.length>2?arguments[2]:undefined;var extensions=EXTENSIONS$2.filter(extension=>useExtension(extension.name,options));for(var extension of extensions){var _extension$decode;await((_extension$decode=extension.decode)===null||_extension$decode===void 0?void 0:_extension$decode.call(extension,gltf,options,context));}}function useExtension(extensionName,options){var _options$gltf;var excludes=(options===null||options===void 0?void 0:(_options$gltf=options.gltf)===null||_options$gltf===void 0?void 0:_options$gltf.excludeExtensions)||{};var exclude=extensionName in excludes&&!excludes[extensionName];return !exclude;}var KHR_BINARY_GLTF='KHR_binary_glTF';function preprocess(gltfData){var gltfScenegraph=new GLTFScenegraph(gltfData);var{json}=gltfScenegraph;for(var image of json.images||[]){var extension=gltfScenegraph.getObjectExtension(image,KHR_BINARY_GLTF);if(extension){Object.assign(image,extension);}gltfScenegraph.removeObjectExtension(image,KHR_BINARY_GLTF);}if(json.buffers&&json.buffers[0]){delete json.buffers[0].uri;}gltfScenegraph.removeExtension(KHR_BINARY_GLTF);}var GLTF_ARRAYS={accessors:'accessor',animations:'animation',buffers:'buffer',bufferViews:'bufferView',images:'image',materials:'material',meshes:'mesh',nodes:'node',samplers:'sampler',scenes:'scene',skins:'skin',textures:'texture'};var GLTF_KEYS={accessor:'accessors',animations:'animation',buffer:'buffers',bufferView:'bufferViews',image:'images',material:'materials',mesh:'meshes',node:'nodes',sampler:'samplers',scene:'scenes',skin:'skins',texture:'textures'};class GLTFV1Normalizer{constructor(){_defineProperty$1(this,"idToIndexMap",{animations:{},accessors:{},buffers:{},bufferViews:{},images:{},materials:{},meshes:{},nodes:{},samplers:{},scenes:{},skins:{},textures:{}});_defineProperty$1(this,"json",void 0);}normalize(gltf,options){this.json=gltf.json;var json=gltf.json;switch(json.asset&&json.asset.version){case'2.0':return;case undefined:case'1.0':break;default:console.warn("glTF: Unknown version ".concat(json.asset.version));return;}if(!options.normalize){throw new Error('glTF v1 is not supported.');}console.warn('Converting glTF v1 to glTF v2 format. This is experimental and may fail.');this._addAsset(json);this._convertTopLevelObjectsToArrays(json);preprocess(gltf);this._convertObjectIdsToArrayIndices(json);this._updateObjects(json);this._updateMaterial(json);}_addAsset(json){json.asset=json.asset||{};json.asset.version='2.0';json.asset.generator=json.asset.generator||'Normalized to glTF 2.0 by loaders.gl';}_convertTopLevelObjectsToArrays(json){for(var arrayName in GLTF_ARRAYS){this._convertTopLevelObjectToArray(json,arrayName);}}_convertTopLevelObjectToArray(json,mapName){var objectMap=json[mapName];if(!objectMap||Array.isArray(objectMap)){return;}json[mapName]=[];for(var id in objectMap){var object=objectMap[id];object.id=object.id||id;var index=json[mapName].length;json[mapName].push(object);this.idToIndexMap[mapName][id]=index;}}_convertObjectIdsToArrayIndices(json){for(var arrayName in GLTF_ARRAYS){this._convertIdsToIndices(json,arrayName);}if('scene'in json){json.scene=this._convertIdToIndex(json.scene,'scene');}for(var texture of json.textures){this._convertTextureIds(texture);}for(var mesh of json.meshes){this._convertMeshIds(mesh);}for(var _node3 of json.nodes){this._convertNodeIds(_node3);}for(var _node4 of json.scenes){this._convertSceneIds(_node4);}}_convertTextureIds(texture){if(texture.source){texture.source=this._convertIdToIndex(texture.source,'image');}}_convertMeshIds(mesh){for(var primitive of mesh.primitives){var{attributes,indices,material}=primitive;for(var attributeName in attributes){attributes[attributeName]=this._convertIdToIndex(attributes[attributeName],'accessor');}if(indices){primitive.indices=this._convertIdToIndex(indices,'accessor');}if(material){primitive.material=this._convertIdToIndex(material,'material');}}}_convertNodeIds(node){if(node.children){node.children=node.children.map(child=>this._convertIdToIndex(child,'node'));}if(node.meshes){node.meshes=node.meshes.map(mesh=>this._convertIdToIndex(mesh,'mesh'));}}_convertSceneIds(scene){if(scene.nodes){scene.nodes=scene.nodes.map(node=>this._convertIdToIndex(node,'node'));}}_convertIdsToIndices(json,topLevelArrayName){if(!json[topLevelArrayName]){console.warn("gltf v1: json doesn't contain attribute ".concat(topLevelArrayName));json[topLevelArrayName]=[];}for(var object of json[topLevelArrayName]){for(var key in object){var id=object[key];var index=this._convertIdToIndex(id,key);object[key]=index;}}}_convertIdToIndex(id,key){var arrayName=GLTF_KEYS[key];if(arrayName in this.idToIndexMap){var index=this.idToIndexMap[arrayName][id];if(!Number.isFinite(index)){throw new Error("gltf v1: failed to resolve ".concat(key," with id ").concat(id));}return index;}return id;}_updateObjects(json){for(var buffer of this.json.buffers){delete buffer.type;}}_updateMaterial(json){var _loop3=function _loop3(){material.pbrMetallicRoughness={baseColorFactor:[1,1,1,1],metallicFactor:1,roughnessFactor:1};var textureId=material.values&&material.values.tex;var textureIndex=json.textures.findIndex(texture=>texture.id===textureId);if(textureIndex!==-1){material.pbrMetallicRoughness.baseColorTexture={index:textureIndex};}};for(var material of json.materials){_loop3();}}}function normalizeGLTFV1(gltf){var options=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};return new GLTFV1Normalizer().normalize(gltf,options);}var COMPONENTS={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16};var BYTES={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};var GL_SAMPLER={TEXTURE_MAG_FILTER:0x2800,TEXTURE_MIN_FILTER:0x2801,TEXTURE_WRAP_S:0x2802,TEXTURE_WRAP_T:0x2803,REPEAT:0x2901,LINEAR:0x2601,NEAREST_MIPMAP_LINEAR:0x2702};var SAMPLER_PARAMETER_GLTF_TO_GL={magFilter:GL_SAMPLER.TEXTURE_MAG_FILTER,minFilter:GL_SAMPLER.TEXTURE_MIN_FILTER,wrapS:GL_SAMPLER.TEXTURE_WRAP_S,wrapT:GL_SAMPLER.TEXTURE_WRAP_T};var DEFAULT_SAMPLER={[GL_SAMPLER.TEXTURE_MAG_FILTER]:GL_SAMPLER.LINEAR,[GL_SAMPLER.TEXTURE_MIN_FILTER]:GL_SAMPLER.NEAREST_MIPMAP_LINEAR,[GL_SAMPLER.TEXTURE_WRAP_S]:GL_SAMPLER.REPEAT,[GL_SAMPLER.TEXTURE_WRAP_T]:GL_SAMPLER.REPEAT};function getBytesFromComponentType(componentType){return BYTES[componentType];}function getSizeFromAccessorType(type){return COMPONENTS[type];}class GLTFPostProcessor{constructor(){_defineProperty$1(this,"baseUri",'');_defineProperty$1(this,"json",{});_defineProperty$1(this,"buffers",[]);_defineProperty$1(this,"images",[]);}postProcess(gltf){var options=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var{json,buffers=[],images=[],baseUri=''}=gltf;assert$1(json);this.baseUri=baseUri;this.json=json;this.buffers=buffers;this.images=images;this._resolveTree(this.json,options);return this.json;}_resolveTree(json){var options=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};if(json.bufferViews){json.bufferViews=json.bufferViews.map((bufView,i)=>this._resolveBufferView(bufView,i));}if(json.images){json.images=json.images.map((image,i)=>this._resolveImage(image,i));}if(json.samplers){json.samplers=json.samplers.map((sampler,i)=>this._resolveSampler(sampler,i));}if(json.textures){json.textures=json.textures.map((texture,i)=>this._resolveTexture(texture,i));}if(json.accessors){json.accessors=json.accessors.map((accessor,i)=>this._resolveAccessor(accessor,i));}if(json.materials){json.materials=json.materials.map((material,i)=>this._resolveMaterial(material,i));}if(json.meshes){json.meshes=json.meshes.map((mesh,i)=>this._resolveMesh(mesh,i));}if(json.nodes){json.nodes=json.nodes.map((node,i)=>this._resolveNode(node,i));}if(json.skins){json.skins=json.skins.map((skin,i)=>this._resolveSkin(skin,i));}if(json.scenes){json.scenes=json.scenes.map((scene,i)=>this._resolveScene(scene,i));}if(json.scene!==undefined){json.scene=json.scenes[this.json.scene];}}getScene(index){return this._get('scenes',index);}getNode(index){return this._get('nodes',index);}getSkin(index){return this._get('skins',index);}getMesh(index){return this._get('meshes',index);}getMaterial(index){return this._get('materials',index);}getAccessor(index){return this._get('accessors',index);}getCamera(index){return null;}getTexture(index){return this._get('textures',index);}getSampler(index){return this._get('samplers',index);}getImage(index){return this._get('images',index);}getBufferView(index){return this._get('bufferViews',index);}getBuffer(index){return this._get('buffers',index);}_get(array,index){if(typeof index==='object'){return index;}var object=this.json[array]&&this.json[array][index];if(!object){console.warn("glTF file error: Could not find ".concat(array,"[").concat(index,"]"));}return object;}_resolveScene(scene,index){scene.id=scene.id||"scene-".concat(index);scene.nodes=(scene.nodes||[]).map(node=>this.getNode(node));return scene;}_resolveNode(node,index){node.id=node.id||"node-".concat(index);if(node.children){node.children=node.children.map(child=>this.getNode(child));}if(node.mesh!==undefined){node.mesh=this.getMesh(node.mesh);}else if(node.meshes!==undefined&&node.meshes.length){node.mesh=node.meshes.reduce((accum,meshIndex)=>{var mesh=this.getMesh(meshIndex);accum.id=mesh.id;accum.primitives=accum.primitives.concat(mesh.primitives);return accum;},{primitives:[]});}if(node.camera!==undefined){node.camera=this.getCamera(node.camera);}if(node.skin!==undefined){node.skin=this.getSkin(node.skin);}return node;}_resolveSkin(skin,index){skin.id=skin.id||"skin-".concat(index);skin.inverseBindMatrices=this.getAccessor(skin.inverseBindMatrices);return skin;}_resolveMesh(mesh,index){mesh.id=mesh.id||"mesh-".concat(index);if(mesh.primitives){mesh.primitives=mesh.primitives.map(primitive=>{primitive=_objectSpread2({},primitive);var attributes=primitive.attributes;primitive.attributes={};for(var attribute in attributes){primitive.attributes[attribute]=this.getAccessor(attributes[attribute]);}if(primitive.indices!==undefined){primitive.indices=this.getAccessor(primitive.indices);}if(primitive.material!==undefined){primitive.material=this.getMaterial(primitive.material);}return primitive;});}return mesh;}_resolveMaterial(material,index){material.id=material.id||"material-".concat(index);if(material.normalTexture){material.normalTexture=_objectSpread2({},material.normalTexture);material.normalTexture.texture=this.getTexture(material.normalTexture.index);}if(material.occlusionTexture){material.occlustionTexture=_objectSpread2({},material.occlustionTexture);material.occlusionTexture.texture=this.getTexture(material.occlusionTexture.index);}if(material.emissiveTexture){material.emmisiveTexture=_objectSpread2({},material.emmisiveTexture);material.emissiveTexture.texture=this.getTexture(material.emissiveTexture.index);}if(!material.emissiveFactor){material.emissiveFactor=material.emmisiveTexture?[1,1,1]:[0,0,0];}if(material.pbrMetallicRoughness){material.pbrMetallicRoughness=_objectSpread2({},material.pbrMetallicRoughness);var mr=material.pbrMetallicRoughness;if(mr.baseColorTexture){mr.baseColorTexture=_objectSpread2({},mr.baseColorTexture);mr.baseColorTexture.texture=this.getTexture(mr.baseColorTexture.index);}if(mr.metallicRoughnessTexture){mr.metallicRoughnessTexture=_objectSpread2({},mr.metallicRoughnessTexture);mr.metallicRoughnessTexture.texture=this.getTexture(mr.metallicRoughnessTexture.index);}}return material;}_resolveAccessor(accessor,index){accessor.id=accessor.id||"accessor-".concat(index);if(accessor.bufferView!==undefined){accessor.bufferView=this.getBufferView(accessor.bufferView);}accessor.bytesPerComponent=getBytesFromComponentType(accessor.componentType);accessor.components=getSizeFromAccessorType(accessor.type);accessor.bytesPerElement=accessor.bytesPerComponent*accessor.components;if(accessor.bufferView){var buffer=accessor.bufferView.buffer;var{ArrayType,byteLength}=getAccessorArrayTypeAndLength(accessor,accessor.bufferView);var byteOffset=(accessor.bufferView.byteOffset||0)+(accessor.byteOffset||0)+buffer.byteOffset;var cutBuffer=buffer.arrayBuffer.slice(byteOffset,byteOffset+byteLength);if(accessor.bufferView.byteStride){cutBuffer=this._getValueFromInterleavedBuffer(buffer,byteOffset,accessor.bufferView.byteStride,accessor.bytesPerElement,accessor.count);}accessor.value=new ArrayType(cutBuffer);}return accessor;}_getValueFromInterleavedBuffer(buffer,byteOffset,byteStride,bytesPerElement,count){var result=new Uint8Array(count*bytesPerElement);for(var _i52=0;_i52<count;_i52++){var elementOffset=byteOffset+_i52*byteStride;result.set(new Uint8Array(buffer.arrayBuffer.slice(elementOffset,elementOffset+bytesPerElement)),_i52*bytesPerElement);}return result.buffer;}_resolveTexture(texture,index){texture.id=texture.id||"texture-".concat(index);texture.sampler='sampler'in texture?this.getSampler(texture.sampler):DEFAULT_SAMPLER;texture.source=this.getImage(texture.source);return texture;}_resolveSampler(sampler,index){sampler.id=sampler.id||"sampler-".concat(index);sampler.parameters={};for(var key in sampler){var glEnum=this._enumSamplerParameter(key);if(glEnum!==undefined){sampler.parameters[glEnum]=sampler[key];}}return sampler;}_enumSamplerParameter(key){return SAMPLER_PARAMETER_GLTF_TO_GL[key];}_resolveImage(image,index){image.id=image.id||"image-".concat(index);if(image.bufferView!==undefined){image.bufferView=this.getBufferView(image.bufferView);}var preloadedImage=this.images[index];if(preloadedImage){image.image=preloadedImage;}return image;}_resolveBufferView(bufferView,index){var bufferIndex=bufferView.buffer;var result=_objectSpread2(_objectSpread2({id:"bufferView-".concat(index)},bufferView),{},{buffer:this.buffers[bufferIndex]});var arrayBuffer=this.buffers[bufferIndex].arrayBuffer;var byteOffset=this.buffers[bufferIndex].byteOffset||0;if('byteOffset'in bufferView){byteOffset+=bufferView.byteOffset;}result.data=new Uint8Array(arrayBuffer,byteOffset,bufferView.byteLength);return result;}_resolveCamera(camera,index){camera.id=camera.id||"camera-".concat(index);if(camera.perspective);if(camera.orthographic);return camera;}}function postProcessGLTF(gltf,options){return new GLTFPostProcessor().postProcess(gltf,options);}var MAGIC_glTF=0x676c5446;var GLB_FILE_HEADER_SIZE=12;var GLB_CHUNK_HEADER_SIZE=8;var GLB_CHUNK_TYPE_JSON=0x4e4f534a;var GLB_CHUNK_TYPE_BIN=0x004e4942;var GLB_CHUNK_TYPE_JSON_XVIZ_DEPRECATED=0;var GLB_CHUNK_TYPE_BIX_XVIZ_DEPRECATED=1;var GLB_V1_CONTENT_FORMAT_JSON=0x0;var LE=true;function getMagicString(dataView){var byteOffset=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;return "".concat(String.fromCharCode(dataView.getUint8(byteOffset+0))).concat(String.fromCharCode(dataView.getUint8(byteOffset+1))).concat(String.fromCharCode(dataView.getUint8(byteOffset+2))).concat(String.fromCharCode(dataView.getUint8(byteOffset+3)));}function isGLB(arrayBuffer){var byteOffset=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var options=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};var dataView=new DataView(arrayBuffer);var{magic=MAGIC_glTF}=options;var magic1=dataView.getUint32(byteOffset,false);return magic1===magic||magic1===MAGIC_glTF;}function parseGLBSync(glb,arrayBuffer){var byteOffset=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0;var options=arguments.length>3&&arguments[3]!==undefined?arguments[3]:{};var dataView=new DataView(arrayBuffer);var type=getMagicString(dataView,byteOffset+0);var version=dataView.getUint32(byteOffset+4,LE);var byteLength=dataView.getUint32(byteOffset+8,LE);Object.assign(glb,{header:{byteOffset,byteLength,hasBinChunk:false},type,version,json:{},binChunks:[]});byteOffset+=GLB_FILE_HEADER_SIZE;switch(glb.version){case 1:return parseGLBV1(glb,dataView,byteOffset);case 2:return parseGLBV2(glb,dataView,byteOffset,options={});default:throw new Error("Invalid GLB version ".concat(glb.version,". Only supports v1 and v2."));}}function parseGLBV1(glb,dataView,byteOffset){assert$7(glb.header.byteLength>GLB_FILE_HEADER_SIZE+GLB_CHUNK_HEADER_SIZE);var contentLength=dataView.getUint32(byteOffset+0,LE);var contentFormat=dataView.getUint32(byteOffset+4,LE);byteOffset+=GLB_CHUNK_HEADER_SIZE;assert$7(contentFormat===GLB_V1_CONTENT_FORMAT_JSON);parseJSONChunk(glb,dataView,byteOffset,contentLength);byteOffset+=contentLength;byteOffset+=parseBINChunk(glb,dataView,byteOffset,glb.header.byteLength);return byteOffset;}function parseGLBV2(glb,dataView,byteOffset,options){assert$7(glb.header.byteLength>GLB_FILE_HEADER_SIZE+GLB_CHUNK_HEADER_SIZE);parseGLBChunksSync(glb,dataView,byteOffset,options);return byteOffset+glb.header.byteLength;}function parseGLBChunksSync(glb,dataView,byteOffset,options){while(byteOffset+8<=glb.header.byteLength){var chunkLength=dataView.getUint32(byteOffset+0,LE);var chunkFormat=dataView.getUint32(byteOffset+4,LE);byteOffset+=GLB_CHUNK_HEADER_SIZE;switch(chunkFormat){case GLB_CHUNK_TYPE_JSON:parseJSONChunk(glb,dataView,byteOffset,chunkLength);break;case GLB_CHUNK_TYPE_BIN:parseBINChunk(glb,dataView,byteOffset,chunkLength);break;case GLB_CHUNK_TYPE_JSON_XVIZ_DEPRECATED:if(!options.strict){parseJSONChunk(glb,dataView,byteOffset,chunkLength);}break;case GLB_CHUNK_TYPE_BIX_XVIZ_DEPRECATED:if(!options.strict){parseBINChunk(glb,dataView,byteOffset,chunkLength);}break;}byteOffset+=padToNBytes(chunkLength,4);}return byteOffset;}function parseJSONChunk(glb,dataView,byteOffset,chunkLength){var jsonChunk=new Uint8Array(dataView.buffer,byteOffset,chunkLength);var textDecoder=new TextDecoder('utf8');var jsonText=textDecoder.decode(jsonChunk);glb.json=JSON.parse(jsonText);return padToNBytes(chunkLength,4);}function parseBINChunk(glb,dataView,byteOffset,chunkLength){glb.header.hasBinChunk=true;glb.binChunks.push({byteOffset,byteLength:chunkLength,arrayBuffer:dataView.buffer});return padToNBytes(chunkLength,4);}async function parseGLTF(gltf,arrayBufferOrString){var byteOffset=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0;var options=arguments.length>3?arguments[3]:undefined;var context=arguments.length>4?arguments[4]:undefined;var _options$gltf,_options$gltf2,_options$gltf3,_options$gltf4;parseGLTFContainerSync(gltf,arrayBufferOrString,byteOffset,options);normalizeGLTFV1(gltf,{normalize:options===null||options===void 0?void 0:(_options$gltf=options.gltf)===null||_options$gltf===void 0?void 0:_options$gltf.normalize});preprocessExtensions(gltf,options,context);var promises=[];if(options!==null&&options!==void 0&&(_options$gltf2=options.gltf)!==null&&_options$gltf2!==void 0&&_options$gltf2.loadBuffers&&gltf.json.buffers){await loadBuffers(gltf,options,context);}if(options!==null&&options!==void 0&&(_options$gltf3=options.gltf)!==null&&_options$gltf3!==void 0&&_options$gltf3.loadImages){var _promise=loadImages(gltf,options,context);promises.push(_promise);}var promise=decodeExtensions(gltf,options,context);promises.push(promise);await Promise.all(promises);gltf.json.gltfArrayBuffer=arrayBufferOrString;// !zeg add 兼容gltf
  59556. return options!==null&&options!==void 0&&(_options$gltf4=options.gltf)!==null&&_options$gltf4!==void 0&&_options$gltf4.postProcess?postProcessGLTF(gltf,options):gltf;}function parseGLTFContainerSync(gltf,data,byteOffset,options){if(options.uri){gltf.baseUri=options.uri;}if(data instanceof ArrayBuffer&&!isGLB(data,byteOffset,options)){var textDecoder=new TextDecoder();data=textDecoder.decode(data);}if(typeof data==='string'){gltf.json=parseJSON(data);}else if(data instanceof ArrayBuffer){var glb={};byteOffset=parseGLBSync(glb,data,byteOffset,options.glb);assert$1(glb.type==='glTF',"Invalid GLB magic string ".concat(glb.type));gltf._glb=glb;gltf.json=glb.json;}else {assert$1(false,'GLTF: must be ArrayBuffer or string');}var buffers=gltf.json.buffers||[];gltf.buffers=new Array(buffers.length).fill(null);if(gltf._glb&&gltf._glb.header.hasBinChunk){var{binChunks}=gltf._glb;gltf.buffers[0]={arrayBuffer:binChunks[0].arrayBuffer,byteOffset:binChunks[0].byteOffset,byteLength:binChunks[0].byteLength};}var images=gltf.json.images||[];gltf.images=new Array(images.length).fill({});}async function loadBuffers(gltf,options,context){var buffers=gltf.json.buffers||[];for(var _i53=0;_i53<buffers.length;++_i53){var buffer=buffers[_i53];if(buffer.uri){var _context$fetch,_response$arrayBuffer;var{fetch:_fetch}=context;assert$1(_fetch);var uri=resolveUrl(buffer.uri,options);var response=await(context===null||context===void 0?void 0:(_context$fetch=context.fetch)===null||_context$fetch===void 0?void 0:_context$fetch.call(context,uri));var arrayBuffer=await(response===null||response===void 0?void 0:(_response$arrayBuffer=response.arrayBuffer)===null||_response$arrayBuffer===void 0?void 0:_response$arrayBuffer.call(response));gltf.buffers[_i53]={arrayBuffer,byteOffset:0,byteLength:arrayBuffer.byteLength};delete buffer.uri;}}}async function loadImages(gltf,options,context){var imageIndices=getReferencesImageIndices(gltf);var images=gltf.json.images||[];var promises=[];for(var imageIndex of imageIndices){promises.push(loadImage(gltf,images[imageIndex],imageIndex,options,context));}return await Promise.all(promises);}function getReferencesImageIndices(gltf){var imageIndices=new Set();var textures=gltf.json.textures||[];for(var texture of textures){if(texture.source!==undefined){imageIndices.add(texture.source);}}return Array.from(imageIndices).sort();}async function loadImage(gltf,image,index,options,context){var{fetch,parse}=context;var arrayBuffer;if(image.uri){var uri=resolveUrl(image.uri,options);var response=await fetch(uri);arrayBuffer=await response.arrayBuffer();}if(Number.isFinite(image.bufferView)){var array=getTypedArrayForBufferView(gltf.json,gltf.buffers,image.bufferView);arrayBuffer=sliceArrayBuffer(array.buffer,array.byteOffset,array.byteLength);}assert$1(arrayBuffer,'glTF image has no data');var parsedImage=await parse(arrayBuffer,[ImageLoader$1,BasisLoader],{mimeType:image.mimeType,basis:options.basis||{format:selectSupportedBasisFormat()}},context);if(parsedImage&&parsedImage[0]){parsedImage={compressed:true,mipmaps:false,width:parsedImage[0].width,height:parsedImage[0].height,data:parsedImage};}gltf.images=gltf.images||[];gltf.images[index]=parsedImage;}var GLTFLoader$1={name:'glTF',id:'gltf',module:'gltf',version:VERSION$3,extensions:['gltf','glb'],mimeTypes:['model/gltf+json','model/gltf-binary'],text:true,binary:true,tests:['glTF'],parse:parse$1,options:{gltf:{normalize:true,loadBuffers:true,loadImages:true,decompressMeshes:true,postProcess:true},log:console},deprecatedOptions:{fetchImages:'gltf.loadImages',createImages:'gltf.loadImages',decompress:'gltf.decompressMeshes',postProcess:'gltf.postProcess',gltf:{decompress:'gltf.decompressMeshes'}}};async function parse$1(arrayBuffer){var options=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var context=arguments.length>2?arguments[2]:undefined;options=_objectSpread2(_objectSpread2({},GLTFLoader$1.options),options);options.gltf=_objectSpread2(_objectSpread2({},GLTFLoader$1.options.gltf),options.gltf);var{byteOffset=0}=options;var gltf={};return await parseGLTF(gltf,arrayBuffer,byteOffset,options,context);}var GLTF_FORMAT={URI:0,EMBEDDED:1};function parse3DTileGLTFViewSync(tile,arrayBuffer,byteOffset,options){tile.rotateYtoZ=true;var gltfByteLength=tile.byteOffset+tile.byteLength-byteOffset;if(gltfByteLength===0){throw new Error('glTF byte length must be greater than 0.');}tile.gltfUpAxis=options['3d-tiles']&&options['3d-tiles'].assetGltfUpAxis?options['3d-tiles'].assetGltfUpAxis:'Y';tile.gltfArrayBuffer=sliceArrayBuffer(arrayBuffer,byteOffset,gltfByteLength);tile.gltfByteOffset=0;tile.gltfByteLength=gltfByteLength;if(byteOffset%4===0);else {console.warn("".concat(tile.type,": embedded glb is not aligned to a 4-byte boundary."));}return tile.byteOffset+tile.byteLength;}async function extractGLTF(tile,gltfFormat,options,context){var tile3DOptions=options['3d-tiles']||{};extractGLTFBufferOrURL(tile,gltfFormat);if(tile3DOptions.loadGLTF){var{parse:_parse,fetch:_fetch2}=context;if(tile.gltfUrl){tile.gltfArrayBuffer=await _fetch2(tile.gltfUrl,options);tile.gltfByteOffset=0;}if(tile.gltfArrayBuffer){tile.gltf=await _parse(tile.gltfArrayBuffer,GLTFLoader$1,options,context);delete tile.gltfArrayBuffer;delete tile.gltfByteOffset;delete tile.gltfByteLength;}}}function extractGLTFBufferOrURL(tile,gltfFormat,options){switch(gltfFormat){case GLTF_FORMAT.URI:var gltfUrlBytes=new Uint8Array(tile.gltfArrayBuffer,tile.gltfByteOffset);var textDecoder=new TextDecoder();var gltfUrl=textDecoder.decode(gltfUrlBytes);tile.gltfUrl=gltfUrl.replace(/[\s\0]+$/,'');delete tile.gltfArrayBuffer;delete tile.gltfByteOffset;delete tile.gltfByteLength;break;case GLTF_FORMAT.EMBEDDED:break;default:throw new Error('b3dm: Illegal glTF format field');}}async function parseBatchedModel3DTile(tile,arrayBuffer,byteOffset,options,context){var _tile$gltf;byteOffset=parseBatchedModel(tile,arrayBuffer,byteOffset,options);await extractGLTF(tile,GLTF_FORMAT.EMBEDDED,options,context);var extensions=tile===null||tile===void 0?void 0:(_tile$gltf=tile.gltf)===null||_tile$gltf===void 0?void 0:_tile$gltf.extensions;if(extensions&&extensions.CESIUM_RTC){tile.rtcCenter=extensions.CESIUM_RTC.center;}return byteOffset;}function parseBatchedModel(tile,arrayBuffer,byteOffset,options,context){byteOffset=parse3DTileHeaderSync(tile,arrayBuffer,byteOffset);byteOffset=parse3DTileTablesHeaderSync(tile,arrayBuffer,byteOffset);byteOffset=parse3DTileTablesSync(tile,arrayBuffer,byteOffset);byteOffset=parse3DTileGLTFViewSync(tile,arrayBuffer,byteOffset,options);var featureTable=new Tile3DFeatureTable(tile.featureTableJson,tile.featureTableBinary);tile.rtcCenter=featureTable.getGlobalProperty('RTC_CENTER',GL$1.FLOAT,3);return byteOffset;}async function parseInstancedModel3DTile(tile,arrayBuffer,byteOffset,options,context){byteOffset=parseInstancedModel(tile,arrayBuffer,byteOffset,options);await extractGLTF(tile,tile.gltfFormat,options,context);return byteOffset;}function parseInstancedModel(tile,arrayBuffer,byteOffset,options,context){byteOffset=parse3DTileHeaderSync(tile,arrayBuffer,byteOffset);if(tile.version!==1){throw new Error("Instanced 3D Model version ".concat(tile.version," is not supported"));}byteOffset=parse3DTileTablesHeaderSync(tile,arrayBuffer,byteOffset);var view=new DataView(arrayBuffer);tile.gltfFormat=view.getUint32(byteOffset,true);byteOffset+=4;byteOffset=parse3DTileTablesSync(tile,arrayBuffer,byteOffset);byteOffset=parse3DTileGLTFViewSync(tile,arrayBuffer,byteOffset,options);if(tile.featureTableJsonByteLength===0){throw new Error('i3dm parser: featureTableJsonByteLength is zero.');}var featureTable=new Tile3DFeatureTable(tile.featureTableJson,tile.featureTableBinary);var instancesLength=featureTable.getGlobalProperty('INSTANCES_LENGTH');featureTable.featuresLength=instancesLength;if(!Number.isFinite(instancesLength)){throw new Error('i3dm parser: INSTANCES_LENGTH must be defined');}tile.eastNorthUp=featureTable.getGlobalProperty('EAST_NORTH_UP');tile.rtcCenter=featureTable.getGlobalProperty('RTC_CENTER',GL$1.FLOAT,3);var batchTable=new Tile3DBatchTableParser(tile.batchTableJson,tile.batchTableBinary,instancesLength);extractInstancedAttributes(tile,featureTable,batchTable,instancesLength);return byteOffset;}function extractInstancedAttributes(tile,featureTable,batchTable,instancesLength){var collectionOptions={instances:new Array(instancesLength),batchTable:tile._batchTable,cull:false,url:undefined,gltf:undefined,basePath:undefined,incrementallyLoadTextures:false,forwardAxis:[1,0,0]};var instances=collectionOptions.instances;var instancePosition=new Vector3$1();new Vector3$1();new Vector3$1();new Vector3$1();var instanceRotation=new Matrix3$1();var instanceQuaternion=new Quaternion$1();var instanceScale=new Vector3$1();var instanceTranslationRotationScale={};var instanceTransform=new Matrix4$1();var scratch1=[];var scratch2=[];var scratchVector1=new Vector3$1();var scratchVector2=new Vector3$1();for(var _i54=0;_i54<instancesLength;_i54++){var position=void 0;if(featureTable.hasProperty('POSITION')){position=featureTable.getProperty('POSITION',GL$1.FLOAT,3,_i54,instancePosition);}else if(featureTable.hasProperty('POSITION_QUANTIZED')){position=featureTable.getProperty('POSITION_QUANTIZED',GL$1.UNSIGNED_SHORT,3,_i54,instancePosition);var quantizedVolumeOffset=featureTable.getGlobalProperty('QUANTIZED_VOLUME_OFFSET',GL$1.FLOAT,3,scratchVector1);if(!quantizedVolumeOffset){throw new Error('i3dm parser: QUANTIZED_VOLUME_OFFSET must be defined for quantized positions.');}var quantizedVolumeScale=featureTable.getGlobalProperty('QUANTIZED_VOLUME_SCALE',GL$1.FLOAT,3,scratchVector2);if(!quantizedVolumeScale){throw new Error('i3dm parser: QUANTIZED_VOLUME_SCALE must be defined for quantized positions.');}var MAX_UNSIGNED_SHORT=65535.0;for(var j=0;j<3;j++){position[j]=position[j]/MAX_UNSIGNED_SHORT*quantizedVolumeScale[j]+quantizedVolumeOffset[j];}}if(!position){throw new Error('i3dm: POSITION or POSITION_QUANTIZED must be defined for each instance.');}instancePosition.copy(position);instanceTranslationRotationScale.translation=instancePosition;tile.normalUp=featureTable.getProperty('NORMAL_UP',GL$1.FLOAT,3,_i54,scratch1);tile.normalRight=featureTable.getProperty('NORMAL_RIGHT',GL$1.FLOAT,3,_i54,scratch2);if(tile.normalUp){if(!tile.normalRight){throw new Error('i3dm: Custom orientation requires both NORMAL_UP and NORMAL_RIGHT.');}tile.hasCustomOrientation=true;}else {tile.octNormalUp=featureTable.getProperty('NORMAL_UP_OCT32P',GL$1.UNSIGNED_SHORT,2,scratch1);tile.octNormalRight=featureTable.getProperty('NORMAL_RIGHT_OCT32P',GL$1.UNSIGNED_SHORT,2,scratch2);if(tile.octNormalUp){if(!tile.octNormalRight){throw new Error('i3dm: oct-encoded orientation requires NORMAL_UP_OCT32P and NORMAL_RIGHT_OCT32P');}throw new Error('i3dm: oct-encoded orientation not implemented');}else if(tile.eastNorthUp){Ellipsoid.WGS84.eastNorthUpToFixedFrame(instancePosition,instanceTransform);instanceTransform.getRotationMatrix3(instanceRotation);}else {instanceRotation.identity();}}instanceQuaternion.fromMatrix3(instanceRotation);instanceTranslationRotationScale.rotation=instanceQuaternion;instanceScale.set(1.0,1.0,1.0);var _scale=featureTable.getProperty('SCALE',GL$1.FLOAT,1,_i54);if(Number.isFinite(_scale)){instanceScale.multiplyByScalar(_scale);}var nonUniformScale=featureTable.getProperty('SCALE_NON_UNIFORM',GL$1.FLOAT,3,_i54,scratch1);if(nonUniformScale){instanceScale.scale(nonUniformScale);}instanceTranslationRotationScale.scale=instanceScale;var batchId=featureTable.getProperty('BATCH_ID',GL$1.UNSIGNED_SHORT,1,_i54);if(batchId===undefined){batchId=_i54;}var rotationMatrix=new Matrix4$1().fromQuaternion(instanceTranslationRotationScale.rotation);instanceTransform.identity();instanceTransform.translate(instanceTranslationRotationScale.translation);instanceTransform.multiplyRight(rotationMatrix);instanceTransform.scale(instanceTranslationRotationScale.scale);var modelMatrix=instanceTransform.clone();instances[_i54]={modelMatrix,batchId};}tile.instances=instances;}async function parseComposite3DTile(tile,arrayBuffer,byteOffset,options,context,parse3DTile){byteOffset=parse3DTileHeaderSync(tile,arrayBuffer,byteOffset);var view=new DataView(arrayBuffer);tile.tilesLength=view.getUint32(byteOffset,true);byteOffset+=4;tile.tiles=[];while(tile.tiles.length<tile.tilesLength&&tile.byteLength-byteOffset>12){var subtile={};tile.tiles.push(subtile);byteOffset=await parse3DTile(arrayBuffer,byteOffset,options,context,subtile);}return byteOffset;}async function parseGltf3DTile(tile,arrayBuffer,options,context){tile.rotateYtoZ=true;tile.gltfUpAxis=options['3d-tiles']&&options['3d-tiles'].assetGltfUpAxis?options['3d-tiles'].assetGltfUpAxis:'Y';var{parse}=context;tile.gltf=await parse(arrayBuffer,GLTFLoader$1,options,context);}async function parse3DTile(arrayBuffer){var byteOffset=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var options=arguments.length>2?arguments[2]:undefined;var context=arguments.length>3?arguments[3]:undefined;var tile=arguments.length>4&&arguments[4]!==undefined?arguments[4]:{};tile.byteOffset=byteOffset;tile.type=getMagicString$1(arrayBuffer,byteOffset);switch(tile.type){case TILE3D_TYPE.COMPOSITE:return await parseComposite3DTile(tile,arrayBuffer,byteOffset,options,context,parse3DTile);case TILE3D_TYPE.BATCHED_3D_MODEL:return await parseBatchedModel3DTile(tile,arrayBuffer,byteOffset,options,context);case TILE3D_TYPE.GLTF:return await parseGltf3DTile(tile,arrayBuffer,options,context);case TILE3D_TYPE.INSTANCED_3D_MODEL:return await parseInstancedModel3DTile(tile,arrayBuffer,byteOffset,options,context);case TILE3D_TYPE.POINT_CLOUD:return await parsePointCloud3DTile(tile,arrayBuffer,byteOffset,options,context);default:throw new Error("3DTileLoader: unknown type ".concat(tile.type));}}var SUBTREE_FILE_MAGIC=0x74627573;var SUBTREE_FILE_VERSION=1;async function parse3DTilesSubtree(data){var magic=new Uint32Array(data.slice(0,4));if(magic[0]!==SUBTREE_FILE_MAGIC){throw new Error('Wrong subtree file magic number');}var version=new Uint32Array(data.slice(4,8));if(version[0]!==SUBTREE_FILE_VERSION){throw new Error('Wrong subtree file verson, must be 1');}var jsonByteLength=parseUint64Value(data.slice(8,16));var stringAttribute=new Uint8Array(data,24,jsonByteLength);var textDecoder=new TextDecoder('utf8');var string=textDecoder.decode(stringAttribute);var subtree=JSON.parse(string);var binaryByteLength=parseUint64Value(data.slice(16,24));var internalBinaryBuffer=new ArrayBuffer(0);if(binaryByteLength){internalBinaryBuffer=data.slice(24+jsonByteLength);}if('bufferView'in subtree.tileAvailability){subtree.tileAvailability.explicitBitstream=await getExplicitBitstream(subtree,'tileAvailability',internalBinaryBuffer);}if('bufferView'in subtree.contentAvailability){subtree.contentAvailability.explicitBitstream=await getExplicitBitstream(subtree,'contentAvailability',internalBinaryBuffer);}if('bufferView'in subtree.childSubtreeAvailability){subtree.childSubtreeAvailability.explicitBitstream=await getExplicitBitstream(subtree,'childSubtreeAvailability',internalBinaryBuffer);}return subtree;}async function getExplicitBitstream(subtree,name,internalBinaryBuffer){var bufferViewIndex=subtree[name].bufferView;var bufferView=subtree.bufferViews[bufferViewIndex];var buffer=subtree.buffers[bufferView.buffer];if(buffer.uri){var response=await fetchFile(buffer.uri);var data=await response.arrayBuffer();return new Uint8Array(data,bufferView.byteOffset,bufferView.byteLength);}return new Uint8Array(internalBinaryBuffer,bufferView.byteOffset,bufferView.byteLength);}function parseUint64Value(buffer){var dataView=new DataView(buffer);var left=dataView.getUint32(0,true);var right=dataView.getUint32(4,true);return left+2**32*right;}var Tile3DSubtreeLoader={id:'3d-tiles-subtree',name:'3D Tiles Subtree',module:'3d-tiles',version:VERSION$5,extensions:['subtree'],mimeTypes:['application/octet-stream'],tests:['subtree'],parse:parse3DTilesSubtree,options:{}};var QUADTREE_DEVISION_COUNT=4;var OCTREE_DEVISION_COUNT=8;var SUBDIVISION_COUNT_MAP={QUADTREE:QUADTREE_DEVISION_COUNT,OCTREE:OCTREE_DEVISION_COUNT};async function parseImplicitTiles(subtree,options){var parentData=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{mortonIndex:0,x:0,y:0,z:0};var childIndex=arguments.length>3&&arguments[3]!==undefined?arguments[3]:0;var level=arguments.length>4&&arguments[4]!==undefined?arguments[4]:0;var globalData=arguments.length>5&&arguments[5]!==undefined?arguments[5]:{level:0,mortonIndex:0,x:0,y:0,z:0};var{subdivisionScheme,subtreeLevels,maximumLevel,contentUrlTemplate,subtreesUriTemplate,basePath}=options;var tile={children:[],lodMetricValue:0,contentUrl:''};var childrenPerTile=SUBDIVISION_COUNT_MAP[subdivisionScheme];var childX=childIndex&0b01;var childY=childIndex>>1&0b01;var childZ=childIndex>>2&0b01;var levelOffset=(childrenPerTile**level-1)/(childrenPerTile-1);var childTileMortonIndex=concatBits(parentData.mortonIndex,childIndex);var tileAvailabilityIndex=levelOffset+childTileMortonIndex;var childTileX=concatBits(parentData.x,childX);var childTileY=concatBits(parentData.y,childY);var childTileZ=concatBits(parentData.z,childZ);var isChildSubtreeAvailable=false;if(level+1>subtreeLevels){isChildSubtreeAvailable=getAvailabilityResult(subtree.childSubtreeAvailability,childTileMortonIndex);}var x=concatBits(globalData.x,childTileX);var y=concatBits(globalData.y,childTileY);var z=concatBits(globalData.z,childTileZ);var lev=level+globalData.level;if(isChildSubtreeAvailable){var subtreePath="".concat(basePath,"/").concat(subtreesUriTemplate);var childSubtreeUrl=replaceContentUrlTemplate(subtreePath,lev,x,y,z);var childSubtree=await load(childSubtreeUrl,Tile3DSubtreeLoader);subtree=childSubtree;globalData.mortonIndex=childTileMortonIndex;globalData.x=childTileX;globalData.y=childTileY;globalData.z=childTileZ;globalData.level=level;childTileMortonIndex=0;tileAvailabilityIndex=0;childTileX=0;childTileY=0;childTileZ=0;level=0;}var isTileAvailable=getAvailabilityResult(subtree.tileAvailability,tileAvailabilityIndex);if(!isTileAvailable||level>maximumLevel){return tile;}var isContentAvailable=getAvailabilityResult(subtree.contentAvailability,tileAvailabilityIndex);if(isContentAvailable){tile.contentUrl=replaceContentUrlTemplate(contentUrlTemplate,lev,x,y,z);}var childTileLevel=level+1;var pData={mortonIndex:childTileMortonIndex,x:childTileX,y:childTileY,z:childTileZ};for(var index=0;index<childrenPerTile;index++){var currentTile=await parseImplicitTiles(subtree,options,pData,index,childTileLevel,globalData);if(currentTile.contentUrl||currentTile.children.length){var globalLevel=lev+1;var childCoordinates={childTileX,childTileY,childTileZ};var formattedTile=formatTileData(currentTile,globalLevel,childCoordinates,options);tile.children.push(formattedTile);}}return tile;}function getAvailabilityResult(availabilityData,index){if('constant'in availabilityData){return Boolean(availabilityData.constant);}if(availabilityData.explicitBitstream){return getBooleanValueFromBitstream(index,availabilityData.explicitBitstream);}return false;}function formatTileData(tile,level,childCoordinates,options){var{basePath,refine,getRefine,lodMetricType,getTileType,rootLodMetricValue,rootBoundingVolume}=options;var uri=tile.contentUrl&&tile.contentUrl.replace("".concat(basePath,"/"),'');var lodMetricValue=rootLodMetricValue/2**level;var boundingVolume=calculateBoundingVolumeForChildTile(level,rootBoundingVolume,childCoordinates);return {children:tile.children,contentUrl:tile.contentUrl,content:{uri},id:tile.contentUrl,refine:getRefine(refine),type:getTileType(tile),lodMetricType,lodMetricValue,boundingVolume};}function calculateBoundingVolumeForChildTile(level,rootBoundingVolume,childCoordinates){if(rootBoundingVolume.region){var{childTileX,childTileY,childTileZ}=childCoordinates;var[west,south,east,north,minimumHeight,maximumHeight]=rootBoundingVolume.region;var boundingVolumesCount=2**level;var sizeX=(east-west)/boundingVolumesCount;var sizeY=(north-south)/boundingVolumesCount;var sizeZ=(maximumHeight-minimumHeight)/boundingVolumesCount;var[childWest,childEast]=[west+sizeX*childTileX,west+sizeX*(childTileX+1)];var[childSouth,childNorth]=[south+sizeY*childTileY,south+sizeY*(childTileY+1)];var[childMinimumHeight,childMaximumHeight]=[minimumHeight+sizeZ*childTileZ,minimumHeight+sizeZ*(childTileZ+1)];return {region:[childWest,childSouth,childEast,childNorth,childMinimumHeight,childMaximumHeight]};}console.warn('Unsupported bounding volume type: ',rootBoundingVolume);return null;}function concatBits(first,second){return parseInt(first.toString(2)+second.toString(2),2);}function replaceContentUrlTemplate(templateUrl,level,x,y,z){var mapUrl=generateMapUrl({level,x,y,z});return templateUrl.replace(/{level}|{x}|{y}|{z}/gi,matched=>mapUrl[matched]);}function generateMapUrl(items){var mapUrl={};for(var key in items){mapUrl["{".concat(key,"}")]=items[key];}return mapUrl;}function getBooleanValueFromBitstream(availabilityIndex,availabilityBuffer){var byteIndex=Math.floor(availabilityIndex/8);var bitIndex=availabilityIndex%8;var bitValue=availabilityBuffer[byteIndex]>>bitIndex&1;return bitValue===1;}function getTileType(tile){if(!tile.contentUrl){return TILE_TYPE.EMPTY;}var contentUrl=tile.contentUrl;var fileExtension=contentUrl.split('.').pop();switch(fileExtension){case'pnts':return TILE_TYPE.POINTCLOUD;case'i3dm':case'b3dm':case'glb':case'gltf':return TILE_TYPE.SCENEGRAPH;default:return fileExtension;}}function getRefine(refine){switch(refine){case'REPLACE':case'replace':return TILE_REFINEMENT.REPLACE;case'ADD':case'add':return TILE_REFINEMENT.ADD;default:return refine;}}function normalizeTileData(tile,options){if(!tile){return null;}if(tile.content){var contentUri=tile.content.uri||tile.content.url;tile.contentUrl="".concat(options.basePath,"/").concat(contentUri);}tile.id=tile.contentUrl;tile.lodMetricType=LOD_METRIC_TYPE.GEOMETRIC_ERROR;tile.lodMetricValue=tile.geometricError;tile.transformMatrix=tile.transform;tile.type=getTileType(tile);tile.refine=getRefine(tile.refine);return tile;}function normalizeTileHeaders(tileset){var basePath=tileset.basePath;var root=normalizeTileData(tileset.root,tileset);var stack=[];stack.push(root);while(stack.length>0){var tile=stack.pop()||{};var children=tile.children||[];for(var childHeader of children){normalizeTileData(childHeader,{basePath});stack.push(childHeader);}}return root;}async function normalizeImplicitTileHeaders(tileset){if(!tileset.root){return null;}var basePath=tileset.basePath;var implicitTilingExtension=tileset.root.extensions['3DTILES_implicit_tiling'];var{subdivisionScheme,maximumLevel,subtreeLevels,subtrees:{uri:subtreesUriTemplate}}=implicitTilingExtension;var subtreeUrl=replaceContentUrlTemplate(subtreesUriTemplate,0,0,0,0);var rootSubtreeUrl="".concat(basePath,"/").concat(subtreeUrl);var rootSubtree=await load(rootSubtreeUrl,Tile3DSubtreeLoader);var contentUrlTemplate="".concat(basePath,"/").concat(tileset.root.content.uri);var refine=tileset.root.refine;var rootLodMetricValue=tileset.root.geometricError;var rootBoundingVolume=tileset.root.boundingVolume;var options={contentUrlTemplate,subtreesUriTemplate,subdivisionScheme,subtreeLevels,maximumLevel,refine,basePath,lodMetricType:LOD_METRIC_TYPE.GEOMETRIC_ERROR,rootLodMetricValue,rootBoundingVolume,getTileType,getRefine};return await normalizeImplicitTileData(tileset.root,rootSubtree,options);}async function normalizeImplicitTileData(tile,rootSubtree,options){if(!tile){return null;}tile.lodMetricType=LOD_METRIC_TYPE.GEOMETRIC_ERROR;tile.lodMetricValue=tile.geometricError;tile.transformMatrix=tile.transform;var{children,contentUrl}=await parseImplicitTiles(rootSubtree,options);if(contentUrl){tile.contentUrl=contentUrl;tile.content={uri:contentUrl.replace("".concat(options.basePath,"/"),'')};}tile.refine=getRefine(tile.refine);tile.type=getTileType(tile);tile.children=children;tile.id=tile.contentUrl;return tile;}var IMPLICIT_TILING_EXTENSION_NAME='3DTILES_implicit_tiling';var Tiles3DLoader={id:'3d-tiles',name:'3D Tiles',module:'3d-tiles',version:VERSION$5,extensions:['cmpt','pnts','b3dm','i3dm'],mimeTypes:['application/octet-stream'],tests:['cmpt','pnts','b3dm','i3dm'],parse,options:{'3d-tiles':{loadGLTF:true,decodeQuantizedPositions:false,isTileset:'auto',assetGltfUpAxis:null}}};function getBaseUri(tileset){return dirname(tileset.url);}async function parseTile(arrayBuffer,options,context){var tile={content:{featureIds:null}};var byteOffset=0;await parse3DTile(arrayBuffer,byteOffset,options,context,tile.content);return tile.content;}async function parseTileset(data,options,context){var _tilesetJson$root;var tilesetJson=JSON.parse(new TextDecoder().decode(data));tilesetJson.loader=options.loader||Tiles3DLoader;tilesetJson.url=context.url;tilesetJson.basePath=getBaseUri(tilesetJson);tilesetJson.root=hasImplicitTilingExtension(tilesetJson)?await normalizeImplicitTileHeaders(tilesetJson):normalizeTileHeaders(tilesetJson);tilesetJson.type=TILESET_TYPE.TILES3D;tilesetJson.lodMetricType=LOD_METRIC_TYPE.GEOMETRIC_ERROR;tilesetJson.lodMetricValue=((_tilesetJson$root=tilesetJson.root)===null||_tilesetJson$root===void 0?void 0:_tilesetJson$root.lodMetricValue)||0;return tilesetJson;}async function parse(data,options,context){var loaderOptions=options['3d-tiles']||{};var isTileset;if(loaderOptions.isTileset==='auto'){isTileset=context.url&&context.url.indexOf('.json')!==-1;}else {isTileset=loaderOptions.isTileset;}if(isTileset){data=await parseTileset(data,options,context);}else {data=await parseTile(data,options,context);}return data;}function hasImplicitTilingExtension(tilesetJson){var _tilesetJson$extensio,_tilesetJson$extensio2;return (tilesetJson===null||tilesetJson===void 0?void 0:(_tilesetJson$extensio=tilesetJson.extensionsRequired)===null||_tilesetJson$extensio===void 0?void 0:_tilesetJson$extensio.includes(IMPLICIT_TILING_EXTENSION_NAME))&&(tilesetJson===null||tilesetJson===void 0?void 0:(_tilesetJson$extensio2=tilesetJson.extensionsUsed)===null||_tilesetJson$extensio2===void 0?void 0:_tilesetJson$extensio2.includes(IMPLICIT_TILING_EXTENSION_NAME));}var CESIUM_ION_URL='https://api.cesium.com/v1/assets';async function getIonTilesetMetadata(accessToken,assetId){if(!assetId){var assets=await getIonAssets(accessToken);for(var item of assets.items){if(item.type==='3DTILES'){assetId=item.id;}}}var ionAssetMetadata=await getIonAssetMetadata(accessToken,assetId);var{type,url}=ionAssetMetadata;assert$7(type==='3DTILES'&&url);ionAssetMetadata.headers={Authorization:"Bearer ".concat(ionAssetMetadata.accessToken)};return ionAssetMetadata;}async function getIonAssets(accessToken){assert$7(accessToken);var url=CESIUM_ION_URL;var headers={Authorization:"Bearer ".concat(accessToken)};var response=await fetchFile(url,{fetch:{headers}});if(!response.ok){throw new Error(response.statusText);}return await response.json();}async function getIonAssetMetadata(accessToken,assetId){assert$7(accessToken,assetId);var headers={Authorization:"Bearer ".concat(accessToken)};var url="".concat(CESIUM_ION_URL,"/").concat(assetId);var response=await fetchFile("".concat(url),{fetch:{headers}});if(!response.ok){throw new Error(response.statusText);}var metadata=await response.json();response=await fetchFile("".concat(url,"/endpoint"),{fetch:{headers}});if(!response.ok){throw new Error(response.statusText);}var tilesetInfo=await response.json();metadata=_objectSpread2(_objectSpread2({},metadata),tilesetInfo);return metadata;}async function preload(url){var options=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};options=options['cesium-ion']||{};var{accessToken}=options;var assetId=options.assetId;if(!Number.isFinite(assetId)){var matched=url.match(/\/([0-9]+)\/tileset.json/);assetId=matched&&matched[1];}return getIonTilesetMetadata(accessToken,assetId);}var CesiumIonLoader=_objectSpread2(_objectSpread2({},Tiles3DLoader),{},{id:'cesium-ion',name:'Cesium Ion',preload,parse:async(data,options,context)=>{options=_objectSpread2({},options);options['3d-tiles']=options['cesium-ion'];options.loader=CesiumIonLoader;return Tiles3DLoader.parse(data,options,context);},options:{'cesium-ion':_objectSpread2(_objectSpread2({},Tiles3DLoader.options['3d-tiles']),{},{accessToken:null})}});// From https://github.com/potree/potree/blob/master/src/materials/PointCloudMaterial.js
  59557. function generateGradientTexture(gradient){var size=64;// create canvas
  59558. var canvas=document.createElement('canvas');canvas.width=size;canvas.height=size;// get context
  59559. var context=canvas.getContext('2d');// draw gradient
  59560. context.rect(0,0,size,size);var ctxGradient=context.createLinearGradient(0,0,size,size);for(var _i55=0;_i55<gradient.length;_i55++){var step=gradient[_i55];ctxGradient.addColorStop(step[0],'#'+step[1].getHexString());}context.fillStyle=ctxGradient;context.fill();//let texture = new THREE.Texture(canvas);
  59561. var texture=new CanvasTexture(canvas);texture.needsUpdate=true;texture.minFilter=LinearFilter;texture.wrapS=RepeatWrapping;texture.wrapT=RepeatWrapping;texture.repeat.set(2,2);// textureImage = texture.image;
  59562. return texture;}function _getCameraFrustum(camera){camera.updateMatrix();// make sure camera's local matrix is updated
  59563. camera.updateMatrixWorld();// make sure camera's world matrix is updated
  59564. camera.matrixWorldInverse.copy(camera.matrixWorld).invert();var frustum=new Frustum();frustum.setFromProjectionMatrix(new Matrix4().multiplyMatrices(camera.projectionMatrix,camera.matrixWorldInverse));return frustum;}function loadersPlaneToMesh(plane){var group=new Group();// Create a basic rectangle geometry from math.gl plane
  59565. var planeGeometry=new PlaneGeometry(10,5);// Align the geometry to the plane
  59566. var coplanarPoint=new Vector3(...plane.projectPointOntoPlane([0,0,0]));var normal=new Vector3(plane.normal.x,plane.normal.y,plane.normal.z);var focalPoint=new Vector3().copy(coplanarPoint).add(normal);planeGeometry.lookAt(focalPoint);planeGeometry.translate(coplanarPoint.x,coplanarPoint.y,coplanarPoint.z);// Edges
  59567. /*
  59568. const edges = new EdgesGeometry(planeGeometry)
  59569. var dispPlane = new LineSegments(edges, new LineBasicMaterial({ color: 0x00ffff }))*/ //plane
  59570. var material=new BasicMaterial({color:0x00ffff,side:DoubleSide});var mesh=new Mesh(planeGeometry,material);var arrowHelper=new ArrowHelper(normal,coplanarPoint,5,0xffff00);group.add(arrowHelper);group.add(mesh);return group;}function loadersBoundingBoxToMesh(tile){// Create a basic rectangle geometry from math.gl half-axes
  59571. var boundUntransformed=tile.type=='empty'?tile.boundingVolume:tile.getBoundUntransformed();//empty时没创建好,直接给boundingVolume一样
  59572. /* let redColor = 0;
  59573. if (tile.content) {
  59574. //redColor = Math.min((tile.content.byteLength != void 0 ? tile.content.byteLength : 0) / 500000, 1.0);
  59575. redColor = Math.min( tile.depth / 10 , 1.0); //改
  59576. } */var hue=0;if(tile.content){hue=Math.min(tile.depth/10,1.0);//改
  59577. }var boxColor=new THREE.Color().setHSL(hue,0.9,0.85);//const boxColor = new Color(redColor, 1.0, 0.0);
  59578. var boxGeometry=new BoxGeometry(1,1,1);var boxTransform=new Matrix4();if(boundUntransformed.halfAxes){boxTransform.copy(getMatrix4FromHalfAxes(boundUntransformed.halfAxes));}else if(boundUntransformed.radius){boxGeometry.scale(boundUntransformed.radius*2,boundUntransformed.radius*2,boundUntransformed.radius*2);}boxTransform.premultiply(new Matrix4().setPosition(...boundUntransformed.center));//add
  59579. /* if(tile.type != "empty"){ //root单独处理了
  59580. boxTransform.premultiply((new Matrix4$1()).makeScale(1,1,-1))//xzw 因为mesh倒转了所以box也
  59581. }else{
  59582. console.log('empty')
  59583. } */boxGeometry.applyMatrix4(boxTransform);var edges=new EdgesGeometry(boxGeometry);var dispPlane=new LineSegments(edges,new LineBasicMaterial({color:boxColor,transparent:true}));//dispPlane.position.copy(new Vector3$1(...boundingVolume.center));
  59584. dispPlane.matrixAutoUpdate=false;//add
  59585. var label=new Potree.TextSprite({mat:new THREE.MeshBasicMaterial({transparent:true}),//depthTest:false会导致经常显示不出
  59586. backgroundColor:{r:0,g:0,b:0,a:0.1},textColor:{r:boxColor.r*255,g:boxColor.g*255,b:boxColor.b*255,a:0.9},fontsize:100,//useDepth : true ,
  59587. renderOrder:5,text:tile.id.split('/').pop().split('.b3dm')[0],//Tile_+094_-010.b3dm'
  59588. name:'tile'});label.addEventListener('mouseover',()=>{if(label.sprite.material.opacity<1)return;window.hoverTile=tile;console.log('hoverLabel',tile.id,tile._distanceToCamera);});/* let s = 0.6
  59589. label.scale.set(s,s,s) */var s=tile.tileset.options.maximumScreenSpaceError/400;label.scale.set(s,s,s);dispPlane.add(label);label.position.set(...boundUntransformed.center);//label.position.z *= -1
  59590. /* if(tile.content.byteLength == void 0){
  59591. let oldUpdate = dispPlane.updateMatrixWorld.bind(dispPlane)
  59592. dispPlane.updateMatrixWorld = (a,b)=>{
  59593. oldUpdate(a,b)
  59594. }
  59595. let oldU = dispPlane.updateMatrix.bind(dispPlane)
  59596. dispPlane.updateMatrix = (a,b)=>{
  59597. oldU(a,b)
  59598. }
  59599. } */tile.volumeBox=dispPlane;return dispPlane;}function getMatrix4FromHalfAxes(halfAxes){var m=halfAxes;var rotateMatrix=new Matrix4().fromArray([m[0]*2,m[1]*2,m[2]*2,0,m[3]*2,m[4]*2,m[5]*2,0,m[6]*2,m[7]*2,m[8]*2,0,0,0,0,1]);return rotateMatrix;}/*
  59600. * from https://github.com/tentone/geo-three
  59601. * Tree-shaking did not work, probably due to static class methods
  59602. */function datumsToSpherical(latitude,longitude){var EARTH_RADIUS=6378137;var EARTH_PERIMETER=2*Math.PI*EARTH_RADIUS;var EARTH_ORIGIN=EARTH_PERIMETER/2.0;var x=longitude*EARTH_ORIGIN/180.0;var y=Math.log(Math.tan((90+latitude)*Math.PI/360.0))/(Math.PI/180.0);y=y*EARTH_ORIGIN/180.0;return new Vector2(x,y);}var Gradients$1={// From chroma spectral http://gka.github.io/chroma.js/
  59603. SPECTRAL:[[0,new Color(0.3686,0.3098,0.6353)],[0.1,new Color(0.1961,0.5333,0.7412)],[0.2,new Color(0.4,0.7608,0.6471)],[0.3,new Color(0.6706,0.8667,0.6431)],[0.4,new Color(0.902,0.9608,0.5961)],[0.5,new Color(1.0,1.0,0.749)],[0.6,new Color(0.9961,0.8784,0.5451)],[0.7,new Color(0.9922,0.6824,0.3804)],[0.8,new Color(0.9569,0.4275,0.2627)],[0.9,new Color(0.8353,0.2431,0.3098)],[1,new Color(0.6196,0.0039,0.2588)]],PLASMA:[[0.0,new Color(0.241,0.015,0.61)],[0.1,new Color(0.387,0.001,0.654)],[0.2,new Color(0.524,0.025,0.653)],[0.3,new Color(0.651,0.125,0.596)],[0.4,new Color(0.752,0.227,0.513)],[0.5,new Color(0.837,0.329,0.431)],[0.6,new Color(0.907,0.435,0.353)],[0.7,new Color(0.963,0.554,0.272)],[0.8,new Color(0.992,0.681,0.195)],[0.9,new Color(0.987,0.822,0.144)],[1.0,new Color(0.94,0.975,0.131)]],YELLOW_GREEN:[[0,new Color(0.1647,0.2824,0.3451)],[0.1,new Color(0.1338,0.3555,0.4227)],[0.2,new Color(0.061,0.4319,0.4864)],[0.3,new Color(0.0,0.5099,0.5319)],[0.4,new Color(0.0,0.5881,0.5569)],[0.5,new Color(0.137,0.665,0.5614)],[0.6,new Color(0.2906,0.7395,0.5477)],[0.7,new Color(0.4453,0.8099,0.5201)],[0.8,new Color(0.6102,0.8748,0.485)],[0.9,new Color(0.7883,0.9323,0.4514)],[1,new Color(0.9804,0.9804,0.4314)]],VIRIDIS:[[0.0,new Color(0.267,0.005,0.329)],[0.1,new Color(0.283,0.141,0.458)],[0.2,new Color(0.254,0.265,0.53)],[0.3,new Color(0.207,0.372,0.553)],[0.4,new Color(0.164,0.471,0.558)],[0.5,new Color(0.128,0.567,0.551)],[0.6,new Color(0.135,0.659,0.518)],[0.7,new Color(0.267,0.749,0.441)],[0.8,new Color(0.478,0.821,0.318)],[0.9,new Color(0.741,0.873,0.15)],[1.0,new Color(0.993,0.906,0.144)]],INFERNO:[[0.0,new Color(0.077,0.042,0.206)],[0.1,new Color(0.225,0.036,0.388)],[0.2,new Color(0.373,0.074,0.432)],[0.3,new Color(0.522,0.128,0.42)],[0.4,new Color(0.665,0.182,0.37)],[0.5,new Color(0.797,0.255,0.287)],[0.6,new Color(0.902,0.364,0.184)],[0.7,new Color(0.969,0.516,0.063)],[0.8,new Color(0.988,0.683,0.072)],[0.9,new Color(0.961,0.859,0.298)],[1.0,new Color(0.988,0.998,0.645)]],GRAYSCALE:[[0,new Color(0,0,0)],[1,new Color(1,1,1)]],// 16 samples of the TURBU color scheme
  59604. // values taken from: https://gist.github.com/mikhailov-work/ee72ba4191942acecc03fe6da94fc73f
  59605. // original file licensed under Apache-2.0
  59606. TURBO:[[0.0,new Color(0.18995,0.07176,0.23217)],[0.07,new Color(0.25107,0.25237,0.63374)],[0.13,new Color(0.27628,0.42118,0.89123)],[0.2,new Color(0.25862,0.57958,0.99876)],[0.27,new Color(0.15844,0.73551,0.92305)],[0.33,new Color(0.09267,0.86554,0.7623)],[0.4,new Color(0.19659,0.94901,0.59466)],[0.47,new Color(0.42778,0.99419,0.38575)],[0.53,new Color(0.64362,0.98999,0.23356)],[0.6,new Color(0.80473,0.92452,0.20459)],[0.67,new Color(0.93301,0.81236,0.22667)],[0.73,new Color(0.99314,0.67408,0.20348)],[0.8,new Color(0.9836,0.49291,0.12849)],[0.87,new Color(0.92105,0.31489,0.05475)],[0.93,new Color(0.81608,0.18462,0.01809)],[1.0,new Color(0.66449,0.08436,0.00424)]],RAINBOW:[[0,new Color(0.278,0,0.714)],[1/6,new Color(0,0,1)],[2/6,new Color(0,1,1)],[3/6,new Color(0,1,0)],[4/6,new Color(1,1,0)],[5/6,new Color(1,0.64,0)],[1,new Color(1,0,0)]],CONTOUR:[[0.0,new Color(0,0,0)],[0.03,new Color(0,0,0)],[0.04,new Color(1,1,1)],[1.0,new Color(1,1,1)]]};var PointCloudFS="\n varying vec3 vColor;\n uniform float alpha;\n\n void main() {\n if (vColor == vec3(0.0, 0.0, 0.0)) {\n discard;\n } else {\n gl_FragColor = vec4( vColor, alpha);\n }\n }\n";var PointCloudVS="\n varying vec3 vColor;\n uniform sampler2D gradient;\n uniform sampler2D grayscale;\n attribute float intensity;\n attribute float classification;\n uniform vec3 rootCenter;\n uniform vec3 rootNormal;\n uniform vec2 elevationRange;\n uniform int coloring;\n uniform bool hideGround;\n uniform float maxIntensity;\n uniform float intensityContrast;\n uniform float pointSize;\n\n #ifdef USE_COLOR\n vec3 getRGB() {\n vec3 rgb = color;\n return rgb;\n }\n #endif\n\n vec3 getElevation(){\n vec4 world = modelMatrix * vec4( position, 1.0 );\n float diff = abs(dot(rootNormal, (vec3(world) - rootCenter)));\n float w = max(diff - elevationRange.x,0.0) / max(elevationRange.y - elevationRange.x,1.0);\n vec3 cElevation = texture2D(gradient, vec2(w,1.0-w)).rgb;\n\n return cElevation;\n }\n\n vec3 getIntensity(){\n // TODO: real contrast enhancement. Check https://github.com/yuki-koyama/enhancer/blob/master/shaders/enhancer.fs\n float intmod = pow(intensity, intensityContrast);\n vec3 cIntensity = texture2D(grayscale, vec2(intmod / maxIntensity ,1.0-(intmod / maxIntensity))).rgb;\n return cIntensity;\n }\n\n vec3 getClassification(){\n float classNormalized = classification / 255.0;\n vec3 cClassification = texture2D(gradient, vec2(classNormalized * 5.0,1.0-classNormalized * 5.0)).rgb;\n return cClassification;\n }\n\n vec3 getColor(){\n vec3 color;\n if (hideGround && classification == 2.0) {\n return vec3(0.0, 0.0, 0.0); \n }\n\n if (coloring == 1) {\n color = getIntensity();\n }\n else if (coloring == 2) {\n color = getClassification();\n } else if (coloring == 3) {\n color = getElevation();\n } \n #ifdef USE_COLOR\n else if (coloring == 4) {\n color = getRGB();\n }\n #endif\n else {\n color = vec3(1.0, 1.0, 1.0);\n }\n return color;\n }\n\n void main() {\n vColor = getColor();\n\n gl_PointSize = pointSize;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n }\n";/** Types of coloring used when viewing point cloud tiles */var PointCloudColoring;(function(PointCloudColoring){PointCloudColoring[PointCloudColoring["Intensity"]=1]="Intensity";PointCloudColoring[PointCloudColoring["Classification"]=2]="Classification";PointCloudColoring[PointCloudColoring["Elevation"]=3]="Elevation";PointCloudColoring[PointCloudColoring["RGB"]=4]="RGB";PointCloudColoring[PointCloudColoring["White"]=5]="White";})(PointCloudColoring||(PointCloudColoring={}));/** Types of shading used when viewing b3dm (mesh) tiles */var Shading;(function(Shading){Shading[Shading["FlatTexture"]=1]="FlatTexture";Shading[Shading["ShadedTexture"]=2]="ShadedTexture";Shading[Shading["ShadedNoTexture"]=3]="ShadedNoTexture";})(Shading||(Shading={}));var GeoTransform;(function(GeoTransform){GeoTransform[GeoTransform["Reset"]=1]="Reset";GeoTransform[GeoTransform["Mercator"]=2]="Mercator";GeoTransform[GeoTransform["WGS84Cartesian"]=3]="WGS84Cartesian";})(GeoTransform||(GeoTransform={}));var gradient=Gradients$1.RAINBOW;var gradientTexture=typeof document!='undefined'?generateGradientTexture(gradient):null;var grayscale=Gradients$1.GRAYSCALE;var grayscaleTexture=typeof document!='undefined'?generateGradientTexture(grayscale):null;var defaultOptions={throttleRequests:true,maxRequests:64,updateInterval:0.1,maxConcurrency:1,maximumScreenSpaceError:16,maximumMemoryUsage:32,viewDistanceScale:1.0,skipLevelOfDetail:false,updateTransforms:true,shading:Shading.FlatTexture,transparent:false,pointCloudColoring:PointCloudColoring.White,pointSize:1.0,worker:true,wireframe:false,debug:false,basisTranscoderPath:null,dracoDecoderPath:null,material:null,computeNormals:false,shaderCallback:null,geoTransform:GeoTransform.Reset,preloadTilesCount:null};/** 3D Tiles Loader */class Loader3DTiles{/**
  59607. * Loads a tileset of 3D Tiles according to the given {@link LoaderProps}
  59608. * @public
  59609. *
  59610. * @param props - Properties for this load call {@link LoaderProps}.
  59611. * @returns An object containing the 3D Model to be added to the scene
  59612. * and a runtime engine to be updated every frame.
  59613. */static load(props){return __awaiter(this,void 0,void 0,function*(){var options=Object.assign(Object.assign({},defaultOptions),props.options);var{url}=props;var UPDATE_INTERVAL=options.updateInterval;var MAX_DEPTH_FOR_ORIENTATION=5;var loadersGLOptions={};if(options.cesiumIONToken){loadersGLOptions['cesium-ion']={accessToken:options.cesiumIONToken};var metadata=yield CesiumIonLoader.preload(url,loadersGLOptions);loadersGLOptions['fetch']={headers:metadata.headers};}if(props.loadingManager){props.loadingManager.itemStart(url);}var tilesetJson=yield load(url,Tiles3DLoader,Object.assign({},loadersGLOptions));var renderMap={};var boxMap={};var unloadQueue=[];var root=new Group();var tileBoxes=new Group();tileBoxes.matrixAutoUpdate=false;//add
  59614. if(!options.debug){tileBoxes.visible=false;}else {options.parent.add(tileBoxes);//add
  59615. }var pointcloudUniforms={pointSize:{type:'f',value:options.pointSize},gradient:{type:'t',value:gradientTexture},grayscale:{type:'t',value:grayscaleTexture},rootCenter:{type:'vec3',value:new Vector3()},rootNormal:{type:'vec3',value:new Vector3()},coloring:{type:'i',value:options.pointCloudColoring},hideGround:{type:'b',value:true},elevationRange:{type:'vec2',value:new Vector2(0,400)},maxIntensity:{type:'f',value:1.0},intensityContrast:{type:'f',value:1.0},alpha:{type:'f',value:1.0}};var pointcloudMaterial=new ShaderMaterial({uniforms:pointcloudUniforms,vertexShader:PointCloudVS,fragmentShader:PointCloudFS,transparent:options.transparent,vertexColors:true});var cameraReference=null;var rendererReference=null;var gltfLoader=props.gltfLoader||new GLTFLoader();//xzw改
  59616. var ktx2Loader=undefined;var dracoLoader=undefined;if(options.basisTranscoderPath){ktx2Loader=new KTX2Loader();ktx2Loader.detectSupport(props.renderer);ktx2Loader.setTranscoderPath(options.basisTranscoderPath+'/');ktx2Loader.setWorkerLimit(1);gltfLoader.setKTX2Loader(ktx2Loader);}if(options.dracoDecoderPath){dracoLoader=new DRACOLoader();dracoLoader.setDecoderPath(options.dracoDecoderPath+'/');dracoLoader.setWorkerLimit(options.maxConcurrency);gltfLoader.setDRACOLoader(dracoLoader);}var unlitMaterial=new BasicMaterial({transparent:options.transparent});var tileOptions={maximumMemoryUsage:options.maximumMemoryUsage,maximumScreenSpaceError:options.maximumScreenSpaceError,viewDistanceScale:options.viewDistanceScale,skipLevelOfDetail:options.skipLevelOfDetail,updateTransforms:options.updateTransforms,throttleRequests:options.throttleRequests,maxRequests:options.maxRequests,updateTime:options.updateTime||0,//add
  59617. //maxDepth: options.maxDepth || 50, // !zeg改
  59618. contentLoader:tile=>__awaiter(this,void 0,void 0,function*(){var tileContent=null;switch(tile.type){case TILE_TYPE.POINTCLOUD:{tileContent=createPointNodes(tile,pointcloudMaterial,options,rootTransformInverse);break;}case TILE_TYPE.SCENEGRAPH:case TILE_TYPE.MESH:{tileContent=yield createGLTFNodes(gltfLoader,tile,unlitMaterial,options,rootTransformInverse);break;}}if(tileContent){tileContent.visible=false;renderMap[tile.id]=tileContent;tileContent.name=tile.id;//add
  59619. tileContent.tile=tile;//add
  59620. root.add(renderMap[tile.id]);if(options.debug){var box=loadersBoundingBoxToMesh(tile);tileBoxes.add(box);boxMap[tile.id]=box;}//xzw :
  59621. tileset.dispatchEvent({type:'tileLoaded',tileContent});//每一个tile加载完要更改透明度等
  59622. }}),onTileLoad:tile=>__awaiter(this,void 0,void 0,function*(){if(tileset){if(!orientationDetected&&(tile===null||tile===void 0?void 0:tile.depth)<=MAX_DEPTH_FOR_ORIENTATION){detectOrientation(tile);}tileset._frameNumber++;tilesetUpdate(tileset,renderMap,rendererReference,cameraReference);}}),onTileUnload:tile=>{unloadQueue.push(tile);},onTileError:(tile,message)=>{console.error('Tile error',tile.id,message);}};var tileset=new Tileset3D(tilesetJson,Object.assign(Object.assign({},tileOptions),{loadOptions:Object.assign(Object.assign({},loadersGLOptions),{maxConcurrency:options.maxConcurrency,worker:options.worker,gltf:{loadImages:false},'3d-tiles':{loadGLTF:false}})}));tileset.boxMap=boxMap;//add
  59623. // transformations
  59624. var threeMat=new Matrix4();var tileTransform=new Matrix4();var rootCenter=new Vector3();var orientationDetected=false;if(tileset.root.boundingVolume){if(tileset.root.header.boundingVolume.region){// TODO: Handle region type bounding volumes
  59625. // https://github.com/visgl/loaders.gl/issues/1994
  59626. console.warn("Cannot apply a model matrix to bounding volumes of type region. Tileset stays in original geo-coordinates.");options.geoTransform=GeoTransform.WGS84Cartesian;}tileTransform.setPosition(tileset.root.boundingVolume.center[0],tileset.root.boundingVolume.center[1],tileset.root.boundingVolume.center[2]);}else {console.warn("Bounding volume not found, no transformations applied");}if(options.debug){var box=loadersBoundingBoxToMesh(tileset.root);tileBoxes.add(box);boxMap[tileset.root.id]=box;}var disposeFlag=false;var loadingEnded=false;pointcloudUniforms.rootCenter.value.copy(rootCenter);pointcloudUniforms.rootNormal.value.copy(new Vector3(0,0,1).normalize());// Extra stats
  59627. tileset.stats.get('Loader concurrency').count=options.maxConcurrency;tileset.stats.get('Maximum SSE').count=options.maximumScreenSpaceError;tileset.stats.get('Maximum mem usage').count=options.maximumMemoryUsage;var timer=0;var lastCameraTransform=null;var lastCameraAspect=null;var lastCameraPosition=new Vector3(Infinity,Infinity,Infinity);var sseDenominator=null;root.updateMatrixWorld(true);var lastRootTransform=new Matrix4().copy(root.matrixWorld);var rootTransformInverse=new Matrix4().copy(lastRootTransform).invert();tileset.lastRootTransform=lastRootTransform;//add
  59628. detectOrientation(tileset.root);updateResetTransform();if(options.debug){boxMap[tileset.root.id].applyMatrix4(threeMat);tileBoxes.matrixWorld.copy(root.matrixWorld);}if(options.geoTransform==GeoTransform.Mercator){var coords=datumsToSpherical(tileset.cartographicCenter[1],tileset.cartographicCenter[0]);rootCenter.set(coords.x,0,-coords.y);root.position.copy(rootCenter);root.rotation.set(-Math.PI/2,0,0);root.updateMatrixWorld(true);}else if(options.geoTransform==GeoTransform.WGS84Cartesian){root.applyMatrix4(tileTransform);root.updateMatrixWorld(true);rootCenter.copy(root.position);}function detectOrientation(tile){if(!tile.boundingVolume.halfAxes){return;}var halfAxes=tile.boundingVolume.halfAxes;var orientationMatrix=new Matrix4().extractRotation(getMatrix4FromHalfAxes(halfAxes)).premultiply(new Matrix4().extractRotation(rootTransformInverse));var rotation=new Euler().setFromRotationMatrix(orientationMatrix);if(!rotation.equals(new Euler())){orientationDetected=true;var pos=new Vector3(tileTransform.elements[12],tileTransform.elements[13],tileTransform.elements[14]);tileTransform.extractRotation(orientationMatrix);tileTransform.setPosition(pos);updateResetTransform();}}function updateResetTransform(){if(options.geoTransform!=GeoTransform.WGS84Cartesian){// Reset the current model matrix and apply our own transformation
  59629. //threeMat.copy(tileTransform).invert();
  59630. //threeMat.premultiply(lastRootTransform); //xzw删 被下面copy这句覆盖了
  59631. var tileTransInvert=new Matrix4().copy(tileTransform).invert();threeMat.copy(lastRootTransform).multiply(tileTransInvert);tileset.modelMatrix=new Matrix4$1(threeMat.toArray());//console.log('update tileset ModelMatrix', tileset.modelMatrix.elements)
  59632. tileset.tileTransInvert=tileTransInvert.toArray();// add for volumebox
  59633. }}// 更新瓦片显隐和瓦片迭代更新
  59634. function tilesetUpdate(tileset,renderMap,renderer,camera){if(disposeFlag||options.pauseTilesetUpdate){// !zeg改 pauseTilesetUpdate
  59635. return;}// Assumes camera fov, near and far are not changing
  59636. if(!sseDenominator||camera.aspect!=lastCameraAspect){var loadersFrustum=new PerspectiveFrustum({fov:camera.fov/180*Math.PI,aspectRatio:camera.aspect,near:camera.near,far:camera.far});sseDenominator=loadersFrustum.sseDenominator;lastCameraAspect=camera.aspect;if(camera.aspect==0)return;//add
  59637. if(options.debug){console.log('Updated sse denonimator:',sseDenominator);}}var frustum=_getCameraFrustum(camera);var planes=frustum.planes.map(plane=>new Plane$1(plane.normal.toArray(),plane.constant));var cullingVolume=new CullingVolume(planes);var rendererSize=new Vector2();renderer.getSize(rendererSize);var frameState={camera:{position:lastCameraPosition.toArray()},height:rendererSize.y,frameNumber:tileset._frameNumber,sseDenominator:sseDenominator,cullingVolume:cullingVolume,viewport:{id:0}};tileset._cache.reset();tileset._traverser.traverse(tileset.root,frameState,tileset.options);for(var tile of tileset.tiles){if(tile.selected){if(!renderMap[tile.id]){console.error('TILE SELECTED BUT NOT LOADED!!',tile.id);}else {// Make sure it's visible
  59638. if(!renderMap[tile.id].visible){if(viewer.visiVertexCount<maxVertexVisi){renderMap[tile.id].visible=true;viewer.visiVertexCount+=renderMap[tile.id].vertexCount;//xzw add
  59639. options.debug&&(boxMap[tile.id].material.opacity=1,boxMap[tile.id].children[0].sprite.material.opacity=1);}else {//console.log('超出', visiVertexCount)
  59640. }}/* if(!renderMap[tile.id].realVisible()){
  59641. console.error('!realVisible')
  59642. } */}}else {if(renderMap[tile.id]){if(renderMap[tile.id].visible){renderMap[tile.id].visible=false;options.debug&&(boxMap[tile.id].material.opacity=0.1,boxMap[tile.id].children[0].sprite.material.opacity=0.1);viewer.visiVertexCount-=renderMap[tile.id].vertexCount;//xzw add
  59643. }}}}while(unloadQueue.length>0){var _tile=unloadQueue.pop();if(renderMap[_tile.id]&&_tile.contentState==TILE_CONTENT_STATE.UNLOADED){//console.log('removevisi', renderMap[tile.id].visible) 如果是true,visiVertexCount要减
  59644. root.remove(renderMap[_tile.id]);disposeNode(renderMap[_tile.id]);delete renderMap[_tile.id];}if(boxMap[_tile.id]){disposeNode(boxMap[_tile.id]);tileBoxes.remove(boxMap[_tile.id]);delete boxMap[_tile.id];}}var tilesLoaded=tileset.stats.get('Tiles Loaded').count;var tilesLoading=tileset.stats.get('Tiles Loading').count;if(props.onProgress){props.onProgress(tilesLoaded,tilesLoaded+tilesLoading);}if(props.loadingManager&&!loadingEnded){if(tilesLoading==0&&(options.preloadTilesCount==null||tilesLoaded>=options.preloadTilesCount)){loadingEnded=true;props.loadingManager.itemEnd(props.url);}}return frameState;}return {model:root,runtime:{getTileset:()=>{return tileset;},getStats:()=>{return tileset.stats;},showTiles:visible=>{tileBoxes.visible=visible;},setWireframe:wireframe=>{options.wireframe=wireframe;root.traverse(object=>{if(object instanceof Mesh){object.material.wireframe=wireframe;}});},setDebug:debug=>{options.debug=debug;tileBoxes.visible=debug;},setShading:shading=>{options.shading=shading;},getTileBoxes:()=>{return tileBoxes;},setViewDistanceScale:scale=>{tileset.options.viewDistanceScale=scale;tileset._frameNumber++;tilesetUpdate(tileset,renderMap,rendererReference,cameraReference);},setHideGround:enabled=>{pointcloudUniforms.hideGround.value=enabled;},setPointCloudColoring:selection=>{pointcloudUniforms.coloring.value=selection;},setElevationRange:range=>{pointcloudUniforms.elevationRange.value.set(range[0],range[1]);},setMaxIntensity:intensity=>{pointcloudUniforms.maxIntensity.value=intensity;},setIntensityContrast:contrast=>{pointcloudUniforms.intensityContrast.value=contrast;},setPointAlpha:alpha=>{pointcloudUniforms.alpha.value=alpha;},getLatLongHeightFromPosition:position=>{var cartographicPosition=tileset.ellipsoid.cartesianToCartographic(new Vector3().copy(position).applyMatrix4(new Matrix4().copy(threeMat).invert()).toArray());return {lat:cartographicPosition[1],long:cartographicPosition[0],height:cartographicPosition[2]};},getPositionFromLatLongHeight:coord=>{var cartesianPosition=tileset.ellipsoid.cartographicToCartesian([coord.long,coord.lat,coord.height]);return new Vector3(...cartesianPosition).applyMatrix4(threeMat);},getCameraFrustum:camera=>{var frustum=_getCameraFrustum(camera);var meshes=frustum.planes.map(plane=>new Plane$1(plane.normal.toArray(),plane.constant)).map(loadersPlane=>loadersPlaneToMesh(loadersPlane));var model=new Group();for(var mesh of meshes)model.add(mesh);return model;},update:function update(dt,renderer,camera,ifForce){cameraReference=camera;rendererReference=renderer;timer+=dt;if(!ifForce)ifForce=tileset.nextForceUpdate;tileset.nextForceUpdate=false;if(tileset.needRenderNext){//必须在下一帧渲染刷新否则无法显示
  59645. viewer.dispatchEvent('content_changed');}tileset.needRenderNext=ifForce;if(tileset&&(timer>=UPDATE_INTERVAL||ifForce)){if(!lastRootTransform.equals(root.matrixWorld)){timer=0;lastRootTransform.copy(root.matrixWorld);updateResetTransform();var _rootCenter=new Vector3().setFromMatrixPosition(lastRootTransform);pointcloudUniforms.rootCenter.value.copy(_rootCenter);pointcloudUniforms.rootNormal.value.copy(new Vector3(0,0,1).applyMatrix4(lastRootTransform).normalize());rootTransformInverse.copy(lastRootTransform).invert();if(options.debug){/* console.log('move', tileset.root.id, boxMap[tileset.root.id].matrix.elements, boxMap[tileset.root.id].matrixWorld.elements)
  59646. boxMap[tileset.root.id].matrix.copy(root.matrixWorld);
  59647. boxMap[tileset.root.id].matrixWorld.copy(root.matrixWorld); */ //boxMap[tileset.root.id].applyMatrix4(threeMat);
  59648. tileBoxes.matrix.copy(root.matrixWorld);//boxMap[tileset.root.id].matrixWorld.copy(threeMat);
  59649. //boxMap[tileset.root.id].applyMatrix4(lastRootTransform);//boxMap[tileset.root.id].applyMatrix4(lastRootTransform);
  59650. //boxMap[tileset.root.id].updateWorldMatrix()
  59651. }}if(this.lastCameraTransform==null){this.lastCameraTransform=new Matrix4().copy(camera.matrixWorld);}else {var cameraChanged=!camera.matrixWorld.equals(this.lastCameraTransform)||!(camera.aspect==lastCameraAspect);if(cameraChanged||ifForce){timer=0;tileset._frameNumber++;camera.getWorldPosition(lastCameraPosition);this.lastCameraTransform.copy(camera.matrixWorld);tilesetUpdate(tileset,renderMap,renderer,camera);}}}/* else{
  59652. console.log('11')
  59653. } */},dispose:function dispose(){disposeFlag=true;tileset._destroy();while(root.children.length>0){var obj=root.children[0];disposeNode(obj);root.remove(obj);}while(tileBoxes.children.length>0){var _obj=tileBoxes.children[0];tileBoxes.remove(_obj);_obj.geometry.dispose();_obj.material.dispose();}if(ktx2Loader){ktx2Loader.dispose();}if(dracoLoader){dracoLoader.dispose();}},limit2lowestDepth:isLowest=>{//zeg add 设置是否限制为最低精度tile深度
  59654. maxDepth=isLowest?1:100;//影响到shouldRefine, 检查方法:可以看到当maxDepth降低了之后viewer.objs.children[0].runtime.getTileset().tiles.filter(e=> e.tileContent.visible)变少
  59655. if(cameraReference){tileset._frameNumber++;tilesetUpdate(tileset,renderMap,rendererReference,cameraReference);}}}};});}}function createGLTFNodes(gltfLoader,tile,unlitMaterial,options,rootTransformInverse){return __awaiter(this,void 0,void 0,function*(){return new Promise((resolve,reject)=>{var _a;var rotateX=new Matrix4().makeRotationAxis(new Vector3(1,0,0),Math.PI/2);var shouldRotate=((_a=tile.tileset.asset)===null||_a===void 0?void 0:_a.gltfUpAxis)!=="Z";// The computed trasnform already contains the root's transform, so we have to invert it
  59656. //const contentTransform = new Matrix4$1().fromArray(tile.computedTransform).premultiply(tileMatrix)//.premultiply(rootTransformInverse); //xzw 删。原先的会造成移动后tiles错乱
  59657. //const contentTransform = new Matrix4$1().fromArray(tile.computedTransform).premultiply(tile.tileset.modelMatrix).premultiply(rootTransformInverse)
  59658. // 这句同tile.computedTransform左乘tileTransform。 因为tileTransform拿不到所以使用modelMatrix。modelMatrix为tileTransform左乘rootTransform, 所以再左乘rootTransformInverse
  59659. //改动:contentTransform中的computedTransform 去掉左乘 root.modelMatrixWorld , 因为移动过后这个computedTransform没更新
  59660. gltfLoader.parse(tile.content.type=='glTF'?tile.content.gltf.gltfArrayBuffer:tile.content.gltfArrayBuffer,//tile.content.gltfArrayBuffer,
  59661. tile.contentUrl?tile.contentUrl.substr(0,tile.contentUrl.lastIndexOf('/')+1):'',gltf=>{var tileContent=gltf.scenes[0];tileContent.vertexCount=0;//xzw add
  59662. tile.tileContent=tileContent;//xzw add
  59663. var needUpdate;if(tile.rtcCenterState!=!!tile.content.rtcCenter){// 等mesh加载好才知道rtcCenter,每个mesh坐标都不一样
  59664. needUpdate=true;//console.error('rtcCenter有变化?!')
  59665. }tile.rtcCenterState=rtcCenterGlobal=!!tile.content.rtcCenter;var contentTransform=tile.getContentTransform(needUpdate);if(tile.content.rtcCenter){//大部分模型无 rtcCenter
  59666. //console.error('rtcCenter有?!') //似乎bounding中包含这个信息了 所以getContentTransform不含这个
  59667. var tranM=new Matrix4();tranM.makeTranslation(tile.content.rtcCenter[0],tile.content.rtcCenter[1],tile.content.rtcCenter[2]);contentTransform.premultiply(tranM);}if(needUpdate){tile._updateBoundingVolume(tile.header);//add 重新更新
  59668. }if(shouldRotate){//大部分模型 无需 Rotate
  59669. contentTransform.multiply(rotateX);// convert from GLTF Y-up to Z-up
  59670. }tileContent.applyMatrix4(contentTransform);//'https://testgis.4dage.com/LVBADUI_qp/tileset.json', //村庄 这个案例是 要rotateX 且有rtcCenter的。boundingVolume已经是转换这两者后的值所以getContentTransform不加这个
  59671. //tile总共要左乘的矩阵 rotateX -> tileTransInvert * computedTransform -> 对geometry的tranM修改 -> 整个模型的matrixWorld
  59672. tileContent.traverse(object=>{if(object.type=="Mesh"){var mesh=object;//mesh.tileId = tile.id//add
  59673. var originalMaterial=mesh.material;var originalMap=originalMaterial.map;if(options.material){mesh.material=options.material.clone();originalMaterial.dispose();}else if(options.shading==Shading.FlatTexture){mesh.material=unlitMaterial.clone();originalMaterial.dispose();}if(options.shading!=Shading.ShadedNoTexture){if(mesh.material.type=="ShaderMaterial"&&!(mesh.material instanceof BasicMaterial)){//改
  59674. mesh.material.uniforms.map={value:originalMap};}else {mesh.material.map=originalMap;}}else {if(originalMap){originalMap.dispose();}mesh.material.map=null;}if(options.shaderCallback){mesh.onBeforeRender=options.shaderCallback;}mesh.material.wireframe=options.wireframe;if(options.computeNormals){mesh.geometry.computeVertexNormals();}//xzw add:
  59675. tileContent.vertexCount+=mesh.geometry.attributes.position.count;//------------------add on 2023.1.16----zeg
  59676. //mesh.geometry.applyMatrix4(contentTransform)
  59677. /* if (tile.content.rtcCenter) {
  59678. // 有些b3dm模型会将坐标写在源码的rtcCenter里 如https://testgis.4dage.com/LVBADUI_qp/tileset.json
  59679. mesh.geometry.translate(tile.content.rtcCenter[0], tile.content.rtcCenter[1], tile.content.rtcCenter[2])
  59680. } else {
  59681. mesh.geometry.scale(1, 1, -1) // 调整缩放,对应box也要进行变换(scaleZ对应box[2])
  59682. } */ //---------------------
  59683. }});resolve(tileContent);},e=>{reject(new Error("error parsing gltf in tile ".concat(tile.id,": ").concat(e)));});});});}function createPointNodes(tile,pointcloudMaterial,options,rootTransformInverse){var d={rtc_center:tile.content.rtcCenter,points:tile.content.attributes.positions,intensities:tile.content.attributes.intensity,classifications:tile.content.attributes.classification,rgb:null,rgba:null};var{colors}=tile.content.attributes;if(colors&&colors.size===3){d.rgb=colors.value;}if(colors&&colors.size===4){d.rgba=colors.value;}var geometry=new BufferGeometry();geometry.setAttribute('position',new Float32BufferAttribute(d.points,3));var contentTransform=new Matrix4().fromArray(tile.computedTransform).premultiply(rootTransformInverse);if(d.rgba){geometry.setAttribute('color',new Float32BufferAttribute(d.rgba,4));}else if(d.rgb){geometry.setAttribute('color',new Uint8BufferAttribute(d.rgb,3,true));}if(d.intensities){geometry.setAttribute('intensity',// Handles both 16bit or 8bit intensity values
  59684. new BufferAttribute(d.intensities,1,true));}if(d.classifications){geometry.setAttribute('classification',new Uint8BufferAttribute(d.classifications,1,false));}var tileContent=new Points(geometry,options.material||pointcloudMaterial);if(d.rtc_center){var c=d.rtc_center;contentTransform.multiply(new Matrix4().makeTranslation(c[0],c[1],c[2]));}tileContent.applyMatrix4(contentTransform);return tileContent;}function disposeMaterial(material){var _a,_b,_c,_d;if((_a=material===null||material===void 0?void 0:material.uniforms)===null||_a===void 0?void 0:_a.map){(_c=(_b=material===null||material===void 0?void 0:material.uniforms)===null||_b===void 0?void 0:_b.map.value)===null||_c===void 0?void 0:_c.dispose();}else if(material.map){(_d=material.map)===null||_d===void 0?void 0:_d.dispose();}material.dispose();}function disposeNode(node){node.traverse(object=>{if(object.isMesh){object.geometry.dispose();if(object.material.isMaterial){disposeMaterial(object.material);}else {// an array of materials
  59685. for(var material of object.material){disposeMaterial(material);}}}});for(var _i56=node.children.length-1;_i56>=0;_i56--){var obj=node.children[_i56];node.remove(obj);}}/*
  59686. 关键搜寻:
  59687. Loader3DTiles : const tileset = new Tileset3D
  59688. tileset.dispatchEvent({type:'tileLoaded',tileContent})
  59689. createGLTFNodes(gltfLoader 创建tile
  59690. executeTraversal(root, frameState) 遍历root
  59691. lastRootTransform rootTransformInverse
  59692. tileset._loadTiles 依次加载tiles
  59693. _getPriority 加载优先级 加了一句
  59694. 笔记:
  59695. 主要类:
  59696. class tileset3D 最外层整体。 获取方法: viewer.objs.children[index].runtime.getTileset()。 .tiles包含所有tiles
  59697. class tileHeader 也就是tileset里面的一个个tile 。 其上有.tileset
  59698. tileset里算的tileTransform之后是不会改变的, tile.transform也是,是json里的。
  59699. tileset.modelMatrix (通常这个值很大) 会随着位移改变
  59700. tile.computedTransform 被我修改了,之前左乘了tileset.modelMatrix,现只包含了transform信息 _updateTransform(parentTransfor 其中有_updateBoundingVolume,这个影响可见性, 在computeVisibilityWithPlaneMask中计算
  59701. tileset._cache.trim(), 然后再update //可以将所有不可见的tiles dispose
  59702. 相机靠近容易缺块的bug暂时修改如下: _visible是由computeVisibilityWithPlaneMask计算得
  59703. get isVisibleAndInRequestVolume() {
  59704. return this._inRequestVolume; //去掉了_visible ||
  59705. }
  59706. 显示所有tile似乎也不会卡顿. 但好像影响了加载顺序从而变慢了。visiVertexCount过量。 怀疑应该还是文件的bound有问题。
  59707. 原本会消失的地方虽然不会消失了但一直是模糊的
  59708. =========
  59709. 访问所有tile:
  59710. viewer.objs.children[0].runtime.getTileset().tiles
  59711. 它的mesh: tile.tileContent
  59712. 或者直接得到所有mesh: viewer.objs.children[0].children
  59713. tile.depth最低为1 , root是0
  59714. */
  59715. var OBJLoader = function () {
  59716. // o object_name | g group_name
  59717. var object_pattern = /^[og]\s*(.+)?/;
  59718. // mtllib file_reference
  59719. var material_library_pattern = /^mtllib /;
  59720. // usemtl material_name
  59721. var material_use_pattern = /^usemtl /;
  59722. // usemap map_name
  59723. var map_use_pattern = /^usemap /;
  59724. var vA = new Vector3();
  59725. var vB = new Vector3();
  59726. var vC = new Vector3();
  59727. var ab = new Vector3();
  59728. var cb = new Vector3();
  59729. function ParserState() {
  59730. var state = {
  59731. objects: [],
  59732. object: {},
  59733. vertices: [],
  59734. normals: [],
  59735. colors: [],
  59736. uvs: [],
  59737. materials: {},
  59738. materialLibraries: [],
  59739. startObject: function startObject(name, fromDeclaration) {
  59740. // If the current object (initial from reset) is not from a g/o declaration in the parsed
  59741. // file. We need to use it for the first parsed g/o to keep things in sync.
  59742. if (this.object && this.object.fromDeclaration === false) {
  59743. this.object.name = name;
  59744. this.object.fromDeclaration = fromDeclaration !== false;
  59745. return;
  59746. }
  59747. var previousMaterial = this.object && typeof this.object.currentMaterial === 'function' ? this.object.currentMaterial() : undefined;
  59748. if (this.object && typeof this.object._finalize === 'function') {
  59749. this.object._finalize(true);
  59750. }
  59751. this.object = {
  59752. name: name || '',
  59753. fromDeclaration: fromDeclaration !== false,
  59754. geometry: {
  59755. vertices: [],
  59756. normals: [],
  59757. colors: [],
  59758. uvs: [],
  59759. hasUVIndices: false
  59760. },
  59761. materials: [],
  59762. smooth: true,
  59763. startMaterial: function startMaterial(name, libraries) {
  59764. var previous = this._finalize(false);
  59765. // New usemtl declaration overwrites an inherited material, except if faces were declared
  59766. // after the material, then it must be preserved for proper MultiMaterial continuation.
  59767. if (previous && (previous.inherited || previous.groupCount <= 0)) {
  59768. this.materials.splice(previous.index, 1);
  59769. }
  59770. var material = {
  59771. index: this.materials.length,
  59772. name: name || '',
  59773. mtllib: Array.isArray(libraries) && libraries.length > 0 ? libraries[libraries.length - 1] : '',
  59774. smooth: previous !== undefined ? previous.smooth : this.smooth,
  59775. groupStart: previous !== undefined ? previous.groupEnd : 0,
  59776. groupEnd: -1,
  59777. groupCount: -1,
  59778. inherited: false,
  59779. clone: function clone(index) {
  59780. var cloned = {
  59781. index: typeof index === 'number' ? index : this.index,
  59782. name: this.name,
  59783. mtllib: this.mtllib,
  59784. smooth: this.smooth,
  59785. groupStart: 0,
  59786. groupEnd: -1,
  59787. groupCount: -1,
  59788. inherited: false
  59789. };
  59790. cloned.clone = this.clone.bind(cloned);
  59791. return cloned;
  59792. }
  59793. };
  59794. this.materials.push(material);
  59795. return material;
  59796. },
  59797. currentMaterial: function currentMaterial() {
  59798. if (this.materials.length > 0) {
  59799. return this.materials[this.materials.length - 1];
  59800. }
  59801. return undefined;
  59802. },
  59803. _finalize: function _finalize(end) {
  59804. var lastMultiMaterial = this.currentMaterial();
  59805. if (lastMultiMaterial && lastMultiMaterial.groupEnd === -1) {
  59806. lastMultiMaterial.groupEnd = this.geometry.vertices.length / 3;
  59807. lastMultiMaterial.groupCount = lastMultiMaterial.groupEnd - lastMultiMaterial.groupStart;
  59808. lastMultiMaterial.inherited = false;
  59809. }
  59810. // Ignore objects tail materials if no face declarations followed them before a new o/g started.
  59811. if (end && this.materials.length > 1) {
  59812. for (var mi = this.materials.length - 1; mi >= 0; mi--) {
  59813. if (this.materials[mi].groupCount <= 0) {
  59814. this.materials.splice(mi, 1);
  59815. }
  59816. }
  59817. }
  59818. // Guarantee at least one empty material, this makes the creation later more straight forward.
  59819. if (end && this.materials.length === 0) {
  59820. this.materials.push({
  59821. name: '',
  59822. smooth: this.smooth
  59823. });
  59824. }
  59825. return lastMultiMaterial;
  59826. }
  59827. };
  59828. // Inherit previous objects material.
  59829. // Spec tells us that a declared material must be set to all objects until a new material is declared.
  59830. // If a usemtl declaration is encountered while this new object is being parsed, it will
  59831. // overwrite the inherited material. Exception being that there was already face declarations
  59832. // to the inherited material, then it will be preserved for proper MultiMaterial continuation.
  59833. if (previousMaterial && previousMaterial.name && typeof previousMaterial.clone === 'function') {
  59834. var declared = previousMaterial.clone(0);
  59835. declared.inherited = true;
  59836. this.object.materials.push(declared);
  59837. }
  59838. this.objects.push(this.object);
  59839. },
  59840. finalize: function finalize() {
  59841. if (this.object && typeof this.object._finalize === 'function') {
  59842. this.object._finalize(true);
  59843. }
  59844. },
  59845. parseVertexIndex: function parseVertexIndex(value, len) {
  59846. var index = parseInt(value, 10);
  59847. return (index >= 0 ? index - 1 : index + len / 3) * 3;
  59848. },
  59849. parseNormalIndex: function parseNormalIndex(value, len) {
  59850. var index = parseInt(value, 10);
  59851. return (index >= 0 ? index - 1 : index + len / 3) * 3;
  59852. },
  59853. parseUVIndex: function parseUVIndex(value, len) {
  59854. var index = parseInt(value, 10);
  59855. return (index >= 0 ? index - 1 : index + len / 2) * 2;
  59856. },
  59857. addVertex: function addVertex(a, b, c) {
  59858. var src = this.vertices;
  59859. var dst = this.object.geometry.vertices;
  59860. dst.push(src[a + 0], src[a + 1], src[a + 2]);
  59861. dst.push(src[b + 0], src[b + 1], src[b + 2]);
  59862. dst.push(src[c + 0], src[c + 1], src[c + 2]);
  59863. },
  59864. addVertexPoint: function addVertexPoint(a) {
  59865. var src = this.vertices;
  59866. var dst = this.object.geometry.vertices;
  59867. dst.push(src[a + 0], src[a + 1], src[a + 2]);
  59868. },
  59869. addVertexLine: function addVertexLine(a) {
  59870. var src = this.vertices;
  59871. var dst = this.object.geometry.vertices;
  59872. dst.push(src[a + 0], src[a + 1], src[a + 2]);
  59873. },
  59874. addNormal: function addNormal(a, b, c) {
  59875. var src = this.normals;
  59876. var dst = this.object.geometry.normals;
  59877. dst.push(src[a + 0], src[a + 1], src[a + 2]);
  59878. dst.push(src[b + 0], src[b + 1], src[b + 2]);
  59879. dst.push(src[c + 0], src[c + 1], src[c + 2]);
  59880. },
  59881. addFaceNormal: function addFaceNormal(a, b, c) {
  59882. var src = this.vertices;
  59883. var dst = this.object.geometry.normals;
  59884. vA.fromArray(src, a);
  59885. vB.fromArray(src, b);
  59886. vC.fromArray(src, c);
  59887. cb.subVectors(vC, vB);
  59888. ab.subVectors(vA, vB);
  59889. cb.cross(ab);
  59890. cb.normalize();
  59891. dst.push(cb.x, cb.y, cb.z);
  59892. dst.push(cb.x, cb.y, cb.z);
  59893. dst.push(cb.x, cb.y, cb.z);
  59894. },
  59895. addColor: function addColor(a, b, c) {
  59896. var src = this.colors;
  59897. var dst = this.object.geometry.colors;
  59898. if (src[a] !== undefined) dst.push(src[a + 0], src[a + 1], src[a + 2]);
  59899. if (src[b] !== undefined) dst.push(src[b + 0], src[b + 1], src[b + 2]);
  59900. if (src[c] !== undefined) dst.push(src[c + 0], src[c + 1], src[c + 2]);
  59901. },
  59902. addUV: function addUV(a, b, c) {
  59903. var src = this.uvs;
  59904. var dst = this.object.geometry.uvs;
  59905. dst.push(src[a + 0], src[a + 1]);
  59906. dst.push(src[b + 0], src[b + 1]);
  59907. dst.push(src[c + 0], src[c + 1]);
  59908. },
  59909. addDefaultUV: function addDefaultUV() {
  59910. var dst = this.object.geometry.uvs;
  59911. dst.push(0, 0);
  59912. dst.push(0, 0);
  59913. dst.push(0, 0);
  59914. },
  59915. addUVLine: function addUVLine(a) {
  59916. var src = this.uvs;
  59917. var dst = this.object.geometry.uvs;
  59918. dst.push(src[a + 0], src[a + 1]);
  59919. },
  59920. addFace: function addFace(a, b, c, ua, ub, uc, na, nb, nc) {
  59921. var vLen = this.vertices.length;
  59922. var ia = this.parseVertexIndex(a, vLen);
  59923. var ib = this.parseVertexIndex(b, vLen);
  59924. var ic = this.parseVertexIndex(c, vLen);
  59925. this.addVertex(ia, ib, ic);
  59926. this.addColor(ia, ib, ic);
  59927. // normals
  59928. if (na !== undefined && na !== '') {
  59929. var nLen = this.normals.length;
  59930. ia = this.parseNormalIndex(na, nLen);
  59931. ib = this.parseNormalIndex(nb, nLen);
  59932. ic = this.parseNormalIndex(nc, nLen);
  59933. this.addNormal(ia, ib, ic);
  59934. } else {
  59935. this.addFaceNormal(ia, ib, ic);
  59936. }
  59937. // uvs
  59938. if (ua !== undefined && ua !== '') {
  59939. var uvLen = this.uvs.length;
  59940. ia = this.parseUVIndex(ua, uvLen);
  59941. ib = this.parseUVIndex(ub, uvLen);
  59942. ic = this.parseUVIndex(uc, uvLen);
  59943. this.addUV(ia, ib, ic);
  59944. this.object.geometry.hasUVIndices = true;
  59945. } else {
  59946. // add placeholder values (for inconsistent face definitions)
  59947. this.addDefaultUV();
  59948. }
  59949. },
  59950. addPointGeometry: function addPointGeometry(vertices) {
  59951. this.object.geometry.type = 'Points';
  59952. var vLen = this.vertices.length;
  59953. for (var vi = 0, l = vertices.length; vi < l; vi++) {
  59954. var index = this.parseVertexIndex(vertices[vi], vLen);
  59955. this.addVertexPoint(index);
  59956. this.addColor(index);
  59957. }
  59958. },
  59959. addLineGeometry: function addLineGeometry(vertices, uvs) {
  59960. this.object.geometry.type = 'Line';
  59961. var vLen = this.vertices.length;
  59962. var uvLen = this.uvs.length;
  59963. for (var vi = 0, l = vertices.length; vi < l; vi++) {
  59964. this.addVertexLine(this.parseVertexIndex(vertices[vi], vLen));
  59965. }
  59966. for (var uvi = 0, l = uvs.length; uvi < l; uvi++) {
  59967. this.addUVLine(this.parseUVIndex(uvs[uvi], uvLen));
  59968. }
  59969. }
  59970. };
  59971. state.startObject('', false);
  59972. return state;
  59973. }
  59974. //
  59975. function OBJLoader(manager) {
  59976. Loader.call(this, manager);
  59977. this.materials = null;
  59978. }
  59979. OBJLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  59980. constructor: OBJLoader,
  59981. load: function load(url, onLoad, onProgress, onError) {
  59982. var scope = this;
  59983. var loader = new FileLoader(this.manager);
  59984. loader.setPath(this.path);
  59985. loader.setRequestHeader(this.requestHeader);
  59986. loader.setWithCredentials(this.withCredentials);
  59987. loader.load(url, function (text, total) {
  59988. // xzw add total
  59989. try {
  59990. onLoad(scope.parse(text), total);
  59991. } catch (e) {
  59992. if (onError) {
  59993. onError(e);
  59994. } else {
  59995. console.error(e);
  59996. }
  59997. scope.manager.itemError(url);
  59998. }
  59999. }, onProgress, onError);
  60000. },
  60001. setMaterials: function setMaterials(materials) {
  60002. this.materials = materials;
  60003. return this;
  60004. },
  60005. parse: function parse(text) {
  60006. var state = new ParserState();
  60007. if (text.indexOf('\r\n') !== -1) {
  60008. // This is faster than String.split with regex that splits on both
  60009. text = text.replace(/\r\n/g, '\n');
  60010. }
  60011. if (text.indexOf('\\\n') !== -1) {
  60012. // join lines separated by a line continuation character (\)
  60013. text = text.replace(/\\\n/g, '');
  60014. }
  60015. var lines = text.split('\n');
  60016. var line = '',
  60017. lineFirstChar = '';
  60018. var lineLength = 0;
  60019. var result = [];
  60020. // Faster to just trim left side of the line. Use if available.
  60021. var trimLeft = typeof ''.trimLeft === 'function';
  60022. for (var i = 0, l = lines.length; i < l; i++) {
  60023. line = lines[i];
  60024. line = trimLeft ? line.trimLeft() : line.trim();
  60025. lineLength = line.length;
  60026. if (lineLength === 0) continue;
  60027. lineFirstChar = line.charAt(0);
  60028. // @todo invoke passed in handler if any
  60029. if (lineFirstChar === '#') continue;
  60030. if (lineFirstChar === 'v') {
  60031. var data = line.split(/\s+/);
  60032. switch (data[0]) {
  60033. case 'v':
  60034. state.vertices.push(parseFloat(data[1]), parseFloat(data[2]), parseFloat(data[3]));
  60035. if (data.length >= 7) {
  60036. state.colors.push(parseFloat(data[4]), parseFloat(data[5]), parseFloat(data[6]));
  60037. } else {
  60038. // if no colors are defined, add placeholders so color and vertex indices match
  60039. state.colors.push(undefined, undefined, undefined);
  60040. }
  60041. break;
  60042. case 'vn':
  60043. state.normals.push(parseFloat(data[1]), parseFloat(data[2]), parseFloat(data[3]));
  60044. break;
  60045. case 'vt':
  60046. state.uvs.push(parseFloat(data[1]), parseFloat(data[2]));
  60047. break;
  60048. }
  60049. } else if (lineFirstChar === 'f') {
  60050. var lineData = line.substr(1).trim();
  60051. var vertexData = lineData.split(/\s+/);
  60052. var faceVertices = [];
  60053. // Parse the face vertex data into an easy to work with format
  60054. for (var j = 0, jl = vertexData.length; j < jl; j++) {
  60055. var vertex = vertexData[j];
  60056. if (vertex.length > 0) {
  60057. var vertexParts = vertex.split('/');
  60058. faceVertices.push(vertexParts);
  60059. }
  60060. }
  60061. // Draw an edge between the first vertex and all subsequent vertices to form an n-gon
  60062. var v1 = faceVertices[0];
  60063. for (var j = 1, jl = faceVertices.length - 1; j < jl; j++) {
  60064. var v2 = faceVertices[j];
  60065. var v3 = faceVertices[j + 1];
  60066. state.addFace(v1[0], v2[0], v3[0], v1[1], v2[1], v3[1], v1[2], v2[2], v3[2]);
  60067. }
  60068. } else if (lineFirstChar === 'l') {
  60069. var lineParts = line.substring(1).trim().split(' ');
  60070. var lineVertices = [],
  60071. lineUVs = [];
  60072. if (line.indexOf('/') === -1) {
  60073. lineVertices = lineParts;
  60074. } else {
  60075. for (var li = 0, llen = lineParts.length; li < llen; li++) {
  60076. var parts = lineParts[li].split('/');
  60077. if (parts[0] !== '') lineVertices.push(parts[0]);
  60078. if (parts[1] !== '') lineUVs.push(parts[1]);
  60079. }
  60080. }
  60081. state.addLineGeometry(lineVertices, lineUVs);
  60082. } else if (lineFirstChar === 'p') {
  60083. var lineData = line.substr(1).trim();
  60084. var pointData = lineData.split(' ');
  60085. state.addPointGeometry(pointData);
  60086. } else if ((result = object_pattern.exec(line)) !== null) {
  60087. // o object_name
  60088. // or
  60089. // g group_name
  60090. // WORKAROUND: https://bugs.chromium.org/p/v8/issues/detail?id=2869
  60091. // var name = result[ 0 ].substr( 1 ).trim();
  60092. var name = (' ' + result[0].substr(1).trim()).substr(1);
  60093. state.startObject(name);
  60094. } else if (material_use_pattern.test(line)) {
  60095. // material
  60096. state.object.startMaterial(line.substring(7).trim(), state.materialLibraries);
  60097. } else if (material_library_pattern.test(line)) {
  60098. // mtl file
  60099. state.materialLibraries.push(line.substring(7).trim());
  60100. } else if (map_use_pattern.test(line)) {
  60101. // the line is parsed but ignored since the loader assumes textures are defined MTL files
  60102. // (according to https://www.okino.com/conv/imp_wave.htm, 'usemap' is the old-style Wavefront texture reference method)
  60103. console.warn('THREE.OBJLoader: Rendering identifier "usemap" not supported. Textures must be defined in MTL files.');
  60104. } else if (lineFirstChar === 's') {
  60105. result = line.split(' ');
  60106. // smooth shading
  60107. // @todo Handle files that have varying smooth values for a set of faces inside one geometry,
  60108. // but does not define a usemtl for each face set.
  60109. // This should be detected and a dummy material created (later MultiMaterial and geometry groups).
  60110. // This requires some care to not create extra material on each smooth value for "normal" obj files.
  60111. // where explicit usemtl defines geometry groups.
  60112. // Example asset: examples/models/obj/cerberus/Cerberus.obj
  60113. /*
  60114. * http://paulbourke.net/dataformats/obj/
  60115. * or
  60116. * http://www.cs.utah.edu/~boulos/cs3505/obj_spec.pdf
  60117. *
  60118. * From chapter "Grouping" Syntax explanation "s group_number":
  60119. * "group_number is the smoothing group number. To turn off smoothing groups, use a value of 0 or off.
  60120. * Polygonal elements use group numbers to put elements in different smoothing groups. For free-form
  60121. * surfaces, smoothing groups are either turned on or off; there is no difference between values greater
  60122. * than 0."
  60123. */
  60124. if (result.length > 1) {
  60125. var value = result[1].trim().toLowerCase();
  60126. state.object.smooth = value !== '0' && value !== 'off';
  60127. } else {
  60128. // ZBrush can produce "s" lines #11707
  60129. state.object.smooth = true;
  60130. }
  60131. var material = state.object.currentMaterial();
  60132. if (material) material.smooth = state.object.smooth;
  60133. } else {
  60134. // Handle null terminated files without exception
  60135. if (line === '\0') continue;
  60136. console.warn('THREE.OBJLoader: Unexpected line: "' + line + '"');
  60137. }
  60138. }
  60139. state.finalize();
  60140. var container = new Group();
  60141. container.materialLibraries = [].concat(state.materialLibraries);
  60142. var hasPrimitives = !(state.objects.length === 1 && state.objects[0].geometry.vertices.length === 0);
  60143. if (hasPrimitives === true) {
  60144. for (var i = 0, l = state.objects.length; i < l; i++) {
  60145. var object = state.objects[i];
  60146. var geometry = object.geometry;
  60147. var materials = object.materials;
  60148. var isLine = geometry.type === 'Line';
  60149. var isPoints = geometry.type === 'Points';
  60150. var hasVertexColors = false;
  60151. // Skip o/g line declarations that did not follow with any faces
  60152. if (geometry.vertices.length === 0) continue;
  60153. var buffergeometry = new BufferGeometry();
  60154. buffergeometry.setAttribute('position', new Float32BufferAttribute(geometry.vertices, 3));
  60155. if (geometry.normals.length > 0) {
  60156. buffergeometry.setAttribute('normal', new Float32BufferAttribute(geometry.normals, 3));
  60157. }
  60158. if (geometry.colors.length > 0) {
  60159. hasVertexColors = true;
  60160. buffergeometry.setAttribute('color', new Float32BufferAttribute(geometry.colors, 3));
  60161. }
  60162. if (geometry.hasUVIndices === true) {
  60163. buffergeometry.setAttribute('uv', new Float32BufferAttribute(geometry.uvs, 2));
  60164. }
  60165. // Create materials
  60166. var createdMaterials = [];
  60167. for (var mi = 0, miLen = materials.length; mi < miLen; mi++) {
  60168. var sourceMaterial = materials[mi];
  60169. var materialHash = sourceMaterial.name + '_' + sourceMaterial.smooth + '_' + hasVertexColors;
  60170. var material = state.materials[materialHash];
  60171. if (this.materials !== null) {
  60172. material = this.materials.create(sourceMaterial.name);
  60173. // mtl etc. loaders probably can't create line materials correctly, copy properties to a line material.
  60174. if (isLine && material && !(material instanceof LineBasicMaterial)) {
  60175. var materialLine = new LineBasicMaterial();
  60176. Material.prototype.copy.call(materialLine, material);
  60177. materialLine.color.copy(material.color);
  60178. material = materialLine;
  60179. } else if (isPoints && material && !(material instanceof PointsMaterial)) {
  60180. var materialPoints = new PointsMaterial({
  60181. size: 10,
  60182. sizeAttenuation: false
  60183. });
  60184. Material.prototype.copy.call(materialPoints, material);
  60185. materialPoints.color.copy(material.color);
  60186. materialPoints.map = material.map;
  60187. material = materialPoints;
  60188. }
  60189. }
  60190. if (material === undefined) {
  60191. if (isLine) {
  60192. material = new LineBasicMaterial();
  60193. } else if (isPoints) {
  60194. material = new PointsMaterial({
  60195. size: 1,
  60196. sizeAttenuation: false
  60197. });
  60198. } else {
  60199. material = new MeshPhongMaterial();
  60200. }
  60201. material.name = sourceMaterial.name;
  60202. material.flatShading = sourceMaterial.smooth ? false : true;
  60203. material.vertexColors = hasVertexColors;
  60204. state.materials[materialHash] = material;
  60205. }
  60206. createdMaterials.push(material);
  60207. }
  60208. // Create mesh
  60209. var mesh;
  60210. if (createdMaterials.length > 1) {
  60211. for (var mi = 0, miLen = materials.length; mi < miLen; mi++) {
  60212. var sourceMaterial = materials[mi];
  60213. buffergeometry.addGroup(sourceMaterial.groupStart, sourceMaterial.groupCount, mi);
  60214. }
  60215. if (isLine) {
  60216. mesh = new LineSegments(buffergeometry, createdMaterials);
  60217. } else if (isPoints) {
  60218. mesh = new Points(buffergeometry, createdMaterials);
  60219. } else {
  60220. mesh = new Mesh(buffergeometry, createdMaterials);
  60221. }
  60222. } else {
  60223. if (isLine) {
  60224. mesh = new LineSegments(buffergeometry, createdMaterials[0]);
  60225. } else if (isPoints) {
  60226. mesh = new Points(buffergeometry, createdMaterials[0]);
  60227. } else {
  60228. mesh = new Mesh(buffergeometry, createdMaterials[0]);
  60229. }
  60230. }
  60231. mesh.name = object.name;
  60232. container.add(mesh);
  60233. }
  60234. } else {
  60235. // if there is only the default parser state object with no geometry data, interpret data as point cloud
  60236. if (state.vertices.length > 0) {
  60237. var material = new PointsMaterial({
  60238. size: 1,
  60239. sizeAttenuation: false
  60240. });
  60241. var buffergeometry = new BufferGeometry();
  60242. buffergeometry.setAttribute('position', new Float32BufferAttribute(state.vertices, 3));
  60243. if (state.colors.length > 0 && state.colors[0] !== undefined) {
  60244. buffergeometry.setAttribute('color', new Float32BufferAttribute(state.colors, 3));
  60245. material.vertexColors = true;
  60246. }
  60247. var points = new Points(buffergeometry, material);
  60248. container.add(points);
  60249. }
  60250. }
  60251. return container;
  60252. }
  60253. });
  60254. return OBJLoader;
  60255. }();
  60256. /**
  60257. * Loads a Wavefront .mtl file specifying materials
  60258. */
  60259. var MTLLoader = function MTLLoader(manager) {
  60260. Loader.call(this, manager);
  60261. };
  60262. MTLLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  60263. constructor: MTLLoader,
  60264. /**
  60265. * Loads and parses a MTL asset from a URL.
  60266. *
  60267. * @param {String} url - URL to the MTL file.
  60268. * @param {Function} [onLoad] - Callback invoked with the loaded object.
  60269. * @param {Function} [onProgress] - Callback for download progress.
  60270. * @param {Function} [onError] - Callback for download errors.
  60271. *
  60272. * @see setPath setResourcePath
  60273. *
  60274. * @note In order for relative texture references to resolve correctly
  60275. * you must call setResourcePath() explicitly prior to load.
  60276. */
  60277. load: function load(url, onLoad, onProgress, onError) {
  60278. var scope = this;
  60279. var path = this.path === '' ? LoaderUtils.extractUrlBase(url) : this.path;
  60280. var loader = new FileLoader(this.manager);
  60281. loader.setPath(this.path);
  60282. loader.setRequestHeader(this.requestHeader);
  60283. loader.setWithCredentials(this.withCredentials);
  60284. loader.load(url, function (text) {
  60285. try {
  60286. onLoad(scope.parse(text, path));
  60287. } catch (e) {
  60288. if (onError) {
  60289. onError(e);
  60290. } else {
  60291. console.error(e);
  60292. }
  60293. scope.manager.itemError(url);
  60294. }
  60295. }, onProgress, onError);
  60296. },
  60297. setMaterialOptions: function setMaterialOptions(value) {
  60298. this.materialOptions = value;
  60299. return this;
  60300. },
  60301. /**
  60302. * Parses a MTL file.
  60303. *
  60304. * @param {String} text - Content of MTL file
  60305. * @return {MTLLoader.MaterialCreator}
  60306. *
  60307. * @see setPath setResourcePath
  60308. *
  60309. * @note In order for relative texture references to resolve correctly
  60310. * you must call setResourcePath() explicitly prior to parse.
  60311. */
  60312. parse: function parse(text, path) {
  60313. var lines = text.split('\n');
  60314. var info = {};
  60315. var delimiter_pattern = /\s+/;
  60316. var materialsInfo = {};
  60317. for (var i = 0; i < lines.length; i++) {
  60318. var line = lines[i];
  60319. line = line.trim();
  60320. if (line.length === 0 || line.charAt(0) === '#') {
  60321. // Blank line or comment ignore
  60322. continue;
  60323. }
  60324. var pos = line.indexOf(' ');
  60325. var key = pos >= 0 ? line.substring(0, pos) : line;
  60326. key = key.toLowerCase();
  60327. var value = pos >= 0 ? line.substring(pos + 1) : '';
  60328. value = value.trim();
  60329. if (key === 'newmtl') {
  60330. // New material
  60331. info = {
  60332. name: value
  60333. };
  60334. materialsInfo[value] = info;
  60335. } else {
  60336. if (key === 'ka' || key === 'kd' || key === 'ks' || key === 'ke') {
  60337. var ss = value.split(delimiter_pattern, 3);
  60338. info[key] = [parseFloat(ss[0]), parseFloat(ss[1]), parseFloat(ss[2])];
  60339. } else {
  60340. info[key] = value;
  60341. }
  60342. }
  60343. }
  60344. var materialCreator = new MTLLoader.MaterialCreator(this.resourcePath || path, this.materialOptions);
  60345. materialCreator.setCrossOrigin(this.crossOrigin);
  60346. materialCreator.setManager(this.manager);
  60347. materialCreator.setMaterials(materialsInfo);
  60348. return materialCreator;
  60349. }
  60350. });
  60351. /**
  60352. * Create a new MTLLoader.MaterialCreator
  60353. * @param baseUrl - Url relative to which textures are loaded
  60354. * @param options - Set of options on how to construct the materials
  60355. * side: Which side to apply the material
  60356. * FrontSide (default), THREE.BackSide, THREE.DoubleSide
  60357. * wrap: What type of wrapping to apply for textures
  60358. * RepeatWrapping (default), THREE.ClampToEdgeWrapping, THREE.MirroredRepeatWrapping
  60359. * normalizeRGB: RGBs need to be normalized to 0-1 from 0-255
  60360. * Default: false, assumed to be already normalized
  60361. * ignoreZeroRGBs: Ignore values of RGBs (Ka,Kd,Ks) that are all 0's
  60362. * Default: false
  60363. * @constructor
  60364. */
  60365. MTLLoader.MaterialCreator = function (baseUrl, options) {
  60366. this.baseUrl = baseUrl || '';
  60367. this.options = options;
  60368. this.materialsInfo = {};
  60369. this.materials = {};
  60370. this.materialsArray = [];
  60371. this.nameLookup = {};
  60372. this.side = this.options && this.options.side ? this.options.side : FrontSide;
  60373. this.wrap = this.options && this.options.wrap ? this.options.wrap : RepeatWrapping;
  60374. };
  60375. MTLLoader.MaterialCreator.prototype = {
  60376. constructor: MTLLoader.MaterialCreator,
  60377. crossOrigin: 'anonymous',
  60378. setCrossOrigin: function setCrossOrigin(value) {
  60379. this.crossOrigin = value;
  60380. return this;
  60381. },
  60382. setManager: function setManager(value) {
  60383. this.manager = value;
  60384. },
  60385. setMaterials: function setMaterials(materialsInfo) {
  60386. this.materialsInfo = this.convert(materialsInfo);
  60387. this.materials = {};
  60388. this.materialsArray = [];
  60389. this.nameLookup = {};
  60390. },
  60391. convert: function convert(materialsInfo) {
  60392. if (!this.options) return materialsInfo;
  60393. var converted = {};
  60394. for (var mn in materialsInfo) {
  60395. // Convert materials info into normalized form based on options
  60396. var mat = materialsInfo[mn];
  60397. var covmat = {};
  60398. converted[mn] = covmat;
  60399. for (var prop in mat) {
  60400. var save = true;
  60401. var value = mat[prop];
  60402. var lprop = prop.toLowerCase();
  60403. switch (lprop) {
  60404. case 'kd':
  60405. case 'ka':
  60406. case 'ks':
  60407. // Diffuse color (color under white light) using RGB values
  60408. if (this.options && this.options.normalizeRGB) {
  60409. value = [value[0] / 255, value[1] / 255, value[2] / 255];
  60410. }
  60411. if (this.options && this.options.ignoreZeroRGBs) {
  60412. if (value[0] === 0 && value[1] === 0 && value[2] === 0) {
  60413. // ignore
  60414. save = false;
  60415. }
  60416. }
  60417. break;
  60418. default:
  60419. break;
  60420. }
  60421. if (save) {
  60422. covmat[lprop] = value;
  60423. }
  60424. }
  60425. }
  60426. return converted;
  60427. },
  60428. preload: function preload() {
  60429. for (var mn in this.materialsInfo) {
  60430. this.create(mn);
  60431. }
  60432. },
  60433. getIndex: function getIndex(materialName) {
  60434. return this.nameLookup[materialName];
  60435. },
  60436. getAsArray: function getAsArray() {
  60437. var index = 0;
  60438. for (var mn in this.materialsInfo) {
  60439. this.materialsArray[index] = this.create(mn);
  60440. this.nameLookup[mn] = index;
  60441. index++;
  60442. }
  60443. return this.materialsArray;
  60444. },
  60445. create: function create(materialName) {
  60446. if (this.materials[materialName] === undefined) {
  60447. this.createMaterial_(materialName);
  60448. }
  60449. return this.materials[materialName];
  60450. },
  60451. createMaterial_: function createMaterial_(materialName) {
  60452. // Create material
  60453. var scope = this;
  60454. var mat = this.materialsInfo[materialName];
  60455. var params = {
  60456. name: materialName,
  60457. side: this.side
  60458. };
  60459. function resolveURL(baseUrl, url) {
  60460. if (typeof url !== 'string' || url === '') return '';
  60461. // Absolute URL
  60462. if (/^https?:\/\//i.test(url)) return url;
  60463. return baseUrl + url;
  60464. }
  60465. function setMapForType(mapType, value) {
  60466. if (params[mapType]) return; // Keep the first encountered texture
  60467. var texParams = scope.getTextureParams(value, params);
  60468. var map = scope.loadTexture(resolveURL(scope.baseUrl, texParams.url));
  60469. map.repeat.copy(texParams.scale);
  60470. map.offset.copy(texParams.offset);
  60471. map.wrapS = scope.wrap;
  60472. map.wrapT = scope.wrap;
  60473. params[mapType] = map;
  60474. }
  60475. for (var prop in mat) {
  60476. var value = mat[prop];
  60477. var n;
  60478. if (value === '') continue;
  60479. switch (prop.toLowerCase()) {
  60480. // Ns is material specular exponent
  60481. case 'kd':
  60482. // Diffuse color (color under white light) using RGB values
  60483. params.color = new Color().fromArray(value);
  60484. break;
  60485. case 'ks':
  60486. // Specular color (color when light is reflected from shiny surface) using RGB values
  60487. //params.specular = new Color().fromArray( value );
  60488. //console.log('specular',value)
  60489. break;
  60490. case 'ke':
  60491. // Emissive using RGB values
  60492. params.emissive = new Color().fromArray(value);
  60493. break;
  60494. case 'map_kd':
  60495. // Diffuse texture map
  60496. setMapForType('map', value);
  60497. break;
  60498. case 'map_ks':
  60499. // Specular map
  60500. setMapForType('specularMap', value);
  60501. break;
  60502. case 'map_ke':
  60503. // Emissive map
  60504. setMapForType('emissiveMap', value);
  60505. break;
  60506. case 'norm':
  60507. setMapForType('normalMap', value);
  60508. break;
  60509. case 'map_bump':
  60510. case 'bump':
  60511. // Bump texture map
  60512. setMapForType('bumpMap', value);
  60513. break;
  60514. case 'map_d':
  60515. // Alpha map
  60516. setMapForType('alphaMap', value);
  60517. params.transparent = true;
  60518. break;
  60519. case 'ns':
  60520. // The specular exponent (defines the focus of the specular highlight)
  60521. // A high exponent results in a tight, concentrated highlight. Ns values normally range from 0 to 1000.
  60522. //params.shininess = parseFloat( value );
  60523. //console.log('shininess',value)
  60524. break;
  60525. case 'd':
  60526. n = parseFloat(value);
  60527. if (n < 1) {
  60528. params.opacity = n;
  60529. params.transparent = true;
  60530. }
  60531. break;
  60532. case 'tr':
  60533. n = parseFloat(value);
  60534. if (this.options && this.options.invertTrProperty) n = 1 - n;
  60535. if (n > 0) {
  60536. params.opacity = 1 - n;
  60537. params.transparent = true;
  60538. }
  60539. break;
  60540. default:
  60541. break;
  60542. }
  60543. }
  60544. this.materials[materialName] = new MeshStandardMaterial(params); //MeshPhongMaterial( params );
  60545. return this.materials[materialName];
  60546. },
  60547. getTextureParams: function getTextureParams(value, matParams) {
  60548. var texParams = {
  60549. scale: new Vector2(1, 1),
  60550. offset: new Vector2(0, 0)
  60551. };
  60552. var items = value.split(/\s+/);
  60553. var pos;
  60554. pos = items.indexOf('-bm');
  60555. if (pos >= 0) {
  60556. matParams.bumpScale = parseFloat(items[pos + 1]);
  60557. items.splice(pos, 2);
  60558. }
  60559. pos = items.indexOf('-s');
  60560. if (pos >= 0) {
  60561. texParams.scale.set(parseFloat(items[pos + 1]), parseFloat(items[pos + 2]));
  60562. items.splice(pos, 4); // we expect 3 parameters here!
  60563. }
  60564. pos = items.indexOf('-o');
  60565. if (pos >= 0) {
  60566. texParams.offset.set(parseFloat(items[pos + 1]), parseFloat(items[pos + 2]));
  60567. items.splice(pos, 4); // we expect 3 parameters here!
  60568. }
  60569. texParams.url = items.join(' ').trim();
  60570. return texParams;
  60571. },
  60572. loadTexture: function loadTexture(url, mapping, onLoad, onProgress, onError) {
  60573. var texture;
  60574. var manager = this.manager !== undefined ? this.manager : DefaultLoadingManager;
  60575. var loader = manager.getHandler(url);
  60576. if (loader === null) {
  60577. loader = new TextureLoader(manager);
  60578. }
  60579. if (loader.setCrossOrigin) loader.setCrossOrigin(this.crossOrigin);
  60580. texture = loader.load(url, onLoad, onProgress, onError);
  60581. if (mapping !== undefined) texture.mapping = mapping;
  60582. return texture;
  60583. }
  60584. };
  60585. /**
  60586. * Description: A THREE loader for PLY ASCII files (known as the Polygon
  60587. * File Format or the Stanford Triangle Format).
  60588. *
  60589. * Limitations: ASCII decoding assumes file is UTF-8.
  60590. *
  60591. * Usage:
  60592. * var loader = new PLYLoader();
  60593. * loader.load('./models/ply/ascii/dolphins.ply', function (geometry) {
  60594. *
  60595. * scene.add( new THREE.Mesh( geometry ) );
  60596. *
  60597. * } );
  60598. *
  60599. * If the PLY file uses non standard property names, they can be mapped while
  60600. * loading. For example, the following maps the properties
  60601. * “diffuse_(red|green|blue)” in the file to standard color names.
  60602. *
  60603. * loader.setPropertyNameMapping( {
  60604. * diffuse_red: 'red',
  60605. * diffuse_green: 'green',
  60606. * diffuse_blue: 'blue'
  60607. * } );
  60608. *
  60609. */
  60610. var PLYLoader = function PLYLoader(manager) {
  60611. Loader.call(this, manager);
  60612. this.propertyNameMapping = {};
  60613. };
  60614. PLYLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  60615. constructor: PLYLoader,
  60616. load: function load(url, onLoad, onProgress, onError) {
  60617. var scope = this;
  60618. var loader = new FileLoader(this.manager);
  60619. loader.setPath(this.path);
  60620. loader.setResponseType('arraybuffer');
  60621. loader.setRequestHeader(this.requestHeader);
  60622. loader.setWithCredentials(this.withCredentials);
  60623. loader.load(url, function (text) {
  60624. try {
  60625. onLoad(scope.parse(text));
  60626. } catch (e) {
  60627. if (onError) {
  60628. onError(e);
  60629. } else {
  60630. console.error(e);
  60631. }
  60632. scope.manager.itemError(url);
  60633. }
  60634. }, onProgress, onError);
  60635. },
  60636. setPropertyNameMapping: function setPropertyNameMapping(mapping) {
  60637. this.propertyNameMapping = mapping;
  60638. },
  60639. parse: function parse(data) {
  60640. function parseHeader(data) {
  60641. var patternHeader = /ply([\s\S]*)end_header\r?\n/;
  60642. var headerText = '';
  60643. var headerLength = 0;
  60644. var result = patternHeader.exec(data);
  60645. if (result !== null) {
  60646. headerText = result[1];
  60647. headerLength = new Blob([result[0]]).size;
  60648. }
  60649. var header = {
  60650. comments: [],
  60651. elements: [],
  60652. headerLength: headerLength,
  60653. objInfo: ''
  60654. };
  60655. var lines = headerText.split('\n');
  60656. var currentElement;
  60657. var lineType, lineValues;
  60658. function make_ply_element_property(propertValues, propertyNameMapping) {
  60659. var property = {
  60660. type: propertValues[0]
  60661. };
  60662. if (property.type === 'list') {
  60663. property.name = propertValues[3];
  60664. property.countType = propertValues[1];
  60665. property.itemType = propertValues[2];
  60666. } else {
  60667. property.name = propertValues[1];
  60668. }
  60669. if (property.name in propertyNameMapping) {
  60670. property.name = propertyNameMapping[property.name];
  60671. }
  60672. return property;
  60673. }
  60674. for (var i = 0; i < lines.length; i++) {
  60675. var line = lines[i];
  60676. line = line.trim();
  60677. if (line === '') continue;
  60678. lineValues = line.split(/\s+/);
  60679. lineType = lineValues.shift();
  60680. line = lineValues.join(' ');
  60681. switch (lineType) {
  60682. case 'format':
  60683. header.format = lineValues[0];
  60684. header.version = lineValues[1];
  60685. break;
  60686. case 'comment':
  60687. header.comments.push(line);
  60688. break;
  60689. case 'element':
  60690. if (currentElement !== undefined) {
  60691. header.elements.push(currentElement);
  60692. }
  60693. currentElement = {};
  60694. currentElement.name = lineValues[0];
  60695. currentElement.count = parseInt(lineValues[1]);
  60696. currentElement.properties = [];
  60697. break;
  60698. case 'property':
  60699. currentElement.properties.push(make_ply_element_property(lineValues, scope.propertyNameMapping));
  60700. break;
  60701. case 'obj_info':
  60702. header.objInfo = line;
  60703. break;
  60704. default:
  60705. console.log('unhandled', lineType, lineValues);
  60706. }
  60707. }
  60708. if (currentElement !== undefined) {
  60709. header.elements.push(currentElement);
  60710. }
  60711. return header;
  60712. }
  60713. function parseASCIINumber(n, type) {
  60714. switch (type) {
  60715. case 'char':
  60716. case 'uchar':
  60717. case 'short':
  60718. case 'ushort':
  60719. case 'int':
  60720. case 'uint':
  60721. case 'int8':
  60722. case 'uint8':
  60723. case 'int16':
  60724. case 'uint16':
  60725. case 'int32':
  60726. case 'uint32':
  60727. return parseInt(n);
  60728. case 'float':
  60729. case 'double':
  60730. case 'float32':
  60731. case 'float64':
  60732. return parseFloat(n);
  60733. }
  60734. }
  60735. function parseASCIIElement(properties, line) {
  60736. var values = line.split(/\s+/);
  60737. var element = {};
  60738. for (var i = 0; i < properties.length; i++) {
  60739. if (properties[i].type === 'list') {
  60740. var list = [];
  60741. var n = parseASCIINumber(values.shift(), properties[i].countType);
  60742. for (var j = 0; j < n; j++) {
  60743. list.push(parseASCIINumber(values.shift(), properties[i].itemType));
  60744. }
  60745. element[properties[i].name] = list;
  60746. } else {
  60747. element[properties[i].name] = parseASCIINumber(values.shift(), properties[i].type);
  60748. }
  60749. }
  60750. return element;
  60751. }
  60752. function parseASCII(data, header) {
  60753. // PLY ascii format specification, as per http://en.wikipedia.org/wiki/PLY_(file_format)
  60754. var buffer = {
  60755. indices: [],
  60756. vertices: [],
  60757. normals: [],
  60758. uvs: [],
  60759. faceVertexUvs: [],
  60760. colors: []
  60761. };
  60762. var result;
  60763. var patternBody = /end_header\s([\s\S]*)$/;
  60764. var body = '';
  60765. if ((result = patternBody.exec(data)) !== null) {
  60766. body = result[1];
  60767. }
  60768. var lines = body.split('\n');
  60769. var currentElement = 0;
  60770. var currentElementCount = 0;
  60771. for (var i = 0; i < lines.length; i++) {
  60772. var line = lines[i];
  60773. line = line.trim();
  60774. if (line === '') {
  60775. continue;
  60776. }
  60777. if (currentElementCount >= header.elements[currentElement].count) {
  60778. currentElement++;
  60779. currentElementCount = 0;
  60780. }
  60781. var element = parseASCIIElement(header.elements[currentElement].properties, line);
  60782. handleElement(buffer, header.elements[currentElement].name, element);
  60783. currentElementCount++;
  60784. }
  60785. return postProcess(buffer);
  60786. }
  60787. function postProcess(buffer) {
  60788. var geometry = new BufferGeometry();
  60789. // mandatory buffer data
  60790. if (buffer.indices.length > 0) {
  60791. geometry.setIndex(buffer.indices);
  60792. }
  60793. geometry.setAttribute('position', new Float32BufferAttribute(buffer.vertices, 3));
  60794. // optional buffer data
  60795. if (buffer.normals.length > 0) {
  60796. geometry.setAttribute('normal', new Float32BufferAttribute(buffer.normals, 3));
  60797. }
  60798. if (buffer.uvs.length > 0) {
  60799. geometry.setAttribute('uv', new Float32BufferAttribute(buffer.uvs, 2));
  60800. }
  60801. if (buffer.colors.length > 0) {
  60802. geometry.setAttribute('color', new Float32BufferAttribute(buffer.colors, 3));
  60803. }
  60804. if (buffer.faceVertexUvs.length > 0) {
  60805. geometry = geometry.toNonIndexed();
  60806. geometry.setAttribute('uv', new Float32BufferAttribute(buffer.faceVertexUvs, 2));
  60807. }
  60808. geometry.computeBoundingSphere();
  60809. return geometry;
  60810. }
  60811. function handleElement(buffer, elementName, element) {
  60812. if (elementName === 'vertex') {
  60813. buffer.vertices.push(element.x, element.y, element.z);
  60814. if ('nx' in element && 'ny' in element && 'nz' in element) {
  60815. buffer.normals.push(element.nx, element.ny, element.nz);
  60816. }
  60817. if ('s' in element && 't' in element) {
  60818. buffer.uvs.push(element.s, element.t);
  60819. }
  60820. if ('red' in element && 'green' in element && 'blue' in element) {
  60821. buffer.colors.push(element.red / 255.0, element.green / 255.0, element.blue / 255.0);
  60822. }
  60823. } else if (elementName === 'face') {
  60824. var vertex_indices = element.vertex_indices || element.vertex_index; // issue #9338
  60825. var texcoord = element.texcoord;
  60826. if (vertex_indices.length === 3) {
  60827. buffer.indices.push(vertex_indices[0], vertex_indices[1], vertex_indices[2]);
  60828. if (texcoord && texcoord.length === 6) {
  60829. buffer.faceVertexUvs.push(texcoord[0], texcoord[1]);
  60830. buffer.faceVertexUvs.push(texcoord[2], texcoord[3]);
  60831. buffer.faceVertexUvs.push(texcoord[4], texcoord[5]);
  60832. }
  60833. } else if (vertex_indices.length === 4) {
  60834. buffer.indices.push(vertex_indices[0], vertex_indices[1], vertex_indices[3]);
  60835. buffer.indices.push(vertex_indices[1], vertex_indices[2], vertex_indices[3]);
  60836. }
  60837. }
  60838. }
  60839. function binaryRead(dataview, at, type, little_endian) {
  60840. switch (type) {
  60841. // corespondences for non-specific length types here match rply:
  60842. case 'int8':
  60843. case 'char':
  60844. return [dataview.getInt8(at), 1];
  60845. case 'uint8':
  60846. case 'uchar':
  60847. return [dataview.getUint8(at), 1];
  60848. case 'int16':
  60849. case 'short':
  60850. return [dataview.getInt16(at, little_endian), 2];
  60851. case 'uint16':
  60852. case 'ushort':
  60853. return [dataview.getUint16(at, little_endian), 2];
  60854. case 'int32':
  60855. case 'int':
  60856. return [dataview.getInt32(at, little_endian), 4];
  60857. case 'uint32':
  60858. case 'uint':
  60859. return [dataview.getUint32(at, little_endian), 4];
  60860. case 'float32':
  60861. case 'float':
  60862. return [dataview.getFloat32(at, little_endian), 4];
  60863. case 'float64':
  60864. case 'double':
  60865. return [dataview.getFloat64(at, little_endian), 8];
  60866. }
  60867. }
  60868. function binaryReadElement(dataview, at, properties, little_endian) {
  60869. var element = {};
  60870. var result,
  60871. read = 0;
  60872. for (var i = 0; i < properties.length; i++) {
  60873. if (properties[i].type === 'list') {
  60874. var list = [];
  60875. result = binaryRead(dataview, at + read, properties[i].countType, little_endian);
  60876. var n = result[0];
  60877. read += result[1];
  60878. for (var j = 0; j < n; j++) {
  60879. result = binaryRead(dataview, at + read, properties[i].itemType, little_endian);
  60880. list.push(result[0]);
  60881. read += result[1];
  60882. }
  60883. element[properties[i].name] = list;
  60884. } else {
  60885. result = binaryRead(dataview, at + read, properties[i].type, little_endian);
  60886. element[properties[i].name] = result[0];
  60887. read += result[1];
  60888. }
  60889. }
  60890. return [element, read];
  60891. }
  60892. function parseBinary(data, header) {
  60893. var buffer = {
  60894. indices: [],
  60895. vertices: [],
  60896. normals: [],
  60897. uvs: [],
  60898. faceVertexUvs: [],
  60899. colors: []
  60900. };
  60901. var little_endian = header.format === 'binary_little_endian';
  60902. var body = new DataView(data, header.headerLength);
  60903. var result,
  60904. loc = 0;
  60905. for (var currentElement = 0; currentElement < header.elements.length; currentElement++) {
  60906. for (var currentElementCount = 0; currentElementCount < header.elements[currentElement].count; currentElementCount++) {
  60907. result = binaryReadElement(body, loc, header.elements[currentElement].properties, little_endian);
  60908. loc += result[1];
  60909. var element = result[0];
  60910. handleElement(buffer, header.elements[currentElement].name, element);
  60911. }
  60912. }
  60913. return postProcess(buffer);
  60914. }
  60915. //
  60916. var geometry;
  60917. var scope = this;
  60918. if (data instanceof ArrayBuffer) {
  60919. var text = LoaderUtils.decodeText(new Uint8Array(data));
  60920. var header = parseHeader(text);
  60921. geometry = header.format === 'ascii' ? parseASCII(text, header) : parseBinary(data, header);
  60922. } else {
  60923. geometry = parseASCII(data, parseHeader(data));
  60924. }
  60925. return geometry;
  60926. }
  60927. });
  60928. var renderOrders = {
  60929. line: 0,
  60930. spot: 15 //高过模型
  60931. };
  60932. var planeGeo$2 = new PlaneGeometry(1, 1);
  60933. var texLoader$7 = new TextureLoader();
  60934. var lineMat = new LineBasicMaterial({
  60935. color: '#ffffff'
  60936. });
  60937. var spotMat;
  60938. var defaultLineLength = 0.6;
  60939. var defaultSpotScale = 0.4;
  60940. class Tag extends Object3D {
  60941. constructor(o) {
  60942. super();
  60943. this.lineLength = o.lineLength != void 0 ? o.lineLength : defaultLineLength;
  60944. this.position.copy(o.position);
  60945. this.normal = o.normal != void 0 ? o.normal : new Vector3(0, 0, -1);
  60946. this.root = o.root;
  60947. //this.matrixAutoUpdate = false
  60948. this.build();
  60949. /* this.spot.addEventListener('mouseover',()=>{
  60950. }) */
  60951. }
  60952. build() {
  60953. if (!spotMat) {
  60954. spotMat = new MeshBasicMaterial({
  60955. transparent: true,
  60956. map: texLoader$7.load(Potree.resourcePath + '/textures/spot_default.png')
  60957. });
  60958. }
  60959. var endPos = this.normal.clone().multiplyScalar(this.lineLength);
  60960. this.line = LineDraw.createLine([new Vector3(0, 0, 0), endPos], {
  60961. mat: lineMat
  60962. });
  60963. var group = new Object3D();
  60964. this.spot = new Mesh(planeGeo$2, spotMat);
  60965. this.spot.scale.set(defaultSpotScale, defaultSpotScale, defaultSpotScale);
  60966. this.titleLabel = new TextSprite$2({
  60967. root: group,
  60968. text: '1',
  60969. sizeInfo: {
  60970. width2d: 200
  60971. },
  60972. textColor: {
  60973. r: 255,
  60974. g: 255,
  60975. b: 255,
  60976. a: 1.0
  60977. },
  60978. backgroundColor: {
  60979. r: 0,
  60980. g: 0,
  60981. b: 0,
  60982. a: 0.8
  60983. },
  60984. borderRadius: 6,
  60985. fontsize: 13,
  60986. fontWeight: '',
  60987. //thick
  60988. renderOrder: renderOrders.spot,
  60989. pickOrder: renderOrders.spot
  60990. }); //更新sprite时,实际更新的是root: spot的矩阵
  60991. this.spot.renderOrder = renderOrders.spot;
  60992. /* const mainLabelProp = {
  60993. backgroundColor: {r: defaultColor.r*255, g: defaultColor.g*255, b: defaultColor.b*255, a:config.measure.default.opacity},
  60994. textColor: {r: textColor.r*255, g: textColor.g*255, b: textColor.b*255, a: 1.0},
  60995. fontsize:16,
  60996. useDepth : true ,
  60997. renderOrder : 5, pickOrder:5,
  60998. } */
  60999. this.titleLabel.position.set(0, 0.4, 0);
  61000. this.titleLabel.sprite.material.depthTest = this.titleLabel.sprite.material.depthWrite = true;
  61001. group.position.copy(endPos);
  61002. group.add(this.spot);
  61003. group.add(this.titleLabel);
  61004. this.add(group);
  61005. this.add(this.line);
  61006. viewer.scene.tags.add(this);
  61007. }
  61008. changeTitle(title) {
  61009. this.titleLabel.changeText(title);
  61010. }
  61011. updateMatrixWorld(force) {
  61012. //重写,只为了将root当做parent
  61013. this.updateMatrix();
  61014. this.matrixWorld.multiplyMatrices(this.root.matrixWorld, this.matrix);
  61015. var children = this.children;
  61016. for (var i = 0, l = children.length; i < l; i++) {
  61017. children[i].updateMatrixWorld(force);
  61018. }
  61019. }
  61020. updateWorldMatrix(updateParents, updateChildren) {
  61021. //重写,只为了将root当做parent
  61022. if (updateParents === true && this.root !== null) {
  61023. this.root.updateWorldMatrix(true, false);
  61024. }
  61025. if (this.matrixAutoUpdate) this.updateMatrix();
  61026. this.matrixWorld.multiplyMatrices(this.root.matrixWorld, this.matrix);
  61027. if (updateChildren === true) {
  61028. var children = this.children;
  61029. for (var i = 0, l = children.length; i < l; i++) {
  61030. children[i].updateWorldMatrix(false, true);
  61031. }
  61032. }
  61033. }
  61034. dispose() {
  61035. this.parent.remove(this);
  61036. this.titleLabel.dispose();
  61037. }
  61038. }
  61039. class TagTool extends EventDispatcher {
  61040. constructor(viewer) {
  61041. super();
  61042. this.viewer = viewer;
  61043. this.viewer.addEventListener('start_inserting_tag', e => {
  61044. this.viewer.dispatchEvent({
  61045. type: 'cancel_insertions'
  61046. });
  61047. });
  61048. }
  61049. createTagFromData(data) {
  61050. var tag = new Tag({
  61051. title: data.title,
  61052. position: data.position,
  61053. normal: data.normal,
  61054. root: data.root //e.intersect.pointcloud || e.intersect.object
  61055. });
  61056. return tag;
  61057. }
  61058. startInsertion() {
  61059. var args = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  61060. var callback = arguments.length > 1 ? arguments[1] : undefined;
  61061. var cancelFun = arguments.length > 2 ? arguments[2] : undefined;
  61062. var deferred = $.Deferred();
  61063. this.viewer.dispatchEvent({
  61064. type: 'start_inserting_tag'
  61065. });
  61066. this.adding = true;
  61067. var cancel = () => {
  61068. end();
  61069. };
  61070. var end = () => {
  61071. this.adding = false;
  61072. viewer.dispatchEvent({
  61073. type: "endTagMove"
  61074. });
  61075. this.viewer.removeEventListener('global_click', click);
  61076. };
  61077. var click = e => {
  61078. var worldPos = e.intersect && ( /* e.intersect.orthoIntersect || */e.intersect.location);
  61079. if (!worldPos) {
  61080. return;
  61081. }
  61082. var localPos = Potree.Utils.datasetPosTransform({
  61083. toDataset: true,
  61084. pointcloud: e.intersect.pointcloud,
  61085. object: e.intersect.object,
  61086. position: worldPos
  61087. });
  61088. var tag = new Tag({
  61089. title: '1',
  61090. position: localPos,
  61091. normal: e.intersect.normal,
  61092. root: e.intersect.pointcloud || e.intersect.object
  61093. });
  61094. //pointcloud里加一个normal 的非float32
  61095. end();
  61096. e.consume && e.consume();
  61097. deferred.resolve(tag);
  61098. return {
  61099. stopContinue: true
  61100. };
  61101. };
  61102. this.viewer.addEventListener('global_click', click, {
  61103. importance: 10
  61104. });
  61105. return deferred.promise();
  61106. }
  61107. }
  61108. var initDir = new Vector3(0, 1, 0); //指南针模型的北方向 向屏幕里
  61109. class Compass extends EventDispatcher {
  61110. constructor(dom, viewport) {
  61111. super();
  61112. this.angle = 0;
  61113. this.show = false;
  61114. if (dom) {
  61115. this.dom = $(dom);
  61116. }
  61117. this.viewport = viewport;
  61118. this.init();
  61119. }
  61120. init() {
  61121. var width = 100,
  61122. height = 100;
  61123. if (!this.dom) {
  61124. this.dom = $('<div name="compass"></div>');
  61125. $(viewer.renderArea).append(this.dom);
  61126. }
  61127. this.dom.css({
  61128. display: "none",
  61129. position: "absolute",
  61130. right: "1%",
  61131. top: "60px",
  61132. width: width + "px",
  61133. height: height + "px",
  61134. "z-index": 100,
  61135. "pointer-events": "none"
  61136. });
  61137. var child = $("<div class='dirText north'><span>" + /* (config.lang=='zh'? */'北' /* :'N') */ + "</span></div><div class='center'></div>");
  61138. this.dom.append(child);
  61139. this.dom.find(".dirText").css({
  61140. textAlign: "center",
  61141. "font-size": "10px",
  61142. "position": "absolute",
  61143. width: "100%",
  61144. height: "25px",
  61145. "line-height": "25px"
  61146. });
  61147. this.dom.find(".north").css({
  61148. "color": "#02a0e9",
  61149. "top": "0"
  61150. });
  61151. this.dom.find(".south").css({
  61152. "color": "#ff1414",
  61153. "bottom": "0"
  61154. });
  61155. this.dom.find(".center").css({
  61156. //"background":`url(${config.getStaticResource('img')}/dire.png)`,
  61157. width: width / 2 + "px",
  61158. height: height / 2 + "px",
  61159. "background-size": "contain",
  61160. "background-position": "center",
  61161. left: "50%",
  61162. top: "50%",
  61163. transform: "translate(-50%,-50%)",
  61164. position: "absolute"
  61165. });
  61166. this.dom.find(".dirText").css({
  61167. "text-align": "center",
  61168. "font-size": "10px",
  61169. "color": "rgb(255, 255, 255)",
  61170. "position": "absolute",
  61171. "top": "50%",
  61172. "left": "50%",
  61173. "width": "45%",
  61174. "height": "0px",
  61175. "transform-origin": "left center"
  61176. });
  61177. this.dom.find(".dirText span").css({
  61178. display: "block",
  61179. position: "absolute",
  61180. right: "5px",
  61181. top: "0",
  61182. width: "20px",
  61183. height: "20px",
  61184. "line-height": "20px",
  61185. // "font-size": ".75rem ",
  61186. "margin-top": "-10px"
  61187. });
  61188. try {
  61189. this.renderer = new WebGLRenderer({
  61190. antialias: true,
  61191. alpha: true
  61192. }); //许钟文 添加个抗锯齿,否则添加的线条锯齿严重,
  61193. this.renderer.autoClear = !0;
  61194. this.renderer.setPixelRatio(window.devicePixelRatio ? window.devicePixelRatio : 1);
  61195. this.renderer.domElement.setAttribute('name', 'compass');
  61196. this.renderer.setClearAlpha(0.0);
  61197. //xst修改
  61198. //this.renderer.setSize(width/2, height/2, false, window.devicePixelRatio ? window.devicePixelRatio : 1);
  61199. //xst修改
  61200. //this.renderer.setPixelRatio(window.devicePixelRatio ? window.devicePixelRatio : 1);
  61201. //this.renderer.setSize(width/2, height/2);
  61202. //xst修改
  61203. this.renderer.setDrawingBufferSize(width / 2, height / 2, window.devicePixelRatio ? window.devicePixelRatio : 1);
  61204. //this.emit(SceneRendererEvents.ContextCreated)
  61205. } catch (e) {
  61206. viewer.dispatchEvent('webglError', {
  61207. msg: e
  61208. });
  61209. }
  61210. this.dom.find(".center")[0].appendChild(this.renderer.domElement);
  61211. this.renderer.domElement.style.width = this.renderer.domElement.style.height = '100%';
  61212. this.camera = new PerspectiveCamera();
  61213. this.camera.fov = 50;
  61214. this.camera.updateProjectionMatrix();
  61215. this.scene = new Scene(), this.scene.add(this.camera);
  61216. this.createCompass();
  61217. viewer.addEventListener('camera_changed', e => {
  61218. if (e.viewport == this.viewport && e.changeInfo.quaternionChanged /* || e.changeInfo.quaternionChanged */) {
  61219. this.update();
  61220. }
  61221. });
  61222. this.setDomPos();
  61223. if (this.viewport) this.setDisplay(true);
  61224. }
  61225. createCompass() {
  61226. //ConeBufferGeometry(radius : Float, height : Float, radialSegments : Integer, heightSegments : Integer, openEnded : Boolean, thetaStart : Float, thetaLength : Float)
  61227. var height = 2;
  61228. var geometry1 = new ConeBufferGeometry(0.7, height, 4, true);
  61229. var geometry2 = new ConeBufferGeometry(0.7, height, 4, true);
  61230. var material = new MeshBasicMaterial({
  61231. vertexColors: true
  61232. });
  61233. //指南针由两个四棱锥拼成,为了渐变颜色,采用指定vertexColor的方式。
  61234. var setColor = function setColor(geometry, color1, color2) {
  61235. var colors = [];
  61236. for (var i = 0, n = geometry.attributes.position.count; i < n; ++i) {
  61237. colors.push(1, 1, 1);
  61238. }
  61239. var set = function set(index, color) {
  61240. //设置第index个点的颜色
  61241. colors[index * 3 + 0] = color[0];
  61242. colors[index * 3 + 1] = color[1];
  61243. colors[index * 3 + 2] = color[2];
  61244. };
  61245. var mid = [(color1[0] + color2[0]) / 2, (color1[1] + color2[1]) / 2, (color1[2] + color2[2]) / 2];
  61246. set(1, color1);
  61247. set(5, color1);
  61248. set(6, color1);
  61249. set(2, mid);
  61250. set(3, mid);
  61251. set(7, mid);
  61252. set(4, color2);
  61253. set(8, color2);
  61254. set(9, color2);
  61255. geometry.setAttribute("color", new BufferAttribute(new Float32Array(colors), 3));
  61256. };
  61257. var blue1 = [1 / 255, 238 / 255, 245 / 255]; //逐渐变深
  61258. var blue2 = [20 / 255, 146 / 255, 170 / 255];
  61259. var blue3 = [40 / 255, 60 / 255, 103 / 255];
  61260. setColor(geometry1, blue1, blue2);
  61261. setColor(geometry2, blue2, blue3);
  61262. /* 朝箭头方向看点构成如下 虽然geometry.attributes.position.count = 19 只有1-9设置的颜色是有效的 另外为什么7决定了上下两边的颜色呢…… 5、9可将其分成上下两个颜色
  61263. 6
  61264. /|\
  61265. / | \
  61266. 7 /_2|1_\ 5
  61267. \ 3|4 / 9
  61268. \ | /
  61269. \|/
  61270. 8
  61271. */
  61272. var cone = new Mesh(geometry1, material);
  61273. cone.position.setY(height / 2);
  61274. geometry1.computeVertexNormals(); //computeFaceNormals
  61275. geometry2.computeVertexNormals();
  61276. var cones = new Object3D();
  61277. cones.add(cone);
  61278. var cone2 = new Mesh(geometry2, material);
  61279. cone2.rotation.x = Math.PI;
  61280. cone2.position.setY(-height / 2);
  61281. cones.add(cone2);
  61282. //cones.rotation.x = Math.PI / 2;//转向initDir的方向
  61283. //cones.rotation.z = Math.PI / 2;
  61284. cones.rotation.z = Math.PI; //转向initDir的方向
  61285. cones.scale.set(0.7, 0.7, 0.7);
  61286. this.scene.add(cones);
  61287. this.cones = cones;
  61288. }
  61289. setNorth() {
  61290. //设置北方向,这决定了指南针自身的朝向。
  61291. var floors = store.getters['scene/houstFloor'].floors;
  61292. if (!floors || !floors.length) {
  61293. return;
  61294. }
  61295. var floor = floors[0];
  61296. var metadata = app.store.getters['scene/metadata'] || {};
  61297. this.angle = (floor && floor.dire || 0) + MathUtils.radToDeg(parseFloat(metadata.floorPlanAngle || 0)); //基础朝向
  61298. this.cones.rotation.y = Math.PI / 2 - MathUtils.degToRad(this.angle);
  61299. //console.log("dir:"+floor.dire+", floorPlanAngle:"+metadata.floorPlanAngle)
  61300. this.update();
  61301. }
  61302. update(quaternion) {
  61303. if (!this.show) return;
  61304. if (!quaternion) quaternion = this.viewport.camera.quaternion.clone();
  61305. this.updateCamera(quaternion);
  61306. this.updateLabel(quaternion);
  61307. this.render();
  61308. }
  61309. /*updateLabel(quaternion){//更新北标签
  61310. var dir = viewer.mainViewport.view.direction;
  61311. var oriDir = initDir.clone() //指南针最初始时的北方向
  61312. var extraQua
  61313. if(objects.player.mode == "transitioning"){//当transitioning时,相机的quaternion不是用control的lookAt算出来,而是直接由一个quaternion过渡到另一个,这样相机将会是歪的,投影面也就不会是原先的水平面。
  61314. var tempCamera = new THREE.Camera(); //借用camera的lookAt算出如果正视同样的target, quaternion会是什么值。 将它乘以当前相机quaternion,得到的就是相机歪的旋转值。
  61315. tempCamera.position.copy(this.camera.position);
  61316. tempCamera.lookAt(tempCamera.position.clone().add(dir))
  61317. var q = tempCamera.quaternion.inverse()
  61318. extraQua = q.premultiply(quaternion) //歪掉的额外旋转值
  61319. }
  61320. //北标签的方向为指南针轮盘方向,也就是要将camera的方向投影到水平面上。 但是如果相机歪了,看到的世界都会歪一定角度,投影面也要歪一定角度。
  61321. var up = new THREE.Vector3(0,0,1) //投影水平面的法线,也是相机的摆正的up方向
  61322. extraQua && up.applyQuaternion(extraQua)
  61323. dir.projectOnPlane(up) //将方向投影到水平面上; 如果相机不是正视(extraQua不为0001),就要将水平面也转动
  61324. oriDir.projectOnPlane(up)//为什么initDir投影了和没有投影angle结果一样
  61325. var angle = dir.angleTo(oriDir)
  61326. if(dir.cross(oriDir).y > 0)angle = -angle
  61327. var deg = this.angle - 90 + THREE.Math.radToDeg(angle) //因为css写的样式初始是指向右方,和initDir差了90°,所以减去。
  61328. this.dom.find(".dirText").css( "transform","rotate("+deg+"deg)" )
  61329. this.dom.find(".dirText span").css("transform","rotate("+(-deg)+"deg)")
  61330. } */
  61331. updateLabel(quaternion) {
  61332. //更新北标签
  61333. var deg = MathUtils.radToDeg(this.viewport.view.yaw) - 90;
  61334. this.dom.find(".dirText").css("transform", "rotate(" + deg + "deg)");
  61335. this.dom.find(".dirText span").css("transform", "rotate(" + -deg + "deg)");
  61336. }
  61337. updateCamera(quaternion) {
  61338. //更新canvas中的指南针表现,也就是更新相机,和场景中的相机朝向一致。
  61339. var radius = 5; //相机距离
  61340. this.camera.quaternion.copy(quaternion);
  61341. var dir = this.viewport.view.direction; //相机朝向
  61342. this.camera.position.copy(dir.multiplyScalar(radius).negate()); //相机绕着指南针中心(000)转动
  61343. }
  61344. changeViewport(viewport) {
  61345. this.viewport = viewport;
  61346. this.update(); //因相机更新了
  61347. }
  61348. render() {
  61349. this.renderer.render(this.scene, this.camera);
  61350. }
  61351. setDisplay(state) {
  61352. this.show = !!state;
  61353. if (this.show) {
  61354. this.update();
  61355. this.dom.fadeIn(100);
  61356. } else {
  61357. this.dom.fadeOut(100);
  61358. }
  61359. }
  61360. setAutoDisplay(state) {
  61361. //被直接改变了dom的显示
  61362. this.autoJudgeShow = state;
  61363. if (state) {
  61364. this._autoDisplayEvent = () => {
  61365. var oldShow = this.show;
  61366. this.show = !!this.renderer.domElement.clientHeight;
  61367. if (oldShow != this.show) {
  61368. this.update();
  61369. }
  61370. };
  61371. viewer.addEventListener('update_start', this._autoDisplayEvent);
  61372. } else {
  61373. viewer.removeEventListener('update_start', this._autoDisplayEvent);
  61374. }
  61375. }
  61376. setDomPos() {
  61377. if (!this.viewport) return;
  61378. var right = this.viewport.left + this.viewport.width;
  61379. this.dom.css({
  61380. 'right': (1 - right) * 100 + 1 + '%'
  61381. });
  61382. }
  61383. }
  61384. class AxisViewer extends ViewerBase {
  61385. constructor(listenViewport, parentArea) {
  61386. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  61387. var domElement = $("<div name=\"Axisdom\" viewport=".concat(listenViewport.name, "></div>"));
  61388. $(parentArea).append(domElement);
  61389. var posInfo = Object.assign({
  61390. //default:
  61391. right: 0,
  61392. top: 0,
  61393. width: '100px',
  61394. height: '100px'
  61395. }, options.domStyle, {
  61396. position: 'absolute'
  61397. });
  61398. if (options.domStyle) {
  61399. if (options.domStyle.bottom != void 0) {
  61400. delete posInfo.top;
  61401. }
  61402. if (options.domStyle.left != void 0) {
  61403. delete posInfo.right;
  61404. }
  61405. }
  61406. domElement.css(posInfo);
  61407. super(domElement[0], {
  61408. name: 'axis',
  61409. antialias: true
  61410. });
  61411. this.listenViewport = listenViewport;
  61412. Object.defineProperty(listenViewport, 'axis', {
  61413. value: this,
  61414. writable: true,
  61415. // 可写(可选)
  61416. enumerable: false,
  61417. // 不可枚举
  61418. configurable: true // 可配置(可选)
  61419. });
  61420. this.scene = new Scene();
  61421. //this.camera = new THREE.PerspectiveCamera(30, 1, 1, this.radius*3);
  61422. var w = 50;
  61423. this.camera = new OrthographicCamera(-w / 2, w / 2, w / 2, -w / 2, 1, w * 4);
  61424. this.camera.zoom = 2.7; //(domElement.clientWidth || 300) / w * 1.267//zoom越大视野越小
  61425. this.camera.updateProjectionMatrix();
  61426. this.view = new ExtendView();
  61427. this.view.radius = 70;
  61428. this.viewports = [new Viewport(this.view, this.camera, {
  61429. left: 0,
  61430. bottom: 0,
  61431. width: 1,
  61432. height: 1,
  61433. name: 'axis'
  61434. })];
  61435. this.updateScreenSize();
  61436. this.createAxis();
  61437. var updateCamera = e => {
  61438. if (e.viewport == listenViewport && e.changeInfo.quaternionChanged) {
  61439. this.update();
  61440. }
  61441. };
  61442. viewer.addEventListener('camera_changed', updateCamera);
  61443. var repos = () => {
  61444. if (!listenViewport.active || listenViewport.width == 0 || listenViewport.height == 0) {
  61445. return domElement.css('visibility', 'hidden');
  61446. }
  61447. domElement.css('visibility', 'visible');
  61448. var props = [['left', 'right', 'width'], ['bottom', 'top', 'height']];
  61449. var set = prop => {
  61450. var str;
  61451. var name = posInfo[prop[1]] != void 0 ? prop[1] : prop[0];
  61452. var percent = posInfo[prop[1]] != void 0 ? 1 - listenViewport[prop[0]] - listenViewport[prop[2]] : listenViewport[prop[0]];
  61453. if (posInfo[name] == 0 || posInfo[name].includes('%')) {
  61454. str = parseFloat(posInfo[name]) + percent * 100 + '%';
  61455. } else {
  61456. //px
  61457. str = 'calc(' + percent * 100 + '% + ' + posInfo[name] + ')';
  61458. }
  61459. domElement.css(name, str);
  61460. };
  61461. set(props[0]);
  61462. set(props[1]);
  61463. };
  61464. this.listenViewport.addEventListener('resize', repos);
  61465. this.addEventListener('dispose', () => {
  61466. viewer.removeEventListener('camera_changed', updateCamera);
  61467. viewer.removeEventListener('resize', repos);
  61468. });
  61469. repos();
  61470. this.update();
  61471. }
  61472. createAxis() {
  61473. var axis = new Object3D();
  61474. ['x', 'y', 'z'].forEach(axisText => {
  61475. var color = new Color().set(Potree.config.axis[axisText].color);
  61476. var group = new Object3D();
  61477. var line = LineDraw.createLine([new Vector3(), new Vector3(0, 0, 7)], {
  61478. color
  61479. });
  61480. var label = this.createLabel(axisText, color);
  61481. label.position.set(0, 0, 11 /* + this.renderArea.clientWidth/200 */);
  61482. if (axisText == 'y') {
  61483. group.rotation.x = -Math.PI / 2;
  61484. } else if (axisText == 'x') {
  61485. group.rotation.y = Math.PI / 2;
  61486. }
  61487. group.add(line);
  61488. group.add(label);
  61489. axis.add(group);
  61490. });
  61491. this.axis = axis;
  61492. this.scene.add(this.axis);
  61493. }
  61494. createLabel(text, color) {
  61495. var fontsize = this.renderArea.clientWidth / 5; //20//Math.round( Potree.math.linearClamp(this.renderArea.clientWidth, [80,500],[12,50]))
  61496. var s = 3100 / this.renderArea.clientWidth;
  61497. console.log('fontsize', fontsize);
  61498. var label = new TextSprite$2({
  61499. backgroundColor: {
  61500. r: 0,
  61501. g: 0,
  61502. b: 0,
  61503. a: 0
  61504. },
  61505. textColor: {
  61506. r: color.r * 255,
  61507. g: color.g * 255,
  61508. b: color.b * 255,
  61509. a: 1
  61510. },
  61511. fontsize,
  61512. //useDepth : true ,
  61513. renderOrder: 5,
  61514. // pickOrder:5,
  61515. fontWeight: 'Lighter',
  61516. text,
  61517. name: 'axis',
  61518. viewports: this.viewports
  61519. });
  61520. label.scale.set(s, s, s);
  61521. return label;
  61522. }
  61523. update() {
  61524. this.updateCamera();
  61525. this.render();
  61526. }
  61527. updateCamera() {
  61528. var view = this.listenViewport.view;
  61529. this.view.yaw = view.yaw;
  61530. this.view.pitch = view.pitch;
  61531. var dir = view.direction; //相机朝向
  61532. this.view.position.copy(dir.multiplyScalar(this.view.radius).negate()); //相机绕着指南针中心(000)转动
  61533. this.view.applyToCamera(this.camera);
  61534. }
  61535. render() {
  61536. viewer.dispatchEvent({
  61537. type: "render.begin",
  61538. viewport: this.viewports[0]
  61539. }); //update sprite
  61540. this.renderer.render(this.scene, this.camera);
  61541. }
  61542. dispose() {
  61543. this.axis.traverse(child => {
  61544. if (child instanceof TextSprite$2) {
  61545. child.dispose();
  61546. } else if (child instanceof LineSegments) {
  61547. child.material.dispose();
  61548. child.geometry.dispose();
  61549. }
  61550. });
  61551. super.dispose();
  61552. delete this.listenViewport.axis;
  61553. }
  61554. }
  61555. //
  61556. // Algorithm by Christian Boucheny
  61557. // shader code taken and adapted from CloudCompare
  61558. //
  61559. // see
  61560. // https://github.com/cloudcompare/trunk/tree/master/plugins/qEDL/shaders/EDL
  61561. // http://www.kitware.com/source/home/post/9
  61562. // https://tel.archives-ouvertes.fr/tel-00438464/document p. 115+ (french)
  61563. class ExtendEyeDomeLightingMaterial extends EyeDomeLightingMaterial {
  61564. constructor() {
  61565. var parameters = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  61566. super(parameters);
  61567. delete this.uniforms.screenWidth;
  61568. delete this.uniforms.screenHeight;
  61569. this.uniforms.resolution = {
  61570. type: 'v2',
  61571. value: new Vector2()
  61572. };
  61573. this.uniforms.useEDL = {
  61574. type: 'i',
  61575. value: 1
  61576. };
  61577. this.vertexShader = this.getDefines() + Shaders['edl_new.vs']; //改
  61578. this.fragmentShader = this.getDefines() + Shaders['edl_new.fs']; //改
  61579. }
  61580. }
  61581. var copyShader = {
  61582. uniforms: {
  61583. tDiffuse: {
  61584. type: "t",
  61585. value: null
  61586. },
  61587. opacity: {
  61588. type: "f",
  61589. value: 1
  61590. },
  61591. depthTex: {
  61592. type: "t",
  61593. value: null
  61594. }
  61595. },
  61596. vertexShader: " \n varying vec2 vUv;\n void main() {\n vUv = uv; \n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n }\n ",
  61597. fragmentShader: "\n #extension GL_EXT_frag_depth : enable\n uniform float opacity;\n uniform sampler2D tDiffuse;\n #if defined(GL_EXT_frag_depth) && defined(useDepth) \n uniform sampler2D depthTex;\n #endif\n \n varying vec2 vUv;\n void main() { \n #if defined(GL_EXT_frag_depth) && defined(useDepth) \n float depth = texture2D(depthTex, vUv).r;\n /* if(depth >= 1.0){ //\u8D85\u7EA7\u8FDC\uFF08\u4F46\u662F\u5728modelTex\u91CC\u6211\u628A\u5929\u7A7A\u8DDD\u79BB\u8D85\u51FAfar\u4E86\uFF0C\u6240\u4EE5\u4E0D\u5220\uFF09\n discard;\n } */\n gl_FragDepthEXT = depth; \n #endif\n \n \n \n vec4 texel = texture2D( tDiffuse, vUv );\n gl_FragColor = opacity * texel; \n \n \n } \n "
  61598. };
  61599. //import DepthTexSampler from "../custom/utils/DepthTexSampler.js";
  61600. class EDLRenderer {
  61601. //Eye-Dome Lighting 眼罩照明
  61602. constructor(viewer) {
  61603. this.viewer = viewer;
  61604. this.edlMaterial = null;
  61605. //this.rtRegular;
  61606. this.rtEDLs = new Map();
  61607. this.gl = viewer.renderer.getContext();
  61608. //反正也没用到,注释了:
  61609. //this.shadowMap = new PointCloudSM(this.viewer.pRenderer);
  61610. viewer.addEventListener('resize', this.resize.bind(this));
  61611. this.initEDL(viewer);
  61612. }
  61613. initEDL(viewer) {
  61614. if (this.edlMaterial != null || !Features.EXT_DEPTH.isSupported()) {
  61615. return;
  61616. }
  61617. this.edlMaterial = new ExtendEyeDomeLightingMaterial();
  61618. this.edlMaterial.depthTest = true;
  61619. this.edlMaterial.depthWrite = true;
  61620. this.edlMaterial.transparent = true;
  61621. var copyUniforms = UniformsUtils.clone(copyShader.uniforms);
  61622. var {
  61623. vs,
  61624. fs
  61625. } = Common.changeShaderToWebgl2(copyShader.vertexShader, copyShader.fragmentShader, 'ShaderMaterial');
  61626. this.recoverToScreenMat = new ShaderMaterial({
  61627. uniforms: copyUniforms,
  61628. vertexShader: vs,
  61629. fragmentShader: fs,
  61630. transparent: true,
  61631. defines: {
  61632. useDepth: true //开启后,其他物体才能被遮挡
  61633. }
  61634. });
  61635. /* let copyUniforms = THREE.UniformsUtils.clone( copyShader.uniforms );
  61636. this.copyMaterial = new THREE.ShaderMaterial( {
  61637. uniforms: copyUniforms,
  61638. vertexShader: copyShader.vertexShader,
  61639. fragmentShader: copyShader.fragmentShader,
  61640. //premultipliedAlpha: true,
  61641. transparent: true,
  61642. //blending: THREE.AdditiveBlending,
  61643. depthTest: false,
  61644. depthWrite: false
  61645. }); */
  61646. if (Potree.settings.useRTskybox != Potree.settings.useRTPoint) {
  61647. //如果两个只开了一个
  61648. viewer.images360.addEventListener('endChangeMode', () => {
  61649. this.resize({
  61650. viewport: viewer.mainViewport
  61651. });
  61652. });
  61653. }
  61654. //this.depthTexSampler = new DepthTexSampler(this);
  61655. }
  61656. resize(e) {
  61657. if (Features.EXT_DEPTH.isSupported()) {
  61658. var viewport = e.viewport;
  61659. var size = (Potree.settings.displayMode == 'showPanos' ? Potree.settings.useRTskybox : Potree.settings.useRTPoint) ? viewport.resolution2 : viewport.resolution; //若要渲染skybox,需要和设备一样精度的rt
  61660. this.getRtEDL(viewport).setSize(size.x, size.y); //理论上可以是任意尺寸,但会影响精度,且aspect最好和渲染的一致
  61661. }
  61662. }
  61663. clearTargets() {
  61664. var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  61665. var viewer = this.viewer;
  61666. var {
  61667. renderer
  61668. } = viewer;
  61669. var oldTarget = renderer.getRenderTarget();
  61670. if (params.target) {
  61671. //add
  61672. renderer.setRenderTarget(params.target);
  61673. renderer.clear();
  61674. }
  61675. if (Features.EXT_DEPTH.isSupported()) {
  61676. if (params.rtEDL) {
  61677. renderer.setRenderTarget(params.rtEDL);
  61678. renderer.clear();
  61679. } else {
  61680. var rtEDL = this.getRtEDL(params.viewport);
  61681. if (rtEDL) {
  61682. renderer.setRenderTarget(rtEDL);
  61683. renderer.setClearAlpha(0);
  61684. renderer.clear(true, true, true);
  61685. }
  61686. }
  61687. }
  61688. //renderer.setRenderTarget( this.rtRegular );
  61689. //renderer.clear( true, true, false );
  61690. renderer.setRenderTarget(oldTarget);
  61691. }
  61692. getRtEDL(viewport) {
  61693. //根据不同viewport返回rtEDL的texture
  61694. if (!viewport) {
  61695. console.warn('getRtEDL没传viewport!!!! !!!!!!!!!!');
  61696. viewport = viewer.mainViewport;
  61697. }
  61698. var rtEDL = this.rtEDLs.get(viewport);
  61699. if (!rtEDL) {
  61700. if (Features.EXT_DEPTH.isSupported()) {
  61701. rtEDL = new WebGLRenderTarget(viewport.resolution.x, viewport.resolution.y, {
  61702. minFilter: NearestFilter,
  61703. magFilter: NearestFilter,
  61704. format: RGBAFormat,
  61705. type: FloatType,
  61706. depthTexture: new DepthTexture(undefined, undefined, UnsignedIntType)
  61707. });
  61708. //注: 部分手机在resize时会崩溃,经检验去掉rtEDL的resize可以解决,所以更应该注释掉这个
  61709. this.rtEDLs.set(viewport, rtEDL);
  61710. }
  61711. }
  61712. //注:当pc窗口缩小,deviceRatio变小后,resolution2会小于resolution,然后遮挡会出现精度损失而有细微不准,是正常现象。
  61713. return rtEDL;
  61714. }
  61715. renderShadowMap(visiblePointClouds, camera, lights) {
  61716. var {
  61717. viewer
  61718. } = this;
  61719. var doShadows = lights.length > 0 && !lights[0].disableShadowUpdates;
  61720. if (doShadows) {
  61721. var light = lights[0];
  61722. this.shadowMap.setLight(light);
  61723. var originalAttributes = new Map();
  61724. for (var pointcloud of viewer.scene.pointclouds) {
  61725. // TODO IMPORTANT !!! check
  61726. originalAttributes.set(pointcloud, pointcloud.material.activeAttributeName);
  61727. pointcloud.material.disableEvents();
  61728. pointcloud.material.activeAttributeName = "depth";
  61729. //pointcloud.material.pointColorType = PointColorType.DEPTH;
  61730. }
  61731. this.shadowMap.render(viewer.scene.scenePointCloud, camera);
  61732. for (var _pointcloud of visiblePointClouds) {
  61733. var originalAttribute = originalAttributes.get(_pointcloud);
  61734. // TODO IMPORTANT !!! check
  61735. _pointcloud.material.activeAttributeName = originalAttribute;
  61736. _pointcloud.material.enableEvents();
  61737. }
  61738. viewer.shadowTestCam.updateMatrixWorld();
  61739. viewer.shadowTestCam.matrixWorldInverse.copy(viewer.shadowTestCam.matrixWorld).invert();
  61740. viewer.shadowTestCam.updateProjectionMatrix();
  61741. }
  61742. }
  61743. render() {
  61744. var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  61745. var viewer = this.viewer;
  61746. var camera = params.camera ? params.camera : viewer.scene.getActiveCamera();
  61747. var rtEDL = (Potree.settings.pointEnableRT || Potree.settings.displayMode == 'showPanos' || viewer.useEDL) && Features.EXT_DEPTH.isSupported() && camera.type != "OrthographicCamera" && !params.dontRenderRtEDL && (params.rtEDL || this.getRtEDL(params.viewport)); // 平面相机不用depthTex直接打开depthTest?且不使用edl
  61748. var useEDL = viewer.useEDL && rtEDL && Potree.settings.displayMode != 'showPanos';
  61749. var target = params.target || null;
  61750. var resolution = rtEDL && Potree.settings.useRTPoint ? new Vector2(rtEDL.width, rtEDL.height) : params.target ? new Vector2(params.target.width, params.target.height) : params.viewport ? params.viewport.resolution2 : this.viewer.renderer.getSize(new Vector2()); //截图时需要用target的大小
  61751. var renderer = params.renderer || viewer.renderer;
  61752. var pRenderer = params.pRenderer || viewer.pRenderer;
  61753. renderer.setRenderTarget(target);
  61754. //viewer.dispatchEvent({type: "render.pass.begin",viewer: viewer});
  61755. var lights = [];
  61756. /* viewer.scene.scene.traverse(node => {
  61757. if(node.type === "SpotLight"){
  61758. lights.push(node);
  61759. }
  61760. }); */
  61761. //skybox 全景图
  61762. if (!params.magnifier) {
  61763. if (Potree.settings.displayMode == 'showPanos' || Potree.settings.testCube) {
  61764. Potree.Utils.setCameraLayers(camera, ['skybox']);
  61765. if (Potree.settings.displayMode == 'showPanos' && (viewer.images360.currentPano.pointcloud.hasDepthTex || Potree.settings.modelSkybox && viewer.images360.currentPano.pointcloud.is4dkkModel) && rtEDL) {
  61766. //渲染深度图
  61767. renderer.setRenderTarget(rtEDL); //将带有深度图的skybox画在rtEDL一下,这样就不需要绘制后边的点云了
  61768. renderer.render(viewer.scene.scene, camera);
  61769. renderer.setRenderTarget(target);
  61770. if (Potree.settings.useRTskybox) {
  61771. //直接使用rtEDL,但是会失去抗锯齿,不知在skybox上需要抗锯齿吗
  61772. this.recoverToScreenMat.uniforms.depthTex.value = rtEDL.depthTexture;
  61773. this.recoverToScreenMat.uniforms.tDiffuse.value = rtEDL.texture;
  61774. Utils.screenPass.render(renderer, this.recoverToScreenMat, target);
  61775. } else {
  61776. renderer.render(viewer.scene.scene, camera);
  61777. }
  61778. } else {
  61779. renderer.render(viewer.scene.scene, camera);
  61780. }
  61781. if (Potree.settings.displayMode == 'showPanos') {
  61782. if (Potree.settings.fastTran && viewer.images360.fastTranMaskPass.enabled) {
  61783. viewer.images360.fastTranMaskPass.render();
  61784. }
  61785. return;
  61786. }
  61787. }
  61788. }
  61789. var visiblePointClouds2 = viewer.scene.pointclouds.filter(pc => Potree.Utils.getObjVisiByReason(pc, 'datasetSelection')); //需要绘制到rtEDL的
  61790. var showPointClouds = params.magnifier ? visiblePointClouds2.length > 0 : viewer.scene.pointclouds.some(e => e.visible); //是否有需要绘制到屏幕的
  61791. visiblePointClouds2.forEach(e => {
  61792. //为了绘制到depthTexture,先显示(展示全景图时隐藏了点云,所以需要显示下。且放大镜需要绘制点云)
  61793. e.oldVisi = e.visible;
  61794. e.visible = true;
  61795. });
  61796. Potree.Utils.setCameraLayers(camera, ['pointcloud']); //设置多少都会渲染出来,因为渲染里没有sort
  61797. //camera.layers.set(Potree.config.renderLayers.pointcloud);
  61798. //TODO adapt to multiple lights
  61799. //this.renderShadowMap(visiblePointClouds2, camera, lights); //???????
  61800. {
  61801. for (var pointcloud of visiblePointClouds2) {
  61802. var material = pointcloud.material;
  61803. var octreeSize = pointcloud.pcoGeometry.boundingBox.getSize(new Vector3()).x;
  61804. material.fov = MathUtils.degToRad(camera.fov);
  61805. material.resolution = resolution;
  61806. material.spacing = pointcloud.pcoGeometry.spacing; // * Math.max(this.scale.x, this.scale.y, this.scale.z);
  61807. material.near = camera.near;
  61808. material.far = camera.far;
  61809. material.uniforms.octreeSize.value = octreeSize;
  61810. if (useEDL) {
  61811. material.useEDL = true;
  61812. //material.fakeEDL = false; //add
  61813. } else {
  61814. material.useEDL = false;
  61815. //material.fakeEDL = true; //add 使也输出深度
  61816. }
  61817. }
  61818. if (rtEDL) {
  61819. //借用rtEDL存储深度信息
  61820. renderer.setRenderTarget(rtEDL);
  61821. if (visiblePointClouds2.length > 0) {
  61822. //渲染scenePointCloud到rtEDL
  61823. pRenderer.render(viewer.scene.scenePointCloud, camera, rtEDL, {
  61824. shadowMaps: lights.length > 0 ? [this.shadowMap] : null,
  61825. clipSpheres: viewer.scene.volumes.filter(v => v instanceof SphereVolume$1),
  61826. transparent: true,
  61827. //如果点云透明需要透明
  61828. notAdditiveBlending: Potree.settings.notAdditiveBlending
  61829. });
  61830. }
  61831. if (Potree.settings.intersectOnObjs) {
  61832. // model也要渲染到rtEDL
  61833. Potree.Utils.setCameraLayers(camera, ['model', 'light']);
  61834. viewer.objs.traverse(e => {
  61835. if (e.material) e._OlddepthWrite = e.material.depthWrite, e.material.depthWrite = true;
  61836. }); //否则半透明的mesh无法遮住测量线
  61837. renderer.render(viewer.scene.scene, camera);
  61838. viewer.objs.traverse(e => {
  61839. if (e.material) e.material.depthWrite = e._OlddepthWrite;
  61840. });
  61841. //缺点:半透明的model 就算完全透明, 也会遮住测量线
  61842. }
  61843. }
  61844. }
  61845. //渲染到rtEDL完毕
  61846. viewer.dispatchEvent({
  61847. type: "render.pass.scene",
  61848. viewer: viewer
  61849. });
  61850. renderer.setRenderTarget(target);
  61851. if (!params.magnifier) visiblePointClouds2.forEach(e => {
  61852. //放大镜显示点云
  61853. e.visible = e.oldVisi;
  61854. });
  61855. if (showPointClouds) {
  61856. //绘制点云到画布
  61857. if (useEDL) {
  61858. //设置edlMaterial //Features.EXT_DEPTH不支持的话不会到这一块
  61859. var uniforms = this.edlMaterial.uniforms;
  61860. uniforms.resolution.value.copy(resolution);
  61861. uniforms.edlStrength.value = viewer.edlStrength;
  61862. uniforms.radius.value = viewer.edlRadius;
  61863. uniforms.useEDL.value = 1; //add
  61864. var proj = camera.projectionMatrix;
  61865. var projArray = new Float32Array(16);
  61866. projArray.set(proj.elements);
  61867. uniforms.uProj.value = projArray;
  61868. uniforms.uEDLColor.value = rtEDL.texture;
  61869. uniforms.opacity.value = viewer.edlOpacity; // HACK
  61870. Utils.screenPass.render(renderer, this.edlMaterial, target); //相当于一个描边后期特效。 缺点: 因为target上的没有抗锯齿,所以点云在晃动镜头时会不稳定地闪烁1px位置。优点:比不打开edl少绘制一次点云,更流畅了?!
  61871. } else if (Potree.settings.useRTPoint && rtEDL) {
  61872. this.recoverToScreenMat.uniforms.tDiffuse.value = rtEDL.texture;
  61873. if (this.recoverToScreenMat.defines.useDepth) {
  61874. this.recoverToScreenMat.uniforms.depthTex.value = rtEDL.depthTexture;
  61875. }
  61876. Utils.screenPass.render(renderer, this.recoverToScreenMat, target /* , Potree.settings.useFxaa && viewer.composer2 */);
  61877. params.drawedModelOnRT = Potree.settings.intersectOnObjs;
  61878. } else {
  61879. //渲染点云 (直接用rtEDL上的会失去抗锯齿, 导致频闪、密集时出现条纹, 自己写抗锯齿也要渲染好几次。另外透明度也要处理下)
  61880. var prop = {
  61881. shadowMaps: lights.length > 0 ? [this.shadowMap] : null,
  61882. clipSpheres: viewer.scene.volumes.filter(v => v instanceof SphereVolume$1),
  61883. notAdditiveBlending: Potree.settings.notAdditiveBlending //add 否则透明的点云会挡住后面的模型。 加上这句后竟然透明不会叠加了!
  61884. };
  61885. pRenderer.render(viewer.scene.scenePointCloud, camera, null, prop);
  61886. }
  61887. }
  61888. visiblePointClouds2.forEach(e => {
  61889. e.visible = e.oldVisi;
  61890. });
  61891. //viewer.dispatchEvent({type: "render.pass.end",viewer: viewer});
  61892. }
  61893. /*
  61894. 渲染顺序:
  61895. 底层:背景 -> skybox(也可中间)
  61896. 中间层(含有深度信息):1 点云、marker等mesh,
  61897. 2 测量线(现在被做成借用depthTex
  61898. 顶层:maginifier
  61899. magnifier的贴图渲染不需要顶层、中间层只需要点云。
  61900. */
  61901. }
  61902. class NavigationCube extends Object3D {
  61903. constructor(viewer) {
  61904. super();
  61905. this.viewer = viewer;
  61906. var createPlaneMaterial = img => {
  61907. var material = new MeshBasicMaterial({
  61908. depthTest: true,
  61909. depthWrite: true,
  61910. side: DoubleSide
  61911. });
  61912. new TextureLoader().load(exports.resourcePath + '/textures/navigation/' + img, function (texture) {
  61913. texture.anisotropy = viewer.renderer.capabilities.getMaxAnisotropy();
  61914. material.map = texture;
  61915. material.needsUpdate = true;
  61916. });
  61917. return material;
  61918. };
  61919. var planeGeometry = new PlaneGeometry(1, 1);
  61920. this.front = new Mesh(planeGeometry, createPlaneMaterial('F.png'));
  61921. this.front.position.y = -0.5;
  61922. this.front.rotation.x = Math.PI / 2.0;
  61923. this.front.updateMatrixWorld();
  61924. this.front.name = "F";
  61925. this.add(this.front);
  61926. this.back = new Mesh(planeGeometry, createPlaneMaterial('B.png'));
  61927. this.back.position.y = 0.5;
  61928. this.back.rotation.x = Math.PI / 2.0;
  61929. this.back.updateMatrixWorld();
  61930. this.back.name = "B";
  61931. this.add(this.back);
  61932. this.left = new Mesh(planeGeometry, createPlaneMaterial('L.png'));
  61933. this.left.position.x = -0.5;
  61934. this.left.rotation.y = Math.PI / 2.0;
  61935. this.left.updateMatrixWorld();
  61936. this.left.name = "L";
  61937. this.add(this.left);
  61938. this.right = new Mesh(planeGeometry, createPlaneMaterial('R.png'));
  61939. this.right.position.x = 0.5;
  61940. this.right.rotation.y = Math.PI / 2.0;
  61941. this.right.updateMatrixWorld();
  61942. this.right.name = "R";
  61943. this.add(this.right);
  61944. this.bottom = new Mesh(planeGeometry, createPlaneMaterial('D.png'));
  61945. this.bottom.position.z = -0.5;
  61946. this.bottom.updateMatrixWorld();
  61947. this.bottom.name = "D";
  61948. this.add(this.bottom);
  61949. this.top = new Mesh(planeGeometry, createPlaneMaterial('U.png'));
  61950. this.top.position.z = 0.5;
  61951. this.top.updateMatrixWorld();
  61952. this.top.name = "U";
  61953. this.add(this.top);
  61954. this.width = 150; // in px
  61955. this.camera = new OrthographicCamera(-1, 1, 1, -1, -1, 1);
  61956. this.camera.position.copy(new Vector3(0, 0, 0));
  61957. this.camera.lookAt(new Vector3(0, 1, 0));
  61958. this.camera.updateMatrixWorld();
  61959. this.camera.rotation.order = "ZXY";
  61960. var onMouseDown = event => {
  61961. if (!this.visible) {
  61962. return;
  61963. }
  61964. this.pickedFace = null;
  61965. var mouse = new Vector2();
  61966. mouse.x = event.clientX - (window.innerWidth - this.width);
  61967. mouse.y = event.clientY;
  61968. if (mouse.x < 0 || mouse.y > this.width) return;
  61969. mouse.x = mouse.x / this.width * 2 - 1;
  61970. mouse.y = -(mouse.y / this.width) * 2 + 1;
  61971. var raycaster = new Raycaster();
  61972. raycaster.setFromCamera(mouse, this.camera);
  61973. raycaster.ray.origin.sub(this.camera.getWorldDirection(new Vector3()));
  61974. var intersects = raycaster.intersectObjects(this.children);
  61975. var minDistance = 1000;
  61976. for (var i = 0; i < intersects.length; i++) {
  61977. if (intersects[i].distance < minDistance) {
  61978. this.pickedFace = intersects[i].object.name;
  61979. minDistance = intersects[i].distance;
  61980. }
  61981. }
  61982. if (this.pickedFace) {
  61983. this.viewer.setView(this.pickedFace);
  61984. }
  61985. };
  61986. this.viewer.renderer.domElement.addEventListener('mousedown', onMouseDown, false);
  61987. }
  61988. update(rotation) {
  61989. this.camera.rotation.copy(rotation);
  61990. this.visible && this.camera.updateMatrixWorld();
  61991. }
  61992. }
  61993. /**
  61994. *
  61995. * @author sigeom sa / http://sigeom.ch
  61996. * @author Ioda-Net Sàrl / https://www.ioda-net.ch/
  61997. * @author Markus Schütz / http://potree.org
  61998. *
  61999. */
  62000. class GeoJSONExporter {
  62001. static measurementToFeatures(measurement) {
  62002. var coords = measurement.points.map(e => e.position.toArray());
  62003. var features = [];
  62004. if (coords.length === 1) {
  62005. var feature = {
  62006. type: 'Feature',
  62007. geometry: {
  62008. type: 'Point',
  62009. coordinates: coords[0]
  62010. },
  62011. properties: {
  62012. name: measurement.name
  62013. }
  62014. };
  62015. features.push(feature);
  62016. } else if (coords.length > 1 && !measurement.closed) {
  62017. var object = {
  62018. 'type': 'Feature',
  62019. 'geometry': {
  62020. 'type': 'LineString',
  62021. 'coordinates': coords
  62022. },
  62023. 'properties': {
  62024. name: measurement.name
  62025. }
  62026. };
  62027. features.push(object);
  62028. } else if (coords.length > 1 && measurement.closed) {
  62029. var _object = {
  62030. 'type': 'Feature',
  62031. 'geometry': {
  62032. 'type': 'Polygon',
  62033. 'coordinates': [[...coords, coords[0]]]
  62034. },
  62035. 'properties': {
  62036. name: measurement.name
  62037. }
  62038. };
  62039. features.push(_object);
  62040. }
  62041. if (measurement.showDistances) {
  62042. measurement.edgeLabels.forEach(label => {
  62043. var labelPoint = {
  62044. type: 'Feature',
  62045. geometry: {
  62046. type: 'Point',
  62047. coordinates: label.position.toArray()
  62048. },
  62049. properties: {
  62050. distance: label.text
  62051. }
  62052. };
  62053. features.push(labelPoint);
  62054. });
  62055. }
  62056. if (measurement.showArea) {
  62057. var point = measurement.areaLabel.position;
  62058. var labelArea = {
  62059. type: 'Feature',
  62060. geometry: {
  62061. type: 'Point',
  62062. coordinates: point.toArray()
  62063. },
  62064. properties: {
  62065. area: measurement.areaLabel.text
  62066. }
  62067. };
  62068. features.push(labelArea);
  62069. }
  62070. return features;
  62071. }
  62072. static toString(measurements) {
  62073. if (!(measurements instanceof Array)) {
  62074. measurements = [measurements];
  62075. }
  62076. measurements = measurements.filter(m => m instanceof Measure);
  62077. var features = [];
  62078. for (var measure of measurements) {
  62079. var f = GeoJSONExporter.measurementToFeatures(measure);
  62080. features = features.concat(f);
  62081. }
  62082. var geojson = {
  62083. 'type': 'FeatureCollection',
  62084. 'features': features
  62085. };
  62086. return JSON.stringify(geojson, null, '\t');
  62087. }
  62088. }
  62089. /**
  62090. *
  62091. * @author sigeom sa / http://sigeom.ch
  62092. * @author Ioda-Net Sàrl / https://www.ioda-net.ch/
  62093. * @author Markus Schuetz / http://potree.org
  62094. *
  62095. */
  62096. class DXFExporter {
  62097. static measurementPointSection(measurement) {
  62098. var position = measurement.points[0].position;
  62099. if (!position) {
  62100. return '';
  62101. }
  62102. var dxfSection = "0\nCIRCLE\n8\nlayer_point\n10\n".concat(position.x, "\n20\n").concat(position.y, "\n30\n").concat(position.z, "\n40\n1.0\n");
  62103. return dxfSection;
  62104. }
  62105. static measurementPolylineSection(measurement) {
  62106. // bit code for polygons/polylines:
  62107. // https://www.autodesk.com/techpubs/autocad/acad2000/dxf/polyline_dxf_06.htm
  62108. var geomCode = 8;
  62109. if (measurement.closed) {
  62110. geomCode += 1;
  62111. }
  62112. var dxfSection = "0\nPOLYLINE\n8\nlayer_polyline\n62\n1\n66\n1\n10\n0.0\n20\n0.0\n30\n0.0\n70\n".concat(geomCode, "\n");
  62113. var xMax = 0.0;
  62114. var yMax = 0.0;
  62115. var zMax = 0.0;
  62116. for (var point of measurement.points) {
  62117. point = point.position;
  62118. xMax = Math.max(xMax, point.x);
  62119. yMax = Math.max(yMax, point.y);
  62120. zMax = Math.max(zMax, point.z);
  62121. dxfSection += "0\nVERTEX\n8\n0\n10\n".concat(point.x, "\n20\n").concat(point.y, "\n30\n").concat(point.z, "\n70\n32\n");
  62122. }
  62123. dxfSection += "0\nSEQEND\n";
  62124. return dxfSection;
  62125. }
  62126. static measurementSection(measurement) {
  62127. // if(measurement.points.length <= 1){
  62128. // return "";
  62129. // }
  62130. if (measurement.points.length === 0) {
  62131. return '';
  62132. } else if (measurement.points.length === 1) {
  62133. return DXFExporter.measurementPointSection(measurement);
  62134. } else if (measurement.points.length >= 2) {
  62135. return DXFExporter.measurementPolylineSection(measurement);
  62136. }
  62137. }
  62138. static toString(measurements) {
  62139. if (!(measurements instanceof Array)) {
  62140. measurements = [measurements];
  62141. }
  62142. measurements = measurements.filter(m => m instanceof Measure);
  62143. var points = measurements.filter(m => m instanceof Measure).map(m => m.points).reduce((a, v) => a.concat(v)).map(p => p.position);
  62144. var min = new Vector3(Infinity, Infinity, Infinity);
  62145. var max = new Vector3(-Infinity, -Infinity, -Infinity);
  62146. for (var point of points) {
  62147. min.min(point);
  62148. max.max(point);
  62149. }
  62150. var dxfHeader = "999\nDXF created from potree\n0\nSECTION\n2\nHEADER\n9\n$ACADVER\n1\nAC1006\n9\n$INSBASE\n10\n0.0\n20\n0.0\n30\n0.0\n9\n$EXTMIN\n10\n".concat(min.x, "\n20\n").concat(min.y, "\n30\n").concat(min.z, "\n9\n$EXTMAX\n10\n").concat(max.x, "\n20\n").concat(max.y, "\n30\n").concat(max.z, "\n0\nENDSEC\n");
  62151. var dxfBody = "0\nSECTION\n2\nENTITIES\n";
  62152. for (var measurement of measurements) {
  62153. dxfBody += DXFExporter.measurementSection(measurement);
  62154. }
  62155. dxfBody += "0\nENDSEC\n";
  62156. var dxf = dxfHeader + dxfBody + '0\nEOF';
  62157. return dxf;
  62158. }
  62159. }
  62160. class HandleSvg extends EventDispatcher {
  62161. constructor(position, color) {
  62162. super();
  62163. this.position = position;
  62164. this.color = '#' + new Color(color).getHexString();
  62165. this.svg = this.create();
  62166. this.visible_ = true;
  62167. var update = () => {
  62168. this.update();
  62169. };
  62170. viewer.addEventListener("camera_changed", update);
  62171. this.addEventListener('dispose', () => {
  62172. viewer.removeEventListener("camera_changed", update);
  62173. });
  62174. }
  62175. create() {
  62176. var svgns = "http://www.w3.org/2000/svg";
  62177. var svg = document.createElementNS(svgns, "svg");
  62178. svg.setAttribute("width", "2em");
  62179. svg.setAttribute("height", "2em");
  62180. svg.setAttribute("position", "absolute");
  62181. svg.style.left = "50px";
  62182. svg.style.top = "50px";
  62183. svg.style.position = "absolute";
  62184. svg.style.zIndex = "10000";
  62185. svg.style.cursor = 'grab';
  62186. svg.style.transform = 'translate(-50%,-50%)';
  62187. var circle = document.createElementNS(svgns, 'circle');
  62188. circle.setAttributeNS(null, 'cx', "1em");
  62189. circle.setAttributeNS(null, 'cy', "1em");
  62190. circle.setAttributeNS(null, 'r', "0.5em");
  62191. circle.setAttributeNS(null, 'style', 'fill: ' + this.color + '; stroke: black; stroke-width: 0.2em;');
  62192. svg.appendChild(circle);
  62193. var element = viewer.renderer.domElement.parentElement;
  62194. element.appendChild(svg);
  62195. var startDrag = evt => {
  62196. /* if(evt.button === THREE.MOUSE.RIGHT){
  62197. return
  62198. } */
  62199. this.selectedElement = svg;
  62200. document.addEventListener("mousemove", drag);
  62201. };
  62202. var endDrag = evt => {
  62203. this.selectedElement = null;
  62204. document.removeEventListener("mousemove", drag);
  62205. };
  62206. var drag = evt => {
  62207. if (this.selectedElement) {
  62208. evt.preventDefault();
  62209. var rect = viewer.renderer.domElement.getBoundingClientRect();
  62210. var x = evt.clientX - rect.x;
  62211. var y = evt.clientY - rect.y;
  62212. var {
  62213. width,
  62214. height
  62215. } = viewer.renderer.getSize(new Vector2());
  62216. var camera = viewer.scene.getActiveCamera();
  62217. var projected = this.position.clone().project(camera);
  62218. projected.x = (x / width - 0.5) / 0.5;
  62219. projected.y = (-(y - height) / height - 0.5) / 0.5;
  62220. var unprojected = projected.clone().unproject(camera);
  62221. this.position.set(unprojected.x, unprojected.y, unprojected.z);
  62222. this.update();
  62223. this.dispatchEvent({
  62224. type: 'dragged',
  62225. position: this.position
  62226. });
  62227. }
  62228. };
  62229. svg.addEventListener('mousedown', startDrag);
  62230. svg.addEventListener('mouseup', endDrag);
  62231. svg.style.display = this.visible ? "" : "none";
  62232. this.addEventListener('dispose', () => {
  62233. svg.removeEventListener('mousedown', startDrag);
  62234. svg.removeEventListener('mouseup', endDrag);
  62235. });
  62236. return svg;
  62237. }
  62238. set visible(v) {
  62239. this.visible_ = v;
  62240. if (v) {
  62241. this.update();
  62242. } else {
  62243. this.svg.style.display = "none";
  62244. }
  62245. }
  62246. get visible() {
  62247. return this.visible_;
  62248. }
  62249. update() {
  62250. if (!this.visible) return;
  62251. var camera = viewer.scene.getActiveCamera();
  62252. var p = Potree.Utils.getPos2d(this.position, viewer.mainViewport, viewer.renderArea);
  62253. if (!p.trueSide) {
  62254. return this.svg.style.display = 'none';
  62255. }
  62256. this.svg.style.left = p.posInViewport.x;
  62257. this.svg.style.top = p.posInViewport.y;
  62258. this.svg.style.display = '';
  62259. }
  62260. dispose() {
  62261. this.svg.remove();
  62262. this.dispatchEvent('dispose');
  62263. }
  62264. }
  62265. /*
  62266. 两种拖拽方式:
  62267. 1 只依附在点云上
  62268. 2 平行于镜头view移动 */
  62269. var geo$1 = new PlaneBufferGeometry(1, 1);
  62270. class HandleSprite extends Sprite$2 {
  62271. constructor(position) {
  62272. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  62273. options.sizeInfo = {
  62274. width2d: 60
  62275. };
  62276. super(options);
  62277. this.position.copy(position);
  62278. this.dragStyle = options.dragStyle || 'default'; //'default'||'onPointCloud'
  62279. this.bindEvent();
  62280. }
  62281. bindEvent() {
  62282. var projectedStart, pointerStart;
  62283. var drag = e => {
  62284. /* if(e.hoverViewport != e.drag.dragViewport){//不能使用e.dragViewport,要使用drag中的,因为drag中存储的要一直继承下来,不因mouseup了而改变。
  62285. viewer.dispatchEvent({
  62286. type : "CursorChange", action : "add", name:"polygon_AtWrongPlace"
  62287. })
  62288. return
  62289. } */
  62290. var camera = viewer.scene.getActiveCamera();
  62291. if (projectedStart) {
  62292. var move2d = new Vector2().subVectors(e.pointer, pointerStart);
  62293. var projectNow = projectedStart.clone();
  62294. projectNow.x += move2d.x;
  62295. projectNow.y += move2d.y;
  62296. var unprojected = projectNow.clone().unproject(camera);
  62297. this.position.set(unprojected.x, unprojected.y, unprojected.z);
  62298. } else {
  62299. projectedStart = this.position.clone().project(camera);
  62300. pointerStart = e.pointer.clone();
  62301. }
  62302. this.update();
  62303. this.dispatchEvent({
  62304. type: 'dragged',
  62305. position: this.position
  62306. });
  62307. };
  62308. var drop = e => {
  62309. projectedStart = null, pointerStart = null;
  62310. };
  62311. var mouseover = e => {
  62312. viewer.dispatchEvent({
  62313. type: "CursorChange",
  62314. action: "add",
  62315. name: "markerMove"
  62316. });
  62317. };
  62318. var mouseleave = e => {
  62319. viewer.dispatchEvent({
  62320. type: "CursorChange",
  62321. action: "remove",
  62322. name: "markerMove"
  62323. });
  62324. };
  62325. this.addEventListener('drag', drag);
  62326. this.addEventListener('drop', drop);
  62327. this.addEventListener('mouseover', mouseover);
  62328. this.addEventListener('mouseleave', mouseleave);
  62329. }
  62330. }
  62331. var sphere = new Mesh(new SphereBufferGeometry(0.08, 0.08, 3, 2), new MeshBasicMaterial({
  62332. color: '#f88'
  62333. }));
  62334. class CurveCtrl extends Object3D {
  62335. constructor(points, lineMat, color, name) {
  62336. var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
  62337. super();
  62338. this.curve = new CatmullRomCurve3(points, false, "centripetal" /* , tension */);
  62339. this.name = name || 'curveNode';
  62340. this.handleMat = options.handleMat;
  62341. this.lineMat = lineMat;
  62342. this.createPath();
  62343. this.color = color;
  62344. this.handles = [];
  62345. this.wholeLength = 0;
  62346. this.viewports = options.viewports || [viewer.mainViewport]; //for HandleSprite
  62347. for (var i = 0, j = this.points.length; i < j; i++) {
  62348. this.handles.push(this.createHandle(this.points[i]));
  62349. }
  62350. this.visible_ = true;
  62351. if (Potree.settings.isTest) {
  62352. this.spheres = new Object3D();
  62353. /* let i = Count+1;
  62354. while(i>0){
  62355. this.spheres.add(sphere.clone());
  62356. i--;
  62357. } */
  62358. this.add(this.spheres);
  62359. }
  62360. this.updatePath();
  62361. }
  62362. addPoint(position, index, ifUpdate) {
  62363. var length = this.points.length;
  62364. if (index == void 0) {
  62365. index = length;
  62366. }
  62367. var handle = this.createHandle(position);
  62368. this.handles = [...this.handles.slice(0, index), handle, ...this.handles.slice(index, length)];
  62369. this.points = [...this.points.slice(0, index), position, ...this.points.slice(index, length)];
  62370. ifUpdate && (this.updatePath(), this.updateHandle(index));
  62371. }
  62372. removePoint(index) {
  62373. var handle = this.handles[index];
  62374. handle.dispose();
  62375. this.handles.splice(index, 1);
  62376. this.points.splice(index, 1);
  62377. this.updatePath();
  62378. }
  62379. createPath() {
  62380. var line = LineDraw.createFatLine([], this.lineMat);
  62381. this.line = line;
  62382. this.add(line);
  62383. }
  62384. updatePath() {
  62385. this.curve.needsUpdate = true; //如果不更新,得到的点不均匀,开头点少。
  62386. var points,
  62387. length = this.points.length;
  62388. this.wholeLength = this.points.reduce((total, currentValue, currentIndex, arr) => {
  62389. //所有端点的距离总和
  62390. if (currentIndex == 0) return 0;
  62391. return total + currentValue.distanceTo(arr[currentIndex - 1]);
  62392. }, 0);
  62393. if (length > 1) {
  62394. var count = MathUtils.clamp(Math.ceil(this.wholeLength * 5), 30, 500);
  62395. points = this.curve.getSpacedPoints(count);
  62396. if (this.needsPercent) {
  62397. //获取每个节点在整条中的百分比,便于定位(但不精确)
  62398. this.pointsPercent = [0];
  62399. var sums = [0];
  62400. var sum = 0,
  62401. last = points[0];
  62402. for (var i = 1; i < length; i++) {
  62403. var point = this.points[i];
  62404. sum += point.distanceTo(last); //参考getLengths函数,根据长度得到百分比
  62405. last = point;
  62406. sums.push(sum);
  62407. }
  62408. for (var _i = 1; _i < length; _i++) {
  62409. this.pointsPercent.push(sum == 0 ? _i / length : sums[_i] / sum);
  62410. }
  62411. }
  62412. if (Potree.settings.isTest) {
  62413. this.spheres.children.forEach(e => e.visible = false);
  62414. points.forEach((e, i) => {
  62415. var sphere1 = this.spheres.children[i];
  62416. if (!sphere1) {
  62417. sphere1 = sphere.clone();
  62418. this.spheres.add(sphere1);
  62419. }
  62420. sphere1.position.copy(e);
  62421. sphere1.visible = true;
  62422. });
  62423. }
  62424. } else {
  62425. points = [];
  62426. }
  62427. LineDraw.updateLine(this.line, points);
  62428. this.dispatchEvent('updatePath');
  62429. }
  62430. createHandle(position) {
  62431. if (this.handleMat) {
  62432. var handle = new HandleSprite(position, {
  62433. mat: this.handleMat,
  62434. viewports: this.viewports
  62435. });
  62436. this.add(handle);
  62437. } else {
  62438. var handle = new HandleSvg(position, this.color);
  62439. }
  62440. handle.visible = this.visible;
  62441. handle.addEventListener('dragged', e => {
  62442. var index = this.handles.indexOf(handle);
  62443. this.points[index].copy(e.position);
  62444. this.updatePath();
  62445. this.dispatchEvent({
  62446. type: 'dragCurvePoint',
  62447. index
  62448. });
  62449. });
  62450. return handle;
  62451. }
  62452. updateHandle(index) {
  62453. if (!this.visible) return;
  62454. this.handles[index].update();
  62455. }
  62456. updateHandles() {
  62457. this.handles.forEach((handle, index) => {
  62458. this.updateHandle(index);
  62459. });
  62460. }
  62461. update() {
  62462. this.updateHandles();
  62463. this.updatePath();
  62464. }
  62465. set visible(v) {
  62466. if (v != this.visible_) {
  62467. this.visible_ = v;
  62468. this.visible = v;
  62469. if (this.handles) {
  62470. this.handles.forEach(e => e.visible = v);
  62471. if (v) this.updateHandles(); //因为不可见时没更新位置
  62472. }
  62473. }
  62474. }
  62475. get visible() {
  62476. return this.visible_;
  62477. }
  62478. /* set visible(v){
  62479. this.handles.forEach(e=>e.svg.style.display = v ? "" : "none" )
  62480. if(v) this.updateHandles() //因为不可见时没更新位置
  62481. } */
  62482. get points() {
  62483. return this.curve.points;
  62484. }
  62485. set points(points) {
  62486. this.curve.points = points;
  62487. }
  62488. getPointAt(t) {
  62489. return this.curve.getPointAt(t);
  62490. }
  62491. getSpacedPoints(t) {
  62492. return this.curve.getSpacedPoints(t);
  62493. }
  62494. dispose() {
  62495. this.parent && this.parent.remove(this);
  62496. this.handles.forEach(e => e.dispose());
  62497. this.line.geometry && this.line.geometry.dispose();
  62498. }
  62499. }
  62500. var colors$1 = {
  62501. position: 'red',
  62502. target: 'blue'
  62503. };
  62504. var lineMats$1;
  62505. var getLineMat = function getLineMat(name) {
  62506. if (!lineMats$1) {
  62507. lineMats$1 = {
  62508. position: LineDraw.createFatLineMat({
  62509. color: colors$1.position,
  62510. lineWidth: 3
  62511. }),
  62512. target: LineDraw.createFatLineMat({
  62513. color: colors$1.target,
  62514. lineWidth: 3
  62515. }),
  62516. frustum: LineDraw.createFatLineMat({
  62517. color: colors$1.position,
  62518. lineWidth: 2
  62519. }),
  62520. aimAtTarget: new LineBasicMaterial({
  62521. color: colors$1.target,
  62522. depthTest: false
  62523. })
  62524. };
  62525. }
  62526. return lineMats$1[name];
  62527. };
  62528. class CameraAnimation$1 extends EventDispatcher {
  62529. constructor(viewer) {
  62530. super();
  62531. this.viewer = viewer;
  62532. this.selectedElement = null;
  62533. //this.controlPoints = [];
  62534. this.uuid = MathUtils.generateUUID();
  62535. this.node = new Object3D();
  62536. this.node.name = "camera animation";
  62537. this.viewer.scene.scene.add(this.node);
  62538. this.frustum = this.createFrustum();
  62539. this.node.add(this.frustum);
  62540. this.name = "Camera Animation";
  62541. // "centripetal", "chordal", "catmullrom"
  62542. this.curveType = "centripetal";
  62543. this.visible = true;
  62544. this.targets = [];
  62545. this.createPath();
  62546. this.duration = 5;
  62547. this.percent = 0;
  62548. this.currentIndex = 0;
  62549. this.durations = [];
  62550. this.quaternions = [];
  62551. if (!Potree.settings.isTest && Potree.settings.isOfficial) {
  62552. this.setVisible(false);
  62553. }
  62554. this.addEventListener('dispose', () => {
  62555. this.dispose();
  62556. });
  62557. this.targetLines = new Object3D();
  62558. this.node.add(this.targetLines);
  62559. }
  62560. static defaultFromView(viewer) {
  62561. var animation = new CameraAnimation$1(viewer);
  62562. var camera = viewer.scene.getActiveCamera();
  62563. var target = viewer.scene.view.getPivot();
  62564. var cpCenter = new Vector3(0.3 * camera.position.x + 0.7 * target.x, 0.3 * camera.position.y + 0.7 * target.y, 0.3 * camera.position.z + 0.7 * target.z);
  62565. var targetCenter = new Vector3(0.05 * camera.position.x + 0.95 * target.x, 0.05 * camera.position.y + 0.95 * target.y, 0.05 * camera.position.z + 0.95 * target.z);
  62566. var r = 2; //camera.position.distanceTo(target) * 0.3;
  62567. //const dir = target.clone().sub(camera.position).normalize();
  62568. var angle = Utils.computeAzimuth(camera.position, target);
  62569. var n = 5;
  62570. for (var i = 0; i < n; i++) {
  62571. var u = 1.5 * Math.PI * (i / n) + angle;
  62572. var dx = r * Math.cos(u);
  62573. var dy = r * Math.sin(u);
  62574. var cpPos = new Vector3(cpCenter.x + dx, cpCenter.y + dy, cpCenter.z);
  62575. var targetPos = new Vector3(targetCenter.x + dx * 0.1, targetCenter.y + dy * 0.1, targetCenter.z);
  62576. animation.createControlPoint(null, {
  62577. position: cpPos,
  62578. target: targetPos
  62579. });
  62580. }
  62581. animation.changeCallback();
  62582. return animation;
  62583. }
  62584. createControlPoint(index, posInfo) {
  62585. var length = this.posCurve.points.length;
  62586. var position = new Vector3();
  62587. var target = new Vector3();
  62588. if (index == void 0) {
  62589. index = length;
  62590. }
  62591. if (!posInfo) {
  62592. if (length >= 2 && index === 0) {
  62593. var dir = new Vector3().subVectors(this.posCurve.points[0], this.posCurve.points[1]);
  62594. position.copy(this.posCurve.points[0]).add(dir);
  62595. var tDir = new Vector3().subVectors(this.targets[0].position, this.targets[1].position);
  62596. target.copy(this.targets[0].position).add(dir);
  62597. } else if (length >= 2 && index === length) {
  62598. var _dir = new Vector3().subVectors(this.posCurve.points[length - 1], this.posCurve.points[length - 2]);
  62599. position.copy(this.posCurve.points[length - 2]).add(_dir);
  62600. var _tDir = new Vector3().subVectors(this.targets[length - 1].position, this.targets[length - 2].position);
  62601. target.copy(this.targets[length - 2].position).add(_dir);
  62602. } else if (length >= 2) {
  62603. position.copy(this.posCurve.points[index - 1].clone().add(this.posCurve.points[index]).multiplyScalar(0.5));
  62604. target.copy(this.targets[index - 1].position.clone().add(this.targets[index].position).multiplyScalar(0.5));
  62605. }
  62606. } else {
  62607. position.copy(posInfo.position);
  62608. target.copy(posInfo.target);
  62609. }
  62610. this.posCurve.addPoint(position, index /* , true */);
  62611. //this.targetCurve.addPoint(target, index/* , true */)
  62612. var targetSvg = new HandleSvg(target, colors$1.target);
  62613. targetSvg.visible = this.visible;
  62614. this.targets = [...this.targets.slice(0, index), targetSvg, ...this.targets.slice(index, length)];
  62615. if (this.useDurSlice) {
  62616. //不使用全局的duration,而是分段的
  62617. this.durations = [...this.durations.slice(0, index), posInfo.duration, ...this.durations.slice(index, length)];
  62618. }
  62619. this.dispatchEvent({
  62620. type: "controlpoint_added",
  62621. index
  62622. });
  62623. {
  62624. var targetLine = LineDraw.createLine([position, target], {
  62625. mat: getLineMat('aimAtTarget')
  62626. });
  62627. this.targetLines.children = [...this.targetLines.children.slice(0, index), targetLine, ...this.targetLines.children.slice(index, length)];
  62628. this.targets[index].addEventListener('dragged', e => {
  62629. this.updatePathCallback();
  62630. this.dragPointCallback(e);
  62631. });
  62632. }
  62633. }
  62634. dragPointCallback(e) {
  62635. var index = e.index;
  62636. if (e.index == void 0) {
  62637. index = this.targets.indexOf(e.target);
  62638. }
  62639. LineDraw.moveLine(this.targetLines.children[index], [this.posCurve.points[index], this.targets[index].position]);
  62640. viewer.dispatchEvent('content_changed');
  62641. this.updateFrustum();
  62642. }
  62643. updatePathCallback() {
  62644. {
  62645. this.quaternions = [];
  62646. var length = this.posCurve.points.length;
  62647. for (var i = 0; i < length; i++) {
  62648. var quaternion = math.getQuaFromPosAim(this.posCurve.points[i], this.targets[i].position);
  62649. this.quaternions.push(quaternion);
  62650. }
  62651. }
  62652. this.reMapCurvePercent();
  62653. }
  62654. removeControlPoint(index) {
  62655. this.posCurve.removePoint(index);
  62656. //this.targetCurve.removePoint(index)
  62657. this.targets[index].dispose();
  62658. this.targets.splice(index, 1);
  62659. this.dispatchEvent({
  62660. type: "controlpoint_removed",
  62661. index
  62662. });
  62663. this.targetLines.remove(this.targetLines.children[index]);
  62664. if (this.useDurSlice) {
  62665. this.durations.splice(index, 1);
  62666. }
  62667. }
  62668. createPath() {
  62669. this.posCurve = new CurveCtrl([], getLineMat('position'), colors$1.position, 'posCurve');
  62670. //this.targetCurve = new CurveCtrl([], getLineMat('target'), colors.target, 'targetCurve', {noLine:true});
  62671. this.posCurve.needsPercent = true;
  62672. this.node.add(this.posCurve);
  62673. //this.node.add(this.targetCurve)
  62674. this.posCurve.addEventListener('dragCurvePoint', this.dragPointCallback.bind(this));
  62675. this.posCurve.addEventListener('updatePath', this.updatePathCallback.bind(this));
  62676. }
  62677. createFrustum() {
  62678. var f = 0.3;
  62679. var positions = [new Vector3(0, 0, 0), new Vector3(-f, -f, +1), new Vector3(0, 0, 0), new Vector3(f, -f, +1), new Vector3(0, 0, 0), new Vector3(f, f, +1), new Vector3(0, 0, 0), new Vector3(-f, f, +1), new Vector3(-f, -f, +1), new Vector3(f, -f, +1), new Vector3(f, -f, +1), new Vector3(f, f, +1), new Vector3(f, f, +1), new Vector3(-f, f, +1), new Vector3(-f, f, +1), new Vector3(-f, -f, +1)];
  62680. positions.forEach(e => e.z *= -1); //因为得到的rotation是camera的,作用在物体上要反向,所以这里反向一下
  62681. //geometry.computeBoundingSphere();//?
  62682. var line = LineDraw.createFatLine(positions, {
  62683. mat: getLineMat('frustum')
  62684. });
  62685. //line.scale.set(20, 20, 20);
  62686. line.visible = false;
  62687. return line;
  62688. }
  62689. reMapCurvePercent() {
  62690. //因在不同点在相同位置旋转,由于间隔仅和位置距离相关,导致时间间隔为0,采取重新调整间隔的策略。
  62691. var length = this.posCurve.points.length;
  62692. if (length < 2) {
  62693. return this.newPointsPercents = [];
  62694. }
  62695. var newPercents = [0];
  62696. if (this.useDurSlice) {
  62697. //已经设定好了每一段的duration的话
  62698. var sums = [0];
  62699. var sum = 0,
  62700. last;
  62701. for (var i = 0; i < length - 1; i++) {
  62702. //去掉最后一个duration,因为已到终点
  62703. var duration = this.durations[i];
  62704. sum += duration;
  62705. last = duration;
  62706. sums.push(sum);
  62707. }
  62708. for (var _i = 1; _i < length; _i++) {
  62709. newPercents.push(sum == 0 ? _i / length : sums[_i] / sum);
  62710. }
  62711. } else {
  62712. var maxSpaceDur = this.duration / length; //每两点之间修改间隔时间后,最大时间
  62713. var durPerRad = 0.8; //每弧度应该占用的时间
  62714. var minSpaceDur = Math.min(0.8, maxSpaceDur); //每两点之间修改间隔时间后,最小时间
  62715. var maxAngleSpaceDur = MathUtils.clamp(durPerRad * Math.PI, minSpaceDur, maxSpaceDur); // 最大可能差距是180度
  62716. var percents = this.posCurve.pointsPercent;
  62717. for (var _i2 = 1; _i2 < length; _i2++) {
  62718. var diff = (percents[_i2] - percents[_i2 - 1]) * this.duration; //间隔时间
  62719. var percent = void 0;
  62720. var curMin = minSpaceDur;
  62721. if (diff < maxAngleSpaceDur) {
  62722. //若小于最大旋转时间
  62723. var rad = this.quaternions[_i2].angleTo(this.quaternions[_i2 - 1]);
  62724. curMin = MathUtils.clamp(rad * durPerRad, minSpaceDur, maxSpaceDur);
  62725. }
  62726. diff = Math.max(diff, curMin);
  62727. percent = newPercents[_i2 - 1] + diff / this.duration; //得到新的percent
  62728. newPercents.push(percent);
  62729. }
  62730. var maxPercent = newPercents[length - 1]; //最后一个,若扩充过时间,就会>1
  62731. if (!math.closeTo(maxPercent, 1)) {
  62732. var scale = 1 / maxPercent; //需要压缩的比例 <1 这一步会让实际得到的间隔更小
  62733. newPercents = newPercents.map(e => e *= scale);
  62734. }
  62735. }
  62736. this.newPointsPercents = newPercents;
  62737. //console.log(newPercents)
  62738. }
  62739. at(originPercent, delta, transitionRatio) {
  62740. originPercent = MathUtils.clamp(originPercent, 0, 1);
  62741. //修改第一层:起始时间
  62742. var percent = originPercent;
  62743. /* const easePercent = 0.3; //缓动占比 //如果能在所有从静止到运动的中间加缓动就好了呀:lastPos * 0.9 + currentPos * 0.1 ?
  62744. if(originPercent < easePercent){
  62745. console.log('easeIn')
  62746. percent = easing.easeInSine(originPercent, 0, easePercent, easePercent) //currentTime, startY, wholeY, duration 选了一个衔接时接近斜率1的缓动函数
  62747. }else if(originPercent > 1-easePercent){
  62748. console.log('easeOut')
  62749. percent = easing.easeOutSine(originPercent-(1-easePercent), 1-easePercent, easePercent, easePercent)
  62750. } */
  62751. var quaternion;
  62752. if (percent < 1) {
  62753. //修改第二层:使用每个点的重定位的 newPointsPercents
  62754. this.currentIndex = this.newPointsPercents.findIndex(e => e > percent) - 1;
  62755. //假设每个节点的百分比是精确的,那么:
  62756. var curIndexPercent = this.newPointsPercents[this.currentIndex];
  62757. var nextIndexPercent = this.newPointsPercents[this.currentIndex + 1];
  62758. var progress = (percent - curIndexPercent) / (nextIndexPercent - curIndexPercent); //在这两个节点间的百分比
  62759. //投影到原本的 posCurve.pointsPercent上:
  62760. var curIndexOriPercent = this.posCurve.pointsPercent[this.currentIndex];
  62761. var nextIndexOriPercent = this.posCurve.pointsPercent[this.currentIndex + 1];
  62762. percent = curIndexOriPercent + (nextIndexOriPercent - curIndexOriPercent) * progress;
  62763. var endQuaternion = this.quaternions[this.currentIndex + 1];
  62764. var startQuaternion = this.quaternions[this.currentIndex];
  62765. quaternion = new Quaternion().copy(startQuaternion);
  62766. lerp.quaternion(quaternion, endQuaternion)(progress);
  62767. } else {
  62768. this.currentIndex = this.posCurve.points.length - 1;
  62769. quaternion = math.getQuaFromPosAim(this.posCurve.points[this.currentIndex], this.targets[this.currentIndex].position);
  62770. }
  62771. var position = this.posCurve.getPointAt(percent); // 需要this.posCurve.points.length>1 否则报错
  62772. //console.log(this.currentIndex, originPercent)
  62773. //缓动:
  62774. var aimQua, aimPos;
  62775. if (delta != void 0) {
  62776. if (Potree.settings.tourTestCameraMove) {
  62777. aimQua = this.frustum.quaternion.clone();
  62778. aimPos = this.frustum.position.clone();
  62779. } else {
  62780. var camera = viewer.scene.getActiveCamera();
  62781. aimQua = camera.quaternion.clone();
  62782. aimPos = camera.position.clone();
  62783. }
  62784. transitionRatio = transitionRatio || 1 / Potree.settings.cameraAniSmoothRatio; //渐变系数,越小缓动程度越高,越平滑
  62785. transitionRatio *= delta * 60; //假设标准帧率为60fps,当帧率低时(delta大时)要降低缓动
  62786. //console.log(transitionRatio, delta) //画面ui变化会使delta变大
  62787. transitionRatio = MathUtils.clamp(transitionRatio, 0, 1);
  62788. lerp.quaternion(aimQua, quaternion)(transitionRatio); //每次只改变一点点
  62789. lerp.vector(aimPos, position)(transitionRatio);
  62790. } else {
  62791. aimQua = quaternion;
  62792. aimPos = position;
  62793. }
  62794. var rotation = new Euler().setFromQuaternion(aimQua);
  62795. var frame = {
  62796. position: aimPos,
  62797. rotation
  62798. };
  62799. return frame;
  62800. }
  62801. set(percent) {
  62802. this.percent = percent;
  62803. }
  62804. setVisible(visible) {
  62805. this.node.visible = visible;
  62806. this.posCurve.visible = visible;
  62807. this.targets.forEach(e => e.visible = visible);
  62808. this.visible = visible;
  62809. }
  62810. setDuration(duration) {
  62811. if (duration != this.duration) {
  62812. this.duration = duration;
  62813. if (this.quaternions.length == this.posCurve.points.length) this.reMapCurvePercent();
  62814. }
  62815. }
  62816. getDuration(duration) {
  62817. return this.duration;
  62818. }
  62819. play() {
  62820. var startOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  62821. if (this.onUpdate) {
  62822. return console.error('已经开始播放');
  62823. }
  62824. var startPercent = 0,
  62825. currentIndex = 0;
  62826. if (startOptions.percent != void 0) {
  62827. startPercent = startOptions.percent;
  62828. } else if (startOptions.index) {
  62829. currentIndex = index;
  62830. //startPercent = index/(this.posCurve.points.length-1)
  62831. startPercent = this.posCurve.pointsPercent[index];
  62832. }
  62833. //const tStart = performance.now();
  62834. var duration = this.duration;
  62835. this.originalyVisible = this.visible;
  62836. Potree.settings.tourTestCameraMove || this.setVisible(false);
  62837. var tStart,
  62838. startTransitionRatio = 0.2;
  62839. var startDelay = 1 / startTransitionRatio / 20; //因为缓动所以延迟开始,前面前都是at(0),使过渡到开始点位(但是依旧不能准确停在起始点,因为缓动是乘百分比有残留。所以直接平滑衔接到开始后的位置)
  62840. var hasPlayedTime = 0;
  62841. var finishDelay = Potree.settings.cameraAniSmoothRatio / 60 * 3; //结束后还需要多久时间才能大致达到缓动的最终目标
  62842. var hasStoppedTime = 0;
  62843. this.onUpdate = e => {
  62844. if (this.posCurve.points.length < 2) {
  62845. if (this.posCurve.points.length == 1) {
  62846. viewer.scene.view.position.copy(this.posCurve.points[0]);
  62847. viewer.scene.view.rotation = new Euler().setFromQuaternion(this.quaternions[0]);
  62848. }
  62849. this.pause();
  62850. return;
  62851. }
  62852. var percent, transitionRatio;
  62853. if (tStart) {
  62854. var tNow = performance.now();
  62855. var elapsed = (tNow - tStart) / 1000;
  62856. percent = elapsed / duration + startPercent;
  62857. } else {
  62858. //从当前位置过渡到开始位置
  62859. percent = 0;
  62860. hasPlayedTime += e.delta;
  62861. transitionRatio = startTransitionRatio;
  62862. //console.log('延迟开始')
  62863. if (hasPlayedTime > startDelay) {
  62864. tStart = performance.now();
  62865. }
  62866. }
  62867. this.set(percent);
  62868. var frame = this.at(percent, e.delta, transitionRatio);
  62869. if (currentIndex != this.currentIndex) {
  62870. currentIndex = this.currentIndex;
  62871. console.log('updateCurrentIndex', currentIndex);
  62872. this.dispatchEvent({
  62873. type: 'updateCurrentIndex',
  62874. currentIndex
  62875. });
  62876. }
  62877. if (!Potree.settings.tourTestCameraMove) {
  62878. viewer.scene.view.position.copy(frame.position);
  62879. //viewer.scene.view.lookAt(frame.target);
  62880. viewer.scene.view.rotation = frame.rotation;
  62881. }
  62882. this.updateFrustum(frame);
  62883. if (percent >= 1) {
  62884. if (hasStoppedTime > finishDelay) {
  62885. this.pause();
  62886. } else {
  62887. hasStoppedTime += e.delta;
  62888. //console.log('延迟结束')
  62889. }
  62890. }
  62891. };
  62892. this.viewer.addEventListener("update", this.onUpdate);
  62893. }
  62894. pause() {
  62895. this.setVisible(this.originalyVisible);
  62896. this.viewer.removeEventListener("update", this.onUpdate);
  62897. this.dispatchEvent('playDone');
  62898. this.onUpdate = null;
  62899. }
  62900. updateFrustum(frame) {
  62901. var frustum = this.frustum;
  62902. if (this.posCurve.points.length > 1) {
  62903. frustum.visible = true;
  62904. } else {
  62905. frustum.visible = false;
  62906. return;
  62907. }
  62908. frame = frame || this.at(this.percent);
  62909. frustum.position.copy(frame.position);
  62910. //frustum.lookAt(...frame.target.toArray());
  62911. frustum.rotation.copy(frame.rotation);
  62912. viewer.dispatchEvent('content_changed');
  62913. }
  62914. changeCallback(i) {
  62915. this.posCurve.update();
  62916. //this.targets.forEach(e=>e.update())
  62917. this.updatePathCallback();
  62918. if (i == void 0) {
  62919. var length = this.posCurve.points.length;
  62920. for (var _i3 = 0; _i3 < length; _i3++) {
  62921. this.dragPointCallback({
  62922. index: _i3
  62923. });
  62924. }
  62925. } else this.dragPointCallback({
  62926. index: i
  62927. });
  62928. this.updateFrustum();
  62929. }
  62930. dispose() {
  62931. //add
  62932. this.posCurve.dispose();
  62933. //this.targetCurve.dispatchEvent({type:'dispose'})
  62934. this.targets.forEach(e => e.dispose());
  62935. this.durations = [];
  62936. this.node.parent.remove(this.node);
  62937. }
  62938. }
  62939. //scene.removeCameraAnimation
  62940. //修改:不使用targetCurve作为target曲线,因为播放时posCuve的节点和targetCurve并没有对应,且使用target的曲线会使角度变化大的情况过渡生硬。
  62941. // 改完旋转了。但是位置也有问题。速度完全和路程相关,当在同一位置设置多点时,这段的总时长为0. (是否要设置最小时长?不过也做不到 - -)
  62942. class MeasurePanel {
  62943. constructor(viewer, measurement, propertiesPanel) {
  62944. this.viewer = viewer;
  62945. this.measurement = measurement;
  62946. this.propertiesPanel = propertiesPanel;
  62947. this._update = () => {
  62948. this.update();
  62949. };
  62950. }
  62951. createCoordinatesTable(points) {
  62952. var _this = this;
  62953. var table = $("\n\t\t\t<table class=\"measurement_value_table\">\n\t\t\t\t<tr>\n\t\t\t\t\t<th>x</th>\n\t\t\t\t\t<th>y</th>\n\t\t\t\t\t<th>z</th>\n\t\t\t\t\t<th></th>\n\t\t\t\t</tr>\n\t\t\t</table>\n\t\t");
  62954. var copyIconPath = Potree.resourcePath + '/icons/copy.svg';
  62955. var _loop = function _loop(point) {
  62956. var x = Utils.addCommas(point.x.toFixed(3));
  62957. var y = Utils.addCommas(point.y.toFixed(3));
  62958. var z = Utils.addCommas(point.z.toFixed(3));
  62959. var row = $("\n\t\t\t\t<tr>\n\t\t\t\t\t<td><span>".concat(x, "</span></td>\n\t\t\t\t\t<td><span>").concat(y, "</span></td>\n\t\t\t\t\t<td><span>").concat(z, "</span></td>\n\t\t\t\t\t<td align=\"right\" style=\"width: 25%\">\n\t\t\t\t\t\t<img name=\"copy\" title=\"copy\" class=\"button-icon\" src=\"").concat(copyIconPath, "\" style=\"width: 16px; height: 16px\"/>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\t\t\t"));
  62960. _this.elCopy = row.find("img[name=copy]");
  62961. _this.elCopy.click(() => {
  62962. var msg = point.toArray().map(c => c.toFixed(3)).join(", ");
  62963. Utils.clipboardCopy(msg);
  62964. _this.viewer.postMessage("Copied value to clipboard: <br>'".concat(msg, "'"), {
  62965. duration: 3000
  62966. });
  62967. });
  62968. table.append(row);
  62969. };
  62970. for (var point of points) {
  62971. _loop(point);
  62972. }
  62973. return table;
  62974. }
  62975. createAttributesTable() {
  62976. var elTable = $('<table class="measurement_value_table"></table>');
  62977. var point = this.measurement.points[0];
  62978. /* for(let attributeName of Object.keys(point)){
  62979. if(attributeName === "position"){
  62980. }else if(attributeName === "rgba"){
  62981. let color = point.rgba;
  62982. let text = color.join(', ');
  62983. elTable.append($(`
  62984. <tr>
  62985. <td>rgb</td>
  62986. <td>${text}</td>
  62987. </tr>
  62988. `));
  62989. }else{
  62990. let value = point[attributeName];
  62991. let text = value.join(', ');
  62992. elTable.append($(`
  62993. <tr>
  62994. <td>${attributeName}</td>
  62995. <td>${text}</td>
  62996. </tr>
  62997. `));
  62998. }
  62999. } */
  63000. return elTable;
  63001. }
  63002. update() {}
  63003. }
  63004. ;
  63005. class DistancePanel extends MeasurePanel {
  63006. constructor(viewer, measurement, propertiesPanel) {
  63007. super(viewer, measurement, propertiesPanel);
  63008. var removeIconPath = Potree.resourcePath + '/icons/remove.svg';
  63009. this.elContent = $("\n\t\t\t<div class=\"measurement_content selectable\">\n\t\t\t\t<span class=\"coordinates_table_container\"></span>\n\t\t\t\t<br>\n\t\t\t\t<table id=\"distances_table\" class=\"measurement_value_table\"></table>\n\n\t\t\t\t<!-- ACTIONS -->\n\t\t\t\t<div style=\"display: flex; margin-top: 12px\">\n\t\t\t\t\t<span>\n\t\t\t\t\t\t<input type=\"button\" name=\"make_profile\" value=\"profile from measure\" />\n\t\t\t\t\t</span>\n\t\t\t\t\t<span style=\"flex-grow: 1\"></span>\n\t\t\t\t\t<img name=\"remove\" class=\"button-icon\" src=\"".concat(removeIconPath, "\" style=\"width: 16px; height: 16px\"/>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t"));
  63010. this.elRemove = this.elContent.find("img[name=remove]");
  63011. this.elRemove.click(() => {
  63012. this.viewer.scene.removeMeasurement(measurement);
  63013. });
  63014. this.elMakeProfile = this.elContent.find("input[name=make_profile]");
  63015. this.elMakeProfile.click(() => {
  63016. //measurement.points;
  63017. var profile = new Profile();
  63018. profile.name = measurement.name;
  63019. profile.width = measurement.getTotalDistance() / 50;
  63020. for (var point of measurement.points) {
  63021. profile.addMarker(point.position.clone());
  63022. }
  63023. this.viewer.scene.addProfile(profile);
  63024. });
  63025. this.propertiesPanel.addVolatileListener(measurement, "marker_added", this._update);
  63026. this.propertiesPanel.addVolatileListener(measurement, "marker_removed", this._update);
  63027. this.propertiesPanel.addVolatileListener(measurement, "marker_moved", this._update);
  63028. this.update();
  63029. }
  63030. update() {
  63031. var elCoordiantesContainer = this.elContent.find('.coordinates_table_container');
  63032. elCoordiantesContainer.empty();
  63033. elCoordiantesContainer.append(this.createCoordinatesTable(this.measurement.points.map(p => p.position)));
  63034. var positions = this.measurement.points.map(p => p.position);
  63035. var distances = [];
  63036. for (var i = 0; i < positions.length - 1; i++) {
  63037. var d = positions[i].distanceTo(positions[i + 1]);
  63038. distances.push(d.toFixed(3));
  63039. }
  63040. var totalDistance = this.measurement.getTotalDistance().toFixed(3);
  63041. var elDistanceTable = this.elContent.find("#distances_table");
  63042. elDistanceTable.empty();
  63043. for (var _i = 0; _i < distances.length; _i++) {
  63044. var label = _i === 0 ? 'Distances: ' : '';
  63045. var distance = distances[_i];
  63046. var elDistance = $("\n\t\t\t\t<tr>\n\t\t\t\t\t<th>".concat(label, "</th>\n\t\t\t\t\t<td style=\"width: 100%; padding-left: 10px\">").concat(distance, "</td>\n\t\t\t\t</tr>"));
  63047. elDistanceTable.append(elDistance);
  63048. }
  63049. var elTotal = $("\n\t\t\t<tr>\n\t\t\t\t<th>Total: </td><td style=\"width: 100%; padding-left: 10px\">".concat(totalDistance, "</th>\n\t\t\t</tr>"));
  63050. elDistanceTable.append(elTotal);
  63051. }
  63052. }
  63053. ;
  63054. class PointPanel extends MeasurePanel {
  63055. constructor(viewer, measurement, propertiesPanel) {
  63056. super(viewer, measurement, propertiesPanel);
  63057. var removeIconPath = Potree.resourcePath + '/icons/remove.svg';
  63058. this.elContent = $("\n\t\t\t<div class=\"measurement_content selectable\">\n\t\t\t\t<span class=\"coordinates_table_container\"></span>\n\t\t\t\t<br>\n\t\t\t\t<span class=\"attributes_table_container\"></span>\n\n\t\t\t\t<!-- ACTIONS -->\n\t\t\t\t<div style=\"display: flex; margin-top: 12px\">\n\t\t\t\t\t<span></span>\n\t\t\t\t\t<span style=\"flex-grow: 1\"></span>\n\t\t\t\t\t<img name=\"remove\" class=\"button-icon\" src=\"".concat(removeIconPath, "\" style=\"width: 16px; height: 16px\"/>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t"));
  63059. this.elRemove = this.elContent.find("img[name=remove]");
  63060. this.elRemove.click(() => {
  63061. this.viewer.scene.removeMeasurement(measurement);
  63062. });
  63063. this.propertiesPanel.addVolatileListener(measurement, "marker_added", this._update);
  63064. this.propertiesPanel.addVolatileListener(measurement, "marker_removed", this._update);
  63065. this.propertiesPanel.addVolatileListener(measurement, "marker_moved", this._update);
  63066. this.update();
  63067. }
  63068. update() {
  63069. var elCoordiantesContainer = this.elContent.find('.coordinates_table_container');
  63070. elCoordiantesContainer.empty();
  63071. elCoordiantesContainer.append(this.createCoordinatesTable(this.measurement.points));
  63072. var elAttributesContainer = this.elContent.find('.attributes_table_container');
  63073. elAttributesContainer.empty();
  63074. elAttributesContainer.append(this.createAttributesTable());
  63075. }
  63076. }
  63077. ;
  63078. class AreaPanel extends MeasurePanel {
  63079. constructor(viewer, measurement, propertiesPanel) {
  63080. super(viewer, measurement, propertiesPanel);
  63081. var removeIconPath = Potree.resourcePath + '/icons/remove.svg';
  63082. this.elContent = $("\n\t\t\t<div class=\"measurement_content selectable\">\n\t\t\t\t<span class=\"coordinates_table_container\"></span>\n\t\t\t\t<br>\n\t\t\t\t<span style=\"font-weight: bold\">Area: </span>\n\t\t\t\t<span id=\"measurement_area\"></span>\n\n\t\t\t\t<!-- ACTIONS -->\n\t\t\t\t<div style=\"display: flex; margin-top: 12px\">\n\t\t\t\t\t<span></span>\n\t\t\t\t\t<span style=\"flex-grow: 1\"></span>\n\t\t\t\t\t<img name=\"remove\" class=\"button-icon\" src=\"".concat(removeIconPath, "\" style=\"width: 16px; height: 16px\"/>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t"));
  63083. this.elRemove = this.elContent.find("img[name=remove]");
  63084. this.elRemove.click(() => {
  63085. this.viewer.scene.removeMeasurement(measurement);
  63086. });
  63087. this.propertiesPanel.addVolatileListener(measurement, "marker_added", this._update);
  63088. this.propertiesPanel.addVolatileListener(measurement, "marker_removed", this._update);
  63089. this.propertiesPanel.addVolatileListener(measurement, "marker_moved", this._update);
  63090. this.update();
  63091. }
  63092. update() {
  63093. var elCoordiantesContainer = this.elContent.find('.coordinates_table_container');
  63094. elCoordiantesContainer.empty();
  63095. elCoordiantesContainer.append(this.createCoordinatesTable(this.measurement.points));
  63096. var elArea = this.elContent.find("#measurement_area");
  63097. elArea.html(this.measurement.area.value.toFixed(3));
  63098. }
  63099. }
  63100. ;
  63101. class AnglePanel extends MeasurePanel {
  63102. constructor(viewer, measurement, propertiesPanel) {
  63103. super(viewer, measurement, propertiesPanel);
  63104. var removeIconPath = Potree.resourcePath + '/icons/remove.svg';
  63105. this.elContent = $("\n\t\t\t<div class=\"measurement_content selectable\">\n\t\t\t\t<span class=\"coordinates_table_container\"></span>\n\t\t\t\t<br>\n\t\t\t\t<table class=\"measurement_value_table\">\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<th>\u03B1</th>\n\t\t\t\t\t\t<th>\u03B2</th>\n\t\t\t\t\t\t<th>\u03B3</th>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td align=\"center\" id=\"angle_cell_alpha\" style=\"width: 33%\"></td>\n\t\t\t\t\t\t<td align=\"center\" id=\"angle_cell_betta\" style=\"width: 33%\"></td>\n\t\t\t\t\t\t<td align=\"center\" id=\"angle_cell_gamma\" style=\"width: 33%\"></td>\n\t\t\t\t\t</tr>\n\t\t\t\t</table>\n\n\t\t\t\t<!-- ACTIONS -->\n\t\t\t\t<div style=\"display: flex; margin-top: 12px\">\n\t\t\t\t\t<span></span>\n\t\t\t\t\t<span style=\"flex-grow: 1\"></span>\n\t\t\t\t\t<img name=\"remove\" class=\"button-icon\" src=\"".concat(removeIconPath, "\" style=\"width: 16px; height: 16px\"/>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t"));
  63106. this.elRemove = this.elContent.find("img[name=remove]");
  63107. this.elRemove.click(() => {
  63108. this.viewer.scene.removeMeasurement(measurement);
  63109. });
  63110. this.propertiesPanel.addVolatileListener(measurement, "marker_added", this._update);
  63111. this.propertiesPanel.addVolatileListener(measurement, "marker_removed", this._update);
  63112. this.propertiesPanel.addVolatileListener(measurement, "marker_moved", this._update);
  63113. this.update();
  63114. }
  63115. update() {
  63116. var elCoordiantesContainer = this.elContent.find('.coordinates_table_container');
  63117. elCoordiantesContainer.empty();
  63118. elCoordiantesContainer.append(this.createCoordinatesTable(this.measurement.points.map(p => p.position)));
  63119. var angles = [];
  63120. for (var i = 0; i < this.measurement.points.length; i++) {
  63121. angles.push(this.measurement.getAngle(i) * (180.0 / Math.PI));
  63122. }
  63123. angles = angles.map(a => a.toFixed(1) + '\u00B0');
  63124. var elAlpha = this.elContent.find("#angle_cell_alpha");
  63125. var elBetta = this.elContent.find("#angle_cell_betta");
  63126. var elGamma = this.elContent.find("#angle_cell_gamma");
  63127. elAlpha.html(angles[0]);
  63128. elBetta.html(angles[1]);
  63129. elGamma.html(angles[2]);
  63130. }
  63131. }
  63132. ;
  63133. class CirclePanel extends MeasurePanel {
  63134. constructor(viewer, measurement, propertiesPanel) {
  63135. super(viewer, measurement, propertiesPanel);
  63136. var removeIconPath = Potree.resourcePath + '/icons/remove.svg';
  63137. this.elContent = $("\n\t\t\t<div class=\"measurement_content selectable\">\n\t\t\t\t<span class=\"coordinates_table_container\"></span>\n\t\t\t\t<br>\n\t\t\t\t<table id=\"infos_table\" class=\"measurement_value_table\"></table>\n\n\t\t\t\t<!-- ACTIONS -->\n\t\t\t\t<div style=\"display: flex; margin-top: 12px\">\n\t\t\t\t\t<span></span>\n\t\t\t\t\t<span style=\"flex-grow: 1\"></span>\n\t\t\t\t\t<img name=\"remove\" class=\"button-icon\" src=\"".concat(removeIconPath, "\" style=\"width: 16px; height: 16px\"/>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t"));
  63138. this.elRemove = this.elContent.find("img[name=remove]");
  63139. this.elRemove.click(() => {
  63140. this.viewer.scene.removeMeasurement(measurement);
  63141. });
  63142. this.propertiesPanel.addVolatileListener(measurement, "marker_added", this._update);
  63143. this.propertiesPanel.addVolatileListener(measurement, "marker_removed", this._update);
  63144. this.propertiesPanel.addVolatileListener(measurement, "marker_moved", this._update);
  63145. this.update();
  63146. }
  63147. update() {
  63148. var elCoordiantesContainer = this.elContent.find('.coordinates_table_container');
  63149. elCoordiantesContainer.empty();
  63150. elCoordiantesContainer.append(this.createCoordinatesTable(this.measurement.points.map(p => p.position)));
  63151. var elInfos = this.elContent.find("#infos_table");
  63152. if (this.measurement.points.length !== 3) {
  63153. elInfos.empty();
  63154. return;
  63155. }
  63156. var A = this.measurement.points[0].position;
  63157. var B = this.measurement.points[1].position;
  63158. var C = this.measurement.points[2].position;
  63159. var center = Potree.Utils.computeCircleCenter(A, B, C);
  63160. var radius = center.distanceTo(A);
  63161. var circumference = 2 * Math.PI * radius;
  63162. var format = number => {
  63163. return Potree.Utils.addCommas(number.toFixed(3));
  63164. };
  63165. var txtCenter = "".concat(format(center.x), " ").concat(format(center.y), " ").concat(format(center.z));
  63166. var txtRadius = format(radius);
  63167. var txtCircumference = format(circumference);
  63168. var thStyle = "style=\"text-align: left\"";
  63169. var tdStyle = "style=\"width: 100%; padding: 5px;\"";
  63170. elInfos.html("\n\t\t\t<tr>\n\t\t\t\t<th ".concat(thStyle, ">Center: </th>\n\t\t\t\t<td ").concat(tdStyle, "></td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td ").concat(tdStyle, " colspan=\"2\">\n\t\t\t\t\t").concat(txtCenter, "\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<th ").concat(thStyle, ">Radius: </th>\n\t\t\t\t<td ").concat(tdStyle, ">").concat(txtRadius, "</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<th ").concat(thStyle, ">Circumference: </th>\n\t\t\t\t<td ").concat(tdStyle, ">").concat(txtCircumference, "</td>\n\t\t\t</tr>\n\t\t"));
  63171. }
  63172. }
  63173. ;
  63174. class HeightPanel extends MeasurePanel {
  63175. constructor(viewer, measurement, propertiesPanel) {
  63176. super(viewer, measurement, propertiesPanel);
  63177. var removeIconPath = Potree.resourcePath + '/icons/remove.svg';
  63178. this.elContent = $("\n\t\t\t<div class=\"measurement_content selectable\">\n\t\t\t\t<span class=\"coordinates_table_container\"></span>\n\t\t\t\t<br>\n\t\t\t\t<span id=\"height_label\">Height: </span><br>\n\n\t\t\t\t<!-- ACTIONS -->\n\t\t\t\t<div style=\"display: flex; margin-top: 12px\">\n\t\t\t\t\t<span></span>\n\t\t\t\t\t<span style=\"flex-grow: 1\"></span>\n\t\t\t\t\t<img name=\"remove\" class=\"button-icon\" src=\"".concat(removeIconPath, "\" style=\"width: 16px; height: 16px\"/>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t"));
  63179. this.elRemove = this.elContent.find("img[name=remove]");
  63180. this.elRemove.click(() => {
  63181. this.viewer.scene.removeMeasurement(measurement);
  63182. });
  63183. this.propertiesPanel.addVolatileListener(measurement, "marker_added", this._update);
  63184. this.propertiesPanel.addVolatileListener(measurement, "marker_removed", this._update);
  63185. this.propertiesPanel.addVolatileListener(measurement, "marker_moved", this._update);
  63186. this.update();
  63187. }
  63188. update() {
  63189. var elCoordiantesContainer = this.elContent.find('.coordinates_table_container');
  63190. elCoordiantesContainer.empty();
  63191. elCoordiantesContainer.append(this.createCoordinatesTable(this.measurement.points.map(p => p.position)));
  63192. {
  63193. var points = this.measurement.points;
  63194. var sorted = points.slice().sort((a, b) => a.position.z - b.position.z);
  63195. var lowPoint = sorted[0].position.clone();
  63196. var highPoint = sorted[sorted.length - 1].position.clone();
  63197. var min = lowPoint.z;
  63198. var max = highPoint.z;
  63199. var height = max - min;
  63200. height = height.toFixed(3);
  63201. this.elHeightLabel = this.elContent.find("#height_label");
  63202. this.elHeightLabel.html("<b>Height:</b> ".concat(height));
  63203. }
  63204. }
  63205. }
  63206. ;
  63207. class VolumePanel extends MeasurePanel {
  63208. constructor(viewer, measurement, propertiesPanel) {
  63209. super(viewer, measurement, propertiesPanel);
  63210. var copyIconPath = Potree.resourcePath + '/icons/copy.svg';
  63211. var removeIconPath = Potree.resourcePath + '/icons/remove.svg';
  63212. var lblLengthText = new Map([[BoxVolume, "length"], [SphereVolume$1, "rx"]]).get(measurement.constructor);
  63213. var lblWidthText = new Map([[BoxVolume, "width"], [SphereVolume$1, "ry"]]).get(measurement.constructor);
  63214. var lblHeightText = new Map([[BoxVolume, "height"], [SphereVolume$1, "rz"]]).get(measurement.constructor);
  63215. this.elContent = $("\n\t\t\t<div class=\"measurement_content selectable\">\n\t\t\t\t<span class=\"coordinates_table_container\"></span>\n\n\t\t\t\t<table class=\"measurement_value_table\">\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<th>\u03B1</th>\n\t\t\t\t\t\t<th>\u03B2</th>\n\t\t\t\t\t\t<th>\u03B3</th>\n\t\t\t\t\t\t<th></th>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td align=\"center\" id=\"angle_cell_alpha\" style=\"width: 33%\"></td>\n\t\t\t\t\t\t<td align=\"center\" id=\"angle_cell_betta\" style=\"width: 33%\"></td>\n\t\t\t\t\t\t<td align=\"center\" id=\"angle_cell_gamma\" style=\"width: 33%\"></td>\n\t\t\t\t\t\t<td align=\"right\" style=\"width: 25%\">\n\t\t\t\t\t\t\t<img name=\"copyRotation\" title=\"copy\" class=\"button-icon\" src=\"".concat(copyIconPath, "\" style=\"width: 16px; height: 16px\"/>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>\n\t\t\t\t</table>\n\n\t\t\t\t<table class=\"measurement_value_table\">\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<th>").concat(lblLengthText, "</th>\n\t\t\t\t\t\t<th>").concat(lblWidthText, "</th>\n\t\t\t\t\t\t<th>").concat(lblHeightText, "</th>\n\t\t\t\t\t\t<th></th>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td align=\"center\" id=\"cell_length\" style=\"width: 33%\"></td>\n\t\t\t\t\t\t<td align=\"center\" id=\"cell_width\" style=\"width: 33%\"></td>\n\t\t\t\t\t\t<td align=\"center\" id=\"cell_height\" style=\"width: 33%\"></td>\n\t\t\t\t\t\t<td align=\"right\" style=\"width: 25%\">\n\t\t\t\t\t\t\t<img name=\"copyScale\" title=\"copy\" class=\"button-icon\" src=\"").concat(copyIconPath, "\" style=\"width: 16px; height: 16px\"/>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>\n\t\t\t\t</table>\n\n\t\t\t\t<br>\n\t\t\t\t<span style=\"font-weight: bold\">Volume: </span>\n\t\t\t\t<span id=\"measurement_volume\"></span>\n\n\t\t\t\t<!--\n\t\t\t\t<li>\n\t\t\t\t\t<label style=\"whitespace: nowrap\">\n\t\t\t\t\t\t<input id=\"volume_show\" type=\"checkbox\"/>\n\t\t\t\t\t\t<span>show volume</span>\n\t\t\t\t\t</label>\n\t\t\t\t</li>-->\n\n\t\t\t\t<li>\n\t\t\t\t\t<label style=\"whitespace: nowrap\">\n\t\t\t\t\t\t<input id=\"volume_clip\" type=\"checkbox\"/>\n\t\t\t\t\t\t<span>make clip volume</span>\n\t\t\t\t\t</label>\n\t\t\t\t</li>\n\n\t\t\t\t<li style=\"margin-top: 10px\">\n\t\t\t\t\t<input name=\"download_volume\" type=\"button\" value=\"prepare download\" style=\"width: 100%\" />\n\t\t\t\t\t<div name=\"download_message\"></div>\n\t\t\t\t</li>\n\n\n\t\t\t\t<!-- ACTIONS -->\n\t\t\t\t<li style=\"display: grid; grid-template-columns: auto auto; grid-column-gap: 5px; margin-top: 10px\">\n\t\t\t\t\t<input id=\"volume_reset_orientation\" type=\"button\" value=\"reset orientation\"/>\n\t\t\t\t\t<input id=\"volume_make_uniform\" type=\"button\" value=\"make uniform\"/>\n\t\t\t\t</li>\n\t\t\t\t<div style=\"display: flex; margin-top: 12px\">\n\t\t\t\t\t<span></span>\n\t\t\t\t\t<span style=\"flex-grow: 1\"></span>\n\t\t\t\t\t<img name=\"remove\" class=\"button-icon\" src=\"").concat(removeIconPath, "\" style=\"width: 16px; height: 16px\"/>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t"));
  63216. {
  63217. // download
  63218. this.elDownloadButton = this.elContent.find("input[name=download_volume]");
  63219. if (this.propertiesPanel.viewer.server) {
  63220. this.elDownloadButton.click(() => this.download());
  63221. } else {
  63222. this.elDownloadButton.hide();
  63223. }
  63224. }
  63225. this.elCopyRotation = this.elContent.find("img[name=copyRotation]");
  63226. this.elCopyRotation.click(() => {
  63227. var rotation = this.measurement.rotation.toArray().slice(0, 3);
  63228. var msg = rotation.map(c => c.toFixed(3)).join(", ");
  63229. Utils.clipboardCopy(msg);
  63230. this.viewer.postMessage("Copied value to clipboard: <br>'".concat(msg, "'"), {
  63231. duration: 3000
  63232. });
  63233. });
  63234. this.elCopyScale = this.elContent.find("img[name=copyScale]");
  63235. this.elCopyScale.click(() => {
  63236. var scale = this.measurement.scale.toArray();
  63237. var msg = scale.map(c => c.toFixed(3)).join(", ");
  63238. Utils.clipboardCopy(msg);
  63239. this.viewer.postMessage("Copied value to clipboard: <br>'".concat(msg, "'"), {
  63240. duration: 3000
  63241. });
  63242. });
  63243. this.elRemove = this.elContent.find("img[name=remove]");
  63244. this.elRemove.click(() => {
  63245. this.viewer.scene.removeVolume(measurement);
  63246. });
  63247. this.elContent.find("#volume_reset_orientation").click(() => {
  63248. measurement.rotation.set(0, 0, 0);
  63249. });
  63250. this.elContent.find("#volume_make_uniform").click(() => {
  63251. var mean = (measurement.scale.x + measurement.scale.y + measurement.scale.z) / 3;
  63252. measurement.scale.set(mean, mean, mean);
  63253. });
  63254. this.elCheckClip = this.elContent.find('#volume_clip');
  63255. this.elCheckClip.click(event => {
  63256. this.measurement.clip = event.target.checked;
  63257. });
  63258. this.elCheckShow = this.elContent.find('#volume_show');
  63259. this.elCheckShow.click(event => {
  63260. this.measurement.visible = event.target.checked;
  63261. });
  63262. this.propertiesPanel.addVolatileListener(measurement, "position_changed", this._update);
  63263. this.propertiesPanel.addVolatileListener(measurement, "orientation_changed", this._update);
  63264. this.propertiesPanel.addVolatileListener(measurement, "scale_changed", this._update);
  63265. this.propertiesPanel.addVolatileListener(measurement, "clip_changed", this._update);
  63266. this.update();
  63267. }
  63268. async download() {
  63269. var clipBox = this.measurement;
  63270. var regions = [];
  63271. //for(let clipBox of boxes){
  63272. {
  63273. var toClip = clipBox.matrixWorld;
  63274. var px = new Vector3(+0.5, 0, 0).applyMatrix4(toClip);
  63275. var nx = new Vector3(-0.5, 0, 0).applyMatrix4(toClip);
  63276. var py = new Vector3(0, +0.5, 0).applyMatrix4(toClip);
  63277. var ny = new Vector3(0, -0.5, 0).applyMatrix4(toClip);
  63278. var pz = new Vector3(0, 0, +0.5).applyMatrix4(toClip);
  63279. var nz = new Vector3(0, 0, -0.5).applyMatrix4(toClip);
  63280. var pxN = new Vector3().subVectors(nx, px).normalize();
  63281. var nxN = pxN.clone().multiplyScalar(-1);
  63282. var pyN = new Vector3().subVectors(ny, py).normalize();
  63283. var nyN = pyN.clone().multiplyScalar(-1);
  63284. var pzN = new Vector3().subVectors(nz, pz).normalize();
  63285. var nzN = pzN.clone().multiplyScalar(-1);
  63286. var planes = [new Plane().setFromNormalAndCoplanarPoint(pxN, px), new Plane().setFromNormalAndCoplanarPoint(nxN, nx), new Plane().setFromNormalAndCoplanarPoint(pyN, py), new Plane().setFromNormalAndCoplanarPoint(nyN, ny), new Plane().setFromNormalAndCoplanarPoint(pzN, pz), new Plane().setFromNormalAndCoplanarPoint(nzN, nz)];
  63287. var planeQueryParts = [];
  63288. for (var plane of planes) {
  63289. var part = [plane.normal.toArray(), plane.constant].join(",");
  63290. part = "[".concat(part, "]");
  63291. planeQueryParts.push(part);
  63292. }
  63293. var region = "[" + planeQueryParts.join(",") + "]";
  63294. regions.push(region);
  63295. }
  63296. var regionsArg = regions.join(",");
  63297. var pointcloudArgs = [];
  63298. for (var pointcloud of this.viewer.scene.pointclouds) {
  63299. if (!pointcloud.visible) {
  63300. continue;
  63301. }
  63302. var offset = pointcloud.pcoGeometry.offset.clone();
  63303. var negateOffset = new Matrix4().makeTranslation(...offset.multiplyScalar(-1).toArray());
  63304. var matrixWorld = pointcloud.matrixWorld;
  63305. var transform = new Matrix4().multiplyMatrices(matrixWorld, negateOffset);
  63306. var path = "".concat(window.location.pathname, "/../").concat(pointcloud.pcoGeometry.url);
  63307. var arg = {
  63308. path: path,
  63309. transform: transform.elements
  63310. };
  63311. var argString = JSON.stringify(arg);
  63312. pointcloudArgs.push(argString);
  63313. }
  63314. var pointcloudsArg = pointcloudArgs.join(",");
  63315. var elMessage = this.elContent.find("div[name=download_message]");
  63316. var error = message => {
  63317. elMessage.html("<div style=\"color: #ff0000\">ERROR: ".concat(message, "</div>"));
  63318. };
  63319. var info = message => {
  63320. elMessage.html("".concat(message));
  63321. };
  63322. var handle = null;
  63323. {
  63324. // START FILTER
  63325. var url = "".concat(viewer.server, "/create_regions_filter?pointclouds=[").concat(pointcloudsArg, "]&regions=[").concat(regionsArg, "]");
  63326. //console.log(url);
  63327. info("estimating results ...");
  63328. var response = await fetch(url);
  63329. var jsResponse = await response.json();
  63330. //console.log(jsResponse);
  63331. if (!jsResponse.handle) {
  63332. error(jsResponse.message);
  63333. return;
  63334. } else {
  63335. handle = jsResponse.handle;
  63336. }
  63337. }
  63338. {
  63339. // WAIT, CHECK PROGRESS, HANDLE FINISH
  63340. var _url = "".concat(viewer.server, "/check_regions_filter?handle=").concat(handle);
  63341. var sleep = function sleep(duration) {
  63342. return new Promise((res, rej) => {
  63343. setTimeout(() => {
  63344. res();
  63345. }, duration);
  63346. });
  63347. };
  63348. var handleFiltering = jsResponse => {
  63349. var {
  63350. progress,
  63351. estimate
  63352. } = jsResponse;
  63353. var progressFract = progress["processed points"] / estimate.points;
  63354. var progressPercents = parseInt(progressFract * 100);
  63355. info("progress: ".concat(progressPercents, "%"));
  63356. };
  63357. var handleFinish = jsResponse => {
  63358. var message = "downloads ready: <br>";
  63359. message += "<ul>";
  63360. for (var i = 0; i < jsResponse.pointclouds.length; i++) {
  63361. var _url2 = "".concat(viewer.server, "/download_regions_filter_result?handle=").concat(handle, "&index=").concat(i);
  63362. message += "<li><a href=\"".concat(_url2, "\">result_").concat(i, ".las</a> </li>\n");
  63363. }
  63364. var reportURL = "".concat(viewer.server, "/download_regions_filter_report?handle=").concat(handle);
  63365. message += "<li> <a href=\"".concat(reportURL, "\">report.json</a> </li>\n");
  63366. message += "</ul>";
  63367. info(message);
  63368. };
  63369. var handleUnexpected = jsResponse => {
  63370. var message = "Unexpected Response. <br>status: ".concat(jsResponse.status, " <br>message: ").concat(jsResponse.message);
  63371. info(message);
  63372. };
  63373. var handleError = jsResponse => {
  63374. var message = "ERROR: ".concat(jsResponse.message);
  63375. error(message);
  63376. throw new Error(message);
  63377. };
  63378. var start = Date.now();
  63379. while (true) {
  63380. var _response = await fetch(_url);
  63381. var _jsResponse = await _response.json();
  63382. if (_jsResponse.status === "ERROR") {
  63383. handleError(_jsResponse);
  63384. } else if (_jsResponse.status === "FILTERING") {
  63385. handleFiltering(_jsResponse);
  63386. } else if (_jsResponse.status === "FINISHED") {
  63387. handleFinish(_jsResponse);
  63388. break;
  63389. } else {
  63390. handleUnexpected(_jsResponse);
  63391. }
  63392. var durationS = (Date.now() - start) / 1000;
  63393. var sleepAmountMS = durationS < 10 ? 100 : 1000;
  63394. await sleep(sleepAmountMS);
  63395. }
  63396. }
  63397. }
  63398. update() {
  63399. var elCoordiantesContainer = this.elContent.find('.coordinates_table_container');
  63400. elCoordiantesContainer.empty();
  63401. elCoordiantesContainer.append(this.createCoordinatesTable([this.measurement.position]));
  63402. {
  63403. var angles = this.measurement.rotation.toVector3();
  63404. angles = angles.toArray();
  63405. //angles = [angles.z, angles.x, angles.y];
  63406. angles = angles.map(v => 180 * v / Math.PI);
  63407. angles = angles.map(a => a.toFixed(1) + '\u00B0');
  63408. var elAlpha = this.elContent.find("#angle_cell_alpha");
  63409. var elBetta = this.elContent.find("#angle_cell_betta");
  63410. var elGamma = this.elContent.find("#angle_cell_gamma");
  63411. elAlpha.html(angles[0]);
  63412. elBetta.html(angles[1]);
  63413. elGamma.html(angles[2]);
  63414. }
  63415. {
  63416. var dimensions = this.measurement.scale.toArray();
  63417. dimensions = dimensions.map(v => Utils.addCommas(v.toFixed(2)));
  63418. var elLength = this.elContent.find("#cell_length");
  63419. var elWidth = this.elContent.find("#cell_width");
  63420. var elHeight = this.elContent.find("#cell_height");
  63421. elLength.html(dimensions[0]);
  63422. elWidth.html(dimensions[1]);
  63423. elHeight.html(dimensions[2]);
  63424. }
  63425. {
  63426. var elVolume = this.elContent.find("#measurement_volume");
  63427. var volume = this.measurement.getVolume();
  63428. elVolume.html(Utils.addCommas(volume.toFixed(2)));
  63429. }
  63430. this.elCheckClip.prop("checked", this.measurement.clip);
  63431. this.elCheckShow.prop("checked", this.measurement.visible);
  63432. }
  63433. }
  63434. ;
  63435. class ProfilePanel extends MeasurePanel {
  63436. constructor(viewer, measurement, propertiesPanel) {
  63437. super(viewer, measurement, propertiesPanel);
  63438. var removeIconPath = Potree.resourcePath + '/icons/remove.svg';
  63439. this.elContent = $("\n\t\t\t<div class=\"measurement_content selectable\">\n\t\t\t\t<span class=\"coordinates_table_container\"></span>\n\t\t\t\t<br>\n\t\t\t\t<span style=\"display:flex\">\n\t\t\t\t\t<span style=\"display:flex; align-items: center; padding-right: 10px\">Width: </span>\n\t\t\t\t\t<input id=\"sldProfileWidth\" name=\"sldProfileWidth\" value=\"5.06\" style=\"flex-grow: 1; width:100%\">\n\t\t\t\t</span>\n\t\t\t\t<br>\n\n\t\t\t\t<li style=\"margin-top: 10px\">\n\t\t\t\t\t<input name=\"download_profile\" type=\"button\" value=\"prepare download\" style=\"width: 100%\" />\n\t\t\t\t\t<div name=\"download_message\"></div>\n\t\t\t\t</li>\n\n\t\t\t\t<br>\n\n\t\t\t\t<input type=\"button\" id=\"show_2d_profile\" value=\"show 2d profile\" style=\"width: 100%\"/>\n\n\t\t\t\t<!-- ACTIONS -->\n\t\t\t\t<div style=\"display: flex; margin-top: 12px\">\n\t\t\t\t\t<span></span>\n\t\t\t\t\t<span style=\"flex-grow: 1\"></span>\n\t\t\t\t\t<img name=\"remove\" class=\"button-icon\" src=\"".concat(removeIconPath, "\" style=\"width: 16px; height: 16px\"/>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t"));
  63440. this.elRemove = this.elContent.find("img[name=remove]");
  63441. this.elRemove.click(() => {
  63442. this.viewer.scene.removeProfile(measurement);
  63443. });
  63444. {
  63445. // download
  63446. this.elDownloadButton = this.elContent.find("input[name=download_profile]");
  63447. if (this.propertiesPanel.viewer.server) {
  63448. this.elDownloadButton.click(() => this.download());
  63449. } else {
  63450. this.elDownloadButton.hide();
  63451. }
  63452. }
  63453. {
  63454. // width spinner
  63455. var elWidthSlider = this.elContent.find("#sldProfileWidth");
  63456. elWidthSlider.spinner({
  63457. min: 0,
  63458. max: 10 * 1000 * 1000,
  63459. step: 0.01,
  63460. numberFormat: 'n',
  63461. start: () => {},
  63462. spin: (event, ui) => {
  63463. var value = elWidthSlider.spinner('value');
  63464. measurement.setWidth(value);
  63465. },
  63466. change: (event, ui) => {
  63467. var value = elWidthSlider.spinner('value');
  63468. measurement.setWidth(value);
  63469. },
  63470. stop: (event, ui) => {
  63471. var value = elWidthSlider.spinner('value');
  63472. measurement.setWidth(value);
  63473. },
  63474. incremental: count => {
  63475. var value = elWidthSlider.spinner('value');
  63476. var step = elWidthSlider.spinner('option', 'step');
  63477. var delta = value * 0.05;
  63478. var increments = Math.max(1, parseInt(delta / step));
  63479. return increments;
  63480. }
  63481. });
  63482. elWidthSlider.spinner('value', measurement.getWidth());
  63483. elWidthSlider.spinner('widget').css('width', '100%');
  63484. var widthListener = event => {
  63485. var value = elWidthSlider.spinner('value');
  63486. if (value !== measurement.getWidth()) {
  63487. elWidthSlider.spinner('value', measurement.getWidth());
  63488. }
  63489. };
  63490. this.propertiesPanel.addVolatileListener(measurement, "width_changed", widthListener);
  63491. }
  63492. var elShow2DProfile = this.elContent.find("#show_2d_profile");
  63493. elShow2DProfile.click(() => {
  63494. this.propertiesPanel.viewer.profileWindow.show();
  63495. this.propertiesPanel.viewer.profileWindowController.setProfile(measurement);
  63496. });
  63497. this.propertiesPanel.addVolatileListener(measurement, "marker_added", this._update);
  63498. this.propertiesPanel.addVolatileListener(measurement, "marker_removed", this._update);
  63499. this.propertiesPanel.addVolatileListener(measurement, "marker_moved", this._update);
  63500. this.update();
  63501. }
  63502. update() {
  63503. var elCoordiantesContainer = this.elContent.find('.coordinates_table_container');
  63504. elCoordiantesContainer.empty();
  63505. elCoordiantesContainer.append(this.createCoordinatesTable(this.measurement.points));
  63506. }
  63507. async download() {
  63508. var profile = this.measurement;
  63509. var regions = [];
  63510. {
  63511. var segments = profile.getSegments();
  63512. var width = profile.width;
  63513. for (var segment of segments) {
  63514. var start = segment.start.clone().multiply(new Vector3(1, 1, 0));
  63515. var end = segment.end.clone().multiply(new Vector3(1, 1, 0));
  63516. var center = new Vector3().addVectors(start, end).multiplyScalar(0.5);
  63517. var startEndDir = new Vector3().subVectors(end, start).normalize();
  63518. var endStartDir = new Vector3().subVectors(start, end).normalize();
  63519. var upDir = new Vector3(0, 0, 1);
  63520. var rightDir = new Vector3().crossVectors(startEndDir, upDir);
  63521. var leftDir = new Vector3().crossVectors(endStartDir, upDir);
  63522. console.log(leftDir);
  63523. var right = rightDir.clone().multiplyScalar(width * 0.5).add(center);
  63524. var left = leftDir.clone().multiplyScalar(width * 0.5).add(center);
  63525. var planes = [new Plane().setFromNormalAndCoplanarPoint(startEndDir, start), new Plane().setFromNormalAndCoplanarPoint(endStartDir, end), new Plane().setFromNormalAndCoplanarPoint(leftDir, right), new Plane().setFromNormalAndCoplanarPoint(rightDir, left)];
  63526. var planeQueryParts = [];
  63527. for (var plane of planes) {
  63528. var part = [plane.normal.toArray(), plane.constant].join(",");
  63529. part = "[".concat(part, "]");
  63530. planeQueryParts.push(part);
  63531. }
  63532. var region = "[" + planeQueryParts.join(",") + "]";
  63533. regions.push(region);
  63534. }
  63535. }
  63536. var regionsArg = regions.join(",");
  63537. var pointcloudArgs = [];
  63538. for (var pointcloud of this.viewer.scene.pointclouds) {
  63539. if (!pointcloud.visible) {
  63540. continue;
  63541. }
  63542. var offset = pointcloud.pcoGeometry.offset.clone();
  63543. var negateOffset = new Matrix4().makeTranslation(...offset.multiplyScalar(-1).toArray());
  63544. var matrixWorld = pointcloud.matrixWorld;
  63545. var transform = new Matrix4().multiplyMatrices(matrixWorld, negateOffset);
  63546. var path = "".concat(window.location.pathname, "/../").concat(pointcloud.pcoGeometry.url);
  63547. var arg = {
  63548. path: path,
  63549. transform: transform.elements
  63550. };
  63551. var argString = JSON.stringify(arg);
  63552. pointcloudArgs.push(argString);
  63553. }
  63554. var pointcloudsArg = pointcloudArgs.join(",");
  63555. var elMessage = this.elContent.find("div[name=download_message]");
  63556. var error = message => {
  63557. elMessage.html("<div style=\"color: #ff0000\">ERROR: ".concat(message, "</div>"));
  63558. };
  63559. var info = message => {
  63560. elMessage.html("".concat(message));
  63561. };
  63562. var handle = null;
  63563. {
  63564. // START FILTER
  63565. var url = "".concat(viewer.server, "/create_regions_filter?pointclouds=[").concat(pointcloudsArg, "]&regions=[").concat(regionsArg, "]");
  63566. //console.log(url);
  63567. info("estimating results ...");
  63568. var response = await fetch(url);
  63569. var jsResponse = await response.json();
  63570. //console.log(jsResponse);
  63571. if (!jsResponse.handle) {
  63572. error(jsResponse.message);
  63573. return;
  63574. } else {
  63575. handle = jsResponse.handle;
  63576. }
  63577. }
  63578. {
  63579. // WAIT, CHECK PROGRESS, HANDLE FINISH
  63580. var _url = "".concat(viewer.server, "/check_regions_filter?handle=").concat(handle);
  63581. var sleep = function sleep(duration) {
  63582. return new Promise((res, rej) => {
  63583. setTimeout(() => {
  63584. res();
  63585. }, duration);
  63586. });
  63587. };
  63588. var handleFiltering = jsResponse => {
  63589. var {
  63590. progress,
  63591. estimate
  63592. } = jsResponse;
  63593. var progressFract = progress["processed points"] / estimate.points;
  63594. var progressPercents = parseInt(progressFract * 100);
  63595. info("progress: ".concat(progressPercents, "%"));
  63596. };
  63597. var handleFinish = jsResponse => {
  63598. var message = "downloads ready: <br>";
  63599. message += "<ul>";
  63600. for (var i = 0; i < jsResponse.pointclouds.length; i++) {
  63601. var _url2 = "".concat(viewer.server, "/download_regions_filter_result?handle=").concat(handle, "&index=").concat(i);
  63602. message += "<li><a href=\"".concat(_url2, "\">result_").concat(i, ".las</a> </li>\n");
  63603. }
  63604. var reportURL = "".concat(viewer.server, "/download_regions_filter_report?handle=").concat(handle);
  63605. message += "<li> <a href=\"".concat(reportURL, "\">report.json</a> </li>\n");
  63606. message += "</ul>";
  63607. info(message);
  63608. };
  63609. var handleUnexpected = jsResponse => {
  63610. var message = "Unexpected Response. <br>status: ".concat(jsResponse.status, " <br>message: ").concat(jsResponse.message);
  63611. info(message);
  63612. };
  63613. var handleError = jsResponse => {
  63614. var message = "ERROR: ".concat(jsResponse.message);
  63615. error(message);
  63616. throw new Error(message);
  63617. };
  63618. var _start = Date.now();
  63619. while (true) {
  63620. var _response = await fetch(_url);
  63621. var _jsResponse = await _response.json();
  63622. if (_jsResponse.status === "ERROR") {
  63623. handleError(_jsResponse);
  63624. } else if (_jsResponse.status === "FILTERING") {
  63625. handleFiltering(_jsResponse);
  63626. } else if (_jsResponse.status === "FINISHED") {
  63627. handleFinish(_jsResponse);
  63628. break;
  63629. } else {
  63630. handleUnexpected(_jsResponse);
  63631. }
  63632. var durationS = (Date.now() - _start) / 1000;
  63633. var sleepAmountMS = durationS < 10 ? 100 : 1000;
  63634. await sleep(sleepAmountMS);
  63635. }
  63636. }
  63637. }
  63638. }
  63639. ;
  63640. class CameraPanel {
  63641. constructor(viewer, propertiesPanel) {
  63642. this.viewer = viewer;
  63643. this.propertiesPanel = propertiesPanel;
  63644. this._update = () => {
  63645. this.update();
  63646. };
  63647. var copyIconPath = Potree.resourcePath + '/icons/copy.svg';
  63648. this.elContent = $("\n\t\t<div class=\"propertypanel_content\">\n\t\t\t<table>\n\t\t\t\t<tr>\n\t\t\t\t\t<th colspan=\"3\">position</th>\n\t\t\t\t\t<th></th>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td align=\"center\" id=\"camera_position_x\" style=\"width: 25%\"></td>\n\t\t\t\t\t<td align=\"center\" id=\"camera_position_y\" style=\"width: 25%\"></td>\n\t\t\t\t\t<td align=\"center\" id=\"camera_position_z\" style=\"width: 25%\"></td>\n\t\t\t\t\t<td align=\"right\" id=\"copy_camera_position\" style=\"width: 25%\">\n\t\t\t\t\t\t<img name=\"copyPosition\" title=\"copy\" class=\"button-icon\" src=\"".concat(copyIconPath, "\" style=\"width: 16px; height: 16px\"/>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<th colspan=\"3\">target</th>\n\t\t\t\t\t<th></th>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td align=\"center\" id=\"camera_target_x\" style=\"width: 25%\"></td>\n\t\t\t\t\t<td align=\"center\" id=\"camera_target_y\" style=\"width: 25%\"></td>\n\t\t\t\t\t<td align=\"center\" id=\"camera_target_z\" style=\"width: 25%\"></td>\n\t\t\t\t\t<td align=\"right\" id=\"copy_camera_target\" style=\"width: 25%\">\n\t\t\t\t\t\t<img name=\"copyTarget\" title=\"copy\" class=\"button-icon\" src=\"").concat(copyIconPath, "\" style=\"width: 16px; height: 16px\"/>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\t\t\t</table>\n\t\t</div>\n\t\t"));
  63649. this.elCopyPosition = this.elContent.find("img[name=copyPosition]");
  63650. this.elCopyPosition.click(() => {
  63651. var pos = this.viewer.scene.getActiveCamera().position.toArray();
  63652. var msg = pos.map(c => c.toFixed(3)).join(", ");
  63653. Utils.clipboardCopy(msg);
  63654. this.viewer.postMessage("Copied value to clipboard: <br>'".concat(msg, "'"), {
  63655. duration: 3000
  63656. });
  63657. });
  63658. this.elCopyTarget = this.elContent.find("img[name=copyTarget]");
  63659. this.elCopyTarget.click(() => {
  63660. var pos = this.viewer.scene.view.getPivot().toArray();
  63661. var msg = pos.map(c => c.toFixed(3)).join(", ");
  63662. Utils.clipboardCopy(msg);
  63663. this.viewer.postMessage("Copied value to clipboard: <br>'".concat(msg, "'"), {
  63664. duration: 3000
  63665. });
  63666. });
  63667. this.propertiesPanel.addVolatileListener(viewer, "camera_changed", this._update);
  63668. this.update();
  63669. }
  63670. update() {
  63671. //console.log("updating camera panel");
  63672. var camera = this.viewer.scene.getActiveCamera();
  63673. var view = this.viewer.scene.view;
  63674. var pos = camera.position.toArray().map(c => Utils.addCommas(c.toFixed(3)));
  63675. this.elContent.find("#camera_position_x").html(pos[0]);
  63676. this.elContent.find("#camera_position_y").html(pos[1]);
  63677. this.elContent.find("#camera_position_z").html(pos[2]);
  63678. var target = view.getPivot().toArray().map(c => Utils.addCommas(c.toFixed(3)));
  63679. this.elContent.find("#camera_target_x").html(target[0]);
  63680. this.elContent.find("#camera_target_y").html(target[1]);
  63681. this.elContent.find("#camera_target_z").html(target[2]);
  63682. }
  63683. }
  63684. ;
  63685. class AnnotationPanel {
  63686. constructor(viewer, propertiesPanel, annotation) {
  63687. this.viewer = viewer;
  63688. this.propertiesPanel = propertiesPanel;
  63689. this.annotation = annotation;
  63690. this._update = () => {
  63691. this.update();
  63692. };
  63693. var copyIconPath = "".concat(Potree.resourcePath, "/icons/copy.svg");
  63694. this.elContent = $("\n\t\t<div class=\"propertypanel_content\">\n\t\t\t<table>\n\t\t\t\t<tr>\n\t\t\t\t\t<th colspan=\"3\">position</th>\n\t\t\t\t\t<th></th>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td align=\"center\" id=\"annotation_position_x\" style=\"width: 25%\"></td>\n\t\t\t\t\t<td align=\"center\" id=\"annotation_position_y\" style=\"width: 25%\"></td>\n\t\t\t\t\t<td align=\"center\" id=\"annotation_position_z\" style=\"width: 25%\"></td>\n\t\t\t\t\t<td align=\"right\" id=\"copy_annotation_position\" style=\"width: 25%\">\n\t\t\t\t\t\t<img name=\"copyPosition\" title=\"copy\" class=\"button-icon\" src=\"".concat(copyIconPath, "\" style=\"width: 16px; height: 16px\"/>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t</table>\n\n\t\t\t<div>\n\n\t\t\t\t<div class=\"heading\">Title</div>\n\t\t\t\t<div id=\"annotation_title\" contenteditable=\"true\">\n\t\t\t\t\tAnnotation Title\n\t\t\t\t</div>\n\n\t\t\t\t<div class=\"heading\">Description</div>\n\t\t\t\t<div id=\"annotation_description\" contenteditable=\"true\">\n\t\t\t\t\tA longer description of this annotation. \n\t\t\t\t\t\tCan be multiple lines long. TODO: the user should be able\n\t\t\t\t\t\tto modify title and description. \n\t\t\t\t</div>\n\n\t\t\t</div>\n\n\t\t</div>\n\t\t"));
  63695. this.elCopyPosition = this.elContent.find("img[name=copyPosition]");
  63696. this.elCopyPosition.click(() => {
  63697. var pos = this.annotation.position.toArray();
  63698. var msg = pos.map(c => c.toFixed(3)).join(", ");
  63699. Utils.clipboardCopy(msg);
  63700. this.viewer.postMessage("Copied value to clipboard: <br>'".concat(msg, "'"), {
  63701. duration: 3000
  63702. });
  63703. });
  63704. this.elTitle = this.elContent.find("#annotation_title").html(annotation.title);
  63705. this.elDescription = this.elContent.find("#annotation_description").html(annotation.description);
  63706. this.elTitle[0].addEventListener("input", () => {
  63707. var title = this.elTitle.html();
  63708. annotation.title = title;
  63709. }, false);
  63710. this.elDescription[0].addEventListener("input", () => {
  63711. var description = this.elDescription.html();
  63712. annotation.description = description;
  63713. }, false);
  63714. this.update();
  63715. }
  63716. update() {
  63717. var {
  63718. annotation,
  63719. elContent,
  63720. elTitle,
  63721. elDescription
  63722. } = this;
  63723. var pos = annotation.position.toArray().map(c => Utils.addCommas(c.toFixed(3)));
  63724. elContent.find("#annotation_position_x").html(pos[0]);
  63725. elContent.find("#annotation_position_y").html(pos[1]);
  63726. elContent.find("#annotation_position_z").html(pos[2]);
  63727. elTitle.html(annotation.title);
  63728. elDescription.html(annotation.description);
  63729. }
  63730. }
  63731. ;
  63732. class CameraAnimationPanel {
  63733. constructor(viewer, propertiesPanel, animation) {
  63734. this.viewer = viewer;
  63735. this.propertiesPanel = propertiesPanel;
  63736. this.animation = animation;
  63737. this.elContent = $("\n\t\t\t<div class=\"propertypanel_content\">\n\t\t\t\t<span id=\"animation_keyframes\"></span>\n\n\t\t\t\t<span>\n\n\t\t\t\t\t<span style=\"display:flex\">\n\t\t\t\t\t\t<span style=\"display:flex; align-items: center; padding-right: 10px\">Duration: </span>\n\t\t\t\t\t\t<input name=\"spnDuration\" value=\"5.0\" style=\"flex-grow: 1; width:100%\">\n\t\t\t\t\t</span>\n\n\t\t\t\t\t<span>Time: </span><span id=\"lblTime\"></span> <div id=\"sldTime\"></div>\n\n\t\t\t\t\t<input name=\"play\" type=\"button\" value=\"play\"/>\n\t\t\t\t\t<input name=\"pause\" type=\"button\" value=\"pause\"/>\n\t\t\t\t</span>\n\t\t\t</div>\n\t\t");
  63738. var elPlay = this.elContent.find("input[name=play]");
  63739. elPlay.click(() => {
  63740. animation.play();
  63741. });
  63742. var elPause = this.elContent.find("input[name=pause]");
  63743. elPause.click(() => {
  63744. animation.pause();
  63745. });
  63746. var elSlider = this.elContent.find('#sldTime');
  63747. elSlider.slider({
  63748. value: 0,
  63749. min: 0,
  63750. max: 1,
  63751. step: 0.001,
  63752. slide: (event, ui) => {
  63753. animation.set(ui.value);
  63754. animation.updateFrustum();
  63755. }
  63756. });
  63757. var elDuration = this.elContent.find("input[name=spnDuration]");
  63758. elDuration.spinner({
  63759. min: 0,
  63760. max: 300,
  63761. step: 0.01,
  63762. numberFormat: 'n',
  63763. start: () => {},
  63764. spin: (event, ui) => {
  63765. var value = elDuration.spinner('value');
  63766. animation.setDuration(value);
  63767. },
  63768. change: (event, ui) => {
  63769. var value = elDuration.spinner('value');
  63770. animation.setDuration(value);
  63771. },
  63772. stop: (event, ui) => {
  63773. var value = elDuration.spinner('value');
  63774. animation.setDuration(value);
  63775. },
  63776. incremental: count => {
  63777. var value = elDuration.spinner('value');
  63778. var step = elDuration.spinner('option', 'step');
  63779. var delta = value * 0.05;
  63780. var increments = Math.max(1, parseInt(delta / step));
  63781. return increments;
  63782. }
  63783. });
  63784. elDuration.spinner('value', animation.getDuration());
  63785. elDuration.spinner('widget').css('width', '100%');
  63786. var elKeyframes = this.elContent.find("#animation_keyframes");
  63787. var updateKeyframes = () => {
  63788. elKeyframes.empty();
  63789. //let index = 0;
  63790. // <span style="flex-grow: 0;">
  63791. // <img name="add" src="${Potree.resourcePath}/icons/add.svg" style="width: 1.5em; height: 1.5em"/>
  63792. // </span>
  63793. var addNewKeyframeItem = index => {
  63794. var elNewKeyframe = $("\n\t\t\t\t\t<div style=\"display: flex; margin: 0.2em 0em\">\n\t\t\t\t\t\t<span style=\"flex-grow: 1\"></span>\n\t\t\t\t\t\t<input type=\"button\" name=\"add\" value=\"insert control point\" />\n\t\t\t\t\t\t<span style=\"flex-grow: 1\"></span>\n\t\t\t\t\t</div>\n\t\t\t\t");
  63795. var elAdd = elNewKeyframe.find("input[name=add]");
  63796. elAdd.click(() => {
  63797. animation.createControlPoint(index, {
  63798. position: viewer.scene.view.position,
  63799. target: viewer.scene.view.getPivot()
  63800. });
  63801. animation.changeCallback();
  63802. });
  63803. elKeyframes.append(elNewKeyframe);
  63804. };
  63805. var addKeyframeItem = index => {
  63806. var elKeyframe = $("\n\t\t\t\t\t<div style=\"display: flex; margin: 0.2em 0em\">\n\t\t\t\t\t\t<span style=\"flex-grow: 0;\">\n\t\t\t\t\t\t\t<img name=\"assign\" src=\"".concat(Potree.resourcePath, "/icons/assign.svg\" style=\"width: 1.5em; height: 1.5em\"/>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t<span style=\"flex-grow: 0;\">\n\t\t\t\t\t\t\t<img name=\"move\" src=\"").concat(Potree.resourcePath, "/icons/circled_dot.svg\" style=\"width: 1.5em; height: 1.5em\"/>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t<span style=\"flex-grow: 0; width: 1.5em; height: 1.5em\"></span>\n\t\t\t\t\t\t<span style=\"flex-grow: 0; font-size: 1.5em\">keyframe</span>\n\t\t\t\t\t\t<span style=\"flex-grow: 1\"></span>\n\t\t\t\t\t\t<span style=\"flex-grow: 0;\">\n\t\t\t\t\t\t\t<img name=\"delete\" src=\"").concat(Potree.resourcePath, "/icons/remove.svg\" style=\"width: 1.5em; height: 1.5em\"/>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</div>\n\t\t\t\t"));
  63807. var elAssign = elKeyframe.find("img[name=assign]");
  63808. var elMove = elKeyframe.find("img[name=move]");
  63809. var elDelete = elKeyframe.find("img[name=delete]");
  63810. elAssign.click(() => {
  63811. //修改
  63812. animation.posCurve.points[index].copy(viewer.scene.view.position);
  63813. animation.targets[index].position.copy(viewer.scene.view.getPivot());
  63814. animation.changeCallback(index);
  63815. });
  63816. elMove.click(() => {
  63817. viewer.scene.view.position.copy(animation.posCurve.points[index]);
  63818. viewer.scene.view.lookAt(animation.targets[index].position);
  63819. });
  63820. elDelete.click(() => {
  63821. animation.removeControlPoint(index);
  63822. animation.changeCallback();
  63823. });
  63824. elKeyframes.append(elKeyframe);
  63825. };
  63826. var index = 0;
  63827. addNewKeyframeItem(index);
  63828. animation.posCurve.points.forEach(e => {
  63829. addKeyframeItem(index);
  63830. index++;
  63831. addNewKeyframeItem(index);
  63832. });
  63833. };
  63834. updateKeyframes();
  63835. animation.addEventListener("controlpoint_added", updateKeyframes);
  63836. animation.addEventListener("controlpoint_removed", updateKeyframes);
  63837. // this._update = () => { this.update(); };
  63838. // this.update();
  63839. }
  63840. update() {}
  63841. }
  63842. ;
  63843. class PropertiesPanel {
  63844. constructor(container, viewer) {
  63845. this.container = container;
  63846. this.viewer = viewer;
  63847. this.object = null;
  63848. this.cleanupTasks = [];
  63849. this.scene = null;
  63850. }
  63851. setScene(scene) {
  63852. this.scene = scene;
  63853. }
  63854. set(object) {
  63855. if (this.object === object) {
  63856. return;
  63857. }
  63858. this.object = object;
  63859. for (var task of this.cleanupTasks) {
  63860. task();
  63861. }
  63862. this.cleanupTasks = [];
  63863. this.container.empty();
  63864. if (object instanceof PointCloudTree) {
  63865. this.setPointCloud(object);
  63866. } else if (object instanceof Measure || object instanceof Profile || object instanceof Volume) {
  63867. this.setMeasurement(object);
  63868. } else if (object instanceof Camera) {
  63869. this.setCamera(object);
  63870. } else if (object instanceof Annotation) {
  63871. this.setAnnotation(object);
  63872. } else if (object instanceof CameraAnimation$1) {
  63873. //改
  63874. this.setCameraAnimation(object);
  63875. }
  63876. }
  63877. //
  63878. // Used for events that should be removed when the property object changes.
  63879. // This is for listening to materials, scene, point clouds, etc.
  63880. // not required for DOM listeners, since they are automatically cleared by removing the DOM subtree.
  63881. //
  63882. addVolatileListener(target, type, callback) {
  63883. target.addEventListener(type, callback);
  63884. this.cleanupTasks.push(() => {
  63885. target.removeEventListener(type, callback);
  63886. });
  63887. }
  63888. setPointCloud(pointcloud) {
  63889. var material = pointcloud.material;
  63890. var panel = $("\n\t\t\t<div class=\"scene_content selectable\">\n\t\t\t\t<ul class=\"pv-menu-list\">\n\n\t\t\t\t<li>\n\t\t\t\t<span data-i18n=\"appearance.point_size\"></span>:&nbsp;<span id=\"lblPointSize\"></span> <div id=\"sldPointSize\"></div>\n\t\t\t\t</li>\n\t\t\t\t<li>\n\t\t\t\t<span data-i18n=\"appearance.min_point_size\"></span>:&nbsp;<span id=\"lblMinPointSize\"></span> <div id=\"sldMinPointSize\"></div>\n\t\t\t\t</li>\n\n\t\t\t\t<!-- SIZE TYPE -->\n\t\t\t\t<li>\n\t\t\t\t\t<label for=\"optPointSizing\" class=\"pv-select-label\" data-i18n=\"appearance.point_size_type\">Point Sizing </label>\n\t\t\t\t\t<select id=\"optPointSizing\" name=\"optPointSizing\">\n\t\t\t\t\t\t<option>FIXED</option>\n\t\t\t\t\t\t<option>ATTENUATED</option>\n\t\t\t\t\t\t<option>ADAPTIVE</option>\n\t\t\t\t\t</select>\n\t\t\t\t</li>\n\n\t\t\t\t<!-- SHAPE -->\n\t\t\t\t<li>\n\t\t\t\t\t<label for=\"optShape\" class=\"pv-select-label\" data-i18n=\"appearance.point_shape\"></label><br>\n\t\t\t\t\t<select id=\"optShape\" name=\"optShape\">\n\t\t\t\t\t\t<option>SQUARE</option>\n\t\t\t\t\t\t<option>CIRCLE</option>\n\t\t\t\t\t\t<option>PARABOLOID</option>\n\t\t\t\t\t</select>\n\t\t\t\t</li>\n\n\t\t\t\t<li id=\"materials_backface_container\">\n\t\t\t\t<label><input id=\"set_backface_culling\" type=\"checkbox\" /><span data-i18n=\"appearance.backface_culling\"></span></label>\n\t\t\t\t</li>\n\t\t\t\t\n\t\t\t\t<!-- OPACITY -->\n\t\t\t\t<li><span data-i18n=\"appearance.point_opacity\"></span>:<span id=\"lblOpacity\"></span><div id=\"sldOpacity\"></div></li>\n\n\t\t\t\t<div class=\"divider\">\n\t\t\t\t\t<span>Attribute</span>\n\t\t\t\t</div>\n\n\t\t\t\t<li>\n\t\t\t\t\t<select id=\"optMaterial\" name=\"optMaterial\"></select>\n\t\t\t\t</li>\n\n\t\t\t\t<div id=\"materials.composite_weight_container\">\n\t\t\t\t\t<div class=\"divider\">\n\t\t\t\t\t\t<span>Attribute Weights</span>\n\t\t\t\t\t</div>\n\n\t\t\t\t\t<li>RGB: <span id=\"lblWeightRGB\"></span> <div id=\"sldWeightRGB\"></div>\t</li>\n\t\t\t\t\t<li>Intensity: <span id=\"lblWeightIntensity\"></span> <div id=\"sldWeightIntensity\"></div>\t</li>\n\t\t\t\t\t<li>Elevation: <span id=\"lblWeightElevation\"></span> <div id=\"sldWeightElevation\"></div>\t</li>\n\t\t\t\t\t<li>Classification: <span id=\"lblWeightClassification\"></span> <div id=\"sldWeightClassification\"></div>\t</li>\n\t\t\t\t\t<li>Return Number: <span id=\"lblWeightReturnNumber\"></span> <div id=\"sldWeightReturnNumber\"></div>\t</li>\n\t\t\t\t\t<li>Source ID: <span id=\"lblWeightSourceID\"></span> <div id=\"sldWeightSourceID\"></div>\t</li>\n\t\t\t\t</div>\n\n\t\t\t\t<div id=\"materials.rgb_container\">\n\t\t\t\t\t<div class=\"divider\">\n\t\t\t\t\t\t<span>RGB</span>\n\t\t\t\t\t</div>\n\n\t\t\t\t\t<li>Gamma: <span id=\"lblRGBGamma\"></span> <div id=\"sldRGBGamma\"></div>\t</li>\n\t\t\t\t\t<li>Brightness: <span id=\"lblRGBBrightness\"></span> <div id=\"sldRGBBrightness\"></div>\t</li>\n\t\t\t\t\t<li>Contrast: <span id=\"lblRGBContrast\"></span> <div id=\"sldRGBContrast\"></div>\t</li>\n\t\t\t\t</div>\n\n\t\t\t\t<div id=\"materials.extra_container\">\n\t\t\t\t\t<div class=\"divider\">\n\t\t\t\t\t\t<span>Extra Attribute</span>\n\t\t\t\t\t</div>\n\n\t\t\t\t\t<li><span data-i18n=\"appearance.extra_range\"></span>: <span id=\"lblExtraRange\"></span> <div id=\"sldExtraRange\"></div></li>\n\n\t\t\t\t\t<li>Gamma: <span id=\"lblExtraGamma\"></span> <div id=\"sldExtraGamma\"></div></li>\n\t\t\t\t\t<li>Brightness: <span id=\"lblExtraBrightness\"></span> <div id=\"sldExtraBrightness\"></div></li>\n\t\t\t\t\t<li>Contrast: <span id=\"lblExtraContrast\"></span> <div id=\"sldExtraContrast\"></div></li>\n\t\t\t\t</div>\n\t\t\t\t\n\t\t\t\t<div id=\"materials.matcap_container\">\n\t\t\t\t\t<div class=\"divider\">\n\t\t\t\t\t\t<span>MATCAP</span>\n\t\t\t\t\t</div>\n\n\t\t\t\t\t<li>\n\t\t\t\t\t\t<div id=\"matcap_scheme_selection\" style=\"display: flex; flex-wrap: wrap;\"> </div>\n\t\t\t\t\t</li>\n\t\t\t\t</div>\n\n\t\t\t\t<div id=\"materials.color_container\">\n\t\t\t\t\t<div class=\"divider\">\n\t\t\t\t\t\t<span>Color</span>\n\t\t\t\t\t</div>\n\n\t\t\t\t\t<input id=\"materials.color.picker\" />\n\t\t\t\t</div>\n\n\n\t\t\t\t<div id=\"materials.elevation_container\">\n\t\t\t\t\t<div class=\"divider\">\n\t\t\t\t\t\t<span>Elevation</span>\n\t\t\t\t\t</div>\n\n\t\t\t\t\t<li><span data-i18n=\"appearance.elevation_range\"></span>: <span id=\"lblHeightRange\"></span> <div id=\"sldHeightRange\"></div>\t</li>\n\n\t\t\t\t\t<li>\n\t\t\t\t\t\t<selectgroup id=\"gradient_repeat_option\">\n\t\t\t\t\t\t\t<option id=\"gradient_repeat_clamp\" value=\"CLAMP\">Clamp</option>\n\t\t\t\t\t\t\t<option id=\"gradient_repeat_repeat\" value=\"REPEAT\">Repeat</option>\n\t\t\t\t\t\t\t<option id=\"gradient_repeat_mirrored_repeat\" value=\"MIRRORED_REPEAT\">Mirrored Repeat</option>\n\t\t\t\t\t\t</selectgroup>\n\t\t\t\t\t</li>\n\n\t\t\t\t\t<li>\n\t\t\t\t\t\t<span>Gradient Scheme:</span>\n\t\t\t\t\t\t<div id=\"elevation_gradient_scheme_selection\" style=\"display: flex; padding: 1em 0em\">\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</li>\n\t\t\t\t</div>\n\n\t\t\t\t<div id=\"materials.transition_container\">\n\t\t\t\t\t<div class=\"divider\">\n\t\t\t\t\t\t<span>Transition</span>\n\t\t\t\t\t</div>\n\n\t\t\t\t\t<li>transition: <span id=\"lblTransition\"></span> <div id=\"sldTransition\"></div>\t</li>\n\t\t\t\t</div>\n\n\t\t\t\t<div id=\"materials.intensity_container\">\n\t\t\t\t\t<div class=\"divider\">\n\t\t\t\t\t\t<span>Intensity</span>\n\t\t\t\t\t</div>\n\n\t\t\t\t\t<li>Range: <span id=\"lblIntensityRange\"></span> <div id=\"sldIntensityRange\"></div>\t</li>\n\t\t\t\t\t<li>Gamma: <span id=\"lblIntensityGamma\"></span> <div id=\"sldIntensityGamma\"></div>\t</li>\n\t\t\t\t\t<li>Brightness: <span id=\"lblIntensityBrightness\"></span> <div id=\"sldIntensityBrightness\"></div>\t</li>\n\t\t\t\t\t<li>Contrast: <span id=\"lblIntensityContrast\"></span> <div id=\"sldIntensityContrast\"></div>\t</li>\n\t\t\t\t</div>\n\n\t\t\t\t<div id=\"materials.gpstime_container\">\n\t\t\t\t\t<div class=\"divider\">\n\t\t\t\t\t\t<span>GPS Time</span>\n\t\t\t\t\t</div>\n\n\t\t\t\t</div>\n\t\t\t\t\n\t\t\t\t<div id=\"materials.index_container\">\n\t\t\t\t\t<div class=\"divider\">\n\t\t\t\t\t\t<span>Indices</span>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\n\n\t\t\t\t</ul>\n\t\t\t</div>\n\t\t");
  63891. panel.i18n();
  63892. this.container.append(panel);
  63893. {
  63894. // POINT SIZE
  63895. var sldPointSize = panel.find("#sldPointSize");
  63896. var lblPointSize = panel.find("#lblPointSize");
  63897. sldPointSize.slider({
  63898. value: material.size,
  63899. min: 0,
  63900. max: 3,
  63901. step: 0.01,
  63902. slide: function slide(event, ui) {
  63903. material.size = ui.value;
  63904. }
  63905. });
  63906. var update = e => {
  63907. lblPointSize.html(material.size.toFixed(2));
  63908. sldPointSize.slider({
  63909. value: material.size
  63910. });
  63911. };
  63912. this.addVolatileListener(material, "point_size_changed", update);
  63913. update();
  63914. }
  63915. {
  63916. // MINIMUM POINT SIZE
  63917. var sldMinPointSize = panel.find("#sldMinPointSize");
  63918. var lblMinPointSize = panel.find("#lblMinPointSize");
  63919. sldMinPointSize.slider({
  63920. value: material.size,
  63921. min: 0,
  63922. max: 3,
  63923. step: 0.01,
  63924. slide: function slide(event, ui) {
  63925. material.minSize = ui.value;
  63926. }
  63927. });
  63928. var _update = e => {
  63929. lblMinPointSize.html(material.minSize.toFixed(2));
  63930. sldMinPointSize.slider({
  63931. value: material.minSize
  63932. });
  63933. };
  63934. this.addVolatileListener(material, "point_size_changed", _update);
  63935. _update();
  63936. }
  63937. {
  63938. // POINT SIZING
  63939. var strSizeType = Object.keys(PointSizeType)[material.pointSizeType];
  63940. var opt = panel.find("#optPointSizing");
  63941. opt.selectmenu();
  63942. opt.val(strSizeType).selectmenu('refresh');
  63943. opt.selectmenu({
  63944. change: (event, ui) => {
  63945. material.pointSizeType = PointSizeType[ui.item.value];
  63946. }
  63947. });
  63948. }
  63949. {
  63950. // SHAPE
  63951. var _opt = panel.find("#optShape");
  63952. _opt.selectmenu({
  63953. change: (event, ui) => {
  63954. var value = ui.item.value;
  63955. material.shape = PointShape$1[value];
  63956. }
  63957. });
  63958. var _update2 = () => {
  63959. var typename = Object.keys(PointShape$1)[material.shape];
  63960. _opt.selectmenu().val(typename).selectmenu('refresh');
  63961. };
  63962. this.addVolatileListener(material, "point_shape_changed", _update2);
  63963. _update2();
  63964. }
  63965. {
  63966. // BACKFACE CULLING
  63967. var _opt2 = panel.find("#set_backface_culling");
  63968. _opt2.click(() => {
  63969. material.backfaceCulling = _opt2.prop("checked");
  63970. });
  63971. var _update3 = () => {
  63972. var value = material.backfaceCulling;
  63973. _opt2.prop("checked", value);
  63974. };
  63975. this.addVolatileListener(material, "backface_changed", _update3);
  63976. _update3();
  63977. var blockBackface = $('#materials_backface_container');
  63978. blockBackface.css('display', 'none');
  63979. var pointAttributes = pointcloud.pcoGeometry.pointAttributes;
  63980. var hasNormals = pointAttributes.hasNormals ? pointAttributes.hasNormals() : false;
  63981. if (hasNormals) {
  63982. blockBackface.css('display', 'block');
  63983. }
  63984. /*
  63985. opt.checkboxradio({
  63986. clicked: (event, ui) => {
  63987. // let value = ui.item.value;
  63988. let value = ui.item.checked;
  63989. console.log(value);
  63990. material.backfaceCulling = value; // $('#set_freeze').prop("checked");
  63991. }
  63992. });
  63993. */
  63994. }
  63995. {
  63996. // OPACITY
  63997. var sldOpacity = panel.find("#sldOpacity");
  63998. var lblOpacity = panel.find("#lblOpacity");
  63999. sldOpacity.slider({
  64000. value: material.opacity,
  64001. min: 0,
  64002. max: 1,
  64003. step: 0.001,
  64004. slide: function slide(event, ui) {
  64005. material.opacity = ui.value;
  64006. }
  64007. });
  64008. var _update4 = e => {
  64009. lblOpacity.html(material.opacity.toFixed(2));
  64010. sldOpacity.slider({
  64011. value: material.opacity
  64012. });
  64013. };
  64014. this.addVolatileListener(material, "opacity_changed", _update4);
  64015. _update4();
  64016. }
  64017. {
  64018. var attributes = pointcloud.pcoGeometry.pointAttributes.attributes;
  64019. var options = [];
  64020. options.push(...attributes.map(a => a.name));
  64021. var intensityIndex = options.indexOf("intensity");
  64022. if (intensityIndex >= 0) {
  64023. options.splice(intensityIndex + 1, 0, "intensity gradient");
  64024. }
  64025. options.push("elevation", "color", 'matcap', 'indices', 'level of detail', 'composite');
  64026. var blacklist = ["POSITION_CARTESIAN", "position"];
  64027. options = options.filter(o => !blacklist.includes(o));
  64028. var attributeSelection = panel.find('#optMaterial');
  64029. for (var option of options) {
  64030. var elOption = $("<option>".concat(option, "</option>"));
  64031. attributeSelection.append(elOption);
  64032. }
  64033. var updateMaterialPanel = (event, ui) => {
  64034. var selectedValue = attributeSelection.selectmenu().val();
  64035. material.activeAttributeName = selectedValue;
  64036. var attribute = pointcloud.getAttribute(selectedValue);
  64037. if (selectedValue === "intensity gradient") {
  64038. attribute = pointcloud.getAttribute("intensity");
  64039. }
  64040. var isIntensity = attribute ? ["intensity", "intensity gradient"].includes(attribute.name) : false;
  64041. if (isIntensity) {
  64042. if (pointcloud.material.intensityRange[0] === Infinity) {
  64043. pointcloud.material.intensityRange = attribute.range;
  64044. }
  64045. var [min, max] = attribute.range;
  64046. panel.find('#sldIntensityRange').slider({
  64047. range: true,
  64048. min: min,
  64049. max: max,
  64050. step: 0.01,
  64051. values: [min, max],
  64052. slide: (event, ui) => {
  64053. var min = ui.values[0];
  64054. var max = ui.values[1];
  64055. material.intensityRange = [min, max];
  64056. }
  64057. });
  64058. } else if (attribute) {
  64059. var [_min, _max] = attribute.range;
  64060. var selectedRange = material.getRange(attribute.name);
  64061. if (!selectedRange) {
  64062. selectedRange = [...attribute.range];
  64063. }
  64064. var minMaxAreNumbers = typeof _min === "number" && typeof _max === "number";
  64065. if (minMaxAreNumbers) {
  64066. panel.find('#sldExtraRange').slider({
  64067. range: true,
  64068. min: _min,
  64069. max: _max,
  64070. step: 0.01,
  64071. values: selectedRange,
  64072. slide: (event, ui) => {
  64073. var [a, b] = ui.values;
  64074. material.setRange(attribute.name, [a, b]);
  64075. }
  64076. });
  64077. }
  64078. }
  64079. var blockWeights = $('#materials\\.composite_weight_container');
  64080. var blockElevation = $('#materials\\.elevation_container');
  64081. var blockRGB = $('#materials\\.rgb_container');
  64082. var blockExtra = $('#materials\\.extra_container');
  64083. var blockColor = $('#materials\\.color_container');
  64084. var blockIntensity = $('#materials\\.intensity_container');
  64085. var blockIndex = $('#materials\\.index_container');
  64086. var blockTransition = $('#materials\\.transition_container');
  64087. var blockGps = $('#materials\\.gpstime_container');
  64088. var blockMatcap = $('#materials\\.matcap_container');
  64089. blockIndex.css('display', 'none');
  64090. blockIntensity.css('display', 'none');
  64091. blockElevation.css('display', 'none');
  64092. blockRGB.css('display', 'none');
  64093. blockExtra.css('display', 'none');
  64094. blockColor.css('display', 'none');
  64095. blockWeights.css('display', 'none');
  64096. blockTransition.css('display', 'none');
  64097. blockMatcap.css('display', 'none');
  64098. blockGps.css('display', 'none');
  64099. if (selectedValue === 'composite') {
  64100. blockWeights.css('display', 'block');
  64101. blockElevation.css('display', 'block');
  64102. blockRGB.css('display', 'block');
  64103. blockIntensity.css('display', 'block');
  64104. } else if (selectedValue === 'elevation') {
  64105. blockElevation.css('display', 'block');
  64106. } else if (selectedValue === 'RGB and Elevation') {
  64107. blockRGB.css('display', 'block');
  64108. blockElevation.css('display', 'block');
  64109. } else if (selectedValue === 'rgba') {
  64110. blockRGB.css('display', 'block');
  64111. } else if (selectedValue === 'color') {
  64112. blockColor.css('display', 'block');
  64113. } else if (selectedValue === 'intensity') {
  64114. blockIntensity.css('display', 'block');
  64115. } else if (selectedValue === 'intensity gradient') {
  64116. blockIntensity.css('display', 'block');
  64117. } else if (selectedValue === "indices") {
  64118. blockIndex.css('display', 'block');
  64119. } else if (selectedValue === "matcap") {
  64120. blockMatcap.css('display', 'block');
  64121. } else if (selectedValue === "classification") {
  64122. // add classification color selctor?
  64123. } else if (selectedValue === "gps-time") {
  64124. blockGps.css('display', 'block');
  64125. } else if (selectedValue === "number of returns") {} else if (selectedValue === "return number") {} else if (["source id", "point source id"].includes(selectedValue)) {} else {
  64126. blockExtra.css('display', 'block');
  64127. }
  64128. };
  64129. attributeSelection.selectmenu({
  64130. change: updateMaterialPanel
  64131. });
  64132. var _update5 = () => {
  64133. attributeSelection.val(material.activeAttributeName).selectmenu('refresh');
  64134. };
  64135. this.addVolatileListener(material, "point_color_type_changed", _update5);
  64136. this.addVolatileListener(material, "active_attribute_changed", _update5);
  64137. _update5();
  64138. updateMaterialPanel();
  64139. }
  64140. {
  64141. var schemes = Object.keys(Potree.Gradients).map(name => ({
  64142. name: name,
  64143. values: Gradients[name]
  64144. }));
  64145. var elSchemeContainer = panel.find("#elevation_gradient_scheme_selection");
  64146. var _loop = function _loop(scheme) {
  64147. var elScheme = $("\n\t\t\t\t\t<span style=\"flex-grow: 1;\">\n\t\t\t\t\t</span>\n\t\t\t\t");
  64148. var svg = Potree.Utils.createSvgGradient(scheme.values);
  64149. svg.setAttributeNS(null, "class", "button-icon");
  64150. elScheme.append($(svg));
  64151. elScheme.click(() => {
  64152. material.gradient = Gradients[scheme.name];
  64153. });
  64154. elSchemeContainer.append(elScheme);
  64155. };
  64156. for (var scheme of schemes) {
  64157. _loop(scheme);
  64158. }
  64159. }
  64160. {
  64161. var matcaps = [{
  64162. name: "Normals",
  64163. icon: "".concat(Potree.resourcePath, "/icons/matcap/check_normal+y.jpg")
  64164. }, {
  64165. name: "Basic 1",
  64166. icon: "".concat(Potree.resourcePath, "/icons/matcap/basic_1.jpg")
  64167. }, {
  64168. name: "Basic 2",
  64169. icon: "".concat(Potree.resourcePath, "/icons/matcap/basic_2.jpg")
  64170. }, {
  64171. name: "Basic Dark",
  64172. icon: "".concat(Potree.resourcePath, "/icons/matcap/basic_dark.jpg")
  64173. }, {
  64174. name: "Basic Side",
  64175. icon: "".concat(Potree.resourcePath, "/icons/matcap/basic_side.jpg")
  64176. }, {
  64177. name: "Ceramic Dark",
  64178. icon: "".concat(Potree.resourcePath, "/icons/matcap/ceramic_dark.jpg")
  64179. }, {
  64180. name: "Ceramic Lightbulb",
  64181. icon: "".concat(Potree.resourcePath, "/icons/matcap/ceramic_lightbulb.jpg")
  64182. }, {
  64183. name: "Clay Brown",
  64184. icon: "".concat(Potree.resourcePath, "/icons/matcap/clay_brown.jpg")
  64185. }, {
  64186. name: "Clay Muddy",
  64187. icon: "".concat(Potree.resourcePath, "/icons/matcap/clay_muddy.jpg")
  64188. }, {
  64189. name: "Clay Studio",
  64190. icon: "".concat(Potree.resourcePath, "/icons/matcap/clay_studio.jpg")
  64191. }, {
  64192. name: "Resin",
  64193. icon: "".concat(Potree.resourcePath, "/icons/matcap/resin.jpg")
  64194. }, {
  64195. name: "Skin",
  64196. icon: "".concat(Potree.resourcePath, "/icons/matcap/skin.jpg")
  64197. }, {
  64198. name: "Jade",
  64199. icon: "".concat(Potree.resourcePath, "/icons/matcap/jade.jpg")
  64200. }, {
  64201. name: "Metal_ Anisotropic",
  64202. icon: "".concat(Potree.resourcePath, "/icons/matcap/metal_anisotropic.jpg")
  64203. }, {
  64204. name: "Metal Carpaint",
  64205. icon: "".concat(Potree.resourcePath, "/icons/matcap/metal_carpaint.jpg")
  64206. }, {
  64207. name: "Metal Lead",
  64208. icon: "".concat(Potree.resourcePath, "/icons/matcap/metal_lead.jpg")
  64209. }, {
  64210. name: "Metal Shiny",
  64211. icon: "".concat(Potree.resourcePath, "/icons/matcap/metal_shiny.jpg")
  64212. }, {
  64213. name: "Pearl",
  64214. icon: "".concat(Potree.resourcePath, "/icons/matcap/pearl.jpg")
  64215. }, {
  64216. name: "Toon",
  64217. icon: "".concat(Potree.resourcePath, "/icons/matcap/toon.jpg")
  64218. }, {
  64219. name: "Check Rim Light",
  64220. icon: "".concat(Potree.resourcePath, "/icons/matcap/check_rim_light.jpg")
  64221. }, {
  64222. name: "Check Rim Dark",
  64223. icon: "".concat(Potree.resourcePath, "/icons/matcap/check_rim_dark.jpg")
  64224. }, {
  64225. name: "Contours 1",
  64226. icon: "".concat(Potree.resourcePath, "/icons/matcap/contours_1.jpg")
  64227. }, {
  64228. name: "Contours 2",
  64229. icon: "".concat(Potree.resourcePath, "/icons/matcap/contours_2.jpg")
  64230. }, {
  64231. name: "Contours 3",
  64232. icon: "".concat(Potree.resourcePath, "/icons/matcap/contours_3.jpg")
  64233. }, {
  64234. name: "Reflection Check Horizontal",
  64235. icon: "".concat(Potree.resourcePath, "/icons/matcap/reflection_check_horizontal.jpg")
  64236. }, {
  64237. name: "Reflection Check Vertical",
  64238. icon: "".concat(Potree.resourcePath, "/icons/matcap/reflection_check_vertical.jpg")
  64239. }];
  64240. var elMatcapContainer = panel.find("#matcap_scheme_selection");
  64241. var _loop2 = function _loop2(matcap) {
  64242. var elMatcap = $("\n\t\t\t\t\t\t<img src=\"".concat(matcap.icon, "\" class=\"button-icon\" style=\"width: 25%;\" />\n\t\t\t\t"));
  64243. elMatcap.click(() => {
  64244. material.matcap = matcap.icon.substring(matcap.icon.lastIndexOf('/'));
  64245. });
  64246. elMatcapContainer.append(elMatcap);
  64247. };
  64248. for (var matcap of matcaps) {
  64249. _loop2(matcap);
  64250. }
  64251. }
  64252. {
  64253. panel.find('#sldRGBGamma').slider({
  64254. value: material.rgbGamma,
  64255. min: 0,
  64256. max: 4,
  64257. step: 0.01,
  64258. slide: (event, ui) => {
  64259. material.rgbGamma = ui.value;
  64260. }
  64261. });
  64262. panel.find('#sldRGBContrast').slider({
  64263. value: material.rgbContrast,
  64264. min: -1,
  64265. max: 1,
  64266. step: 0.01,
  64267. slide: (event, ui) => {
  64268. material.rgbContrast = ui.value;
  64269. }
  64270. });
  64271. panel.find('#sldRGBBrightness').slider({
  64272. value: material.rgbBrightness,
  64273. min: -1,
  64274. max: 1,
  64275. step: 0.01,
  64276. slide: (event, ui) => {
  64277. material.rgbBrightness = ui.value;
  64278. }
  64279. });
  64280. panel.find('#sldExtraGamma').slider({
  64281. value: material.extraGamma,
  64282. min: 0,
  64283. max: 4,
  64284. step: 0.01,
  64285. slide: (event, ui) => {
  64286. material.extraGamma = ui.value;
  64287. }
  64288. });
  64289. panel.find('#sldExtraBrightness').slider({
  64290. value: material.extraBrightness,
  64291. min: -1,
  64292. max: 1,
  64293. step: 0.01,
  64294. slide: (event, ui) => {
  64295. material.extraBrightness = ui.value;
  64296. }
  64297. });
  64298. panel.find('#sldExtraContrast').slider({
  64299. value: material.extraContrast,
  64300. min: -1,
  64301. max: 1,
  64302. step: 0.01,
  64303. slide: (event, ui) => {
  64304. material.extraContrast = ui.value;
  64305. }
  64306. });
  64307. panel.find('#sldHeightRange').slider({
  64308. range: true,
  64309. min: 0,
  64310. max: 1000,
  64311. step: 0.01,
  64312. values: [0, 1000],
  64313. slide: (event, ui) => {
  64314. material.heightMin = ui.values[0];
  64315. material.heightMax = ui.values[1];
  64316. }
  64317. });
  64318. panel.find('#sldIntensityGamma').slider({
  64319. value: material.intensityGamma,
  64320. min: 0,
  64321. max: 4,
  64322. step: 0.01,
  64323. slide: (event, ui) => {
  64324. material.intensityGamma = ui.value;
  64325. }
  64326. });
  64327. panel.find('#sldIntensityContrast').slider({
  64328. value: material.intensityContrast,
  64329. min: -1,
  64330. max: 1,
  64331. step: 0.01,
  64332. slide: (event, ui) => {
  64333. material.intensityContrast = ui.value;
  64334. }
  64335. });
  64336. panel.find('#sldIntensityBrightness').slider({
  64337. value: material.intensityBrightness,
  64338. min: -1,
  64339. max: 1,
  64340. step: 0.01,
  64341. slide: (event, ui) => {
  64342. material.intensityBrightness = ui.value;
  64343. }
  64344. });
  64345. panel.find('#sldWeightRGB').slider({
  64346. value: material.weightRGB,
  64347. min: 0,
  64348. max: 1,
  64349. step: 0.01,
  64350. slide: (event, ui) => {
  64351. material.weightRGB = ui.value;
  64352. }
  64353. });
  64354. panel.find('#sldWeightIntensity').slider({
  64355. value: material.weightIntensity,
  64356. min: 0,
  64357. max: 1,
  64358. step: 0.01,
  64359. slide: (event, ui) => {
  64360. material.weightIntensity = ui.value;
  64361. }
  64362. });
  64363. panel.find('#sldWeightElevation').slider({
  64364. value: material.weightElevation,
  64365. min: 0,
  64366. max: 1,
  64367. step: 0.01,
  64368. slide: (event, ui) => {
  64369. material.weightElevation = ui.value;
  64370. }
  64371. });
  64372. panel.find('#sldWeightClassification').slider({
  64373. value: material.weightClassification,
  64374. min: 0,
  64375. max: 1,
  64376. step: 0.01,
  64377. slide: (event, ui) => {
  64378. material.weightClassification = ui.value;
  64379. }
  64380. });
  64381. panel.find('#sldWeightReturnNumber').slider({
  64382. value: material.weightReturnNumber,
  64383. min: 0,
  64384. max: 1,
  64385. step: 0.01,
  64386. slide: (event, ui) => {
  64387. material.weightReturnNumber = ui.value;
  64388. }
  64389. });
  64390. panel.find('#sldWeightSourceID').slider({
  64391. value: material.weightSourceID,
  64392. min: 0,
  64393. max: 1,
  64394. step: 0.01,
  64395. slide: (event, ui) => {
  64396. material.weightSourceID = ui.value;
  64397. }
  64398. });
  64399. panel.find("#materials\\.color\\.picker").spectrum({
  64400. flat: true,
  64401. showInput: true,
  64402. preferredFormat: 'rgb',
  64403. cancelText: '',
  64404. chooseText: 'Apply',
  64405. color: "#".concat(material.color.getHexString()),
  64406. move: color => {
  64407. var cRGB = color.toRgb();
  64408. var tc = new Color().setRGB(cRGB.r / 255, cRGB.g / 255, cRGB.b / 255);
  64409. material.color = tc;
  64410. },
  64411. change: color => {
  64412. var cRGB = color.toRgb();
  64413. var tc = new Color().setRGB(cRGB.r / 255, cRGB.g / 255, cRGB.b / 255);
  64414. material.color = tc;
  64415. }
  64416. });
  64417. this.addVolatileListener(material, "color_changed", () => {
  64418. panel.find("#materials\\.color\\.picker").spectrum('set', "#".concat(material.color.getHexString()));
  64419. });
  64420. var updateHeightRange = function updateHeightRange() {
  64421. var aPosition = pointcloud.getAttribute("position");
  64422. var bMin, bMax;
  64423. if (aPosition) {
  64424. // for new format 2.0 and loader that contain precomputed min/max of attributes
  64425. var min = aPosition.range[0][2];
  64426. var max = aPosition.range[1][2];
  64427. var width = max - min;
  64428. bMin = min - 0.2 * width;
  64429. bMax = max + 0.2 * width;
  64430. } else {
  64431. // for format up until exlusive 2.0
  64432. var box = [pointcloud.pcoGeometry.tightBoundingBox, pointcloud.getBoundingBoxWorld()].find(v => v !== undefined);
  64433. pointcloud.updateMatrixWorld(true);
  64434. box = Utils.computeTransformedBoundingBox(box, pointcloud.matrixWorld);
  64435. var bWidth = box.max.z - box.min.z;
  64436. bMin = box.min.z - 0.2 * bWidth;
  64437. bMax = box.max.z + 0.2 * bWidth;
  64438. }
  64439. var range = material.elevationRange;
  64440. panel.find('#lblHeightRange').html("".concat(range[0].toFixed(2), " to ").concat(range[1].toFixed(2)));
  64441. panel.find('#sldHeightRange').slider({
  64442. min: bMin,
  64443. max: bMax,
  64444. values: range
  64445. });
  64446. };
  64447. var updateExtraRange = function updateExtraRange() {
  64448. var attributeName = material.activeAttributeName;
  64449. var attribute = pointcloud.getAttribute(attributeName);
  64450. if (attribute == null) {
  64451. return;
  64452. }
  64453. var range = material.getRange(attributeName);
  64454. if (range == null) {
  64455. range = attribute.range;
  64456. }
  64457. // currently only supporting scalar ranges.
  64458. // rgba, normals, positions, etc have vector ranges, however
  64459. var isValidRange = typeof range[0] === "number" && typeof range[1] === "number";
  64460. if (!isValidRange) {
  64461. return;
  64462. }
  64463. if (range) {
  64464. var msg = "".concat(range[0].toFixed(2), " to ").concat(range[1].toFixed(2));
  64465. panel.find('#lblExtraRange').html(msg);
  64466. } else {
  64467. panel.find("could not deduce range");
  64468. }
  64469. };
  64470. var updateIntensityRange = function updateIntensityRange() {
  64471. var range = material.intensityRange;
  64472. panel.find('#lblIntensityRange').html("".concat(parseInt(range[0]), " to ").concat(parseInt(range[1])));
  64473. };
  64474. {
  64475. updateHeightRange();
  64476. panel.find("#sldHeightRange").slider('option', 'min');
  64477. panel.find("#sldHeightRange").slider('option', 'max');
  64478. }
  64479. {
  64480. var elGradientRepeat = panel.find("#gradient_repeat_option");
  64481. elGradientRepeat.selectgroup({
  64482. title: "Gradient"
  64483. });
  64484. elGradientRepeat.find("input").click(e => {
  64485. this.viewer.setElevationGradientRepeat(ElevationGradientRepeat[e.target.value]);
  64486. });
  64487. var current = Object.keys(ElevationGradientRepeat).filter(key => ElevationGradientRepeat[key] === this.viewer.elevationGradientRepeat);
  64488. elGradientRepeat.find("input[value=".concat(current, "]")).trigger("click");
  64489. }
  64490. var onIntensityChange = () => {
  64491. var gamma = material.intensityGamma;
  64492. var contrast = material.intensityContrast;
  64493. var brightness = material.intensityBrightness;
  64494. updateIntensityRange();
  64495. panel.find('#lblIntensityGamma').html(gamma.toFixed(2));
  64496. panel.find('#lblIntensityContrast').html(contrast.toFixed(2));
  64497. panel.find('#lblIntensityBrightness').html(brightness.toFixed(2));
  64498. panel.find('#sldIntensityGamma').slider({
  64499. value: gamma
  64500. });
  64501. panel.find('#sldIntensityContrast').slider({
  64502. value: contrast
  64503. });
  64504. panel.find('#sldIntensityBrightness').slider({
  64505. value: brightness
  64506. });
  64507. };
  64508. var onRGBChange = () => {
  64509. var gamma = material.rgbGamma;
  64510. var contrast = material.rgbContrast;
  64511. var brightness = material.rgbBrightness;
  64512. panel.find('#lblRGBGamma').html(gamma.toFixed(2));
  64513. panel.find('#lblRGBContrast').html(contrast.toFixed(2));
  64514. panel.find('#lblRGBBrightness').html(brightness.toFixed(2));
  64515. panel.find('#sldRGBGamma').slider({
  64516. value: gamma
  64517. });
  64518. panel.find('#sldRGBContrast').slider({
  64519. value: contrast
  64520. });
  64521. panel.find('#sldRGBBrightness').slider({
  64522. value: brightness
  64523. });
  64524. };
  64525. this.addVolatileListener(material, "material_property_changed", updateExtraRange);
  64526. this.addVolatileListener(material, "material_property_changed", updateHeightRange);
  64527. this.addVolatileListener(material, "material_property_changed", onIntensityChange);
  64528. this.addVolatileListener(material, "material_property_changed", onRGBChange);
  64529. updateExtraRange();
  64530. updateHeightRange();
  64531. onIntensityChange();
  64532. onRGBChange();
  64533. }
  64534. }
  64535. setMeasurement(object) {
  64536. var TYPE = {
  64537. DISTANCE: {
  64538. panel: DistancePanel
  64539. },
  64540. AREA: {
  64541. panel: AreaPanel
  64542. },
  64543. POINT: {
  64544. panel: PointPanel
  64545. },
  64546. ANGLE: {
  64547. panel: AnglePanel
  64548. },
  64549. HEIGHT: {
  64550. panel: HeightPanel
  64551. },
  64552. PROFILE: {
  64553. panel: ProfilePanel
  64554. },
  64555. VOLUME: {
  64556. panel: VolumePanel
  64557. },
  64558. CIRCLE: {
  64559. panel: CirclePanel
  64560. },
  64561. OTHER: {
  64562. panel: PointPanel
  64563. }
  64564. };
  64565. var getType = measurement => {
  64566. if (measurement instanceof Measure) {
  64567. if (measurement.showDistances && !measurement.showArea && !measurement.showAngles) {
  64568. return TYPE.DISTANCE;
  64569. } else if (measurement.showDistances && measurement.showArea && !measurement.showAngles) {
  64570. return TYPE.AREA;
  64571. } else if (measurement.maxMarkers === 1) {
  64572. return TYPE.POINT;
  64573. } else if (!measurement.showDistances && !measurement.showArea && measurement.showAngles) {
  64574. return TYPE.ANGLE;
  64575. } else if (measurement.showHeight) {
  64576. return TYPE.HEIGHT;
  64577. } else if (measurement.showCircle) {
  64578. return TYPE.CIRCLE;
  64579. } else {
  64580. return TYPE.OTHER;
  64581. }
  64582. } else if (measurement instanceof Profile) {
  64583. return TYPE.PROFILE;
  64584. } else if (measurement instanceof Volume) {
  64585. return TYPE.VOLUME;
  64586. }
  64587. };
  64588. //this.container.html("measurement");
  64589. var type = getType(object);
  64590. var Panel = type.panel;
  64591. var panel = new Panel(this.viewer, object, this);
  64592. this.container.append(panel.elContent);
  64593. }
  64594. setCamera(camera) {
  64595. var panel = new CameraPanel(this.viewer, this);
  64596. this.container.append(panel.elContent);
  64597. }
  64598. setAnnotation(annotation) {
  64599. var panel = new AnnotationPanel(this.viewer, this, annotation);
  64600. this.container.append(panel.elContent);
  64601. }
  64602. setCameraAnimation(animation) {
  64603. var panel = new CameraAnimationPanel(this.viewer, this, animation);
  64604. this.container.append(panel.elContent);
  64605. }
  64606. }
  64607. function addCommas(nStr) {
  64608. nStr += '';
  64609. var x = nStr.split('.');
  64610. var x1 = x[0];
  64611. var x2 = x.length > 1 ? '.' + x[1] : '';
  64612. var rgx = /(\d+)(\d{3})/;
  64613. while (rgx.test(x1)) {
  64614. x1 = x1.replace(rgx, '$1' + ',' + '$2');
  64615. }
  64616. return x1 + x2;
  64617. }
  64618. ;
  64619. function format(value) {
  64620. return addCommas(value.toFixed(3));
  64621. }
  64622. ;
  64623. class HierarchicalSlider {
  64624. constructor() {
  64625. var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  64626. this.element = document.createElement("div");
  64627. this.labels = [];
  64628. this.sliders = [];
  64629. this.range = params.range != null ? params.range : [0, 1];
  64630. this.slide = params.slide != null ? params.slide : null;
  64631. this.step = params.step != null ? params.step : 0.0001;
  64632. var levels = params.levels != null ? params.levels : 1;
  64633. for (var level = 0; level < levels; level++) {
  64634. this.addLevel();
  64635. }
  64636. }
  64637. setRange(range) {
  64638. this.range = [...range];
  64639. {
  64640. // root slider
  64641. var slider = this.sliders[0];
  64642. $(slider).slider({
  64643. min: range[0],
  64644. max: range[1]
  64645. });
  64646. }
  64647. for (var i = 1; i < this.sliders.length; i++) {
  64648. var parentSlider = this.sliders[i - 1];
  64649. var _slider = this.sliders[i];
  64650. var parentValues = $(parentSlider).slider("option", "values");
  64651. var childRange = [...parentValues];
  64652. $(_slider).slider({
  64653. min: childRange[0],
  64654. max: childRange[1]
  64655. });
  64656. }
  64657. this.updateLabels();
  64658. }
  64659. setValues(values) {
  64660. for (var slider of this.sliders) {
  64661. $(slider).slider({
  64662. values: [...values]
  64663. });
  64664. }
  64665. this.updateLabels();
  64666. }
  64667. addLevel() {
  64668. var elLevel = document.createElement("li");
  64669. var elRange = document.createTextNode("Range: ");
  64670. var label = document.createElement("span");
  64671. var slider = document.createElement("div");
  64672. var level = this.sliders.length;
  64673. var [min, max] = [0, 0];
  64674. if (this.sliders.length === 0) {
  64675. [min, max] = this.range;
  64676. } else {
  64677. var parentSlider = this.sliders[this.sliders.length - 1];
  64678. [min, max] = $(parentSlider).slider("option", "values");
  64679. }
  64680. $(slider).slider({
  64681. range: true,
  64682. min: min,
  64683. max: max,
  64684. step: this.step,
  64685. values: [min, max],
  64686. slide: (event, ui) => {
  64687. // set all descendants to same range
  64688. var levels = this.sliders.length;
  64689. for (var i = level + 1; i < levels; i++) {
  64690. var descendant = this.sliders[i];
  64691. $(descendant).slider({
  64692. range: true,
  64693. min: ui.values[0],
  64694. max: ui.values[1],
  64695. values: [...ui.values]
  64696. });
  64697. }
  64698. if (this.slide) {
  64699. var values = [...ui.values];
  64700. this.slide({
  64701. target: this,
  64702. range: this.range,
  64703. values: values
  64704. });
  64705. }
  64706. this.updateLabels();
  64707. }
  64708. });
  64709. elLevel.append(elRange, label, slider);
  64710. this.sliders.push(slider);
  64711. this.labels.push(label);
  64712. this.element.append(elLevel);
  64713. this.updateLabels();
  64714. }
  64715. removeLevel() {}
  64716. updateSliders() {}
  64717. updateLabels() {
  64718. var levels = this.sliders.length;
  64719. for (var i = 0; i < levels; i++) {
  64720. var slider = this.sliders[i];
  64721. var label = this.labels[i];
  64722. var [min, max] = $(slider).slider("option", "values");
  64723. var strMin = format(min);
  64724. var strMax = format(max);
  64725. var strLabel = "".concat(strMin, " to ").concat(strMax);
  64726. label.innerHTML = strLabel;
  64727. }
  64728. }
  64729. }
  64730. class OrientedImageControls extends EventDispatcher$1 {
  64731. constructor(viewer) {
  64732. super();
  64733. this.viewer = viewer;
  64734. this.renderer = viewer.renderer;
  64735. this.originalCam = viewer.scene.getActiveCamera();
  64736. this.shearCam = viewer.scene.getActiveCamera().clone();
  64737. this.shearCam.rotation.set(this.originalCam.rotation.toArray());
  64738. this.shearCam.updateProjectionMatrix();
  64739. this.shearCam.updateProjectionMatrix = () => {
  64740. return this.shearCam.projectionMatrix;
  64741. };
  64742. this.image = null;
  64743. this.fadeFactor = 20;
  64744. this.fovDelta = 0;
  64745. this.fovMin = 0.1;
  64746. this.fovMax = 120;
  64747. this.shear = [0, 0];
  64748. // const style = ``;
  64749. this.elUp = $("<input type=\"button\" value=\"\uD83E\uDC45\" style=\"position: absolute; top: 10px; left: calc(50%); z-index: 1000\" />");
  64750. this.elRight = $("<input type=\"button\" value=\"\uD83E\uDC46\" style=\"position: absolute; top: calc(50%); right: 10px; z-index: 1000\" />");
  64751. this.elDown = $("<input type=\"button\" value=\"\uD83E\uDC47\" style=\"position: absolute; bottom: 10px; left: calc(50%); z-index: 1000\" />");
  64752. this.elLeft = $("<input type=\"button\" value=\"\uD83E\uDC44\" style=\"position: absolute; top: calc(50%); left: 10px; z-index: 1000\" />");
  64753. this.elExit = $("<input type=\"button\" value=\"Back to 3D view\" style=\"position: absolute; bottom: 10px; right: 10px; z-index: 1000\" />");
  64754. this.elExit.click(() => {
  64755. this.release();
  64756. });
  64757. this.elUp.click(() => {
  64758. var fovY = viewer.getFOV();
  64759. var top = Math.tan(MathUtils.degToRad(fovY / 2));
  64760. this.shear[1] += 0.1 * top;
  64761. });
  64762. this.elRight.click(() => {
  64763. var fovY = viewer.getFOV();
  64764. var top = Math.tan(MathUtils.degToRad(fovY / 2));
  64765. this.shear[0] += 0.1 * top;
  64766. });
  64767. this.elDown.click(() => {
  64768. var fovY = viewer.getFOV();
  64769. var top = Math.tan(MathUtils.degToRad(fovY / 2));
  64770. this.shear[1] -= 0.1 * top;
  64771. });
  64772. this.elLeft.click(() => {
  64773. var fovY = viewer.getFOV();
  64774. var top = Math.tan(MathUtils.degToRad(fovY / 2));
  64775. this.shear[0] -= 0.1 * top;
  64776. });
  64777. this.scene = null;
  64778. this.sceneControls = new Scene();
  64779. var scroll = e => {
  64780. this.fovDelta += -e.delta * 1.0;
  64781. };
  64782. this.addEventListener('mousewheel', scroll);
  64783. //this.addEventListener("mousemove", onMove);
  64784. }
  64785. hasSomethingCaptured() {
  64786. return this.image !== null;
  64787. }
  64788. capture(image) {
  64789. if (this.hasSomethingCaptured()) {
  64790. return;
  64791. }
  64792. this.image = image;
  64793. this.originalFOV = this.viewer.getFOV();
  64794. this.originalControls = this.viewer.getControls();
  64795. this.viewer.setControls(this);
  64796. this.viewer.scene.overrideCamera = this.shearCam;
  64797. var elCanvas = this.viewer.renderer.domElement;
  64798. var elRoot = $(elCanvas.parentElement);
  64799. this.shear = [0, 0];
  64800. elRoot.append(this.elUp);
  64801. elRoot.append(this.elRight);
  64802. elRoot.append(this.elDown);
  64803. elRoot.append(this.elLeft);
  64804. elRoot.append(this.elExit);
  64805. }
  64806. release() {
  64807. this.image = null;
  64808. this.viewer.scene.overrideCamera = null;
  64809. this.elUp.detach();
  64810. this.elRight.detach();
  64811. this.elDown.detach();
  64812. this.elLeft.detach();
  64813. this.elExit.detach();
  64814. this.viewer.setFOV(this.originalFOV);
  64815. this.viewer.setControls(this.originalControls);
  64816. }
  64817. setScene(scene) {
  64818. this.scene = scene;
  64819. }
  64820. update(delta) {
  64821. // const view = this.scene.view;
  64822. // let prevTotal = this.shearCam.projectionMatrix.elements.reduce( (a, i) => a + i, 0);
  64823. //const progression = Math.min(1, this.fadeFactor * delta);
  64824. //const attenuation = Math.max(0, 1 - this.fadeFactor * delta);
  64825. var progression = 1;
  64826. var attenuation = 0;
  64827. var oldFov = this.viewer.getFOV();
  64828. var fovProgression = progression * this.fovDelta;
  64829. var newFov = oldFov * (1 + fovProgression / 10);
  64830. newFov = Math.max(this.fovMin, newFov);
  64831. newFov = Math.min(this.fovMax, newFov);
  64832. var diff = newFov / oldFov;
  64833. var mouse = this.viewer.inputHandler.mouse;
  64834. var canvasSize = this.viewer.renderer.getSize(new Vector2());
  64835. var uv = [mouse.x / canvasSize.x, (canvasSize.y - mouse.y) / canvasSize.y];
  64836. var fovY = newFov;
  64837. var aspect = canvasSize.x / canvasSize.y;
  64838. var top = Math.tan(MathUtils.degToRad(fovY / 2));
  64839. var height = 2 * top;
  64840. var width = aspect * height;
  64841. var shearRangeX = [this.shear[0] - 0.5 * width, this.shear[0] + 0.5 * width];
  64842. var shearRangeY = [this.shear[1] - 0.5 * height, this.shear[1] + 0.5 * height];
  64843. var shx = (1 - uv[0]) * shearRangeX[0] + uv[0] * shearRangeX[1];
  64844. var shy = (1 - uv[1]) * shearRangeY[0] + uv[1] * shearRangeY[1];
  64845. var shu = 1 - diff;
  64846. var newShear = [(1 - shu) * this.shear[0] + shu * shx, (1 - shu) * this.shear[1] + shu * shy];
  64847. this.shear = newShear;
  64848. this.viewer.setFOV(newFov);
  64849. var {
  64850. originalCam,
  64851. shearCam
  64852. } = this;
  64853. originalCam.fov = newFov;
  64854. originalCam.updateMatrixWorld();
  64855. originalCam.updateProjectionMatrix();
  64856. shearCam.copy(originalCam);
  64857. shearCam.rotation.set(...originalCam.rotation.toArray());
  64858. shearCam.updateMatrixWorld();
  64859. shearCam.projectionMatrix.copy(originalCam.projectionMatrix);
  64860. var [sx, sy] = this.shear;
  64861. var mShear = new Matrix4().set(1, 0, sx, 0, 0, 1, sy, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  64862. var proj = shearCam.projectionMatrix;
  64863. proj.multiply(mShear);
  64864. shearCam.projectionMatrixInverse.copy(proj).invert();
  64865. var total = shearCam.projectionMatrix.elements.reduce((a, i) => a + i, 0);
  64866. this.fovDelta *= attenuation;
  64867. }
  64868. }
  64869. ;
  64870. // https://support.pix4d.com/hc/en-us/articles/205675256-How-are-yaw-pitch-roll-defined
  64871. // https://support.pix4d.com/hc/en-us/articles/202558969-How-are-omega-phi-kappa-defined
  64872. function createMaterial() {
  64873. var vertexShader = "\n\tuniform float uNear;\n\tvarying vec2 vUV;\n\tvarying vec4 vDebug;\n\t\n\tvoid main(){\n\t\tvDebug = vec4(0.0, 1.0, 0.0, 1.0);\n\t\tvec4 modelViewPosition = modelViewMatrix * vec4(position, 1.0);\n\t\t// make sure that this mesh is at least in front of the near plane\n\t\tmodelViewPosition.xyz += normalize(modelViewPosition.xyz) * uNear;\n\t\tgl_Position = projectionMatrix * modelViewPosition;\n\t\tvUV = uv;\n\t}\n\t";
  64874. var fragmentShader = "\n\tuniform sampler2D tColor;\n\tuniform float uOpacity;\n\tvarying vec2 vUV;\n\tvarying vec4 vDebug;\n\tvoid main(){\n\t\tvec4 color = texture2D(tColor, vUV);\n\t\tgl_FragColor = color;\n\t\tgl_FragColor.a = uOpacity;\n\t}\n\t";
  64875. var material = new ShaderMaterial({
  64876. uniforms: {
  64877. // time: { value: 1.0 },
  64878. // resolution: { value: new THREE.Vector2() }
  64879. tColor: {
  64880. value: new Texture()
  64881. },
  64882. uNear: {
  64883. value: 0.0
  64884. },
  64885. uOpacity: {
  64886. value: 1.0
  64887. }
  64888. },
  64889. vertexShader: vertexShader,
  64890. fragmentShader: fragmentShader,
  64891. side: DoubleSide
  64892. });
  64893. material.side = DoubleSide;
  64894. return material;
  64895. }
  64896. var planeGeometry = new PlaneGeometry(1, 1);
  64897. var lineGeometry = new Geometry();
  64898. lineGeometry.vertices.push(new Vector3(-0.5, -0.5, 0), new Vector3(0.5, -0.5, 0), new Vector3(0.5, 0.5, 0), new Vector3(-0.5, 0.5, 0), new Vector3(-0.5, -0.5, 0));
  64899. class OrientedImage {
  64900. constructor(id) {
  64901. this.id = id;
  64902. this.fov = 1.0;
  64903. this.position = new Vector3();
  64904. this.rotation = new Vector3();
  64905. this.width = 0;
  64906. this.height = 0;
  64907. this.fov = 1.0;
  64908. var material = createMaterial();
  64909. var lineMaterial = new LineBasicMaterial({
  64910. color: 0x00ff00
  64911. });
  64912. this.mesh = new Mesh(planeGeometry, material);
  64913. this.line = new Line(lineGeometry, lineMaterial);
  64914. this.texture = null;
  64915. this.mesh.orientedImage = this;
  64916. }
  64917. set(position, rotation, dimension, fov) {
  64918. var radians = rotation.map(MathUtils.degToRad);
  64919. this.position.set(...position);
  64920. this.mesh.position.set(...position);
  64921. this.rotation.set(...radians);
  64922. this.mesh.rotation.set(...radians);
  64923. [this.width, this.height] = dimension;
  64924. this.mesh.scale.set(this.width / this.height, 1, 1);
  64925. this.fov = fov;
  64926. this.updateTransform();
  64927. }
  64928. updateTransform() {
  64929. var {
  64930. mesh,
  64931. line,
  64932. fov
  64933. } = this;
  64934. mesh.updateMatrixWorld();
  64935. var dir = mesh.getWorldDirection();
  64936. var alpha = MathUtils.degToRad(fov / 2);
  64937. var d = -0.5 / Math.tan(alpha);
  64938. var move = dir.clone().multiplyScalar(d);
  64939. mesh.position.add(move);
  64940. line.position.copy(mesh.position);
  64941. line.scale.copy(mesh.scale);
  64942. line.rotation.copy(mesh.rotation);
  64943. }
  64944. }
  64945. ;
  64946. class OrientedImages extends EventDispatcher$1 {
  64947. constructor() {
  64948. super();
  64949. this.node = null;
  64950. this.cameraParams = null;
  64951. this.imageParams = null;
  64952. this.images = null;
  64953. this._visible = true;
  64954. }
  64955. set visible(visible) {
  64956. if (this._visible === visible) {
  64957. return;
  64958. }
  64959. for (var image of this.images) {
  64960. image.mesh.visible = visible;
  64961. image.line.visible = visible;
  64962. }
  64963. this._visible = visible;
  64964. this.dispatchEvent({
  64965. type: "visibility_changed",
  64966. images: this
  64967. });
  64968. }
  64969. get visible() {
  64970. return this._visible;
  64971. }
  64972. }
  64973. ;
  64974. class OrientedImageLoader {
  64975. static async loadCameraParams(path) {
  64976. var res = await fetch(path);
  64977. var text = await res.text();
  64978. var parser = new DOMParser();
  64979. var doc = parser.parseFromString(text, "application/xml");
  64980. var width = parseInt(doc.getElementsByTagName("width")[0].textContent);
  64981. var height = parseInt(doc.getElementsByTagName("height")[0].textContent);
  64982. var f = parseFloat(doc.getElementsByTagName("f")[0].textContent);
  64983. var a = height / 2 / f;
  64984. var fov = 2 * MathUtils.radToDeg(Math.atan(a));
  64985. var params = {
  64986. path: path,
  64987. width: width,
  64988. height: height,
  64989. f: f,
  64990. fov: fov
  64991. };
  64992. return params;
  64993. }
  64994. static async loadImageParams(path) {
  64995. var response = await fetch(path);
  64996. if (!response.ok) {
  64997. console.error("failed to load ".concat(path));
  64998. return;
  64999. }
  65000. var content = await response.text();
  65001. var lines = content.split(/\r?\n/);
  65002. var imageParams = [];
  65003. for (var i = 1; i < lines.length; i++) {
  65004. var line = lines[i];
  65005. if (line.startsWith("#")) {
  65006. continue;
  65007. }
  65008. var tokens = line.split(/\s+/);
  65009. if (tokens.length < 6) {
  65010. continue;
  65011. }
  65012. var params = {
  65013. id: tokens[0],
  65014. x: Number.parseFloat(tokens[1]),
  65015. y: Number.parseFloat(tokens[2]),
  65016. z: Number.parseFloat(tokens[3]),
  65017. omega: Number.parseFloat(tokens[4]),
  65018. phi: Number.parseFloat(tokens[5]),
  65019. kappa: Number.parseFloat(tokens[6])
  65020. };
  65021. // const whitelist = ["47518.jpg"];
  65022. // if(whitelist.includes(params.id)){
  65023. // imageParams.push(params);
  65024. // }
  65025. imageParams.push(params);
  65026. }
  65027. // debug
  65028. //return [imageParams[50]];
  65029. return imageParams;
  65030. }
  65031. static async load(cameraParamsPath, imageParamsPath, viewer) {
  65032. var tStart = performance.now();
  65033. var [cameraParams, imageParams] = await Promise.all([OrientedImageLoader.loadCameraParams(cameraParamsPath), OrientedImageLoader.loadImageParams(imageParamsPath)]);
  65034. var orientedImageControls = new OrientedImageControls(viewer);
  65035. var raycaster = new Raycaster();
  65036. var tEnd = performance.now();
  65037. console.log(tEnd - tStart);
  65038. // const sp = new THREE.PlaneGeometry(1, 1);
  65039. // const lg = new THREE.Geometry();
  65040. // lg.vertices.push(
  65041. // new THREE.Vector3(-0.5, -0.5, 0),
  65042. // new THREE.Vector3( 0.5, -0.5, 0),
  65043. // new THREE.Vector3( 0.5, 0.5, 0),
  65044. // new THREE.Vector3(-0.5, 0.5, 0),
  65045. // new THREE.Vector3(-0.5, -0.5, 0),
  65046. // );
  65047. var {
  65048. width,
  65049. height
  65050. } = cameraParams;
  65051. var orientedImages = [];
  65052. var sceneNode = new Object3D();
  65053. sceneNode.name = "oriented_images";
  65054. for (var params of imageParams) {
  65055. // const material = createMaterial();
  65056. // const lm = new THREE.LineBasicMaterial( { color: 0x00ff00 } );
  65057. // const mesh = new THREE.Mesh(sp, material);
  65058. var {
  65059. x,
  65060. y,
  65061. z,
  65062. omega,
  65063. phi,
  65064. kappa
  65065. } = params;
  65066. // const [rx, ry, rz] = [omega, phi, kappa]
  65067. // .map(THREE.Math.degToRad);
  65068. // mesh.position.set(x, y, z);
  65069. // mesh.scale.set(width / height, 1, 1);
  65070. // mesh.rotation.set(rx, ry, rz);
  65071. // {
  65072. // mesh.updateMatrixWorld();
  65073. // const dir = mesh.getWorldDirection();
  65074. // const alpha = THREE.Math.degToRad(cameraParams.fov / 2);
  65075. // const d = -0.5 / Math.tan(alpha);
  65076. // const move = dir.clone().multiplyScalar(d);
  65077. // mesh.position.add(move);
  65078. // }
  65079. // sceneNode.add(mesh);
  65080. // const line = new THREE.Line(lg, lm);
  65081. // line.position.copy(mesh.position);
  65082. // line.scale.copy(mesh.scale);
  65083. // line.rotation.copy(mesh.rotation);
  65084. // sceneNode.add(line);
  65085. var orientedImage = new OrientedImage(params.id);
  65086. // orientedImage.setPosition(x, y, z);
  65087. // orientedImage.setRotation(omega, phi, kappa);
  65088. // orientedImage.setDimension(width, height);
  65089. var position = [x, y, z];
  65090. var rotation = [omega, phi, kappa];
  65091. var dimension = [width, height];
  65092. orientedImage.set(position, rotation, dimension, cameraParams.fov);
  65093. sceneNode.add(orientedImage.mesh);
  65094. sceneNode.add(orientedImage.line);
  65095. orientedImages.push(orientedImage);
  65096. }
  65097. var hoveredElement = null;
  65098. var clipVolume = null;
  65099. var onMouseMove = evt => {
  65100. var tStart = performance.now();
  65101. if (hoveredElement) {
  65102. hoveredElement.line.material.color.setRGB(0, 1, 0);
  65103. }
  65104. evt.preventDefault();
  65105. //var array = getMousePosition( container, evt.clientX, evt.clientY );
  65106. var rect = viewer.renderer.domElement.getBoundingClientRect();
  65107. var [x, y] = [evt.clientX, evt.clientY];
  65108. var array = [(x - rect.left) / rect.width, (y - rect.top) / rect.height];
  65109. var onClickPosition = new Vector2(...array);
  65110. //const intersects = getIntersects(onClickPosition, scene.children);
  65111. var camera = viewer.scene.getActiveCamera();
  65112. var mouse = new Vector3(+(onClickPosition.x * 2) - 1, -(onClickPosition.y * 2) + 1);
  65113. var objects = orientedImages.map(i => i.mesh);
  65114. raycaster.setFromCamera(mouse, camera);
  65115. var intersects = raycaster.intersectObjects(objects);
  65116. var selectionChanged = false;
  65117. if (intersects.length > 0) {
  65118. //console.log(intersects);
  65119. var intersection = intersects[0];
  65120. var _orientedImage = intersection.object.orientedImage;
  65121. _orientedImage.line.material.color.setRGB(1, 0, 0);
  65122. selectionChanged = hoveredElement !== _orientedImage;
  65123. hoveredElement = _orientedImage;
  65124. } else {
  65125. hoveredElement = null;
  65126. }
  65127. var shouldRemoveClipVolume = clipVolume !== null && hoveredElement === null;
  65128. var shouldAddClipVolume = clipVolume === null && hoveredElement !== null;
  65129. if (clipVolume !== null && (hoveredElement === null || selectionChanged)) {
  65130. // remove existing
  65131. viewer.scene.removePolygonClipVolume(clipVolume);
  65132. clipVolume = null;
  65133. }
  65134. if (shouldAddClipVolume || selectionChanged) {
  65135. var img = hoveredElement;
  65136. var fov = cameraParams.fov;
  65137. var aspect = cameraParams.width / cameraParams.height;
  65138. var near = 1.0;
  65139. var far = 1000 * 1000;
  65140. var _camera = new PerspectiveCamera(fov, aspect, near, far);
  65141. _camera.rotation.order = viewer.scene.getActiveCamera().rotation.order;
  65142. _camera.rotation.copy(img.mesh.rotation);
  65143. {
  65144. var mesh = img.mesh;
  65145. var dir = mesh.getWorldDirection();
  65146. var pos = mesh.position;
  65147. var alpha = MathUtils.degToRad(fov / 2);
  65148. var d = 0.5 / Math.tan(alpha);
  65149. var newCamPos = pos.clone().add(dir.clone().multiplyScalar(d));
  65150. var newCamDir = pos.clone().sub(newCamPos);
  65151. var newCamTarget = new Vector3().addVectors(newCamPos, newCamDir.clone().multiplyScalar(viewer.getMoveSpeed()));
  65152. _camera.position.copy(newCamPos);
  65153. }
  65154. var volume = new Potree.PolygonClipVolume(_camera);
  65155. var m0 = new Mesh();
  65156. var m1 = new Mesh();
  65157. var m2 = new Mesh();
  65158. var m3 = new Mesh();
  65159. m0.position.set(-1, -1, 0);
  65160. m1.position.set(1, -1, 0);
  65161. m2.position.set(1, 1, 0);
  65162. m3.position.set(-1, 1, 0);
  65163. volume.markers.push(m0, m1, m2, m3);
  65164. volume.initialized = true;
  65165. viewer.scene.addPolygonClipVolume(volume);
  65166. clipVolume = volume;
  65167. }
  65168. var tEnd = performance.now();
  65169. //console.log(tEnd - tStart);
  65170. };
  65171. var moveToImage = image => {
  65172. console.log("move to image " + image.id);
  65173. var mesh = image.mesh;
  65174. var newCamPos = image.position.clone();
  65175. var newCamTarget = mesh.position.clone();
  65176. viewer.scene.view.setView(newCamPos, newCamTarget, 500, () => {
  65177. orientedImageControls.capture(image);
  65178. });
  65179. if (image.texture === null) {
  65180. var target = image;
  65181. var tmpImagePath = "".concat(Potree.resourcePath, "/images/loading.jpg");
  65182. new TextureLoader().load(tmpImagePath, texture => {
  65183. if (target.texture === null) {
  65184. target.texture = texture;
  65185. target.mesh.material.uniforms.tColor.value = texture;
  65186. mesh.material.needsUpdate = true;
  65187. }
  65188. });
  65189. var imagePath = "".concat(imageParamsPath, "/../").concat(target.id);
  65190. new TextureLoader().load(imagePath, texture => {
  65191. target.texture = texture;
  65192. target.mesh.material.uniforms.tColor.value = texture;
  65193. mesh.material.needsUpdate = true;
  65194. });
  65195. }
  65196. };
  65197. var onMouseClick = evt => {
  65198. if (orientedImageControls.hasSomethingCaptured()) {
  65199. return;
  65200. }
  65201. if (hoveredElement) {
  65202. moveToImage(hoveredElement);
  65203. }
  65204. };
  65205. viewer.renderer.domElement.addEventListener('mousemove', onMouseMove, false);
  65206. viewer.renderer.domElement.addEventListener('mousedown', onMouseClick, false);
  65207. viewer.addEventListener("update", () => {
  65208. for (var image of orientedImages) {
  65209. var world = image.mesh.matrixWorld;
  65210. var {
  65211. width: _width,
  65212. height: _height
  65213. } = image;
  65214. var aspect = _width / _height;
  65215. var camera = viewer.scene.getActiveCamera();
  65216. var imgPos = image.mesh.getWorldPosition(new Vector3());
  65217. var camPos = camera.position;
  65218. var d = camPos.distanceTo(imgPos);
  65219. var minSize = 1; // in degrees of fov
  65220. var a = MathUtils.degToRad(minSize);
  65221. var r = d * Math.tan(a);
  65222. r = Math.max(r, 1);
  65223. image.mesh.scale.set(r * aspect, r, 1);
  65224. image.line.scale.set(r * aspect, r, 1);
  65225. image.mesh.material.uniforms.uNear.value = camera.near;
  65226. }
  65227. });
  65228. var images = new OrientedImages();
  65229. images.node = sceneNode;
  65230. images.cameraParamsPath = cameraParamsPath;
  65231. images.imageParamsPath = imageParamsPath;
  65232. images.cameraParams = cameraParams;
  65233. images.imageParams = imageParams;
  65234. images.images = orientedImages;
  65235. Potree.debug.moveToImage = moveToImage;
  65236. return images;
  65237. }
  65238. }
  65239. // This is a generated file. Do not edit.
  65240. var Space_Separator = /[\u1680\u2000-\u200A\u202F\u205F\u3000]/;
  65241. var ID_Start = /[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312E\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEA\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDF00-\uDF19]|\uD806[\uDCA0-\uDCDF\uDCFF\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE83\uDE86-\uDE89\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F\uDFE0\uDFE1]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]/;
  65242. var ID_Continue = /[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u08D4-\u08E1\u08E3-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u09FC\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0AF9-\u0AFF\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C60-\u0C63\u0C66-\u0C6F\u0C80-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D00-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D54-\u0D57\u0D5F-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19D9\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1C80-\u1C88\u1CD0-\u1CD2\u1CD4-\u1CF9\u1D00-\u1DF9\u1DFB-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u2E2F\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099\u309A\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312E\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEA\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C5\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE38-\uDE3A\uDE3F\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE6\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDCA-\uDDCC\uDDD0-\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE37\uDE3E\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3C-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF50\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC00-\uDC4A\uDC50-\uDC59\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDDD8-\uDDDD\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB7\uDEC0-\uDEC9\uDF00-\uDF19\uDF1D-\uDF2B\uDF30-\uDF39]|\uD806[\uDCA0-\uDCE9\uDCFF\uDE00-\uDE3E\uDE47\uDE50-\uDE83\uDE86-\uDE99\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC36\uDC38-\uDC40\uDC50-\uDC59\uDC72-\uDC8F\uDC92-\uDCA7\uDCA9-\uDCB6\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD36\uDD3A\uDD3C\uDD3D\uDD3F-\uDD47\uDD50-\uDD59]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50-\uDF7E\uDF8F-\uDF9F\uDFE0\uDFE1]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD838[\uDC00-\uDC06\uDC08-\uDC18\uDC1B-\uDC21\uDC23\uDC24\uDC26-\uDC2A]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6\uDD00-\uDD4A\uDD50-\uDD59]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF]/;
  65243. var unicode = {
  65244. Space_Separator: Space_Separator,
  65245. ID_Start: ID_Start,
  65246. ID_Continue: ID_Continue
  65247. };
  65248. var util = {
  65249. isSpaceSeparator(c) {
  65250. return typeof c === 'string' && unicode.Space_Separator.test(c);
  65251. },
  65252. isIdStartChar(c) {
  65253. return typeof c === 'string' && (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c === '$' || c === '_' || unicode.ID_Start.test(c));
  65254. },
  65255. isIdContinueChar(c) {
  65256. return typeof c === 'string' && (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c === '$' || c === '_' || c === '\u200C' || c === '\u200D' || unicode.ID_Continue.test(c));
  65257. },
  65258. isDigit(c) {
  65259. return typeof c === 'string' && /[0-9]/.test(c);
  65260. },
  65261. isHexDigit(c) {
  65262. return typeof c === 'string' && /[0-9A-Fa-f]/.test(c);
  65263. }
  65264. };
  65265. var source;
  65266. var parseState;
  65267. var stack$1;
  65268. var pos;
  65269. var line;
  65270. var column;
  65271. var token;
  65272. var key;
  65273. var root;
  65274. var parse$4 = function parse(text, reviver) {
  65275. source = String(text);
  65276. parseState = 'start';
  65277. stack$1 = [];
  65278. pos = 0;
  65279. line = 1;
  65280. column = 0;
  65281. token = undefined;
  65282. key = undefined;
  65283. root = undefined;
  65284. do {
  65285. token = lex();
  65286. // This code is unreachable.
  65287. // if (!parseStates[parseState]) {
  65288. // throw invalidParseState()
  65289. // }
  65290. parseStates[parseState]();
  65291. } while (token.type !== 'eof');
  65292. if (typeof reviver === 'function') {
  65293. return internalize({
  65294. '': root
  65295. }, '', reviver);
  65296. }
  65297. return root;
  65298. };
  65299. function internalize(holder, name, reviver) {
  65300. var value = holder[name];
  65301. if (value != null && typeof value === 'object') {
  65302. for (var _key in value) {
  65303. var replacement = internalize(value, _key, reviver);
  65304. if (replacement === undefined) {
  65305. delete value[_key];
  65306. } else {
  65307. value[_key] = replacement;
  65308. }
  65309. }
  65310. }
  65311. return reviver.call(holder, name, value);
  65312. }
  65313. var lexState;
  65314. var buffer;
  65315. var doubleQuote;
  65316. var sign$1;
  65317. var c$2;
  65318. function lex() {
  65319. lexState = 'default';
  65320. buffer = '';
  65321. doubleQuote = false;
  65322. sign$1 = 1;
  65323. for (;;) {
  65324. c$2 = peek();
  65325. // This code is unreachable.
  65326. // if (!lexStates[lexState]) {
  65327. // throw invalidLexState(lexState)
  65328. // }
  65329. var _token = lexStates[lexState]();
  65330. if (_token) {
  65331. return _token;
  65332. }
  65333. }
  65334. }
  65335. function peek() {
  65336. if (source[pos]) {
  65337. return String.fromCodePoint(source.codePointAt(pos));
  65338. }
  65339. }
  65340. function read() {
  65341. var c = peek();
  65342. if (c === '\n') {
  65343. line++;
  65344. column = 0;
  65345. } else if (c) {
  65346. column += c.length;
  65347. } else {
  65348. column++;
  65349. }
  65350. if (c) {
  65351. pos += c.length;
  65352. }
  65353. return c;
  65354. }
  65355. var lexStates = {
  65356. default() {
  65357. switch (c$2) {
  65358. case '\t':
  65359. case '\v':
  65360. case '\f':
  65361. case ' ':
  65362. case '\u00A0':
  65363. case '\uFEFF':
  65364. case '\n':
  65365. case '\r':
  65366. case '\u2028':
  65367. case '\u2029':
  65368. read();
  65369. return;
  65370. case '/':
  65371. read();
  65372. lexState = 'comment';
  65373. return;
  65374. case undefined:
  65375. read();
  65376. return newToken('eof');
  65377. }
  65378. if (util.isSpaceSeparator(c$2)) {
  65379. read();
  65380. return;
  65381. }
  65382. // This code is unreachable.
  65383. // if (!lexStates[parseState]) {
  65384. // throw invalidLexState(parseState)
  65385. // }
  65386. return lexStates[parseState]();
  65387. },
  65388. comment() {
  65389. switch (c$2) {
  65390. case '*':
  65391. read();
  65392. lexState = 'multiLineComment';
  65393. return;
  65394. case '/':
  65395. read();
  65396. lexState = 'singleLineComment';
  65397. return;
  65398. }
  65399. throw invalidChar(read());
  65400. },
  65401. multiLineComment() {
  65402. switch (c$2) {
  65403. case '*':
  65404. read();
  65405. lexState = 'multiLineCommentAsterisk';
  65406. return;
  65407. case undefined:
  65408. throw invalidChar(read());
  65409. }
  65410. read();
  65411. },
  65412. multiLineCommentAsterisk() {
  65413. switch (c$2) {
  65414. case '*':
  65415. read();
  65416. return;
  65417. case '/':
  65418. read();
  65419. lexState = 'default';
  65420. return;
  65421. case undefined:
  65422. throw invalidChar(read());
  65423. }
  65424. read();
  65425. lexState = 'multiLineComment';
  65426. },
  65427. singleLineComment() {
  65428. switch (c$2) {
  65429. case '\n':
  65430. case '\r':
  65431. case '\u2028':
  65432. case '\u2029':
  65433. read();
  65434. lexState = 'default';
  65435. return;
  65436. case undefined:
  65437. read();
  65438. return newToken('eof');
  65439. }
  65440. read();
  65441. },
  65442. value() {
  65443. switch (c$2) {
  65444. case '{':
  65445. case '[':
  65446. return newToken('punctuator', read());
  65447. case 'n':
  65448. read();
  65449. literal('ull');
  65450. return newToken('null', null);
  65451. case 't':
  65452. read();
  65453. literal('rue');
  65454. return newToken('boolean', true);
  65455. case 'f':
  65456. read();
  65457. literal('alse');
  65458. return newToken('boolean', false);
  65459. case '-':
  65460. case '+':
  65461. if (read() === '-') {
  65462. sign$1 = -1;
  65463. }
  65464. lexState = 'sign';
  65465. return;
  65466. case '.':
  65467. buffer = read();
  65468. lexState = 'decimalPointLeading';
  65469. return;
  65470. case '0':
  65471. buffer = read();
  65472. lexState = 'zero';
  65473. return;
  65474. case '1':
  65475. case '2':
  65476. case '3':
  65477. case '4':
  65478. case '5':
  65479. case '6':
  65480. case '7':
  65481. case '8':
  65482. case '9':
  65483. buffer = read();
  65484. lexState = 'decimalInteger';
  65485. return;
  65486. case 'I':
  65487. read();
  65488. literal('nfinity');
  65489. return newToken('numeric', Infinity);
  65490. case 'N':
  65491. read();
  65492. literal('aN');
  65493. return newToken('numeric', NaN);
  65494. case '"':
  65495. case "'":
  65496. doubleQuote = read() === '"';
  65497. buffer = '';
  65498. lexState = 'string';
  65499. return;
  65500. }
  65501. throw invalidChar(read());
  65502. },
  65503. identifierNameStartEscape() {
  65504. if (c$2 !== 'u') {
  65505. throw invalidChar(read());
  65506. }
  65507. read();
  65508. var u = unicodeEscape();
  65509. switch (u) {
  65510. case '$':
  65511. case '_':
  65512. break;
  65513. default:
  65514. if (!util.isIdStartChar(u)) {
  65515. throw invalidIdentifier();
  65516. }
  65517. break;
  65518. }
  65519. buffer += u;
  65520. lexState = 'identifierName';
  65521. },
  65522. identifierName() {
  65523. switch (c$2) {
  65524. case '$':
  65525. case '_':
  65526. case '\u200C':
  65527. case '\u200D':
  65528. buffer += read();
  65529. return;
  65530. case '\\':
  65531. read();
  65532. lexState = 'identifierNameEscape';
  65533. return;
  65534. }
  65535. if (util.isIdContinueChar(c$2)) {
  65536. buffer += read();
  65537. return;
  65538. }
  65539. return newToken('identifier', buffer);
  65540. },
  65541. identifierNameEscape() {
  65542. if (c$2 !== 'u') {
  65543. throw invalidChar(read());
  65544. }
  65545. read();
  65546. var u = unicodeEscape();
  65547. switch (u) {
  65548. case '$':
  65549. case '_':
  65550. case '\u200C':
  65551. case '\u200D':
  65552. break;
  65553. default:
  65554. if (!util.isIdContinueChar(u)) {
  65555. throw invalidIdentifier();
  65556. }
  65557. break;
  65558. }
  65559. buffer += u;
  65560. lexState = 'identifierName';
  65561. },
  65562. sign() {
  65563. switch (c$2) {
  65564. case '.':
  65565. buffer = read();
  65566. lexState = 'decimalPointLeading';
  65567. return;
  65568. case '0':
  65569. buffer = read();
  65570. lexState = 'zero';
  65571. return;
  65572. case '1':
  65573. case '2':
  65574. case '3':
  65575. case '4':
  65576. case '5':
  65577. case '6':
  65578. case '7':
  65579. case '8':
  65580. case '9':
  65581. buffer = read();
  65582. lexState = 'decimalInteger';
  65583. return;
  65584. case 'I':
  65585. read();
  65586. literal('nfinity');
  65587. return newToken('numeric', sign$1 * Infinity);
  65588. case 'N':
  65589. read();
  65590. literal('aN');
  65591. return newToken('numeric', NaN);
  65592. }
  65593. throw invalidChar(read());
  65594. },
  65595. zero() {
  65596. switch (c$2) {
  65597. case '.':
  65598. buffer += read();
  65599. lexState = 'decimalPoint';
  65600. return;
  65601. case 'e':
  65602. case 'E':
  65603. buffer += read();
  65604. lexState = 'decimalExponent';
  65605. return;
  65606. case 'x':
  65607. case 'X':
  65608. buffer += read();
  65609. lexState = 'hexadecimal';
  65610. return;
  65611. }
  65612. return newToken('numeric', sign$1 * 0);
  65613. },
  65614. decimalInteger() {
  65615. switch (c$2) {
  65616. case '.':
  65617. buffer += read();
  65618. lexState = 'decimalPoint';
  65619. return;
  65620. case 'e':
  65621. case 'E':
  65622. buffer += read();
  65623. lexState = 'decimalExponent';
  65624. return;
  65625. }
  65626. if (util.isDigit(c$2)) {
  65627. buffer += read();
  65628. return;
  65629. }
  65630. return newToken('numeric', sign$1 * Number(buffer));
  65631. },
  65632. decimalPointLeading() {
  65633. if (util.isDigit(c$2)) {
  65634. buffer += read();
  65635. lexState = 'decimalFraction';
  65636. return;
  65637. }
  65638. throw invalidChar(read());
  65639. },
  65640. decimalPoint() {
  65641. switch (c$2) {
  65642. case 'e':
  65643. case 'E':
  65644. buffer += read();
  65645. lexState = 'decimalExponent';
  65646. return;
  65647. }
  65648. if (util.isDigit(c$2)) {
  65649. buffer += read();
  65650. lexState = 'decimalFraction';
  65651. return;
  65652. }
  65653. return newToken('numeric', sign$1 * Number(buffer));
  65654. },
  65655. decimalFraction() {
  65656. switch (c$2) {
  65657. case 'e':
  65658. case 'E':
  65659. buffer += read();
  65660. lexState = 'decimalExponent';
  65661. return;
  65662. }
  65663. if (util.isDigit(c$2)) {
  65664. buffer += read();
  65665. return;
  65666. }
  65667. return newToken('numeric', sign$1 * Number(buffer));
  65668. },
  65669. decimalExponent() {
  65670. switch (c$2) {
  65671. case '+':
  65672. case '-':
  65673. buffer += read();
  65674. lexState = 'decimalExponentSign';
  65675. return;
  65676. }
  65677. if (util.isDigit(c$2)) {
  65678. buffer += read();
  65679. lexState = 'decimalExponentInteger';
  65680. return;
  65681. }
  65682. throw invalidChar(read());
  65683. },
  65684. decimalExponentSign() {
  65685. if (util.isDigit(c$2)) {
  65686. buffer += read();
  65687. lexState = 'decimalExponentInteger';
  65688. return;
  65689. }
  65690. throw invalidChar(read());
  65691. },
  65692. decimalExponentInteger() {
  65693. if (util.isDigit(c$2)) {
  65694. buffer += read();
  65695. return;
  65696. }
  65697. return newToken('numeric', sign$1 * Number(buffer));
  65698. },
  65699. hexadecimal() {
  65700. if (util.isHexDigit(c$2)) {
  65701. buffer += read();
  65702. lexState = 'hexadecimalInteger';
  65703. return;
  65704. }
  65705. throw invalidChar(read());
  65706. },
  65707. hexadecimalInteger() {
  65708. if (util.isHexDigit(c$2)) {
  65709. buffer += read();
  65710. return;
  65711. }
  65712. return newToken('numeric', sign$1 * Number(buffer));
  65713. },
  65714. string() {
  65715. switch (c$2) {
  65716. case '\\':
  65717. read();
  65718. buffer += escape$1();
  65719. return;
  65720. case '"':
  65721. if (doubleQuote) {
  65722. read();
  65723. return newToken('string', buffer);
  65724. }
  65725. buffer += read();
  65726. return;
  65727. case "'":
  65728. if (!doubleQuote) {
  65729. read();
  65730. return newToken('string', buffer);
  65731. }
  65732. buffer += read();
  65733. return;
  65734. case '\n':
  65735. case '\r':
  65736. throw invalidChar(read());
  65737. case '\u2028':
  65738. case '\u2029':
  65739. separatorChar(c$2);
  65740. break;
  65741. case undefined:
  65742. throw invalidChar(read());
  65743. }
  65744. buffer += read();
  65745. },
  65746. start() {
  65747. switch (c$2) {
  65748. case '{':
  65749. case '[':
  65750. return newToken('punctuator', read());
  65751. // This code is unreachable since the default lexState handles eof.
  65752. // case undefined:
  65753. // return newToken('eof')
  65754. }
  65755. lexState = 'value';
  65756. },
  65757. beforePropertyName() {
  65758. switch (c$2) {
  65759. case '$':
  65760. case '_':
  65761. buffer = read();
  65762. lexState = 'identifierName';
  65763. return;
  65764. case '\\':
  65765. read();
  65766. lexState = 'identifierNameStartEscape';
  65767. return;
  65768. case '}':
  65769. return newToken('punctuator', read());
  65770. case '"':
  65771. case "'":
  65772. doubleQuote = read() === '"';
  65773. lexState = 'string';
  65774. return;
  65775. }
  65776. if (util.isIdStartChar(c$2)) {
  65777. buffer += read();
  65778. lexState = 'identifierName';
  65779. return;
  65780. }
  65781. throw invalidChar(read());
  65782. },
  65783. afterPropertyName() {
  65784. if (c$2 === ':') {
  65785. return newToken('punctuator', read());
  65786. }
  65787. throw invalidChar(read());
  65788. },
  65789. beforePropertyValue() {
  65790. lexState = 'value';
  65791. },
  65792. afterPropertyValue() {
  65793. switch (c$2) {
  65794. case ',':
  65795. case '}':
  65796. return newToken('punctuator', read());
  65797. }
  65798. throw invalidChar(read());
  65799. },
  65800. beforeArrayValue() {
  65801. if (c$2 === ']') {
  65802. return newToken('punctuator', read());
  65803. }
  65804. lexState = 'value';
  65805. },
  65806. afterArrayValue() {
  65807. switch (c$2) {
  65808. case ',':
  65809. case ']':
  65810. return newToken('punctuator', read());
  65811. }
  65812. throw invalidChar(read());
  65813. },
  65814. end() {
  65815. // This code is unreachable since it's handled by the default lexState.
  65816. // if (c === undefined) {
  65817. // read()
  65818. // return newToken('eof')
  65819. // }
  65820. throw invalidChar(read());
  65821. }
  65822. };
  65823. function newToken(type, value) {
  65824. return {
  65825. type,
  65826. value,
  65827. line,
  65828. column
  65829. };
  65830. }
  65831. function literal(s) {
  65832. for (var _c of s) {
  65833. var p = peek();
  65834. if (p !== _c) {
  65835. throw invalidChar(read());
  65836. }
  65837. read();
  65838. }
  65839. }
  65840. function escape$1() {
  65841. var c = peek();
  65842. switch (c) {
  65843. case 'b':
  65844. read();
  65845. return '\b';
  65846. case 'f':
  65847. read();
  65848. return '\f';
  65849. case 'n':
  65850. read();
  65851. return '\n';
  65852. case 'r':
  65853. read();
  65854. return '\r';
  65855. case 't':
  65856. read();
  65857. return '\t';
  65858. case 'v':
  65859. read();
  65860. return '\v';
  65861. case '0':
  65862. read();
  65863. if (util.isDigit(peek())) {
  65864. throw invalidChar(read());
  65865. }
  65866. return '\0';
  65867. case 'x':
  65868. read();
  65869. return hexEscape();
  65870. case 'u':
  65871. read();
  65872. return unicodeEscape();
  65873. case '\n':
  65874. case '\u2028':
  65875. case '\u2029':
  65876. read();
  65877. return '';
  65878. case '\r':
  65879. read();
  65880. if (peek() === '\n') {
  65881. read();
  65882. }
  65883. return '';
  65884. case '1':
  65885. case '2':
  65886. case '3':
  65887. case '4':
  65888. case '5':
  65889. case '6':
  65890. case '7':
  65891. case '8':
  65892. case '9':
  65893. throw invalidChar(read());
  65894. case undefined:
  65895. throw invalidChar(read());
  65896. }
  65897. return read();
  65898. }
  65899. function hexEscape() {
  65900. var buffer = '';
  65901. var c = peek();
  65902. if (!util.isHexDigit(c)) {
  65903. throw invalidChar(read());
  65904. }
  65905. buffer += read();
  65906. c = peek();
  65907. if (!util.isHexDigit(c)) {
  65908. throw invalidChar(read());
  65909. }
  65910. buffer += read();
  65911. return String.fromCodePoint(parseInt(buffer, 16));
  65912. }
  65913. function unicodeEscape() {
  65914. var buffer = '';
  65915. var count = 4;
  65916. while (count-- > 0) {
  65917. var _c2 = peek();
  65918. if (!util.isHexDigit(_c2)) {
  65919. throw invalidChar(read());
  65920. }
  65921. buffer += read();
  65922. }
  65923. return String.fromCodePoint(parseInt(buffer, 16));
  65924. }
  65925. var parseStates = {
  65926. start() {
  65927. if (token.type === 'eof') {
  65928. throw invalidEOF();
  65929. }
  65930. push();
  65931. },
  65932. beforePropertyName() {
  65933. switch (token.type) {
  65934. case 'identifier':
  65935. case 'string':
  65936. key = token.value;
  65937. parseState = 'afterPropertyName';
  65938. return;
  65939. case 'punctuator':
  65940. // This code is unreachable since it's handled by the lexState.
  65941. // if (token.value !== '}') {
  65942. // throw invalidToken()
  65943. // }
  65944. pop();
  65945. return;
  65946. case 'eof':
  65947. throw invalidEOF();
  65948. }
  65949. // This code is unreachable since it's handled by the lexState.
  65950. // throw invalidToken()
  65951. },
  65952. afterPropertyName() {
  65953. // This code is unreachable since it's handled by the lexState.
  65954. // if (token.type !== 'punctuator' || token.value !== ':') {
  65955. // throw invalidToken()
  65956. // }
  65957. if (token.type === 'eof') {
  65958. throw invalidEOF();
  65959. }
  65960. parseState = 'beforePropertyValue';
  65961. },
  65962. beforePropertyValue() {
  65963. if (token.type === 'eof') {
  65964. throw invalidEOF();
  65965. }
  65966. push();
  65967. },
  65968. beforeArrayValue() {
  65969. if (token.type === 'eof') {
  65970. throw invalidEOF();
  65971. }
  65972. if (token.type === 'punctuator' && token.value === ']') {
  65973. pop();
  65974. return;
  65975. }
  65976. push();
  65977. },
  65978. afterPropertyValue() {
  65979. // This code is unreachable since it's handled by the lexState.
  65980. // if (token.type !== 'punctuator') {
  65981. // throw invalidToken()
  65982. // }
  65983. if (token.type === 'eof') {
  65984. throw invalidEOF();
  65985. }
  65986. switch (token.value) {
  65987. case ',':
  65988. parseState = 'beforePropertyName';
  65989. return;
  65990. case '}':
  65991. pop();
  65992. }
  65993. // This code is unreachable since it's handled by the lexState.
  65994. // throw invalidToken()
  65995. },
  65996. afterArrayValue() {
  65997. // This code is unreachable since it's handled by the lexState.
  65998. // if (token.type !== 'punctuator') {
  65999. // throw invalidToken()
  66000. // }
  66001. if (token.type === 'eof') {
  66002. throw invalidEOF();
  66003. }
  66004. switch (token.value) {
  66005. case ',':
  66006. parseState = 'beforeArrayValue';
  66007. return;
  66008. case ']':
  66009. pop();
  66010. }
  66011. // This code is unreachable since it's handled by the lexState.
  66012. // throw invalidToken()
  66013. },
  66014. end() {
  66015. // This code is unreachable since it's handled by the lexState.
  66016. // if (token.type !== 'eof') {
  66017. // throw invalidToken()
  66018. // }
  66019. }
  66020. };
  66021. function push() {
  66022. var value;
  66023. switch (token.type) {
  66024. case 'punctuator':
  66025. switch (token.value) {
  66026. case '{':
  66027. value = {};
  66028. break;
  66029. case '[':
  66030. value = [];
  66031. break;
  66032. }
  66033. break;
  66034. case 'null':
  66035. case 'boolean':
  66036. case 'numeric':
  66037. case 'string':
  66038. value = token.value;
  66039. break;
  66040. // This code is unreachable.
  66041. // default:
  66042. // throw invalidToken()
  66043. }
  66044. if (root === undefined) {
  66045. root = value;
  66046. } else {
  66047. var parent = stack$1[stack$1.length - 1];
  66048. if (Array.isArray(parent)) {
  66049. parent.push(value);
  66050. } else {
  66051. parent[key] = value;
  66052. }
  66053. }
  66054. if (value !== null && typeof value === 'object') {
  66055. stack$1.push(value);
  66056. if (Array.isArray(value)) {
  66057. parseState = 'beforeArrayValue';
  66058. } else {
  66059. parseState = 'beforePropertyName';
  66060. }
  66061. } else {
  66062. var current = stack$1[stack$1.length - 1];
  66063. if (current == null) {
  66064. parseState = 'end';
  66065. } else if (Array.isArray(current)) {
  66066. parseState = 'afterArrayValue';
  66067. } else {
  66068. parseState = 'afterPropertyValue';
  66069. }
  66070. }
  66071. }
  66072. function pop() {
  66073. stack$1.pop();
  66074. var current = stack$1[stack$1.length - 1];
  66075. if (current == null) {
  66076. parseState = 'end';
  66077. } else if (Array.isArray(current)) {
  66078. parseState = 'afterArrayValue';
  66079. } else {
  66080. parseState = 'afterPropertyValue';
  66081. }
  66082. }
  66083. // This code is unreachable.
  66084. // function invalidParseState () {
  66085. // return new Error(`JSON5: invalid parse state '${parseState}'`)
  66086. // }
  66087. // This code is unreachable.
  66088. // function invalidLexState (state) {
  66089. // return new Error(`JSON5: invalid lex state '${state}'`)
  66090. // }
  66091. function invalidChar(c) {
  66092. if (c === undefined) {
  66093. return syntaxError("JSON5: invalid end of input at ".concat(line, ":").concat(column));
  66094. }
  66095. return syntaxError("JSON5: invalid character '".concat(formatChar(c), "' at ").concat(line, ":").concat(column));
  66096. }
  66097. function invalidEOF() {
  66098. return syntaxError("JSON5: invalid end of input at ".concat(line, ":").concat(column));
  66099. }
  66100. // This code is unreachable.
  66101. // function invalidToken () {
  66102. // if (token.type === 'eof') {
  66103. // return syntaxError(`JSON5: invalid end of input at ${line}:${column}`)
  66104. // }
  66105. // const c = String.fromCodePoint(token.value.codePointAt(0))
  66106. // return syntaxError(`JSON5: invalid character '${formatChar(c)}' at ${line}:${column}`)
  66107. // }
  66108. function invalidIdentifier() {
  66109. column -= 5;
  66110. return syntaxError("JSON5: invalid identifier character at ".concat(line, ":").concat(column));
  66111. }
  66112. function separatorChar(c) {
  66113. console.warn("JSON5: '".concat(formatChar(c), "' in strings is not valid ECMAScript; consider escaping"));
  66114. }
  66115. function formatChar(c) {
  66116. var replacements = {
  66117. "'": "\\'",
  66118. '"': '\\"',
  66119. '\\': '\\\\',
  66120. '\b': '\\b',
  66121. '\f': '\\f',
  66122. '\n': '\\n',
  66123. '\r': '\\r',
  66124. '\t': '\\t',
  66125. '\v': '\\v',
  66126. '\0': '\\0',
  66127. '\u2028': '\\u2028',
  66128. '\u2029': '\\u2029'
  66129. };
  66130. if (replacements[c]) {
  66131. return replacements[c];
  66132. }
  66133. if (c < ' ') {
  66134. var hexString = c.charCodeAt(0).toString(16);
  66135. return '\\x' + ('00' + hexString).substring(hexString.length);
  66136. }
  66137. return c;
  66138. }
  66139. function syntaxError(message) {
  66140. var err = new SyntaxError(message);
  66141. err.lineNumber = line;
  66142. err.columnNumber = column;
  66143. return err;
  66144. }
  66145. var stringify = function stringify(value, replacer, space) {
  66146. var stack = [];
  66147. var indent = '';
  66148. var propertyList;
  66149. var replacerFunc;
  66150. var gap = '';
  66151. var quote;
  66152. if (replacer != null && typeof replacer === 'object' && !Array.isArray(replacer)) {
  66153. space = replacer.space;
  66154. quote = replacer.quote;
  66155. replacer = replacer.replacer;
  66156. }
  66157. if (typeof replacer === 'function') {
  66158. replacerFunc = replacer;
  66159. } else if (Array.isArray(replacer)) {
  66160. propertyList = [];
  66161. for (var v of replacer) {
  66162. var item = void 0;
  66163. if (typeof v === 'string') {
  66164. item = v;
  66165. } else if (typeof v === 'number' || v instanceof String || v instanceof Number) {
  66166. item = String(v);
  66167. }
  66168. if (item !== undefined && propertyList.indexOf(item) < 0) {
  66169. propertyList.push(item);
  66170. }
  66171. }
  66172. }
  66173. if (space instanceof Number) {
  66174. space = Number(space);
  66175. } else if (space instanceof String) {
  66176. space = String(space);
  66177. }
  66178. if (typeof space === 'number') {
  66179. if (space > 0) {
  66180. space = Math.min(10, Math.floor(space));
  66181. gap = ' '.substr(0, space);
  66182. }
  66183. } else if (typeof space === 'string') {
  66184. gap = space.substr(0, 10);
  66185. }
  66186. return serializeProperty('', {
  66187. '': value
  66188. });
  66189. function serializeProperty(key, holder) {
  66190. var value = holder[key];
  66191. if (value != null) {
  66192. if (typeof value.toJSON5 === 'function') {
  66193. value = value.toJSON5(key);
  66194. } else if (typeof value.toJSON === 'function') {
  66195. value = value.toJSON(key);
  66196. }
  66197. }
  66198. if (replacerFunc) {
  66199. value = replacerFunc.call(holder, key, value);
  66200. }
  66201. if (value instanceof Number) {
  66202. value = Number(value);
  66203. } else if (value instanceof String) {
  66204. value = String(value);
  66205. } else if (value instanceof Boolean) {
  66206. value = value.valueOf();
  66207. }
  66208. switch (value) {
  66209. case null:
  66210. return 'null';
  66211. case true:
  66212. return 'true';
  66213. case false:
  66214. return 'false';
  66215. }
  66216. if (typeof value === 'string') {
  66217. return quoteString(value, false);
  66218. }
  66219. if (typeof value === 'number') {
  66220. return String(value);
  66221. }
  66222. if (typeof value === 'object') {
  66223. return Array.isArray(value) ? serializeArray(value) : serializeObject(value);
  66224. }
  66225. return undefined;
  66226. }
  66227. function quoteString(value) {
  66228. var quotes = {
  66229. "'": 0.1,
  66230. '"': 0.2
  66231. };
  66232. var replacements = {
  66233. "'": "\\'",
  66234. '"': '\\"',
  66235. '\\': '\\\\',
  66236. '\b': '\\b',
  66237. '\f': '\\f',
  66238. '\n': '\\n',
  66239. '\r': '\\r',
  66240. '\t': '\\t',
  66241. '\v': '\\v',
  66242. '\0': '\\0',
  66243. '\u2028': '\\u2028',
  66244. '\u2029': '\\u2029'
  66245. };
  66246. var product = '';
  66247. for (var i = 0; i < value.length; i++) {
  66248. var _c3 = value[i];
  66249. switch (_c3) {
  66250. case "'":
  66251. case '"':
  66252. quotes[_c3]++;
  66253. product += _c3;
  66254. continue;
  66255. case '\0':
  66256. if (util.isDigit(value[i + 1])) {
  66257. product += '\\x00';
  66258. continue;
  66259. }
  66260. }
  66261. if (replacements[_c3]) {
  66262. product += replacements[_c3];
  66263. continue;
  66264. }
  66265. if (_c3 < ' ') {
  66266. var hexString = _c3.charCodeAt(0).toString(16);
  66267. product += '\\x' + ('00' + hexString).substring(hexString.length);
  66268. continue;
  66269. }
  66270. product += _c3;
  66271. }
  66272. var quoteChar = quote || Object.keys(quotes).reduce((a, b) => quotes[a] < quotes[b] ? a : b);
  66273. product = product.replace(new RegExp(quoteChar, 'g'), replacements[quoteChar]);
  66274. return quoteChar + product + quoteChar;
  66275. }
  66276. function serializeObject(value) {
  66277. if (stack.indexOf(value) >= 0) {
  66278. throw TypeError('Converting circular structure to JSON5');
  66279. }
  66280. stack.push(value);
  66281. var stepback = indent;
  66282. indent = indent + gap;
  66283. var keys = propertyList || Object.keys(value);
  66284. var partial = [];
  66285. for (var _key2 of keys) {
  66286. var propertyString = serializeProperty(_key2, value);
  66287. if (propertyString !== undefined) {
  66288. var member = serializeKey(_key2) + ':';
  66289. if (gap !== '') {
  66290. member += ' ';
  66291. }
  66292. member += propertyString;
  66293. partial.push(member);
  66294. }
  66295. }
  66296. var final;
  66297. if (partial.length === 0) {
  66298. final = '{}';
  66299. } else {
  66300. var properties;
  66301. if (gap === '') {
  66302. properties = partial.join(',');
  66303. final = '{' + properties + '}';
  66304. } else {
  66305. var separator = ',\n' + indent;
  66306. properties = partial.join(separator);
  66307. final = '{\n' + indent + properties + ',\n' + stepback + '}';
  66308. }
  66309. }
  66310. stack.pop();
  66311. indent = stepback;
  66312. return final;
  66313. }
  66314. function serializeKey(key) {
  66315. if (key.length === 0) {
  66316. return quoteString(key, true);
  66317. }
  66318. var firstChar = String.fromCodePoint(key.codePointAt(0));
  66319. if (!util.isIdStartChar(firstChar)) {
  66320. return quoteString(key, true);
  66321. }
  66322. for (var i = firstChar.length; i < key.length; i++) {
  66323. if (!util.isIdContinueChar(String.fromCodePoint(key.codePointAt(i)))) {
  66324. return quoteString(key, true);
  66325. }
  66326. }
  66327. return key;
  66328. }
  66329. function serializeArray(value) {
  66330. if (stack.indexOf(value) >= 0) {
  66331. throw TypeError('Converting circular structure to JSON5');
  66332. }
  66333. stack.push(value);
  66334. var stepback = indent;
  66335. indent = indent + gap;
  66336. var partial = [];
  66337. for (var i = 0; i < value.length; i++) {
  66338. var propertyString = serializeProperty(String(i), value);
  66339. partial.push(propertyString !== undefined ? propertyString : 'null');
  66340. }
  66341. var final;
  66342. if (partial.length === 0) {
  66343. final = '[]';
  66344. } else {
  66345. if (gap === '') {
  66346. var properties = partial.join(',');
  66347. final = '[' + properties + ']';
  66348. } else {
  66349. var separator = ',\n' + indent;
  66350. var _properties = partial.join(separator);
  66351. final = '[\n' + indent + _properties + ',\n' + stepback + ']';
  66352. }
  66353. }
  66354. stack.pop();
  66355. indent = stepback;
  66356. return final;
  66357. }
  66358. };
  66359. var JSON5$1 = {
  66360. parse: parse$4,
  66361. stringify
  66362. };
  66363. var lib = JSON5$1;
  66364. class Sidebar {
  66365. constructor(viewer) {
  66366. this.viewer = viewer;
  66367. this.measuringTool = viewer.measuringTool;
  66368. this.profileTool = viewer.profileTool;
  66369. this.volumeTool = viewer.volumeTool;
  66370. this.dom = $("#sidebar_root");
  66371. }
  66372. createToolIcon(icon, title, callback) {
  66373. var element = $("\n\t\t\t<img src=\"".concat(icon, "\"\n\t\t\t\tstyle=\"width: 32px; height: 32px\"\n\t\t\t\tclass=\"button-icon\"\n\t\t\t\tdata-i18n=\"").concat(title, "\" />\n\t\t"));
  66374. element.click(callback);
  66375. return element;
  66376. }
  66377. init() {
  66378. if (Potree.settings.editType == 'merge') {
  66379. this.initMergeBar();
  66380. this.initToolbar();
  66381. this.initScene();
  66382. this.initNavigation();
  66383. } else {
  66384. this.initAccordion();
  66385. this.initAppearance();
  66386. this.initToolbar();
  66387. this.initScene();
  66388. this.initNavigation();
  66389. this.initFilters();
  66390. //this.initClippingTool(); //因为修改了clipping,所以这项有bug不能使用
  66391. this.initSettings();
  66392. if (Potree.settings.editType != 'pano') {
  66393. this.initAlignment();
  66394. this.initClipModel();
  66395. this.initSiteModel();
  66396. this.initParitcle();
  66397. this.initClippingModel();
  66398. } else {
  66399. this.initPanosEdit();
  66400. }
  66401. }
  66402. $('#potree_version_number').html(Potree.version.major + "." + Potree.version.minor + Potree.version.suffix);
  66403. }
  66404. initAlignment() {
  66405. var Alignment = viewer.modules.Alignment;
  66406. var pannel = $('#alignment');
  66407. var buttons = pannel.find('[name="transform"] button');
  66408. var applyToPointcloud = (fun, value) => {
  66409. return function () {
  66410. var selected = $('#alignment li[name="selectPointCloud"] input:checked');
  66411. Array.from(selected).forEach(e => {
  66412. var pointcloud = viewer.scene.pointclouds.find(p => p.name == e.name);
  66413. fun(pointcloud, value);
  66414. });
  66415. };
  66416. };
  66417. //逆时针是正数
  66418. buttons.eq(0).on('click', applyToPointcloud(Alignment.rotate, 10));
  66419. //viewer.scene.pointclouds[0].rotation.z += THREE.Math.degToRad(10)
  66420. buttons.eq(1).on('click', applyToPointcloud(Alignment.rotate, 1));
  66421. buttons.eq(2).on('click', applyToPointcloud(Alignment.rotate, 0.1));
  66422. buttons.eq(3).on('click', applyToPointcloud(Alignment.rotate, -10));
  66423. buttons.eq(4).on('click', applyToPointcloud(Alignment.rotate, -1));
  66424. buttons.eq(5).on('click', applyToPointcloud(Alignment.rotate, -0.1));
  66425. buttons.eq(6).on('click', applyToPointcloud(Alignment.translate, new Vector3(-1, 0, 0)));
  66426. buttons.eq(7).on('click', applyToPointcloud(Alignment.translate, new Vector3(1, 0, 0)));
  66427. buttons.eq(8).on('click', applyToPointcloud(Alignment.translate, new Vector3(0, -1, 0)));
  66428. buttons.eq(9).on('click', applyToPointcloud(Alignment.translate, new Vector3(0, 1, 0)));
  66429. buttons.eq(10).on('click', applyToPointcloud(Alignment.translate, new Vector3(0, 0, -1)));
  66430. buttons.eq(11).on('click', applyToPointcloud(Alignment.translate, new Vector3(0, 0, 1)));
  66431. pannel.find('#startAlignment').on('click', () => {
  66432. Alignment.enter();
  66433. });
  66434. pannel.find('#exitAlignment').on('click', () => {
  66435. Alignment.save();
  66436. Alignment.leave();
  66437. });
  66438. pannel.find('#rotTool').on('click', () => {
  66439. Alignment.switchHandle('rotate');
  66440. });
  66441. pannel.find('#moveTool').on('click', () => {
  66442. Alignment.switchHandle('translate');
  66443. });
  66444. }
  66445. initMergeBar() {
  66446. //多元融合模块
  66447. var pannel = $('#mergeModel');
  66448. var buttons = pannel.find('button');
  66449. var MergeEditor = viewer.modules.MergeEditor;
  66450. var loading = false;
  66451. pannel.find('ul[name="model"] li button').on('click', e => {
  66452. if (loading) return console.log('还在加载', loading);
  66453. var $elem = $(e.target);
  66454. var parent = $elem.parent();
  66455. var name = parent.attr('name');
  66456. if ($elem.attr('name') == 'select') {
  66457. return Potree.selectModel(name);
  66458. }
  66459. if ($elem.text() == '添加') {
  66460. var startTime = Date.now();
  66461. Potree.addModel(name, () => {
  66462. loading = false;
  66463. //$elem.text('删除')
  66464. var now = Date.now();
  66465. console.log('加载完毕', name, '用时', (now - startTime) / 1000, 's');
  66466. });
  66467. loading = name;
  66468. } else {
  66469. Potree.removeModel(name);
  66470. $elem.text('添加');
  66471. }
  66472. });
  66473. pannel.find('li button[name="splitScreen"]').on('click', e => {
  66474. var $elem = $(e.target);
  66475. if ($elem.text() == '分屏') {
  66476. $elem.text('恢复');
  66477. MergeEditor.enterSplit();
  66478. } else {
  66479. $elem.text('分屏');
  66480. MergeEditor.leaveSplit();
  66481. }
  66482. });
  66483. var addingTag = false;
  66484. pannel.find('li button[name="tag"]').on('click', e => {
  66485. var $elem = $(e.target);
  66486. viewer.tagTool.startInsertion();
  66487. });
  66488. }
  66489. initClippingModel() {
  66490. //实时裁剪
  66491. /* 总共两种box : 可见和不可见(都是并集)
  66492. 当有可见box时,需要在任一可见box内才可见
  66493. 当有不可见box时,不在所有不可见box内才可见 */
  66494. var clipping = viewer.modules.clipping;
  66495. var pannel = $('#clipping');
  66496. var addBtn = pannel.find('[name="operation"] button[name="add"] ');
  66497. var switchBtn = pannel.find('[name="operation"] button[name="switchView"] ');
  66498. var enterBtn = pannel.find(' button[name="enter"] ');
  66499. var exitBtn = pannel.find(' button[name="exit"] ');
  66500. var list = pannel.find('[name="list"] ul ');
  66501. enterBtn.on('click', () => {
  66502. clipping.enter();
  66503. pannel.find('li[name=operation]').css('display', 'block');
  66504. pannel.find('li[name=list]').css('display', 'block');
  66505. });
  66506. exitBtn.on('click', () => {
  66507. clipping.leave();
  66508. pannel.find('li[name=operation]').css('display', 'none');
  66509. pannel.find('li[name=list]').css('display', 'none');
  66510. });
  66511. switchBtn.on('click', () => {
  66512. clipping.switchView(clipping.activeViewName == 'top' ? 'mainView' : 'top');
  66513. });
  66514. pannel.find('[name="operation"] button[name="translation"] ').on('click', () => {
  66515. clipping.setTranMode('translation');
  66516. });
  66517. pannel.find('[name="operation"] button[name="rotation"] ').on('click', () => {
  66518. clipping.setTranMode('rotation');
  66519. });
  66520. pannel.find('[name="operation"] button[name="scale"] ').on('click', () => {
  66521. clipping.setTranMode('scale');
  66522. });
  66523. addBtn.on('click', () => {
  66524. var volumeBox = this.volumeTool.startInsertion({
  66525. clip: true,
  66526. clipTask: Potree.ClipTask.SHOW_OUTSIDE
  66527. });
  66528. var li = $("<li><button name='changeTask'>不可见</button><button name='chose'>选择</button><button name='delete'>删除</button></li>");
  66529. list.append(li);
  66530. li.find('button[name=changeTask]').on('click', e => {
  66531. if (e.target.innerText == '不可见') {
  66532. volumeBox.clipTask = Potree.ClipTask.SHOW_INSIDE;
  66533. e.target.innerText = '可见';
  66534. } else {
  66535. volumeBox.clipTask = Potree.ClipTask.SHOW_OUTSIDE;
  66536. e.target.innerText = '不可见';
  66537. }
  66538. volumeBox.update();
  66539. });
  66540. li.find('button[name=chose]').on('click', e => {
  66541. viewer.transformObject(volumeBox); //viewer.inputHandler.toggleSelection(volumeBox)
  66542. });
  66543. li.find('button[name=delete]').on('click', e => {
  66544. li.remove();
  66545. viewer.scene.removeVolume(volumeBox);
  66546. });
  66547. });
  66548. pannel.find('button[name=save]').on('click', e => {
  66549. var data = clipping.saveClipData();
  66550. });
  66551. }
  66552. addAlignmentButton(pointcloud) {
  66553. var pannel = $('#alignment li[name="selectPointCloud"]>div');
  66554. var option = $(" <input name=\"".concat(pointcloud.name, "\" class=\"editCheckbox\" type=\"checkbox\" >\n \n <label for=\"showingLabels\">").concat(pointcloud.name, "</label>"));
  66555. pannel.append(option);
  66556. /* option.find("input").on('change',function(){
  66557. })
  66558. */
  66559. }
  66560. initClipModel() {
  66561. var Clip = viewer.modules.Clip;
  66562. var pannel = $('#clipModel');
  66563. var buttons = pannel.find('button');
  66564. buttons.eq(0).on('click', Clip.enter.bind(Clip));
  66565. buttons.eq(1).on('click', Clip.download.bind(Clip));
  66566. buttons.eq(2).on('click', Clip.leave.bind(Clip));
  66567. }
  66568. initSiteModel() {
  66569. var SiteModel = viewer.modules.SiteModel;
  66570. var pannel = $('#siteModel');
  66571. pannel.find('button[name="start"] ').on('click', SiteModel.enter.bind(SiteModel));
  66572. pannel.find('button[name="exit"] ').on('click', SiteModel.leave.bind(SiteModel));
  66573. pannel.find('button[name="building"] ').on('click', SiteModel.startInsertion.bind(SiteModel, 'building'));
  66574. pannel.find('button[name="floor"] ').on('click', () => {
  66575. SiteModel.addFloor(SiteModel.buildings[0], 'top');
  66576. });
  66577. pannel.find('button[name="room"] ').on('click', () => {
  66578. SiteModel.startInsertion('room', SiteModel.buildings[0].buildChildren[0]);
  66579. });
  66580. pannel.find('button[name="digHole"] ').on('click', () => {
  66581. SiteModel.selected && SiteModel.startInsertion('hole', SiteModel.selected);
  66582. });
  66583. pannel.find('button[name="selectBuilding"] ').on('click', () => {
  66584. SiteModel.selectEntity(SiteModel.buildings[0]);
  66585. });
  66586. pannel.find('button[name="selectFloor"] ').on('click', () => {
  66587. SiteModel.selectEntity(SiteModel.buildings[0].buildChildren[0]);
  66588. });
  66589. pannel.find('button[name="selectRoom"] ').on('click', () => {
  66590. SiteModel.selectEntity(SiteModel.buildings[0].buildChildren[0].buildChildren[0]);
  66591. });
  66592. pannel.find('button[name="removeFirstBuilding"] ').on('click', () => {
  66593. SiteModel.removeEntity(SiteModel.buildings[0]);
  66594. });
  66595. pannel.find('button[name="removeFirstFloor"] ').on('click', () => {
  66596. SiteModel.removeEntity(SiteModel.buildings[0].buildChildren[0]);
  66597. });
  66598. pannel.find('button[name="removeFirstRoom"] ').on('click', () => {
  66599. SiteModel.removeEntity(SiteModel.buildings[0].buildChildren[0].buildChildren[0]);
  66600. });
  66601. pannel.find('button[name="removeFirstHole"] ').on('click', () => {
  66602. SiteModel.selected.removeHole(SiteModel.selected.holes[0]);
  66603. });
  66604. pannel.find('button[name="removeFirstMarker"] ').on('click', () => {
  66605. //SiteModel.removeMarker(SiteModel.selected.markers[0])
  66606. SiteModel.selected.removeMarker(0);
  66607. });
  66608. }
  66609. initParitcle() {
  66610. var ParticleEditor = viewer.modules.ParticleEditor;
  66611. var pannel = $('#particle');
  66612. pannel.find('button[name="addFire"] ').on('click', () => {
  66613. ParticleEditor.startInsertion('fire+smoke');
  66614. });
  66615. pannel.find('button[name="addExplode"] ').on('click', () => {
  66616. ParticleEditor.startInsertion('explode');
  66617. });
  66618. }
  66619. initPanosEdit() {
  66620. var PanoEditor = viewer.modules.PanoEditor;
  66621. var Alignment = viewer.modules.Alignment;
  66622. var pannel = $('#panos');
  66623. pannel.find('button[name="save"] ').on('click', () => {
  66624. console.log('saveData', PanoEditor.exportSavingData());
  66625. });
  66626. pannel.find('button[name="translate"] ').on('click', () => {
  66627. Alignment.switchHandle('translate');
  66628. });
  66629. pannel.find('button[name="rotate"] ').on('click', () => {
  66630. Alignment.switchHandle('rotate');
  66631. });
  66632. pannel.find('button[name="topView"] ').on('click', () => {
  66633. PanoEditor.switchView('top');
  66634. });
  66635. pannel.find('button[name="sideView"] ').on('click', () => {
  66636. PanoEditor.switchView('right');
  66637. });
  66638. pannel.find('button[name="3DView"] ').on('click', () => {
  66639. PanoEditor.switchView('mainView');
  66640. });
  66641. pannel.find('button[name="addLink"] ').on('click', () => {
  66642. PanoEditor.setLinkOperateState('addLink', true);
  66643. });
  66644. pannel.find('button[name="removeLink"] ').on('click', () => {
  66645. PanoEditor.setLinkOperateState('removeLink', true);
  66646. });
  66647. pannel.find('button[name="getCloser"] ').on('click', () => {
  66648. PanoEditor.setZoomInState(true);
  66649. });
  66650. }
  66651. initToolbar() {
  66652. // ANGLE
  66653. var elToolbar = $('#tools');
  66654. elToolbar.append(this.createToolIcon(Potree.resourcePath + '/icons/angle.png', '[title]tt.angle_measurement', () => {
  66655. $('#menu_measurements').next().slideDown();
  66656. var measurement = this.measuringTool.startInsertion({
  66657. showDistances: false,
  66658. showAngles: true,
  66659. showArea: false,
  66660. closed: true,
  66661. maxMarkers: 3,
  66662. minMarkers: 3,
  66663. measureType: 'Angle'
  66664. });
  66665. var measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  66666. var jsonNode = measurementsRoot.children.find(child => child.data.uuid === measurement.uuid);
  66667. $.jstree.reference(jsonNode.id).deselect_all();
  66668. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  66669. }));
  66670. // POINT
  66671. elToolbar.append(this.createToolIcon(Potree.resourcePath + '/icons/point.svg', '[title]tt.point_measurement', () => {
  66672. $('#menu_measurements').next().slideDown();
  66673. var measurement = this.measuringTool.startInsertion({
  66674. showDistances: false,
  66675. showAngles: false,
  66676. showCoordinates: true,
  66677. showEdges: false,
  66678. showArea: false,
  66679. closed: true,
  66680. maxMarkers: 1,
  66681. minMarkers: 1,
  66682. measureType: 'Point'
  66683. });
  66684. var measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  66685. var jsonNode = measurementsRoot.children.find(child => child.data.uuid === measurement.uuid);
  66686. $.jstree.reference(jsonNode.id).deselect_all();
  66687. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  66688. }));
  66689. // DISTANCE
  66690. elToolbar.append(this.createToolIcon(Potree.resourcePath + '/icons/distance.svg', '[title]tt.distance_measurement', () => {
  66691. $('#menu_measurements').next().slideDown();
  66692. var measurement = this.measuringTool.startInsertion({
  66693. showDistances: true,
  66694. showArea: false,
  66695. closed: false,
  66696. minMarkers: 2,
  66697. maxMarkers: 2,
  66698. measureType: 'Distance'
  66699. });
  66700. var measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  66701. var jsonNode = measurementsRoot.children.find(child => child.data.uuid === measurement.uuid);
  66702. $.jstree.reference(jsonNode.id).deselect_all();
  66703. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  66704. }));
  66705. // DISTANCE2
  66706. elToolbar.append(this.createToolIcon(Potree.resourcePath + '/icons/distance.svg', '[title]MulDistance', () => {
  66707. $('#menu_measurements').next().slideDown();
  66708. var measurement = this.measuringTool.startInsertion({
  66709. showDistances: true,
  66710. showArea: false,
  66711. closed: false,
  66712. minMarkers: 2,
  66713. measureType: 'MulDistance'
  66714. });
  66715. var measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  66716. var jsonNode = measurementsRoot.children.find(child => child.data.uuid === measurement.uuid);
  66717. $.jstree.reference(jsonNode.id).deselect_all();
  66718. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  66719. }));
  66720. // DISTANCE2
  66721. elToolbar.append(this.createToolIcon(Potree.resourcePath + '/icons/distance.svg', '[title]MulDistance Ring', () => {
  66722. $('#menu_measurements').next().slideDown();
  66723. var measurement = this.measuringTool.startInsertion({
  66724. //showArea: false,
  66725. closed: true,
  66726. minMarkers: 3,
  66727. measureType: 'MulDistance Ring'
  66728. });
  66729. var measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  66730. var jsonNode = measurementsRoot.children.find(child => child.data.uuid === measurement.uuid);
  66731. $.jstree.reference(jsonNode.id).deselect_all();
  66732. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  66733. }));
  66734. elToolbar.append(this.createToolIcon(Potree.resourcePath + '/icons/distance.svg', '[title]Ver MulDistance', () => {
  66735. $('#menu_measurements').next().slideDown();
  66736. var measurement = this.measuringTool.startInsertion({
  66737. measureType: 'Ver MulDistance'
  66738. });
  66739. var measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  66740. var jsonNode = measurementsRoot.children.find(child => child.data.uuid === measurement.uuid);
  66741. $.jstree.reference(jsonNode.id).deselect_all();
  66742. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  66743. }));
  66744. elToolbar.append(this.createToolIcon(Potree.resourcePath + '/icons/distance.svg', '[title]Hor MulDistance', () => {
  66745. $('#menu_measurements').next().slideDown();
  66746. var measurement = this.measuringTool.startInsertion({
  66747. measureType: 'Hor MulDistance'
  66748. });
  66749. var measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  66750. var jsonNode = measurementsRoot.children.find(child => child.data.uuid === measurement.uuid);
  66751. $.jstree.reference(jsonNode.id).deselect_all();
  66752. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  66753. }));
  66754. // HEIGHT
  66755. elToolbar.append(this.createToolIcon(Potree.resourcePath + '/icons/height.svg', '[title]tt.height_measurement', () => {
  66756. $('#menu_measurements').next().slideDown();
  66757. var measurement = this.measuringTool.startInsertion({
  66758. showDistances: true,
  66759. //false,
  66760. showHeight: true,
  66761. showArea: false,
  66762. closed: false,
  66763. maxMarkers: 2,
  66764. minMarkers: 2,
  66765. //showGuideLine: true: true
  66766. measureType: 'Ver Distance'
  66767. });
  66768. var measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  66769. var jsonNode = measurementsRoot.children.find(child => child.data.uuid === measurement.uuid);
  66770. $.jstree.reference(jsonNode.id).deselect_all();
  66771. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  66772. }));
  66773. // CIRCLE
  66774. elToolbar.append(this.createToolIcon(Potree.resourcePath + '/icons/circle.svg', '[title]tt.circle_measurement', () => {
  66775. $('#menu_measurements').next().slideDown();
  66776. var measurement = this.measuringTool.startInsertion({
  66777. showDistances: false,
  66778. showHeight: false,
  66779. showArea: false,
  66780. showCircle: true,
  66781. showEdges: false,
  66782. closed: false,
  66783. maxMarkers: 3,
  66784. minMarkers: 3,
  66785. measureType: 'Circle'
  66786. });
  66787. var measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  66788. var jsonNode = measurementsRoot.children.find(child => child.data.uuid === measurement.uuid);
  66789. $.jstree.reference(jsonNode.id).deselect_all();
  66790. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  66791. }));
  66792. // AZIMUTH
  66793. elToolbar.append(this.createToolIcon(Potree.resourcePath + '/icons/azimuth.svg', 'Azimuth', () => {
  66794. $('#menu_measurements').next().slideDown();
  66795. var measurement = this.measuringTool.startInsertion({
  66796. showDistances: false,
  66797. showHeight: false,
  66798. showArea: false,
  66799. showCircle: false,
  66800. showEdges: false,
  66801. showAzimuth: true,
  66802. closed: false,
  66803. maxMarkers: 2,
  66804. minMarkers: 2,
  66805. measureType: 'Azimuth'
  66806. });
  66807. var measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  66808. var jsonNode = measurementsRoot.children.find(child => child.data.uuid === measurement.uuid);
  66809. $.jstree.reference(jsonNode.id).deselect_all();
  66810. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  66811. }));
  66812. // AREA
  66813. elToolbar.append(this.createToolIcon(Potree.resourcePath + '/icons/area.svg', '[title]tt.area_measurement', () => {
  66814. $('#menu_measurements').next().slideDown();
  66815. var measurement = this.measuringTool.startInsertion({
  66816. showDistances: true,
  66817. showArea: true,
  66818. closed: true,
  66819. minMarkers: 3,
  66820. //showGuideLine: true: true,
  66821. measureType: 'Area'
  66822. });
  66823. var measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  66824. var jsonNode = measurementsRoot.children.find(child => child.data.uuid === measurement.uuid);
  66825. $.jstree.reference(jsonNode.id).deselect_all();
  66826. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  66827. }));
  66828. //Hor AREA
  66829. elToolbar.append(this.createToolIcon(Potree.resourcePath + '/icons/area.svg', '[title]Hor Area', () => {
  66830. $('#menu_measurements').next().slideDown();
  66831. var measurement = this.measuringTool.startInsertion({
  66832. showDistances: true,
  66833. showArea: true,
  66834. closed: true,
  66835. minMarkers: 3,
  66836. measureType: 'Hor Area'
  66837. });
  66838. var measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  66839. var jsonNode = measurementsRoot.children.find(child => child.data.uuid === measurement.uuid);
  66840. $.jstree.reference(jsonNode.id).deselect_all();
  66841. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  66842. }));
  66843. // Ver Area
  66844. elToolbar.append(this.createToolIcon(Potree.resourcePath + '/icons/area.svg', '[title]Ver Area', () => {
  66845. $('#menu_measurements').next().slideDown();
  66846. var measurement = this.measuringTool.startInsertion({
  66847. showDistances: true,
  66848. showArea: true,
  66849. closed: true,
  66850. minMarkers: 3,
  66851. measureType: 'Ver Area'
  66852. });
  66853. var measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  66854. var jsonNode = measurementsRoot.children.find(child => child.data.uuid === measurement.uuid);
  66855. $.jstree.reference(jsonNode.id).deselect_all();
  66856. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  66857. }));
  66858. // rect area freedom direction
  66859. elToolbar.append(this.createToolIcon(Potree.resourcePath + '/icons/area.svg', '[title]area_freedom_rect', () => {
  66860. $('#menu_measurements').next().slideDown();
  66861. var measurement = this.measuringTool.startInsertion({
  66862. showDistances: true,
  66863. showArea: true,
  66864. closed: true,
  66865. minMarkers: 4,
  66866. maxMarkers: 4,
  66867. //showGuideLine: true: true,
  66868. isRect: true,
  66869. measureType: 'Rect Area'
  66870. });
  66871. var measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  66872. var jsonNode = measurementsRoot.children.find(child => child.data.uuid === measurement.uuid);
  66873. $.jstree.reference(jsonNode.id).deselect_all();
  66874. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  66875. }));
  66876. // rect area horizontal
  66877. elToolbar.append(this.createToolIcon(Potree.resourcePath + '/icons/area.svg', '[title]area_horizontal_rect', () => {
  66878. $('#menu_measurements').next().slideDown();
  66879. var measurement = this.measuringTool.startInsertion({
  66880. showDistances: true,
  66881. showArea: true,
  66882. closed: true,
  66883. minMarkers: 4,
  66884. maxMarkers: 4,
  66885. //showGuideLine: true: true,
  66886. isRect: true,
  66887. faceDirection: "horizontal",
  66888. measureType: 'Hor Rect Area'
  66889. });
  66890. var measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  66891. var jsonNode = measurementsRoot.children.find(child => child.data.uuid === measurement.uuid);
  66892. $.jstree.reference(jsonNode.id).deselect_all();
  66893. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  66894. }));
  66895. // rect area vertical
  66896. elToolbar.append(this.createToolIcon(Potree.resourcePath + '/icons/area.svg', '[title]area_vertical_rect', () => {
  66897. $('#menu_measurements').next().slideDown();
  66898. var measurement = this.measuringTool.startInsertion({
  66899. showDistances: true,
  66900. showArea: true,
  66901. closed: true,
  66902. minMarkers: 4,
  66903. maxMarkers: 4,
  66904. //showGuideLine: true: true,
  66905. isRect: true,
  66906. faceDirection: "vertical",
  66907. measureType: 'Ver Rect Area'
  66908. });
  66909. var measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  66910. var jsonNode = measurementsRoot.children.find(child => child.data.uuid === measurement.uuid);
  66911. $.jstree.reference(jsonNode.id).deselect_all();
  66912. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  66913. }));
  66914. // AREA
  66915. elToolbar.append(this.createToolIcon(Potree.resourcePath + '/icons/area.svg', '[title]prism', () => {
  66916. $('#menu_measurements').next().slideDown();
  66917. var measurement = this.measuringTool.startInsertion({
  66918. measureType: 'MulDistance Ring',
  66919. unit: 'metric'
  66920. });
  66921. var measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  66922. var jsonNode = measurementsRoot.children.find(child => child.data.uuid === measurement.uuid);
  66923. $.jstree.reference(jsonNode.id).deselect_all();
  66924. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  66925. }));
  66926. // VOLUME
  66927. elToolbar.append(this.createToolIcon(Potree.resourcePath + '/icons/volume.svg', '[title]tt.volume_measurement', () => {
  66928. var volume = this.volumeTool.startInsertion();
  66929. var measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  66930. var jsonNode = measurementsRoot.children.find(child => child.data.uuid === volume.uuid);
  66931. $.jstree.reference(jsonNode.id).deselect_all();
  66932. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  66933. }));
  66934. // SPHERE VOLUME
  66935. elToolbar.append(this.createToolIcon(Potree.resourcePath + '/icons/sphere_distances.svg', '[title]tt.volume_measurement', () => {
  66936. var volume = this.volumeTool.startInsertion({
  66937. type: SphereVolume$2
  66938. });
  66939. var measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  66940. var jsonNode = measurementsRoot.children.find(child => child.data.uuid === volume.uuid);
  66941. $.jstree.reference(jsonNode.id).deselect_all();
  66942. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  66943. }));
  66944. // PROFILE
  66945. elToolbar.append(this.createToolIcon(Potree.resourcePath + '/icons/profile.svg', '[title]tt.height_profile', () => {
  66946. $('#menu_measurements').next().slideDown();
  66947. ;
  66948. var profile = this.profileTool.startInsertion();
  66949. var measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  66950. var jsonNode = measurementsRoot.children.find(child => child.data.uuid === profile.uuid);
  66951. $.jstree.reference(jsonNode.id).deselect_all();
  66952. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  66953. }));
  66954. // ANNOTATION
  66955. elToolbar.append(this.createToolIcon(Potree.resourcePath + '/icons/annotation.svg', '[title]tt.annotation', () => {
  66956. $('#menu_measurements').next().slideDown();
  66957. ;
  66958. var annotation = this.viewer.annotationTool.startInsertion();
  66959. var annotationsRoot = $("#jstree_scene").jstree().get_json("annotations");
  66960. var jsonNode = annotationsRoot.children.find(child => child.data.uuid === annotation.uuid);
  66961. $.jstree.reference(jsonNode.id).deselect_all();
  66962. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  66963. }));
  66964. // REMOVE ALL
  66965. elToolbar.append(this.createToolIcon(Potree.resourcePath + '/icons/reset_tools.svg', '[title]tt.remove_all_measurement', () => {
  66966. this.viewer.scene.removeAllMeasurements();
  66967. }));
  66968. {
  66969. // SHOW / HIDE Measurements
  66970. var elShow = $("#measurement_options_show");
  66971. elShow.selectgroup({
  66972. title: "Show/Hide labels"
  66973. });
  66974. elShow.find("input").click(e => {
  66975. var show = e.target.value === "SHOW";
  66976. this.measuringTool.showLabels = show;
  66977. });
  66978. var currentShow = this.measuringTool.showLabels ? "SHOW" : "HIDE";
  66979. elShow.find("input[value=".concat(currentShow, "]")).trigger("click");
  66980. }
  66981. }
  66982. initScene() {
  66983. var elScene = $("#menu_scene");
  66984. var elObjects = elScene.next().find("#scene_objects");
  66985. var elProperties = elScene.next().find("#scene_object_properties");
  66986. {
  66987. var elExport = elScene.next().find("#scene_export");
  66988. var geoJSONIcon = "".concat(Potree.resourcePath, "/icons/file_geojson.svg");
  66989. var dxfIcon = "".concat(Potree.resourcePath, "/icons/file_dxf.svg");
  66990. var potreeIcon = "".concat(Potree.resourcePath, "/icons/file_potree.svg");
  66991. elExport.append("\n\t\t\t\tExport: <br>\n\t\t\t\t<a href=\"#\" download=\"measure.json\"><img name=\"geojson_export_button\" src=\"".concat(geoJSONIcon, "\" class=\"button-icon\" style=\"height: 24px\" /></a>\n\t\t\t\t<a href=\"#\" download=\"measure.dxf\"><img name=\"dxf_export_button\" src=\"").concat(dxfIcon, "\" class=\"button-icon\" style=\"height: 24px\" /></a>\n\t\t\t\t<a href=\"#\" download=\"potree.json5\"><img name=\"potree_export_button\" src=\"").concat(potreeIcon, "\" class=\"button-icon\" style=\"height: 24px\" /></a>\n\t\t\t"));
  66992. var elDownloadJSON = elExport.find("img[name=geojson_export_button]").parent();
  66993. elDownloadJSON.click(event => {
  66994. var scene = this.viewer.scene;
  66995. var measurements = [...scene.measurements, ...scene.profiles, ...scene.volumes];
  66996. if (measurements.length > 0) {
  66997. var geoJson = GeoJSONExporter.toString(measurements);
  66998. var url = window.URL.createObjectURL(new Blob([geoJson], {
  66999. type: 'data:application/octet-stream'
  67000. }));
  67001. elDownloadJSON.attr('href', url);
  67002. } else {
  67003. this.viewer.postError("nothing to export");
  67004. event.preventDefault();
  67005. }
  67006. });
  67007. var elDownloadDXF = elExport.find("img[name=dxf_export_button]").parent();
  67008. elDownloadDXF.click(event => {
  67009. var scene = this.viewer.scene;
  67010. var measurements = [...scene.measurements, ...scene.profiles, ...scene.volumes];
  67011. if (measurements.length > 0) {
  67012. var dxf = DXFExporter.toString(measurements);
  67013. var url = window.URL.createObjectURL(new Blob([dxf], {
  67014. type: 'data:application/octet-stream'
  67015. }));
  67016. elDownloadDXF.attr('href', url);
  67017. } else {
  67018. this.viewer.postError("no measurements to export");
  67019. event.preventDefault();
  67020. }
  67021. });
  67022. var elDownloadPotree = elExport.find("img[name=potree_export_button]").parent();
  67023. elDownloadPotree.click(event => {
  67024. var data = Potree.saveProject(this.viewer);
  67025. var dataString = lib.stringify(data, null, "\t");
  67026. var url = window.URL.createObjectURL(new Blob([dataString], {
  67027. type: 'data:application/octet-stream'
  67028. }));
  67029. elDownloadPotree.attr('href', url);
  67030. });
  67031. }
  67032. var propertiesPanel = new PropertiesPanel(elProperties, this.viewer);
  67033. propertiesPanel.setScene(this.viewer.scene);
  67034. localStorage.removeItem('jstree');
  67035. var tree = $("<div id=\"jstree_scene\"></div>");
  67036. elObjects.append(tree);
  67037. tree.jstree({
  67038. 'plugins': ["checkbox", "state"],
  67039. 'core': {
  67040. "dblclick_toggle": false,
  67041. "state": {
  67042. "checked": true
  67043. },
  67044. 'check_callback': true,
  67045. "expand_selected_onload": true
  67046. },
  67047. "checkbox": {
  67048. "keep_selected_style": true,
  67049. "three_state": false,
  67050. "whole_node": false,
  67051. "tie_selection": false
  67052. }
  67053. });
  67054. var createNode = (parent, text, icon, object) => {
  67055. var nodeID = tree.jstree('create_node', parent, {
  67056. "text": text,
  67057. "icon": icon,
  67058. "data": object
  67059. }, "last", false, false);
  67060. if (object.visible) {
  67061. tree.jstree('check_node', nodeID);
  67062. } else {
  67063. tree.jstree('uncheck_node', nodeID);
  67064. }
  67065. return nodeID;
  67066. };
  67067. var pcID = tree.jstree('create_node', "#", {
  67068. "text": "<b>Point Clouds</b>",
  67069. "id": "pointclouds"
  67070. }, "last", false, false);
  67071. var measurementID = tree.jstree('create_node', "#", {
  67072. "text": "<b>Measurements</b>",
  67073. "id": "measurements"
  67074. }, "last", false, false);
  67075. var annotationsID = tree.jstree('create_node', "#", {
  67076. "text": "<b>Annotations</b>",
  67077. "id": "annotations"
  67078. }, "last", false, false);
  67079. var otherID = tree.jstree('create_node', "#", {
  67080. "text": "<b>Other</b>",
  67081. "id": "other"
  67082. }, "last", false, false);
  67083. var vectorsID = tree.jstree('create_node', "#", {
  67084. "text": "<b>Vectors</b>",
  67085. "id": "vectors"
  67086. }, "last", false, false);
  67087. var imagesID = tree.jstree('create_node', "#", {
  67088. "text": "<b> Images</b>",
  67089. "id": "images"
  67090. }, "last", false, false);
  67091. tree.jstree("check_node", pcID);
  67092. tree.jstree("check_node", measurementID);
  67093. tree.jstree("check_node", annotationsID);
  67094. tree.jstree("check_node", otherID);
  67095. tree.jstree("check_node", vectorsID);
  67096. tree.jstree("check_node", imagesID);
  67097. tree.on('create_node.jstree', (e, data) => {
  67098. tree.jstree("open_all");
  67099. });
  67100. tree.on("select_node.jstree", (e, data) => {
  67101. var object = data.node.data;
  67102. propertiesPanel.set(object);
  67103. this.viewer.inputHandler.deselectAll();
  67104. if (object instanceof Volume$1) {
  67105. this.viewer.inputHandler.toggleSelection(object);
  67106. }
  67107. $(this.viewer.renderer.domElement).focus();
  67108. });
  67109. tree.on("deselect_node.jstree", (e, data) => {
  67110. propertiesPanel.set(null);
  67111. });
  67112. tree.on("delete_node.jstree", (e, data) => {
  67113. propertiesPanel.set(null);
  67114. });
  67115. tree.on('dblclick', '.jstree-anchor', e => {
  67116. var instance = $.jstree.reference(e.target);
  67117. var node = instance.get_node(e.target);
  67118. var object = node.data;
  67119. // ignore double click on checkbox
  67120. if (e.target.classList.contains("jstree-checkbox")) {
  67121. return;
  67122. }
  67123. if (object instanceof PointCloudTree) {
  67124. var box = this.viewer.getBoundingBox([object]);
  67125. var _node = new Object3D();
  67126. _node.boundingBox = box;
  67127. this.viewer.zoomTo(_node, 1, 500);
  67128. } else if (object instanceof Measure$1) {
  67129. var points = object.points.map(p => p.position);
  67130. var _box = new Box3().setFromPoints(points);
  67131. if (_box.getSize(new Vector3()).length() == 0) {
  67132. _box.min = _box.max.clone(); //禁止相同
  67133. _box.expandByVector(new Vector3(1, 1, 1));
  67134. }
  67135. var _node2 = new Object3D();
  67136. _node2.boundingBox = _box;
  67137. this.viewer.zoomTo(_node2, 2, 500);
  67138. } else if (object instanceof Profile) {
  67139. var _points = object.points;
  67140. var _box2 = new Box3().setFromPoints(_points);
  67141. if (_box2.getSize(new Vector3()).length() > 0) {
  67142. var _node3 = new Object3D();
  67143. _node3.boundingBox = _box2;
  67144. this.viewer.zoomTo(_node3, 1, 500);
  67145. }
  67146. } else if (object instanceof Volume$1) {
  67147. var _box3 = object.boundingBox.clone().applyMatrix4(object.matrixWorld);
  67148. if (_box3.getSize(new Vector3()).length() > 0) {
  67149. var _node4 = new Object3D();
  67150. _node4.boundingBox = _box3;
  67151. this.viewer.zoomTo(_node4, 1, 500);
  67152. }
  67153. } else if (object instanceof Annotation) {
  67154. object.moveHere(this.viewer.scene.getActiveCamera());
  67155. } else if (object instanceof PolygonClipVolume) {
  67156. var dir = object.camera.getWorldDirection(new Vector3());
  67157. var target;
  67158. if (object.camera instanceof OrthographicCamera) {
  67159. dir.multiplyScalar(object.camera.right);
  67160. target = new Vector3().addVectors(object.camera.position, dir);
  67161. this.viewer.setCameraMode(CameraMode.ORTHOGRAPHIC);
  67162. } else if (object.camera instanceof PerspectiveCamera) {
  67163. dir.multiplyScalar(this.viewer.scene.view.radius);
  67164. target = new Vector3().addVectors(object.camera.position, dir);
  67165. this.viewer.setCameraMode(CameraMode.PERSPECTIVE);
  67166. }
  67167. this.viewer.scene.view.position.copy(object.camera.position);
  67168. this.viewer.scene.view.lookAt(target);
  67169. } else if (object.type === "SpotLight") {
  67170. var distance = object.distance > 0 ? object.distance / 4 : 5 * 1000;
  67171. var position = object.position;
  67172. var _target = new Vector3().addVectors(position, object.getWorldDirection(new Vector3()).multiplyScalar(distance));
  67173. this.viewer.scene.view.position.copy(object.position);
  67174. this.viewer.scene.view.lookAt(_target);
  67175. } else if (object instanceof Object3D) {
  67176. var _box4 = new Box3().setFromObject(object);
  67177. if (_box4.getSize(new Vector3()).length() > 0) {
  67178. var _node5 = new Object3D();
  67179. _node5.boundingBox = _box4;
  67180. this.viewer.zoomTo(_node5, 1, 500);
  67181. }
  67182. } else if (object instanceof OrientedImage) {
  67183. // TODO zoom to images
  67184. // let box = new THREE.Box3().setFromObject(object);
  67185. // if(box.getSize(new THREE.Vector3()).length() > 0){
  67186. // let node = new THREE.Object3D();
  67187. // node.boundingBox = box;
  67188. // this.viewer.zoomTo(node, 1, 500);
  67189. // }
  67190. } else if (object instanceof Images360) {
  67191. // TODO
  67192. } else if (object instanceof Geopackage) {
  67193. // TODO
  67194. }
  67195. });
  67196. tree.on("uncheck_node.jstree", (e, data) => {
  67197. var object = data.node.data;
  67198. if (object) {
  67199. object.visible = false;
  67200. }
  67201. });
  67202. tree.on("check_node.jstree", (e, data) => {
  67203. var object = data.node.data;
  67204. if (object) {
  67205. object.visible = true;
  67206. }
  67207. });
  67208. var onPointCloudAdded = e => {
  67209. var pointcloud = e.pointcloud;
  67210. var cloudIcon = "".concat(Potree.resourcePath, "/icons/cloud.svg");
  67211. var node = createNode(pcID, pointcloud.name, cloudIcon, pointcloud);
  67212. pointcloud.addEventListener("visibility_changed", () => {
  67213. if (pointcloud.visible) {
  67214. tree.jstree('check_node', node);
  67215. } else {
  67216. tree.jstree('uncheck_node', node);
  67217. }
  67218. });
  67219. };
  67220. var onMeasurementAdded = e => {
  67221. var measurement = e.measurement;
  67222. var icon = Utils.getMeasurementIcon(measurement);
  67223. createNode(measurementID, measurement.name, icon, measurement);
  67224. };
  67225. var onVolumeAdded = e => {
  67226. var volume = e.volume;
  67227. var icon = Utils.getMeasurementIcon(volume);
  67228. var node = createNode(measurementID, volume.name, icon, volume);
  67229. volume.addEventListener("visibility_changed", () => {
  67230. if (volume.visible) {
  67231. tree.jstree('check_node', node);
  67232. } else {
  67233. tree.jstree('uncheck_node', node);
  67234. }
  67235. });
  67236. };
  67237. var onProfileAdded = e => {
  67238. var profile = e.profile;
  67239. var icon = Utils.getMeasurementIcon(profile);
  67240. createNode(measurementID, profile.name, icon, profile);
  67241. };
  67242. var onAnnotationAdded = e => {
  67243. var annotation = e.annotation;
  67244. var annotationIcon = "".concat(Potree.resourcePath, "/icons/annotation.svg");
  67245. var parentID = this.annotationMapping.get(annotation.parent);
  67246. var annotationID = createNode(parentID, annotation.title, annotationIcon, annotation);
  67247. this.annotationMapping.set(annotation, annotationID);
  67248. annotation.addEventListener("annotation_changed", e => {
  67249. var annotationsRoot = $("#jstree_scene").jstree().get_json("annotations");
  67250. var jsonNode = annotationsRoot.children.find(child => child.data.uuid === annotation.uuid);
  67251. $.jstree.reference(jsonNode.id).rename_node(jsonNode.id, annotation.title);
  67252. });
  67253. };
  67254. var onCameraAnimationAdded = e => {
  67255. var animation = e.animation;
  67256. var animationIcon = "".concat(Potree.resourcePath, "/icons/camera_animation.svg");
  67257. createNode(otherID, "animation", animationIcon, animation);
  67258. };
  67259. var onOrientedImagesAdded = e => {
  67260. var images = e.images;
  67261. var imagesIcon = "".concat(Potree.resourcePath, "/icons/picture.svg");
  67262. var node = createNode(imagesID, "images", imagesIcon, images);
  67263. images.addEventListener("visibility_changed", () => {
  67264. if (images.visible) {
  67265. tree.jstree('check_node', node);
  67266. } else {
  67267. tree.jstree('uncheck_node', node);
  67268. }
  67269. });
  67270. };
  67271. var onImages360Added = e => {
  67272. var images = e.images;
  67273. var imagesIcon = "".concat(Potree.resourcePath, "/icons/picture.svg");
  67274. var node = createNode(imagesID, "360° images", imagesIcon, images);
  67275. images.addEventListener("visibility_changed", () => {
  67276. if (images.visible) {
  67277. tree.jstree('check_node', node);
  67278. } else {
  67279. tree.jstree('uncheck_node', node);
  67280. }
  67281. });
  67282. };
  67283. var onGeopackageAdded = e => {
  67284. var geopackage = e.geopackage;
  67285. var geopackageIcon = "".concat(Potree.resourcePath, "/icons/triangle.svg");
  67286. var tree = $("#jstree_scene");
  67287. var parentNode = "vectors";
  67288. for (var layer of geopackage.node.children) {
  67289. var name = layer.name;
  67290. var shpPointsID = tree.jstree('create_node', parentNode, {
  67291. "text": name,
  67292. "icon": geopackageIcon,
  67293. "object": layer,
  67294. "data": layer
  67295. }, "last", false, false);
  67296. tree.jstree(layer.visible ? "check_node" : "uncheck_node", shpPointsID);
  67297. }
  67298. };
  67299. this.viewer.scene.addEventListener("pointcloud_added", onPointCloudAdded);
  67300. this.viewer.scene.addEventListener("measurement_added", onMeasurementAdded);
  67301. this.viewer.scene.addEventListener("profile_added", onProfileAdded);
  67302. this.viewer.scene.addEventListener("volume_added", onVolumeAdded);
  67303. this.viewer.scene.addEventListener("camera_animation_added", onCameraAnimationAdded);
  67304. this.viewer.scene.addEventListener("oriented_images_added", onOrientedImagesAdded);
  67305. this.viewer.scene.addEventListener("360_images_added", onImages360Added);
  67306. this.viewer.scene.addEventListener("geopackage_added", onGeopackageAdded);
  67307. this.viewer.scene.addEventListener("polygon_clip_volume_added", onVolumeAdded);
  67308. this.viewer.scene.annotations.addEventListener("annotation_added", onAnnotationAdded);
  67309. var onMeasurementRemoved = e => {
  67310. var measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  67311. var jsonNode = measurementsRoot.children.find(child => child.data.uuid === e.measurement.uuid);
  67312. tree.jstree("delete_node", jsonNode.id);
  67313. };
  67314. var onVolumeRemoved = e => {
  67315. var measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  67316. var jsonNode = measurementsRoot.children.find(child => child.data.uuid === e.volume.uuid);
  67317. tree.jstree("delete_node", jsonNode.id);
  67318. };
  67319. var onPolygonClipVolumeRemoved = e => {
  67320. var measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  67321. var jsonNode = measurementsRoot.children.find(child => child.data.uuid === e.volume.uuid);
  67322. tree.jstree("delete_node", jsonNode.id);
  67323. };
  67324. var onProfileRemoved = e => {
  67325. var measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  67326. var jsonNode = measurementsRoot.children.find(child => child.data.uuid === e.profile.uuid);
  67327. tree.jstree("delete_node", jsonNode.id);
  67328. };
  67329. this.viewer.scene.addEventListener("measurement_removed", onMeasurementRemoved);
  67330. this.viewer.scene.addEventListener("volume_removed", onVolumeRemoved);
  67331. this.viewer.scene.addEventListener("polygon_clip_volume_removed", onPolygonClipVolumeRemoved);
  67332. this.viewer.scene.addEventListener("profile_removed", onProfileRemoved);
  67333. {
  67334. var annotationIcon = "".concat(Potree.resourcePath, "/icons/annotation.svg");
  67335. this.annotationMapping = new Map();
  67336. this.annotationMapping.set(this.viewer.scene.annotations, annotationsID);
  67337. this.viewer.scene.annotations.traverseDescendants(annotation => {
  67338. var parentID = this.annotationMapping.get(annotation.parent);
  67339. var annotationID = createNode(parentID, annotation.title, annotationIcon, annotation);
  67340. this.annotationMapping.set(annotation, annotationID);
  67341. });
  67342. }
  67343. var scene = this.viewer.scene;
  67344. for (var pointcloud of scene.pointclouds) {
  67345. onPointCloudAdded({
  67346. pointcloud: pointcloud
  67347. });
  67348. }
  67349. for (var measurement of scene.measurements) {
  67350. onMeasurementAdded({
  67351. measurement: measurement
  67352. });
  67353. }
  67354. for (var volume of [...scene.volumes, ...scene.polygonClipVolumes]) {
  67355. onVolumeAdded({
  67356. volume: volume
  67357. });
  67358. }
  67359. for (var animation of scene.cameraAnimations) {
  67360. onCameraAnimationAdded({
  67361. animation: animation
  67362. });
  67363. }
  67364. for (var images of scene.orientedImages) {
  67365. onOrientedImagesAdded({
  67366. images: images
  67367. });
  67368. }
  67369. for (var _images of scene.images360) {
  67370. onImages360Added({
  67371. images: _images
  67372. });
  67373. }
  67374. for (var geopackage of scene.geopackages) {
  67375. onGeopackageAdded({
  67376. geopackage: geopackage
  67377. });
  67378. }
  67379. for (var profile of scene.profiles) {
  67380. onProfileAdded({
  67381. profile: profile
  67382. });
  67383. }
  67384. {
  67385. createNode(otherID, "Camera", null, new Camera());
  67386. }
  67387. this.viewer.addEventListener("scene_changed", e => {
  67388. propertiesPanel.setScene(e.scene);
  67389. e.oldScene.removeEventListener("pointcloud_added", onPointCloudAdded);
  67390. e.oldScene.removeEventListener("measurement_added", onMeasurementAdded);
  67391. e.oldScene.removeEventListener("profile_added", onProfileAdded);
  67392. e.oldScene.removeEventListener("volume_added", onVolumeAdded);
  67393. e.oldScene.removeEventListener("polygon_clip_volume_added", onVolumeAdded);
  67394. e.oldScene.removeEventListener("measurement_removed", onMeasurementRemoved);
  67395. e.scene.addEventListener("pointcloud_added", onPointCloudAdded);
  67396. e.scene.addEventListener("measurement_added", onMeasurementAdded);
  67397. e.scene.addEventListener("profile_added", onProfileAdded);
  67398. e.scene.addEventListener("volume_added", onVolumeAdded);
  67399. e.scene.addEventListener("polygon_clip_volume_added", onVolumeAdded);
  67400. e.scene.addEventListener("measurement_removed", onMeasurementRemoved);
  67401. });
  67402. }
  67403. initClippingTool() {
  67404. this.viewer.addEventListener("cliptask_changed", event => {
  67405. console.log("TODO");
  67406. });
  67407. this.viewer.addEventListener("clipmethod_changed", event => {
  67408. console.log("TODO");
  67409. });
  67410. {
  67411. var elClipTask = $("#cliptask_options");
  67412. elClipTask.selectgroup({
  67413. title: "Clip Task"
  67414. });
  67415. elClipTask.find("input").click(e => {
  67416. this.viewer.setClipTask(ClipTask[e.target.value]);
  67417. });
  67418. var currentClipTask = Object.keys(ClipTask).filter(key => ClipTask[key] === this.viewer.clipTask);
  67419. elClipTask.find("input[value=".concat(currentClipTask, "]")).trigger("click");
  67420. }
  67421. {
  67422. var elClipMethod = $("#clipmethod_options");
  67423. elClipMethod.selectgroup({
  67424. title: "Clip Method"
  67425. });
  67426. elClipMethod.find("input").click(e => {
  67427. this.viewer.setClipMethod(ClipMethod[e.target.value]);
  67428. });
  67429. var currentClipMethod = Object.keys(ClipMethod).filter(key => ClipMethod[key] === this.viewer.clipMethod);
  67430. elClipMethod.find("input[value=".concat(currentClipMethod, "]")).trigger("click");
  67431. }
  67432. var clippingToolBar = $("#clipping_tools");
  67433. // CLIP VOLUME
  67434. clippingToolBar.append(this.createToolIcon(Potree.resourcePath + '/icons/clip_volume.svg', '[title]tt.clip_volume', () => {
  67435. var item = this.volumeTool.startInsertion({
  67436. clip: true
  67437. });
  67438. var measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  67439. var jsonNode = measurementsRoot.children.find(child => child.data.uuid === item.uuid);
  67440. $.jstree.reference(jsonNode.id).deselect_all();
  67441. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  67442. }));
  67443. // CLIP POLYGON
  67444. clippingToolBar.append(this.createToolIcon(Potree.resourcePath + "/icons/clip-polygon.svg", "[title]tt.clip_polygon", () => {
  67445. var item = this.viewer.clippingTool.startInsertion({
  67446. type: "polygon"
  67447. });
  67448. var measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  67449. var jsonNode = measurementsRoot.children.find(child => child.data.uuid === item.uuid);
  67450. $.jstree.reference(jsonNode.id).deselect_all();
  67451. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  67452. }));
  67453. {
  67454. // SCREEN BOX SELECT
  67455. var boxSelectTool = new ScreenBoxSelectTool(this.viewer);
  67456. clippingToolBar.append(this.createToolIcon(Potree.resourcePath + "/icons/clip-screen.svg", "[title]tt.screen_clip_box", () => {
  67457. if (!(this.viewer.scene.getActiveCamera() instanceof OrthographicCamera)) {
  67458. this.viewer.postMessage("Switch to Orthographic Camera Mode before using the Screen-Box-Select tool.", {
  67459. duration: 2000
  67460. });
  67461. return;
  67462. }
  67463. var item = boxSelectTool.startInsertion();
  67464. var measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  67465. var jsonNode = measurementsRoot.children.find(child => child.data.uuid === item.uuid);
  67466. $.jstree.reference(jsonNode.id).deselect_all();
  67467. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  67468. }));
  67469. }
  67470. {
  67471. // REMOVE CLIPPING TOOLS
  67472. clippingToolBar.append(this.createToolIcon(Potree.resourcePath + "/icons/remove.svg", "[title]tt.remove_all_clipping_volumes", () => {
  67473. this.viewer.scene.removeAllClipVolumes();
  67474. }));
  67475. }
  67476. }
  67477. initFilters() {
  67478. this.initClassificationList();
  67479. this.initReturnFilters();
  67480. this.initGPSTimeFilters();
  67481. this.initPointSourceIDFilters();
  67482. }
  67483. initReturnFilters() {
  67484. var elReturnFilterPanel = $('#return_filter_panel');
  67485. {
  67486. // RETURN NUMBER
  67487. var sldReturnNumber = elReturnFilterPanel.find('#sldReturnNumber');
  67488. var lblReturnNumber = elReturnFilterPanel.find('#lblReturnNumber');
  67489. sldReturnNumber.slider({
  67490. range: true,
  67491. min: 0,
  67492. max: 7,
  67493. step: 1,
  67494. values: [0, 7],
  67495. slide: (event, ui) => {
  67496. this.viewer.setFilterReturnNumberRange(ui.values[0], ui.values[1]);
  67497. }
  67498. });
  67499. var onReturnNumberChanged = event => {
  67500. var [from, to] = this.viewer.filterReturnNumberRange;
  67501. lblReturnNumber[0].innerHTML = "".concat(from, " to ").concat(to);
  67502. sldReturnNumber.slider({
  67503. values: [from, to]
  67504. });
  67505. };
  67506. this.viewer.addEventListener('filter_return_number_range_changed', onReturnNumberChanged);
  67507. onReturnNumberChanged();
  67508. }
  67509. {
  67510. // NUMBER OF RETURNS
  67511. var sldNumberOfReturns = elReturnFilterPanel.find('#sldNumberOfReturns');
  67512. var lblNumberOfReturns = elReturnFilterPanel.find('#lblNumberOfReturns');
  67513. sldNumberOfReturns.slider({
  67514. range: true,
  67515. min: 0,
  67516. max: 7,
  67517. step: 1,
  67518. values: [0, 7],
  67519. slide: (event, ui) => {
  67520. this.viewer.setFilterNumberOfReturnsRange(ui.values[0], ui.values[1]);
  67521. }
  67522. });
  67523. var onNumberOfReturnsChanged = event => {
  67524. var [from, to] = this.viewer.filterNumberOfReturnsRange;
  67525. lblNumberOfReturns[0].innerHTML = "".concat(from, " to ").concat(to);
  67526. sldNumberOfReturns.slider({
  67527. values: [from, to]
  67528. });
  67529. };
  67530. this.viewer.addEventListener('filter_number_of_returns_range_changed', onNumberOfReturnsChanged);
  67531. onNumberOfReturnsChanged();
  67532. }
  67533. }
  67534. initGPSTimeFilters() {
  67535. var elGPSTimeFilterPanel = $('#gpstime_filter_panel');
  67536. {
  67537. var slider = new HierarchicalSlider({
  67538. levels: 4,
  67539. slide: event => {
  67540. this.viewer.setFilterGPSTimeRange(...event.values);
  67541. }
  67542. });
  67543. var initialized = false;
  67544. var initialize = () => {
  67545. var elRangeContainer = $("#gpstime_multilevel_range_container");
  67546. elRangeContainer[0].prepend(slider.element);
  67547. var extent = this.viewer.getGpsTimeExtent();
  67548. slider.setRange(extent);
  67549. slider.setValues(extent);
  67550. initialized = true;
  67551. };
  67552. this.viewer.addEventListener("update", e => {
  67553. var extent = this.viewer.getGpsTimeExtent();
  67554. var gpsTimeAvailable = extent[0] !== Infinity;
  67555. if (!initialized && gpsTimeAvailable) {
  67556. initialize();
  67557. }
  67558. slider.setRange(extent); //高耗cpu
  67559. });
  67560. }
  67561. {
  67562. var txtGpsTime = elGPSTimeFilterPanel.find("#txtGpsTime");
  67563. var btnFindGpsTime = elGPSTimeFilterPanel.find("#btnFindGpsTime");
  67564. var targetTime = null;
  67565. txtGpsTime.on("input", e => {
  67566. var str = txtGpsTime.val();
  67567. if (!isNaN(str)) {
  67568. var value = parseFloat(str);
  67569. targetTime = value;
  67570. txtGpsTime.css("background-color", "");
  67571. } else {
  67572. targetTime = null;
  67573. txtGpsTime.css("background-color", "#ff9999");
  67574. }
  67575. });
  67576. btnFindGpsTime.click(() => {
  67577. if (targetTime !== null) {
  67578. viewer.moveToGpsTimeVicinity(targetTime);
  67579. }
  67580. });
  67581. }
  67582. }
  67583. initPointSourceIDFilters() {
  67584. var elPointSourceIDFilterPanel = $('#pointsourceid_filter_panel');
  67585. {
  67586. var slider = new HierarchicalSlider({
  67587. levels: 4,
  67588. range: [0, 65535],
  67589. precision: 1,
  67590. slide: event => {
  67591. var values = event.values;
  67592. this.viewer.setFilterPointSourceIDRange(values[0], values[1]);
  67593. }
  67594. });
  67595. var initialized = false;
  67596. var initialize = () => {
  67597. elPointSourceIDFilterPanel[0].prepend(slider.element);
  67598. initialized = true;
  67599. };
  67600. this.viewer.addEventListener("update", e => {
  67601. var extent = this.viewer.filterPointSourceIDRange;
  67602. if (!initialized) {
  67603. initialize();
  67604. slider.setValues(extent);
  67605. }
  67606. });
  67607. }
  67608. // let lblPointSourceID = elPointSourceIDFilterPanel.find("#lblPointSourceID");
  67609. // let elPointSourceID = elPointSourceIDFilterPanel.find("#spnPointSourceID");
  67610. // let slider = new ZoomableSlider();
  67611. // elPointSourceID[0].appendChild(slider.element);
  67612. // slider.update();
  67613. // slider.change( () => {
  67614. // let range = slider.chosenRange;
  67615. // this.viewer.setFilterPointSourceIDRange(range[0], range[1]);
  67616. // });
  67617. // let onPointSourceIDExtentChanged = (event) => {
  67618. // let range = this.viewer.filterPointSourceIDExtent;
  67619. // slider.setVisibleRange(range);
  67620. // };
  67621. // let onPointSourceIDChanged = (event) => {
  67622. // let range = this.viewer.filterPointSourceIDRange;
  67623. // let precision = 1;
  67624. // let from = `${Utils.addCommas(range[0].toFixed(precision))}`;
  67625. // let to = `${Utils.addCommas(range[1].toFixed(precision))}`;
  67626. // lblPointSourceID[0].innerHTML = `${from} to ${to}`;
  67627. // slider.setRange(range);
  67628. // };
  67629. // this.viewer.addEventListener('filter_point_source_id_range_changed', onPointSourceIDChanged);
  67630. // this.viewer.addEventListener('filter_point_source_id_extent_changed', onPointSourceIDExtentChanged);
  67631. }
  67632. initClassificationList() {
  67633. var elClassificationList = $('#classificationList');
  67634. var addClassificationItem = (code, name) => {
  67635. var classification = this.viewer.classifications[code];
  67636. var inputID = 'chkClassification_' + code;
  67637. var colorPickerID = 'colorPickerClassification_' + code;
  67638. var checked = classification.visible ? "checked" : "";
  67639. var element = $("\n\t\t\t\t<li>\n\t\t\t\t\t<label style=\"whitespace: nowrap; display: flex\">\n\t\t\t\t\t\t<input id=\"".concat(inputID, "\" type=\"checkbox\" ").concat(checked, "/>\n\t\t\t\t\t\t<span style=\"flex-grow: 1\">").concat(name, "</span>\n\t\t\t\t\t\t<input id=\"").concat(colorPickerID, "\" style=\"zoom: 0.5\" />\n\t\t\t\t\t</label>\n\t\t\t\t</li>\n\t\t\t"));
  67640. var elInput = element.find('input');
  67641. var elColorPicker = element.find("#".concat(colorPickerID));
  67642. elInput.click(event => {
  67643. this.viewer.setClassificationVisibility(code, event.target.checked);
  67644. });
  67645. var defaultColor = classification.color.map(c => c * 255).join(", ");
  67646. defaultColor = "rgb(".concat(defaultColor, ")");
  67647. elColorPicker.spectrum({
  67648. // flat: true,
  67649. color: defaultColor,
  67650. showInput: true,
  67651. preferredFormat: 'rgb',
  67652. cancelText: '',
  67653. chooseText: 'Apply',
  67654. move: color => {
  67655. var rgb = color.toRgb();
  67656. var c = [rgb.r / 255, rgb.g / 255, rgb.b / 255, 1];
  67657. classification.color = c;
  67658. },
  67659. change: color => {
  67660. var rgb = color.toRgb();
  67661. var c = [rgb.r / 255, rgb.g / 255, rgb.b / 255, 1];
  67662. classification.color = c;
  67663. }
  67664. });
  67665. elClassificationList.append(element);
  67666. };
  67667. var addToggleAllButton = () => {
  67668. // toggle all button
  67669. var element = $("\n\t\t\t\t<li>\n\t\t\t\t\t<label style=\"whitespace: nowrap\">\n\t\t\t\t\t\t<input id=\"toggleClassificationFilters\" type=\"checkbox\" checked/>\n\t\t\t\t\t\t<span>show/hide all</span>\n\t\t\t\t\t</label>\n\t\t\t\t</li>\n\t\t\t");
  67670. var elInput = element.find('input');
  67671. elInput.click(event => {
  67672. this.viewer.toggleAllClassificationsVisibility();
  67673. });
  67674. elClassificationList.append(element);
  67675. };
  67676. var addInvertButton = () => {
  67677. var element = $("\n\t\t\t\t<li>\n\t\t\t\t\t<input type=\"button\" value=\"invert\" />\n\t\t\t\t</li>\n\t\t\t");
  67678. var elInput = element.find('input');
  67679. elInput.click(() => {
  67680. var classifications = this.viewer.classifications;
  67681. for (var key of Object.keys(classifications)) {
  67682. var value = classifications[key];
  67683. this.viewer.setClassificationVisibility(key, !value.visible);
  67684. }
  67685. });
  67686. elClassificationList.append(element);
  67687. };
  67688. var populate = () => {
  67689. addToggleAllButton();
  67690. for (var classID in this.viewer.classifications) {
  67691. addClassificationItem(classID, this.viewer.classifications[classID].name);
  67692. }
  67693. addInvertButton();
  67694. };
  67695. populate();
  67696. this.viewer.addEventListener("classifications_changed", () => {
  67697. elClassificationList.empty();
  67698. populate();
  67699. });
  67700. this.viewer.addEventListener("classification_visibility_changed", () => {
  67701. {
  67702. // set checked state of classification buttons
  67703. for (var classID of Object.keys(this.viewer.classifications)) {
  67704. var classValue = this.viewer.classifications[classID];
  67705. var elItem = elClassificationList.find("#chkClassification_".concat(classID));
  67706. elItem.prop("checked", classValue.visible);
  67707. }
  67708. }
  67709. {
  67710. // set checked state of toggle button based on state of all other buttons
  67711. var numVisible = 0;
  67712. var numItems = 0;
  67713. for (var key of Object.keys(this.viewer.classifications)) {
  67714. if (this.viewer.classifications[key].visible) {
  67715. numVisible++;
  67716. }
  67717. numItems++;
  67718. }
  67719. var allVisible = numVisible === numItems;
  67720. var elToggle = elClassificationList.find("#toggleClassificationFilters");
  67721. elToggle.prop("checked", allVisible);
  67722. }
  67723. });
  67724. }
  67725. initAccordion() {
  67726. var _this = this;
  67727. $('.accordion > h3').each(function () {
  67728. var header = $(this);
  67729. var content = $(this).next();
  67730. //header.addClass('accordion-header ui-widget');
  67731. //content.addClass('accordion-content ui-widget');
  67732. content.hide();
  67733. header.click(() => {
  67734. content.slideToggle();
  67735. });
  67736. });
  67737. var languages = [["EN", "en"], ["FR", "fr"], ["DE", "de"], ["JP", "jp"], ["ES", "es"], ["SE", "se"], ["ZH", "zh"]];
  67738. var elLanguages = $('#potree_languages');
  67739. var _loop = function _loop() {
  67740. var [key, value] = languages[i];
  67741. var element = $("<a>".concat(key, "</a>"));
  67742. element.click(() => _this.viewer.setLanguage(value));
  67743. if (i === 0) {
  67744. element.css("margin-left", "30px");
  67745. }
  67746. elLanguages.append(element);
  67747. if (i < languages.length - 1) {
  67748. elLanguages.append($(document.createTextNode(' - ')));
  67749. }
  67750. };
  67751. for (var i = 0; i < languages.length; i++) {
  67752. _loop();
  67753. }
  67754. // to close all, call
  67755. // $(".accordion > div").hide()
  67756. // to open the, for example, tool menu, call:
  67757. // $("#menu_tools").next().show()
  67758. }
  67759. initAppearance() {
  67760. var sldPointBudget = this.dom.find('#sldPointBudget');
  67761. sldPointBudget.slider({
  67762. value: this.viewer.getPointBudget(),
  67763. min: 100 * 1000,
  67764. max: 10 * 1000 * 1000,
  67765. step: 1000,
  67766. slide: (event, ui) => {
  67767. this.viewer.setPointBudget(ui.value);
  67768. }
  67769. });
  67770. this.dom.find('#sldFOV').slider({
  67771. value: this.viewer.getFOV(),
  67772. min: 20,
  67773. max: 100,
  67774. step: 1,
  67775. slide: (event, ui) => {
  67776. this.viewer.setFOV(ui.value);
  67777. }
  67778. });
  67779. $('#sldEDLRadius').slider({
  67780. value: this.viewer.getEDLRadius(),
  67781. min: 1,
  67782. max: 4,
  67783. step: 0.01,
  67784. slide: (event, ui) => {
  67785. this.viewer.setEDLRadius(ui.value);
  67786. }
  67787. });
  67788. $('#sldEDLStrength').slider({
  67789. value: this.viewer.getEDLStrength(),
  67790. min: 0,
  67791. max: 5,
  67792. step: 0.01,
  67793. slide: (event, ui) => {
  67794. this.viewer.setEDLStrength(ui.value);
  67795. }
  67796. });
  67797. $('#sldEDLOpacity').slider({
  67798. value: this.viewer.getEDLOpacity(),
  67799. min: 0,
  67800. max: 1,
  67801. step: 0.01,
  67802. slide: (event, ui) => {
  67803. this.viewer.setEDLOpacity(ui.value);
  67804. }
  67805. });
  67806. this.viewer.addEventListener('point_budget_changed', event => {
  67807. $('#lblPointBudget')[0].innerHTML = Utils.addCommas(this.viewer.getPointBudget());
  67808. sldPointBudget.slider({
  67809. value: this.viewer.getPointBudget()
  67810. });
  67811. });
  67812. this.viewer.addEventListener('fov_changed', event => {
  67813. $('#lblFOV')[0].innerHTML = parseInt(this.viewer.getFOV());
  67814. $('#sldFOV').slider({
  67815. value: this.viewer.getFOV()
  67816. });
  67817. });
  67818. this.viewer.addEventListener('use_edl_changed', event => {
  67819. $('#chkEDLEnabled')[0].checked = this.viewer.getEDLEnabled();
  67820. });
  67821. this.viewer.addEventListener('edl_radius_changed', event => {
  67822. $('#lblEDLRadius')[0].innerHTML = this.viewer.getEDLRadius().toFixed(1);
  67823. $('#sldEDLRadius').slider({
  67824. value: this.viewer.getEDLRadius()
  67825. });
  67826. });
  67827. this.viewer.addEventListener('edl_strength_changed', event => {
  67828. $('#lblEDLStrength')[0].innerHTML = this.viewer.getEDLStrength().toFixed(1);
  67829. $('#sldEDLStrength').slider({
  67830. value: this.viewer.getEDLStrength()
  67831. });
  67832. });
  67833. this.viewer.addEventListener('background_changed', event => {
  67834. $("input[name=background][value='" + this.viewer.getBackground() + "']").prop('checked', true);
  67835. });
  67836. $('#lblPointBudget')[0].innerHTML = Utils.addCommas(this.viewer.getPointBudget());
  67837. $('#lblFOV')[0].innerHTML = parseInt(this.viewer.getFOV());
  67838. $('#lblEDLRadius')[0].innerHTML = this.viewer.getEDLRadius().toFixed(1);
  67839. $('#lblEDLStrength')[0].innerHTML = this.viewer.getEDLStrength().toFixed(1);
  67840. $('#chkEDLEnabled')[0].checked = this.viewer.getEDLEnabled();
  67841. {
  67842. var elBackground = $("#background_options");
  67843. elBackground.selectgroup();
  67844. elBackground.find("input").click(e => {
  67845. this.viewer.setBackground(e.target.value);
  67846. });
  67847. var currentBackground = this.viewer.getBackground();
  67848. try {
  67849. $("input[name=background_options][value=".concat(currentBackground, "]")).trigger("click");
  67850. } catch (e) {}
  67851. }
  67852. $('#chkEDLEnabled').click(() => {
  67853. this.viewer.setEDLEnabled($('#chkEDLEnabled').prop("checked"));
  67854. });
  67855. }
  67856. initNavigation() {
  67857. var elNavigation = $('#navigation');
  67858. var sldMoveSpeed = $('#sldMoveSpeed');
  67859. var lblMoveSpeed = $('#lblMoveSpeed');
  67860. elNavigation.append(this.createToolIcon(Potree.resourcePath + '/icons/earth_controls_1.png', '[title]tt.earth_control', () => {
  67861. this.viewer.setControls(this.viewer.earthControls);
  67862. }));
  67863. elNavigation.append(this.createToolIcon(Potree.resourcePath + '/icons/fps_controls.svg', '[title]tt.flight_control', () => {
  67864. this.viewer.setControls(this.viewer.fpControls);
  67865. this.viewer.fpControls.lockElevation = false;
  67866. }));
  67867. elNavigation.append(this.createToolIcon(Potree.resourcePath + '/icons/helicopter_controls.svg', '[title]tt.heli_control', () => {
  67868. this.viewer.setControls(this.viewer.fpControls);
  67869. this.viewer.fpControls.lockElevation = true;
  67870. }));
  67871. elNavigation.append(this.createToolIcon(Potree.resourcePath + '/icons/orbit_controls.svg', '[title]tt.orbit_control', () => {
  67872. this.viewer.setControls(this.viewer.orbitControls);
  67873. }));
  67874. elNavigation.append(this.createToolIcon(Potree.resourcePath + '/icons/focus.svg', '[title]tt.focus_control', () => {
  67875. this.viewer.fitToScreen();
  67876. }));
  67877. elNavigation.append(this.createToolIcon(Potree.resourcePath + "/icons/navigation_cube.svg", "[title]tt.navigation_cube_control", () => {
  67878. this.viewer.toggleNavigationCube();
  67879. }));
  67880. elNavigation.append(this.createToolIcon(Potree.resourcePath + "/images/compas.svg", "[title]tt.compass", () => {
  67881. var visible = !this.viewer.compass.isVisible();
  67882. this.viewer.compass.setVisible(visible);
  67883. }));
  67884. elNavigation.append(this.createToolIcon(Potree.resourcePath + "/icons/camera_animation.svg", "[title]tt.camera_animation", () => {
  67885. var animation = CameraAnimation$1.defaultFromView(this.viewer);
  67886. viewer.scene.addCameraAnimation(animation);
  67887. }));
  67888. elNavigation.append("<br>");
  67889. elNavigation.append(this.createToolIcon(Potree.resourcePath + "/icons/left.svg", "[title]tt.left_view_control", () => {
  67890. this.viewer.setLeftView();
  67891. }));
  67892. elNavigation.append(this.createToolIcon(Potree.resourcePath + "/icons/right.svg", "[title]tt.right_view_control", () => {
  67893. this.viewer.setRightView();
  67894. }));
  67895. elNavigation.append(this.createToolIcon(Potree.resourcePath + "/icons/front.svg", "[title]tt.front_view_control", () => {
  67896. this.viewer.setFrontView();
  67897. }));
  67898. elNavigation.append(this.createToolIcon(Potree.resourcePath + "/icons/back.svg", "[title]tt.back_view_control", () => {
  67899. this.viewer.setBackView();
  67900. }));
  67901. elNavigation.append(this.createToolIcon(Potree.resourcePath + "/icons/top.svg", "[title]tt.top_view_control", () => {
  67902. this.viewer.setTopView();
  67903. }));
  67904. elNavigation.append(this.createToolIcon(Potree.resourcePath + "/icons/bottom.svg", "[title]tt.bottom_view_control", () => {
  67905. this.viewer.setBottomView();
  67906. }));
  67907. var elCameraProjection = $("\n\t\t\t<selectgroup id=\"camera_projection_options\">\n\t\t\t\t<option id=\"camera_projection_options_perspective\" value=\"PERSPECTIVE\">Perspective</option>\n\t\t\t\t<option id=\"camera_projection_options_orthigraphic\" value=\"ORTHOGRAPHIC\">Orthographic</option>\n\t\t\t</selectgroup>\n\t\t");
  67908. elNavigation.append(elCameraProjection);
  67909. elCameraProjection.selectgroup({
  67910. title: "Camera Projection"
  67911. });
  67912. elCameraProjection.find("input").click(e => {
  67913. this.viewer.setCameraMode(CameraMode[e.target.value]);
  67914. });
  67915. var cameraMode = Object.keys(CameraMode).filter(key => CameraMode[key] === this.viewer.scene.cameraMode);
  67916. elCameraProjection.find("input[value=".concat(cameraMode, "]")).trigger("click");
  67917. var speedRange = new Vector2(1, 10 * 1000);
  67918. var toLinearSpeed = value => {
  67919. return Math.pow(value, 4) * speedRange.y + speedRange.x;
  67920. };
  67921. var toExpSpeed = value => {
  67922. return Math.pow((value - speedRange.x) / speedRange.y, 1 / 4);
  67923. };
  67924. sldMoveSpeed.slider({
  67925. value: toExpSpeed(this.viewer.getMoveSpeed()),
  67926. min: 0,
  67927. max: 1,
  67928. step: 0.01,
  67929. slide: (event, ui) => {
  67930. this.viewer.setMoveSpeed(toLinearSpeed(ui.value));
  67931. }
  67932. });
  67933. this.viewer.addEventListener('move_speed_changed', event => {
  67934. lblMoveSpeed.html(this.viewer.getMoveSpeed().toFixed(1));
  67935. sldMoveSpeed.slider({
  67936. value: toExpSpeed(this.viewer.getMoveSpeed())
  67937. });
  67938. });
  67939. lblMoveSpeed.html(this.viewer.getMoveSpeed().toFixed(1));
  67940. }
  67941. initSettings() {
  67942. {
  67943. $('#sldMinNodeSize').slider({
  67944. value: this.viewer.getMinNodeSize(),
  67945. min: 0,
  67946. max: 1000,
  67947. step: 0.01,
  67948. slide: (event, ui) => {
  67949. this.viewer.setMinNodeSize(ui.value);
  67950. }
  67951. });
  67952. this.viewer.addEventListener('minnodesize_changed', event => {
  67953. $('#lblMinNodeSize').html(parseInt(this.viewer.getMinNodeSize()));
  67954. $('#sldMinNodeSize').slider({
  67955. value: this.viewer.getMinNodeSize()
  67956. });
  67957. });
  67958. $('#lblMinNodeSize').html(parseInt(this.viewer.getMinNodeSize()));
  67959. }
  67960. {
  67961. var elSplatQuality = $("#splat_quality_options");
  67962. elSplatQuality.selectgroup({
  67963. title: "Splat Quality"
  67964. });
  67965. elSplatQuality.find("input").click(e => {
  67966. if (e.target.value === "standard") {
  67967. this.viewer.useHQ = false;
  67968. } else if (e.target.value === "hq") {
  67969. this.viewer.useHQ = true;
  67970. }
  67971. });
  67972. var currentQuality = this.viewer.useHQ ? "hq" : "standard";
  67973. elSplatQuality.find("input[value=".concat(currentQuality, "]")).trigger("click");
  67974. }
  67975. $('#show_bounding_box').click(() => {
  67976. this.viewer.setShowBoundingBox($('#show_bounding_box').prop("checked"));
  67977. });
  67978. $('#set_freeze').click(() => {
  67979. this.viewer.setFreeze($('#set_freeze').prop("checked"));
  67980. });
  67981. }
  67982. }
  67983. class AnnotationTool extends EventDispatcher$1 {
  67984. constructor(viewer) {
  67985. super();
  67986. this.viewer = viewer;
  67987. this.renderer = viewer.renderer;
  67988. this.sg = new SphereGeometry(0.1);
  67989. this.sm = new MeshNormalMaterial();
  67990. this.s = new Mesh(this.sg, this.sm);
  67991. }
  67992. startInsertion() {
  67993. var args = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  67994. var domElement = this.viewer.renderer.domElement;
  67995. var annotation = new Annotation({
  67996. position: [589748.270, 231444.540, 753.675],
  67997. title: "Annotation Title",
  67998. description: "Annotation Description"
  67999. });
  68000. this.dispatchEvent({
  68001. type: 'start_inserting_annotation',
  68002. annotation: annotation
  68003. });
  68004. var annotations = this.viewer.scene.annotations;
  68005. annotations.add(annotation);
  68006. var callbacks = {
  68007. cancel: null,
  68008. finish: null
  68009. };
  68010. var insertionCallback = e => {
  68011. if (e.button === MOUSE.LEFT) {
  68012. callbacks.finish();
  68013. } else if (e.button === MOUSE.RIGHT) {
  68014. callbacks.cancel();
  68015. }
  68016. };
  68017. callbacks.cancel = e => {
  68018. annotations.remove(annotation);
  68019. domElement.removeEventListener('mouseup', insertionCallback, true);
  68020. };
  68021. callbacks.finish = e => {
  68022. domElement.removeEventListener('mouseup', insertionCallback, true);
  68023. };
  68024. domElement.addEventListener('mouseup', insertionCallback, true);
  68025. var drag = e => {
  68026. var I = Utils.getMousePointCloudIntersection(e.drag.end, e.viewer.scene.getActiveCamera(), e.viewer, e.viewer.scene.pointclouds, {
  68027. pickClipped: true
  68028. });
  68029. if (I) {
  68030. this.s.position.copy(I.location);
  68031. annotation.position.copy(I.location);
  68032. }
  68033. };
  68034. var drop = e => {
  68035. viewer.scene.scene.remove(this.s);
  68036. this.s.removeEventListener("drag", drag);
  68037. this.s.removeEventListener("drop", drop);
  68038. };
  68039. this.s.addEventListener('drag', drag);
  68040. this.s.addEventListener('drop', drop);
  68041. this.viewer.scene.scene.add(this.s);
  68042. this.viewer.inputHandler.startDragging(this.s);
  68043. return annotation;
  68044. }
  68045. update() {
  68046. // let camera = this.viewer.scene.getActiveCamera();
  68047. // let domElement = this.renderer.domElement;
  68048. // let measurements = this.viewer.scene.measurements;
  68049. // const renderAreaSize = this.renderer.getSize(new THREE.Vector2());
  68050. // let clientWidth = renderAreaSize.width;
  68051. // let clientHeight = renderAreaSize.height;
  68052. }
  68053. render() {
  68054. //this.viewer.renderer.render(this.scene, this.viewer.scene.getActiveCamera());
  68055. }
  68056. }
  68057. ;
  68058. //处理cursor优先级
  68059. var CursorDeal = {
  68060. priorityEvent: [
  68061. //在前面的优先级高
  68062. {
  68063. 'zoomInCloud': 'zoom-in'
  68064. }, {
  68065. 'hoverPano': 'pointer'
  68066. }, {
  68067. 'connectPano': "url({Potree.resourcePath}/images/connect.png),auto"
  68068. }, {
  68069. 'disconnectPano': "url({Potree.resourcePath}/images/connect-dis.png),auto"
  68070. }, {
  68071. 'hoverLine': 'pointer'
  68072. }, {
  68073. 'hoverTranHandle': 'grab'
  68074. }, {
  68075. "movePointcloud": 'move'
  68076. }, {
  68077. "polygon_isIntersectSelf": 'not-allowed'
  68078. }, {
  68079. "polygon_AtWrongPlace": 'not-allowed'
  68080. }, {
  68081. 'delPoint': 'url("https://4dkk.4dage.com/v4-test/www/sdk/images/polygon_mark/pic_pen_sub.png"), auto'
  68082. }, {
  68083. "markerMove": 'grab'
  68084. }, {
  68085. 'addPoint': 'url("https://4dkk.4dage.com/v4-test/www/sdk/images/polygon_mark/pic_pen_add.png"), auto'
  68086. }, {
  68087. 'mapClipMove': 'move'
  68088. }, {
  68089. 'mapClipRotate': "url({Potree.resourcePath}/images/rotate-cursor.png),auto"
  68090. }, {
  68091. 'rotatePointcloud': "url({Potree.resourcePath}/images/rotate-cursor.png),auto"
  68092. }, {
  68093. 'siteModelFloorDrag': 'row-resize'
  68094. }, {
  68095. 'addSth': 'cell'
  68096. } //or crosshair
  68097. ],
  68098. list: [],
  68099. //当前存在的cursor状态
  68100. currentCursorIndex: null,
  68101. init: function init(viewer, viewers) {
  68102. this.priorityEvent.forEach(e => {
  68103. //刚开始Potree.resourcePath没值,现在换
  68104. for (var i in e) {
  68105. e[i] = Common.replaceAll(e[i], '{Potree.resourcePath}', Potree.resourcePath);
  68106. }
  68107. });
  68108. this.domElements = viewers.map(e => e.renderArea);
  68109. viewer.addEventListener("CursorChange", e => {
  68110. if (e.action == 'add') {
  68111. this.add(e.name);
  68112. } else {
  68113. this.remove(e.name);
  68114. }
  68115. });
  68116. },
  68117. add: function add(name) {
  68118. var priorityItem = this.priorityEvent.find(e => e[name]);
  68119. if (!priorityItem) {
  68120. console.error('CursorDeal 未定义优先级 name:' + name);
  68121. return;
  68122. }
  68123. if (!this.list.includes(name)) {
  68124. this.judge({
  68125. addItem: priorityItem,
  68126. name
  68127. });
  68128. this.list.push(name);
  68129. }
  68130. },
  68131. remove: function remove(name) {
  68132. var index = this.list.indexOf(name);
  68133. if (index > -1) {
  68134. this.list.splice(index, 1);
  68135. this.judge();
  68136. }
  68137. },
  68138. judge: function judge() {
  68139. var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  68140. //console.log(o,this.list)
  68141. if (o.addItem) {
  68142. var addIndex = this.priorityEvent.indexOf(o.addItem);
  68143. if (addIndex < this.currentCursorIndex || this.currentCursorIndex == void 0) {
  68144. this.domElements.forEach(e => e.style.cursor = o.addItem[o.name]);
  68145. this.currentCursorIndex = addIndex;
  68146. }
  68147. } else {
  68148. var levelMax = {
  68149. index: Infinity,
  68150. cursor: null
  68151. };
  68152. this.list.forEach(name => {
  68153. var priorityItem = this.priorityEvent.find(e => e[name]);
  68154. var index = this.priorityEvent.indexOf(priorityItem);
  68155. if (index < levelMax.index) {
  68156. levelMax.index = index;
  68157. levelMax.cursor = priorityItem[name];
  68158. }
  68159. });
  68160. this.currentCursorIndex = levelMax.index;
  68161. this.domElements.forEach(e => e.style.cursor = levelMax.cursor || '');
  68162. }
  68163. }
  68164. };
  68165. class SplitScreen extends EventDispatcher {
  68166. constructor() {
  68167. var args = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  68168. super();
  68169. }
  68170. /*
  68171. viewport.targetPlane // bound中心点处的plane,方向和view一致
  68172. viewport.shiftTarget // camera的位置project在targetPlane上的位置
  68173. 这两个参数的主要目的是为了getPosOutOfModel,以及rotateSideCamera时保持相对位置
  68174. */
  68175. splitStart(cameraProps) {
  68176. var _this = this;
  68177. this.splited = true;
  68178. var viewports = [];
  68179. var subViewports = [viewer.mainViewport];
  68180. if (viewer.mapViewer) {
  68181. subViewports.push(viewer.mapViewer.viewports[0]);
  68182. }
  68183. var length = cameraProps.length;
  68184. var _loop = function _loop() {
  68185. var prop = cameraProps[i];
  68186. var viewport;
  68187. var v = subViewports.find(e => e.name == (prop.name2 || prop.name));
  68188. if (v) {
  68189. viewport = v;
  68190. viewport.left = prop.left;
  68191. viewport.bottom = prop.bottom;
  68192. viewport.width = prop.width;
  68193. viewport.height = prop.height;
  68194. }
  68195. if (!viewport) {
  68196. var view = new ExtendView();
  68197. if (prop.limitBound) view.limitBound = prop.limitBound;
  68198. prop.direction && (view.direction = prop.direction);
  68199. viewport = new Viewport(view, _this.getOrthoCamera(), prop);
  68200. if (prop.viewContainsPoints) viewport.viewContainsPoints = prop.viewContainsPoints;
  68201. //viewport.unableDepth = true //depthBasicMaterial等在此viewport中不开启depth
  68202. }
  68203. if (viewport.camera.type == 'OrthographicCamera') {
  68204. viewport.targetPlane = new Plane();
  68205. viewport.shiftTarget = new Vector3(); //project在targetPlane上的位置
  68206. }
  68207. viewport.fitMargin = prop.margin;
  68208. viewports.push(viewport);
  68209. };
  68210. for (var i = 0; i < length; i++) {
  68211. _loop();
  68212. }
  68213. viewer.viewports = viewports;
  68214. viewer.updateScreenSize({
  68215. forceUpdateSize: true
  68216. });
  68217. viewports.forEach(viewport => {
  68218. if (viewport.name == 'MainView') return;
  68219. this.viewportFitBound(viewport, viewer.bound.boundingBox, viewer.bound.center, 0, viewport.fitMargin);
  68220. });
  68221. return viewports;
  68222. }
  68223. unSplit() {
  68224. this.splited = false;
  68225. this.unfocusViewport();
  68226. viewer.inputHandler.hoverViewport = null; //清空
  68227. viewer.viewports = [viewer.mainViewport];
  68228. viewer.mainViewport.width = 1;
  68229. viewer.mainViewport.height = 1;
  68230. viewer.mainViewport.left = 0;
  68231. viewer.mainViewport.bottom = 0;
  68232. viewer.updateScreenSize({
  68233. forceUpdateSize: true
  68234. });
  68235. }
  68236. viewportFitBound(viewport, bound, center) {
  68237. var duration = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
  68238. var margin = arguments.length > 4 ? arguments[4] : undefined;
  68239. var view = viewport.view;
  68240. var info = {
  68241. bound
  68242. };
  68243. var {
  68244. boundSize,
  68245. boundCenter
  68246. } = this.getViewBound(viewport, bound);
  68247. //this.setShiftTarget(viewport, boundCenter)
  68248. viewport.targetPlane.setFromNormalAndCoplanarPoint(view.direction.clone(), boundCenter);
  68249. viewport.targetPlane.projectPoint(center, viewport.shiftTarget); //target转换到过模型中心的平面,以保证镜头一定在模型外 this.shiftTarget是得到的
  68250. info.endPosition = this.getPosOutOfModel(viewport, boundSize);
  68251. //if(viewport.name == 'mapViewport')info.endPosition.z = Math.max(Potree.config.map.cameraHeight, info.endPosition.z)
  68252. info.margin = margin || {
  68253. x: 30,
  68254. y: 30
  68255. };
  68256. view.moveOrthoCamera(viewport, info, duration);
  68257. }
  68258. getViewBound(viewport, boundingBox) {
  68259. if (boundingBox) {
  68260. boundSize = boundingBox.getSize(new Vector3());
  68261. center = boundingBox.getCenter(new Vector3());
  68262. } else {
  68263. var {
  68264. boundSize,
  68265. center,
  68266. boundingBox
  68267. } = viewer.bound;
  68268. }
  68269. var containsPoints = [];
  68270. this.focusCenter && containsPoints.push(this.focusCenter);
  68271. viewport.viewContainsPoints && containsPoints.push(...viewport.viewContainsPoints);
  68272. if (containsPoints.length) {
  68273. //视野范围内必须要包含的点,直接算入模型区域。这时候得到的boundCenter和模型中心不重合
  68274. boundingBox = boundingBox.clone();
  68275. containsPoints.forEach(point => {
  68276. boundingBox.expandByPoint(point);
  68277. });
  68278. boundSize = boundingBox.getSize(new Vector3());
  68279. center = boundingBox.getCenter(new Vector3());
  68280. }
  68281. return {
  68282. boundSize,
  68283. boundCenter: center
  68284. };
  68285. }
  68286. getPosOutOfModel(viewport, boundSize) {
  68287. //let {boundSize, center} = viewer.bound
  68288. boundSize = boundSize || this.getViewBound(viewport).boundSize;
  68289. var expand = 10;
  68290. var radius = boundSize.length() * 2;
  68291. var position = viewport.shiftTarget.clone().sub(viewport.view.direction.clone().multiplyScalar(radius + expand));
  68292. return position;
  68293. }
  68294. updateCameraOutOfModel() {
  68295. //因为移动模型导致模型超出相机外,所以更新位置
  68296. viewer.viewports.forEach((viewport, i) => {
  68297. if (viewport.camera.isOrthographicCamera) {
  68298. //or if(viewport.targetPlane)
  68299. var {
  68300. boundSize,
  68301. boundCenter
  68302. } = this.getViewBound(viewport);
  68303. /* viewport.targetPlane.setFromNormalAndCoplanarPoint( viewport.view.direction.clone(), boundCenter)
  68304. viewport.targetPlane.projectPoint(viewport.view.position, viewport.shiftTarget) //target转换到过模型中心的平面,以保证镜头一定在模型外 this.shiftTarget是得到的
  68305. */
  68306. this.setShiftTarget(viewport, boundCenter);
  68307. var endPosition = this.getPosOutOfModel(viewport, boundSize);
  68308. //if(viewport.name == 'mapViewport')endPosition.z = Math.max(Potree.config.map.cameraHeight, endPosition.z)
  68309. viewport.view.position.copy(endPosition);
  68310. }
  68311. });
  68312. }
  68313. setShiftTarget(viewport, center) {
  68314. if (!viewport.targetPlane) {
  68315. viewport.targetPlane = new Plane();
  68316. viewport.shiftTarget = new Vector3(); //project在targetPlane上的位置
  68317. }
  68318. viewport.targetPlane.setFromNormalAndCoplanarPoint(viewport.view.direction, center);
  68319. viewport.targetPlane.projectPoint(viewport.view.position, viewport.shiftTarget); //target转换到过模型中心的平面,以保证镜头一定在模型外
  68320. }
  68321. rotateSideCamera(viewport, angle) {
  68322. //侧视图或俯视图绕模型中心水平旋转
  68323. //let {boundSize, center} = viewer.bound
  68324. var {
  68325. boundSize,
  68326. boundCenter
  68327. } = this.getViewBound(viewport);
  68328. var center = this.focusCenter || boundCenter; //旋转中心,一般是所有模型的中心,除非想指定中心点
  68329. this.setShiftTarget(viewport, center);
  68330. //找到平移向量
  68331. var vec = new Vector3().subVectors(center, viewport.shiftTarget); //相对于中心的偏移值,旋转后偏移值也旋转
  68332. //旋转
  68333. var rotMatrix = new Matrix4().makeRotationAxis(new Vector3(0, 0, 1), angle);
  68334. viewport.view.direction = viewport.view.direction.applyMatrix4(rotMatrix);
  68335. vec.applyMatrix4(rotMatrix);
  68336. viewport.shiftTarget.subVectors(center, vec); //新的
  68337. viewport.view.position = this.getPosOutOfModel(viewport, boundSize);
  68338. }
  68339. getOrthoCamera() {
  68340. var camera = new OrthographicCamera(-100, 100, 100, 100, 0.01, 10000);
  68341. camera.up.set(0, 0, 1);
  68342. return camera;
  68343. }
  68344. focusOnViewport(name) {
  68345. //全屏
  68346. viewer.viewports.forEach((viewport, i) => {
  68347. if (viewport.name == name) {
  68348. this.focusInfo = {
  68349. name,
  68350. left: viewport.left,
  68351. bottom: viewport.bottom,
  68352. height: viewport.height,
  68353. width: viewport.width
  68354. };
  68355. viewport.left = 0;
  68356. viewport.bottom = 0;
  68357. viewport.height = 1;
  68358. viewport.width = 1;
  68359. } else {
  68360. viewport.active = false;
  68361. }
  68362. });
  68363. viewer.updateScreenSize({
  68364. forceUpdateSize: true
  68365. });
  68366. }
  68367. unfocusViewport() {
  68368. if (!this.focusInfo) return;
  68369. viewer.viewports.forEach((viewport, i) => {
  68370. if (this.focusInfo.name == viewport.name) {
  68371. //全屏的恢复
  68372. viewport.left = this.focusInfo.left;
  68373. viewport.bottom = this.focusInfo.bottom;
  68374. viewport.height = this.focusInfo.height;
  68375. viewport.width = this.focusInfo.width;
  68376. }
  68377. viewport.active = true;
  68378. });
  68379. viewer.updateScreenSize({
  68380. forceUpdateSize: true
  68381. });
  68382. this.focusInfo = null;
  68383. }
  68384. }
  68385. var FEET_TO_INCHES_FACTOR = 12;
  68386. var EIGHTHS_SYMBOLS = ["", "⅛", "¼", "⅜", "½", "⅝", "¾", "⅞"]; //eighths 八分之……
  68387. class UnitOfMeasurement {
  68388. //转化单位工具
  68389. constructor(t, e, n, i) {
  68390. this.name = t, this.symbol = e, this.base = n, this.factor = i;
  68391. }
  68392. toBase(t) {
  68393. //换算到base
  68394. return t * this.factor;
  68395. }
  68396. fromBase(t) {
  68397. //换算到当前
  68398. return t / this.factor;
  68399. }
  68400. }
  68401. /* var o = function t(e) {
  68402. this.gettext = e,
  68403. t.METRIC = this.gettext("metric", void 0, "measurement system"),
  68404. t.IMPERIAL = this.gettext("imperial", void 0, "measurement system")
  68405. };
  68406. e.UoMSystem = o;
  68407. let UoMSystem = {
  68408. } */
  68409. /* var MeasurementDomain = {
  68410. DISTANCE : "DISTANCE",
  68411. t.AREA = "AREA",
  68412. t.VOLUME = "VOLUME",
  68413. t.DATA = "DATA",
  68414. t
  68415. }
  68416. */
  68417. var UnitsOfMeasurement = {
  68418. MILLIMETER: ["Millimeter", "mm"],
  68419. CENTIMETER: ["Centimeter", "cm"],
  68420. METER: ["Meter", "m"],
  68421. KILOMETER: ["Kilometer", "km"],
  68422. INCH: ["Inch", "in"],
  68423. FOOT: ["Foot", "ft"],
  68424. MILE: ["Mile", "mi"],
  68425. SQUAREMETER: ["SquareMeter", "m²"],
  68426. SQUAREFOOT: ["SquareFoot", "ft²"],
  68427. CUBICMETER: ["CubicMeter", "m³"],
  68428. CUBICFOOT: ["CubicFoot", "ft³"],
  68429. BYTE: ["Byte", "B"],
  68430. KILOBYTE: ["Kilobyte", "kB"],
  68431. MEGABYTE: ["Megabyte", "MB"],
  68432. GIGABYTE: ["Gigabyte", "GB"],
  68433. TERABYTE: ["Terabyte", "TB"],
  68434. PETABYTE: ["Petabyte", "PB"],
  68435. init: function init() {
  68436. var e,
  68437. n,
  68438. i,
  68439. a,
  68440. s,
  68441. c,
  68442. l,
  68443. u,
  68444. d,
  68445. p,
  68446. h,
  68447. f = new UnitOfMeasurement(UnitsOfMeasurement.METER[0], UnitsOfMeasurement.METER[1], void 0, 1),
  68448. g = new UnitOfMeasurement(UnitsOfMeasurement.SQUAREMETER[0], UnitsOfMeasurement.SQUAREMETER[1], void 0, 1),
  68449. m = new UnitOfMeasurement(UnitsOfMeasurement.CUBICMETER[0], UnitsOfMeasurement.CUBICMETER[1], void 0, 1),
  68450. v = new UnitOfMeasurement(UnitsOfMeasurement.BYTE[0], UnitsOfMeasurement.BYTE[1], void 0, 1);
  68451. UnitsOfMeasurement.DISTANCE = ((e = {})['metric'] = ((n = {})[UnitsOfMeasurement.MILLIMETER[0]] = new UnitOfMeasurement(UnitsOfMeasurement.MILLIMETER[0], UnitsOfMeasurement.MILLIMETER[1], f, .001), n[UnitsOfMeasurement.CENTIMETER[0]] = new UnitOfMeasurement(UnitsOfMeasurement.CENTIMETER[0], UnitsOfMeasurement.CENTIMETER[1], f, .01), n[UnitsOfMeasurement.METER[0]] = f, n[UnitsOfMeasurement.KILOMETER[0]] = new UnitOfMeasurement(UnitsOfMeasurement.KILOMETER[0], UnitsOfMeasurement.KILOMETER[1], f, 1e3), n), e['imperial'] = ((i = {})[UnitsOfMeasurement.INCH[0]] = new UnitOfMeasurement(UnitsOfMeasurement.INCH[0], UnitsOfMeasurement.INCH[1], f, .0254), i[UnitsOfMeasurement.FOOT[0]] = new UnitOfMeasurement(UnitsOfMeasurement.FOOT[0], UnitsOfMeasurement.FOOT[1], f, .3048), i[UnitsOfMeasurement.MILE[0]] = new UnitOfMeasurement(UnitsOfMeasurement.MILE[0], UnitsOfMeasurement.MILE[1], f, 1609.344), i), e);
  68452. UnitsOfMeasurement.AREA = ((a = {})['metric'] = ((s = {})[UnitsOfMeasurement.SQUAREMETER[0]] = g, s), a['imperial'] = ((c = {})[UnitsOfMeasurement.SQUAREFOOT[0]] = new UnitOfMeasurement(UnitsOfMeasurement.SQUAREFOOT[0], UnitsOfMeasurement.SQUAREFOOT[1], g, .092903), c), a);
  68453. UnitsOfMeasurement.VOLUME = ((l = {})['metric'] = ((u = {})[UnitsOfMeasurement.CUBICMETER[0]] = m, u), l['imperial'] = ((d = {})[UnitsOfMeasurement.CUBICFOOT[0]] = new UnitOfMeasurement(UnitsOfMeasurement.CUBICFOOT[0], UnitsOfMeasurement.CUBICFOOT[1], m, .0283168), d), l);
  68454. //数据大小
  68455. var y = ((p = {})[UnitsOfMeasurement.BYTE[0]] = v, p[UnitsOfMeasurement.KILOBYTE[0]] = new UnitOfMeasurement(UnitsOfMeasurement.KILOBYTE[0], UnitsOfMeasurement.KILOBYTE[1], v, 1e3), p[UnitsOfMeasurement.MEGABYTE[0]] = new UnitOfMeasurement(UnitsOfMeasurement.MEGABYTE[0], UnitsOfMeasurement.MEGABYTE[1], v, 1e6), p[UnitsOfMeasurement.GIGABYTE[0]] = new UnitOfMeasurement(UnitsOfMeasurement.GIGABYTE[0], UnitsOfMeasurement.GIGABYTE[1], v, 1e9), p[UnitsOfMeasurement.TERABYTE[0]] = new UnitOfMeasurement(UnitsOfMeasurement.TERABYTE[0], UnitsOfMeasurement.TERABYTE[1], v, 1e12), p[UnitsOfMeasurement.PETABYTE[0]] = new UnitOfMeasurement(UnitsOfMeasurement.PETABYTE[0], UnitsOfMeasurement.PETABYTE[1], v, 1e15), p);
  68456. UnitsOfMeasurement.DATA = ((h = {})['metric'] = y, h['imperial'] = y, h);
  68457. },
  68458. getUnitsOfMeasurementByDomain: function getUnitsOfMeasurementByDomain(e) {
  68459. return this[e.toUpperCase()];
  68460. /* switch (e.toUpperCase()) {
  68461. case a.DISTANCE:
  68462. return t.DISTANCE;
  68463. case a.AREA:
  68464. return t.AREA;
  68465. case a.VOLUME:
  68466. return t.VOLUME;
  68467. case a.DATA:
  68468. return t.DATA;
  68469. default:
  68470. console.error(e + " measurement domain is not supported.")
  68471. } */
  68472. },
  68473. getUnitsOfMeasurementByDomainAndSystem: function getUnitsOfMeasurementByDomainAndSystem(domain, system) {
  68474. var r = this.getUnitsOfMeasurementByDomain(domain);
  68475. if (r.hasOwnProperty(system.toLowerCase())) return r[system.toLowerCase()];
  68476. console.error(n + " measurement system is not supported.");
  68477. },
  68478. getDefaultUnitByDomainAndSystem: function getDefaultUnitByDomainAndSystem(e, n) {
  68479. switch (e.toUpperCase()) {
  68480. case 'DISTANCE':
  68481. switch (n.toLowerCase()) {
  68482. case 'metric':
  68483. return this.DISTANCE['metric'][this.METER[0]];
  68484. case 'imperial':
  68485. return this.DISTANCE['imperial'][this.FOOT[0]];
  68486. default:
  68487. console.error(n + " measurement system is not supported.");
  68488. }
  68489. case 'AREA':
  68490. switch (n.toLowerCase()) {
  68491. case 'metric':
  68492. return this.AREA['metric'][this.SQUAREMETER[0]];
  68493. case 'imperial':
  68494. return this.AREA['imperial'][this.SQUAREFOOT[0]];
  68495. default:
  68496. console.error(n + " measurement system is not supported.");
  68497. }
  68498. case 'VOLUME':
  68499. switch (n.toLowerCase()) {
  68500. case 'metric':
  68501. return this.VOLUME['metric'][this.CUBICMETER[0]];
  68502. case 'imperial':
  68503. return this.VOLUME['imperial'][this.CUBICFOOT[0]];
  68504. default:
  68505. console.error(n + " measurement system is not supported.");
  68506. }
  68507. case 'DATA':
  68508. switch (n.toLowerCase()) {
  68509. case 'metric':
  68510. return this.DATA['metric'][this.BYTE[0]];
  68511. case 'imperial':
  68512. return this.DATA['imperial'][this.BYTE[0]];
  68513. default:
  68514. console.error(n + " measurement system is not supported.");
  68515. }
  68516. default:
  68517. console.error(e + " measurement domain is not supported.");
  68518. }
  68519. }
  68520. };
  68521. class UnitService {
  68522. constructor( /* e, n, i */
  68523. ) {
  68524. //this.LanguageService = e,
  68525. //this.localStorageService = n,
  68526. //this.gettext = i,
  68527. //this.unitChanged = new r.Signal,
  68528. this.LOCAL_STORAGE_KEY = "iv_unit_key"; //?
  68529. UnitsOfMeasurement.init();
  68530. this.unitSystems = ['metric', 'imperial']; //[o.UoMSystem.METRIC, o.UoMSystem.IMPERIAL],
  68531. this.defaultSystem = 'metric'; //'imperial'
  68532. //var a = this.LanguageService.getBrowserLocaleString().toLowerCase();
  68533. //this.defaultSystem = t.isLocaleImperial(a) ? o.UoMSystem.IMPERIAL : o.UoMSystem.METRIC,
  68534. //this.initUnit()
  68535. }
  68536. /* initUnit() {
  68537. var t = this.localStorageService.get(this.LOCAL_STORAGE_KEY);
  68538. if (t)
  68539. for (var e = 0, n = this.unitSystems; e < n.length; e++) {
  68540. var i = n[e];
  68541. if (i === t)
  68542. return void this.setUnit(i, !0)
  68543. }
  68544. this.setUnit(this.defaultSystem, !1)
  68545. }
  68546. setUnit(t, e) {
  68547. this.currentSystem !== t && (this.currentSystem = t,
  68548. this.unitChanged.emit()),
  68549. e && this.localStorageService.set(this.LOCAL_STORAGE_KEY, t)
  68550. } */
  68551. /*isLocaleImperial(e) {
  68552. return t.IMPERIAL_LOCALES.indexOf(e.toLowerCase()) >= 0
  68553. }
  68554. ,
  68555. t.IMPERIAL_LOCALES = ["en_us"],
  68556. t.ɵfac(e) {
  68557. return new (e || t)(c.ɵɵinject(l.LanguageService),
  68558. c.ɵɵinject("localStorageService"),c.ɵɵinject("gettext"))
  68559. }
  68560. ,
  68561. t.ɵprov = c.ɵɵdefineInjectable({
  68562. token: t,
  68563. factory: t.ɵfac,
  68564. providedIn: "root"
  68565. }), */
  68566. }
  68567. class UoMService {
  68568. constructor( /* UnitService */
  68569. ) {
  68570. this.UnitService = new UnitService(); /* UnitService */
  68571. }
  68572. scopedConvert(t, n) {
  68573. var precision = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2;
  68574. var r = arguments.length > 3 ? arguments[3] : undefined;
  68575. var minFactor = arguments.length > 4 ? arguments[4] : undefined;
  68576. return this.convert(t, n, precision, r, minFactor);
  68577. }
  68578. convert(number, domain) {
  68579. var precision = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2;
  68580. var system = arguments.length > 3 ? arguments[3] : undefined;
  68581. var ifEighths = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : !1;
  68582. var o /* minFactor, ifRestrict */ = arguments.length > 5 ? arguments[5] : undefined;
  68583. var {
  68584. minFactor,
  68585. restrictUnit
  68586. } = o[system];
  68587. //if (!number) return "";
  68588. var s = this.getMostRelevantMeasurement(domain, system || this.UnitService.currentSystem, number, minFactor, restrictUnit);
  68589. return this.getFormattedMeasurementString(s[0], s[1], precision, ifEighths);
  68590. }
  68591. convertBack(number, domain) {
  68592. var precision = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2;
  68593. var fromSystem = arguments.length > 3 ? arguments[3] : undefined;
  68594. var minFactor = arguments.length > 4 ? arguments[4] : undefined;
  68595. //从英制转到'metric'
  68596. if (!number) return "";
  68597. var d = UnitsOfMeasurement.getDefaultUnitByDomainAndSystem(domain, 'metric');
  68598. var s = this.getMostRelevantMeasurement2(domain, fromSystem, number, minFactor);
  68599. return this.getFormattedMeasurementString(s[0], d, precision);
  68600. /* 栗子:
  68601. viewer.unitConvert.convertBack(1, 'area', 5, 'imperial')
  68602. '0.09290 m²'
  68603. viewer.unitConvert.convertBack(1, 'Distance', 2, 'imperial')
  68604. '0.03 m'
  68605. */
  68606. }
  68607. getFormattedMeasurementString(number, unit, precision, ifEighths) {
  68608. var result;
  68609. if (ifEighths && unit.name === UnitsOfMeasurement.FOOT[0]) {
  68610. result = this.formatImperialDistance(number * FEET_TO_INCHES_FACTOR);
  68611. } else if (ifEighths && unit.name === UnitsOfMeasurement.INCH[0]) {
  68612. result = this.formatImperialDistance(number);
  68613. } else {
  68614. result = number.toLocaleString(void 0, {
  68615. minimumFractionDigits: precision,
  68616. maximumFractionDigits: precision
  68617. }) + " " + unit.symbol;
  68618. }
  68619. return result;
  68620. }
  68621. formatImperialDistance(e) {
  68622. var n = Math.round(8 * e),
  68623. i = Math.floor(n / 8),
  68624. r = Math.floor(i / FEET_TO_INCHES_FACTOR),
  68625. o = i - r * FEET_TO_INCHES_FACTOR,
  68626. a = EIGHTHS_SYMBOLS[Math.abs(n % 8)],
  68627. s = 0 === o && "" !== a ? "" : o;
  68628. "" !== s && "" !== a && (a = " " + a);
  68629. return 0 !== r ? r + "' " + s + a + '"' : "" + s + a + '"';
  68630. }
  68631. getMostRelevantMeasurement(domain, system, number) {
  68632. var minFactor = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
  68633. var restrictUnit = arguments.length > 4 ? arguments[4] : undefined;
  68634. /* var a = r.values(UnitsOfMeasurement.getUnitsOfMeasurementByDomainAndSystem(domain, system))
  68635. , s = r.filter(a, function(t) {
  68636. return t.factor >= i
  68637. })
  68638. , c = r.reduce(s, function(t, e) {
  68639. return e.fromBase(number) < t.fromBase(number) && e.fromBase(number) >= 1 ? e : t
  68640. }); */
  68641. var a = [];
  68642. var u = UnitsOfMeasurement.getUnitsOfMeasurementByDomainAndSystem(domain, system);
  68643. for (var i in u) {
  68644. a.push(u[i]);
  68645. }
  68646. var s = a;
  68647. if (s.length > 1) {
  68648. if (restrictUnit) {
  68649. //是否只用这一单位,如只用mm。如果不是,就会寻找最大的接近的单位,如设置最小为mmminFactor=0.001),则1.2米时是'1.2m'、0.2米时是'20cm'、0.002米时是'2mm'
  68650. s = a.filter(m => m.name == restrictUnit);
  68651. } else {
  68652. s = a.filter(m => m.factor >= minFactor);
  68653. }
  68654. }
  68655. var c = s.reduce(function (prev, currentValue) {
  68656. //reduce最终值是最后一次return的值 ( 没看懂这句话作用)
  68657. return currentValue.fromBase(number) < prev.fromBase(number) && currentValue.fromBase(number) >= 1 ? currentValue : prev;
  68658. });
  68659. return c ? [c.fromBase(number), c] : void 0;
  68660. }
  68661. getMostRelevantMeasurement2(domain, system, number) {
  68662. var minFactor = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
  68663. //add
  68664. var a = [];
  68665. var u = UnitsOfMeasurement.getUnitsOfMeasurementByDomainAndSystem(domain, system);
  68666. for (var i in u) {
  68667. a.push(u[i]);
  68668. }
  68669. var s = a.filter(m => m.factor >= minFactor);
  68670. var c = s.reduce(function (prev, currentValue) {
  68671. //reduce最终值是最后一次return的值 ( 没看懂这句话作用)
  68672. return currentValue.toBase(number) < prev.toBase(number) && currentValue.toBase(number) >= 1 ? currentValue : prev;
  68673. });
  68674. return c ? [c.toBase(number), c] : void 0;
  68675. }
  68676. /* ɵfac(e){
  68677. return new (e || t)(c.ɵɵinject(l.UnitService))
  68678. }
  68679. ɵprov = c.ɵɵdefineInjectable({
  68680. token: t,
  68681. factory: t.ɵfac,
  68682. providedIn: "root"
  68683. }) */
  68684. }
  68685. var texLoader$8 = new TextureLoader();
  68686. var color$1 = new Color(config$1.clip.color);
  68687. var markerMats$1;
  68688. var markerSizeInfo$1 = {
  68689. width2d: 40
  68690. };
  68691. var pickOrders = {
  68692. marker: 1,
  68693. area: 0
  68694. };
  68695. class mapClipBox extends ctrlPolygon {
  68696. constructor(center, scale) {
  68697. center = center.clone().setZ(0); //所有Z都为0
  68698. var prop = {
  68699. points: getPoints(center, scale, 0),
  68700. closed: true,
  68701. atPlane: true,
  68702. isRect: true,
  68703. dimension: '2d'
  68704. };
  68705. super('mapClipBox', prop);
  68706. this.angle = 0;
  68707. this.createRotateBar();
  68708. this.edgeMarkers = [];
  68709. //addMarkers:
  68710. this.initData(prop);
  68711. {
  68712. //areaPlane event 能拖动
  68713. this.areaPlane.addEventListener('mouseover', () => {
  68714. viewer.dispatchEvent({
  68715. type: "CursorChange",
  68716. action: "add",
  68717. name: "mapClipMove"
  68718. });
  68719. });
  68720. this.areaPlane.addEventListener('mouseleave', () => {
  68721. viewer.dispatchEvent({
  68722. type: "CursorChange",
  68723. action: "remove",
  68724. name: "mapClipMove"
  68725. });
  68726. });
  68727. var lastPos;
  68728. var drag = e => {
  68729. var intersect = e.intersect.orthoIntersect;
  68730. if (lastPos) {
  68731. var moveVec = new Vector3().subVectors(intersect, lastPos).setZ(0);
  68732. this.center.add(moveVec);
  68733. this.updatePoints();
  68734. this.dispatchEvent({
  68735. type: 'repos'
  68736. });
  68737. }
  68738. lastPos = intersect.clone();
  68739. };
  68740. var drop = e => {
  68741. lastPos = null;
  68742. };
  68743. this.areaPlane.addEventListener('drag', drag);
  68744. this.areaPlane.addEventListener('drop', drop);
  68745. }
  68746. /* this.addEventListener('dragChange',()=>{
  68747. this.updateTwoMidMarker(index+1)
  68748. }) */
  68749. Potree.Utils.setObjectLayers(this, 'mapObjects');
  68750. }
  68751. getScale() {
  68752. return new Vector3(this.points[0].distanceTo(this.points[1]), this.points[1].distanceTo(this.points[2]), 1);
  68753. }
  68754. addMarker() {
  68755. var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  68756. var marker = new Sprite$2({
  68757. mat: this.getMarkerMaterial('default'),
  68758. pickOrder: pickOrders.marker,
  68759. sizeInfo: markerSizeInfo$1,
  68760. dontFixOrient: true,
  68761. viewports: viewer.mapViewer.viewports,
  68762. name: "mapClipBox_marker"
  68763. });
  68764. marker.renderOrder = 3;
  68765. //marker.markerSelectStates = {}
  68766. var edge = LineDraw.createLine([new Vector3(), new Vector3()], {
  68767. color: color$1
  68768. });
  68769. var edgeMarker = new Sprite$2({
  68770. mat: this.getMarkerMaterial('default'),
  68771. pickOrder: pickOrders.marker,
  68772. sizeInfo: markerSizeInfo$1,
  68773. dontFixOrient: true,
  68774. viewports: viewer.mapViewer.viewports,
  68775. name: "mapClipBox_edgePoint"
  68776. });
  68777. var mouseover = e => {
  68778. this.setMarkerSelected(e.object, true, 'single');
  68779. viewer.dispatchEvent({
  68780. type: "CursorChange",
  68781. action: "add",
  68782. name: "markerMove"
  68783. });
  68784. };
  68785. var mouseleave = e => {
  68786. this.setMarkerSelected(e.object, false, 'single');
  68787. viewer.dispatchEvent({
  68788. type: "CursorChange",
  68789. action: "remove",
  68790. name: "markerMove"
  68791. });
  68792. };
  68793. edgeMarker.addEventListener('mouseover', mouseover);
  68794. edgeMarker.addEventListener('mouseleave', mouseleave);
  68795. var dragInfo = {
  68796. lastPos: null
  68797. };
  68798. edgeMarker.addEventListener('drag', this.dragEdge.bind(this, dragInfo));
  68799. edgeMarker.addEventListener('drop', this.dropEdge.bind(this, dragInfo));
  68800. this.edgeMarkers.push(edgeMarker);
  68801. this.add(edgeMarker);
  68802. marker.dispatchEvent('addHoverEvent');
  68803. super.addMarker({
  68804. point: o.point,
  68805. marker: marker,
  68806. edge
  68807. });
  68808. }
  68809. dragEdge(dragInfo, e) {
  68810. //拖拽一个边(或一个边类型的marker),带动它的两个端点。 可以转化为拖拽marker往法线方向
  68811. var I, atMap;
  68812. atMap = e.dragViewport.name == 'mapViewport';
  68813. I = e.intersect.orthoIntersect;
  68814. if (I && dragInfo.lastPos) {
  68815. var i = this.edgeMarkers.indexOf(e.drag.object);
  68816. if (i !== -1) {
  68817. var lineNormal = math.getNormal2d({
  68818. p1: this.points[i],
  68819. p2: this.points[(i + 1) % 4]
  68820. });
  68821. var moveVec = new Vector3().subVectors(I, dragInfo.lastPos).setZ(0); //移动的向量
  68822. var dragVec = moveVec.projectOnVector(lineNormal).setZ(0); //在法线上移动的向量
  68823. var newPos = new Vector3().addVectors(this.points[i], dragVec); //marker应到的位置
  68824. this.dragChange(newPos, i, atMap); //转化为这个marker的拖拽
  68825. }
  68826. }
  68827. dragInfo.lastPos = I.clone();
  68828. }
  68829. dropEdge(dragInfo, e) {
  68830. dragInfo.lastPos = null;
  68831. this.setMarkerSelected(e.drag.object, false, 'single'); //拖拽时似乎没有触发mouseout
  68832. }
  68833. createAreaPlane() {
  68834. var planeMat = new MeshBasicMaterial({
  68835. color: color$1,
  68836. //"#00eeff",
  68837. side: DoubleSide,
  68838. opacity: 0.3,
  68839. transparent: true,
  68840. depthTest: false
  68841. });
  68842. return super.createAreaPlane(planeMat);
  68843. }
  68844. getMarkerMaterial(type) {
  68845. if (!markerMats$1) {
  68846. markerMats$1 = {
  68847. default: new MeshBasicMaterial({
  68848. transparent: !0,
  68849. color: color$1,
  68850. opacity: 0.8,
  68851. map: texLoader$8.load(Potree.resourcePath + '/textures/whiteCircle.png')
  68852. }),
  68853. select: new MeshBasicMaterial({
  68854. transparent: !0,
  68855. color: color$1,
  68856. opacity: 1,
  68857. map: texLoader$8.load(Potree.resourcePath + '/textures/whiteCircle.png')
  68858. })
  68859. };
  68860. mapClipBox.markerMats = markerMats$1;
  68861. }
  68862. return markerMats$1[type];
  68863. }
  68864. setMarkerSelected(marker, state, hoverObject) {
  68865. //console.warn(marker.id , state, hoverObject)
  68866. if (state == 'hover') {
  68867. marker.material = this.getMarkerMaterial('select');
  68868. } else {
  68869. marker.material = this.getMarkerMaterial('default');
  68870. }
  68871. /* marker.markerSelectStates[hoverObject] = state
  68872. let absoluteState = false
  68873. for(var i in marker.markerSelectStates){
  68874. if(marker.markerSelectStates[i]){
  68875. absoluteState = true; break;
  68876. }
  68877. }
  68878. if(absoluteState){
  68879. marker.material = this.getMarkerMaterial('select')
  68880. }else{
  68881. marker.material = this.getMarkerMaterial('default')
  68882. }
  68883. marker.selected = absoluteState */
  68884. viewer.mapViewer.dispatchEvent('content_changed');
  68885. }
  68886. createRotateBar() {
  68887. //中心点在线的一端,整体初始在box上方
  68888. var lineLen = 1.5,
  68889. circleWidth = 2,
  68890. barOpacity = 0.7;
  68891. var object = new Object3D();
  68892. var bar = new Sprite$2({
  68893. mat: new MeshBasicMaterial({
  68894. side: DoubleSide,
  68895. opacity: barOpacity,
  68896. transparent: true,
  68897. depthTest: false,
  68898. map: texLoader$8.load(Potree.resourcePath + '/textures/rotation_circle.png')
  68899. }),
  68900. root: object,
  68901. sizeInfo: markerSizeInfo$1,
  68902. dontFixOrient: true,
  68903. viewports: viewer.mapViewer.viewports,
  68904. name: "mapClipRotateBar"
  68905. });
  68906. bar.position.set(0, lineLen + circleWidth / 2, 0);
  68907. bar.scale.set(circleWidth, circleWidth, circleWidth);
  68908. bar.addEventListener('mouseover', () => {
  68909. bar.material.opacity = 1;
  68910. viewer.dispatchEvent({
  68911. type: "CursorChange",
  68912. action: "add",
  68913. name: "mapClipRotate"
  68914. });
  68915. viewer.mapViewer.dispatchEvent('content_changed');
  68916. });
  68917. var leave = () => {
  68918. bar.material.opacity = barOpacity;
  68919. viewer.dispatchEvent({
  68920. type: "CursorChange",
  68921. action: "remove",
  68922. name: "mapClipRotate"
  68923. });
  68924. viewer.mapViewer.dispatchEvent('content_changed');
  68925. };
  68926. bar.addEventListener('mouseleave', leave);
  68927. this.addEventListener('dispose', leave);
  68928. var lastPos;
  68929. bar.addEventListener('drag', e => {
  68930. var intersect = e.intersect.orthoIntersect;
  68931. if (lastPos) {
  68932. var vec1 = new Vector3().subVectors(lastPos, this.center).setZ(0);
  68933. var vec2 = new Vector3().subVectors(intersect, this.center).setZ(0);
  68934. var angle = math.getAngle(vec1, vec2, 'z');
  68935. this.angle += angle;
  68936. this.rotateBar.rotation.z = this.angle;
  68937. this.updatePoints();
  68938. this.dispatchEvent({
  68939. type: 'rotate',
  68940. angle: this.angle
  68941. });
  68942. }
  68943. lastPos = intersect.clone();
  68944. });
  68945. bar.addEventListener('drop', () => {
  68946. lastPos = null;
  68947. viewer.dispatchEvent({
  68948. type: "CursorChange",
  68949. action: "remove",
  68950. name: "mapClipRotate"
  68951. });
  68952. });
  68953. var line = LineDraw.createLine([new Vector3(), new Vector3(0, lineLen, 0)], {
  68954. color: color$1
  68955. });
  68956. object.add(bar);
  68957. object.add(line);
  68958. this.add(object);
  68959. this.rotateBar = object;
  68960. this.rotateBar.bar = bar;
  68961. }
  68962. updatePoints(scale) {
  68963. this.points = getPoints(this.center, scale || this.getScale(), this.angle);
  68964. this.getPoint2dInfo(this.points);
  68965. this.update({
  68966. ifUpdateMarkers: true
  68967. });
  68968. }
  68969. update() {
  68970. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  68971. super.update(options);
  68972. {
  68973. //update rotateBar
  68974. var center = new Vector3().addVectors(this.points[0], this.points[1]).multiplyScalar(0.5);
  68975. this.rotateBar.position.copy(center);
  68976. this.rotateBar.bar.waitUpdate(); //更新sprite matrix
  68977. }
  68978. {
  68979. for (var i = 0; i < 4; i++) {
  68980. var current = this.points[i];
  68981. var next = this.points[(i + 1) % 4];
  68982. var mid = new Vector3().addVectors(current, next).multiplyScalar(0.5);
  68983. this.updateMarker(this.edgeMarkers[i], mid);
  68984. }
  68985. }
  68986. }
  68987. dispose() {
  68988. super.dispose();
  68989. this.dispatchEvent('dispose');
  68990. this.rotateBar.bar.dispose();
  68991. }
  68992. }
  68993. function getPoints(center, scale) {
  68994. var angle = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  68995. var points = [new Vector3(-scale.x / 2, +scale.y / 2, 0), new Vector3(+scale.x / 2, +scale.y / 2, 0), new Vector3(+scale.x / 2, -scale.y / 2, 0), new Vector3(-scale.x / 2, -scale.y / 2, 0)];
  68996. var rotMatrix = new Matrix4().makeRotationAxis(new Vector3(0, 0, 1), angle); //再旋转
  68997. points.forEach(e => {
  68998. e.applyMatrix4(rotMatrix);
  68999. e.add(center);
  69000. });
  69001. return points;
  69002. }
  69003. var defaultBoxWidth = 16; //navvis: 10
  69004. //navvis position: si {x: 0, y: 0, z: 0}
  69005. var cameraProps = [{
  69006. name: 'top',
  69007. axis: ["x", "y"],
  69008. direction: new Vector3(0, 0, -1),
  69009. //镜头朝向
  69010. openCount: 0
  69011. }, {
  69012. name: 'front',
  69013. axis: ["x", "z"],
  69014. direction: new Vector3(0, 1, 0),
  69015. openCount: 0
  69016. }, {
  69017. name: 'mainView',
  69018. openCount: 0
  69019. }];
  69020. var Clip = {
  69021. bus: new EventDispatcher(),
  69022. selectedDatasets: [],
  69023. changeCallback(force) {
  69024. if (this.activeViewName != 'mainView') {
  69025. this.splitScreenTool.updateCameraOutOfModel(); //更新相机位置
  69026. }
  69027. if (Potree.settings.isOfficial && this.showMap) {
  69028. var fun = () => {
  69029. var pointclouds = this.getIntersectPointcloud();
  69030. if (Common.getDifferenceSet(pointclouds, this.selectedDatasets).length) {
  69031. this.selectedDatasets = pointclouds;
  69032. //console.error('clipSelectedDatasets',selectedDatasets)
  69033. this.bus.dispatchEvent({
  69034. type: 'updateSelectedDatasets',
  69035. selectedDatasets: pointclouds.map(e => e.dataset_id)
  69036. });
  69037. }
  69038. };
  69039. if (force) fun();else Common.intervalTool.isWaiting('clipSelectedDatasets', fun, 300);
  69040. }
  69041. },
  69042. enter: function enter() {
  69043. this.initViews();
  69044. this.previousView = {
  69045. position: viewer.images360.position,
  69046. target: viewer.scene.view.getPivot(),
  69047. displayMode: Potree.settings.displayMode,
  69048. //---
  69049. ifShowMarker: Potree.settings.ifShowMarker
  69050. };
  69051. var pointcloud = this.getPointcloud();
  69052. var bound = pointcloud.bound; //只选取其中一个数据集的bound,而非整体,是因为担心两个数据集中间有空隙,于是刚好落在没有点云的地方。
  69053. var boundSize = bound.getSize(new Vector3());
  69054. var target = this.getTarget(bound.getCenter(new Vector3())); //navvis的位置xy是用相机位置 this.ViewService.mainView.getCamera().position 我觉得也可以用第一个漫游点的,或者最接近bound中心的漫游点
  69055. var scale = new Vector3(defaultBoxWidth, defaultBoxWidth, boundSize.z); //z和navvis一样
  69056. var eyeDir = viewer.scene.view.direction.clone().setZ(0 /* -boundSize.z/3 */).multiplyScalar(-defaultBoxWidth); //为了使所在楼层不变,不修改z
  69057. //let eyeDir = scale.clone().setZ(boundSize.z/3).multiplyScalar(1.3)
  69058. var position = new Vector3().addVectors(target, eyeDir);
  69059. Potree.settings.displayMode = 'showPointCloud';
  69060. viewer.setView({
  69061. position,
  69062. target,
  69063. duration: 300,
  69064. callback: function callback() {}
  69065. });
  69066. //viewer.setControls(viewer.orbitControls);
  69067. viewer.setLimitFar(false);
  69068. //viewer.setClipState(false) //暂时关闭旧的clipping
  69069. /* new AxisViewer(viewer.mainViewport, viewer.renderArea,{domStyle:{
  69070. bottom: '2px',right: '20px', width:'80px',height:'80px'}
  69071. }) */
  69072. {
  69073. this.box = new BoxVolume$1({
  69074. clip: true
  69075. });
  69076. this.box.clipTask = ClipTask['SHOW_INSIDE_Big' /* "SHOW_INSIDE" */];
  69077. this.box.showBox = false;
  69078. this.box.name = "ClipBox";
  69079. this.box.position.copy(target);
  69080. this.box.scale.copy(scale);
  69081. viewer.controls.setTarget(this.box.position); //绕其旋转
  69082. this.splitScreenTool.focusCenter = this.box.position;
  69083. //带动mapBox
  69084. this.box.addEventListener('position_changed', e => {
  69085. if (this.showMap) {
  69086. this.mapBox.center.setX(this.box.position.x);
  69087. this.mapBox.center.setY(this.box.position.y);
  69088. this.mapBox.updatePoints();
  69089. }
  69090. this.changeCallback();
  69091. });
  69092. this.box.addEventListener('scale_changed', e => {
  69093. if (this.showMap) {
  69094. var scale = this.box.scale;
  69095. this.mapBox.updatePoints(scale);
  69096. }
  69097. this.changeCallback();
  69098. });
  69099. this.box.addEventListener('orientation_changed', e => {
  69100. if (this.showMap) {
  69101. this.mapBox.angle = this.box.rotation.z;
  69102. this.mapBox.rotateBar.rotation.z = this.mapBox.angle;
  69103. this.mapBox.updatePoints();
  69104. }
  69105. this.changeCallback();
  69106. });
  69107. viewer.scene.addVolume(this.box);
  69108. }
  69109. if (this.showMap) {
  69110. //map
  69111. var boxRotateBack = () => {
  69112. //不知道是不是这么写。 因为可能z的旋转不一定都在z
  69113. this.box.rotation.x = 0;
  69114. this.box.rotation.y = 0;
  69115. };
  69116. this.mapBox = new mapClipBox(target, scale);
  69117. viewer.mapViewer.scene.add(this.mapBox);
  69118. //带动box
  69119. this.mapBox.addEventListener('repos', e => {
  69120. this.box.position.setX(this.mapBox.center.x);
  69121. this.box.position.setY(this.mapBox.center.y);
  69122. boxRotateBack();
  69123. this.changeCallback();
  69124. });
  69125. this.mapBox.addEventListener('dragChange', e => {
  69126. var scale = this.mapBox.getScale();
  69127. this.box.scale.setX(scale.x);
  69128. this.box.scale.setY(scale.y);
  69129. this.box.position.setX(this.mapBox.center.x);
  69130. this.box.position.setY(this.mapBox.center.y);
  69131. boxRotateBack();
  69132. this.changeCallback();
  69133. });
  69134. this.mapBox.addEventListener('rotate', e => {
  69135. this.box.rotation.z = this.mapBox.angle;
  69136. boxRotateBack();
  69137. this.changeCallback();
  69138. });
  69139. }
  69140. this.switchView('mainView');
  69141. {
  69142. //viewer.setClipTask(ClipTask["SHOW_INSIDE"])
  69143. }
  69144. Potree.settings.unableNavigate = true;
  69145. Potree.settings.ifShowMarker = false;
  69146. Potree.Utils.updateVisible(viewer.measuringTool.scene, 'clipModel', false);
  69147. //Potree.Utils.updateVisible(viewer.mapViewer.cursor, 'clipModel', false)//隐藏地图游标
  69148. viewer.inputHandler.toggleSelection(this.box);
  69149. viewer.inputHandler.fixSelection = true;
  69150. viewer.transformationTool.setModeEnable(['scale', 'translation', 'rotation']);
  69151. viewer.transformationTool.frame.material.color.set(Potree.config.clip.color); //navvis 15899953
  69152. viewer.setPointStandardMat(true);
  69153. if (this.showMap) {
  69154. var mapVisi = false;
  69155. this.events = {
  69156. flyToPos: e => {
  69157. var dis = 2;
  69158. var target = e.position;
  69159. target = this.box.position;
  69160. position = e.position;
  69161. //为了方便缩放操作,直接使用box中心作为target
  69162. var duration = e.duration == void 0 ? 1000 : e.duration;
  69163. viewer.scene.view.setView({
  69164. position,
  69165. duration,
  69166. target
  69167. });
  69168. },
  69169. mapVisiChange(e) {
  69170. mapVisi = e.visible;
  69171. var delay = 100; //因resize了camera需要时间更新projectionMatrix
  69172. setTimeout(() => {
  69173. var boundingBox = Clip.box.boundingBox.clone().applyMatrix4(Clip.box.matrixWorld);
  69174. if (mapVisi) {
  69175. //切换地图
  69176. if (viewer.fpVisiDatasets.length == 0) {
  69177. //不会显示任何一个floorplan图,就要就近移动到一个可见数据集里
  69178. var clouds = viewer.scene.pointclouds.filter(e => e.visible);
  69179. if (clouds.length == 0) clouds = viewer.scene.pointclouds;
  69180. var scores = clouds.map((e, i) => {
  69181. return [-viewer.scene.view.position.distanceToSquared(e.bound2), i];
  69182. });
  69183. scores = scores.sort((a, b) => a[0] - b[0]);
  69184. var neareast = clouds[scores[0][1]];
  69185. viewer.flyToDataset({
  69186. pointcloud: neareast,
  69187. duration: 0
  69188. });
  69189. }
  69190. if (Clip.switchMapCount == 0 || !Potree.Utils.getPos2d(viewer.scene.view.position, viewer.mapViewer.viewports[0], viewer.mapViewer.renderArea).inSight || !Potree.Utils.isInsideFrustum(boundingBox, viewer.mapViewer.camera)) {
  69191. //要使box框和游标都在屏幕内。因为游标是3d的当前位置,很可能是准备去框住的位置
  69192. var _bound = boundingBox.clone();
  69193. _bound.expandByPoint(viewer.scene.view.position);
  69194. var size = _bound.getSize(new Vector3());
  69195. var center = _bound.getCenter(new Vector3());
  69196. var margin = viewer.mainViewport.resolution.clone().multiplyScalar(0.3);
  69197. viewer.mapViewer.moveTo(center, size, 100, margin);
  69198. }
  69199. Clip.switchMapCount++;
  69200. //关于究竟是focus box还是dataset有点纠结,又或是两个的union。box和数据集可能离得很远,且无法确定当前想选择的数据集,且数据集可能无floorplan, 即使有可能也不展示……
  69201. } else {
  69202. //切换3d
  69203. if (!Potree.Utils.isInsideFrustum(boundingBox, viewer.scene.getActiveCamera())) {
  69204. //屏幕上没有box的话
  69205. viewer.focusOnObject({
  69206. boundingBox
  69207. }, 'boundingBox', 100);
  69208. }
  69209. }
  69210. }, delay);
  69211. }
  69212. };
  69213. this.switchMapCount = 0;
  69214. this.bus.addEventListener('flyToPos', this.events.flyToPos);
  69215. viewer.mapViewer.addEventListener('forceVisible', this.events.mapVisiChange);
  69216. }
  69217. this.editing = true;
  69218. setTimeout(() => {
  69219. this.changeCallback(true);
  69220. }, 1);
  69221. },
  69222. leave: function leave() {
  69223. viewer.inputHandler.fixSelection = false;
  69224. viewer.scene.removeVolume(this.box);
  69225. this.showMap && this.mapBox.dispose();
  69226. //viewer.setControls(viewer.fpControls);
  69227. this.switchView('mainView');
  69228. Potree.settings.unableNavigate = false;
  69229. Potree.settings.ifShowMarker = this.previousView.ifShowMarker;
  69230. Potree.Utils.updateVisible(viewer.measuringTool.scene, 'clipModel', true);
  69231. //Potree.Utils.updateVisible(viewer.mapViewer.cursor, 'clipModel', true)
  69232. viewer.setView(this.previousView);
  69233. viewer.setLimitFar(true);
  69234. viewer.setPointStandardMat(false);
  69235. //viewer.setClipState(true)
  69236. viewer.controls.setTarget(null);
  69237. this.splitScreenTool.focusCenter = null;
  69238. //viewer.mainViewport.axis.dispose()
  69239. cameraProps.forEach(e => e.openCount = 0);
  69240. if (this.showMap) {
  69241. this.bus.removeEventListener('flyToPos', this.events.flyToPos);
  69242. viewer.mapViewer.removeEventListener('forceVisible', this.events.mapVisiChange);
  69243. this.events = null;
  69244. }
  69245. this.editing = false;
  69246. },
  69247. initViews() {
  69248. if (this.views) {
  69249. this.views.top.pitch = -Math.PI;
  69250. this.views.top.yaw = 0;
  69251. this.views.front.pitch = 0;
  69252. this.views.front.yaw = 0; //--还原for bugID 44757
  69253. return;
  69254. }
  69255. this.views = {};
  69256. this.cameras = {};
  69257. this.orthoCamera = new OrthographicCamera(-100, 100, 100, 100, 0.01, 10000);
  69258. this.orthoCamera.up.set(0, 0, 1);
  69259. this.splitScreenTool = new SplitScreen();
  69260. this.targetPlane = viewer.mainViewport.targetPlane = new Plane();
  69261. this.shiftTarget = viewer.mainViewport.shiftTarget = new Vector3(); //project在targetPlane上的位置
  69262. for (var i = 0; i < 2; i++) {
  69263. var prop = cameraProps[i];
  69264. var view = new ExtendView();
  69265. this.views[prop.name] = view;
  69266. this.cameras[prop.name] = this.orthoCamera;
  69267. view.name = prop.name;
  69268. view.direction = prop.direction;
  69269. }
  69270. this.views.mainView = viewer.mainViewport.view;
  69271. this.cameras.mainView = viewer.mainViewport.camera;
  69272. },
  69273. switchView(name) {
  69274. //替换view和camera到mainViewport
  69275. if (this.activeViewName == name) return;
  69276. var view = this.views[name];
  69277. var camera = this.cameras[name];
  69278. var prop = cameraProps.find(e => e.name == name);
  69279. var {
  69280. boundSize,
  69281. center,
  69282. boundingBox
  69283. } = viewer.bound;
  69284. this.lastViewName = this.activeViewName;
  69285. this.activeViewName = name;
  69286. var lastView = this.views[this.lastViewName];
  69287. var lastCamera = this.cameras[this.lastViewName];
  69288. viewer.mainViewport.view = view;
  69289. viewer.mainViewport.camera = camera;
  69290. if (lastCamera) lastView.zoom = lastCamera.zoom;
  69291. view.zoom && (camera.zoom = view.zoom);
  69292. viewer.updateScreenSize({
  69293. forceUpdateSize: true
  69294. }); //更新camera aspect left等
  69295. view.applyToCamera(camera);
  69296. var ifFocus;
  69297. var boxBound = Clip.box.boundingBox.clone().applyMatrix4(Clip.box.matrixWorld);
  69298. if (!Potree.Utils.isInsideFrustum(boxBound, camera)) {
  69299. //屏幕上没有box的话
  69300. ifFocus = true;
  69301. }
  69302. if (name == 'mainView') {
  69303. if (lastView) {//2d->3d
  69304. }
  69305. if (prop.openCount == 0) ifFocus = false;
  69306. //viewer.fpControls.lockKey = false
  69307. } else {
  69308. this.targetPlane.setFromNormalAndCoplanarPoint(view.direction.clone(), center);
  69309. this.targetPlane.projectPoint(view.position, this.shiftTarget); //target转换到过模型中心的平面,以保证镜头一定在模型外
  69310. //view.position.copy(this.splitScreenTool.getPosOutOfModel(viewer.mainViewport))
  69311. //if(view.zoom)camera.zoom = view.zoom//恢复上次的zoom
  69312. if (prop.openCount == 0) {
  69313. //至多执行一次
  69314. ifFocus = true;
  69315. }
  69316. if (this.lastViewName == 'mainView') {//3d->2d
  69317. } else {}
  69318. ifFocus || this.splitScreenTool.updateCameraOutOfModel(); //更新相机位置
  69319. //if(name == 'top') viewer.mainViewport.alignment = {rotate:true,translate:true};
  69320. if (name == 'front') {
  69321. //viewer.mainViewport.alignment = {translate:true, rotateSide:true, translateVec:new THREE.Vector3(0,0,1)}; //只能上下移动
  69322. viewer.mainViewport.rotateSide = true;
  69323. } else {
  69324. viewer.mainViewport.rotateSide = false;
  69325. }
  69326. //viewer.fpControls.lockKey = true
  69327. }
  69328. ifFocus && this.focusOnObject(this.box);
  69329. //首次到front最好能自动对准box的长边的角度上
  69330. prop.openCount++;
  69331. },
  69332. focusOnObject(box) {
  69333. var duration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  69334. if (this.activeViewName == 'mainView') {
  69335. viewer.focusOnObject({
  69336. boundingBox: box.boundingBox.clone().applyMatrix4(box.matrixWorld)
  69337. }, 'boundingBox', duration);
  69338. } else {
  69339. this.orthoMoveFit(box.position, {
  69340. bound: box.boundingBox.clone().applyMatrix4(box.matrixWorld)
  69341. }, duration);
  69342. }
  69343. },
  69344. transform(type, axis, value) {
  69345. //使用按键微调
  69346. this.box[type][axis] += value;
  69347. },
  69348. setModeEnable(type, enable) {
  69349. var modes = [];
  69350. ['scale', 'translation', 'rotation'].forEach(e => {
  69351. if (e == type) {
  69352. enable && modes.push(e);
  69353. } else {
  69354. viewer.transformationTool.modesEnabled[e] && modes.push(e);
  69355. }
  69356. });
  69357. viewer.transformationTool.setModeEnable(modes);
  69358. viewer.dispatchEvent('content_changed');
  69359. },
  69360. rotateSideCamera(angle) {
  69361. //侧视图绕模型中心水平旋转到的角度 angle: -180 ~ 180
  69362. var diff = MathUtils.degToRad(angle) - viewer.mainViewport.view.yaw;
  69363. this.splitScreenTool.rotateSideCamera(viewer.mainViewport, diff);
  69364. },
  69365. orthoMoveFit(pos, info, duration) {
  69366. var margin = {
  69367. x: viewer.mainViewport.resolution.x * 0.4,
  69368. y: viewer.mainViewport.resolution.y * 0.4
  69369. };
  69370. this.splitScreenTool.viewportFitBound(viewer.mainViewport, info.bound, pos, duration, margin);
  69371. },
  69372. getPointcloud: function getPointcloud() {
  69373. //找一个离当前最近的点云,且最好有漫游点
  69374. var pointclouds = viewer.scene.pointclouds.filter(e => e.panos.length > 0);
  69375. if (pointclouds.length == 0) pointclouds = viewer.scene.pointclouds;
  69376. var result = Common.sortByScore(pointclouds, [], [e => {
  69377. var center = e.bound.getCenter(new Vector3());
  69378. var size = e.bound.getSize(new Vector3()).length() / 2;
  69379. var posToCenter = viewer.images360.position.distanceTo(center);
  69380. return size / posToCenter;
  69381. }]);
  69382. return result[0].item;
  69383. },
  69384. getTarget: function getTarget(boundCenter) {
  69385. //box位置。要找一个有点云的地方。方案1相机位置, 方案2接近相机的漫游点, 方案3接近中心的漫游点。选择方案2,因最大概率有点云
  69386. var target = new Vector3();
  69387. var cameraPos = viewer.images360.position;
  69388. var pano = Common.find(viewer.images360.panos, [], [Images360.sortFunctions.floorDisSquaredToPoint(cameraPos)]);
  69389. if (pano) {
  69390. target.copy(pano.position);
  69391. target.setZ(boundCenter.z);
  69392. } else {
  69393. target.copy(boundCenter);
  69394. }
  69395. return target;
  69396. },
  69397. /* switchMap:function(state){
  69398. }, */
  69399. download: function download() {
  69400. if (this.getIntersectPointcloud().length == 0) {
  69401. return null;
  69402. }
  69403. var visiPointclouds = viewer.scene.pointclouds.filter(e => Potree.Utils.getObjVisiByReason(e, 'datasetSelection'));
  69404. visiPointclouds.sort((a, b) => {
  69405. return a.dataset_id - b.dataset_id;
  69406. }); //缓存需要固定排序好比较
  69407. var data = {
  69408. transformation_matrix: visiPointclouds.map(cloud => {
  69409. var data = {
  69410. id: cloud.dataset_id,
  69411. matrix: this.getTransformationMatrix(cloud).elements,
  69412. //剪裁大框
  69413. visiMatrixes: cloud.material.clipBoxes_in.map(e => this.getTransformationMatrix(cloud, e.inverse).elements),
  69414. //若干个可见型小框(虽然现在用不到了,因为普通界面不展示这些剪裁区域)
  69415. unVisiMatrixes: cloud.material.clipBoxes_out.map(e => this.getTransformationMatrix(cloud, e.inverse).elements),
  69416. //若干个不可见型小框
  69417. modelMatrix: new Matrix4().copy(cloud.transformMatrix).transpose().elements
  69418. };
  69419. return data;
  69420. }),
  69421. aabb: "b-0.5 -0.5 -0.5 0.5 0.5 0.5" //剪裁空间( 所有点在乘上这个矩阵后, 还能落在 1 * 1 * 1的box内的点就是所裁剪的
  69422. };
  69423. return data;
  69424. },
  69425. downloadNoCrop() {
  69426. //不剪裁 下载整个点云
  69427. var visiPointclouds = viewer.scene.pointclouds.filter(e => Potree.Utils.getObjVisiByReason(e, 'datasetSelection'));
  69428. visiPointclouds.sort((a, b) => {
  69429. return a.dataset_id - b.dataset_id;
  69430. }); //缓存需要固定排序好比较
  69431. var data = {
  69432. transformation_matrix: visiPointclouds.map(cloud => {
  69433. var data = {
  69434. id: cloud.dataset_id,
  69435. matrix: new Matrix4().elements,
  69436. //固定值
  69437. modelMatrix: new Matrix4().copy(cloud.transformMatrix).transpose().elements
  69438. };
  69439. return data;
  69440. }),
  69441. aabb: "b-12742000 -12742000 -12742000 12742000 12742000 12742000" //固定剪裁空间
  69442. };
  69443. console.log(data);
  69444. return data;
  69445. },
  69446. getTransformationMatrix: function getTransformationMatrix(pointcloud, invMatrix) {
  69447. //剪裁矩阵
  69448. var invMatrix = invMatrix || this.box.matrixWorld.clone().invert();
  69449. return new Matrix4().multiplyMatrices(invMatrix, pointcloud.transformMatrix).transpose();
  69450. },
  69451. getIntersectPointcloud() {
  69452. var intersect = pointcloud => {
  69453. if (pointcloud.intersectBox(this.box.matrixWorld)) return true;
  69454. };
  69455. return viewer.scene.pointclouds.filter(e => intersect(e));
  69456. },
  69457. getRulerBound() {
  69458. //坐标尺边界
  69459. var camera = viewer.mainViewport.camera;
  69460. if (!camera.isOrthographicCamera) return;
  69461. var w = camera.right / camera.zoom; //half
  69462. var h = camera.top / camera.zoom;
  69463. var points = [];
  69464. var boundAtCamera = new Box3();
  69465. Clip.box.children[0].geometry.vertices.forEach(e => {
  69466. //模仿getPosWithFullBound
  69467. var p = e.clone().applyMatrix4(Clip.box.matrixWorld);
  69468. points.push(p);
  69469. var p1 = p.clone().applyMatrix4(camera.matrixWorldInverse);
  69470. boundAtCamera.expandByPoint(p1);
  69471. });
  69472. //需要找出clipbox的bound的左上角,它在标尺中是原点
  69473. var ClipBoxLeftTop = new Vector2(boundAtCamera.min.x, boundAtCamera.max.y); //相对于相机的位置
  69474. var camPos = new Vector2(-ClipBoxLeftTop.x, ClipBoxLeftTop.y); //由于ClipBoxLeftTop要变换到原点,所以相机位置就成了ClipBoxLeftTop的相反数, 但因是从上到下所以y再乘-1
  69475. var bound_ = {
  69476. left: camPos.x - w,
  69477. right: camPos.x + w,
  69478. bottom: camPos.y + h,
  69479. //注意从上到下增大
  69480. top: camPos.y - h
  69481. };
  69482. //console.log(bound)
  69483. return bound_;
  69484. },
  69485. screenshot: async function screenshot(rulerBound, rulerMargin) {
  69486. var unitText = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '像素 : 米';
  69487. //测绘图下载。顶视图|侧视图
  69488. return new Promise((resolve, reject) => {
  69489. if (Clip.screenshoting) return reject();
  69490. var visiPointclouds = viewer.scene.pointclouds.filter(e => Potree.Utils.getObjVisiByReason(e, 'datasetSelection'));
  69491. var camera = viewer.mainViewport.camera;
  69492. //if(Clip.activeViewName == 'mainView')return reject()
  69493. var maxWidth = 8192,
  69494. minWidth = Potree.browser.urlHasValue('clipMinWidth', true) || 1024; //图片尺寸最大最小值。
  69495. //Potree.settings.pointDensity = 'ultraHigh'
  69496. viewer.inputHandler.deselectAll();
  69497. Clip.box.visible = false;
  69498. Clip.screenshoting = true;
  69499. var material = new ExtendPointCloudMaterial();
  69500. material.pointSizeType = Potree.PointSizeType.FIXED; //Potree.PointSizeType
  69501. material.size = Potree.browser.urlHasValue('clipPointSize', true) || 1;
  69502. material.uniforms.minSize.value = 0.1;
  69503. material.activeAttributeName = 'rgba';
  69504. //material.classification = pointcloud.material.classification;
  69505. material.clipBoxBig_in = visiPointclouds[0].material.clipBoxBig_in;
  69506. material.shaderNeedsUpdate = true;
  69507. material.bigClipInBox = visiPointclouds[0].material.bigClipInBox;
  69508. var materials = visiPointclouds.map(e => {
  69509. var mat = e.material;
  69510. e.material = material;
  69511. return mat;
  69512. });
  69513. //根据boundingBox尺寸来定图片尺寸
  69514. var boundingBox = Clip.box.boundingBox.clone().applyMatrix4(Clip.box.matrixWorld);
  69515. var points = [];
  69516. var bound = new Box3();
  69517. Clip.box.children[0].geometry.vertices.forEach(e => {
  69518. //模仿getPosWithFullBound
  69519. var p = e.clone().applyMatrix4(Clip.box.matrixWorld);
  69520. points.push(p);
  69521. var p1 = p.clone().applyMatrix4(camera.matrixWorldInverse);
  69522. bound.expandByPoint(p1);
  69523. });
  69524. var boundSize = bound.getSize(new Vector3());
  69525. var minZoom = Potree.browser.urlHasValue('clipZoom', true) || 80; //1px = 1个点 = 1cm , 如果一个点都是1cm的话
  69526. //zoom不宜过大或过小,过小点云重叠、画面模糊;过大点云有间隙,纹理就看不清
  69527. //中间部分75-80为佳,文字100,边缘50. 最好支持调节 . 且当下载尺寸变大往往点云也多,可能冲破pointbudget限制
  69528. //let text = `1 : ${(1 / camera.zoom).toFixed(4)}(像素 : 米)`
  69529. var w = boundSize.x * minZoom;
  69530. var h = boundSize.y * minZoom;
  69531. var max = Math.max(w, h);
  69532. var s = 1;
  69533. if (max > maxWidth) {
  69534. s = maxWidth / max;
  69535. } else if (max < minWidth) {
  69536. s = minWidth / max;
  69537. }
  69538. w *= s, h *= s;
  69539. material.size *= s;
  69540. s != 1 && console.log('宽度缩放倍数', s);
  69541. //虽然size>1就是浪费像素,但是太小了视觉效果有点差……可能因为fov不真实。 点云大就像是老式电视机虽然显示像素量少但感觉不出画面模糊,且边缘锐利。
  69542. w = Math.round(w);
  69543. h = Math.round(h);
  69544. var focusObjectInfo = [{
  69545. boundingBox,
  69546. points
  69547. }, 'boundingBox', 0, {
  69548. dontChangeCamDir: true,
  69549. dontMoveMap: true,
  69550. boundScale: 1
  69551. }];
  69552. //分块渲染截图,最后拼合图片。需要使每一块的点数不超过pointBudget, 且尺寸不超过4096(会崩溃),过小的话一般不会超过pointBudget,除非是深度较大后排点云多。
  69553. var r = MathUtils.clamp(Math.sqrt(3.5e7 / boundSize.z) * s, 1024, 4096); //每多少米分一块。 推理 wc*hc = w / r * h / r = zoom * w * s * zoom * h * s / r^2 = xyz / V(常数,每多少立方米会超出pointBudget,就是括号里的数字,给大概值)
  69554. //let r = THREE.Math.clamp(1024 / boundSize.z, 256, 4096);
  69555. var wc = w / r; //横向块数
  69556. var hc = h / r; //纵向块数
  69557. var splitRenderInfo = (wc > 1 || hc > 1) && {
  69558. wc: Math.ceil(wc),
  69559. hc: Math.ceil(hc)
  69560. }; //因为结果需要化为整数所以可能不太理想, 分割数过多。 另外如果面积小但是因z过长而超出pointBudget没关系,因后排点云无需绘制
  69561. console.log({
  69562. wc,
  69563. hc,
  69564. w,
  69565. h
  69566. });
  69567. var meterPerPixel = boundSize.x / w;
  69568. var text = "1 : ".concat(meterPerPixel.toFixed(4), "\uFF08").concat(unitText, "\uFF09");
  69569. var beforeScreenshot = () => {
  69570. if (rulerBound) {
  69571. var ruler = Clip.getRulerBound();
  69572. Object.assign(rulerBound, ruler);
  69573. }
  69574. };
  69575. var {
  69576. getImagePromise,
  69577. finishPromise
  69578. } = viewer.startScreenshot({
  69579. type: 'default',
  69580. bgOpacity: 0,
  69581. focusObjectInfo,
  69582. maxTimeForPointLoad: 3e5,
  69583. pointDensity: 'screenshot2',
  69584. splitRenderInfo,
  69585. beforeScreenshot
  69586. }, w, h, 1);
  69587. finishPromise.done(_ref => {
  69588. var {
  69589. dataUrl
  69590. } = _ref;
  69591. viewer.inputHandler.toggleSelection(Clip.box);
  69592. Clip.box.visible = true;
  69593. var img = new Image();
  69594. img.src = dataUrl;
  69595. img.onload = async () => {
  69596. //加上标尺比例水印
  69597. //固定文字大小和边距像素 //如果有一边过小,可能超出画面外,暂时不管这种可能
  69598. var fontsize = math.linearClamp(w, [100, 700, 8000], [12, 20, 30]);
  69599. var marginSelf = {
  69600. //img外的margin(标尺内)
  69601. left: rulerBound ? 76 : 40,
  69602. right: rulerBound ? 30 : 40,
  69603. bottom: rulerBound ? 20 + fontsize * 2 : 40 + fontsize * 2,
  69604. top: rulerBound ? 60 : 40
  69605. };
  69606. //const Margin = rulerMargin + marginSelf
  69607. //文字的边距
  69608. var bottomRatioToImg = -Math.min(fontsize * 2.5, rulerBound ? marginSelf.bottom : marginSelf.bottom * 0.9) / h; //- (marginSelf.bottom - fontsize)/ h //在img之下. text底部到img底部的距离
  69609. //let leftRatioToImg = Margin / w
  69610. var labelInfo = {
  69611. bottomRatioToImg,
  69612. horizonCenter: true,
  69613. //leftRatioToImg,
  69614. textColor: rulerBound ? {
  69615. r: 0,
  69616. g: 0,
  69617. b: 0,
  69618. a: 1
  69619. } : {
  69620. r: 255,
  69621. g: 255,
  69622. b: 255,
  69623. a: 1
  69624. },
  69625. textBorderColor: {
  69626. r: 30,
  69627. g: 30,
  69628. b: 30,
  69629. a: 1
  69630. },
  69631. textBorderThick: rulerBound ? 0 : 1,
  69632. fontsize,
  69633. fontWeight: rulerBound ? 'normal' : 'Bold',
  69634. outputCanvas: !!rulerBound,
  69635. bgColor: rulerBound ? {
  69636. r: 255,
  69637. g: 255,
  69638. b: 255,
  69639. a: 255
  69640. } : null
  69641. };
  69642. labelInfo.bgMargin = {
  69643. //img外需要多少margin
  69644. left: marginSelf.left + rulerMargin,
  69645. //rulerMargin是在标尺外的margin
  69646. bottom: marginSelf.bottom + rulerMargin,
  69647. right: marginSelf.right + rulerMargin,
  69648. top: marginSelf.top + rulerMargin
  69649. };
  69650. if (rulerBound) {
  69651. //因为margin 扩大bound
  69652. rulerBound.left -= marginSelf.left * meterPerPixel;
  69653. rulerBound.right += marginSelf.right * meterPerPixel;
  69654. rulerBound.top -= marginSelf.top * meterPerPixel;
  69655. rulerBound.bottom += marginSelf.bottom * meterPerPixel;
  69656. }
  69657. //console.log('topRatioToImg',topRatioToImg,'leftRatioToImg',leftRatioToImg,'fontsize', labelInfo.fontsize)
  69658. var result = await Potree.Utils.imgAddText(img, text, labelInfo);
  69659. //Common.downloadFile(finalDataUrl, 'screenshot11.png')
  69660. visiPointclouds.forEach((e, i) => e.material = materials[i]);
  69661. Clip.screenshoting = false;
  69662. viewer.viewports = [viewer.mainViewport];
  69663. resolve(result);
  69664. };
  69665. });
  69666. });
  69667. /*
  69668. 隐患:无法获知最大可加载的点的数量,也未知需要加载的点的数量。需要掌控好分块数量,避免因pointBudget限制造成周围的点稀疏。
  69669. 加载点云时间过久
  69670. */
  69671. return finishPromise;
  69672. }
  69673. };
  69674. /*
  69675. 裁剪点云时,2D界面显示全部平面图,按楼层切换显示。
  69676. 所有点云下载后点云所带的本地坐标都是场景显示的local坐标,这样才能看起来一样。
  69677. 且为了使之和坐标页面对应,坐标页面的本地坐标也是local,而非mesh_local.
  69678. //保存box
  69679. viewer.modules.Clip.box.matrix
  69680. //恢复box
  69681. let a = new THREE.Matrix4().fromArray([
  69682. 14.189120116830964,
  69683. 0,
  69684. 0,
  69685. 0,
  69686. 0,
  69687. 9.924790069368392,
  69688. 0,
  69689. 0,
  69690. 0,
  69691. 0,
  69692. 0.8751009568437951,
  69693. 0,
  69694. -7.433819981633984,
  69695. 1.528696446650445,
  69696. 2.9412375879215977,
  69697. 1
  69698. ])
  69699. a.decompose(viewer.modules.Clip.box.position,viewer.modules.Clip.box.quaternion,viewer.modules.Clip.box.scale)
  69700. viewer.modules.Clip.rotateSideCamera(-93)
  69701. */
  69702. var viewportProps = [{
  69703. left: 0.5,
  69704. bottom: 0.5,
  69705. width: 0.5,
  69706. height: 0.5,
  69707. name: 'MainView',
  69708. //view: viewer.scene.view,
  69709. active: true
  69710. }, {
  69711. left: 0,
  69712. bottom: 0.5,
  69713. width: 0.5,
  69714. height: 0.5,
  69715. name: 'top',
  69716. name2: 'mapViewport',
  69717. axis: ["x", "y"],
  69718. direction: new Vector3(0, 0, -1),
  69719. //镜头朝向
  69720. //axisSign:[1,1],
  69721. active: true
  69722. //相机位置在z轴正向
  69723. }, {
  69724. left: 0.5,
  69725. bottom: 0,
  69726. width: 0.5,
  69727. height: 0.5,
  69728. name: 'right',
  69729. axis: ["y", "z"],
  69730. direction: new Vector3(1, 0, 0),
  69731. //axisSign:[1,1],
  69732. active: true
  69733. //相机位置在x轴负向 右下角屏
  69734. }, {
  69735. left: 0,
  69736. bottom: 0,
  69737. width: 0.5,
  69738. height: 0.5,
  69739. name: 'back',
  69740. axis: ["x", "z"],
  69741. direction: new Vector3(0, -1, 0),
  69742. //axisSign:[-1,1], // 从镜头方向看 x向左 所以取负
  69743. active: true
  69744. //相机位置在y轴正向 左下角屏
  69745. }];
  69746. var SplitScreen4Views = new SplitScreen();
  69747. SplitScreen4Views.split = function () {
  69748. var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  69749. var defaultCamera = viewer.scene.getActiveCamera();
  69750. var {
  69751. boundSize,
  69752. center
  69753. } = viewer.bound;
  69754. viewer.setLimitFar(false);
  69755. viewer.mapViewer.attachToMainViewer(true, 'split4Screens', 'dontSet');
  69756. viewer.renderer.clear(); //clear back的viewport左边的1px宽的部分,因setScissor的bug
  69757. var viewports = this.splitStart(viewportProps);
  69758. //覆盖在map上、点云等其他物体之下的一层背景
  69759. var mapViewport = viewer.mapViewer.viewports[0];
  69760. mapViewport.noPointcloud = false;
  69761. //隐藏地图游标
  69762. //Potree.Utils.updateVisible(viewer.mapViewer.cursor, 'split4Screens', false)
  69763. /* viewer.images360.panos.forEach(pano=>{
  69764. Potree.Utils.updateVisible(pano.mapMarker, 'split4Screens', false) //希望这时候mapMarker已经建好了吧
  69765. }) */
  69766. /* viewer.images360.panos.forEach(pano=>{
  69767. pano.addLabel2()
  69768. Potree.Utils.updateVisible(pano.label2, 'notDisplay', true)
  69769. pano.dispatchEvent({type:'changeMarkerTex',name:'ring'})
  69770. }) */
  69771. //材质
  69772. this.statesBefore = {
  69773. pointDensity: Potree.settings.pointDensity,
  69774. displayMode: Potree.settings.displayMode,
  69775. position: viewer.images360.position,
  69776. target: viewer.scene.view.getPivot(),
  69777. currentPano: viewer.images360.currentPano
  69778. //---
  69779. //ifShowMarker : Potree.settings.ifShowMarker,
  69780. };
  69781. viewer.setPointStandardMat(true, null, true); //切换到标准模式(主要为了mainViewport) 点云使用标准大小
  69782. var matBefore = {
  69783. opacity: new Map()
  69784. };
  69785. var newOpacityMap = new Map();
  69786. viewer.scene.pointclouds.forEach(e => {
  69787. matBefore.opacity.set(e, e.temp.pointOpacity);
  69788. matBefore.colorType = e.material.activeAttributeName;
  69789. /* {
  69790. var map = new Map()
  69791. newOpacityMap.set(e, map )
  69792. var size = e.bound.getSize()
  69793. viewports.forEach(viewport=>{//根据bound设置opacity,越小的要靠越近,需要大的opacity。但似乎影响太大了
  69794. if(viewport.name == 'MainView')return;
  69795. var prop = viewportProps.find(v => viewport.name == v.name2||viewport.name == v.name)
  69796. let axis = prop.axis
  69797. var width = size[axis[0]]
  69798. var height = size[axis[1]]
  69799. var area = width * height
  69800. map.set(viewport, 5000/area);
  69801. })
  69802. } */
  69803. });
  69804. var beforeRender = function beforeRender() {
  69805. viewer.dealBeforeRender = true; //使不全部渲染
  69806. viewer.scene.pointclouds.forEach(e => {
  69807. if (this.name == "MainView") {
  69808. e.material.activeAttributeName = matBefore.colorType; // 'rgba'
  69809. e.material.useFilterByNormal = false;
  69810. //e.material.pointSizeType = Potree.config.material.pointSizeType
  69811. e.changePointOpacity(matBefore.opacity.get(e)); //1 //恢复下 e.temp.pointOpacity 其实就是1
  69812. Potree.settings.pointDensity = 'fourViewportsMain'; /* 'fourViewports' */ //本来想比另外三屏高一点质量,结果发现会闪烁,因为点云加载需要时间 (navvis仿版也是一样,以后看看能否优化)
  69813. } else {
  69814. e.material.activeAttributeName = "color";
  69815. e.material.useFilterByNormal = true;
  69816. //e.material.pointSizeType = 'ADAPTIVE'
  69817. Potree.settings.pointDensity = 'fourViewports'; //强制降低点云质量
  69818. //侧面重叠概率更大,所以透明度调小
  69819. e.changePointOpacity(this.name == "mapViewport" ? 0.5 : 0.1 /* newOpacityMap.get(e).get(viewport), true */); //多数据集有的数据集很小,放大后显示特别淡
  69820. //console.log(e.name, viewport.name, e.temp.pointOpacity, e.material.opacity)
  69821. }
  69822. viewer.images360.panos.forEach(pano => {
  69823. if (this.name == 'mapViewport') {
  69824. Potree.Utils.updateVisible(pano.marker, 'showOnMap', true, 1, 'add');
  69825. } else {
  69826. Potree.Utils.updateVisible(pano.marker, 'showOnMap', false, 1, 'cancel');
  69827. }
  69828. });
  69829. });
  69830. viewer.dealBeforeRender = false;
  69831. };
  69832. viewports.forEach(viewport => {
  69833. viewport.beforeRender = beforeRender;
  69834. new AxisViewer(viewport, viewer.renderArea, {
  69835. domStyle: {
  69836. top: '22px',
  69837. //viewport.name == 'mapViewport' ? '2px' : '-25px',
  69838. right: viewport.name == 'mapViewport' ? '30px' : '2px',
  69839. width: '80px',
  69840. height: '80px'
  69841. }
  69842. });
  69843. });
  69844. this.enableMap(false);
  69845. this.enableFloorplan(false);
  69846. viewer.mapViewer.setViewLimit('null'); //多数据集距离远时可以任意远,所以不限制了。但是这样就会看到地图边界了怎么办?超出后让地图隐藏?
  69847. //viewer.dispatchEvent({'type': 'beginSplitView' })
  69848. //viewer.updateScreenSize({forceUpdateSize:true})
  69849. //this.viewportFitBound(mapViewport, boundSize, center)
  69850. //Potree.settings.ifShowMarker = false
  69851. Potree.settings.displayMode = 'showPointCloud';
  69852. };
  69853. SplitScreen4Views.recover = function () {
  69854. viewer.viewports.forEach(e => {
  69855. e.axis.dispose();
  69856. });
  69857. this.unSplit();
  69858. viewer.mapViewer.viewports[0].beforeRender = null;
  69859. /* const {width, height} = viewer.renderer.getSize(new THREE.Vector2());
  69860. viewer.renderer.setViewport(0,0,width,height)
  69861. viewer.renderer.setScissorTest( false ); */
  69862. viewer.setView({
  69863. position: this.statesBefore.position,
  69864. target: this.statesBefore.target,
  69865. currentPano: this.statesBefore.currentPano,
  69866. duration: 300,
  69867. callback: function callback() {}
  69868. });
  69869. viewer.mainViewport.beforeRender = null;
  69870. viewer.setLimitFar(true);
  69871. var mapViewport = viewer.mapViewer.viewports[0];
  69872. viewer.mapViewer.attachToMainViewer(false);
  69873. //Potree.Utils.updateVisible(viewer.mapViewer.cursor, 'split4Screens', true)
  69874. /* viewer.images360.panos.forEach(pano=>{
  69875. Potree.Utils.updateVisible(pano.mapMarker, 'split4Screens', true)
  69876. }) */
  69877. /* viewer.images360.panos.forEach(pano=>{
  69878. Potree.Utils.updateVisible(pano.label2, 'notDisplay', false )
  69879. pano.dispatchEvent({type:'changeMarkerTex',name:'default'})
  69880. }) */
  69881. mapViewport.noPointcloud = true;
  69882. {
  69883. this.enableMap(Potree.settings.mapEnable);
  69884. this.enableFloorplan(Potree.settings.floorplanEnable);
  69885. if (this.floorplanListener) {
  69886. viewer.mapViewer.mapLayer.removeEventListener('floorplanLoaded', this.floorplanListener);
  69887. this.floorplanListener = null;
  69888. }
  69889. }
  69890. Potree.settings.pointDensity = this.statesBefore.pointDensity;
  69891. if (!Potree.settings.isOfficial) {
  69892. Potree.settings.displayMode = this.statesBefore.displayMode;
  69893. }
  69894. viewer.scene.pointclouds.forEach(e => {
  69895. e.material.useFilterByNormal = false;
  69896. //e.material.pointSizeType = Potree.config.material.pointSizeType
  69897. });
  69898. viewer.setPointStandardMat(false);
  69899. viewer.mapViewer.setViewLimit('standard');
  69900. viewer.images360.panos.forEach(pano => {
  69901. Potree.Utils.updateVisible(pano.marker, 'showOnMap', false, 1, 'cancel');
  69902. });
  69903. //Potree.settings.ifShowMarker = this.statesBefore.ifShowMarker
  69904. //viewer.dispatchEvent({'type': 'finishSplitView' })
  69905. //viewer.updateScreenSize({forceUpdateSize:true})
  69906. };
  69907. SplitScreen4Views.updateMapViewerBG = function () {
  69908. var mapViewport = viewer.mapViewer.viewports[0];
  69909. if (this.splited && (this.floorplanEnabled || this.mapEnabled)) {
  69910. mapViewport.background = 'overlayColor';
  69911. mapViewport.backgroundColor = new Color(0, 0, 0);
  69912. mapViewport.backgroundOpacity = 0.5;
  69913. } else {
  69914. mapViewport.background = null;
  69915. mapViewport.backgroundColor = null;
  69916. mapViewport.backgroundOpacity = null;
  69917. }
  69918. viewer.mapViewer.mapChanged = true;
  69919. viewer.mapViewer.needUpdate = true;
  69920. };
  69921. SplitScreen4Views.setFloorplanDisplay = function (e) {
  69922. var show = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  69923. e.floorplan.setEnable(show);
  69924. };
  69925. SplitScreen4Views.enableMap = function (enable) {
  69926. var map = viewer.mapViewer.mapLayer.maps.find(e => e.name == 'map');
  69927. map.setEnable(!!enable);
  69928. //viewer.mapViewer.mapGradientBG = viewer.background == 'gradient' && !enable
  69929. this.mapEnabled = enable;
  69930. this.updateMapViewerBG();
  69931. },
  69932. //直接覆盖原设置
  69933. SplitScreen4Views.enableFloorplan = function (enable) {
  69934. //是否让自定义的平面图显示
  69935. var floorplans = viewer.mapViewer.mapLayer.maps.filter(e => e.name.includes('floorplan'));
  69936. if (this.floorplanListener) {
  69937. viewer.mapViewer.mapLayer.removeEventListener('floorplanLoaded', this.floorplanListener);
  69938. }
  69939. this.floorplanListener = e => {
  69940. this.setFloorplanDisplay(e, enable);
  69941. };
  69942. viewer.mapViewer.mapLayer.addEventListener('floorplanLoaded', this.floorplanListener); //万一之后才加载
  69943. if (!enable) {
  69944. //隐藏平面图
  69945. floorplans.forEach(floorplan => this.setFloorplanDisplay({
  69946. floorplan
  69947. }, false));
  69948. } else {
  69949. floorplans.forEach(floorplan => this.setFloorplanDisplay({
  69950. floorplan
  69951. }, true));
  69952. }
  69953. if (enable && floorplans.length == 0) Potree.loadMapEntity('all', true);
  69954. this.floorplanEnabled = enable;
  69955. this.updateMapViewerBG();
  69956. },
  69957. /* viewportFitBound:function(viewport, boundSize, center){ //使一个viewport聚焦在某个范围
  69958. var prop = viewportProps.find(v => viewport.name == v.name2||viewport.name == v.name)
  69959. let axis = prop.axis
  69960. let expand = 10;
  69961. let position = center.clone()
  69962. var moveAtAxis = ['x','y','z'].find(e=>!(axis.includes(e)))
  69963. if(viewport.name == 'mapViewport'){
  69964. let ori = viewport.view.position[moveAtAxis]
  69965. position[moveAtAxis] = ori //不改变这个值,尤其是mapViewer中的z
  69966. }else{
  69967. position[moveAtAxis] += boundSize[moveAtAxis]/2+expand//移动到bounding边缘外
  69968. }
  69969. viewport.view.position.copy(position)
  69970. var width = Math.max(boundSize[axis[0]], boundSize[axis[1]] * viewport.camera.aspect)//视口宽度(米)
  69971. var margin = 50 //px
  69972. viewport.camera.zoom = (viewport.resolution.x - margin) / width
  69973. viewport.camera.updateProjectionMatrix()
  69974. },
  69975. */
  69976. SplitScreen4Views.focusOnPointCloud = function (pointcloud) {
  69977. //三个屏都聚焦在这个点云
  69978. var boundSize = pointcloud.bound.getSize(new Vector3());
  69979. var center = pointcloud.bound.getCenter(new Vector3());
  69980. var target = pointcloud.panosBound && pointcloud.panosBound.center; //看向pano集中的地方,也就是真正有点云的地方。(因为需要展示所有点云,所以没办法用这个做为center)
  69981. this.focusOnObject(pointcloud.bound, center, target);
  69982. viewer.flyToDataset({
  69983. pointcloud,
  69984. dontMoveMap: true,
  69985. duration: 0
  69986. });
  69987. };
  69988. SplitScreen4Views.focusOnObject = function (bound, center, target) {
  69989. var duration = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
  69990. viewer.viewports.forEach(e => {
  69991. if (e.name == 'MainView') {
  69992. /* let len = boundSize.length()
  69993. let distance = THREE.Math.clamp(e.view.position.distanceTo(center), len * 0.01, len*0.3 ) //距离限制
  69994. //viewer.focusOnObject({position:center}, 'point', duration, {distance, direction: e.view.direction,dontMoveMap:true} )//平移镜头
  69995. //为了方便定位,直接飞到中心位置:
  69996. e.view.setView({
  69997. position:center, duration, target
  69998. }) */
  69999. } else {
  70000. this.viewportFitBound(e, bound, center);
  70001. }
  70002. });
  70003. };
  70004. var Alignment = {
  70005. SplitScreen: SplitScreen4Views,
  70006. handleState: null,
  70007. //操作状态 'translate'|'rotate'
  70008. bus: new EventDispatcher(),
  70009. /* prepareRecord : true,
  70010. writeToHistory(pointclouds){
  70011. if(!this.prepareRecord)return;
  70012. this.prepareRecord = false
  70013. let content = this.getTemp(pointclouds)
  70014. this.history.writeIn(content)
  70015. },
  70016. undo(){//撤销一步
  70017. let last = this.history.pop();
  70018. last && last.forEach(item=>{
  70019. this.applyTemp(item)
  70020. })
  70021. }, */
  70022. applyTemp(item) {
  70023. var pointcloud = viewer.scene.pointclouds.find(p => p.dataset_id + p.name == item.sid);
  70024. pointcloud.orientationUser = item.orientationUser;
  70025. pointcloud.translateUser = item.translateUser;
  70026. this.setMatrix(pointcloud);
  70027. },
  70028. getTemp(pointclouds) {
  70029. //记录最近一次保存后的状态,便于恢复
  70030. pointclouds = pointclouds || viewer.scene.pointclouds;
  70031. return pointclouds.map(e => {
  70032. return {
  70033. sid: e.dataset_id + e.name,
  70034. orientationUser: e.orientationUser,
  70035. translateUser: e.translateUser.clone()
  70036. };
  70037. });
  70038. },
  70039. init: function init() {
  70040. var transfromInfo;
  70041. this.history = new History({
  70042. applyData: data => {
  70043. data.forEach(item => {
  70044. Alignment.applyTemp(item);
  70045. });
  70046. return true;
  70047. },
  70048. getData: pointclouds => {
  70049. return Alignment.getTemp(pointclouds);
  70050. }
  70051. });
  70052. viewer.fpControls.addEventListener("transformPointcloud", e => {
  70053. if (e.pointclouds[0].dataset_id == Potree.settings.originDatasetId) {
  70054. //禁止手动移动初始数据集
  70055. return this.bus.dispatchEvent('forbitMoveOriginDataset');
  70056. }
  70057. this.history.beforeChange(e.pointclouds);
  70058. //this.writeToHistory( e.pointclouds )
  70059. if (!transfromInfo) {
  70060. transfromInfo = {
  70061. pointclouds: e.pointclouds
  70062. };
  70063. }
  70064. if (this.handleState == 'translate') {
  70065. e.pointclouds.forEach(cloud => Alignment.translate(cloud, e.moveVec));
  70066. } else if (this.handleState == 'rotate') {
  70067. if (Potree.settings.editType == 'pano') {
  70068. //旋转中心是intersectStart的版本
  70069. /* let center = e.intersectStart //旋转中心是mousedown的位置
  70070. if(e.intersect.equals(center))return
  70071. if(!transfromInfo){
  70072. transfromInfo = {
  70073. orientationUser : e.pointclouds[0].orientationUser,
  70074. //vecStart : e.moveVec, // 首次移动向量 只有八个方向,精度太小,所以延迟
  70075. pointclouds: e.pointclouds
  70076. }
  70077. this.bus.dispatchEvent({type:'rotateStart', startPoint:center})
  70078. return
  70079. }else if(!transfromInfo.vecStart){
  70080. let vec = new THREE.Vector3().subVectors(e.intersect, center).setZ(0)
  70081. if(vec.length() * e.camera.zoom > 30){ //在屏幕上距离初始点有一定距离后开始算
  70082. //console.log('moveVec',vec)
  70083. transfromInfo.vecStart = vec
  70084. } */
  70085. var center = e.pointclouds[0].translateUser; //旋转中心是第一个点云的位置
  70086. if (e.intersect.equals(center)) return;
  70087. if (!transfromInfo.vecStart) {
  70088. transfromInfo.orientationUser = e.pointclouds[0].orientationUser;
  70089. transfromInfo.vecStart = new Vector3().subVectors(e.intersectStart, center).setZ(0);
  70090. } else {
  70091. var vec = new Vector3().subVectors(e.intersect, center).setZ(0);
  70092. var angle = math.getAngle(transfromInfo.vecStart, vec, 'z');
  70093. var diffAngle = transfromInfo.orientationUser + angle - transfromInfo.pointclouds[0].orientationUser;
  70094. transfromInfo.pointclouds.forEach(cloud => {
  70095. /* let centerNoTranfrom = Potree.Utils.datasetPosTransform({ toDataset: true, pointcloud:cloud, position: center }) //中心点在数据集中的位置
  70096. Alignment.rotate(cloud, null, diffAngle)
  70097. let centerNow = Potree.Utils.datasetPosTransform({ fromDataset: true, pointcloud:cloud, position: centerNoTranfrom }) //中心点的现在位置
  70098. let shift = new THREE.Vector3().subVectors( center, centerNow); //偏移量
  70099. Alignment.translate(cloud,shift) //使center还保留在原位
  70100. //let centerNow1 = Potree.Utils.datasetPosTransform({ fromDataset: true, pointcloud:transfromInfo.pointcloud, position: centerNoTranfrom }) //中心点的现在位置
  70101. */
  70102. Alignment.rotateAround(center, cloud, null, diffAngle);
  70103. });
  70104. }
  70105. //this.bus.dispatchEvent({type:'rotate', endPoint: e.intersect})
  70106. } else {
  70107. var _center = e.pointclouds[0].translateUser; //移动到的位置就是中心
  70108. if (e.intersect.equals(_center)) return;
  70109. if (!transfromInfo.vecStart) {
  70110. transfromInfo.orientationUser = e.pointclouds[0].orientationUser;
  70111. transfromInfo.vecStart = new Vector3().subVectors(e.intersectStart, _center).setZ(0);
  70112. } else {
  70113. var _vec = new Vector3().subVectors(e.intersect, _center).setZ(0);
  70114. var _angle = math.getAngle(transfromInfo.vecStart, _vec, 'z');
  70115. var _diffAngle = transfromInfo.orientationUser + _angle - transfromInfo.pointclouds[0].orientationUser;
  70116. Alignment.rotate(transfromInfo.pointclouds[0], null, _diffAngle);
  70117. }
  70118. }
  70119. }
  70120. });
  70121. viewer.fpControls.addEventListener("end", e => {
  70122. transfromInfo && this.history.afterChange(transfromInfo.pointclouds);
  70123. transfromInfo = null;
  70124. });
  70125. // cursor:
  70126. var updateCursor = e => {
  70127. if (e.drag || !this.editing) return; //仅在鼠标不按下时更新:
  70128. var handleState = Alignment.handleState;
  70129. if (e.hoverViewport.alignment && handleState && e.hoverViewport.alignment[handleState]) {
  70130. if (handleState == 'translate') {
  70131. if (e.intersect && e.intersect.location) {
  70132. viewer.dispatchEvent({
  70133. type: "CursorChange",
  70134. action: "add",
  70135. name: "movePointcloud"
  70136. });
  70137. } else {
  70138. viewer.dispatchEvent({
  70139. type: "CursorChange",
  70140. action: "remove",
  70141. name: "movePointcloud"
  70142. });
  70143. }
  70144. } else if (handleState == 'rotate') {
  70145. if (e.intersect && e.intersect.location) {
  70146. viewer.dispatchEvent({
  70147. type: "CursorChange",
  70148. action: "add",
  70149. name: "rotatePointcloud"
  70150. });
  70151. } else {
  70152. viewer.dispatchEvent({
  70153. type: "CursorChange",
  70154. action: "remove",
  70155. name: "rotatePointcloud"
  70156. });
  70157. }
  70158. }
  70159. } else {
  70160. //清空:
  70161. viewer.dispatchEvent({
  70162. type: "CursorChange",
  70163. action: "remove",
  70164. name: "movePointcloud"
  70165. });
  70166. viewer.dispatchEvent({
  70167. type: "CursorChange",
  70168. action: "remove",
  70169. name: "rotatePointcloud"
  70170. });
  70171. }
  70172. };
  70173. viewer.addEventListener('global_mousemove', updateCursor);
  70174. viewer.addEventListener('global_drop', updateCursor); //拖拽结束
  70175. viewer.addEventListener('updateModelBound', e => {
  70176. if (this.editing) {
  70177. this.SplitScreen.updateCameraOutOfModel();
  70178. }
  70179. });
  70180. },
  70181. setMatrix: function setMatrix(pointcloud) {
  70182. var vec1 = pointcloud.position; //position为数据集内部的偏移,在navvis中对应的是dataset.pointCloudSceneNode的children[0].position
  70183. var vec2 = pointcloud.translateUser;
  70184. var angle = pointcloud.orientationUser;
  70185. var pos1Matrix = new Matrix4().setPosition(vec1); //先移动到点云本身应该在的初始位置(在4dkk里和其他应用中都是在这个位置的,也能和漫游点对应上)
  70186. var rotMatrix = new Matrix4().makeRotationAxis(new Vector3(0, 0, 1), angle); //再旋转
  70187. var pos2Matrix = new Matrix4().setPosition(vec2); //最后是平移
  70188. var matrix = new Matrix4().multiplyMatrices(pos2Matrix, rotMatrix);
  70189. pointcloud.transformMatrix = matrix.clone(); //为该数据集的变化矩阵。 对应navvis的m2w_
  70190. pointcloud.transformInvMatrix.copy(pointcloud.transformMatrix).invert();
  70191. pointcloud.rotateMatrix = rotMatrix;
  70192. pointcloud.rotateInvMatrix.copy(rotMatrix).invert();
  70193. pointcloud.panos.forEach(e => e.transformByPointcloud());
  70194. matrix = new Matrix4().multiplyMatrices(matrix, pos1Matrix);
  70195. //matrix.premultiply(viewer.scene.scene.matrix);////////////////////////add
  70196. pointcloud.matrix = matrix;
  70197. //pointcloud.matrixWorldNeedsUpdate = true //更新matrixWorld (非计算,直接赋值)
  70198. pointcloud.updateMatrixWorld(true);
  70199. if (this.editing) {
  70200. Alignment.changeCallBack && Alignment.changeCallBack();
  70201. }
  70202. if (pointcloud.spriteNodeRoot) {
  70203. pointcloud.spriteNodeRoot.matrixWorld.copy(pointcloud.matrixWorld); //.multiplyMatrices(pointcloud.matrixWorld, pointcloud.matrixWorld);
  70204. }
  70205. viewer.boundNeedUpdate = true;
  70206. //pointcloud.updateBound()
  70207. pointcloud.getPanosBound();
  70208. viewer.dispatchEvent('content_changed');
  70209. },
  70210. rotateAround(center, pointcloud, deg, angle) {
  70211. //绕center点转动
  70212. var angle = angle != void 0 ? angle : MathUtils.degToRad(deg);
  70213. var vec1 = new Vector3().subVectors(pointcloud.translateUser, center);
  70214. var rotMatrix = new Matrix4().makeRotationAxis(new Vector3(0, 0, 1), angle);
  70215. var vec2 = vec1.clone().applyMatrix4(rotMatrix); //将到旋转中心的偏差也转动
  70216. var vec3 = new Vector3().subVectors(vec2, vec1); //这个就是多出来的一步translateUser
  70217. this.rotate(pointcloud, deg, angle);
  70218. this.translate(pointcloud, vec3);
  70219. //绕点转动就是比普通转动多一步移动到相对center的某个位置。 1 初始点云移动到自己的position; 2 移动一个vec1 3绕原点旋转 4再移动一个原本的translateUser。 绘制出来后发现移动量就是第二步vec旋转后的偏移
  70220. },
  70221. rotate: function rotate(pointcloud, deg, angle) {
  70222. //绕各自中心转动(各自的position) 假设点云位移position后0,0,0就是它的中心了(根据navvis观察这样做是绕同一个点旋转的)
  70223. var angle = angle != void 0 ? angle : MathUtils.degToRad(deg); //正逆负顺
  70224. pointcloud.orientationUser += angle;
  70225. Alignment.setMatrix(pointcloud);
  70226. },
  70227. translate: function translate(pointcloud, vec) {
  70228. pointcloud.translateUser.add(vec);
  70229. Alignment.setMatrix(pointcloud);
  70230. },
  70231. enter: function enter() {
  70232. //this.saveTemp()
  70233. this.originData = this.getTemp();
  70234. this.SplitScreen.split({
  70235. alignment: true
  70236. });
  70237. /* viewer.images360.panos.forEach(pano=>{
  70238. Potree.Utils.updateVisible(pano.mapMarker, 'split4Screens', false)
  70239. }) */
  70240. viewer.viewports.find(e => e.name == 'mapViewport').alignment = {
  70241. rotate: true,
  70242. translate: true
  70243. };
  70244. viewer.viewports.find(e => e.name == 'right').alignment = {
  70245. translate: true,
  70246. translateVec: new Vector3(0, 0, 1)
  70247. }; //只能上下移动
  70248. viewer.viewports.find(e => e.name == 'back').alignment = {
  70249. translate: true,
  70250. translateVec: new Vector3(0, 0, 1)
  70251. }; //只能上下移动
  70252. this.editing = true;
  70253. viewer.updateFpVisiDatasets();
  70254. },
  70255. leave: function leave() {
  70256. this.switchHandle(null);
  70257. /* this.originData.forEach(e=>{//恢复
  70258. var pointcloud = viewer.scene.pointclouds.find(p=>p.dataset_id == e.id)
  70259. this.translate(pointcloud, new THREE.Vector3().subVectors(e.translateUser , pointcloud.translateUser))
  70260. this.rotate(pointcloud, null, e.orientationUser - pointcloud.orientationUser)
  70261. }) */
  70262. this.originData.forEach(e => {
  70263. //恢复
  70264. this.applyTemp(e);
  70265. });
  70266. this.SplitScreen.recover();
  70267. /* viewer.images360.panos.forEach(pano=>{
  70268. Potree.Utils.updateVisible(pano.mapMarker, 'split4Screens', true)
  70269. }) */
  70270. this.editing = false;
  70271. this.history.clear();
  70272. viewer.updateFpVisiDatasets();
  70273. viewer.dispatchEvent({
  70274. type: "CursorChange",
  70275. action: "remove",
  70276. name: "movePointcloud"
  70277. });
  70278. viewer.dispatchEvent({
  70279. type: "CursorChange",
  70280. action: "remove",
  70281. name: "rotatePointcloud"
  70282. });
  70283. },
  70284. switchHandle: function switchHandle(state) {
  70285. this.handleState = state;
  70286. //清空:
  70287. viewer.dispatchEvent({
  70288. type: "CursorChange",
  70289. action: "remove",
  70290. name: "movePointcloud"
  70291. });
  70292. viewer.dispatchEvent({
  70293. type: "CursorChange",
  70294. action: "remove",
  70295. name: "rotatePointcloud"
  70296. });
  70297. this.bus.dispatchEvent({
  70298. type: 'switchHandle',
  70299. state
  70300. });
  70301. },
  70302. save: function save() {
  70303. //保存所有数据集的位置和旋转
  70304. var callback = () => {
  70305. //保存成功后
  70306. this.originData = this.getTemp(); //this.saveTemp();
  70307. //需要修改 测量线的position。漫游点已经实时修改了
  70308. viewer.scene.measurements.forEach(e => e.transformByPointcloud());
  70309. viewer.images360.updateCube(viewer.bound);
  70310. };
  70311. var data = viewer.scene.pointclouds.map(e => {
  70312. var pos = viewer.transform.lonlatToLocal.inverse(e.translateUser.clone());
  70313. var initialPointcloud = viewer.scene.pointclouds.find(e => e.dataset_id == Potree.settings.originDatasetId);
  70314. return {
  70315. id: e.dataset_id,
  70316. orientation: e.orientationUser,
  70317. location: [pos.x, pos.y, pos.z + initialPointcloud.datasetData.location[2]]
  70318. //transformMatrix: e.transformMatrix.elements,
  70319. };
  70320. });
  70321. //data = JSON.stringify(data)
  70322. //test: 退出后保留结果
  70323. if (!Potree.settings.isOfficial) {
  70324. callback();
  70325. }
  70326. return {
  70327. data,
  70328. callback
  70329. };
  70330. }
  70331. };
  70332. var texLoader$9 = new TextureLoader();
  70333. var markerMats$2;
  70334. var markerSizeInfo$2 = {
  70335. width2d: 35
  70336. };
  70337. var color$2 = new Color('#FFF');
  70338. var faceMats;
  70339. var getFaceMat = name => {
  70340. if (!faceMats) {
  70341. //navvis材质可以搜gridTexture
  70342. var gridTex = texLoader$9.load(Potree.resourcePath + '/textures/gridmap.png');
  70343. gridTex.wrapS = gridTex.wrapT = RepeatWrapping;
  70344. //gridTex.repeat.set(0.5,0.5)//放大一些
  70345. faceMats = {
  70346. dataset: new MeshStandardMaterial({
  70347. color: 812922,
  70348. side: DoubleSide,
  70349. opacity: 0.2,
  70350. transparent: true,
  70351. depthTest: false,
  70352. wireframe: true
  70353. }),
  70354. building: new MeshStandardMaterial({
  70355. color: 812922,
  70356. metalness: 0.2,
  70357. roughness: 0.8,
  70358. side: DoubleSide,
  70359. opacity: 0.1,
  70360. transparent: true,
  70361. depthTest: true
  70362. }),
  70363. buildingSelect: new MeshStandardMaterial({
  70364. color: 36582,
  70365. metalness: 0,
  70366. roughness: 1,
  70367. side: DoubleSide,
  70368. opacity: 0.1,
  70369. transparent: true,
  70370. depthTest: true
  70371. }),
  70372. floor: new MeshStandardMaterial({
  70373. color: 11708469,
  70374. metalness: 0.1,
  70375. roughness: 1,
  70376. side: DoubleSide,
  70377. //BackSide,
  70378. opacity: 0.05,
  70379. transparent: true,
  70380. depthTest: true
  70381. }),
  70382. floorSelect: new DepthBasicMaterial({
  70383. map: gridTex,
  70384. color: 16707151,
  70385. side: DoubleSide,
  70386. //BackSide,
  70387. opacity: 1,
  70388. transparent: true,
  70389. useDepth: true,
  70390. clipDistance: 1,
  70391. occlusionDistance: 1,
  70392. /* occlusionDistance:变为backColor距离, clipDistance:opacity到达0或者1-maxClipFactor时的距离 */
  70393. maxClipFactor: 0.9,
  70394. backColor: '#efe' //backColor:"#669988" ,
  70395. }),
  70396. room: new MeshStandardMaterial({
  70397. color: "#ff44ee",
  70398. metalness: 0,
  70399. roughness: 1,
  70400. side: DoubleSide,
  70401. //BackSide,
  70402. opacity: 0.08,
  70403. transparent: true,
  70404. depthTest: false
  70405. }),
  70406. roomSelect: new DepthBasicMaterial({
  70407. map: gridTex,
  70408. color: "#ff44ee",
  70409. side: DoubleSide,
  70410. //BackSide,
  70411. opacity: 1,
  70412. transparent: true,
  70413. useDepth: true,
  70414. clipDistance: 1,
  70415. occlusionDistance: 0.5,
  70416. /* occlusionDistance:变为backColor距离, clipDistance:opacity到达0或者1-maxClipFactor时的距离 */
  70417. maxClipFactor: 0.8,
  70418. backColor: '#ff88dd' //"#cc99c2" ,
  70419. })
  70420. };
  70421. }
  70422. return faceMats[name];
  70423. };
  70424. class BuildingBox extends ctrlPolygon {
  70425. //建筑实体,包括building, floor, room
  70426. constructor(prop) {
  70427. prop.dimension = '3d';
  70428. //prop.name = Potree.config.siteModel.names[prop.buildType] +
  70429. super('siteModel_' + prop.buildType, prop);
  70430. this.midMarkers = [];
  70431. this.buildChildren = []; //子实体
  70432. this.holes = []; //在这创建的hole
  70433. this.parentHoles = []; //floor从building那得到的当层holes
  70434. this.mats = {}; //材质
  70435. this.panos = this.panos || [];
  70436. this.center; //中心点
  70437. if (this.buildType == 'floor') {
  70438. this.points = prop.points = this.buildParent.points; //完全等于建筑的点
  70439. this.buildParent.holes.forEach(hole => {
  70440. //从building获取holes
  70441. var floorHole = new BuildingBox({
  70442. buildType: 'hole',
  70443. buildParent: this,
  70444. originHole: hole,
  70445. //整栋大楼在当层的hole
  70446. ifDraw: this.ifDraw || Potree.settings.drawEntityData
  70447. });
  70448. this.parentHoles.push(floorHole);
  70449. this.add(floorHole);
  70450. floorHole.points = hole.points; //完全等于建筑的点
  70451. });
  70452. }
  70453. if (this.buildType == 'room' || this.buildType == 'hole') {
  70454. this.restrictArea = this.buildParent; //不能超出的区域
  70455. }
  70456. if (this.buildParent) this.dontDragFloorHeight = this.buildParent.dontDragFloorHeight;
  70457. if (this.buildType != 'hole') {
  70458. this.box = this.createBox(); //无论是否edit都绘制的原因:为了将在外的点移到在内,需要用mesh来获取intersect
  70459. this.add(this.box);
  70460. this.box.visible = !!this.ifDraw;
  70461. }
  70462. if (this.ifDraw) {
  70463. //只存储空间模型信息,不绘制
  70464. {
  70465. this.createPrismLines(color$2);
  70466. this.lineMesh.visible = false;
  70467. Potree.Utils.setObjectLayers(this.lineMesh, 'bothMapAndScene');
  70468. }
  70469. this.addEventListener('dragChange', e => {
  70470. //修改中点
  70471. this.updateTwoMidMarker(e.index);
  70472. });
  70473. }
  70474. this.initData(prop);
  70475. }
  70476. initData(prop) {
  70477. if (prop.ifDraw) {
  70478. super.initData(prop);
  70479. } else {
  70480. if (prop.points) {
  70481. this.points = prop.points;
  70482. }
  70483. }
  70484. }
  70485. intersectPointcloudVolume(pointcloud) {
  70486. //和pointcloud的重叠体积
  70487. return this.intersectPointcloudArea(pointcloud) * this.coverPointcloudHeight(pointcloud);
  70488. }
  70489. coverPointcloudHeight(pointcloud, getPercent) {
  70490. var bound2 = pointcloud.bound;
  70491. var {
  70492. zMin,
  70493. zMax
  70494. } = this.getRealZ();
  70495. var min = Math.min(zMin, bound2.min.z);
  70496. var max = Math.max(zMax, bound2.max.z);
  70497. var height1 = zMax - zMin;
  70498. var height2 = bound2.max.z - bound2.min.z;
  70499. var coverHeight = height1 + height2 - (max - min); //重叠高度 <=0是没重叠
  70500. if (getPercent) {
  70501. return coverHeight / height1;
  70502. }
  70503. return coverHeight;
  70504. }
  70505. intersectPointcloudArea(pointcloud, getPercent) {
  70506. //和pointcloud的重叠面积
  70507. var bound = this.getBound();
  70508. var bound2 = pointcloud.bound;
  70509. if (!bound.intersectsBox(bound2)) return 0;
  70510. var boxPoints = pointcloud.getUnrotBoundPoint(); //获取tightBound的四个点。 如果是有旋转角度的点云,这个和pointcloud.bound的四个点是不一致的,覆盖面积小于pointcloud.bound
  70511. var areaWhole = 0;
  70512. var area1 = this.getArea();
  70513. var area2 = Math.abs(math.getArea(boxPoints));
  70514. {
  70515. //计算points与点云总面积 (但是把hole也加入了面积)(并集,重叠部分只算一次)
  70516. var rings = math.getPolygonsMixedRings([this.points, boxPoints]);
  70517. rings.forEach(e => {
  70518. areaWhole += e.area;
  70519. });
  70520. }
  70521. var coverHoleArea = 0; //holes与数据集重叠的部分
  70522. var holes = this.holes.concat(this.parentHoles);
  70523. var holesArea = 0; //所有holes面积相加
  70524. var areaHoleWithPointcloud = 0; //hole和点云的面积并集
  70525. if (holes.length > 0) {
  70526. //还要再扣除holes与数据集重叠的部分。其中holes为mix轮廓
  70527. var outHoles = []; //没有重合的holes的外轮廓
  70528. /* if(holes.length>=2){//合并holes。如果能在绘制时直接合并holes就好啦,这步就转移到那去,但是要删除hole好麻烦
  70529. let holes_ = holes.map(e=>e.points)
  70530. outHoles = math.getPolygonsMixedRings(holes_, true )
  70531. outHoles.forEach(e=>{
  70532. holesArea+=e.area
  70533. })
  70534. outHoles = outHoles.map(e=>e.points)
  70535. }else{
  70536. outHoles = holes.map(e=>e.points)
  70537. outHoles.forEach(e=> holesArea += Math.abs(math.getArea(e)))
  70538. } */
  70539. holesArea = this.getHolesArea();
  70540. //holes与数据集重叠的部分
  70541. {
  70542. var polygons = outHoles.concat([boxPoints]);
  70543. var _rings = math.getPolygonsMixedRings(polygons);
  70544. _rings.forEach(e => {
  70545. areaHoleWithPointcloud += e.area;
  70546. });
  70547. coverHoleArea = holesArea + area2 - areaHoleWithPointcloud; //hole和点云的交集
  70548. }
  70549. }
  70550. var coverArea = area1 + area2 - areaWhole - coverHoleArea; //重叠面积
  70551. if (getPercent) {
  70552. return {
  70553. toEntity: coverArea / this.getArea(true),
  70554. //占entity
  70555. toPointcloud: coverArea / area2 //占点云
  70556. };
  70557. }
  70558. return coverArea;
  70559. }
  70560. addHole() {
  70561. var points = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  70562. var prop = {
  70563. buildType: 'hole',
  70564. zMin: this.zMin,
  70565. zMax: this.zMax,
  70566. points,
  70567. buildParent: this,
  70568. ifDraw: this.ifDraw || Potree.settings.drawEntityData
  70569. };
  70570. //hole的zMin zMax跟随buildParent
  70571. var hole = new BuildingBox(prop);
  70572. this.holes.push(hole);
  70573. if (this.buildType == 'building') {
  70574. //为每一层添加对应的hole
  70575. this.buildChildren.forEach(floor => {
  70576. var floorHole = new BuildingBox({
  70577. buildType: 'hole',
  70578. zMin: this.zMin,
  70579. zMax: this.zMax,
  70580. buildParent: floor,
  70581. originHole: hole,
  70582. //整栋大楼在当层的hole
  70583. ifDraw: this.ifDraw || Potree.settings.drawEntityData
  70584. });
  70585. floor.parentHoles.push(floorHole);
  70586. floor.add(floorHole);
  70587. floorHole.points = hole.points; //完全等于建筑的点
  70588. });
  70589. }
  70590. this.add(hole); //直接加在这,不加meshGroup了
  70591. this.update(); //update box mesh
  70592. return hole;
  70593. //hole不创建box,只有它的buildParent需要更新box。 但有线条和marker. hole不在buildChildren里,但有buildParent
  70594. }
  70595. removeHole(hole) {
  70596. // 这个hole不会是parentHoles里的。
  70597. hole.dispose();
  70598. if (this.buildType == 'building') {
  70599. //若是整栋大楼的hole,在每层去除它的对应hole
  70600. this.buildChildren.forEach(floor => {
  70601. var holeAtFloor = floor.parentHoles.find(e => e.originHole == this);
  70602. var index = floor.parentHoles.indexOf(holeAtFloor);
  70603. index > -1 && floor.parentHoles.splice(index, 1);
  70604. holeAtFloor.dispose();
  70605. });
  70606. }
  70607. var index = this.holes.indexOf(hole);
  70608. if (index > -1) {
  70609. this.holes.splice(index, 1);
  70610. }
  70611. this.remove(hole);
  70612. this.update();
  70613. }
  70614. createBox() {
  70615. var geometry = new Geometry();
  70616. this.mats.boxDefault = getFaceMat(this.buildType);
  70617. this.mats.boxSelected = getFaceMat(this.buildType + 'Select');
  70618. var mesh = new Mesh(geometry, this.mats.boxDefault);
  70619. mesh.name = 'buildingBox';
  70620. if (this.buildType == 'floor') {
  70621. Potree.Utils.setObjectLayers(mesh, 'siteModelMapUnvisi'); //楼层默认在地图不显示,为了不会叠加透明度
  70622. //mesh.renderOrder = 1
  70623. } else {
  70624. /* if(this.buildType == 'room'){
  70625. mesh.renderOrder = 2
  70626. } */
  70627. Potree.Utils.setObjectLayers(mesh, 'bothMapAndScene');
  70628. }
  70629. //mesh.frustumCulled = false;
  70630. return mesh;
  70631. }
  70632. addMarker() {
  70633. var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  70634. if (this.buildType == 'floor') return; //楼层不需要marker
  70635. var marker = new Sprite$2({
  70636. mat: this.getMarkerMaterial('default'),
  70637. renderOrder: 3,
  70638. sizeInfo: markerSizeInfo$2,
  70639. dontFixOrient: true,
  70640. name: "building_marker"
  70641. });
  70642. Potree.Utils.setObjectLayers(marker, 'siteModeOnlyMapVisi');
  70643. o.marker = marker;
  70644. super.addMarker(o);
  70645. if (!this.selected) Potree.Utils.updateVisible(marker, 'select', false);
  70646. var addClickEvent = e => {
  70647. var click = e => {
  70648. this.dispatchEvent({
  70649. type: 'clickMarker',
  70650. marker
  70651. }); //由entity发送给sitemodel统一处理
  70652. };
  70653. marker.addEventListener('click', click);
  70654. marker.addEventListener('clickSelect', e => {
  70655. this.setMarkerSelected(marker, e.state ? 'select' : 'unselect');
  70656. });
  70657. marker.removeEventListener('addHoverEvent', addClickEvent);
  70658. };
  70659. marker.addEventListener('addHoverEvent', addClickEvent); //当非isNew时才添加事件
  70660. if (!this.isNew) {
  70661. marker.dispatchEvent('addHoverEvent');
  70662. }
  70663. return marker;
  70664. }
  70665. removeMarker(index) {
  70666. super.removeMarker(index);
  70667. if (!this.isNew) {
  70668. //重新添加midMarkers
  70669. this.midMarkers.forEach(e => this.remove(e));
  70670. this.midMarkers = [];
  70671. this.addMidMarkers();
  70672. }
  70673. this.update();
  70674. if (this.points.length == 2 && this.box) {
  70675. //清除原先length>=3时候的
  70676. this.box.geometry = new Geometry();
  70677. }
  70678. }
  70679. addMidMarker(index, point) {
  70680. if (this.buildType == 'floor') return; //楼层不需要marker
  70681. var marker = new Sprite$2({
  70682. mat: this.getMarkerMaterial('midPrepare'),
  70683. sizeInfo: markerSizeInfo$2,
  70684. dontFixOrient: true,
  70685. name: "building_midMarker"
  70686. });
  70687. this.midMarkers = [...this.midMarkers.slice(0, index), marker, ...this.midMarkers.slice(index, this.midMarkers.length)];
  70688. marker.renderOrder = 3;
  70689. Potree.Utils.setObjectLayers(marker, 'siteModeOnlyMapVisi');
  70690. {
  70691. // Event Listeners
  70692. var mouseover = e => {
  70693. this.setMarkerSelected(e.object, 'hover', 'single');
  70694. viewer.dispatchEvent({
  70695. type: "CursorChange",
  70696. action: "add",
  70697. name: "markerMove"
  70698. });
  70699. };
  70700. var mouseleave = e => {
  70701. this.setMarkerSelected(e.object, 'unhover', 'single');
  70702. viewer.dispatchEvent({
  70703. type: "CursorChange",
  70704. action: "remove",
  70705. name: "markerMove"
  70706. });
  70707. };
  70708. var drag = e => {
  70709. this.dispatchEvent('startDragging');
  70710. var index = this.midMarkers.indexOf(marker);
  70711. var newMarker = this.addMarker({
  70712. index: index + 1,
  70713. point: marker.position.clone()
  70714. });
  70715. this.addMidMarker(index + 1, new Vector3());
  70716. this.updateTwoMidMarker(index + 1);
  70717. this.setMarkerSelected(marker, 'unhover');
  70718. viewer.inputHandler.startDragging(newMarker, {/* dragViewport:viewer.mapViewer.viewports[0], */}); //notPressMouse代表不是通过按下鼠标来拖拽. dragViewport指定了只能在地图上拖拽
  70719. };
  70720. marker.addEventListener('drag', drag);
  70721. marker.addEventListener('mouseover', mouseover);
  70722. marker.addEventListener('mouseleave', mouseleave);
  70723. }
  70724. this.add(marker);
  70725. this.updateMarker(marker, point);
  70726. if (!this.selected) Potree.Utils.updateVisible(marker, 'select', false);
  70727. return marker;
  70728. }
  70729. addMidMarkers() {
  70730. //第一次画好所有marker后,一次性为线段增加中点marker
  70731. var length = this.points.length;
  70732. this.points.forEach((point, index) => {
  70733. var nextPoint = this.points[(index + 1) % length];
  70734. var midPoint = new Vector3().addVectors(point, nextPoint).multiplyScalar(0.5);
  70735. this.addMidMarker(index, midPoint);
  70736. });
  70737. }
  70738. updateTwoMidMarker(index) {
  70739. //更新第index个marker两边的midMarker
  70740. if (!this.midMarkers.length) return;
  70741. var length = this.points.length;
  70742. var last = this.points[(index - 1 + length) % length]; //它之前的marker位置
  70743. var next = this.points[(index + 1) % length]; //它之后的marker位置
  70744. var current = this.points[index]; //当前位置
  70745. var lastMid = new Vector3().addVectors(last, current).multiplyScalar(0.5); //上一个中点
  70746. var nextMid = new Vector3().addVectors(next, current).multiplyScalar(0.5); //下一个中点
  70747. var lastMidMarker = this.midMarkers[(index - 1 + length) % length];
  70748. var nextMidMarker = this.midMarkers[index];
  70749. this.updateMarker(lastMidMarker, lastMid);
  70750. this.updateMarker(nextMidMarker, nextMid);
  70751. }
  70752. dispose() {
  70753. //销毁geo、remove from parent
  70754. super.dispose();
  70755. this.box && this.box.geometry.dispose();
  70756. this.lineMesh && this.lineMesh.geometry.dispose();
  70757. this.holes.forEach(e => e.dispose());
  70758. this.parentHoles.forEach(e => e.dispose());
  70759. //this.buildChildren.forEach(e=>e.dispose())
  70760. this.dispatchEvent('dispose');
  70761. }
  70762. updateBox() {
  70763. if (!this.box) return;
  70764. this.box.geometry.dispose();
  70765. var shrink = this.buildType == 'room' ? 0.11 : this.buildType == 'floor' ? 0.082 : 0.2; //防止mesh重叠冲突(给一个不寻常的数字) 但离远了还是会有点闪烁
  70766. if (this.points.length >= 3) {
  70767. var holes = this.holes.concat(this.parentHoles);
  70768. var holesPoints = holes.filter(e => e.points.length > 2).map(e => e.points);
  70769. this.box.geometry = MeshDraw.getExtrudeGeo(this.points, holesPoints, {
  70770. depth: this.zMax - this.zMin - shrink,
  70771. UVGenerator: new MetricUVGenerator()
  70772. });
  70773. if (this.buildType == 'building') {
  70774. this.box.position.z = this.zMin - shrink / 2;
  70775. } else {
  70776. this.box.position.z = this.zMin + shrink / 2;
  70777. }
  70778. }
  70779. }
  70780. update() {
  70781. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  70782. super.update(this.buildType != 'floor' && options.ifUpdateMarkers);
  70783. var length = this.points.length;
  70784. {
  70785. //确保一下一样
  70786. if (this.originHole) {
  70787. this.points = this.originHole.points; //完全等于building的hole
  70788. }
  70789. if (this.buildType == 'hole') {
  70790. this.zMin = this.buildParent.zMin;
  70791. this.zMax = this.buildParent.zMax;
  70792. }
  70793. }
  70794. if (!options.dontUpdateBox) {
  70795. var boxOwner;
  70796. if (this.buildType == 'hole') {
  70797. if (this.buildParent.buildType == 'building') {
  70798. //若是整栋大楼的hole,在每层都要更新下它的对应hole
  70799. this.buildParent.buildChildren.forEach(floor => {
  70800. var holeAtFloor = floor.parentHoles.find(e => e.originHole == this);
  70801. holeAtFloor && holeAtFloor.update(); //刚开始创建时还没创建对应的 holeAtFloor会为null
  70802. });
  70803. }
  70804. boxOwner = this.buildParent;
  70805. } else {
  70806. boxOwner = this;
  70807. }
  70808. boxOwner.updateBox();
  70809. }
  70810. this.updatePrismLines(); //update lines
  70811. if (!options.dontUpdateChildren) {
  70812. if (this.buildType == 'building') {
  70813. this.buildChildren.forEach(floor => {
  70814. floor.points = this.points;
  70815. floor.update();
  70816. });
  70817. }
  70818. {
  70819. var holes = this.holes.concat(this.parentHoles);
  70820. holes.forEach(hole => {
  70821. hole.update({
  70822. dontUpdateBox: true
  70823. }); //父级更新了box,hole就不需要更新box了
  70824. });
  70825. }
  70826. }
  70827. }
  70828. getHolesArea() {
  70829. var holes = this.holes.concat(this.parentHoles);
  70830. var outHoles,
  70831. holesArea = 0;
  70832. if (holes.length >= 2) {
  70833. //合并holes。如果能在绘制时直接合并holes就好啦,这步就转移到那去,但是要删除hole好麻烦
  70834. var holes_ = holes.map(e => e.points);
  70835. outHoles = math.getPolygonsMixedRings(holes_, true);
  70836. outHoles.forEach(e => {
  70837. holesArea += e.area;
  70838. });
  70839. outHoles = outHoles.map(e => e.points);
  70840. } else {
  70841. outHoles = holes.map(e => e.points);
  70842. outHoles.forEach(e => holesArea += Math.abs(math.getArea(e)));
  70843. }
  70844. return holesArea;
  70845. }
  70846. getArea(ifRidOfHoles) {
  70847. //面积
  70848. //不排除hole
  70849. return Math.abs(math.getArea(this.points)) - (ifRidOfHoles ? this.getHolesArea() : 0);
  70850. }
  70851. getVolume(ifRidOfHoles) {
  70852. //体积
  70853. var {
  70854. zMin,
  70855. zMax
  70856. } = this.getRealZ();
  70857. var height = zMax - zMin;
  70858. if (isNaN(height)) height = 0;
  70859. return this.getArea(ifRidOfHoles) * height;
  70860. }
  70861. getRealZ() {
  70862. //求真实高度时用到的
  70863. var zMin, zMax;
  70864. if (this.buildType == 'building') {
  70865. //因为building只有一个地基平面 所以自身的zMin == 自身的zMax 所以要算
  70866. var top = this.buildChildren[this.buildChildren.length - 1];
  70867. var btm = this.buildChildren[0];
  70868. zMin = btm ? btm.zMin : 0; //建好的建筑不加楼的话是0。
  70869. zMax = top ? top.zMax : 0;
  70870. } else if (this.buildType == 'hole') {
  70871. return this.buildParent.getRealZ();
  70872. } else {
  70873. zMin = this.zMin, zMax = this.zMax;
  70874. }
  70875. return {
  70876. zMin,
  70877. zMax
  70878. };
  70879. }
  70880. //架站式多楼层SG-t-ihjV2cDVFlE 有初始的z, 但是总高度范围小于数据集。 不允许修改高度。
  70881. /* getDrawZ(){ //画线和box时用到的z
  70882. let zMin , zMax
  70883. if(this.buildType == 'hole'){
  70884. if(this.buildParent.buildType == 'building' && atFloor){
  70885. zMin = atFloor.zMin, zMax = atFloor.zMax
  70886. }else{
  70887. zMin = this.buildParent.zMin, zMax = this.buildParent.zMax
  70888. }
  70889. }else{
  70890. zMin = this.zMin, zMax = this.zMax
  70891. }
  70892. return {zMin, zMax}
  70893. } */
  70894. getBound() {
  70895. var bound = new Box3();
  70896. var {
  70897. zMin,
  70898. zMax
  70899. } = this.getRealZ();
  70900. var points = this.buildType == 'floor' ? this.buildParent.points : this.points;
  70901. points.forEach(p => {
  70902. bound.expandByPoint(p.clone().setZ(zMin));
  70903. bound.expandByPoint(p.clone().setZ(zMax));
  70904. });
  70905. return bound;
  70906. }
  70907. getMarkerMaterial(type) {
  70908. if (!markerMats$2) {
  70909. markerMats$2 = {
  70910. default: new MeshBasicMaterial({
  70911. transparent: !0,
  70912. color: color$2,
  70913. opacity: 0.8,
  70914. map: texLoader$9.load(Potree.resourcePath + '/textures/whiteCircle.png'),
  70915. depthTest: false
  70916. }),
  70917. midPrepare: new MeshBasicMaterial({
  70918. //线中心的半透明点
  70919. transparent: !0,
  70920. color: color$2,
  70921. opacity: 0.4,
  70922. map: texLoader$9.load(Potree.resourcePath + '/textures/whiteCircle.png'),
  70923. depthTest: false
  70924. }),
  70925. hover: new MeshBasicMaterial({
  70926. transparent: !0,
  70927. color: color$2,
  70928. opacity: 1,
  70929. map: texLoader$9.load(Potree.resourcePath + '/textures/whiteCircle.png'),
  70930. depthTest: false
  70931. }),
  70932. select: new MeshBasicMaterial({
  70933. transparent: !0,
  70934. color: new Color('#00C8AF'),
  70935. opacity: 1,
  70936. map: texLoader$9.load(Potree.resourcePath + '/textures/whiteCircle.png'),
  70937. depthTest: false
  70938. })
  70939. };
  70940. }
  70941. return markerMats$2[type];
  70942. }
  70943. setMarkerSelected(marker, state, hoverObject) {
  70944. //console.warn(marker.id , state, hoverObject)
  70945. if (state == 'select') {
  70946. marker.selected = true;
  70947. marker.material = this.getMarkerMaterial('select');
  70948. } else if (state == 'unselect') {
  70949. marker.selected = false;
  70950. marker.material = this.getMarkerMaterial('default');
  70951. } else {
  70952. if (marker.selected) return; //选中时不允许修改为除了'unselect'以外的状态
  70953. if (state == 'hover') {
  70954. marker.material = this.getMarkerMaterial('hover');
  70955. } else if (state == 'unhover') {
  70956. if (marker.name.includes('mid')) {
  70957. marker.material = this.getMarkerMaterial('midPrepare');
  70958. } else {
  70959. marker.material = this.getMarkerMaterial('default');
  70960. }
  70961. }
  70962. }
  70963. }
  70964. select() {
  70965. //最多再显示一层子级的线,如building不会显示room中的hole的线
  70966. //box是一直显示的,但会切换材质
  70967. /*
  70968. 选中 box 线
  70969. building 自己(底盘)选中 自己, floor不带hole
  70970. floor 自己选中 自己, room不带hole
  70971. room 自己选中 自己
  70972. */ //注:自己的就代表定包括hole,如果有parentHoles的也(building上的hole的对应)
  70973. //console.log('select '+this.name, this.selected)
  70974. if (this.selected) return;
  70975. if (this.box) {
  70976. this.box.material = this.mats.boxSelected;
  70977. }
  70978. if (this.buildType == 'building' || this.buildType == 'floor') {
  70979. this.buildChildren.forEach(e => {
  70980. e.lineMesh.visible = true;
  70981. });
  70982. if (this.buildType == 'floor') {
  70983. Potree.Utils.setObjectLayers(this.box, 'bothMapAndScene');
  70984. Potree.Utils.setObjectLayers(this.buildParent.box, 'siteModelMapUnvisi'); //当选中floor或room时,building在地图不可见
  70985. }
  70986. } else if (this.buildType == 'room') {
  70987. Potree.Utils.setObjectLayers(this.buildParent.box, 'bothMapAndScene');
  70988. Potree.Utils.setObjectLayers(this.buildParent.buildParent.box, 'siteModelMapUnvisi');
  70989. }
  70990. this.lineMesh.visible = true;
  70991. this.markers && this.markers.forEach(e => Potree.Utils.updateVisible(e, 'select', true));
  70992. this.midMarkers && this.midMarkers.forEach(e => Potree.Utils.updateVisible(e, 'select', true));
  70993. var holes = this.holes.concat(this.parentHoles);
  70994. holes.forEach(e => e.select());
  70995. this.selected = true;
  70996. this.dispatchEvent({
  70997. type: 'select'
  70998. });
  70999. }
  71000. unselect() {
  71001. if (!this.selected) return;
  71002. //console.log('unselect '+this.name )
  71003. if (this.box) {
  71004. this.box.material = this.mats.boxDefault;
  71005. }
  71006. if (this.buildType == 'building' || this.buildType == 'floor') {
  71007. this.buildChildren.forEach(e => {
  71008. //(这里要保证选中前要先取消选中,否则如选中房间后取消了楼层,房间线就隐藏了)
  71009. e.lineMesh.visible = false;
  71010. });
  71011. if (this.buildType == 'floor') {
  71012. Potree.Utils.setObjectLayers(this.box, 'siteModelMapUnvisi');
  71013. Potree.Utils.setObjectLayers(this.buildParent.box, 'bothMapAndScene');
  71014. }
  71015. } else if (this.buildType == 'room') {
  71016. Potree.Utils.setObjectLayers(this.buildParent.box, 'siteModelMapUnvisi');
  71017. Potree.Utils.setObjectLayers(this.buildParent.buildParent.box, 'bothMapAndScene');
  71018. }
  71019. this.lineMesh.visible = false;
  71020. this.markers && this.markers.forEach(e => Potree.Utils.updateVisible(e, 'select', false));
  71021. this.midMarkers && this.midMarkers.forEach(e => Potree.Utils.updateVisible(e, 'select', false));
  71022. var holes = this.holes.concat(this.parentHoles);
  71023. holes.forEach(e => e.unselect());
  71024. this.selected = false;
  71025. this.dispatchEvent({
  71026. type: 'unselect'
  71027. });
  71028. }
  71029. ifContainsPoint(position) {
  71030. //看它所定义的空间是否包含某个坐标(要排除hole)
  71031. var {
  71032. zMin,
  71033. zMax
  71034. } = this.getRealZ();
  71035. if (position.z < zMin || position.z > zMax) return;
  71036. var holes = this.holes.concat(this.parentHoles);
  71037. var holesPoints = holes.filter(e => e != this && e.points.length > 2).map(e => e.points);
  71038. var inShape = math.isPointInArea(this.points, holesPoints, position);
  71039. return !!inShape;
  71040. }
  71041. }
  71042. class MetricUVGenerator {
  71043. constructor() {
  71044. this.a = new Vector3(), this.b = new Vector3(), this.c = new Vector3(), this.d = new Vector3();
  71045. }
  71046. generateTopUV(t, e, n, r, o) {
  71047. return [new Vector2(e[3 * n], e[3 * n + 1]), new Vector2(e[3 * r], e[3 * r + 1]), new Vector2(e[3 * o], e[3 * o + 1])];
  71048. }
  71049. generateSideWallUV(t, e, n, r, o, a) {
  71050. var s = e;
  71051. this.a.set(s[3 * n], s[3 * n + 1], s[3 * n + 2]), this.b.set(s[3 * r], s[3 * r + 1], s[3 * r + 2]), this.c.set(s[3 * o], s[3 * o + 1], s[3 * o + 2]), this.d.set(s[3 * a], s[3 * a + 1], s[3 * a + 2]);
  71052. var c = this.a.x !== this.b.x,
  71053. l = c ? this.b : this.d,
  71054. u = this.a.distanceTo(l),
  71055. d = l.distanceTo(this.c);
  71056. return [new Vector2(this.a.x, 0), c ? new Vector2(this.a.x + u, 0) : new Vector2(this.a.x, d), new Vector2(this.a.x + u, d), c ? new Vector2(this.a.x, d) : new Vector2(this.a.x + u, 0)];
  71057. }
  71058. }
  71059. var minFloorHeight = 0.5;
  71060. var ifDrawDatasetBound = true; //显示一下数据集的tightBound线框
  71061. var minMarkers = 3;
  71062. var Limit = {
  71063. zMin: -config$1.map.cameraHeight,
  71064. zMax: config$1.map.cameraHeight
  71065. }; //不能超过camera的高度,为了对称所以也限制了最低
  71066. var SiteModel = {
  71067. bus: new EventDispatcher(),
  71068. entities: [],
  71069. //所有实体
  71070. buildings: [],
  71071. //所有建筑父集
  71072. meshGroup: new Object3D(),
  71073. inEntity: null,
  71074. lastPos: new Vector3(Infinity, Infinity, Infinity),
  71075. init: function init() {
  71076. viewer.scene.scene.add(this.meshGroup);
  71077. this.meshGroup.name = 'siteModel';
  71078. this.SplitScreen = SplitScreen4Views;
  71079. if (Potree.settings.editType == 'pano') {
  71080. return;
  71081. }
  71082. this.createHeightPull();
  71083. this.history = new History({
  71084. applyData: data => {
  71085. if (data.entity.parent && data.entity.selected) {
  71086. data = Potree.Common.CloneObject(data); //避免使用后更改数据又被使用
  71087. data.entity.reDraw();
  71088. data.entity.initData(data);
  71089. data.isNew || data.entity.addMidMarkers();
  71090. data.entity.isNew = data.isNew;
  71091. data.entity.dispatchEvent('changeByHistory');
  71092. return true;
  71093. }
  71094. },
  71095. getData: entity => {
  71096. //if(entity.isNew)return
  71097. return {
  71098. entity,
  71099. points: entity.points.map(e => e.clone()),
  71100. ifDraw: true,
  71101. isNew: entity.isNew
  71102. };
  71103. }
  71104. });
  71105. if (Potree.settings.isTest && ifDrawDatasetBound) {
  71106. viewer.addEventListener('allLoaded', () => {
  71107. viewer.scene.pointclouds.forEach(pointcloud => {
  71108. var boxPoints = pointcloud.getUnrotBoundPoint();
  71109. var boundingBox = new BuildingBox({
  71110. name: '数据集tightBound_' + pointcloud.dataset_id,
  71111. points: boxPoints,
  71112. buildType: 'dataset',
  71113. zMax: pointcloud.bound.max.z,
  71114. zMin: pointcloud.bound.min.z,
  71115. ifDraw: true
  71116. });
  71117. this.meshGroup.add(boundingBox);
  71118. //boundingBox.markers.forEach(e=>e.visible = false)
  71119. });
  71120. });
  71121. }
  71122. if (Potree.settings.isOfficial) {
  71123. viewer.addEventListener('camera_changed', e => {
  71124. if (e.changeInfo && e.changeInfo.positionChanged) {
  71125. this.updateEntityAt();
  71126. }
  71127. });
  71128. }
  71129. {
  71130. var pressDelete = e => {
  71131. if (e.keyCode == KeyCodes.BACKSPACE || e.keyCode == KeyCodes.DELETE) {
  71132. if (this.selectedMarker) {
  71133. var entity = this.selectedMarker.parent;
  71134. var index = entity.markers.indexOf(this.selectedMarker);
  71135. entity.removeMarker(index);
  71136. if (entity.points.length < 2) {
  71137. //删到只剩一个点时重新画(如果是hole的点,直接删除hole吧?)
  71138. this.startInsertion('resume', entity);
  71139. }
  71140. }
  71141. }
  71142. };
  71143. viewer.inputHandler.addEventListener('keydown', pressDelete);
  71144. }
  71145. {
  71146. var updated = false;
  71147. this.bus.addEventListener('updated', () => {
  71148. Common.intervalTool.isWaiting('siteModelUpdated', () => {
  71149. this.changedCallback();
  71150. }, 500);
  71151. });
  71152. }
  71153. },
  71154. changedCallback() {
  71155. this.findPanos();
  71156. this.findEntityForDataset();
  71157. this.updateEntityAt(true); //更新所在建筑,更新marker显示
  71158. //console.log('changedCallback')
  71159. },
  71160. updateEntityAt(force) {
  71161. var {
  71162. measure
  71163. } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  71164. //if(!this.entities.length || this.editing) return //编辑时也要根据位置显示不同楼层的漫游点与cad
  71165. var fun = () => {
  71166. //延时update,防止卡顿
  71167. var currPos = viewer.mainViewport.view.position;
  71168. if (this.pauseUpdateEntity) return; // console.error('pauseUpdateEntity')
  71169. //if(force || !currPos.equals(this.lastPos) ){
  71170. //console.log('currPos ', currPos.toArray())
  71171. this.lastPos.copy(currPos);
  71172. var entity;
  71173. if (measure) {
  71174. //因为测量线的点可能在多个房间,所以干脆直接找在哪个楼层
  71175. var list = [];
  71176. measure.points.forEach(e => {
  71177. var entity = this.pointInWhichEntity(e, 'floor'); //每个点都找到其所在楼层
  71178. var item = list.find(e => e.entity == entity);
  71179. if (item) {
  71180. item.count++;
  71181. } else {
  71182. list.push({
  71183. entity,
  71184. count: 1
  71185. });
  71186. }
  71187. });
  71188. list.sort((a, b) => {
  71189. return b.count - a.count;
  71190. }); //找出出现次数最多的楼层
  71191. if (list[0]) {
  71192. entity = list[0].entity;
  71193. }
  71194. } else {
  71195. var searchPos = Potree.settings.displayMode == 'showPanos' ? viewer.images360.currentPano : currPos;
  71196. entity = this.pointInWhichEntity(searchPos, 'room');
  71197. }
  71198. if (force || this.inEntity != entity) {
  71199. var oldEntity = this.inEntity;
  71200. this.inEntity = entity;
  71201. //console.log('buildingChange', entity)
  71202. this.bus.dispatchEvent({
  71203. type: 'buildingChange',
  71204. entity
  71205. });
  71206. //this.updatePanosVisible(oldEntity, this.inEntity)
  71207. var lastFloor = this.currentFloor; //oldEntity ? oldEntity.buildType == 'floor' ? oldEntity : oldEntity.buildType == 'room' ? oldEntity.buildParent : null : null; //基本只会是floor或room
  71208. var currentFloor = entity ? entity.buildType == 'floor' ? entity : entity.buildType == 'room' ? entity.buildParent : null : null; //基本只会是floor或room
  71209. if (force || currentFloor != lastFloor) {
  71210. //console.log('改变了floor',lastFloor,currentFloor)
  71211. this.currentFloor = currentFloor;
  71212. this.bus.dispatchEvent({
  71213. type: 'FloorChange',
  71214. currentFloor
  71215. });
  71216. }
  71217. }
  71218. force = false;
  71219. //}
  71220. };
  71221. if (force) fun();else Common.intervalTool.isWaiting('sitemodelCameraInterval', fun, 500);
  71222. },
  71223. enter: function enter() {
  71224. Potree.Log('sitemodel enter');
  71225. this.clear(); //确保全部清空
  71226. this.editing = true;
  71227. //this.updatePanosVisible(null, null, true)//show all
  71228. viewer.updateFpVisiDatasets();
  71229. var mapViewport = viewer.mapViewer.viewports[0];
  71230. this.SplitScreen.split({
  71231. siteModel: true /* , viewports:[{name:'Top',viewport : mapViewport }] */
  71232. });
  71233. viewer.viewports.forEach(e => {
  71234. if (e.name != 'mapViewport') {
  71235. e.layersAdd('siteModelMapUnvisi');
  71236. }
  71237. if (e.name == 'right' || e.name == 'back') {
  71238. e.layersAdd('siteModeSideVisi');
  71239. }
  71240. });
  71241. viewer.images360.panos.forEach(pano => {
  71242. Potree.Utils.setObjectLayers(pano.marker, 'siteModelMapUnvisi');
  71243. //Potree.Utils.setObjectLayers(pano.label2, 'bothMapAndScene')
  71244. });
  71245. mapViewport.layersAdd('siteModeOnlyMapVisi'); //只有mapViewport能看到marker
  71246. },
  71247. leave: function leave() {
  71248. Potree.Log('sitemodel leave');
  71249. var mapViewport = viewer.mapViewer.viewports[0];
  71250. this.SplitScreen.recover();
  71251. viewer.viewports.forEach(e => {
  71252. if (e.name != 'mapViewport') {
  71253. e.layersRemove('siteModelMapUnvisi');
  71254. }
  71255. if (e.name == 'right' || e.name == 'back') {
  71256. e.layersRemove('siteModeSideVisi');
  71257. }
  71258. });
  71259. viewer.images360.panos.forEach(pano => {
  71260. Potree.Utils.setObjectLayers(pano.marker, 'sceneObjects');
  71261. //Potree.Utils.setObjectLayers(pano.label2, 'bothMapAndScene')
  71262. });
  71263. mapViewport.layersRemove('siteModeOnlyMapVisi');
  71264. this.clear();
  71265. this.editing = false;
  71266. this.updateEntityAt(true);
  71267. viewer.updateFpVisiDatasets();
  71268. },
  71269. addFloor: function addFloor(parent, dirType, sid, name) {
  71270. //dirType:'top'|'bottom'在上方建还是下方。如果建筑中没有楼层,默认在基底建一个
  71271. var buildType = 'floor';
  71272. var zMin, zMax;
  71273. if (parent.buildChildren.length == 0) {
  71274. zMin = parent.zMin;
  71275. zMax = zMin + Potree.config.siteModel.floorHeightDefault;
  71276. } else {
  71277. if (dirType == 'bottom') {
  71278. //var btm = Common.find(parent.buildChildren,null,[e=>e.zMin])
  71279. var btm = parent.buildChildren[0];
  71280. zMax = btm.zMin;
  71281. zMin = zMax - Potree.config.siteModel.floorHeightDefault;
  71282. } else {
  71283. //var top = Common.find(parent.buildChildren,null,[e=>e.zMax])
  71284. var top = parent.buildChildren[parent.buildChildren.length - 1];
  71285. zMin = top.zMax;
  71286. zMax = zMin + Potree.config.siteModel.floorHeightDefault;
  71287. }
  71288. }
  71289. var prop = {
  71290. buildType,
  71291. //name : Potree.config.siteModel.names[buildType],
  71292. zMin,
  71293. zMax,
  71294. buildParent: parent,
  71295. sid,
  71296. name,
  71297. ifDraw: true
  71298. };
  71299. var floor = new BuildingBox(prop);
  71300. /* parent.buildChildren.push(floor)
  71301. this.meshGroup.add(floor);
  71302. this.entities.push(floor) */
  71303. floor.update();
  71304. this.addEntity(floor, parent);
  71305. //this.selectEntity(floor)
  71306. if (this.selected == parent) {
  71307. //重新选择下,为了显示新楼层线框
  71308. parent.unselect();
  71309. parent.select();
  71310. }
  71311. this.bus.dispatchEvent('updated');
  71312. return floor;
  71313. },
  71314. startInsertion: function startInsertion(buildType, parent, sid, name, callback, cancelFun) {
  71315. var _this = this;
  71316. var zMin, zMax, entity, resume;
  71317. var mapViewport = viewer.mapViewer.viewports[0];
  71318. if (buildType == 'resume') {
  71319. //继续画(使用最后一个点或者新加的点)
  71320. resume = true;
  71321. entity = parent;
  71322. buildType = parent.buildType;
  71323. //删除原先所有的点,因为它们已经添加了事件,会很麻烦:
  71324. entity.reDraw(0);
  71325. entity.isNew = true; //当作新的来画
  71326. }
  71327. if (!resume) {
  71328. if (buildType == 'hole' || buildType == 'room') {
  71329. zMin = parent.zMin;
  71330. zMax = parent.zMax;
  71331. } else if (buildType == 'building') {
  71332. parent = null;
  71333. zMin = viewer.bound.boundingBox.min.z;
  71334. zMax = viewer.bound.boundingBox.min.z;
  71335. }
  71336. if (buildType == 'hole') {
  71337. entity = parent.addHole();
  71338. entity.isNew = true;
  71339. this.selectEntity(parent);
  71340. entity.select();
  71341. console.log('挖洞 ', entity.uuid);
  71342. } else {
  71343. var prop = {
  71344. buildType,
  71345. //name : Potree.config.siteModel.names[buildType],//'building',
  71346. zMin,
  71347. zMax,
  71348. buildParent: parent,
  71349. sid,
  71350. name,
  71351. ifDraw: true
  71352. };
  71353. entity = new BuildingBox(prop);
  71354. entity.isNew = true;
  71355. this.selectEntity(entity);
  71356. }
  71357. this.addEntity(entity, parent);
  71358. }
  71359. var timer;
  71360. var endDragFun = e => {
  71361. if (e.button == MOUSE.LEFT) {
  71362. this.history.beforeChange(entity);
  71363. var marker = entity.addMarker({
  71364. point: entity.points[entity.points.length - 1].clone()
  71365. });
  71366. this.history.afterChange(entity);
  71367. //entity.editStateChange(true) //重新激活reticule状态
  71368. entity.continueDrag(marker, e);
  71369. } else if (e.button === MOUSE.RIGHT) {
  71370. if (e.pressDistance < Potree.config.clickMaxDragDis) end(e); //非拖拽的话
  71371. else entity.continueDrag(null, e /* .drag.object */);
  71372. }
  71373. };
  71374. var finish = () => {
  71375. //结束绘画
  71376. viewer.removeEventListener('cancel_insertions', Exit);
  71377. entity.removeEventListener('unselect', Exit);
  71378. clearTimeout(timer);
  71379. entity.editStateChange(false);
  71380. //pressExit && viewer.inputHandler.removeEventListener('keydown', pressExit);
  71381. callback && callback(entity);
  71382. viewer.dispatchEvent('endBuildEntity');
  71383. };
  71384. var end = function end() {
  71385. var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  71386. //尝试结束
  71387. /* 退出的三种形式:
  71388. 1 普通:如果大于三个marker,结束且保留;否则重新画。()
  71389. 2 删除:直接结束且删除。(remove)
  71390. 3 结束:如果大于三个marker,结束且保留;否则结束且删除。 (finish)
  71391. 4 保留:无论几个marker,都保留着,结束。(remain)
  71392. */
  71393. if (e.remove) {
  71394. finish();
  71395. return _this.removeEntity(entity);
  71396. }
  71397. if (!e.remain && !e.finish && !e.remove && entity.markers.length <= minMarkers) {
  71398. //右键 当个数不够时取消
  71399. //重新开始画
  71400. entity.reDraw(1);
  71401. Potree.Utils.updateVisible(entity.markers[0], 'unMove', false);
  71402. var f = () => {
  71403. Potree.Utils.updateVisible(entity.markers[0], 'unMove', true);
  71404. entity.removeEventListener('dragChange', f);
  71405. };
  71406. entity.addEventListener('dragChange', f);
  71407. //console.log('waitcontinue')
  71408. entity.continueDrag(entity.markers[0], e);
  71409. return;
  71410. }
  71411. finish();
  71412. if (e.remain || !e.remove && entity.markers.length > 3) {
  71413. //保留
  71414. entity.removeMarker(entity.points.length - 1);
  71415. entity.markers.forEach(marker => {
  71416. marker.dispatchEvent('addHoverEvent');
  71417. });
  71418. if (buildType == 'room') {
  71419. _this.fitPullBox();
  71420. }
  71421. entity.isNew = false;
  71422. entity.addMidMarkers();
  71423. var boundingBox = entity.getBound();
  71424. var center = boundingBox.getCenter(new Vector3());
  71425. viewer.controls.setTarget(center, 2);
  71426. } else {
  71427. _this.removeEntity(entity); //直接删除没画好的,比较简单。这样就不用担心旧的continueDrag仍旧触发了
  71428. }
  71429. return entity;
  71430. };
  71431. var Exit = e => {
  71432. //强制结束
  71433. entity.removeEventListener('unselect', Exit);
  71434. if (viewer.inputHandler.drag) {
  71435. //还未触发drop的话
  71436. viewer.inputHandler.drag.object.dispatchEvent({
  71437. type: 'drop',
  71438. drag: viewer.inputHandler.drag,
  71439. viewer: viewer,
  71440. pressDistance: 0,
  71441. button: MOUSE.RIGHT
  71442. });
  71443. viewer.inputHandler.drag.object.isDragging = false;
  71444. } else {
  71445. end({
  71446. remain: true
  71447. });
  71448. }
  71449. viewer.inputHandler.drag = null;
  71450. };
  71451. viewer.dispatchEvent('cancel_insertions'); //取消之前的
  71452. viewer.addEventListener('cancel_insertions', Exit);
  71453. setTimeout(() => {
  71454. entity.isNew && entity.addEventListener('unselect', Exit);
  71455. }, 1); //因为刚创建会unselect一下所以延迟
  71456. var marker = entity.addMarker({
  71457. point: new Vector3(0, 0, 0)
  71458. });
  71459. Potree.Utils.updateVisible(marker, 'unMove', false); //这时候的位置是假的(0,0,0)所以先不可见
  71460. var f = () => {
  71461. Potree.Utils.updateVisible(marker, 'unMove', true);
  71462. entity.removeEventListener('dragChange', f);
  71463. };
  71464. entity.addEventListener('dragChange', f);
  71465. marker.isDragging = true;
  71466. viewer.inputHandler.startDragging(marker, {
  71467. dragViewport: mapViewport,
  71468. endDragFun,
  71469. notPressMouse: true
  71470. }); //notPressMouse代表不是通过按下鼠标来拖拽. dragViewport指定了只能在地图上拖拽
  71471. viewer.dispatchEvent('startBuildEntity');
  71472. var changeByHistory = e => {
  71473. if (!entity.isNew) return;
  71474. var marker = entity.markers[entity.points.length - 1];
  71475. viewer.inputHandler.startDragging(marker, {
  71476. dragViewport: mapViewport,
  71477. endDragFun,
  71478. notPressMouse: true
  71479. });
  71480. var I = viewer.inputHandler.intersect && (viewer.inputHandler.intersect.orthoIntersect || viewer.inputHandler.intersect.location);
  71481. if (I) {
  71482. entity.dragChange(I.clone(), entity.points.length - 1); //使最后一个点在鼠标处
  71483. }
  71484. };
  71485. entity.addEventListener('changeByHistory', changeByHistory);
  71486. return entity;
  71487. },
  71488. getPreDealData(points, zMin, zMax, initial, buildType, parent) {
  71489. /* if( buildType == 'building' ){
  71490. zMax = zMin //强制变得一样,作为基底。如果有必要,保存时再算真实的zMax。目前zMin没有保存所以数据是错的,会直接根据floor计算
  71491. } */
  71492. var bound = viewer.bound.boundingBox;
  71493. if (buildType == 'building' && initial) {
  71494. //初始数据错的,要自己建(只有一个building和floor) 原posIsLonlat
  71495. console.log('空间模型未编辑过, 初始化了一个');
  71496. points = [new Vector3(bound.min.x, bound.min.y, 0), new Vector3(bound.max.x, bound.min.y, 0), new Vector3(bound.max.x, bound.max.y, 0), new Vector3(bound.min.x, bound.max.y, 0)];
  71497. zMin = bound.min.z;
  71498. zMax = bound.max.z;
  71499. /* points = points.map(e=>{
  71500. return viewer.transform.lonlatToLocal.forward(e)
  71501. }) */
  71502. } else {
  71503. //相对于初始数据集的模型内坐标
  71504. points = points.map(e => this.transform(e, 'fromDataset'));
  71505. if (buildType == 'floor' && initial) {
  71506. zMin = bound.min.z;
  71507. zMax = bound.max.z;
  71508. }
  71509. }
  71510. return {
  71511. points,
  71512. zMax,
  71513. zMin
  71514. };
  71515. },
  71516. resetFromData: function resetFromData(entity) {
  71517. var _this2 = this;
  71518. var points = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  71519. var holes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
  71520. var zMin = arguments.length > 3 ? arguments[3] : undefined;
  71521. var zMax = arguments.length > 4 ? arguments[4] : undefined;
  71522. return function (points, zMin, zMax) {
  71523. var {
  71524. points,
  71525. zMax,
  71526. zMin
  71527. } = _this2.getPreDealData(points, zMin, zMax, _this2.autoBuild, entity.buildType, entity.buildParent);
  71528. if (entity.buildType != 'floor') entity.points = points;
  71529. if (entity.buildType == 'room') {
  71530. entity.zMin = zMin;
  71531. entity.zMax = zMax;
  71532. } else if (entity.buildType == 'floor') {
  71533. //改楼高
  71534. var height = zMax - zMin;
  71535. var zMax2 = entity.zMin + height;
  71536. SiteModel.changeZ(entity, 'zMax', zMax2);
  71537. }
  71538. {
  71539. //删除旧的holes重新添加
  71540. var holesOld = entity.holes;
  71541. holesOld.forEach(e => {
  71542. entity.removeHole(e);
  71543. });
  71544. holes.forEach(points => {
  71545. var ps = points.map(e => _this2.transform(e, 'fromDataset'));
  71546. var hole = entity.addHole(ps);
  71547. hole.addMidMarkers();
  71548. });
  71549. }
  71550. entity.update();
  71551. return entity;
  71552. }(points, zMin, zMax);
  71553. },
  71554. createFromData: function createFromData(buildType, parent, sid, name) {
  71555. var _this3 = this;
  71556. var points = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
  71557. var holes = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : [];
  71558. var zMin = arguments.length > 6 ? arguments[6] : undefined;
  71559. var zMax = arguments.length > 7 ? arguments[7] : undefined;
  71560. var initial = arguments.length > 8 ? arguments[8] : undefined;
  71561. var panos_ = arguments.length > 9 ? arguments[9] : undefined;
  71562. var flagPano = arguments.length > 10 ? arguments[10] : undefined;
  71563. return function (points, zMin, zMax) {
  71564. if (buildType != 'building' && buildType != 'floor' && buildType != 'room') return;
  71565. var {
  71566. points,
  71567. zMax,
  71568. zMin
  71569. } = _this3.getPreDealData(points, zMin, zMax, initial, buildType, parent);
  71570. var panos = [];
  71571. {
  71572. if (panos_) {
  71573. panos_.forEach(sid => {
  71574. var pano = viewer.images360.getPano(sid, 'sid');
  71575. if (pano) panos.push(pano);
  71576. });
  71577. }
  71578. flagPano = flagPano != void 0 ? viewer.images360.getPano(flagPano, 'sid') : null; //最中心的pano 或者 最靠近该实体的pano(当panos为空时)
  71579. if (!_this3.editing && buildType == 'floor' && !flagPano) {
  71580. //没有的话可能是自动添加的floor,直接用parent的吧
  71581. panos = parent.panos;
  71582. flagPano = parent.flagPano;
  71583. }
  71584. }
  71585. var prop = {
  71586. buildType,
  71587. points,
  71588. name,
  71589. sid,
  71590. zMin,
  71591. zMax,
  71592. buildParent: parent,
  71593. ifDraw: _this3.editing || Potree.settings.drawEntityData,
  71594. panos,
  71595. flagPano,
  71596. autoBuild: initial
  71597. };
  71598. var entity = new BuildingBox(prop);
  71599. SiteModel.addEntity(entity, parent);
  71600. if (_this3.editing) {
  71601. if (buildType == 'building' || buildType == 'room') {
  71602. entity.addMidMarkers();
  71603. }
  71604. }
  71605. holes.forEach(points => {
  71606. var ps = points.map(e => _this3.transform(e, 'fromDataset'));
  71607. var hole = entity.addHole(ps);
  71608. _this3.editing && hole.addMidMarkers();
  71609. });
  71610. /* if(buildType == 'floor'){
  71611. this.updateBuildingZ(parent)
  71612. } */
  71613. return entity;
  71614. }(points, zMin, zMax);
  71615. },
  71616. transform: function transform(pos, type) {
  71617. if (Potree.settings.editType == 'pano') {
  71618. // 模型不经转换
  71619. return new Vector3().copy(pos).setZ(0);
  71620. }
  71621. if (type == 'toDataset') {
  71622. var point = Potree.Utils.datasetPosTransform({
  71623. toDataset: true,
  71624. position: pos.clone(),
  71625. datasetId: Potree.settings.originDatasetId
  71626. });
  71627. return new Vector2().copy(point);
  71628. } else {
  71629. var position = new Vector3().copy(pos).setZ(0);
  71630. return Potree.Utils.datasetPosTransform({
  71631. fromDataset: true,
  71632. position,
  71633. datasetId: Potree.settings.originDatasetId
  71634. });
  71635. }
  71636. },
  71637. addEntity: function addEntity(entity, parent) {
  71638. if (entity.buildType != 'hole') {
  71639. this.meshGroup.add(entity);
  71640. this.entities.push(entity);
  71641. if (entity.buildType == 'building') {
  71642. this.buildings.push(entity);
  71643. } else {
  71644. parent.buildChildren.push(entity);
  71645. }
  71646. }
  71647. if (entity.buildType == 'room') {
  71648. entity.addEventListener('marker_dropped', () => {
  71649. this.fitPullBox();
  71650. });
  71651. } else if (entity.buildType == 'floor') {
  71652. this.updateBuildingZ(parent);
  71653. parent.dispatchEvent({
  71654. type: 'addFloor'
  71655. });
  71656. }
  71657. {
  71658. //仅能存在一个marker被选中。选中的点可以被删除
  71659. entity.addEventListener('clickMarker', e => {
  71660. if (this.selectedMarker == e.marker) {
  71661. this.selectedMarker.dispatchEvent({
  71662. type: 'clickSelect',
  71663. state: false
  71664. });
  71665. this.selectedMarker = null;
  71666. } else {
  71667. if (this.selectedMarker) {
  71668. this.selectedMarker.dispatchEvent({
  71669. type: 'clickSelect',
  71670. state: false
  71671. });
  71672. }
  71673. this.selectedMarker = e.marker;
  71674. this.selectedMarker.dispatchEvent({
  71675. type: 'clickSelect',
  71676. state: true
  71677. });
  71678. }
  71679. });
  71680. entity.addEventListener('removeMarker', e => {
  71681. if (this.selectedMarker == e.marker) {
  71682. this.selectedMarker = null;
  71683. }
  71684. });
  71685. var unselect = e => {
  71686. //取消选中实体或删除后
  71687. if (this.selectedMarker && entity.markers.includes(this.selectedMarker)) {
  71688. this.selectedMarker.dispatchEvent({
  71689. type: 'clickSelect',
  71690. state: false
  71691. });
  71692. this.selectedMarker = null;
  71693. }
  71694. };
  71695. entity.addEventListener('dispose', unselect);
  71696. entity.addEventListener('unselect', unselect);
  71697. }
  71698. //console.log('添加实体:', entity.buildType, entity.sid, entity.uuid)
  71699. this.bus.dispatchEvent('updated');
  71700. entity.addEventListener('startDragging', () => {
  71701. this.history.beforeChange(entity);
  71702. });
  71703. entity.addEventListener('marker_dropped', () => {
  71704. this.bus.dispatchEvent('updated');
  71705. this.history.afterChange(entity);
  71706. });
  71707. },
  71708. removeEntity: function removeEntity(entity) {
  71709. if (!this.entities.includes(entity)) return;
  71710. console.log('删除实体:', entity.buildType, entity.sid);
  71711. if (this.selected == entity) {
  71712. this.height_pull_box && (this.height_pull_box.visible = false);
  71713. this.selectEntity(null);
  71714. }
  71715. if (entity.buildType == 'building') {
  71716. var index = this.buildings.indexOf(entity);
  71717. if (index > -1) {
  71718. this.buildings.splice(index, 1);
  71719. }
  71720. } else {
  71721. var index = entity.buildParent.buildChildren.indexOf(entity);
  71722. if (index > -1) {
  71723. entity.buildParent.buildChildren.splice(index, 1);
  71724. if (entity.buildType == 'floor' && index == 0) {
  71725. this.updateBuildingZ(entity.buildParent);
  71726. }
  71727. }
  71728. }
  71729. var index = this.entities.indexOf(entity);
  71730. if (index > -1) {
  71731. this.entities.splice(index, 1);
  71732. }
  71733. entity.dispose();
  71734. var buildChildren = entity.buildChildren.slice();
  71735. buildChildren.forEach(e => this.removeEntity(e));
  71736. this.bus.dispatchEvent('updated');
  71737. },
  71738. updateBuildingZ: function updateBuildingZ(building) {
  71739. building.buildChildren = building.buildChildren.sort((e, a) => e.zMin - a.zMin); //从低到高排序
  71740. building.buildChildren[0] && (building.zMin = building.zMax = building.buildChildren[0].zMin); //基底高度
  71741. //building.zMax = building.buildChildren[building.buildChildren.length-1].zMax
  71742. if (this.editing) building.update({
  71743. dontUpdateChildren: true
  71744. });
  71745. building.dispatchEvent('updateBuildingZ');
  71746. },
  71747. selectEntity: function selectEntity(entity) {
  71748. var state = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  71749. viewer.dispatchEvent('content_changed');
  71750. if (state === false) {
  71751. entity.unselect();
  71752. if (this.selected == entity) this.selected = null;
  71753. viewer.controls.setTarget(null, 2);
  71754. return;
  71755. }
  71756. if (this.selected == entity || entity && entity.buildType == 'hole') return;
  71757. //this.buildings.forEach(e=>e.unselect())
  71758. this.selected && this.selected.unselect();
  71759. this.height_pull_box && (this.height_pull_box.visible = false);
  71760. if (entity) {
  71761. entity.select();
  71762. if (!entity.isNew) {
  71763. var boundingBox = entity.getBound();
  71764. var center = boundingBox.getCenter(new Vector3()); //中心点不一定在entity中,比如半环形建筑(所以要不要改成到漫游点呢)
  71765. viewer.controls.setTarget(center, 2);
  71766. }
  71767. } else {
  71768. viewer.controls.setTarget(null, 2);
  71769. }
  71770. this.selected = entity;
  71771. if (entity && !entity.dontDragFloorHeight && (entity.buildType == 'floor' || entity.buildType == 'room')) {
  71772. this.height_pull_box && (this.height_pull_box.visible = true);
  71773. this.fitPullBox();
  71774. }
  71775. if (entity && !entity.isNew && (entity.buildType == 'building' || entity.buildType == 'room') && entity.points.length < 2) {
  71776. this.startInsertion('resume', entity); //继续画
  71777. }
  71778. },
  71779. fitPullBox: function fitPullBox() {
  71780. //自适应拖拽楼层的pullMesh
  71781. if (!this.height_pull_box || !this.selected || this.selected.buildType != 'floor' && this.selected.buildType != 'room') return;
  71782. var bound = new Box3();
  71783. bound.expandByObject(this.selected.box);
  71784. var center = bound.getCenter(new Vector3());
  71785. var size = bound.getSize(new Vector3());
  71786. this.height_pull_box.scale.copy(size);
  71787. this.height_pull_box.position.copy(center);
  71788. },
  71789. changeZ: function changeZ(entity, dirType, value) {
  71790. // floor or room 修改zMin or zMax
  71791. var max, min; //limit
  71792. if (entity.buildType == 'floor') {
  71793. //楼层
  71794. var index = entity.buildParent.buildChildren.indexOf(entity);
  71795. if (dirType == 'zMax') {
  71796. var upper = entity.buildParent.buildChildren[index + 1];
  71797. entity.zMax = Math.min(Limit.zMax, value);
  71798. min = entity.zMin + minFloorHeight;
  71799. if (entity.zMax < min) {
  71800. entity.zMax = min;
  71801. } else {
  71802. if (upper) {
  71803. max = upper.zMax - minFloorHeight;
  71804. if (entity.zMax > max) {
  71805. entity.zMax = max;
  71806. }
  71807. }
  71808. }
  71809. if (upper) {
  71810. upper.zMin = entity.zMax;
  71811. upper.update();
  71812. upper.dispatchEvent({
  71813. type: 'changeHeight'
  71814. });
  71815. }
  71816. } else {
  71817. var lower = entity.buildParent.buildChildren[index - 1];
  71818. entity.zMin = Math.max(Limit.zMin, value);
  71819. max = entity.zMax - minFloorHeight;
  71820. if (entity.zMin > max) {
  71821. entity.zMin = max;
  71822. } else {
  71823. if (lower) {
  71824. min = lower.zMin + minFloorHeight;
  71825. if (entity.zMin < min) {
  71826. entity.zMin = min;
  71827. }
  71828. }
  71829. }
  71830. if (lower) {
  71831. lower.zMax = entity.zMin;
  71832. lower.update();
  71833. lower.dispatchEvent({
  71834. type: 'changeHeight'
  71835. });
  71836. }
  71837. if (index == 0) this.updateBuildingZ(entity.buildParent);
  71838. }
  71839. } else if (entity.buildType == 'room') {
  71840. //房间
  71841. //按照navvis的是不一定限制在当前楼层,只要高度不超过当前楼层即可。
  71842. var maxHeight = entity.buildParent.zMax - entity.buildParent.zMin;
  71843. if (dirType == 'zMax') {
  71844. min = entity.zMin + minFloorHeight;
  71845. max = entity.zMin + maxHeight;
  71846. entity.zMax = MathUtils.clamp(value, min, max);
  71847. } else {
  71848. min = entity.zMax - maxHeight;
  71849. max = entity.zMax - minFloorHeight;
  71850. entity.zMin = MathUtils.clamp(value, min, max);
  71851. }
  71852. }
  71853. entity.update();
  71854. entity.dispatchEvent({
  71855. type: 'changeHeight'
  71856. });
  71857. //this.selected.emit('update')
  71858. this.fitPullBox();
  71859. this.bus.dispatchEvent('updated');
  71860. },
  71861. createHeightPull: function createHeightPull() {
  71862. //拖拽楼层的bounding box
  71863. var boxGeo = new BoxBufferGeometry(1, 1, 1 / 4);
  71864. var boxMat = new MeshBasicMaterial({
  71865. color: "#F00",
  71866. opacity: 0,
  71867. transparent: true,
  71868. depthTest: false,
  71869. side: 2
  71870. });
  71871. var height_pull_box_up = new Mesh(boxGeo, boxMat);
  71872. var height_pull_box_down = new Mesh(boxGeo, boxMat);
  71873. height_pull_box_up.name = 'height_pull_box_up';
  71874. height_pull_box_down.name = 'height_pull_box_down';
  71875. this.height_pull_box = new Object3D();
  71876. this.height_pull_box.name = 'height_pull_box';
  71877. this.height_pull_box.add(height_pull_box_up);
  71878. this.height_pull_box.add(height_pull_box_down);
  71879. this.height_pull_box.visible = false;
  71880. this.meshGroup.add(this.height_pull_box);
  71881. height_pull_box_up.position.set(0, 0, 1 / 2 /* 3/8 */);
  71882. height_pull_box_down.position.set(0, 0, -1 / 2 /* -3/8 */);
  71883. Potree.Utils.setObjectLayers(this.height_pull_box, 'siteModeSideVisi');
  71884. var mouseover = e => {
  71885. viewer.dispatchEvent({
  71886. type: "CursorChange",
  71887. action: "add",
  71888. name: "siteModelFloorDrag"
  71889. });
  71890. };
  71891. var mouseleave = e => {
  71892. viewer.dispatchEvent({
  71893. type: "CursorChange",
  71894. action: "remove",
  71895. name: "siteModelFloorDrag"
  71896. });
  71897. };
  71898. var firstZ, firstIntersect;
  71899. var drag = e => {
  71900. var intersect = e.intersect.orthoIntersect; //不要点云的intersect,只要orthocamera算出的平面intersect
  71901. if (firstIntersect != void 0) {
  71902. var moveZ = intersect.z - firstIntersect;
  71903. if (this.selected.buildType == 'floor') {
  71904. //楼层
  71905. //限制高度不能超过上下
  71906. if (e.target == height_pull_box_up) {
  71907. if (firstZ == void 0) firstZ = this.selected.zMax;
  71908. this.changeZ(this.selected, 'zMax', firstZ + moveZ);
  71909. } else {
  71910. if (firstZ == void 0) firstZ = this.selected.zMin;
  71911. this.changeZ(this.selected, 'zMin', firstZ + moveZ);
  71912. }
  71913. } else if (this.selected.buildType == 'room') {
  71914. //房屋
  71915. if (e.target == height_pull_box_up) {
  71916. if (firstZ == void 0) firstZ = this.selected.zMax;
  71917. this.changeZ(this.selected, 'zMax', firstZ + moveZ);
  71918. } else {
  71919. if (firstZ == void 0) firstZ = this.selected.zMin;
  71920. this.changeZ(this.selected, 'zMin', firstZ + moveZ);
  71921. }
  71922. }
  71923. } else {
  71924. firstIntersect = intersect.z;
  71925. }
  71926. };
  71927. var drop = e => {
  71928. firstZ = firstIntersect = null;
  71929. };
  71930. height_pull_box_up.addEventListener('mousemove', mouseover);
  71931. height_pull_box_down.addEventListener('mousemove', mouseover);
  71932. height_pull_box_up.addEventListener('mouseleave', mouseleave);
  71933. height_pull_box_down.addEventListener('mouseleave', mouseleave);
  71934. height_pull_box_up.addEventListener('drag', drag);
  71935. height_pull_box_down.addEventListener('drag', drag);
  71936. height_pull_box_up.addEventListener('drop', drop);
  71937. height_pull_box_down.addEventListener('drop', drop);
  71938. },
  71939. pointInWhichEntity(location, buildType, ifIgnoreHole) {
  71940. //buildType是要找的建筑类型
  71941. //location 可以是pano或者坐标
  71942. //由于房间可能在building外,所以房间要另外单独识别。
  71943. var lastResult; //最接近的上一层结果,如果没有result返回这个
  71944. var result;
  71945. var level = {
  71946. building: 0,
  71947. floor: 1,
  71948. room: 2
  71949. };
  71950. var traverse = (parent, buildType) => {
  71951. //返回第一个符合标准的实体
  71952. var contains;
  71953. if (location instanceof Vector3) {
  71954. contains = parent.ifContainsPoint(location);
  71955. } else {
  71956. //is pano
  71957. contains = parent.panos.includes(location);
  71958. }
  71959. if (contains) {
  71960. if (!lastResult || level[lastResult.buildType] < level[parent.buildType]) lastResult = parent;
  71961. if (parent.buildType == buildType) {
  71962. return parent;
  71963. } else {
  71964. for (var i = 0, len = parent.buildChildren.length; i < len; i++) {
  71965. var result1 = traverse(parent.buildChildren[i]);
  71966. if (result1) return result1;
  71967. }
  71968. }
  71969. }
  71970. };
  71971. //因为建筑可能重叠,所以需要先找到最接近其中心的建筑物
  71972. result = Common.sortByScore(this.buildings, [building => {
  71973. return traverse(building, 'building'); //在building中
  71974. }], [building => {
  71975. //写法类似pointInWhichPointcloud
  71976. var boundingBox = building.getBound();
  71977. var center = boundingBox.getCenter(new Vector3());
  71978. var position = location instanceof Vector3 ? location : location.position;
  71979. var dis = position.distanceTo(center);
  71980. var size = boundingBox.getSize(new Vector3());
  71981. var length = size.length() / 2;
  71982. return length / dis;
  71983. }]);
  71984. var building = result && result[0] && result[0].score > 1 && result[0].item;
  71985. if (buildType == 'building' || !building) return building;
  71986. result = traverse(building, buildType);
  71987. /* if(!result && buildType == 'room'){//如果要找的是room, 且按刚才的顺序找不到的话,就单独从所有rooms中找一遍。因为room可能不在floor和building内。
  71988. let rooms = this.entities.filter(e=>e.buildType == 'room');
  71989. result = rooms.find(e=>e.ifContainsPoint(position))
  71990. }*/
  71991. //虽然房间可以画到上级之外,但是为了方便起见,假定房间绝对在楼层之内。找不到的话要调整空间模型了。
  71992. return result || lastResult;
  71993. },
  71994. findPanos: function findPanos() {
  71995. {
  71996. this.entities.forEach(entity => {
  71997. //清空:
  71998. entity.panos = [];
  71999. entity.flagPano = null;
  72000. viewer.images360.panos.forEach(pano => {
  72001. if (entity.ifContainsPoint(pano.position)) {
  72002. entity.panos.push(pano);
  72003. }
  72004. });
  72005. });
  72006. }
  72007. /* viewer.images360.panos.forEach(pano=>{ //一个漫游点只对应一个实体的话
  72008. let result = this.pointInWhichEntity(pano.position, 'room');
  72009. {//get panos for every entities
  72010. let entity = result
  72011. while(entity){
  72012. entity.panos.push(pano);
  72013. entity = entity.buildParent
  72014. }
  72015. }
  72016. }) */
  72017. {
  72018. //search center pano
  72019. this.entities.forEach(entity => {
  72020. var panos = entity.panos;
  72021. if (panos.length == 0) return;
  72022. var bound = entity.getBound();
  72023. var center = bound.getCenter(new Vector3());
  72024. var request = [];
  72025. var rank = [Images360.scoreFunctions.distanceSquared({
  72026. position: center
  72027. })];
  72028. //let panos = entity.panos && entity.panos.length ? entity.panos : viewer.images360.panos //entity没有panos的话,就扩大到所有panos
  72029. var r = Common.sortByScore(panos, request, rank);
  72030. if (r && r.length) {
  72031. entity.flagPano = r[0].item;
  72032. } else {
  72033. console.error('no flagPano??');
  72034. }
  72035. });
  72036. }
  72037. },
  72038. findEntityForDataset: function findEntityForDataset() {
  72039. //为每一个数据集寻找它所属的最小实体
  72040. /* var entities = this.entities.filter(e=>e.buildType == 'room' || e.buildType == 'floor' && e.buildChildren.length == 0)
  72041. viewer.scene.pointclouds.forEach(pointcloud=>{
  72042. let cloudVolume = pointcloud.getVolume()
  72043. let scores = []
  72044. entities.forEach(entity=>{
  72045. let volume = entity.intersectPointcloudVolume(pointcloud)
  72046. //注:默认已经findPanos过
  72047. let panos = entity.panos.filter(e=>pointcloud.panos.includes(e));
  72048. let panoCount = panos.length
  72049. let score = volume / cloudVolume + panoCount / pointcloud.panos.length
  72050. scores.push({entity, volume, panoCount, score})
  72051. })
  72052. scores.sort((a,b)=>{ return b.score-a.score })
  72053. if(scores.length == 0 || scores[0].volume/cloudVolume < 0.0001 && scores[0].volume < 3 ){//如果约等于0
  72054. pointcloud.belongToEntity = null
  72055. }else{
  72056. pointcloud.belongToEntity = scores[0].entity;
  72057. }
  72058. }) */
  72059. var getScores = (pointcloud, entities, cloudVolume) => {
  72060. var scores = [];
  72061. entities.forEach(entity => {
  72062. var volume = entity.intersectPointcloudVolume(pointcloud);
  72063. //注:默认已经findPanos过
  72064. var panos = entity.panos.filter(e => pointcloud.panos.includes(e));
  72065. var panoCount = panos.length;
  72066. var score = volume / cloudVolume;
  72067. if (pointcloud.panos.length > 0) {
  72068. score += panoCount / pointcloud.panos.length;
  72069. } else {
  72070. //score += 1
  72071. }
  72072. scores.push({
  72073. entity,
  72074. volume,
  72075. panoCount,
  72076. score
  72077. });
  72078. });
  72079. scores.sort((a, b) => {
  72080. return b.score - a.score;
  72081. });
  72082. return scores;
  72083. };
  72084. viewer.scene.pointclouds.forEach(pointcloud => {
  72085. //先判断父级,如果父集不通过就不判断子级。
  72086. var cloudVolume = pointcloud.getVolume();
  72087. var entities = this.buildings;
  72088. while (1) {
  72089. var scores = getScores(pointcloud, entities, cloudVolume);
  72090. if (scores.length == 0 || scores[0].volume / cloudVolume < 0.0001 && scores[0].volume < 3) {
  72091. //如果约等于0
  72092. if (scores[0] && scores[0].entity.buildType == 'room') {
  72093. pointcloud.belongToEntity = scores[0].entity; //当该数据集在楼层中,但不在楼层中的任意一个房间时,任意挂载在其中一个房间上。
  72094. break;
  72095. }
  72096. pointcloud.belongToEntity = null;
  72097. break;
  72098. } else {
  72099. entities = scores[0].entity.buildChildren;
  72100. if (entities.length == 0) {
  72101. pointcloud.belongToEntity = scores[0].entity;
  72102. break;
  72103. }
  72104. }
  72105. }
  72106. });
  72107. /*
  72108. 旧版:
  72109. 只需要考虑 floor 和 room, 因为building的只有一个基底没高度
  72110. floor 和 room 在空间中没有完全的从属关系,因为room可以超出floor之外。所以直接混在一起来查找,但要排除有房间的楼层。
  72111. (现在改为层层递进查找,否则数据集包含entity多的,会直接挂载到体积最大的房间里,即使看起来主体点云并不在该房间)
  72112. 有的数据集虽然很高,但只有近地面的部分才是主体,这部分一般含有全部漫游点。为了防止上层的实体因体积较大而分数高,就把包含漫游点的个数也加入考虑。
  72113. 重叠体积大、且包含漫游点最多的最小实体将会拥有该点云。
  72114. 期望: 最好不挂载到最小子级,因为现在有房间都到房间里了。
  72115. */
  72116. },
  72117. clear: function clear() {
  72118. //清空
  72119. /* entities:[], //所有实体
  72120. buildings:[], //所有建筑父集
  72121. meshGroup: new THREE.Object3D, */
  72122. this.selectEntity(null);
  72123. var length = this.entities.length;
  72124. for (var i = 0; i < length; i++) {
  72125. this.entities[i].dispose();
  72126. }
  72127. this.entities = [];
  72128. this.buildings = [];
  72129. this.inEntity = null;
  72130. },
  72131. gotoEntity(id, isNearBy) {
  72132. var duration = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1000;
  72133. var entity = this.entities.find(e => e.sid == id);
  72134. var aimPano;
  72135. if (!entity) {
  72136. return console.error('没找到entity ');
  72137. }
  72138. if (Potree.settings.displayMode == 'showPanos') {
  72139. if (isNearBy && entity.panos.length) {
  72140. if (entity.panos.includes(viewer.images360.currentPano)) return 'posNoChange'; //已在当前实体中
  72141. var position = viewer.scene.getActiveCamera().position;
  72142. var request = [];
  72143. var rank = [Images360.scoreFunctions.distanceSquared({
  72144. position
  72145. })];
  72146. var r = Common.sortByScore(entity.panos, request, rank);
  72147. aimPano = r[0].item;
  72148. } else {
  72149. if (!entity.flagPano) {
  72150. return console.log('没有flagPano');
  72151. }
  72152. aimPano = entity.flagPano;
  72153. }
  72154. if (aimPano == viewer.images360.currentPano) return 'posNoChange';
  72155. viewer.images360.flyToPano(aimPano);
  72156. } else {
  72157. if (isNearBy && entity.ifContainsPoint(viewer.images360.position)) {
  72158. return 'posNoChange'; //已在当前实体中
  72159. }
  72160. var boundingBox = entity.getBound();
  72161. var _position = boundingBox.getCenter(new Vector3()); //中心点不一定在entity中,比如半环形建筑(所以要不要改成到漫游点呢)
  72162. var size = boundingBox.getSize(new Vector3());
  72163. if (viewer.modules.Clip && viewer.modules.Clip.editing) {
  72164. viewer.modules.Clip.bus.dispatchEvent({
  72165. type: 'flyToPos',
  72166. position: _position
  72167. });
  72168. } else {
  72169. if (math.closeTo(_position, viewer.images360.position)) return 'posNoChange';
  72170. viewer.scene.view.setView({
  72171. position: _position,
  72172. duration
  72173. });
  72174. }
  72175. viewer.mapViewer.moveTo(_position, size, duration);
  72176. }
  72177. return true;
  72178. },
  72179. focusEntity(id) {
  72180. var entity = this.entities.find(e => e.sid == id);
  72181. var boundingBox = entity.getBound();
  72182. //let boundSize = boundingBox.getSize(new THREE.Vector3())
  72183. var center = boundingBox.getCenter(new Vector3());
  72184. this.SplitScreen.focusOnObject(boundingBox, center);
  72185. this.gotoEntity(id, false, 0);
  72186. },
  72187. removeIlligalArchi() {
  72188. //删除marker数量小于3个的建筑,当保存时
  72189. var needDelete = [];
  72190. this.entities.forEach(e => {
  72191. if (e.points.length < 3) {
  72192. needDelete.push(e);
  72193. }
  72194. });
  72195. needDelete.forEach(e => this.removeEntity(e));
  72196. }
  72197. };
  72198. // Author: Fyrestar https://mevedia.com (https://github.com/Fyrestar/THREE.InfiniteGridHelper)
  72199. class InfiniteGridHelper extends Mesh {
  72200. constructor(size1, size2, color, distance) {
  72201. var opacity1 = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0.2;
  72202. var opacity2 = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 1;
  72203. color = color || new Color('white');
  72204. size1 = size1 || 10;
  72205. size2 = size2 || 100;
  72206. distance = distance || 8000; //可视距离?越远越模糊
  72207. var geometry = new PlaneBufferGeometry(2, 2, 1, 1);
  72208. var material = new ShaderMaterial({
  72209. side: DoubleSide,
  72210. uniforms: {
  72211. uSize1: {
  72212. value: size1
  72213. },
  72214. uSize2: {
  72215. value: size2
  72216. },
  72217. opacity1: {
  72218. //线条1的 小格子
  72219. value: opacity1
  72220. },
  72221. opacity2: {
  72222. //线条2的
  72223. value: opacity2
  72224. },
  72225. uColor: {
  72226. value: color
  72227. },
  72228. uDistance: {
  72229. value: distance
  72230. }
  72231. },
  72232. transparent: true,
  72233. vertexShader: "\n \n varying vec3 worldPosition;\n \n uniform float uDistance;\n \n void main() {\n \n vec3 pos = position.xyz * uDistance;\n pos.xy += cameraPosition.xy;\n \n worldPosition = pos;\n \n gl_Position = projectionMatrix * modelViewMatrix * vec4(pos, 1.0);\n \n }\n ",
  72234. fragmentShader: "\n \n varying vec3 worldPosition;\n \n uniform float uSize1;\n uniform float uSize2;\n uniform float opacity1;\n uniform float opacity2;\n uniform vec3 uColor;\n uniform float uDistance;\n \n \n \n float getGrid(float size) {\n \n vec2 r = worldPosition.xy / size;\n \n \n vec2 grid = abs(fract(r - 0.5) - 0.5) / fwidth(r);\n float line = min(grid.x, grid.y);\n \n \n return 1.0 - min(line, 1.0);\n }\n //\u4E3A\u4F55\u4FA7\u9762\u770B\u4E0D\u5230\u7EBF\uFF0C\u56E0\u4E3Amesh\u7684\u6B63\u4FA7\u9762\u90FD\u770B\u4E0D\u5230\uFF1F\n\n void main() {\n \n \n float d = 1.0 - min(distance(cameraPosition.xy, worldPosition.xy) / uDistance, 1.0);\n \n float g1 = getGrid(uSize1);\n float g2 = getGrid(uSize2);\n \n \n gl_FragColor = vec4(uColor.rgb, mix(g2, g1, g1) * pow(d, 3.0));\n //gl_FragColor.a = mix(0.5 * gl_FragColor.a, gl_FragColor.a, g2);\n gl_FragColor.a = mix(opacity1 * gl_FragColor.a, opacity2 * gl_FragColor.a, g2);\n \n \n if ( gl_FragColor.a <= 0.0 ) discard;\n \n \n }\n \n ",
  72235. extensions: {
  72236. derivatives: true
  72237. }
  72238. });
  72239. super(geometry, material);
  72240. this.frustumCulled = false;
  72241. }
  72242. }
  72243. ;
  72244. /*
  72245. THREE.InfiniteGridHelper.prototype = {
  72246. ...THREE.Mesh.prototype,
  72247. ...THREE.Object3D.prototype,
  72248. ...THREE.EventDispatcher.prototype
  72249. };
  72250. */
  72251. var TransformControls = function TransformControls(camera, domElement, options) {
  72252. if (domElement === undefined) {
  72253. console.warn('THREE.TransformControls: The second parameter "domElement" is now mandatory.');
  72254. domElement = document;
  72255. }
  72256. Object3D.call(this);
  72257. this.visible = false;
  72258. this.domElement = domElement;
  72259. var _gizmo = new TransformControlsGizmo(options);
  72260. this.add(_gizmo);
  72261. this._gizmo = _gizmo;
  72262. var _plane = new TransformControlsPlane(options);
  72263. this.add(_plane);
  72264. /* this.linesAssistance = new TransformControlsLines(options); //水平 垂直 辅助
  72265. this.add( this.linesAssistance ); */
  72266. var scope = this;
  72267. //this.player = options.player;//xzw add
  72268. this.options = options; //xzw add
  72269. // Define properties with getters/setter
  72270. // Setting the defined property will automatically trigger change event
  72271. // Defined properties are passed down to gizmo and plane
  72272. defineProperty("camera", camera);
  72273. defineProperty("object", undefined);
  72274. defineProperty("enabled", true);
  72275. defineProperty("axis", null);
  72276. defineProperty("mode", "translate");
  72277. defineProperty("translationSnap", null);
  72278. defineProperty("rotationSnap", null);
  72279. defineProperty("scaleSnap", null);
  72280. defineProperty("space", "world");
  72281. defineProperty("size", 1);
  72282. defineProperty("dragging", false);
  72283. defineProperty("showX", true);
  72284. defineProperty("showY", true);
  72285. defineProperty("showZ", true);
  72286. var changeEvent = {
  72287. type: "change"
  72288. };
  72289. var mouseDownEvent = {
  72290. type: "mouseDown"
  72291. };
  72292. var mouseUpEvent = {
  72293. type: "mouseUp",
  72294. mode: scope.mode
  72295. };
  72296. var objectChangeEvent = {
  72297. type: "objectChange"
  72298. };
  72299. // Reusable utility variables
  72300. var ray = new Raycaster();
  72301. var _tempVector = new Vector3();
  72302. var _tempVector2 = new Vector3();
  72303. var _tempQuaternion = new Quaternion();
  72304. var _unit = {
  72305. X: new Vector3(1, 0, 0),
  72306. Y: new Vector3(0, 1, 0),
  72307. Z: new Vector3(0, 0, 1)
  72308. };
  72309. var pointStart = new Vector3();
  72310. var pointEnd = new Vector3();
  72311. var offset = new Vector3();
  72312. var rotationAxis = new Vector3();
  72313. var startNorm = new Vector3();
  72314. var endNorm = new Vector3();
  72315. var rotationAngle = 0;
  72316. var cameraPosition = new Vector3();
  72317. var cameraQuaternion = new Quaternion();
  72318. var cameraScale = new Vector3();
  72319. var parentPosition = new Vector3();
  72320. var parentQuaternion = new Quaternion();
  72321. var parentQuaternionInv = new Quaternion();
  72322. var parentScale = new Vector3();
  72323. var worldPositionStart = new Vector3();
  72324. var worldQuaternionStart = new Quaternion();
  72325. var worldScaleStart = new Vector3();
  72326. var worldPosition = new Vector3();
  72327. var worldQuaternion = new Quaternion();
  72328. var worldQuaternionInv = new Quaternion();
  72329. var worldScale = new Vector3();
  72330. var eye = new Vector3();
  72331. var positionStart = new Vector3();
  72332. var quaternionStart = new Quaternion();
  72333. var scaleStart = new Vector3();
  72334. // TODO: remove properties unused in plane and gizmo
  72335. defineProperty("worldPosition", worldPosition);
  72336. defineProperty("worldPositionStart", worldPositionStart);
  72337. defineProperty("worldQuaternion", worldQuaternion);
  72338. defineProperty("worldQuaternionStart", worldQuaternionStart);
  72339. defineProperty("cameraPosition", cameraPosition);
  72340. defineProperty("cameraQuaternion", cameraQuaternion);
  72341. defineProperty("pointStart", pointStart);
  72342. defineProperty("pointEnd", pointEnd);
  72343. defineProperty("rotationAxis", rotationAxis);
  72344. defineProperty("rotationAngle", rotationAngle);
  72345. defineProperty("eye", eye);
  72346. {
  72347. domElement.addEventListener("mousedown", onPointerDown, false);
  72348. domElement.addEventListener("touchstart", onPointerDown, false);
  72349. domElement.addEventListener("mousemove", onPointerHover, false);
  72350. domElement.addEventListener("touchmove", onPointerHover, false);
  72351. domElement.addEventListener("touchmove", onPointerMove, false);
  72352. document.addEventListener("mouseup", onPointerUp, false);
  72353. domElement.addEventListener("touchend", onPointerUp, false);
  72354. domElement.addEventListener("touchcancel", onPointerUp, false);
  72355. domElement.addEventListener("touchleave", onPointerUp, false);
  72356. var drag = () => {
  72357. if (this.dragging) {
  72358. this.pointerMove();
  72359. return {
  72360. stopContinue: true
  72361. };
  72362. }
  72363. };
  72364. this.addEventListener('dragging', drag, {
  72365. importance: 10
  72366. });
  72367. viewer.addEventListener('global_drag', drag, {
  72368. importance: 10
  72369. });
  72370. }
  72371. this.setRotateMethod = function (number) {
  72372. //add 注意为2时 旋转期间不能改变位置 space可能不能为local ._gizmo.hideAxis = { rotate:[这里必须包含'e' ] }
  72373. this.rotateMethod = number;
  72374. };
  72375. this.dispose = function () {
  72376. domElement.removeEventListener("mousedown", onPointerDown);
  72377. domElement.removeEventListener("touchstart", onPointerDown);
  72378. domElement.removeEventListener("mousemove", onPointerHover);
  72379. domElement.removeEventListener("mousemove", onPointerMove);
  72380. domElement.removeEventListener("touchmove", onPointerHover);
  72381. domElement.removeEventListener("touchmove", onPointerMove);
  72382. document.removeEventListener("mouseup", onPointerUp);
  72383. domElement.removeEventListener("touchend", onPointerUp);
  72384. domElement.removeEventListener("touchcancel", onPointerUp);
  72385. domElement.removeEventListener("touchleave", onPointerUp);
  72386. this.traverse(function (child) {
  72387. if (child.geometry) child.geometry.dispose();
  72388. if (child.material) child.material.dispose();
  72389. });
  72390. };
  72391. // Set current object
  72392. this.attach = function (object) {
  72393. this.object = object;
  72394. this.visible = true;
  72395. //Config.keyCon = false;//add
  72396. //this.linesAssistance.setVisible(true)
  72397. viewer.dispatchEvent('content_changed');
  72398. return this;
  72399. };
  72400. // Detatch from object
  72401. this.detach = function () {
  72402. this.object = undefined;
  72403. this.visible = false;
  72404. this.axis = null;
  72405. //Config.keyCon = true;//add
  72406. //this.linesAssistance.setVisible(false)
  72407. viewer.dispatchEvent('content_changed');
  72408. return this;
  72409. };
  72410. //this.space = 'local'
  72411. /* this.hideAxis = function ( mode, axis=[] ) {//xzw add 设置不可见的axis
  72412. var handles = [];
  72413. handles = handles.concat( this._gizmo.picker[ mode ].children );
  72414. handles = handles.concat( this._gizmo.gizmo[ mode ].children );
  72415. handles = handles.concat( this._gizmo.helper[ mode ].children );
  72416. handles.forEach(e=>e.visible = false)
  72417. axis.forEach(name=>{
  72418. handles.filter(handle =>!handle.name.includes(name))
  72419. })
  72420. handles.forEach(e=>e.visible = true)
  72421. }; */
  72422. // Defined getter, setter and store for a property
  72423. function defineProperty(propName, defaultValue) {
  72424. var propValue = defaultValue;
  72425. Object.defineProperty(scope, propName, {
  72426. get: function get() {
  72427. return propValue !== undefined ? propValue : defaultValue;
  72428. },
  72429. set: function set(value) {
  72430. if (propValue !== value) {
  72431. propValue = value;
  72432. _plane[propName] = value;
  72433. _gizmo[propName] = value;
  72434. scope.dispatchEvent({
  72435. type: propName + "-changed",
  72436. value: value
  72437. });
  72438. scope.dispatchEvent(changeEvent);
  72439. }
  72440. }
  72441. });
  72442. scope[propName] = defaultValue;
  72443. _plane[propName] = defaultValue;
  72444. _gizmo[propName] = defaultValue;
  72445. }
  72446. // updateMatrixWorld updates key transformation variables
  72447. this.updateMatrixWorld = function () {
  72448. if (!this.visible) return; //add
  72449. if (this.object !== undefined) {
  72450. this.object.updateMatrixWorld();
  72451. this.object.parent.matrixWorld.decompose(parentPosition, parentQuaternion, parentScale);
  72452. this.object.matrixWorld.decompose(worldPosition, worldQuaternion, worldScale);
  72453. //add
  72454. if (this.object.boundingBox) {
  72455. var boundingBox = this.object.boundingBox.clone().applyMatrix4(this.object.matrixWorld);
  72456. boundingBox.getCenter(worldPosition); //bound中心
  72457. if (this.pivotOnBottom) {
  72458. worldPosition.setZ(boundingBox.min.z); //中心点居于模型bound底部,因固定离地高度,旋转时旋转中心在地面上就不会变位置
  72459. }
  72460. }
  72461. parentQuaternionInv.copy(parentQuaternion).invert();
  72462. worldQuaternionInv.copy(worldQuaternion).invert();
  72463. }
  72464. this.camera.updateMatrixWorld();
  72465. this.camera.matrixWorld.decompose(cameraPosition, cameraQuaternion, cameraScale);
  72466. if (this.camera.type == "OrthographicCamera") {
  72467. //xzw add
  72468. eye.copy(this.view.direction);
  72469. } else {
  72470. eye.copy(cameraPosition).sub(worldPosition).normalize();
  72471. }
  72472. Object3D.prototype.updateMatrixWorld.call(this);
  72473. };
  72474. this.pointerHover = function () {
  72475. var pointer = viewer.inputHandler.pointer;
  72476. if (this.object === undefined) return;
  72477. //if(this.dragging === true /* || ( pointer.button !== undefined && pointer.button !== 0 ) */) return;
  72478. if (!this.dragging) {
  72479. var oldAxis = this.axis;
  72480. //ray.setFromCamera( pointer, this.camera ); //这句会在floorplan模式get不到intersect
  72481. var {
  72482. origin,
  72483. direction
  72484. } = viewer.inputHandler.getMouseDirection();
  72485. ray.set(origin, direction);
  72486. Potree.Utils.setCameraLayers(ray,
  72487. //设置能识别到的layers
  72488. ['sceneObjects', 'mapObjects', 'measure', 'transformationTool', 'model'], viewer.inputHandler.hoverViewport && viewer.inputHandler.hoverViewport.extraEnableLayers);
  72489. var intersect = ray.intersectObjects(_gizmo.picker[this.mode].children.filter(e => e.visible), true)[0] || false;
  72490. if (intersect) {
  72491. this.axis = intersect.object.name;
  72492. } else {
  72493. this.axis = null;
  72494. }
  72495. if (oldAxis != this.axis) {
  72496. viewer.dispatchEvent('content_changed');
  72497. }
  72498. } else {
  72499. //this.pointerMove()
  72500. }
  72501. };
  72502. this.pointerDown = function /* pointer */
  72503. () {
  72504. var pointer = viewer.inputHandler.pointer;
  72505. if (this.object === undefined || this.dragging === true /* || ( pointer.button !== undefined && pointer.button !== 0 ) */) return;
  72506. if ( /* ( pointer.button === 0 || pointer.button === undefined ) && */this.axis !== null) {
  72507. //ray.setFromCamera( pointer, this.camera ); //这句会在floorplan模式get不到intersect
  72508. var {
  72509. origin,
  72510. direction
  72511. } = viewer.inputHandler.getMouseDirection();
  72512. ray.set(origin, direction);
  72513. Potree.Utils.setCameraLayers(ray,
  72514. //设置能识别到的layers
  72515. ['sceneObjects', 'mapObjects', 'measure', 'transformationTool', 'model'], viewer.inputHandler.hoverViewport && viewer.inputHandler.hoverViewport.extraEnableLayers);
  72516. var planeIntersect = ray.intersectObjects([_plane], true)[0] || false;
  72517. if (planeIntersect) {
  72518. var space = this.space;
  72519. if (this.mode === 'scale') {
  72520. space = 'local';
  72521. } else if (this.axis === 'E' || this.axis === 'XYZE' || this.axis === 'XYZ') {
  72522. space = 'world';
  72523. }
  72524. if (space === 'local' && this.mode === 'rotate') {
  72525. var snap = this.rotationSnap;
  72526. if (this.axis === 'X' && snap) this.object.rotation.x = Math.round(this.object.rotation.x / snap) * snap;
  72527. if (this.axis === 'Y' && snap) this.object.rotation.y = Math.round(this.object.rotation.y / snap) * snap;
  72528. if (this.axis === 'Z' && snap) this.object.rotation.z = Math.round(this.object.rotation.z / snap) * snap;
  72529. }
  72530. this.object.updateMatrixWorld();
  72531. this.object.parent.updateMatrixWorld();
  72532. positionStart.copy(this.object.position);
  72533. quaternionStart.copy(this.object.quaternion);
  72534. scaleStart.copy(this.object.scale);
  72535. this.object.matrixWorld.decompose(worldPositionStart, worldQuaternionStart, worldScaleStart);
  72536. //add: 使坐标轴在boundingBox中心
  72537. this.object.boundingBox && this.object.boundingBox.getCenter(worldPositionStart).applyMatrix4(this.object.matrixWorld);
  72538. pointStart.copy(planeIntersect.point).sub(worldPositionStart);
  72539. /* if(this.player.cameraControls.activeControl){
  72540. //this.player.cameraControls.activeControl.locked = true; //add
  72541. this.player.cameraControls.activeControl.enabled = false; //add
  72542. } */
  72543. }
  72544. this.dragging = true;
  72545. mouseDownEvent.mode = this.mode;
  72546. this.dispatchEvent(mouseDownEvent);
  72547. }
  72548. };
  72549. this.pointerMove = function /* pointer */
  72550. () {
  72551. var pointer = viewer.inputHandler.pointer;
  72552. var axis = this.axis;
  72553. var mode = this.mode;
  72554. var object = this.object;
  72555. var space = this.space;
  72556. if (mode === 'scale') {
  72557. space = 'local';
  72558. } else if (axis === 'E' || axis === 'XYZE' || axis === 'XYZ') {
  72559. space = 'world';
  72560. }
  72561. if (object === undefined || axis === null || this.dragging === false || pointer.button !== undefined && pointer.button !== 0) return;
  72562. //ray.setFromCamera( pointer, this.camera ); //这句会在floorplan模式get不到intersect
  72563. var {
  72564. origin,
  72565. direction
  72566. } = viewer.inputHandler.getMouseDirection();
  72567. ray.set(origin, direction);
  72568. Potree.Utils.setCameraLayers(ray,
  72569. //设置能识别到的layers
  72570. ['sceneObjects', 'mapObjects', 'measure', 'transformationTool', 'model'], viewer.inputHandler.hoverViewport && viewer.inputHandler.hoverViewport.extraEnableLayers);
  72571. var planeIntersect = ray.intersectObjects([_plane], true)[0] || false;
  72572. if (planeIntersect === false) return;
  72573. pointEnd.copy(planeIntersect.point).sub(worldPositionStart);
  72574. if (mode === 'translate') {
  72575. // Apply translate
  72576. offset.copy(pointEnd).sub(pointStart);
  72577. if (space === 'local' && axis !== 'XYZ') {
  72578. offset.applyQuaternion(worldQuaternionInv);
  72579. }
  72580. if (axis.indexOf('X') === -1) offset.x = 0;
  72581. if (axis.indexOf('Y') === -1) offset.y = 0;
  72582. if (axis.indexOf('Z') === -1) offset.z = 0;
  72583. if (space === 'local' && axis !== 'XYZ') {
  72584. //xzw 加,否则会反向---------------
  72585. object.scale.x < 0 && (offset.x *= -1);
  72586. object.scale.y < 0 && (offset.y *= -1);
  72587. object.scale.z < 0 && (offset.z *= -1);
  72588. //---------------------------------
  72589. offset.applyQuaternion(quaternionStart).divide(parentScale);
  72590. } else {
  72591. offset.applyQuaternion(parentQuaternionInv).divide(parentScale);
  72592. }
  72593. object.position.copy(offset).add(positionStart);
  72594. // Apply translation snap
  72595. if (this.translationSnap) {
  72596. if (space === 'local') {
  72597. object.position.applyQuaternion(_tempQuaternion.copy(quaternionStart).invert());
  72598. if (axis.search('X') !== -1) {
  72599. object.position.x = Math.round(object.position.x / this.translationSnap) * this.translationSnap;
  72600. }
  72601. if (axis.search('Y') !== -1) {
  72602. object.position.y = Math.round(object.position.y / this.translationSnap) * this.translationSnap;
  72603. }
  72604. if (axis.search('Z') !== -1) {
  72605. object.position.z = Math.round(object.position.z / this.translationSnap) * this.translationSnap;
  72606. }
  72607. object.position.applyQuaternion(quaternionStart);
  72608. }
  72609. if (space === 'world') {
  72610. if (object.parent) {
  72611. object.position.add(_tempVector.setFromMatrixPosition(object.parent.matrixWorld));
  72612. }
  72613. if (axis.search('X') !== -1) {
  72614. object.position.x = Math.round(object.position.x / this.translationSnap) * this.translationSnap;
  72615. }
  72616. if (axis.search('Y') !== -1) {
  72617. object.position.y = Math.round(object.position.y / this.translationSnap) * this.translationSnap;
  72618. }
  72619. if (axis.search('Z') !== -1) {
  72620. object.position.z = Math.round(object.position.z / this.translationSnap) * this.translationSnap;
  72621. }
  72622. if (object.parent) {
  72623. object.position.sub(_tempVector.setFromMatrixPosition(object.parent.matrixWorld));
  72624. }
  72625. }
  72626. }
  72627. //add:
  72628. object.dispatchEvent({
  72629. type: "position_changed"
  72630. });
  72631. } else if (mode === 'scale') {
  72632. if (axis.search('XYZ') !== -1) {
  72633. var d = pointEnd.length() / pointStart.length();
  72634. if (pointEnd.dot(pointStart) < 0) d *= -1;
  72635. if (options.NoScaleZ) {
  72636. //xzw add
  72637. _tempVector2.set(d, d, 1);
  72638. } else {
  72639. _tempVector2.set(d, d, d);
  72640. }
  72641. } else if (axis.search('XY') !== -1) {
  72642. //add 等比例for plane
  72643. var d = pointEnd.length() / pointStart.length();
  72644. if (pointEnd.dot(pointStart) < 0) d *= -1;
  72645. _tempVector2.set(d, d, 1);
  72646. } else {
  72647. _tempVector.copy(pointStart);
  72648. _tempVector2.copy(pointEnd);
  72649. _tempVector.applyQuaternion(worldQuaternionInv);
  72650. _tempVector2.applyQuaternion(worldQuaternionInv);
  72651. _tempVector2.divide(_tempVector);
  72652. if (axis.search('X') === -1) {
  72653. _tempVector2.x = 1;
  72654. }
  72655. if (axis.search('Y') === -1) {
  72656. _tempVector2.y = 1;
  72657. }
  72658. if (axis.search('Z') === -1) {
  72659. _tempVector2.z = 1;
  72660. }
  72661. }
  72662. // Apply scale
  72663. object.scale.copy(scaleStart).multiply(_tempVector2);
  72664. if (this.scaleSnap) {
  72665. if (axis.search('X') !== -1) {
  72666. object.scale.x = Math.round(object.scale.x / this.scaleSnap) * this.scaleSnap || this.scaleSnap;
  72667. }
  72668. if (axis.search('Y') !== -1) {
  72669. object.scale.y = Math.round(object.scale.y / this.scaleSnap) * this.scaleSnap || this.scaleSnap;
  72670. }
  72671. if (axis.search('Z') !== -1) {
  72672. object.scale.z = Math.round(object.scale.z / this.scaleSnap) * this.scaleSnap || this.scaleSnap;
  72673. }
  72674. }
  72675. //add:
  72676. object.dispatchEvent({
  72677. type: "scale_changed"
  72678. });
  72679. } else if (mode === 'rotate') {
  72680. if (this.rotateMethod == 2) {
  72681. //新版参照transfromTool的写法,更跟手,但是有bug,在同时移动位置时或e轴上有问题
  72682. if (axis === 'E') {
  72683. //绕着视线转
  72684. rotationAxis.copy(eye); //旋转轴
  72685. rotationAngle = pointEnd.angleTo(pointStart);
  72686. startNorm.copy(pointStart).normalize();
  72687. endNorm.copy(pointEnd).normalize();
  72688. rotationAngle *= endNorm.cross(startNorm).dot(eye) < 0 ? 1 : -1; //角度
  72689. } else {
  72690. if (axis === 'XYZE') {
  72691. //像滚球一样拨动,鼠标滑动方向为拨动方向,在plane面上滚动
  72692. offset.copy(pointEnd).sub(pointStart);
  72693. rotationAxis.copy(offset).cross(eye).normalize();
  72694. } else {
  72695. rotationAxis.copy(_unit[axis]);
  72696. }
  72697. var center = new Vector3(); //坐标轴位置
  72698. /* if(this.object.boundingBox){
  72699. center.copy(worldPosition) //center设置为boundingbox的中心。但center一直更改会导致虽然在按某个时针旋转,但v2相对v1可能会时不时逆向,导致闪烁。所以固定住center,虽然这样计算的角度和绕模型中心的感觉偏颇
  72700. }else{ */
  72701. center.copy(worldPositionStart);
  72702. //}
  72703. var rotationAxis_ = space === 'local' ? rotationAxis.clone().applyQuaternion(worldQuaternion) : rotationAxis;
  72704. var plane = new Plane().setFromNormalAndCoplanarPoint(rotationAxis_, center); //旋转过程中rotationAxis不会变化,但center可能会
  72705. var {
  72706. origin: _origin,
  72707. direction: _direction
  72708. } = viewer.inputHandler.getMouseDirection();
  72709. ray.set(_origin, _direction);
  72710. var I = ray.ray.intersectPlane(plane, new Vector3());
  72711. if (I) {
  72712. var v2 = I.clone().sub(center); //.normalize();
  72713. if (!this.rotateStart) {
  72714. this.rotateStart = {
  72715. v1: v2
  72716. };
  72717. return;
  72718. }
  72719. var v1 = this.rotateStart.v1;
  72720. rotationAngle = math.getAngle(v1, v2, rotationAxis_);
  72721. //console.log('rot', rotationAngle, center.toArray())
  72722. if (Number.isNaN(rotationAngle)) {
  72723. return;
  72724. }
  72725. this.rotateStart.v1 = v2;
  72726. }
  72727. }
  72728. } else {
  72729. //pointStart 是起始intersect - object中心的向量
  72730. //pointEnd 是当前intersect - object中心的向量
  72731. offset.copy(pointEnd).sub(pointStart);
  72732. var ROTATION_SPEED = 2 / worldPosition.distanceTo(_tempVector.setFromMatrixPosition(this.camera.matrixWorld));
  72733. if (axis === 'E') {
  72734. //绕着视线转
  72735. rotationAxis.copy(eye); //旋转轴
  72736. rotationAngle = pointEnd.angleTo(pointStart);
  72737. startNorm.copy(pointStart).normalize();
  72738. endNorm.copy(pointEnd).normalize();
  72739. rotationAngle *= endNorm.cross(startNorm).dot(eye) < 0 ? 1 : -1; //角度
  72740. } else if (axis === 'XYZE') {
  72741. //像滚球一样拨动,鼠标滑动方向为拨动方向,在plane面上滚动
  72742. rotationAxis.copy(offset).cross(eye).normalize();
  72743. rotationAngle = offset.dot(_tempVector.copy(rotationAxis).cross(this.eye)) * ROTATION_SPEED;
  72744. } else if (axis === 'X' || axis === 'Y' || axis === 'Z') {
  72745. rotationAxis.copy(_unit[axis]);
  72746. _tempVector.copy(_unit[axis]);
  72747. if (space === 'local') {
  72748. _tempVector.applyQuaternion(worldQuaternion);
  72749. }
  72750. rotationAngle = offset.dot(_tempVector.cross(eye).normalize()) * ROTATION_SPEED;
  72751. }
  72752. // Apply rotation snap
  72753. if (this.rotationSnap) rotationAngle = Math.round(rotationAngle / this.rotationSnap) * this.rotationSnap;
  72754. this.rotationAngle = rotationAngle;
  72755. }
  72756. // Apply rotate
  72757. if (space === 'local' && axis !== 'E' && axis !== 'XYZE') {
  72758. object.scale[axis.toLowerCase()] < 0 && (rotationAngle *= -1); //xzw 加,否则会反向
  72759. object.quaternion.copy(quaternionStart);
  72760. object.quaternion.multiply(_tempQuaternion.setFromAxisAngle(rotationAxis, rotationAngle)).normalize();
  72761. } else {
  72762. rotationAxis.applyQuaternion(parentQuaternionInv);
  72763. object.quaternion.copy(_tempQuaternion.setFromAxisAngle(rotationAxis, rotationAngle));
  72764. object.quaternion.multiply(quaternionStart).normalize();
  72765. }
  72766. if (this.rotateMethod == 2 && axis != 'E') {
  72767. quaternionStart.copy(object.quaternion);
  72768. }
  72769. //add:
  72770. object.dispatchEvent({
  72771. type: "rotation_changed"
  72772. });
  72773. }
  72774. this.dispatchEvent(changeEvent);
  72775. this.dispatchEvent(objectChangeEvent);
  72776. viewer.dispatchEvent('content_changed');
  72777. };
  72778. this.pointerUp = function (pointer) {
  72779. //if ( pointer.button !== undefined && pointer.button !== 0 ) return;
  72780. if (this.dragging && this.axis !== null) {
  72781. mouseUpEvent.mode = this.mode;
  72782. this.dispatchEvent(mouseUpEvent);
  72783. /* if(this.player.cameraControls.activeControl){
  72784. //this.player.cameraControls.activeControl.locked = false; //add
  72785. this.player.cameraControls.activeControl.pointerDragOn = false //add
  72786. this.player.cameraControls.activeControl.enabled = true
  72787. } */
  72788. this.rotateStart = null; //add
  72789. }
  72790. this.dragging = false;
  72791. //if ( pointer.button === undefined ) this.axis = null;
  72792. /* if(this.player.cameraControls.activeControl){
  72793. //this.player.cameraControls.activeControl.locked = false; //add
  72794. this.player.cameraControls.activeControl.pointerDragOn = false //add
  72795. this.player.cameraControls.activeControl.enabled = true
  72796. } */
  72797. };
  72798. // normalize mouse / touch pointer and remap {x,y} to view space.
  72799. function getPointer(event) {
  72800. if (!event) {
  72801. console.log('hhahhhahah');
  72802. return;
  72803. }
  72804. if (document.pointerLockElement) {
  72805. return {
  72806. x: 0,
  72807. y: 0,
  72808. button: event.button
  72809. };
  72810. } else {
  72811. var pointer = event.changedTouches ? event.changedTouches[0] : event;
  72812. var rect = domElement.getBoundingClientRect();
  72813. return {
  72814. x: (pointer.clientX - rect.left) / rect.width * 2 - 1,
  72815. y: -(pointer.clientY - rect.top) / rect.height * 2 + 1,
  72816. button: event.button
  72817. };
  72818. }
  72819. }
  72820. // mouse / touch event handlers
  72821. function onPointerHover(event) {
  72822. if (!scope.enabled) return;
  72823. //scope.pointerHover( getPointer( event ) );
  72824. scope.pointerHover();
  72825. }
  72826. function onPointerDown(event) {
  72827. if (!scope.enabled) return;
  72828. //document.addEventListener( "mousemove", onPointerMove, false );
  72829. /* scope.pointerHover( getPointer( event ) );
  72830. scope.pointerDown( getPointer( event ) ); */
  72831. scope.pointerHover();
  72832. scope.pointerDown();
  72833. }
  72834. this.onPointerDown = onPointerDown;
  72835. function onPointerMove(event) {
  72836. if (!scope.enabled || !this.dragging) return; //xzw change
  72837. //scope.pointerMove( getPointer( event ) );
  72838. scope.pointerMove();
  72839. }
  72840. this.onPointerMove = onPointerMove;
  72841. function onPointerUp(event) {
  72842. if (!scope.enabled) return;
  72843. //document.removeEventListener( "mousemove", onPointerMove, false );
  72844. //scope.pointerUp( getPointer( event ) );
  72845. scope.pointerUp();
  72846. }
  72847. this.onPointerUp = onPointerUp;
  72848. // TODO: deprecate
  72849. this.getMode = function () {
  72850. return scope.mode;
  72851. };
  72852. this.setMode = function (mode) {
  72853. scope.mode = mode;
  72854. };
  72855. this.setTranslationSnap = function (translationSnap) {
  72856. scope.translationSnap = translationSnap;
  72857. };
  72858. this.setRotationSnap = function (rotationSnap) {
  72859. scope.rotationSnap = rotationSnap;
  72860. };
  72861. this.setScaleSnap = function (scaleSnap) {
  72862. scope.scaleSnap = scaleSnap;
  72863. };
  72864. this.setSize = function (size) {
  72865. scope.size = size;
  72866. };
  72867. this.setSpace = function (space) {
  72868. scope.space = space;
  72869. };
  72870. this.update = function () {
  72871. console.warn('THREE.TransformControls: update function has no more functionality and therefore has been deprecated.');
  72872. };
  72873. };
  72874. var TransformControlsGizmo = function TransformControlsGizmo(options) {
  72875. 'use strict';
  72876. Object3D.call(this);
  72877. this.type = 'TransformControlsGizmo';
  72878. // shared materials
  72879. this.hideAxis = {};
  72880. var gizmoMaterial = new MeshBasicMaterial({
  72881. depthTest: false,
  72882. depthWrite: false,
  72883. transparent: true,
  72884. side: DoubleSide,
  72885. fog: false
  72886. });
  72887. var gizmoLineMaterial = new LineBasicMaterial({
  72888. depthTest: false,
  72889. depthWrite: false,
  72890. transparent: true,
  72891. fog: false
  72892. });
  72893. // Make unique material for each axis/color
  72894. var matInvisible = gizmoMaterial.clone();
  72895. matInvisible.opacity = 0.15;
  72896. var matHelper = gizmoMaterial.clone();
  72897. matHelper.opacity = 0.1;
  72898. var matRed = gizmoMaterial.clone();
  72899. matRed.color.set(0xff0000);
  72900. var matGreen = gizmoMaterial.clone();
  72901. matGreen.color.set(0x00ff00);
  72902. var matBlue = gizmoMaterial.clone();
  72903. matBlue.color.set(0x0000ff);
  72904. var matWhiteTransparent = gizmoMaterial.clone();
  72905. matWhiteTransparent.opacity = 0.35;
  72906. matWhiteTransparent.color.set(0x00d0fd); //xzw add
  72907. var matYellowTransparent = matWhiteTransparent.clone();
  72908. matYellowTransparent.color.set(0xffff00);
  72909. var matCyanTransparent = matWhiteTransparent.clone();
  72910. matCyanTransparent.color.set(0x00ffff);
  72911. var matMagentaTransparent = matWhiteTransparent.clone();
  72912. matMagentaTransparent.color.set(0xff00ff);
  72913. var matYellow = gizmoMaterial.clone();
  72914. matYellow.color.set(0xffff00);
  72915. var matLineRed = gizmoLineMaterial.clone();
  72916. matLineRed.color.set(0xff0000);
  72917. var matLineGreen = gizmoLineMaterial.clone();
  72918. matLineGreen.color.set(0x00ff00);
  72919. var matLineBlue = gizmoLineMaterial.clone();
  72920. matLineBlue.color.set(0x0000ff);
  72921. var matLineCyan = gizmoLineMaterial.clone();
  72922. matLineCyan.color.set(0x00ffff);
  72923. var matLineMagenta = gizmoLineMaterial.clone();
  72924. matLineMagenta.color.set(0xff00ff);
  72925. var matLineYellow = gizmoLineMaterial.clone();
  72926. matLineYellow.color.set(0xffff00);
  72927. var matLineGray = gizmoLineMaterial.clone();
  72928. matLineGray.color.set(0x787878);
  72929. var matLineYellowTransparent = matLineYellow.clone();
  72930. matLineYellowTransparent.opacity = 0.25;
  72931. // reusable geometry
  72932. var arrowGeometry = new CylinderBufferGeometry(0, 0.05, 0.2, 12, 1, false);
  72933. var scaleHandleGeometry = new BoxBufferGeometry(0.125, 0.125, 0.125);
  72934. var lineGeometry = new BufferGeometry();
  72935. //lineGeometry.setAttribute( 'position', new THREE.Float32BufferAttribute( [ 0, 0, 0, 1, 0, 0 ], 3 ) );
  72936. lineGeometry.setAttribute("position", new BufferAttribute(new Float32Array([0, 0, 0, 1, 0, 0]), 3));
  72937. var CircleGeometry = function CircleGeometry(radius, arc) {
  72938. var geometry = new BufferGeometry();
  72939. var vertices = [];
  72940. for (var i = 0; i <= 64 * arc; ++i) {
  72941. vertices.push(0, Math.cos(i / 32 * Math.PI) * radius, Math.sin(i / 32 * Math.PI) * radius);
  72942. }
  72943. //geometry.setAttribute( 'position', new THREE.Float32BufferAttribute( vertices, 3 ) );
  72944. geometry.setAttribute("position", new BufferAttribute(new Float32Array(vertices), 3));
  72945. return geometry;
  72946. };
  72947. // Special geometry for transform helper. If scaled with position vector it spans from [0,0,0] to position
  72948. var TranslateHelperGeometry = function TranslateHelperGeometry() {
  72949. var geometry = new BufferGeometry();
  72950. //geometry.setAttribute( 'position', new THREE.Float32BufferAttribute( [ 0, 0, 0, 1, 1, 1 ], 3 ) );
  72951. geometry.setAttribute("position", new BufferAttribute(new Float32Array([0, 0, 0, 1, 1, 1]), 3));
  72952. return geometry;
  72953. };
  72954. // Gizmo definitions - custom hierarchy definitions for setupGizmo() function
  72955. var gizmoTranslate = {
  72956. X: [[new Mesh(arrowGeometry, matRed), [1, 0, 0], [0, 0, -Math.PI / 2], null, 'fwd'],
  72957. //[ new THREE.Mesh( arrowGeometry, matRed ), [ 1, 0, 0 ], [ 0, 0, Math.PI / 2 ], null, 'bwd' ],
  72958. [new Line(lineGeometry, matLineRed)]],
  72959. Y: [[new Mesh(arrowGeometry, matGreen), [0, 1, 0], null, null, 'fwd'],
  72960. //[ new THREE.Mesh( arrowGeometry, matGreen ), [ 0, 1, 0 ], [ Math.PI, 0, 0 ], null, 'bwd' ],
  72961. [new Line(lineGeometry, matLineGreen), null, [0, 0, Math.PI / 2]]],
  72962. Z: [[new Mesh(arrowGeometry, matBlue), [0, 0, 1], [Math.PI / 2, 0, 0], null, 'fwd'],
  72963. //[ new THREE.Mesh( arrowGeometry, matBlue ), [ 0, 0, 1 ], [ - Math.PI / 2, 0, 0 ], null, 'bwd' ],
  72964. [new Line(lineGeometry, matLineBlue), null, [0, -Math.PI / 2, 0]]],
  72965. /* XYZ: [
  72966. [ new THREE.Mesh( new THREE.OctahedronBufferGeometry( 0.1, 0 ), matWhiteTransparent.clone() ), [ 0, 0, 0 ], [ 0, 0, 0 ]]
  72967. ], */
  72968. XY: [[new Mesh(new PlaneBufferGeometry(0.295, 0.295), matYellowTransparent.clone()), [0.15, 0.15, 0]], [new Line(lineGeometry, matLineYellow), [0.18, 0.3, 0], null, [0.125, 1, 1]], [new Line(lineGeometry, matLineYellow), [0.3, 0.18, 0], [0, 0, Math.PI / 2], [0.125, 1, 1]]],
  72969. YZ: [[new Mesh(new PlaneBufferGeometry(0.295, 0.295), matCyanTransparent.clone()), [0, 0.15, 0.15], [0, Math.PI / 2, 0]], [new Line(lineGeometry, matLineCyan), [0, 0.18, 0.3], [0, 0, Math.PI / 2], [0.125, 1, 1]], [new Line(lineGeometry, matLineCyan), [0, 0.3, 0.18], [0, -Math.PI / 2, 0], [0.125, 1, 1]]],
  72970. XZ: [[new Mesh(new PlaneBufferGeometry(0.295, 0.295), matMagentaTransparent.clone()), [0.15, 0, 0.15], [-Math.PI / 2, 0, 0]], [new Line(lineGeometry, matLineMagenta), [0.18, 0, 0.3], null, [0.125, 1, 1]], [new Line(lineGeometry, matLineMagenta), [0.3, 0, 0.18], [0, -Math.PI / 2, 0], [0.125, 1, 1]]]
  72971. };
  72972. var pickerTranslate = {
  72973. X: [[new Mesh(new CylinderBufferGeometry(0.2, 0, 1, 4, 1, false), matInvisible), [0.6, 0, 0], [0, 0, -Math.PI / 2]]],
  72974. Y: [[new Mesh(new CylinderBufferGeometry(0.2, 0, 1, 4, 1, false), matInvisible), [0, 0.6, 0]]],
  72975. Z: [[new Mesh(new CylinderBufferGeometry(0.2, 0, 1, 4, 1, false), matInvisible), [0, 0, 0.6], [Math.PI / 2, 0, 0]]],
  72976. /* XYZ: [
  72977. [ new THREE.Mesh( new THREE.OctahedronBufferGeometry( 0.2, 0 ), matInvisible ) ]
  72978. ], */
  72979. XY: [[new Mesh(new PlaneBufferGeometry(0.4, 0.4), matInvisible), [0.2, 0.2, 0]]],
  72980. YZ: [[new Mesh(new PlaneBufferGeometry(0.4, 0.4), matInvisible), [0, 0.2, 0.2], [0, Math.PI / 2, 0]]],
  72981. XZ: [[new Mesh(new PlaneBufferGeometry(0.4, 0.4), matInvisible), [0.2, 0, 0.2], [-Math.PI / 2, 0, 0]]]
  72982. };
  72983. var helperTranslate = {
  72984. START: [[new Mesh(new OctahedronBufferGeometry(0.01, 2), matHelper), null, null, null, 'helper']],
  72985. END: [[new Mesh(new OctahedronBufferGeometry(0.01, 2), matHelper), null, null, null, 'helper']],
  72986. DELTA: [[new Line(TranslateHelperGeometry(), matHelper), null, null, null, 'helper']],
  72987. X: [[new Line(lineGeometry, matHelper.clone()), [-1e3, 0, 0], null, [1e6, 1, 1], 'helper']],
  72988. Y: [[new Line(lineGeometry, matHelper.clone()), [0, -1e3, 0], [0, 0, Math.PI / 2], [1e6, 1, 1], 'helper']],
  72989. Z: [[new Line(lineGeometry, matHelper.clone()), [0, 0, -1e3], [0, -Math.PI / 2, 0], [1e6, 1, 1], 'helper']]
  72990. };
  72991. var arc = options.rotFullCircle ? 1 : 0.5; //add
  72992. var gizmoRotate = {
  72993. X: [[new Line(CircleGeometry(1, arc), matLineRed)], [new Mesh(new OctahedronBufferGeometry(0.04, 0), matRed), [0, 0, 0.99], null, [1, 3, 1]]],
  72994. Y: [[new Line(CircleGeometry(1, arc), matLineGreen), null, [0, 0, -Math.PI / 2]], [new Mesh(new OctahedronBufferGeometry(0.04, 0), matGreen), [0, 0, 0.99], null, [3, 1, 1]]],
  72995. Z: [[new Line(CircleGeometry(1, arc), matLineBlue), null, [0, Math.PI / 2, 0]], [new Mesh(new OctahedronBufferGeometry(0.04, 0), matBlue), [0.99, 0, 0], null, [1, 3, 1]]],
  72996. E: [[new Line(CircleGeometry(1.25, 1), matLineYellowTransparent), null, [0, Math.PI / 2, 0]], [new Mesh(new CylinderBufferGeometry(0.03, 0, 0.15, 4, 1, false), matLineYellowTransparent), [1.17, 0, 0], [0, 0, -Math.PI / 2], [1, 1, 0.001]], [new Mesh(new CylinderBufferGeometry(0.03, 0, 0.15, 4, 1, false), matLineYellowTransparent), [-1.17, 0, 0], [0, 0, Math.PI / 2], [1, 1, 0.001]], [new Mesh(new CylinderBufferGeometry(0.03, 0, 0.15, 4, 1, false), matLineYellowTransparent), [0, -1.17, 0], [Math.PI, 0, 0], [1, 1, 0.001]], [new Mesh(new CylinderBufferGeometry(0.03, 0, 0.15, 4, 1, false), matLineYellowTransparent), [0, 1.17, 0], [0, 0, 0], [1, 1, 0.001]]],
  72997. XYZE: [[new Line(CircleGeometry(1, 1), matLineGray), null, [0, Math.PI / 2, 0]]]
  72998. };
  72999. var helperRotate = {
  73000. AXIS: [[new Line(lineGeometry, matHelper.clone()), [-1e3, 0, 0], null, [1e6, 1, 1], 'helper']]
  73001. };
  73002. var pickerRotate = {
  73003. X: [[new Mesh(new TorusBufferGeometry(1, 0.1, 4, 24), matInvisible), [0, 0, 0], [0, -Math.PI / 2, -Math.PI / 2]]],
  73004. Y: [[new Mesh(new TorusBufferGeometry(1, 0.1, 4, 24), matInvisible), [0, 0, 0], [Math.PI / 2, 0, 0]]],
  73005. Z: [[new Mesh(new TorusBufferGeometry(1, 0.1, 4, 24), matInvisible), [0, 0, 0], [0, 0, -Math.PI / 2]]],
  73006. E: [[new Mesh(new TorusBufferGeometry(1.25, 0.1, 2, 24), matInvisible)]],
  73007. XYZE: [[new Mesh(new SphereBufferGeometry(0.7, 10, 8), matInvisible)]]
  73008. };
  73009. var gizmoScale = {
  73010. X: [[new Mesh(scaleHandleGeometry, matRed), [0.8, 0, 0], [0, 0, -Math.PI / 2]], [new Line(lineGeometry, matLineRed), null, null, [0.8, 1, 1]]],
  73011. Y: [[new Mesh(scaleHandleGeometry, matGreen), [0, 0.8, 0]], [new Line(lineGeometry, matLineGreen), null, [0, 0, Math.PI / 2], [0.8, 1, 1]]],
  73012. Z: [[new Mesh(scaleHandleGeometry, matBlue), [0, 0, 0.8], [Math.PI / 2, 0, 0]], [new Line(lineGeometry, matLineBlue), null, [0, -Math.PI / 2, 0], [0.8, 1, 1]]],
  73013. XY: [[new Mesh(scaleHandleGeometry, matYellowTransparent), [0.85, 0.85, 0], null, [2, 2, 0.2]], [new Line(lineGeometry, matLineYellow), [0.855, 0.98, 0], null, [0.125, 1, 1]], [new Line(lineGeometry, matLineYellow), [0.98, 0.855, 0], [0, 0, Math.PI / 2], [0.125, 1, 1]]],
  73014. /* YZ: [
  73015. [ new THREE.Mesh( scaleHandleGeometry, matCyanTransparent ), [ 0, 0.85, 0.85 ], null, [ 0.2, 2, 2 ]],
  73016. [ new THREE.Line( lineGeometry, matLineCyan ), [ 0, 0.855, 0.98 ], [ 0, 0, Math.PI / 2 ], [ 0.125, 1, 1 ]],
  73017. [ new THREE.Line( lineGeometry, matLineCyan ), [ 0, 0.98, 0.855 ], [ 0, - Math.PI / 2, 0 ], [ 0.125, 1, 1 ]]
  73018. ],
  73019. XZ: [
  73020. [ new THREE.Mesh( scaleHandleGeometry, matMagentaTransparent ), [ 0.85, 0, 0.85 ], null, [ 2, 0.2, 2 ]],
  73021. [ new THREE.Line( lineGeometry, matLineMagenta ), [ 0.855, 0, 0.98 ], null, [ 0.125, 1, 1 ]],
  73022. [ new THREE.Line( lineGeometry, matLineMagenta ), [ 0.98, 0, 0.855 ], [ 0, - Math.PI / 2, 0 ], [ 0.125, 1, 1 ]]
  73023. ],
  73024. XYZX: [
  73025. [ new THREE.Mesh( new THREE.BoxBufferGeometry( 0.125, 0.125, 0.125 ), matWhiteTransparent.clone() ), [ 1.1, 0, 0 ]],
  73026. ],*/
  73027. XYZY: [[new Mesh(new BoxBufferGeometry(0.125, 0.125, 0.125), matWhiteTransparent.clone()), [0, 1.1, 0]]] /* ,
  73028. XYZZ: [
  73029. [ new THREE.Mesh( new THREE.BoxBufferGeometry( 0.125, 0.125, 0.125 ), matWhiteTransparent.clone() ), [ 0, 0, 1.1 ]],
  73030. ] */
  73031. };
  73032. var pickerScale = {
  73033. X: [[new Mesh(new CylinderBufferGeometry(0.2, 0, 0.8, 4, 1, false), matInvisible), [0.5, 0, 0], [0, 0, -Math.PI / 2]]],
  73034. Y: [[new Mesh(new CylinderBufferGeometry(0.2, 0, 0.8, 4, 1, false), matInvisible), [0, 0.5, 0]]],
  73035. Z: [[new Mesh(new CylinderBufferGeometry(0.2, 0, 0.8, 4, 1, false), matInvisible), [0, 0, 0.5], [Math.PI / 2, 0, 0]]],
  73036. XY: [[new Mesh(scaleHandleGeometry, matInvisible), [0.85, 0.85, 0], null, [3, 3, 0.2]]],
  73037. /*YZ: [
  73038. [ new THREE.Mesh( scaleHandleGeometry, matInvisible ), [ 0, 0.85, 0.85 ], null, [ 0.2, 3, 3 ]],
  73039. ],
  73040. XZ: [
  73041. [ new THREE.Mesh( scaleHandleGeometry, matInvisible ), [ 0.85, 0, 0.85 ], null, [ 3, 0.2, 3 ]],
  73042. ],
  73043. XYZX: [
  73044. [ new THREE.Mesh( new THREE.BoxBufferGeometry( 0.2, 0.2, 0.2 ), matInvisible ), [ 1.1, 0, 0 ]],
  73045. ],*/
  73046. XYZY: [[new Mesh(new BoxBufferGeometry(0.2, 0.2, 0.2), matInvisible), [0, 1.1, 0]]] /* ,
  73047. XYZZ: [
  73048. [ new THREE.Mesh( new THREE.BoxBufferGeometry( 0.2, 0.2, 0.2 ), matInvisible ), [ 0, 0, 1.1 ]],
  73049. ] */
  73050. };
  73051. var helperScale = {
  73052. X: [[new Line(lineGeometry, matHelper.clone()), [-1e3, 0, 0], null, [1e6, 1, 1], 'helper']],
  73053. Y: [[new Line(lineGeometry, matHelper.clone()), [0, -1e3, 0], [0, 0, Math.PI / 2], [1e6, 1, 1], 'helper']],
  73054. Z: [[new Line(lineGeometry, matHelper.clone()), [0, 0, -1e3], [0, -Math.PI / 2, 0], [1e6, 1, 1], 'helper']]
  73055. };
  73056. // Creates an THREE.Object3D with gizmos described in custom hierarchy definition.
  73057. var setupGizmo = function setupGizmo(gizmoMap) {
  73058. var gizmo = new Object3D();
  73059. for (var name in gizmoMap) {
  73060. for (var i = gizmoMap[name].length; i--;) {
  73061. var object = gizmoMap[name][i][0].clone();
  73062. var position = gizmoMap[name][i][1];
  73063. var rotation = gizmoMap[name][i][2];
  73064. var scale = gizmoMap[name][i][3];
  73065. var tag = gizmoMap[name][i][4];
  73066. // name and tag properties are essential for picking and updating logic.
  73067. object.name = name;
  73068. object.tag = tag;
  73069. if (position) {
  73070. object.position.set(position[0], position[1], position[2]);
  73071. }
  73072. if (rotation) {
  73073. object.rotation.set(rotation[0], rotation[1], rotation[2]);
  73074. }
  73075. if (scale) {
  73076. object.scale.set(scale[0], scale[1], scale[2]);
  73077. }
  73078. object.updateMatrix();
  73079. var tempGeometry = object.geometry.clone();
  73080. tempGeometry.applyMatrix4(object.matrix);
  73081. object.geometry = tempGeometry;
  73082. object.renderOrder = Infinity;
  73083. object.position.set(0, 0, 0);
  73084. object.rotation.set(0, 0, 0);
  73085. object.scale.set(1, 1, 1);
  73086. gizmo.add(object);
  73087. }
  73088. }
  73089. return gizmo;
  73090. };
  73091. // Reusable utility variables
  73092. var tempVector = new Vector3(0, 0, 0);
  73093. var tempEuler = new Euler();
  73094. var alignVector = new Vector3(0, 1, 0);
  73095. var zeroVector = new Vector3(0, 0, 0);
  73096. var lookAtMatrix = new Matrix4();
  73097. var tempQuaternion = new Quaternion();
  73098. var tempQuaternion2 = new Quaternion();
  73099. var identityQuaternion = new Quaternion();
  73100. var unitX = new Vector3(1, 0, 0);
  73101. var unitY = new Vector3(0, 1, 0);
  73102. var unitZ = new Vector3(0, 0, 1);
  73103. // Gizmo creation
  73104. this.gizmo = {};
  73105. this.picker = {};
  73106. this.helper = {};
  73107. this.add(this.gizmo["translate"] = setupGizmo(gizmoTranslate));
  73108. this.add(this.gizmo["rotate"] = setupGizmo(gizmoRotate));
  73109. this.add(this.gizmo["scale"] = setupGizmo(gizmoScale));
  73110. this.add(this.picker["translate"] = setupGizmo(pickerTranslate));
  73111. this.add(this.picker["rotate"] = setupGizmo(pickerRotate));
  73112. this.add(this.picker["scale"] = setupGizmo(pickerScale));
  73113. this.add(this.helper["translate"] = setupGizmo(helperTranslate));
  73114. this.add(this.helper["rotate"] = setupGizmo(helperRotate));
  73115. this.add(this.helper["scale"] = setupGizmo(helperScale));
  73116. // Pickers should be hidden always
  73117. this.picker["translate"].visible = false;
  73118. this.picker["rotate"].visible = false;
  73119. this.picker["scale"].visible = false;
  73120. // updateMatrixWorld will update transformations and appearance of individual handles
  73121. this.updateMatrixWorld = function () {
  73122. if (!this.parent.visible) return; //add
  73123. var space = this.space;
  73124. if (this.mode === 'scale') space = 'local'; // scale always oriented to local rotation
  73125. var quaternion = space === "local" ? this.worldQuaternion : identityQuaternion;
  73126. // Show only gizmos for current transform mode
  73127. this.gizmo["translate"].visible = this.mode === "translate";
  73128. this.gizmo["rotate"].visible = this.mode === "rotate";
  73129. this.gizmo["scale"].visible = this.mode === "scale";
  73130. this.helper["translate"].visible = this.mode === "translate";
  73131. this.helper["rotate"].visible = this.mode === "rotate";
  73132. this.helper["scale"].visible = this.mode === "scale";
  73133. var handles = [];
  73134. handles = handles.concat(this.picker[this.mode].children);
  73135. handles = handles.concat(this.gizmo[this.mode].children);
  73136. handles = handles.concat(this.helper[this.mode].children);
  73137. for (var i = 0; i < handles.length; i++) {
  73138. var handle = handles[i];
  73139. //add
  73140. if (this.hideAxis[this.mode] && this.hideAxis[this.mode].some(e => handle.name.includes(e.toUpperCase()))) {
  73141. Potree.Utils.updateVisible(handle, 'hidden', false);
  73142. continue;
  73143. }
  73144. var visible = true;
  73145. // hide aligned to camera
  73146. handle.rotation.set(0, 0, 0);
  73147. handle.position.copy(this.worldPosition);
  73148. if (this.camera.type == "OrthographicCamera") {
  73149. var eyeDistance = 800 / this.camera.zoom;
  73150. } else {
  73151. var eyeDistance = this.worldPosition.distanceTo(this.cameraPosition);
  73152. }
  73153. handle.scale.set(1, 1, 1).multiplyScalar(eyeDistance * this.size / 7);
  73154. // TODO: simplify helpers and consider decoupling from gizmo
  73155. if (handle.tag === 'helper') {
  73156. visible = false;
  73157. if (handle.name === 'AXIS') {
  73158. handle.position.copy(this.worldPositionStart);
  73159. visible = !!this.axis;
  73160. if (this.axis === 'X') {
  73161. tempQuaternion.setFromEuler(tempEuler.set(0, 0, 0));
  73162. handle.quaternion.copy(quaternion).multiply(tempQuaternion);
  73163. if (Math.abs(alignVector.copy(unitX).applyQuaternion(quaternion).dot(this.eye)) > 0.9) {
  73164. visible = false;
  73165. }
  73166. }
  73167. if (this.axis === 'Y') {
  73168. tempQuaternion.setFromEuler(tempEuler.set(0, 0, Math.PI / 2));
  73169. handle.quaternion.copy(quaternion).multiply(tempQuaternion);
  73170. if (Math.abs(alignVector.copy(unitY).applyQuaternion(quaternion).dot(this.eye)) > 0.9) {
  73171. visible = false;
  73172. }
  73173. }
  73174. if (this.axis === 'Z') {
  73175. tempQuaternion.setFromEuler(tempEuler.set(0, Math.PI / 2, 0));
  73176. handle.quaternion.copy(quaternion).multiply(tempQuaternion);
  73177. if (Math.abs(alignVector.copy(unitZ).applyQuaternion(quaternion).dot(this.eye)) > 0.9) {
  73178. visible = false;
  73179. }
  73180. }
  73181. if (this.axis === 'XYZE') {
  73182. tempQuaternion.setFromEuler(tempEuler.set(0, Math.PI / 2, 0));
  73183. alignVector.copy(this.rotationAxis);
  73184. handle.quaternion.setFromRotationMatrix(lookAtMatrix.lookAt(zeroVector, alignVector, unitY));
  73185. handle.quaternion.multiply(tempQuaternion);
  73186. visible = this.dragging;
  73187. }
  73188. if (this.axis === 'E') {
  73189. visible = false;
  73190. }
  73191. } else if (handle.name === 'START') {
  73192. handle.position.copy(this.worldPositionStart);
  73193. visible = this.dragging;
  73194. } else if (handle.name === 'END') {
  73195. handle.position.copy(this.worldPosition);
  73196. visible = this.dragging;
  73197. } else if (handle.name === 'DELTA') {
  73198. handle.position.copy(this.worldPositionStart);
  73199. handle.quaternion.copy(this.worldQuaternionStart);
  73200. tempVector.set(1e-10, 1e-10, 1e-10).add(this.worldPositionStart).sub(this.worldPosition).multiplyScalar(-1);
  73201. tempVector.applyQuaternion(this.worldQuaternionStart.clone().invert());
  73202. handle.scale.copy(tempVector);
  73203. visible = this.dragging;
  73204. } else {
  73205. handle.quaternion.copy(quaternion);
  73206. if (this.dragging) {
  73207. handle.position.copy(this.worldPositionStart);
  73208. } else {
  73209. handle.position.copy(this.worldPosition);
  73210. }
  73211. if (this.axis) {
  73212. visible = this.axis.search(handle.name) !== -1;
  73213. }
  73214. }
  73215. // If updating helper, skip rest of the loop
  73216. Potree.Utils.updateVisible(handle, 'hidden', !!visible);
  73217. continue;
  73218. }
  73219. // Align handles to current local or world rotation
  73220. handle.quaternion.copy(quaternion);
  73221. if (this.mode === 'translate' || this.mode === 'scale') {
  73222. // Hide translate and scale axis facing the camera
  73223. var AXIS_HIDE_TRESHOLD = 0.99;
  73224. var PLANE_HIDE_TRESHOLD = 0.2;
  73225. var AXIS_FLIP_TRESHOLD = 0.0;
  73226. if (options.dontHideWhenFaceCamera) {//xzw add
  73227. //正对镜头时不隐藏箭头
  73228. } else {
  73229. if (handle.name === 'X' || handle.name === 'XYZX') {
  73230. if (Math.abs(alignVector.copy(unitX).applyQuaternion(quaternion).dot(this.eye)) > AXIS_HIDE_TRESHOLD) {
  73231. handle.scale.set(1e-10, 1e-10, 1e-10);
  73232. visible = false;
  73233. }
  73234. }
  73235. if (handle.name === 'Y' || handle.name === 'XYZY') {
  73236. if (Math.abs(alignVector.copy(unitY).applyQuaternion(quaternion).dot(this.eye)) > AXIS_HIDE_TRESHOLD) {
  73237. handle.scale.set(1e-10, 1e-10, 1e-10);
  73238. visible = false;
  73239. }
  73240. }
  73241. if (handle.name === 'Z' || handle.name === 'XYZZ') {
  73242. if (Math.abs(alignVector.copy(unitZ).applyQuaternion(quaternion).dot(this.eye)) > AXIS_HIDE_TRESHOLD) {
  73243. handle.scale.set(1e-10, 1e-10, 1e-10);
  73244. visible = false;
  73245. }
  73246. }
  73247. if (handle.name === 'XY') {
  73248. if (Math.abs(alignVector.copy(unitZ).applyQuaternion(quaternion).dot(this.eye)) < PLANE_HIDE_TRESHOLD) {
  73249. handle.scale.set(1e-10, 1e-10, 1e-10);
  73250. visible = false;
  73251. }
  73252. }
  73253. if (handle.name === 'YZ') {
  73254. if (Math.abs(alignVector.copy(unitX).applyQuaternion(quaternion).dot(this.eye)) < PLANE_HIDE_TRESHOLD) {
  73255. handle.scale.set(1e-10, 1e-10, 1e-10);
  73256. visible = false;
  73257. }
  73258. }
  73259. if (handle.name === 'XZ') {
  73260. if (Math.abs(alignVector.copy(unitY).applyQuaternion(quaternion).dot(this.eye)) < PLANE_HIDE_TRESHOLD) {
  73261. handle.scale.set(1e-10, 1e-10, 1e-10);
  73262. visible = false;
  73263. }
  73264. }
  73265. }
  73266. // Flip translate and scale axis ocluded behind another axis
  73267. //xzw 改 去掉反向箭头
  73268. if (handle.name.search('X') !== -1) {
  73269. if (alignVector.copy(unitX).applyQuaternion(quaternion).dot(this.eye) < AXIS_FLIP_TRESHOLD) {
  73270. /* if ( handle.tag === 'fwd' ) {
  73271. handle.visible = false;
  73272. } else {
  73273. handle.scale.x *= - 1;
  73274. }
  73275. } else if ( handle.tag === 'bwd' ) {
  73276. handle.visible = false;*/
  73277. handle.scale.x *= -1;
  73278. }
  73279. }
  73280. if (handle.name.search('Y') !== -1) {
  73281. if (alignVector.copy(unitY).applyQuaternion(quaternion).dot(this.eye) < AXIS_FLIP_TRESHOLD) {
  73282. /* if ( handle.tag === 'fwd' ) {
  73283. handle.visible = false;
  73284. } else {
  73285. handle.scale.y *= - 1;
  73286. }
  73287. } else if ( handle.tag === 'bwd' ) {
  73288. handle.visible = false;
  73289. */
  73290. handle.scale.y *= -1;
  73291. }
  73292. }
  73293. if (handle.name.search('Z') !== -1) {
  73294. if (alignVector.copy(unitZ).applyQuaternion(quaternion).dot(this.eye) < AXIS_FLIP_TRESHOLD) {
  73295. /* if ( handle.tag === 'fwd' ) {
  73296. handle.visible = false;
  73297. } else {
  73298. handle.scale.z *= - 1;
  73299. }
  73300. } else if ( handle.tag === 'bwd' ) {
  73301. handle.visible = false; */
  73302. handle.scale.z *= -1;
  73303. }
  73304. }
  73305. } else if (this.mode === 'rotate') {
  73306. // Align handles to current local or world rotation
  73307. tempQuaternion2.copy(quaternion);
  73308. alignVector.copy(this.eye).applyQuaternion(tempQuaternion.copy(quaternion).invert());
  73309. if (handle.name.search("E") !== -1) {
  73310. handle.quaternion.setFromRotationMatrix(lookAtMatrix.lookAt(this.eye, zeroVector, unitY));
  73311. }
  73312. if (handle.name === 'X') {
  73313. tempQuaternion.setFromAxisAngle(unitX, Math.atan2(-alignVector.y, alignVector.z));
  73314. tempQuaternion.multiplyQuaternions(tempQuaternion2, tempQuaternion);
  73315. handle.quaternion.copy(tempQuaternion);
  73316. }
  73317. if (handle.name === 'Y') {
  73318. tempQuaternion.setFromAxisAngle(unitY, Math.atan2(alignVector.x, alignVector.z));
  73319. tempQuaternion.multiplyQuaternions(tempQuaternion2, tempQuaternion);
  73320. handle.quaternion.copy(tempQuaternion);
  73321. }
  73322. if (handle.name === 'Z') {
  73323. tempQuaternion.setFromAxisAngle(unitZ, Math.atan2(alignVector.y, alignVector.x));
  73324. tempQuaternion.multiplyQuaternions(tempQuaternion2, tempQuaternion);
  73325. handle.quaternion.copy(tempQuaternion);
  73326. }
  73327. }
  73328. // Hide disabled axes
  73329. visible = visible && (handle.name.indexOf("X") === -1 || this.showX);
  73330. visible = visible && (handle.name.indexOf("Y") === -1 || this.showY);
  73331. visible = visible && (handle.name.indexOf("Z") === -1 || this.showZ);
  73332. visible = visible && (handle.name.indexOf("E") === -1 || this.showX && this.showY && this.showZ);
  73333. Potree.Utils.updateVisible(handle, 'hidden', !!visible);
  73334. // highlight selected axis
  73335. handle.material._opacity = handle.material._opacity || handle.material.opacity;
  73336. handle.material._color = handle.material._color || handle.material.color.clone();
  73337. handle.material.color.copy(handle.material._color);
  73338. handle.material.opacity = handle.material._opacity;
  73339. if (!this.enabled) {
  73340. handle.material.opacity *= 0.5;
  73341. handle.material.color.lerp(new Color(1, 1, 1), 0.5);
  73342. } else if (this.axis) {
  73343. if (handle.name === this.axis) {
  73344. handle.material.opacity = 1.0;
  73345. handle.material.color.lerp(new Color(1, 1, 1), 0.5);
  73346. } else if (this.axis.split('').some(function (a) {
  73347. return handle.name === a;
  73348. })) {
  73349. handle.material.opacity = 1.0;
  73350. handle.material.color.lerp(new Color(1, 1, 1), 0.5);
  73351. } else {
  73352. handle.material.opacity *= 0.25;
  73353. handle.material.color.lerp(new Color(1, 1, 1), 0.5);
  73354. }
  73355. }
  73356. }
  73357. Object3D.prototype.updateMatrixWorld.call(this);
  73358. };
  73359. };
  73360. /* var TransformControlsLines = function (options) {
  73361. THREE.Object3D.call( this)
  73362. let label1 = new Label2D({ innerHTML:`<div>与相机水平距离</div>` , domElement:$("#otherLabels")[0] ,autoUpdate:true })
  73363. let label2 = new Label2D({ innerHTML:`<div>与相机高度差</div>` , domElement:$("#otherLabels")[0] ,autoUpdate:true })
  73364. let css = {'opacity': 0.7, 'color': '#07fceb', transform:'translate(-50%, -50%)'}
  73365. label1.elem.css(css);
  73366. label2.elem.css(css)
  73367. //for(let i=0;i<2;i++){
  73368. // let line = LineDraw.createLine([new THREE.THREE.Vector3, new THREE.THREE.Vector3],{color:'#07fceb', opacity:0.7 })
  73369. // this.add(line)
  73370. //}
  73371. this.updateTransform = function(object){
  73372. object = object || this.parent.object;
  73373. let A = player.position.clone(); //当前相机位置
  73374. let B = object.position //物体位置
  73375. let C = B.clone().setY(A.y); //物体在相机的高度的位置
  73376. let D = A.clone().setY(B.y); //相机在物体的高度的位置
  73377. //LineDraw.moveLine(this.children[0], [B, C]) // 垂直线
  73378. //LineDraw.moveLine(this.children[1], [D, B]) // 水平线
  73379. let dis1 = toPrecision(D.distanceTo(B),1)
  73380. let dis2 = C.y - B.y
  73381. label1.elem.text('与相机水平距离: '+dis1+'米')
  73382. label2.elem.text('在相机之'+ (dis2>0?'下' : '上') +' :'+ toPrecision(dis2 , 1) +'米')
  73383. label1.setPos(new THREE.THREE.Vector3().addVectors(D,B).multiplyScalar(0.5))
  73384. label2.setPos(new THREE.THREE.Vector3().addVectors(B,C).multiplyScalar(0.5))
  73385. }
  73386. this.setVisible = (v,reason)=>{
  73387. label1.setVisible(v, reason || 'unvisi')
  73388. label2.setVisible(v, reason || 'unvisi')
  73389. this.visible = label1.visible
  73390. if(this.visible){
  73391. this.updateTransform()
  73392. }
  73393. }
  73394. this.setVisible(false)
  73395. player.on("mode.changing",(currentMode, mode, pano, duration)=>{
  73396. if(mode != 'panorama'){
  73397. this.setVisible(false, 'isPanorama')
  73398. }else{
  73399. this.setVisible(true, 'isPanorama')
  73400. }
  73401. })
  73402. player.on("flying.started",( )=>{
  73403. this.setVisible(false, 'flying')
  73404. })
  73405. player.on("flying.ended",( )=>{
  73406. this.setVisible(true, 'flying')
  73407. })
  73408. }
  73409. */
  73410. var TransformControlsPlane = function TransformControlsPlane(options) {
  73411. 'use strict';
  73412. Mesh.call(this, new PlaneBufferGeometry(100000, 100000, 2, 2), new MeshBasicMaterial({
  73413. color: "#ff0000",
  73414. visible: false,
  73415. wireframe: false,
  73416. side: DoubleSide,
  73417. transparent: true,
  73418. opacity: 0.2
  73419. }));
  73420. this.type = 'TransformControlsPlane';
  73421. var unitX = new Vector3(1, 0, 0);
  73422. var unitY = new Vector3(0, 1, 0);
  73423. var unitZ = new Vector3(0, 0, 1);
  73424. var tempVector = new Vector3();
  73425. var dirVector = new Vector3();
  73426. var alignVector = new Vector3();
  73427. var tempMatrix = new Matrix4();
  73428. var identityQuaternion = new Quaternion();
  73429. this.updateMatrixWorld = function () {
  73430. if (!this.visible) return; //add
  73431. var space = this.space;
  73432. this.position.copy(this.worldPosition);
  73433. if (this.mode === 'scale') space = 'local'; // scale always oriented to local rotation
  73434. unitX.set(1, 0, 0).applyQuaternion(space === "local" ? this.worldQuaternion : identityQuaternion);
  73435. unitY.set(0, 1, 0).applyQuaternion(space === "local" ? this.worldQuaternion : identityQuaternion);
  73436. unitZ.set(0, 0, 1).applyQuaternion(space === "local" ? this.worldQuaternion : identityQuaternion);
  73437. // Align the plane for current transform mode, axis and space.
  73438. alignVector.copy(unitY);
  73439. switch (this.mode) {
  73440. case 'translate':
  73441. case 'scale':
  73442. switch (this.axis) {
  73443. case 'X':
  73444. alignVector.copy(this.eye).cross(unitX);
  73445. dirVector.copy(unitX).cross(alignVector);
  73446. break;
  73447. case 'Y':
  73448. alignVector.copy(this.eye).cross(unitY);
  73449. dirVector.copy(unitY).cross(alignVector);
  73450. break;
  73451. case 'Z':
  73452. alignVector.copy(this.eye).cross(unitZ);
  73453. dirVector.copy(unitZ).cross(alignVector);
  73454. break;
  73455. case 'XY':
  73456. dirVector.copy(unitZ);
  73457. break;
  73458. case 'YZ':
  73459. dirVector.copy(unitX);
  73460. break;
  73461. case 'XZ':
  73462. alignVector.copy(unitZ);
  73463. dirVector.copy(unitY);
  73464. break;
  73465. case 'XYZ':
  73466. case 'E':
  73467. default:
  73468. //xzw add for scale xyzz
  73469. dirVector.set(0, 0, 0);
  73470. break;
  73471. }
  73472. break;
  73473. case 'rotate':
  73474. default:
  73475. // special case for rotate
  73476. dirVector.set(0, 0, 0);
  73477. }
  73478. if (dirVector.length() === 0) {
  73479. //使物体在视线中平移
  73480. // If in rotate mode, make the plane parallel to camera
  73481. this.quaternion.copy(this.cameraQuaternion);
  73482. } else {
  73483. //方向滑动所在面
  73484. tempMatrix.lookAt(tempVector.set(0, 0, 0), dirVector, alignVector);
  73485. this.quaternion.setFromRotationMatrix(tempMatrix);
  73486. }
  73487. Object3D.prototype.updateMatrixWorld.call(this);
  73488. };
  73489. };
  73490. TransformControls.prototype = Object.assign(Object.create(Object3D.prototype), {
  73491. constructor: TransformControls,
  73492. isTransformControls: true
  73493. });
  73494. TransformControlsGizmo.prototype = Object.assign(Object.create(Object3D.prototype), {
  73495. constructor: TransformControlsGizmo,
  73496. isTransformControlsGizmo: true
  73497. });
  73498. TransformControlsPlane.prototype = Object.assign(Object.create(Mesh.prototype), {
  73499. constructor: TransformControlsPlane,
  73500. isTransformControlsPlane: true
  73501. });
  73502. /*
  73503. 备注:
  73504. //这里虽然 使坐标轴在boundingBox中心
  73505. boundingBox && this.object.boundingBox.getCenter(worldPosition).applyMatrix4(this.object.matrixWorld);
  73506. 但是旋转中心并不是这个坐标轴显示的位置,需要再执行 MergeEditor.maintainBoundXY()才能维持在这个中心
  73507. */
  73508. var texLoader$a = new TextureLoader();
  73509. texLoader$a.crossOrigin = "anonymous";
  73510. var edgeStrengths = {
  73511. pointcloud: 4,
  73512. glb: 100
  73513. };
  73514. var viewportProps$1 = [{
  73515. left: 0,
  73516. bottom: 0,
  73517. width: 0.5,
  73518. height: 1,
  73519. name: 'top',
  73520. axis: ["x", "y"],
  73521. direction: new Vector3(0, 0, -1),
  73522. //镜头朝向
  73523. active: true,
  73524. //相机位置在z轴正向
  73525. limitBound: new Box3(new Vector3(-Infinity, -Infinity, 1), new Vector3(Infinity, Infinity, 5000)),
  73526. //在地面以上
  73527. margin: {
  73528. x: 50,
  73529. y: 150
  73530. }
  73531. }, {
  73532. left: 0.5,
  73533. bottom: 0,
  73534. width: 0.5,
  73535. height: 1,
  73536. name: 'right',
  73537. axis: ["y", "z"],
  73538. direction: new Vector3(1, 0, 0),
  73539. active: true,
  73540. //相机位置在x轴负向 右下角屏
  73541. viewContainsPoints: [new Vector3(0, 0, 0)],
  73542. margin: {
  73543. x: 300,
  73544. y: 250
  73545. }
  73546. }];
  73547. var cylinderSkyGeo, oldSkyGeo;
  73548. var MergeEditor = {
  73549. bus: new EventDispatcher(),
  73550. SplitScreen: new SplitScreen(),
  73551. init() {
  73552. this.boxHelper = new Box3Helper$1(new Box3(new Vector3(-0.5, -0.5, -0.5), new Vector3(0.5, 0.5, 0.5)));
  73553. viewer.scene.scene.add(this.boxHelper);
  73554. Potree.Utils.updateVisible(this.boxHelper, 'unselect', false);
  73555. this.history = new History({
  73556. applyData: data => {
  73557. if (data.object.parent /* && data.object == this.selected */) {
  73558. data = Potree.Common.CloneObject(data); //避免使用后更改数据又被使用
  73559. data.matrix.decompose(data.object.position, data.object.quaternion, data.object.scale);
  73560. data.object.boundCenter.copy(data.boundCenter);
  73561. data.object.dispatchEvent('changeByHistory');
  73562. data.object.dispatchEvent('transformChanged');
  73563. viewer.dispatchEvent('content_changed');
  73564. return true;
  73565. }
  73566. },
  73567. getData: object => {
  73568. return {
  73569. object,
  73570. matrix: object.matrixWorld.clone(),
  73571. boundCenter: object.boundCenter.clone()
  73572. };
  73573. }
  73574. });
  73575. {
  73576. Potree.settings.notAdditiveBlending = true;
  73577. var ground = this.ground = new InfiniteGridHelper(1, 10000, new Color('#eee'), 10000, 0.2, 0.3);
  73578. viewer.scene.scene.add(ground);
  73579. //再加两条线否则在正侧边看不到
  73580. var line1 = LineDraw.createLine([new Vector3(-10000, 0, 0), new Vector3(10000, 0, 0)], {
  73581. color: '#aaa'
  73582. });
  73583. var line2 = LineDraw.createLine([new Vector3(0, -10000, 0), new Vector3(0, 10000, 0)], {
  73584. mat: line1.material
  73585. });
  73586. ground.renderOrder = Potree.config.renderOrders.model + 1; //line1.renderOrder + 1 //要比模型低,否则模型透明时效果不对
  73587. ground.add(line1);
  73588. ground.add(line2);
  73589. ground.material.opacity = 0.9; //为了滞后渲染,否则被rt遮住
  73590. ground.material.polygonOffset = true; //多边形偏移(视觉上没有移动模型位置),防止闪烁
  73591. ground.material.polygonOffsetFactor = 100; //多边形偏移因子
  73592. ground.material.polygonOffsetUnits = 10; //多边形偏移单位
  73593. ground.material.depthWrite = false;
  73594. //ground.material.depthTest = false
  73595. line1.material.polygonOffset = true;
  73596. line1.material.polygonOffsetFactor = 130;
  73597. line1.material.polygonOffsetUnits = 10;
  73598. line1.material.depthWrite = false;
  73599. //见笔记:透明物体的材质设置
  73600. }
  73601. var oriEdgeStrength = viewer.outlinePass.edgeStrength;
  73602. {
  73603. this.transformControls = new TransformControls(viewer.mainViewport.camera, viewer.renderArea, {
  73604. dontHideWhenFaceCamera: true
  73605. });
  73606. //this.transformControls.space = 'local'//为了在当前方向上平移
  73607. this.transformControls.setSize(1.5);
  73608. viewer.scene.scene.add(this.transformControls);
  73609. this.transformControls._gizmo.hideAxis = {
  73610. rotate: ['e']
  73611. };
  73612. this.transformControls.setRotateMethod(2);
  73613. //右屏
  73614. this.transformControls2 = new TransformControls(viewer.mainViewport.camera, viewer.renderArea, {
  73615. dontHideWhenFaceCamera: true
  73616. });
  73617. this.transformControls2.setSize(1.5);
  73618. viewer.scene.scene.add(this.transformControls2);
  73619. Potree.Utils.setObjectLayers(this.transformControls2, 'layer2');
  73620. var mouseDown = e => {
  73621. viewer.outlinePass.edgeStrength = 0; //暂时消失线
  73622. };
  73623. var mouseUp = e => {
  73624. //this.updateEdgeStrength()
  73625. viewer.outlinePass.edgeStrength = oriEdgeStrength;
  73626. };
  73627. this.transformControls.addEventListener('mouseDown', mouseDown);
  73628. this.transformControls2.addEventListener('mouseDown', mouseDown);
  73629. this.transformControls.addEventListener('mouseUp', mouseUp);
  73630. this.transformControls2.addEventListener('mouseUp', mouseUp);
  73631. this.transformControls.addEventListener('mouseDown', () => {
  73632. //dragstart
  73633. this.history.beforeChange(this.selected);
  73634. });
  73635. this.transformControls.addEventListener('mouseUp', () => {
  73636. this.history.afterChange(this.selected);
  73637. });
  73638. }
  73639. {
  73640. this.secondCompass = new Compass(null);
  73641. }
  73642. viewer.setControls(viewer.orbitControls);
  73643. //viewer.mainViewport.view.fixZWhenPan = true
  73644. viewer.orbitControls.constantlyForward = true;
  73645. viewer.addEventListener('global_single_click', e => {
  73646. if (this.noNeedSelection //如模型查看页
  73647. || viewer.scene.cameraAnimations.some(c => c.onUpdate) //正在播放
  73648. || e.drag && e.drag.notPressMouse //在加测量线
  73649. || viewer.mainViewport.view.isFlying() //有其他校准
  73650. || this.split //分屏中
  73651. || e.clickElement //触发别的点击事件,如测量时click marker /* && e.clickElement != e.intersect.object */
  73652. ) {
  73653. return;
  73654. }
  73655. if (e.intersect) {
  73656. var object = e.intersect.object || e.intersect.pointcloud;
  73657. var objects = this.getAllObjects();
  73658. if (objects.includes(object) && this.selected != object) {
  73659. this.selectModel(object);
  73660. } else {
  73661. //if(!viewer.inputHandler.selection[0]){//正在平移和旋转,不允许取消
  73662. this.selectModel(null);
  73663. //}
  73664. }
  73665. } else {
  73666. //if(!viewer.inputHandler.selection[0]){
  73667. this.selectModel(null);
  73668. //}
  73669. }
  73670. });
  73671. viewer.inputHandler.addEventListener('keydown', e => {
  73672. if (e.event.key.toLowerCase() == "h") {
  73673. this.fadeOutlineAuto = !this.fadeOutlineAuto;
  73674. this.showModelOutline(this.selected, !!this.selected);
  73675. }
  73676. });
  73677. //viewer.fxaaPass.enabled = false//viewer.ssaaRenderPass.enabled = false
  73678. viewer.outlinePass.enabled = true;
  73679. //Potree.settings.intersectWhenHover = false
  73680. //Potree.Utils.updateVisible(viewer.reticule, 'force', false)
  73681. viewer.composer.scaleRatio = 1;
  73682. viewer.composer.readTarget = false;
  73683. viewer.mainViewport.camera.near = 0.05; // too small will result in z-fighting
  73684. viewer.addEventListener('updateModelBound', e => {
  73685. if (this.split) {
  73686. this.SplitScreen.updateCameraOutOfModel( /* this.selected && [this.selected] */);
  73687. }
  73688. });
  73689. {
  73690. //校准页面拖拽
  73691. //左右屏都可以拖拽模型,旋转只能左屏
  73692. var dragInfo;
  73693. var drag = e => {
  73694. if (this.split && this.selected && this.transformState && (e.dragViewport.name == 'top' || this.transformState == 'translate')) {
  73695. if (e.type == 'global_mousedown') {
  73696. //开始
  73697. //if((e.intersect.object || e.intersect.pointcloud) == this.selected){
  73698. if (e.intersect.pointclouds.includes(this.selected) || e.intersect.allElements.some(e => e.object == this.selected)) {
  73699. dragInfo = {};
  73700. //if(this.selected.isPointcloud){
  73701. viewer.outlinePass.edgeStrength = 0; //暂时消失线
  73702. //}
  73703. }
  73704. }
  73705. if (e.type == 'global_drag' && dragInfo) {
  73706. if (this.transformState == 'translate') {
  73707. var moveVec = Potree.Utils.getOrthoCameraMoveVec(e.drag.pointerDelta, e.dragViewport.camera); //最近一次移动向量
  73708. this.selected.position.add(moveVec);
  73709. this.selected.dispatchEvent("position_changed");
  73710. } else if (this.transformState == 'rotate') {
  73711. var vec = new Vector3().subVectors(e.intersect.orthoIntersect || e.intersect.location, this.selected.boundCenter).setZ(0);
  73712. if (dragInfo.lastVec == void 0) {
  73713. //global_mousedown
  73714. dragInfo.lastVec = vec;
  73715. return;
  73716. }
  73717. var angle = math.getAngle(dragInfo.lastVec, vec, 'z');
  73718. dragInfo.lastVec = vec;
  73719. //this.selected.rotation.z += angle //局部
  73720. /* object.quaternion.copy( .setFromAxisAngle( new THREE.Vector3(0,0,1), angle ) );
  73721. object.quaternion.multiply( quaternionStart ).normalize(); */
  73722. var diffQua = new Quaternion().setFromAxisAngle(new Vector3(0, 0, 1), angle);
  73723. this.selected.quaternion.premultiply(diffQua); //世界
  73724. this.selected.dispatchEvent("rotation_changed");
  73725. }
  73726. return {
  73727. stopContinue: true
  73728. };
  73729. }
  73730. }
  73731. };
  73732. viewer.addEventListener('global_mousedown', drag);
  73733. viewer.addEventListener('global_drag', drag, {
  73734. importance: 10
  73735. });
  73736. viewer.addEventListener('global_mousemove', e => {
  73737. if (this.split && this.transformState && !e.drag && (e.hoverViewport.name == 'top' || this.transformState == 'translate')) {
  73738. /* if(this.lastHoverViewport != e.hoverViewport){
  73739. this.lastHoverViewport = e.hoverViewport
  73740. this.transformControls.view = e.hoverViewport.view
  73741. this.transformControls.camera = e.hoverViewport.camera
  73742. this.transformControls.hideAxis( this.transformState, e.hoverViewport.name == 'top' ? [z] : [x,y]);
  73743. } */
  73744. var mouseover = e.intersect.pointclouds.includes(this.selected) || e.intersect.allElements.some(e => e.object == this.selected);
  73745. //let mouseover = (e.intersect.object || e.intersect.pointcloud) == this.selected
  73746. if (mouseover) {
  73747. if (this.transformState == 'translate') {
  73748. viewer.dispatchEvent({
  73749. type: "CursorChange",
  73750. action: "add",
  73751. name: "movePointcloud"
  73752. });
  73753. } else {
  73754. viewer.dispatchEvent({
  73755. type: "CursorChange",
  73756. action: "add",
  73757. name: "rotatePointcloud"
  73758. });
  73759. }
  73760. } else {
  73761. this.clearTranCursor();
  73762. }
  73763. }
  73764. });
  73765. viewer.addEventListener('global_drop', e => {
  73766. dragInfo = null;
  73767. this.clearTranCursor();
  73768. //this.updateEdgeStrength()
  73769. viewer.outlinePass.edgeStrength = oriEdgeStrength;
  73770. });
  73771. }
  73772. /* viewer.addEventListener('background_changed',()=>{
  73773. }) */
  73774. viewer.addEventListener('camera_changed', () => {
  73775. Common.intervalTool.isWaiting('updateMemoryUsage', () => {
  73776. this.updateMemoryUsage();
  73777. }, 1000);
  73778. });
  73779. viewer.addEventListener('setDisplay', this.updateMemoryUsage.bind(this));
  73780. },
  73781. clearTranCursor() {
  73782. viewer.dispatchEvent({
  73783. type: "CursorChange",
  73784. action: "remove",
  73785. name: "movePointcloud"
  73786. });
  73787. viewer.dispatchEvent({
  73788. type: "CursorChange",
  73789. action: "remove",
  73790. name: "rotatePointcloud"
  73791. });
  73792. },
  73793. enterSplit() {
  73794. this.split = true;
  73795. if (this.selected) this.SplitScreen.focusCenter = this.selected.boundCenter; //旋转中心。注意 boundCenter不能直接赋值,否则改变后focusCenter也要改
  73796. else this.SplitScreen.focusCenter = null;
  73797. this.SplitScreen.splitStart(viewportProps$1);
  73798. this.beforeSplit = {
  73799. pointDensity: Potree.settings.pointDensity
  73800. };
  73801. Potree.settings.pointDensity = 'fourViewports'; //强制降低点云质量
  73802. viewer.setControls(viewer.fpControls);
  73803. var rightViewport = viewer.viewports.find(e => e.name == 'right');
  73804. var topViewport = viewer.viewports.find(e => e.name == 'top');
  73805. topViewport.alignment = true;
  73806. rightViewport.rotateSide = true;
  73807. rightViewport.skyboxFixPos = true;
  73808. rightViewport.skyboxMinZoom = 10;
  73809. rightViewport.skyboxRenderFun = () => {
  73810. // 使cube的一面永远正向镜头。 因侧视图的camera是ortho类型,需要平视mesh才不会拉伸
  73811. viewer.skybox.scene.children[0].rotation.copy(rightViewport.camera.rotation);
  73812. };
  73813. topViewport.skyboxRenderFun = () => {
  73814. viewer.skybox.scene.children[0].rotation.set(0, 0, 0);
  73815. };
  73816. viewer.viewports[1].layersAdd('layer2');
  73817. viewer.viewports[0].layersAdd('layer1');
  73818. Potree.Utils.setObjectLayers(this.transformControls, 'layer1');
  73819. this.transformControls.view = viewer.viewports[0].view;
  73820. this.transformControls.camera = viewer.viewports[0].camera;
  73821. this.transformControls._gizmo.hideAxis = {
  73822. translate: ['z'],
  73823. rotate: ['x', 'y', 'z']
  73824. };
  73825. this.transformControls2.view = viewer.viewports[1].view;
  73826. this.transformControls2.camera = viewer.viewports[1].camera;
  73827. this.transformControls2._gizmo.hideAxis = {
  73828. translate: ['x', 'y'],
  73829. rotate: ['x', 'y', 'z']
  73830. };
  73831. this.secondCompass.changeViewport(viewer.viewports[0]);
  73832. this.secondCompass.setDomPos();
  73833. this.secondCompass.setDisplay(true);
  73834. viewer.compass.changeViewport(viewer.viewports[1]);
  73835. viewer.compass.setDomPos();
  73836. //this.changeSkyboxGeo(true)
  73837. },
  73838. leaveSplit() {
  73839. this.split = false;
  73840. this.SplitScreen.unSplit();
  73841. viewer.setControls(viewer.orbitControls);
  73842. Potree.settings.pointDensity = this.beforeSplit.pointDensity;
  73843. /* if(this.selected && this.selected.isPointcloud){
  73844. this.showModelOutline(this.selected, true)
  73845. this.selected.material.activeAttributeName = "rgba"
  73846. } */
  73847. this.transformControls.camera = viewer.viewports[0].camera;
  73848. this.transformControls.view = viewer.viewports[0].view;
  73849. this.transformControls._gizmo.hideAxis = {
  73850. rotate: ['e']
  73851. };
  73852. Potree.Utils.setObjectLayers(this.transformControls, 'sceneObjects'); //恢复
  73853. viewer.compass.changeViewport(viewer.viewports[0]); //恢复
  73854. viewer.compass.setDomPos();
  73855. this.secondCompass.setDisplay(false);
  73856. },
  73857. rotateSideCamera(angle) {
  73858. this.SplitScreen.rotateSideCamera(viewer.viewports.find(e => e.name == 'right'), angle);
  73859. },
  73860. setTransformState(state) {
  73861. //校准时
  73862. this.transformState = state;
  73863. this.clearTranCursor();
  73864. },
  73865. //---------------------------
  73866. getAllObjects() {
  73867. return viewer.objs.children.concat(viewer.scene.pointclouds);
  73868. },
  73869. getModel(id) {
  73870. var models = this.getAllObjects();
  73871. return models.find(e => e.dataset_id == id);
  73872. },
  73873. removeModel(model) {
  73874. if (this.selected == model) this.selectModel(null);
  73875. var dispose = e => {
  73876. e.geometry && e.geometry.dispose();
  73877. e.material && e.material.dispose();
  73878. };
  73879. if (model.isPointcloud) {
  73880. dispose(model);
  73881. viewer.scene.removePointCloud(model);
  73882. } else {
  73883. model.traverse(e => {
  73884. dispose(e);
  73885. });
  73886. viewer.objs.remove(model);
  73887. this.updateMemoryUsage();
  73888. }
  73889. },
  73890. selectModel(model) {
  73891. var state = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  73892. var fitBound = arguments.length > 2 ? arguments[2] : undefined;
  73893. var by2d = arguments.length > 3 ? arguments[3] : undefined;
  73894. if (!model) {
  73895. model = this.selected;
  73896. state = false;
  73897. }
  73898. if (state) {
  73899. if (this.selected) {
  73900. if (this.selected == model) return;else {
  73901. var transToolAttached = !!this.transformControls.object;
  73902. this.selectModel(this.selected, false, fitBound, by2d);
  73903. transToolAttached && this.transformControls.attach(model);
  73904. }
  73905. }
  73906. this.selected = model;
  73907. MergeEditor.focusOn(model, 500, !!fitBound); //通过在场景里点击模型的话,不focus
  73908. this.showModelOutline(model);
  73909. //this.updateEdgeStrength()
  73910. //console.log('selectModel', model)
  73911. } else {
  73912. if (this.selected != model) return; //model本来就没选中,不需要处理(防止2d先选中新的再取消旧的)
  73913. this.showModelOutline(model, false);
  73914. this.selected = null;
  73915. this.transformControls.detach(); //viewer.transformObject(null);
  73916. //console.log('selectModel', null)
  73917. }
  73918. if (!by2d && model) {
  73919. model.dispatchEvent({
  73920. type: 'changeSelect',
  73921. selected: state
  73922. });
  73923. }
  73924. },
  73925. updateBoxHelper(model) {
  73926. var size = new Vector3();
  73927. model.boundingBox.getSize(size);
  73928. size.multiply(model.scale);
  73929. this.boxHelper.scale.copy(size);
  73930. var center = new Vector3();
  73931. model.boundingBox.getCenter(center);
  73932. center.applyMatrix4(model.matrixWorld);
  73933. //center.add(model.position)
  73934. this.boxHelper.position.copy(center);
  73935. this.boxHelper.quaternion.copy(model.quaternion);
  73936. },
  73937. showModelOutline(model, state) {
  73938. if (Potree.settings.mergeType2) {
  73939. //高斯很卡
  73940. if (state !== false) {
  73941. this.updateBoxHelper(model);
  73942. Potree.Utils.updateVisible(this.boxHelper, 'unselect', true);
  73943. } else {
  73944. Potree.Utils.updateVisible(this.boxHelper, 'unselect', false);
  73945. }
  73946. return;
  73947. }
  73948. if (this.fadeOutlineAuto) {
  73949. if (state === false) {
  73950. viewer.outlinePass.selectedObjects = [];
  73951. clearTimeout(this.timer);
  73952. return;
  73953. }
  73954. viewer.outlinePass.selectedObjects = [model];
  73955. if (this.timer) {
  73956. clearTimeout(this.timer);
  73957. }
  73958. this.timer = setTimeout(() => {
  73959. viewer.outlinePass.selectedObjects = [];
  73960. viewer.dispatchEvent('content_changed');
  73961. }, 1000);
  73962. } else {
  73963. if (state === false) {
  73964. viewer.outlinePass.selectedObjects = [];
  73965. } else {
  73966. viewer.outlinePass.selectedObjects = [model];
  73967. }
  73968. }
  73969. viewer.dispatchEvent('content_changed');
  73970. },
  73971. /*updateEdgeStrength(){
  73972. if(!this.selected)return
  73973. if(this.selected.isPointcloud){
  73974. viewer.outlinePass.edgeStrength = edgeStrengths.pointcloud// / this.selected.material.opacity
  73975. }else{
  73976. viewer.outlinePass.edgeStrength = edgeStrengths.glb
  73977. }
  73978. },*/
  73979. focusOn(objects) {
  73980. var duration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 400;
  73981. var fitBound = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
  73982. var dontLookUp = arguments.length > 3 ? arguments[3] : undefined;
  73983. if (!(objects instanceof Array)) {
  73984. objects = [objects];
  73985. }
  73986. var boundingBox = new Box3();
  73987. objects.forEach(object => {
  73988. boundingBox.union(object.boundingBox.clone().applyMatrix4(object.matrixWorld));
  73989. });
  73990. var len = boundingBox.getSize(new Vector3()).length();
  73991. Potree.settings.cameraFar = Math.max(Potree.settings.cameraFar, len * 3);
  73992. if (fitBound) {
  73993. viewer.focusOnObject({
  73994. boundingBox
  73995. }, 'boundingBox', duration, {
  73996. dontLookUp,
  73997. dontChangeCamDir: true
  73998. });
  73999. } else {
  74000. /*
  74001. let position = viewer.inputHandler.intersect ? viewer.inputHandler.intersect.location : boundingBox.getCenter(new THREE.Vector3)
  74002. position && viewer.focusOnObject({position}, 'point', duration, {dontChangePos: true})
  74003. */
  74004. var position = viewer.inputHandler.intersect ? viewer.inputHandler.intersect.location : boundingBox.getCenter(new Vector3());
  74005. if (!position) return;
  74006. /* let targetOld = viewer.mainViewport.view.getPivot()
  74007. let projected1 = targetOld.clone().project(viewer.mainViewport.camera);
  74008. let projected2 = position.clone().project(viewer.mainViewport.camera); //使用其z
  74009. let targetNew = projected1.clone().setZ(projected2.z).unproject(viewer.mainViewport.camera);
  74010. viewer.mainViewport.view.lookAt(targetNew) */
  74011. viewer.mainViewport.view.radius = viewer.mainViewport.camera.position.distanceTo(position);
  74012. //为了不改画面,不调节方向了,只能调调radius,一定程度将target靠近model
  74013. }
  74014. },
  74015. moveBoundCenterTo(model, pos) {
  74016. //使boundCenter在所要的位置
  74017. var diff = new Vector3().subVectors(pos, model.boundCenter);
  74018. model.position.add(diff);
  74019. },
  74020. getBoundCenter(model) {
  74021. if (!model.boundCenter) model.boundCenter = new Vector3();
  74022. model.boundingBox.getCenter(model.boundCenter).applyMatrix4(model.matrixWorld);
  74023. },
  74024. setModelBtmHeight(model, z) {
  74025. //无论模型怎么缩放、旋转,都使最低点为z
  74026. if (z == void 0) z = model.btmHeight; //维持离地高度
  74027. else model.btmHeight = z;
  74028. if (model.btmHeight == void 0) return;
  74029. model.updateMatrixWorld();
  74030. var boundingBox2 = model.boundingBox.clone().applyMatrix4(model.matrixWorld);
  74031. var size = boundingBox2.getSize(new Vector3());
  74032. var center = boundingBox2.getCenter(new Vector3());
  74033. var hopeZ = z + size.z / 2;
  74034. //model.position.z = z + size.z / 2 - center.z
  74035. model.position.z += hopeZ - center.z;
  74036. },
  74037. computeBtmHeight(model) {
  74038. //位移之后重新计算btmHeight
  74039. model.updateMatrixWorld();
  74040. var boundingBox2 = model.boundingBox.clone().applyMatrix4(model.matrixWorld);
  74041. var size = boundingBox2.getSize(new Vector3());
  74042. var center = boundingBox2.getCenter(new Vector3());
  74043. model.btmHeight = center.z - size.z / 2;
  74044. },
  74045. maintainBoundXY(model) {
  74046. //在旋转和缩放后,立即执行这个函数,使boundCenter保持原位
  74047. model.updateMatrixWorld();
  74048. var center1 = model.boundCenter.clone(); //还未更新的
  74049. this.getBoundCenter(model); //更新
  74050. var center2 = model.boundCenter.clone();
  74051. var diff = new Vector2().subVectors(center1, center2);
  74052. model.position.x += diff.x;
  74053. model.position.y += diff.y;
  74054. model.boundCenter.copy(center1);
  74055. },
  74056. maintainBoundCenter(model) {
  74057. model.updateMatrixWorld();
  74058. var center1 = model.boundCenter.clone(); //还未更新的
  74059. this.getBoundCenter(model); //更新
  74060. var center2 = model.boundCenter.clone();
  74061. var diff = new Vector3().subVectors(center1, center2);
  74062. model.position.add(diff);
  74063. model.boundCenter.copy(center1);
  74064. },
  74065. modelTransformCallback(model, force) {
  74066. model.updateMatrixWorld();
  74067. if (!force && model.matrixWorld.equals(model.lastMatrixWorld)) return;
  74068. viewer.scene.measurements.forEach(measure => {
  74069. var changed;
  74070. measure.points_datasets.forEach((dataset_id, i) => {
  74071. if (dataset_id == model.dataset_id) {
  74072. changed = true;
  74073. measure.points[i] = Potree.Utils.datasetPosTransform({
  74074. fromDataset: true,
  74075. datasetId: dataset_id,
  74076. position: measure.dataset_points[i].clone()
  74077. });
  74078. measure.updateMarker(measure.markers[i], measure.points[i]);
  74079. }
  74080. });
  74081. if (changed) {
  74082. //仿transformByPointcloud
  74083. measure.getPoint2dInfo(measure.points);
  74084. measure.update();
  74085. measure.setSelected(false); //隐藏edgelabel
  74086. }
  74087. });
  74088. //反向求transformMatrix 参考Alignment.js 移动漫游点
  74089. if (model.isPointcloud && model.transformMatrix) {
  74090. model.transformMatrix.multiplyMatrices(model.matrix, model.pos1MatrixInvert);
  74091. model.transformInvMatrix.copy(model.transformMatrix).invert();
  74092. model.rotateMatrix = new Matrix4().makeRotationFromEuler(model.rotation);
  74093. model.panos.forEach(e => e.transformByPointcloud());
  74094. } else if (model.panos) {
  74095. model.rotateMatrix = new Matrix4().makeRotationFromEuler(model.rotation).multiply(model.rot1MatrixInvert);
  74096. model.transformMatrix.multiplyMatrices(model.matrix, model.posRot1MatrixInvert);
  74097. model.panos.forEach(e => e.transformByPointcloud());
  74098. model.bound = model.boundingBox.clone().applyMatrix4(model.matrixWorld);
  74099. }
  74100. model.lastMatrixWorld = model.matrixWorld.clone();
  74101. viewer.dispatchEvent('content_changed');
  74102. viewer.mapViewer && Potree.settings.showObjectsOnMap && viewer.mapViewer.dispatchEvent('content_changed');
  74103. //--------
  74104. this.updateBoxHelper(model);
  74105. },
  74106. changeOpacity(model, opacity) {
  74107. var isRoot = model.dataset_id != void 0; //是否是最外层
  74108. if (model.isPointcloud) {
  74109. model.changePointOpacity(opacity);
  74110. //MergeEditor.updateEdgeStrength()
  74111. } else {
  74112. //model.traverse(e=>e.material && setOp(e, opacity))
  74113. model.traverse(mesh => {
  74114. if (mesh.material) {
  74115. if (mesh.material.originOpacity == void 0) {
  74116. mesh.material.originOpacity = mesh.material.opacity;
  74117. }
  74118. mesh.material.opacity = mesh.material.originOpacity * opacity;
  74119. if (mesh.material.opacity < 1) {
  74120. mesh.material.transparent = true;
  74121. /* if(model.isPointcloud){
  74122. mesh.changePointOpacity(realOpacity)
  74123. }else{
  74124. mesh.material.opacity = realOpacity
  74125. } */
  74126. mesh.renderOrder = Potree.config.renderOrders.model + 1;
  74127. //mesh.material.depthWrite = false
  74128. } else {
  74129. mesh.material.transparent = false;
  74130. mesh.renderOrder = Potree.config.renderOrders.model;
  74131. //mesh.material.depthWrite = true
  74132. }
  74133. mesh.material.depthWrite = mesh.material.opacity > 0.3;
  74134. }
  74135. });
  74136. }
  74137. isRoot && (model.opacity = opacity); //记录在最外层
  74138. viewer.dispatchEvent('content_changed');
  74139. },
  74140. modelAdded(model) {
  74141. model.addEventListener('isVisible', e => {
  74142. if (e.reason == "overlinePass") return;
  74143. //console.log(e)
  74144. viewer.addEventListener('update', () => {
  74145. //下一次更新结束后
  74146. this.updateMemoryUsage();
  74147. }, {
  74148. once: true
  74149. });
  74150. });
  74151. this.updateMemoryUsage();
  74152. },
  74153. updateMemoryUsage() {
  74154. //obj暂时不管其贴图大小, 因为顶点造成的不仅是内存还有卡顿所以先只看顶点
  74155. var maxMemory = Potree.config.tiles3DMaxMemory + 100; //M 实际估计是这个的10倍
  74156. var eachObjPosWeight = 100 / 1000 / 1000; //M 每个顶点pos是3*4个字节?法线3*4和uv2*4 其实还有贴图
  74157. var eachCloudPointWeight = 12 / 1000 / 1000; //M 每个点 pos + 颜色 + 法线 大概
  74158. var eachVisiCPointWeight = eachCloudPointWeight * 5; // 或 maxMemory / (6*1000*1000) 大概值接近 (再除以一个数是因为显示的要比内存中的耗更多资源
  74159. var eachGltfPosWeight = 100 / 1000 / 1000; //M 每个顶点pos是3*4个字节?法线3*4和uv2*4 其实还有贴图
  74160. var posCount = 0;
  74161. viewer.objs.children.forEach(e => {
  74162. if (!e.visible) return;
  74163. if (e.fileType == 'glb' || e.fileType == 'obj') {
  74164. e.traverse(mesh => {
  74165. if (mesh.geometry) {
  74166. posCount += mesh.geometry.attributes.position.count;
  74167. }
  74168. });
  74169. } else if (e.fileType == '3dTiles') {}
  74170. });
  74171. //获取点云的内存限制
  74172. var objWeight = posCount * eachObjPosWeight;
  74173. var laserWeight = Potree.numVisiblePoints * eachCloudPointWeight; //点云实际显示所占大小
  74174. var laserMemoryWeight = Potree.lru.numPoints * eachCloudPointWeight; //点云所使用内存大小
  74175. var tiles3DWeight = viewer.tiles3dVisiVCount * eachGltfPosWeight; //M 3dTiles所占内存大小
  74176. var tiles3DMemoryWeight = viewer.tiles3dMemoryUsage / 1000 / 1000; //M 3dTiles显示的所占内存大小
  74177. /* let min = 0.1, max = 6, minP = 100, maxP = 1000000;
  74178. let ratio = Math.round(math.linearClamp(score, minP, maxP, max, min )); */
  74179. var rest = maxMemory - objWeight - tiles3DWeight;
  74180. Potree.pointBudget = MathUtils.clamp(Math.round(rest / eachVisiCPointWeight), Potree.config.pointDensity.low.pointBudget, 1.5 * Potree.config.pointDensity.high.pointBudget);
  74181. //获取3dTiles的内存限制
  74182. var tiles3DMaxMemory = maxMemory - Math.round(objWeight + laserWeight);
  74183. Potree.settings.tiles3DMaxMemory = MathUtils.clamp(tiles3DMaxMemory, 30, Potree.config.tiles3DMaxMemory);
  74184. //还存在的问题:仍然有隐患,因为没用到真实缓存的大小: tiles3DMemoryWeight laserMemoryWeight, 它们比真实可见的要多。不使用是因为它们无法反应出实际需要的内存量,缓存是只增不减
  74185. //obj等普通mesh限制不了
  74186. //console.log('objWeight',objWeight.toFixed(1), 'laserMemoryWeight',laserMemoryWeight.toFixed(1), 'tiles3DWeight',tiles3DWeight.toFixed(1), 'pointBudget',Potree.pointBudget, 'tiles3DMaxMemory',tiles3DMaxMemory)
  74187. //总内存 = 内存占用空间+图片缓存 , obj的缓存比较多在图片中
  74188. },
  74189. setGroundPlaneImg(src, scale, angle) {
  74190. //设置地面图
  74191. this.goundScale = scale || 1, this.goundAngle = angle || 0;
  74192. var oldSrc = this.curGroundImgSrc;
  74193. this.curGroundImgSrc = src;
  74194. var ratio = 0.03;
  74195. if (src) {
  74196. if (oldSrc == src && this.groundPlane.material.map.image) {
  74197. //仅修改大小
  74198. var s = ratio * this.goundScale;
  74199. var {
  74200. width,
  74201. height
  74202. } = this.groundPlane.material.map.image;
  74203. this.groundPlane.scale.set(width * s, height * s);
  74204. viewer.dispatchEvent('content_changed');
  74205. this.groundPlane.rotation.z = MathUtils.degToRad(this.goundAngle);
  74206. return;
  74207. }
  74208. var map = texLoader$a.load(src, tex => {
  74209. if (this.curGroundImgSrc == src) {
  74210. var _s = ratio * this.goundScale;
  74211. this.groundPlane.scale.set(tex.image.width * _s, tex.image.height * _s);
  74212. this.groundPlane.rotation.z = MathUtils.degToRad(this.goundAngle);
  74213. viewer.dispatchEvent('content_changed');
  74214. }
  74215. });
  74216. Potree.Utils.makeTexDontResize(map);
  74217. if (!this.groundPlane) {
  74218. this.groundPlane = new Mesh(new PlaneBufferGeometry(1, 1, 1), new MeshBasicMaterial({
  74219. map,
  74220. side: 2
  74221. }));
  74222. viewer.scene.scene.add(this.groundPlane);
  74223. this.groundPlane.position.z = 0.1;
  74224. } else {
  74225. this.groundPlane.material.map = map;
  74226. }
  74227. Potree.Utils.updateVisible(this.groundPlane, 'show', true);
  74228. } else {
  74229. this.groundPlane && Potree.Utils.updateVisible(this.groundPlane, 'show', false);
  74230. }
  74231. }
  74232. };
  74233. /*
  74234. note:
  74235. 要注意getHoveredElements只在getIntersect时才使interactables包含加载的model, 也就是model上不能有使之成为interactables的事件,否则在鼠标hover到模型上开始转动的一瞬间很卡。
  74236. */
  74237. var texLoader$b = new TextureLoader();
  74238. var arrowSpacing = 1; //间隔
  74239. var arrowSize = arrowSpacing * 0.5;
  74240. var planeGeo$3 = new PlaneBufferGeometry(1, 1);
  74241. var sphereSizeInfo = {
  74242. nearBound: 0.1,
  74243. farBound: 25,
  74244. minSize: 50,
  74245. maxSize: 200 //scale:arrowSize, restricMeshScale : true,
  74246. };
  74247. //const arrowsShowingCount = 25; //场景里最多展示多少个箭头
  74248. var arrowShowMinDis = 10;
  74249. class RouteGuider extends EventDispatcher {
  74250. constructor() {
  74251. super();
  74252. this.route = [];
  74253. this.curve = [];
  74254. this.scenePoints = [];
  74255. this.sceneMeshGroup = new Object3D();
  74256. this.mapMeshGroup = new Object3D();
  74257. this.generateDeferred;
  74258. viewer.addEventListener('loadPointCloudDone', this.init.bind(this));
  74259. this.lastResult; //保存上一个的结果,以便于反向
  74260. this.datasetIds = []; //起始和终点的datasetId
  74261. }
  74262. init() {
  74263. if (this.inited) return;
  74264. var zoom,
  74265. resolution = new Vector2();
  74266. viewer.mapViewer.addEventListener('camera_changed', e => {
  74267. if (!this.routeStart || !this.routeEnd) return;
  74268. var camera = e.viewport.camera;
  74269. if (camera.zoom != zoom || !resolution.equals(e.viewport.resolution)) {
  74270. Common.intervalTool.isWaiting('routeCameraInterval', () => {
  74271. //延时update,防止卡顿
  74272. if (camera.zoom != zoom || !resolution.equals(e.viewport.resolution)) {
  74273. //console.log('updateMapArrows')
  74274. this.updateMapArrows(true);
  74275. zoom = camera.zoom;
  74276. resolution.copy(e.viewport.resolution);
  74277. }
  74278. }, browser.isMobile() ? 500 : 200);
  74279. }
  74280. });
  74281. viewer.addEventListener('camera_changed', e => {
  74282. if (!this.routeStart || !this.routeEnd || !e.changeInfo.positionChanged) return;
  74283. Common.intervalTool.isWaiting('routeCameraInterval2', () => {
  74284. //延时update,防止卡顿
  74285. this.updateArrowDisplay();
  74286. }, 1000);
  74287. });
  74288. var polesMats = {
  74289. shadowMat: new MeshBasicMaterial({
  74290. transparent: true,
  74291. depthTest: false,
  74292. map: texLoader$b.load(Potree.resourcePath + '/textures/pano_instruction_bottomMarker.png')
  74293. }),
  74294. sphereMat: new MeshBasicMaterial({
  74295. transparent: true,
  74296. depthTest: false,
  74297. map: texLoader$b.load(Potree.resourcePath + '/textures/whiteCircle.png')
  74298. }),
  74299. hatMats: {
  74300. start: new MeshBasicMaterial({
  74301. transparent: true,
  74302. depthTest: false,
  74303. map: texLoader$b.load(Potree.resourcePath + '/textures/pano_instruction_start_route.png')
  74304. }),
  74305. end: new MeshBasicMaterial({
  74306. transparent: true,
  74307. depthTest: false,
  74308. map: texLoader$b.load(Potree.resourcePath + '/textures/pano_instruction_target_reached.png')
  74309. })
  74310. }
  74311. };
  74312. polesMats.shadowMat.map.anisotropy = 4;
  74313. this.poleStart = this.createPole(polesMats, 'start');
  74314. this.poleEnd = this.createPole(polesMats, 'end');
  74315. this.sceneMeshGroup.add(this.poleStart);
  74316. this.sceneMeshGroup.add(this.poleEnd);
  74317. var map = texLoader$b.load(Potree.resourcePath + '/textures/routePoint_panorama.png');
  74318. map.anisotropy = 4; // 各向异性过滤 .防止倾斜模糊
  74319. this.arrow = new Mesh(planeGeo$3, new MeshBasicMaterial({
  74320. transparent: true,
  74321. depthTest: false,
  74322. map
  74323. }));
  74324. this.arrow.scale.set(arrowSize, arrowSize, arrowSize);
  74325. Potree.Utils.setObjectLayers(this.arrow, 'sceneObjects');
  74326. /* this.testArrow = this.arrow.clone();
  74327. this.testArrow.material = this.arrow.material.clone()
  74328. this.testArrow.material.color = 'red' */
  74329. this.arrows = new Object3D();
  74330. this.sceneMeshGroup.add(this.arrows);
  74331. Potree.Utils.setObjectLayers(this.sceneMeshGroup, 'sceneObjects');
  74332. //this.sceneMeshGroup.traverse(e=>e.renderOrder = 90)
  74333. viewer.scene.scene.add(this.sceneMeshGroup);
  74334. this.sceneMeshGroup.visible = false;
  74335. this.poleStart.visible = false;
  74336. this.poleEnd.visible = false;
  74337. //-------------map---------------------
  74338. /* this.mapMarkStart = new THREE.Mesh( planeGeo, new THREE.MeshBasicMaterial({
  74339. transparent:true, depthTest:false,
  74340. map: texLoader.load(Potree.resourcePath+'/textures/map_instruction_start_route.png' )
  74341. }))
  74342. this.mapMarkEnd = new THREE.Mesh( planeGeo, new THREE.MeshBasicMaterial({
  74343. transparent:true, depthTest:false,
  74344. map: texLoader.load(Potree.resourcePath+'/textures/map_instruction_target_reached.png' )
  74345. }))
  74346. this.mapMarkStart.renderOrder = this.mapMarkEnd.renderOrder = 2//在箭头之上 */
  74347. var map2 = texLoader$b.load(Potree.resourcePath + '/textures/routePoint_map_fsna.png');
  74348. this.mapArrowMats = {
  74349. default: new MeshBasicMaterial({
  74350. transparent: true,
  74351. depthTest: false,
  74352. map: map2
  74353. }),
  74354. fade: new MeshBasicMaterial({
  74355. transparent: true,
  74356. depthTest: false,
  74357. map: map2,
  74358. opacity: 0.4
  74359. })
  74360. };
  74361. this.mapArrow = new Mesh(planeGeo$3, this.mapArrowMats.default);
  74362. this.mapArrow.scale.set(arrowSize, arrowSize, arrowSize);
  74363. this.mapArrows = new Object3D();
  74364. this.mapArrows.name = 'mapArrows';
  74365. this.mapMeshGroup.add(this.mapArrows);
  74366. this.mapMeshGroup.name = 'mapRouteLayer';
  74367. this.mapMeshGroup.visible = false;
  74368. viewer.mapViewer.dispatchEvent({
  74369. type: 'add',
  74370. object: this.mapMeshGroup,
  74371. name: 'route'
  74372. });
  74373. this.mapArrow.layers.mask = this.mapArrows.layers.mask; // 修改成和map中的layer一样的
  74374. viewer.modules.SiteModel.bus.addEventListener('FloorChange', () => {
  74375. if (this.routeStart && this.routeEnd) {
  74376. this.updateOpacityAtMap();
  74377. }
  74378. });
  74379. this.inited = true;
  74380. }
  74381. updateOpacityAtMap() {
  74382. //只有当前楼层的透明度为1
  74383. var currentFloor = viewer.modules.SiteModel.currentFloor;
  74384. //console.log('updateOpacityAtMap', currentFloor && currentFloor.name)
  74385. var lift = 0.3; // 因为发送请求时用的是floorPosition的高度,而它可能会到画好的floor之下,所以有误差
  74386. this.mapArrows.children.forEach((arrow, index) => {
  74387. var pos = this.mapPoints[index].clone();
  74388. pos.z += lift;
  74389. var inSide = currentFloor && currentFloor.ifContainsPoint(pos);
  74390. arrow.material = inSide ? this.mapArrowMats.default : this.mapArrowMats.fade;
  74391. //console.log('arrow',index, arrow.material.opacity)
  74392. });
  74393. viewer.mapViewer.dispatchEvent('content_changed');
  74394. } //但是如果楼层刚好只框柱相机位置而没框住地面位置就不好了……
  74395. createPole(polesMats, name) {
  74396. var height = 1.5,
  74397. sphereCount = 6,
  74398. shadowSize = 0.5 /* sphereSizeInfo.scale */,
  74399. sphereSize = 0.05;
  74400. var group = new Object3D();
  74401. group.name = 'pole_' + name;
  74402. var shadow = new Mesh(planeGeo$3, polesMats.shadowMat);
  74403. shadow.scale.set(shadowSize, shadowSize, shadowSize);
  74404. var sliceDis = height / (sphereCount + 1);
  74405. group.add(shadow);
  74406. for (var i = 0; i < sphereCount; i++) {
  74407. var sphere = new Sprite$2({
  74408. mat: polesMats.sphereMat,
  74409. renderOrder: 3
  74410. });
  74411. sphere.position.set(0, 0, sliceDis * (i + 1));
  74412. sphere.scale.set(sphereSize, sphereSize, sphereSize);
  74413. //sphere.visible = false
  74414. group.add(sphere);
  74415. }
  74416. var hatSphere = new Sprite$2({
  74417. mat: polesMats.hatMats[name],
  74418. sizeInfo: sphereSizeInfo,
  74419. renderOrder: 4
  74420. });
  74421. //sphere.visible = false
  74422. hatSphere.position.set(0, 0, height);
  74423. hatSphere.scale.copy(shadow.scale);
  74424. group.add(hatSphere);
  74425. group.hatSphere = hatSphere;
  74426. return group;
  74427. }
  74428. addTestArrow() {}
  74429. addArrow(position) {
  74430. var arrow = this.arrow.clone();
  74431. arrow.position.copy(position);
  74432. this.arrows.add(arrow);
  74433. }
  74434. addMapArrow(position) {
  74435. var mapArrow = this.mapArrow.clone();
  74436. mapArrow.position.copy(position).setZ(0);
  74437. this.mapArrows.add(mapArrow);
  74438. }
  74439. setArrowDir(arrows, index) {
  74440. var arrow = arrows[index];
  74441. var nextOne = arrows[index + 1];
  74442. var nextPos = nextOne ? nextOne.position : this.endPolePos; //routeEnd
  74443. var direction = new Vector3().subVectors(arrow.position, nextPos).setZ(0);
  74444. //direction.normalize();
  74445. //console.log(direction.toArray())
  74446. var angle = Math.atan2(direction.y, direction.x) + Math.PI / 2; //Math.PI/2是因为贴图本身箭头方向不朝x
  74447. arrow.rotation.z = angle;
  74448. //console.log(angle)
  74449. }
  74450. setRouteStart(pos, dealZ, datasetId) {
  74451. if (this.routeStart && pos && this.routeStart.equals(pos)) return; //可能重复设置
  74452. this.routeStart = pos && new Vector3().copy(pos);
  74453. if (dealZ && this.routeStart) {
  74454. this.routeStart.setZ(this.getZAtMap());
  74455. this.bus && this.bus.emit('reposStartMarker', this.routeStart);
  74456. }
  74457. console.log('setRouteStart', this.routeStart && this.routeStart.toArray());
  74458. this.datasetIds[0] = datasetId;
  74459. //this.setStartPole(pos)
  74460. this.poleStart.visible = !!pos;
  74461. pos && this.poleStart.position.copy(this.routeStart);
  74462. pos && this.poleStart.hatSphere.waitUpdate();
  74463. this.generateRoute();
  74464. viewer.dispatchEvent('content_changed');
  74465. }
  74466. setStartPole(pos) {
  74467. this.startPolePos = pos;
  74468. this.bus && this.bus.emit('reposStartMarker', pos);
  74469. }
  74470. setRouteEnd(pos, dealZ, datasetId) {
  74471. if (this.routeEnd && pos && this.routeEnd.equals(pos)) return;
  74472. this.routeEnd = pos && new Vector3().copy(pos);
  74473. if (dealZ && this.routeEnd) {
  74474. this.routeEnd.setZ(this.getZAtMap());
  74475. this.bus && this.bus.emit('reposEndMarker', this.routeEnd);
  74476. }
  74477. console.log('setRouteEnd', this.routeEnd && this.routeEnd.toArray());
  74478. this.datasetIds[1] = datasetId;
  74479. //this.setEndPole(pos)
  74480. this.poleEnd.visible = !!pos;
  74481. pos && this.poleEnd.position.copy(this.routeEnd);
  74482. pos && this.poleEnd.hatSphere.waitUpdate();
  74483. this.generateRoute();
  74484. viewer.dispatchEvent('content_changed');
  74485. }
  74486. getZAtMap() {
  74487. //找到position.z与当前高度最接近的漫游点
  74488. var result = Common.sortByScore(viewer.images360.panos, [], [e => -Math.abs(e.position.z - viewer.images360.position.z)]);
  74489. var pano = result && result[0] && result[0].item;
  74490. return pano ? pano.floorPosition.z : viewer.bound.boundingBox.min.z + 1;
  74491. //若在平面图上画实在得不到当前楼层的,大概率是楼层画得不好,那就只能去获取当前楼层的了
  74492. //navvis的高度取的是主视图所在楼层的中心高度(可能再高些)
  74493. }
  74494. setEndPole(pos) {
  74495. this.endPolePos = pos;
  74496. this.bus && this.bus.emit('reposEndMarker', pos);
  74497. }
  74498. getSourceProjectionIndex(route) {
  74499. //真正的起始
  74500. var e = route.findIndex(function (t) {
  74501. return t.instruction && t.instruction.type === 'source_projection_to_navgraph';
  74502. });
  74503. return e < 0 ? 0 : e;
  74504. }
  74505. getDestinationProjectionIndex(route) {
  74506. //真正的终点
  74507. var e = route.findIndex(function (t) {
  74508. return t.instruction && t.instruction.type === "destination_projection_to_navgraph";
  74509. });
  74510. return e < 0 ? route.length - 1 : e;
  74511. }
  74512. generateRoute() {
  74513. this.sceneMeshGroup.visible = true;
  74514. if (!this.routeStart || !this.routeEnd) {
  74515. return;
  74516. }
  74517. var initialPointcloud = viewer.scene.pointclouds.find(e => e.dataset_id == Potree.settings.originDatasetId);
  74518. //array.reduce(function(total, currentValue, currentIndex, arr), initialValue)
  74519. var create = () => {
  74520. this.routeLength = this.route.reduce((total, currentValue, currentIndex, arr) => {
  74521. if (currentIndex == 0) return 0;
  74522. return total + currentValue.distanceTo(arr[currentIndex - 1]);
  74523. }, 0);
  74524. var count = Math.max(2, Math.round(this.routeLength / arrowSpacing)); //点数
  74525. var curve = new CatmullRomCurve3(this.route);
  74526. curve.curveType = 'chordal'; //'centripetal' 'catmullrom'这个可能会超出路径外
  74527. this.curve = curve;
  74528. var scenePoints = curve.getSpacedPoints(count); //更平均
  74529. //const scenePoints = curve.getPoints( count );
  74530. scenePoints.splice(0, 1); //去掉首尾
  74531. scenePoints.pop();
  74532. this.scenePoints = scenePoints;
  74533. this.updateMapArrows();
  74534. this.displayRoute();
  74535. {
  74536. //map focus on this area
  74537. var minBound = new Vector2(1, 1); //针对垂直线,在地图上只有一个点
  74538. var bound = new Box2();
  74539. this.route.forEach(e => {
  74540. bound.expandByPoint(e);
  74541. });
  74542. var size = bound.getSize(new Vector2());
  74543. var markerSize = new Vector2(115, 40); //起始和终点的标识呈长方形
  74544. var areaSize = viewer.mapViewer.viewports[0].resolution2;
  74545. var areaArea = areaSize.x * areaSize.y;
  74546. if (areaArea > 800 * 400) {
  74547. //是放大的
  74548. markerSize.multiplyScalar(areaArea / (800 * 400) /* / (size.x * size.y) */);
  74549. }
  74550. var margin = size.clone().divide(viewer.mapViewer.viewports[0].resolution2).multiply(markerSize); ///边距 重点是起始和终点的标识占据较大
  74551. size.add(margin);
  74552. var center = bound.getCenter(new Vector2());
  74553. size.x = Math.max(size.x, minBound.x);
  74554. size.y = Math.max(size.y, minBound.y);
  74555. var duration = 1000;
  74556. viewer.mapViewer.moveTo(center, size, duration);
  74557. }
  74558. this.bus.emit('gotResult', {
  74559. dis: this.routeLength
  74560. });
  74561. /* this.generateDeferred && this.generateDeferred.resolve({dis:this.routeLength})
  74562. this.generateDeferred = null */
  74563. };
  74564. if (Potree.fileServer) {
  74565. var dealData = data => {
  74566. if (!data.data) {
  74567. console.log('没有数据');
  74568. var result;
  74569. if (data && data.code == 4002) {
  74570. result = data; //正被修改数据集
  74571. } else if (this.routeStart.distanceTo(this.routeEnd) < 1) {
  74572. result = {
  74573. code: 500,
  74574. msg: '距离太短,无法规划路线'
  74575. };
  74576. } else {
  74577. result = {
  74578. code: 500,
  74579. msg: '超出数据集范围,无法规划路线'
  74580. };
  74581. }
  74582. this.clearRoute();
  74583. this.setStartPole(this.routeStart);
  74584. this.setEndPole(this.routeEnd);
  74585. this.displayRoute(); //还是要显示一下起始
  74586. this.bus && this.bus.emit('gotResult', result);
  74587. return; //this.generateDeferred && this.generateDeferred.resolve()
  74588. }
  74589. data = data.data;
  74590. this.clearRoute();
  74591. var length = data.length;
  74592. if (length < 2) {
  74593. //可能距离太短
  74594. console.log('路径点数为' + length + ',直接取起点和终点连线');
  74595. this.route = [this.routeStart, this.routeEnd];
  74596. } else {
  74597. var startIndex = this.getSourceProjectionIndex(data);
  74598. var endIndex = this.getDestinationProjectionIndex(data);
  74599. var effectiveItems = data.slice(startIndex, endIndex + 1); //只要点云范围内的点
  74600. effectiveItems.forEach((item, i) => {
  74601. //let pos = viewer.transform.lonlatToLocal.forward(item.location.slice(0)/* ,true */)
  74602. var pos = item.location.slice(0);
  74603. pos = new Vector3().fromArray(pos); //.setZ(item.z)
  74604. pos.z -= initialPointcloud.datasetData.location[2];
  74605. this.route.push(pos);
  74606. });
  74607. //console.log('route', this.route)
  74608. }
  74609. this.setStartPole(this.route[0]);
  74610. this.setEndPole(this.route[this.route.length - 1]);
  74611. create();
  74612. /*
  74613. distance: 0.17581000000000116
  74614. distance_to_previous: 0.17581000000000116
  74615. id: 567
  74616. instruction: {type: 'source_projection_to_navgraph'}
  74617. latitude: 22.366605927999238
  74618. location: (3) [113.5957510575092, 22.366605927999238, -1.12419]
  74619. longitude: 113.5957510575092
  74620. z: -1.12419
  74621. */
  74622. };
  74623. if (this.lastResult && (this.lastResult.data || this.lastResult.data.code != 4002)) {
  74624. //正被修改数据集的话要重新计算
  74625. var data = Common.CloneObject(this.lastResult.data),
  74626. use; //直接用上次的结果
  74627. if (this.lastResult.routeStart.equals(this.routeStart) && this.lastResult.routeEnd.equals(this.routeEnd)) {
  74628. //和上次请求相同
  74629. use = true;
  74630. } else if (this.lastResult.routeStart.equals(this.routeEnd) && this.lastResult.routeEnd.equals(this.routeStart)) {
  74631. //..反向
  74632. use = true;
  74633. if (data.data) {
  74634. data.data = this.lastResult.data.data.slice(0).reverse();
  74635. }
  74636. }
  74637. if (use) {
  74638. console.log('直接用上次的结果');
  74639. return setTimeout(() => {
  74640. dealData(data);
  74641. }, 1); //延迟是为了等待获得 RouteGuider.generateDeferred
  74642. }
  74643. }
  74644. var start = this.routeStart.clone();
  74645. var end = this.routeEnd.clone();
  74646. //let startLonlat = viewer.transform.lonlatToLocal.inverse(start/* , true */)
  74647. //let endLonlat = viewer.transform.lonlatToLocal.inverse(end/* , true */)
  74648. /* var query = {
  74649. source_longitude: start.x,
  74650. source_latitude: start.y,
  74651. source_z: start.z,
  74652. destination_longitude: end.x,
  74653. destination_latitude: end.y,
  74654. destination_z: end.z
  74655. }; */
  74656. var query = {
  74657. source_longitude: start.x,
  74658. source_latitude: start.y,
  74659. source_z: start.z + initialPointcloud.datasetData.location[2],
  74660. destination_longitude: end.x,
  74661. destination_latitude: end.y,
  74662. destination_z: end.z + initialPointcloud.datasetData.location[2]
  74663. };
  74664. /* var query = {
  74665. source_longitude: startLonlat.x,
  74666. source_latitude: startLonlat.y,
  74667. source_z: start.z,
  74668. destination_longitude: endLonlat.x,
  74669. destination_latitude: endLonlat.y,
  74670. destination_z: end.z
  74671. }; */
  74672. //let url = `/laser/route/${Potree.settings.number}/getRoute/${this.datasetIds[0]}/${this.datasetIds[1]}?`
  74673. var url = "/laser/route/".concat(Potree.settings.number, "/getRoute/").concat(Potree.settings.originDatasetId, "?");
  74674. for (var i in query) {
  74675. url += i + '=' + query[i] + '&';
  74676. }
  74677. Potree.fileServer.get(url).then(data => {
  74678. //console.log('data', data.data)
  74679. if (!this.routeStart || !this.routeEnd) return;
  74680. this.lastResult = {
  74681. //保存数据
  74682. routeStart: this.routeStart.clone(),
  74683. routeEnd: this.routeEnd.clone(),
  74684. data
  74685. };
  74686. dealData(data);
  74687. });
  74688. } else {
  74689. //创个直线
  74690. /* const sliceDis = 1
  74691. let dis = this.routeStart.distanceTo(this.routeEnd);
  74692. let count = Math.max(2,Math.round(dis / sliceDis))//点数
  74693. let realSlideDis = dis / (count-1);
  74694. let dir = new THREE.Vector3().subVectors(this.routeEnd, this.routeStart).normalize().multiplyScalar(realSlideDis);
  74695. this.route = [this.routeStart];
  74696. for(let i=0;i<count-1;i++){
  74697. let lastOne = this.route[i];
  74698. this.route.push(new THREE.Vector3().addVectors(lastOne,dir))
  74699. }
  74700. this.route.splice(0,1) //route不用包含收尾 */
  74701. this.clearRoute();
  74702. this.route = [this.routeStart, this.routeEnd];
  74703. create();
  74704. }
  74705. }
  74706. updateMapArrows(ifReset) {
  74707. if (this.route.length == 0) return;
  74708. var zoom = viewer.mapViewer.camera.zoom;
  74709. var isBig = viewer.mapViewer.viewports[0].resolution.y > 300;
  74710. var count = Math.max(2, Math.round(this.routeLength * zoom / arrowSpacing / (isBig ? 35 : 30))); //点数
  74711. if (count == this.mapPoints.length + 1) return; //没变
  74712. var mapPoints = this.curve.getSpacedPoints(count);
  74713. mapPoints.splice(0, 1); //去掉首尾
  74714. mapPoints.pop();
  74715. this.mapPoints = mapPoints;
  74716. var scale = (isBig ? 26 : 22) / zoom;
  74717. this.mapArrow.scale.set(scale, scale, scale);
  74718. /* this.mapMarkStart.scale.set(scale,scale,scale)
  74719. this.mapMarkEnd.scale.set(scale,scale,scale) */
  74720. if (ifReset) {
  74721. //因为缩放而重新排布箭头
  74722. this.clearRoute({
  74723. resetMap: true
  74724. });
  74725. this.displayRoute({
  74726. resetMap: true
  74727. });
  74728. }
  74729. this.updateOpacityAtMap();
  74730. }
  74731. updateArrowDisplay() {
  74732. //根据当前位置更新显示一定范围内的箭头
  74733. if (this.scenePoints.length == 0) return;
  74734. /* var a = Common.sortByScore(this.scenePoints , null, [(point)=>{ //是否还要再requires里限制最远距离?
  74735. var playerPos = viewer.scene.getActiveCamera().position.clone().setZ(0)
  74736. var pos = point.clone().setZ(0)
  74737. return -pos.distanceTo(playerPos);
  74738. }]);
  74739. //获得展示的起始点
  74740. let start = a[0].item
  74741. let startIndex = this.scenePoints.indexOf(start)
  74742. this.arrows.children.forEach((e,i)=>{
  74743. if(i<startIndex || i>startIndex+arrowsShowingCount)e.visible = false
  74744. else e.visible = true
  74745. }) */
  74746. var cameraPos = viewer.scene.getActiveCamera().position;
  74747. this.arrows.children.forEach((e, i) => {
  74748. if (e.position.distanceTo(cameraPos) < arrowShowMinDis) e.visible = true;else e.visible = false;
  74749. });
  74750. viewer.dispatchEvent('content_changed');
  74751. }
  74752. displayRoute() {
  74753. var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  74754. if (!o.resetMap) {
  74755. this.poleStart.position.copy(this.startPolePos || this.routeStart);
  74756. this.poleEnd.position.copy(this.endPolePos || this.routeEnd);
  74757. /* this.mapMarkStart.position.copy(this.routeStart).setZ(0)
  74758. this.mapMarkEnd.position.copy(this.routeEnd).setZ(0) */
  74759. this.scenePoints.forEach(e => this.addArrow(e));
  74760. this.arrows.children.forEach((e, i) => this.setArrowDir(this.arrows.children, i));
  74761. }
  74762. this.sceneMeshGroup.visible = true; //.traverse(e=>e.visible = true)
  74763. this.mapMeshGroup.visible = true;
  74764. this.mapPoints.forEach(e => this.addMapArrow(e));
  74765. this.mapArrows.children.forEach((e, i) => this.setArrowDir(this.mapArrows.children, i));
  74766. viewer.mapViewer.dispatchEvent({
  74767. 'type': 'content_changed'
  74768. });
  74769. this.updateArrowDisplay();
  74770. }
  74771. clearRoute() {
  74772. var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  74773. if (!o.resetMap) {
  74774. this.routeLength = 0;
  74775. this.route = [];
  74776. this.scenePoints = [];
  74777. this.mapPoints = [];
  74778. var arrows = this.arrows.children.slice(0);
  74779. arrows.forEach(e => {
  74780. this.arrows.remove(e);
  74781. });
  74782. }
  74783. var mapArrows = this.mapArrows.children.slice(0);
  74784. mapArrows.forEach(e => {
  74785. this.mapArrows.remove(e);
  74786. });
  74787. this.sceneMeshGroup.visible = false;
  74788. //this.sceneMeshGroup.traverse(e=>e.visible = false) //包括sprite也要设置,防止update
  74789. this.mapMeshGroup.visible = false;
  74790. viewer.mapViewer.dispatchEvent({
  74791. 'type': 'content_changed'
  74792. });
  74793. viewer.dispatchEvent('content_changed');
  74794. }
  74795. clear() {
  74796. //退出
  74797. console.log('导航clear');
  74798. this.routeStart = null;
  74799. this.routeEnd = null;
  74800. this.clearRoute();
  74801. }
  74802. }
  74803. //大概每十米要花一秒
  74804. /*
  74805. 存在的问题:
  74806. 路径不准确。起始点和终点偏移。
  74807. https://uat-laser.4dkankan.com/routeDebug/ 可查整个map的通路点位图
  74808. */
  74809. //import History from "../../utils/History.js"
  74810. var cameraProps$1 = [{
  74811. name: 'top',
  74812. axis: ["x", "y"],
  74813. direction: new Vector3(0, 0, -1),
  74814. //镜头朝向
  74815. openCount: 0
  74816. }];
  74817. class Clipping extends EventDispatcher {
  74818. //实时剪裁
  74819. constructor() {
  74820. super();
  74821. this.views = {};
  74822. this.cameras = {};
  74823. this.orthoCamera = new OrthographicCamera(-100, 100, 100, 100, 0.01, 10000);
  74824. this.orthoCamera.up.set(0, 0, 1);
  74825. }
  74826. init() {
  74827. if (this.inited) return;
  74828. this.initViews();
  74829. this.inited = true;
  74830. this.prepareRecord = true;
  74831. this.activeViewName = 'mainView';
  74832. this.events = {
  74833. transfromCallback: e => {
  74834. //拖拽变化时
  74835. this.adjustCamHeight();
  74836. //检测漫游点、回退等
  74837. /* if(this.prepareRecord){
  74838. let box = viewer.transformationTool.selection[0]
  74839. this.history.writeIn({box, matrix:box.matrix.clone()})
  74840. this.prepareRecord = false
  74841. } */
  74842. },
  74843. /* onTransfromEnd:(e)=>{//拖拽结束、松开
  74844. this.prepareRecord = true
  74845. }, */
  74846. selectCallback: e => {
  74847. this.adjustCamHeight();
  74848. var unableNavigate = this.activeViewName != 'mainView' || e.selection.length > 0;
  74849. if (Potree.settings.unableNavigate && !unableNavigate) {
  74850. setTimeout(() => {
  74851. Potree.settings.unableNavigate = this.activeViewName != 'mainView' || e.selection.length > 0;
  74852. }, 300); //延迟是因为点击时取消选择后可能立即就会触发flyToPano。 而且有的人喜欢点两下
  74853. } else Potree.settings.unableNavigate = unableNavigate;
  74854. },
  74855. onkeydown: e => {
  74856. if (e.keyCode == 8 || e.keyCode == 46) {
  74857. // Backspace or Delete
  74858. viewer.inputHandler.selection[0] && viewer.scene.removeVolume(viewer.inputHandler.selection[0]);
  74859. }
  74860. }
  74861. };
  74862. /* this.history = new History({ //也可以写到全局,但需要加个判断物品是否存在的函数
  74863. applyData: (data)=>{
  74864. if(viewer.scene.volumes.includes(data.box)){
  74865. data.matrix.decompose( data.box.position, data.box.quaternion, data.box.scale );
  74866. }else{
  74867. this.history.undo()//找不到就回退下一个。(直接写这?)
  74868. }
  74869. }
  74870. }) */
  74871. }
  74872. initViews() {
  74873. this.splitScreenTool = new SplitScreen();
  74874. for (var i = 0; i < 1; i++) {
  74875. var prop = cameraProps$1[i];
  74876. var view = new ExtendView();
  74877. this.views[prop.name] = view;
  74878. this.cameras[prop.name] = this.orthoCamera;
  74879. view.direction = prop.direction;
  74880. }
  74881. this.views.mainView = viewer.mainViewport.view;
  74882. this.cameras.mainView = viewer.mainViewport.camera;
  74883. }
  74884. switchView(name) {
  74885. //替换view和camera到mainViewport
  74886. if (this.activeViewName == name) return;
  74887. var view = this.views[name];
  74888. var camera = this.cameras[name];
  74889. var prop = cameraProps$1.find(e => e.name == name);
  74890. var {
  74891. boundSize,
  74892. center,
  74893. boundingBox
  74894. } = viewer.bound;
  74895. this.lastViewName = this.activeViewName;
  74896. this.activeViewName = name;
  74897. var lastView = this.views[this.lastViewName];
  74898. var lastCamera = this.cameras[this.lastViewName];
  74899. viewer.mainViewport.view = view;
  74900. viewer.mainViewport.camera = camera;
  74901. if (lastCamera) lastView.zoom = lastCamera.zoom;
  74902. /* if(lastView){//2d->3d
  74903. view.copy(lastView)
  74904. } */
  74905. if (name == 'mainView') {
  74906. Potree.settings.unableNavigate = false;
  74907. /* viewer.transformationTool.handles['scale.z+'].node.visible = true
  74908. viewer.transformationTool.handles['scale.z-'].node.visible = true */
  74909. } else {
  74910. Potree.settings.unableNavigate = true;
  74911. /* viewer.transformationTool.handles['scale.z+'].node.visible = false
  74912. viewer.transformationTool.handles['scale.z-'].node.visible = false */
  74913. if (prop.openCount == 0) {
  74914. //至多执行一次
  74915. //this.viewportFitBound(name, boundSize, center)
  74916. this.orthoMoveFit(center, {
  74917. bound: boundingBox
  74918. }, 0);
  74919. this.camHeightOutOfModel = view.position.z; //记录下此刻相机高度。
  74920. }
  74921. prop.openCount++;
  74922. this.adjustCamHeight();
  74923. /* this.targetPlane.setFromNormalAndCoplanarPoint( view.direction.clone(), center )
  74924. this.targetPlane.projectPoint(view.position, this.shiftTarget ) //target转换到过模型中心的平面,以保证镜头一定在模型外
  74925. view.position.copy(this.splitScreenTool.getPosOutOfModel(viewer.mainViewport)) */
  74926. if (view.zoom) camera.zoom = view.zoom; //恢复上次的zoom
  74927. }
  74928. viewer.updateScreenSize({
  74929. forceUpdateSize: true
  74930. }); //更新camera aspect left等
  74931. if (viewer.inputHandler.selection.length) {
  74932. this.focusOnObject(viewer.inputHandler.selection[0]);
  74933. }
  74934. }
  74935. focusOnObject(box) {
  74936. var duration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  74937. if (this.activeViewName == 'mainView') {
  74938. viewer.focusOnObject({
  74939. boundingBox: box.boundingBox.clone().applyMatrix4(box.matrixWorld)
  74940. }, 'boundingBox', duration);
  74941. } else {
  74942. this.orthoMoveFit(box.position, {
  74943. bound: box.boundingBox.clone().applyMatrix4(box.matrixWorld)
  74944. }, duration);
  74945. }
  74946. this.adjustCamHeight();
  74947. }
  74948. orthoMoveFit(pos, info, duration) {
  74949. var margin = {
  74950. x: viewer.mainViewport.resolution.x * 0.4,
  74951. y: viewer.mainViewport.resolution.y * 0.4
  74952. };
  74953. this.splitScreenTool.viewportFitBound(viewer.mainViewport, info.bound, pos, duration, margin);
  74954. }
  74955. adjustCamHeight() {
  74956. if (this.activeViewName != 'top') return;
  74957. var view = this.views.top;
  74958. var height;
  74959. if (viewer.inputHandler.selection.length) {
  74960. //相机高度位于选中的box的顶部
  74961. var box = viewer.inputHandler.selection[0];
  74962. height = box.boundingBox.clone().applyMatrix4(box.matrixWorld).max.z;
  74963. } else {
  74964. height = this.camHeightOutOfModel; //显示全部点云
  74965. }
  74966. view.position.z = height;
  74967. //console.log('adjustCamHeight',height)
  74968. //缺点:1 会导致缩放很小的时候,transformationTool的轴因放大到了相机背面。(只有scale轴做了处理)
  74969. //2 无法直接切换 看不到的box,但可以先取消选择
  74970. //3 但是俯视图中无法切换到被上层盖住的box(不过把俯视图作为辅助,只针对单个box调动的话,问题不大)
  74971. }
  74972. enter() {
  74973. this.init();
  74974. viewer.transformationTool.setModeEnable(['translation']);
  74975. //viewer.transformationTool.handles['rotation.x'].node.visible = false
  74976. viewer.transformationTool.frame.material.visible = false; //不盖住boxVolume的frame
  74977. this.targetPlane = viewer.mainViewport.targetPlane = new Plane();
  74978. this.shiftTarget = viewer.mainViewport.shiftTarget = new Vector3(); //project在targetPlane上的位置
  74979. this.getAllBoxes().forEach(box => {
  74980. Potree.Utils.updateVisible(box, 'hidden', true); //显现
  74981. });
  74982. viewer.transformationTool.history.clear();
  74983. viewer.transformationTool.addEventListener('transformed', this.events.transfromCallback);
  74984. //viewer.transformationTool.addEventListener('stopDrag', this.events.onTransfromEnd)
  74985. viewer.inputHandler.addEventListener('selection_changed', this.events.selectCallback);
  74986. viewer.inputHandler.addEventListener('keydown', this.events.onkeydown);
  74987. this.setPointLevelAuto();
  74988. var initialPointcloud = viewer.scene.pointclouds.find(p => p.dataset_id == Potree.settings.originDatasetId);
  74989. //隐藏 初始数据集以外的数据集
  74990. viewer.scene.pointclouds.forEach(e => {
  74991. if (e.dataset_id != Potree.settings.originDatasetId) {
  74992. Potree.Utils.updateVisible(e, 'enterClipping', false);
  74993. //Potree.settings.floorplanEnables[e.dataset_id] = false
  74994. e.panos.forEach(pano => pano.setEnable(false)); //禁止漫游
  74995. } else {
  74996. Potree.Utils.updateVisible(e, 'enterClipping', true, 1, 'add');
  74997. //Potree.settings.floorplanEnables[e.dataset_id] = true
  74998. }
  74999. });
  75000. viewer.flyToDataset({
  75001. pointcloud: initialPointcloud,
  75002. duration: 0
  75003. });
  75004. }
  75005. enter2() {
  75006. //在土方量界面的
  75007. viewer.transformationTool.setModeEnable(['translation']);
  75008. viewer.transformationTool.frame.material.visible = false; //不盖住boxVolume的frame
  75009. viewer.transformationTool.history.clear();
  75010. //viewer.inputHandler.addEventListener('keydown', this.events.onkeydown)
  75011. }
  75012. leave() {
  75013. viewer.transformationTool.setModeEnable(['scale', 'translation', 'rotation']);
  75014. viewer.transformationTool.frame.material.visible = true; //恢复
  75015. this.switchView('mainView');
  75016. this.getAllBoxes().forEach(box => {
  75017. Potree.Utils.updateVisible(box, 'hidden', false); //隐身
  75018. });
  75019. viewer.transformationTool.removeEventListener('transformed', this.events.transfromCallback);
  75020. //viewer.transformationTool.removeEventListener('stopDrag', this.events.onTransfromEnd)
  75021. viewer.inputHandler.removeEventListener('selection_changed', this.events.selectCallback);
  75022. //viewer.inputHandler.removeEventListener('keydown', this.events.onkeydown)
  75023. viewer.transformObject(null);
  75024. viewer.transformationTool.history.clear();
  75025. //恢复 初始数据集以外的数据集
  75026. viewer.scene.pointclouds.forEach(e => {
  75027. if (e.dataset_id != Potree.settings.originDatasetId) {
  75028. Potree.Utils.updateVisible(e, 'enterClipping', true);
  75029. e.panos.forEach(pano => pano.setEnable(true));
  75030. } else {
  75031. Potree.Utils.updateVisible(e, 'enterClipping', false, 0, 'cancel');
  75032. }
  75033. });
  75034. }
  75035. setTranMode(mode) {
  75036. //rotate or translate
  75037. this.tranMode = mode;
  75038. viewer.transformationTool.setModeEnable([mode]);
  75039. viewer.dispatchEvent('content_changed');
  75040. }
  75041. //问:是否要显示其他数据集
  75042. setPointLevelAuto() {
  75043. /*
  75044. let visiCount = viewer.images360.panos.length
  75045. let maxCount = 200, minCount = 20, minPer = 0.7, maxPer = 1
  75046. let percent = maxPer - ( maxPer - minPer) * THREE.Math.clamp((visiCount - minCount) / (maxCount - minCount),0,1)
  75047. Potree.settings.UserDensityPercent = percent ---还是不限制了,尤其是平面图希望更细致点,毕竟剪裁主要要看清剪裁的部位。
  75048. */
  75049. viewer.setPointBudget(5 * 1000 * 1000); //给个中等到高等之间的质量
  75050. Potree.settings.sizeFitToLevel = true;
  75051. viewer.setPointLevels();
  75052. }
  75053. getAllBoxes() {
  75054. return viewer.scene.volumes.filter(v => v.clip && v instanceof Potree.BoxVolume);
  75055. }
  75056. getCalcData() {
  75057. //给后台矩阵数据,以裁剪点云。
  75058. var Clip = viewer.modules.Clip; //裁剪下载模块
  75059. var data = {
  75060. transformation_matrix: viewer.scene.pointclouds.filter(p => p.dataset_id == Potree.settings.originDatasetId).map(cloud => {
  75061. var data = {
  75062. id: cloud.dataset_id,
  75063. matrix: new Matrix4().elements,
  75064. //参照downloadNoCrop,给默认值,表示没有最外层裁剪
  75065. visiMatrixes: cloud.material.clipBoxes_in.filter(e => !e.box.isNew).map(e => Clip.getTransformationMatrix(cloud, e.inverse).elements),
  75066. unVisiMatrixes: cloud.material.clipBoxes_out.filter(e => !e.box.isNew).map(e => Clip.getTransformationMatrix(cloud, e.inverse).elements),
  75067. modelMatrix: new Matrix4().elements //(new THREE.Matrix4).copy(cloud.transformMatrix).transpose().elements //需要保证没有位移,否则剪裁后的模型位置会变化
  75068. };
  75069. return data;
  75070. }),
  75071. aabb: "b-12742000 -12742000 -12742000 12742000 12742000 12742000" //剪裁空间
  75072. };
  75073. return data;
  75074. }
  75075. saveClipData(boxes) {
  75076. //输出所有的clip volumeBox
  75077. var oldState = !viewer.clipUnabled;
  75078. //viewer.setClipState(true)
  75079. var data = (boxes || this.getAllBoxes()).filter(e => !e.isNew).map(volume => {
  75080. return {
  75081. clipTask: volume.clipTask,
  75082. position: Potree.Utils.datasetPosTransform({
  75083. position: volume.position,
  75084. toDataset: true,
  75085. datasetId: Potree.settings.originDatasetId
  75086. }).toArray(),
  75087. rotation: Potree.Utils.datasetRotTransform({
  75088. rotation: volume.rotation,
  75089. toDataset: true,
  75090. datasetId: Potree.settings.originDatasetId,
  75091. getRotation: true
  75092. }).toArray().slice(0, 3),
  75093. scale: volume.scale.toArray()
  75094. };
  75095. });
  75096. //console.log(data)
  75097. //console.log(JSON.stringify(data))
  75098. //viewer.setClipState(oldState)
  75099. return data;
  75100. }
  75101. loadFromData() {
  75102. var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  75103. data.forEach(v => {
  75104. var volume = new Potree.BoxVolume({
  75105. clip: true,
  75106. clipTask: v.clipTask
  75107. });
  75108. volume.scale.fromArray(v.scale);
  75109. volume.position.fromArray(v.position);
  75110. volume.rotation.fromArray(v.rotation);
  75111. volume.position.copy(Potree.Utils.datasetPosTransform({
  75112. position: volume.position,
  75113. fromDataset: true,
  75114. datasetId: Potree.settings.originDatasetId
  75115. }));
  75116. volume.rotation.copy(Potree.Utils.datasetRotTransform({
  75117. rotation: volume.rotation,
  75118. fromDataset: true,
  75119. datasetId: Potree.settings.originDatasetId,
  75120. getRotation: true
  75121. }));
  75122. viewer.scene.addVolume(volume);
  75123. viewer.volumeTool.scene.add(volume);
  75124. });
  75125. }
  75126. }
  75127. //注意:实时裁剪只对初始数据集有效,其他数据集已经隐藏
  75128. /*
  75129. 备注:
  75130. 2023
  75131. 发送给后台数据样例:
  75132. {"transformation_matrix":[{"id":"1626189981883699200","matrix":[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],"visiMatrixes":[],"unVisiMatrixes":[[0.18610746638254325,-0.0005022517888587003,0,-0.01638495865566026,0.0002721420073982042,0.10084117292688818,0,0.25897037181878035,0,0,0.17066427841288187,-0.1913158687770112,0,0,0,1]],"modelMatrix":[0.999996358477288,-0.0026987093514294095,0,3.275872500136923e-8,0.0026987093514294095,0.999996358477288,0,-4.2486927309681385e-9,0,0,1,0,0,0,0,1]}],"aabb":"b-12742000 -12742000 -12742000 12742000 12742000 12742000"}
  75133. 发送给算法部的数据样例:
  75134. {
  75135. "model": [
  75136. {
  75137. "cut_transformation": "1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0",
  75138. "file": "/mnt/data/pvt000004/1079784714115481600/pvt000004_202302271512444930_laserData/laserData/laser.las",
  75139. "visiMatrixes": [[..],[..]],
  75140. "dataSetId": "1630105213031026688",
  75141. "sceneCode": "SS-t-MVQ1Jb80oMG",
  75142. "modelMatrix": "-0.9338946595415051 -0.35754826930060274 0.0 -3.483651134875185E-8 0.35754826930060274 -0.9338946595415051 0.0 5.664923641290965E-9 0.0 0.0 0.9999999999999999 0.0 0.0 0.0 0.0 1.0",
  75143. "unVisiMatrixes": [[..],[..]]
  75144. }
  75145. ],
  75146. "aabb": "b-12742000 -12742000 -12742000 12742000 12742000 12742000"
  75147. }
  75148. */
  75149. var vertexShader = "\n attribute float randam;\n attribute float sprite;\n attribute float centerHeight; //add\n \n //uniform float fireHeight; //add \n uniform float time;\n uniform float size;\n uniform float heightOfNearPlane;\n \n \n \n \n //varying float heightRatio;\n varying float vSprite;\n varying float vOpacity; \n float PI = 3.14;\n\n float quadraticIn( float t ) \n { \n float tt = t * t;\n return tt * tt; \n //\u53D8\u5316\u66F2\u7EBF \u8D8A\u6765\u8D8A\u5FEB\n } \n \n void main() {\n float progress = fract( time + ( 2.0 * randam - 1.0 ) );\n float progressNeg = 1.0 - progress;\n float ease = quadraticIn( progress );\n float influence = sin( PI * ease );\n //vec3 newPosition = position * vec3( 1.0, 1.0 , ease);\n vec3 newPosition = position;\n newPosition.z = (newPosition.z - centerHeight) * ease + centerHeight;\n \n gl_Position = projectionMatrix * modelViewMatrix * vec4( newPosition, 1.0 );\n gl_PointSize = ( heightOfNearPlane * size ) / gl_Position.w;\n vOpacity = min( influence * 4.0, 1.0 ) * progressNeg;\n vSprite = sprite;\n \n //heightRatio = (newPosition.z - centerHeight) / fireHeight ;\n \n }\n";
  75150. var fragmentShader = "\n uniform vec3 color;\n uniform sampler2D u_sampler;\n\n varying float vSprite;\n varying float vOpacity;\n //varying float heightRatio;\n\n void main() \n {\n \n \n vec2 texCoord = vec2(gl_PointCoord.x * 0.25 + vSprite, gl_PointCoord.y);\n \n gl_FragColor = vec4( texture2D( u_sampler, texCoord ).xyz * color * vOpacity, 1.0 );\n \n \n }\n";
  75151. // import { vertexShader, fragmentShader } from './shaders'
  75152. var ONE_SPRITE_ROW_LENGTH = 0.25; //对应着色器的0.25
  75153. var texture;
  75154. var getTexture = () => {
  75155. if (!texture) {
  75156. texture = new TextureLoader().load(Potree.resourcePath + '/textures/fire.png');
  75157. }
  75158. return texture;
  75159. };
  75160. var boxGeo = new BoxBufferGeometry(1, 1, 1, 1);
  75161. var boxMat = new MeshBasicMaterial({
  75162. wireframe: true,
  75163. color: "#ffffff"
  75164. });
  75165. class FireParticle extends Points {
  75166. constructor(prop) {
  75167. super();
  75168. for (var key in prop) {
  75169. this[key] = prop[key];
  75170. }
  75171. this.strength = this.strength || 1;
  75172. this.radius = prop.radius || 1;
  75173. this.height = prop.height || 5;
  75174. this.computeParams();
  75175. this.geometry = this.createGeometry(this.radius, this.height, this.particleCount);
  75176. if (this.color == void 0) this.color = 0xff3200;
  75177. this.createMaterial(); //小蓝火:0x00338f
  75178. //---?:
  75179. this.velocity = new Vector3();
  75180. this.acceleration = new Vector3();
  75181. this.angle = 0;
  75182. this.angleVelocity = 0;
  75183. this.angleAcceleration = 0;
  75184. this.size = 16;
  75185. this.opacity = 1;
  75186. this.age = 0;
  75187. this.alive = 0;
  75188. this.sizeTween = null;
  75189. this.colorTween = null;
  75190. this.opacityTween = null;
  75191. this.setSize({
  75192. viewport: viewer.mainViewport
  75193. });
  75194. this.setFov(viewer.fov);
  75195. var setSize = e => {
  75196. if (e.viewport.name != "MainView") return;
  75197. this.setSize(e);
  75198. };
  75199. var setFov = e => {
  75200. this.setFov(e.fov);
  75201. };
  75202. viewer.addEventListener('resize', setSize);
  75203. viewer.addEventListener('fov_changed', setFov);
  75204. this.addEventListener('dispose', () => {
  75205. viewer.removeEventListener('resize', setSize);
  75206. viewer.removeEventListener('fov_changed', setFov);
  75207. });
  75208. }
  75209. computeParams() {
  75210. var length = (this.curve ? this.curve.wholeLength : 0) + this.radius * 2; //加上首尾的半径
  75211. var minSize = 0.3,
  75212. maxSize = 3,
  75213. minRadiusBound = 0.3,
  75214. maxRadiusBound = 10;
  75215. this.size = minSize + (maxSize - minSize) * MathUtils.smoothstep(this.radius, minRadiusBound, maxRadiusBound);
  75216. //console.log('fire material particle size:', size )
  75217. this.particleCount = Math.ceil(length * Math.sqrt(this.strength * this.height) * this.radius / (this.size * this.size) * 25);
  75218. //console.log('fire particleCount',this.particleCount)
  75219. }
  75220. getPointsForBound() {
  75221. return this.boundPoints; //可以用于expand实时bound的点, 不含particle的size等边距
  75222. }
  75223. getBound(points) {
  75224. // points为生成点(圆心)
  75225. this.boundPoints = [];
  75226. var boundingBox = new Box3();
  75227. var margin = this.size * 0.13 + 0.3;
  75228. points.forEach(bottom => {
  75229. var top = bottom.clone();
  75230. top.z += this.height;
  75231. boundingBox.expandByPoint(bottom);
  75232. boundingBox.expandByPoint(top);
  75233. this.boundPoints.push(bottom, top);
  75234. });
  75235. var xyExpand = this.radius + margin;
  75236. boundingBox.expandByVector(new Vector3(xyExpand, xyExpand, margin));
  75237. this.boundingBox = boundingBox;
  75238. /* if(!this.debugBox){
  75239. this.debugBox = new THREE.Mesh(boxGeo, boxMat)
  75240. this.add(this.debugBox)
  75241. }
  75242. this.debugBox.scale.copy(boundingBox.getSize(new THREE.Vector3))
  75243. this.debugBox.position.copy(boundingBox.getCenter(new THREE.Vector3)) */
  75244. }
  75245. createGeometry(radius, height, particleCount) {
  75246. var geometry = new BufferGeometry();
  75247. var count, points;
  75248. if (this.positions.length > 1) {
  75249. var spaceDis = 0.2; //间隔距离
  75250. count = Math.ceil(this.curve.wholeLength / spaceDis) + 1;
  75251. //console.log('count', count)
  75252. points = this.curve.getSpacedPoints(count); //得到的数量会比count多一个
  75253. count = points.length;
  75254. //得到的点不太均匀,两端容易点少。
  75255. this.getBound(points);
  75256. } else {
  75257. this.getBound(this.positions);
  75258. }
  75259. var position = new Float32Array(particleCount * 3);
  75260. var randam = new Float32Array(particleCount);
  75261. var sprite = new Float32Array(particleCount);
  75262. var centerHeight = new Float32Array(particleCount);
  75263. for (var i = 0; i < particleCount; i++) {
  75264. var center = new Vector3().copy(this.positions.length > 1 ? points[Math.floor(i / particleCount * count)] : this.positions[0]);
  75265. centerHeight[i] = center.z;
  75266. if (i === 0) {
  75267. // to avoid going out of Frustum
  75268. position[i * 3 + 0] = center.x;
  75269. position[i * 3 + 1] = center.y;
  75270. position[i * 3 + 2] = center.z;
  75271. } else {
  75272. var r = Math.sqrt(Math.random()) * radius;
  75273. var angle = Math.random() * 2 * Math.PI;
  75274. position[i * 3 + 0] = center.x + Math.cos(angle) * r;
  75275. position[i * 3 + 1] = center.y + Math.sin(angle) * r;
  75276. position[i * 3 + 2] = center.z + (radius - r) / radius * height / 2 + height / 2; //不太明白这句为什么能达到height高度
  75277. sprite[i] = 0.25 * (Math.random() * 4 | 0);
  75278. randam[i] = Math.random();
  75279. //center在底部
  75280. }
  75281. }
  75282. geometry.setAttribute('centerHeight', new BufferAttribute(centerHeight, 1));
  75283. geometry.setAttribute('position', new BufferAttribute(position, 3));
  75284. geometry.setAttribute('randam', new BufferAttribute(randam, 1));
  75285. geometry.setAttribute('sprite', new BufferAttribute(sprite, 1));
  75286. return geometry;
  75287. }
  75288. updateGeometry() {
  75289. this.computeParams();
  75290. this.geometry.dispose();
  75291. this.geometry = this.createGeometry(this.radius, this.height, this.particleCount);
  75292. this.material.uniforms.size.value = this.size;
  75293. }
  75294. createMaterial() {
  75295. var material = new ShaderMaterial({
  75296. uniforms: {
  75297. color: {
  75298. type: "c",
  75299. value: new Color(this.color)
  75300. },
  75301. size: {
  75302. type: "f",
  75303. value: this.size
  75304. },
  75305. u_sampler: {
  75306. type: "t",
  75307. value: getTexture()
  75308. },
  75309. time: {
  75310. type: "f",
  75311. value: 0.0
  75312. },
  75313. heightOfNearPlane: {
  75314. type: "f",
  75315. value: 0
  75316. },
  75317. //相对far ,以确保画面缩放时点的大小也会缩放
  75318. height: {
  75319. type: "f",
  75320. value: this.height
  75321. }
  75322. },
  75323. vertexShader,
  75324. fragmentShader,
  75325. blending: AdditiveBlending,
  75326. //加法融合模式 glBlendFunc(GL_ONE, GL_ONE)
  75327. depthTest: true,
  75328. depthWrite: false,
  75329. transparent: true
  75330. });
  75331. this.material = material;
  75332. this.setPerspective(this.fov, this.screenHeight);
  75333. }
  75334. setSize(e) {
  75335. var viewport = e.viewport;
  75336. this.screenHeight = viewport.resolution.y;
  75337. this.setPerspective(this.fov, this.screenHeight);
  75338. }
  75339. setFov(fov) {
  75340. this.fov = fov;
  75341. this.setPerspective(this.fov, this.screenHeight);
  75342. }
  75343. setPerspective(fov, height) {
  75344. //this.uniforms.heightOfNearPlane.value = Math.abs(height / (2 * Math.tan(THREE.Math.degToRad(fov * 0.5))));
  75345. var far = Math.abs(height / (2 * Math.tan(MathUtils.degToRad(fov * 0.5))));
  75346. this.material.uniforms.heightOfNearPlane.value = far;
  75347. }
  75348. update(delta) {
  75349. if (!Potree.Utils.getObjVisiByReason(this, 'force')) {
  75350. //被手动隐藏了
  75351. return;
  75352. }
  75353. if (!Potree.Utils.isInsideFrustum(this.boundingBox, viewer.scene.getActiveCamera())) {
  75354. Potree.Utils.updateVisible(this, 'isInsideFrustum', false); //不在视野范围
  75355. //console.log('unvi')
  75356. return;
  75357. } else {
  75358. Potree.Utils.updateVisible(this, 'isInsideFrustum', true);
  75359. }
  75360. delta *= 1; //更改速度
  75361. this.material.uniforms.time.value = (this.material.uniforms.time.value + delta) % 1;
  75362. viewer.dispatchEvent('content_changed');
  75363. }
  75364. dispose() {
  75365. this.geometry.dispose();
  75366. this.material.dispose();
  75367. this.dispatchEvent('dispose');
  75368. }
  75369. }
  75370. class Tween {
  75371. constructor(times, values) {
  75372. this.times = times || [];
  75373. this.values = values || [];
  75374. }
  75375. lerp(t) {
  75376. if (this.times.length == 0) return;
  75377. var i = 0,
  75378. n = this.times.length;
  75379. while (i < n && t > this.times[i]) i++;
  75380. if (i == 0) return this.values[0];
  75381. if (i == n) return this.values[n - 1];
  75382. var ratio = (t - this.times[i - 1]) / (this.times[i] - this.times[i - 1]);
  75383. if (this.values[0] instanceof Vector3) {
  75384. return this.values[i - 1].clone().lerp(this.values[i], ratio);
  75385. } else {
  75386. return this.values[i - 1] + ratio * (this.values[i] - this.values[i - 1]);
  75387. }
  75388. }
  75389. clone() {
  75390. return Common.CloneClassObject(this);
  75391. }
  75392. }
  75393. class Particle$1 {
  75394. constructor() {
  75395. var prop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  75396. this.position = new Vector3();
  75397. this.velocity = new Vector3(); // units per second
  75398. this.angle = 0;
  75399. this.angleVelocity = 0; // degrees per second
  75400. this.angleAcceleration = 0; // degrees per second, per second
  75401. this.size = 16.0;
  75402. this.color = new Color();
  75403. this.opacity = 1.0;
  75404. this.age = 0;
  75405. this.alive = 0; // use float instead of boolean for shader purposes
  75406. this.lastChangeVage = 0; //add
  75407. this.sizeTween = prop.sizeTween || new Tween([0, 1], [32, 128]);
  75408. this.opacityTween = prop.opacityTween || new Tween([0.8, 2], [0.5, 0]);
  75409. this.colorTween = prop.colorTween || new Tween([0.4, 1], [new Vector3(0, 0, 0.2), new Vector3(0, 0, 0.5)]);
  75410. }
  75411. update(dt) {
  75412. this.position.add(this.velocity.clone().multiplyScalar(dt));
  75413. this.velocity.multiplyScalar(1 + this.acceleration * dt);
  75414. // convert from degrees to radians: 0.01745329251 = Math.PI/180
  75415. this.angle += this.angleVelocity * 0.01745329251 * dt;
  75416. this.angleVelocity += this.angleAcceleration * 0.01745329251 * dt;
  75417. this.age += dt;
  75418. // if the tween for a given attribute is nonempty,
  75419. // then use it to update the attribute's value
  75420. if (this.sizeTween.times.length > 0) this.size = this.sizeTween.lerp(this.age / this.deathAge);
  75421. if (this.colorTween.times.length > 0) {
  75422. var colorHSL = this.colorTween.lerp(this.age / this.deathAge);
  75423. this.color = new Color().setHSL(colorHSL.x, colorHSL.y, colorHSL.z);
  75424. }
  75425. if (this.opacityTween.times.length > 0) {
  75426. this.opacity = this.opacityTween.lerp(this.age / this.deathAge);
  75427. }
  75428. viewer.dispatchEvent('content_changed');
  75429. }
  75430. }
  75431. var vertexShader$1 = "\n attribute vec3 customColor;\n attribute float customOpacity;\n attribute float customSize;\n attribute float customAngle;\n attribute float customVisible; \n uniform float heightOfNearPlane;\n \n \n varying vec4 vColor;\n varying float vAngle;\n void main()\n {\n if ( customVisible > 0.5 ) \t\t\t\t\n vColor = vec4( customColor, customOpacity ); \n else\t\t\t\t\t\t\t\n vColor = vec4(0.0, 0.0, 0.0, 0.0);\t\t\n \n vAngle = customAngle;\n\n vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\n //gl_PointSize = customSize * ( 300.0 / length( mvPosition.xyz ) ); \n gl_Position = projectionMatrix * mvPosition;\n gl_PointSize = ( heightOfNearPlane * customSize ) / gl_Position.w;\n \n \n }\n";
  75432. var fragmentShader$1 = "\n uniform sampler2D u_sampler;\n varying vec4 vColor;\t\n varying float vAngle; \n void main()\n {\n gl_FragColor = vColor;\n \n float c = cos(vAngle);\n float s = sin(vAngle);\n vec2 rotatedUV = vec2(c * (gl_PointCoord.x - 0.5) + s * (gl_PointCoord.y - 0.5) + 0.5, c * (gl_PointCoord.y - 0.5) - s * (gl_PointCoord.x - 0.5) + 0.5); \n vec4 rotatedTexture = texture2D( u_sampler, rotatedUV );\n gl_FragColor = gl_FragColor * rotatedTexture; \n }\n";
  75433. var Type$1 = Object.freeze({
  75434. "CUBE": 1,
  75435. "SPHERE": 2
  75436. });
  75437. var particleTexture;
  75438. var getTexture$1 = () => {
  75439. if (!particleTexture) {
  75440. particleTexture = new TextureLoader().load(Potree.resourcePath + '/textures/smokeparticle.png');
  75441. }
  75442. return particleTexture;
  75443. };
  75444. var boxGeo$1 = new BoxBufferGeometry(1, 1, 1, 1);
  75445. var boxMat$1 = new MeshBasicMaterial({
  75446. wireframe: true,
  75447. color: "#ffffff"
  75448. });
  75449. var defaults = {
  75450. positions: [],
  75451. positionStyle: "sphere",
  75452. positionBase: new Vector3(0, 0, 0),
  75453. positionSpread: new Vector3(1, 1, 0),
  75454. //cube
  75455. radius: 1,
  75456. // sphere
  75457. velocityStyle: 'cube',
  75458. velocityBase: new Vector3(0, 0, 0.5),
  75459. // cube 基础速度
  75460. velocitySpread: new Vector3(1, 1, 0.3),
  75461. accelerationBase: 0.3,
  75462. //基础加速度
  75463. accelerationSpread: 0.6,
  75464. //没使用
  75465. speedBase: 0.1,
  75466. //sphere
  75467. speedSpread: 0.5,
  75468. angleBase: 0,
  75469. angleSpread: 360,
  75470. angleVelocityBase: 1,
  75471. angleVelocitySpread: 30,
  75472. angleAccelerationBase: 1,
  75473. angleAccelerationSpread: 5,
  75474. sizeBase: 0,
  75475. sizeSpread: 0,
  75476. sizeTween: [[0, 0.3, 1], [0.3, 1.4, 6]],
  75477. colorBase: new Vector3(0.0, 1.0, 0.5),
  75478. colorSpread: new Vector3(0.0, 0.0, 0.0),
  75479. colorTween: new Tween([0.2, 1], [new Vector3(0, 0, 0.4), new Vector3(0, 0, 0.1)]),
  75480. opacityBase: 0.1,
  75481. //1.0,
  75482. opacitySpread: 0.2,
  75483. opacityTween: [[0, 0.1, 0.9, 1], [0.1, 0.4, 0.03, 0]],
  75484. //particlesPerSecond : 20,
  75485. strength: 1,
  75486. particleDeathAge: 3,
  75487. //从底下升起后能持续的时间
  75488. //emitterDeathAge : 60 // time (seconds) at which to stop creating particles.
  75489. height: 3
  75490. };
  75491. var debugSphere = new Mesh(new SphereBufferGeometry(0.03, 5, 5), new MeshBasicMaterial({
  75492. color: 'white',
  75493. depthTest: false
  75494. }));
  75495. class SmokeParticle extends Points {
  75496. constructor() {
  75497. var prop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  75498. super();
  75499. this.blendStyle = NormalBlending; // false;
  75500. this.emitterAge = 0.0;
  75501. //this.emitterAlive = true;
  75502. prop = $.extend({}, defaults, prop);
  75503. for (var key in prop) {
  75504. var value = prop[key];
  75505. if (value instanceof Array && value[0] instanceof Array) this[key] = new Tween(...value);else if (value instanceof Vector3 || value instanceof Color) {
  75506. this[key] = value.clone();
  75507. } else {
  75508. this[key] = value;
  75509. }
  75510. }
  75511. this.defaultSizeTween = this.sizeTween.clone();
  75512. this.defaultOpacityTween = this.opacityTween.clone();
  75513. this.geometry = new BufferGeometry();
  75514. this.computeParams();
  75515. this.createMaterial();
  75516. this.createGeometry();
  75517. this.dynamic = true;
  75518. this.sortParticles = true;
  75519. this.frustumCulled = false; //似乎是禁止相机裁剪,否则会在某些角度消失。但是会不会更耗性能呢?
  75520. prop.position && this.position.copy(prop.position);
  75521. //---------------------------------------
  75522. this.setSize({
  75523. viewport: viewer.mainViewport
  75524. });
  75525. this.setFov(viewer.fov);
  75526. var setSize = e => {
  75527. if (e.viewport.name != "MainView") return;
  75528. this.setSize(e);
  75529. };
  75530. var setFov = e => {
  75531. this.setFov(e.fov);
  75532. };
  75533. /* let reStart = (e)=>{
  75534. if(e.v){//重新一个个放出粒子,否则会一股脑儿全部出来,因为同时大于粒子周期了一起重新生成出现。
  75535. setTimeout(()=>{//会先update一次delta为pageUnvisile的时间才触发
  75536. //console.log('归零')
  75537. //this.reStart()
  75538. },1)
  75539. }
  75540. } */
  75541. viewer.addEventListener('resize', setSize);
  75542. viewer.addEventListener('fov_changed', setFov);
  75543. //viewer.addEventListener('pageVisible', reStart)
  75544. this.addEventListener('dispose', () => {
  75545. viewer.removeEventListener('resize', setSize);
  75546. viewer.removeEventListener('fov_changed', setFov);
  75547. //viewer.removeEventListener('pageVisible', reStart)
  75548. });
  75549. }
  75550. computeParams() {
  75551. var length = (this.curve ? this.curve.wholeLength : 0) + this.radius * 2; //加上首尾的半径
  75552. //注意:烟最低高度一米, 0<strength<1
  75553. if (this.positionStyle == 'cube') {
  75554. this.positionSpread.set(this.radius, this.radius, 0);
  75555. }
  75556. this.velocityBase.set(0, 0, (this.height - 0.5 * this.accelerationBase * this.particleDeathAge * this.particleDeathAge) / this.particleDeathAge);
  75557. //let height = this.velocityBase.z * this.particleDeathAge + 0.5 * this.accelerationBase * this.particleDeathAge * this.particleDeathAge;//s = V0 * t + 0.5 * a * t*t ;
  75558. this.velocityBase.z = Math.max(0, this.velocityBase.z);
  75559. this.particleCount = Math.ceil(length * Math.sqrt(this.strength * this.height * this.radius));
  75560. this.particleCount = Math.max(5, this.particleCount);
  75561. {
  75562. var minSize = 1,
  75563. maxSize = 2,
  75564. minBound = 0.01,
  75565. maxBound = 1;
  75566. var size = minSize + (maxSize - minSize) * MathUtils.smoothstep(this.strength, minBound, maxBound);
  75567. this.sizeTween.values = this.defaultSizeTween.values.map(e => e * size);
  75568. }
  75569. {
  75570. var _minSize = 1,
  75571. _maxSize = 1.5,
  75572. _minBound = 0.01,
  75573. _maxBound = 1;
  75574. var opac = _minSize + (_maxSize - _minSize) * MathUtils.smoothstep(this.strength, _minBound, _maxBound);
  75575. this.opacityTween.values = this.defaultOpacityTween.values.map(e => e * opac);
  75576. }
  75577. //console.log('smoke particleCount',this.particleCount)
  75578. }
  75579. reStart() {
  75580. this.emitterAge = 0;
  75581. this.createGeometry();
  75582. }
  75583. updateGeometry() {
  75584. this.computeParams();
  75585. this.reStart();
  75586. }
  75587. createParticle(center) {
  75588. var particle = new Particle$1({
  75589. sizeTween: this.sizeTween,
  75590. opacityTween: this.opacityTween,
  75591. colorTween: this.colorTween
  75592. });
  75593. particle.deathAge = this.particleDeathAge;
  75594. particle.center = center;
  75595. if (this.positionStyle == 'cube') particle.position = this.randomVector3(this.positionBase, this.positionSpread);
  75596. if (this.positionStyle == 'sphere') {
  75597. /* var z = 2 * Math.random() - 1
  75598. var t = Math.PI * 2 * Math.random();
  75599. var r = Math.sqrt( 1 - z*z ) ;
  75600. var vec3 = new THREE.Vector3( r * Math.cos(t), r * Math.sin(t), z );
  75601. particle.position = new THREE.Vector3().addVectors( this.positionBase, vec3.multiplyScalar( this.radius ) );
  75602. */
  75603. //怎么改半径
  75604. var y = 2 * Math.random() - 1;
  75605. var t = Math.PI * 2 * Math.random();
  75606. var r = Math.sqrt(1 - y * y); //因为 r*r = 1-y*y = x*x + z*z = r*r(cos^2 + sin^2 );
  75607. var lowDownRatio = 0.2; //压低近平面
  75608. var vec3 = new Vector3(r * Math.cos(t), y, Math.abs(r * Math.sin(t)) * lowDownRatio);
  75609. particle.position = new Vector3().addVectors(this.positionBase, vec3.multiplyScalar(this.radius));
  75610. }
  75611. particle.position.add(center); //add
  75612. if (this.velocityStyle == 'cube') {
  75613. particle.velocity = this.randomVector3(this.velocityBase, this.velocitySpread);
  75614. }
  75615. if (this.velocityStyle == 'sphere') {
  75616. //var direction = particle.position.clone()
  75617. var direction = new Vector3(0, 0, 1); //烟应该都是向上的
  75618. var speed = this.randomValue(this.speedBase, this.speedSpread);
  75619. particle.velocity = direction.normalize().multiplyScalar(speed);
  75620. }
  75621. particle.acceleration = this.randomValue(this.accelerationBase, this.accelerationSpread);
  75622. particle.angle = this.randomValue(this.angleBase, this.angleSpread);
  75623. particle.angleVelocity = this.randomValue(this.angleVelocityBase, this.angleVelocitySpread);
  75624. particle.angleAcceleration = this.randomValue(this.angleAccelerationBase, this.angleAccelerationSpread);
  75625. particle.size = this.randomValue(this.sizeBase, this.sizeSpread);
  75626. var color = this.randomVector3(this.colorBase, this.colorSpread);
  75627. particle.color = new Color().setHSL(color.x, color.y, color.z);
  75628. particle.opacity = this.randomValue(this.opacityBase, this.opacitySpread);
  75629. particle.age = 0;
  75630. particle.alive = 0; // particles initialize as inactive
  75631. return particle;
  75632. }
  75633. getPointsForBound() {
  75634. return this.boundPoints; //可以用于expand实时bound的点, 不含particle的size等边距
  75635. }
  75636. getBound(points) {
  75637. // points为生成点(圆心)
  75638. this.boundPoints = [];
  75639. var boundingBox = new Box3();
  75640. var maxSize = this.sizeTween.values.slice().sort((a, b) => b - a)[0];
  75641. var margin0 = maxSize * 0.11;
  75642. var margin1 = margin0 + 0.5; //保守估计还会飘出这么多距离吧: size + 飘动
  75643. points.forEach(bottom => {
  75644. var top = bottom.clone();
  75645. top.z += this.height;
  75646. boundingBox.expandByPoint(bottom);
  75647. boundingBox.expandByPoint(top);
  75648. this.boundPoints.push(bottom, top);
  75649. });
  75650. var xyExpand = this.radius + margin1;
  75651. boundingBox.expandByVector(new Vector3(xyExpand, xyExpand, 0));
  75652. boundingBox.min.z -= margin0;
  75653. boundingBox.max.z += margin1;
  75654. this.boundingBox = boundingBox;
  75655. /* if(!this.debugBox){
  75656. this.debugBox = new THREE.Mesh(boxGeo, boxMat)
  75657. this.add(this.debugBox)
  75658. }
  75659. this.debugBox.scale.copy(boundingBox.getSize(new THREE.Vector3))
  75660. this.debugBox.position.copy(boundingBox.getCenter(new THREE.Vector3)) */
  75661. }
  75662. createGeometry() {
  75663. this.particleArray = [];
  75664. var positions = [];
  75665. var colors = [];
  75666. var alives = [];
  75667. var opacitys = [];
  75668. var sizes = [];
  75669. var angles = [];
  75670. var count, points;
  75671. if (this.positions.length > 1) {
  75672. var spaceDis = 0.6; //间隔距离
  75673. count = Math.ceil(this.curve.wholeLength / spaceDis) + 1;
  75674. points = this.curve.getSpacedPoints(count);
  75675. count = points.length;
  75676. /* points.forEach(e=> {
  75677. var sphere = debugSphere.clone();
  75678. sphere.position.copy(e)
  75679. viewer.scene.scene.add(sphere)
  75680. }) */
  75681. var haventGetPoints = points.slice();
  75682. var getRanPoints = function getRanPoints(i) {
  75683. var a = Math.random();
  75684. var choseIndex = Math.floor(haventGetPoints.length * a);
  75685. var point = haventGetPoints[choseIndex];
  75686. if (haventGetPoints.length == 1) {
  75687. haventGetPoints = points.slice();
  75688. } else {
  75689. haventGetPoints.splice(choseIndex, 1);
  75690. }
  75691. return point;
  75692. };
  75693. this.getBound(points);
  75694. } else {
  75695. this.getBound(this.positions);
  75696. }
  75697. for (var i = 0; i < this.particleCount; i++) {
  75698. var center = new Vector3().copy(this.positions.length > 1 ? getRanPoints(i) : this.positions[0]);
  75699. //var center = new THREE.Vector3().copy(this.positions.length>1 ? points[Math.floor(i/this.particleCount * count)] : this.positions[0])
  75700. // remove duplicate code somehow, here and in update function below.
  75701. this.particleArray[i] = this.createParticle(center);
  75702. positions[3 * i] = this.particleArray[i].position.x;
  75703. positions[3 * i + 1] = this.particleArray[i].position.y;
  75704. positions[3 * i + 2] = this.particleArray[i].position.z;
  75705. colors[3 * i] = this.particleArray[i].color.r;
  75706. colors[3 * i + 1] = this.particleArray[i].color.g;
  75707. colors[3 * i + 2] = this.particleArray[i].color.b;
  75708. alives[i] = this.particleArray[i].alive;
  75709. opacitys[i] = this.particleArray[i].opacity;
  75710. sizes[i] = this.particleArray[i].size;
  75711. angles[i] = this.particleArray[i].angle;
  75712. }
  75713. this.geometry.setAttribute('position', new BufferAttribute(new Float32Array(positions), 3));
  75714. this.geometry.setAttribute('customColor', new BufferAttribute(new Float32Array(colors), 3));
  75715. this.geometry.setAttribute('customVisible', new BufferAttribute(new Float32Array(alives), 1));
  75716. this.geometry.setAttribute('customOpacity', new BufferAttribute(new Float32Array(opacitys), 1));
  75717. this.geometry.setAttribute('customSize', new BufferAttribute(new Float32Array(sizes), 1));
  75718. this.geometry.setAttribute('customAngle', new BufferAttribute(new Float32Array(angles), 1));
  75719. }
  75720. createMaterial() {
  75721. this.material = new ShaderMaterial({
  75722. uniforms: {
  75723. u_sampler: {
  75724. type: "t",
  75725. value: getTexture$1()
  75726. },
  75727. heightOfNearPlane: {
  75728. type: "f",
  75729. value: 0
  75730. } //相对far ,以确保画面缩放时点的大小也会缩放
  75731. },
  75732. vertexShader: vertexShader$1,
  75733. vertexShader: vertexShader$1,
  75734. fragmentShader: fragmentShader$1,
  75735. transparent: true,
  75736. alphaTest: 0.5,
  75737. // if having transparency issues, try including: alphaTest: 0.5,
  75738. blending: this.blendStyle,
  75739. depthTest: this.blendStyle != NormalBlending
  75740. });
  75741. this.setPerspective(this.fov, this.screenHeight);
  75742. }
  75743. update(dt) {
  75744. if (!Potree.Utils.getObjVisiByReason(this, 'force')) {
  75745. //被手动隐藏了
  75746. return;
  75747. }
  75748. if (!Potree.Utils.isInsideFrustum(this.boundingBox, viewer.scene.getActiveCamera())) {
  75749. Potree.Utils.updateVisible(this, 'isInsideFrustum', false); //不在视野范围
  75750. //console.log('unvi')
  75751. return;
  75752. } else {
  75753. Potree.Utils.updateVisible(this, 'isInsideFrustum', true);
  75754. }
  75755. if (dt > 1) {
  75756. console.log('update dt>1', dt);
  75757. }
  75758. //dt *= 0.5;
  75759. var recycleIndices = [];
  75760. var recycleAges = [];
  75761. var positions = [];
  75762. var colors = [];
  75763. var alives = [];
  75764. var opacitys = [];
  75765. var sizes = [];
  75766. var angles = [];
  75767. for (var i = 0; i < this.particleCount; i++) {
  75768. if (this.particleArray[i].alive) {
  75769. if (this.velocityStyle == 'cube') {
  75770. //一定几率改变下方向
  75771. var ratio = Math.random();
  75772. if (this.particleArray[i].age - this.particleArray[i].lastChangeVage > this.particleDeathAge * ratio) {
  75773. this.particleArray[i].velocity = this.randomVector3(this.velocityBase, this.velocitySpread);
  75774. this.particleArray[i].lastChangeVage = this.particleArray[i].age;
  75775. }
  75776. } else {
  75777. /* if(this.particleArray[i].age - this.particleArray[i].lastChangeVage > this.particleDeathAge*0.3 ){
  75778. if( Math.random()>0.1){//一定几率改变下方向
  75779. var speed = this.randomValue( this.speedBase, this.speedSpread );
  75780. this.particleArray[i].velocity = this.randomVector3( new THREE.Vector3, new THREE.Vector3(1,1,1) );
  75781. this.particleArray[i].velocity.normalize().multiplyScalar( speed );
  75782. }
  75783. this.particleArray[i].lastChangeVage = this.particleArray[i].age
  75784. } */
  75785. }
  75786. this.particleArray[i].update(dt);
  75787. // check if particle should expire
  75788. // could also use: death by size<0 or alpha<0.
  75789. if (this.particleArray[i].age > this.particleDeathAge) {
  75790. this.particleArray[i].alive = 0.0;
  75791. recycleIndices.push(i);
  75792. recycleAges.push((this.particleArray[i].age - this.particleDeathAge) % this.particleDeathAge);
  75793. }
  75794. // update particle properties in shader
  75795. positions[3 * i] = this.particleArray[i].position.x;
  75796. positions[3 * i + 1] = this.particleArray[i].position.y;
  75797. positions[3 * i + 2] = this.particleArray[i].position.z;
  75798. colors[3 * i] = this.particleArray[i].color.r;
  75799. colors[3 * i + 1] = this.particleArray[i].color.g;
  75800. colors[3 * i + 2] = this.particleArray[i].color.b;
  75801. alives[i] = this.particleArray[i].alive;
  75802. opacitys[i] = this.particleArray[i].opacity;
  75803. sizes[i] = this.particleArray[i].size;
  75804. angles[i] = this.particleArray[i].angle;
  75805. }
  75806. }
  75807. // check if particle emitter is still running
  75808. //if ( !this.emitterAlive ) return;
  75809. this.geometry.setAttribute('position', new BufferAttribute(new Float32Array(positions), 3));
  75810. this.geometry.setAttribute('customColor', new BufferAttribute(new Float32Array(colors), 3));
  75811. this.geometry.setAttribute('customVisible', new BufferAttribute(new Float32Array(alives), 1));
  75812. this.geometry.setAttribute('customOpacity', new BufferAttribute(new Float32Array(opacitys), 1));
  75813. this.geometry.setAttribute('customSize', new BufferAttribute(new Float32Array(sizes), 1));
  75814. this.geometry.setAttribute('customAngle', new BufferAttribute(new Float32Array(angles), 1));
  75815. this.geometry.attributes.customColor.needsUpdate = true;
  75816. this.geometry.attributes.customVisible.needsUpdate = true;
  75817. this.geometry.attributes.customOpacity.needsUpdate = true;
  75818. this.geometry.attributes.customSize.needsUpdate = true;
  75819. this.geometry.attributes.customAngle.needsUpdate = true;
  75820. // if no particles have died yet, then there are still particles to activate
  75821. if (this.emitterAge < this.particleDeathAge)
  75822. //开始时一个个放出来
  75823. {
  75824. var particlesPerSecond = this.particleCount / this.particleDeathAge;
  75825. // determine indices of particles to activate
  75826. var startIndex = Math.round(particlesPerSecond * (this.emitterAge + 0));
  75827. var endIndex = Math.round(particlesPerSecond * (this.emitterAge + dt));
  75828. if (endIndex > this.particleCount) endIndex = this.particleCount;
  75829. for (var i = startIndex; i < endIndex; i++) this.particleArray[i].alive = 1.0;
  75830. }
  75831. // if any particles have died while the emitter is still running, we imediately recycle them
  75832. for (var j = 0; j < recycleIndices.length; j++) {
  75833. var i = recycleIndices[j];
  75834. this.particleArray[i] = this.createParticle(this.particleArray[i].center);
  75835. this.particleArray[i].alive = 1.0; // activate right away
  75836. this.particleArray[i].age = recycleAges[j];
  75837. positions[3 * i] = this.particleArray[i].position.x;
  75838. positions[3 * i + 1] = this.particleArray[i].position.y;
  75839. positions[3 * i + 2] = this.particleArray[i].position.z;
  75840. }
  75841. this.geometry.setAttribute('position', new BufferAttribute(new Float32Array(positions), 3));
  75842. this.geometry.attributes.position.needsUpdate = true;
  75843. // stop emitter?
  75844. this.emitterAge += dt;
  75845. //if ( this.emitterAge > this.emitterDeathAge ) this.emitterAlive = false;
  75846. }
  75847. randomValue(base, spread) {
  75848. //return base + spread * (Math.random() - 0.5);
  75849. var p = Math.random();
  75850. return base * p + spread * (1 - p);
  75851. }
  75852. randomVector3(base, spread) {
  75853. var rand3 = new Vector3(Math.random() - 0.5, Math.random() - 0.5, Math.random() - 0.5);
  75854. return new Vector3().addVectors(base, new Vector3().multiplyVectors(spread, rand3));
  75855. }
  75856. setSize(e) {
  75857. var viewport = e.viewport;
  75858. this.screenHeight = viewport.resolution.y;
  75859. this.setPerspective(this.fov, this.screenHeight);
  75860. }
  75861. setFov(fov) {
  75862. this.fov = fov;
  75863. this.setPerspective(this.fov, this.screenHeight);
  75864. }
  75865. setPerspective(fov, height) {
  75866. //this.uniforms.heightOfNearPlane.value = Math.abs(height / (2 * Math.tan(THREE.Math.degToRad(fov * 0.5))));
  75867. var far = Math.abs(height / (2 * Math.tan(MathUtils.degToRad(fov * 0.5))));
  75868. this.material.uniforms.heightOfNearPlane.value = far;
  75869. }
  75870. dispose() {
  75871. this.geometry.dispose();
  75872. this.material.dispose();
  75873. this.dispatchEvent('dispose');
  75874. }
  75875. }
  75876. /*
  75877. 改进:如果有必要
  75878. 根据curve中分成的点,分成多个簇,每个簇掌管该部分的可见性和particle的数量。
  75879. 在camera_changed时根据远近修改每个簇的particle的数量,当然不会大于初始创建的个数。多出的随机隐藏。
  75880. */
  75881. var vertexShader$2 = "\n attribute vec3 color;\n attribute float size;\n attribute float angle;\n attribute float opacity;\n attribute float visible;\n varying vec4 vColor;\n varying float vAngle;\n uniform float heightOfNearPlane;\n \n void main() {\n if(visible > 0.5) {\n vColor = vec4(color, opacity);\n } else {\n vColor = vec4(0.0, 0.0, 0.0, 0.0);\n }\n vAngle = angle;\n vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);\n gl_Position = projectionMatrix * mvPosition;\n \n gl_PointSize = ( heightOfNearPlane * size ) / gl_Position.w;\n }\n";
  75882. var fragmentShader$2 = "\n uniform sampler2D u_sampler;\n varying vec4 vColor;\n varying float vAngle;\n void main() {\n gl_FragColor = vColor;\n float u = cos(vAngle);\n float v = sin(vAngle);\n vec2 uv = vec2(\n u * (gl_PointCoord.x - 0.5) + v * (gl_PointCoord.y - 0.5) + 0.5, \n u * (gl_PointCoord.y - 0.5) - v * (gl_PointCoord.x - 0.5) + 0.5\n );\n vec4 texture = texture2D(u_sampler, uv);\n gl_FragColor = gl_FragColor * texture;\n }\n";
  75883. // import { vertexShader, fragmentShader } from './shader'
  75884. var DEG2RAD = Math.PI / 180;
  75885. class Particle$2 {
  75886. constructor() {
  75887. this.position = new Vector3();
  75888. this.velocity = new Vector3();
  75889. this.angle = 0;
  75890. this.angleVelocity = 0;
  75891. this.angleAcceleration = 0;
  75892. this.size = 16;
  75893. this.color = new Color();
  75894. this.opacity = 1;
  75895. this.rebornCount = 0; //重生次数
  75896. this.age = 0;
  75897. this.alive = 0; //注意,一开始时是未出生的
  75898. this.deadAge = 0; //已死亡时间
  75899. this.sizeTween = null;
  75900. this.colorTween = null;
  75901. this.opacityTween = null;
  75902. }
  75903. update(dt) {
  75904. //s = s0 + (v0 + at) * t 或 lastS + delta(vt)
  75905. this.position.add(this.velocity.clone().multiplyScalar(dt));
  75906. this.velocity.multiplyScalar(1 + this.acceleration * dt);
  75907. this.angle += this.angleVelocity * DEG2RAD * dt;
  75908. this.angleVelocity += this.angleAcceleration * DEG2RAD * dt;
  75909. this.age += dt;
  75910. if (this.sizeTween.times.length > 0) {
  75911. this.size = this.sizeTween.lerp(this.age / this.deathAge);
  75912. }
  75913. if (this.colorTween.times.length > 0) {
  75914. var colorHSL = this.colorTween.lerp(this.age / this.deathAge);
  75915. this.color = new Color().setHSL(colorHSL.x, colorHSL.y, colorHSL.z);
  75916. }
  75917. if (this.opacityTween.times.length > 0) {
  75918. this.opacity = this.opacityTween.lerp(this.age / this.deathAge);
  75919. }
  75920. viewer.dispatchEvent('content_changed');
  75921. }
  75922. }
  75923. class Util {
  75924. constructor() {}
  75925. randomValue(min, max) {
  75926. //return min + max * (Math.random() - 0.5)
  75927. var p = Math.random();
  75928. return min * p + max * (1 - p);
  75929. }
  75930. randomVector3(min, max) {
  75931. var rand3 = new Vector3(Math.random() - 0.5, Math.random() - 0.5, Math.random() - 0.5);
  75932. return new Vector3().addVectors(min, new Vector3().multiplyVectors(max, rand3));
  75933. }
  75934. }
  75935. var util$1 = new Util();
  75936. var Shape$1 = {
  75937. CUBE: 1,
  75938. SPHERE: 2
  75939. };
  75940. var particleTexture$1;
  75941. var getTexture$2 = () => {
  75942. if (!particleTexture$1) {
  75943. particleTexture$1 = new TextureLoader().load(Potree.resourcePath + '/textures/explode.png');
  75944. }
  75945. return particleTexture$1;
  75946. };
  75947. var sphereGeo = new SphereBufferGeometry(1, 10, 4);
  75948. var sphereMat = new MeshBasicMaterial({
  75949. wireframe: true,
  75950. color: "#ffffff"
  75951. });
  75952. var defaults$1 = {
  75953. position: new Vector3(0, 0, 1),
  75954. positionShape: Shape$1.SPHERE,
  75955. positionRange: new Vector3(1, 1, 1),
  75956. //cube
  75957. radius: 1.3,
  75958. //sphere
  75959. velocityShape: Shape$1.SPHERE,
  75960. velocity: new Vector3(0, 0, 2),
  75961. //cube
  75962. velocityRange: new Vector3(0, 0, 3),
  75963. //sphere
  75964. speed: 0.4,
  75965. speedRange: 1,
  75966. size: 0.4,
  75967. sizeRange: 2,
  75968. //sizeTween: new Tween( [0, 0.05, 0.3, 0.45], [0, 1, 3, 0.1] ),
  75969. sizeTween: [[0, 0.04, 0.2, 1], [0.1, 1, 6, 8]],
  75970. color: new Vector3(1.0, 1.0, 1.0),
  75971. colorRange: new Vector3(0, 0, 0),
  75972. colorTween: new Tween(),
  75973. opacity: 1.0,
  75974. opacityRange: 0.0,
  75975. opacityTween: new Tween([0, 0.06, 0.3, 0.8, 1], [0, 1, 0.3, 0.05, 0]),
  75976. blendMode: AdditiveBlending,
  75977. acceleration: 0.5,
  75978. accelerationRange: 0,
  75979. angle: 0,
  75980. angleRange: 0,
  75981. angleVelocity: 0,
  75982. angleVelocityRange: 0,
  75983. angleAcceleration: 0,
  75984. angleAccelerationRange: 0,
  75985. strength: 1,
  75986. //particlesPerSecond: 8,
  75987. particleDeathAge: 0.7,
  75988. recycleTimes: 3,
  75989. //每个粒子在一次爆炸后循环次数,循环完毕进入particleSpaceTime,等待下一次爆炸.
  75990. //爆炸时长: particleDeathAge * (recycleTimes+1)
  75991. particleSpaceTime: 3 //间隔
  75992. };
  75993. class ExplodeParticle extends Points {
  75994. constructor(params) {
  75995. super();
  75996. this.age = 0;
  75997. this.alive = true;
  75998. //this.deathAge = 60
  75999. this.loop = true;
  76000. this.blendMode = NormalBlending;
  76001. this.setParameters(params);
  76002. this.createParticles();
  76003. this.frustumCulled = false; //似乎是禁止相机裁剪,否则会在某些角度消失。但是会不会更耗性能呢?
  76004. //------------------------------------
  76005. this.setSize({
  76006. viewport: viewer.mainViewport
  76007. });
  76008. this.setFov(viewer.fov);
  76009. var setSize = e => {
  76010. if (e.viewport.name != "MainView") return;
  76011. this.setSize(e);
  76012. };
  76013. var setFov = e => {
  76014. this.setFov(e.fov);
  76015. };
  76016. /* let reStart = (e)=>{
  76017. if(e.v){//重新一个个放出粒子,否则会一股脑儿全部出来,因为同时大于粒子周期了一起重新生成出现。
  76018. setTimeout(()=>{//会先update一次delta为pageUnvisile的时间才触发
  76019. //console.log('归零')
  76020. //this.reStart()
  76021. },1)
  76022. }
  76023. } */
  76024. viewer.addEventListener('resize', setSize);
  76025. viewer.addEventListener('fov_changed', setFov);
  76026. //viewer.addEventListener('pageVisible', reStart)
  76027. this.addEventListener('dispose', () => {
  76028. viewer.removeEventListener('resize', setSize);
  76029. viewer.removeEventListener('fov_changed', setFov);
  76030. //viewer.removeEventListener('pageVisible', reStart)
  76031. });
  76032. }
  76033. computeParams() {
  76034. if (this.curve) {
  76035. this.position.copy(this.curve.points[0]);
  76036. }
  76037. var minSize = 0.8,
  76038. maxSize = 10,
  76039. minRadiusBound = 0.2,
  76040. maxRadiusBound = 20;
  76041. var size = minSize + (maxSize - minSize) * MathUtils.smoothstep(this.radius * this.strength, minRadiusBound, maxRadiusBound);
  76042. this.sizeTween.values = this.defaultSizeTween.values.map(e => e * size);
  76043. this.particleCount = Math.ceil(this.strength * this.radius * 5 /* * this.radius * this.radius */);
  76044. this.speed = defaults$1.speed * this.radius;
  76045. this.speedRange = defaults$1.speedRange * this.radius;
  76046. console.log(this.particleCount);
  76047. {
  76048. this.boundPoints = [];
  76049. this.boundPoints.push(this.position.clone());
  76050. var _maxSize = this.sizeTween.values.slice().sort((a, b) => b - a)[0];
  76051. var margin = _maxSize * 0.35 + 0.5;
  76052. var scale = this.radius + margin;
  76053. var sphere = new Sphere(this.position, scale); //加上防止剪裁
  76054. this.boundingSphere = sphere; //虽然还是会有一些后续移动的会超出
  76055. this.boundingBox = new Box3().setFromCenterAndSize(this.position, new Vector3(scale * 2, scale * 2, scale * 2));
  76056. /* if(!this.debugSphere){
  76057. this.debugSphere = new THREE.Mesh(sphereGeo, sphereMat)
  76058. this.add(this.debugSphere)
  76059. }
  76060. this.debugSphere.scale.set(scale,scale,scale) */
  76061. }
  76062. }
  76063. getPointsForBound() {
  76064. return this.boundPoints; //可以用于expand实时bound的点, 不含particle的size等边距
  76065. }
  76066. reStart() {
  76067. this.age = 0;
  76068. this.createParticles();
  76069. }
  76070. setParameters(params) {
  76071. params = $.extend({}, defaults$1, params);
  76072. for (var key in params) {
  76073. var value = params[key];
  76074. if (key == 'position') this.position.copy(value);else if (value instanceof Array && value[0] instanceof Array) {
  76075. this[key] = new Tween(...value);
  76076. } else if (value instanceof Vector3 || value instanceof Color) {
  76077. this[key] = value.clone();
  76078. } else {
  76079. this[key] = value;
  76080. }
  76081. }
  76082. this.defaultSizeTween = this.sizeTween.clone();
  76083. //Object.assign(this, params)
  76084. this.particles = [];
  76085. this.age = 0.0;
  76086. this.alive = true;
  76087. this.geometry = new BufferGeometry();
  76088. this.computeParams();
  76089. this.material = new ShaderMaterial({
  76090. uniforms: {
  76091. u_sampler: {
  76092. value: this.texture || getTexture$2()
  76093. },
  76094. heightOfNearPlane: {
  76095. type: "f",
  76096. value: 0
  76097. } //相对far ,以确保画面缩放时点的大小也会缩放
  76098. },
  76099. vertexShader: vertexShader$2,
  76100. fragmentShader: fragmentShader$2,
  76101. transparent: true,
  76102. alphaTest: 0.5,
  76103. depthTest: this.blendMode == NormalBlending,
  76104. blending: this.blendMode
  76105. });
  76106. }
  76107. createParticles() {
  76108. this.particles = [];
  76109. var count = this.particleCount;
  76110. var positionArray = new Float32Array(count * 3);
  76111. var colorArray = new Float32Array(count * 3);
  76112. var sizeArray = new Float32Array(count);
  76113. var angleArray = new Float32Array(count);
  76114. var opacityArray = new Float32Array(count);
  76115. var visibleArray = new Float32Array(count);
  76116. for (var i = 0; i < count; i++) {
  76117. var particle = this.createParticle();
  76118. /* positionArray[i * 3] = particle.position.x
  76119. positionArray[i * 3 + 1] = particle.position.y
  76120. positionArray[i * 3 + 2] = particle.position.z
  76121. colorArray[i * 3] = particle.color.r
  76122. colorArray[i * 3 + 1] = particle.color.g
  76123. colorArray[i * 3 + 2] = particle.color.b
  76124. sizeArray[i] = particle.size
  76125. angleArray[i] = particle.angel
  76126. opacityArray[i] = particle.opacity
  76127. visibleArray[i] = particle.alive */
  76128. this.particles[i] = particle;
  76129. }
  76130. this.geometry.setAttribute('position', new BufferAttribute(positionArray, 3));
  76131. this.geometry.setAttribute('color', new BufferAttribute(colorArray, 3));
  76132. this.geometry.setAttribute('angle', new BufferAttribute(angleArray, 1));
  76133. this.geometry.setAttribute('size', new BufferAttribute(sizeArray, 1));
  76134. this.geometry.setAttribute('visible', new BufferAttribute(visibleArray, 1));
  76135. this.geometry.setAttribute('opacity', new BufferAttribute(opacityArray, 1));
  76136. }
  76137. createParticle() {
  76138. var particle = new Particle$2();
  76139. particle.sizeTween = this.sizeTween;
  76140. particle.colorTween = this.colorTween;
  76141. particle.opacityTween = this.opacityTween;
  76142. particle.deathAge = this.particleDeathAge;
  76143. if (this.positionShape == Shape$1.CUBE) {
  76144. particle.position = util$1.randomVector3(new Vector3(), this.positionRange);
  76145. }
  76146. if (this.positionShape == Shape$1.SPHERE) {
  76147. /* const z = 2 * Math.random() - 1
  76148. const t = Math.PI * 2 * Math.random()
  76149. const r = Math.sqrt(1 - z*z)
  76150. const vec3 = new THREE.Vector3(r * Math.cos(t), r * Math.sin(t), z)
  76151. particle.position = vec3.multiplyScalar(this.radius) */
  76152. var y = 2 * Math.random() - 1;
  76153. var t = Math.PI * 2 * Math.random();
  76154. var r = Math.sqrt(1 - y * y);
  76155. var vec3 = new Vector3(r * Math.cos(t), y, r * Math.sin(t));
  76156. particle.position = vec3.multiplyScalar(this.radius);
  76157. }
  76158. if (this.velocityShape == Shape$1.CUBE) {
  76159. particle.velocity = util$1.randomVector3(this.velocity, this.velocityRange);
  76160. }
  76161. if (this.velocityShape == Shape$1.SPHERE) {
  76162. var direction = new Vector3().addVectors(particle.position, new Vector3(0, 0, this.radius * 2)); //向上升?
  76163. var speed = util$1.randomValue(this.speed, this.speedRange);
  76164. particle.velocity = direction.normalize().multiplyScalar(speed);
  76165. }
  76166. particle.acceleration = util$1.randomValue(this.acceleration, this.accelerationRange);
  76167. particle.angle = util$1.randomValue(this.angle, this.angleRange);
  76168. particle.angleVelocity = util$1.randomValue(this.angleVelocity, this.angleVelocityRange);
  76169. particle.angleAcceleration = util$1.randomValue(this.angleAcceleration, this.angleAccelerationRange);
  76170. particle.size = util$1.randomValue(this.size, this.sizeRange);
  76171. var color = util$1.randomVector3(this.color, this.colorRange);
  76172. particle.color = new Color().setHSL(color.x, color.y, color.z);
  76173. particle.opacity = util$1.randomValue(this.opacity, this.opacityRange);
  76174. return particle;
  76175. }
  76176. update(dt) {
  76177. if (!Potree.Utils.getObjVisiByReason(this, 'force')) {
  76178. //被手动隐藏了
  76179. return;
  76180. }
  76181. if (this.delayStartTime > 0) {
  76182. // 爆炸延迟
  76183. return this.delayStartTime -= dt;
  76184. }
  76185. if (!Potree.Utils.isInsideFrustum(this.boundingSphere, viewer.scene.getActiveCamera())) {
  76186. Potree.Utils.updateVisible(this, 'isInsideFrustum', false); //不在视野范围
  76187. return;
  76188. } else {
  76189. Potree.Utils.updateVisible(this, 'isInsideFrustum', true);
  76190. }
  76191. //const timeRatio = 0.5
  76192. if (dt > 1) {
  76193. console.log('update dt>1', dt);
  76194. }
  76195. //dt *= timeRatio
  76196. var particleDeathAge = this.particleDeathAge; /* * timeRatio */
  76197. var particleSpaceTime = this.particleSpaceTime; /* * timeRatio */
  76198. var recycleIndices = [];
  76199. var recycleAges = [];
  76200. var recycleRebornCount = [];
  76201. var positionArray = this.geometry.attributes.position.array;
  76202. var opacityArray = this.geometry.attributes.opacity.array;
  76203. var visibleArray = this.geometry.attributes.visible.array;
  76204. var colorArray = this.geometry.attributes.color.array;
  76205. var angleArray = this.geometry.attributes.angle.array;
  76206. var sizeArray = this.geometry.attributes.size.array;
  76207. for (var i = 0; i < this.particleCount; i++) {
  76208. var particle = this.particles[i];
  76209. if (particle.alive) {
  76210. particle.update(dt);
  76211. if (particle.age > particleDeathAge) {
  76212. particle.alive = 0.0;
  76213. if (particle.rebornCount >= this.recycleTimes) {
  76214. particle.deadAge = particle.age - particleDeathAge; //已死亡时间
  76215. } else {
  76216. //直接循环
  76217. recycleIndices.push(i);
  76218. recycleAges.push( /* ( */particle.age - particleDeathAge /* )%(this.particleDeathAge ) */);
  76219. recycleRebornCount.push(particle.rebornCount + 1);
  76220. }
  76221. }
  76222. positionArray[i * 3] = particle.position.x;
  76223. positionArray[i * 3 + 1] = particle.position.y;
  76224. positionArray[i * 3 + 2] = particle.position.z;
  76225. colorArray[i * 3] = particle.color.r;
  76226. colorArray[i * 3 + 1] = particle.color.g;
  76227. colorArray[i * 3 + 2] = particle.color.b;
  76228. visibleArray[i] = particle.alive;
  76229. opacityArray[i] = particle.opacity;
  76230. angleArray[i] = particle.angle;
  76231. sizeArray[i] = particle.size;
  76232. } else {
  76233. if (particle.rebornCount >= this.recycleTimes) {
  76234. if (particle.age > particleDeathAge) {
  76235. //其他已经死亡的粒子的时间继续增加
  76236. particle.deadAge += dt;
  76237. }
  76238. }
  76239. }
  76240. if (particle.rebornCount >= this.recycleTimes && particle.age > particleDeathAge) {
  76241. //已经死亡
  76242. if (particle.deadAge >= particleSpaceTime) {
  76243. //死亡时间超过设定的间隔时间后重启
  76244. recycleIndices.push(i);
  76245. var wholeTime = particleDeathAge * (this.recycleTimes + 1) + particleSpaceTime;
  76246. recycleAges.push((particle.deadAge - particleSpaceTime) % wholeTime); //剩余时间就是重生后的age
  76247. recycleRebornCount.push(0);
  76248. }
  76249. }
  76250. }
  76251. this.geometry.attributes.size.needsUpdate = true;
  76252. this.geometry.attributes.color.needsUpdate = true;
  76253. this.geometry.attributes.angle.needsUpdate = true;
  76254. this.geometry.attributes.visible.needsUpdate = true;
  76255. this.geometry.attributes.opacity.needsUpdate = true;
  76256. this.geometry.attributes.position.needsUpdate = true;
  76257. if (!this.alive) return;
  76258. if (this.age < particleDeathAge) {
  76259. var startIndex = Math.round(this.particleCount * (this.age + 0) / particleDeathAge);
  76260. var endIndex = Math.round(this.particleCount * (this.age + dt) / particleDeathAge);
  76261. if (endIndex > this.particleCount) {
  76262. endIndex = this.particleCount;
  76263. }
  76264. for (var _i = startIndex; _i < endIndex; _i++) {
  76265. this.particles[_i].alive = 1.0;
  76266. }
  76267. }
  76268. for (var j = 0; j < recycleIndices.length; j++) {
  76269. var _i2 = recycleIndices[j];
  76270. this.particles[_i2] = this.createParticle();
  76271. this.particles[_i2].alive = 1.0; //出生
  76272. this.particles[_i2].age = recycleAges[j];
  76273. this.particles[_i2].rebornCount = recycleRebornCount[j];
  76274. /* if(this.particles[i].age < particleDeathAge){
  76275. positionArray[i * 3] = this.particles[i].position.x
  76276. positionArray[i * 3 + 1] = this.particles[i].position.y
  76277. positionArray[i * 3 + 2] = this.particles[i].position.z
  76278. visibleArray[i] = particle.alive?
  76279. } */
  76280. }
  76281. this.geometry.attributes.position.needsUpdate = true;
  76282. this.age += dt;
  76283. if (this.age > this.deathAge && !this.loop) {
  76284. this.alive = false;
  76285. }
  76286. }
  76287. setSize(e) {
  76288. var viewport = e.viewport;
  76289. this.screenHeight = viewport.resolution.y;
  76290. this.setPerspective(this.fov, this.screenHeight);
  76291. }
  76292. setFov(fov) {
  76293. this.fov = fov;
  76294. this.setPerspective(this.fov, this.screenHeight);
  76295. }
  76296. setPerspective(fov, height) {
  76297. //this.uniforms.heightOfNearPlane.value = Math.abs(height / (2 * Math.tan(THREE.Math.degToRad(fov * 0.5))));
  76298. var far = Math.abs(height / (2 * Math.tan(MathUtils.degToRad(fov * 0.5))));
  76299. this.material.uniforms.heightOfNearPlane.value = far;
  76300. }
  76301. updateGeometry() {
  76302. this.computeParams();
  76303. this.reStart();
  76304. }
  76305. dispose() {
  76306. this.geometry.dispose();
  76307. this.material.dispose();
  76308. this.dispatchEvent('dispose');
  76309. }
  76310. }
  76311. var colors$2 = {
  76312. 'fire+smoke': 0xffffff,
  76313. 'smoke': 0xffffff,
  76314. 'explode': 0xffffff
  76315. };
  76316. var depthMatPrefix = {
  76317. clipDistance: 100,
  76318. occlusionDistance: 60,
  76319. /* 变为backColor距离 */
  76320. maxClipFactor: 0.5,
  76321. backColor: "#777",
  76322. useDepth: true,
  76323. transparent: !0
  76324. };
  76325. var lineMats$2;
  76326. var getLineMat$1 = function getLineMat(type) {
  76327. if (!lineMats$2) {
  76328. lineMats$2 = {
  76329. 'fire+smoke': LineDraw.createFatLineMat($.extend(depthMatPrefix, {
  76330. color: colors$2['fire+smoke'],
  76331. lineWidth: 2
  76332. })),
  76333. 'smoke': LineDraw.createFatLineMat($.extend(depthMatPrefix, {
  76334. color: colors$2['smoke'],
  76335. lineWidth: 2
  76336. })),
  76337. 'explode': LineDraw.createFatLineMat($.extend(depthMatPrefix, {
  76338. color: colors$2['explode'],
  76339. lineWidth: 2
  76340. }))
  76341. };
  76342. }
  76343. return lineMats$2[type];
  76344. };
  76345. var handleMats;
  76346. var getHandleMat = function getHandleMat(type) {
  76347. if (!handleMats) {
  76348. var texLoader = new TextureLoader();
  76349. handleMats = {
  76350. "fire+smoke": new DepthBasicMaterial($.extend(depthMatPrefix, {
  76351. map: texLoader.load(Potree.resourcePath + '/textures/icon-fire.png'),
  76352. color: colors$2['fire+smoke']
  76353. })),
  76354. "smoke": new DepthBasicMaterial($.extend(depthMatPrefix, {
  76355. map: texLoader.load(Potree.resourcePath + '/textures/icon-smoke.png'),
  76356. color: colors$2['smoke']
  76357. })),
  76358. "explode": new DepthBasicMaterial($.extend(depthMatPrefix, {
  76359. map: texLoader.load(Potree.resourcePath + '/textures/icon-explode.png'),
  76360. color: colors$2['explode']
  76361. }))
  76362. };
  76363. }
  76364. return handleMats[type];
  76365. };
  76366. var ParticleEditor = {
  76367. bus: new EventDispatcher(),
  76368. particleGroup: new Object3D(),
  76369. curveGroup: new Object3D(),
  76370. init: function init() {
  76371. this.particleGroup.name = 'particles';
  76372. viewer.scene.scene.add(this.particleGroup);
  76373. this.curveGroup.name = 'particles-curves';
  76374. viewer.scene.scene.add(this.curveGroup);
  76375. },
  76376. addParticle: function addParticle() {
  76377. var prop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  76378. var particle;
  76379. if (prop.type == 'fire') {
  76380. particle = new FireParticle(prop);
  76381. } else if (prop.type == 'smoke') {
  76382. particle = new SmokeParticle(prop);
  76383. } else if (prop.type == 'explode') {
  76384. particle = new ExplodeParticle(prop);
  76385. }
  76386. this.particleGroup.add(particle);
  76387. return particle;
  76388. },
  76389. removeParticle(particle) {
  76390. //particle.dispatchEvent('delete')
  76391. particle.dispose();
  76392. this.particleGroup.remove(particle);
  76393. particle.curve.dispose();
  76394. },
  76395. update(delta) {
  76396. this.particleGroup.children.forEach(e => e.update(delta));
  76397. },
  76398. startInsertion() {
  76399. var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'fire';
  76400. var prop = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  76401. //viewer.modules.ParticleEditor.startInsertion()
  76402. var deferred = $.Deferred();
  76403. var particles = [];
  76404. var finish = ifDone => {
  76405. if (ifDone) {
  76406. deferred.resolve(particles);
  76407. }
  76408. viewer.dispatchEvent({
  76409. type: "CursorChange",
  76410. action: "remove",
  76411. name: "addSth"
  76412. });
  76413. viewer.removeEventListener('global_click', click);
  76414. this.bus.removeEventListener('cancel_insertions', cancel);
  76415. };
  76416. var curve = new CurveCtrl([], getLineMat$1(type), colors$2[type], type + '_curve', {
  76417. handleMat: getHandleMat(type)
  76418. });
  76419. this.curveGroup.add(curve);
  76420. prop.curve = curve;
  76421. prop.type = type;
  76422. //console.log('创建curve',type,curve.uuid)
  76423. var cancel = () => {
  76424. console.log('cancel_insertions', curve.uuid);
  76425. curve.dispose();
  76426. finish(false);
  76427. };
  76428. this.bus.dispatchEvent('cancel_insertions'); //删除旧的
  76429. this.bus.addEventListener('cancel_insertions', cancel);
  76430. var click = e => {
  76431. if (e.button === MOUSE.RIGHT) {
  76432. if (curve.points.length >= 1) {
  76433. //if(type.includes('fire') || type.includes('smoke') ){
  76434. particles = this.createFromData(prop);
  76435. finish(true);
  76436. }
  76437. return;
  76438. }
  76439. var I = e.intersect && (e.intersect.orthoIntersect || e.intersect.location);
  76440. if (!I) return;
  76441. curve.addPoint(I, null, true);
  76442. if (type == 'explode') {
  76443. particles = this.createFromData(prop);
  76444. finish(true);
  76445. }
  76446. return {
  76447. stopContinue: true
  76448. }; //防止继续执行别的侦听,如flytopano
  76449. };
  76450. viewer.addEventListener('global_click', click, {
  76451. importance: 10
  76452. }); //add importance
  76453. viewer.dispatchEvent({
  76454. type: "CursorChange",
  76455. action: "add",
  76456. name: "addSth"
  76457. });
  76458. return deferred.promise();
  76459. },
  76460. createFromData(prop) {
  76461. var type = prop.type;
  76462. var particles = [];
  76463. var curve = prop.curve;
  76464. if (!curve) {
  76465. curve = new CurveCtrl(prop.points, getLineMat$1(type), colors$2[type], type + '_curve', {
  76466. handleMat: getHandleMat(type)
  76467. });
  76468. this.curveGroup.add(curve);
  76469. }
  76470. if (type.includes('fire') || type.includes('smoke')) {
  76471. if (type.includes('fire')) {
  76472. var fire = this.addParticle({
  76473. type: 'fire',
  76474. positions: curve.points,
  76475. curve,
  76476. radius: prop.radius,
  76477. height: prop.height,
  76478. strength: prop.strength
  76479. });
  76480. particles.push(fire);
  76481. }
  76482. if (type.includes('smoke')) {
  76483. var smoke = this.addParticle({
  76484. type: 'smoke',
  76485. positions: curve.points,
  76486. curve,
  76487. positionStyle: 'sphere',
  76488. strength: prop.smokeStrength,
  76489. radius: prop.smokeRadius,
  76490. height: prop.smokeHeight
  76491. });
  76492. particles.push(smoke);
  76493. }
  76494. } else if (type == 'explode') {
  76495. var explode = this.addParticle({
  76496. type: 'explode',
  76497. position: curve.points[0],
  76498. strength: prop.strength,
  76499. radius: prop.radius,
  76500. particleSpaceTime: prop.particleSpaceTime,
  76501. curve,
  76502. delayStartTime: prop.delayStartTime
  76503. });
  76504. particles.push(explode);
  76505. }
  76506. curve.addEventListener('dragCurvePoint', () => {
  76507. Common.intervalTool.isWaiting('particlePointChange', () => {
  76508. //延时update,防止卡顿
  76509. particles.forEach(e => e.updateGeometry());
  76510. //geoNeedsUpdate = false
  76511. curve.dispatchEvent('sendUpdatePoints');
  76512. }, 400);
  76513. });
  76514. return particles;
  76515. }
  76516. };
  76517. var CamAniEditor = {
  76518. createAnimation(data) {
  76519. var animation = new CameraAnimation$1(viewer);
  76520. if (data) {
  76521. animation.name = data.name;
  76522. animation.duration = data.duration;
  76523. animation.useDurSlice = data.useDurSlice;
  76524. for (var cpdata of data.points) {
  76525. /* const position = Potree.Utils.datasetPosTransform({ fromDataset: true, position: cpdata.position, datasetId: Potree.settings.originDatasetId })
  76526. const target = Potree.Utils.datasetPosTransform({ fromDataset: true, position: cpdata.target, datasetId: Potree.settings.originDatasetId })
  76527. */
  76528. var position = new Vector3().copy(cpdata.position);
  76529. var target = new Vector3().copy(cpdata.target);
  76530. var duration = cpdata.time;
  76531. var cp = animation.createControlPoint(null, {
  76532. position,
  76533. target,
  76534. duration
  76535. });
  76536. }
  76537. }
  76538. animation.changeCallback();
  76539. viewer.scene.addCameraAnimation(animation);
  76540. return animation;
  76541. },
  76542. removeAnimation(animation) {
  76543. animation.dispatchEvent('dispose');
  76544. viewer.scene.removeCameraAnimation(animation);
  76545. }
  76546. };
  76547. var clickPanoToDisLink = false; //是否在编辑漫游点连接时,通过点击漫游点能断开连接
  76548. var images360, Alignment$1, SiteModel$1, suggestCircleMat;
  76549. var texLoader$c = new TextureLoader();
  76550. texLoader$c.crossOrigin = "anonymous";
  76551. var rotQua = new Quaternion().setFromAxisAngle(new Vector3(0, 0, 1), Math.PI);
  76552. var lineMats$3 = {};
  76553. var circleMats = {};
  76554. var renderOrders$1 = {
  76555. circleSelected: 3,
  76556. circle: 2,
  76557. line: 1
  76558. };
  76559. var pointColor = {
  76560. /* selected:"#c80",
  76561. default:'#1ac' */
  76562. selected: "#c60",
  76563. default: '#17c'
  76564. };
  76565. var opacitys = {
  76566. //点云透明度
  76567. 'topView': {
  76568. default: 0.4,
  76569. selected: 0.6
  76570. },
  76571. 'sideView': {
  76572. //侧面重叠概率高
  76573. default: 0.2,
  76574. selected: 0.5
  76575. }
  76576. }; //调这么低是因为有的重叠边缘太亮了
  76577. var cameraProps$2 = [{
  76578. name: 'top',
  76579. axis: ["x", "y"],
  76580. direction: new Vector3(0, 0, -1),
  76581. //镜头朝向
  76582. openCount: 0
  76583. }, {
  76584. name: 'right',
  76585. axis: ["y", "z"],
  76586. direction: new Vector3(1, 0, 0),
  76587. openCount: 0
  76588. }, {
  76589. name: 'mainView',
  76590. openCount: 0
  76591. }];
  76592. class PanoEditor extends EventDispatcher {
  76593. constructor() {
  76594. super();
  76595. this.panoGroup = [],
  76596. //分组
  76597. this.viewports = {}, this.panoLink = {}, this.panoMeshs = new Object3D(), this.lineMeshes = new Object3D();
  76598. this.views = {};
  76599. this.cameras = {};
  76600. this.orthoCamera = new OrthographicCamera(-100, 100, 100, 100, 0.01, 10000);
  76601. this.orthoCamera.up.set(0, 0, 1);
  76602. this.selectedPano;
  76603. this.selectedGroup;
  76604. this.operation;
  76605. this.visiblePanos = [];
  76606. this.suggestLines = [];
  76607. }
  76608. init() {
  76609. {
  76610. //init lineMats
  76611. lineMats$3.default = LineDraw.createFatLineMat({
  76612. color: '#eeeeee',
  76613. lineWidth: 2,
  76614. depthTest: false
  76615. });
  76616. lineMats$3.hovered = LineDraw.createFatLineMat({
  76617. color: '#00c8af',
  76618. lineWidth: 2,
  76619. depthTest: false
  76620. });
  76621. lineMats$3.selected = LineDraw.createFatLineMat({
  76622. color: '#00c8af',
  76623. lineWidth: 3,
  76624. depthTest: false
  76625. });
  76626. lineMats$3.suggestLink = LineDraw.createFatLineMat({
  76627. color: '#ff2222',
  76628. lineWidth: 4,
  76629. dashed: true,
  76630. depthTest: false
  76631. });
  76632. }
  76633. suggestCircleMat = new MeshBasicMaterial({
  76634. map: texLoader$c.load(Potree.resourcePath + '/textures/whiteCircle.png'),
  76635. color: '#ff2222',
  76636. transparent: true,
  76637. depthTest: false,
  76638. depthWrite: false
  76639. });
  76640. this.initViews();
  76641. /* {
  76642. this.box = new BoxVolume({
  76643. clip:true
  76644. })
  76645. this.box.clipTask = ClipTask['SHOW_INSIDE_Big' ]
  76646. this.box.name = "panoEditClipBox";
  76647. } */
  76648. viewer.addEventListener('allLoaded', () => {
  76649. images360 = viewer.images360;
  76650. Alignment$1 = viewer.modules.Alignment;
  76651. SiteModel$1 = viewer.modules.SiteModel;
  76652. this.panoMeshs.name = 'panoMeshs';
  76653. viewer.scene.scene.add(this.panoMeshs);
  76654. this.lineMeshes.name = 'lineMeshes';
  76655. viewer.scene.scene.add(this.lineMeshes);
  76656. Potree.settings.ifShowMarker = false;
  76657. {
  76658. this.transformControls = new TransformControls(viewer.mainViewport.camera, viewer.renderArea, {
  76659. dontHideWhenFaceCamera: true,
  76660. rotFullCircle: true
  76661. });
  76662. this.transformControls.setSize(1.5);
  76663. viewer.scene.scene.add(this.transformControls);
  76664. this.transformControls._gizmo.hideAxis = {
  76665. /* translate:['x','y'], */rotate: ['x', 'y', 'e']
  76666. };
  76667. this.transformControls.setRotateMethod(2);
  76668. this.fakeMarkerForTran = new Mesh(new BoxBufferGeometry(0.3, 0.3, 0.3), new MeshBasicMaterial({
  76669. color: "#FFFFFF",
  76670. opacity: 0.4,
  76671. transparent: true,
  76672. visible: false
  76673. })); //一个看不见的mesh,只是为了让transformControls移动点云
  76674. viewer.scene.scene.add(this.fakeMarkerForTran);
  76675. var afterMoveCircle = type => {
  76676. if (type == 'position') {
  76677. var moveVec = new Vector3().subVectors(this.fakeMarkerForTran.position, this.fakeMarkerForTran.oldState.position);
  76678. this.selectedClouds.forEach(cloud => Alignment$1.translate(cloud, moveVec));
  76679. } else {
  76680. var center = this.selectedPano.position;
  76681. var forward = new Vector3(0, 1, 0);
  76682. var vec1 = forward.clone().applyQuaternion(this.fakeMarkerForTran.oldState.quaternion);
  76683. var vec2 = forward.clone().applyQuaternion(this.fakeMarkerForTran.quaternion);
  76684. var diffAngle = math.getAngle(vec1, vec2, 'z');
  76685. this.selectedClouds.forEach(cloud => {
  76686. Alignment$1.rotateAround(center, cloud, null, diffAngle);
  76687. });
  76688. }
  76689. this.fakeMarkerForTran.oldState = {
  76690. position: this.fakeMarkerForTran.position.clone(),
  76691. quaternion: this.fakeMarkerForTran.quaternion.clone()
  76692. };
  76693. Alignment$1.history.beforeChange(this.selectedClouds);
  76694. };
  76695. this.fakeMarkerForTran.addEventListener('position_changed', afterMoveCircle.bind(this, 'position'));
  76696. this.fakeMarkerForTran.addEventListener("rotation_changed", afterMoveCircle.bind(this, 'rotation'));
  76697. this.transformControls.addEventListener('mouseUp', () => {
  76698. Alignment$1.history.afterChange(this.selectedClouds);
  76699. });
  76700. Alignment$1.history.addEventListener('undo', () => {
  76701. this.updateTranCtl();
  76702. });
  76703. }
  76704. this.initPanoLink();
  76705. this.addPanoMesh();
  76706. viewer.scene.pointclouds.forEach(e => {
  76707. e.material.color = pointColor.default;
  76708. });
  76709. viewer.setEDLEnabled(true); //为了降一倍的绘制. 同时用描边增强立体感,弥补点云稀疏
  76710. viewer.setEDLRadius(3);
  76711. viewer.setEDLStrength(0.02);
  76712. this.switchView('top');
  76713. {
  76714. //默认选择一个楼层
  76715. var panoVisiReady, siteModelReady;
  76716. var floorInit = () => {
  76717. if (!panoVisiReady || !siteModelReady) return;
  76718. setTimeout(() => {
  76719. if (this.currentFloor == 'all') {
  76720. //还未选择楼层的话
  76721. var floor = SiteModel$1.entities.find(e => e.buildType == 'floor' && e.panos.length); //选择有漫游点的一层
  76722. if (!floor) {
  76723. floor = 'all'; //SiteModel.entities.find(e=>e.buildType == 'floor')
  76724. console.log('没有一层有漫游点?!');
  76725. }
  76726. console.log('initDataDone');
  76727. console.log('gotoFloor 1');
  76728. this.gotoFloor(floor);
  76729. }
  76730. }, 1); //2d那边用了nextTick ,so setTimeout here
  76731. };
  76732. SiteModel$1.bus.addEventListener('initDataDone', () => {
  76733. siteModelReady = true;
  76734. floorInit();
  76735. }, {
  76736. once: true
  76737. });
  76738. this.addEventListener('panoVisiReady', () => {
  76739. //2d初始化完成,才可以由3d修改pano显示 (因为在之前2d会给每个pano传来显示的消息,在这之前的修改都会别覆盖)
  76740. panoVisiReady = true;
  76741. floorInit();
  76742. }, {
  76743. once: true
  76744. });
  76745. }
  76746. Alignment$1.bus.addEventListener('switchHandle', this.updateCursor.bind(this));
  76747. viewer.addEventListener('global_click', e => {
  76748. if (e.button === MOUSE.RIGHT) {
  76749. //取消旋转和平移
  76750. //console.log('right click',e)
  76751. this.setLinkOperateState('addLink', false);
  76752. this.setLinkOperateState('removeLink', false);
  76753. } else if (this.clickToZoomInEnabled) {
  76754. if (this.activeViewName == 'mainView') {
  76755. viewer.controls.zoomToLocation(e.mouse);
  76756. } else {
  76757. this.zoomIn(e.intersect.orthoIntersect, e.pointer);
  76758. }
  76759. this.setZoomInState(false);
  76760. }
  76761. });
  76762. /* {//旋转时的辅助线--绕某个点旋转的版本
  76763. this.rotGuideLine = LineDraw.createLine([], {color:'#aaffee'})
  76764. this.rotGuideLine.visible = false
  76765. this.rotGuideLine.name = 'rotGuideLine'
  76766. this.rotGuideLine.renderOrder = renderOrders.line
  76767. viewer.scene.scene.add(this.rotGuideLine)
  76768. let startPoint
  76769. Alignment.bus.addEventListener('rotateStart', (e)=>{
  76770. startPoint = e.startPoint
  76771. })
  76772. Alignment.bus.addEventListener('rotate', (e)=>{
  76773. LineDraw.updateLine(this.rotGuideLine, [startPoint, e.endPoint] )
  76774. this.rotGuideLine.visible = true
  76775. })
  76776. viewer.fpControls.addEventListener("end",(e)=>{
  76777. startPoint = null
  76778. this.rotGuideLine.visible = false
  76779. })
  76780. } */
  76781. {
  76782. //连接时的辅助线
  76783. this.linkGuideLine = LineDraw.createLine([], {
  76784. color: '#ddd',
  76785. deshed: true,
  76786. dashSize: 0.1,
  76787. gapSize: 0.05,
  76788. depthTest: false
  76789. });
  76790. this.linkGuideLine.visible = false;
  76791. this.linkGuideLine.name = 'linkGuideLine';
  76792. viewer.scene.scene.add(this.linkGuideLine);
  76793. this.linkGuideLine.renderOrder = renderOrders$1.line;
  76794. var update = e => {
  76795. if (this.operation != 'addLink' || this.activeViewName != 'top' && this.activeViewName != 'mainView' || !this.selectedPano) {
  76796. return this.linkGuideLine.visible = false;
  76797. }
  76798. var endPos;
  76799. if (this.activeViewName == 'top') {
  76800. endPos = e.intersect.orthoIntersect.clone().setZ(this.selectedPano.position.z);
  76801. } else if (this.activeViewName == 'mainView') {
  76802. if (!e.intersect || !e.intersect.point) return;
  76803. endPos = e.intersect.point.position;
  76804. }
  76805. LineDraw.updateLine(this.linkGuideLine, [this.selectedPano.position, endPos]);
  76806. this.linkGuideLine.visible = true;
  76807. viewer.dispatchEvent('content_changed');
  76808. };
  76809. viewer.addEventListener('global_mousemove', e => {
  76810. update(e);
  76811. });
  76812. //this.addEventListener('updateLinkGuideLine', update)
  76813. }
  76814. /*
  76815. viewer.inputHandler.addEventListener('keydown', (e)=>{
  76816. if(e.event.key == "r" ){
  76817. this.setTranMode('rotate')
  76818. }else if(e.event.key == "t"){
  76819. this.setTranMode('translate')
  76820. }
  76821. }) */
  76822. /* {
  76823. viewer.addEventListener('camera_changed', (e)=>{
  76824. Common.intervalTool.isWaiting('updatePointLevels', ()=>{
  76825. this.updatePointLevels()
  76826. }, 1050)
  76827. })
  76828. setTimeout(()=>{
  76829. this.updatePointLevels()
  76830. }, viewer.scene.pointclouds.length*150) //等待差不多updat出了正确的visibleNode时
  76831. } */
  76832. this.panoReposCallback = () => {
  76833. viewer.controls.setTarget(this.selectedPano.position); //3d时绕其为中心转动
  76834. };
  76835. });
  76836. }
  76837. setTranMode(mode) {
  76838. //rotate or translate
  76839. console.log('setTranMode', mode);
  76840. this.tranMode = mode;
  76841. if (this.activeViewName == 'mainView') {
  76842. mode && this.transformControls.setMode(mode);
  76843. this.updateTranCtl();
  76844. } else {
  76845. Alignment$1.switchHandle(mode);
  76846. }
  76847. this.updateIntersectEnable();
  76848. }
  76849. updateIntersectEnable() {
  76850. //侧面容易因intersect卡住, 如果非必要关闭intersect. 3d页面也会卡,但controls需要所以不能去掉
  76851. Potree.settings.intersectWhenHover = !!(this.activeViewName == 'mainView' || this.selectedPano && this.tranMode);
  76852. }
  76853. updateTranCtl() {
  76854. // 设置3D页面的transformControls相关
  76855. if (!this.tranMode || !this.selectedPano || this.activeViewName != 'mainView') {
  76856. return this.transformControls.detach();
  76857. } else if (this.checkIfAllLinked({
  76858. group: this.selectedGroup
  76859. })) {
  76860. this.dispatchEvent('needToDisConnect');
  76861. return this.transformControls.detach();
  76862. }
  76863. this.transformControls.attach(this.fakeMarkerForTran);
  76864. var {
  76865. position,
  76866. quaternion
  76867. } = this.getPanoPose(this.selectedPano);
  76868. this.fakeMarkerForTran.position.copy(position);
  76869. this.fakeMarkerForTran.quaternion.copy(quaternion);
  76870. this.fakeMarkerForTran.oldState = {
  76871. position: position.clone(),
  76872. quaternion: quaternion.clone()
  76873. };
  76874. }
  76875. //////////////////////////////////
  76876. initViews() {
  76877. this.splitScreenTool = new SplitScreen();
  76878. this.targetPlane = viewer.mainViewport.targetPlane = new Plane();
  76879. this.shiftTarget = viewer.mainViewport.shiftTarget = new Vector3(); //project在targetPlane上的位置
  76880. for (var i = 0; i < 2; i++) {
  76881. var prop = cameraProps$2[i];
  76882. var view = new ExtendView();
  76883. this.views[prop.name] = view;
  76884. this.cameras[prop.name] = this.orthoCamera;
  76885. view.name = prop.name;
  76886. view.direction = prop.direction;
  76887. }
  76888. this.views.mainView = viewer.mainViewport.view;
  76889. this.cameras.mainView = viewer.mainViewport.camera;
  76890. }
  76891. switchView(name) {
  76892. //替换view和camera到mainViewport
  76893. var view = this.views[name];
  76894. var camera = this.cameras[name];
  76895. var prop = cameraProps$2.find(e => e.name == name);
  76896. var {
  76897. boundSize,
  76898. center
  76899. } = viewer.bound;
  76900. this.lastViewName = this.activeViewName;
  76901. this.activeViewName = name;
  76902. var lastView = this.views[this.lastViewName];
  76903. var lastCamera = this.cameras[this.lastViewName];
  76904. viewer.mainViewport.view = view;
  76905. viewer.mainViewport.camera = camera;
  76906. if (lastCamera) lastView.zoom = lastCamera.zoom;
  76907. this.targetPlane.setFromNormalAndCoplanarPoint(view.direction.clone(), center);
  76908. this.targetPlane.projectPoint(view.position, this.shiftTarget); //target转换到过模型中心的平面,以保证镜头一定在模型外
  76909. view.position.copy(this.splitScreenTool.getPosOutOfModel(viewer.mainViewport));
  76910. if (view.zoom) camera.zoom = view.zoom; //恢复上次的zoom
  76911. viewer.updateScreenSize({
  76912. forceUpdateSize: true
  76913. }); //更新camera aspect left等
  76914. this.updateCursor();
  76915. if (name == 'mainView') {
  76916. viewer.mainViewport.alignment = null;
  76917. var changeMat = () => {
  76918. viewer.scene.pointclouds.forEach(e => {
  76919. e.material.activeAttributeName = 'rgba';
  76920. e.material.useFilterByNormal = false;
  76921. e.changePointOpacity(1);
  76922. });
  76923. };
  76924. /* if(prop.openCount == 0){ //点数较多时,首次转到3D视角会卡顿,因为要切换材质。
  76925. let delay1 = THREE.Math.clamp(viewer.scene.pointclouds.length*0.5, 1, 200)
  76926. setTimeout(()=>{
  76927. this.activeViewName == 'mainView' && changeMat()
  76928. },delay1)
  76929. //console.log('switchview',delay1 )
  76930. }else{ */
  76931. changeMat();
  76932. //}
  76933. Potree.Utils.updateVisible(viewer.reticule, 'force', true);
  76934. if (lastView) {
  76935. //2d->3d
  76936. view.copy(lastView);
  76937. var direction = view.direction;
  76938. var panos = images360.panos.filter(e => e.circle.visible);
  76939. var nearestPano = Common.sortByScore(panos, [], [pano => {
  76940. var vec = new Vector3().subVectors(pano.position, view.position);
  76941. return -vec.dot(direction);
  76942. }], true);
  76943. //console.log('最近',nearestPano )
  76944. if (nearestPano && nearestPano[0]) {
  76945. //尽量不变画面范围,使pano点保持原位,转换到mainView
  76946. var halfHeight = lastCamera.top / lastCamera.zoom;
  76947. var dis = halfHeight / Math.tan(MathUtils.degToRad(camera.fov / 2));
  76948. view.position.add(direction.clone().multiplyScalar(-nearestPano[0].score - dis));
  76949. //console.log('getCloser', -nearestPano[0].score - dis)
  76950. this.lastDisToPano = dis; //记录一下
  76951. }
  76952. }
  76953. viewer.fpControls.lockKey = false;
  76954. } else {
  76955. if (this.lastViewName == 'mainView') {
  76956. //3d->2d
  76957. var _direction = lastView.direction;
  76958. var _panos = images360.panos.filter(e => e.circle.visible);
  76959. //尽量靠近画布中心,且距离相机较近
  76960. var _nearestPano = Common.sortByScore(_panos, [], [pano => {
  76961. var vec = new Vector3().subVectors(pano.position, lastView.position);
  76962. var dis = vec.dot(_direction);
  76963. return dis < 0 ? dis * 10 : -dis;
  76964. }, pano => {
  76965. var vec = new Vector3().subVectors(pano.position, lastView.position);
  76966. var angle = vec.angleTo(_direction);
  76967. return -angle * 70;
  76968. }], true);
  76969. //目前还存在的问题就是不知selectedPano和最近点的取舍
  76970. //console.log('panos',nearestPano )
  76971. if (_nearestPano && _nearestPano[0]) {
  76972. //console.log('nearestPano',nearestPano[0].item.id )
  76973. var pos1 = _nearestPano[0].item.position.clone();
  76974. var pos2 = pos1.clone();
  76975. var _dis = new Vector3().subVectors(_nearestPano[0].item.position, lastView.position).dot(_direction); //-nearestPano[0].score
  76976. //根据2d->3d的式子逆求zoom
  76977. var _halfHeight = Math.abs(_dis) * Math.tan(MathUtils.degToRad(lastCamera.fov / 2));
  76978. camera.zoom = camera.top / _halfHeight;
  76979. camera.updateProjectionMatrix();
  76980. if (name == 'right') {
  76981. //侧视图
  76982. view.direction = _direction.clone().setZ(0); //水平方向设定为3d的方向
  76983. this.targetPlane.setFromNormalAndCoplanarPoint(view.direction.clone(), center);
  76984. this.targetPlane.projectPoint(view.position, this.shiftTarget); //target转换到过模型中心的平面,以保证镜头一定在模型外
  76985. view.position.copy(this.splitScreenTool.getPosOutOfModel(viewer.mainViewport));
  76986. }
  76987. view.applyToCamera(camera); //update
  76988. pos1.project(lastCamera);
  76989. pos2.project(camera);
  76990. //目标是找到画面上最接近中心的一点(最好是漫游点,不然就是点云),让其在转换画面后在画面上的位置不变。万一找到的点不在屏幕中(比如当屏幕中没点云时),就默认让那个点移动到屏幕中央,也就是假设当前它pos1在屏幕中央位置。
  76991. //
  76992. if (pos1.z > 1) {
  76993. console.warn('选取的点在相机背后了!?');
  76994. }
  76995. //如果最近点超出屏幕范围 (-1,1), 最好将其拉到边缘,甚至居中 。这样屏幕上就不会没有漫游点了
  76996. var bound = 0.9;
  76997. pos1.x = MathUtils.clamp(pos1.x, -bound, bound);
  76998. pos1.y = MathUtils.clamp(pos1.y, -bound, bound);
  76999. var vecOnscreen = new Vector3().subVectors(pos1, pos2);
  77000. var moveVec = Potree.Utils.getOrthoCameraMoveVec(vecOnscreen, camera);
  77001. //console.log('pos1', pos1)
  77002. view.position.sub(moveVec);
  77003. }
  77004. } else {
  77005. if (prop.openCount == 0) {
  77006. //至多执行一次
  77007. this.viewportFitBound(name, boundSize, center);
  77008. }
  77009. }
  77010. viewer.scene.pointclouds.forEach(e => {
  77011. e.material.activeAttributeName = 'color';
  77012. e.material.useFilterByNormal = true;
  77013. var opaProp = name == 'top' ? opacitys.topView : opacitys.sideView;
  77014. if (this.selectedPano && this.selectedClouds.includes(e)) {
  77015. e.changePointOpacity(opaProp.selected, true);
  77016. e.material.color = pointColor.selected;
  77017. } else {
  77018. e.changePointOpacity(opaProp.default, true);
  77019. e.material.color = pointColor.default;
  77020. }
  77021. });
  77022. Potree.Utils.updateVisible(viewer.reticule, 'force', false);
  77023. if (name == 'top') viewer.mainViewport.alignment = {
  77024. rotate: true,
  77025. translate: true
  77026. };
  77027. if (name == 'right') {
  77028. viewer.mainViewport.alignment = {
  77029. translate: true,
  77030. rotateSide: true,
  77031. translateVec: new Vector3(0, 0, 1)
  77032. }; //只能上下移动
  77033. viewer.mainViewport.rotateSide = true;
  77034. } else {
  77035. viewer.mainViewport.rotateSide = false;
  77036. }
  77037. viewer.fpControls.lockKey = true;
  77038. }
  77039. this.updateTranCtl();
  77040. this.setTranMode(this.tranMode); // update
  77041. this.setZoomInState(false); //取消放大模式
  77042. //this.updatePointLevels()
  77043. this.updateIntersectEnable();
  77044. prop.openCount++;
  77045. }
  77046. viewportFitBound() {
  77047. //使一个viewport聚焦在某个范围
  77048. if (viewer.mainViewport.resolution.x == 0 || viewer.mainViewport.resolution.y == 0) {
  77049. return setTimeout(() => {
  77050. this.viewportFitBound();
  77051. }, 10);
  77052. }
  77053. this.gotoFloor(this.currentFloor, true, 0, null, true);
  77054. }
  77055. rotateSideCamera(angle) {
  77056. //侧视图绕模型中心水平旋转
  77057. this.splitScreenTool.rotateSideCamera(viewer.mainViewport, angle);
  77058. }
  77059. zoomIn(intersect, pointer) {
  77060. var camera = viewer.mainViewport.camera;
  77061. var endZoom = 200;
  77062. //this.orthoMoveFit(intersect, {endZoom:viewer.mainViewport.camera.zoom < aimZoom ? aimZoom : null} , 300)
  77063. var startZoom = camera.zoom;
  77064. if (startZoom >= endZoom) {
  77065. return;
  77066. }
  77067. viewer.mainViewport.view.zoomOrthoCamera(camera, endZoom, pointer, 300);
  77068. }
  77069. orthoMoveFit(pos, info, duration) {
  77070. var margin = {
  77071. x: 200,
  77072. y: 230
  77073. };
  77074. this.splitScreenTool.viewportFitBound(viewer.mainViewport, info.bound, pos, duration, margin);
  77075. }
  77076. setZoomInState(state, informinformBy2d) {
  77077. //是否点击后可放大
  77078. //if(state && this.activeViewName == 'mainView')return console.log('3D不可放大')
  77079. this.clickToZoomInEnabled = !!state;
  77080. if (state) {
  77081. viewer.dispatchEvent({
  77082. type: "CursorChange",
  77083. action: "add",
  77084. name: "zoomInCloud"
  77085. });
  77086. } else {
  77087. viewer.dispatchEvent({
  77088. type: "CursorChange",
  77089. action: "remove",
  77090. name: "zoomInCloud"
  77091. });
  77092. }
  77093. if (!state && !informinformBy2d) {
  77094. this.dispatchEvent({
  77095. type: 'operationCancel',
  77096. operation: 'zoomIn'
  77097. });
  77098. }
  77099. }
  77100. gotoFloor(floor, force) {
  77101. var duration = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 600;
  77102. var informBy2d = arguments.length > 3 ? arguments[3] : undefined;
  77103. var fitBound = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
  77104. // 选择不同楼层, 切换点位显示。 'all'为全部显示
  77105. floor = floor || 'all';
  77106. if (this.currentFloor == floor && !force) return;
  77107. if (this.currentFloor != floor) {
  77108. //如果楼层没变,不修改可视
  77109. //let pointclouds = viewer.findPointcloudsAtFloor(floor)
  77110. var panos = floor == 'all' ? viewer.images360.panos : floor.panos;
  77111. viewer.images360.panos.forEach(pano => {
  77112. var v = panos.includes(pano);
  77113. this.switchPanoVisible(pano, v);
  77114. });
  77115. }
  77116. this.updateLinesVisible();
  77117. //切换楼层时清空选择状态
  77118. if (this.selectedPano && floor != 'all' && !floor.panos.includes(this.selectedPano)) {
  77119. this.selectedPano.circle.dispatchEvent('click');
  77120. }
  77121. if (this.selectedLine) {
  77122. this.selectedLine.dispatchEvent('click');
  77123. }
  77124. var bound, center;
  77125. if (floor == 'all') {
  77126. bound = viewer.images360.bound.bounding;
  77127. center = viewer.images360.bound.center;
  77128. } else {
  77129. bound = this.getPanosBound(floor);
  77130. center = bound.getCenter(new Vector3());
  77131. if (floor.panos.length == 0) console.log(floor.name, 'floor无漫游点');
  77132. }
  77133. if (this.activeViewName != 'mainView') {
  77134. fitBound && this.orthoMoveFit(center, {
  77135. bound
  77136. }, duration);
  77137. } else if (this.activeViewName == 'mainView') {
  77138. //if(floor != 'all'){ //切换一下位置,因为原处点云会消失
  77139. //viewer.scene.view.setView({position:center, duration })
  77140. viewer.focusOnObject({
  77141. boundingBox: bound
  77142. }, 'boundingBox');
  77143. //}
  77144. }
  77145. this.currentFloor = floor;
  77146. //if(!informBy2d){ //注释原因:2d居然不会自己变
  77147. this.dispatchEvent({
  77148. type: 'changeFloor',
  77149. floor
  77150. });
  77151. //}
  77152. }
  77153. getPanosBound(floor) {
  77154. if (!floor.panosBound) {
  77155. if (floor.panos.length == 0) {
  77156. floor.panosBound = viewer.images360.bound.bounding.clone();
  77157. } else {
  77158. var minSize = new Vector3(10, 10, 10);
  77159. var bound = math.getBoundByPoints(floor.panos.map(e => e.position), minSize);
  77160. floor.panosBound = bound.bounding;
  77161. }
  77162. }
  77163. return floor.panosBound;
  77164. }
  77165. switchPanoVisible(pano, v, informBy2d) {
  77166. //console.log(pano.id,v)
  77167. Potree.Utils.updateVisible(pano.circle, 'panoEditor', v);
  77168. Potree.Utils.updateVisible(pano, 'panoEditor', v);
  77169. Potree.Utils.updateVisible(pano.pointcloud, 'panoEditor', v);
  77170. if (v) {
  77171. this.visiblePanos.includes(pano) || this.visiblePanos.push(pano);
  77172. } else {
  77173. var index = this.visiblePanos.indexOf(pano);
  77174. index > -1 && this.visiblePanos.splice(index, 1);
  77175. }
  77176. if (informBy2d) {
  77177. this.dispatchEvent('panoVisiReady');
  77178. this.updateLinesVisible();
  77179. }
  77180. informBy2d || this.dispatchEvent({
  77181. type: "switchPanoVisible",
  77182. pano,
  77183. v
  77184. });
  77185. /* {
  77186. setTimeout(()=>{
  77187. Common.intervalTool.isWaiting('updatePointLevels2', ()=>{
  77188. this.updatePointLevels()
  77189. }, 50)
  77190. },1)//等update过visibleNodes
  77191. } */
  77192. }
  77193. updateLinesVisible() {
  77194. this.lineMeshes.children.forEach(line => {
  77195. var names = line.name.split('-');
  77196. var pano0 = images360.getPano(names[0]);
  77197. var pano1 = images360.getPano(names[1]);
  77198. line.visible = this.visiblePanos.includes(pano0) || this.visiblePanos.includes(pano1);
  77199. });
  77200. }
  77201. updateCursor() {
  77202. var cursor;
  77203. if (this.activeViewName == 'mainView' || !this.selectedPano) {
  77204. cursor = null;
  77205. } else {
  77206. cursor = Alignment$1.handleState;
  77207. }
  77208. if (cursor == 'rotate') {
  77209. viewer.dispatchEvent({
  77210. type: "CursorChange",
  77211. action: "add",
  77212. name: "rotatePointcloud"
  77213. });
  77214. viewer.dispatchEvent({
  77215. type: "CursorChange",
  77216. action: "remove",
  77217. name: "movePointcloud"
  77218. });
  77219. } else if (cursor == 'translate') {
  77220. viewer.dispatchEvent({
  77221. type: "CursorChange",
  77222. action: "add",
  77223. name: "movePointcloud"
  77224. });
  77225. viewer.dispatchEvent({
  77226. type: "CursorChange",
  77227. action: "remove",
  77228. name: "rotatePointcloud"
  77229. });
  77230. } else {
  77231. viewer.dispatchEvent({
  77232. type: "CursorChange",
  77233. action: "remove",
  77234. name: "movePointcloud"
  77235. });
  77236. viewer.dispatchEvent({
  77237. type: "CursorChange",
  77238. action: "remove",
  77239. name: "rotatePointcloud"
  77240. });
  77241. }
  77242. //this.cursorState = cursor
  77243. }
  77244. setLinkOperateState(name, state, informinformBy2d) {
  77245. if (state && name == this.operation || !state && name != this.operation) return;
  77246. var old = this.operation;
  77247. this.operation = state ? name : null;
  77248. if (this.operation == 'removeLink') {
  77249. if (this.selectedLine) {
  77250. this.selectedLine.dispatchEvent('click'); //删除
  77251. }
  77252. if (this.selectedPano && clickPanoToDisLink) {
  77253. this.selectedPano.circle.dispatchEvent('click'); //删除
  77254. }
  77255. }
  77256. if (this.operation != 'addLink') {
  77257. this.linkGuideLine.visible = false;
  77258. }
  77259. if (!state && !informinformBy2d) {
  77260. this.dispatchEvent({
  77261. type: "operationCancel",
  77262. operation: old
  77263. });
  77264. }
  77265. if (this.operation == 'addLink') {
  77266. viewer.dispatchEvent({
  77267. type: "CursorChange",
  77268. action: "add",
  77269. name: "connectPano"
  77270. });
  77271. } else {
  77272. viewer.dispatchEvent({
  77273. type: "CursorChange",
  77274. action: "remove",
  77275. name: "connectPano"
  77276. });
  77277. }
  77278. if (this.operation == 'removeLink') {
  77279. viewer.dispatchEvent({
  77280. type: "CursorChange",
  77281. action: "add",
  77282. name: "disconnectPano"
  77283. });
  77284. } else {
  77285. viewer.dispatchEvent({
  77286. type: "CursorChange",
  77287. action: "remove",
  77288. name: "disconnectPano"
  77289. });
  77290. }
  77291. viewer.dispatchEvent('content_changed');
  77292. }
  77293. /////////////////////////////////
  77294. initPanoLink() {
  77295. images360.panos.forEach(pano => {
  77296. this.panoLink[pano.id] = {};
  77297. this.panoGroup.push([pano]);
  77298. });
  77299. images360.panos.forEach(pano => {
  77300. pano.visibles.forEach(index => {
  77301. //visibles中存的是下标!
  77302. this.linkChange(pano, images360.getPano(index, 'index'), 'add');
  77303. });
  77304. });
  77305. //console.log('panoLink',this.panoLink)
  77306. }
  77307. linkChange(pano0, pano1, type) {
  77308. //修改link (type == 'remove'时,pano1可以为空)
  77309. var temp = [];
  77310. if (type == 'add') {
  77311. if (!pano1) return console.error('不支持add时pano1为空');
  77312. this.panoLink[pano0.id][pano1.id] = this.panoLink[pano0.id][pano1.id] || {};
  77313. this.panoLink[pano1.id][pano0.id] = this.panoLink[pano1.id][pano0.id] || {};
  77314. } else {
  77315. if (!pano1) {
  77316. for (var id in this.panoLink[pano0.id]) {
  77317. if (this.panoLink[pano0.id][id]) {
  77318. this.panoLink[id][pano0.id] = false;
  77319. temp.push(id);
  77320. }
  77321. }
  77322. this.panoLink[pano0.id] = {}; //全部断连
  77323. } else {
  77324. this.panoLink[pano0.id][pano1.id] = false;
  77325. this.panoLink[pano1.id][pano0.id] = false;
  77326. }
  77327. }
  77328. if (!pano1) {
  77329. //全部断连
  77330. temp.forEach(id => {
  77331. this.lineChange(pano0, images360.getPano(id), type);
  77332. });
  77333. } else {
  77334. this.lineChange(pano0, pano1, type);
  77335. }
  77336. this.groupChange(pano0, pano1, type);
  77337. //this.updateSelectGroup()
  77338. this.selectPano(this.selectedPano, false, true); //更新选中点云显示
  77339. }
  77340. lineChange(pano0, pano1, type) {
  77341. //修改line
  77342. if (type == 'add') {
  77343. if (this.panoLink[pano0.id][pano1.id].line) return;
  77344. var line = LineDraw.createFatLine([pano0.position, pano1.position], {
  77345. mat: lineMats$3.default
  77346. });
  77347. line.name = "".concat(pano0.id, "-").concat(pano1.id);
  77348. line.renderOrder = line.pickOrder = renderOrders$1.line;
  77349. this.lineMeshes.add(line);
  77350. this.panoLink[pano0.id][pano1.id].line = this.panoLink[pano1.id][pano0.id].line = line;
  77351. line.addEventListener('mouseover', () => {
  77352. if (this.clickToZoomInEnabled) return;
  77353. //if(this.activeViewName == 'mainView')return
  77354. if (this.selectedLine != line) line.material = lineMats$3.hovered;
  77355. viewer.dispatchEvent({
  77356. type: "CursorChange",
  77357. action: "add",
  77358. name: "hoverLine"
  77359. });
  77360. });
  77361. line.addEventListener('mouseleave', () => {
  77362. if (this.clickToZoomInEnabled) return;
  77363. //if(this.activeViewName == 'mainView')return
  77364. if (this.selectedLine != line) line.material = lineMats$3.default;
  77365. viewer.dispatchEvent({
  77366. type: "CursorChange",
  77367. action: "remove",
  77368. name: "hoverLine"
  77369. });
  77370. });
  77371. line.addEventListener('click', e => {
  77372. if (this.clickToZoomInEnabled) return;
  77373. //if(this.activeViewName == 'mainView')return
  77374. if (this.operation == 'removeLink') {
  77375. if (this.selectedLine == line) this.selectLine(null);
  77376. return this.linkChange(pano0, pano1, 'remove');
  77377. }
  77378. this.selectLine(line);
  77379. });
  77380. } else {
  77381. var _line = this.lineMeshes.children.find(e => e.name == "".concat(pano0.id, "-").concat(pano1.id) || e.name == "".concat(pano1.id, "-").concat(pano0.id));
  77382. if (_line) {
  77383. this.lineMeshes.remove(_line);
  77384. _line.geometry.dispose();
  77385. }
  77386. }
  77387. }
  77388. groupChange(pano0, pano1, type) {
  77389. //修改group (type == 'remove'时,pano1可以为空)
  77390. if (type == 'add') {
  77391. Common.pushToGroupAuto([pano0, pano1], this.panoGroup);
  77392. } else {
  77393. var atGroup = this.panoGroup.find(e => e.includes(pano0) && (e.includes(pano1) || !pano1)); //所在组
  77394. if (!atGroup) {
  77395. if (pano1) {
  77396. console.log('这两个pano原本就不在一个组', pano0.id, pano1.id);
  77397. } else {
  77398. console.log('pano0不在任何组', pano0);
  77399. }
  77400. return;
  77401. }
  77402. //断开连接时,因为组内没有其他成员的连接信息,所以需要清除整组,并将剩余的一个个重新连接
  77403. this.panoGroup.splice(this.panoGroup.indexOf(atGroup), 1); //删除
  77404. atGroup.forEach(pano => {
  77405. //然后再重新生成这两个和组的关系,各自分组
  77406. this.panoGroup.push([pano]);
  77407. for (var id in this.panoLink[pano.id]) {
  77408. if (this.panoLink[pano.id][id]) {
  77409. var pano_ = images360.getPano(id);
  77410. Common.pushToGroupAuto([pano, pano_], this.panoGroup);
  77411. }
  77412. }
  77413. });
  77414. }
  77415. }
  77416. selectLine(line) {
  77417. if (this.selectedLine == line) return;
  77418. if (this.selectedLine) {
  77419. this.selectedLine.material = lineMats$3.default;
  77420. }
  77421. if (line) {
  77422. line.material = lineMats$3.selected;
  77423. }
  77424. this.selectedLine = line;
  77425. }
  77426. addPanoMesh() {
  77427. var map = texLoader$c.load(Potree.resourcePath + '/textures/correct_n.png');
  77428. /* circleMats.default_normal = new THREE.MeshBasicMaterial({
  77429. map,
  77430. color: 0xffffff,
  77431. transparent: true,
  77432. depthTest: false,
  77433. depthWrite: false,
  77434. }) */
  77435. window.circleMats = circleMats;
  77436. circleMats.default_normal = new DepthBasicMaterial({
  77437. map,
  77438. color: 0xffffff,
  77439. transparent: true,
  77440. useDepth: true,
  77441. backColor: 0x33ffdd,
  77442. occlusionDistance: 10,
  77443. //变为backColor距离
  77444. clipDistance: 5,
  77445. //消失距离
  77446. maxClipFactor: 0.8,
  77447. maxOcclusionFactor: 0.8
  77448. });
  77449. circleMats.default_rtk_on = circleMats.default_normal.clone();
  77450. circleMats.default_rtk_on.map = texLoader$c.load(Potree.resourcePath + '/textures/rtk-y-n.png');
  77451. circleMats.default_rtk_off = circleMats.default_normal.clone();
  77452. circleMats.default_rtk_off.map = texLoader$c.load(Potree.resourcePath + '/textures/rtk-f-n.png');
  77453. circleMats.selected_normal = circleMats.default_normal.clone();
  77454. circleMats.selected_normal.map = texLoader$c.load(Potree.resourcePath + '/textures/correct_s.png');
  77455. circleMats.selected_normal.useDepth = false;
  77456. circleMats.selected_rtk_on = circleMats.selected_normal.clone();
  77457. circleMats.selected_rtk_on.map = texLoader$c.load(Potree.resourcePath + '/textures/rtk-y-s.png');
  77458. circleMats.selected_rtk_off = circleMats.selected_normal.clone();
  77459. circleMats.selected_rtk_off.map = texLoader$c.load(Potree.resourcePath + '/textures/rtk-f-s.png');
  77460. circleMats.hovered_normal = circleMats.default_normal.clone();
  77461. circleMats.hovered_normal.color.set(0x00ff00);
  77462. circleMats.hovered_normal.useDepth = false;
  77463. circleMats.hovered_rtk_on = circleMats.default_rtk_on.clone();
  77464. circleMats.hovered_rtk_on.color.set(0x00ff00);
  77465. circleMats.hovered_rtk_on.useDepth = false;
  77466. circleMats.hovered_rtk_off = circleMats.default_rtk_off.clone();
  77467. circleMats.hovered_rtk_off.color.set(0x00ff00);
  77468. circleMats.hovered_rtk_off.useDepth = false;
  77469. var setPos = circle => {
  77470. circle.position.copy(circle.pano.position);
  77471. for (var id in this.panoLink[circle.pano.id]) {
  77472. var linkInfo = this.panoLink[circle.pano.id][id];
  77473. if (linkInfo) {
  77474. LineDraw.updateLine(linkInfo.line, [circle.pano.position, images360.getPano(id).position]);
  77475. }
  77476. }
  77477. circle.waitUpdate(); //update sprite Matrix
  77478. };
  77479. images360.panos.forEach(pano => {
  77480. var circle = new Sprite$2({
  77481. mat: circleMats['default' + '_' + this.getPanoRtkState(pano)],
  77482. sizeInfo: {
  77483. minSize: 50,
  77484. maxSize: 120,
  77485. nearBound: 2,
  77486. farBound: 10
  77487. },
  77488. renderOrder: renderOrders$1.circle,
  77489. pickOrder: renderOrders$1.circle
  77490. });
  77491. circle.pickDontCheckDis = true;
  77492. circle.name = 'panoCircle';
  77493. circle.sid = pano.id;
  77494. circle.pano = pano;
  77495. pano.circle = circle;
  77496. this.panoMeshs.add(circle);
  77497. setPos(circle);
  77498. pano.addEventListener('rePos', setPos.bind(this, circle));
  77499. var drag = e => {
  77500. /* if(this.activeViewName == 'mainView' && this.tranMode == 'translate'){//如果3d页不禁止xy的话,这段打开
  77501. this.transformControls.dispatchEvent('dragging')//触发拖拽
  77502. return
  77503. } */
  77504. if (this.tranMode != 'translate' || this.activeViewName == 'mainView') return e.refuse();
  77505. this.selectPano(circle.pano); //为了方便拖拽点云,拖动circle就直接选中
  77506. viewer.inputHandler.drag.object = null; //取消拖拽状态,否则不触发点云拖动
  77507. };
  77508. circle.addEventListener('drag', drag);
  77509. circle.addEventListener('mouseover', () => {
  77510. this.hoverPano(pano, true);
  77511. });
  77512. circle.addEventListener('mouseleave', () => {
  77513. this.hoverPano(pano, false);
  77514. });
  77515. circle.addEventListener('click', () => {
  77516. //if(this.activeViewName == 'mainView')return
  77517. if (this.clickToZoomInEnabled) return;
  77518. if (clickPanoToDisLink && this.operation == 'removeLink') {
  77519. this.linkChange(pano, null, 'remove'); //删除所有连接
  77520. }
  77521. if (this.selectedPano == circle.pano) return this.selectPano(null);
  77522. if (this.operation == 'addLink' && this.selectedPano) {
  77523. this.linkChange(this.selectedPano, circle.pano, 'add');
  77524. //this.setLinkOperateState('addLink',false)
  77525. return;
  77526. }
  77527. //if(this.operation == 'removeLink' && this.selectedPano){ //和选择中心点冲突
  77528. // this.linkChange(this.selectedPano, circle.pano, 'remove')
  77529. // //this.setLinkOperateState('removeLink',false)
  77530. // return
  77531. // }
  77532. this.selectPano(circle.pano);
  77533. });
  77534. });
  77535. }
  77536. hoverPano(pano, state) {
  77537. if (this.clickToZoomInEnabled) return;
  77538. if (pano && state) {
  77539. //在hover一个pano之前,一定会先取消已经hover的pano, 最多存在一个hovered的pano
  77540. if (this.hoveredPano == pano) return;
  77541. if (this.hoveredPano) {
  77542. this.hoverPano(this.hoveredPano, false);
  77543. }
  77544. this.hoveredPano = pano;
  77545. pano.hovered = true;
  77546. if ( /* this.activeViewName == 'mainView' || */Alignment$1.handleState && this.selectedPano && this.selectedPano == pano) return;
  77547. if (this.operation != 'addLink' || !this.selectedPano || this.selectedPano == pano) {
  77548. // this.selectedPano == pano?
  77549. viewer.dispatchEvent({
  77550. type: "CursorChange",
  77551. action: "add",
  77552. name: "hoverPano"
  77553. });
  77554. }
  77555. if (this.selectedPano != pano) pano.circle.material = circleMats['hovered' + '_' + this.getPanoRtkState(pano)];
  77556. } else if (pano && !state) {
  77557. //unhover
  77558. if (this.hoveredPano != pano) return;
  77559. pano.hovered = false;
  77560. viewer.dispatchEvent({
  77561. type: "CursorChange",
  77562. action: "remove",
  77563. name: "hoverPano"
  77564. });
  77565. if (this.selectedPano != pano) pano.circle.material = circleMats['default' + '_' + this.getPanoRtkState(pano)];
  77566. this.hoveredPano = null;
  77567. } else {
  77568. //unhover any
  77569. if (this.hoveredPano) {
  77570. this.hoverPano(this.hoveredPano, false);
  77571. }
  77572. }
  77573. }
  77574. selectPano(pano, informinformBy2d, force) {
  77575. if (this.selectedPano == pano && !force) return;
  77576. var lastSeletedPano = this.selectedPano;
  77577. var opaProp = this.activeViewName == 'top' ? opacitys.topView : opacitys.sideView;
  77578. if (this.selectedPano) {
  77579. this.selectedPano.circle.material = circleMats['default' + '_' + this.getPanoRtkState(this.selectedPano)];
  77580. this.selectedPano.circle.renderOrder = renderOrders$1.circle;
  77581. this.selectedPano.removeEventListener('rePos', this.panoReposCallback);
  77582. if (this.activeViewName == 'mainView') {} else {
  77583. this.selectedClouds.forEach(e => {
  77584. e.changePointOpacity(opaProp.default, true);
  77585. e.material.color = pointColor.default;
  77586. });
  77587. }
  77588. }
  77589. this.selectedPano = pano || null;
  77590. this.updateSelectGroup();
  77591. if (pano) {
  77592. this.selectedPano.circle.material = circleMats['selected' + '_' + this.getPanoRtkState(this.selectedPano)];
  77593. this.selectedPano.circle.renderOrder = this.selectedPano.circle.pickOrder = renderOrders$1.circleSelected; //侧视图能显示在最前
  77594. viewer.controls.setTarget(this.selectedPano.position); //3d时绕其为中心转动
  77595. this.selectedPano.addEventListener('rePos', this.panoReposCallback);
  77596. if (this.activeViewName == 'mainView') {} else {
  77597. this.selectedClouds.forEach(e => {
  77598. e.changePointOpacity(opaProp.selected, true);
  77599. e.material.color = pointColor.selected;
  77600. });
  77601. }
  77602. if (this.currentFloor != 'all') {
  77603. //如果原本不是展示全部楼层的话,自动切换楼层
  77604. var atFloor = SiteModel$1.entities.find(e => e.buildType == 'floor' && e.panos.includes(pano));
  77605. if (!atFloor) {
  77606. atFloor = 'all';
  77607. } else {}
  77608. this.gotoFloor(atFloor, false, 600);
  77609. }
  77610. } else {
  77611. viewer.controls.setTarget(null);
  77612. }
  77613. this.updateCursor();
  77614. this.updateTranCtl();
  77615. if (informinformBy2d) {
  77616. if (this.selectedPano) {
  77617. if (this.activeViewName == 'mainView') {
  77618. //平移,focus选中的pano
  77619. var distance = this.lastDisToPano || 5;
  77620. if (lastSeletedPano) {
  77621. distance = viewer.mainViewport.camera.position.distanceTo(lastSeletedPano.position);
  77622. }
  77623. viewer.focusOnObject({
  77624. position: this.selectedPano.position
  77625. }, 'point', null, {
  77626. distance
  77627. });
  77628. } else {
  77629. this.orthoMoveFit(this.selectedPano.position, {}, 500);
  77630. }
  77631. }
  77632. } else {
  77633. this.dispatchEvent({
  77634. type: 'panoSelect',
  77635. pano
  77636. });
  77637. }
  77638. this.updateIntersectEnable();
  77639. viewer.dispatchEvent('content_changed');
  77640. }
  77641. /* updatePointLevels(){
  77642. if(this.pauseUpdateLevels)return
  77643. let maxBudget = Potree.config.pointDensity.panoEdit.pointBudget
  77644. let visiCount1 = viewer.scene.pointclouds.filter(e=>e.visible).length
  77645. let visiCount2 = viewer.scene.pointclouds.filter(e=>e.visibleNodes.length>0).length //屏幕范围内可见的个数
  77646. let maxCount = 200, minCount = 1, minPer = 0.45 , maxPer = 1
  77647. let percent1 = maxPer - ( maxPer - minPer) * THREE.Math.clamp((visiCount1 - minCount) / (maxCount - minCount),0,1)
  77648. let percent2 = maxPer - ( maxPer - minPer) * THREE.Math.clamp((visiCount2 - minCount) / (maxCount - minCount),0,1)
  77649. let percent = percent1*percent2
  77650. if(this.activeViewName == 'mainView' ){
  77651. //假设每个pointcloud所带的点个数大致相同,那么当可见点云个数越多,所能展示的level越低,否则因总个数超过budget的话密度会参差不齐。
  77652. //pointcloud.changePointSize()
  77653. //console.log('updatePointLevels', percent, visiCount)
  77654. Potree.settings.UserDensityPercent = Math.sqrt(percent2)
  77655. viewer.setPointBudget(maxBudget * percent2)
  77656. }else{
  77657. Potree.settings.UserDensityPercent = 1
  77658. viewer.setPointBudget(maxBudget * percent)
  77659. }
  77660. viewer.setPointBudget(maxBudget * percent)
  77661. viewer.setPointLevels()
  77662. //侧面容易卡顿,但和显示的点数无关,似乎是因加载点云多而卡?为何正面不会
  77663. //console.warn('setPointBudget', Potree.pointBudget, visiCount1,visiCount2, Potree.settings.UserDensityPercent)
  77664. } */
  77665. getPanoRtkState(pano) {
  77666. return pano.panosData.has_rtk ? pano.rtkState ? 'rtk_on' : 'rtk_off' : 'normal';
  77667. }
  77668. setPanoRtkState(pano, state) {
  77669. pano.rtkState = state;
  77670. pano.circle.material = circleMats[(this.selectedPano == pano ? 'selected' : 'default') + '_' + this.getPanoRtkState(pano)];
  77671. }
  77672. updateSelectGroup() {
  77673. //更新选中的组
  77674. this.selectedGroup = this.panoGroup.find(e => e.includes(this.selectedPano));
  77675. if (this.selectedGroup) {
  77676. this.selectedGroup = [this.selectedPano, ...this.selectedGroup.filter(e => e != this.selectedPano)]; //将选中的放第一个,便于旋转时绕其旋转。
  77677. }
  77678. //this.selectedClouds = this.selectedPano ? (this.selectedGroup || [this.selectedPano]).map(e=>e.pointcloud) : []
  77679. this.selectedClouds = this.selectedPano ? this.selectedGroup.map(e => e.pointcloud) : [];
  77680. }
  77681. checkIfCanSave() {
  77682. //如果未全部相连,不能保存
  77683. for (var datasetId in Potree.settings.datasetsPanos) {
  77684. if (!this.checkIfAllLinked({
  77685. datasetId
  77686. })) {
  77687. console.log('没有全部连通,不能保存。其中一个:', datasetId);
  77688. return;
  77689. }
  77690. }
  77691. return true;
  77692. }
  77693. checkIfAllLinked(o) {
  77694. //某个(or组所在的)数据集是否全部连通
  77695. var datasetId, group;
  77696. if (o.group) {
  77697. group = o.group;
  77698. var pano = o.group[0];
  77699. if (!pano) return; //会有没有漫游点的点云来编辑吗
  77700. datasetId = pano.pointcloud.dataset_id;
  77701. } else if (o.datasetId) {
  77702. datasetId = o.datasetId;
  77703. group = this.panoGroup.find(panos => panos[0].pointcloud.dataset_id == datasetId);
  77704. if (!group) return; //要找的数据集的pano全部都孤立了
  77705. }
  77706. if (datasetId == void 0) return;
  77707. var panos = Potree.settings.datasetsPanos[datasetId].panos;
  77708. return panos.length == group.length;
  77709. }
  77710. getSuggestLinkPanos() {
  77711. var _this = this;
  77712. //给出建议连接的点
  77713. var panos = [];
  77714. var startTime = Date.now();
  77715. var _loop = function _loop(datasetId) {
  77716. if (!_this.checkIfAllLinked({
  77717. datasetId
  77718. })) {
  77719. var groups = _this.panoGroup.filter(panos => panos[0].pointcloud.dataset_id == datasetId);
  77720. groups = groups.sort((a, b) => {
  77721. return b.length - a.length;
  77722. }); //找出个数最多的一组来连接其他组
  77723. var mainGroup = groups[0].slice(),
  77724. subGroup;
  77725. for (var i = 1, len = groups.length; i < len; i++) {
  77726. subGroup = groups[i];
  77727. var minDis = {
  77728. dis: Infinity,
  77729. panos: []
  77730. };
  77731. for (var a = 0, len1 = mainGroup.length; a < len1; a++) {
  77732. for (var b = 0, len2 = subGroup.length; b < len2; b++) {
  77733. var dis = mainGroup[a].position.distanceToSquared(subGroup[b].position);
  77734. if (dis < minDis.dis) {
  77735. minDis.dis = dis;
  77736. minDis.panos = [mainGroup[a], subGroup[b]];
  77737. }
  77738. }
  77739. }
  77740. panos.push(minDis.panos);
  77741. //console.log('第i次',minDis)
  77742. mainGroup.push(...subGroup); //连接后,加入集合
  77743. }
  77744. }
  77745. };
  77746. for (var datasetId in Potree.settings.datasetsPanos) {
  77747. _loop(datasetId);
  77748. }
  77749. //console.log('cost', Date.now() - startTime)
  77750. return panos;
  77751. }
  77752. showSuggestLinkPanos() {
  77753. var groups = this.getSuggestLinkPanos();
  77754. var s = 0.7;
  77755. var createCircle = pano => {
  77756. var circle = new Mesh(pano.circle.geometry, suggestCircleMat);
  77757. circle.name = 'suggest-circle';
  77758. circle.scale.set(s, s, s);
  77759. circle.renderOrder = 100;
  77760. pano.circle.add(circle);
  77761. };
  77762. groups.forEach(panos => {
  77763. createCircle(panos[0]);
  77764. createCircle(panos[1]);
  77765. var line = LineDraw.createFatLine([panos[0].position, panos[1].position], {
  77766. mat: lineMats$3.suggestLink
  77767. });
  77768. this.suggestLines.push(line);
  77769. line.renderOrder = renderOrders$1.line;
  77770. viewer.scene.scene.add(line);
  77771. });
  77772. }
  77773. getPanoPose(pano) {
  77774. var pose = {
  77775. position: pano.position.clone(),
  77776. quaternion: new Quaternion().setFromRotationMatrix(pano.panoMatrix).premultiply(rotQua)
  77777. };
  77778. return pose;
  77779. }
  77780. exportSavingData() {
  77781. //输出漫游点新的坐标和朝向、以及连接信息
  77782. var sweepLocations = {};
  77783. for (var datasetId in Potree.settings.datasetsPanos) {
  77784. var {
  77785. panos
  77786. } = Potree.settings.datasetsPanos[datasetId];
  77787. var data = panos.map(pano => {
  77788. var visibles = [];
  77789. for (var id in this.panoLink[pano.id]) {
  77790. if (this.panoLink[pano.id][id]) {
  77791. visibles.push(viewer.images360.getPano(id).index);
  77792. }
  77793. }
  77794. var {
  77795. position,
  77796. quaternion
  77797. } = this.getPanoPose(pano);
  77798. return Object.assign({}, pano.panosData, {
  77799. uuid: pano.uuid,
  77800. /* pose:{
  77801. translation: dealData(pano.position.clone() ),
  77802. rotation: dealData(new THREE.Quaternion().setFromRotationMatrix(pano.panoMatrix).premultiply(rotQua) ),
  77803. }, */
  77804. pose: {
  77805. translation: dealData(position),
  77806. rotation: dealData(quaternion)
  77807. },
  77808. visibles,
  77809. use_rtk: !!pano.rtkState
  77810. //subgroup: 0,group: 1, "id_view":..
  77811. });
  77812. });
  77813. sweepLocations[datasetId] = {
  77814. sweepLocations: data
  77815. };
  77816. }
  77817. /* this.lineMeshes.children.forEach(e=>{//从line中搜集连接信息,而不从linkInfo,这样visibles不会重复一次
  77818. let names = e.name.split('-') //是不是该转成数字
  77819. var pano0 = names[0]
  77820. var pano1 = names[1]
  77821. sweepLocations.find(s=>s.uuid == pano0).visibles.push(pano1)
  77822. }) */
  77823. function dealData(value) {
  77824. var v = math.toPrecision(value, 6);
  77825. if (v instanceof Quaternion) {
  77826. return {
  77827. x: v.x,
  77828. y: v.y,
  77829. z: v.z,
  77830. w: v.w
  77831. };
  77832. } else if (v instanceof Vector3) {
  77833. return {
  77834. x: v.x,
  77835. y: v.y,
  77836. z: v.z
  77837. };
  77838. }
  77839. }
  77840. //console.log(sweepLocations)
  77841. return sweepLocations;
  77842. }
  77843. }
  77844. /*
  77845. 不同数据集之间不能连线
  77846. 不同楼层可能也不能
  77847. 如果楼层在不同建筑物怎么办? 楼层切换按钮只能在一个建筑内切换。
  77848. 全部相连时不能移动和旋转
  77849. 如果未全部相连,不能保存
  77850. */
  77851. var PanoEditor$1 = new PanoEditor();
  77852. /*
  77853. import {Utils} from "../../../utils.js";
  77854. import Sprite from '../../objects/Sprite.js'
  77855. import browser from '../../utils/browser.js'
  77856. */
  77857. //import {Prism} from './Prism.js'
  77858. var maxWidth = 4096;
  77859. var surfaceThick = 0.1; //最大表面厚度
  77860. var pointDensity = 'screenshot';
  77861. var maxPointBudge = Potree.config.pointDensity[pointDensity].pointBudget;
  77862. var Shaders$1 = {
  77863. 'modelHeight.vs': " \n precision highp float;\n \n uniform vec2 boundZ;\n varying float heightPercent; \n \n\n float round(float number){\n return floor(number + 0.5);\n }\n \n \n \n \n \n void main() \n { \n vec3 worldPos = (modelMatrix * vec4(position, 1.0)).xyz; \n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); \n \n float zMin = boundZ.x, zMax = boundZ.y ;\n heightPercent = (worldPos.z - zMin) / (zMax - zMin); \n \n \n }\n \n \n ",
  77864. 'modelHeight.fs': "\n precision highp float;\n varying float heightPercent; \n \n \n \n \n vec3 percentToByte(float num){\n //\u8F93\u51FA\u662F0-1\uFF0C shader\u7CBE\u5EA6\u4E0D\u591F\uFF0C\u53EA\u591F\u5B583\u4E2A\u6570\uFF0C\u56E0\u7B2C\u56DB\u4F4D\u603B\u662F0\n float a = 1.0;\n float result[4];\n for(int i=0;i<3;i++){\n a = i == 2 ? a/255.0 : a / 256.0 ; \n //\u5206\u6210256\u4EFD\uFF0C\u5176\u4E2D255\u4EFD\u7ED9\u5F53\u524D\u4F4D\u7F6E\uFF0C\u6700\u540E\u4E00\u4EFD\u7ED9\u540E\u4E00\u4E2A\u4F4D\u7F6E\uFF0C\u800C\u5230\u4E86\u6700\u540E\u4E00\u4E2A\u4F4D\u7F6E\u65F6\u6CA1\u6709\u4E0B\u4E00\u4E2A\u4F4D\u7F6E\u4E86\u6240\u4EE5\u53EA\u5206\u6210255\u4EFD\n if(num > a){\n float c = num / a;\n float r = floor(c);\n r = min(255.0, r);\n result[i] = r;\n num -= r * a;\n }else{\n result[i] = 0.0;\n }\n } \n return vec3(result[0]/255.0, result[1]/255.0,result[2]/255.0); \n \n } \n \n \n void main() {\n \n gl_FragColor = vec4(percentToByte(heightPercent),1.0); \n \n \n }\n "
  77865. };
  77866. var horizonZ,
  77867. zMin,
  77868. zMax,
  77869. lowest,
  77870. highest,
  77871. wDelta,
  77872. sDelta,
  77873. deferred,
  77874. interrupt,
  77875. timestamp,
  77876. buffer1,
  77877. buffer2,
  77878. modelZs = [];
  77879. var testPoint$1 = false;
  77880. //const asyncTimeout = (delay) => new Promise(resolve => setTimeout(resolve, delay))
  77881. var delayForNotify = 5,
  77882. notifyInterval = 500;
  77883. var lastNotifyTime = Date.now();
  77884. var curPercent;
  77885. var notify = (areas, num, str) => {
  77886. //num: 0-1
  77887. return new Promise(resolve => {
  77888. if (!deferred) return resolve();
  77889. var now = Date.now();
  77890. if (now - lastNotifyTime < notifyInterval) {
  77891. return resolve();
  77892. }
  77893. lastNotifyTime = now;
  77894. if (num == void 0) {
  77895. num = curPercent;
  77896. } else {
  77897. var s = 0,
  77898. e = 1;
  77899. if (num instanceof Function) {
  77900. num = num();
  77901. }
  77902. areas.forEach(area => {
  77903. var s_ = e * area[0] + s * (1 - area[0]);
  77904. var e_ = e * area[1] + s * (1 - area[1]);
  77905. s = s_, e = e_;
  77906. });
  77907. var p = e * num + s * (1 - num);
  77908. str == 'loadpoints' && Potree.settings.isTest && console.log('notify pro', p, str);
  77909. deferred.notify(p);
  77910. curPercent = p;
  77911. if (isNaN(p)) {
  77912. console.log('nan');
  77913. }
  77914. }
  77915. setTimeout(resolve, delayForNotify);
  77916. });
  77917. };
  77918. class VolumeComputer extends EventDispatcher {
  77919. constructor() {
  77920. super();
  77921. this.camera = new OrthographicCamera(-100, 100, -100, 100, 0.01, 100);
  77922. this.camera.up.set(0, 0, 1);
  77923. Potree.Utils.setCameraLayers(this.camera, ['model']);
  77924. this.view = new ExtendView();
  77925. this.viewport = new Viewport(this.view, this.camera, {
  77926. left: 0,
  77927. bottom: 0,
  77928. width: 1,
  77929. height: 1
  77930. });
  77931. this.renderTarget = new WebGLRenderTarget(1, 1, {
  77932. minFilter: LinearFilter,
  77933. magFilter: NearestFilter,
  77934. format: RGBAFormat
  77935. });
  77936. this.renderTarget2 = new WebGLRenderTarget(1, 1, {
  77937. minFilter: LinearFilter,
  77938. magFilter: NearestFilter,
  77939. format: RGBAFormat
  77940. });
  77941. this.renderTarget2.texture.name = 'volumeCptModelTex';
  77942. this.material = new ExtendPointCloudMaterial();
  77943. this.material.activeAttributeName = testPoint$1 ? "rgba" : 'heightCpt'; // 'rgba' indices prismHeight
  77944. this.prisms = [];
  77945. this.modelMat = new ShaderMaterial({
  77946. uniforms: {
  77947. boundZ: {
  77948. type: "vec2",
  77949. value: new Vector2()
  77950. }
  77951. },
  77952. vertexShader: Shaders$1['modelHeight.vs'],
  77953. fragmentShader: Shaders$1['modelHeight.fs'],
  77954. depthWrite: true,
  77955. depthTest: true,
  77956. transparent: false,
  77957. side: DoubleSide
  77958. });
  77959. this.scene = new Scene();
  77960. }
  77961. init() {
  77962. viewer.scene.addEventListener('measurement_added', e => {
  77963. if (e.measurement.isPrism) this.add(e.measurement);
  77964. });
  77965. viewer.scene.addEventListener('measurement_removed', e => {
  77966. if (e.measurement.isPrism) this.remove(e.measurement);
  77967. });
  77968. var this_ = this;
  77969. this.events = {
  77970. transformCallback: () => {
  77971. if (!this_.currentPrism) return;
  77972. //Common.intervalTool.isWaiting('volCptTransformed', ()=>{ //延时update,防止卡顿
  77973. var object = viewer.transformationTool.selection[0];
  77974. if (object == this_.currentPrism.baseModel) {
  77975. this.updateModelBound({
  77976. modelChange: true
  77977. });
  77978. }
  77979. this_.currentPrism.dispatchEvent('needsCompute'); //模型变动或clipBox变动后要重算
  77980. //}, 1000)
  77981. }
  77982. };
  77983. }
  77984. enter() {
  77985. this.entered = true;
  77986. viewer.measuringTool.history.clear(); //避免撤销到测量线去
  77987. this.oldStates = {
  77988. rotAroundPoint: Potree.settings.rotAroundPoint
  77989. };
  77990. Potree.settings.rotAroundPoint = false;
  77991. //viewer.objs.traverse(e=>e.material && ( e.material = this.material))
  77992. viewer.transformationTool.addEventListener('stopDrag', this.events.transformCallback);
  77993. viewer.transformationTool.addEventListener('changeByHistory', this.events.transformCallback);
  77994. }
  77995. leave() {
  77996. this.entered = false;
  77997. Potree.settings.rotAroundPoint = this.oldStates.rotAroundPoint;
  77998. this.setCurrentPrism(null);
  77999. viewer.transformationTool.removeEventListener('stopDrag', this.events.transformCallback);
  78000. viewer.transformationTool.removeEventListener('changeByHistory', this.events.transformCallback);
  78001. }
  78002. add(prism) {
  78003. this.prisms.push(prism);
  78004. }
  78005. remove(prism) {
  78006. var i = this.prisms.indexOf(prism);
  78007. i > -1 && this.prisms.splice(i, 1);
  78008. }
  78009. cancel() {
  78010. if (this.computingObject) {
  78011. interrupt = true;
  78012. }
  78013. }
  78014. startCompute(model, dontCompute) {
  78015. //test
  78016. this.enter();
  78017. var deferred = $.Deferred();
  78018. deferred.done(e => {
  78019. console.log('done', e);
  78020. });
  78021. deferred.fail(e => {
  78022. console.log('?fail????', e);
  78023. });
  78024. /* deferred.progress((e)=>{
  78025. console.log('progress', e)
  78026. }) */
  78027. if (model) {
  78028. this.prisms[this.prisms.length - 1].setBaseModel(model);
  78029. this.setCurrentPrism(this.prisms[this.prisms.length - 1]);
  78030. dontCompute || this.compute(this.prisms[this.prisms.length - 1]);
  78031. } else {
  78032. this.compute(this.prisms[this.prisms.length - 1], deferred);
  78033. }
  78034. }
  78035. setCurrentPrism(prism) {
  78036. //当进入单个prism编辑后才会高亮点云
  78037. if (this.currentPrism) {
  78038. this.currentPrism.removeEventListeners('updated');
  78039. }
  78040. this.currentPrism = prism; //允许没有model
  78041. if (!prism || !prism.baseModel /* || !prism.baseModel.visible */) {
  78042. viewer.scene.pointclouds.forEach(e => {
  78043. this.updateMatForModel(e.material); //取消高亮
  78044. });
  78045. return;
  78046. }
  78047. prism.addEventListener('updated', () => {
  78048. if (this.currentPrism != prism) {
  78049. return console.log('currentPrism changed? 侦听没删除');
  78050. }
  78051. this.updateModelBound();
  78052. });
  78053. this.updateModelBound({
  78054. regetMap: true
  78055. });
  78056. }
  78057. setModelMat(model, type) {
  78058. if (type == 'recover') {
  78059. model.traverse(e => e.originMat_ && (e.material = e.originMat_));
  78060. } else {
  78061. model.traverse(e => e.material && e.material != this.modelMat && (e.originMat_ = e.material, e.material = this.modelMat));
  78062. }
  78063. }
  78064. updateModelBound() {
  78065. var {
  78066. modelChange,
  78067. regetMap
  78068. } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  78069. //regetMap是在更换currentPrism必须重绘map,但不需要needUpdate
  78070. var prism = this.currentPrism;
  78071. var model = this.currentPrism.baseModel;
  78072. if (!model) return;
  78073. model.currentBound = model.boundingBox.clone().applyMatrix4(model.matrixWorld); //作用同prismBound
  78074. var oldBound = model.clipBound && model.clipBound.clone();
  78075. model.clipBound = model.currentBound.clone(); //高亮范围
  78076. model.clipBound.min.max(prism.prismBound.min); //xy为交集
  78077. model.clipBound.max.min(prism.prismBound.max);
  78078. model.clipBound.min.z = Math.min(model.currentBound.min.z, prism.prismBound.min.z); //z为并集,范围覆盖prism点、点云、model三者
  78079. model.clipBound.max.z = Math.max(model.currentBound.max.z, prism.prismBound.max.z);
  78080. this.modelMat.uniforms.boundZ.value.set(model.clipBound.min.z, model.clipBound.max.z);
  78081. var boundChanged = !oldBound || !oldBound.equals(model.clipBound);
  78082. var boundSize = this.currentPrism.baseModel.clipBound.getSize(new Vector3());
  78083. this.boundSizeZero = boundSize.x <= 0 || boundSize.y <= 0 || boundSize.z <= 0; //会造成renderTarget尺寸为0,背景变白,报错:Framebuffer is incomplete: Attachment has zero size 和 The texture is a non-power-of-two texture.
  78084. if ((modelChange || regetMap || boundChanged) && !this.boundSizeZero) {
  78085. this.setModelHeightMap(); //包含cad在俯视中的范围 + 高度信息
  78086. //this.setModelMat(model,this.boundSizeZero ? 'recover' : null)
  78087. }
  78088. viewer.scene.pointclouds.forEach(e => {
  78089. //暂时先只支持一个高亮区域
  78090. this.updateMatForModel(e.material, model);
  78091. });
  78092. //需要重新渲染modelHeightmap的情况:bound改变、模型变动、更换currentPrism后
  78093. //注意,即使上传几种都没发生,仅仅移动prism的marker也要重算,假设一个marker在model范围内,移动后bound可能不变但体积肯定变。
  78094. /* if(boundChanged){
  78095. if(prism.recoverNeedCptNextTime){
  78096. prism.needsCompute = 'byVolume' //初始化,有volume就不用重算
  78097. prism.recoverNeedCptNextTime = false
  78098. }else{
  78099. prism.dispatchEvent('needsCompute')
  78100. }
  78101. } */
  78102. }
  78103. updateMatForModel(material, model) {
  78104. var oldMap = material.uniforms.baseHeightAreaMap.value;
  78105. if (model) {
  78106. material.uniforms.baseHeightAreaMap.value = this.renderTarget2.texture; //model.baseHeightAreaMap ;
  78107. material.uniforms.baseHeightBoundZ.value.set(model.clipBound.min.z, model.clipBound.max.z);
  78108. material.uniforms.baseHeightBoundXY.value.set(model.clipBound.min.x, model.clipBound.max.x, model.clipBound.min.y, model.clipBound.max.y);
  78109. } else {
  78110. material.uniforms.baseHeightAreaMap.value = null;
  78111. }
  78112. if (oldMap != material.uniforms.baseHeightAreaMap.value) {
  78113. material.shaderNeedsUpdate = true;
  78114. }
  78115. }
  78116. setModelHeightMap() {
  78117. var oldTarget = viewer.renderer.getRenderTarget();
  78118. var oldParent = this.currentPrism.baseModel.parent;
  78119. var oldVisi = this.currentPrism.baseModel.visible;
  78120. var boundSize = this.currentPrism.baseModel.clipBound.getSize(new Vector3());
  78121. var boundCenter = this.currentPrism.baseModel.clipBound.getCenter(new Vector3());
  78122. var {
  78123. w,
  78124. h
  78125. } = this.getResByBound(boundSize, 'forModel');
  78126. if (w <= 0 || h <= 0) {
  78127. return console.error('w<=0 || h<=0!!!!!!!!!', w, h);
  78128. }
  78129. /* w = THREE.Math.floorPowerOfTwo( w );
  78130. h = THREE.Math.floorPowerOfTwo( h ); */ //for warning:The texture is a non-power-of-two texture
  78131. this.camera.far = boundSize.z + 10;
  78132. this.camera.right = w / 2;
  78133. this.camera.left = -this.camera.right;
  78134. this.camera.top = h / 2;
  78135. this.camera.bottom = -this.camera.top;
  78136. this.viewport.resolution.set(w, h);
  78137. this.renderTarget2.setSize(w, h);
  78138. viewer.renderer.setRenderTarget(this.renderTarget2);
  78139. console.log('setModelHeightMap');
  78140. //最高处朝下看
  78141. var endPosition = new Vector3();
  78142. endPosition.copy(boundCenter).setZ(this.currentPrism.baseModel.clipBound.max.z + this.camera.near + 0.1);
  78143. this.view.pitch = -Math.PI / 2;
  78144. this.view.moveOrthoCamera(this.viewport, {
  78145. boundSize,
  78146. endPosition
  78147. }, 0);
  78148. this.view.applyToCamera(this.camera);
  78149. this.scene.add(this.currentPrism.baseModel);
  78150. this.setModelMat(this.currentPrism.baseModel);
  78151. this.currentPrism.baseModel.visible = true;
  78152. var gl = viewer.renderer.getContext();
  78153. viewer.renderer.setClearColor(new Color('#000'), 0);
  78154. viewer.renderer.clear();
  78155. viewer.renderer.render(this.scene, this.camera);
  78156. this.setModelMat(this.currentPrism.baseModel, 'recover');
  78157. var pixelCount = this.renderTarget2.width * this.renderTarget2.height;
  78158. buffer2 = new Uint8Array(4 * pixelCount);
  78159. //因为需要渲染完立即readPixels才能获取到,所以只能这时候就read了
  78160. gl.readPixels(0, 0, this.renderTarget2.width, this.renderTarget2.height, gl.RGBA, gl.UNSIGNED_BYTE, buffer2); //这句花费最多时间 pc:2-4, 即使只有1*1像素
  78161. modelZs = []; //等待计算
  78162. if (window.needDownload) {
  78163. var dataUrl = Potree.Utils.renderTargetToDataUrl(this.renderTarget2, this.renderTarget2.width, this.renderTarget2.height, viewer.renderer);
  78164. Common.downloadFile(dataUrl, (name || 'screenshot') + '-' + Date.now() + '.png');
  78165. }
  78166. oldParent.add(this.currentPrism.baseModel);
  78167. this.currentPrism.baseModel.visible = oldVisi;
  78168. viewer.renderer.setRenderTarget(oldTarget);
  78169. this.renderTarget2.texture.needsRebuild = true; //renderTarget在resize后会触发dispose, 然后 _gl.deleteTexture( textureProperties.__webglTexture )所以需要重新建立 否则图片变黑
  78170. return this.renderTarget2.texture;
  78171. }
  78172. getResByBound(boundSize, type) {
  78173. //let pxPerMetric = math.linearClamp(Math.max(boundSize.x,boundSize.y), [4, 10, 20, 80, 500, 2000], [300, 200, 100, 30, 6, 3])
  78174. var pxPerMetric = math.linearClamp(Math.max(boundSize.x, boundSize.y), [10, 60, 100, 500, 2000], [150, 60, 40, 6, 3]);
  78175. var w = pxPerMetric * boundSize.x,
  78176. h = boundSize.y * pxPerMetric;
  78177. var cW = 1,
  78178. cH = 1; //横向纵向渲染次数 超过maxWidth时分批渲染
  78179. if (w > maxWidth || h > maxWidth) {
  78180. /* if(){//多数据集判断是否间隔过远,是的话返回
  78181. } */
  78182. if (type == 'forCompute') {
  78183. //计算可以分多次渲染
  78184. cW = Math.ceil(w / maxWidth), cH = Math.ceil(h / maxWidth);
  78185. w /= cW, h /= cH;
  78186. } else if (type == 'forModel') {
  78187. //但是model的贴图只能有一个
  78188. if (w > h) {
  78189. w = maxWidth, h = w * boundSize.y / boundSize.x;
  78190. } else {
  78191. h = maxWidth, w = h * boundSize.x / boundSize.y;
  78192. }
  78193. }
  78194. }
  78195. w = Math.round(w);
  78196. h = Math.round(h);
  78197. return {
  78198. w,
  78199. h,
  78200. pxPerMetric,
  78201. cW,
  78202. cH
  78203. };
  78204. }
  78205. //法1:只用一个顶部相机(当挖方遮挡填方时不准,但好算)
  78206. async compute(prism, deferred_, getResolveResult) {
  78207. var _this = this;
  78208. if (!prism || prism.modelHaventLoad) {
  78209. console.log('prism有问题');
  78210. return deferred_.reject();
  78211. }
  78212. if (this.computingObject) return console.log('正在计算,请稍等');
  78213. var oldCurPrism = this.currentPrism;
  78214. if (prism != this.currentPrism) {
  78215. //在列表外点击计算
  78216. this.setCurrentPrism(prism);
  78217. }
  78218. var computeDone = (_ref, deferred) => {
  78219. var {
  78220. highest,
  78221. lowest,
  78222. Vupper,
  78223. Vlower
  78224. } = _ref;
  78225. prism && prism.setVolumeInfo({
  78226. highest,
  78227. lowest,
  78228. Vupper,
  78229. Vlower
  78230. });
  78231. if (oldCurPrism != prism) {
  78232. this.setCurrentPrism(oldCurPrism);
  78233. }
  78234. deferred && deferred.resolve(getResolveResult && getResolveResult());
  78235. };
  78236. if (prism.baseModel && this.boundSizeZero) {
  78237. //bound没有交集 或 prism的boundsize为0
  78238. return computeDone({
  78239. highest: 0,
  78240. lowest: 0,
  78241. Vupper: 0,
  78242. Vlower: 0
  78243. }, deferred_);
  78244. }
  78245. this.computingObject = {
  78246. prism,
  78247. model: prism.baseModel
  78248. };
  78249. deferred = deferred_;
  78250. var computeFinish = (debugStr, makeit) => {
  78251. makeit || deferred.reject(interrupt ? '主动取消' : debugStr || '');
  78252. this.computingObject = null;
  78253. deferred = null;
  78254. interrupt = false;
  78255. debugStr && console.log('computeFinish', debugStr);
  78256. Potree.settings.displayMode = statesBefore.mode;
  78257. Potree.settings.pointDensity = statesBefore.pointDensity;
  78258. viewer.renderer.setRenderTarget(null);
  78259. viewer.renderer.state.reset();
  78260. viewer.renderer.setScissorTest(false);
  78261. gl.disable(gl.SCISSOR_TEST);
  78262. viewer.screenshoting = false;
  78263. viewer.mainViewport.active = true;
  78264. viewer.mapViewer && (viewer.mapViewer.viewports[0].active = true);
  78265. viewer.magnifier.viewport.active = true;
  78266. viewer.pauseTestMaxLevel = false;
  78267. };
  78268. var pointcloud = viewer.scene.pointclouds[0];
  78269. var center = new Vector3();
  78270. var boundSize = new Vector3();
  78271. var bound;
  78272. var gl = viewer.renderer.getContext();
  78273. var statesBefore = {
  78274. mode: Potree.settings.displayMode,
  78275. pointDensity: Potree.settings.pointDensity
  78276. };
  78277. timestamp = Date.now();
  78278. if (!this.computingObject.model) {
  78279. horizonZ = prism.horizonZ;
  78280. zMin = prism.zMin;
  78281. zMax = prism.zMax;
  78282. bound = new Box3().copy(prism.prismBound);
  78283. /* for(let i=0;i<prism.points.length;i++){
  78284. bound.expandByPoint(prism.points[i])
  78285. } */
  78286. } else {
  78287. zMin = this.computingObject.model.clipBound.min.z;
  78288. zMax = this.computingObject.model.clipBound.max.z;
  78289. bound = this.computingObject.model.clipBound;
  78290. //读取model的高度
  78291. for (var u = 0; u < this.renderTarget2.width; u++) {
  78292. var col = [];
  78293. for (var v = 0; v < this.renderTarget2.height; v++) {
  78294. var offset = u + v * this.renderTarget2.width;
  78295. var rgb = buffer2.slice(4 * offset, 4 * offset + 3),
  78296. a = buffer2[4 * offset + 3];
  78297. if (a == 0) {
  78298. //无点
  78299. col.push(null);
  78300. } else {
  78301. var z = this.convertColorToHeight(rgb, zMin, zMax);
  78302. col.push(z);
  78303. }
  78304. }
  78305. modelZs.push(col);
  78306. }
  78307. }
  78308. lowest = zMax, highest = zMin; //init. to store pixel lowest and highest
  78309. bound.getCenter(center);
  78310. bound.getSize(boundSize);
  78311. this.boundSizeZero = boundSize.x <= 0 || boundSize.y <= 0 || this.computingObject.model && boundSize.z <= 0; //prism的问题
  78312. if (this.boundSizeZero) {
  78313. computeDone({
  78314. highest: 0,
  78315. lowest: 0,
  78316. Vupper: 0,
  78317. Vlower: 0
  78318. }, deferred);
  78319. return computeFinish('finish', true);
  78320. }
  78321. center.z = zMax + this.camera.near + 0.1;
  78322. this.camera.far = zMax - zMin + 10;
  78323. viewer.screenshoting = true;
  78324. viewer.pauseTestMaxLevel = true;
  78325. var {
  78326. w,
  78327. h,
  78328. pxPerMetric,
  78329. cW,
  78330. cH
  78331. } = this.getResByBound(boundSize, 'forCompute');
  78332. this.camera.right = w / 2;
  78333. this.camera.left = -this.camera.right;
  78334. this.camera.top = h / 2;
  78335. this.camera.bottom = -this.camera.top;
  78336. this.viewport.resolution.set(w, h);
  78337. this.renderTarget.setSize(w, h);
  78338. wDelta = boundSize.x / (w * cW);
  78339. sDelta = Math.pow(wDelta, 2);
  78340. //准备
  78341. Potree.settings.displayMode = 'showPointCloud';
  78342. Potree.settings.pointDensity = 'screenshot';
  78343. viewer.mainViewport.active = false; //暂停渲染,否则影响这边点云的加载
  78344. viewer.mapViewer && (viewer.mapViewer.viewports[0].active = false);
  78345. viewer.magnifier.viewport.active = false; //防止页面变白(似乎mainViewport被clear)
  78346. {
  78347. //material
  78348. if (!this.computingObject.model) {
  78349. //this.material.shape = Potree.PointShape.PARABOLOID;//加上之后depth出错,后排点云会挡前排,可pick时为什么不会?
  78350. this.updateMatForModel(this.material, null); //计算时的shader这两种类型只能选一个,要么prism要么model,只能渲染一块区域
  78351. //this.material.opacity = 1;
  78352. } else {
  78353. this.updateMatForModel(this.material, this.computingObject.model);
  78354. //this.material.opacity = 0.9; //为了输出透明度,负数高度的alpha是0.5
  78355. }
  78356. var clipBoxes_out = prism.clipBoxes.map(box => {
  78357. return {
  78358. inverse: box.matrixWorld.clone().invert(),
  78359. box
  78360. };
  78361. });
  78362. this.material.setClipBoxes(null, [], clipBoxes_out, [], [prism]);
  78363. this.material.pointSizeType = 'FIXED'; //'ADAPTIVE' //node会自动根据的其level更改点大小 使用ADAPTIVE后会使baseModelMap整片是黑的,原因未知
  78364. this.material.uniforms.minSize.value = 0.1;
  78365. this.material.uniforms.orthoMaxSize.value = 5; //px
  78366. this.material.classification = pointcloud.material.classification;
  78367. this.material.recomputeClassification();
  78368. this.material.shaderNeedsUpdate = true;
  78369. pointcloud.updateMaterial(this.material, null, this.camera, viewer.renderer, this.viewport.resolution);
  78370. this.material.size = 1; //this.getPointsize(pointcloud.maxLevel) //0.025 米 //视图缩小(截图面积变大)后点会自动缩小,但至少是1个像素大小
  78371. }
  78372. viewer.renderer.state.buffers.depth.setTest(this.material.depthTest);
  78373. viewer.renderer.state.buffers.depth.setMask(this.material.depthWrite);
  78374. viewer.renderer.state.setBlending(NoBlending); //只需要设置不透明即可(使alpha不混合,后方不会影响前方的alpha,否则输出的a通道将没法用)
  78375. var pixelCount = this.renderTarget.width * this.renderTarget.height;
  78376. buffer1 = new Uint8Array(4 * pixelCount);
  78377. viewer.renderer.setRenderTarget(this.renderTarget);
  78378. var results = [];
  78379. var boundSize_ = boundSize.clone();
  78380. boundSize_.x /= cW, boundSize_.y /= cH;
  78381. //分批渲染:从左到右 从下到上
  78382. var _loop = async function _loop(i) {
  78383. var _loop2 = async function _loop2(j) {
  78384. var infos = [];
  78385. var progressStart = (i * cH + j) / (cW * cH),
  78386. progressEnd = (i * cH + j + 1) / (cW * cH);
  78387. if (interrupt) {
  78388. return {
  78389. v: {
  78390. v: computeFinish('23')
  78391. }
  78392. };
  78393. }
  78394. Potree.settings.pointDensity = 'screenshot'; //恢复为nodeMaxLevel
  78395. //最高处朝下看,找挖方的顶部
  78396. _this.view.pitch = -Math.PI / 2;
  78397. var endPosition = new Vector3(center.x + (i - cW / 2 + 0.5) * boundSize_.x, center.y + (j - cH / 2 + 0.5) * boundSize_.y, center.z);
  78398. _this.view.moveOrthoCamera(_this.viewport, {
  78399. boundSize: boundSize_,
  78400. endPosition
  78401. }, 0);
  78402. var endPercent = _this.computingObject.model ? 0.7 : 0.4;
  78403. await _this.render({
  78404. i,
  78405. j,
  78406. index: 1,
  78407. cW,
  78408. cH,
  78409. infos,
  78410. /* maxLevels, */notifyArea: [[progressStart, progressEnd], [0, endPercent]],
  78411. computeFinish
  78412. });
  78413. if (interrupt) {
  78414. return {
  78415. v: {
  78416. v: computeFinish('2123')
  78417. }
  78418. };
  78419. }
  78420. if (!_this.computingObject.model) {
  78421. //水平面朝下看,找填方
  78422. _this.view.position.z = horizonZ + _this.camera.near;
  78423. await _this.render({
  78424. i,
  78425. j,
  78426. index: 2,
  78427. cW,
  78428. cH,
  78429. infos,
  78430. /* maxLevels, */notifyArea: [[progressStart, progressEnd], [0.4, 0.7]],
  78431. computeFinish
  78432. });
  78433. }
  78434. //水平面朝上看,找挖方的底部
  78435. /* this.view.position.z = horizonZ + surfaceThick //排除地面(水平面)上的点
  78436. this.view.pitch = Math.PI / 2;
  78437. await this.render({reverseRow:true,name:'第3张-'+i+'-'+j, infos, buffer,maxLevels }) */ //---土堆上有草地有厚度,还是去掉吧
  78438. var result = {
  78439. index: {
  78440. i,
  78441. j
  78442. },
  78443. allFills: [],
  78444. fillVupper: 0,
  78445. fillVlower: 0,
  78446. Vupper: 0,
  78447. Vlower: infos[1] ? infos[1].Vlower : infos[0].Vlower,
  78448. // >= infos[0].Vlower 因能找到被上方遮挡住的凹槽
  78449. allDiffHeights: [],
  78450. fillVupperCount: 0,
  78451. fillVlowerCount: 0,
  78452. infos
  78453. };
  78454. var waitFill = [];
  78455. waitFill.count = 0;
  78456. var isNeighbor = (a, b) => {
  78457. return Math.abs(a.u - b.u) <= 1 && Math.abs(a.v - b.v) <= 1;
  78458. };
  78459. var isBelongToGroup = (group, item) => {
  78460. if (item[0]) item = item[0];
  78461. var i = group.length;
  78462. while (--i >= 0) {
  78463. //从后往前
  78464. if (item.u - group[i].u > 1 && Math.abs(item.v - group[i].v) > 1) break; //距离超出,前面肯定不相邻了
  78465. if (isNeighbor(group[i], item)) {
  78466. return true;
  78467. }
  78468. }
  78469. };
  78470. //计算挖方(但是边缘附近垂直方向上很多点云,体积被削皮,最终得到的会比infos[0]少)
  78471. var getValue = (u, v) => {
  78472. //当到了左上边界是否需要向前几批的查找?
  78473. if (infos[0].allHeights[u] && infos[0].allHeights[u][v] != void 0) return infos[0].allHeights[u][v];
  78474. return result.allFills[u] && result.allFills[u][v];
  78475. };
  78476. var hasValue = (u, v) => {
  78477. //在边界内
  78478. return u >= 0 && u < infos[0].allHeights.length && v >= 0 && v < infos[0].allHeights[0].length;
  78479. };
  78480. var getFill = (u, v) => {
  78481. //使用周围的八个点的平均值补洞
  78482. var neighbours = [[-1, 0], [0, 1], [1, 0], [0, -1], [-1, -1], [1, -1], [-1, 1], [1, 1]]; //先左右右先上后下
  78483. var i = 0,
  78484. c = 0,
  78485. sum = 0;
  78486. while (c < 4 && i < 8) {
  78487. var x = neighbours[i][0] + u,
  78488. y = neighbours[i][1] + v;
  78489. if (hasValue(x, y)) {
  78490. var neigh = getValue(x, y);
  78491. if (neigh != void 0) {
  78492. c++;
  78493. sum += neigh;
  78494. } else if (i >= 3) {
  78495. //add 2024.5.27
  78496. if (c == 0) break; //节省时间,主要为了大片透明区域
  78497. }
  78498. }
  78499. i++;
  78500. }
  78501. if (c > 0) {
  78502. sum /= c;
  78503. result.allFills[u] || (result.allFills[u] = []);
  78504. result.allFills[u][v] = sum;
  78505. return sum;
  78506. }
  78507. };
  78508. var add = (v, fill, count) => {
  78509. if (v > 0) {
  78510. result.Vupper += v;
  78511. fill && (result.fillVupper += v, result.fillVupperCount += count);
  78512. } else {
  78513. //fill的话才会有
  78514. fill && (result.fillVlower -= v, result.fillVlowerCount += count);
  78515. }
  78516. };
  78517. var compute = async (u, v) => {
  78518. var top = infos[0].allHeights[u][v];
  78519. //let btm = infos[2].allHeights[u][v]
  78520. var fill;
  78521. if (top == void 0) {
  78522. if (prism) {
  78523. var x = endPosition.x - boundSize_.x / 2 + wDelta * (u + 0.5);
  78524. var y = endPosition.y - boundSize_.y / 2 + wDelta * (v + 0.5);
  78525. if (!math.isPointInArea(prism.points, null, {
  78526. x,
  78527. y
  78528. })) {
  78529. return; //出界
  78530. }
  78531. } else {
  78532. if (_this.getModelZByRes(u, v, cW, cH, i, j) == void 0) {
  78533. return; //出界
  78534. }
  78535. }
  78536. fill = true;
  78537. top = getFill(u, v);
  78538. if (top == void 0) {
  78539. //左侧边缘有缺口时会出现
  78540. if (waitFill.cancel || waitFill.count > 1000 && waitFill[waitFill.length - 1][waitFill[waitFill.length - 1].length - 1].u - waitFill[0][0].u > 4) {
  78541. //跨度超过4列
  78542. waitFill.cancel = true; //丢弃,不加入补洞, 降低耗时
  78543. } else {
  78544. Common.pushToGroupAuto([{
  78545. u,
  78546. v
  78547. }], waitFill, null, isBelongToGroup); //按邻近点分组
  78548. }
  78549. waitFill.count++; //当数量达到几万以上会在这个地方花很长时间,不过很少出现这种情况
  78550. return;
  78551. }
  78552. }
  78553. /* let diff = top-btm
  78554. let useDiff
  78555. if(btm != void 0 && diff > surfaceThick ){
  78556. useDiff = diff
  78557. result.allDiffHeights.push(useDiff)
  78558. }else{
  78559. useDiff = top //从顶部一直到水平
  78560. }*/
  78561. if (waitFill.length) {
  78562. //补 之前没有值的邻居重新获取
  78563. if (interrupt) {
  78564. return computeFinish('12312');
  78565. }
  78566. if (waitFill.cancel) {
  78567. //console.log('直接清空waitFill', waitFill.count, waitFill.map(list=>[list[0], list[list.length-1]]))
  78568. waitFill.count = 0;
  78569. waitFill.length = 0;
  78570. waitFill.cancel = false;
  78571. } else {
  78572. ///* //Potree.settings.isTest && */ waitFill.count>1000 && console.log('waitFill.count', waitFill.count, 'groupLen', waitFill.length, waitFill[0][0], waitFill[0][waitFill[0].length-1])
  78573. waitFill.slice().forEach(group => {
  78574. //每个组都看看是否跟它相邻
  78575. if (isBelongToGroup(group, {
  78576. u,
  78577. v
  78578. })) {
  78579. var index = waitFill.indexOf(group);
  78580. waitFill.splice(index, 1);
  78581. waitFill.count -= group.length;
  78582. group.forEach(e => {
  78583. result.allFills[e.u] || (result.allFills[e.u] = []);
  78584. result.allFills[e.u][e.v] = top; //该组全部都使用该体积
  78585. });
  78586. var sum = top * group.length;
  78587. add(sum, fill, group.length);
  78588. }
  78589. });
  78590. }
  78591. }
  78592. add(top, fill, 1);
  78593. };
  78594. var lastNotifyTime = Date.now();
  78595. //从左到右,从下到上一列列扫描
  78596. var _loop3 = async function _loop3(_u) {
  78597. for (var _v2 = 0; _v2 < _this.renderTarget.height; _v2++) {
  78598. //数据是从图的下到上存储的
  78599. if (interrupt) {
  78600. return {
  78601. v: {
  78602. v: {
  78603. v: computeFinish('1121')
  78604. }
  78605. }
  78606. };
  78607. }
  78608. compute(_u, _v2);
  78609. }
  78610. await notify([[progressStart, progressEnd], [0.7, 1]], () => {
  78611. return _u / _this.renderTarget.width;
  78612. }, 'compute');
  78613. },
  78614. _ret3;
  78615. for (var _u = 0; _u < _this.renderTarget.width; _u++) {
  78616. _ret3 = await _loop3(_u);
  78617. if (_ret3) return _ret3.v;
  78618. }
  78619. if (waitFill.length) {
  78620. console.log('waitFill怎么还有??', waitFill); //如果是模型的话是有剩的可能,当它的周围刚好是模型的hole时,就被断开在孤立的组里了,如"回"字型,中间的口是有model但无点云处,外面的口是无model处。
  78621. }
  78622. result.Vupper *= sDelta;
  78623. result.fillVlower *= sDelta;
  78624. result.fillVupper *= sDelta;
  78625. result.Vlower += result.fillVlower;
  78626. results.push(result);
  78627. deferred && deferred.notify(progressEnd);
  78628. },
  78629. _ret2;
  78630. for (var j = 0; j < cH; j++) {
  78631. _ret2 = await _loop2(j);
  78632. if (_ret2) return _ret2.v;
  78633. }
  78634. },
  78635. _ret;
  78636. for (var i = 0; i < cW; i++) {
  78637. _ret = await _loop(i);
  78638. if (_ret) return _ret.v;
  78639. }
  78640. var Vupper = 0,
  78641. Vlower = 0,
  78642. fillVlower = 0,
  78643. fillVupper = 0;
  78644. results.forEach(c => {
  78645. Vupper += c.Vupper;
  78646. Vlower += c.Vlower;
  78647. fillVlower += c.fillVlower;
  78648. fillVupper += c.fillVupper;
  78649. });
  78650. computeDone({
  78651. highest,
  78652. lowest,
  78653. Vupper,
  78654. Vlower
  78655. }, deferred);
  78656. computeFinish('finish', true);
  78657. console.log({
  78658. Vupper,
  78659. Vlower,
  78660. oldVupper: Vupper - fillVupper,
  78661. oldVlower: Vlower - fillVlower,
  78662. highest,
  78663. lowest,
  78664. horizonZ,
  78665. wDelta
  78666. }, results, this.viewport.resolution, {
  78667. cW,
  78668. cH
  78669. }, 'cost:', Date.now() - timestamp, 'pxPerMetric', pxPerMetric, 'boundSize', boundSize); //firefox用时是chrome两倍,edge和chrome差不多
  78670. }
  78671. getModelZByRes(u, v, cW, cH, wIndex, hIndex) {
  78672. //传入renderTarget2的像素index
  78673. //如果两个map的尺寸不同
  78674. var x = Math.round(wIndex / cW + u / this.renderTarget.width * this.renderTarget2.width);
  78675. var y = Math.round(hIndex / cH + v / this.renderTarget.height * this.renderTarget2.height);
  78676. var z0 = modelZs[x][y];
  78677. return z0;
  78678. //return modelZs[u][v]
  78679. }
  78680. async render() {
  78681. var _this2 = this;
  78682. var {
  78683. i,
  78684. j,
  78685. index,
  78686. cW,
  78687. cH,
  78688. reverseRow,
  78689. infos,
  78690. /* maxLevels, */notifyArea,
  78691. computeFinish
  78692. } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  78693. this.view.applyToCamera(this.camera);
  78694. Potree.updatePointClouds(viewer.scene.pointclouds, this.camera, this.viewport.resolution);
  78695. var gl = viewer.renderer.getContext();
  78696. var screenshot = name => {
  78697. //if(window.testScreen){
  78698. var dataUrl = Potree.Utils.renderTargetToDataUrl(this.renderTarget, this.renderTarget.width, this.renderTarget.height, viewer.renderer);
  78699. Common.downloadFile(dataUrl, (name || 'screenshot') + '-' + timestamp + '.png'); //为什么图片上不是只有pickWindowSize区域有颜色??
  78700. //}
  78701. };
  78702. var name = i + '-' + j + '-第' + index + '张';
  78703. console.log('开始渲染', name);
  78704. var camera = this.camera;
  78705. var viewport = this.viewport;
  78706. return new Promise((resolve, reject) => {
  78707. var done = async () => {
  78708. gl.clearColor(0, 0, 0, 0);
  78709. viewer.renderer.clear(true, true, true);
  78710. //viewer.pRenderer.renderOctree(pointcloud, nodes, this.camera, this.renderTarget ,{material:this.material});
  78711. viewer.pRenderer.render(viewer.scene.scenePointCloud, this.camera, this.renderTarget, {
  78712. material: this.material /* transparent:!this.computingObject.isPrism */
  78713. });
  78714. if (interrupt) {
  78715. return reject(), computeFinish('re 23');
  78716. }
  78717. Potree.settings.isTest && screenshot(name);
  78718. gl.readPixels(0, 0, this.renderTarget.width, this.renderTarget.height, gl.RGBA, gl.UNSIGNED_BYTE, buffer1); //这句花费最多时间 pc:2-4, 即使只有1*1像素
  78719. notifyArea.push([progressEnd1, 1]);
  78720. var Vupper = 0,
  78721. Vlower = 0;
  78722. var upperHeights = [],
  78723. lowerHeights = [],
  78724. allHeights = [];
  78725. var _loop4 = async function _loop4(u) {
  78726. var col = [];
  78727. for (var v = 0; v < _this2.renderTarget.height; v++) {
  78728. var _v = reverseRow ? _this2.renderTarget.height - v - 1 : v;
  78729. var offset = u + _v * _this2.renderTarget.width;
  78730. var rgb = buffer1.slice(4 * offset, 4 * offset + 3),
  78731. a = buffer1[4 * offset + 3];
  78732. if (a == 0 /* rgb[0] == 0 && rgb[1] == 0 && rgb[2] == 0 */) {
  78733. //无点
  78734. col.push(null);
  78735. } else {
  78736. var z = _this2.convertColorToHeight(rgb, zMin, zMax);
  78737. var h = void 0;
  78738. if (!_this2.computingObject.model) {
  78739. h = z - horizonZ;
  78740. } else {
  78741. //和baseModel标准面之间的高度差
  78742. /* if(a == 128){//负数
  78743. h = -h
  78744. } ///如果这个也要lowest 那需改shader ,shader不计算高度差
  78745. */
  78746. var z0 = _this2.getModelZByRes(u, v, cW, cH, i, j);
  78747. h = z - z0;
  78748. }
  78749. z < lowest && (lowest = z); //上表面最低点
  78750. z > highest && (highest = z); //上表面最高点
  78751. if (h > 0) {
  78752. Vupper += h;
  78753. upperHeights.push(h); //
  78754. } else {
  78755. Vlower += -h;
  78756. lowerHeights.push(h);
  78757. }
  78758. col.push(h);
  78759. }
  78760. if (interrupt) {
  78761. return {
  78762. v: (reject(), computeFinish('re 023'))
  78763. };
  78764. }
  78765. //notify(notifyArea, (u*this.renderTarget.height + v) /(this.renderTarget.width*this.renderTarget.height))
  78766. }
  78767. allHeights.push(col);
  78768. await notify(notifyArea, () => {
  78769. return u / _this2.renderTarget.width;
  78770. }, 'readPixels get');
  78771. },
  78772. _ret4;
  78773. for (var u = 0; u < this.renderTarget.width; u++) {
  78774. _ret4 = await _loop4(u);
  78775. if (_ret4) return _ret4.v;
  78776. }
  78777. Vupper *= sDelta;
  78778. Vlower *= sDelta;
  78779. infos.push({
  78780. Vupper,
  78781. Vlower,
  78782. sDelta,
  78783. upperHeights,
  78784. lowerHeights,
  78785. allHeights
  78786. });
  78787. resolve();
  78788. };
  78789. //let finish , maxTime = 1e6
  78790. var progressEnd1 = math.linearClamp(this.camera.zoom, [1, 1000], [0.8, 0.2]); //放得越大,实际加载的点云相对越少,费时越少
  78791. var notifyArea_ = [...notifyArea, [0, progressEnd1]];
  78792. if (Potree.pointsLoading) {
  78793. //如果有要加载的node
  78794. var curProgress = 0,
  78795. beginTime = Date.now(),
  78796. unloadBefore,
  78797. tryPreLoadTime = Math.round(math.linearClamp(buffer1.length / this.camera.zoom / this.camera.zoom, [50, 10000], [1000, 15000]));
  78798. //console.log('tryPreLoadTime',tryPreLoadTime)
  78799. var decreaseLevel = () => {
  78800. //降点云level
  78801. //暂时先都一起降1
  78802. var pointclouds = viewer.scene.pointclouds.filter(e => e.visibleNodes.length);
  78803. console.log('准备decreaseLevel, numVisiblePoints', Potree.numVisiblePoints, '最小numVisiblePoints占比', 1 / pointclouds.length);
  78804. pointclouds.forEach(e => {
  78805. var percent = e.numVisiblePoints / Potree.numVisiblePoints;
  78806. console.log('numVisiblePoints占总比', e.dataset_id, percent);
  78807. if (percent < 1 / pointclouds.length) return;
  78808. var old = e.maxLevel;
  78809. var levels = e.visibleNodes.map(e => e.getLevel());
  78810. var actMaxLevel = Math.max.apply(null, levels); //实际加载到的最高的node level
  78811. e.maxLevel = actMaxLevel - 1;
  78812. console.warn(e.dataset_id, 'decreaseLevel,新maxLevel', actMaxLevel - 1, '原maxlevel', old);
  78813. //this.material.size = this.getPointsize(e.maxLevel)
  78814. //this.material.size *= 2
  78815. });
  78816. };
  78817. var finish = makeit => {
  78818. //viewer.removeEventListener('overPointBudget',decreaseLevel)
  78819. makeit && done();
  78820. viewer.removeEventListener('update', update);
  78821. viewer.removeEventListener('pointsLoaded', loaded);
  78822. };
  78823. var update = () => {
  78824. Potree.updatePointClouds(viewer.scene.pointclouds, camera, viewport.resolution);
  78825. /* if( Potree.numVisiblePoints > maxPointBudge * 0.9){
  78826. decreaseLevel()
  78827. */
  78828. notify(notifyArea_, () => {
  78829. /* console.log('unloadedGeometry',Potree.unloadedGeometry.length)
  78830. return curProgress */
  78831. /* curProgress = THREE.Math.clamp(Potree.numVisiblePoints/predictPointCount,curProgress,1) //如果decreaseLevel了点会减少,也不管它,就停住吧,反正很快就加载好了
  78832. return curProgress */
  78833. if (!unloadBefore && Date.now() - beginTime < tryPreLoadTime) {
  78834. curProgress = (Date.now() - beginTime) / tryPreLoadTime * 0.5;
  78835. } else {
  78836. if (!unloadBefore) {
  78837. unloadBefore = Potree.unloadedGeometry.length;
  78838. //console.log('unloadBefore', unloadBefore)
  78839. }
  78840. unloadBefore = Math.max(Potree.unloadedGeometry.length, unloadBefore); //unloadedGeometry 刚开始可能越涨越多 - - 所以进度条会卡住
  78841. var curProgress_ = 0.5 + 0.5 * (1 - Potree.unloadedGeometry.length / unloadBefore);
  78842. curProgress = Math.max(curProgress, curProgress_);
  78843. }
  78844. //console.log('curProgress ', curProgress, 'numVisiblePoints', Potree.numVisiblePoints, 'unloadedGeometry',Potree.unloadedGeometry.length)
  78845. return curProgress;
  78846. }, 'loadpoints');
  78847. interrupt && (finish(false), reject(), computeFinish('正在loadPoints,unloadedGeometry个数' + Potree.unloadedGeometry.length)); //曾经遇到遇到bug 不发送pointsLoaded 一直update 一直有3个unloadedGeometry加载不了。。 是否为每个加载的node加个计时?
  78848. };
  78849. viewer.addEventListener('update', update);
  78850. var loaded = () => {
  78851. //点云加载完时(不一定准确)
  78852. console.warn('加载完毕', ' numVisiblePoints', Potree.numVisiblePoints);
  78853. finish(true);
  78854. };
  78855. viewer.addEventListener('pointsLoaded', loaded);
  78856. /* let predictPointCount = Math.round(math.linearClamp(buffer.length, [1e5, maxWidth*maxWidth*4],[1e6, maxPointBudge ]))//最终要加载到的数目
  78857. */
  78858. /* let overTime = ()=>{
  78859. if(document.hidden){
  78860. return setTimeout(overTime, maxTime)
  78861. }
  78862. if(!finish)console.warn('超时, numVisiblePoints', Potree.numVisiblePoints)
  78863. dealDone()
  78864. }
  78865. setTimeout(overTime, maxTime) */
  78866. } else {
  78867. notify(notifyArea_, 1);
  78868. done();
  78869. }
  78870. });
  78871. }
  78872. convertColorToHeight(color, zMin, zMax) {
  78873. var percent = 0;
  78874. var a = 1;
  78875. for (var i = 0; i < 3; i++) {
  78876. a = i == 2 ? a / 255 : a / 256;
  78877. percent += a * color[i];
  78878. }
  78879. var height = (zMax - zMin) * percent;
  78880. return height + zMin;
  78881. }
  78882. getPointsize(maxLevel) {
  78883. //尽量铺满 size单位是米,需要和点云缝隙同宽
  78884. return 0.01; /* adaptive:0.2 */
  78885. var s = /* this.material.spacing */100 / Math.pow(2, maxLevel - 1); //adaptive的话在shader中已经乘了spacing
  78886. console.log('getPointsize', s, 'maxLevel', maxLevel);
  78887. return s; //会不会直接返回1就好?
  78888. //不能太小。假如gl_pointsize计算结果是0.1,那么显示就是1px;当level将级后,放大2倍为0.2,也还是1px,看起来就稀疏了。所以要保证这个数在最大level时gl_pointsize计算结果差不多是1px.(虽然我会在渲染大尺寸面积时降画布尺寸,但不能保证刚刚好,且因点云个数不可控不会降尺寸太狠)
  78889. }
  78890. download(prisms) {
  78891. if (this.prisms.length == 0) {
  78892. return null;
  78893. }
  78894. var visiPointclouds = viewer.scene.pointclouds.filter(e => Potree.Utils.getObjVisiByReason(e, 'datasetSelection'));
  78895. visiPointclouds.sort((a, b) => {
  78896. return a.dataset_id - b.dataset_id;
  78897. }); //缓存需要固定排序好比较
  78898. var data = {
  78899. transformation_matrix: visiPointclouds.map(cloud => {
  78900. var data = {
  78901. id: cloud.dataset_id,
  78902. matrix: new Matrix4().elements,
  78903. //参照downloadNoCrop,给默认值,表示没有最外层裁剪
  78904. visiMatrixes: prisms.map(prism => {
  78905. return {
  78906. matrix: prism.getTransformationMatrix(cloud).elements,
  78907. //剪裁框
  78908. points: prism.points.map(p => {
  78909. return {
  78910. x: p.x,
  78911. y: p.y
  78912. };
  78913. })
  78914. };
  78915. }),
  78916. modelMatrix: new Matrix4().copy(cloud.transformMatrix).transpose().elements
  78917. };
  78918. return data;
  78919. }),
  78920. aabb: "b-12742000 -12742000 -12742000 12742000 12742000 12742000" //剪裁空间
  78921. };
  78922. return data;
  78923. }
  78924. //体积多边形棱柱,z需要变换到-0.5 ~ 0.5
  78925. }
  78926. /* VolumeComputer.prototype.setClipBoxes = function(){
  78927. let lastPrisms = []
  78928. return function(){
  78929. let prismPolygons = this.prisms.filter(e=>!e.isNew && e.visible)
  78930. let prismList = [], prismPoints = [], maxPointsCount
  78931. if(prismPolygons.length){
  78932. let pointsCount = prismPolygons.pointsCount = prismPolygons.reduce((w,c)=>{return w+c.points.length},0)
  78933. prismList = new Float32Array(9 * prismPolygons.length);
  78934. prismPoints = new Float32Array(2 * pointsCount);
  78935. prismPolygons.maxPointsCount = 0//单个prism最大点个数
  78936. if(!this.entered)this.enter()
  78937. let pointIndex = 0
  78938. for(let i=0;i<prismPolygons.length;i++ ){
  78939. let bound = prismPolygons[i].prismBound
  78940. let z = prismPolygons[i].horizonZ
  78941. //z = Potree.browser.urlHasValue('zmin',true) || zs[0]
  78942. prismList.set([bound.min.z, z, bound.max.z, bound.min.x, bound.max.x, bound.min.y, bound.max.y, prismPolygons[i].points.length ],9*i);
  78943. //prismList.push(new THREE.Matrix3().fromArray([bound.min.z, z, bound.max.z, bound.min.x, bound.max.x, bound.min.y, bound.max.y, prismPolygons[i].points.length,0 ]))
  78944. for(let j=0;j<prismPolygons[i].points.length;j++){
  78945. prismPoints.set([prismPolygons[i].points[j].x, prismPolygons[i].points[j].y] , 2*j+pointIndex);
  78946. //prismPoints.push( new THREE.Vector2().copy(prismPolygons[i].points[j]))
  78947. }
  78948. pointIndex += 2 * prismPolygons[i].points.length
  78949. prismPolygons.maxPointsCount = Math.max(prismPolygons.maxPointsCount, prismPolygons[i].points.length)
  78950. }
  78951. }
  78952. let doUpdate = ( lastPrisms.length != prismPolygons.length) || lastPrisms.maxPointsCount != prismPolygons.maxPointsCount
  78953. let materials = viewer.scene.pointclouds.map(e=>e.material).concat([this.material])
  78954. materials.forEach(e=>{
  78955. e.uniforms.prismList.value = prismList
  78956. e.uniforms.prismPoints.value = prismPoints
  78957. e.shaderNeedsUpdate = e.shaderNeedsUpdate || doUpdate
  78958. e.prisms = prismPolygons
  78959. })
  78960. //修改obj材质
  78961. this.material.defines.num_prism = this.material.prisms.length//土方量数
  78962. this.material.defines.prismPointCountSum = this.material.prisms.pointsCount //点总个数
  78963. this.material.defines.prism_maxPointsCount = this.material.prisms.maxPointsCount //单个prism最大点个数
  78964. if(doUpdate){
  78965. this.material.needsUpdate = true
  78966. viewer.dispatchEvent('content_changed')
  78967. }
  78968. lastPrisms = prismPolygons
  78969. }
  78970. }(); */
  78971. /*
  78972. 渲染像素pxPerMetric越高,边缘越细腻、准确; 点size越小,越不容易遮盖住下方点云,造成体积偏大。但会不会有底部点云透出来?
  78973. 该版本计算用到两张截图,第一张为整体的俯视图,包括挖方和填方;第二张仅包含填方。
  78974. 缺陷:在补洞时,只利用第一张图的结果,所以整体的挖方会偏多,填方偏少(因为在挖方填方同时存在时,没有分别补挖方和填方,而是放在一起,而上方可能遮盖下方的)
  78975. 尝试过第一张只绘制挖方部分,但是在遍历时就需要多遍历一次,测得的用时更多一些,结果却没变化
  78976. 也尝试过补洞时挖方填方分别补各自的,但这样要考虑更多的东西,用时多了两倍以上。(因为目前规定无论范围内实际有没有点云都补上,非挖即填;如果分开的话,填方边缘也都补上肯定是错的,无法找到挖和填的界限,无法分清是只有挖还是填还是两者均有。如果要探测周围点,耗时很多)
  78977. 如果数据集修改了,土方量需要手动重算。所以场景刷新后显示的体积有可能是错的。
  78978. 之前记的,太麻烦了,延期处理:
  78979. 1 一般情况:我需要记录每个土方量范围内存在的数据集的位置,如
  78980. {datasetId:"1745733728954093568", location:[113.59550104511611, 22.36677932324081, 0] ,orientation: 0.1}
  78981. 如果刷新后土方量范围内存在的数据集发生改变,将重算。
  78982. 数据集也可能显示或隐藏
  78983. 2 其他特殊情况,如裁剪,难以知道裁剪了哪块,所以只能全部重算
  78984. ------------------
  78985. baseModel 基于模型的挖方填方
  78986. 由于模型高度不一致,只能把相机放最高处朝下看,而无法像prism那样在horizonZ处再渲染一张,所以更加不能有多层点云干扰。
  78987. 如模型在一个房间屋顶上方,那么填方会得到两个高度,屋顶和地板的高度,地板是从屋顶的点云缝隙而得。
  78988. 如果模型放房间中间,并不能按理想的那样得到其上的挖方和其下的填方,因为相机朝下看时屋顶会遮住屋底,导致填方减少挖方增多。虽然能在bound底部朝上再拍一张,但若是有更复杂的情况依旧不能保证正确。
  78989. 故需要设置好zMin zMax
  78990. 如果模型有可能很大,但数据集不大,可以将bound只取交集
  78991. */
  78992. var texLoader$d = new TextureLoader();
  78993. var circleGeo = new CircleGeometry(1.45, 100);
  78994. var sphereGeo$1 = new SphereBufferGeometry(0.008, 8, 8);
  78995. var magDisMin = 1; //相机离目标位置的距离的分界线,当离得远时要缩小fov以使看到的视野固定(望远镜效果)
  78996. var magDisMax = 20;
  78997. /* const radius_ = 0.2; //当相机离目标位置的距离>magDistance_时,希望看到的视野的半径
  78998. const maxFov = THREE.Math.radToDeg(Math.atan(radius_ / magDisMin )) * 2//提前计算出当相机离目标位置的距离<magDisMin时的fov,均使用=magDisMin时的fov。只要保证该fov大于主相机的fov就会有放大效果
  78999. */
  79000. var w$2 = 230 / 1.43;
  79001. var maxPX = 1366 * 1024; //ipad pro. 大于这个分辨率的就直接用devicePixelRatio, 如macbook也是
  79002. var width2dPX = Math.round(window.devicePixelRatio >= 2 ? (window.screen.width * window.screen.height >= maxPX ? window.devicePixelRatio / 1.2 : window.devicePixelRatio / 1.5) * w$2 : w$2); //触屏或高分辨率的可能要放大些。但在手机上不能太大
  79003. //console.log('width2dPX', width2dPX)
  79004. var orthoView = new ExtendView();
  79005. class Magnifier extends Object3D {
  79006. //放大镜or望远镜
  79007. constructor(viewer) {
  79008. super();
  79009. this.width = this.height = width2dPX /* * window.devicePixelRatio */;
  79010. this.camera = new PerspectiveCamera(50, 1, 0.01, 10000); //fov aspect near far
  79011. this.camera.up = new Vector3(0, 0, 1);
  79012. this.viewport = new Viewport(null, this.camera, {
  79013. left: 0,
  79014. bottom: 0,
  79015. width: 1,
  79016. height: 1,
  79017. name: 'magnifier',
  79018. cameraLayers: ['magnifierContent'],
  79019. pixelRatio: 1
  79020. });
  79021. this.viewport.setResolution(this.width, this.height, 0, 0);
  79022. {
  79023. var density;
  79024. var sizeType;
  79025. var colorType;
  79026. var opacityBefore = new Map();
  79027. var sizeBefore = new Map();
  79028. var visiMap = new Map();
  79029. this.viewport.beforeRender = () => {
  79030. viewer.scene.pointclouds.forEach(e => {
  79031. //因为更改pointDensity时会自动变opacity,所以这项最先获取
  79032. visiMap.set(e, e.visible);
  79033. e.visible = Potree.Utils.getObjVisiByReason(e, 'datasetSelection'); //先将隐藏的点云显示
  79034. opacityBefore.set(e, e.temp.pointOpacity);
  79035. sizeBefore.set(e, e.temp.pointSize);
  79036. });
  79037. //使放大镜里的pointDensity是'magnifier' 最高质量。
  79038. density = Potree.settings.pointDensity;
  79039. Potree.settings.pointDensity = 'magnifier';
  79040. viewer.scene.pointclouds.forEach(e => {
  79041. //因为全景模式的pointSizeType是fixed所以要还原下
  79042. sizeType = e.material.pointSizeType;
  79043. e.material.pointSizeType = Potree.config.material.pointSizeType;
  79044. //材质
  79045. colorType = e.material.activeAttributeName;
  79046. e.material.activeAttributeName = 'rgba';
  79047. e.changePointOpacity(1);
  79048. //e.changePointSize(Potree.config.material.realPointSize, true)
  79049. });
  79050. };
  79051. this.viewport.afterRender = () => {
  79052. Potree.settings.pointDensity = density;
  79053. viewer.scene.pointclouds.forEach(e => {
  79054. e.visible = visiMap.get(e);
  79055. e.material.pointSizeType = sizeType;
  79056. e.material.activeAttributeName = colorType;
  79057. e.changePointOpacity(opacityBefore.get(e));
  79058. //e.changePointSize(sizeBefore.get(e))
  79059. });
  79060. };
  79061. }
  79062. this.renderTarget = new WebGLRenderTarget(this.width, this.height, {
  79063. minFilter: LinearFilter,
  79064. magFilter: LinearFilter,
  79065. format: RGBAFormat
  79066. /* type: THREE.FloatType,
  79067. minFilter: THREE.NearestFilter,
  79068. magFilter: THREE.NearestFilter,
  79069. */
  79070. });
  79071. this.rtEDL = new WebGLRenderTarget(this.width, this.height, {
  79072. //好像没用到? 因为这里不绘制测量线
  79073. minFilter: NearestFilter,
  79074. magFilter: NearestFilter,
  79075. format: RGBAFormat,
  79076. type: FloatType,
  79077. depthTexture: new DepthTexture(undefined, undefined, UnsignedIntType)
  79078. });
  79079. this.mesh = new Mesh(circleGeo, new MeshBasicMaterial({
  79080. side: DoubleSide,
  79081. map: this.renderTarget.texture,
  79082. transparent: true,
  79083. depthTest: !1
  79084. //depthWrite: !1,
  79085. }));
  79086. this.overlayMesh = new Mesh(circleGeo, new MeshBasicMaterial({
  79087. side: DoubleSide,
  79088. map: texLoader$d.load(Potree.resourcePath + '/textures/crosshair.png'),
  79089. transparent: true,
  79090. depthTest: !1
  79091. //depthWrite: !1,
  79092. }));
  79093. this.targetPoint = new Object3D();
  79094. this.targetPoint.add(new Mesh(sphereGeo$1, new MeshBasicMaterial({
  79095. color: "#ff0000",
  79096. transparent: true,
  79097. opacity: 0.7
  79098. })));
  79099. this.targetPoint.add(new Mesh(sphereGeo$1, new MeshBasicMaterial({
  79100. color: "#ff0000",
  79101. transparent: true,
  79102. opacity: 0.3,
  79103. depthTest: false //被遮挡层
  79104. })));
  79105. this.targetPoint.name = 'magnifierPointTarget';
  79106. viewer.scene.scene.add(this.targetPoint);
  79107. Potree.Utils.setObjectLayers(this.targetPoint, 'magnifierContent');
  79108. this.add(this.mesh);
  79109. this.add(this.overlayMesh);
  79110. this.position.set(-1000, -1000, -100000); //令它看不见
  79111. this.mesh.renderOrder = Potree.config.renderOrders.magnifier;
  79112. this.overlayMesh.renderOrder = Potree.config.renderOrders.magnifier + 1;
  79113. this.aimPos;
  79114. Potree.Utils.setObjectLayers(this, 'magnifier');
  79115. //viewer.inputHandler.addInputListener(this)
  79116. viewer.addEventListener('camera_changed', e => {
  79117. // 平移、滚轮时更新
  79118. if (e.viewport == viewer.mainViewport) this.update(); //不过intersectPoint没更新
  79119. });
  79120. this.mesh.layers.set(Potree.config.renderLayers.magnifier);
  79121. this.overlayMesh.layers.set(Potree.config.renderLayers.magnifier);
  79122. //this.layers.set(Potree.config.renderLayers.magnifier);//这句在外层写没用
  79123. this.dontRender = false;
  79124. viewer.addEventListener('global_drag', e => {
  79125. //拖拽时不渲染。主要是右键平移时渲染延迟了,会闪烁。
  79126. this.dontRender = true;
  79127. });
  79128. viewer.addEventListener('global_drop', e => {
  79129. this.dontRender = false;
  79130. });
  79131. viewer.addEventListener('global_mouseup', e => {
  79132. //测量时拖拽场景再mouseup
  79133. this.dontRender = false;
  79134. });
  79135. var updateVisi = e => {
  79136. if (e.hoverViewport == viewer.mainViewport) {
  79137. Potree.Utils.updateVisible(this, "atViewport", true);
  79138. this.update(e.intersect && e.intersect.location);
  79139. } else {
  79140. Potree.Utils.updateVisible(this, "atViewport", false); //小地图不显示
  79141. }
  79142. };
  79143. viewer.addEventListener('global_mousemove', updateVisi);
  79144. viewer.addEventListener('global_touchstart', updateVisi);
  79145. viewer.addEventListener('updateMagnifier', updateVisi);
  79146. /* viewer.addEventListener("beginSplitView",()=>{
  79147. this.updateVisible("splitView", false)
  79148. })
  79149. viewer.addEventListener("finishSplitView",()=>{
  79150. this.updateVisible("splitView", true)
  79151. }) */
  79152. this.addEventListener("setEnable", e => {
  79153. Potree.Utils.updateVisible(this, "enable", e.value); //界面开关
  79154. /* if(Potree.settings.displayMode == 'showPanos') && e.value){
  79155. Potree.settings.pointDensity = 'magnifier'
  79156. }else if() */
  79157. viewer.dispatchEvent('content_changed');
  79158. });
  79159. if (Potree.settings.isOfficial) {
  79160. Potree.Utils.updateVisible(this, "enable", false);
  79161. } else {
  79162. Potree.Utils.updateVisible(this, "measure", false);
  79163. viewer.addEventListener("measureMovePoint", () => {//测量开始
  79164. //Potree.Utils.updateVisible(this, "measure", true)
  79165. });
  79166. viewer.addEventListener("endMeasureMove", () => {
  79167. Potree.Utils.updateVisible(this, "measure", false);
  79168. viewer.dispatchEvent('content_changed');
  79169. });
  79170. }
  79171. this.addEventListener('isVisible', e => {
  79172. if (!this.visible) Potree.settings.pointDensity = Potree.settings.pointDensity; //恢复pointBudget
  79173. });
  79174. viewer.scene.view.addEventListener('flyingDone', () => {
  79175. if (!this.visible) return;
  79176. var pickWindowSize = 100;
  79177. var intersect = viewer.inputHandler.getIntersect({
  79178. viewport: viewer.mainViewport,
  79179. usePointcloud: true,
  79180. pickWindowSize
  79181. });
  79182. this.update(intersect && intersect.location);
  79183. });
  79184. }
  79185. //注意:在鼠标没有移动的时候,无法获取到最新的intersect, 放大镜内的内容可能是错误的。全景模式下更奇怪,原因未知
  79186. update(aimPos) {
  79187. //相机靠近 navvis的做法
  79188. var dontRender = this.dontRender || !(aimPos instanceof Vector3) || Potree.settings.displayMode == 'showPanos' && viewer.images360.flying;
  79189. aimPos = aimPos instanceof Vector3 ? aimPos : this.aimPos;
  79190. if (!aimPos || !this.visible) return;
  79191. var playerCamera = viewer.scene.getActiveCamera();
  79192. var playerPos = playerCamera.position; //viewer.scene.view.getPivot()
  79193. var dis = playerPos.distanceTo(aimPos);
  79194. var dirToCamera = new Vector3().subVectors(playerPos, aimPos).normalize();
  79195. var fareast = 300;
  79196. //相机位置
  79197. if (playerCamera.type == 'OrthographicCamera') {
  79198. var finalDisToAim = 2;
  79199. } else {
  79200. var finalDisToAim = dis > magDisMin ? dis > fareast ? magDisMax : (dis - magDisMin) / (fareast - magDisMin) * (magDisMax - magDisMin) + magDisMin : dis / 2; //dis>magDistance_ ? magDistance_ : dis / 2;
  79201. }
  79202. this.camera.fov = playerCamera.type == 'OrthographicCamera' ? 30 : playerCamera.fov / 2;
  79203. this.camera.updateProjectionMatrix();
  79204. if (playerCamera.type == 'OrthographicCamera') {
  79205. orthoView.position.copy(aimPos).sub(viewer.mainViewport.view.direction.multiplyScalar(finalDisToAim));
  79206. orthoView.yaw = viewer.mainViewport.view.yaw;
  79207. orthoView.pitch = viewer.mainViewport.view.pitch;
  79208. orthoView.applyToCamera(this.camera);
  79209. } else {
  79210. this.camera.position.copy(aimPos).add(dirToCamera.multiplyScalar(finalDisToAim));
  79211. this.camera.lookAt(aimPos);
  79212. }
  79213. //自身位置
  79214. //let pos2d = viewer.inputHandler.pointer.clone(); //跟随鼠标
  79215. var pos2d_ = Potree.Utils.getPos2d(aimPos, viewer.mainViewport, viewer.renderArea); //更新目标点的实时二维位置
  79216. var pos2d = pos2d_.vector;
  79217. var margin = width2dPX * 1.1 / viewer.mainViewport.resolution2.y * 2; //确保到鼠标的间距占放大镜的比例不变(检查mobile、上下分屏后的变化)
  79218. var screenPos = pos2d.clone().setY(pos2d.y + (pos2d.y > 0 ? -margin : margin));
  79219. var newPos = new Vector3(screenPos.x, screenPos.y, 0.8).unproject(playerCamera); //z:-1朝外
  79220. if (playerCamera.type != 'OrthographicCamera') {
  79221. var dir = newPos.clone().sub(playerPos).normalize().multiplyScalar(10); //这个数值要大于playerCamera.near
  79222. this.position.copy(playerPos.clone().add(dir));
  79223. } else {
  79224. viewer.navCubeViewer.splitScreen.setShiftTarget(viewer.mainViewport, viewer.bound.center);
  79225. viewer.mainViewport.targetPlane.setFromNormalAndCoplanarPoint(viewer.mainViewport.view.direction.clone(), viewer.bound.center);
  79226. viewer.mainViewport.targetPlane.projectPoint(newPos, viewer.mainViewport.shiftTarget);
  79227. this.position.copy(viewer.mainViewport.shiftTarget.clone());
  79228. //this.position.copy(playerPos.clone().add(dir))
  79229. }
  79230. var s = finalDisToAim * this.camera.fov / 30;
  79231. this.quaternion.copy(playerCamera.quaternion);
  79232. this.targetPoint.position.copy(aimPos);
  79233. this.targetPoint.scale.set(s, s, s);
  79234. this.aimPos = aimPos;
  79235. var scale = math.getScaleForConstantSize({
  79236. //
  79237. width2d: width2dPX,
  79238. camera: viewer.scene.getActiveCamera(),
  79239. position: this.getWorldPosition(new Vector3()),
  79240. resolution: viewer.mainViewport.resolution2
  79241. });
  79242. this.scale.set(scale, scale, scale);
  79243. if (!dontRender) {
  79244. this.waitRender = true;
  79245. }
  79246. viewer.dispatchEvent('content_changed');
  79247. }
  79248. /* update(aimPos){ //仅改fov的版本
  79249. aimPos = aimPos instanceof THREE.Vector3 ? aimPos : this.aimPos
  79250. if(!aimPos || !this.visible)return
  79251. //相机位置
  79252. var playerCamera = viewer.scene.getActiveCamera()
  79253. var playerPos = playerCamera.position;//viewer.scene.view.getPivot()
  79254. var dis = playerPos.distanceTo(aimPos);
  79255. if(dis<magDisMin){
  79256. this.camera.fov = maxFov
  79257. }else{
  79258. this.camera.fov = THREE.Math.radToDeg(Math.atan(radius_ / dis )) * 2 //radius_是能看到的范围半径。当dis大于magDisMin时就放大,否则维持fov为maxFov
  79259. }
  79260. this.camera.updateProjectionMatrix()
  79261. this.camera.position.copy(playerPos)
  79262. this.camera.lookAt(aimPos)
  79263. this.quaternion.copy(playerCamera.quaternion);
  79264. let pointer = viewer.inputHandler.pointer.clone();
  79265. let margin = 0.4, maxY = 0.4
  79266. let screenPos = pointer.clone().setY(pointer.y + (pointer.y>maxY ? -margin : margin ))
  79267. let newPos = new THREE.Vector3(screenPos.x,screenPos.y,0.8).unproject(playerCamera); //z:-1朝外
  79268. let dir = newPos.clone().sub(playerPos).normalize().multiplyScalar(10);//这个数值要大于playerCamera.near
  79269. this.position.copy(playerPos.clone().add(dir))
  79270. this.aimPos = aimPos
  79271. this.targetPoint.position.copy(aimPos);
  79272. var scale = math.getScaleForConstantSize({//
  79273. width2d : width2dPX,
  79274. camera:viewer.scene.getActiveCamera(), position: this.getWorldPosition(new THREE.Vector3()),
  79275. resolution: viewer.mainViewport.resolution2
  79276. })
  79277. this.scale.set(scale, scale, scale);
  79278. if(!this.dontRender){
  79279. this.waitRender = true
  79280. }
  79281. }//位置需要计算,不仅仅是点云,所以需要深度图
  79282. */
  79283. render() {
  79284. if (!this.visible || !this.waitRender && !viewer.needRender) return; //viewer.needRender为true要渲染是因为可能是点云node加载完
  79285. viewer.render({
  79286. target: this.renderTarget,
  79287. viewports: [this.viewport],
  79288. camera: this.camera,
  79289. magnifier: true,
  79290. rtEDL: this.rtEDL
  79291. /* width :this.renderTarget.width,
  79292. height: this.renderTarget.height, */
  79293. });
  79294. this.waitRender = false;
  79295. viewer.dispatchEvent('content_changed');
  79296. }
  79297. }
  79298. /*
  79299. 如果遇到放大镜内点云很不正常,应该是深度图错误(可能全景和点云没匹配上)。
  79300. */
  79301. var texLoader$e = new TextureLoader();
  79302. var defaultOpacity = 0.6;
  79303. var Buttons$2 = Potree.defines.Buttons;
  79304. //鼠标指示小圆片
  79305. class Reticule extends Mesh {
  79306. constructor(viewer) {
  79307. var defaultTex = texLoader$e.load(Potree.resourcePath + '/textures/whiteCircle.png' /* reticule-256x256.png' */);
  79308. super(new PlaneBufferGeometry(0.11, 0.11, 1, 1), new MeshBasicMaterial({
  79309. side: DoubleSide,
  79310. map: defaultTex,
  79311. transparent: true,
  79312. depthTest: !1,
  79313. opacity: defaultOpacity
  79314. //depthWrite: !1,
  79315. }));
  79316. this.name = 'reticule';
  79317. this.defaultTex = defaultTex;
  79318. this.crosshairTex = texLoader$e.load(Potree.resourcePath + '/textures/reticule_cross_hair.png');
  79319. this.forbitTex = texLoader$e.load(Potree.resourcePath + '/textures/pic-forbid.png');
  79320. this.defaultTex.anisotropy = 4;
  79321. this.crosshairTex.anisotropy = 4;
  79322. this.forbitTex.anisotropy = 4;
  79323. //this.layers.set(0/* RenderLayers.RETICULE */);
  79324. this.renderOrder = Potree.config.renderOrders.reticule;
  79325. this.layers.set(Potree.config.renderLayers.marker);
  79326. this.direction = new Vector3();
  79327. this.mouseLastMoveTime = Date.now();
  79328. this.hoverViewport;
  79329. this.matrixMap = new Map();
  79330. this.matrixAutoUpdate = false;
  79331. this.hide(0);
  79332. //viewer.inputHandler.addInputListener(this);
  79333. Potree.settings.intersectWhenHover && viewer.addEventListener('global_mousemove', this.move.bind(this));
  79334. //viewer.addEventListener('global_click',this.move.bind(this))
  79335. viewer.addEventListener('global_mousedown', this.move.bind(this)); //主要针对触屏
  79336. this.state = {};
  79337. var startCrossStyle = () => {
  79338. this.state.cross = true;
  79339. this.judgeTex();
  79340. };
  79341. var endCrossStyle = () => {
  79342. this.state.cross = false;
  79343. this.judgeTex();
  79344. };
  79345. viewer.addEventListener('measureMovePoint', startCrossStyle);
  79346. viewer.addEventListener('endMeasureMove', endCrossStyle);
  79347. viewer.addEventListener('startBuildEntity', startCrossStyle);
  79348. viewer.addEventListener('endBuildEntity', endCrossStyle);
  79349. viewer.addEventListener('start_inserting_tag', startCrossStyle);
  79350. viewer.addEventListener('endTagMove', endCrossStyle);
  79351. viewer.addEventListener('reticule_forbit', e => {
  79352. if (this.state.forbit != e.v) {
  79353. console.log('change forbit ', e.v);
  79354. }
  79355. this.state.forbit = e.v;
  79356. this.judgeTex();
  79357. });
  79358. Potree.Utils.setObjectLayers(this, 'sceneObjects');
  79359. }
  79360. judgeTex() {
  79361. if (this.state.forbit) {
  79362. this.material.map = this.forbitTex;
  79363. } else if (this.state.cross) {
  79364. this.material.map = this.crosshairTex;
  79365. } else {
  79366. this.material.map = this.defaultTex;
  79367. }
  79368. viewer.mapViewer && viewer.mapViewer.dispatchEvent({
  79369. type: 'content_changed'
  79370. });
  79371. }
  79372. move(e) {
  79373. if (e.type == "global_mousemove" && (e.isTouch || e.buttons != Buttons$2.NONE) && !this.state.cross) {
  79374. return; //按下时不更新,除非拖拽测量
  79375. }
  79376. this.mouseLastMoveTime = Date.now();
  79377. this.updatePosition(e.intersect, e.hoverViewport);
  79378. }
  79379. hide() {
  79380. var duration = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 500;
  79381. if (this.hidden) return;
  79382. this.hidden = !0;
  79383. transitions.start(lerp.property(this.material, "opacity", 0, () => {
  79384. //progress
  79385. this.dispatchEvent({
  79386. type: 'update'
  79387. });
  79388. //viewer.dispatchEvent('content_changed')
  79389. }), duration, () => {
  79390. //done
  79391. this.dispatchEvent({
  79392. type: 'update',
  79393. visible: false
  79394. });
  79395. });
  79396. this.dispatchEvent({
  79397. type: 'update',
  79398. visible: false
  79399. });
  79400. setTimeout(() => {}, duration);
  79401. }
  79402. show() {
  79403. var duration = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 300;
  79404. if (!Potree.Utils.getObjVisiByReason(this, 'force')) return;
  79405. //console.log("show Reticule")
  79406. this.hidden = !1;
  79407. if (this.material.opacity <= 0) {
  79408. transitions.start(lerp.property(this.material, "opacity", defaultOpacity, () => {
  79409. //progress
  79410. this.dispatchEvent({
  79411. type: 'update'
  79412. });
  79413. //viewer.dispatchEvent('content_changed')
  79414. }), duration, () => {
  79415. //done
  79416. this.dispatchEvent({
  79417. type: 'update',
  79418. visible: false
  79419. });
  79420. });
  79421. this.dispatchEvent({
  79422. type: 'update',
  79423. visible: true
  79424. });
  79425. }
  79426. }
  79427. //鼠标静止一段时间它就会消失
  79428. updateVisible() {
  79429. Date.now() - this.mouseLastMoveTime > 1500 && !this.hidden && this.hide();
  79430. }
  79431. updateScale(viewport) {
  79432. var s,
  79433. camera = viewport.camera;
  79434. if (camera.type == "OrthographicCamera") {
  79435. var sizeInfo = this.state.cross ? {
  79436. width2d: 500
  79437. } : {
  79438. minSize: 100,
  79439. maxSize: 400,
  79440. nearBound: 100,
  79441. farBound: 700
  79442. };
  79443. s = math.getScaleForConstantSize($.extend(sizeInfo, {
  79444. position: this.position,
  79445. camera,
  79446. resolution: viewport.resolution /* 2 */
  79447. }));
  79448. } else {
  79449. var n = camera.position.distanceTo(this.position);
  79450. s = 0.8 * Math.log2(n + 1); //底数为2 ( Math.log()底数为e )
  79451. if (this.state.cross) {
  79452. //测量时更精细些
  79453. s /= viewer.images360.zoomLevel;
  79454. }
  79455. }
  79456. this.scale.set(s, s, s);
  79457. }
  79458. updateAtViewports(viewport) {
  79459. //当多个viewports时更新。更新大小等
  79460. if (viewport.name == 'magnifier') return;
  79461. if (this.orthoPos && this.hoverViewport && this.hoverViewport.name == 'mapViewport' && viewport != this.hoverViewport) {
  79462. //若是在地图上更新,在其他viewport要隐藏。因为在地图上无法得知高度。
  79463. Potree.Utils.updateVisible(this, 'hoverMap', false);
  79464. return;
  79465. }
  79466. Potree.Utils.updateVisible(this, 'hoverMap', true);
  79467. if (viewport.name == 'mapViewport') {
  79468. Potree.Utils.setObjectLayers(this, "bothMapAndScene");
  79469. } else {
  79470. //通常地图不显示reticule,只有在特殊编辑时才显示
  79471. Potree.Utils.setObjectLayers(this, 'sceneObjects');
  79472. }
  79473. var matrix = this.matrixMap.get(viewport);
  79474. if (!matrix) {
  79475. this.updateScale(viewport);
  79476. this.updateMatrix();
  79477. //this.updateMatrixWorld()
  79478. this.matrixMap.set(viewport, this.matrix.clone());
  79479. } else {
  79480. this.matrix.copy(matrix);
  79481. //this.updateMatrixWorld()
  79482. }
  79483. }
  79484. updatePosition(intersect, viewport) {
  79485. //在地图(当地图融合到viewer时)和场景里都显示且完全相同(大小可能不同)
  79486. if (Potree.Utils.getObjVisiByReason(this, 'force')) {
  79487. //没有被强制隐藏,如进入某个页面后强制不显示
  79488. if (!intersect /* || !intersect.point.normal */) {
  79489. return; //this.hide();
  79490. }
  79491. var atMap = !intersect.location;
  79492. var location = intersect.location || intersect.orthoIntersect.clone();
  79493. var normal;
  79494. this.orthoPos = atMap;
  79495. //地图上要瞬间变化 , 因为要使needRender为true很麻烦
  79496. this.show(atMap ? 0 : 300);
  79497. if (atMap) {
  79498. normal = new Vector3(0, 0, 1); //地图无normal
  79499. location.setZ(0); //低于相机高度即可
  79500. this.direction = normal.clone();
  79501. } else {
  79502. /* if(intersect.point){
  79503. if(intersect.pointcloud){
  79504. normal = new THREE.Vector3().fromArray(intersect.point.normal ).applyMatrix4( intersect.pointcloud.rotateMatrix );
  79505. }else{//mesh
  79506. normal = new THREE.Vector3().copy(intersect.point.normal).applyQuaternion(intersect.object.quaternion)
  79507. }
  79508. }else{
  79509. normal = intersect.normal //when showPanos
  79510. } */
  79511. normal = intersect.normal;
  79512. if (normal) {
  79513. var ratio = /* Potree.settings.useDepthTex ? 1 : */0.2;
  79514. this.direction = this.direction.multiplyScalar(1 - ratio);
  79515. this.direction.add(normal.clone().multiplyScalar(ratio));
  79516. }
  79517. //this.direction = normal.clone() //改为瞬间变化,否则刚hover上某个点时看起来不太对
  79518. }
  79519. this.position.copy(location); /* .add(normal.clone().multiplyScalar(.01)); */
  79520. this.updateMatrix(); //lookAt之前要保证得到matrix
  79521. this.lookAt(this.position.clone().add(this.direction));
  79522. this.hoverViewport = viewport; //记录下最近一次hover过的viewport
  79523. this.updateScale(viewport);
  79524. {
  79525. //存储matrix,节省计算
  79526. this.updateMatrix();
  79527. //this.updateMatrixWorld()
  79528. this.matrixMap.clear(); //重新计算
  79529. this.matrixMap.set(viewport, this.matrix.clone());
  79530. //别处会updateMatrixWorld
  79531. }
  79532. this.dispatchEvent({
  79533. type: 'update'
  79534. });
  79535. //为什么navvis在校准数据集时每个viewport里reticule的朝向都刚好垂直于屏幕,似乎限定在了一定范围内,还是在pick时就只pick范围内的点?
  79536. }
  79537. }
  79538. //navvis在地图等地方看reticule是有厚度的
  79539. /* updateMatrixWorld(force){
  79540. console.log('updateMatrixWorld', force)
  79541. super.updateMatrixWorld(force)
  79542. } */
  79543. }
  79544. /**
  79545. *
  79546. * Supersample Anti-Aliasing Render Pass
  79547. *
  79548. * @author bhouston / http://clara.io/
  79549. *
  79550. * This manual approach to SSAA re-renders the scene ones for each sample with camera jitter and accumulates the results.
  79551. *
  79552. * References: https://en.wikipedia.org/wiki/Supersampling
  79553. *
  79554. */
  79555. //较为原始的一种抗锯齿 (超级采样抗锯齿)
  79556. var SSAARenderPass = function SSAARenderPass(clearColor, clearAlpha) {
  79557. Pass.call(this);
  79558. //this.scene //= scene;
  79559. //this.camera = camera;
  79560. this.sampleLevel = 4; // specified as n, where the number of samples is 2^n, so sampleLevel = 4, is 2^4 samples, 16.
  79561. this.unbiased = true;
  79562. // as we need to clear the buffer in this pass, clearColor must be set to something, defaults to black.
  79563. this.clearColor = clearColor !== undefined ? clearColor : 0x000000;
  79564. this.clearAlpha = clearAlpha !== undefined ? clearAlpha : 0;
  79565. this.renderUniforms = {
  79566. bgTex: {
  79567. value: null
  79568. },
  79569. outlineTex: {
  79570. value: null
  79571. },
  79572. opacity: {
  79573. value: 1
  79574. }
  79575. };
  79576. this.renderMat = new ShaderMaterial({
  79577. uniforms: this.renderUniforms,
  79578. vertexShader: CopyShader.vertexShader,
  79579. /* fragmentShader: CopyShader.fragmentShader, */
  79580. fragmentShader: " \n uniform sampler2D bgTex; \n uniform sampler2D outlineTex; \n uniform float opacity;\n varying vec2 vUv;\n void main() {\n vec4 color1 = texture2D( bgTex, vUv );\n vec4 color2 = texture2D( outlineTex, vUv ); \n gl_FragColor = opacity * mix(color1, color2, color2.a) ;\n \n \n } \n ",
  79581. premultipliedAlpha: true,
  79582. blending: AdditiveBlending,
  79583. depthTest: false,
  79584. depthWrite: false,
  79585. transparent: true
  79586. });
  79587. this.renderMat2 = new ShaderMaterial({
  79588. uniforms: UniformsUtils.clone(CopyShader.uniforms),
  79589. vertexShader: CopyShader.vertexShader,
  79590. fragmentShader: "uniform float opacity; \n uniform sampler2D tDiffuse; \n varying vec2 vUv;\n\n void main() {\n \n vec4 texel = texture2D( tDiffuse, vUv ); \n \n if(texel.r == 0.0 && texel.g == 0.0 && texel.b == 0.0){\n discard;\n }else{\n gl_FragColor = opacity * texel;\n }\n } \n ",
  79591. depthTest: false,
  79592. depthWrite: false,
  79593. transparent: true
  79594. });
  79595. ////////////////////
  79596. /* this.renderMat.blendSrc = THREE.OneFactor //即将写入缓冲区的颜色。
  79597. this.renderMat.blendDst = THREE.OneFactor //缓冲区已经存在的颜色
  79598. this.renderMat.blendEquation = THREE.AddEquation;
  79599. this.renderMat.blendEquationAlpha = THREE.AddEquation;
  79600. this.renderMat.blendDstAlpha = THREE.SrcAlphaFactor
  79601. this.renderMat.blendSrcAlpha = THREE.SrcAlphaFactor */
  79602. this.camera2 = new OrthographicCamera(-1, 1, 1, -1, 0, 1);
  79603. this.scene2 = new Scene();
  79604. this.quad2 = new Mesh(new PlaneBufferGeometry(2, 2), this.renderMat /* this.copyMaterial */);
  79605. this.quad2.frustumCulled = false; // Avoid getting clipped
  79606. this.scene2.add(this.quad2);
  79607. this.copyPass = new ShaderPass(CopyShader);
  79608. this.copyPass.renderToScreen = true;
  79609. };
  79610. SSAARenderPass.prototype = Object.assign(Object.create(Pass.prototype), {
  79611. constructor: SSAARenderPass,
  79612. dispose: function dispose() {
  79613. if (this.sampleRenderTarget) {
  79614. this.sampleRenderTarget.dispose();
  79615. this.sampleRenderTarget = null;
  79616. }
  79617. },
  79618. setSize: function setSize(width, height) {
  79619. if (this.sampleRenderTarget) this.sampleRenderTarget.setSize(width, height);
  79620. this.childPass && this.childPass.setSize(width, height);
  79621. },
  79622. addPass: function addPass(pass) {
  79623. this.childPass = pass;
  79624. },
  79625. render: function render(scene, camera, viewports, renderer, writeBuffer, readBuffer, maskActive, renderFun) {
  79626. if (this.useCopy) {
  79627. scene = this.copyPass.scene;
  79628. camera = this.copyPass.camera;
  79629. }
  79630. if (!this.sampleRenderTarget) {
  79631. this.sampleRenderTarget = new WebGLRenderTarget(readBuffer.width, readBuffer.height, {
  79632. minFilter: LinearFilter,
  79633. magFilter: LinearFilter,
  79634. format: RGBAFormat
  79635. });
  79636. this.sampleRenderTarget.texture.name = "SSAARenderPass.sample";
  79637. }
  79638. var jitterOffsets = SSAARenderPass.JitterVectors[Math.max(0, Math.min(this.sampleLevel, 5))];
  79639. var autoClear = renderer.autoClear;
  79640. renderer.autoClear = false;
  79641. var oldClearColor = renderer.getClearColor(new Color()).getHex();
  79642. var oldClearAlpha = renderer.getClearAlpha();
  79643. renderer.setClearColor(this.clearColor, this.clearAlpha);
  79644. var baseSampleWeight = 1.0 / jitterOffsets.length;
  79645. var roundingRange = 1 / 32;
  79646. //this.copyUniforms[ "tDiffuse" ].value = this.sampleRenderTarget.texture;
  79647. var oldTarget = renderer.getRenderTarget();
  79648. if (oldTarget) {
  79649. if (oldTarget.scissorTest) {
  79650. var width = oldTarget.scissor.w,
  79651. height = oldTarget.scissor.z;
  79652. } else {
  79653. var width = oldTarget.width,
  79654. height = oldTarget.height;
  79655. }
  79656. } else {
  79657. var width = readBuffer.width,
  79658. height = readBuffer.height;
  79659. }
  79660. // render the scene multiple times, each slightly jitter offset from the last and accumulate the results.
  79661. var opa = 0;
  79662. for (var i = 0; i < jitterOffsets.length; i++) {
  79663. var jitterOffset = jitterOffsets[i];
  79664. if (camera.setViewOffset) {
  79665. camera.setViewOffset(width, height, jitterOffset[0] * 0.0625, jitterOffset[1] * 0.0625,
  79666. // 0.0625 = 1 / 16
  79667. width, height);
  79668. }
  79669. var sampleWeight = baseSampleWeight;
  79670. if (this.unbiased) {
  79671. //更柔和
  79672. var uniformCenteredDistribution = -0.5 + (i + 0.5) / jitterOffsets.length;
  79673. sampleWeight += roundingRange * uniformCenteredDistribution;
  79674. }
  79675. renderer.setRenderTarget(this.sampleRenderTarget);
  79676. renderer.clear();
  79677. if (this.useCopy) {
  79678. this.copyPass.render(scene, camera, null, renderer, writeBuffer, readBuffer);
  79679. } else {
  79680. if (renderFun) {
  79681. renderFun({
  79682. target: this.sampleRenderTarget
  79683. });
  79684. } else {
  79685. renderer.render(scene, camera);
  79686. }
  79687. }
  79688. renderer.setRenderTarget(oldTarget);
  79689. //---------------------
  79690. //获取outline tex
  79691. var hasOutline = this.childPass && this.childPass.render(scene, camera, renderer, writeBuffer, readBuffer, null, renderFun);
  79692. //合成到该材质
  79693. this.renderUniforms["bgTex"].value = this.sampleRenderTarget.texture;
  79694. this.renderUniforms["outlineTex"].value = hasOutline ? readBuffer.texture : null;
  79695. this.renderUniforms["opacity"].value = sampleWeight;
  79696. /* console.log('sampleWeight', sampleWeight)
  79697. opa += sampleWeight */
  79698. if (!this.renderToScreen) {
  79699. renderer.setRenderTarget(writeBuffer);
  79700. }
  79701. if (i === 0) {
  79702. renderer.setClearColor(0x000000, 0); //叠加前颜色必须0
  79703. renderer.clear();
  79704. }
  79705. renderer.render(this.scene2, this.camera2); // , this.renderToScreen ? null : writeBuffer, ( i === 0 )
  79706. if (!this.renderToScreen) {
  79707. renderer.setRenderTarget(oldTarget);
  79708. }
  79709. //if(i==2)break;
  79710. }
  79711. //console.log('sum:',opa)
  79712. if (camera.clearViewOffset) camera.clearViewOffset();
  79713. //renderer.setRenderTarget(readBuffer)
  79714. //renderer.setClearColor( 0x000000, 0 );
  79715. //renderer.clear()
  79716. /* this.quad2.material = this.renderMat2
  79717. this.renderMat2.uniforms.tDiffuse.value = writeBuffer.texture;
  79718. renderer.render( this.scene2, this.camera2);
  79719. this.quad2.material = this.renderMat */
  79720. //renderer.setRenderTarget(oldTarget)
  79721. renderer.autoClear = autoClear;
  79722. renderer.setClearColor(oldClearColor, oldClearAlpha);
  79723. /* 试了好几次,测量线的透明度还是还原不了。 clearAlpha十分影响结果。
  79724. 因为绘制测量线需要背景透明。 或许可以先全部绘制完后,再 copyshader中 抗锯齿?
  79725. 另外会有黑边。
  79726. */
  79727. }
  79728. });
  79729. // These jitter vectors are specified in integers because it is easier.
  79730. // I am assuming a [-8,8) integer grid, but it needs to be mapped onto [-0.5,0.5)
  79731. // before being used, thus these integers need to be scaled by 1/16.
  79732. //
  79733. // Sample patterns reference: https://msdn.microsoft.com/en-us/library/windows/desktop/ff476218%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
  79734. SSAARenderPass.JitterVectors = [[[0, 0]], [[4, 4], [-4, -4]], [[-2, -6], [6, -2], [-6, 2], [2, 6]], [[1, -3], [-1, 3], [5, 1], [-3, -5], [-5, 5], [-7, -1], [3, 7], [7, -7]], [[1, 1], [-1, -3], [-3, 2], [4, -1], [-5, -2], [2, 5], [5, 3], [3, -5], [-2, 6], [0, -7], [-4, -6], [-6, 4], [-8, 0], [7, -4], [6, 7], [-7, -8]], [[-4, -7], [-7, -5], [-3, -5], [-5, -4], [-1, -4], [-2, -2], [-6, -1], [-4, 0], [-7, 1], [-1, 2], [-6, 3], [-3, 3], [-7, 6], [-3, 6], [-5, 7], [-1, 7], [5, -7], [1, -6], [6, -5], [4, -4], [2, -3], [7, -2], [1, -1], [4, -1], [2, 1], [6, 2], [0, 4], [4, 4], [2, 5], [7, 5], [5, 6], [3, 7]]];
  79735. class MaskPass extends Pass {
  79736. constructor(scene, camera) {
  79737. super();
  79738. this.scene = scene;
  79739. this.camera = camera;
  79740. this.clear = true;
  79741. this.needsSwap = false;
  79742. this.inverse = false;
  79743. }
  79744. render(renderer, writeBuffer, readBuffer /*, deltaTime, maskActive */) {
  79745. var context = renderer.getContext();
  79746. var state = renderer.state;
  79747. // don't update color or depth
  79748. state.buffers.color.setMask(false);
  79749. state.buffers.depth.setMask(false);
  79750. // lock buffers
  79751. state.buffers.color.setLocked(true);
  79752. state.buffers.depth.setLocked(true);
  79753. // set up stencil
  79754. var writeValue, clearValue;
  79755. if (this.inverse) {
  79756. writeValue = 0;
  79757. clearValue = 1;
  79758. } else {
  79759. writeValue = 1;
  79760. clearValue = 0;
  79761. }
  79762. state.buffers.stencil.setTest(true);
  79763. state.buffers.stencil.setOp(context.REPLACE, context.REPLACE, context.REPLACE);
  79764. state.buffers.stencil.setFunc(context.ALWAYS, writeValue, 0xffffffff);
  79765. state.buffers.stencil.setClear(clearValue);
  79766. state.buffers.stencil.setLocked(true);
  79767. // draw into the stencil buffer
  79768. renderer.setRenderTarget(readBuffer);
  79769. if (this.clear) renderer.clear();
  79770. renderer.render(this.scene, this.camera);
  79771. renderer.setRenderTarget(writeBuffer);
  79772. if (this.clear) renderer.clear();
  79773. renderer.render(this.scene, this.camera);
  79774. // unlock color and depth buffer for subsequent rendering
  79775. state.buffers.color.setLocked(false);
  79776. state.buffers.depth.setLocked(false);
  79777. // only render where stencil is set to 1
  79778. state.buffers.stencil.setLocked(false);
  79779. state.buffers.stencil.setFunc(context.EQUAL, 1, 0xffffffff); // draw if == 1
  79780. state.buffers.stencil.setOp(context.KEEP, context.KEEP, context.KEEP);
  79781. state.buffers.stencil.setLocked(true);
  79782. }
  79783. }
  79784. class ClearMaskPass extends Pass {
  79785. constructor() {
  79786. super();
  79787. this.needsSwap = false;
  79788. }
  79789. render(renderer /*, writeBuffer, readBuffer, deltaTime, maskActive */) {
  79790. renderer.state.buffers.stencil.setLocked(false);
  79791. renderer.state.buffers.stencil.setTest(false);
  79792. }
  79793. }
  79794. /**
  79795. * @author alteredq / http://alteredqualia.com/
  79796. */
  79797. var EffectComposer = function EffectComposer(renderer, renderTarget) {
  79798. this.renderer = renderer;
  79799. if (renderTarget === undefined) {
  79800. var parameters = {
  79801. minFilter: LinearFilter,
  79802. magFilter: LinearFilter,
  79803. format: RGBAFormat,
  79804. stencilBuffer: false
  79805. };
  79806. var size = renderer.getDrawingBufferSize(new Vector2());
  79807. renderTarget = new WebGLRenderTarget(size.width, size.height, parameters);
  79808. renderTarget.texture.name = 'EffectComposer.rt1';
  79809. }
  79810. this.renderTarget1 = renderTarget;
  79811. this.renderTarget2 = renderTarget.clone();
  79812. this.renderTarget2.texture.name = 'EffectComposer.rt2';
  79813. this.writeBuffer = this.renderTarget1;
  79814. this.readBuffer = this.renderTarget2;
  79815. this.passes = [];
  79816. // dependencies
  79817. /* if ( THREE.CopyShader === undefined ) {
  79818. console.error( 'THREE.EffectComposer relies on THREE.CopyShader' );
  79819. }
  79820. if ( THREE.ShaderPass === undefined ) {
  79821. console.error( 'THREE.EffectComposer relies on THREE.ShaderPass' );
  79822. } */
  79823. this.copyPass = new ShaderPass(CopyShader);
  79824. viewer.addEventListener('resize', e => {
  79825. //readTarget的话是渲染一整张的,暂时无法一个个viewport渲染所以不用
  79826. this.readTarget || this.setSize(e.viewport.resolution2.x, e.viewport.resolution2.y); //暂时假设composer渲染的viewer的viewports.length == 1
  79827. });
  79828. };
  79829. Object.assign(EffectComposer.prototype, {
  79830. swapBuffers: function swapBuffers() {
  79831. var tmp = this.readBuffer;
  79832. this.readBuffer = this.writeBuffer;
  79833. this.writeBuffer = tmp;
  79834. },
  79835. addPass: function addPass(pass) {
  79836. this.passes.push(pass);
  79837. var size = this.renderer.getDrawingBufferSize(new Vector2());
  79838. pass.setSize(size.width, size.height);
  79839. },
  79840. removePass: function removePass(pass) {
  79841. //add
  79842. var index = this.passes.indexOf(pass);
  79843. index > -1 && this.passes.splice(index, 1);
  79844. },
  79845. insertPass: function insertPass(pass, index) {
  79846. this.passes.splice(index, 0, pass);
  79847. },
  79848. render: function render(scene, camera, viewports, renderFun) {
  79849. var maskActive = false;
  79850. var passes = this.passes.filter(e => e.enabled);
  79851. var pass,
  79852. i,
  79853. il = passes.length;
  79854. var oldTarget = this.renderer.getRenderTarget();
  79855. if (this.readTarget && oldTarget) {
  79856. //add 使用当前renderTarget中的像素
  79857. this.setSize(oldTarget.width, oldTarget.height); //所有viewports一起渲染,整个画面 因暂时没办法一个个copy
  79858. oldTarget.viewport.set(0, 0, oldTarget.width, oldTarget.height);
  79859. oldTarget.scissorTest = false;
  79860. this.copyPass.render(scene, camera, viewports, this.renderer, this.readBuffer, oldTarget);
  79861. }
  79862. for (i = 0; i < il; i++) {
  79863. pass = passes[i];
  79864. //if(i == il-1)pass.renderToScreen = true//
  79865. pass.render(scene, camera, viewports, this.renderer, this.writeBuffer, this.readBuffer, maskActive, renderFun);
  79866. if (pass.needsSwap) {
  79867. if (maskActive) {
  79868. var context = this.renderer.context;
  79869. context.stencilFunc(context.NOTEQUAL, 1, 0xffffffff);
  79870. this.copyPass.render(null, null, viewports, this.renderer, this.writeBuffer, this.readBuffer); // delta
  79871. context.stencilFunc(context.EQUAL, 1, 0xffffffff);
  79872. }
  79873. this.swapBuffers();
  79874. }
  79875. if (MaskPass !== undefined) {
  79876. if (pass instanceof MaskPass) {
  79877. maskActive = true;
  79878. } else if (pass instanceof ClearMaskPass) {
  79879. maskActive = false;
  79880. }
  79881. }
  79882. }
  79883. this.renderer.setRenderTarget(oldTarget);
  79884. //add
  79885. if (!pass.renderToScreen) {
  79886. //最后一个如果没有绘制到屏幕or target上
  79887. this.copyPass.renderToScreen = true;
  79888. this.copyPass.render(null, null, viewports, this.renderer, this.writeBuffer, this.readBuffer);
  79889. }
  79890. },
  79891. reset: function reset(renderTarget) {
  79892. if (renderTarget === undefined) {
  79893. var size = this.renderer.getDrawingBufferSize(new Vector2());
  79894. renderTarget = this.renderTarget1.clone();
  79895. renderTarget.setSize(size.width, size.height);
  79896. }
  79897. this.renderTarget1.dispose();
  79898. this.renderTarget2.dispose();
  79899. this.renderTarget1 = renderTarget;
  79900. this.renderTarget2 = renderTarget.clone();
  79901. this.writeBuffer = this.renderTarget1;
  79902. this.readBuffer = this.renderTarget2;
  79903. },
  79904. setSize: function setSize(width, height, scaleRatio) {
  79905. scaleRatio = scaleRatio || this.scaleRatio || 1;
  79906. //console.log('setSize', width * scaleRatio, height * scaleRatio)
  79907. var maxTexWidth = 4096;
  79908. var w = width * scaleRatio;
  79909. var h = height * scaleRatio;
  79910. if (w > maxTexWidth || h > maxTexWidth) {
  79911. //超出会崩溃
  79912. if (w > h) {
  79913. scaleRatio = maxTexWidth / width;
  79914. } else {
  79915. scaleRatio = maxTexWidth / height;
  79916. }
  79917. }
  79918. w = width * scaleRatio;
  79919. h = height * scaleRatio;
  79920. this.renderTarget1.setSize(w, h);
  79921. this.renderTarget2.setSize(w, h);
  79922. for (var i = 0; i < this.passes.length; i++) {
  79923. this.passes[i].setSize(w, h);
  79924. }
  79925. }
  79926. });
  79927. /**
  79928. * @author alteredq / http://alteredqualia.com/
  79929. */
  79930. class RenderPass extends Pass {
  79931. constructor(overrideMaterial, clearColor, clearAlpha) {
  79932. super();
  79933. /* this.scene = scene;
  79934. this.camera = camera; */
  79935. this.overrideMaterial = overrideMaterial;
  79936. this.clearColor = clearColor;
  79937. this.clearAlpha = clearAlpha !== undefined ? clearAlpha : 0;
  79938. this.clear = true;
  79939. this.clearDepth = false;
  79940. this.needsSwap = false;
  79941. this._oldClearColor = new Color();
  79942. }
  79943. render(scene, camera, viewports, renderer, writeBuffer, readBuffer /*, deltaTime, maskActive */) {
  79944. var oldAutoClear = renderer.autoClear;
  79945. renderer.autoClear = false;
  79946. var oldClearAlpha, oldOverrideMaterial;
  79947. if (this.overrideMaterial !== undefined) {
  79948. oldOverrideMaterial = this.scene.overrideMaterial;
  79949. scene.overrideMaterial = this.overrideMaterial;
  79950. }
  79951. if (this.clearColor) {
  79952. renderer.getClearColor(this._oldClearColor);
  79953. oldClearAlpha = renderer.getClearAlpha();
  79954. renderer.setClearColor(this.clearColor, this.clearAlpha);
  79955. }
  79956. if (this.clearDepth) {
  79957. renderer.clearDepth();
  79958. }
  79959. var oldTarget = renderer.getRenderTarget();
  79960. if (!this.renderToScreen) renderer.setRenderTarget(readBuffer);
  79961. // TODO: Avoid using autoClear properties, see https://github.com/mrdoob/three.js/pull/15571#issuecomment-465669600
  79962. if (this.clear) renderer.clear(renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil);
  79963. renderer.render(scene, camera);
  79964. if (!this.renderToScreen) renderer.setRenderTarget(oldTarget);
  79965. if (this.clearColor) {
  79966. renderer.setClearColor(this._oldClearColor, oldClearAlpha);
  79967. }
  79968. if (this.overrideMaterial !== undefined) {
  79969. scene.overrideMaterial = oldOverrideMaterial;
  79970. }
  79971. renderer.setRenderTarget(oldTarget);
  79972. renderer.autoClear = oldAutoClear;
  79973. }
  79974. }
  79975. /**
  79976. * NVIDIA FXAA by Timothy Lottes
  79977. * https://developer.download.nvidia.com/assets/gamedev/files/sdk/11/FXAA_WhitePaper.pdf
  79978. * - WebGL port by @supereggbert
  79979. * http://www.glge.org/demos/fxaa/
  79980. * Further improved by Daniel Sturk
  79981. */
  79982. var FXAAShader = {
  79983. uniforms: {
  79984. 'tDiffuse': {
  79985. value: null
  79986. },
  79987. 'resolution': {
  79988. value: new Vector2(1 / 1024, 1 / 512)
  79989. }
  79990. },
  79991. vertexShader: /* glsl */"\n\n\t\tvarying vec2 vUv;\n\n\t\tvoid main() {\n\n\t\t\tvUv = uv;\n\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n\t\t}",
  79992. fragmentShader: "\n\tprecision highp float;\n\n\tuniform sampler2D tDiffuse;\n\n\tuniform vec2 resolution;\n\n\tvarying vec2 vUv;\n\n\t// FXAA 3.11 implementation by NVIDIA, ported to WebGL by Agost Biro (biro@archilogic.com)\n\n\t//----------------------------------------------------------------------------------\n\t// File: es3-keplerFXAAassetsshaders/FXAA_DefaultES.frag\n\t// SDK Version: v3.00\n\t// Email: gameworks@nvidia.com\n\t// Site: http://developer.nvidia.com/\n\t//\n\t// Copyright (c) 2014-2015, NVIDIA CORPORATION. All rights reserved.\n\t//\n\t// Redistribution and use in source and binary forms, with or without\n\t// modification, are permitted provided that the following conditions\n\t// are met:\n\t// * Redistributions of source code must retain the above copyright\n\t// notice, this list of conditions and the following disclaimer.\n\t// * Redistributions in binary form must reproduce the above copyright\n\t// notice, this list of conditions and the following disclaimer in the\n\t// documentation and/or other materials provided with the distribution.\n\t// * Neither the name of NVIDIA CORPORATION nor the names of its\n\t// contributors may be used to endorse or promote products derived\n\t// from this software without specific prior written permission.\n\t//\n\t// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY\n\t// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n\t// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n\t// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n\t// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\n\t// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\n\t// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n\t// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY\n\t// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n\t// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n\t// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\t//\n\t//----------------------------------------------------------------------------------\n\n\t#ifndef FXAA_DISCARD\n\t\t\t//\n\t\t\t// Only valid for PC OpenGL currently.\n\t\t\t// Probably will not work when FXAA_GREEN_AS_LUMA = 1.\n\t\t\t//\n\t\t\t// 1 = Use discard on pixels which don't need AA.\n\t\t\t// For APIs which enable concurrent TEX+ROP from same surface.\n\t\t\t// 0 = Return unchanged color on pixels which don't need AA.\n\t\t\t//\n\t\t\t#define FXAA_DISCARD 0\n\t#endif\n\n\t/*--------------------------------------------------------------------------*/\n //\u7B2C\u4E09\u4E2A\u53C2\u6570\u52A0\u5165\u540E\u53EA\u80FD\u5728\u7247\u5143\u7740\u8272\u5668\u4E2D\u8C03\u7528\uFF0C\u4E14\u53EA\u5BF9\u91C7\u6837\u5668\u4E3Amipmap\u7C7B\u578B\u7EB9\u7406\u65F6\u6709\u6548\u3002\u4E0D\u660E\u767D\u4F5C\u7528\uFF1F\uFF1F\uFF1F \u4F46\u8B66\u544A\u8BF4\u8303\u56F4\u572816\u4E4B\u5185\n\t#define FxaaTexTop(t, p) texture2D(t, p, -15.0); //-100.0); \n\t#define FxaaTexOff(t, p, o, r) texture2D(t, p + (o * r), -15.0); //-100.0)\n\t/*--------------------------------------------------------------------------*/\n\n\t#define NUM_SAMPLES 5\n\n\t// assumes colors have premultipliedAlpha, so that the calculated color contrast is scaled by alpha\n\tfloat contrast( vec4 a, vec4 b ) {\n\t\t\tvec4 diff = abs( a - b );\n\t\t\treturn max( max( max( diff.r, diff.g ), diff.b ), diff.a );\n\t}\n\n\t/*============================================================================\n\n\t\t\t\t\t\t\t\t\tFXAA3 QUALITY - PC\n\n\t============================================================================*/\n\n\t/*--------------------------------------------------------------------------*/\n\tvec4 FxaaPixelShader(\n\t\t\tvec2 posM,\n\t\t\tsampler2D tex,\n\t\t\tvec2 fxaaQualityRcpFrame,\n\t\t\tfloat fxaaQualityEdgeThreshold,\n\t\t\tfloat fxaaQualityinvEdgeThreshold\n\t) {\n\t\t\tvec4 rgbaM = FxaaTexTop(tex, posM);\n\t\t\tvec4 rgbaS = FxaaTexOff(tex, posM, vec2( 0.0, 1.0), fxaaQualityRcpFrame.xy);\n\t\t\tvec4 rgbaE = FxaaTexOff(tex, posM, vec2( 1.0, 0.0), fxaaQualityRcpFrame.xy);\n\t\t\tvec4 rgbaN = FxaaTexOff(tex, posM, vec2( 0.0,-1.0), fxaaQualityRcpFrame.xy);\n\t\t\tvec4 rgbaW = FxaaTexOff(tex, posM, vec2(-1.0, 0.0), fxaaQualityRcpFrame.xy);\n\t\t\t// . S .\n\t\t\t// W M E\n\t\t\t// . N .\n\n\t\t\tbool earlyExit = max( max( max(\n\t\t\t\t\tcontrast( rgbaM, rgbaN ),\n\t\t\t\t\tcontrast( rgbaM, rgbaS ) ),\n\t\t\t\t\tcontrast( rgbaM, rgbaE ) ),\n\t\t\t\t\tcontrast( rgbaM, rgbaW ) )\n\t\t\t\t\t< fxaaQualityEdgeThreshold;\n\t\t\t// . 0 .\n\t\t\t// 0 0 0\n\t\t\t// . 0 .\n\n\t\t\t#if (FXAA_DISCARD == 1)\n\t\t\t\t\tif(earlyExit) FxaaDiscard;\n\t\t\t#else\n\t\t\t\t\tif(earlyExit) return rgbaM;\n\t\t\t#endif\n\n\t\t\tfloat contrastN = contrast( rgbaM, rgbaN );\n\t\t\tfloat contrastS = contrast( rgbaM, rgbaS );\n\t\t\tfloat contrastE = contrast( rgbaM, rgbaE );\n\t\t\tfloat contrastW = contrast( rgbaM, rgbaW );\n\n\t\t\tfloat relativeVContrast = ( contrastN + contrastS ) - ( contrastE + contrastW );\n\t\t\trelativeVContrast *= fxaaQualityinvEdgeThreshold;\n\n\t\t\tbool horzSpan = relativeVContrast > 0.;\n\t\t\t// . 1 .\n\t\t\t// 0 0 0\n\t\t\t// . 1 .\n\n\t\t\t// 45 deg edge detection and corners of objects, aka V/H contrast is too similar\n\t\t\tif( abs( relativeVContrast ) < .3 ) {\n\t\t\t\t\t// locate the edge\n\t\t\t\t\tvec2 dirToEdge;\n\t\t\t\t\tdirToEdge.x = contrastE > contrastW ? 1. : -1.;\n\t\t\t\t\tdirToEdge.y = contrastS > contrastN ? 1. : -1.;\n\t\t\t\t\t// . 2 . . 1 .\n\t\t\t\t\t// 1 0 2 ~= 0 0 1\n\t\t\t\t\t// . 1 . . 0 .\n\n\t\t\t\t\t// tap 2 pixels and see which ones are \"outside\" the edge, to\n\t\t\t\t\t// determine if the edge is vertical or horizontal\n\n\t\t\t\t\tvec4 rgbaAlongH = FxaaTexOff(tex, posM, vec2( dirToEdge.x, -dirToEdge.y ), fxaaQualityRcpFrame.xy);\n\t\t\t\t\tfloat matchAlongH = contrast( rgbaM, rgbaAlongH );\n\t\t\t\t\t// . 1 .\n\t\t\t\t\t// 0 0 1\n\t\t\t\t\t// . 0 H\n\n\t\t\t\t\tvec4 rgbaAlongV = FxaaTexOff(tex, posM, vec2( -dirToEdge.x, dirToEdge.y ), fxaaQualityRcpFrame.xy);\n\t\t\t\t\tfloat matchAlongV = contrast( rgbaM, rgbaAlongV );\n\t\t\t\t\t// V 1 .\n\t\t\t\t\t// 0 0 1\n\t\t\t\t\t// . 0 .\n\n\t\t\t\t\trelativeVContrast = matchAlongV - matchAlongH;\n\t\t\t\t\trelativeVContrast *= fxaaQualityinvEdgeThreshold;\n\n\t\t\t\t\tif( abs( relativeVContrast ) < .3 ) { // 45 deg edge\n\t\t\t\t\t\t\t// 1 1 .\n\t\t\t\t\t\t\t// 0 0 1\n\t\t\t\t\t\t\t// . 0 1\n\n\t\t\t\t\t\t\t// do a simple blur\n\t\t\t\t\t\t\treturn mix(\n\t\t\t\t\t\t\t\t\trgbaM,\n\t\t\t\t\t\t\t\t\t(rgbaN + rgbaS + rgbaE + rgbaW) * .25,\n\t\t\t\t\t\t\t\t\t.4\n\t\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\thorzSpan = relativeVContrast > 0.;\n\t\t\t}\n\n\t\t\tif(!horzSpan) rgbaN = rgbaW;\n\t\t\tif(!horzSpan) rgbaS = rgbaE;\n\t\t\t// . 0 . 1\n\t\t\t// 1 0 1 -> 0\n\t\t\t// . 0 . 1\n\n\t\t\tbool pairN = contrast( rgbaM, rgbaN ) > contrast( rgbaM, rgbaS );\n\t\t\tif(!pairN) rgbaN = rgbaS;\n\n\t\t\tvec2 offNP;\n\t\t\toffNP.x = (!horzSpan) ? 0.0 : fxaaQualityRcpFrame.x;\n\t\t\toffNP.y = ( horzSpan) ? 0.0 : fxaaQualityRcpFrame.y;\n\n\t\t\tbool doneN = false;\n\t\t\tbool doneP = false;\n\n\t\t\tfloat nDist = 0.;\n\t\t\tfloat pDist = 0.;\n\n\t\t\tvec2 posN = posM;\n\t\t\tvec2 posP = posM;\n\n\t\t\tint iterationsUsed = 0;\n\t\t\tint iterationsUsedN = 0;\n\t\t\tint iterationsUsedP = 0;\n\t\t\tfor( int i = 0; i < NUM_SAMPLES; i++ ) {\n\t\t\t\t\titerationsUsed = i;\n\n\t\t\t\t\tfloat increment = float(i + 1);\n\n\t\t\t\t\tif(!doneN) {\n\t\t\t\t\t\t\tnDist += increment;\n\t\t\t\t\t\t\tposN = posM + offNP * nDist;\n\t\t\t\t\t\t\tvec4 rgbaEndN = FxaaTexTop(tex, posN.xy);\n\t\t\t\t\t\t\tdoneN = contrast( rgbaEndN, rgbaM ) > contrast( rgbaEndN, rgbaN );\n\t\t\t\t\t\t\titerationsUsedN = i;\n\t\t\t\t\t}\n\n\t\t\t\t\tif(!doneP) {\n\t\t\t\t\t\t\tpDist += increment;\n\t\t\t\t\t\t\tposP = posM - offNP * pDist;\n\t\t\t\t\t\t\tvec4 rgbaEndP = FxaaTexTop(tex, posP.xy);\n\t\t\t\t\t\t\tdoneP = contrast( rgbaEndP, rgbaM ) > contrast( rgbaEndP, rgbaN );\n\t\t\t\t\t\t\titerationsUsedP = i;\n\t\t\t\t\t}\n\n\t\t\t\t\tif(doneN || doneP) break;\n\t\t\t}\n\n\n\t\t\tif ( !doneP && !doneN ) return rgbaM; // failed to find end of edge\n\n\t\t\tfloat dist = min(\n\t\t\t\t\tdoneN ? float( iterationsUsedN ) / float( NUM_SAMPLES - 1 ) : 1.,\n\t\t\t\t\tdoneP ? float( iterationsUsedP ) / float( NUM_SAMPLES - 1 ) : 1.\n\t\t\t);\n\n\t\t\t// hacky way of reduces blurriness of mostly diagonal edges\n\t\t\t// but reduces AA quality\n\t\t\tdist = pow(dist, .5);\n\n\t\t\tdist = 1. - dist;\n\n\t\t\treturn mix(\n\t\t\t\t\trgbaM,\n\t\t\t\t\trgbaN,\n\t\t\t\t\tdist * .5\n\t\t\t);\n\t}\n\n\tvoid main() {\n\t\t\tconst float edgeDetectionQuality = 0.1 ;//.05 ; //\u8D8A\u9AD8\uFF0C\u8D8A\u4FDD\u7559\u7EC6\u8282\uFF1B\u8D8A\u4F4E\uFF0C\u8D8A\u5E73\u6ED1 \u4F46\u6A21\u7CCA \n\t\t\tconst float invEdgeDetectionQuality = 1. / edgeDetectionQuality;\n\n\t\t\tgl_FragColor = FxaaPixelShader(\n\t\t\t\t\tvUv,\n\t\t\t\t\ttDiffuse,\n\t\t\t\t\tresolution,\n\t\t\t\t\tedgeDetectionQuality, // [0,1] contrast needed, otherwise early discard\n\t\t\t\t\tinvEdgeDetectionQuality\n\t\t\t);\n //\u5355\u72EC\u6E32\u67D3\u6D4B\u91CF\u7EBF\u6709\u9ED1\u8FB9\uFF0C\u56E0\u4E3A\u900F\u660E\u533A\u57DF\u7684clearColor\u662F(0,0,0)\uFF0C\u6A21\u7CCA\u5316\u7684\u65F6\u5019\u91C7\u7528\u4E86\u8FD9\u4E9B\u9ED1\u8272\u56E0\u5B50\u6765\u6DF7\u8272\u3002\u56E0\u4E3A\u6D4B\u91CF\u7EBF\u989C\u8272\u53EF\u80FD\u591A\u79CD\uFF0C\u4E5F\u4E0D\u80FD\u76F4\u63A5\u4FEE\u6539clearColor\u4E3A\u5176\u989C\u8272\uFF0C\u4E14\u8FD8\u6709label\u3002\n //\u6545\u800C\u65E0\u6CD5\u5355\u72EC\u6E32\u67D3\u6D4B\u91CF\u7EBF\uFF0C\u800C\u9700\u8981\u5C06\u5E95\u56FE\u4E00\u8D77\u6E32\u67D3\u3002\n }\n\t"
  79993. };
  79994. /**
  79995. * @author spidersharma / http://eduperiment.com/
  79996. */
  79997. var OutlinePass = function OutlinePass(selectedObjects) {
  79998. /* scene = scene;
  79999. camera = camera; */
  80000. this.selectedObjects = selectedObjects !== undefined ? selectedObjects : [];
  80001. this.visibleEdgeColor = new Color(1, 1, 1);
  80002. this.hiddenEdgeColor = new Color(0.1, 0.04, 0.02);
  80003. this.edgeGlow = 0.0;
  80004. this.usePatternTexture = false;
  80005. //this.edgeThickness = 1.0;
  80006. this.edgeStrength = 50;
  80007. this.downSampleRatio = 1; //2; // 抗锯齿 值越低renderTarget size越大,抗锯齿越强,线条可越细(或许可以把模糊化去掉?)
  80008. this.pulsePeriod = 0;
  80009. this.showHiddenPart = false; //是否判断被遮住的部分,以设置hiddenEdgeColor。一般不需要
  80010. Pass.call(this);
  80011. this.resolution = new Vector2(256, 256);
  80012. var pars = {
  80013. minFilter: LinearFilter,
  80014. magFilter: LinearFilter,
  80015. format: RGBAFormat
  80016. };
  80017. var resx = Math.round(this.resolution.x / this.downSampleRatio);
  80018. var resy = Math.round(this.resolution.y / this.downSampleRatio);
  80019. this.renderTargetMaskBuffer = new WebGLRenderTarget(this.resolution.x, this.resolution.y, pars);
  80020. this.renderTargetMaskBuffer.texture.name = "OutlinePass.mask";
  80021. this.renderTargetMaskBuffer.texture.generateMipmaps = false;
  80022. this.depthMaterial = new MeshDepthMaterial();
  80023. this.depthMaterial.side = DoubleSide;
  80024. this.depthMaterial.depthPacking = RGBADepthPacking;
  80025. this.depthMaterial.blending = NoBlending;
  80026. this.prepareMaskMaterial = this.getPrepareMaskMaterial();
  80027. this.prepareMaskMaterial.side = DoubleSide;
  80028. this.renderTargetDepthBuffer = new WebGLRenderTarget(this.resolution.x, this.resolution.y, pars);
  80029. this.renderTargetDepthBuffer.texture.name = "OutlinePass.depth";
  80030. this.renderTargetDepthBuffer.texture.generateMipmaps = false;
  80031. this.edgeDetectionMaterial = this.getEdgeDetectionMaterial(this.edgeStrength);
  80032. this.renderTargetEdgeBuffer1 = new WebGLRenderTarget(resx, resy, pars);
  80033. this.renderTargetEdgeBuffer1.texture.name = "OutlinePass.edge1";
  80034. this.renderTargetEdgeBuffer1.texture.generateMipmaps = false;
  80035. // Overlay material
  80036. this.overlayMaterial = this.getOverlayMaterial();
  80037. // copy material
  80038. this.copyUniforms = UniformsUtils.clone(CopyShader.uniforms);
  80039. this.copyUniforms["opacity"].value = 1.0;
  80040. this.materialCopy = new ShaderMaterial({
  80041. uniforms: this.copyUniforms,
  80042. vertexShader: CopyShader.vertexShader,
  80043. fragmentShader: CopyShader.fragmentShader,
  80044. blending: NoBlending,
  80045. depthTest: false,
  80046. depthWrite: false,
  80047. transparent: true
  80048. });
  80049. this.enabled = true;
  80050. this.needsSwap = false;
  80051. this.oldClearColor = new Color();
  80052. this.oldClearAlpha = 1;
  80053. this.camera = new OrthographicCamera(-1, 1, 1, -1, 0, 1);
  80054. this.scene = new Scene();
  80055. this.quad = new Mesh(new PlaneBufferGeometry(2, 2), null);
  80056. this.quad.frustumCulled = false; // Avoid getting clipped
  80057. this.scene.add(this.quad);
  80058. this.textureMatrix = new Matrix4();
  80059. viewer.addEventListener('viewerResize', e => {
  80060. var size = viewer.renderer.getSize(new Vector2());
  80061. this.renderTargetEdgeBuffer1.setSize(size.x, size.y);
  80062. this.renderTargetMaskBuffer.setSize(size.x, size.y);
  80063. this.resolution.set(size.x, size.y);
  80064. });
  80065. };
  80066. OutlinePass.prototype = Object.assign(Object.create(Pass.prototype), {
  80067. constructor: OutlinePass,
  80068. dispose: function dispose() {
  80069. this.renderTargetMaskBuffer.dispose();
  80070. this.renderTargetEdgeBuffer1.dispose();
  80071. this.renderTargetDepthBuffer.dispose();
  80072. },
  80073. replaceDepthToViewZ(camera) {
  80074. var type = camera.isPerspectiveCamera ? 'perspective' : 'orthographic';
  80075. if (type == this.lastCameraType) return;
  80076. this.lastCameraType = type;
  80077. this.prepareMaskMaterial.fragmentShader = this.prepareMaskMaterial.fragmentShader.replace(/DEPTH_TO_VIEW_Z/g, type + 'DepthToViewZ');
  80078. this.prepareMaskMaterial.needsUpdate = true;
  80079. },
  80080. setSize: function setSize(width, height) {},
  80081. changeVisibilityOfSelectedObjects: function changeVisibilityOfSelectedObjects(bVisible) {
  80082. function gatherSelectedMeshesCallBack(object) {
  80083. /* if ( object.isMesh ) { */
  80084. if (object.isPointcloud || object.isMesh || object.isLine || object.isSprite) {
  80085. /* if ( bVisible ) {
  80086. object.visible = object.userData.oldVisible;
  80087. delete object.userData.oldVisible;
  80088. } else {
  80089. object.userData.oldVisible = object.visible;
  80090. object.visible = bVisible;
  80091. } */
  80092. Potree.Utils.updateVisible(object, 'overlinePass', bVisible);
  80093. }
  80094. }
  80095. for (var i = 0; i < this.selectedObjects.length; i++) {
  80096. var selectedObject = this.selectedObjects[i];
  80097. selectedObject.traverse(gatherSelectedMeshesCallBack);
  80098. }
  80099. },
  80100. changeVisibilityOfNonSelectedObjects: function changeVisibilityOfNonSelectedObjects(bVisible, scenes) {
  80101. var selectedMeshes = [];
  80102. function gatherSelectedMeshesCallBack(object) {
  80103. //if ( object.isMesh ) selectedMeshes.push( object );
  80104. if (object.isPointcloud || object.isMesh || object.isLine || object.isSprite) {
  80105. selectedMeshes.push(object);
  80106. }
  80107. }
  80108. for (var i = 0; i < this.selectedObjects.length; i++) {
  80109. var selectedObject = this.selectedObjects[i];
  80110. selectedObject.traverse(gatherSelectedMeshesCallBack);
  80111. }
  80112. function VisibilityChangeCallBack(object) {
  80113. if (object.isPointcloud || object.isMesh || object.isLine || object.isSprite) {
  80114. var bFound = false;
  80115. for (var i = 0; i < selectedMeshes.length; i++) {
  80116. var selectedObjectId = selectedMeshes[i].id;
  80117. if (selectedObjectId === object.id) {
  80118. bFound = true;
  80119. break;
  80120. }
  80121. }
  80122. if (!bFound) {
  80123. var visibility = object.visible;
  80124. Potree.Utils.updateVisible(object, 'overlinePass', bVisible); //add
  80125. //但保不齐在设置为false后,渲染时又true了,所以在其他地方update时设置visible 得用updateVisible
  80126. if (!bVisible) {
  80127. object.visible = false;
  80128. } else {
  80129. object.visible = !!object.bVisible;
  80130. }
  80131. object.bVisible = visibility;
  80132. //这两种updateVisible 和 visible 设置都不能去掉, 第一块是为了防止有的visible不是通过updateVisible设置的; 第二块是为了防止渲染时updateVisible又修改了visible为true, 另外渲染时
  80133. return {
  80134. stopContinue: true
  80135. }; //for pointcloud
  80136. }
  80137. }
  80138. }
  80139. scenes.forEach(scene => scene.traverse(VisibilityChangeCallBack));
  80140. },
  80141. updateTextureMatrix: function updateTextureMatrix(camera) {
  80142. this.textureMatrix.set(0.5, 0.0, 0.0, 0.5, 0.0, 0.5, 0.0, 0.5, 0.0, 0.0, 0.5, 0.5, 0.0, 0.0, 0.0, 1.0);
  80143. this.textureMatrix.multiply(camera.projectionMatrix);
  80144. this.textureMatrix.multiply(camera.matrixWorldInverse);
  80145. },
  80146. render: function render(scenes, camera, viewports, renderer, writeBuffer, readBuffer, maskActive, renderFun) {
  80147. if (!(scenes instanceof Array)) scenes = [scenes];
  80148. if (this.selectedObjects.length > 0 && this.edgeStrength > 0) {
  80149. var render2 = function render2(target) {
  80150. var dontRenderRtEDL = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  80151. if (renderFun) {
  80152. renderFun({
  80153. target,
  80154. dontRenderRtEDL
  80155. });
  80156. } else {
  80157. renderer.setRenderTarget(target);
  80158. renderer.clear();
  80159. scenes.forEach(scene => renderer.render(scene, camera));
  80160. }
  80161. };
  80162. this.oldClearColor.copy(renderer.getClearColor(new Color()));
  80163. this.oldClearAlpha = renderer.getClearAlpha();
  80164. var oldAutoClear = renderer.autoClear;
  80165. var oldTarget = renderer.getRenderTarget();
  80166. renderer.autoClear = false;
  80167. if (maskActive) renderer.context.disable(renderer.context.STENCIL_TEST);
  80168. renderer.setClearColor(0xffffff, 1);
  80169. var oldBG = viewer.background,
  80170. oldBgOpacity = viewer.backgroundOpacity;
  80171. viewer.background = new Color(1, 1, 1);
  80172. viewer.backgroundOpacity = 1;
  80173. if (this.showHiddenPart) {
  80174. //几乎不会使用
  80175. viewports.forEach(e => {
  80176. e.oldBeforeRender = e.beforeRender;
  80177. e.beforeRender = () => {
  80178. e.oldBeforeRender && e.oldBeforeRender();
  80179. this.replaceDepthToViewZ(e.camera);
  80180. };
  80181. });
  80182. // Make selected objects invisible
  80183. this.changeVisibilityOfSelectedObjects(false);
  80184. scenes.forEach(scene => {
  80185. scene.currentBackground = scene.background;
  80186. scene.background = null;
  80187. // 1. Draw Non Selected objects in the depth buffer
  80188. scene.overrideMaterial = this.depthMaterial;
  80189. });
  80190. render2(this.renderTargetDepthBuffer);
  80191. // Make selected objects visible
  80192. this.changeVisibilityOfSelectedObjects(true);
  80193. viewports.forEach(e => {
  80194. e.beforeRender = () => {
  80195. e.oldBeforeRender && e.oldBeforeRender();
  80196. // Update Texture Matrix for Depth compare
  80197. this.updateTextureMatrix(e.camera);
  80198. this.prepareMaskMaterial.uniforms["cameraNearFar"].value = new Vector2(e.camera.near, e.camera.far);
  80199. };
  80200. });
  80201. } else {
  80202. //不渲染背景
  80203. scenes.forEach(scene => {
  80204. scene.currentBackground = scene.background;
  80205. scene.background = null;
  80206. });
  80207. }
  80208. var colorType,
  80209. colors = new Map(),
  80210. opas = new Map();
  80211. {
  80212. //绘制选中部分
  80213. // Make non selected objects invisible, and draw only the selected objects, by comparing the depth buffer of non selected objects
  80214. this.changeVisibilityOfNonSelectedObjects(false, scenes);
  80215. scenes.forEach(scene => {
  80216. scene.overrideMaterial = this.prepareMaskMaterial;
  80217. });
  80218. if (this.showHiddenPart) {
  80219. this.prepareMaskMaterial.uniforms["depthTexture"].value = this.renderTargetDepthBuffer.texture;
  80220. this.prepareMaskMaterial.uniforms["textureMatrix"].value = this.textureMatrix;
  80221. }
  80222. //因为点云不受prepareMaskMaterial作用,所以手动将他们变为黑色不透明
  80223. viewer.scene.pointclouds.forEach(e => {
  80224. //先将点云透明度变为1,因为点云透明度莫名其妙会影响其r值//
  80225. colorType = e.material.activeAttributeName;
  80226. e.material.activeAttributeName = 'color';
  80227. colors.set(e, e.material.color);
  80228. e.material.color = '#000000';
  80229. opas.set(e, e.material.opacity);
  80230. e.material.opacity = 1;
  80231. });
  80232. }
  80233. render2(this.renderTargetMaskBuffer);
  80234. {
  80235. //恢复
  80236. viewer.scene.pointclouds.forEach(e => {
  80237. e.material.activeAttributeName = colorType;
  80238. e.material.color = colors.get(e);
  80239. e.material.opacity = opas.get(e);
  80240. });
  80241. if (this.showHiddenPart) {
  80242. viewports.forEach(e => {
  80243. e.beforeRender = e.oldBeforeRender;
  80244. });
  80245. }
  80246. scenes.forEach(scene => {
  80247. scene.overrideMaterial = null;
  80248. scene.background = scene.currentBackground;
  80249. });
  80250. viewer.background = oldBG;
  80251. viewer.backgroundOpacity = oldBgOpacity;
  80252. this.changeVisibilityOfNonSelectedObjects(true, scenes);
  80253. }
  80254. //检测边缘并绘制
  80255. // 3. Apply Edge Detection Pass
  80256. this.quad.material = this.edgeDetectionMaterial;
  80257. this.edgeDetectionMaterial.uniforms["maskTexture"].value = this.renderTargetMaskBuffer.texture; //this.renderTargetMaskDownSampleBuffer.texture;
  80258. this.edgeDetectionMaterial.uniforms["texSize"].value = new Vector2(this.resolution.x, this.resolution.y); //new THREE.Vector2( this.renderTargetMaskDownSampleBuffer.width, this.renderTargetMaskDownSampleBuffer.height );
  80259. //this.edgeDetectionMaterial.uniforms[ "texSize" ].value = new THREE.Vector2(this.renderTargetMaskBuffer.width, this.renderTargetMaskBuffer.height)//new THREE.Vector2( this.renderTargetMaskDownSampleBuffer.width, this.renderTargetMaskDownSampleBuffer.height );
  80260. this.edgeDetectionMaterial.uniforms["edgeStrength"].value = this.edgeStrength;
  80261. this.edgeDetectionMaterial.uniforms["visibleEdgeColor"].value = this.visibleEdgeColor; //this.tempPulseColor1;
  80262. this.edgeDetectionMaterial.uniforms["hiddenEdgeColor"].value = this.hiddenEdgeColor; //this.tempPulseColor2;
  80263. var buffer;
  80264. if (this.renderToScreen) {
  80265. this.quad.material.transparent = true;
  80266. buffer = null;
  80267. renderer.setClearColor(this.oldClearColor, this.oldClearAlpha);
  80268. render2(null, false); //普通绘制原场景
  80269. //绘制到全屏
  80270. var renderSize = renderer.getSize(new Vector2()); //是client大小
  80271. renderer.setViewport(0, 0, renderSize.x, renderSize.y); //规定视口,影响图形变换(画布的使用范围)
  80272. renderer.setScissorTest(false);
  80273. } else {
  80274. buffer = readBuffer;
  80275. renderer.setClearColor(0x000000, 0);
  80276. renderer.clear();
  80277. }
  80278. renderer.setRenderTarget(buffer);
  80279. renderer.render(this.scene, this.camera); //将边缘覆盖上去
  80280. renderer.setRenderTarget(oldTarget);
  80281. renderer.setClearColor(this.oldClearColor, this.oldClearAlpha);
  80282. renderer.autoClear = oldAutoClear;
  80283. return true;
  80284. }
  80285. },
  80286. getPrepareMaskMaterial: function getPrepareMaskMaterial() {
  80287. if (this.showHiddenPart) {
  80288. return new ShaderMaterial({
  80289. uniforms: {
  80290. "depthTexture": {
  80291. value: null
  80292. },
  80293. "cameraNearFar": {
  80294. value: new Vector2(0.5, 0.5)
  80295. },
  80296. "textureMatrix": {
  80297. value: new Matrix4()
  80298. }
  80299. },
  80300. vertexShader: ['varying vec4 projTexCoord;', 'varying vec4 vPosition;', 'uniform mat4 textureMatrix;', 'void main() {', ' vPosition = modelViewMatrix * vec4( position, 1.0 );', ' vec4 worldPosition = modelMatrix * vec4( position, 1.0 );', ' projTexCoord = textureMatrix * worldPosition;', ' gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );', '}'].join('\n'),
  80301. fragmentShader: ['#include <packing>', 'varying vec4 vPosition;', 'varying vec4 projTexCoord;', 'uniform sampler2D depthTexture;', 'uniform vec2 cameraNearFar;', 'void main() {', ' float depth = unpackRGBAToDepth(texture2DProj( depthTexture, projTexCoord ));', ' float viewZ = - DEPTH_TO_VIEW_Z( depth, cameraNearFar.x, cameraNearFar.y );', ' float depthTest = (-vPosition.z > viewZ) ? 1.0 : 0.0;',
  80302. //决定是否为hiddenPart
  80303. ' gl_FragColor = vec4(0.0, depthTest, 1.0, 1.0);', '}'].join('\n')
  80304. }); //没有绘制部分的颜色是clearColor,255
  80305. } else {
  80306. return new MeshBasicMaterial({
  80307. color: '#000000'
  80308. }); //不检测深度,不判断遮挡
  80309. }
  80310. },
  80311. getEdgeDetectionMaterial: function getEdgeDetectionMaterial(edgeStrength) {
  80312. return new ShaderMaterial({
  80313. uniforms: {
  80314. "edgeStrength": {
  80315. value: edgeStrength
  80316. },
  80317. "maskTexture": {
  80318. value: null
  80319. },
  80320. "texSize": {
  80321. value: new Vector2(10, 10)
  80322. },
  80323. "visibleEdgeColor": {
  80324. value: new Vector3(1.0, 1.0, 1.0)
  80325. },
  80326. "hiddenEdgeColor": {
  80327. value: new Vector3(1.0, 1.0, 1.0)
  80328. }
  80329. },
  80330. vertexShader: "varying vec2 vUv;\n\
  80331. void main() {\n\
  80332. vUv = uv;\n\
  80333. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\
  80334. }",
  80335. /* fragmentShader:
  80336. "varying vec2 vUv;\
  80337. uniform sampler2D maskTexture;\
  80338. uniform vec2 texSize;\
  80339. uniform vec3 visibleEdgeColor;\
  80340. uniform vec3 hiddenEdgeColor;\
  80341. \
  80342. void main() {\n\
  80343. vec2 invSize = 1.0 / texSize;\
  80344. vec4 uvOffset = vec4(1.0, 0.0, 0.0, 1.0) * vec4(invSize, invSize);\
  80345. vec4 c1 = texture2D( maskTexture, vUv + uvOffset.xy);\
  80346. vec4 c2 = texture2D( maskTexture, vUv - uvOffset.xy);\
  80347. vec4 c3 = texture2D( maskTexture, vUv + uvOffset.yw);\
  80348. vec4 c4 = texture2D( maskTexture, vUv - uvOffset.yw);\
  80349. float diff1 = (c1.r - c2.r)*0.5;\
  80350. float diff2 = (c3.r - c4.r)*0.5;\
  80351. float d = length( vec2(diff1, diff2) );\
  80352. float a1 = min(c1.g, c2.g);\
  80353. float a2 = min(c3.g, c4.g);\
  80354. float visibilityFactor = min(a1, a2);\
  80355. vec3 edgeColor = 1.0 - visibilityFactor > 0.001 ? visibleEdgeColor : hiddenEdgeColor;\
  80356. gl_FragColor = vec4(edgeColor, 1.0) * vec4(d);\
  80357. }" */
  80358. fragmentShader: "varying vec2 vUv;\n\t\t\t\tuniform sampler2D maskTexture;\n uniform float edgeStrength;\n\t\t\t\tuniform vec2 texSize;\n\t\t\t\tuniform vec3 visibleEdgeColor;\n\t\t\t\tuniform vec3 hiddenEdgeColor;\n\t\t\t\t\n\t\t\t\tvoid main() { \n const float thickness = 1.0;\n vec2 invSize = thickness / texSize;\n\t\t\t\t\tvec4 uvOffset = vec4(1.0, 0.0, 0.0, 1.0) * vec4(invSize, invSize);\n\t\t\t\t\tvec4 c1 = texture2D( maskTexture, vUv + uvOffset.xy);\n\t\t\t\t\tvec4 c2 = texture2D( maskTexture, vUv - uvOffset.xy);\n\t\t\t\t\tvec4 c3 = texture2D( maskTexture, vUv + uvOffset.yw);\n\t\t\t\t\tvec4 c4 = texture2D( maskTexture, vUv - uvOffset.yw);\n\t\t\t\t\tfloat diff1 = (c1.r - c2.r)*0.5; //\u68C0\u6D4B\u8FB9\u7F18\uFF0C\n\t\t\t\t\tfloat diff2 = (c3.r - c4.r)*0.5;\n\t\t\t\t\tfloat d = length( vec2(diff1, diff2) ) * edgeStrength;\n\t\t\t\t\tfloat a1 = min(c1.g, c2.g);\n\t\t\t\t\tfloat a2 = min(c3.g, c4.g);\n\t\t\t\t\tfloat visibilityFactor = min(a1, a2); //\u68C0\u6D4B\u6DF1\u5EA6\u503C\uFF0C\u662F\u5426\u88AB\u906E\u6321\n\t\t\t\t\tvec3 edgeColor = 1.0 - visibilityFactor > 0.001 ? visibleEdgeColor : hiddenEdgeColor;\n\t\t\t\t\t//gl_FragColor = vec4(0.0,1.0,0.0,1.0); \n gl_FragColor = vec4(edgeColor, 1.0) * vec4(d); \n\t\t\t\t}"
  80359. });
  80360. //为什么vec4(0.0,1.0,1.0,1.0); 显示出来的是rgb(109,255,255) ? 几乎只有绿色通道会影响红色通道
  80361. },
  80362. getSeperableBlurMaterial: function getSeperableBlurMaterial(maxRadius) {
  80363. return new ShaderMaterial({
  80364. defines: {
  80365. "MAX_RADIUS": maxRadius
  80366. },
  80367. uniforms: {
  80368. "colorTexture": {
  80369. value: null
  80370. },
  80371. "texSize": {
  80372. value: new Vector2(0.5, 0.5)
  80373. },
  80374. "direction": {
  80375. value: new Vector2(0.5, 0.5)
  80376. },
  80377. "kernelRadius": {
  80378. value: 1.0
  80379. }
  80380. },
  80381. vertexShader: "varying vec2 vUv;\n\
  80382. void main() {\n\
  80383. vUv = uv;\n\
  80384. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\
  80385. }",
  80386. fragmentShader: "#include <common>\
  80387. varying vec2 vUv;\
  80388. uniform sampler2D colorTexture;\
  80389. uniform vec2 texSize;\
  80390. uniform vec2 direction;\
  80391. uniform float kernelRadius;\
  80392. \
  80393. float gaussianPdf(in float x, in float sigma) {\
  80394. return 0.39894 * exp( -0.5 * x * x/( sigma * sigma))/sigma;\
  80395. }\
  80396. void main() {\
  80397. vec2 invSize = 1.0 / texSize;\
  80398. float weightSum = gaussianPdf(0.0, kernelRadius);\
  80399. vec3 diffuseSum = texture2D( colorTexture, vUv).rgb * weightSum;\
  80400. vec2 delta = direction * invSize * kernelRadius/float(MAX_RADIUS);\
  80401. vec2 uvOffset = delta;\
  80402. for( int i = 1; i <= MAX_RADIUS; i ++ ) {\
  80403. float w = gaussianPdf(uvOffset.x, kernelRadius);\
  80404. vec3 sample1 = texture2D( colorTexture, vUv + uvOffset).rgb;\
  80405. vec3 sample2 = texture2D( colorTexture, vUv - uvOffset).rgb;\
  80406. diffuseSum += ((sample1 + sample2) * w);\
  80407. weightSum += (2.0 * w);\
  80408. uvOffset += delta;\
  80409. }\
  80410. gl_FragColor = vec4(diffuseSum/weightSum, 1.0);\
  80411. }"
  80412. });
  80413. },
  80414. getOverlayMaterial: function getOverlayMaterial() {
  80415. //对边缘线进一步处理,已被废弃
  80416. return new ShaderMaterial({
  80417. uniforms: {
  80418. "maskTexture": {
  80419. value: null
  80420. },
  80421. "edgeTexture1": {
  80422. value: null
  80423. },
  80424. "edgeTexture2": {
  80425. value: null
  80426. },
  80427. "patternTexture": {
  80428. value: null
  80429. },
  80430. "edgeStrength": {
  80431. value: 1.0
  80432. },
  80433. "edgeGlow": {
  80434. value: 1.0
  80435. },
  80436. "usePatternTexture": {
  80437. value: 0.0
  80438. }
  80439. },
  80440. vertexShader: "varying vec2 vUv;\n\
  80441. void main() {\n\
  80442. vUv = uv;\n\
  80443. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\
  80444. }",
  80445. /* fragmentShader:
  80446. "varying vec2 vUv;\
  80447. uniform sampler2D maskTexture;\
  80448. uniform sampler2D edgeTexture1;\
  80449. uniform sampler2D edgeTexture2;\
  80450. uniform sampler2D patternTexture;\
  80451. uniform float edgeStrength;\
  80452. uniform float edgeGlow;\
  80453. uniform bool usePatternTexture;\
  80454. \
  80455. void main() {\
  80456. vec4 edgeValue1 = texture2D(edgeTexture1, vUv);\
  80457. vec4 edgeValue2 = texture2D(edgeTexture2, vUv);\
  80458. vec4 maskColor = texture2D(maskTexture, vUv);\
  80459. vec4 patternColor = texture2D(patternTexture, 6.0 * vUv);\
  80460. float visibilityFactor = 1.0 - maskColor.g > 0.0 ? 1.0 : 0.5;\
  80461. vec4 edgeValue = edgeValue1 + edgeValue2 * edgeGlow;\
  80462. vec4 finalColor = edgeStrength * maskColor.r * edgeValue;\ // 删除 * maskColor.r 也就是去掉遮罩,使模型部分也有outline
  80463. if(usePatternTexture)\
  80464. finalColor += + visibilityFactor * (1.0 - maskColor.r) * (1.0 - patternColor.r);\
  80465. gl_FragColor = finalColor;\
  80466. }", */
  80467. fragmentShader: "varying vec2 vUv; \n\t\t\t\tuniform sampler2D edgeTexture1; \n\t\t\t\tuniform float edgeStrength; \n\t\t\t\t \n\t\t\t\tvoid main() { \n\t\t\t\t\tgl_FragColor = edgeStrength * texture2D(edgeTexture1, vUv); \n\t\t\t\t}",
  80468. blending: AdditiveBlending,
  80469. depthTest: false,
  80470. depthWrite: false,
  80471. transparent: true
  80472. });
  80473. }
  80474. });
  80475. OutlinePass.BlurDirectionX = new Vector2(1.0, 0.0);
  80476. OutlinePass.BlurDirectionY = new Vector2(0.0, 1.0);
  80477. /*
  80478. 渲染步骤:(没有showHiddenPart时)
  80479. 仅绘制选中部分,材质为普通的单色材质,颜色是黑色不透明。未绘制部分的clearColor是白色不透明。
  80480. (详见prepareMaskMaterial,输出的r要为0)
  80481. 然后在上面绘制的图中,根据r的差值,得到边缘线。
  80482. 正常绘制场景之后,将上面的边缘线覆盖于其上。
  80483. (如果showHiddenPart,最开始还要先隐藏选中部分,这是为了得到非选中部分的深度值,然后再绘制选中部分时去比较选中和非选中部分之间的深度差异。以判断是否被遮挡。)
  80484. */
  80485. /**
  80486. * @author mschuetz / http://mschuetz.at
  80487. *
  80488. * adapted from THREE.OrbitControls by
  80489. *
  80490. * @author qiao / https://github.com/qiao
  80491. * @author mrdoob / http://mrdoob.com
  80492. * @author alteredq / http://alteredqualia.com/
  80493. * @author WestLangley / http://github.com/WestLangley
  80494. * @author erich666 / http://erichaines.com
  80495. *
  80496. *
  80497. *
  80498. */
  80499. var minRadius = 2;
  80500. class OrbitControls$1 extends EventDispatcher {
  80501. constructor(viewer, viewport) {
  80502. super();
  80503. this.viewer = viewer;
  80504. this.renderer = viewer.renderer;
  80505. this.scene = null;
  80506. this.sceneControls = new Scene();
  80507. this.rotationSpeed = 3; //旋转速度
  80508. viewport = viewport || viewer.viewports[0];
  80509. this.setCurrentViewport({
  80510. hoverViewport: viewport,
  80511. force: true
  80512. }); //this.currentViewport = viewport
  80513. this.fadeFactor = 20;
  80514. this.yawDelta = 0;
  80515. this.pitchDelta = 0;
  80516. this.panDelta = new Vector2(0, 0);
  80517. this.radiusDelta = 0;
  80518. this.doubleClockZoomEnabled = true;
  80519. this.tweens = [];
  80520. this.dollyStart = new Vector2();
  80521. this.dollyEnd = new Vector2();
  80522. this.keys = {
  80523. FORWARD: ['W'.charCodeAt(0), 38],
  80524. BACKWARD: ['S'.charCodeAt(0), 40],
  80525. LEFT: ['A'.charCodeAt(0), 37],
  80526. RIGHT: ['D'.charCodeAt(0), 39],
  80527. UP: ['Q'.charCodeAt(0)],
  80528. DOWN: ['E'.charCodeAt(0)]
  80529. };
  80530. var drag = e => {
  80531. if (!this.enabled) return;
  80532. var viewport = e.dragViewport;
  80533. if (!viewport /* || viewport.camera.type == "OrthographicCamera" */) return;
  80534. //let camera = viewport.camera
  80535. if (e.drag.object !== null) {
  80536. return;
  80537. }
  80538. var mode;
  80539. if (e.isTouch) {
  80540. if (e.touches.length == 1) {
  80541. mode = 'rotate';
  80542. } else {
  80543. mode = 'scale-pan';
  80544. }
  80545. } else {
  80546. mode = e.buttons === Potree.defines.Buttons.LEFT ? 'rotate' : 'pan';
  80547. }
  80548. if (e.drag.startHandled === undefined) {
  80549. e.drag.startHandled = true;
  80550. this.dispatchEvent({
  80551. type: 'start'
  80552. });
  80553. }
  80554. var ndrag = e.drag.pointerDelta.clone(); //.add(new THREE.Vector2(1,1)).multiplyScalar(0.5)
  80555. ndrag.y *= -1;
  80556. if (mode == 'rotate') {
  80557. this.yawDelta += ndrag.x * this.rotationSpeed;
  80558. this.pitchDelta += ndrag.y * this.rotationSpeed;
  80559. } else if (mode == 'pan') {
  80560. this.panDelta.x += ndrag.x;
  80561. this.panDelta.y += ndrag.y;
  80562. } else if (mode == 'scale-pan') {
  80563. //add
  80564. this.dollyEnd.subVectors(e.touches[0].pointer, e.touches[1].pointer);
  80565. var scale = this.dollyEnd.length() / this.dollyStart.length();
  80566. this.dollyStart.copy(this.dollyEnd);
  80567. this.radiusDelta = (1 - scale) * this.currentViewport.view.radius;
  80568. //------------------------
  80569. //平移
  80570. var pointer = new Vector2().addVectors(e.touches[0].pointer, e.touches[1].pointer).multiplyScalar(0.5); //两个指头的中心点
  80571. var delta = new Vector2().subVectors(pointer, this.lastScalePointer);
  80572. delta.y *= -1;
  80573. this.panDelta.add(delta);
  80574. this.lastScalePointer = pointer.clone();
  80575. //console.log('scale ',scale, this.radiusDelta)
  80576. }
  80577. this.stopTweens();
  80578. };
  80579. var drop = e => {
  80580. if (!this.enabled) return;
  80581. this.dispatchEvent({
  80582. type: 'end'
  80583. });
  80584. };
  80585. var scroll = e => {
  80586. if (!this.enabled) return;
  80587. var resolvedRadius = this.currentViewport.view.radius + this.radiusDelta;
  80588. if (resolvedRadius < 0.1 && e.delta > 0) return; //防止缩放太小,导致很慢
  80589. this.radiusDelta += -e.delta * resolvedRadius * 0.1;
  80590. this.stopTweens();
  80591. };
  80592. var dblclick = e => {
  80593. if (!this.enabled) return;
  80594. if (this.doubleClockZoomEnabled) {
  80595. this.zoomToLocation(e.mouse);
  80596. }
  80597. };
  80598. var previousTouch = null;
  80599. var touchStart = e => {
  80600. previousTouch = e;
  80601. };
  80602. var touchEnd = e => {
  80603. previousTouch = e;
  80604. };
  80605. var touchMove = e => {
  80606. if (!this.enabled) return;
  80607. if (e.touches.length === 2 && previousTouch.touches.length === 2) {
  80608. var prev = previousTouch;
  80609. var curr = e;
  80610. var prevDX = prev.touches[0].pageX - prev.touches[1].pageX;
  80611. var prevDY = prev.touches[0].pageY - prev.touches[1].pageY;
  80612. var prevDist = Math.sqrt(prevDX * prevDX + prevDY * prevDY);
  80613. var currDX = curr.touches[0].pageX - curr.touches[1].pageX;
  80614. var currDY = curr.touches[0].pageY - curr.touches[1].pageY;
  80615. var currDist = Math.sqrt(currDX * currDX + currDY * currDY);
  80616. var delta = currDist / prevDist;
  80617. var resolvedRadius = this.currentViewport.view.radius + this.radiusDelta;
  80618. var newRadius = resolvedRadius / delta;
  80619. this.radiusDelta = newRadius - resolvedRadius;
  80620. this.stopTweens();
  80621. } else if (e.touches.length === 3 && previousTouch.touches.length === 3) {
  80622. var _prev = previousTouch;
  80623. var _curr = e;
  80624. var prevMeanX = (_prev.touches[0].pageX + _prev.touches[1].pageX + _prev.touches[2].pageX) / 3;
  80625. var prevMeanY = (_prev.touches[0].pageY + _prev.touches[1].pageY + _prev.touches[2].pageY) / 3;
  80626. var currMeanX = (_curr.touches[0].pageX + _curr.touches[1].pageX + _curr.touches[2].pageX) / 3;
  80627. var currMeanY = (_curr.touches[0].pageY + _curr.touches[1].pageY + _curr.touches[2].pageY) / 3;
  80628. var _delta = {
  80629. x: (currMeanX - prevMeanX) / this.renderer.domElement.clientWidth,
  80630. y: (currMeanY - prevMeanY) / this.renderer.domElement.clientHeight
  80631. };
  80632. this.panDelta.x += _delta.x;
  80633. this.panDelta.y += _delta.y;
  80634. this.stopTweens();
  80635. }
  80636. previousTouch = e;
  80637. };
  80638. this.addEventListener('touchstart', touchStart);
  80639. this.addEventListener('touchend', touchEnd);
  80640. this.addEventListener('touchmove', touchMove);
  80641. this.viewer.addEventListener('global_drag', drag);
  80642. this.viewer.addEventListener('global_drop', drop);
  80643. this.viewer.addEventListener('global_mousewheel', scroll);
  80644. this.viewer.addEventListener('global_dblclick', dblclick);
  80645. this.viewer.addEventListener('global_touchmove', e => {
  80646. if (e.touches.length > 1) {
  80647. //单指的就触发上一句
  80648. //console.log('global_touchmove' )
  80649. drag(e);
  80650. }
  80651. });
  80652. var prepareScale = e => {
  80653. //触屏的scale
  80654. this.dollyStart.subVectors(e.touches[0].pointer, e.touches[1].pointer);
  80655. this.lastScalePointer = new Vector2().addVectors(e.touches[0].pointer, e.touches[1].pointer).multiplyScalar(0.5); //两个指头的中心点
  80656. };
  80657. this.viewer.addEventListener('global_touchstart', e => {
  80658. if (this.enabled && e.touches.length == 2) {
  80659. //只监听开头两个指头
  80660. prepareScale(e);
  80661. }
  80662. });
  80663. /* this.viewer.addEventListener('global_touchend', (e)=>{
  80664. if(!this.enabled)return
  80665. if(e.touches.length==1){//停止scale,开始rotate
  80666. prepareRotate(e)
  80667. //this.pointerDragStart = null
  80668. //console.log('只剩一个', e.pointer.toArray())
  80669. }
  80670. }) */
  80671. this.viewer.addEventListener('focusOnObject', o => {
  80672. if (o.position && o.CamTarget) {
  80673. var distance = o.position.distanceTo(o.CamTarget);
  80674. if (distance < minRadius) minRadius = distance * 0.5; //融合页面当focus一个很小的物体时,需要将minRadius也调小
  80675. }
  80676. });
  80677. }
  80678. setScene(scene) {
  80679. this.scene = scene;
  80680. }
  80681. setCurrentViewport() {
  80682. var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  80683. //add
  80684. if (!this.enabled && !o.force) return;
  80685. if (o.hoverViewport && this.currentViewport != o.hoverViewport) {
  80686. this.currentViewport = o.hoverViewport;
  80687. }
  80688. }
  80689. setEnable(enabled) {
  80690. this.enabled = enabled;
  80691. }
  80692. stop() {
  80693. this.yawDelta = 0;
  80694. this.pitchDelta = 0;
  80695. this.radiusDelta = 0;
  80696. this.panDelta.set(0, 0);
  80697. }
  80698. /* zoomToLocation(mouse){
  80699. if(!this.enabled)return
  80700. let camera = this.scene.getActiveCamera();
  80701. let I = Utils.getMousePointCloudIntersection(
  80702. null, mouse, this.viewer.inputHandler.pointer,
  80703. camera,
  80704. this.viewer,
  80705. this.scene.pointclouds,
  80706. {pickClipped: true});
  80707. if (I === null) {
  80708. return;
  80709. }
  80710. let targetRadius = 0;
  80711. {
  80712. let minimumJumpDistance = 0.2;
  80713. let domElement = this.renderer.domElement;
  80714. let ray = Utils.mouseToRay(this.viewer.inputHandler.pointer , camera, domElement.clientWidth, domElement.clientHeight);
  80715. let nodes = I.pointcloud.nodesOnRay(I.pointcloud.visibleNodes, ray);
  80716. let lastNode = nodes[nodes.length - 1];
  80717. let radius = lastNode.getBoundingSphere(new THREE.Sphere()).radius;
  80718. targetRadius = Math.min(this.currentViewport.view.radius, radius);
  80719. targetRadius = Math.max(minimumJumpDistance, targetRadius);
  80720. }
  80721. let d = this.currentViewport.view.direction.multiplyScalar(-1);
  80722. let cameraTargetPosition = new THREE.Vector3().addVectors(I.location, d.multiplyScalar(targetRadius));
  80723. // TODO Unused: let controlsTargetPosition = I.location;
  80724. let animationDuration = 600;
  80725. let easing = TWEEN.Easing.Quartic.Out;
  80726. { // animate
  80727. let value = {x: 0};
  80728. let tween = new TWEEN.Tween(value).to({x: 1}, animationDuration);
  80729. tween.easing(easing);
  80730. this.tweens.push(tween);
  80731. let startPos = this.currentViewport.view.position.clone();
  80732. let targetPos = cameraTargetPosition.clone();
  80733. let startRadius = this.currentViewport.view.radius;
  80734. let targetRadius = cameraTargetPosition.distanceTo(I.location);
  80735. tween.onUpdate(() => {
  80736. let t = value.x;
  80737. this.currentViewport.view.position.x = (1 - t) * startPos.x + t * targetPos.x;
  80738. this.currentViewport.view.position.y = (1 - t) * startPos.y + t * targetPos.y;
  80739. this.currentViewport.view.position.z = (1 - t) * startPos.z + t * targetPos.z;
  80740. this.currentViewport.view.radius = (1 - t) * startRadius + t * targetRadius;
  80741. this.viewer.setMoveSpeed(this.currentViewport.view.radius);
  80742. });
  80743. tween.onComplete(() => {
  80744. this.tweens = this.tweens.filter(e => e !== tween);
  80745. });
  80746. tween.start();
  80747. }
  80748. } */
  80749. zoomToLocation(mouse) {
  80750. var I = viewer.inputHandler.intersect;
  80751. if (!I) return;
  80752. var object = I.object || I.pointcloud;
  80753. I = I.location;
  80754. if (!I || !object) return;
  80755. var dis = this.currentViewport.view.position.distanceTo(I);
  80756. var bound = object.boundingBox.clone().applyMatrix4(object.matrixWorld);
  80757. var size = bound.getSize(new Vector3());
  80758. var len = size.length();
  80759. var distance = MathUtils.clamp(dis, 0.1, Math.max(len * 0.1, 3));
  80760. minRadius = distance;
  80761. viewer.focusOnObject({
  80762. position: I
  80763. }, 'point', null, {
  80764. distance
  80765. });
  80766. }
  80767. stopTweens() {
  80768. this.tweens.forEach(e => e.stop());
  80769. this.tweens = [];
  80770. }
  80771. update(delta) {
  80772. if (!this.enabled) return;
  80773. var view = this.currentViewport.view; //this.currentViewport.view;
  80774. var camera = this.currentViewport.camera;
  80775. {
  80776. // accelerate while input is given
  80777. var ih = this.viewer.inputHandler;
  80778. var moveForward = this.keys.FORWARD.some(e => ih.pressedKeys[e]);
  80779. var moveBackward = this.keys.BACKWARD.some(e => ih.pressedKeys[e]);
  80780. var moveLeft = this.keys.LEFT.some(e => ih.pressedKeys[e]);
  80781. var moveRight = this.keys.RIGHT.some(e => ih.pressedKeys[e]);
  80782. var moveUp = this.keys.UP.some(e => ih.pressedKeys[e]);
  80783. var moveDown = this.keys.DOWN.some(e => ih.pressedKeys[e]);
  80784. var moveSpeed = this.currentViewport.getMoveSpeed() / 20;
  80785. var px = 0,
  80786. py = 0,
  80787. pz = 0;
  80788. if (moveForward) {
  80789. py = 1 * moveSpeed;
  80790. } else if (moveBackward) {
  80791. py = -1 * moveSpeed;
  80792. }
  80793. if (moveLeft) {
  80794. px = -1 * moveSpeed;
  80795. } else if (moveRight) {
  80796. px = 1 * moveSpeed;
  80797. }
  80798. if (moveUp) {
  80799. pz = 1 * moveSpeed;
  80800. } else if (moveDown) {
  80801. pz = -1 * moveSpeed;
  80802. }
  80803. (px != 0 || py != 0 || pz != 0) && view.translate(px, py, pz, true);
  80804. }
  80805. {
  80806. // apply rotation
  80807. var progression = Math.min(1, this.fadeFactor * delta);
  80808. var yaw = view.yaw;
  80809. var pitch = view.pitch;
  80810. var pivot = view.getPivot();
  80811. yaw -= progression * this.yawDelta;
  80812. pitch -= progression * this.pitchDelta;
  80813. view.yaw = yaw;
  80814. view.pitch = pitch;
  80815. var V = this.currentViewport.view.direction.multiplyScalar(-view.radius);
  80816. var position = new Vector3().addVectors(pivot, V);
  80817. view.position.copy(position);
  80818. }
  80819. if (camera.type != 'OrthographicCamera') {
  80820. // apply pan
  80821. /* let progression = Math.min(1, this.fadeFactor * delta);
  80822. let panDistance = progression * view.radius * 3; */
  80823. var panDistance = 2 * view.radius * Math.tan(MathUtils.degToRad(camera.fov / 2)); //参照4dkk。 平移target(也就是平移镜头位置),但还是难以保证跟手(navvis也不一定跟手,但是很奇怪在居中时中心点居然是跟手的,可能计算方式不同)
  80824. //计算了下确实是这么算的。 平移pivot。
  80825. var _px = -this.panDelta.x * panDistance;
  80826. var _py = this.panDelta.y * panDistance;
  80827. view.pan(_px, _py);
  80828. }
  80829. {
  80830. // apply zoom
  80831. var _progression = 1; //Math.min(1, this.fadeFactor * delta);
  80832. // let radius = view.radius + progression * this.radiusDelta * view.radius * 0.1;
  80833. var radius = view.radius + _progression * this.radiusDelta;
  80834. var _V = view.direction.multiplyScalar(-radius);
  80835. var _position = new Vector3().addVectors(view.getPivot(), _V);
  80836. if (this.constantlyForward) {
  80837. // 到达中心点后还能继续向前移动,也就是能推进中心点
  80838. if (radius < minRadius) {
  80839. radius = minRadius;
  80840. }
  80841. }
  80842. view.radius = radius;
  80843. view.position.copy(_position);
  80844. }
  80845. {
  80846. var speed = view.radius;
  80847. this.viewer.setMoveSpeed && this.viewer.setMoveSpeed(speed);
  80848. }
  80849. {
  80850. // decelerate over time
  80851. /* let progression = Math.min(1, this.fadeFactor * delta);
  80852. let attenuation = Math.max(0, 1 - this.fadeFactor * delta);
  80853. this.yawDelta *= attenuation;
  80854. this.pitchDelta *= attenuation;
  80855. this.panDelta.multiplyScalar(attenuation);
  80856. // this.radiusDelta *= attenuation;
  80857. this.radiusDelta -= progression * this.radiusDelta; */
  80858. //取消衰减,直接stop
  80859. this.stop();
  80860. }
  80861. }
  80862. }
  80863. ;
  80864. // Adapted from three.js VRButton
  80865. class VRButton$1 {
  80866. constructor() {
  80867. this.onStartListeners = [];
  80868. this.onEndListeners = [];
  80869. this.element = null;
  80870. }
  80871. onStart(callback) {
  80872. this.onStartListeners.push(callback);
  80873. }
  80874. onEnd(callback) {
  80875. this.onEndListeners.push(callback);
  80876. }
  80877. static async createButton(renderer, options) {
  80878. if (options) {
  80879. console.error('THREE.VRButton: The "options" parameter has been removed. Please set the reference space type via renderer.xr.setReferenceSpaceType() instead.');
  80880. }
  80881. var button = new VRButton$1();
  80882. var element = document.createElement('button');
  80883. button.element = element;
  80884. function setEnter() {
  80885. button.element.innerHTML = "\n\t\t\t\t<div style=\"font-size: 0.5em;\">ENTER</div>\n\t\t\t\t<div style=\"font-weight: bold;\">VR</div>\n\t\t\t";
  80886. }
  80887. function setExit() {
  80888. button.element.innerHTML = "\n\t\t\t\t<div style=\"font-size: 0.5em;\">EXIT</div>\n\t\t\t\t<div style=\"font-weight: bold;\">VR</div>\n\t\t\t";
  80889. }
  80890. function showEnterVR( /*device*/
  80891. ) {
  80892. var currentSession = null;
  80893. function onSessionStarted(session) {
  80894. session.addEventListener('end', onSessionEnded);
  80895. for (var listener of button.onStartListeners) {
  80896. listener();
  80897. }
  80898. renderer.xr.setSession(session);
  80899. setExit();
  80900. currentSession = session;
  80901. }
  80902. function onSessionEnded( /*event*/
  80903. ) {
  80904. currentSession.removeEventListener('end', onSessionEnded);
  80905. for (var listener of button.onEndListeners) {
  80906. listener();
  80907. }
  80908. setEnter();
  80909. currentSession = null;
  80910. }
  80911. //
  80912. button.element.style.display = '';
  80913. button.element.style.cursor = 'pointer';
  80914. setEnter();
  80915. button.element.onmouseenter = function () {
  80916. button.element.style.opacity = '1.0';
  80917. };
  80918. button.element.onmouseleave = function () {
  80919. button.element.style.opacity = '0.7';
  80920. };
  80921. button.element.onclick = function () {
  80922. if (currentSession === null) {
  80923. // WebXR's requestReferenceSpace only works if the corresponding feature
  80924. // was requested at session creation time. For simplicity, just ask for
  80925. // the interesting ones as optional features, but be aware that the
  80926. // requestReferenceSpace call will fail if it turns out to be unavailable.
  80927. // ('local' is always available for immersive sessions and doesn't need to
  80928. // be requested separately.)
  80929. var sessionInit = {
  80930. optionalFeatures: ['local-floor', 'bounded-floor', 'hand-tracking']
  80931. };
  80932. navigator.xr.requestSession('immersive-vr', sessionInit).then(onSessionStarted);
  80933. } else {
  80934. currentSession.end();
  80935. }
  80936. };
  80937. }
  80938. function stylizeElement(element) {
  80939. element.style.position = 'absolute';
  80940. element.style.bottom = '20px';
  80941. element.style.padding = '12px 6px';
  80942. element.style.border = '1px solid #fff';
  80943. element.style.borderRadius = '4px';
  80944. element.style.background = 'rgba(0,0,0,0.1)';
  80945. element.style.color = '#fff';
  80946. element.style.font = 'normal 13px sans-serif';
  80947. element.style.textAlign = 'center';
  80948. element.style.opacity = '0.7';
  80949. element.style.outline = 'none';
  80950. element.style.zIndex = '999';
  80951. }
  80952. if ('xr' in navigator) {
  80953. button.element.id = 'VRButton';
  80954. button.element.style.display = 'none';
  80955. stylizeElement(button.element);
  80956. var supported = await navigator.xr.isSessionSupported('immersive-vr');
  80957. if (supported) {
  80958. showEnterVR();
  80959. return button;
  80960. } else {
  80961. return null;
  80962. }
  80963. } else {
  80964. if (window.isSecureContext === false) {
  80965. console.log("WEBXR NEEDS HTTPS");
  80966. } else {
  80967. console.log("WEBXR not available");
  80968. }
  80969. return null;
  80970. }
  80971. }
  80972. }
  80973. !function (e, a) {
  80974. "object" == typeof exports && "object" == typeof module ? module.exports = a() : "function" == typeof define && define.amd ? define([], a) : "object" == typeof exports ? exports.DxfParser = a() : e.DxfParser = a();
  80975. }("undefined" != typeof self ? self : undefined, function () {
  80976. return function (e) {
  80977. var a = {};
  80978. function t(r) {
  80979. if (a[r]) return a[r].exports;
  80980. var n = a[r] = {
  80981. i: r,
  80982. l: !1,
  80983. exports: {}
  80984. };
  80985. return e[r].call(n.exports, n, n.exports, t), n.l = !0, n.exports;
  80986. }
  80987. return t.m = e, t.c = a, t.d = function (e, a, r) {
  80988. t.o(e, a) || Object.defineProperty(e, a, {
  80989. enumerable: !0,
  80990. get: r
  80991. });
  80992. }, t.r = function (e) {
  80993. "undefined" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(e, Symbol.toStringTag, {
  80994. value: "Module"
  80995. }), Object.defineProperty(e, "__esModule", {
  80996. value: !0
  80997. });
  80998. }, t.t = function (e, a) {
  80999. if (1 & a && (e = t(e)), 8 & a) return e;
  81000. if (4 & a && "object" == typeof e && e && e.__esModule) return e;
  81001. var r = Object.create(null);
  81002. if (t.r(r), Object.defineProperty(r, "default", {
  81003. enumerable: !0,
  81004. value: e
  81005. }), 2 & a && "string" != typeof e) for (var n in e) t.d(r, n, function (a) {
  81006. return e[a];
  81007. }.bind(null, n));
  81008. return r;
  81009. }, t.n = function (e) {
  81010. var a = e && e.__esModule ? function () {
  81011. return e.default;
  81012. } : function () {
  81013. return e;
  81014. };
  81015. return t.d(a, "a", a), a;
  81016. }, t.o = function (e, a) {
  81017. return Object.prototype.hasOwnProperty.call(e, a);
  81018. }, t.p = "", t(t.s = 1);
  81019. }([function (e, a, t) {
  81020. var r, n;
  81021. !function (o, c) {
  81022. "use strict";
  81023. void 0 === (n = "function" == typeof (r = function r() {
  81024. var e = function e() {},
  81025. a = "undefined",
  81026. t = ["trace", "debug", "info", "warn", "error"];
  81027. function r(e, a) {
  81028. var t = e[a];
  81029. if ("function" == typeof t.bind) return t.bind(e);
  81030. try {
  81031. return Function.prototype.bind.call(t, e);
  81032. } catch (a) {
  81033. return function () {
  81034. return Function.prototype.apply.apply(t, [e, arguments]);
  81035. };
  81036. }
  81037. }
  81038. function n(a, r) {
  81039. for (var n = 0; n < t.length; n++) {
  81040. var o = t[n];
  81041. this[o] = n < a ? e : this.methodFactory(o, a, r);
  81042. }
  81043. this.log = this.debug;
  81044. }
  81045. function o(t, o, c) {
  81046. return function (t) {
  81047. "debug" === t && (t = "log");
  81048. return typeof console !== a && (void 0 !== console[t] ? r(console, t) : void 0 !== console.log ? r(console, "log") : e);
  81049. }(t) || function (e, t, r) {
  81050. return function () {
  81051. typeof console !== a && (n.call(this, t, r), this[e].apply(this, arguments));
  81052. };
  81053. }.apply(this, arguments);
  81054. }
  81055. function c(e, r, c) {
  81056. var i,
  81057. u = this,
  81058. s = "loglevel";
  81059. function l() {
  81060. var e;
  81061. if (typeof window !== a) {
  81062. try {
  81063. e = window.localStorage[s];
  81064. } catch (e) {}
  81065. if (typeof e === a) try {
  81066. var t = window.document.cookie,
  81067. r = t.indexOf(encodeURIComponent(s) + "=");
  81068. -1 !== r && (e = /^([^;]+)/.exec(t.slice(r))[1]);
  81069. } catch (e) {}
  81070. return void 0 === u.levels[e] && (e = void 0), e;
  81071. }
  81072. }
  81073. e && (s += ":" + e), u.name = e, u.levels = {
  81074. TRACE: 0,
  81075. DEBUG: 1,
  81076. INFO: 2,
  81077. WARN: 3,
  81078. ERROR: 4,
  81079. SILENT: 5
  81080. }, u.methodFactory = c || o, u.getLevel = function () {
  81081. return i;
  81082. }, u.setLevel = function (r, o) {
  81083. if ("string" == typeof r && void 0 !== u.levels[r.toUpperCase()] && (r = u.levels[r.toUpperCase()]), !("number" == typeof r && r >= 0 && r <= u.levels.SILENT)) throw "log.setLevel() called with invalid level: " + r;
  81084. if (i = r, !1 !== o && function (e) {
  81085. var r = (t[e] || "silent").toUpperCase();
  81086. if (typeof window === a) return;
  81087. try {
  81088. return void (window.localStorage[s] = r);
  81089. } catch (e) {}
  81090. try {
  81091. window.document.cookie = encodeURIComponent(s) + "=" + r + ";";
  81092. } catch (e) {}
  81093. }(r), n.call(u, r, e), typeof console === a && r < u.levels.SILENT) return "No console available for logging";
  81094. }, u.setDefaultLevel = function (e) {
  81095. l() || u.setLevel(e, !1);
  81096. }, u.enableAll = function (e) {
  81097. u.setLevel(u.levels.TRACE, e);
  81098. }, u.disableAll = function (e) {
  81099. u.setLevel(u.levels.SILENT, e);
  81100. };
  81101. var v = l();
  81102. null == v && (v = null == r ? "WARN" : r), u.setLevel(v, !1);
  81103. }
  81104. var i = new c(),
  81105. u = {};
  81106. i.getLogger = function (e) {
  81107. if ("string" != typeof e || "" === e) throw new TypeError("You must supply a name when creating a logger.");
  81108. var a = u[e];
  81109. return a || (a = u[e] = new c(e, i.getLevel(), i.methodFactory)), a;
  81110. };
  81111. var s = typeof window !== a ? window.log : void 0;
  81112. return i.noConflict = function () {
  81113. return typeof window !== a && window.log === i && (window.log = s), i;
  81114. }, i.getLoggers = function () {
  81115. return u;
  81116. }, i;
  81117. }) ? r.call(a, t, a, e) : r) || (e.exports = n);
  81118. }();
  81119. }, function (e, a, t) {
  81120. "use strict";
  81121. function r(e) {
  81122. this._pointer = 0, this._data = e, this._eof = !1;
  81123. }
  81124. function n(e, a) {
  81125. return e <= 9 ? a : e >= 10 && e <= 59 ? parseFloat(a) : e >= 60 && e <= 99 ? parseInt(a) : e >= 100 && e <= 109 ? a : e >= 110 && e <= 149 ? parseFloat(a) : e >= 160 && e <= 179 ? parseInt(a) : e >= 210 && e <= 239 ? parseFloat(a) : e >= 270 && e <= 289 ? parseInt(a) : e >= 290 && e <= 299 ? function (e) {
  81126. if ("0" === e) return !1;
  81127. if ("1" === e) return !0;
  81128. throw TypeError("String '" + e + "' cannot be cast to Boolean type");
  81129. }(a) : e >= 300 && e <= 369 ? a : e >= 370 && e <= 389 ? parseInt(a) : e >= 390 && e <= 399 ? a : e >= 400 && e <= 409 ? parseInt(a) : e >= 410 && e <= 419 ? a : e >= 420 && e <= 429 ? parseInt(a) : e >= 430 && e <= 439 ? a : e >= 440 && e <= 459 ? parseInt(a) : e >= 460 && e <= 469 ? parseFloat(a) : e >= 470 && e <= 481 ? a : 999 === e ? a : e >= 1e3 && e <= 1009 ? a : e >= 1010 && e <= 1059 ? parseFloat(a) : e >= 1060 && e <= 1071 ? parseInt(a) : (console.log("WARNING: Group code does not have a defined type: %j", {
  81130. code: e,
  81131. value: a
  81132. }), a);
  81133. }
  81134. t.r(a), r.prototype.next = function () {
  81135. var e;
  81136. if (!this.hasNext()) throw this._eof ? new Error("Cannot call 'next' after EOF group has been read") : new Error("Unexpected end of input: EOF group not read before end of file. Ended on code " + this._data[this._pointer]);
  81137. return e = {
  81138. code: parseInt(this._data[this._pointer])
  81139. }, this._pointer++, e.value = n(e.code, this._data[this._pointer].trim()), this._pointer++, 0 === e.code && "EOF" === e.value && (this._eof = !0), this.lastReadGroup = e, e;
  81140. }, r.prototype.peek = function () {
  81141. if (!this.hasNext()) throw this._eof ? new Error("Cannot call 'next' after EOF group has been read") : new Error("Unexpected end of input: EOF group not read before end of file. Ended on code " + this._data[this._pointer]);
  81142. var e = {
  81143. code: parseInt(this._data[this._pointer])
  81144. };
  81145. return e.value = n(e.code, this._data[this._pointer + 1].trim()), e;
  81146. }, r.prototype.rewind = function (e) {
  81147. e = e || 1, this._pointer = this._pointer - 2 * e;
  81148. }, r.prototype.hasNext = function () {
  81149. return !this._eof && !(this._pointer > this._data.length - 2);
  81150. }, r.prototype.isEOF = function () {
  81151. return this._eof;
  81152. };
  81153. var o = [0, 16711680, 16776960, 65280, 65535, 255, 16711935, 16777215, 8421504, 12632256, 16711680, 16744319, 13369344, 13395558, 10027008, 10046540, 8323072, 8339263, 4980736, 4990502, 16727808, 16752511, 13382400, 13401958, 10036736, 10051404, 8331008, 8343359, 4985600, 4992806, 16744192, 16760703, 13395456, 13408614, 10046464, 10056268, 8339200, 8347455, 4990464, 4995366, 16760576, 16768895, 13408512, 13415014, 10056192, 10061132, 8347392, 8351551, 4995328, 4997670, 16776960, 16777087, 13421568, 13421670, 10000384, 10000460, 8355584, 8355647, 5000192, 5000230, 12582656, 14679935, 10079232, 11717734, 7510016, 8755276, 6258432, 7307071, 3755008, 4344870, 8388352, 12582783, 6736896, 10079334, 5019648, 7510092, 4161280, 6258495, 2509824, 3755046, 4194048, 10485631, 3394560, 8375398, 2529280, 6264908, 2064128, 5209919, 1264640, 3099686, 65280, 8388479, 52224, 6736998, 38912, 5019724, 32512, 4161343, 19456, 2509862, 65343, 8388511, 52275, 6737023, 38950, 5019743, 32543, 4161359, 19475, 2509871, 65407, 8388543, 52326, 6737049, 38988, 5019762, 32575, 4161375, 19494, 2509881, 65471, 8388575, 52377, 6737074, 39026, 5019781, 32607, 4161391, 19513, 2509890, 65535, 8388607, 52428, 6737100, 39064, 5019800, 32639, 4161407, 19532, 2509900, 49151, 8380415, 39372, 6730444, 29336, 5014936, 24447, 4157311, 14668, 2507340, 32767, 8372223, 26316, 6724044, 19608, 5010072, 16255, 4153215, 9804, 2505036, 16383, 8364031, 13260, 6717388, 9880, 5005208, 8063, 4149119, 4940, 2502476, 255, 8355839, 204, 6710988, 152, 5000344, 127, 4145023, 76, 2500172, 4129023, 10452991, 3342540, 8349388, 2490520, 6245528, 2031743, 5193599, 1245260, 3089996, 8323327, 12550143, 6684876, 10053324, 4980888, 7490712, 4128895, 6242175, 2490444, 3745356, 12517631, 14647295, 10027212, 11691724, 7471256, 8735896, 6226047, 7290751, 3735628, 4335180, 16711935, 16744447, 13369548, 13395660, 9961624, 9981080, 8323199, 8339327, 4980812, 4990540, 16711871, 16744415, 13369497, 13395634, 9961586, 9981061, 8323167, 8339311, 4980793, 4990530, 16711807, 16744383, 13369446, 13395609, 9961548, 9981042, 8323135, 8339295, 4980774, 4990521, 16711743, 16744351, 13369395, 13395583, 9961510, 9981023, 8323103, 8339279, 4980755, 4990511, 3355443, 5987163, 8684676, 11382189, 14079702, 16777215];
  81154. function c(e) {
  81155. var a = {};
  81156. e.rewind();
  81157. var t = e.next(),
  81158. r = t.code;
  81159. if (a.x = t.value, r += 10, (t = e.next()).code != r) throw new Error("Expected code for point value to be " + r + " but got " + t.code + ".");
  81160. return a.y = t.value, r += 10, (t = e.next()).code != r ? (e.rewind(), a) : (a.z = t.value, a);
  81161. }
  81162. function i(e, a) {
  81163. switch (a.code) {
  81164. case 0:
  81165. e.type = a.value;
  81166. break;
  81167. case 5:
  81168. e.handle = a.value;
  81169. /* if(e.handle == "2FDDB"){
  81170. console.log(1)
  81171. } */
  81172. break;
  81173. case 6:
  81174. e.lineType = a.value;
  81175. break;
  81176. case 8:
  81177. e.layer = a.value;
  81178. break;
  81179. case 48:
  81180. e.lineTypeScale = a.value;
  81181. break;
  81182. case 60:
  81183. e.visible = 0 === a.value;
  81184. break;
  81185. case 62:
  81186. e.colorIndex = a.value, e.color = (t = Math.abs(a.value), o[t]);
  81187. break;
  81188. case 67:
  81189. e.inPaperSpace = 0 !== a.value;
  81190. break;
  81191. case 100:
  81192. break;
  81193. case 330:
  81194. e.ownerHandle = a.value;
  81195. break;
  81196. case 347:
  81197. e.materialObjectHandle = a.value;
  81198. break;
  81199. case 370:
  81200. e.lineweight = a.value;
  81201. break;
  81202. case 420:
  81203. e.color = a.value;
  81204. break;
  81205. case 1e3:
  81206. e.extendedData = e.extendedData || {}, e.extendedData.customStrings = e.extendedData.customStrings || [], e.extendedData.customStrings.push(a.value);
  81207. break;
  81208. case 1001:
  81209. e.extendedData = e.extendedData || {}, e.extendedData.applicationName = a.value;
  81210. break;
  81211. default:
  81212. return !1;
  81213. }
  81214. var t;
  81215. return !0;
  81216. }
  81217. function u() {}
  81218. function s(e, a) {
  81219. var t,
  81220. r = [],
  81221. n = !1,
  81222. o = !1;
  81223. for (t = 0; t <= 4; t++) {
  81224. for (var c = {}; "EOF" !== a && 0 !== a.code && !o;) {
  81225. switch (a.code) {
  81226. case 10:
  81227. case 11:
  81228. case 12:
  81229. case 13:
  81230. if (n) {
  81231. o = !0;
  81232. continue;
  81233. }
  81234. c.x = a.value, n = !0;
  81235. break;
  81236. case 20:
  81237. case 21:
  81238. case 22:
  81239. case 23:
  81240. c.y = a.value;
  81241. break;
  81242. case 30:
  81243. case 31:
  81244. case 32:
  81245. case 33:
  81246. c.z = a.value;
  81247. break;
  81248. default:
  81249. return r;
  81250. }
  81251. a = e.next();
  81252. }
  81253. r.push(c), n = !1, o = !1;
  81254. }
  81255. return e.rewind(), r;
  81256. }
  81257. function l() {}
  81258. function v() {}
  81259. function d() {}
  81260. function b() {}
  81261. function p() {}
  81262. function f() {}
  81263. function k() {}
  81264. function y() {}
  81265. function x(e, a) {
  81266. if (!e || e <= 0) throw Error("n must be greater than 0 verticies");
  81267. var t,
  81268. r = [],
  81269. n = !1,
  81270. o = !1,
  81271. c = a.lastReadGroup;
  81272. for (t = 0; t < e; t++) {
  81273. for (var i = {}; "EOF" !== c && 0 !== c.code && !o;) {
  81274. switch (c.code) {
  81275. case 10:
  81276. if (n) {
  81277. o = !0;
  81278. continue;
  81279. }
  81280. i.x = c.value, n = !0;
  81281. break;
  81282. case 20:
  81283. i.y = c.value;
  81284. break;
  81285. case 30:
  81286. i.z = c.value;
  81287. break;
  81288. case 40:
  81289. i.startWidth = c.value;
  81290. break;
  81291. case 41:
  81292. i.endWidth = c.value;
  81293. break;
  81294. case 42:
  81295. 0 != c.value && (i.bulge = c.value);
  81296. break;
  81297. default:
  81298. return n && r.push(i), r;
  81299. }
  81300. c = a.next();
  81301. }
  81302. r.push(i), n = !1, o = !1;
  81303. }
  81304. return a.rewind(), r;
  81305. }
  81306. function h() {}
  81307. function g() {}
  81308. function E() {}
  81309. function w() {}
  81310. function m(e, a) {
  81311. var t = {
  81312. type: a.value
  81313. };
  81314. for (a = e.next(); "EOF" != a && 0 != a.code;) i(t, a), a = e.next();
  81315. return t;
  81316. }
  81317. function P() {}
  81318. function F() {}
  81319. function O() {}
  81320. u.ForEntityName = "3DFACE", u.prototype.parseEntity = function (e, a) {
  81321. var t = {
  81322. type: a.value,
  81323. vertices: []
  81324. };
  81325. for (a = e.next(); "EOF" !== a && 0 !== a.code;) {
  81326. switch (a.code) {
  81327. case 70:
  81328. t.shape = 1 == (1 & a.value), t.hasContinuousLinetypePattern = 128 == (128 & a.value);
  81329. break;
  81330. case 10:
  81331. t.vertices = s(e, a), a = e.lastReadGroup;
  81332. break;
  81333. default:
  81334. i(t, a);
  81335. }
  81336. a = e.next();
  81337. }
  81338. return t;
  81339. }, l.ForEntityName = "ARC", l.prototype.parseEntity = function (e, a) {
  81340. var t;
  81341. for (t = {
  81342. type: a.value
  81343. }, a = e.next(); "EOF" !== a && 0 !== a.code;) {
  81344. switch (a.code) {
  81345. case 10:
  81346. t.center = c(e);
  81347. break;
  81348. case 40:
  81349. t.radius = a.value;
  81350. break;
  81351. case 50:
  81352. t.startAngle = Math.PI / 180 * a.value;
  81353. break;
  81354. case 51:
  81355. t.endAngle = Math.PI / 180 * a.value, t.angleLength = t.endAngle - t.startAngle;
  81356. break;
  81357. default:
  81358. i(t, a);
  81359. }
  81360. a = e.next();
  81361. }
  81362. return t;
  81363. }, v.ForEntityName = "ATTDEF", v.prototype.parseEntity = function (e, a) {
  81364. var t = {
  81365. type: a.value,
  81366. scale: 1,
  81367. textStyle: "STANDARD"
  81368. };
  81369. for (a = e.next(); "EOF" !== a && 0 !== a.code;) {
  81370. switch (a.code) {
  81371. case 1:
  81372. t.text = a.value;
  81373. break;
  81374. case 2:
  81375. t.tag = a.value;
  81376. break;
  81377. case 3:
  81378. t.prompt = a.value;
  81379. break;
  81380. case 7:
  81381. t.textStyle = a.value;
  81382. break;
  81383. case 10:
  81384. t.startPoint = c(e);
  81385. break;
  81386. case 11:
  81387. t.endPoint = c(e);
  81388. break;
  81389. case 39:
  81390. t.thickness = a.value;
  81391. break;
  81392. case 40:
  81393. t.textHeight = a.value;
  81394. break;
  81395. case 41:
  81396. t.scale = a.value;
  81397. break;
  81398. case 50:
  81399. t.rotation = a.value;
  81400. break;
  81401. case 51:
  81402. t.obliqueAngle = a.value;
  81403. break;
  81404. case 70:
  81405. t.invisible = !!(1 & a.value), t.constant = !!(2 & a.value), t.verificationRequired = !!(4 & a.value), t.preset = !!(8 & a.value);
  81406. break;
  81407. case 71:
  81408. t.backwards = !!(2 & a.value), t.mirrored = !!(4 & a.value);
  81409. break;
  81410. case 72:
  81411. t.horizontalJustification = a.value;
  81412. break;
  81413. case 73:
  81414. t.fieldLength = a.value;
  81415. break;
  81416. case 74:
  81417. t.verticalJustification = a.value;
  81418. break;
  81419. case 100:
  81420. break;
  81421. case 210:
  81422. t.extrusionDirectionX = a.value;
  81423. break;
  81424. case 220:
  81425. t.extrusionDirectionY = a.value;
  81426. break;
  81427. case 230:
  81428. t.extrusionDirectionZ = a.value;
  81429. break;
  81430. default:
  81431. i(t, a);
  81432. }
  81433. a = e.next();
  81434. }
  81435. return t;
  81436. }, d.ForEntityName = "CIRCLE", d.prototype.parseEntity = function (e, a) {
  81437. var t, r;
  81438. for (t = {
  81439. type: a.value
  81440. }, a = e.next(); "EOF" !== a && 0 !== a.code;) {
  81441. switch (a.code) {
  81442. case 10:
  81443. t.center = c(e);
  81444. break;
  81445. case 40:
  81446. t.radius = a.value;
  81447. break;
  81448. case 50:
  81449. t.startAngle = Math.PI / 180 * a.value;
  81450. break;
  81451. case 51:
  81452. (r = Math.PI / 180 * a.value) < t.startAngle ? t.angleLength = r + 2 * Math.PI - t.startAngle : t.angleLength = r - t.startAngle, t.endAngle = r;
  81453. break;
  81454. default:
  81455. i(t, a);
  81456. }
  81457. a = e.next();
  81458. }
  81459. return t;
  81460. }, b.ForEntityName = "DIMENSION", b.prototype.parseEntity = function (e, a) {
  81461. var t;
  81462. for (t = {
  81463. type: a.value
  81464. }, a = e.next(); "EOF" !== a && 0 !== a.code;) {
  81465. switch (a.code) {
  81466. case 2:
  81467. t.block = a.value;
  81468. break;
  81469. case 10:
  81470. t.anchorPoint = c(e);
  81471. break;
  81472. case 11:
  81473. t.middleOfText = c(e);
  81474. break;
  81475. case 12:
  81476. t.insertionPoint = c(e);
  81477. break;
  81478. case 13:
  81479. t.linearOrAngularPoint1 = c(e);
  81480. break;
  81481. case 14:
  81482. t.linearOrAngularPoint2 = c(e);
  81483. break;
  81484. case 15:
  81485. t.diameterOrRadiusPoint = c(e);
  81486. break;
  81487. case 16:
  81488. t.arcPoint = c(e);
  81489. break;
  81490. case 70:
  81491. t.dimensionType = a.value;
  81492. break;
  81493. case 71:
  81494. t.attachmentPoint = a.value;
  81495. break;
  81496. case 42:
  81497. t.actualMeasurement = a.value;
  81498. break;
  81499. case 1:
  81500. t.text = a.value;
  81501. break;
  81502. case 50:
  81503. t.angle = a.value;
  81504. break;
  81505. default:
  81506. i(t, a);
  81507. }
  81508. a = e.next();
  81509. }
  81510. return t;
  81511. }, p.ForEntityName = "ELLIPSE", p.prototype.parseEntity = function (e, a) {
  81512. var t;
  81513. for (t = {
  81514. type: a.value
  81515. }, a = e.next(); "EOF" !== a && 0 !== a.code;) {
  81516. switch (a.code) {
  81517. case 10:
  81518. t.center = c(e);
  81519. break;
  81520. case 11:
  81521. t.majorAxisEndPoint = c(e);
  81522. break;
  81523. case 40:
  81524. t.axisRatio = a.value;
  81525. break;
  81526. case 41:
  81527. t.startAngle = a.value;
  81528. break;
  81529. case 42:
  81530. t.endAngle = a.value;
  81531. break;
  81532. case 2:
  81533. t.name = a.value;
  81534. break;
  81535. default:
  81536. i(t, a);
  81537. }
  81538. a = e.next();
  81539. }
  81540. return t;
  81541. }, f.ForEntityName = "INSERT", f.prototype.parseEntity = function (e, a) {
  81542. var t;
  81543. for (t = {
  81544. type: a.value
  81545. }, a = e.next(); "EOF" !== a && 0 !== a.code;) {
  81546. switch (a.code) {
  81547. case 2:
  81548. t.name = a.value;
  81549. break;
  81550. case 41:
  81551. t.xScale = a.value;
  81552. break;
  81553. case 42:
  81554. t.yScale = a.value;
  81555. break;
  81556. case 43:
  81557. t.zScale = a.value;
  81558. break;
  81559. case 10:
  81560. t.position = c(e);
  81561. break;
  81562. case 50:
  81563. t.rotation = a.value;
  81564. break;
  81565. case 70:
  81566. t.columnCount = a.value;
  81567. break;
  81568. case 71:
  81569. t.rowCount = a.value;
  81570. break;
  81571. case 44:
  81572. t.columnSpacing = a.value;
  81573. break;
  81574. case 45:
  81575. t.rowSpacing = a.value;
  81576. break;
  81577. case 210:
  81578. t.extrusionDirection = c(e);
  81579. break;
  81580. default:
  81581. i(t, a);
  81582. }
  81583. a = e.next();
  81584. }
  81585. return t;
  81586. }, k.ForEntityName = "LINE", k.prototype.parseEntity = function (e, a) {
  81587. var t = {
  81588. type: a.value,
  81589. vertices: []
  81590. };
  81591. for (a = e.next(); "EOF" !== a && 0 !== a.code;) {
  81592. switch (a.code) {
  81593. case 10:
  81594. t.vertices.unshift(c(e));
  81595. break;
  81596. case 11:
  81597. t.vertices.push(c(e));
  81598. break;
  81599. case 210:
  81600. t.extrusionDirection = c(e);
  81601. break;
  81602. case 100:
  81603. break;
  81604. default:
  81605. i(t, a);
  81606. }
  81607. a = e.next();
  81608. }
  81609. return t;
  81610. }, y.ForEntityName = "LWPOLYLINE", y.prototype.parseEntity = function (e, a) {
  81611. var t = {
  81612. type: a.value,
  81613. vertices: []
  81614. },
  81615. r = 0;
  81616. for (a = e.next(); "EOF" !== a && 0 !== a.code;) {
  81617. switch (a.code) {
  81618. case 38:
  81619. t.elevation = a.value;
  81620. break;
  81621. case 39:
  81622. t.depth = a.value;
  81623. break;
  81624. case 70:
  81625. t.shape = 1 == (1 & a.value), t.hasContinuousLinetypePattern = 128 == (128 & a.value);
  81626. break;
  81627. case 90:
  81628. r = a.value;
  81629. break;
  81630. case 10:
  81631. //t.vertices = x(r, e);
  81632. //改,因有的文件有点问题,可能版本原因
  81633. t.vertices.push(...x(r, e)); //有的文件同一个entity需要多次执行到这里,所以不能直接覆盖,要push
  81634. t.vertices = t.vertices.filter(e => e.x != void 0); //而且会出现空的vertix:{},所以排除下
  81635. break;
  81636. case 43:
  81637. 0 !== a.value && (t.width = a.value);
  81638. break;
  81639. case 210:
  81640. t.extrusionDirectionX = a.value;
  81641. break;
  81642. case 220:
  81643. t.extrusionDirectionY = a.value;
  81644. break;
  81645. case 230:
  81646. t.extrusionDirectionZ = a.value;
  81647. break;
  81648. default:
  81649. i(t, a);
  81650. }
  81651. a = e.next();
  81652. }
  81653. return t;
  81654. }, h.ForEntityName = "MTEXT", h.prototype.parseEntity = function (e, a) {
  81655. var t = {
  81656. type: a.value
  81657. };
  81658. for (a = e.next(); "EOF" !== a && 0 !== a.code;) {
  81659. switch (a.code) {
  81660. case 3:
  81661. case 1:
  81662. t.text ? t.text += a.value : t.text = a.value;
  81663. break;
  81664. case 10:
  81665. t.position = c(e);
  81666. break;
  81667. case 40:
  81668. t.height = a.value;
  81669. break;
  81670. case 41:
  81671. t.width = a.value;
  81672. break;
  81673. case 50:
  81674. t.rotation = a.value;
  81675. break;
  81676. case 71:
  81677. t.attachmentPoint = a.value;
  81678. break;
  81679. case 72:
  81680. t.drawingDirection = a.value;
  81681. break;
  81682. default:
  81683. i(t, a);
  81684. }
  81685. a = e.next();
  81686. }
  81687. return t;
  81688. }, g.ForEntityName = "POINT", g.prototype.parseEntity = function (e, a) {
  81689. var t;
  81690. for (t = {
  81691. type: a.value
  81692. }, a = e.next(); "EOF" !== a && 0 !== a.code;) {
  81693. switch (a.code) {
  81694. case 10:
  81695. t.position = c(e);
  81696. break;
  81697. case 39:
  81698. t.thickness = a.value;
  81699. break;
  81700. case 210:
  81701. t.extrusionDirection = c(e);
  81702. break;
  81703. case 100:
  81704. break;
  81705. default:
  81706. i(t, a);
  81707. }
  81708. a = e.next();
  81709. }
  81710. return t;
  81711. }, E.ForEntityName = "VERTEX", E.prototype.parseEntity = function (e, a) {
  81712. var t = {
  81713. type: a.value
  81714. };
  81715. for (a = e.next(); "EOF" !== a && 0 !== a.code;) {
  81716. switch (a.code) {
  81717. case 10:
  81718. t.x = a.value;
  81719. break;
  81720. case 20:
  81721. t.y = a.value;
  81722. break;
  81723. case 30:
  81724. t.z = a.value;
  81725. break;
  81726. case 40:
  81727. case 41:
  81728. case 42:
  81729. 0 != a.value && (t.bulge = a.value);
  81730. break;
  81731. case 70:
  81732. t.curveFittingVertex = 0 != (1 & a.value), t.curveFitTangent = 0 != (2 & a.value), t.splineVertex = 0 != (8 & a.value), t.splineControlPoint = 0 != (16 & a.value), t.threeDPolylineVertex = 0 != (32 & a.value), t.threeDPolylineMesh = 0 != (64 & a.value), t.polyfaceMeshVertex = 0 != (128 & a.value);
  81733. break;
  81734. case 50:
  81735. case 71:
  81736. t.faceA = a.value;
  81737. break;
  81738. case 72:
  81739. t.faceB = a.value;
  81740. break;
  81741. case 73:
  81742. t.faceC = a.value;
  81743. break;
  81744. case 74:
  81745. t.faceD = a.value;
  81746. break;
  81747. default:
  81748. i(t, a);
  81749. }
  81750. a = e.next();
  81751. }
  81752. return t;
  81753. }, w.ForEntityName = "POLYLINE", w.prototype.parseEntity = function (e, a) {
  81754. var t = {
  81755. type: a.value,
  81756. vertices: []
  81757. };
  81758. for (a = e.next(); "EOF" !== a && 0 !== a.code;) {
  81759. switch (a.code) {
  81760. case 10:
  81761. case 20:
  81762. case 30:
  81763. case 39:
  81764. t.thickness = a.value;
  81765. break;
  81766. case 40:
  81767. case 41:
  81768. break;
  81769. case 70:
  81770. t.shape = 0 != (1 & a.value), t.includesCurveFitVertices = 0 != (2 & a.value), t.includesSplineFitVertices = 0 != (4 & a.value), t.is3dPolyline = 0 != (8 & a.value), t.is3dPolygonMesh = 0 != (16 & a.value), t.is3dPolygonMeshClosed = 0 != (32 & a.value), t.isPolyfaceMesh = 0 != (64 & a.value), t.hasContinuousLinetypePattern = 0 != (128 & a.value);
  81771. break;
  81772. case 71:
  81773. case 72:
  81774. case 73:
  81775. case 74:
  81776. case 75:
  81777. break;
  81778. case 210:
  81779. t.extrusionDirection = c(e);
  81780. break;
  81781. default:
  81782. i(t, a);
  81783. }
  81784. a = e.next();
  81785. }
  81786. return t.vertices = function (e, a) {
  81787. var t = new E(),
  81788. r = [];
  81789. for (; !e.isEOF();) if (0 === a.code) if ("VERTEX" === a.value) r.push(t.parseEntity(e, a)), a = e.lastReadGroup;else if ("SEQEND" === a.value) {
  81790. m(e, a);
  81791. break;
  81792. }
  81793. return r;
  81794. }(e, a), t;
  81795. }, P.ForEntityName = "SOLID", P.prototype.parseEntity = function (e, a) {
  81796. var t;
  81797. for ((t = {
  81798. type: a.value
  81799. }).points = [], a = e.next(); "EOF" !== a && 0 !== a.code;) {
  81800. switch (a.code) {
  81801. case 10:
  81802. t.points[0] = c(e);
  81803. break;
  81804. case 11:
  81805. t.points[1] = c(e);
  81806. break;
  81807. case 12:
  81808. t.points[2] = c(e);
  81809. break;
  81810. case 13:
  81811. t.points[3] = c(e);
  81812. break;
  81813. case 210:
  81814. t.extrusionDirection = c(e);
  81815. break;
  81816. default:
  81817. i(t, a);
  81818. }
  81819. a = e.next();
  81820. }
  81821. return t;
  81822. }, F.ForEntityName = "SPLINE", F.prototype.parseEntity = function (e, a) {
  81823. var t;
  81824. for (t = {
  81825. type: a.value
  81826. }, a = e.next(); "EOF" !== a && 0 !== a.code;) {
  81827. switch (a.code) {
  81828. case 10:
  81829. t.controlPoints || (t.controlPoints = []), t.controlPoints.push(c(e));
  81830. break;
  81831. case 11:
  81832. t.fitPoints || (t.fitPoints = []), t.fitPoints.push(c(e));
  81833. break;
  81834. case 12:
  81835. t.startTangent = c(e);
  81836. break;
  81837. case 13:
  81838. t.endTangent = c(e);
  81839. break;
  81840. case 40:
  81841. t.knotValues || (t.knotValues = []), t.knotValues.push(a.value);
  81842. break;
  81843. case 70:
  81844. 0 != (1 & a.value) && (t.closed = !0), 0 != (2 & a.value) && (t.periodic = !0), 0 != (4 & a.value) && (t.rational = !0), 0 != (8 & a.value) && (t.planar = !0), 0 != (16 & a.value) && (t.planar = !0, t.linear = !0);
  81845. break;
  81846. case 71:
  81847. t.degreeOfSplineCurve = a.value;
  81848. break;
  81849. case 72:
  81850. t.numberOfKnots = a.value;
  81851. break;
  81852. case 73:
  81853. t.numberOfControlPoints = a.value;
  81854. break;
  81855. case 74:
  81856. t.numberOfFitPoints = a.value;
  81857. break;
  81858. case 210:
  81859. t.normalVector = c(e);
  81860. break;
  81861. default:
  81862. i(t, a);
  81863. }
  81864. a = e.next();
  81865. }
  81866. return t;
  81867. }, O.ForEntityName = "TEXT", O.prototype.parseEntity = function (e, a) {
  81868. var t;
  81869. for (t = {
  81870. type: a.value
  81871. }, a = e.next(); "EOF" !== a && 0 !== a.code;) {
  81872. switch (a.code) {
  81873. case 10:
  81874. t.startPoint = c(e);
  81875. break;
  81876. case 11:
  81877. t.endPoint = c(e);
  81878. break;
  81879. case 40:
  81880. t.textHeight = a.value;
  81881. break;
  81882. case 41:
  81883. t.xScale = a.value;
  81884. break;
  81885. case 50:
  81886. t.rotation = a.value;
  81887. break;
  81888. case 1:
  81889. t.text = a.value;
  81890. break;
  81891. case 72:
  81892. t.halign = a.value;
  81893. break;
  81894. case 73:
  81895. t.valign = a.value;
  81896. break;
  81897. default:
  81898. i(t, a);
  81899. }
  81900. a = e.next();
  81901. }
  81902. return t;
  81903. };
  81904. var N = t(0);
  81905. function T() {
  81906. var e;
  81907. this._entityHandlers = {}, (e = this).registerEntityHandler(u), e.registerEntityHandler(l), e.registerEntityHandler(v), e.registerEntityHandler(d), e.registerEntityHandler(b), e.registerEntityHandler(p), e.registerEntityHandler(f), e.registerEntityHandler(k), e.registerEntityHandler(y), e.registerEntityHandler(h), e.registerEntityHandler(g), e.registerEntityHandler(w), e.registerEntityHandler(P), e.registerEntityHandler(F), e.registerEntityHandler(O);
  81908. }
  81909. function S(e) {
  81910. N.debug("unhandled group " + L(e));
  81911. }
  81912. function L(e) {
  81913. return e.code + ":" + e.value;
  81914. }
  81915. N.setLevel("error"), T.prototype.parse = function (e, a) {
  81916. throw new Error("read() not implemented. Use readSync()");
  81917. }, T.prototype.registerEntityHandler = function (e) {
  81918. var a = new e();
  81919. this._entityHandlers[e.ForEntityName] = a;
  81920. }, T.prototype.parseSync = function (e) {
  81921. return "string" == typeof e ? this._parse(e) : (console.error("Cannot read dxf source of type `" + typeof e), null);
  81922. }, T.prototype.parseStream = function (e, a) {
  81923. var t = "",
  81924. r = this;
  81925. e.on("data", function (e) {
  81926. t += e;
  81927. }), e.on("end", function () {
  81928. try {
  81929. var e = r._parse(t);
  81930. } catch (e) {
  81931. return a(e);
  81932. }
  81933. a(null, e);
  81934. }), e.on("error", function (e) {
  81935. a(e);
  81936. });
  81937. }, T.prototype._parse = function (e) {
  81938. var a,
  81939. t,
  81940. n = {},
  81941. c = 0,
  81942. i = e.split(/\r\n|\r|\n/g);
  81943. if (!(a = new r(i)).hasNext()) throw Error("Empty file");
  81944. var u = this,
  81945. s = function s(e, a) {
  81946. return t.code === e && t.value === a;
  81947. },
  81948. l = function l() {
  81949. var e = null,
  81950. r = null,
  81951. n = {};
  81952. for (t = a.next();;) {
  81953. if (s(0, "ENDSEC")) {
  81954. e && (n[e] = r);
  81955. break;
  81956. }
  81957. 9 === t.code ? (e && (n[e] = r), e = t.value) : 10 === t.code ? r = {
  81958. x: t.value
  81959. } : 20 === t.code ? r.y = t.value : 30 === t.code ? r.z = t.value : r = t.value, t = a.next();
  81960. }
  81961. return t = a.next(), n;
  81962. },
  81963. v = function v() {
  81964. var e,
  81965. r = {};
  81966. for (t = a.next(); "EOF" !== t.value && !s(0, "ENDSEC");) s(0, "BLOCK") ? (N.debug("block {"), e = d(), N.debug("}"), x(e), e.name ? r[e.name] = e : N.error('block with handle "' + e.handle + '" is missing a name.')) : (S(t), t = a.next());
  81967. return r;
  81968. },
  81969. d = function d() {
  81970. var e = {};
  81971. for (t = a.next(); "EOF" !== t.value;) {
  81972. switch (t.code) {
  81973. case 1:
  81974. e.xrefPath = t.value, t = a.next();
  81975. break;
  81976. case 2:
  81977. e.name = t.value, t = a.next();
  81978. break;
  81979. case 3:
  81980. e.name2 = t.value, t = a.next();
  81981. break;
  81982. case 5:
  81983. e.handle = t.value, t = a.next();
  81984. break;
  81985. case 8:
  81986. e.layer = t.value, t = a.next();
  81987. break;
  81988. case 10:
  81989. e.position = y(), t = a.next();
  81990. break;
  81991. case 67:
  81992. e.paperSpace = !(!t.value || 1 != t.value), t = a.next();
  81993. break;
  81994. case 70:
  81995. 0 != t.value && (e.type = t.value), t = a.next();
  81996. break;
  81997. case 100:
  81998. t = a.next();
  81999. break;
  82000. case 330:
  82001. e.ownerHandle = t.value, t = a.next();
  82002. break;
  82003. case 0:
  82004. if ("ENDBLK" == t.value) break;
  82005. e.entities = k(!0);
  82006. break;
  82007. default:
  82008. S(t), t = a.next();
  82009. }
  82010. if (s(0, "ENDBLK")) {
  82011. t = a.next();
  82012. break;
  82013. }
  82014. }
  82015. return e;
  82016. },
  82017. b = function b() {
  82018. var e = {};
  82019. for (t = a.next(); "EOF" !== t.value && !s(0, "ENDSEC");) {
  82020. s(0, "TABLE") ? (t = a.next(), f[t.value] ? (N.debug(t.value + " Table {"), e[f[t.value].tableName] = p(), N.debug("}")) : N.debug("Unhandled Table " + t.value)) : t = a.next();
  82021. }
  82022. return t = a.next(), e;
  82023. };
  82024. var p = function p() {
  82025. var e,
  82026. r = f[t.value],
  82027. n = {},
  82028. o = 0;
  82029. for (t = a.next(); !s(0, "ENDTAB");) switch (t.code) {
  82030. case 5:
  82031. n.handle = t.value, t = a.next();
  82032. break;
  82033. case 330:
  82034. n.ownerHandle = t.value, t = a.next();
  82035. break;
  82036. case 100:
  82037. "AcDbSymbolTable" === t.value ? t = a.next() : (S(t), t = a.next());
  82038. break;
  82039. case 70:
  82040. o = t.value, t = a.next();
  82041. break;
  82042. case 0:
  82043. t.value === r.dxfSymbolName ? n[r.tableRecordsProperty] = r.parseTableRecords() : (S(t), t = a.next());
  82044. break;
  82045. default:
  82046. S(t), t = a.next();
  82047. }
  82048. var c = n[r.tableRecordsProperty];
  82049. return c && (c.constructor === Array ? e = c.length : "object" == typeof c && (e = Object.keys(c).length), o !== e && N.warn("Parsed " + e + " " + r.dxfSymbolName + "'s but expected " + o)), t = a.next(), n;
  82050. },
  82051. f = {
  82052. VPORT: {
  82053. tableRecordsProperty: "viewPorts",
  82054. tableName: "viewPort",
  82055. dxfSymbolName: "VPORT",
  82056. parseTableRecords: function parseTableRecords() {
  82057. var e = [],
  82058. r = {};
  82059. for (N.debug("ViewPort {"), t = a.next(); !s(0, "ENDTAB");) switch (t.code) {
  82060. case 2:
  82061. r.name = t.value, t = a.next();
  82062. break;
  82063. case 10:
  82064. r.lowerLeftCorner = y(), t = a.next();
  82065. break;
  82066. case 11:
  82067. r.upperRightCorner = y(), t = a.next();
  82068. break;
  82069. case 12:
  82070. r.center = y(), t = a.next();
  82071. break;
  82072. case 13:
  82073. r.snapBasePoint = y(), t = a.next();
  82074. break;
  82075. case 14:
  82076. r.snapSpacing = y(), t = a.next();
  82077. break;
  82078. case 15:
  82079. r.gridSpacing = y(), t = a.next();
  82080. break;
  82081. case 16:
  82082. r.viewDirectionFromTarget = y(), t = a.next();
  82083. break;
  82084. case 17:
  82085. r.viewTarget = y(), t = a.next();
  82086. break;
  82087. case 42:
  82088. r.lensLength = t.value, t = a.next();
  82089. break;
  82090. case 43:
  82091. r.frontClippingPlane = t.value, t = a.next();
  82092. break;
  82093. case 44:
  82094. r.backClippingPlane = t.value, t = a.next();
  82095. break;
  82096. case 45:
  82097. r.viewHeight = t.value, t = a.next();
  82098. break;
  82099. case 50:
  82100. r.snapRotationAngle = t.value, t = a.next();
  82101. break;
  82102. case 51:
  82103. r.viewTwistAngle = t.value, t = a.next();
  82104. break;
  82105. case 79:
  82106. r.orthographicType = t.value, t = a.next();
  82107. break;
  82108. case 110:
  82109. r.ucsOrigin = y(), t = a.next();
  82110. break;
  82111. case 111:
  82112. r.ucsXAxis = y(), t = a.next();
  82113. break;
  82114. case 112:
  82115. r.ucsYAxis = y(), t = a.next();
  82116. break;
  82117. case 110:
  82118. r.ucsOrigin = y(), t = a.next();
  82119. break;
  82120. case 281:
  82121. r.renderMode = t.value, t = a.next();
  82122. break;
  82123. case 281:
  82124. r.defaultLightingType = t.value, t = a.next();
  82125. break;
  82126. case 292:
  82127. r.defaultLightingOn = t.value, t = a.next();
  82128. break;
  82129. case 330:
  82130. r.ownerHandle = t.value, t = a.next();
  82131. break;
  82132. case 63:
  82133. case 421:
  82134. case 431:
  82135. r.ambientColor = t.value, t = a.next();
  82136. break;
  82137. case 0:
  82138. "VPORT" === t.value && (N.debug("}"), e.push(r), N.debug("ViewPort {"), r = {}, t = a.next());
  82139. break;
  82140. default:
  82141. S(t), t = a.next();
  82142. }
  82143. return N.debug("}"), e.push(r), e;
  82144. }
  82145. },
  82146. LTYPE: {
  82147. tableRecordsProperty: "lineTypes",
  82148. tableName: "lineType",
  82149. dxfSymbolName: "LTYPE",
  82150. parseTableRecords: function parseTableRecords() {
  82151. var e,
  82152. r,
  82153. n = {},
  82154. o = {};
  82155. for (N.debug("LType {"), t = a.next(); !s(0, "ENDTAB");) switch (t.code) {
  82156. case 2:
  82157. o.name = t.value, e = t.value, t = a.next();
  82158. break;
  82159. case 3:
  82160. o.description = t.value, t = a.next();
  82161. break;
  82162. case 73:
  82163. (r = t.value) > 0 && (o.pattern = []), t = a.next();
  82164. break;
  82165. case 40:
  82166. o.patternLength = t.value, t = a.next();
  82167. break;
  82168. case 49:
  82169. o.pattern.push(t.value), t = a.next();
  82170. break;
  82171. case 0:
  82172. N.debug("}"), r > 0 && r !== o.pattern.length && N.warn("lengths do not match on LTYPE pattern"), n[e] = o, o = {}, N.debug("LType {"), t = a.next();
  82173. break;
  82174. default:
  82175. t = a.next();
  82176. }
  82177. return N.debug("}"), n[e] = o, n;
  82178. }
  82179. },
  82180. LAYER: {
  82181. tableRecordsProperty: "layers",
  82182. tableName: "layer",
  82183. dxfSymbolName: "LAYER",
  82184. parseTableRecords: function parseTableRecords() {
  82185. var e,
  82186. r,
  82187. n = {},
  82188. c = {};
  82189. for (N.debug("Layer {"), t = a.next(); !s(0, "ENDTAB");) switch (t.code) {
  82190. case 2:
  82191. c.name = t.value, e = t.value, t = a.next();
  82192. break;
  82193. case 62:
  82194. c.visible = t.value >= 0, c.colorIndex = Math.abs(t.value), c.color = (r = c.colorIndex, o[r]), t = a.next();
  82195. break;
  82196. case 70:
  82197. c.frozen = 0 != (1 & t.value) || 0 != (2 & t.value), t = a.next();
  82198. break;
  82199. case 0:
  82200. "LAYER" === t.value && (N.debug("}"), n[e] = c, N.debug("Layer {"), c = {}, e = void 0, t = a.next());
  82201. break;
  82202. default:
  82203. S(t), t = a.next();
  82204. }
  82205. return N.debug("}"), n[e] = c, n;
  82206. }
  82207. }
  82208. },
  82209. k = function k(e) {
  82210. var r = [],
  82211. n = e ? "ENDBLK" : "ENDSEC";
  82212. for (e || (t = a.next());;) if (0 === t.code) {
  82213. if (t.value === n) break;
  82214. var o,
  82215. c = u._entityHandlers[t.value];
  82216. if (null == c) {
  82217. N.warn("Unhandled entity " + t.value), t = a.next();
  82218. continue;
  82219. }
  82220. N.debug(t.value + " {"), o = c.parseEntity(a, t), t = a.lastReadGroup, N.debug("}"), x(o), r.push(o);
  82221. } else t = a.next();
  82222. return "ENDSEC" == n && (t = a.next()), r;
  82223. },
  82224. y = function y() {
  82225. var e = {},
  82226. r = t.code;
  82227. if (e.x = t.value, r += 10, (t = a.next()).code != r) throw new Error("Expected code for point value to be " + r + " but got " + t.code + ".");
  82228. return e.y = t.value, r += 10, (t = a.next()).code != r ? (a.rewind(), e) : (e.z = t.value, e);
  82229. },
  82230. x = function x(e) {
  82231. if (!e) throw new TypeError("entity cannot be undefined or null");
  82232. e.handle || (e.handle = c++);
  82233. };
  82234. return function () {
  82235. for (t = a.next(); !a.isEOF();) if (0 === t.code && "SECTION" === t.value) {
  82236. if (2 !== (t = a.next()).code) {
  82237. console.error("Unexpected code %s after 0:SECTION", L(t)), t = a.next();
  82238. continue;
  82239. }
  82240. "HEADER" === t.value ? (N.debug("> HEADER"), n.header = l(), N.debug("<")) : "BLOCKS" === t.value ? (N.debug("> BLOCKS"), n.blocks = v(), N.debug("<")) : "ENTITIES" === t.value ? (N.debug("> ENTITIES"), n.entities = k(!1), N.debug("<")) : "TABLES" === t.value ? (N.debug("> TABLES"), n.tables = b(), N.debug("<")) : "EOF" === t.value ? N.debug("EOF") : N.warn("Skipping section '%s'", t.value);
  82241. } else t = a.next();
  82242. }(), n;
  82243. };
  82244. a.default = T;
  82245. }]).default;
  82246. });
  82247. class DxfLoader extends EventDispatcher {
  82248. constructor() {
  82249. super();
  82250. this.parser = new Potree.DxfParser();
  82251. }
  82252. load(url, done) {
  82253. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  82254. Potree.loadFile(url, {
  82255. returnText: true
  82256. }, data => {
  82257. var dxfJson = this.parser.parseSync(data);
  82258. console.log(dxfJson);
  82259. var model = this.createModel(dxfJson, options);
  82260. done(model);
  82261. });
  82262. }
  82263. createModel(data) {
  82264. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  82265. var root = new Object3D();
  82266. var i, entity, obj, min_x, min_y, min_z, max_x, max_y, max_z;
  82267. /* var dims = {
  82268. min: { x: false, y: false, z: false},
  82269. max: { x: false, y: false, z: false}
  82270. }; */
  82271. //let bound = THREE.Box3
  82272. for (i = 0; i < data.entities.length; i++) {
  82273. entity = data.entities[i];
  82274. obj = drawEntity(entity, data, options.unsupportTypes);
  82275. if (obj) {
  82276. var bbox = new Box3().setFromObject(obj);
  82277. /* if (bbox.min.x && ((dims.min.x === false) || (dims.min.x > bbox.min.x))) dims.min.x = bbox.min.x;
  82278. if (bbox.min.y && ((dims.min.y === false) || (dims.min.y > bbox.min.y))) dims.min.y = bbox.min.y;
  82279. if (bbox.min.z && ((dims.min.z === false) || (dims.min.z > bbox.min.z))) dims.min.z = bbox.min.z;
  82280. if (bbox.max.x && ((dims.max.x === false) || (dims.max.x < bbox.max.x))) dims.max.x = bbox.max.x;
  82281. if (bbox.max.y && ((dims.max.y === false) || (dims.max.y < bbox.max.y))) dims.max.y = bbox.max.y;
  82282. if (bbox.max.z && ((dims.max.z === false) || (dims.max.z < bbox.max.z))) dims.max.z = bbox.max.z; */
  82283. root.add(obj);
  82284. }
  82285. obj = null;
  82286. }
  82287. return root;
  82288. }
  82289. }
  82290. function drawEntity(entity, data, unsupportTypes, group) {
  82291. var mesh;
  82292. if (unsupportTypes && unsupportTypes.includes(entity.type)) {
  82293. console.warn('����һ��dxf������Ƶ�type��', entity.type);
  82294. return; //add �����Ƹ���
  82295. }
  82296. if (entity.type === 'CIRCLE' || entity.type === 'ARC') {
  82297. mesh = drawArc(entity, data, unsupportTypes, group);
  82298. } else if (entity.type === 'LWPOLYLINE' || entity.type === 'LINE' || entity.type === 'POLYLINE') {
  82299. mesh = drawLine(entity, data, unsupportTypes, group);
  82300. } else if (entity.type === 'TEXT') {
  82301. //"MTEXT" text: "{\fKaiTi|b0|i0|c134|p49;�������̨}"
  82302. mesh = drawText(entity, data, unsupportTypes, group);
  82303. } else if (entity.type === 'SOLID') {
  82304. mesh = drawSolid(entity, data);
  82305. } else if (entity.type === 'POINT') {
  82306. mesh = drawPoint(entity, data);
  82307. } else if (entity.type === 'INSERT') {
  82308. //Ƕ������group
  82309. mesh = drawBlock(entity, data, unsupportTypes, group);
  82310. } else if (entity.type === 'SPLINE') {
  82311. mesh = drawSpline(entity, data);
  82312. } else if (entity.type === 'MTEXT') {
  82313. mesh = drawMtext(entity, data, unsupportTypes, group);
  82314. } else if (entity.type === 'ELLIPSE') {
  82315. mesh = drawEllipse(entity, data, unsupportTypes, group);
  82316. } else if (entity.type === 'DIMENSION') {
  82317. var dimTypeEnum = entity.dimensionType & 7;
  82318. if (dimTypeEnum === 0) {
  82319. mesh = drawDimension(entity, data);
  82320. } else {
  82321. console.log("Unsupported Dimension type: " + dimTypeEnum);
  82322. }
  82323. } else {
  82324. console.log("Unsupported Entity Type: " + entity.type);
  82325. }
  82326. if (entity.type === 'LWPOLYLINE' || entity.type === 'LINE' || entity.type === 'POLYLINE') {
  82327. mesh = drawLine(entity, data);
  82328. }
  82329. /* if(entity.type === 'INSERT') {
  82330. mesh = drawBlock(entity, data); //group
  82331. } */
  82332. /*
  82333. �Ŷ���arc
  82334. �ƺ�ǽ�ڶ��Dz���insert���ͣ���������
  82335. */
  82336. mesh && (mesh.dxfInfo = entity); //add
  82337. return mesh;
  82338. }
  82339. function drawEllipse(entity, data) {
  82340. var color = getColor$2(entity, data);
  82341. var xrad = Math.sqrt(Math.pow(entity.majorAxisEndPoint.x, 2) + Math.pow(entity.majorAxisEndPoint.y, 2));
  82342. var yrad = xrad * entity.axisRatio;
  82343. var rotation = Math.atan2(entity.majorAxisEndPoint.y, entity.majorAxisEndPoint.x);
  82344. var curve = new EllipseCurve(entity.center.x, entity.center.y, xrad, yrad, entity.startAngle, entity.endAngle, false,
  82345. // Always counterclockwise
  82346. rotation);
  82347. var points = curve.getPoints(50);
  82348. var geometry = new BufferGeometry().setFromPoints(points);
  82349. var material = new LineBasicMaterial({
  82350. linewidth: 1,
  82351. color: color
  82352. });
  82353. // Create the final object to add to the scene
  82354. var ellipse = new Line(geometry, material);
  82355. return ellipse;
  82356. }
  82357. function drawMtext(entity, data) {
  82358. var color = getColor$2(entity, data);
  82359. //if (!font) { return console.log('font parameter not set. Ignoring text entity.')}
  82360. var geometry = new TextGeometry(entity.text, {
  82361. //font: font,
  82362. size: entity.height * (4 / 5),
  82363. height: 1
  82364. });
  82365. var material = new MeshBasicMaterial({
  82366. color: color
  82367. });
  82368. var text = new Mesh(geometry, material);
  82369. // Measure what we rendered.
  82370. var measure = new Box3();
  82371. measure.setFromObject(text);
  82372. var textWidth = measure.max.x - measure.min.x;
  82373. // If the text ends up being wider than the box, it's supposed
  82374. // to be multiline. Doing that in threeJS is overkill.
  82375. if (textWidth > entity.width) {
  82376. console.log("Can't render this multipline MTEXT entity, sorry.", entity);
  82377. return undefined;
  82378. }
  82379. text.position.z = 0;
  82380. switch (entity.attachmentPoint) {
  82381. case 1:
  82382. // Top Left
  82383. text.position.x = entity.position.x;
  82384. text.position.y = entity.position.y - entity.height;
  82385. break;
  82386. case 2:
  82387. // Top Center
  82388. text.position.x = entity.position.x - textWidth / 2;
  82389. text.position.y = entity.position.y - entity.height;
  82390. break;
  82391. case 3:
  82392. // Top Right
  82393. text.position.x = entity.position.x - textWidth;
  82394. text.position.y = entity.position.y - entity.height;
  82395. break;
  82396. case 4:
  82397. // Middle Left
  82398. text.position.x = entity.position.x;
  82399. text.position.y = entity.position.y - entity.height / 2;
  82400. break;
  82401. case 5:
  82402. // Middle Center
  82403. text.position.x = entity.position.x - textWidth / 2;
  82404. text.position.y = entity.position.y - entity.height / 2;
  82405. break;
  82406. case 6:
  82407. // Middle Right
  82408. text.position.x = entity.position.x - textWidth;
  82409. text.position.y = entity.position.y - entity.height / 2;
  82410. break;
  82411. case 7:
  82412. // Bottom Left
  82413. text.position.x = entity.position.x;
  82414. text.position.y = entity.position.y;
  82415. break;
  82416. case 8:
  82417. // Bottom Center
  82418. text.position.x = entity.position.x - textWidth / 2;
  82419. text.position.y = entity.position.y;
  82420. break;
  82421. case 9:
  82422. // Bottom Right
  82423. text.position.x = entity.position.x - textWidth;
  82424. text.position.y = entity.position.y;
  82425. break;
  82426. default:
  82427. return undefined;
  82428. }
  82429. ;
  82430. return text;
  82431. }
  82432. function drawSpline(entity, data) {
  82433. var color = getColor$2(entity, data);
  82434. var points = entity.controlPoints.map(function (vec) {
  82435. return new Vector2(vec.x, vec.y);
  82436. });
  82437. var interpolatedPoints = [];
  82438. var curve;
  82439. if (entity.degreeOfSplineCurve === 2 || entity.degreeOfSplineCurve === 3) {
  82440. for (var i = 0; i + 2 < points.length; i = i + 2) {
  82441. if (entity.degreeOfSplineCurve === 2) {
  82442. curve = new QuadraticBezierCurve(points[i], points[i + 1], points[i + 2]);
  82443. } else {
  82444. curve = new QuadraticBezierCurve3(points[i], points[i + 1], points[i + 2]);
  82445. }
  82446. interpolatedPoints.push.apply(interpolatedPoints, curve.getPoints(50));
  82447. }
  82448. } else {
  82449. curve = new SplineCurve(points);
  82450. interpolatedPoints = curve.getPoints(100);
  82451. }
  82452. var geometry = new BufferGeometry().setFromPoints(interpolatedPoints);
  82453. var material = new LineBasicMaterial({
  82454. linewidth: 1,
  82455. color: color
  82456. });
  82457. var splineObject = new Line(geometry, material);
  82458. return splineObject;
  82459. }
  82460. function drawLine(entity, data) {
  82461. var geometry = new Geometry(),
  82462. color = getColor$2(entity, data),
  82463. material,
  82464. lineType,
  82465. vertex,
  82466. startPoint,
  82467. endPoint,
  82468. bulgeGeometry,
  82469. bulge,
  82470. i,
  82471. line;
  82472. if (!entity.vertices) return console.log('entity missing vertices.');
  82473. // create geometry
  82474. for (i = 0; i < entity.vertices.length; i++) {
  82475. if (entity.vertices[i].bulge) {
  82476. bulge = entity.vertices[i].bulge;
  82477. startPoint = entity.vertices[i];
  82478. endPoint = i + 1 < entity.vertices.length ? entity.vertices[i + 1] : geometry.vertices[0];
  82479. bulgeGeometry = new THREEx.BulgeGeometry(startPoint, endPoint, bulge);
  82480. geometry.vertices.push.apply(geometry.vertices, bulgeGeometry.vertices);
  82481. } else {
  82482. vertex = entity.vertices[i];
  82483. geometry.vertices.push(new Vector3(vertex.x, vertex.y, 0));
  82484. }
  82485. }
  82486. if (entity.shape) geometry.vertices.push(geometry.vertices[0]);
  82487. // set material
  82488. if (entity.lineType) {
  82489. lineType = data.tables.lineType.lineTypes[entity.lineType];
  82490. }
  82491. if (lineType && lineType.pattern && lineType.pattern.length !== 0) {
  82492. material = new LineDashedMaterial({
  82493. color: color,
  82494. gapSize: 4,
  82495. dashSize: 4
  82496. });
  82497. } else {
  82498. material = new LineBasicMaterial({
  82499. linewidth: 1,
  82500. color: color
  82501. });
  82502. }
  82503. // if(lineType && lineType.pattern && lineType.pattern.length !== 0) {
  82504. // geometry.computeLineDistances();
  82505. // // Ugly hack to add diffuse to this. Maybe copy the uniforms object so we
  82506. // // don't add diffuse to a material.
  82507. // lineType.material.uniforms.diffuse = { type: 'c', value: new THREE.Color(color) };
  82508. // material = new THREE.ShaderMaterial({
  82509. // uniforms: lineType.material.uniforms,
  82510. // vertexShader: lineType.material.vertexShader,
  82511. // fragmentShader: lineType.material.fragmentShader
  82512. // });
  82513. // }else {
  82514. // material = new THREE.LineBasicMaterial({ linewidth: 1, color: color });
  82515. // }
  82516. line = new Line(geometry, material);
  82517. return line;
  82518. }
  82519. function drawArc(entity, data) {
  82520. var startAngle, endAngle;
  82521. if (entity.type === 'CIRCLE') {
  82522. startAngle = entity.startAngle || 0;
  82523. endAngle = startAngle + 2 * Math.PI;
  82524. } else {
  82525. startAngle = entity.startAngle;
  82526. endAngle = entity.endAngle;
  82527. }
  82528. var curve = new ArcCurve(0, 0, entity.radius, startAngle, endAngle);
  82529. var points = curve.getPoints(32);
  82530. var geometry = new BufferGeometry().setFromPoints(points);
  82531. var material = new LineBasicMaterial({
  82532. color: getColor$2(entity, data)
  82533. });
  82534. var arc = new Line(geometry, material);
  82535. arc.position.x = entity.center.x;
  82536. arc.position.y = entity.center.y;
  82537. arc.position.z = entity.center.z;
  82538. return arc;
  82539. }
  82540. function drawSolid(entity, data) {
  82541. var material,
  82542. mesh,
  82543. verts,
  82544. geometry = new Geometry();
  82545. verts = geometry.vertices;
  82546. verts.push(new Vector3(entity.points[0].x, entity.points[0].y, entity.points[0].z));
  82547. verts.push(new Vector3(entity.points[1].x, entity.points[1].y, entity.points[1].z));
  82548. verts.push(new Vector3(entity.points[2].x, entity.points[2].y, entity.points[2].z));
  82549. verts.push(new Vector3(entity.points[3].x, entity.points[3].y, entity.points[3].z));
  82550. // Calculate which direction the points are facing (clockwise or counter-clockwise)
  82551. var vector1 = new Vector3();
  82552. var vector2 = new Vector3();
  82553. vector1.subVectors(verts[1], verts[0]);
  82554. vector2.subVectors(verts[2], verts[0]);
  82555. vector1.cross(vector2);
  82556. // If z < 0 then we must draw these in reverse order
  82557. if (vector1.z < 0) {
  82558. geometry.faces.push(new Face3(2, 1, 0));
  82559. geometry.faces.push(new Face3(2, 3, 1));
  82560. } else {
  82561. geometry.faces.push(new Face3(0, 1, 2));
  82562. geometry.faces.push(new Face3(1, 3, 2));
  82563. }
  82564. material = new MeshBasicMaterial({
  82565. color: getColor$2(entity, data)
  82566. });
  82567. return new Mesh(geometry, material);
  82568. }
  82569. function drawText(entity, data) {
  82570. var geometry, material, text;
  82571. //����Ҫfont���ܻ�������
  82572. /* if(!font)
  82573. return console.warn('Text is not supported without a Three.js font loaded with THREE.FontLoader! Load a font of your choice and pass this into the constructor. See the sample for this repository or Three.js examples at http://threejs.org/examples/?q=text#webgl_geometry_text for more details.');
  82574. */
  82575. geometry = new TextGeometry(entity.text, {
  82576. /* font: font, */height: 0,
  82577. size: entity.textHeight || 12
  82578. });
  82579. if (entity.rotation) {
  82580. var zRotation = entity.rotation * Math.PI / 180;
  82581. geometry.rotateZ(zRotation);
  82582. }
  82583. material = new MeshBasicMaterial({
  82584. color: getColor$2(entity, data)
  82585. });
  82586. text = new Mesh(geometry, material);
  82587. text.position.x = entity.startPoint.x;
  82588. text.position.y = entity.startPoint.y;
  82589. text.position.z = entity.startPoint.z;
  82590. return text;
  82591. }
  82592. function drawPoint(entity, data) {
  82593. var geometry, material, point;
  82594. geometry = new Geometry();
  82595. geometry.vertices.push(new Vector3(entity.position.x, entity.position.y, entity.position.z));
  82596. // TODO: could be more efficient. PointCloud per layer?
  82597. var numPoints = 1;
  82598. var color = getColor$2(entity, data);
  82599. var colors = new Float32Array(numPoints * 3);
  82600. colors[0] = color.r;
  82601. colors[1] = color.g;
  82602. colors[2] = color.b;
  82603. geometry.colors = colors;
  82604. geometry.computeBoundingBox();
  82605. material = new PointsMaterial({
  82606. size: 0.05,
  82607. vertexColors: VertexColors
  82608. });
  82609. point = new Points(geometry, material);
  82610. //scene.add(point);
  82611. return point;
  82612. }
  82613. function drawDimension(entity, data, unsupportTypes, parentGroup) {
  82614. return drawBlock(entity, data, unsupportTypes, parentGroup, true);
  82615. //��
  82616. /* var block = data.blocks[entity.block];
  82617. if (!block || !block.entities) return null;
  82618. var group = new THREE.Object3D();
  82619. // if(entity.anchorPoint) {
  82620. // group.position.x = entity.anchorPoint.x;
  82621. // group.position.y = entity.anchorPoint.y;
  82622. // group.position.z = entity.anchorPoint.z;
  82623. // }
  82624. for(var i = 0; i < block.entities.length; i++) {
  82625. var childEntity = drawEntity(block.entities[i], data, group);
  82626. if(childEntity && !group.children.includes(childEntity)) group.add(childEntity);
  82627. }
  82628. return group; */
  82629. }
  82630. function drawBlock(entity, data, unsupportTypes, parentGroup, isDimension) {
  82631. var block = data.blocks[entity.name];
  82632. if (!block.entities) return null;
  82633. var group = new Object3D();
  82634. parentGroup && parentGroup.add(group); //��ǰ���� Ϊ�˻��matrixWorld
  82635. if (!isDimension) {
  82636. if (entity.position) {
  82637. group.position.x = entity.position.x;
  82638. group.position.y = entity.position.y;
  82639. group.position.z = entity.position.z;
  82640. }
  82641. if (entity.xScale) {
  82642. group.scale.x = entity.xScale;
  82643. }
  82644. if (entity.yScale) {
  82645. group.scale.y = entity.yScale;
  82646. }
  82647. if (entity.rotation) {
  82648. group.rotation.z = entity.rotation * Math.PI / 180;
  82649. }
  82650. //add: ���������еĻ������������Զ add zScale
  82651. var flag;
  82652. if (entity.zScale != void 0 && entity.extrusionDirection) {
  82653. //see (005.dxf�� others/01.dxf) extrusionDirection ={x:0,y:0,z:-1}
  82654. group.position.x *= Math.sign(entity.zScale);
  82655. group.scale.x *= Math.sign(entity.zScale);
  82656. group.rotation.z *= Math.sign(entity.zScale);
  82657. flag = 1;
  82658. //�����������extrusionDirection
  82659. }
  82660. } else {
  82661. /* if(entity.anchorPoint) {
  82662. group.position.x = entity.anchorPoint.x;
  82663. group.position.y = entity.anchorPoint.y;
  82664. group.position.z = entity.anchorPoint.z;
  82665. } */
  82666. }
  82667. //add:
  82668. group.updateMatrixWorld();
  82669. var visiEntities = block.entities.filter(e => e.visible !== false);
  82670. //console.log("block�Ŀɼ�children����"+block.entities.length)
  82671. for (var i = 0; i < visiEntities.length; i++) {
  82672. var childEntity = drawEntity(visiEntities[i], data, unsupportTypes, group);
  82673. if (childEntity && !group.children.includes(childEntity)) group.add(childEntity);
  82674. }
  82675. return group;
  82676. }
  82677. function getColor$2(entity, data) {
  82678. var color = 0x000000; //default
  82679. if (entity.color) color = entity.color;else if (data.tables && data.tables.layer && data.tables.layer.layers[entity.layer]) color = data.tables.layer.layers[entity.layer].color;
  82680. if (color == null || color === 0xffffff) {
  82681. color = 0x000000;
  82682. }
  82683. return color;
  82684. }
  82685. function createLineTypeShaders(data) {
  82686. var ltype, type;
  82687. if (!data.tables || !data.tables.lineType) return;
  82688. var ltypes = data.tables.lineType.lineTypes;
  82689. for (type in ltypes) {
  82690. ltype = ltypes[type];
  82691. if (!ltype.pattern) continue;
  82692. ltype.material = createDashedLineShader(ltype.pattern);
  82693. }
  82694. }
  82695. function createDashedLineShader(pattern) {
  82696. var i,
  82697. dashedLineShader = {},
  82698. totalLength = 0.0;
  82699. for (i = 0; i < pattern.length; i++) {
  82700. totalLength += Math.abs(pattern[i]);
  82701. }
  82702. dashedLineShader.uniforms = UniformsUtils.merge([UniformsLib['common'], UniformsLib['fog'], {
  82703. 'pattern': {
  82704. type: 'fv1',
  82705. value: pattern
  82706. },
  82707. 'patternLength': {
  82708. type: 'f',
  82709. value: totalLength
  82710. }
  82711. }]);
  82712. dashedLineShader.vertexShader = ['attribute float lineDistance;', 'varying float vLineDistance;', ShaderChunk['color_pars_vertex'], 'void main() {', ShaderChunk['color_vertex'], 'vLineDistance = lineDistance;', 'gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );', '}'].join('\n');
  82713. dashedLineShader.fragmentShader = ['uniform vec3 diffuse;', 'uniform float opacity;', 'uniform float pattern[' + pattern.length + '];', 'uniform float patternLength;', 'varying float vLineDistance;', ShaderChunk['color_pars_fragment'], ShaderChunk['fog_pars_fragment'], 'void main() {', 'float pos = mod(vLineDistance, patternLength);', 'for ( int i = 0; i < ' + pattern.length + '; i++ ) {', 'pos = pos - abs(pattern[i]);', 'if( pos < 0.0 ) {', 'if( pattern[i] > 0.0 ) {', 'gl_FragColor = vec4(1.0, 0.0, 0.0, opacity );', 'break;', '}', 'discard;', '}', '}', ShaderChunk['color_fragment'], ShaderChunk['fog_fragment'], '}'].join('\n');
  82714. return dashedLineShader;
  82715. }
  82716. function findExtents(scene) {
  82717. for (var child of scene.children) {
  82718. var minX, maxX, minY, maxY;
  82719. if (child.position) {
  82720. minX = Math.min(child.position.x, minX);
  82721. minY = Math.min(child.position.y, minY);
  82722. maxX = Math.max(child.position.x, maxX);
  82723. maxY = Math.max(child.position.y, maxY);
  82724. }
  82725. }
  82726. return {
  82727. min: {
  82728. x: minX,
  82729. y: minY
  82730. },
  82731. max: {
  82732. x: maxX,
  82733. y: maxY
  82734. }
  82735. };
  82736. }
  82737. // Three.js extension functions. Webpack doesn't seem to like it if we modify the THREE object directly.
  82738. var THREEx = {
  82739. Math: {}
  82740. };
  82741. /**
  82742. * Returns the angle in radians of the vector (p1,p2). In other words, imagine
  82743. * putting the base of the vector at coordinates (0,0) and finding the angle
  82744. * from vector (1,0) to (p1,p2).
  82745. * @param {Object} p1 start point of the vector
  82746. * @param {Object} p2 end point of the vector
  82747. * @return {Number} the angle
  82748. */
  82749. THREEx.Math.angle2 = function (p1, p2) {
  82750. var v1 = new Vector2(p1.x, p1.y);
  82751. var v2 = new Vector2(p2.x, p2.y);
  82752. v2.sub(v1); // sets v2 to be our chord
  82753. v2.normalize();
  82754. if (v2.y < 0) return -Math.acos(v2.x);
  82755. return Math.acos(v2.x);
  82756. };
  82757. THREEx.Math.polar = function (point, distance, angle) {
  82758. var result = {};
  82759. result.x = point.x + distance * Math.cos(angle);
  82760. result.y = point.y + distance * Math.sin(angle);
  82761. return result;
  82762. };
  82763. /**
  82764. * Calculates points for a curve between two points
  82765. * @param startPoint - the starting point of the curve
  82766. * @param endPoint - the ending point of the curve
  82767. * @param bulge - a value indicating how much to curve
  82768. * @param segments - number of segments between the two given points
  82769. */
  82770. THREEx.BulgeGeometry = function (startPoint, endPoint, bulge, segments) {
  82771. var vertex, i, center, p0, p1, angle, radius, startAngle, thetaAngle;
  82772. Geometry.call(this);
  82773. this.startPoint = p0 = startPoint ? new Vector2(startPoint.x, startPoint.y) : new Vector2(0, 0);
  82774. this.endPoint = p1 = endPoint ? new Vector2(endPoint.x, endPoint.y) : new Vector2(1, 0);
  82775. this.bulge = bulge = bulge || 1;
  82776. angle = 4 * Math.atan(bulge);
  82777. radius = p0.distanceTo(p1) / 2 / Math.sin(angle / 2);
  82778. center = THREEx.Math.polar(startPoint, radius, THREEx.Math.angle2(p0, p1) + (Math.PI / 2 - angle / 2));
  82779. this.segments = segments = segments || Math.max(Math.abs(Math.ceil(angle / (Math.PI / 18))), 6); // By default want a segment roughly every 10 degrees
  82780. startAngle = THREEx.Math.angle2(center, p0);
  82781. thetaAngle = angle / segments;
  82782. this.vertices.push(new Vector3(p0.x, p0.y, 0));
  82783. for (i = 1; i <= segments - 1; i++) {
  82784. vertex = THREEx.Math.polar(center, Math.abs(radius), startAngle + thetaAngle * i);
  82785. this.vertices.push(new Vector3(vertex.x, vertex.y, 0));
  82786. }
  82787. };
  82788. THREEx.BulgeGeometry.prototype = Object.create(Geometry.prototype);
  82789. /* -----note--------------
  82790. */
  82791. var manager = new LoadingManager();
  82792. var loaders = {};
  82793. var mapArea;
  82794. var shelterHistory = [];
  82795. Potree.isIframeChild = window.parent != window; //子页面
  82796. /* if(Potree.isIframeChild){
  82797. let rootWin = Common.getRootWindow()
  82798. rootWin && rootWin.viewer.dispatchEvent({type:'createIframe', window}) //给祖先页面发送信息,得不到可能跨域了或无viewer
  82799. } */
  82800. /* window.addEventListener('focus',()=>{
  82801. console.log('focus',window.winIndex)
  82802. })
  82803. window.addEventListener('blur',()=>{
  82804. console.log('blur',window.winIndex)
  82805. }) */
  82806. class Viewer$1 extends ViewerBase {
  82807. constructor(domElement, mapArea_) {
  82808. var args = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  82809. super(domElement, $.extend(args, {
  82810. name: 'mainViewer',
  82811. antialias: true,
  82812. preserveDrawingBuffer: true
  82813. }));
  82814. //注:viewer因为要分屏,尤其是四屏,preserveDrawingBuffer需要为true, 否则无法局部clear
  82815. window.viewer = this;
  82816. mapArea = mapArea_;
  82817. if (Potree.settings.editType == "pano" || Potree.settings.editType == "merge") {
  82818. this.modules = {
  82819. Alignment,
  82820. SiteModel,
  82821. volumeComputer: new VolumeComputer() //暂时
  82822. };
  82823. Potree.settings.useDepthTex = Potree.settings.mergeType2;
  82824. if (Potree.settings.editType == "pano") {
  82825. this.modules.PanoEditor = PanoEditor$1;
  82826. } else if (Potree.settings.editType == "merge") {
  82827. this.modules.MergeEditor = MergeEditor;
  82828. this.modules.CamAniEditor = CamAniEditor;
  82829. }
  82830. } else {
  82831. this.modules = {
  82832. Clip,
  82833. Alignment,
  82834. SiteModel,
  82835. RouteGuider: new RouteGuider(),
  82836. clipping: new Clipping(),
  82837. ParticleEditor,
  82838. CamAniEditor,
  82839. volumeComputer: new VolumeComputer(),
  82840. MergeEditor
  82841. };
  82842. }
  82843. {
  82844. Potree.timeCollect = {
  82845. //median预置一个中等值,以防止cpu过低的设备首次卡顿
  82846. //depthSampler : {minCount:400, median: 1}, //旧的 实时从图片中获取色值的用时,但是现在直接从data中取
  82847. depthSamChangeImg: {
  82848. minCount: 200,
  82849. median: 25
  82850. } //换图的用时。 需要一开始就start
  82851. };
  82852. for (var i in Potree.timeCollect) {
  82853. Potree.timeCollect[i].measures = [];
  82854. Potree.timeCollect[i].sum = 0;
  82855. }
  82856. setTimeout(() => {
  82857. for (var _i in Potree.timeCollect) {
  82858. Potree.timeCollect[_i].start = true;
  82859. }
  82860. /* setTimeout(()=>{
  82861. console.log('timeCollect', Potree.timeCollect.depthSampler.median, Potree.timeCollect.depthSampler.ave, Potree.timeCollect.depthSampler.measures.length)
  82862. },10000) */
  82863. }, 2000);
  82864. }
  82865. this.navigateMode = 'free'; // 'panorama'; 'free'自由模式是只显示点云或者未进入到漫游点,
  82866. this.isEdit = true;
  82867. this.waitQueue = [];
  82868. this.unitConvert = new UoMService();
  82869. this.visible = true;
  82870. this.fpVisiDatasets = [];
  82871. this.atDatasets = [];
  82872. this.objs = new Object3D(), this.objs.name = 'objs';
  82873. this.objs.addEventListener('isVisible', () => {
  82874. this.setAllTilesets(model => model.visiChangeCallback());
  82875. });
  82876. this.testMaxNodeCount = 0;
  82877. this.tiles3dVisiVCount = 0;
  82878. //this.lastPos = new THREE.Vector3(Infinity,Infinity,Infinity)
  82879. //-------------
  82880. var supportExtFragDepth = !!Potree.Features.EXT_DEPTH.isSupported(this.renderer.getContext()); //iphoneX居然不支持
  82881. //这意味着边缘增强和测量线遮挡失效
  82882. if (!supportExtFragDepth) console.error('ExtFragDepth unsupported! 边缘增强和测量线遮挡失效');
  82883. this.guiLoaded = false;
  82884. this.guiLoadTasks = [];
  82885. this.onVrListeners = [];
  82886. this.messages = [];
  82887. this.elMessages = $("\n\t\t<div id=\"message_listing\" \n\t\t\tstyle=\"position: absolute; z-index: 1000; left: 10px; bottom: 10px\">\n\t\t</div>");
  82888. $(domElement).append(this.elMessages);
  82889. this.fakeMeasure = {};
  82890. try {
  82891. if (!Potree.settings.isOfficial) {
  82892. // generate missing dom hierarchy
  82893. if ($(domElement).find('#potree_map').length === 0) {
  82894. var potreeMap = $("\n <div id=\"potree_map\" class=\"mapBox\" style=\"position: absolute; left: 50px; top: 50px; width: 400px; height: 400px; display: none\">\n <div id=\"potree_map_header\" style=\"position: absolute; width: 100%; height: 25px; top: 0px; background-color: rgba(0,0,0,0.5); z-index: 1000; border-top-left-radius: 3px; border-top-right-radius: 3px;\">\n </div>\n <div id=\"potree_map_content\" class=\"map\" style=\"position: absolute; z-index: 100; top: 25px; width: 100%; height: calc(100% - 25px); border: 2px solid rgba(0,0,0,0.5); box-sizing: border-box;\"></div>\n </div>\n ");
  82895. $(domElement).append(potreeMap);
  82896. }
  82897. if ($(domElement).find('#potree_description').length === 0) {
  82898. var potreeDescription = $("<div id=\"potree_description\" class=\"potree_info_text\"></div>");
  82899. $(domElement).append(potreeDescription);
  82900. }
  82901. if ($(domElement).find('#potree_annotations').length === 0) {
  82902. var potreeAnnotationContainer = $("\n <div id=\"potree_annotation_container\" \n style=\"position: absolute; z-index: 100000; width: 100%; height: 100%; pointer-events: none;\"></div>");
  82903. $(domElement).append(potreeAnnotationContainer);
  82904. }
  82905. if ($(domElement).find('#potree_quick_buttons').length === 0) {
  82906. var _potreeMap = $("\n <div id=\"potree_quick_buttons\" class=\"quick_buttons_container\" style=\"\">\n </div>\n ");
  82907. $(domElement).append(_potreeMap);
  82908. }
  82909. //add
  82910. {
  82911. $(domElement).append($("<div id='potree_labels'></div>"));
  82912. if (!mapArea && Potree.settings.editType != 'merge' /* || Potree.settings.showObjectsOnMap */) {
  82913. mapArea = $("<div id='mapGaode'></div>");
  82914. $(domElement).append(mapArea);
  82915. mapArea = mapArea[0];
  82916. }
  82917. }
  82918. /* let domRoot = this.renderer.domElement.parentElement;
  82919. let elAttach = $("<input type='button' value='test'></input>");
  82920. elAttach.css({
  82921. position : "absolute",
  82922. right : '10%',
  82923. bottom: '20px',
  82924. zIndex: "10000",
  82925. fontSize:'1em', color:"black",
  82926. background:'rgba(255,255,255,0.8)',
  82927. })
  82928. let state = false
  82929. elAttach.on("click", () => {
  82930. window.buttonFunction && window.buttonFunction()
  82931. });
  82932. domRoot.appendChild(elAttach[0]); */
  82933. }
  82934. this.tiles3dMemoryUsage = 0;
  82935. this.pointCloudLoadedCallback = args.onPointCloudLoaded || function () {};
  82936. // if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
  82937. // defaultSettings.navigation = "Orbit";
  82938. // }
  82939. this.server = null;
  82940. this.fov = 60;
  82941. this.isFlipYZ = false;
  82942. this.useDEMCollisions = false;
  82943. this.generateDEM = false;
  82944. this.minNodeSize = 30; //允许加载的node的最小可见像素宽度。越大越省性能
  82945. this.edlStrength = 1.0;
  82946. this.edlRadius = 1.4;
  82947. this.edlOpacity = 1.0;
  82948. this.useEDL = false;
  82949. this.description = "";
  82950. this.classifications = ClassificationScheme.DEFAULT;
  82951. this.moveSpeed = 1;
  82952. this.lengthUnit = LengthUnits.METER;
  82953. this.lengthUnitDisplay = LengthUnits.METER;
  82954. this.showBoundingBox = false;
  82955. this.showAnnotations = true;
  82956. this.freeze = false;
  82957. this.elevationGradientRepeat = ElevationGradientRepeat.CLAMP;
  82958. this.filterReturnNumberRange = [0, 7];
  82959. this.filterNumberOfReturnsRange = [0, 7];
  82960. this.filterGPSTimeRange = [-Infinity, Infinity];
  82961. this.filterPointSourceIDRange = [0, 65535];
  82962. this.potreeRenderer = null;
  82963. this.edlRenderer = null;
  82964. this.pRenderer = null;
  82965. this.scene = null;
  82966. this.sceneVR = null;
  82967. this.overlay = null;
  82968. this.overlayCamera = null;
  82969. this.inputHandler = null;
  82970. this.controls = null;
  82971. this.clippingTool = null;
  82972. this.transformationTool = null;
  82973. this.navigationCube = null;
  82974. this.compass = null;
  82975. this.skybox = null;
  82976. this.clock = new Clock();
  82977. this.background = null;
  82978. this.buffers = new Map();
  82979. if (args.noDragAndDrop) {} else {
  82980. this.initDragAndDrop();
  82981. }
  82982. if (typeof Stats !== "undefined") {
  82983. this.stats = new Stats();
  82984. this.stats.showPanel(0); // 0: fps, 1: ms, 2: mb, 3+: custom
  82985. document.body.appendChild(this.stats.dom);
  82986. }
  82987. {
  82988. this.overlay = new Scene();
  82989. this.overlayCamera = new OrthographicCamera(0, 1, 1, 0, -1000, 1000);
  82990. }
  82991. this.pRenderer = new Renderer$1(this.renderer);
  82992. {
  82993. var near = 2.5;
  82994. var far = 10.0;
  82995. var fov = 90;
  82996. this.shadowTestCam = new PerspectiveCamera(90, 1, near, far);
  82997. this.shadowTestCam.position.set(3.50, -2.80, 8.561);
  82998. this.shadowTestCam.lookAt(new Vector3(0, 0, 4.87));
  82999. }
  83000. var scene = new ExtendScene(this.renderer);
  83001. {
  83002. // create VR scene
  83003. this.sceneVR = new Scene();
  83004. // let texture = new THREE.TextureLoader().load(`${Potree.resourcePath}/images/vr_controller_help.jpg`);
  83005. // let plane = new THREE.PlaneBufferGeometry(1, 1, 1, 1);
  83006. // let infoMaterial = new THREE.MeshBasicMaterial({map: texture});
  83007. // let infoNode = new THREE.Mesh(plane, infoMaterial);
  83008. // infoNode.position.set(-0.5, 1, 0);
  83009. // infoNode.scale.set(0.4, 0.3, 1);
  83010. // infoNode.lookAt(0, 1, 0)
  83011. // this.sceneVR.add(infoNode);
  83012. // window.infoNode = infoNode;
  83013. }
  83014. this.setScene(scene);
  83015. //add: for 截图时抗锯齿
  83016. {
  83017. /* this.composer = new EffectComposer( this.renderer );
  83018. this.ssaaRenderPass = new SSAARenderPass(0x000000, 0);
  83019. this.composer.addPass( this.ssaaRenderPass );
  83020. */
  83021. //this.ssaaRenderPass.useCopy = true
  83022. //this.ssaaRenderPass.renderToScreen = true;
  83023. //this.ssaaRenderPass.needsSwap = false
  83024. //见 https://threejs.org/examples/?q=AA#webgl_postprocessing_fxaa 效果和SSAA差不多,都对透明不太友好。
  83025. /* let outlinePass = this.outlinePass = new OutlinePass( );
  83026. this.ssaaRenderPass.addPass(outlinePass)
  83027. */
  83028. //ssaa有透明度、发黑的问题所以不用了
  83029. //--------------------------
  83030. this.composer = new EffectComposer(this.renderer);
  83031. this.composer.scaleRatio = 4; //将底图和测量线绘制在一张高倍贴图上,for测量线不模糊
  83032. this.composer.readTarget = true; //把底图和测量线一起fxaa
  83033. /* const renderPass = new RenderPass();
  83034. //renderPass.clearColor = new THREE.Color( 0,0,0 );
  83035. //renderPass.clearAlpha = 0;
  83036. renderPass.clear = !this.composer.readTarget
  83037. this.composer.addPass( renderPass );
  83038. */
  83039. //for 融合页面
  83040. var outlinePass = this.outlinePass = new OutlinePass();
  83041. outlinePass.renderToScreen = true; //这样更流畅,不用ssaa了,缺点是outline有锯齿
  83042. outlinePass.enabled = false;
  83043. this.composer.addPass(outlinePass);
  83044. outlinePass.edgeStrength = 4;
  83045. outlinePass.edgeGlow = 0;
  83046. outlinePass.visibleEdgeColor = new Color("#09a1b3");
  83047. /* this.fxaaPass = new ShaderPass( FXAAShader );
  83048. this.fxaaPass.readTarget = true //add
  83049. this.fxaaPass.setSize = function(width, height){
  83050. this.material.uniforms[ 'resolution' ].value.x = 1 / ( width ) ;
  83051. this.material.uniforms[ 'resolution' ].value.y = 1 / ( height ) ;
  83052. }
  83053. this.fxaaPass.renderToScreen = true;
  83054. this.composer.addPass( this.fxaaPass ); */
  83055. //抗锯齿截图 效果时而好时而不好,文字比较模糊
  83056. //这两个暂时不能一起用。目前刚好不需要一起用
  83057. /* this.images360.fastTranMaskPass = new FastTranPass( this.renderer )
  83058. this.composer.addPass(this.images360.fastTranMaskPass)//add */
  83059. }
  83060. {
  83061. this.mainViewport = new Viewport(this.scene.view, this.scene.cameraP, {
  83062. left: 0,
  83063. bottom: 0,
  83064. width: 1,
  83065. height: 1,
  83066. name: 'MainView'
  83067. });
  83068. this.viewports = [this.mainViewport];
  83069. Potree.settings.showCompass && (this.compass = new Compass(Potree.settings.compassDom, this.mainViewport));
  83070. //this.axis = new AxisViewer(this.mainViewport, this.renderArea )
  83071. this.magnifier = new Magnifier(this);
  83072. this.reticule = new Reticule(this);
  83073. this.scene.scene.add(this.magnifier);
  83074. this.scene.scene.add(this.reticule);
  83075. if (Potree.settings.editType != "pano" && Potree.settings.editType != 'merge' /* || Potree.settings.showObjectsOnMap */) {
  83076. this.mapViewer = new MapViewer(mapArea /* $('#mapGaode')[0] */);
  83077. }
  83078. this.inputHandler = new InputHandler(this, this.scene.scene);
  83079. this.inputHandler.containsMouse = true; //初始化,使键盘事件在mainViewer有效
  83080. //this.inputHandler.setScene(this.scene);
  83081. //this.inputHandler.addInputListener(this);//add
  83082. this.clippingTool = new ClippingTool(this);
  83083. this.transformationTool = new TransformationTool(this);
  83084. this.navigationCube = new NavigationCube(this);
  83085. this.navigationCube.visible = false;
  83086. this.createControls();
  83087. this.clippingTool.setScene(this.scene);
  83088. var onPointcloudAdded = e => {
  83089. if (this.scene.pointclouds.length === 1) {
  83090. var speed = e.pointcloud.boundingBox.getSize(new Vector3()).length();
  83091. speed = speed / 2000;
  83092. this.setMoveSpeed(speed);
  83093. }
  83094. };
  83095. var onVolumeRemoved = e => {
  83096. this.inputHandler.deselect(e.volume);
  83097. };
  83098. this.addEventListener('scene_changed', e => {
  83099. this.inputHandler.setScene(e.scene);
  83100. this.clippingTool.setScene(this.scene);
  83101. if (!e.scene.hasEventListener("pointcloud_added", onPointcloudAdded)) {
  83102. e.scene.addEventListener("pointcloud_added", onPointcloudAdded);
  83103. }
  83104. if (!e.scene.hasEventListener("volume_removed", onPointcloudAdded)) {
  83105. e.scene.addEventListener("volume_removed", onVolumeRemoved);
  83106. }
  83107. });
  83108. this.scene.addEventListener("volume_removed", onVolumeRemoved);
  83109. this.scene.addEventListener('pointcloud_added', onPointcloudAdded);
  83110. }
  83111. {
  83112. // set defaults
  83113. this.setFOV(60);
  83114. this.setEDLEnabled(false);
  83115. this.setEDLRadius(3);
  83116. this.setEDLStrength(0.01);
  83117. this.setEDLOpacity(1.0);
  83118. this.setPointBudget(1 * 1000 * 1000);
  83119. this.setShowBoundingBox(false);
  83120. this.setFreeze(false);
  83121. this.setControls(this.fpControls /* orbitControls */);
  83122. this.setBackground(new Color(Potree.config.background), 1 /* 'gradient' */);
  83123. this.scaleFactor = 1;
  83124. this.loadSettingsFromURL();
  83125. }
  83126. // start rendering!
  83127. //if(args.useDefaultRenderLoop === undefined || args.useDefaultRenderLoop === true){
  83128. //requestAnimationFrame(this.loop.bind(this));
  83129. //}
  83130. this.renderer.setAnimationLoop(this.loop.bind(this));
  83131. this.loadGUI = this.loadGUI.bind(this);
  83132. this.annotationTool = new AnnotationTool(this);
  83133. this.measuringTool = new MeasuringTool(this);
  83134. //this.profileTool = new ProfileTool(this);
  83135. this.volumeTool = new VolumeTool(this);
  83136. this.tagTool = new TagTool(this);
  83137. //-----------
  83138. CursorDeal.init(this, this.mapViewer ? [this, this.mapViewer] : [this]); //ADD
  83139. if (Potree.settings.editType == "pano") {
  83140. this.modules.PanoEditor.init();
  83141. } else if (Potree.settings.editType == "merge") {
  83142. this.modules.MergeEditor.init();
  83143. } else {
  83144. this.modules.SiteModel.init();
  83145. this.modules.ParticleEditor.init();
  83146. }
  83147. this.modules.Alignment.init();
  83148. this.images360 = new Images360(this);
  83149. this.scene.scene.add(this.objs);
  83150. loaders = {
  83151. objLoader: new OBJLoader(manager),
  83152. mtlLoader: new MTLLoader(manager),
  83153. glbLoader: new GLTFLoader(undefined, this.renderer, Potree.settings.libsUrl),
  83154. plyLoader: new PLYLoader(manager),
  83155. dxfLoader: new DxfLoader(),
  83156. shapeLoader: new Potree.ShapefileLoader()
  83157. };
  83158. //add test
  83159. /* const environment = new RoomEnvironment();
  83160. const pmremGenerator = new THREE.PMREMGenerator( this.renderer );
  83161. this.scene.scene.environment = pmremGenerator.fromScene( environment ).texture;
  83162. */
  83163. //-----------
  83164. this.modules.volumeComputer && this.modules.volumeComputer.init();
  83165. } catch (e) {
  83166. this.onCrash(e);
  83167. }
  83168. //-----------------------add----------------------------------------------------
  83169. /* {
  83170. let ratio
  83171. this.addEventListener('resize',(e)=>{
  83172. if(ratio != e.deviceRatio){ //因为devicePixelRatio会影响到点云大小,所以改变时计算下点云大小
  83173. viewer.scene.pointclouds.forEach(p => {
  83174. p.changePointSize()
  83175. })
  83176. }
  83177. ratio = e.deviceRatio
  83178. })
  83179. } */
  83180. {
  83181. var pointDensity = '';
  83182. Object.defineProperty(Potree.settings, "pointDensity", {
  83183. get: function get() {
  83184. return pointDensity;
  83185. },
  83186. set: density => {
  83187. if (density) {
  83188. var config = Potree.config.pointDensity[density];
  83189. var pointBudget = config.pointBudget;
  83190. if (density == 'magnifier') {
  83191. //尽可能不变pointBudget,否则点云可能会闪烁,因点云被释放又加载,如SS-t-7DUfWAUZ3V
  83192. pointBudget = Math.max(Potree.pointBudget, Potree.config.pointDensity['magnifier'].pointBudget);
  83193. } else if (this.magnifier.visible) {
  83194. //放大镜打开时要保证最低点云数量(全景模式没点)
  83195. pointBudget = Math.max(pointBudget, Potree.config.pointDensity['magnifier'].pointBudget);
  83196. }
  83197. viewer.setMinNodeSize(config.minNodeSize || Potree.config.minNodeSize);
  83198. viewer.setPointBudget(pointBudget);
  83199. pointDensity = density;
  83200. this.setPointLevels();
  83201. this.dispatchEvent('pointDensityChanged');
  83202. }
  83203. }
  83204. });
  83205. var UserPointDensity = '';
  83206. Object.defineProperty(Potree.settings, "UserPointDensity", {
  83207. get: function get() {
  83208. return UserPointDensity;
  83209. },
  83210. set: density => {
  83211. if (UserPointDensity != density) {
  83212. if (Potree.settings.displayMode == 'showPointCloud' && this.viewports.length != 4) {
  83213. //漫游模式和四屏时都有自己的pointDensity
  83214. Potree.settings.pointDensity = density;
  83215. }
  83216. UserPointDensity = density;
  83217. this.dispatchEvent('UserPointDensityChanged');
  83218. }
  83219. }
  83220. });
  83221. }
  83222. {
  83223. var cameraFar = Potree.settings.cameraFar;
  83224. Object.defineProperty(Potree.settings, "cameraFar", {
  83225. get: function get() {
  83226. return cameraFar;
  83227. },
  83228. set: far => {
  83229. if (far != cameraFar) {
  83230. if (Potree.settings.displayMode != 'showPanos' && !this.fixCamFar) {
  83231. this.mainViewport.camera.far = far;
  83232. this.mainViewport.camera.updateProjectionMatrix();
  83233. }
  83234. cameraFar = far;
  83235. }
  83236. }
  83237. });
  83238. }
  83239. /* this.reticule.addEventListener('update',(e)=>{
  83240. this.needRender = true
  83241. if(this.mapViewer && this.mapViewer.attachedToViewer)this.mapViewer.needRender = true //分屏时mapViewer也有reticule
  83242. }) */
  83243. this.reticule.addEventListener('update', e => {
  83244. this.reticule.hoverViewport && (this.reticule.hoverViewport.needRender = true);
  83245. this.lazyRenderViewports();
  83246. if (this.mapViewer && this.mapViewer.attachedToViewer && (this.mapViewer.viewports[0].needRender || this.needRender)) this.mapViewer.needRender = true; //分屏时mapViewer也有reticule
  83247. });
  83248. this.addEventListener('pointcloud_changed', e => {
  83249. if (this.screenshoting) {
  83250. this.viewports.filter(e => !e.noPointcloud).forEach(e => e.needRender = true);
  83251. } else this.lazyRenderViewports();
  83252. });
  83253. this.addEventListener('allLoaded', () => {
  83254. setTimeout(this.testPointcloudsMaxLevel.bind(this), 1000); //延迟一丢丢,等画面出现
  83255. this.scene.pointclouds.forEach(pointcloud => {
  83256. pointcloud.addEventListener('isVisible', e => {
  83257. //是否显示该点的mesh(不显示也能走)
  83258. //console.log('pointcloud isVisible', this.id, e.visible)
  83259. if (e.reason != 'displayMode' && e.reason != 'overlinePass') {
  83260. this.updateModelBound('visibleChanged');
  83261. }
  83262. this.dispatchEvent('pointcloud_changed');
  83263. });
  83264. pointcloud.material.addEventListener('material_property_changed', () => {
  83265. this.dispatchEvent('pointcloud_changed');
  83266. });
  83267. });
  83268. window.addEventListener('unfocusPage', e => {
  83269. console.log('unfocusPage', document.title);
  83270. this.setDisplay(false);
  83271. });
  83272. window.addEventListener('focusPage', e => {
  83273. console.log('focusPage', document.title);
  83274. this.setDisplay(true);
  83275. });
  83276. });
  83277. if (Potree.settings.editType != 'pano' && Potree.settings.editType != 'merge' || Potree.settings.mergeType2) {
  83278. var updated, zoomLevel;
  83279. var update = e => {
  83280. if (e.type == 'updateModelBound' || e.viewport == this.mainViewport && (e.changeInfo.positionChanged || zoomLevel != this.images360.zoomLevel)) {
  83281. zoomLevel = this.images360.zoomLevel; //对updateMarkerVisibles有影响
  83282. //e.changeInfo.positionChanged && shelterHistory.clear() //清空
  83283. (e.type == 'updateModelBound' || e.changeInfo.positionChanged) && this.updateDatasetAt(); //更新所在数据集
  83284. if (Potree.settings.ifShowMarker) {
  83285. Common.intervalTool.isWaiting('updateMarkerVisibles', () => {
  83286. if (!this.mainViewport.view.isFlying()) {
  83287. this.updateMarkerVisibles();
  83288. }
  83289. }, 500);
  83290. }
  83291. }
  83292. };
  83293. this.addEventListener('camera_changed', update);
  83294. this.addEventListener('updateModelBound', update);
  83295. this.addEventListener('showMarkerChanged', () => {
  83296. this.updatePanosVisibles(this.modules.SiteModel.currentFloor);
  83297. this.updateMarkerVisibles();
  83298. });
  83299. /* if(!Potree.Features.EXT_DEPTH.isSupported()){
  83300. this.images360.addEventListener('endChangeMode',(e)=>{
  83301. if(e.mode == 'showPanos'){
  83302. this.updateMarkerVisibles()
  83303. }
  83304. }) */
  83305. this.images360.addEventListener('getNeighbourAuto', e => {
  83306. if ( /* Potree.settings.displayMode == 'showPanos' && */e.panos.includes(this.images360.currentPano)) {
  83307. Common.intervalTool.isWaiting('updateMarkerVisibles', () => {
  83308. this.updateMarkerVisibles();
  83309. }, 500);
  83310. }
  83311. });
  83312. /* } */
  83313. }
  83314. if (Potree.settings.editType != 'pano' && Potree.settings.editType != 'merge') {
  83315. this.addEventListener('switchFloorplanSelect', e => {
  83316. //进入平面图设置后 切换选中的数据集
  83317. this.selectedFloorplan = e.pointcloud; //绝对显示
  83318. this.updateFpVisiDatasets();
  83319. var pointclouds;
  83320. if (e.pointcloud) {
  83321. pointclouds = [e.pointcloud];
  83322. } else if (this.fpVisiDatasets.length) {
  83323. pointclouds = this.fpVisiDatasets;
  83324. }
  83325. pointclouds && this.mapViewer.fitToDatasets(pointclouds);
  83326. });
  83327. this.modules.SiteModel.bus.addEventListener('FloorChange', e => {
  83328. this.updateFpVisiDatasets();
  83329. this.updatePanosVisibles(e.currentFloor); //问:编辑空间模型时,需不需要改为显示当前选择的楼层。因为若所在楼层和选中的不一致,修改选中楼层的轮廓却改不了marker显示很奇怪,尤其刚好在一个建筑内时。
  83330. });
  83331. this.mapViewer.mapLayer.addEventListener('floorplanLoaded', () => {
  83332. this.updateCadVisibles(this.fpVisiDatasets, true); //加载完成后重新更新下
  83333. });
  83334. /* this.modules.Clip.bus.addEventListener('updateSelectedDatasets',()=>{
  83335. this.updateFpVisiDatasets()
  83336. }) */
  83337. }
  83338. {
  83339. var interval;
  83340. document.addEventListener('visibilitychange', e => {
  83341. var v = !document.hidden;
  83342. //console.warn('visibilitychange', v )
  83343. this.dispatchEvent({
  83344. type: 'pageVisible',
  83345. v
  83346. });
  83347. if (this.screenshoting && !v) {
  83348. //截图过程中离开页面需要照常loop。但是尽量别离开页面,效果只能达到90%
  83349. interval = setInterval(() => {
  83350. //console.log('force loop', Date.now())
  83351. if (this.screenshoting) {
  83352. //截图完成时如果还没回来就不loop
  83353. this.loop(Date.now());
  83354. }
  83355. }, 50); //实际>1000, 浏览器会放慢定时器,放慢多少不确定
  83356. } else if (v && interval) {
  83357. clearInterval(interval);
  83358. }
  83359. });
  83360. }
  83361. /* if(!Potree.isIframeChild){
  83362. window.winIndex = 0;
  83363. let index = 1;
  83364. this.addEventListener('createIframe',(e)=>{//创建了子页面
  83365. let child = e.window;
  83366. child.winIndex = index ++;
  83367. })
  83368. //不知道删除iframe时是否那些模型还在内存里,需要释放吗? 如果要需要加一个事件
  83369. } */
  83370. /* {
  83371. let setInteract = ()=>{
  83372. this.interacted = true //标记这一帧用户有操作屏幕
  83373. }
  83374. this.addEventListener('global_mousedown', setInteract)
  83375. this.addEventListener('global_touchmove', setInteract)
  83376. this.addEventListener('global_mousewheel', setInteract)
  83377. }
  83378. {//针对数据集偏离中心很远后产生的精度损失而抖动
  83379. this.addEventListener('camera_changed', e => {
  83380. if(e.viewport == this.mainViewport && (e.changeInfo.positionChanged)){
  83381. if(Potree.settings.editType != 'merge' && Potree.settings.editType != 'pano'){
  83382. if(!this.mainViewport.view.isFlying() ){
  83383. let pos = this.mainViewport.view.position.clone() // this.mainViewport.camera.getWorldPosition(new THREE.Vector3)
  83384. if(pos.lengthSq() > 25000000){
  83385. Common.intervalTool.isWaiting('moveWorldCenter', ()=>{
  83386. pos = this.mainViewport.view.position.clone()
  83387. this.mainViewport.view.translateWorld(-pos.x, -pos.y, -pos.z)
  83388. this.scene.scene.position.sub(pos)
  83389. console.log('变位置', pos)
  83390. this.scene.pointclouds.forEach(cloud=>{
  83391. Alignment.setMatrix(cloud)
  83392. })
  83393. },500)
  83394. }
  83395. }
  83396. }
  83397. }
  83398. })
  83399. }*/
  83400. }
  83401. lazyRenderViewports(updateCount) {
  83402. //本来要写this.needRender = true的, 但在分四个屏时防止太卡而排队render
  83403. var viewports = this.viewports;
  83404. if (viewports.length == 1 || this.needRender) {
  83405. return this.needRender = true;
  83406. }
  83407. var maxWaitTime = 200;
  83408. var now = Date.now();
  83409. var maxRenderCount = 1;
  83410. viewports.forEach(e => {
  83411. if (now - e.lastRenderTime > maxWaitTime) {
  83412. e.needRender = true;
  83413. }
  83414. });
  83415. var renderCount = viewports.filter(e => e.needRender).length;
  83416. //console.log('renderCount', renderCount)
  83417. var list = viewports.filter(e => !e.needRender).sort((a, b) => a.lastRenderTime - b.lastRenderTime); //没有准备render的,按上次渲染时间排序,作为候补
  83418. if (renderCount < maxRenderCount) {
  83419. //还有名额,补齐
  83420. list.slice(0, maxRenderCount - renderCount).forEach(e => {
  83421. e.needRender = true;
  83422. });
  83423. } else if (list[0] && now - list[0].lastRenderTime > maxWaitTime) {
  83424. //名额不足时,考虑候补队列第一个是否超时,超时的话也渲染
  83425. list[0].needRender = true;
  83426. }
  83427. }
  83428. ifPointBlockedByIntersect(point, panoId, soon) {
  83429. //点是否被遮挡
  83430. var ifShelter;
  83431. var now = Date.now();
  83432. var extraPanoId = panoId != void 0;
  83433. if (!this.shelterCount) return;
  83434. var history = shelterHistory.find(e => e.point.equals(point));
  83435. var cameraPos = this.mainViewport.view.position.clone();
  83436. if (panoId == void 0) {
  83437. if (this.images360.isAtPano(0.05)) {
  83438. panoId = this.images360.currentPano.id;
  83439. }
  83440. }
  83441. if (history) {
  83442. if (panoId != void 0) {
  83443. ifShelter = history.panos[panoId];
  83444. } else {
  83445. if (history.notAtPano.cameraPos && history.notAtPano.cameraPos.equals(cameraPos)) {
  83446. ifShelter = history.notAtPano.ifShelter;
  83447. }
  83448. }
  83449. var index = shelterHistory.indexOf(history); //先取出,稍后放回
  83450. shelterHistory.splice(index, 1);
  83451. } else {
  83452. //新增
  83453. history = {
  83454. point,
  83455. panos: {},
  83456. notAtPano: {}
  83457. };
  83458. var minCount = 100;
  83459. if (shelterHistory.length > minCount) {
  83460. //去除最早的
  83461. var old;
  83462. while (old = shelterHistory[0], now - old.lastTime > 1000) {
  83463. //因为不知热点个数,所以需要加上时间限制,超过时间才能删。
  83464. if (old == history || shelterHistory.length == minCount) break;
  83465. shelterHistory.splice(0, 1);
  83466. //console.log('delete')
  83467. }
  83468. }
  83469. }
  83470. if (ifShelter == void 0) {
  83471. delete history.waitCompute;
  83472. if (this.mainViewport.view.isFlying()) {
  83473. return useLastResult();
  83474. }
  83475. if (panoId != void 0) {
  83476. var pano = this.images360.getPano(panoId);
  83477. if ((soon || this.shelterCount.byTex < this.shelterCount.maxByTex) && pano.depthTex) {
  83478. ifShelter = !!viewer.inputHandler.ifBlockedByIntersect({
  83479. point,
  83480. margin: Potree.config.shelterMargin,
  83481. useDepthTex: true,
  83482. pano,
  83483. viewport: this.mainViewport
  83484. });
  83485. history.panos[panoId] = ifShelter;
  83486. this.shelterCount.byTex++;
  83487. //console.log('computeByTex direct', panoId, point, ifShelter)
  83488. } else {
  83489. //console.log('延迟tex',panoId, point )
  83490. history.waitCompute = {
  83491. panoId,
  83492. forceGet: extraPanoId
  83493. };
  83494. return useLastResult();
  83495. }
  83496. } else {
  83497. if ( /* history.ifShelter == void 0 || */this.shelterCount.byCloud < this.shelterCount.maxByCloud) {
  83498. //弊端:第一个总是直接计算,后面的都是延后。但无法改进,因是一个个传进来的,无法预测。
  83499. ifShelter = !!viewer.inputHandler.ifBlockedByIntersect({
  83500. point,
  83501. margin: Potree.config.shelterMargin,
  83502. pickWindowSize: 3
  83503. });
  83504. history.notAtPano = {
  83505. cameraPos,
  83506. ifShelter
  83507. };
  83508. this.shelterCount.byCloud++;
  83509. //console.log('computeByCloud direct', point.toArray())
  83510. } else {
  83511. //console.log('延迟cloud' )
  83512. history.waitCompute = {
  83513. cameraPos
  83514. };
  83515. return useLastResult();
  83516. }
  83517. }
  83518. }
  83519. history.ifShelter = ifShelter;
  83520. history.lastTime = now;
  83521. shelterHistory.push(history); //最新使用的保持在最后一个,使队列按照从旧到新排列
  83522. function useLastResult() {
  83523. //暂时先用上一次的值
  83524. shelterHistory.push(history);
  83525. history.lastTime = now;
  83526. return history.ifShelter;
  83527. }
  83528. return ifShelter;
  83529. }
  83530. computeShelter() {
  83531. //先算用深度图的,然后再点云;
  83532. //let depthTiming = Potree.timeCollect.depthSampler.median
  83533. var byTex = 0,
  83534. byCloud = 0;
  83535. var len = shelterHistory.length;
  83536. var waitCloud = [];
  83537. var maxTexCount = Common.getBestCount('shelterMaxDepthSample', 1, 50, 1, 13 /* ,true */);
  83538. for (var i = len - 1; i >= 0; i--) {
  83539. var history = shelterHistory[i];
  83540. if (history.waitCompute) {
  83541. if (history.waitCompute.panoId != void 0) {
  83542. if (!history.waitCompute.forceGet && (history.waitCompute.panoId != this.images360.currentPano.id || !this.images360.isAtPano(0.1))) {
  83543. delete history.waitCompute; //取消计算
  83544. } else {
  83545. if (this.images360.currentPano.depthTex) {
  83546. if (byTex >= maxTexCount) break;
  83547. byTex++;
  83548. var ifShelter = !!viewer.inputHandler.ifBlockedByIntersect({
  83549. point: history.point,
  83550. margin: Potree.config.shelterMargin,
  83551. useDepthTex: true,
  83552. viewport: this.mainViewport
  83553. });
  83554. history.panos[this.images360.currentPano.id] = ifShelter;
  83555. history.ifShelter = ifShelter;
  83556. delete history.waitCompute;
  83557. //console.log('补1', history.point.toArray())
  83558. } else {
  83559. if (this.images360.currentPano.pointcloud.hasDepthTex) {
  83560. //先等待加载完深度图
  83561. } else {
  83562. waitCloud.push(history);
  83563. }
  83564. }
  83565. }
  83566. } else {
  83567. waitCloud.push(history);
  83568. }
  83569. }
  83570. }
  83571. var maxCloudCount;
  83572. if (byTex < maxTexCount && waitCloud.length) {
  83573. maxCloudCount = this.lastFrameChanged ? Common.getBestCount('shelterMaxCloud', 0, 2, 4, 8 /* ,true */) : 5;
  83574. var waitCloud2 = [];
  83575. if (maxCloudCount) {
  83576. for (var _i2 = 0; _i2 < waitCloud.length; _i2++) {
  83577. var _history = waitCloud[_i2];
  83578. if (_history.waitCompute.cameraPos) {
  83579. if (!viewer.mainViewport.view.position.equals(_history.waitCompute.cameraPos)) {
  83580. delete _history.waitCompute;
  83581. //console.log('delete history.waitCompute', history)
  83582. continue; //取消计算
  83583. } else {
  83584. waitCloud2.push(_history);
  83585. }
  83586. } else {
  83587. waitCloud2.push(_history);
  83588. }
  83589. }
  83590. var list = waitCloud2.map(e => e.point);
  83591. var result = Common.batchHandling.getSlice('shelterByCloud', list, {
  83592. maxUseCount: maxCloudCount,
  83593. useEquals: true,
  83594. stopWhenAllUsed: true
  83595. }); //iphonex稳定后大概在7-10。
  83596. //list.length>0 && console.log('list',list, maxCloudCount)
  83597. result.list.forEach(e => {
  83598. var history = waitCloud2.find(a => a.point.equals(e));
  83599. var ifShelter = !!viewer.inputHandler.ifBlockedByIntersect({
  83600. point: history.point,
  83601. margin: Potree.config.shelterMargin,
  83602. pickWindowSize: 3,
  83603. viewport: this.mainViewport
  83604. });
  83605. if (history.waitCompute.cameraPos) {
  83606. history.notAtPano = {
  83607. cameraPos: history.waitCompute.cameraPos,
  83608. ifShelter
  83609. };
  83610. } else {
  83611. history.panos[this.images360.currentPano.id] = ifShelter;
  83612. }
  83613. history.ifShelter = ifShelter;
  83614. byCloud++;
  83615. //console.log('补2', history.point.toArray())
  83616. delete history.waitCompute;
  83617. });
  83618. }
  83619. }
  83620. if (byTex || byCloud) {
  83621. //console.log('shelterComputed',byTex,byCloud, maxTexCount, maxCloudCount)
  83622. Common.intervalTool.isWaiting('shelterComputed', () => {
  83623. //console.log('shelterComputed update')
  83624. this.dispatchEvent('shelterComputed');
  83625. }, 340);
  83626. }
  83627. }
  83628. updateDatasetAt(force) {
  83629. //更新所在数据集
  83630. var fun = () => {
  83631. var currPos = viewer.mainViewport.view.position;
  83632. //if(force || !currPos.equals(this.lastPos)){
  83633. //this.lastPos.copy(currPos)
  83634. var at = this.scene.pointclouds.filter(e => (e.visible || e.unvisibleReasons && e.unvisibleReasons.length == 1 && e.unvisibleReasons[0].reason == 'displayMode') && e.ifContainsPoint(currPos));
  83635. if (Common.getDifferenceSet(at, this.atDatasets).length) {
  83636. //console.log('atDatasets', at)
  83637. this.atDatasets = at;
  83638. if (Potree.settings.editType != 'pano' && Potree.settings.editType != 'merge') {
  83639. this.updateFpVisiDatasets();
  83640. if (!viewer.modules.SiteModel.currentFloor) {
  83641. this.updatePanosVisibles(); //所在数据集的点位显示
  83642. }
  83643. }
  83644. this.dispatchEvent({
  83645. type: 'pointcloudAtChange',
  83646. pointclouds: at
  83647. });
  83648. }
  83649. force = false;
  83650. };
  83651. //}
  83652. if (force) fun();else Common.intervalTool.isWaiting('atWhichDataset', fun, 300);
  83653. }
  83654. updatePanosVisibles(currentFloor) {
  83655. //显示当前楼层的所有panos
  83656. if (!Potree.settings.ifShowMarker) return;
  83657. var inEntity = currentFloor;
  83658. //console.error('updatePanosVisibles', currentFloor)
  83659. viewer.images360.panos.forEach(pano => {
  83660. var visible = inEntity ? inEntity.panos.includes(pano) : this.atDatasets.some(e => e.panos.includes(pano));
  83661. Potree.Utils.updateVisible(pano, 'buildingChange', visible, 2);
  83662. });
  83663. this.dispatchEvent('content_changed');
  83664. } //注:非official的没有获取sitemodel的信息所以不执行楼层判断,marker显示不对是正常的
  83665. /* 2023.11.24 针对部分场景的楼层很矮,很容易就到楼层外了,且不能修改楼高。如SG-t-9NdCpxrUPLL#/,采取如下措施:
  83666. 1 如果不在任何一楼层,但在某个数据集中,就显示该数据集所有的marker
  83667. 2 如果当前楼层无,则显示上一次的currentFloor的marker
  83668. (目前先使用方案1)
  83669. */
  83670. updateMarkerVisibles() {
  83671. //限制显示的marker个数,因镜头内marker多的时候可能会卡
  83672. if (!Potree.settings.ifShowMarker) return;
  83673. var minRadius = 8 * this.images360.zoomLevel,
  83674. //当视线垂直于marker时的最小可见距离,此范围内可见的pano绝对可见
  83675. maxRadius = 50 * this.images360.zoomLevel,
  83676. //当视线垂直于marker时的最大可见距离,此范围外绝对不可见
  83677. hopeCount = browser.isMobile() ? 8 : 15; //期望达到的真实可见的marker数
  83678. var sheltered = pano => {
  83679. if ( /* Potree.settings.displayMode == 'showPanos' && !Potree.Features.EXT_DEPTH.isSupported() && */this.images360.isAtPano() && !this.mainViewport.view.isFlying()) {
  83680. return !this.images360.currentPano.neighbours.includes(pano) && this.images360.currentPano != pano; //起初因不支持EXT_DEPTH时无法用depthTex遮住marker, 后为了减少绘制,都判断
  83681. }
  83682. };
  83683. var panoMap = new Map(); //先记录想要设置为可见的
  83684. var set = () => {
  83685. //最后确定设置
  83686. var count = 0;
  83687. viewer.images360.panos.forEach(pano => {
  83688. var v = panoMap.get(pano).visible;
  83689. v && count++;
  83690. Potree.Utils.updateVisible(pano.marker, 'limitMarkerShow', v);
  83691. });
  83692. //console.log('updateMarkerVisibles marker显示个数', count)
  83693. this.dispatchEvent('content_changed');
  83694. };
  83695. var isWithinDis = (pano, maxDis) => {
  83696. //是否marker到相机的距离 没有超出可视距离。可视距离考虑上倾斜角,倾斜越大可视距离越短
  83697. var camPos = viewer.mainViewport.camera.position;
  83698. var o = panoMap.get(pano);
  83699. o.dis = o.dis || camPos.distanceTo(pano.marker.position);
  83700. o.sin = o.sin || Math.sqrt(Math.abs(camPos.z - pano.marker.position.z) / o.dis); //和地面夹角的sin。 按公式是不加Math.sqrt的,但是这样大马路上在贴近地面时算出的个数非常少,所以增大点……
  83701. return o.dis < maxDis * o.sin;
  83702. };
  83703. viewer.images360.panos.forEach(pano => {
  83704. //minRadius内的记录为可见
  83705. var o = {};
  83706. panoMap.set(pano, o);
  83707. if (pano.visible && !sheltered(pano) && isWithinDis(pano, minRadius)) {
  83708. o.visible = true;
  83709. }
  83710. });
  83711. //不超过hopeCount的话,可以直接确定设置
  83712. if (viewer.images360.panos.filter(pano => panoMap.get(pano).visible).length >= hopeCount) return set();
  83713. //距离超过maxRadius就绝对不可见
  83714. var insideOutCirle = viewer.images360.panos.filter(pano => pano.visible && !sheltered(pano) && isWithinDis(pano, maxRadius));
  83715. if (insideOutCirle.length <= hopeCount) {
  83716. insideOutCirle.forEach(pano => panoMap.get(pano).visible = true);
  83717. return set();
  83718. }
  83719. //数量超过hopeCount时,根据距离排序
  83720. insideOutCirle.sort((a, b) => {
  83721. return panoMap.get(a).dis - panoMap.get(b).dis;
  83722. });
  83723. var slice = insideOutCirle.slice(0, hopeCount);
  83724. slice.forEach(pano => panoMap.get(pano).visible = true);
  83725. set();
  83726. }
  83727. updateFpVisiDatasets() {
  83728. var Clip = this.modules.Clip;
  83729. var SiteModel = this.modules.SiteModel;
  83730. var Alignment = this.modules.Alignment;
  83731. var currentFloor = SiteModel.currentFloor;
  83732. /* if(Clip.editing){//下载页面已经改为和普通时一样,根据位置判断
  83733. this.updateCadVisibles(Clip.selectedDatasets)
  83734. }else */
  83735. if (this.selectedFloorplan) {
  83736. //平面图设置中 或 地理设置
  83737. var pointclouds = [this.selectedFloorplan];
  83738. this.updateCadVisibles(pointclouds);
  83739. } else if (SiteModel.editing || Alignment.editing) {
  83740. //只显示勾选的,也就是显示的点云的
  83741. var _pointclouds = this.scene.pointclouds.filter(p => Potree.Utils.getObjVisiByReason(p, 'datasetSelection'));
  83742. this.updateCadVisibles(_pointclouds);
  83743. //this.updatePanosVisibles(currentFloor/* , pointclouds */)
  83744. } else {
  83745. var _pointclouds2 = currentFloor ? this.findPointcloudsAtFloor(currentFloor) : [];
  83746. if (_pointclouds2.length == 0) {
  83747. if (this.focusDatasets) {
  83748. _pointclouds2 = this.focusDatasets;
  83749. }
  83750. }
  83751. if (_pointclouds2.length == 0) {
  83752. //如果当前不在任何楼层或楼层中无数据集,就用当前所在数据集
  83753. _pointclouds2 = this.atDatasets;
  83754. }
  83755. this.updateCadVisibles(_pointclouds2);
  83756. //this.updatePanosVisibles(currentFloor/* , pointclouds */)
  83757. }
  83758. }
  83759. /* findPointcloudsAtFloor(entity){//找当前楼层需要显示哪些数据集。
  83760. //数据集的belongToEntity 在这个entity内(否则会出现点击数据集飞过去平面图却不显示)。or 如果数据集有漫游点的话,需要包含>20%的漫游点。 (防止重叠体积很大但其实一个漫游点都不包含)
  83761. //重叠体积>50% 或 包含>50%的漫游点
  83762. const ratio1 = 0.2, ratio2 = 0.5, ratio3 = 0.95
  83763. var lowScores = []
  83764. var pointclouds = viewer.scene.pointclouds.filter(e=>{
  83765. let score = 0
  83766. if(e.belongToEntity && (e.belongToEntity == entity || e.belongToEntity.buildParent == entity)){//条件1 若该数据集挂载到该楼层 或 该数据集挂载到的房间属于该楼层(这样能显示该层所有房间)
  83767. return true
  83768. }
  83769. if(e.panos.length){//条件2
  83770. var insidePanos = e.panos.filter(a=>entity.ifContainsPoint(a.position));
  83771. let panoCountRatio = insidePanos.length / e.panos.length
  83772. if(panoCountRatio > ratio2)return true
  83773. score += panoCountRatio
  83774. }
  83775. //条件3
  83776. let volume = entity.intersectPointcloudVolume(e);
  83777. let volumeRatio = volume / entity.getVolume(true) //注:hole加入计算
  83778. if(volumeRatio > ratio3){ //ratio3要高一些,因为点云bounding可能很大,包含很多无点云的空间。即使整个数据集包含entity都不一定看起来在数据集中。(千万要防止两层楼都显示了)
  83779. return true
  83780. }else{
  83781. score += volumeRatio
  83782. }
  83783. lowScores.push({score, pointcloud:e})
  83784. })
  83785. if(pointclouds.length == 0){//从低分项挑一个出来。
  83786. lowScores.sort((a,b)=>{return a.score - b.score})
  83787. if(lowScores[0].score > 0.4){
  83788. pointclouds = [lowScores[0].pointcloud]
  83789. }
  83790. }
  83791. return pointclouds
  83792. } */
  83793. findPointcloudsAtFloor(entity) {
  83794. //找当前楼层需要显示哪些数据集。
  83795. //数据集的belongToEntity 在这个entity内(否则会出现点击数据集飞过去平面图却不显示)。or 如果数据集有漫游点的话,需要包含>20%的漫游点。 (防止重叠体积很大但其实一个漫游点都不包含)
  83796. //重叠体积>50% 或 包含>50%的漫游点
  83797. var ratio1 = 0.2,
  83798. ratio2 = 0.5,
  83799. ratio3 = 0.95;
  83800. var lowScores = [];
  83801. var pointclouds = viewer.scene.pointclouds.filter(e => {
  83802. var score = 0;
  83803. if (e.belongToEntity && (e.belongToEntity == entity || e.belongToEntity.buildParent == entity)) {
  83804. //条件1 若该数据集挂载到该楼层 或 该数据集挂载到的房间属于该楼层(这样能显示该层所有房间)
  83805. return true;
  83806. }
  83807. if (e.panos.length) {
  83808. //条件2
  83809. var insidePanos = e.panos.filter(a => entity.ifContainsPoint(a.position));
  83810. var panoCountRatio = insidePanos.length / e.panos.length;
  83811. if (panoCountRatio > ratio2) return true;
  83812. score += panoCountRatio * 2;
  83813. }
  83814. //条件3
  83815. var coverHeightRatio = entity.coverPointcloudHeight(e, true); //重叠高度占楼层高度的比率。
  83816. if (coverHeightRatio < 0.2) return;
  83817. var {
  83818. toEntity,
  83819. toPointcloud
  83820. } = entity.intersectPointcloudArea(e, true); //重叠面积占比
  83821. var coverAreaRatio = Math.max(toEntity, toPointcloud); //占数据集俯视面积的比率 和 占楼层的面积比率,挑一个大的。 (有的数据集被划分多个楼层,所以每层都应该显示该数据集的图。还有的数据集比较大,可能包含多个建筑,则看占楼层面积)
  83822. if (coverAreaRatio < 0.2) return;
  83823. score += coverAreaRatio * coverHeightRatio;
  83824. lowScores.push({
  83825. score,
  83826. pointcloud: e
  83827. });
  83828. });
  83829. /* if(pointclouds.length == 0){//从低分项挑一个出来。
  83830. lowScores.sort((a,b)=>{return a.score - b.score})
  83831. if(lowScores[0].score > 0.4){
  83832. pointclouds = [lowScores[0].pointcloud]
  83833. }
  83834. } */
  83835. lowScores.forEach(e => {
  83836. //一个楼层里可以包含许多个数据集 调试SG-t-ds27ym7xzjJ
  83837. if (e.score > 0.5) {
  83838. pointclouds.push(e.pointcloud);
  83839. }
  83840. });
  83841. return pointclouds;
  83842. }
  83843. updateCadVisibles(visiClouds, force) {
  83844. //console.log('visiClouds',visiClouds)
  83845. var oldVisi = this.fpVisiDatasets;
  83846. var visiClouds = this.fpVisiDatasets = visiClouds;
  83847. if (!force) {
  83848. var difference = Common.getDifferenceSet(oldVisi, visiClouds);
  83849. if (difference.length == 0) return;
  83850. }
  83851. //console.log('visiClouds',visiClouds.map(e=>e.name))
  83852. viewer.scene.pointclouds.forEach(pointcloud => {
  83853. var floorplan = viewer.mapViewer.mapLayer.getFloorplan(pointcloud.dataset_id);
  83854. var visi = visiClouds.includes(pointcloud);
  83855. if (floorplan) {
  83856. Potree.Utils.updateVisible(floorplan.objectGroup, 'buildingChange', visi);
  83857. } /* else if(!visi){
  83858. let changeVisi = (e)=>{
  83859. Potree.Utils.updateVisible(e.floorplan.objectGroup, 'buildingChange', this.fpVisiDatasets.includes(pointcloud))
  83860. viewer.mapViewer.mapLayer.removeEventListener('floorplanLoaded', changeVisi)
  83861. console.log('updateCadVisibles加载后更改显示',e)
  83862. }
  83863. viewer.mapViewer.mapLayer.addEventListener('floorplanLoaded', changeVisi)
  83864. } */
  83865. //已经添加了全局的 floorplanLoaded后会updateCadVisibles,这段就删了
  83866. });
  83867. viewer.mapViewer.mapLayer.needUpdate = true; //可能需要更新加载的level程度
  83868. viewer.mapViewer.needRender = true; //若上句不触发加载也要立即重新绘制
  83869. }
  83870. //促使点云加载出最高级别
  83871. testPointcloudsMaxLevel() {
  83872. var _this = this;
  83873. //所有点云都无需testMaxNodeLevel 就停止
  83874. var camera_changed,
  83875. count = 0;
  83876. var _test = function test() {
  83877. var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  83878. camera_changed = true;
  83879. var camera = e.camera || _this.scene.getActiveCamera();
  83880. Common.intervalTool.isWaiting('testPointcloudsMaxLevel', () => {
  83881. if (!camera_changed && count > 50 || Potree.settings.displayMode == 'showPanos' || _this.pauseTestMaxLevel) return; //只有当camera_changed后才继续循环, 除了最开始几次需要连续加载下
  83882. camera_changed = false;
  83883. count++;
  83884. //console.log('testPointcloudsMaxLevel中', camera.type /* count */)
  83885. var oldCount = _this.testMaxNodeCount;
  83886. var success = true;
  83887. viewer.scene.pointclouds.forEach(e => {
  83888. var wait = e.testMaxNodeLevel(camera);
  83889. if (wait) {
  83890. success = false;
  83891. }
  83892. });
  83893. /* if(oldCount<=Potree.config.testNodeCount1 && this.testMaxNodeCount>Potree.config.testNodeCount1 ){//差不多等当前所在数据集nodeMaxLevel加载出来
  83894. viewer.scene.pointclouds.forEach(e=>{e.changePointSize()}) //重新更新一下大小。因之前用的是nodeMaxLevelPredict (防止刚开始因nodeMaxLevel没涨完,导致过大的点云突然出现
  83895. } */
  83896. if (!success) return true; //没有全部加载完,继续循环
  83897. else {
  83898. _this.removeEventListener('camera_changed', _test);
  83899. console.log('testPointcloudsMaxLevel结束');
  83900. }
  83901. }, count < 10 ? 250 : 500);
  83902. };
  83903. this.addEventListener('camera_changed', _test);
  83904. _test();
  83905. /* 检验:
  83906. viewer.scene.pointclouds.sort((a,b)=>a.nodeMaxLevelPredict.min - b.nodeMaxLevelPredict.min).forEach(e=>console.log(e.nodeMaxLevel, e.nodeMaxLevelPredict.min))
  83907. */
  83908. }
  83909. setPointLevels() {
  83910. this.scene.pointclouds.forEach(e => {
  83911. e.setPointLevel();
  83912. });
  83913. }
  83914. onCrash(error) {
  83915. console.error(error);
  83916. $(this.renderArea).empty();
  83917. if ($(this.renderArea).find('#potree_failpage').length === 0) {
  83918. var elFailPage = $("\n\t\t\t<div id=\"#potree_failpage\" class=\"potree_failpage\"> \n\t\t\t\t\n\t\t\t\t<h1>Potree Encountered An Error </h1>\n\n\t\t\t\t<p>\n\t\t\t\tThis may happen if your browser or graphics card is not supported.\n\t\t\t\t<br>\n\t\t\t\tWe recommend to use \n\t\t\t\t<a href=\"https://www.google.com/chrome/browser\" target=\"_blank\" style=\"color:initial\">Chrome</a>\n\t\t\t\tor \n\t\t\t\t<a href=\"https://www.mozilla.org/\" target=\"_blank\">Firefox</a>.\n\t\t\t\t</p>\n\n\t\t\t\t<p>\n\t\t\t\tPlease also visit <a href=\"http://webglreport.com/\" target=\"_blank\">webglreport.com</a> and \n\t\t\t\tcheck whether your system supports WebGL.\n\t\t\t\t</p>\n\t\t\t\t<p>\n\t\t\t\tIf you are already using one of the recommended browsers and WebGL is enabled, \n\t\t\t\tconsider filing an issue report at <a href=\"https://github.com/potree/potree/issues\" target=\"_blank\">github</a>,<br>\n\t\t\t\tincluding your operating system, graphics card, browser and browser version, as well as the \n\t\t\t\terror message below.<br>\n\t\t\t\tPlease do not report errors on unsupported browsers.\n\t\t\t\t</p>\n\n\t\t\t\t<pre id=\"potree_error_console\" style=\"width: 100%; height: 100%\"></pre>\n\t\t\t\t\n\t\t\t</div>");
  83919. var elErrorMessage = elFailPage.find('#potree_error_console');
  83920. elErrorMessage.html(error.stack);
  83921. $(this.renderArea).append(elFailPage);
  83922. }
  83923. throw error;
  83924. }
  83925. // ------------------------------------------------------------------------------------
  83926. // Viewer API
  83927. // ------------------------------------------------------------------------------------
  83928. setScene(scene) {
  83929. if (scene === this.scene) {
  83930. return;
  83931. }
  83932. var oldScene = this.scene;
  83933. this.scene = scene;
  83934. this.dispatchEvent({
  83935. type: 'scene_changed',
  83936. oldScene: oldScene,
  83937. scene: scene
  83938. });
  83939. {
  83940. // Annotations
  83941. $('.annotation').detach();
  83942. // for(let annotation of this.scene.annotations){
  83943. // this.renderArea.appendChild(annotation.domElement[0]);
  83944. // }
  83945. this.scene.annotations.traverse(annotation => {
  83946. this.renderArea.appendChild(annotation.domElement[0]);
  83947. });
  83948. if (!this.onAnnotationAdded) {
  83949. this.onAnnotationAdded = e => {
  83950. // console.log("annotation added: " + e.annotation.title);
  83951. e.annotation.traverse(node => {
  83952. $("#potree_annotation_container").append(node.domElement);
  83953. //this.renderArea.appendChild(node.domElement[0]);
  83954. node.scene = this.scene;
  83955. });
  83956. };
  83957. }
  83958. if (oldScene) {
  83959. oldScene.annotations.removeEventListener('annotation_added', this.onAnnotationAdded);
  83960. }
  83961. this.scene.annotations.addEventListener('annotation_added', this.onAnnotationAdded);
  83962. }
  83963. }
  83964. setControls(controls /* , setSpeed */) {
  83965. if (controls !== this.controls) {
  83966. if (this.controls) {
  83967. this.controls.setEnable(false);
  83968. //this.inputHandler.removeInputListener(this.controls);
  83969. this.controls.moveSpeed = this.moveSpeed; //记录 (因为orbit的radius很大,转为firstPerson时要缩小)
  83970. }
  83971. this.controls = controls;
  83972. controls.moveSpeed && this.setMoveSpeed(controls.moveSpeed); //add
  83973. this.controls.setEnable(true);
  83974. //this.inputHandler.addInputListener(this.controls);
  83975. }
  83976. }
  83977. getControls() {
  83978. if (this.renderer.xr.isPresenting) {
  83979. return this.vrControls;
  83980. } else {
  83981. return this.controls;
  83982. }
  83983. }
  83984. getMinNodeSize() {
  83985. return this.minNodeSize;
  83986. }
  83987. setMinNodeSize(value) {
  83988. if (this.minNodeSize !== value) {
  83989. this.minNodeSize = value;
  83990. this.dispatchEvent({
  83991. 'type': 'minnodesize_changed',
  83992. 'viewer': this
  83993. });
  83994. }
  83995. }
  83996. getBackground() {
  83997. return this.background;
  83998. }
  83999. setBackground(bg, src) {
  84000. /* if (this.background === bg ) {
  84001. return;
  84002. } */
  84003. if (bg === "skybox") {
  84004. if (!src) src = Potree.resourcePath + '/textures/skybox/xingkong.jpg';
  84005. this.skybox = Utils.loadSkybox(src, this.skybox, () => {
  84006. this.background = bg;
  84007. });
  84008. } else {
  84009. this.background = bg;
  84010. }
  84011. this.backgroundOpacity = 1; //add
  84012. this.dispatchEvent({
  84013. 'type': 'background_changed',
  84014. 'viewer': this
  84015. });
  84016. }
  84017. setDescription(value) {
  84018. this.description = value;
  84019. $('#potree_description').html(value);
  84020. //$('#potree_description').text(value);
  84021. }
  84022. getDescription() {
  84023. return this.description;
  84024. }
  84025. setShowBoundingBox(value) {
  84026. if (this.showBoundingBox !== value) {
  84027. this.showBoundingBox = value;
  84028. this.dispatchEvent({
  84029. 'type': 'show_boundingbox_changed',
  84030. 'viewer': this
  84031. });
  84032. }
  84033. }
  84034. getShowBoundingBox() {
  84035. return this.showBoundingBox;
  84036. }
  84037. setMoveSpeed(value) {
  84038. if (this.getMoveSpeed() !== value) {
  84039. this.mainViewport.setMoveSpeed(value);
  84040. this.dispatchEvent({
  84041. 'type': 'move_speed_changed',
  84042. 'viewer': this,
  84043. 'speed': value
  84044. });
  84045. }
  84046. }
  84047. getMoveSpeed() {
  84048. return this.mainViewport.moveSpeed;
  84049. }
  84050. setWeightClassification(w) {
  84051. for (var i = 0; i < this.scene.pointclouds.length; i++) {
  84052. this.scene.pointclouds[i].material.weightClassification = w;
  84053. this.dispatchEvent({
  84054. 'type': 'attribute_weights_changed' + i,
  84055. 'viewer': this
  84056. });
  84057. }
  84058. }
  84059. setFreeze(value) {
  84060. value = Boolean(value);
  84061. if (this.freeze !== value) {
  84062. this.freeze = value;
  84063. this.dispatchEvent({
  84064. 'type': 'freeze_changed',
  84065. 'viewer': this
  84066. });
  84067. }
  84068. }
  84069. getFreeze() {
  84070. return this.freeze;
  84071. }
  84072. setElevationGradientRepeat(value) {
  84073. if (this.elevationGradientRepeat !== value) {
  84074. this.elevationGradientRepeat = value;
  84075. this.dispatchEvent({
  84076. type: "elevation_gradient_repeat_changed",
  84077. viewer: this
  84078. });
  84079. }
  84080. }
  84081. setPointBudget(value) {
  84082. //pointBudget: 每次刷新显示点数量的最大值。 缓存中的点数量也跟此有关,但大于这个数值。
  84083. if (Potree.pointBudget !== value && value) {
  84084. Potree.pointBudget = parseInt(value);
  84085. this.dispatchEvent({
  84086. 'type': 'point_budget_changed',
  84087. 'viewer': this
  84088. });
  84089. }
  84090. }
  84091. getPointBudget() {
  84092. return Potree.pointBudget;
  84093. }
  84094. setShowAnnotations(value) {
  84095. if (this.showAnnotations !== value) {
  84096. this.showAnnotations = value;
  84097. this.dispatchEvent({
  84098. 'type': 'show_annotations_changed',
  84099. 'viewer': this
  84100. });
  84101. }
  84102. }
  84103. getShowAnnotations() {
  84104. return this.showAnnotations;
  84105. }
  84106. setDEMCollisionsEnabled(value) {
  84107. if (this.useDEMCollisions !== value) {
  84108. this.useDEMCollisions = value;
  84109. this.dispatchEvent({
  84110. 'type': 'use_demcollisions_changed',
  84111. 'viewer': this
  84112. });
  84113. }
  84114. ;
  84115. }
  84116. getDEMCollisionsEnabled() {
  84117. return this.useDEMCollisions;
  84118. }
  84119. setEDLEnabled(value) {
  84120. value = Boolean(value) && Features.SHADER_EDL.isSupported();
  84121. if (this.useEDL !== value) {
  84122. this.useEDL = value;
  84123. this.dispatchEvent({
  84124. 'type': 'use_edl_changed',
  84125. 'viewer': this
  84126. });
  84127. this.dispatchEvent('pointcloud_changed');
  84128. }
  84129. }
  84130. getEDLEnabled() {
  84131. return this.useEDL;
  84132. }
  84133. setEDLRadius(value) {
  84134. if (this.edlRadius !== value) {
  84135. this.edlRadius = value;
  84136. this.dispatchEvent({
  84137. 'type': 'edl_radius_changed',
  84138. 'viewer': this
  84139. });
  84140. this.dispatchEvent('pointcloud_changed');
  84141. }
  84142. }
  84143. getEDLRadius() {
  84144. return this.edlRadius;
  84145. }
  84146. setEDLStrength(value) {
  84147. if (this.edlStrength !== value) {
  84148. this.edlStrength = value;
  84149. this.dispatchEvent({
  84150. 'type': 'edl_strength_changed',
  84151. 'viewer': this
  84152. });
  84153. this.dispatchEvent('pointcloud_changed');
  84154. }
  84155. }
  84156. getEDLStrength() {
  84157. return this.edlStrength;
  84158. }
  84159. setEDLOpacity(value) {
  84160. if (this.edlOpacity !== value) {
  84161. this.edlOpacity = value;
  84162. this.dispatchEvent({
  84163. 'type': 'edl_opacity_changed',
  84164. 'viewer': this
  84165. });
  84166. this.dispatchEvent('pointcloud_changed');
  84167. }
  84168. }
  84169. getEDLOpacity() {
  84170. return this.edlOpacity;
  84171. }
  84172. setFOV(value) {
  84173. if (this.fov !== value) {
  84174. var oldFov = this.fov;
  84175. this.fov = value;
  84176. this.scene.cameraP.fov = this.fov; //add
  84177. this.scene.cameraP.updateProjectionMatrix(); //add
  84178. this.dispatchEvent({
  84179. 'type': 'fov_changed',
  84180. 'viewer': this,
  84181. oldFov,
  84182. fov: this.fov
  84183. });
  84184. }
  84185. }
  84186. getFOV() {
  84187. return this.fov;
  84188. }
  84189. disableAnnotations() {
  84190. this.scene.annotations.traverse(annotation => {
  84191. annotation.domElement.css('pointer-events', 'none');
  84192. // return annotation.visible;
  84193. });
  84194. }
  84195. enableAnnotations() {
  84196. this.scene.annotations.traverse(annotation => {
  84197. annotation.domElement.css('pointer-events', 'auto');
  84198. // return annotation.visible;
  84199. });
  84200. }
  84201. setClassifications(classifications) {
  84202. this.classifications = classifications;
  84203. this.dispatchEvent({
  84204. 'type': 'classifications_changed',
  84205. 'viewer': this
  84206. });
  84207. }
  84208. setClassificationVisibility(key, value) {
  84209. if (!this.classifications[key]) {
  84210. this.classifications[key] = {
  84211. visible: value,
  84212. name: 'no name'
  84213. };
  84214. this.dispatchEvent({
  84215. 'type': 'classification_visibility_changed',
  84216. 'viewer': this
  84217. });
  84218. } else if (this.classifications[key].visible !== value) {
  84219. this.classifications[key].visible = value;
  84220. this.dispatchEvent({
  84221. 'type': 'classification_visibility_changed',
  84222. 'viewer': this
  84223. });
  84224. }
  84225. }
  84226. toggleAllClassificationsVisibility() {
  84227. var numVisible = 0;
  84228. var numItems = 0;
  84229. for (var key of Object.keys(this.classifications)) {
  84230. if (this.classifications[key].visible) {
  84231. numVisible++;
  84232. }
  84233. numItems++;
  84234. }
  84235. var visible = true;
  84236. if (numVisible === numItems) {
  84237. visible = false;
  84238. }
  84239. var somethingChanged = false;
  84240. for (var _key of Object.keys(this.classifications)) {
  84241. if (this.classifications[_key].visible !== visible) {
  84242. this.classifications[_key].visible = visible;
  84243. somethingChanged = true;
  84244. }
  84245. }
  84246. if (somethingChanged) {
  84247. this.dispatchEvent({
  84248. 'type': 'classification_visibility_changed',
  84249. 'viewer': this
  84250. });
  84251. }
  84252. }
  84253. setFilterReturnNumberRange(from, to) {
  84254. this.filterReturnNumberRange = [from, to];
  84255. this.dispatchEvent({
  84256. 'type': 'filter_return_number_range_changed',
  84257. 'viewer': this
  84258. });
  84259. }
  84260. setFilterNumberOfReturnsRange(from, to) {
  84261. this.filterNumberOfReturnsRange = [from, to];
  84262. this.dispatchEvent({
  84263. 'type': 'filter_number_of_returns_range_changed',
  84264. 'viewer': this
  84265. });
  84266. }
  84267. setFilterGPSTimeRange(from, to) {
  84268. this.filterGPSTimeRange = [from, to];
  84269. this.dispatchEvent({
  84270. 'type': 'filter_gps_time_range_changed',
  84271. 'viewer': this
  84272. });
  84273. }
  84274. setFilterPointSourceIDRange(from, to) {
  84275. this.filterPointSourceIDRange = [from, to];
  84276. this.dispatchEvent({
  84277. 'type': 'filter_point_source_id_range_changed',
  84278. 'viewer': this
  84279. });
  84280. }
  84281. setLengthUnit(value) {
  84282. switch (value) {
  84283. case 'm':
  84284. this.lengthUnit = LengthUnits.METER;
  84285. this.lengthUnitDisplay = LengthUnits.METER;
  84286. break;
  84287. case 'ft':
  84288. this.lengthUnit = LengthUnits.FEET;
  84289. this.lengthUnitDisplay = LengthUnits.FEET;
  84290. break;
  84291. case 'in':
  84292. this.lengthUnit = LengthUnits.INCH;
  84293. this.lengthUnitDisplay = LengthUnits.INCH;
  84294. break;
  84295. }
  84296. this.dispatchEvent({
  84297. 'type': 'length_unit_changed',
  84298. 'viewer': this,
  84299. value: value
  84300. });
  84301. }
  84302. setLengthUnitAndDisplayUnit(lengthUnitValue, lengthUnitDisplayValue) {
  84303. switch (lengthUnitValue) {
  84304. case 'm':
  84305. this.lengthUnit = LengthUnits.METER;
  84306. break;
  84307. case 'ft':
  84308. this.lengthUnit = LengthUnits.FEET;
  84309. break;
  84310. case 'in':
  84311. this.lengthUnit = LengthUnits.INCH;
  84312. break;
  84313. }
  84314. switch (lengthUnitDisplayValue) {
  84315. case 'm':
  84316. this.lengthUnitDisplay = LengthUnits.METER;
  84317. break;
  84318. case 'ft':
  84319. this.lengthUnitDisplay = LengthUnits.FEET;
  84320. break;
  84321. case 'in':
  84322. this.lengthUnitDisplay = LengthUnits.INCH;
  84323. break;
  84324. }
  84325. this.dispatchEvent({
  84326. 'type': 'length_unit_changed',
  84327. 'viewer': this,
  84328. value: lengthUnitValue
  84329. });
  84330. }
  84331. zoomTo(node, factor) {
  84332. var animationDuration = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  84333. var view = this.mainViewport.view;
  84334. var camera = this.scene.cameraP.clone();
  84335. camera.rotation.copy(this.scene.cameraP.rotation);
  84336. camera.rotation.order = "ZXY";
  84337. camera.rotation.x = Math.PI / 2 + view.pitch;
  84338. camera.rotation.z = view.yaw;
  84339. camera.updateMatrix();
  84340. camera.updateMatrixWorld();
  84341. camera.zoomTo(node, factor);
  84342. var bs;
  84343. if (node.boundingSphere) {
  84344. bs = node.boundingSphere;
  84345. } else if (node.geometry && node.geometry.boundingSphere) {
  84346. bs = node.geometry.boundingSphere;
  84347. } else {
  84348. bs = node.boundingBox.getBoundingSphere(new Sphere());
  84349. }
  84350. bs = bs.clone().applyMatrix4(node.matrixWorld);
  84351. var startPosition = view.position.clone();
  84352. var endPosition = camera.position.clone();
  84353. var startTarget = view.getPivot();
  84354. var endTarget = bs.center;
  84355. var startRadius = view.radius;
  84356. var endRadius = endPosition.distanceTo(endTarget);
  84357. var easing = TWEEN.Easing.Quartic.Out;
  84358. {
  84359. // animate camera position
  84360. var pos = startPosition.clone();
  84361. var tween = new TWEEN.Tween(pos).to(endPosition, animationDuration);
  84362. tween.easing(easing);
  84363. tween.onUpdate(() => {
  84364. view.position.copy(pos);
  84365. });
  84366. tween.start();
  84367. }
  84368. {
  84369. // animate camera target
  84370. var target = startTarget.clone();
  84371. var _tween = new TWEEN.Tween(target).to(endTarget, animationDuration);
  84372. _tween.easing(easing);
  84373. _tween.onUpdate(() => {
  84374. view.lookAt(target);
  84375. });
  84376. _tween.onComplete(() => {
  84377. view.lookAt(target);
  84378. this.dispatchEvent({
  84379. type: 'focusing_finished',
  84380. target: this
  84381. });
  84382. });
  84383. this.dispatchEvent({
  84384. type: 'focusing_started',
  84385. target: this
  84386. });
  84387. _tween.start();
  84388. }
  84389. }
  84390. moveToGpsTimeVicinity(time) {
  84391. var result = Potree.Utils.findClosestGpsTime(time, viewer);
  84392. var box = result.node.pointcloud.deepestNodeAt(result.position).getBoundingBox();
  84393. var diameter = box.min.distanceTo(box.max);
  84394. var camera = this.scene.getActiveCamera();
  84395. var offset = camera.getWorldDirection(new Vector3()).multiplyScalar(diameter);
  84396. var newCamPos = result.position.clone().sub(offset);
  84397. this.scene.view.position.copy(newCamPos);
  84398. this.scene.view.lookAt(result.position);
  84399. }
  84400. showAbout() {
  84401. $(function () {
  84402. $('#about-panel').dialog();
  84403. });
  84404. }
  84405. getGpsTimeExtent() {
  84406. var range = [Infinity, -Infinity];
  84407. for (var pointcloud of this.scene.pointclouds) {
  84408. var attributes = pointcloud.pcoGeometry.pointAttributes.attributes;
  84409. var aGpsTime = attributes.find(a => a.name === "gps-time");
  84410. if (aGpsTime) {
  84411. range[0] = Math.min(range[0], aGpsTime.range[0]);
  84412. range[1] = Math.max(range[1], aGpsTime.range[1]);
  84413. }
  84414. }
  84415. return range;
  84416. }
  84417. fitToScreen() {
  84418. var factor = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
  84419. var animationDuration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  84420. var box = this.getBoundingBox(this.scene.pointclouds);
  84421. var node = new Object3D();
  84422. node.boundingBox = box;
  84423. this.zoomTo(node, factor, animationDuration);
  84424. this.controls.stop();
  84425. }
  84426. toggleNavigationCube() {
  84427. this.navigationCube.visible = !this.navigationCube.visible;
  84428. /* this.viewports.push({
  84429. name:'navigationCube',
  84430. left:0, bottom:0, width:0.2,
  84431. }) */
  84432. }
  84433. /* setView(pos, view) {
  84434. if(!pos) return;
  84435. switch(pos) {
  84436. case "F":
  84437. this.setFrontView(view);
  84438. break;
  84439. case "B":
  84440. this.setBackView(view);
  84441. break;
  84442. case "L":
  84443. this.setLeftView(view);
  84444. break;
  84445. case "R":
  84446. this.setRightView(view);
  84447. break;
  84448. case "U":
  84449. this.setTopView(view);
  84450. break;
  84451. case "D":
  84452. this.setBottomView(view);
  84453. break;
  84454. }
  84455. } */
  84456. setTopView(view) {
  84457. view = view || this.scene.view;
  84458. view.setCubeView("top");
  84459. this.fitToScreen();
  84460. }
  84461. setBottomView() {
  84462. this.scene.view.yaw = -Math.PI;
  84463. this.scene.view.pitch = Math.PI / 2;
  84464. this.fitToScreen();
  84465. }
  84466. setFrontView(view) {
  84467. view = view || this.scene.view;
  84468. view.yaw = 0;
  84469. view.pitch = 0;
  84470. this.fitToScreen();
  84471. }
  84472. setBackView(view) {
  84473. view = view || this.scene.view;
  84474. view.yaw = Math.PI;
  84475. view.pitch = 0;
  84476. this.fitToScreen();
  84477. }
  84478. setLeftView() {
  84479. this.scene.view.yaw = -Math.PI / 2;
  84480. this.scene.view.pitch = 0;
  84481. this.fitToScreen();
  84482. }
  84483. setRightView() {
  84484. this.scene.view.yaw = Math.PI / 2;
  84485. this.scene.view.pitch = 0;
  84486. this.fitToScreen();
  84487. }
  84488. flipYZ() {
  84489. this.isFlipYZ = !this.isFlipYZ;
  84490. // TODO flipyz
  84491. console.log('TODO');
  84492. }
  84493. setCameraMode(mode) {
  84494. this.scene.cameraMode = mode;
  84495. viewer.mainViewport.camera = mode == CameraMode.PERSPECTIVE ? this.scene.cameraP : this.scene.cameraO; //改
  84496. for (var pointcloud of this.scene.pointclouds) {
  84497. pointcloud.material.useOrthographicCamera = mode == CameraMode.ORTHOGRAPHIC;
  84498. }
  84499. }
  84500. getProjection() {
  84501. var pointcloud = this.scene.pointclouds[0];
  84502. if (pointcloud) {
  84503. return pointcloud.projection;
  84504. } else {
  84505. return null;
  84506. }
  84507. }
  84508. async loadProject(url, done) {
  84509. var response = await fetch(url);
  84510. if (response.ok) {
  84511. var text = await response.text();
  84512. var json = JSON5.parse(text);
  84513. // const json = JSON.parse(text);
  84514. if (json.type === "Potree") {
  84515. Potree.loadProject(viewer, json, done);
  84516. }
  84517. } else {
  84518. console.warn("未能加载:" + url);
  84519. }
  84520. }
  84521. saveProject() {
  84522. return Potree.saveProject(this);
  84523. }
  84524. loadSettingsFromURL() {
  84525. if (Utils.getParameterByName("pointSize")) {
  84526. this.setPointSize(parseFloat(Utils.getParameterByName("pointSize")));
  84527. }
  84528. if (Utils.getParameterByName("FOV")) {
  84529. this.setFOV(parseFloat(Utils.getParameterByName("FOV")));
  84530. }
  84531. if (Utils.getParameterByName("opacity")) {
  84532. this.setOpacity(parseFloat(Utils.getParameterByName("opacity")));
  84533. }
  84534. if (Utils.getParameterByName("edlEnabled")) {
  84535. var enabled = Utils.getParameterByName("edlEnabled") === "true";
  84536. this.setEDLEnabled(enabled);
  84537. }
  84538. if (Utils.getParameterByName('edlRadius')) {
  84539. this.setEDLRadius(parseFloat(Utils.getParameterByName('edlRadius')));
  84540. }
  84541. if (Utils.getParameterByName('edlStrength')) {
  84542. this.setEDLStrength(parseFloat(Utils.getParameterByName('edlStrength')));
  84543. }
  84544. if (Utils.getParameterByName('pointBudget')) {
  84545. this.setPointBudget(parseFloat(Utils.getParameterByName('pointBudget')));
  84546. }
  84547. if (Utils.getParameterByName('showBoundingBox')) {
  84548. var _enabled = Utils.getParameterByName('showBoundingBox') === 'true';
  84549. if (_enabled) {
  84550. this.setShowBoundingBox(true);
  84551. } else {
  84552. this.setShowBoundingBox(false);
  84553. }
  84554. }
  84555. if (Utils.getParameterByName('material')) {
  84556. var material = Utils.getParameterByName('material');
  84557. this.setMaterial(material);
  84558. }
  84559. if (Utils.getParameterByName('pointSizing')) {
  84560. var sizing = Utils.getParameterByName('pointSizing');
  84561. this.setPointSizing(sizing);
  84562. }
  84563. if (Utils.getParameterByName('quality')) {
  84564. var quality = Utils.getParameterByName('quality');
  84565. this.setQuality(quality);
  84566. }
  84567. if (Utils.getParameterByName('position')) {
  84568. var value = Utils.getParameterByName('position');
  84569. value = value.replace('[', '').replace(']', '');
  84570. var tokens = value.split(';');
  84571. var x = parseFloat(tokens[0]);
  84572. var y = parseFloat(tokens[1]);
  84573. var z = parseFloat(tokens[2]);
  84574. this.scene.view.position.set(x, y, z);
  84575. }
  84576. if (Utils.getParameterByName('target')) {
  84577. var _value = Utils.getParameterByName('target');
  84578. _value = _value.replace('[', '').replace(']', '');
  84579. var _tokens = _value.split(';');
  84580. var _x = parseFloat(_tokens[0]);
  84581. var _y = parseFloat(_tokens[1]);
  84582. var _z = parseFloat(_tokens[2]);
  84583. this.scene.view.lookAt(new Vector3(_x, _y, _z));
  84584. }
  84585. if (Utils.getParameterByName('background')) {
  84586. var _value2 = Utils.getParameterByName('background');
  84587. this.setBackground(_value2);
  84588. }
  84589. // if(Utils.getParameterByName("elevationRange")){
  84590. // let value = Utils.getParameterByName("elevationRange");
  84591. // value = value.replace("[", "").replace("]", "");
  84592. // let tokens = value.split(";");
  84593. // let x = parseFloat(tokens[0]);
  84594. // let y = parseFloat(tokens[1]);
  84595. //
  84596. // this.setElevationRange(x, y);
  84597. // //this.scene.view.target.set(x, y, z);
  84598. // }
  84599. }
  84600. // ------------------------------------------------------------------------------------
  84601. // Viewer Internals
  84602. // ------------------------------------------------------------------------------------
  84603. createControls() {
  84604. {
  84605. // create FIRST PERSON CONTROLS
  84606. this.fpControls = new FirstPersonControls(this, this.mainViewport);
  84607. this.fpControls.enabled = false;
  84608. this.fpControls.addEventListener('start', this.disableAnnotations.bind(this));
  84609. this.fpControls.addEventListener('end', this.enableAnnotations.bind(this));
  84610. /* this.addEventListener("loadPointCloudDone", ()=>{
  84611. let boundPlane = new THREE.Box3()
  84612. boundPlane.expandByPoint(this.bound.boundingBox.min.clone())//最低高度为bound的最低
  84613. boundPlane.expandByPoint(this.bound.boundingBox.max.clone().setZ(this.bound.center.z))//最高高度为bound的中心高度
  84614. FirstPersonControls.boundPlane = boundPlane
  84615. FirstPersonControls.standardSpeed = THREE.Math.clamp( Math.sqrt(this.bound.boundSize.length() )/ 100 , 0.02,0.5); //在这个boundPlane中的速度
  84616. }) */
  84617. }
  84618. // { // create GEO CONTROLS
  84619. // this.geoControls = new GeoControls(this.scene.camera, this.renderer.domElement);
  84620. // this.geoControls.enabled = false;
  84621. // this.geoControls.addEventListener("start", this.disableAnnotations.bind(this));
  84622. // this.geoControls.addEventListener("end", this.enableAnnotations.bind(this));
  84623. // this.geoControls.addEventListener("move_speed_changed", (event) => {
  84624. // this.setMoveSpeed(this.geoControls.moveSpeed);
  84625. // });
  84626. // }
  84627. {
  84628. // create ORBIT CONTROLS
  84629. this.orbitControls = new OrbitControls$1(this);
  84630. this.orbitControls.enabled = false;
  84631. this.orbitControls.addEventListener('start', this.disableAnnotations.bind(this));
  84632. this.orbitControls.addEventListener('end', this.enableAnnotations.bind(this));
  84633. }
  84634. /* { // create EARTH CONTROLS
  84635. this.earthControls = new EarthControls(this);
  84636. this.earthControls.enabled = false;
  84637. this.earthControls.addEventListener('start', this.disableAnnotations.bind(this));
  84638. this.earthControls.addEventListener('end', this.enableAnnotations.bind(this));
  84639. }
  84640. { // create DEVICE ORIENTATION CONTROLS
  84641. this.deviceControls = new DeviceOrientationControls(this);
  84642. this.deviceControls.enabled = false;
  84643. this.deviceControls.addEventListener('start', this.disableAnnotations.bind(this));
  84644. this.deviceControls.addEventListener('end', this.enableAnnotations.bind(this));
  84645. } */
  84646. /* { // create VR CONTROLS
  84647. this.vrControls = new VRControls(this);
  84648. this.vrControls.enabled = false;
  84649. this.vrControls.addEventListener('start', this.disableAnnotations.bind(this));
  84650. this.vrControls.addEventListener('end', this.enableAnnotations.bind(this));
  84651. } */
  84652. }
  84653. toggleSidebar() {
  84654. var renderArea = $('#potree_render_area');
  84655. var isVisible = renderArea.css('left') !== '0px';
  84656. if (isVisible) {
  84657. renderArea.css('left', '0px');
  84658. } else {
  84659. renderArea.css('left', '300px');
  84660. }
  84661. }
  84662. toggleMap() {
  84663. // let map = $('#potree_map');
  84664. // map.toggle(100);
  84665. if (this.mapView) {
  84666. this.mapView.toggle();
  84667. }
  84668. }
  84669. onGUILoaded(callback) {
  84670. if (this.guiLoaded) {
  84671. callback();
  84672. } else {
  84673. this.guiLoadTasks.push(callback);
  84674. }
  84675. }
  84676. promiseGuiLoaded() {
  84677. return new Promise(resolve => {
  84678. if (this.guiLoaded) {
  84679. resolve();
  84680. } else {
  84681. this.guiLoadTasks.push(resolve);
  84682. }
  84683. });
  84684. }
  84685. loadGUI(callback) {
  84686. if (callback) {
  84687. this.onGUILoaded(callback);
  84688. }
  84689. var viewer = this;
  84690. var sidebarContainer = $('#potree_sidebar_container');
  84691. sidebarContainer.load(new URL(Potree.scriptPath + '/' + (Potree.settings.sidebar || 'sidebar1.html')).href, () => {
  84692. sidebarContainer.css('width', '300px');
  84693. sidebarContainer.css('height', '100%');
  84694. var imgMenuToggle = document.createElement('img');
  84695. imgMenuToggle.src = new URL(Potree.resourcePath + '/icons/menu_button.svg').href;
  84696. imgMenuToggle.onclick = this.toggleSidebar;
  84697. imgMenuToggle.classList.add('potree_menu_toggle');
  84698. var imgMapToggle = document.createElement('img');
  84699. imgMapToggle.src = new URL(Potree.resourcePath + '/icons/map_icon.png').href;
  84700. imgMapToggle.style.display = 'none';
  84701. imgMapToggle.onclick = e => {
  84702. this.toggleMap();
  84703. };
  84704. imgMapToggle.id = 'potree_map_toggle';
  84705. var elButtons = $("#potree_quick_buttons").get(0);
  84706. elButtons.append(imgMenuToggle);
  84707. elButtons.append(imgMapToggle);
  84708. VRButton$1.createButton(this.renderer).then(vrButton => {
  84709. if (vrButton == null) {
  84710. console.log("VR not supported or active.");
  84711. return;
  84712. }
  84713. this.renderer.xr.enabled = true;
  84714. var element = vrButton.element;
  84715. element.style.position = "";
  84716. element.style.bottom = "";
  84717. element.style.left = "";
  84718. element.style.margin = "4px";
  84719. element.style.fontSize = "100%";
  84720. element.style.width = "2.5em";
  84721. element.style.height = "2.5em";
  84722. element.style.padding = "0";
  84723. element.style.textShadow = "black 2px 2px 2px";
  84724. element.style.display = "block";
  84725. elButtons.append(element);
  84726. vrButton.onStart(() => {
  84727. this.dispatchEvent({
  84728. type: "vr_start"
  84729. });
  84730. });
  84731. vrButton.onEnd(() => {
  84732. this.dispatchEvent({
  84733. type: "vr_end"
  84734. });
  84735. });
  84736. });
  84737. /* this.mapView = new MapView(this);
  84738. this.mapView.init(); */
  84739. i18n.init({
  84740. lng: 'en',
  84741. resGetPath: Potree.resourcePath + '/lang/__lng__/__ns__.json',
  84742. preload: ['en', 'fr', 'de', 'jp', 'se', 'es', 'zh'],
  84743. getAsync: true,
  84744. debug: false
  84745. }, function (t) {
  84746. // Start translation once everything is loaded
  84747. $('body').i18n();
  84748. });
  84749. $(() => {
  84750. //initSidebar(this);
  84751. var sidebar = new Sidebar(this);
  84752. sidebar.init();
  84753. this.sidebar = sidebar;
  84754. //if (callback) {
  84755. // $(callback);
  84756. //}
  84757. var elProfile = $('<div>').load(new URL(Potree.scriptPath + '/profile.html').href, () => {
  84758. $(document.body).append(elProfile.children());
  84759. this.profileWindow = new ProfileWindow(this);
  84760. this.profileWindowController = new ProfileWindowController(this);
  84761. $('#profile_window').draggable({
  84762. handle: $('#profile_titlebar'),
  84763. containment: $(document.body)
  84764. });
  84765. $('#profile_window').resizable({
  84766. containment: $(document.body),
  84767. handles: 'n, e, s, w'
  84768. });
  84769. $(() => {
  84770. this.guiLoaded = true;
  84771. for (var task of this.guiLoadTasks) {
  84772. task();
  84773. }
  84774. });
  84775. });
  84776. });
  84777. });
  84778. return this.promiseGuiLoaded();
  84779. }
  84780. setLanguage(lang) {
  84781. i18n.setLng(lang);
  84782. $('body').i18n();
  84783. }
  84784. setServer(server) {
  84785. this.server = server;
  84786. }
  84787. initDragAndDrop() {
  84788. function allowDrag(e) {
  84789. e.dataTransfer.dropEffect = 'copy';
  84790. e.preventDefault();
  84791. }
  84792. var dropHandler = async event => {
  84793. console.log(event);
  84794. event.preventDefault();
  84795. for (var item of event.dataTransfer.items) {
  84796. console.log(item);
  84797. if (item.kind !== "file") {
  84798. continue;
  84799. }
  84800. var file = item.getAsFile();
  84801. var isJson = file.name.toLowerCase().endsWith(".json");
  84802. var isGeoPackage = file.name.toLowerCase().endsWith(".gpkg");
  84803. if (isJson) {
  84804. try {
  84805. var text = await file.text();
  84806. var json = JSON.parse(text);
  84807. if (json.type === "Potree") {
  84808. Potree.loadProject(viewer, json);
  84809. }
  84810. } catch (e) {
  84811. console.error("failed to parse the dropped file as JSON");
  84812. console.error(e);
  84813. }
  84814. } else if (isGeoPackage) {
  84815. var hasPointcloud = viewer.scene.pointclouds.length > 0;
  84816. if (!hasPointcloud) {
  84817. var msg = "At least one point cloud is needed that specifies the ";
  84818. msg += "coordinate reference system before loading vector data.";
  84819. console.error(msg);
  84820. } else {
  84821. proj4.defs("WGS84", "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs");
  84822. proj4.defs("pointcloud", this.getProjection());
  84823. var transform = proj4("WGS84", "pointcloud");
  84824. var buffer = await file.arrayBuffer();
  84825. var params = {
  84826. transform: transform,
  84827. source: file.name
  84828. };
  84829. var geo = await Potree.GeoPackageLoader.loadBuffer(buffer, params);
  84830. viewer.scene.addGeopackage(geo);
  84831. }
  84832. }
  84833. }
  84834. };
  84835. $("body")[0].addEventListener("dragenter", allowDrag);
  84836. $("body")[0].addEventListener("dragover", allowDrag);
  84837. $("body")[0].addEventListener("drop", dropHandler);
  84838. }
  84839. updateAnnotations() {
  84840. if (!this.visibleAnnotations) {
  84841. this.visibleAnnotations = new Set();
  84842. }
  84843. this.scene.annotations.updateBounds();
  84844. this.scene.cameraP.updateMatrixWorld();
  84845. this.scene.cameraO.updateMatrixWorld();
  84846. var distances = [];
  84847. var renderAreaSize = this.renderer.getSize(new Vector2());
  84848. var viewer = this;
  84849. var visibleNow = [];
  84850. this.scene.annotations.traverse(annotation => {
  84851. if (annotation === this.scene.annotations) {
  84852. return true;
  84853. }
  84854. if (!annotation.visible) {
  84855. return false;
  84856. }
  84857. annotation.scene = this.scene;
  84858. var element = annotation.domElement;
  84859. var position = annotation.position.clone();
  84860. position.add(annotation.offset);
  84861. if (!position) {
  84862. position = annotation.boundingBox.getCenter(new Vector3());
  84863. }
  84864. var distance = viewer.scene.cameraP.position.distanceTo(position);
  84865. var radius = annotation.boundingBox.getBoundingSphere(new Sphere()).radius;
  84866. var screenPos = new Vector3();
  84867. var screenSize = 0;
  84868. {
  84869. // SCREEN POS
  84870. screenPos.copy(position).project(this.scene.getActiveCamera());
  84871. screenPos.x = renderAreaSize.x * (screenPos.x + 1) / 2;
  84872. screenPos.y = renderAreaSize.y * (1 - (screenPos.y + 1) / 2);
  84873. // SCREEN SIZE
  84874. if (viewer.scene.cameraMode == CameraMode.PERSPECTIVE) {
  84875. var fov = Math.PI * viewer.scene.cameraP.fov / 180;
  84876. var slope = Math.tan(fov / 2.0);
  84877. var projFactor = 0.5 * renderAreaSize.y / (slope * distance);
  84878. screenSize = radius * projFactor;
  84879. } else {
  84880. screenSize = Utils.projectedRadiusOrtho(radius, viewer.scene.cameraO.projectionMatrix, renderAreaSize.x, renderAreaSize.y);
  84881. }
  84882. }
  84883. element.css("left", screenPos.x + "px");
  84884. element.css("top", screenPos.y + "px");
  84885. //element.css("display", "block");
  84886. var zIndex = 10000000 - distance * (10000000 / this.scene.cameraP.far);
  84887. if (annotation.descriptionVisible) {
  84888. zIndex += 10000000;
  84889. }
  84890. element.css("z-index", parseInt(zIndex));
  84891. if (annotation.children.length > 0) {
  84892. var expand = screenSize > annotation.collapseThreshold || annotation.boundingBox.containsPoint(this.scene.getActiveCamera().position);
  84893. annotation.expand = expand;
  84894. if (!expand) {
  84895. //annotation.display = (screenPos.z >= -1 && screenPos.z <= 1);
  84896. var inFrustum = screenPos.z >= -1 && screenPos.z <= 1;
  84897. if (inFrustum) {
  84898. visibleNow.push(annotation);
  84899. }
  84900. }
  84901. return expand;
  84902. } else {
  84903. //annotation.display = (screenPos.z >= -1 && screenPos.z <= 1);
  84904. var _inFrustum = screenPos.z >= -1 && screenPos.z <= 1;
  84905. if (_inFrustum) {
  84906. visibleNow.push(annotation);
  84907. }
  84908. }
  84909. });
  84910. var notVisibleAnymore = new Set(this.visibleAnnotations);
  84911. for (var annotation of visibleNow) {
  84912. annotation.display = true;
  84913. notVisibleAnymore.delete(annotation);
  84914. }
  84915. this.visibleAnnotations = visibleNow;
  84916. for (var _annotation of notVisibleAnymore) {
  84917. _annotation.display = false;
  84918. }
  84919. }
  84920. updateMaterialDefaults(pointcloud) {
  84921. // PROBLEM STATEMENT:
  84922. // * [min, max] of intensity, source id, etc. are computed as point clouds are loaded
  84923. // * the point cloud material won't know the range it should use until some data is loaded
  84924. // * users can modify the range at runtime, but sensible default ranges should be
  84925. // applied even if no GUI is present
  84926. // * display ranges shouldn't suddenly change even if the actual range changes over time.
  84927. // e.g. the root node has intensity range [1, 478]. One of the descendants increases range to
  84928. // [0, 2047]. We should not automatically change to the new range because that would result
  84929. // in sudden and drastic changes of brightness. We should adjust the min/max of the sidebar slider.
  84930. var material = pointcloud.material;
  84931. var attIntensity = pointcloud.getAttribute("intensity");
  84932. if (attIntensity != null && material.intensityRange[0] === Infinity) {
  84933. material.intensityRange = [...attIntensity.range];
  84934. }
  84935. // const attIntensity = pointcloud.getAttribute("intensity");
  84936. // if(attIntensity && material.intensityRange[0] === Infinity){
  84937. // material.intensityRange = [...attIntensity.range];
  84938. // }
  84939. // let attributes = pointcloud.getAttributes();
  84940. // for(let attribute of attributes.attributes){
  84941. // if(attribute.range){
  84942. // let range = [...attribute.range];
  84943. // material.computedRange.set(attribute.name, range);
  84944. // //material.setRange(attribute.name, range);
  84945. // }
  84946. // }
  84947. }
  84948. update(delta, timestamp) {
  84949. viewer.addTimeMark('update', 'start');
  84950. TWEEN.update(timestamp);
  84951. transitions.update(delta); //写在开头,因为这时候最为固定,计时准确
  84952. this.dispatchEvent({
  84953. type: 'update_start',
  84954. delta: delta,
  84955. timestamp: timestamp
  84956. });
  84957. this.updateScreenSize(); //判断是否改变canvas大小
  84958. var scene = this.scene;
  84959. var camera = scene.getActiveCamera();
  84960. var visiblePointClouds = this.scene.pointclouds.filter(pc => pc.visible);
  84961. Potree.pointLoadLimit = Potree.pointBudget * 2;
  84962. /* const lTarget = camera.position.clone().add(camera.getWorldDirection(new THREE.Vector3()).multiplyScalar(1000));
  84963. this.scene.directionalLight.position.copy(camera.position);
  84964. this.scene.directionalLight.lookAt(lTarget); */
  84965. for (var pointcloud of visiblePointClouds) {
  84966. pointcloud.showBoundingBox = this.showBoundingBox;
  84967. pointcloud.generateDEM = this.generateDEM;
  84968. pointcloud.minimumNodePixelSize = this.minNodeSize;
  84969. var material = pointcloud.material;
  84970. material.uniforms.uFilterReturnNumberRange.value = this.filterReturnNumberRange;
  84971. material.uniforms.uFilterNumberOfReturnsRange.value = this.filterNumberOfReturnsRange;
  84972. material.uniforms.uFilterGPSTimeClipRange.value = this.filterGPSTimeRange;
  84973. material.uniforms.uFilterPointSourceIDClipRange.value = this.filterPointSourceIDRange;
  84974. material.classification = this.classifications;
  84975. material.recomputeClassification();
  84976. this.updateMaterialDefaults(pointcloud);
  84977. }
  84978. {
  84979. if (this.showBoundingBox) {
  84980. var bbRoot = this.scene.scene.getObjectByName("potree_bounding_box_root");
  84981. if (!bbRoot) {
  84982. var node = new Object3D();
  84983. node.name = "potree_bounding_box_root";
  84984. this.scene.scene.add(node);
  84985. bbRoot = node;
  84986. }
  84987. var visibleBoxes = [];
  84988. for (var _pointcloud of this.scene.pointclouds) {
  84989. for (var _node of _pointcloud.visibleNodes.filter(vn => vn.boundingBoxNode !== undefined)) {
  84990. var box = _node.boundingBoxNode;
  84991. visibleBoxes.push(box);
  84992. }
  84993. }
  84994. bbRoot.children = visibleBoxes;
  84995. }
  84996. }
  84997. if (this.boundNeedUpdate) this.updateModelBound(); //add
  84998. this.scene.cameraP.fov = this.fov;
  84999. var controls = this.getControls();
  85000. if (controls === this.deviceControls) {
  85001. this.controls.setScene(scene);
  85002. this.controls.update(delta);
  85003. this.scene.cameraP.position.copy(scene.view.position);
  85004. this.scene.cameraO.position.copy(scene.view.position);
  85005. } else if (controls !== null) {
  85006. controls.setScene(scene);
  85007. controls.update(delta);
  85008. //更新camera
  85009. this.viewports.forEach(viewport => {
  85010. if (!viewport.active) return;
  85011. viewport.view.applyToCamera(viewport.camera);
  85012. });
  85013. }
  85014. this.lastFrameChanged = this.cameraChanged(); //判断camera画面是否改变
  85015. {
  85016. // update clip boxes
  85017. var boxes = [];
  85018. // volumes with clipping enabled
  85019. boxes.push(...this.scene.volumes.filter(v => v.clip && v instanceof BoxVolume$1));
  85020. // profile segments
  85021. for (var profile of this.scene.profiles) {
  85022. boxes.push(...profile.boxes);
  85023. }
  85024. // Needed for .getInverse(), pre-empt a determinant of 0, see #815 / #816
  85025. var degenerate = box => box.matrixWorld.determinant() !== 0 && box.clip;
  85026. var clipBoxes = boxes.filter(degenerate).map(box => {
  85027. box.updateMatrixWorld();
  85028. var boxInverse = box.matrixWorld.clone().invert();
  85029. //let boxPosition = box.getWorldPosition(new THREE.Vector3());
  85030. return {
  85031. box: box,
  85032. inverse: boxInverse /* , position: boxPosition */
  85033. };
  85034. });
  85035. //改
  85036. var bigClipInBox = clipBoxes.find(e => e.box.clipTask == ClipTask.SHOW_INSIDE_Big && !e.box.highlight); //裁剪下载 when this.modules.Clip.editing
  85037. var clipBoxes_in = clipBoxes.filter(e => e.box.clipTask == ClipTask.SHOW_INSIDE && !e.box.highlight);
  85038. var clipBoxes_out = clipBoxes.filter(e => e.box.clipTask == ClipTask.SHOW_OUTSIDE && !e.box.highlight);
  85039. var highlightBoxes = clipBoxes.filter(e => e.box.highlight);
  85040. //let prismPolygons = this.modules.volumeComputer && this.modules.volumeComputer.entered ? viewer.scene.measurements.filter(e=>(e.measureType == 'MulDistance Ring') && !e.isNew) : []
  85041. var prismPolygons = this.modules.volumeComputer ? this.modules.volumeComputer.prisms.filter(e => !e.isNew && e.visible && !e.dontHighlight && (e.baseModel || !e.modelHaventLoad)) : [];
  85042. // set clip volumes in material
  85043. for (var _pointcloud2 of visiblePointClouds) {
  85044. _pointcloud2.material.setClipBoxes(bigClipInBox, clipBoxes_in, clipBoxes_out, highlightBoxes, prismPolygons);
  85045. }
  85046. }
  85047. {
  85048. for (var _pointcloud3 of visiblePointClouds) {
  85049. _pointcloud3.material.elevationGradientRepeat = this.elevationGradientRepeat;
  85050. }
  85051. }
  85052. {
  85053. // update navigation cube
  85054. this.navigationCube.update(camera.rotation);
  85055. }
  85056. this.updateAnnotations();
  85057. if (this.mapView) {
  85058. this.mapView.update(delta);
  85059. if (this.mapView.sceneProjection) {
  85060. $("#potree_map_toggle").css("display", "block");
  85061. }
  85062. }
  85063. this.transformationTool.update();
  85064. if (Potree.settings.editType != 'pano' && Potree.settings.editType != 'merge') {
  85065. this.modules.ParticleEditor.update(delta);
  85066. }
  85067. this.mapViewer && this.mapViewer.update(delta); //地图更新
  85068. this.dispatchEvent({
  85069. type: 'update',
  85070. delta: delta,
  85071. timestamp: timestamp
  85072. }); //在有sidebar时耗高cpu,占本update函数80%
  85073. viewer.addTimeMark('update', 'end');
  85074. //add ------
  85075. this.reticule.updateVisible();
  85076. }
  85077. updateViewPointcloud(camera, areaSize, isViewport) {
  85078. var result = Potree.updatePointClouds(this.scene.pointclouds, camera, areaSize);
  85079. //if(isViewport)return
  85080. var tStart = performance.now();
  85081. var campos = camera.position;
  85082. var closestImage = Infinity;
  85083. for (var images of this.scene.orientedImages) {
  85084. for (var image of images.images) {
  85085. var distance = image.mesh.position.distanceTo(campos);
  85086. closestImage = Math.min(closestImage, distance);
  85087. }
  85088. }
  85089. //const tEnd = performance.now();
  85090. //改:不根据点云修改视野near far
  85091. var near = camera.near,
  85092. far = camera.far;
  85093. if (!camera.limitFar && result.lowestSpacing !== Infinity) {
  85094. //let near = result.lowestSpacing * 10.0;
  85095. var _far = -this.getBoundingBox().applyMatrix4(camera.matrixWorldInverse).min.z;
  85096. _far = Math.max(_far * 1.5, 10000);
  85097. //near = Math.min(100.0, Math.max(0.01, near));
  85098. //near = Math.min(near, closestImage);
  85099. _far = Math.max(_far, near + 10000);
  85100. /* if(near === Infinity){
  85101. near = 0.1;
  85102. } */
  85103. //camera.near = near; //为了其他物体的显示,不修改near
  85104. camera.far = _far;
  85105. }
  85106. /* if(this.scene.cameraMode == CameraMode.ORTHOGRAPHIC) {//???
  85107. camera.near = -camera.far;
  85108. } */
  85109. if ( /* near != camera.near || */far != camera.far) {
  85110. camera.updateProjectionMatrix();
  85111. }
  85112. //注:pointcloud.visibleNodes会随着near far自动更新
  85113. }
  85114. getPRenderer() {
  85115. if (this.useHQ) {
  85116. if (!this.hqRenderer) {
  85117. this.hqRenderer = new HQSplatRenderer(this);
  85118. }
  85119. this.hqRenderer.useEDL = this.useEDL;
  85120. return this.hqRenderer;
  85121. } else {
  85122. /* if (this.useEDL && Features.SHADER_EDL.isSupported()) {
  85123. if (!this.edlRenderer) {
  85124. this.edlRenderer = new EDLRenderer(this);
  85125. }
  85126. return this.edlRenderer;
  85127. } else {
  85128. if (!this.potreeRenderer) {
  85129. this.potreeRenderer = new PotreeRenderer(this);
  85130. }
  85131. return this.potreeRenderer;
  85132. } */
  85133. if (!this.edlRenderer) {
  85134. this.edlRenderer = new EDLRenderer(this);
  85135. }
  85136. return this.edlRenderer;
  85137. }
  85138. }
  85139. renderVR() {
  85140. //渲染部分没改完
  85141. var renderer = this.renderer;
  85142. renderer.setClearColor(0x550000, 0);
  85143. renderer.clear();
  85144. var xr = renderer.xr;
  85145. var dbg = new PerspectiveCamera();
  85146. var xrCameras = xr.getCamera(dbg);
  85147. if (xrCameras.cameras.length !== 2) {
  85148. return;
  85149. }
  85150. var makeCam = this.vrControls.getCamera.bind(this.vrControls);
  85151. {
  85152. // clear framebuffer
  85153. if (viewer.background === "skybox") {
  85154. renderer.setClearColor(0xff0000, 1);
  85155. } else if (viewer.background === "gradient") {
  85156. renderer.setClearColor(0x112233, 1);
  85157. } else if (viewer.background === "black") {
  85158. renderer.setClearColor(0x000000, 1);
  85159. } else if (viewer.background === "white") {
  85160. renderer.setClearColor(0xFFFFFF, 1);
  85161. } else {
  85162. renderer.setClearColor(0x000000, 0);
  85163. }
  85164. renderer.clear();
  85165. }
  85166. // render background
  85167. if (this.background === "skybox") {
  85168. var {
  85169. skybox
  85170. } = this;
  85171. var _cam = makeCam();
  85172. skybox.camera.rotation.copy(_cam.rotation);
  85173. skybox.camera.fov = _cam.fov;
  85174. skybox.camera.aspect = _cam.aspect;
  85175. // let dbg = new THREE.Object3D();
  85176. var _dbg = skybox.parent;
  85177. // dbg.up.set(0, 0, 1);
  85178. _dbg.rotation.x = Math.PI / 2;
  85179. // skybox.camera.parent = dbg;
  85180. // dbg.children.push(skybox.camera);
  85181. _dbg.updateMatrix();
  85182. _dbg.updateMatrixWorld();
  85183. skybox.camera.updateMatrix();
  85184. skybox.camera.updateMatrixWorld();
  85185. skybox.camera.updateProjectionMatrix();
  85186. renderer.render(skybox.scene, skybox.camera);
  85187. // renderer.render(skybox.scene, cam);
  85188. } else if (this.background === "gradient") {
  85189. // renderer.render(this.scene.sceneBG, this.scene.cameraBG);
  85190. }
  85191. this.renderer.xr.getSession().updateRenderState({
  85192. depthNear: 0.1,
  85193. depthFar: 10000
  85194. });
  85195. var cam = null;
  85196. var view = null;
  85197. {
  85198. // render world scene
  85199. cam = makeCam();
  85200. cam.position.z -= 0.8 * cam.scale.x;
  85201. cam.parent = null;
  85202. // cam.near = 0.05;
  85203. cam.near = viewer.scene.getActiveCamera().near;
  85204. cam.far = viewer.scene.getActiveCamera().far;
  85205. cam.updateMatrix();
  85206. cam.updateMatrixWorld();
  85207. this.scene.scene.updateMatrix();
  85208. this.scene.scene.updateMatrixWorld();
  85209. this.scene.scene.matrixAutoUpdate = false;
  85210. var camWorld = cam.matrixWorld.clone();
  85211. view = camWorld.clone().invert();
  85212. this.scene.scene.matrix.copy(view);
  85213. this.scene.scene.matrixWorld.copy(view);
  85214. cam.matrix.identity();
  85215. cam.matrixWorld.identity();
  85216. cam.matrixWorldInverse.identity();
  85217. renderer.render(this.scene.scene, cam);
  85218. this.scene.scene.matrixWorld.identity();
  85219. }
  85220. for (var pointcloud of this.scene.pointclouds) {
  85221. var viewport = xrCameras.cameras[0].viewport;
  85222. pointcloud.material.useEDL = false;
  85223. pointcloud.screenHeight = viewport.height;
  85224. pointcloud.screenWidth = viewport.width;
  85225. // automatically switch to paraboloids because they cause far less flickering in VR,
  85226. // when point sizes are larger than around 2 pixels
  85227. // if(Features.SHADER_INTERPOLATION.isSupported()){
  85228. // pointcloud.material.shape = Potree.PointShape.PARABOLOID;
  85229. // }
  85230. }
  85231. // render point clouds
  85232. for (var xrCamera of xrCameras.cameras) {
  85233. var v = xrCamera.viewport;
  85234. renderer.setViewport(v.x, v.y, v.width, v.height);
  85235. // xrCamera.fov = 90;
  85236. {
  85237. // estimate VR fov
  85238. var proj = xrCamera.projectionMatrix;
  85239. var inv = proj.clone().invert();
  85240. var p1 = new Vector4(0, 1, -1, 1).applyMatrix4(inv);
  85241. var rad = p1.y;
  85242. var fov = 180 * (rad / Math.PI);
  85243. xrCamera.fov = fov;
  85244. }
  85245. for (var _pointcloud4 of this.scene.pointclouds) {
  85246. var {
  85247. material
  85248. } = _pointcloud4;
  85249. material.useEDL = false;
  85250. }
  85251. var vrWorld = view.clone().invert();
  85252. vrWorld.multiply(xrCamera.matrixWorld);
  85253. var vrView = vrWorld.clone().invert();
  85254. this.pRenderer.render(this.scene.scenePointCloud, xrCamera, null, {
  85255. viewOverride: vrView
  85256. });
  85257. }
  85258. {
  85259. // render VR scene
  85260. var _cam2 = makeCam();
  85261. _cam2.parent = null;
  85262. renderer.render(this.sceneVR, _cam2);
  85263. }
  85264. renderer.resetState();
  85265. }
  85266. clear() {
  85267. var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  85268. var background = params.background || this.background;
  85269. var backgroundOpacity = params.backgroundOpacity == void 0 ? this.backgroundOpacity : params.backgroundOpacity; //如果想完全透明,只需要backgroundOpacity为0
  85270. var renderer = this.renderer;
  85271. //let gl = renderer.getContext()
  85272. if (background instanceof Color) {
  85273. //add
  85274. renderer.setClearColor(background, backgroundOpacity);
  85275. } else if (background === "skybox") {
  85276. renderer.setClearColor(0x000000, backgroundOpacity);
  85277. } else if (background === 'gradient') {
  85278. renderer.setClearColor(0x000000, backgroundOpacity);
  85279. } else if (background === 'black') {
  85280. renderer.setClearColor(0x000000, 1);
  85281. } else if (background === 'white') {
  85282. renderer.setClearColor(0xFFFFFF, 1);
  85283. } else {
  85284. renderer.setClearColor(background, backgroundOpacity);
  85285. }
  85286. params.target || renderer.clear();
  85287. }
  85288. getBuffer(viewport) {
  85289. //根据不同viewport返回rtEDL的texture
  85290. var buffer = this.buffers.get(viewport);
  85291. if (!buffer) {
  85292. buffer = new WebGLRenderTarget(viewport.resolution.x, viewport.resolution.y, {
  85293. minFilter: NearestFilter,
  85294. magFilter: NearestFilter,
  85295. format: RGBAFormat,
  85296. type: FloatType
  85297. });
  85298. this.buffers.set(viewport, rtEDL);
  85299. }
  85300. return buffer;
  85301. }
  85302. async renderDefault() {
  85303. var params_ = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  85304. if (!this.visible) return;
  85305. var pRenderer = this.getPRenderer();
  85306. var viewports = params_.viewports || this.viewports;
  85307. var renderer = params_.renderer || this.renderer;
  85308. viewer.addTimeMark('renderDefault', 'start');
  85309. //console.log('render', viewports.map(e=>e.name).join(','))
  85310. var renderSize;
  85311. if (params_.target) {
  85312. renderSize = new Vector2(params_.target.width, params_.target.height); //是画布大小
  85313. //可能需要viewer.setSize
  85314. } else {
  85315. renderSize = renderer.getSize(new Vector2()); //是client大小
  85316. }
  85317. ///let needsResize = viewports.length > 1 || params_.resize //去掉原因:因为不需要渲染的viewport不在此中所以无法判断几个viewport
  85318. for (var i = 0; i < viewports.length; i++) {
  85319. var viewport = viewports[i];
  85320. var params = $.extend({}, params_);
  85321. params.viewport = viewport;
  85322. //if(!params.target){
  85323. params.camera = params.camera || viewport.camera;
  85324. params.extraEnableLayers = viewport.extraEnableLayers;
  85325. params.cameraLayers = viewport.cameraLayers;
  85326. //}
  85327. var left, bottom, width, height;
  85328. {
  85329. left = Math.ceil(renderSize.x * viewport.left);
  85330. bottom = Math.ceil(renderSize.y * viewport.bottom);
  85331. if (params_.target) {
  85332. //有target时最好viewport是专门建出来的
  85333. width = renderSize.x * viewport.width; //target的大小可能和viewport不同,比如截图,这时会更改viewport大小
  85334. height = renderSize.y * viewport.height;
  85335. } else {
  85336. width = viewport.resolution.x; // 用的是client的width和height
  85337. height = viewport.resolution.y;
  85338. }
  85339. if (width == 0 || height == 0) continue; //return
  85340. width = Math.ceil(width); //使用ceil,当原本有小数时,会重叠一个像素,无所谓
  85341. height = Math.ceil(height);
  85342. var scissorTest = viewport.width < 1 || viewport.height < 1;
  85343. if (params_.target) {
  85344. params_.target.viewport.set(left, bottom, width, height);
  85345. scissorTest && params_.target.scissor.set(left, bottom, width, height);
  85346. params_.target.scissorTest = scissorTest;
  85347. renderer.setRenderTarget(params_.target);
  85348. } else {
  85349. /* if(viewports.length == 1 && left == 0 && bottom == 0){
  85350. left = 1 , width-=1 //这种情况下渲染也会有问题,只有鼠标的地方刷新 估计是pick那影响的
  85351. } */
  85352. /* if(scissorTest && left == 0 && bottom == 0){
  85353. left = 1 , width-=1
  85354. } */
  85355. if (viewport.forViewOffset) {
  85356. //分块渲染,渲染时的camera还是原来的,但加载点云时的camera是分块中的
  85357. viewport.forViewOffset.camera.setViewOffset(renderSize.x, renderSize.y, left, renderSize.y - bottom - height, width, height);
  85358. renderer.setViewport(0, 0, renderSize.x, renderSize.y);
  85359. viewport.resolution.copy(viewport.forViewOffset.originViewport.resolution);
  85360. viewport.resolution2.copy(viewport.forViewOffset.originViewport.resolution2); //后续渲染都当做原先的viewport
  85361. } else {
  85362. renderer.setViewport(left, bottom, width, height); //规定视口,影响图形变换(画布的使用范围)
  85363. }
  85364. //scissorTest && console.log('setScissor', left, bottom, width, height)
  85365. scissorTest && renderer.setScissor(left, bottom, width, height); //规定渲染范围
  85366. renderer.setScissorTest(scissorTest); //开启WebGL剪裁测试功能,如果不开启,.setScissor方法设置的范围不起作用 | width==1且height==1时开启会只有鼠标的地方刷新,很奇怪
  85367. }
  85368. }
  85369. //if(needsResize){
  85370. this.ifEmitResize({
  85371. viewport
  85372. });
  85373. //}
  85374. viewer.dispatchEvent({
  85375. type: "render.begin",
  85376. viewer: viewer,
  85377. viewport,
  85378. params
  85379. });
  85380. viewport.beforeRender && viewport.beforeRender();
  85381. if (viewport.render) {
  85382. if (!viewport.render($.extend({}, params, {
  85383. renderer,
  85384. clear: params.clear || this.clear.bind(this),
  85385. resize: null,
  85386. renderBG: this.renderBG.bind(this),
  85387. force: true //viewer content_change时map也直接渲染吧 //!viewport.noPointcloud //如果要渲染点云,必须也一直渲染地图,否则地图会被覆盖(点云目前未能获取是否改变,也可能有其他动态物体,所以还是一直渲染的好)
  85388. }))) continue; //return
  85389. } else {
  85390. this.clear(params);
  85391. pRenderer.clearTargets(params);
  85392. this.renderBG(viewport);
  85393. if (Potree.settings.notAdditiveBlending) {
  85394. params.renderBeforeCloud = true;
  85395. this.renderOverlay1(params); //先渲染不透明的model。 但drawedModelOnRT时这里提前多渲染了一遍
  85396. }
  85397. }
  85398. if (!viewport.noPointcloud) {
  85399. if (params_.needWaitLoadPoint) {
  85400. await this.waitPointLoad(null, params_.maxTimeForPointLoad, viewport); //resolution得用split前整个的viewport的
  85401. } else {
  85402. this.updateViewPointcloud(params.camera, viewport.resolution, true);
  85403. }
  85404. pRenderer.render(params); //渲染点云 skybox。
  85405. }
  85406. if (Potree.settings.notAdditiveBlending) {
  85407. // 融合页面才用到
  85408. params.renderBeforeCloud = false;
  85409. this.renderOverlay1(params);
  85410. this.renderOverlay2(params);
  85411. } else {
  85412. this.renderOverlay(params);
  85413. }
  85414. viewport.afterRender && viewport.afterRender();
  85415. this.dispatchEvent({
  85416. type: "render.end",
  85417. viewer: this,
  85418. viewport
  85419. });
  85420. viewport.needRender = false;
  85421. viewport.lastRenderTime = Date.now();
  85422. }
  85423. /* if(params_.screenshot){ //抗锯齿
  85424. this.composer.render();
  85425. } */
  85426. this.renderer.setRenderTarget(null);
  85427. viewer.scene.pointclouds[0] && this.addFakeMeasure('visibleNodes', viewer.scene.pointclouds[0].visibleNodes.length); //
  85428. this.addFakeMeasure('numVisiblePoints', Potree.numVisiblePoints / 100000); //十万 numVisiblePoints和帧率成反比(若每一帧都render的话),和render用时成正比 (y=kn+b)。但visibleNodes个数也影响,多的话也更卡。visibleNodes和numVisiblePoints不成正比,少的visibleNodes可能numVisiblePoints多
  85429. viewer.addTimeMark('renderDefault', 'end');
  85430. }
  85431. renderBG(viewport) {
  85432. var background = viewport.background || viewer.background;
  85433. var backgroundOpacity = viewport.backgroundOpacity == void 0 ? viewer.backgroundOpacity : viewport.backgroundOpacity; //如果想完全透明,只需要backgroundOpacity为0
  85434. if (backgroundOpacity != 0) {
  85435. //绘制背景. 为了防止相机移动后天空不动有点死板,做一定的动态
  85436. if (background === "skybox") {
  85437. //限制相机到原点的距离。
  85438. var skyCamera = viewport.camera.type == "OrthographicCamera" ? viewer.skybox.cameraOrtho : viewer.skybox.camera;
  85439. var safeRatio = 0.02;
  85440. var safeWidth = Potree.config.skyboxBgWidth * safeRatio / 2; //相机只能在这个范围内移动
  85441. if (!viewport.skyboxFixPos) {
  85442. //允许不在全景图中心,允许位移造成一定程度畸变
  85443. var dir = new Vector3().subVectors(viewport.camera.position, viewer.bound.center);
  85444. var length = dir.length();
  85445. var moveMax = 100;
  85446. var aimRadius = easing.easeOutQuart(Math.min(length, moveMax), 0, safeWidth, moveMax); //(x, startY, wholeY, maxX) 当自变量为0-moveMax时,相机位移量为0-safeWidth
  85447. dir.multiplyScalar(aimRadius / length);
  85448. skyCamera.position.copy(dir);
  85449. } else {
  85450. skyCamera.position.set(0, 0, 0);
  85451. }
  85452. skyCamera.rotation.copy(viewport.camera.rotation);
  85453. skyCamera.aspect = viewport.camera.aspect;
  85454. if (viewport.camera.type == "OrthographicCamera") {
  85455. //调节zoom
  85456. skyCamera.left = viewport.camera.left;
  85457. skyCamera.right = viewport.camera.right;
  85458. skyCamera.top = viewport.camera.top;
  85459. skyCamera.bottom = viewport.camera.bottom;
  85460. var a = Potree.config.skyboxBgWidth / 2 - safeWidth;
  85461. var minY = Math.max(skyCamera.right / a, skyCamera.top / a, viewport.skyboxMinZoom || 0); //能够使skybox铺满画布的最小zoom. 提示:越远zoom越小
  85462. var maxY = Math.max(20, minY); //自定义一个 不会超过的最大实际zoom
  85463. //viewport.camera.zoom自变量的变化范围:
  85464. var minX = 1;
  85465. var maxX = 80;
  85466. var x = MathUtils.clamp(viewport.camera.zoom - minX, minX, maxX);
  85467. skyCamera.zoom = easing.easeOutCubic(x - minX, minY, maxY - minY, maxX - minX); //自变量范围从0开始,所以减去minX
  85468. //pos的范围先不管了 其实aimRadius是有误的,但效果还行
  85469. } else {
  85470. skyCamera.fov = viewport.camera.fov;
  85471. skyCamera.zoom = 1;
  85472. }
  85473. viewport.skyboxRenderFun && viewport.skyboxRenderFun();
  85474. skyCamera.updateProjectionMatrix();
  85475. skyCamera.updateMatrixWorld();
  85476. viewer.renderer.render(viewer.skybox.scene, skyCamera);
  85477. } else if (background === 'gradient') {
  85478. viewer.scene.cameraBG.layers.set(Potree.config.renderLayers.bg);
  85479. viewer.renderer.render(viewer.scene.scene, viewer.scene.cameraBG);
  85480. } else if (background === 'overlayColor') {
  85481. //在不clear的前提下加一层背景色
  85482. viewer.scene.bg2.material.color.copy(viewport.backgroundColor);
  85483. viewer.scene.bg2.material.opacity = viewport.backgroundOpacity;
  85484. viewer.scene.cameraBG.layers.set(Potree.config.renderLayers.bg2);
  85485. viewer.renderer.render(viewer.scene.scene, viewer.scene.cameraBG);
  85486. }
  85487. }
  85488. //全景图的部分和点云有点相关就不移动到这了。但是如果是showPanos模式,就不要渲染背景了。
  85489. }
  85490. /*
  85491. 关于透明度:
  85492. 由于点云和mesh是分开渲染的,且材质很不一样,所以透明和blend有冲突
  85493. 1 如果点云的blend是AdditiveBlending,也就是普通的叠加模式。
  85494. 则半透明点云的depthTest和depthWrite都为false
  85495. 这时候mesh要后渲染,且depthWrite不能为false(除非depthTest也为false),否则将被点云遮住。
  85496. 2 如果点云的blend是普通型
  85497. 则半透明点云的depthTest和depthWrite都为true。(为何depthWrite不能像mesh一样为false, 否则点云自身透明会错乱,可能因为太多points了)
  85498. 这时候若mesh全部先渲染,则 透过depthWrite为false的半透明mesh看不透明点云,mesh会完全被点云遮住。但是透明的物体就是depthWrite要为false,否则也会完全遮住点云
  85499. 即使是后渲染半透明的mesh,若透过点云看mesh,mesh会完全被点云遮住(为什么之前遇到过 透过点云看mesh,点云会显示不出)
  85500. 最终选择是先渲染不透明的mesh,然后点云,然后透明的mesh。虽然点云对mesh透明会失效。
  85501. */
  85502. renderOverlay(params) {
  85503. viewer.addTimeMark('renderOverlay', 'start');
  85504. this.renderOverlay1(params);
  85505. this.renderOverlay2(params);
  85506. viewer.addTimeMark('renderOverlay', 'end');
  85507. }
  85508. renderOverlay1(params) {
  85509. //渲染主要的mesh
  85510. var camera = params.camera ? params.camera : this.scene.getActiveCamera();
  85511. var renderer = params.renderer || this.renderer;
  85512. this.reticule.updateAtViewports(params.viewport);
  85513. renderer.setRenderTarget(params.target || null);
  85514. //为什么要在点云之后渲染,否则透明失效 、 会被点云覆盖
  85515. var cameraLayers;
  85516. if (params.cameraLayers) cameraLayers = params.cameraLayers;else {
  85517. if (params.viewport.name == "mapViewport") cameraLayers = ['bothMapAndScene', 'light'];else {
  85518. cameraLayers = ['sceneObjects', 'light', 'bothMapAndScene'];
  85519. if (!params.drawedModelOnRT) {
  85520. cameraLayers.push('model');
  85521. }
  85522. }
  85523. }
  85524. if (cameraLayers.length) {
  85525. Potree.Utils.setCameraLayers(camera, cameraLayers, params.extraEnableLayers); //透明贴图层 skybox 、reticule marker 不能遮住测量线
  85526. if ('renderBeforeCloud' in params) {
  85527. this.scene.scene.traverse(object => {
  85528. if (object.material) {
  85529. var transparent = object.material.opacity < 1 || object.material.mapTransparent || !object.material.depthTest;
  85530. Potree.Utils.updateVisible(object, 'renderOpa', params.renderBeforeCloud != transparent);
  85531. //点云之前渲染的话隐藏半透明的, 点云之后渲染的话隐藏不透明的。 depthTest==false的也最后渲染。 mapTransparent是手动加的,代表确定该贴图含有透明部分,即使opacity为1
  85532. }
  85533. }); //ground的材质中opacity为1,所以被当做不透明了
  85534. }
  85535. viewer.dispatchEvent({
  85536. type: "render.begin2",
  85537. name: 'scene',
  85538. viewport: params.viewport
  85539. });
  85540. renderer.render(this.scene.scene, camera);
  85541. if ('renderBeforeCloud' in params) {
  85542. this.scene.scene.traverse(object => {
  85543. if (object.material) {
  85544. Potree.Utils.updateVisible(object, 'renderOpa', true); //恢复
  85545. }
  85546. });
  85547. }
  85548. }
  85549. this.dispatchEvent({
  85550. type: "render.pass.scene",
  85551. viewer: viewer
  85552. });
  85553. }
  85554. renderOverlay2(params) {
  85555. //渲染剩余部分
  85556. var renderer = params.renderer || this.renderer;
  85557. var camera = params.camera ? params.camera : this.scene.getActiveCamera();
  85558. //清除深度 !!!!
  85559. renderer.clearDepth();
  85560. if (!params.magnifier) {
  85561. //测量线
  85562. this.dispatchEvent({
  85563. type: "render.pass.perspective_overlay",
  85564. camera,
  85565. screenshot: params.screenshot,
  85566. viewport: params.viewport,
  85567. renderer
  85568. });
  85569. if (!params.screenshot && params.viewport.name != "mapViewport") {
  85570. Potree.Utils.setCameraLayers(camera, ['magnifier']); //magnifier 遮住测量线
  85571. renderer.render(this.scene.scene, camera);
  85572. }
  85573. }
  85574. if (params.viewport.name != "mapViewport") {
  85575. Potree.Utils.setCameraLayers(camera, ['volume', 'transformationTool']);
  85576. //viewer.dispatchEvent({type: "render.begin2" , name:'clip&trans',viewport:params.viewport })
  85577. renderer.render(this.clippingTool.sceneVolume, camera); //official 可以删
  85578. renderer.render(this.transformationTool.scene, camera);
  85579. }
  85580. }
  85581. setLimitFar(state) {
  85582. //切换是否limitFar
  85583. viewer.mainViewport.camera.limitFar = !!state;
  85584. if (state) {
  85585. viewer.mainViewport.camera.near = 0.02;
  85586. viewer.mainViewport.camera.far = Potree.settings.displayMode == 'showPanos' ? viewer.farWhenShowPano : Potree.settings.cameraFar;
  85587. viewer.mainViewport.camera.updateProjectionMatrix();
  85588. }
  85589. }
  85590. setClipState(state) {
  85591. //有时候需要暂时关闭下clip
  85592. state = !!state;
  85593. if (this.clipUnabled == !state) return;
  85594. this.scene.volumes.filter(v => /* v.clip && */v instanceof Potree.BoxVolume).map(volume => {
  85595. volume.clip = state;
  85596. Potree.Utils.updateVisible(volume, 'setClipState', state);
  85597. });
  85598. this.clipUnabled = !state;
  85599. }
  85600. /* 大规模WebGL应用引发浏览器崩溃的几种情况及解决办法
  85601. https://blog.csdn.net/weixin_30378311/article/details/94846947 */
  85602. async render() {
  85603. var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  85604. //add params
  85605. viewer.addTimeMark('render', 'start');
  85606. var vrActive = this.renderer.xr.isPresenting;
  85607. var SiteModel = viewer.modules.SiteModel;
  85608. if (this.screenshoting && !params.screenshot) return; //正在截图
  85609. var s = SiteModel.editing && SiteModel.selected && (SiteModel.selected.buildType == 'room' || SiteModel.selected.buildType == 'floor'); //空间模型的房间选中材质是需要depth的,这时候需要绘制两次点云
  85610. Potree.settings.pointEnableRT = !this.screenshoting && (this.scene.measurements.filter(e => e.visible).length > 0 || s);
  85611. if (vrActive) {
  85612. this.renderVR();
  85613. } else {
  85614. var specialRender = !!params.viewports;
  85615. var viewports = params.viewports || this.viewports;
  85616. if (!this.needRender) {
  85617. viewports = viewports.filter(v => v.needRender); //可以渲染的条件是viewer或viewport的needRender为true
  85618. }
  85619. viewports = viewports.filter(v => v.active);
  85620. if (viewports.length > 0) {
  85621. params.viewports = viewports;
  85622. if (this.outlinePass.selectedObjects.length && this.outlinePass.edgeStrength > 0 && !params.screenshot
  85623. // || this.images360.fastTranMaskPass.enabled
  85624. ) {
  85625. var scenes = this.inputHandler.interactiveScenes.concat(this.scene.scene).concat(viewer.scene.scenePointCloud);
  85626. this.composer.render(scenes, null, this.viewports, this.renderDefault.bind(this));
  85627. } else {
  85628. await this.renderDefault(params);
  85629. }
  85630. }
  85631. if (!specialRender) this.needRender = false;
  85632. }
  85633. viewer.addTimeMark('render', 'end');
  85634. }
  85635. startScreenshot() {
  85636. var info = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  85637. var width = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 800;
  85638. var height = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 400;
  85639. var compressRatio = arguments.length > 3 ? arguments[3] : undefined;
  85640. //add
  85641. //let deferred = info.deferred || $.Deferred();
  85642. var getImageDeferred = info.getImageDeferred || $.Deferred();
  85643. var finishDeferred = info.finishDeferred || $.Deferred();
  85644. var viewerMaster = info.map ? this.mapViewer : this; //截图主体
  85645. var useMap = info.map || info.type == 'measure' || info.type.includes('prism2d');
  85646. if (Potree.settings.displayMode == 'showPanos' && viewer.mainViewport.view.isFlying('pos')) {
  85647. //如果在飞,飞完再截图
  85648. info.getImageDeferred = getImageDeferred, info.finishDeferred = finishDeferred;
  85649. var f = () => {
  85650. this.startScreenshot(info, width, height, compressRatio);
  85651. };
  85652. viewer.mainViewport.view.addEventListener('flyingDone', f, {
  85653. once: true
  85654. });
  85655. return {
  85656. getImagePromise: getImageDeferred.promise(),
  85657. finishPromise: finishDeferred.promise()
  85658. };
  85659. }
  85660. var startTime = Date.now();
  85661. //抗锯齿待加 1 post处理 2截图大张再抗锯齿缩小
  85662. this.pauseTestMaxLevel = true;
  85663. this.screenshoting = true;
  85664. console.log('startScreenshot: ' + startTime);
  85665. var updateCamera = () => {
  85666. viewports.forEach(e => {
  85667. e.view.applyToCamera(e.camera); //因为fly时只更新了view所以要强制更新下camera
  85668. this.dispatchEvent({
  85669. //update map and sprite, mapChanged
  85670. type: "camera_changed",
  85671. camera: e.camera,
  85672. viewport: e,
  85673. changeInfo: {
  85674. positionChanged: true,
  85675. changed: true
  85676. }
  85677. });
  85678. });
  85679. };
  85680. var screenshot = async () => {
  85681. var pose;
  85682. useMap && (viewer.mapViewer.needRender = true);
  85683. info.beforeScreenshot && info.beforeScreenshot();
  85684. var render = async () => {
  85685. this.needRender = true;
  85686. viewports.forEach(e => e.active = true);
  85687. if (info.useRenderTarget) {
  85688. //离屏渲染 有抗锯齿问题、在手机上速度慢 主视图一样会变内容,还是不用这个了
  85689. var {
  85690. dataUrl
  85691. } = viewerMaster.makeScreenshot(new Vector2(width, height), null, compressRatio);
  85692. } else {
  85693. //直接渲染 会改变canvas大小
  85694. var canvas = viewerMaster.renderer.domElement;
  85695. //canvas.width = width, canvas.height = height //不需要改canvas大小, 只需要 this.renderer.setSize(width, height ); 前面updateScreenSize已经执行
  85696. await viewerMaster.render({
  85697. screenshot: true,
  85698. width,
  85699. height,
  85700. resize: true,
  85701. needWaitLoadPoint: !!info.splitRenderInfo,
  85702. maxTimeForPointLoad: info.maxTimeForPointLoad
  85703. }); //需要resize
  85704. /* if(info.type.includes('prism2d')){//o.map要为true
  85705. viewer.dispatchEvent({type:'resize', viewport:viewer.mapViewer.viewports[0]}) //借用viewer通知lineMaterial resize
  85706. viewerMaster.renderOverlay()
  85707. } */
  85708. var dataUrl = canvas.toDataURL('image/png', compressRatio);
  85709. }
  85710. return dataUrl;
  85711. };
  85712. var dataUrl;
  85713. if (info.splitRenderInfo) {
  85714. //为了防崩溃,分区域批次渲染
  85715. var {
  85716. wc,
  85717. hc
  85718. } = info.splitRenderInfo;
  85719. var camera = viewer.mainViewport.camera;
  85720. var dataUrls = [];
  85721. var width_ = Math.ceil(1 / wc * width),
  85722. height_ = Math.ceil(1 / hc * height); //可能加起来比原图大,没事到时候边界会重合
  85723. viewer.updateScreenSize({
  85724. forceUpdateSize: true,
  85725. width: width_,
  85726. height: height_,
  85727. forTarget: info.useRenderTarget
  85728. }); //更新viewports相机透视 使focusOnObject在此窗口大小下
  85729. for (var i = 0; i < wc; i++) {
  85730. var col = [];
  85731. for (var j = 0; j < hc; j++) {
  85732. var left = Math.ceil((-wc / 2 + 0.5 + i) * width_),
  85733. top = Math.ceil((-hc / 2 + 0.5 + j) * height_);
  85734. camera.setViewOffset(width_, height_, left, top, width_, height_); //顺序从上到下从左到右
  85735. var _dataUrl = await render();
  85736. //Common.downloadFile(dataUrl, 'screenshot'+ i+':'+j+'.png')
  85737. col.push({
  85738. dataUrl: _dataUrl,
  85739. width: width_,
  85740. height: height_
  85741. });
  85742. }
  85743. dataUrls.push(col);
  85744. }
  85745. camera.clearViewOffset();
  85746. dataUrl = await Utils.combineImgs(dataUrls, compressRatio, width, height);
  85747. } else {
  85748. dataUrl = await render();
  85749. }
  85750. if (info.splitRenderInfo) {
  85751. viewer.viewports = [viewer.mainViewport];
  85752. }
  85753. if (!Potree.settings.isOfficial) {
  85754. Common.downloadFile(dataUrl, 'screenshot.png');
  85755. }
  85756. var finish = () => {
  85757. oldStates.viewports.forEach(old => {
  85758. //恢复相机
  85759. var viewport = viewports.find(v => v.name == old.name);
  85760. viewport.left = old.left;
  85761. viewport.bottom = old.bottom;
  85762. viewport.width = old.width;
  85763. viewport.height = old.height;
  85764. viewport.view.copy(old.view);
  85765. //viewport.view.applyToCamera(viewport.camera);
  85766. if (viewport.camera.isOrthographicCamera) {
  85767. viewport.camera.zoom = viewport.view.zoom;
  85768. }
  85769. });
  85770. viewerMaster.updateScreenSize({
  85771. forceUpdateSize: true
  85772. }); //更新像素
  85773. /* oldStates.viewports.forEach(old=>{//恢复相机
  85774. var viewport = [mapViewport, mainViewport].find(v=>v.name == old.name);
  85775. this.dispatchEvent({ //update map
  85776. type: "camera_changed",
  85777. camera: viewport.camera,
  85778. viewport : viewport
  85779. })
  85780. }) */
  85781. updateCamera();
  85782. finishDeferred.resolve({
  85783. dataUrl,
  85784. pose
  85785. });
  85786. info.map || setTimeout(() => {
  85787. if (!this.screenshoting) {
  85788. //Potree.settings.pointNoLimit = false
  85789. Potree.settings.pointDensity = 'high';
  85790. //console.warn('恢复pointDensity')
  85791. /* if(viewer.scene.pointclouds[0].material.oldSize_ ){
  85792. viewer.scene.pointclouds[0].material.size = viewer.scene.pointclouds[0].material.oldSize_
  85793. viewer.scene.pointclouds[0].material.oldSize_ = null
  85794. } */
  85795. }
  85796. }, 500); //延迟:避免连续多次截图时释放点云
  85797. this.screenshoting = false;
  85798. console.log('screenshot done: ' + startTime, 'costTime', Date.now() - startTime + 'ms');
  85799. };
  85800. {
  85801. //恢复:
  85802. this.backgroundOpacity = oldStates.bgOpacity;
  85803. this.background = oldStates.background;
  85804. this.pauseTestMaxLevel = false;
  85805. oldStates.displayMode && (Potree.settings.displayMode = oldStates.displayMode);
  85806. if (info.type == 'measure' || info.type.includes('prism2d')) {
  85807. this.modules.SiteModel.pauseUpdateEntity = false;
  85808. this.focusDatasets = null;
  85809. this.scene.measurements.forEach(e => Potree.Utils.updateVisible(e, 'screenshot', true));
  85810. info.type == 'measure' && info.measurement.setSelected(false, 'screenshot');
  85811. }
  85812. if (info.type.includes('prism2d')) {
  85813. //viewer.mapViewer.transparentBG = false;
  85814. (info.prisms || [info.prism]).forEach(prism => {
  85815. prism.changeStyleForScreenshot(false);
  85816. if (info.type == 'prism2d-single') {
  85817. prism.baseModel && (Potree.Utils.updateVisible(prism.baseModel, 'screenshot', false, 3, 'cancel'), Potree.Utils.setObjectLayers(prism.baseModel, 'model'));
  85818. prism.setEditState(false);
  85819. }
  85820. });
  85821. }
  85822. this.images360.panos.forEach(pano => {
  85823. Potree.Utils.updateVisible(pano, 'screenshot', true);
  85824. });
  85825. Potree.Utils.updateVisible(this.reticule, 'screenshot', true);
  85826. if (useMap) {
  85827. Potree.Utils.updateVisible(this.mapViewer.cursor, 'screenshot', true);
  85828. if (oldStates.attachedToViewer != this.mapViewer.attachedToViewer) {
  85829. this.mapViewer.attachToMainViewer(!!oldStates.attachedToViewer);
  85830. }
  85831. if (oldStates.attachedToViewer && this.mapViewer.splitDir != oldStates.oldSplitDir) {
  85832. this.mapViewer.changeSplitScreenDir(oldStates.oldSplitDir);
  85833. }
  85834. mapViewport.noPointcloud = oldStates.noPointcloud;
  85835. Potree.Utils.updateVisible(viewer.mapViewer.mapLayer.sceneGroup, 'screenshot-prism', true);
  85836. }
  85837. var recover = () => {
  85838. if (Potree.settings.displayMode == 'showPanos') {
  85839. viewer.images360.flyToPano({
  85840. pano: oldStates.pano,
  85841. duration: 0,
  85842. callback: () => {
  85843. finish();
  85844. }
  85845. });
  85846. } else {
  85847. finish();
  85848. }
  85849. };
  85850. if (info.ifGetPose) {
  85851. Potree.sdk.scene.getPose().done(pose_ => {
  85852. pose = pose_;
  85853. getImageDeferred.resolve({
  85854. dataUrl,
  85855. pose
  85856. });
  85857. recover();
  85858. });
  85859. } else {
  85860. recover();
  85861. }
  85862. }
  85863. }; // screenshot end
  85864. var mapViewport;
  85865. var mainViewport = this.mainViewport;
  85866. var viewports = [],
  85867. oldStates = {
  85868. viewports: [],
  85869. pano: Potree.settings.displayMode == 'showPanos' ? viewer.images360.currentPano : null,
  85870. bgOpacity: this.backgroundOpacity,
  85871. background: this.background
  85872. };
  85873. if (!info.type.includes('prism2d')) {
  85874. viewports.push(mainViewport);
  85875. mainViewport.camera.isOrthographicCamera && (mainViewport.view.zoom = mainViewport.camera.zoom);
  85876. oldStates.viewports.push(mainViewport.clone());
  85877. }
  85878. if (useMap) {
  85879. mapViewport = this.mapViewer.viewports[0];
  85880. mapViewport.view.zoom = mapViewport.camera.zoom;
  85881. viewports.push(mapViewport);
  85882. oldStates.viewports.push(mapViewport.clone());
  85883. oldStates.attachedToViewer = this.mapViewer.attachedToViewer;
  85884. oldStates.noPointcloud = mapViewport.noPointcloud;
  85885. oldStates.displayMode = Potree.settings.displayMode;
  85886. Potree.Utils.updateVisible(this.mapViewer.cursor, 'screenshot', false); //令mapCursor不可见
  85887. }
  85888. viewports.forEach(e => e.active = false); //暂停渲染
  85889. if (info.hideMarkers) {
  85890. this.images360.panos.forEach(pano => {
  85891. //令漫游点不可见
  85892. Potree.Utils.updateVisible(pano, 'screenshot', false);
  85893. });
  85894. }
  85895. Potree.Utils.updateVisible(this.reticule, 'screenshot', false); //令reticule不可见
  85896. if (info.bgOpacity != void 0) {
  85897. this.backgroundOpacity = info.bgOpacity;
  85898. }
  85899. if (info.background != void 0) {
  85900. this.background = info.background;
  85901. }
  85902. Potree.settings.pointDensity = info.pointDensity || 'screenshot';
  85903. var focusDatasets = measurements => {
  85904. this.focusDatasets = [];
  85905. measurements.forEach(measure => {
  85906. measure.points_datasets.forEach(e => {
  85907. var p = viewer.scene.pointclouds.find(a => a.dataset_id == e);
  85908. if (p && !this.focusDatasets.includes(p)) {
  85909. this.focusDatasets.push(p);
  85910. }
  85911. });
  85912. });
  85913. this.updateFpVisiDatasets();
  85914. };
  85915. if (info.type == 'measure') {
  85916. //要截图双屏
  85917. this.scene.measurements.forEach(e => Potree.Utils.updateVisible(e, 'screenshot', e == info.measurement));
  85918. info.measurement.setSelected(true, 'screenshot');
  85919. //因为分屏后位置才最终确定,才能确定是否显示出floorplan所以先分屏
  85920. if (Potree.settings.floorplanEnable) {
  85921. oldStates.oldSplitDir = this.mapViewer.splitDir;
  85922. this.mapViewer.attachToMainViewer(true, 'measure', 0.5, {
  85923. dir: 'leftRight'
  85924. });
  85925. }
  85926. viewer.updateScreenSize({
  85927. forceUpdateSize: true,
  85928. width,
  85929. height,
  85930. forTarget: info.useRenderTarget
  85931. }); //更新viewports相机透视 使focusOnObject在此窗口大小下
  85932. var begin = () => {
  85933. useMap = this.mapViewer.attachedToViewer;
  85934. updateCamera();
  85935. if (useMap) {
  85936. var waitMap = () => {
  85937. console.log('waitMap: ' + startTime, Date.now(), this.mapViewer.mapLayer.loadingInProgress);
  85938. this.mapViewer.waitLoadDone(screenshot.bind(this)); //等待地图所有加载完
  85939. };
  85940. this.waitPointLoad(waitMap, info.maxTimeForPointLoad);
  85941. } else {
  85942. this.waitPointLoad(screenshot, info.maxTimeForPointLoad);
  85943. }
  85944. };
  85945. var {
  85946. promise
  85947. } = this.focusOnObject(info.measurement, 'measure', 0, {
  85948. basePanoSize: 1024,
  85949. gotoBestView: true
  85950. //minMapWidth: THREE.Math.clamp(Math.min(viewer.bound.boundSize.x, viewer.bound.boundSize.y) / (20/* this.mapViewer.mapLayer.maps.find(e=>e.name == 'map').disabled ? 6 : 3*/), 2, 25) //有地图的话为了显示出名字需要更大范围
  85951. }); //注意:不同角度截图 得到三维的会不一样,因为focusOnObject是根据方向的
  85952. promise.done(() => {
  85953. //console.log('promise.done')
  85954. //根据当前位置更新floorplan显示
  85955. //console.log('view Pos ', this.mainViewport.view.position.toArray())
  85956. this.updateDatasetAt(true);
  85957. this.modules.SiteModel.updateEntityAt(true, {
  85958. measure: info.measurement
  85959. }); //更新测量线所在楼层,展示俯视图
  85960. if (!this.modules.SiteModel.inEntity) {
  85961. focusDatasets([info.measurement]);
  85962. }
  85963. this.modules.SiteModel.pauseUpdateEntity = true;
  85964. //console.log('currentFloor', this.modules.SiteModel.currentFloor, 'currentDataset', this.atDatasets )
  85965. var floorplanShowed = this.mapViewer.mapLayer.maps.some(e => e.name.includes('floorplan') && e.objectGroup.visible); //如果没有floorplan展示就不分屏(如果focus时飞出数据集从而不展示怎么办。尤其是俯瞰比较长的线时容易这样,或许要根据其所在数据集强制显示)
  85966. if (!floorplanShowed && this.mapViewer.attachedToViewer) {
  85967. this.mapViewer.attachToMainViewer(false); //取消分屏
  85968. viewer.updateScreenSize({
  85969. forceUpdateSize: true,
  85970. width,
  85971. height,
  85972. forTarget: info.useRenderTarget
  85973. }); //更新viewports相机透视
  85974. var {
  85975. promise: _promise
  85976. } = this.focusOnObject(info.measurement, 'measure', 0, {
  85977. basePanoSize: 1024,
  85978. gotoBestView: true
  85979. }); //因画面比例更改,重新focus
  85980. _promise.done(() => {
  85981. begin();
  85982. });
  85983. } else {
  85984. begin();
  85985. }
  85986. });
  85987. } else if (info.type.includes('prism2d')) {
  85988. var points = [],
  85989. prisms = info.type == 'prism2d-all' ? info.prisms : [info.prism];
  85990. this.mapViewer.attachToMainViewer(true, 'screenshot', 1, {/* dir:'leftRight' */});
  85991. viewer.updateScreenSize({
  85992. forceUpdateSize: true,
  85993. width,
  85994. height,
  85995. forTarget: info.useRenderTarget
  85996. }); //更新viewports相机透视 使focusOnObject在此窗口大小下
  85997. prisms.forEach(prism => {
  85998. points.push(...prism.points);
  85999. prism.setSelected(false);
  86000. prism.changeStyleForScreenshot(true, {
  86001. hideLabel: info.type != 'prism2d-all',
  86002. showName: info.type == 'prism2d-all'
  86003. });
  86004. if (info.type == 'prism2d-single') {
  86005. prism.baseModel && (Potree.Utils.updateVisible(prism.baseModel, 'screenshot', true, 3, 'add'), Potree.Utils.setObjectLayers(prism.baseModel, 'bothMapAndScene'));
  86006. prism.setEditState(true);
  86007. }
  86008. });
  86009. this.scene.measurements.forEach(e => Potree.Utils.updateVisible(e, 'screenshot', prisms.includes(e)));
  86010. this.backgroundOpacity = 0;
  86011. var {
  86012. promise: _promise2
  86013. } = this.focusOnObject({
  86014. points
  86015. }, 'prisms2d', 0, {
  86016. minMapWidth: 0.5,
  86017. onlyMap: true,
  86018. focusBoundCenter: true,
  86019. boundExpandRatio: 1.4
  86020. });
  86021. _promise2.done(() => {
  86022. updateCamera();
  86023. if (info.type == 'prism2d-all') {
  86024. //全部 带平面图
  86025. focusDatasets(prisms); //更新平面图 可能有漏洞,当不在任何一个数据集内的话?
  86026. this.mapViewer.waitLoadDone(screenshot.bind(this)); //等待地图所有加载完
  86027. } else {
  86028. //single
  86029. mapViewport.noPointcloud = false; //显示点云,而非平面图
  86030. Potree.settings.displayMode = 'showPointCloud';
  86031. Potree.Utils.updateVisible(viewer.mapViewer.mapLayer.sceneGroup, 'screenshot-prism', false);
  86032. this.waitPointLoad(screenshot, 5000);
  86033. }
  86034. });
  86035. } else {
  86036. //default
  86037. var done = () => {
  86038. updateCamera();
  86039. if (info.splitRenderInfo) {
  86040. screenshot();
  86041. } else {
  86042. this.waitPointLoad(screenshot, info.maxTimeForPointLoad);
  86043. }
  86044. };
  86045. if (info.focusObjectInfo) {
  86046. viewer.updateScreenSize({
  86047. forceUpdateSize: true,
  86048. width,
  86049. height,
  86050. forTarget: info.useRenderTarget
  86051. }); //更新viewports相机透视 使focusOnObject在此窗口大小下
  86052. var {
  86053. promise: _promise3
  86054. } = this.focusOnObject(...info.focusObjectInfo);
  86055. _promise3.done(() => {
  86056. done();
  86057. });
  86058. } else {
  86059. done();
  86060. }
  86061. }
  86062. /*
  86063. 测量线的截图因为要调用分屏的,会改变画面
  86064. 但是普通截图的话,不会改变画面
  86065. */
  86066. return {
  86067. getImagePromise: getImageDeferred.promise(),
  86068. finishPromise: finishDeferred.promise()
  86069. };
  86070. }
  86071. async waitPointLoad(done, maxTimeForPointLoad) {
  86072. var viewport = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : viewer.mainViewport;
  86073. var resolution = arguments.length > 3 ? arguments[3] : undefined;
  86074. return new Promise((resolve, reject) => {
  86075. var finish;
  86076. var dealDone = () => {
  86077. viewer.removeEventListener('update', update);
  86078. viewer.removeEventListener('overPointBudget', decreaseLevel);
  86079. finish || done && done();
  86080. finish = true;
  86081. resolve();
  86082. };
  86083. var decreaseLevel = e => {
  86084. //降点云level 但基本降完也不会再加载低等级的点云了,所以是否直接不降?即使质量不平均
  86085. if (e.restQueueSize < 10) return; //差不多完成了
  86086. var pointclouds = viewer.scene.pointclouds.filter(e => e.visibleNodes.length);
  86087. console.log('准备decreaseLevel, numVisiblePoints', e.numVisiblePoints, '最小numVisiblePoints占比', 1 / pointclouds.length);
  86088. pointclouds.forEach(pointcloud => {
  86089. var percent = pointcloud.numVisiblePoints / e.numVisiblePoints;
  86090. //console.log('numVisiblePoints占总比', pointcloud.dataset_id, percent )
  86091. if (percent < 1 / pointclouds.length) return;
  86092. var old = pointcloud.maxLevel;
  86093. var levels = pointcloud.visibleNodes.map(e => e.getLevel());
  86094. var actMaxLevel = Math.max.apply(null, levels); //实际加载到的最高的node level
  86095. pointcloud.maxLevel = actMaxLevel - 1;
  86096. console.warn(pointcloud.dataset_id, 'decreaseLevel,新maxLevel', actMaxLevel - 1, '原maxlevel', old);
  86097. });
  86098. };
  86099. /* if(Potree.settings.displayMode == 'showPointCloud'){
  86100. viewer.updateScreenSize({forceUpdateSize:true, width, height, forTarget:info.useRenderTarget})//需要先setSize才能加载范围内的点云
  86101. } */
  86102. //updateCamera()
  86103. //viewer.addEventListener('overPointBudget',decreaseLevel)
  86104. var update = () => {
  86105. //前提:已经禁止渲染,仅加载点云
  86106. var camera = viewport.forViewOffset ? viewport.forViewOffset.camera : viewport.camera;
  86107. Potree.updatePointClouds(viewer.scene.pointclouds, camera, resolution || viewport.resolution);
  86108. };
  86109. viewer.addEventListener('update', update);
  86110. update();
  86111. var maxTime = maxTimeForPointLoad || 2000;
  86112. document.hidden && (maxTime *= 6); //离开页面后会变成1秒1帧
  86113. setTimeout(() => {
  86114. if (Potree.pointsLoading && Potree.settings.displayMode == 'showPointCloud') {
  86115. //如果还在加载
  86116. viewer.addEventListener('pointsLoaded', () => {
  86117. //点云加载完时(不一定准确)
  86118. if (!finish) console.log('加载完毕', ' numVisiblePoints', Potree.numVisiblePoints);
  86119. dealDone();
  86120. }, {
  86121. once: true
  86122. });
  86123. var overTime = () => {
  86124. //超时不候(其实之后等待地图还会再加载几秒)
  86125. if (document.hidden) {
  86126. return setTimeout(overTime, maxTime);
  86127. }
  86128. if (!finish) console.warn('超时, numVisiblePoints', Potree.numVisiblePoints);
  86129. dealDone();
  86130. };
  86131. setTimeout(overTime, maxTime);
  86132. } else {
  86133. console.log('已经加载完,无需再加载点云 numVisiblePoints', Potree.numVisiblePoints);
  86134. dealDone();
  86135. }
  86136. }, 200); //先加载一段时间
  86137. });
  86138. }
  86139. focusOnObject(object, type, duration) {
  86140. var o = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  86141. //飞向热点、测量线等 。
  86142. //console.log('focusOnObject: ', object, type)
  86143. var deferred = o.deferred || $.Deferred();
  86144. var target = new Vector3(),
  86145. //相机focus的位置
  86146. position = new Vector3(),
  86147. //相机最终位置
  86148. dis; //相机距离目标
  86149. duration = duration == void 0 ? 1200 : duration;
  86150. var camera = o.endCamera || viewer.scene.getActiveCamera();
  86151. var cameraPos = camera.position.clone();
  86152. var boundSize;
  86153. if (o.dontChangeCamDir && (o.endYaw == void 0 || o.endPitch == void 0)) {
  86154. //在俯视时仅靠dir来算不准
  86155. o.endYaw = viewer.mainViewport.view.yaw;
  86156. o.endPitch = viewer.mainViewport.view.pitch;
  86157. }
  86158. var moveMap = done => {
  86159. if (this.mapViewer && !o.dontMoveMap) {
  86160. //console.log('mapFocusOn: '+target.toArray())
  86161. var minMapWidth = o.minMapWidth || 2; //截图的时候要显示的地图范围较大,为了显示出地区名字
  86162. var minBound = new Vector2(minMapWidth, minMapWidth); //针对垂直线,在地图上只有一个点
  86163. //原始的bound
  86164. var boundOri;
  86165. if (object.points) {
  86166. boundOri = new Box3();
  86167. object.points.forEach(e => {
  86168. boundOri.expandByPoint(e);
  86169. });
  86170. } else {
  86171. boundOri = object.boundingBox;
  86172. }
  86173. if (o.focusBoundCenter) {
  86174. boundOri.getCenter(target);
  86175. }
  86176. var boundSizeOri = boundOri.getSize(new Vector3());
  86177. var boundSizeMap = boundSizeOri.clone().multiplyScalar(o.boundExpandRatio || math.linearClamp(Math.max(boundSizeOri.x, boundSizeOri.y), [0.5, 30], [2.5, 1.2])); //为了能同时看清测量线和地图,当测量线较短时,扩大margin,防止地图过度放大
  86178. boundSizeMap.x = Math.max(minBound.x, boundSizeMap.x);
  86179. boundSizeMap.y = Math.max(minBound.y, boundSizeMap.y);
  86180. this.mapViewer.moveTo(target.clone(), boundSizeMap, duration, o.margin, null, done);
  86181. }
  86182. };
  86183. if (o.onlyMap) {
  86184. moveMap(() => {
  86185. deferred.resolve();
  86186. });
  86187. return {
  86188. promise: deferred.promise()
  86189. };
  86190. }
  86191. var getPosWithFullBound = (points, boundingBox, target, cameraPos) => {
  86192. //使boundingBox差不多占满屏幕时的相机到target的距离
  86193. // points 和 boundingBox 至少有一个
  86194. var scale;
  86195. if (o.dontChangeCamDir) {
  86196. var inv = camera.matrixWorldInverse;
  86197. } else {
  86198. var cameraTemp = camera.clone();
  86199. var view = viewer.mainViewport.view.clone();
  86200. view.position.copy(cameraPos);
  86201. view.lookAt(target);
  86202. if (o.endPitch != void 0) {
  86203. view.pitch = o.endPitch;
  86204. view.yaw = o.endYaw;
  86205. }
  86206. view.applyToCamera(cameraTemp);
  86207. //对镜头的bound
  86208. var inv = cameraTemp.matrixWorldInverse;
  86209. }
  86210. var bound = new Box3();
  86211. if (points) {
  86212. //使用points得到的bound更小 //如果points和boundingbox的差别较大,尤其使target和points中心不一致,那么points不一定会刚好在boundingbox内
  86213. points.forEach(e => {
  86214. var p = e.clone().applyMatrix4(inv);
  86215. bound.expandByPoint(p);
  86216. });
  86217. scale = 1.2;
  86218. } else {
  86219. bound = boundingBox.applyMatrix4(inv);
  86220. scale = 1; //0.9;
  86221. }
  86222. boundSize = bound.getSize(new Vector3());
  86223. if (o.boundScale) {
  86224. scale = o.boundScale;
  86225. }
  86226. {
  86227. boundSize.x *= scale; //稍微放大一些,不然会靠到屏幕边缘
  86228. boundSize.y *= scale;
  86229. var min = 0.0001;
  86230. boundSize.x = Math.max(min, boundSize.x);
  86231. boundSize.y = Math.max(min, boundSize.y);
  86232. }
  86233. if (camera.type == 'OrthographicCamera') {
  86234. dis = boundSize.length() / 2;
  86235. } else {
  86236. var aspect = boundSize.x / boundSize.y;
  86237. if (camera.aspect > aspect) {
  86238. //视野更宽则用bound的纵向来决定
  86239. dis = boundSize.y / 2 / Math.tan(MathUtils.degToRad(camera.fov / 2)) + boundSize.z / 2;
  86240. } else {
  86241. var hfov = cameraLight.getHFOVForCamera(camera, true);
  86242. dis = boundSize.x / 2 / Math.tan(hfov / 2) + boundSize.z / 2;
  86243. }
  86244. dis += camera.near;
  86245. }
  86246. dis = Math.max(0.1, dis);
  86247. //三个顶点以上的由于measure的中心不等于bound的中心,所以点会超出bound外。 且由于视椎近大远小,即使是两个点的,bound居中后线看上去仍旧不居中.
  86248. //获得相机最佳位置
  86249. var dir;
  86250. if (o.dontChangeCamDir) {
  86251. dir = viewer.mainViewport.view.direction.negate();
  86252. } else {
  86253. dir = new Vector3().subVectors(cameraPos, target).normalize();
  86254. }
  86255. if (o.dontLookUp && dir.z < 0) {
  86256. dir.negate();
  86257. }
  86258. position.copy(target).add(dir.multiplyScalar(dis));
  86259. if (false) {
  86260. //打开以检查box
  86261. if (!this.boundBox) {
  86262. //调试
  86263. this.boundBox = new Mesh(new BoxGeometry(1, 1, 1, 1));
  86264. this.boundBox.material.wireframe = true;
  86265. this.boundBox.up.set(0, 0, 1);
  86266. Potree.Utils.setObjectLayers(this.boundBox, 'sceneObjects');
  86267. this.scene.scene.add(this.boundBox);
  86268. }
  86269. this.boundBox.position.copy(target);
  86270. this.boundBox.scale.copy(boundSize);
  86271. this.boundBox.lookAt(position);
  86272. }
  86273. return position;
  86274. };
  86275. if (this.images360.flying) {
  86276. var f = () => {
  86277. this.focusOnObject(object, type, duration, $.extend(o, {
  86278. deferred
  86279. }));
  86280. this.images360.removeEventListener('cameraMoveDone', f);
  86281. };
  86282. this.images360.addEventListener('cameraMoveDone', f);
  86283. return {
  86284. promise: deferred.promise()
  86285. };
  86286. }
  86287. if (type == 'measure') {
  86288. if (object.points.length == 0) {
  86289. return {
  86290. promise: deferred.resolve()
  86291. };
  86292. }
  86293. target.copy(object.getCenter());
  86294. //试试改变位置(方向),直视测量线。能避免倾斜角度造成的非常不居中、以及看不到面的情况
  86295. if (o.gotoBestView) {
  86296. //直接沿着法线方向看
  86297. if (object.points.length > 2) {
  86298. var facePlane = object.getFacePlane(target);
  86299. var normal = facePlane.normal.clone();
  86300. if (normal.dot(this.mainViewport.view.direction) > 0) {
  86301. normal.negate(); //顺着视线
  86302. }
  86303. //normal.z = Math.max(0.2, normal.z)//尽量不要仰视
  86304. cameraPos.copy(target).add(normal);
  86305. } else {
  86306. var lineDir = new Vector3().subVectors(object.points[0], object.points[1]).normalize();
  86307. var _facePlane = new Plane().setFromNormalAndCoplanarPoint(lineDir, target);
  86308. //if(cameraPos.z < target.z + 1)cameraPos.z = target.z + 1//尽量不要仰视
  86309. var dir = new Vector3().subVectors(cameraPos, target).normalize();
  86310. dir.z = Math.max(dir.z, 0.4);
  86311. cameraPos.copy(target).add(dir); //尽量不要仰视
  86312. var _dis = cameraPos.distanceTo(target);
  86313. dir = lineDir.clone().multiplyScalar(_dis);
  86314. var line = new Line3().set(cameraPos.clone().add(dir), cameraPos.clone().add(dir.negate())); //过相机位置作到面的垂线
  86315. _facePlane.intersectLine(line, cameraPos); //得垂足,作为新的相机位置。就能在测量线中间看测量线
  86316. }
  86317. } else {
  86318. if (object.points.length > 2) {
  86319. var _facePlane2 = object.getFacePlane(target);
  86320. var _normal = _facePlane2.normal.clone();
  86321. var angle = this.mainViewport.view.direction.angleTo(_normal);
  86322. var minDiff = MathUtils.degToRad(60);
  86323. //console.log('angle',angle)
  86324. if (angle > minDiff && angle < Math.PI - minDiff) {
  86325. //当几乎正对时就不执行
  86326. if (angle < Math.PI / 2) {
  86327. //在背面
  86328. _normal.negate();
  86329. }
  86330. var _dir = new Vector3().subVectors(camera.position, target).normalize();
  86331. var newDir = new Vector3().addVectors(_dir, _normal); //两个角度的中间
  86332. cameraPos.copy(target.clone().add(newDir));
  86333. }
  86334. } else if (object.points.length == 2) {
  86335. //线段
  86336. var _lineDir = new Vector3().subVectors(object.points[0], object.points[1]).normalize();
  86337. var _angle = this.mainViewport.view.direction.angleTo(_lineDir);
  86338. var maxDiff = Math.PI * 0.25; // 45度
  86339. if (_angle < maxDiff || _angle > Math.PI - maxDiff) {
  86340. //当几乎正对时就不执行
  86341. if (_angle > Math.PI / 2) {
  86342. //令dir和lineDir成钝角
  86343. _lineDir.negate();
  86344. }
  86345. var _dir2 = new Vector3().subVectors(camera.position, target).normalize();
  86346. var mid = new Vector3().addVectors(_lineDir, _dir2).normalize(); //中间法向量(如果刚好dir和lineDir反向,那得到的为零向量,就不移动了,但一般不会酱紫吧)
  86347. var _newDir = new Vector3().addVectors(_dir2, mid);
  86348. cameraPos.copy(target.clone().add(_newDir));
  86349. }
  86350. } else {
  86351. console.error('measure 没有facePlane points点数还不为2?');
  86352. }
  86353. }
  86354. //截图时直接飞到最佳视角,也就是平视它所在面。其余时候为了避免镜头旋转过大就算了。
  86355. position = getPosWithFullBound(object.points, null, target, cameraPos);
  86356. moveMap();
  86357. if (Potree.settings.displayMode == 'showPointCloud') {
  86358. //点云
  86359. var minDis = 0.3;
  86360. if (0) {
  86361. //如果没有被选中,会被遮挡。 2023.11.15 最好展示全局(尤其截图时),虽然被遮挡,但focus的过程是选中状态全显示的,可以看出所在范围。
  86362. var checkIntersect = () => {
  86363. var intersect = this.inputHandler.ifBlockedByIntersect({
  86364. point: position,
  86365. cameraPos: target
  86366. }); // 不一定准确
  86367. if (intersect) {
  86368. var blockCount = 0,
  86369. unblockCount = 0,
  86370. visi;
  86371. for (var i = 0; i < object.points.length; i++) {
  86372. //如果顶点超过一半不可见,就要更改位置
  86373. var p = object.points[i];
  86374. var blocked = this.inputHandler.ifBlockedByIntersect({
  86375. point: p,
  86376. margin: 0.3,
  86377. cameraPos: position,
  86378. pickWindowSize: 4
  86379. });
  86380. if (blocked) {
  86381. blockCount++;
  86382. if (blockCount / object.points.length >= 0.5) {
  86383. visi = false;
  86384. break;
  86385. }
  86386. } else {
  86387. unblockCount++;
  86388. if (unblockCount / object.points.length > 0.5) {
  86389. visi = true;
  86390. break;
  86391. }
  86392. }
  86393. }
  86394. if (visi == void 0) {
  86395. visi = unblockCount / object.points.length > 0.5;
  86396. }
  86397. var shrink = () => {
  86398. var dir = new Vector3().subVectors(position, target).normalize().multiplyScalar(intersect.distance);
  86399. position.copy(target).add(dir);
  86400. console.log('checkIntersect newPos', position.clone());
  86401. };
  86402. if (!visi) {
  86403. //更改位置距离target如果小于最小距离,需要反向。 否则直接缩短距离。
  86404. if (intersect.distance < minDis) {
  86405. console.log('检测到intersect 反向', intersect.distance);
  86406. var position1 = position.clone();
  86407. var _dir3 = new Vector3().subVectors(position, target);
  86408. position.copy(target).sub(_dir3);
  86409. var intersect2 = this.inputHandler.ifBlockedByIntersect({
  86410. point: position,
  86411. cameraPos: target
  86412. }); // 不一定准确
  86413. if (intersect2) {
  86414. if (intersect2.distance < intersect.distance) {
  86415. position.copy(position1); //恢复
  86416. }
  86417. shrink();
  86418. }
  86419. } else {
  86420. shrink();
  86421. }
  86422. }
  86423. }
  86424. };
  86425. checkIntersect();
  86426. //多折线没有areaPlane 有时候会看向空白区域 - -
  86427. }
  86428. } else if (Potree.settings.displayMode == 'showPanos') {
  86429. //全景 (比较难校准)
  86430. var target2, _dir4;
  86431. if (object.measureType.includes('MulDistance')) {
  86432. //因为该线不闭合,可能看向target的方向会没有线,所以换一个target
  86433. target2 = object.points[Math.round(object.points.length / 2)]; //直接看向中间点
  86434. _dir4 = new Vector3().subVectors(target2, position).normalize();
  86435. }
  86436. var pano = viewer.images360.fitPanoTowardPoint({
  86437. /*point : target, //不使用目标点来判断是因为缺少measure角度的信息。比如虽然可以靠近线的中心,但是线朝向屏幕,那几乎就是一个点了。
  86438. //bestDistance : dis * 0.5, //乘以小数是为了尽量靠近
  86439. boundSphere: boundOri.getBoundingSphere(new THREE.Sphere), */
  86440. target,
  86441. dir: _dir4,
  86442. point: position,
  86443. bestDistance: 0,
  86444. checkIntersect: o.checkIntersect,
  86445. gotoBestView: o.gotoBestView
  86446. });
  86447. var result = {
  86448. promise: deferred.promise()
  86449. };
  86450. if (pano && pano.msg) {
  86451. pano = pano.pano;
  86452. result.msg = pano.msg;
  86453. }
  86454. if (pano) {
  86455. viewer.images360.flyToPano({
  86456. pano,
  86457. target: target2 || target,
  86458. duration,
  86459. deferred,
  86460. dontMoveMap: true,
  86461. basePanoSize: o.basePanoSize
  86462. }); //dontMoveMap不要移动map,否则flytopano会自动在map中focus到漫游点的位置,而非测量线了
  86463. if (viewer.images360.currentPano == pano) {
  86464. var dis1 = viewer.images360.currentPano.position.distanceTo(target);
  86465. var dis2 = position.distanceTo(target);
  86466. //console.log('dis1 / dis2',dis1 / dis2, 'dis1-dis2', dis1-dis2)
  86467. return {
  86468. msg: dis1 / dis2 > 1.5 && dis1 - dis2 > 10 ? 'tooFar' : 'posNoChange',
  86469. promise: deferred.promise()
  86470. };
  86471. }
  86472. }
  86473. return result;
  86474. /* if(viewer.images360.currentPano == pano){
  86475. let dis1 = viewer.images360.currentPano.position.distanceTo(target)
  86476. let dis2 = position.distanceTo(target)
  86477. //console.log('dis1 / dis2',dis1 / dis2, 'dis1-dis2', dis1-dis2)
  86478. return {msg: (dis1 / dis2 > 1.5 && dis1-dis2>10)? 'tooFar' : 'posNoChange', promise : deferred.promise() }
  86479. }else{
  86480. return {promise : deferred.promise()}
  86481. } */
  86482. //出现过到达位置后测量线标签闪烁的情况
  86483. // 测量线截图 全景 最好能放大. 但要确保该位置放大后图片加载完有点困难
  86484. }
  86485. } else if (type == 'tag' || type == 'point') {
  86486. //dimension = 1
  86487. target.copy(object.position);
  86488. var bestDistance = o.distance || 3;
  86489. if (!o.dontMoveMap && this.mapViewer) {
  86490. //console.log('mapFocusOn: '+target.toArray())
  86491. this.mapViewer.moveTo(target.clone(), null, duration);
  86492. }
  86493. if (Potree.settings.displayMode == 'showPointCloud') {
  86494. if (o.dontChangePos) {
  86495. position.copy(cameraPos);
  86496. } else {
  86497. dis = bestDistance;
  86498. var _dir5 = o.direction ? o.direction.clone().negate() : this.mainViewport.view.direction.negate(); // */new THREE.Vector3().subVectors(camera.position, target).normalize()
  86499. if (o.dontLookUp && _dir5.z < 0) _dir5.z *= -1;
  86500. position.copy(target).add(_dir5.multiplyScalar(dis));
  86501. }
  86502. if (o.sameFloor) {
  86503. //需要在同一楼层
  86504. var atFloor = this.modules.SiteModel.pointInWhichEntity(target, 'floor');
  86505. if (atFloor) {
  86506. var camFloor = this.modules.SiteModel.pointInWhichEntity(position, 'floor');
  86507. if (camFloor != atFloor) {
  86508. var raycaster = new Raycaster();
  86509. var origin = target;
  86510. var _dir6 = new Vector3().subVectors(position, target).normalize();
  86511. raycaster.set(origin, _dir6);
  86512. var intersect = Potree.Utils.getIntersect(null, [atFloor.box], null, raycaster);
  86513. if (intersect) {
  86514. var _dis2 = MathUtils.clamp(intersect.distance - 0.2, camera.near, intersect.distance);
  86515. position.addVectors(origin, _dir6.multiplyScalar(_dis2));
  86516. console.log('移动到楼层');
  86517. } else {
  86518. console.error('?no intersect?');
  86519. }
  86520. }
  86521. }
  86522. }
  86523. if (o.checkIntersect) {
  86524. //识别被点云遮住的话
  86525. var _intersect; //反向查找从target到相机的第一个intersect
  86526. _intersect = this.inputHandler.ifBlockedByIntersect({
  86527. point: position,
  86528. margin: 0,
  86529. cameraPos: target
  86530. } /* {point:target, margin: 0.2, cameraPos:position} */);
  86531. if (_intersect) {
  86532. position.copy(_intersect.location);
  86533. console.log('移近');
  86534. }
  86535. }
  86536. } else if (Potree.settings.displayMode == 'showPanos') {
  86537. var _pano = viewer.images360.fitPanoTowardPoint({
  86538. point: target,
  86539. dir: this.mainViewport.view.direction,
  86540. //尽量不改相机方向,避免镜头晃动
  86541. checkIntersect: o.checkIntersect,
  86542. sameFloor: o.sameFloor,
  86543. bestDistance,
  86544. maxDis: o.maxDis //越近越好,但不要太近,bestDistance左右差不多
  86545. });
  86546. var _result = {
  86547. promise: deferred.promise()
  86548. };
  86549. if (_pano && _pano.msg) {
  86550. _pano = _pano.pano;
  86551. _result.msg = _pano.msg;
  86552. }
  86553. _pano && viewer.images360.flyToPano({
  86554. pano: _pano,
  86555. target,
  86556. duration,
  86557. deferred,
  86558. dontMoveMap: true,
  86559. basePanoSize: o.basePanoSize
  86560. });
  86561. return _result;
  86562. }
  86563. } else if (object.boundingBox && type == 'boundingBox') {
  86564. //使屏幕刚好看全boundingBox
  86565. target = object.boundingBox.getCenter(new Vector3());
  86566. if (o.dir) {
  86567. //指定方向
  86568. cameraPos.copy(target).sub(o.dir);
  86569. }
  86570. position = getPosWithFullBound(object.points, object.boundingBox.clone(), target, cameraPos);
  86571. if (Potree.settings.displayMode == 'showPanos') {
  86572. //全景 (比较难校准)
  86573. var _pano2 = viewer.images360.fitPanoTowardPoint({
  86574. point: position,
  86575. bestDistance: 0
  86576. });
  86577. var _result2 = {
  86578. promise: deferred.promise()
  86579. };
  86580. if (_pano2 && _pano2.msg) {
  86581. _pano2 = _pano2.pano;
  86582. _result2.msg = _pano2.msg;
  86583. }
  86584. _pano2 && viewer.images360.flyToPano({
  86585. pano: _pano2,
  86586. target,
  86587. duration,
  86588. deferred,
  86589. dontMoveMap: true,
  86590. basePanoSize: o.basePanoSize
  86591. }); //dontMoveMap不要移动map,否则flytopano会自动在map中focus到漫游点的位置,而非测量线了
  86592. if (!_pano2) {
  86593. console.error('no pano');
  86594. }
  86595. return _result2;
  86596. //出现过到达位置后测量线标签闪烁的情况
  86597. } else {
  86598. /* if(o.dontChangeCamDir){
  86599. target = null
  86600. } */
  86601. moveMap();
  86602. }
  86603. }
  86604. if (o.startCamera && o.endCamera) {
  86605. viewer.mainViewport.view.tranCamera(this.mainViewport, {
  86606. endPosition: position,
  86607. target,
  86608. boundSize,
  86609. callback: () => {
  86610. //console.log('focusOnObjectSuccess: '+object.name, type)
  86611. deferred.resolve();
  86612. },
  86613. startCamera: o.startCamera,
  86614. endCamera: o.endCamera,
  86615. midCamera: this.scene.cameraBasic,
  86616. endYaw: o.endYaw,
  86617. endPitch: o.endPitch
  86618. }, duration);
  86619. } else if (camera.type == "OrthographicCamera") {
  86620. viewer.mainViewport.view.moveOrthoCamera(this.mainViewport, {
  86621. endPosition: position,
  86622. target,
  86623. boundSize,
  86624. endYaw: o.endYaw,
  86625. endPitch: o.endPitch,
  86626. callback: () => {
  86627. //console.log('focusOnObjectSuccess: '+object.name, type)
  86628. deferred.resolve();
  86629. }
  86630. }, duration);
  86631. } else {
  86632. viewer.mainViewport.view.setView({
  86633. position,
  86634. target,
  86635. duration,
  86636. endYaw: o.endYaw,
  86637. endPitch: o.endPitch,
  86638. callback: () => {
  86639. //console.log('focusOnObjectSuccess: '+object.name, type)
  86640. deferred.resolve();
  86641. }
  86642. });
  86643. }
  86644. this.dispatchEvent({
  86645. type: 'focusOnObject',
  86646. CamTarget: target,
  86647. position
  86648. }); //给controls发送信息
  86649. return {
  86650. promise: deferred.promise()
  86651. };
  86652. }
  86653. flyToDataset() {
  86654. var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  86655. var pointcloud;
  86656. if (o instanceof Object3D) pointcloud = o;else if (o.pointcloud) pointcloud = o.pointcloud;else pointcloud = this.scene.pointclouds.find(p => p.dataset_id == o.id);
  86657. var duration = o.duration == void 0 ? 1000 : o.duration;
  86658. if (o.focusOnPoint || !pointcloud.panosBound) {
  86659. //focus点云上一点,避免center区域刚好没有点
  86660. if (pointcloud.root.geometryNode) {
  86661. var posArr = pointcloud.root.geometryNode.geometry.attributes.position.array;
  86662. var count = pointcloud.root.geometryNode.geometry.attributes.position.count;
  86663. var index = Math.ceil(count / 2); //随便取一个点
  86664. var point = new Vector3(posArr[index * 3 + 0], posArr[index * 3 + 1], posArr[index * 3 + 2]);
  86665. //point.applyMatrix4(pointcloud.root.pointcloud.matrixWorld)
  86666. point.applyMatrix4(pointcloud.root.sceneNode.matrixWorld);
  86667. viewer.focusOnObject({
  86668. position: point
  86669. }, 'point', duration, {
  86670. dontChangeCamDir: true,
  86671. distance: 15
  86672. });
  86673. o.dontMoveMap || viewer.mapViewer.fitToPointcloud(pointcloud, duration);
  86674. console.log('flyToDataset focusOnPoint done');
  86675. return;
  86676. }
  86677. }
  86678. var center = pointcloud.bound.getCenter(new Vector3());
  86679. var position;
  86680. var getPano = () => {
  86681. //获取离中心最近的pano
  86682. var request = [];
  86683. var rank = [Images360.scoreFunctions.distanceSquared({
  86684. position: center
  86685. })];
  86686. var r = Common.sortByScore(pointcloud.panos, request, rank);
  86687. if (r.length) {
  86688. return r[0].item;
  86689. }
  86690. };
  86691. if (Potree.settings.displayMode == 'showPanos') {
  86692. var pano = getPano();
  86693. if (pano) {
  86694. if (pano == this.images360.currentPano) return 'posNoChange';
  86695. this.images360.flyToPano({
  86696. pano
  86697. });
  86698. } else return false;
  86699. } else {
  86700. var target;
  86701. position = center;
  86702. if (pointcloud.panosBound) {
  86703. var panosCenter = pointcloud.panosBound.center; //pano集中的地方,也就是真正有点云的地方
  86704. position = panosCenter.clone();
  86705. /* let ratio = 0.2
  86706. position.z = center.z * ratio + panosCenter.z * (1-ratio) //因为panos一般比较低,为了不让相机朝下时看不到点云,加一丢丢中心高度
  86707. */
  86708. var _pano3 = getPano();
  86709. if (_pano3) {
  86710. target = _pano3.position; //针对像隧道一样的场景, 中心点还是panosCenter都在没有点云的地方,所以还是看向其中一个漫游点好。
  86711. position.z = target.z; //水平, 避免朝上或朝下
  86712. }
  86713. }
  86714. if (this.modules.Clip.editing) {
  86715. position.z = center.z; //剪裁时在中心高度,因为以点云为重点
  86716. this.modules.Clip.bus.dispatchEvent({
  86717. type: 'flyToPos',
  86718. position,
  86719. duration
  86720. });
  86721. } else {
  86722. if (math.closeTo(position, this.images360.position)) return 'posNoChange';
  86723. viewer.mainViewport.view.setView({
  86724. position,
  86725. target,
  86726. duration
  86727. });
  86728. }
  86729. o.dontMoveMap || viewer.mapViewer.fitToPointcloud(pointcloud, duration);
  86730. }
  86731. return true;
  86732. }
  86733. findClosestDatasetOnMap(position) {
  86734. //寻找当前平面图上离某点最近的数据集
  86735. var pointclouds = viewer.scene.pointclouds.filter(e => e.visible);
  86736. var addScore = viewer.bound.boundSize.length();
  86737. var r = Potree.Common.sortByScore(pointclouds, [], [e => {
  86738. //pos2d和bound2d距离排序
  86739. var pos3d = position.clone().setZ(e.panosBound ? e.panosBound.center.z : (e.bound.min.z + e.bound.max.z) / 2);
  86740. return -(e.panosBound ? e.panosBound.bounding : e.bound).distanceToPoint(pos3d);
  86741. }, e => {
  86742. //最有可能的是地图上显示的平面图
  86743. return e in viewer.fpVisiDatasets ? addScore : 0;
  86744. }]);
  86745. return r[0] && r[0].item;
  86746. }
  86747. addTimeMark(name, type) {
  86748. var record = Potree.timeCollect[name];
  86749. var needRecord = record && record.start && record.measures.length < record.minCount;
  86750. if (needRecord || Potree.measureTimings) {
  86751. performance.mark(name + "-" + type);
  86752. if (type == 'end') {
  86753. var measure = performance.measure(name, name + "-start", name + "-end");
  86754. if (needRecord) {
  86755. record.measures.push(measure.duration);
  86756. record.sum += measure.duration;
  86757. record.ave = record.sum / record.measures.length;
  86758. record.measures.sort((a, b) => a - b);
  86759. record.median = record.measures[parseInt(record.measures.length / 2)];
  86760. }
  86761. }
  86762. }
  86763. }
  86764. addFakeMeasure(name, duration) {
  86765. //把一些count当做duration来统计
  86766. if (!Potree.measureTimings) return;
  86767. if (!this.fakeMeasure[name]) {
  86768. this.fakeMeasure[name] = [];
  86769. }
  86770. var object = {
  86771. name,
  86772. duration
  86773. };
  86774. this.fakeMeasure[name].push(object);
  86775. }
  86776. resolveTimings(timestamp, log) {
  86777. //打印用时。 注:performance手机的精度只到整数位 。 sidebar中监听update时有高cpu的函数所以不要用demo测
  86778. if (!this.toggle) {
  86779. this.toggle = timestamp;
  86780. }
  86781. var duration = timestamp - this.toggle;
  86782. if (duration > 1000.0) {
  86783. if (log) {
  86784. var measures = performance.getEntriesByType("measure");
  86785. for (var i in this.fakeMeasure) {
  86786. measures.push(...this.fakeMeasure[i]);
  86787. }
  86788. var names = new Set();
  86789. for (var measure of measures) {
  86790. names.add(measure.name);
  86791. }
  86792. var groups = new Map();
  86793. for (var name of names) {
  86794. groups.set(name, {
  86795. measures: [],
  86796. sum: 0,
  86797. n: 0,
  86798. min: Infinity,
  86799. max: -Infinity
  86800. });
  86801. }
  86802. for (var _measure of measures) {
  86803. var group = groups.get(_measure.name);
  86804. group.measures.push(_measure);
  86805. group.sum += _measure.duration;
  86806. group.n++;
  86807. group.min = Math.min(group.min, _measure.duration);
  86808. group.max = Math.max(group.max, _measure.duration);
  86809. }
  86810. /* let glQueries = Potree.resolveQueries(this.renderer.getContext()); // resolveQueries 无
  86811. for(let [key, value] of glQueries){
  86812. let group = {
  86813. measures: value.map(v => {return {duration: v}}),
  86814. sum: value.reduce( (a, i) => a + i, 0),
  86815. n: value.length,
  86816. min: Math.min(...value),
  86817. max: Math.max(...value)
  86818. };
  86819. let groupname = `[tq] ${key}`;
  86820. groups.set(groupname, group);
  86821. names.add(groupname);
  86822. } */
  86823. for (var [_name, _group] of groups) {
  86824. _group.mean = _group.sum / _group.n;
  86825. /* group.measures.sort( (a, b) => a.duration - b.duration );
  86826. if(group.n === 1){
  86827. group.median = group.measures[0].duration;
  86828. }else if(group.n > 1){
  86829. group.median = group.measures[parseInt(group.n / 2)].duration;
  86830. }
  86831. */
  86832. var _measures = _group.measures.slice();
  86833. _measures.sort((a, b) => a.duration - b.duration);
  86834. if (_group.n === 1) {
  86835. _group.median = _measures[0].duration;
  86836. } else if (_group.n > 1) {
  86837. _group.median = _measures[parseInt(_group.n / 2)].duration;
  86838. }
  86839. }
  86840. var cn = Array.from(names).reduce((a, i) => Math.max(a, i.length), 0) + 5;
  86841. var cmin = 6;
  86842. var cmed = 6;
  86843. var cmax = 6;
  86844. var csam = 4;
  86845. var message = " ".concat("NAME".padEnd(cn), " |") + " ".concat("MIN".padStart(cmin), " |") + " ".concat("MEDIAN".padStart(cmed), " |") + " ".concat("MAX".padStart(cmax), " |") + " ".concat("AVE".padStart(cmax), " |") + " ".concat("SAMPLES".padStart(csam), " \n");
  86846. message += " ".concat("-".repeat(message.length), "\n");
  86847. names = Array.from(names).sort();
  86848. for (var _name2 of names) {
  86849. var _group2 = groups.get(_name2);
  86850. var min = _group2.min.toFixed(3);
  86851. var median = _group2.median.toFixed(3);
  86852. var max = _group2.max.toFixed(3);
  86853. var ave = _group2.mean.toFixed(3); //add
  86854. var n = _group2.n;
  86855. message += " ".concat(_name2.padEnd(cn), " |") + " ".concat(min.padStart(cmin), " |") + " ".concat(median.padStart(cmed), " |") + " ".concat(max.padStart(cmax), " |") + " ".concat(ave.padStart(cmax), " |") + " ".concat(n.toString().padStart(csam), "\n");
  86856. }
  86857. message += "\n";
  86858. console.log(message);
  86859. }
  86860. this.fakeMeasure = {}; //clear
  86861. performance.clearMarks();
  86862. performance.clearMeasures();
  86863. this.toggle = timestamp;
  86864. }
  86865. //注意,console.log本身用时挺高,降4倍时可能占用0.5毫秒,所以不能每帧都打印
  86866. }
  86867. loop(timestamp) {
  86868. //let startTime = performance.now()
  86869. //console.log('间隔:' /*, parseInt((startTime - this.lastEndTime)*100 )/100 */)
  86870. if (this.paused) return;
  86871. if (performance.getEntriesByName("loopWaitNext-start").length) viewer.addTimeMark('loopWaitNext', 'end');
  86872. if (this.stats) {
  86873. this.stats.begin();
  86874. }
  86875. performance.mark('loop-start'); // 无论有没有reportTimings都要获取,因为getBestCound需要
  86876. this.dispatchEvent('loopStart');
  86877. this.interacted = false;
  86878. this.shelterCount = {
  86879. byTex: 0,
  86880. byCloud: 0,
  86881. maxByTex: 100,
  86882. maxByCloud: 0
  86883. }; //清空 因ifPointBlockedByIntersect可能在任何时候触发,所以需要一开始就定义这个,且每次计算最大可计算次数太麻烦了就定义一个吧。
  86884. var deltaTime = this.clock.getDelta();
  86885. this.update(deltaTime, timestamp);
  86886. this.magnifier.render();
  86887. this.render();
  86888. this.setAllTilesets(model => model.runtime.update(deltaTime, this.renderer, this.mainViewport.camera));
  86889. // let vrActive = viewer.renderer.xr.isPresenting;
  86890. // if(vrActive){
  86891. // this.update(this.clock.getDelta(), timestamp);
  86892. // this.render();
  86893. // }else{
  86894. // this.update(this.clock.getDelta(), timestamp);
  86895. // this.render();
  86896. // }
  86897. Potree.framenumber++;
  86898. //-------------
  86899. this.images360.tileDownloader.update();
  86900. this.images360.panoRenderer.update();
  86901. this.images360.getNeighbours(this.interacted);
  86902. this.computeShelter();
  86903. //-------------
  86904. if (this.stats) {
  86905. this.stats.end();
  86906. }
  86907. viewer.addTimeMark('loop', 'end');
  86908. viewer.addTimeMark('loopWaitNext', 'start');
  86909. this.resolveTimings(timestamp, Potree.measureTimings);
  86910. //Potree.measureTimings = 1
  86911. }
  86912. postError(content) {
  86913. var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  86914. var message = this.postMessage(content, params);
  86915. message.element.addClass("potree_message_error");
  86916. return message;
  86917. }
  86918. postMessage(content) {
  86919. var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  86920. var message = new Message(content);
  86921. var animationDuration = 100;
  86922. message.element.css("display", "none");
  86923. message.elClose.click(() => {
  86924. message.element.slideToggle(animationDuration);
  86925. var index = this.messages.indexOf(message);
  86926. if (index >= 0) {
  86927. this.messages.splice(index, 1);
  86928. }
  86929. });
  86930. this.elMessages.prepend(message.element);
  86931. message.element.slideToggle(animationDuration);
  86932. this.messages.push(message);
  86933. if (params.duration !== undefined) {
  86934. var fadeDuration = 500;
  86935. var slideOutDuration = 200;
  86936. setTimeout(() => {
  86937. message.element.animate({
  86938. opacity: 0
  86939. }, fadeDuration);
  86940. message.element.slideToggle(slideOutDuration);
  86941. }, params.duration);
  86942. }
  86943. return message;
  86944. }
  86945. getBoundingBox(pointclouds) {
  86946. //可以直接返回viewer.bound
  86947. if (!this.bound) {
  86948. this.updateModelBound();
  86949. }
  86950. return this.bound.boundingBox.clone(); //this.scene.getBoundingBox(pointclouds);
  86951. }
  86952. updateModelBound(reason) {
  86953. this.boundNeedUpdate = false;
  86954. this.bound = Utils.computePointcloudsBound(this.scene.pointclouds.filter(pointcloud =>
  86955. //只求可见
  86956. pointcloud.visible || pointcloud.unvisibleReasons && pointcloud.unvisibleReasons.length == 1 && pointcloud.unvisibleReasons[0].reason == 'displayMode'));
  86957. if (Potree.settings.boundAddObjs) {
  86958. //加上obj的bound 需要确保都updateMatrixWorld过
  86959. this.objs.children.forEach(e => {
  86960. this.bound.boundingBox.union(e.boundingBox.clone().applyMatrix4(e.matrixWorld));
  86961. });
  86962. this.bound.boundingBox.getSize(this.bound.boundSize);
  86963. this.bound.boundingBox.getCenter(this.bound.center);
  86964. }
  86965. viewer.farWhenShowPano = this.bound.boundSize.length() * 10; //全景漫游时要能看到整个skybox 原本*2的但对于距离特远的数据集需要乘大一些否则会黑面
  86966. /* let boundPlane = new THREE.Box3()
  86967. boundPlane.expandByPoint(this.bound.boundingBox.min.clone())//最低高度为bound的最低
  86968. boundPlane.expandByPoint(this.bound.boundingBox.max.clone().setZ(this.bound.center.z))//最高高度为bound的中心高度
  86969. FirstPersonControls.boundPlane = boundPlane */
  86970. //FirstPersonControls.standardSpeed = THREE.Math.clamp( Math.sqrt(this.bound.boundSize.length() )/ 100 , 0.02,0.5); //在这个boundPlane中的速度
  86971. viewer.scene.pointclouds.forEach(e => {
  86972. //海拔范围
  86973. e.material.heightMin = this.bound.boundingBox.min.z;
  86974. e.material.heightMax = this.bound.boundingBox.max.z;
  86975. });
  86976. this.dispatchEvent({
  86977. type: 'updateModelBound'
  86978. });
  86979. }
  86980. waitForLoad(object, isLoadedCallback) {
  86981. //等待加载时显示loading。主要是贴图
  86982. this.waitQueue.push({
  86983. object,
  86984. isLoadedCallback
  86985. });
  86986. //console.warn('waitForLoad',object.id,this.waitQueue.length)
  86987. 1 === this.waitQueue.length && this.dispatchEvent({
  86988. type: "loading",
  86989. show: true
  86990. });
  86991. }
  86992. ifAllLoaded() {
  86993. if (this.waitQueue.length > 0) {
  86994. this.waitQueue = this.waitQueue.filter(function (e) {
  86995. return !e.isLoadedCallback();
  86996. });
  86997. }
  86998. //console.warn('ifAllLoaded', this.waitQueue.length)
  86999. 0 === this.waitQueue.length && this.dispatchEvent({
  87000. type: "loading",
  87001. show: false
  87002. });
  87003. }
  87004. cancelLoad(object) {
  87005. //add 突然出现还没加载完就被deactivateTiledPano但还在loading的情况,所以加了这个
  87006. this.waitQueue = this.waitQueue.filter(function (e) {
  87007. return e.object != object;
  87008. });
  87009. //console.log('cancelLoad', object.id)
  87010. this.ifAllLoaded();
  87011. }
  87012. setView() {
  87013. var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  87014. var callback = () => {
  87015. if (o.displayMode) {
  87016. Potree.settings.displayMode = o.displayMode;
  87017. }
  87018. if (!o.pano && o.currentPano) this.images360.currentPano = o.currentPano;
  87019. o.callback && o.callback();
  87020. };
  87021. if (o.pano != void 0) {
  87022. //pano 权重高于 position
  87023. this.images360.flyToPano(o);
  87024. } else {
  87025. this.mainViewport.view.setView($.extend({}, o, {
  87026. callback
  87027. }));
  87028. }
  87029. }
  87030. //设置点云为标准模式
  87031. setPointStandardMat(state, pointDensity, fitPointsize) {
  87032. console.log('setPointStandardMat', state);
  87033. if (state) {
  87034. if (this.pointStatesBefore) {
  87035. return console.warn('已设置过pointStatesBefore!');
  87036. }
  87037. this.pointStatesBefore = {
  87038. opacity: new Map(),
  87039. size: new Map(),
  87040. density: Potree.settings.pointDensity,
  87041. useEDL: this.getEDLEnabled(),
  87042. shape: viewer.scene.pointclouds[0].material.shape
  87043. };
  87044. viewer.scene.pointclouds.forEach(e => {
  87045. this.pointStatesBefore.opacity.set(e, e.temp.pointOpacity); //因为更改pointDensity时会自动变opacity,所以这项最先获取
  87046. this.pointStatesBefore.colorType = e.material.activeAttributeName;
  87047. fitPointsize && this.pointStatesBefore.size.set(e, e.temp.pointSize); //这项不一定有用,因为会被后期覆盖
  87048. });
  87049. if (pointDensity) Potree.settings.pointDensity = pointDensity; //万一之后切换到全景模式怎么办
  87050. if (fitPointsize) Potree.settings.sizeFitToLevel = true;
  87051. viewer.scene.pointclouds.forEach(e => {
  87052. e.material.activeAttributeName = 'rgba';
  87053. e.material.shape = Potree.PointShape['SQUARE'];
  87054. fitPointsize && e.changePointSize(Potree.config.material.realPointSize, true);
  87055. e.changePointOpacity(1);
  87056. });
  87057. viewer.setEDLEnabled(false);
  87058. } else {
  87059. if (!this.pointStatesBefore) {
  87060. return console.error('未设置过pointStatesBefore!');
  87061. }
  87062. Potree.settings.sizeFitToLevel = false;
  87063. if (pointDensity) Potree.settings.pointDensity = this.pointStatesBefore.pointDensity;
  87064. viewer.scene.pointclouds.forEach(e => {
  87065. e.material.activeAttributeName = this.pointStatesBefore.colorType;
  87066. e.changePointOpacity(this.pointStatesBefore.opacity.get(e));
  87067. e.material.shape = this.pointStatesBefore.shape;
  87068. var size = this.pointStatesBefore.size.get(e);
  87069. if (size) e.changePointSize(size);
  87070. });
  87071. viewer.setEDLEnabled(this.pointStatesBefore.useEDL);
  87072. this.pointStatesBefore = null;
  87073. }
  87074. }
  87075. //调试时显示transformControl来调节object
  87076. transformObject(object) {
  87077. var seleted = viewer.inputHandler.selection[0];
  87078. if (!object) {
  87079. //取消
  87080. seleted && viewer.inputHandler.toggleSelection(seleted);
  87081. return;
  87082. }
  87083. if (seleted && seleted != object) {
  87084. //要更换,先取消
  87085. this.transformObject(null);
  87086. }
  87087. if (!object.boundingBox) {
  87088. object.boundingBox = new Box3(); //任意大小 只是为了显示黄色外框
  87089. //??? computeBoundingBox
  87090. }
  87091. if (!viewer.inputHandler.selection.includes(object)) {
  87092. viewer.inputHandler.toggleSelection(object);
  87093. }
  87094. }
  87095. pointInWhichPointcloud(pos) {
  87096. //选择最接近中心的那个 使用boundSphere
  87097. var result = Common.sortByScore(this.scene.pointclouds, [], [pointcloud => {
  87098. var size = pointcloud.pcoGeometry.tightBoundingBox.getSize(new Vector3());
  87099. var center = pointcloud.bound.getCenter(new Vector3());
  87100. var length = size.length() / 2;
  87101. var dis = pos.distanceTo(center);
  87102. return length / dis; //到数据集中心的距离占数据集大小越小越好
  87103. }]);
  87104. //若要求更准确的话,可以使用ifContainsPoint判断一下是否在bound中
  87105. var r = result[0];
  87106. return r && r.score > 1 ? result[0].item : null;
  87107. }
  87108. /* createRoomEv(){
  87109. const environment = new RoomEnvironment();
  87110. const pmremGenerator = new THREE.PMREMGenerator( this.renderer );
  87111. }
  87112. */
  87113. modelLoaded(object) {
  87114. var fileInfo_ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  87115. var done = arguments.length > 2 ? arguments[2] : undefined;
  87116. //普通模型加载完以后
  87117. object.isModel = true;
  87118. var boundingBox = new Box3();
  87119. if (fileInfo_.parentInfo) {
  87120. object.name = fileInfo_.name;
  87121. fileInfo_.parentInfo.loadedCount++;
  87122. fileInfo_.parentInfo.modelGroup.add(object);
  87123. if (fileInfo_.parentInfo.loadedCount == fileInfo_.parentInfo.url.length) {
  87124. return this.modelLoaded(fileInfo_.parentInfo.modelGroup, fileInfo_.parentInfo, done);
  87125. } else {
  87126. return;
  87127. }
  87128. }
  87129. object.name = fileInfo_.name != void 0 ? fileInfo_.name : fileInfo_.fileType;
  87130. object.fileType = fileInfo_.fileType;
  87131. object.boundingBox = boundingBox; //未乘上matrixWorld的本地boundingBox
  87132. //object.scale.set(1,1,1);//先获取原始的大小时的boundingBox
  87133. object.opacity = 1; //初始化 记录
  87134. object.updateMatrixWorld();
  87135. if (fileInfo_.id != void 0) object.dataset_id = fileInfo_.id;
  87136. fileInfo_.loadCostTime = Date.now() - fileInfo_.loadStartTime;
  87137. /* let weight = Math.round((total / 1024 / 1024) * 100) / 100;*/
  87138. console.log('加载完毕:', fileInfo_.name, Common.getNameFromURL(fileInfo_.url), '耗时(ms)', fileInfo_.loadCostTime /* 模型数据量:' + weight + 'M' */);
  87139. if (fileInfo_.fileType == '3dTiles') {
  87140. var isGroup = !object.runtime;
  87141. var children = object.runtime ? [object] : object.children;
  87142. children.forEach(object => {
  87143. var boundingBox_ = new Box3();
  87144. var tileset = object.runtime.getTileset();
  87145. //TileHeader: tileset.root
  87146. //参见另一个工程 TileRenderer.js preprocessNode //这个坐标位置几万…… let data = boundingVolume.halfAxes //但这个似乎是premultiply( transform );过后的,可能需还原下
  87147. var json = tileset.tileset;
  87148. var box = json.root.boundingVolume.box;
  87149. if (box) {
  87150. var center = new Vector3(box[0], box[1], box[2]);
  87151. var boundSize = new Vector3();
  87152. // get the extents of the bounds in each axis
  87153. var vecX = new Vector3(box[3], box[4], box[5]);
  87154. var vecY = new Vector3(box[6], box[7], box[8]);
  87155. var vecZ = new Vector3(box[9], box[10], box[11]);
  87156. var scaleX = vecX.length();
  87157. var scaleY = vecY.length();
  87158. var scaleZ = vecZ.length();
  87159. boundingBox_.min.set(-scaleX, -scaleY, -scaleZ);
  87160. boundingBox_.max.set(scaleX, scaleY, scaleZ);
  87161. if (isGroup) {
  87162. //如果是多个拼成的,每个都保留原先在parent中的offset。 如果是外层,作为独立个体,不用理会位置信息,直接放中央。
  87163. object.position.copy(center);
  87164. object.position.z *= -1;
  87165. boundingBox_.translate(object.position); //由于是内层,其位移会改变整体的boundingbox
  87166. }
  87167. } else if (json.root.boundingVolume.sphere) {
  87168. var sphereData = json.root.boundingVolume.sphere;
  87169. var _center = new Vector3(...sphereData);
  87170. var radius = sphereData[3] / 2;
  87171. /* let sphere = new THREE.Sphere(center, radius)
  87172. let box = sphere.getBoundingBox()
  87173. boundingBox.copy(box) */
  87174. boundingBox_.min.set(-radius, -radius, -radius);
  87175. boundingBox_.max.set(radius, radius, radius);
  87176. } else {
  87177. return console.error('json boundingVolume 缺少信息');
  87178. }
  87179. //中心点居然没用。可能是漏用了什么信息,也许这和LVBADUI_qp是散的有关。
  87180. //console.log('3d tiles json',json)
  87181. json.root.refine = 'ADD';
  87182. json.refine = 'ADD';
  87183. boundingBox.union(boundingBox_);
  87184. });
  87185. } else {
  87186. Potree.Utils.setObjectLayers(object, Potree.settings.showObjectsOnMap ? 'bothMapAndScene' : 'model');
  87187. object.traverse(child => {
  87188. var is = child.isMesh || child instanceof Points || child.isLine;
  87189. if (is) {
  87190. child.renderOrder = Potree.config.renderOrders.model;
  87191. //if(Potree.settings.boundAddObjs){
  87192. child.geometry.computeBoundingBox();
  87193. //console.log(child.matrixWorld.clone())
  87194. boundingBox.union(child.geometry.boundingBox.clone().applyMatrix4(child.matrixWorld)); //但感觉如果最外层object大小不为1,要还原下scale再乘
  87195. //}//获取在scale为1时,表现出的大小
  87196. //Potree.Utils.makeTexDontResize(child.material.map)
  87197. //console.log(child.name, 'roughness',child.material.roughness,'metalness',child.material.metalness)
  87198. if (fileInfo_.unlit && !(child.material instanceof BasicMaterial) /* || object.fileType == 'glb' */) {
  87199. //注释掉是因为已经写入到loader文件里了
  87200. //let material = new THREE.MeshBasicMaterial({map:child.material.map})
  87201. var material = new BasicMaterial({
  87202. map: child.material.map,
  87203. opacity: child.material.opacity,
  87204. color: child.material.color
  87205. }); //很奇怪glb的图会使原本的MeshBasicMaterial 会偏暗,所以自己重新写
  87206. //child.material.dispose()
  87207. child.material = material;
  87208. }
  87209. if (fileInfo_.useStandandMat && !(child.material instanceof MeshStandardMaterial)) {
  87210. child.material = new MeshStandardMaterial();
  87211. child.material.roughness = 0.7;
  87212. child.material.metalness = 0.5;
  87213. }
  87214. //纯色的还是不能用BasicMaterial
  87215. }
  87216. });
  87217. }
  87218. this.objs.add(object);
  87219. if (fileInfo_.transform) {
  87220. var setTransfrom = name => {
  87221. var value = fileInfo_.transform[name];
  87222. if (!value) return;
  87223. if (value instanceof Array) {
  87224. object[name].fromArray(value);
  87225. } else {
  87226. object[name].copy(value);
  87227. }
  87228. };
  87229. setTransfrom('position');
  87230. setTransfrom('rotation');
  87231. setTransfrom('scale');
  87232. }
  87233. if (fileInfo_.moveWithPointcloud) {
  87234. object.updateMatrix();
  87235. object.matrixAutoUpdate = false;
  87236. object.matrix.premultiply(viewer.scene.pointclouds[0].transformMatrix); //默认跟随第一个数据集
  87237. object.matrixWorldNeedsUpdate = true;
  87238. }
  87239. object.updateMatrixWorld();
  87240. MergeEditor.getBoundCenter(object); //初始化
  87241. done && done(object, fileInfo_);
  87242. this.dispatchEvent({
  87243. type: 'modelLoaded',
  87244. model: object
  87245. });
  87246. //如果需要点击出现transform工具需要它有select事件 如 viewer.objs.children[1].addEventListener('select',()=>{})
  87247. }
  87248. async loadModel(fileInfo, done, onProgress_, onError) {
  87249. console.log('开始加载', fileInfo.name, Common.getNameFromURL(fileInfo.url));
  87250. var boundingBox = new Box3();
  87251. /* if(!Potree.settings.boundAddObjs){
  87252. boundingBox.min.set(-0.5,-0.5,-0.5); boundingBox.max.set(0.5,0.5,0.5)
  87253. } */
  87254. if (fileInfo.objurl) {
  87255. fileInfo.url = fileInfo.objurl, fileInfo.fileType = 'obj'; //兼容最早的
  87256. }
  87257. if (fileInfo.url instanceof Array) {
  87258. if (fileInfo.url.length == 1) {
  87259. fileInfo.url = fileInfo.url[0];
  87260. } else {
  87261. fileInfo.loadedCount = 0;
  87262. fileInfo.modelGroup = new Object3D(); //parentGroup.name = fileInfo.title
  87263. fileInfo.url.forEach((url, i) => {
  87264. var fileInfoS = Common.CloneObject(fileInfo);
  87265. fileInfoS.url = url;
  87266. fileInfoS.name = 'child-' + i;
  87267. fileInfoS.parentInfo = fileInfo;
  87268. this.loadModel(fileInfoS, done, onProgress_, onError);
  87269. });
  87270. return;
  87271. }
  87272. }
  87273. fileInfo.url = Common.dealURL(fileInfo.url); //去除'+'
  87274. fileInfo.loadStartTime = Date.now();
  87275. //let fileType = fileInfo.tilesUrl ? '3dTiles' : fileInfo.objurl ? 'obj' : 'glb'
  87276. var loadDone = (object, fileInfo_) => {
  87277. this.modelLoaded(object, fileInfo_ || fileInfo, done);
  87278. };
  87279. var onProgress = function onProgress(xhr) {
  87280. if (xhr.lengthComputable) {
  87281. var percentComplete = xhr.loaded / xhr.total * 100;
  87282. //console.log( Math.round(percentComplete, 2) + '% downloaded' );
  87283. onProgress_ && onProgress_(percentComplete);
  87284. }
  87285. };
  87286. if (fileInfo.fileType == 'obj') {
  87287. //暂时不支持数组
  87288. if (fileInfo.mtlurl) {
  87289. loaders.mtlLoader.load(fileInfo.mtlurl, materials => {
  87290. materials.preload();
  87291. loaders.objLoader.setMaterials(materials).load(fileInfo.objurl, (object, total) => {
  87292. loadDone(object /* , total, fileInfo.objurl */);
  87293. }, onProgress, onError);
  87294. }, onProgress, onError);
  87295. } else {
  87296. loaders.objLoader.load(fileInfo.objurl, (object, total) => {
  87297. loadDone(object);
  87298. }, onProgress, onError);
  87299. }
  87300. } else if (fileInfo.fileType == 'glb') {
  87301. loaders.glbLoader.unlitMat = true; //!!fileInfo.unlit
  87302. loaders.glbLoader.load(fileInfo.url, (gltf, total) => {
  87303. //console.log('loadGLTF', gltf)
  87304. loadDone(gltf.scene /* , total, fileInfo.url */);
  87305. }, onProgress, onError);
  87306. } else if (fileInfo.fileType == 'ply') {
  87307. loaders.plyLoader.load(fileInfo.url, geometry => {
  87308. var object;
  87309. console.log('ply加载完毕', geometry);
  87310. if (!geometry.index) {
  87311. //点云
  87312. object = new Points(geometry, new PointsMaterial({
  87313. vertexColors: true,
  87314. size: 0.02
  87315. }));
  87316. //141M的点云,intersect费时300ms以上
  87317. } else {
  87318. //mesh
  87319. object = new Mesh(geometry);
  87320. }
  87321. loadDone(object);
  87322. });
  87323. } else if (fileInfo.fileType == '3dTiles') {
  87324. var result = await Loader3DTiles.load({
  87325. url: fileInfo.url,
  87326. gltfLoader: loaders.glbLoader,
  87327. //renderer: SceneRenderer.renderer
  87328. options: {
  87329. //dracoDecoderPath: '../utils/loaders/DRACOLoader/draco',
  87330. //basisTranscoderPath: '../utils/loaders/KTX2Loader/basis',
  87331. maximumScreenSpaceError: fileInfo.maximumScreenSpaceError || 80,
  87332. //越小越清晰。 如果本身tiles很密很小这个值就不能很大。
  87333. //maxDepth: 100,
  87334. //maximumMemoryUsage: 100, //缓存大小,见tiles3DMaxMemory。单位M(但实际结果是 2.5*maximumMemoryUsage + 750 。超过2G会崩, 所以应该小于540) 若太小,密集的tile反复加载很卡. (任务管理器刷新网页后若内存不掉就要结束进程否则虚高)
  87335. debug: browser.urlHasValue('tilesBox'),
  87336. //show box
  87337. parent: this.scene.scene,
  87338. is4dkk: fileInfo.is4dkk,
  87339. //是否是4dkk中的模型. 通常maximumScreenSpaceError需要10
  87340. updateTime: fileInfo.updateTime //加后缀防止缓存
  87341. }
  87342. });
  87343. //console.log(result)
  87344. result.model.runtime = result.runtime;
  87345. var loaded = false;
  87346. var tileset = result.runtime.getTileset();
  87347. tileset.addEventListener('endTileLoading', function (data) {
  87348. //Tileset3D
  87349. if (data.loadingCount == 0 && !loaded) {
  87350. loaded = true;
  87351. //console.log('loaded!!!!!!!!!!!!!')
  87352. }
  87353. });
  87354. tileset.addEventListener('tileLoaded', e => {
  87355. //每一个tile加载完要更改透明度
  87356. var opacity = result.model.parent == this.objs ? result.model.opacity : result.model.parent.opacity; //最多两层
  87357. MergeEditor.changeOpacity(e.tileContent, opacity);
  87358. viewer.images360.judgeModelMat(e.tileContent);
  87359. //set Layers ?
  87360. Potree.Utils.setObjectLayers(e.tileContent, Potree.settings.showObjectsOnMap ? 'bothMapAndScene' : 'model');
  87361. });
  87362. {
  87363. var vi = true;
  87364. Object.defineProperty(result.model, "visible", {
  87365. get: function get() {
  87366. return vi;
  87367. },
  87368. set: function set(v) {
  87369. vi = v;
  87370. result.model.visiChangeCallback();
  87371. }
  87372. });
  87373. }
  87374. var v = true;
  87375. result.model.visiChangeCallback = () => {
  87376. var visi = result.model.realVisible();
  87377. tileset.visible = visi; //同步,使不加载
  87378. if (v != visi) {
  87379. tileset.nextForceUpdate = true;
  87380. v = visi;
  87381. }
  87382. };
  87383. loadDone(result.model /* , null, fileInfo.url */);
  87384. } else if (fileInfo.fileType == 'dxf') {
  87385. loaders.dxfLoader.load(fileInfo.url, object => {
  87386. loadDone(object);
  87387. }, fileInfo);
  87388. } else if (fileInfo.fileType == 'shp') {
  87389. if (viewer.transform) {
  87390. loaders.shapeLoader.transform = viewer.transform.lonlatToLocal;
  87391. }
  87392. var shp = await loaders.shapeLoader.load(fileInfo.url, fileInfo.color);
  87393. var shpModel = shp.node;
  87394. loadDone(shpModel);
  87395. } else if (fileInfo.fileType == '3dgs') {
  87396. var gsViewer = new Viewer({
  87397. rootElement: this.renderArea,
  87398. threeScene: this.scene.scene,
  87399. renderer: this.renderer,
  87400. camera: this.mainViewport.camera,
  87401. useBuiltInControls: false
  87402. //dropInMode: true,
  87403. // sharedMemoryForWorkers:false //否则 报错 Uncaught (in promise) DOMException: Failed to execute 'postMessage' on 'DedicatedWorkerGlobalScope': SharedArrayBuffer transfer requires self.crossOriginIsolated.
  87404. });
  87405. //let path = Potree.resourcePath+'/models/gaussian/bonsai.ksplat';
  87406. gsViewer.addSplatScene(fileInfo.url, {
  87407. 'streamView': true
  87408. }).then(() => {
  87409. gsViewer.start();
  87410. /* gsViewer.splatMesh.rotation.x = -2.365929590263301
  87411. gsViewer.splatMesh.position.z = 5 */
  87412. gsViewer.splatMesh.updateMatrix();
  87413. gsViewer.splatMesh.updateMatrixWorld();
  87414. gsViewer.splatMesh.visible = false;
  87415. //viewer.mainViewport.view.setView({position: new THREE.Vector3(-4.980, -5.3879, 5.4503095), quaternion:new THREE.Quaternion(0.5750,-0.2809,-0.3372,0.6903)})
  87416. gsViewer.splatMesh.onSplatTreeReadyCallback = () => {
  87417. loadDone(gsViewer.splatMesh);
  87418. var {
  87419. sceneMax,
  87420. sceneMin
  87421. } = gsViewer.splatMesh.splatTree.subTrees[0];
  87422. gsViewer.splatMesh.boundingBox.min.copy(sceneMin);
  87423. gsViewer.splatMesh.boundingBox.max.copy(sceneMax);
  87424. };
  87425. });
  87426. //window.gsViewer = gsViewer
  87427. viewer.addEventListener('render.begin2', e => {
  87428. if (e.name == 'scene') {
  87429. //gsViewer.selfDrivenUpdate()
  87430. gsViewer.update();
  87431. if (gsViewer.initialized && gsViewer.splatRenderReady) {
  87432. gsViewer.splatMesh.visible = true;
  87433. }
  87434. }
  87435. });
  87436. }
  87437. }
  87438. removeModel(model) {
  87439. this.objs.remove(model);
  87440. var dispose = e => {
  87441. e.geometry && e.geometry.dispose();
  87442. e.material && e.material.dispose();
  87443. };
  87444. model.traverse(e => {
  87445. dispose(e);
  87446. });
  87447. if (Potree.settings.boundAddObjs) {
  87448. this.updateModelBound();
  87449. }
  87450. }
  87451. setAllTilesets() {
  87452. //让所有tileset执行fun。 objs里每个model最多两层tileset
  87453. var models = arguments.length == 2 ? [arguments[0]] : this.objs.children; //如果要设定某个model的tileset,就传第一个参数
  87454. var fun = arguments[1] || arguments[0];
  87455. models.forEach(e => {
  87456. if (e.fileType == '3dTiles') {
  87457. e.traverse(child => {
  87458. if (child.runtime) {
  87459. fun(child);
  87460. return {
  87461. stopContinue: true
  87462. };
  87463. }
  87464. });
  87465. }
  87466. });
  87467. }
  87468. setDisplay(state) {
  87469. var cause = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'setDisplay';
  87470. //如果创建了iframe,主页的需要隐藏的话需要释放一些内存出来。iframe关闭前也释放下比较保险
  87471. state = !!state;
  87472. this.setAllTilesets(model => {
  87473. var tileset = model.runtime.getTileset();
  87474. Potree.Utils.updateVisible(model, cause, state);
  87475. if (!state) tileset._cache.trim(); //使下一次update时dispose所有不可见的tiles
  87476. model.runtime.update(16, this.renderer, this.mainViewport.camera, true);
  87477. if (state) this.dispatchEvent('content_changed');
  87478. });
  87479. if (state) {
  87480. Potree.pointBudget = 6 * 1000 * 1000; //先随便写一个, 随后mergeEditor.updateMemoryUsage
  87481. } else {
  87482. Potree.pointBudget = 0;
  87483. Potree.updatePointClouds(this.scene.pointclouds, this.mainViewport.camera, this.mainViewport.resolution);
  87484. this.images360.panoRenderer.disposeIdelTargets(); //如果也能清空当前使用的就好了,但是恢复就需要时间
  87485. this.images360.depthSampler.clearTexData();
  87486. }
  87487. this.dispatchEvent({
  87488. type: 'setDisplay',
  87489. state
  87490. });
  87491. this.paused = !state;
  87492. }
  87493. addFire() {
  87494. if (Potree.settings.number == 't-CwfhfqJ') {
  87495. var position = Potree.Utils.datasetPosTransform({
  87496. pointcloud: viewer.scene.pointclouds[0],
  87497. position: new Vector3(4.4318, -0.580291847759, -0.78),
  87498. fromDataset: true
  87499. });
  87500. viewer.modules.ParticleEditor.addParticle({
  87501. type: 'fire',
  87502. positions: [position],
  87503. radius: 0.42,
  87504. height: 10
  87505. });
  87506. viewer.modules.ParticleEditor.addParticle({
  87507. type: 'smoke',
  87508. positions: [new Vector3().addVectors(position, new Vector3(0, 0, 0.3))],
  87509. positionStyle: 'sphere',
  87510. positionRadius: 0.3,
  87511. sizeTween: [[0, 0.3, 0.9, 1], [0.05, 0.1, 1, 0.8]],
  87512. opacityBase: 0.2,
  87513. opacityTween: [[0, 0.3, 0.7, 0.95, 1], [0, 0.2, 1, 0.1, 0]],
  87514. velocityBase: new Vector3(0, 0, 1),
  87515. velocitySpread: new Vector3(0.2, 0.2, -0.3),
  87516. accelerationBase: 0.2,
  87517. accelerationSpread: 0.7,
  87518. radius: 0,
  87519. //particlesPerSecond : 30,
  87520. particleDeathAge: 3.0
  87521. });
  87522. viewer.modules.ParticleEditor.addParticle({
  87523. type: 'explode',
  87524. name: 'fire splash',
  87525. position: new Vector3().addVectors(position, new Vector3(0, 0, 0.3)),
  87526. size: 0.1,
  87527. sizeRange: 0.3,
  87528. sizeTween: [[0, 0.05, 0.3, 0.45], [0, 0.02, 0.1, 0.05]],
  87529. opacityTween: [[0, 0.05, 0.3, 0.45], [1, 1, 0.5, 0]],
  87530. speed: 1,
  87531. //sphere
  87532. speedRange: 4,
  87533. radius: 0.1,
  87534. acceleration: 0.3,
  87535. accelerationRange: 1,
  87536. particleSpaceTime: 0,
  87537. strength: 4
  87538. });
  87539. }
  87540. }
  87541. addVideo() {
  87542. if (Potree.settings.number != 'SS-t-P6zBR73Gke') return;
  87543. var geo = new PlaneGeometry(1, 1, 1, 1);
  87544. var videoInfo = this.videoInfo = [{
  87545. id: '40-2',
  87546. url: 'https://laser-oss.4dkankan.com/testdata/SS-t-P6zBR73Gke/temp/poi/2022/05/10/0aabafee-36b8-455d-9c11-0780bf694786.mp4',
  87547. rotation: [-1.494468618954883, -1.4987317433158989, -3.061254983446741],
  87548. position: [19.801820617361624, 2.884673619844108, -0.03362305858221648],
  87549. scale: [3.5741423153151763, 2.8738725275578703, 1]
  87550. }, {
  87551. id: 40,
  87552. /* rotation:[-1.534692822378723, 0.01083403560862361, 3.141535283661569],
  87553. position:[17.2934294239949861, 2.413510747928117, -0.008057029580231356], */
  87554. url: 'https://laser-oss.4dkankan.com/testdata/SS-t-P6zBR73Gke/temp/poi/2022/05/09/7896d6ef-a2d6-4fd7-949c-768782a5b484.mp4',
  87555. rotation: [-1.5487684197910518, 0.021848470169552752, -3.1387534893955236],
  87556. position: [17.277316608096, 2.0840432922115846, -0.0931149415437065],
  87557. scale: [2.0821757723834047, 0.6129478480765236, 1],
  87558. visibles: [40]
  87559. }];
  87560. var add = info => {
  87561. var video = $("<video controls=\"controls\" loop autoplay x5-playsinline=\"\" webkit-playsinline=\"true\" playsinline=\"true\" controlslist=\"nodownload\"></video>")[0];
  87562. video.setAttribute("crossOrigin", 'Anonymous');
  87563. video.src = info.url || Potree.resourcePath + "/video/".concat(Potree.settings.number, "/").concat(info.id, ".mp4");
  87564. var map = new VideoTexture(video);
  87565. var plane = this.videoPlane = new Mesh(geo, new MeshBasicMaterial({
  87566. color: "#ffffff",
  87567. transparent: !0,
  87568. depthTest: false,
  87569. opacity: 0,
  87570. //side:2,
  87571. map
  87572. }));
  87573. plane.position.fromArray(info.position);
  87574. plane.rotation.fromArray(info.rotation);
  87575. info.scale && plane.scale.fromArray(info.scale);
  87576. this.scene.scene.add(plane);
  87577. info.plane = plane;
  87578. plane.boundingBox = new Box3(new Vector3(0, -0.5, 0), new Vector3(1, -0.4, 0.2));
  87579. video.addEventListener('loadeddata', function (e) {
  87580. video.play();
  87581. if (!info.visibles /* ||!viewer.images360.currentPano || info.visibles.includes(viewer.images360.currentPano.id) */) {
  87582. plane.material.opacity = 1;
  87583. }
  87584. info.scale || plane.scale.set(video.videoWidth / 1000, video.videoHeight / 1000, 1); // 1080 * 1920
  87585. console.log('video loadeddata', info.id);
  87586. });
  87587. if (info.visibles) {
  87588. this.images360.addEventListener('flyToPano', e => {
  87589. //飞之前
  87590. if (info.visibles.includes(e.toPano.pano.id)) {
  87591. //出现
  87592. setTimeout(() => {
  87593. plane.visible = true;
  87594. video.currentTime = 0;
  87595. video.play();
  87596. if (video.paused) {
  87597. var startPlay = () => {
  87598. plane.visible && video.play();
  87599. this.removeEventListener('global_mousedown', startPlay);
  87600. };
  87601. this.addEventListener('global_mousedown', startPlay);
  87602. }
  87603. Potree.settings.zoom.enabled = false;
  87604. transitions.start(lerp.property(plane.material, "opacity", 1), e.toPano.duration * 0.4, () => {}, 0, easing['easeInOutQuad']);
  87605. }, e.toPano.duration * 0.6); //时间上不能和消失的重叠 延迟
  87606. } else {
  87607. //消失
  87608. transitions.start(lerp.property(plane.material, "opacity", 0), e.toPano.duration * 0.4, () => {
  87609. if (!info) {
  87610. plane.visible = false;
  87611. video.pause();
  87612. Potree.settings.zoom.enabled = true;
  87613. }
  87614. }, 0, easing['easeInOutQuad']);
  87615. }
  87616. });
  87617. }
  87618. var startPlay = () => {
  87619. video.play();
  87620. //video.pause()
  87621. //video.currentTime = 0.1;
  87622. this.removeEventListener('global_mousedown', startPlay);
  87623. };
  87624. this.addEventListener('global_mousedown', startPlay);
  87625. Potree.settings.isTest && plane.addEventListener('select', e => {
  87626. console.log(e);
  87627. });
  87628. };
  87629. videoInfo.forEach(info => {
  87630. add(info);
  87631. });
  87632. /* this.images360.addEventListener('flyToPano' ,(e)=>{//飞之前
  87633. if(Potree.settings.displayMode != 'showPanos') return
  87634. let info = videoInfo[e.toPano.pano.id]
  87635. if(info ){ //出现
  87636. setTimeout(()=>{
  87637. plane.visible = true;
  87638. plane.position.fromArray(info.position)
  87639. plane.rotation.fromArray(info.rotation)
  87640. video.src = Potree.resourcePath+`/video/${Potree.settings.number}/${e.toPano.pano.id}.mp4`
  87641. video.play();
  87642. video.currentTime = 0
  87643. Potree.settings.zoom.enabled = false
  87644. transitions.start(lerp.property(plane.material, "opacity", 1 ) , e.toPano.duration*0.4 , ()=>{
  87645. }, 0, easing['easeInOutQuad'])
  87646. }, e.toPano.duration*0.6) //时间上不能和消失的重叠 延迟
  87647. }
  87648. //消失
  87649. transitions.start(lerp.property(plane.material, "opacity", 0, ) , e.toPano.duration*0.4, ()=>{
  87650. if(!info){
  87651. plane.visible = false
  87652. video.pause()
  87653. Potree.settings.zoom.enabled = true
  87654. }
  87655. }, 0, easing['easeInOutQuad'])
  87656. })
  87657. this.images360.addEventListener('endChangeMode',(e)=>{ //暂时不处理初始加载时就在有视频的点位上的情况
  87658. if(e.mode == 'showPanos'){
  87659. let info = videoInfo[this.images360.currentPano.id]
  87660. if(info ){ //出现
  87661. plane.visible = true;
  87662. plane.position.fromArray(info.position)
  87663. plane.rotation.fromArray(info.rotation)
  87664. plane.material.opacity = 0
  87665. video.src = Potree.resourcePath+`/video/${Potree.settings.number}/${this.images360.currentPano.id}.mp4`
  87666. video.play();
  87667. video.currentTime = 0
  87668. Potree.settings.zoom.enabled = false
  87669. transitions.start(lerp.property(plane.material, "opacity", 1, (e)=>{console.log('fadeIn',e)}) , 300 , ()=>{
  87670. }, 0, easing['easeInOutQuad'])
  87671. }
  87672. }else{
  87673. plane.visible = false;
  87674. Potree.settings.zoom.enabled = true
  87675. }
  87676. })
  87677. */
  87678. }
  87679. /* addTube(){//加水管 自动生成
  87680. if(Potree.settings.number == 't-8KbK1JjubE'){
  87681. let boundingBox = new THREE.Box3()
  87682. boundingBox.min.set(-1,-1,-1); boundingBox.max.set(1,1,1)
  87683. let radius = 0.08;
  87684. let radialSegments = 5
  87685. let radSegments = Math.PI*2 / radialSegments
  87686. var circlePts = [];//横截面
  87687. for(let i=0;i<radialSegments;i++){
  87688. let angle = radSegments * i;
  87689. circlePts.push(new THREE.Vector2(radius * Math.cos(angle), radius * Math.sin(angle) ))
  87690. }
  87691. var count = 0
  87692. var addMesh = (color, path, height)=>{//height:在path之上的高度,负数代表在path之下
  87693. var name = 'cylinder'+count
  87694. var mat = new THREE.MeshStandardMaterial({color, depthTest:false, roughness:0.4,metalness:0.5}) 
  87695. let linePath = path.map(e=>new THREE.Vector3().copy(e).setZ(e.z+height))
  87696. let geo = MeshDraw.getExtrudeGeo( circlePts, null,{ extrudePath:linePath, tension:0.2} )
  87697. var mesh = new THREE.Mesh(geo,mat);
  87698. mesh.name = name
  87699. window[name] = mesh
  87700. mesh.boundingBox = boundingBox
  87701. mesh.matrixAutoUpdate = false
  87702. mesh.matrix.copy(viewer.scene.pointclouds[0].transformMatrix)
  87703. mesh.matrixWorldNeedsUpdate = true
  87704. this.scene.scene.add(mesh);
  87705. count ++
  87706. }
  87707. let linePath, height
  87708. //地上管子 黄色
  87709. linePath = [{"x":-109.83,"y":-68.33,"z":-7.52},{"x":-95.17,"y":-59.3,"z":-7.38}, {"x":-38.75,"y":-24.01,"z":-6.01},{"x":0.5,"y":0.19,"z":-3.89},{"x":39.29,"y":24.41,"z":-1.31}
  87710. ,{"x":43.58,"y":27.7,"z":-0.97},{"x":40.22,"y":35.37,"z":-0.67}// 拐弯向右
  87711. , {"x":39.18,"y":36.71,"z":0.35},{"x":38.69,"y":36.04,"z":18.04} // 拐弯向上
  87712. ]
  87713. height = radius + 0.05;
  87714. addMesh('#b86', linePath, height)
  87715. //地下管子 藍色
  87716. linePath = [{"x":-108.24,"y":-70.61,"z":-7.52}, {"x":-57.8,"y":-39.31,"z":-6.72},{"x":-18.8,"y":-15.35,"z":-5.01},{"x":55.87,"y":31.67,"z":-0.04},{"x":110.53,"y":66.48,"z":5.14}
  87717. ]
  87718. height = -0.5;
  87719. addMesh('#48a', linePath, height)
  87720. }
  87721. } */
  87722. addTube(datas) {
  87723. var _this2 = this;
  87724. var _loop = function _loop() {
  87725. if (number == Potree.settings.number) {
  87726. var data = datas[number];
  87727. var boundingBox = new Box3();
  87728. boundingBox.min.set(-1, -1, -1);
  87729. boundingBox.max.set(1, 1, 1);
  87730. index = 0;
  87731. addMesh = function addMesh() {
  87732. var {
  87733. color,
  87734. path,
  87735. height,
  87736. fromDataset,
  87737. radius = 0.08,
  87738. datasetId = Potree.settings.originDatasetId,
  87739. spaceDis,
  87740. tension = 0.1,
  87741. visiEntity
  87742. } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  87743. //height:在path之上的高度,负数代表在path之下
  87744. var name = 'tube_' + index;
  87745. var radialSegments = 30; //THREE.Math.clamp( Math.round(radius * 800), 10, 40)
  87746. var radSegments = Math.PI * 2 / radialSegments;
  87747. var circlePts = []; //横截面
  87748. for (var i = 0; i < radialSegments; i++) {
  87749. var angle = radSegments * i;
  87750. circlePts.push(new Vector2(radius * Math.cos(angle), radius * Math.sin(angle)));
  87751. }
  87752. var mat = new MeshStandardMaterial({
  87753. color,
  87754. /* wireframe:true, depthTest:false,*/roughness: 0.9,
  87755. metalness: 0.3
  87756. });
  87757. var linePath = path.map(e => {
  87758. e instanceof Array && (e = new Vector3().fromArray(e));
  87759. var pos;
  87760. if (fromDataset) {
  87761. //获取:JSON.stringify(viewer.scene.measurements[0].dataset_points.map(e=>Potree.math.toPrecision(e.toArray(),3)))
  87762. pos = Potree.Utils.datasetPosTransform({
  87763. fromDataset: true,
  87764. position: e,
  87765. datasetId
  87766. });
  87767. } else {
  87768. pos = new Vector3().copy(e);
  87769. }
  87770. return pos.setZ(pos.z + height);
  87771. });
  87772. console.log(linePath);
  87773. var geo = MeshDraw.getExtrudeGeo(circlePts, null, {
  87774. extrudePath: linePath,
  87775. tension,
  87776. spaceDis
  87777. });
  87778. var mesh = new Mesh(geo, mat);
  87779. mesh.name = name;
  87780. window[name] = mesh;
  87781. mesh.boundingBox = boundingBox;
  87782. mesh.matrixAutoUpdate = false;
  87783. fromDataset || mesh.matrix.copy(viewer.scene.pointclouds[0].transformMatrix);
  87784. mesh.matrixWorldNeedsUpdate = true;
  87785. _this2.scene.scene.add(mesh);
  87786. if (visiEntity) {
  87787. _this2.modules.SiteModel.bus.addEventListener('buildingChange', e => {
  87788. Potree.Utils.updateVisible(mesh, 'isInEntity', e.entity && e.entity.name == visiEntity);
  87789. });
  87790. }
  87791. };
  87792. while (index < data.length) {
  87793. addMesh(data[index]);
  87794. index++;
  87795. }
  87796. }
  87797. },
  87798. index,
  87799. addMesh;
  87800. //加水管 自动生成
  87801. for (var number in datas) {
  87802. _loop();
  87803. }
  87804. /*
  87805. 可能用到的
  87806. viewer.scene.measurements.forEach(e=>e.edgeLabels.forEach(e=>Potree.Utils.updateVisible(e,'f',false)))
  87807. JSON.stringify(viewer.scene.measurements.find(e=>e.visible).dataset_points.map(e=>Potree.math.toPrecision(e.toArray(),3)))
  87808. */
  87809. }
  87810. addSprite(e) {
  87811. //api
  87812. var sprite;
  87813. if (e.text != void 0) {
  87814. sprite = new TextSprite(e);
  87815. } else {
  87816. var map = texLoader.load(src);
  87817. e.map = map;
  87818. sprite = new Sprite(e);
  87819. }
  87820. return sprite;
  87821. }
  87822. }
  87823. ;
  87824. //------ CLIP 默认clipTask都是clipInside ----------------------
  87825. /*
  87826. 并集相当于加法,交集相当于乘法。 所有结果都能展开成多个乘积相加。
  87827. 假设有4个clipBoxes,ABCD, 如果是 A*B + C*D ,那么这是最终结果。 如果是 (A+B)*(C+D) = A*C+A*D+B*C+B*D
  87828. */
  87829. /*
  87830. let Clips = {
  87831. boxes : [],
  87832. unionGroups : [], //二维数组。最外层要求并集,里层要求交集(如果只有一个元素就是本身)。总结起来就是要求一堆交集的并集
  87833. shaderParams:{},
  87834. needsUpdate : true,
  87835. addClip(box, clipMethod){
  87836. //不允许重复
  87837. if(this.boxes.includes(box)){
  87838. return console.warn('addClip重复添加了box',box)
  87839. }
  87840. boxes.push(box)
  87841. if(clipMethod == 'any'){//并
  87842. this.unionGroups.push([box])
  87843. }else if(clipMethod == 'all'){//交
  87844. this.unionGroups.forEach(mixGroup=>mixGroup.push(box))
  87845. }
  87846. this.needsUpdate = true
  87847. },
  87848. removeClip(box){
  87849. if(!this.boxes.includes(box)){
  87850. return console.warn('removeClip没有找到该box',box)
  87851. }
  87852. var newGroups = [];
  87853. this.unionGroups.forEach(mixGroup=>{
  87854. if(mixGroup.length == 1 && mixGroup[0] == box)return;//直接删除
  87855. newGroups.push(mixGroup.filter(e=>e!=box));
  87856. })
  87857. this.unionGroups = newGroups;
  87858. this.needsUpdate = true
  87859. }
  87860. ,
  87861. clearClip(){
  87862. this.boxes = [];
  87863. this.unionGroups = []
  87864. this.needsUpdate = true
  87865. }
  87866. ,
  87867. updateShaderParams(){//没写完 - - 见 pointcloud clip.vs
  87868. //uniform mat4 clipBoxes[num_clipboxes];
  87869. //uniform int clipBoxGroupCount;
  87870. //uniform int mixClipIndices[clipboxGroupItemCount]; //把所有的要求都直接放到数组内
  87871. //这里需要转为Float32Array..? 参考material.setClipBoxes
  87872. let everyClipGroupCount = this.unionGroups.map(e=>e.length)
  87873. let mixClipIndices = []
  87874. this.unionGroups.forEach(e=>{
  87875. mixClipIndices.push(...e)
  87876. })
  87877. this.shaderParams = {
  87878. num_clipboxes : this.boxes.length,
  87879. clipBoxGroupCount : this.unionGroups.length,
  87880. everyClipGroupCount,
  87881. clipBoxIndexCount: mixClipIndices.length,
  87882. mixClipIndices
  87883. }
  87884. }
  87885. ,
  87886. getShaderParams(){//每次要传递参数到shader中,执行这个就好
  87887. if(this.needsUpdate){
  87888. this.updateShaderParams()
  87889. }
  87890. return this.shaderParams
  87891. }
  87892. }
  87893. */
  87894. /**
  87895. * @author mschuetz / http://mschuetz.at
  87896. *
  87897. * adapted from THREE.OrbitControls by
  87898. *
  87899. * @author qiao / https://github.com/qiao
  87900. * @author mrdoob / http://mrdoob.com
  87901. * @author alteredq / http://alteredqualia.com/
  87902. * @author WestLangley / http://github.com/WestLangley
  87903. * @author erich666 / http://erichaines.com
  87904. *
  87905. *
  87906. *
  87907. */
  87908. class OrbitControls$2 extends EventDispatcher$1 {
  87909. constructor(viewer) {
  87910. super();
  87911. this.viewer = viewer;
  87912. this.renderer = viewer.renderer;
  87913. this.scene = null;
  87914. this.sceneControls = new Scene();
  87915. this.rotationSpeed = 5;
  87916. this.fadeFactor = 20;
  87917. this.yawDelta = 0;
  87918. this.pitchDelta = 0;
  87919. this.panDelta = new Vector2(0, 0);
  87920. this.radiusDelta = 0;
  87921. this.doubleClockZoomEnabled = true;
  87922. this.tweens = [];
  87923. var drag = e => {
  87924. if (e.drag.object !== null) {
  87925. return;
  87926. }
  87927. if (e.drag.startHandled === undefined) {
  87928. e.drag.startHandled = true;
  87929. this.dispatchEvent({
  87930. type: 'start'
  87931. });
  87932. }
  87933. var ndrag = {
  87934. x: e.drag.lastDrag.x / this.renderer.domElement.clientWidth,
  87935. y: e.drag.lastDrag.y / this.renderer.domElement.clientHeight
  87936. };
  87937. if (e.drag.mouse === MOUSE$1.LEFT) {
  87938. this.yawDelta += ndrag.x * this.rotationSpeed;
  87939. this.pitchDelta += ndrag.y * this.rotationSpeed;
  87940. this.stopTweens();
  87941. } else if (e.drag.mouse === MOUSE$1.RIGHT) {
  87942. this.panDelta.x += ndrag.x;
  87943. this.panDelta.y += ndrag.y;
  87944. this.stopTweens();
  87945. }
  87946. };
  87947. var drop = e => {
  87948. this.dispatchEvent({
  87949. type: 'end'
  87950. });
  87951. };
  87952. var scroll = e => {
  87953. var resolvedRadius = this.scene.view.radius + this.radiusDelta;
  87954. this.radiusDelta += -e.delta * resolvedRadius * 0.1;
  87955. this.stopTweens();
  87956. };
  87957. var dblclick = e => {
  87958. if (this.doubleClockZoomEnabled) {
  87959. this.zoomToLocation(e.mouse);
  87960. }
  87961. };
  87962. var previousTouch = null;
  87963. var touchStart = e => {
  87964. previousTouch = e;
  87965. };
  87966. var touchEnd = e => {
  87967. previousTouch = e;
  87968. };
  87969. var touchMove = e => {
  87970. if (e.touches.length === 2 && previousTouch.touches.length === 2) {
  87971. var prev = previousTouch;
  87972. var curr = e;
  87973. var prevDX = prev.touches[0].pageX - prev.touches[1].pageX;
  87974. var prevDY = prev.touches[0].pageY - prev.touches[1].pageY;
  87975. var prevDist = Math.sqrt(prevDX * prevDX + prevDY * prevDY);
  87976. var currDX = curr.touches[0].pageX - curr.touches[1].pageX;
  87977. var currDY = curr.touches[0].pageY - curr.touches[1].pageY;
  87978. var currDist = Math.sqrt(currDX * currDX + currDY * currDY);
  87979. var delta = currDist / prevDist;
  87980. var resolvedRadius = this.scene.view.radius + this.radiusDelta;
  87981. var newRadius = resolvedRadius / delta;
  87982. this.radiusDelta = newRadius - resolvedRadius;
  87983. this.stopTweens();
  87984. } else if (e.touches.length === 3 && previousTouch.touches.length === 3) {
  87985. var _prev = previousTouch;
  87986. var _curr = e;
  87987. var prevMeanX = (_prev.touches[0].pageX + _prev.touches[1].pageX + _prev.touches[2].pageX) / 3;
  87988. var prevMeanY = (_prev.touches[0].pageY + _prev.touches[1].pageY + _prev.touches[2].pageY) / 3;
  87989. var currMeanX = (_curr.touches[0].pageX + _curr.touches[1].pageX + _curr.touches[2].pageX) / 3;
  87990. var currMeanY = (_curr.touches[0].pageY + _curr.touches[1].pageY + _curr.touches[2].pageY) / 3;
  87991. var _delta = {
  87992. x: (currMeanX - prevMeanX) / this.renderer.domElement.clientWidth,
  87993. y: (currMeanY - prevMeanY) / this.renderer.domElement.clientHeight
  87994. };
  87995. this.panDelta.x += _delta.x;
  87996. this.panDelta.y += _delta.y;
  87997. this.stopTweens();
  87998. }
  87999. previousTouch = e;
  88000. };
  88001. this.addEventListener('touchstart', touchStart);
  88002. this.addEventListener('touchend', touchEnd);
  88003. this.addEventListener('touchmove', touchMove);
  88004. this.addEventListener('drag', drag);
  88005. this.addEventListener('drop', drop);
  88006. this.addEventListener('mousewheel', scroll);
  88007. this.addEventListener('dblclick', dblclick);
  88008. }
  88009. setScene(scene) {
  88010. this.scene = scene;
  88011. }
  88012. stop() {
  88013. this.yawDelta = 0;
  88014. this.pitchDelta = 0;
  88015. this.radiusDelta = 0;
  88016. this.panDelta.set(0, 0);
  88017. }
  88018. zoomToLocation(mouse) {
  88019. var camera = this.scene.getActiveCamera();
  88020. var I = Utils.getMousePointCloudIntersection(mouse, camera, this.viewer, this.scene.pointclouds, {
  88021. pickClipped: true
  88022. });
  88023. if (I === null) {
  88024. return;
  88025. }
  88026. var targetRadius = 0;
  88027. {
  88028. var minimumJumpDistance = 0.2;
  88029. var domElement = this.renderer.domElement;
  88030. var ray = Utils.mouseToRay(mouse, camera, domElement.clientWidth, domElement.clientHeight);
  88031. var nodes = I.pointcloud.nodesOnRay(I.pointcloud.visibleNodes, ray);
  88032. var lastNode = nodes[nodes.length - 1];
  88033. var radius = lastNode.getBoundingSphere(new Sphere()).radius;
  88034. targetRadius = Math.min(this.scene.view.radius, radius);
  88035. targetRadius = Math.max(minimumJumpDistance, targetRadius);
  88036. }
  88037. var d = this.scene.view.direction.multiplyScalar(-1);
  88038. var cameraTargetPosition = new Vector3().addVectors(I.location, d.multiplyScalar(targetRadius));
  88039. // TODO Unused: let controlsTargetPosition = I.location;
  88040. var animationDuration = 600;
  88041. var easing = TWEEN.Easing.Quartic.Out;
  88042. {
  88043. // animate
  88044. var value = {
  88045. x: 0
  88046. };
  88047. var tween = new TWEEN.Tween(value).to({
  88048. x: 1
  88049. }, animationDuration);
  88050. tween.easing(easing);
  88051. this.tweens.push(tween);
  88052. var startPos = this.scene.view.position.clone();
  88053. var targetPos = cameraTargetPosition.clone();
  88054. var startRadius = this.scene.view.radius;
  88055. var _targetRadius = cameraTargetPosition.distanceTo(I.location);
  88056. tween.onUpdate(() => {
  88057. var t = value.x;
  88058. this.scene.view.position.x = (1 - t) * startPos.x + t * targetPos.x;
  88059. this.scene.view.position.y = (1 - t) * startPos.y + t * targetPos.y;
  88060. this.scene.view.position.z = (1 - t) * startPos.z + t * targetPos.z;
  88061. this.scene.view.radius = (1 - t) * startRadius + t * _targetRadius;
  88062. this.viewer.setMoveSpeed(this.scene.view.radius);
  88063. });
  88064. tween.onComplete(() => {
  88065. this.tweens = this.tweens.filter(e => e !== tween);
  88066. });
  88067. tween.start();
  88068. }
  88069. }
  88070. stopTweens() {
  88071. this.tweens.forEach(e => e.stop());
  88072. this.tweens = [];
  88073. }
  88074. update(delta) {
  88075. var view = this.scene.view;
  88076. {
  88077. // apply rotation
  88078. var progression = Math.min(1, this.fadeFactor * delta);
  88079. var yaw = view.yaw;
  88080. var pitch = view.pitch;
  88081. var pivot = view.getPivot();
  88082. yaw -= progression * this.yawDelta;
  88083. pitch -= progression * this.pitchDelta;
  88084. view.yaw = yaw;
  88085. view.pitch = pitch;
  88086. var V = this.scene.view.direction.multiplyScalar(-view.radius);
  88087. var position = new Vector3().addVectors(pivot, V);
  88088. view.position.copy(position);
  88089. }
  88090. {
  88091. // apply pan
  88092. var _progression = Math.min(1, this.fadeFactor * delta);
  88093. var panDistance = _progression * view.radius * 3;
  88094. var px = -this.panDelta.x * panDistance;
  88095. var py = this.panDelta.y * panDistance;
  88096. view.pan(px, py);
  88097. }
  88098. {
  88099. // apply zoom
  88100. var _progression2 = Math.min(1, this.fadeFactor * delta);
  88101. // let radius = view.radius + progression * this.radiusDelta * view.radius * 0.1;
  88102. var radius = view.radius + _progression2 * this.radiusDelta;
  88103. var _V = view.direction.multiplyScalar(-radius);
  88104. var _position = new Vector3().addVectors(view.getPivot(), _V);
  88105. view.radius = radius;
  88106. view.position.copy(_position);
  88107. }
  88108. {
  88109. var speed = view.radius;
  88110. this.viewer.setMoveSpeed(speed);
  88111. }
  88112. {
  88113. // decelerate over time
  88114. var _progression3 = Math.min(1, this.fadeFactor * delta);
  88115. var attenuation = Math.max(0, 1 - this.fadeFactor * delta);
  88116. this.yawDelta *= attenuation;
  88117. this.pitchDelta *= attenuation;
  88118. this.panDelta.multiplyScalar(attenuation);
  88119. // this.radiusDelta *= attenuation;
  88120. this.radiusDelta -= _progression3 * this.radiusDelta;
  88121. }
  88122. }
  88123. }
  88124. ;
  88125. /**
  88126. * @author mschuetz / http://mschuetz.at
  88127. *
  88128. * adapted from THREE.OrbitControls by
  88129. *
  88130. * @author qiao / https://github.com/qiao
  88131. * @author mrdoob / http://mrdoob.com
  88132. * @author alteredq / http://alteredqualia.com/
  88133. * @author WestLangley / http://github.com/WestLangley
  88134. * @author erich666 / http://erichaines.com
  88135. *
  88136. *
  88137. *
  88138. */
  88139. class FirstPersonControls$1 extends EventDispatcher$1 {
  88140. //old
  88141. constructor(viewer) {
  88142. super();
  88143. this.viewer = viewer;
  88144. this.renderer = viewer.renderer;
  88145. this.scene = null;
  88146. this.sceneControls = new Scene();
  88147. this.rotationSpeed = 200;
  88148. this.moveSpeed = 10;
  88149. this.lockElevation = false;
  88150. this.keys = {
  88151. FORWARD: ['W'.charCodeAt(0), 38],
  88152. BACKWARD: ['S'.charCodeAt(0), 40],
  88153. LEFT: ['A'.charCodeAt(0), 37],
  88154. RIGHT: ['D'.charCodeAt(0), 39],
  88155. UP: ['R'.charCodeAt(0), 33],
  88156. DOWN: ['F'.charCodeAt(0), 34]
  88157. };
  88158. this.fadeFactor = 50;
  88159. this.yawDelta = 0;
  88160. this.pitchDelta = 0;
  88161. this.translationDelta = new Vector3(0, 0, 0);
  88162. this.translationWorldDelta = new Vector3(0, 0, 0);
  88163. this.tweens = [];
  88164. var drag = e => {
  88165. if (e.drag.object !== null) {
  88166. return;
  88167. }
  88168. if (e.drag.startHandled === undefined) {
  88169. e.drag.startHandled = true;
  88170. this.dispatchEvent({
  88171. type: 'start'
  88172. });
  88173. }
  88174. var moveSpeed = this.viewer.getMoveSpeed();
  88175. var ndrag = {
  88176. x: e.drag.lastDrag.x / this.renderer.domElement.clientWidth,
  88177. y: e.drag.lastDrag.y / this.renderer.domElement.clientHeight
  88178. };
  88179. if (e.drag.mouse === MOUSE$1.LEFT) {
  88180. this.yawDelta += ndrag.x * this.rotationSpeed;
  88181. this.pitchDelta += ndrag.y * this.rotationSpeed;
  88182. } else if (e.drag.mouse === MOUSE$1.RIGHT) {
  88183. this.translationDelta.x -= ndrag.x * moveSpeed * 100;
  88184. this.translationDelta.z += ndrag.y * moveSpeed * 100;
  88185. }
  88186. };
  88187. var drop = e => {
  88188. this.dispatchEvent({
  88189. type: 'end'
  88190. });
  88191. };
  88192. var scroll = e => {
  88193. var speed = this.viewer.getMoveSpeed();
  88194. if (e.delta < 0) {
  88195. speed = speed * 0.9;
  88196. } else if (e.delta > 0) {
  88197. speed = speed / 0.9;
  88198. }
  88199. speed = Math.max(speed, 0.1);
  88200. this.viewer.setMoveSpeed(speed);
  88201. };
  88202. var dblclick = e => {
  88203. this.zoomToLocation(e.mouse);
  88204. };
  88205. this.addEventListener('drag', drag);
  88206. this.addEventListener('drop', drop);
  88207. this.addEventListener('mousewheel', scroll);
  88208. this.addEventListener('dblclick', dblclick);
  88209. }
  88210. setScene(scene) {
  88211. this.scene = scene;
  88212. }
  88213. stop() {
  88214. this.yawDelta = 0;
  88215. this.pitchDelta = 0;
  88216. this.translationDelta.set(0, 0, 0);
  88217. }
  88218. zoomToLocation(mouse) {
  88219. var camera = this.scene.getActiveCamera();
  88220. var I = Utils.getMousePointCloudIntersection(mouse, camera, this.viewer, this.scene.pointclouds);
  88221. if (I === null) {
  88222. return;
  88223. }
  88224. var targetRadius = 0;
  88225. {
  88226. var minimumJumpDistance = 0.2;
  88227. var domElement = this.renderer.domElement;
  88228. var ray = Utils.mouseToRay(mouse, camera, domElement.clientWidth, domElement.clientHeight);
  88229. var nodes = I.pointcloud.nodesOnRay(I.pointcloud.visibleNodes, ray);
  88230. var lastNode = nodes[nodes.length - 1];
  88231. var radius = lastNode.getBoundingSphere(new Sphere()).radius;
  88232. targetRadius = Math.min(this.scene.view.radius, radius);
  88233. targetRadius = Math.max(minimumJumpDistance, targetRadius);
  88234. }
  88235. var d = this.scene.view.direction.multiplyScalar(-1);
  88236. var cameraTargetPosition = new Vector3().addVectors(I.location, d.multiplyScalar(targetRadius));
  88237. // TODO Unused: let controlsTargetPosition = I.location;
  88238. var animationDuration = 600;
  88239. var easing = TWEEN.Easing.Quartic.Out;
  88240. {
  88241. // animate
  88242. var value = {
  88243. x: 0
  88244. };
  88245. var tween = new TWEEN.Tween(value).to({
  88246. x: 1
  88247. }, animationDuration);
  88248. tween.easing(easing);
  88249. this.tweens.push(tween);
  88250. var startPos = this.scene.view.position.clone();
  88251. var targetPos = cameraTargetPosition.clone();
  88252. var startRadius = this.scene.view.radius;
  88253. var _targetRadius = cameraTargetPosition.distanceTo(I.location);
  88254. tween.onUpdate(() => {
  88255. var t = value.x;
  88256. this.scene.view.position.x = (1 - t) * startPos.x + t * targetPos.x;
  88257. this.scene.view.position.y = (1 - t) * startPos.y + t * targetPos.y;
  88258. this.scene.view.position.z = (1 - t) * startPos.z + t * targetPos.z;
  88259. this.scene.view.radius = (1 - t) * startRadius + t * _targetRadius;
  88260. this.viewer.setMoveSpeed(this.scene.view.radius / 2.5);
  88261. });
  88262. tween.onComplete(() => {
  88263. this.tweens = this.tweens.filter(e => e !== tween);
  88264. });
  88265. tween.start();
  88266. }
  88267. }
  88268. update(delta) {
  88269. var view = this.scene.view;
  88270. {
  88271. // cancel move animations on user input
  88272. var changes = [this.yawDelta, this.pitchDelta, this.translationDelta.length(), this.translationWorldDelta.length()];
  88273. var changeHappens = changes.some(e => Math.abs(e) > 0.001);
  88274. if (changeHappens && this.tweens.length > 0) {
  88275. this.tweens.forEach(e => e.stop());
  88276. this.tweens = [];
  88277. }
  88278. }
  88279. {
  88280. // accelerate while input is given
  88281. var ih = this.viewer.inputHandler;
  88282. var moveForward = this.keys.FORWARD.some(e => ih.pressedKeys[e]);
  88283. var moveBackward = this.keys.BACKWARD.some(e => ih.pressedKeys[e]);
  88284. var moveLeft = this.keys.LEFT.some(e => ih.pressedKeys[e]);
  88285. var moveRight = this.keys.RIGHT.some(e => ih.pressedKeys[e]);
  88286. var moveUp = this.keys.UP.some(e => ih.pressedKeys[e]);
  88287. var moveDown = this.keys.DOWN.some(e => ih.pressedKeys[e]);
  88288. if (this.lockElevation) {
  88289. var dir = view.direction;
  88290. dir.z = 0;
  88291. dir.normalize();
  88292. if (moveForward && moveBackward) {
  88293. this.translationWorldDelta.set(0, 0, 0);
  88294. } else if (moveForward) {
  88295. this.translationWorldDelta.copy(dir.multiplyScalar(this.viewer.getMoveSpeed()));
  88296. } else if (moveBackward) {
  88297. this.translationWorldDelta.copy(dir.multiplyScalar(-this.viewer.getMoveSpeed()));
  88298. }
  88299. } else {
  88300. if (moveForward && moveBackward) {
  88301. this.translationDelta.y = 0;
  88302. } else if (moveForward) {
  88303. this.translationDelta.y = this.viewer.getMoveSpeed();
  88304. } else if (moveBackward) {
  88305. this.translationDelta.y = -this.viewer.getMoveSpeed();
  88306. }
  88307. }
  88308. if (moveLeft && moveRight) {
  88309. this.translationDelta.x = 0;
  88310. } else if (moveLeft) {
  88311. this.translationDelta.x = -this.viewer.getMoveSpeed();
  88312. } else if (moveRight) {
  88313. this.translationDelta.x = this.viewer.getMoveSpeed();
  88314. }
  88315. if (moveUp && moveDown) {
  88316. this.translationWorldDelta.z = 0;
  88317. } else if (moveUp) {
  88318. this.translationWorldDelta.z = this.viewer.getMoveSpeed();
  88319. } else if (moveDown) {
  88320. this.translationWorldDelta.z = -this.viewer.getMoveSpeed();
  88321. }
  88322. }
  88323. {
  88324. // apply rotation
  88325. var yaw = view.yaw;
  88326. var pitch = view.pitch;
  88327. yaw -= this.yawDelta * delta;
  88328. pitch -= this.pitchDelta * delta;
  88329. view.yaw = yaw;
  88330. view.pitch = pitch;
  88331. }
  88332. {
  88333. // apply translation
  88334. view.translate(this.translationDelta.x * delta, this.translationDelta.y * delta, this.translationDelta.z * delta);
  88335. view.translateWorld(this.translationWorldDelta.x * delta, this.translationWorldDelta.y * delta, this.translationWorldDelta.z * delta);
  88336. }
  88337. {
  88338. // set view target according to speed
  88339. view.radius = 3 * this.viewer.getMoveSpeed();
  88340. }
  88341. {
  88342. // decelerate over time
  88343. var attenuation = Math.max(0, 1 - this.fadeFactor * delta);
  88344. this.yawDelta *= attenuation;
  88345. this.pitchDelta *= attenuation;
  88346. this.translationDelta.multiplyScalar(attenuation);
  88347. this.translationWorldDelta.multiplyScalar(attenuation);
  88348. }
  88349. }
  88350. }
  88351. ;
  88352. OrthographicCamera.prototype.zoomTo = function (node) {
  88353. var factor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
  88354. if (!node.geometry && !node.boundingBox) {
  88355. return;
  88356. }
  88357. // TODO
  88358. //let minWS = new THREE.Vector4(node.boundingBox.min.x, node.boundingBox.min.y, node.boundingBox.min.z, 1);
  88359. //let minVS = minWS.applyMatrix4(this.matrixWorldInverse);
  88360. //let right = node.boundingBox.max.x;
  88361. //let bottom = node.boundingBox.min.y;
  88362. //let top = node.boundingBox.max.y;
  88363. this.updateProjectionMatrix();
  88364. };
  88365. PerspectiveCamera.prototype.zoomTo = function (node, factor) {
  88366. if (!node.geometry && !node.boundingSphere && !node.boundingBox) {
  88367. return;
  88368. }
  88369. if (node.geometry && node.geometry.boundingSphere === null) {
  88370. node.geometry.computeBoundingSphere();
  88371. }
  88372. node.updateMatrixWorld();
  88373. var bs;
  88374. if (node.boundingSphere) {
  88375. bs = node.boundingSphere;
  88376. } else if (node.geometry && node.geometry.boundingSphere) {
  88377. bs = node.geometry.boundingSphere;
  88378. } else {
  88379. bs = node.boundingBox.getBoundingSphere(new Sphere());
  88380. }
  88381. var _factor = factor || 1;
  88382. bs = bs.clone().applyMatrix4(node.matrixWorld);
  88383. var radius = bs.radius;
  88384. var fovr = this.fov * Math.PI / 180;
  88385. if (this.aspect < 1) {
  88386. fovr = fovr * this.aspect;
  88387. }
  88388. var distanceFactor = Math.abs(radius / Math.sin(fovr / 2)) * _factor;
  88389. var offset = this.getWorldDirection(new Vector3()).multiplyScalar(-distanceFactor);
  88390. this.position.copy(bs.center.clone().add(offset));
  88391. };
  88392. Ray.prototype.distanceToPlaneWithNegative = function (plane) {
  88393. var denominator = plane.normal.dot(this.direction);
  88394. if (denominator === 0) {
  88395. // line is coplanar, return origin
  88396. if (plane.distanceToPoint(this.origin) === 0) {
  88397. return 0;
  88398. }
  88399. // Null is preferable to undefined since undefined means.... it is undefined
  88400. return null;
  88401. }
  88402. var t = -(this.origin.dot(plane.normal) + plane.constant) / denominator;
  88403. return t;
  88404. };
  88405. //export * from "./Potree_update_visibility.js"; //因加载顺序问题,该文件直接在shim中重写
  88406. var workerPool = new WorkerPool();
  88407. var version = {
  88408. major: 1,
  88409. minor: 8,
  88410. suffix: '.0'
  88411. };
  88412. var lru = new LRU();
  88413. console.log('Potree ' + version.major + '.' + version.minor + version.suffix);
  88414. var pointBudget = 1 * 1000 * 1000;
  88415. var framenumber = 0;
  88416. var numNodesLoading = 0;
  88417. var maxNodesLoading = 6; //4;
  88418. var debug = {};
  88419. exports.scriptPath = "";
  88420. if (document.currentScript && document.currentScript.src) {
  88421. exports.scriptPath = new URL(document.currentScript.src + '/..').href;
  88422. if (exports.scriptPath.slice(-1) === '/') {
  88423. exports.scriptPath = exports.scriptPath.slice(0, -1);
  88424. }
  88425. } else if (({ url: (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('potree.js', document.baseURI).href)) })) {
  88426. exports.scriptPath = new URL((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('potree.js', document.baseURI).href)) + "/..").href;
  88427. if (exports.scriptPath.slice(-1) === '/') {
  88428. exports.scriptPath = exports.scriptPath.slice(0, -1);
  88429. }
  88430. } else {
  88431. console.error('Potree was unable to find its script path using document.currentScript. Is Potree included with a script tag? Does your browser support this function?');
  88432. }
  88433. var resourcePath = exports.scriptPath + '/resources';
  88434. //add:
  88435. async function loadFile(path, params, callback, onError) {
  88436. params = params || {};
  88437. var fetchMethod = params.fetchMethod || 'get';
  88438. delete params.fetchMethod;
  88439. if (Potree.fileServer) {
  88440. Potree.fileServer[fetchMethod](path, {
  88441. params
  88442. }).then(data => {
  88443. if (data.data) data = data.data;
  88444. if (data.data) data = data.data; //融合页面getdataset需要查找两次data
  88445. callback && callback(data);
  88446. }).catch(onError);
  88447. } else {
  88448. try {
  88449. if (Object.keys(params).length > 0) {
  88450. path += '?';
  88451. var index = 0;
  88452. for (var i in params) {
  88453. if (index > 0) path += '&';
  88454. path += i;
  88455. path += '=';
  88456. path += params[i];
  88457. index++;
  88458. }
  88459. }
  88460. var info = {};
  88461. if (fetchMethod == 'post') info.method = 'POST';
  88462. var response = await fetch(path, info);
  88463. var text = await response.text();
  88464. var data = params.returnText ? text : JSON.parse(text);
  88465. if (data.data) data = data.data;
  88466. callback && callback(data);
  88467. return data;
  88468. } catch (e) {
  88469. console.log('loadFile出错', e);
  88470. onError && onError(e);
  88471. }
  88472. }
  88473. //查询: http://192.168.0.26:8080/doc.html#/default/filter-%E6%BC%AB%E6%B8%B8%E7%82%B9/filterUsingGET
  88474. }
  88475. async function loadDatasets(callback, sceneCode, onError, prefix) {
  88476. //之后直接把path写进来
  88477. var path;
  88478. sceneCode = sceneCode || Potree.settings.number;
  88479. if (Potree.fileServer) {
  88480. path = "/laser/dataset/".concat(sceneCode, "/getDataSet");
  88481. } else {
  88482. //path = `${Potree.settings.urls.prefix2}/indoor/${Potree.settings.number}/api/datasets`
  88483. //现在只能加载得了本地的了
  88484. path = "".concat(prefix || Potree.settings.urls.prefix, "/laser/dataset/").concat(sceneCode, "/getDataSet");
  88485. //path = `${Potree.scriptPath}/data/${sceneCode}/getDataSet.json`
  88486. }
  88487. return loadFile(path, null, callback, onError);
  88488. }
  88489. //目前上传平面图后如果不点击保存按钮,数据还是旧的不生效
  88490. async function loadMapEntity(datasetId, force) {
  88491. if (!Potree.settings.floorplanEnable && !force && Potree.fileServer) return; /* 等待平面图类型定义好会加载 */
  88492. var loaded = 0;
  88493. var needLoads = datasetId == 'all' ? viewer.scene.pointclouds.map(e => e.dataset_id) : [datasetId];
  88494. var callback = (dataset_id, floorplanType, data) => {
  88495. if (!data || data.length == 0) return console.log('平面图没有数据', dataset_id, floorplanType);
  88496. //要防止旧的比新的先获取到导致覆盖新的,因为两种type随时可能切换
  88497. if (floorplanType != Potree.settings.floorplanType[dataset_id]) return; //如果请求的floorplanType不是当前最新的floorplanType就返回
  88498. var map = viewer.mapViewer.mapLayer.maps.find(e => e.name == 'floorplan_' + dataset_id);
  88499. if (map) {
  88500. viewer.mapViewer.mapLayer.removeMap(map);
  88501. }
  88502. var mapNew = viewer.mapViewer.mapLayer.addMapEntity(data.data || data, dataset_id);
  88503. if (map) {
  88504. mapNew.visibleReasons = map.visibleReasons;
  88505. mapNew.unvisibleReasons = map.unvisibleReasons;
  88506. }
  88507. loaded++;
  88508. };
  88509. needLoads.forEach(dataset_id => {
  88510. var floorplanType = Potree.settings.floorplanType[dataset_id],
  88511. prefix = '';
  88512. if (!Potree.fileServer) {
  88513. prefix = Potree.settings.urls.prefix;
  88514. }
  88515. if (!floorplanType) return;
  88516. var path;
  88517. /* if(Potree.fileServer){
  88518. path = `/laser/tiledMap/${Potree.settings.number}/tiledMap/${floorplanType}/${dataset_id}`
  88519. }else{
  88520. path = `${Potree.settings.urls.prefix2}/indoor/${Potree.settings.number}/api/tiled_maps`
  88521. } */
  88522. path = "".concat(prefix, "/laser/tiledMap/").concat(Potree.settings.number, "/tiledMap/").concat(floorplanType, "/").concat(dataset_id);
  88523. Potree.settings.floorplanRequests[dataset_id] = true; //开始加载了
  88524. return loadFile(path, null, callback.bind(this, dataset_id, floorplanType));
  88525. });
  88526. }
  88527. async function loadPanos(datasetId, callback, number) {
  88528. var path;
  88529. //let query = `?datasetId=${datasetId}` //`?lat=${center.lat}&lon=${center.lon}&radius=200000`
  88530. if (Potree.fileServer) {
  88531. path = "/laser/filter/".concat(Potree.settings.number, "/query");
  88532. } else if (Potree.settings.mergeType2) {
  88533. //每个场景只加载初始数据集
  88534. path = "".concat(Potree.settings.urls.prefix, "/laser/filter/").concat(number, "/query");
  88535. } else {
  88536. //path = `${Potree.settings.urls.prefix2}/indoor/${Potree.settings.number}/api/images/filter` + query
  88537. //path = `${Potree.scriptPath}/data/${Potree.settings.number}/panos-${datasetId}.json`
  88538. path = "".concat(Potree.settings.urls.prefix, "/laser/filter/").concat(Potree.settings.number, "/query");
  88539. }
  88540. return loadFile(path, {
  88541. datasetId: datasetId
  88542. }, callback);
  88543. }
  88544. async function loadPanosInfo(callback) {
  88545. var path;
  88546. if (Potree.fileServer) {} else {
  88547. path = "".concat(Potree.scriptPath, "/data/panoEdit/vision_edit.txt");
  88548. }
  88549. return loadFile(path, null, callback);
  88550. }
  88551. function load4dkkPanos(sceneCode, model, done) {
  88552. //加载四维看看的漫游点并转换
  88553. model.is4dkkModel = true;
  88554. model.panos = [];
  88555. //模拟点云,需要rotX(90)+平移一段才能和四维看看的bound一样
  88556. var rot1M = new THREE.Matrix4();
  88557. var pos1 = new THREE.Vector3();
  88558. if (model.fileType == '3dTiles') {
  88559. pos1.fromArray(model.runtime.getTileset().tileset.root.boundingVolume.box.slice(0, 3)); //必须要平移一段才能重合
  88560. pos1.copy(Potree.math.convertVector.ZupToYup(pos1));
  88561. rot1M.makeRotationX(Math.PI / 2);
  88562. }
  88563. var pos1M = new THREE.Matrix4().setPosition(pos1);
  88564. model.posRot1MatrixInvert = new THREE.Matrix4().multiplyMatrices(pos1M, rot1M).invert();
  88565. model.rot1MatrixInvert = rot1M.clone().invert();
  88566. model.transformMatrix = new THREE.Matrix4();
  88567. model.rotateMatrix = new THREE.Matrix4();
  88568. model.datasetData = {
  88569. sceneVersion: 'V4'
  88570. };
  88571. model.sceneCode = sceneCode;
  88572. model.bound = new THREE.Box3();
  88573. var path = "https://4dkk.4dage.com/scene_view_data/".concat(sceneCode, "/images/vision.txt");
  88574. loadFile(path, {}, data => {
  88575. var panoData = data.sweepLocations.map(e => {
  88576. var qua = e.pose.rotation;
  88577. return {
  88578. file_id: e.uuid,
  88579. dataset_location: new THREE.Vector3().copy(e.pose.translation).toArray(),
  88580. dataset_floor_location: new THREE.Vector3().copy(e.puck).toArray(),
  88581. dataset_orientation: [qua.w, qua.x, qua.y, qua.z]
  88582. };
  88583. });
  88584. viewer.images360.addPanoData(panoData, model);
  88585. viewer.images360.loadDone();
  88586. viewer.scene.add360Images(viewer.images360);
  88587. {
  88588. //neighbourMap全部填满,否则之后会被修改
  88589. data.sweepLocations.forEach(pano1Data => {
  88590. var pano1 = model.panos.find(e => e.originID == pano1Data.uuid);
  88591. model.panos.forEach((pano2, i) => {
  88592. if (pano1 == pano2) return;
  88593. var v = pano1Data.visibles.includes(i);
  88594. viewer.images360.neighbourMap[pano1.id][pano2.id] = v;
  88595. viewer.images360.neighbourMap[pano2.id][pano1.id] = v;
  88596. if (v) {
  88597. pano1.neighbours.includes(pano2) || pano1.neighbours.push(pano2);
  88598. pano2.neighbours.includes(pano1) || pano2.neighbours.push(pano1);
  88599. }
  88600. });
  88601. });
  88602. }
  88603. viewer.modules.MergeEditor.modelTransformCallback(model, true); //初始化pano的pose
  88604. done();
  88605. });
  88606. /* neighbours: e.visibles3 || e.visibles,
  88607. noBlocks: e.visibles2,
  88608. seeMarkers: e.visibles, */
  88609. }
  88610. async function loadImgVersion(callback) {
  88611. var path;
  88612. //let query = `?datasetId=${datasetId}` //`?lat=${center.lat}&lon=${center.lon}&radius=200000`
  88613. /* if(Potree.fileServer){
  88614. path = `/laser/filter/${Potree.settings.number}/query`
  88615. }else{ */
  88616. path = "/laser/init/getSceneNumVersion/".concat(Potree.settings.number);
  88617. //api/laser/init
  88618. //}
  88619. return loadFile(path, {
  88620. fetchMethod: 'post'
  88621. }, callback, callback);
  88622. }
  88623. function setLonlat(lon, lat) {
  88624. var locationLonLat = [lon, lat];
  88625. if (window.AMapWith84) {
  88626. //需要转换为高德的,但该函数不准确,转入后再转出,和原来的有偏差. navvis的我看data中存的globalLocation直接输入到高德地图后的定位和其要展示的定位一致,而我们要转为高德后才一致,猜测是navvis后台转为了高德可用的经纬度。 若不转的话,其他看起来没问题,仅高德地图定位不准确,因其为被加密后的火星坐标系。
  88627. locationLonLat = AMapWith84.wgs84ToAMap({
  88628. x: lon,
  88629. y: lat
  88630. });
  88631. locationLonLat = [locationLonLat.x, locationLonLat.y];
  88632. }
  88633. proj4.defs("LOCAL", "+proj=tmerc +ellps=WGS84 +lon_0=" + locationLonLat[0].toPrecision(15) + " +lat_0=" + locationLonLat[1].toPrecision(15)); //高德坐标系
  88634. proj4.defs("LOCAL_MAP", "+proj=tmerc +ellps=WGS84 +lon_0=" + locationLonLat[0].toPrecision(15) + " +lat_0=" + locationLonLat[1].toPrecision(15)); //地图和本地一样
  88635. proj4.defs("WGS84", "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs");
  88636. var transform1 = proj4("WGS84", "LOCAL"); //这个ok 是展开的平面投影 LOCAL即NAVVIS:TMERC
  88637. var transform2 = proj4("+proj=tmerc +lat_0=0 +lon_0=123 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs;");
  88638. //注:转入后再转出,和原来的有偏差。如果输入是local坐标,数字越大偏差越大,当百万时就明显了。如果是lonlat,很奇怪经度小于50时就乱了。
  88639. viewer.transform = {
  88640. lonlatToLocal: transform1,
  88641. lonlatTo4550: transform2 // 转大地坐标EPSG:4550
  88642. };
  88643. if (window.AMapWith84 && Potree.settings.mapCompany != 'google') {
  88644. //需要转换, 因本地高德用的lonlat和数据里的84不一样. (google地图在国内也用的高德,国外84)
  88645. var change = transform => {
  88646. var forward = transform.forward;
  88647. var inverse = transform.inverse;
  88648. transform.forward = function (e, not84) {
  88649. var needTran = e.x == void 0;
  88650. if (needTran) var a1 = {
  88651. x: e[0],
  88652. y: e[1]
  88653. };else var a1 = e;
  88654. var a = not84 ? a1 : AMapWith84.wgs84ToAMap(a1);
  88655. if (needTran) {
  88656. a = [a.x, a.y];
  88657. e[2] != void 0 && (a[2] = e[2]);
  88658. } else {
  88659. e.z != void 0 && (a.z = e.z);
  88660. }
  88661. return forward(a);
  88662. };
  88663. transform.inverse = function (e, not84) {
  88664. var needTran = e.x == void 0;
  88665. var a = inverse(e);
  88666. needTran && (a = {
  88667. x: a[0],
  88668. y: a[1]
  88669. });
  88670. a = not84 ? a : AMapWith84.aMapToWgs84(a);
  88671. if (needTran) {
  88672. a = [a.x, a.y];
  88673. e[2] != void 0 && (a[2] = e[2]);
  88674. } else {
  88675. e.z != void 0 && (a.z = e.z);
  88676. }
  88677. return a;
  88678. };
  88679. };
  88680. for (var f in viewer.transform) {
  88681. change(viewer.transform[f]);
  88682. }
  88683. }
  88684. }
  88685. //site_model
  88686. /* {
  88687. "area": 2503.30551910935,
  88688. "attributes": {},
  88689. "center": [
  88690. 113.59568277455075,
  88691. 22.366566635195288,
  88692. 12.78751625
  88693. ],
  88694. "children": [],
  88695. "geometry_hash": 1891071345,
  88696. "id": 10,
  88697. "name": "港湾一号",
  88698. "parentId": null,
  88699. "polygon": {
  88700. "coordinates": [
  88701. [
  88702. [
  88703. 113.59590810534583,
  88704. 22.36679132753878
  88705. ],
  88706. [
  88707. 113.59590810534583,
  88708. 22.366807172528629
  88709. ],
  88710. [
  88711. 113.59545610274934,
  88712. 22.366807172528629
  88713. ],
  88714. [
  88715. 113.59545610274934,
  88716. 22.36679132753878
  88717. ]
  88718. ]
  88719. ],
  88720. "type": "Polygon"
  88721. },
  88722. "type": "BUILDING",
  88723. "volume": null,
  88724. "z_max": null,
  88725. "z_min": null
  88726. }
  88727. */
  88728. function Log$1() {
  88729. var args = Array.from(arguments);
  88730. var params = args[args.length - 1];
  88731. if (params && params.font) {
  88732. params = params.font, args.pop();
  88733. } else params = {};
  88734. var str = '',
  88735. color = params.color || '#13f',
  88736. fontSize = params.fontSize || 12;
  88737. args.forEach((e, i) => {
  88738. i > 0 && (str += ' , ');
  88739. /* if(params.toFixed && typeof e == 'number'){
  88740. e = e.toFixed(params.toFixed)
  88741. } */
  88742. if (params.toFixed) {
  88743. e = Potree.math.toPrecision(e, params.toFixed);
  88744. }
  88745. str += e; //object可以JSON.stringify,但不是所有都行
  88746. });
  88747. console.warn("%c".concat(str), "color:".concat(color, ";font-size:").concat(fontSize, "px"));
  88748. }
  88749. function loadPointCloud$1(path, name, sceneCode, timeStamp, callback, onError) {
  88750. var loaded = function loaded(e) {
  88751. e.pointcloud.name = name;
  88752. e.pointcloud.sceneCode = sceneCode; //对应4dkk的场景码
  88753. callback(e);
  88754. };
  88755. var promise = new Promise(resolve => {
  88756. // load pointcloud
  88757. if (!path) {
  88758. // TODO: callback? comment? Hello? Bueller? Anyone?
  88759. } else if (path.indexOf('ept.json') > 0) {
  88760. EptLoader.load(path, function (geometry) {
  88761. if (!geometry) {
  88762. console.error(new Error("failed to load point cloud from URL: ".concat(path)));
  88763. } else {
  88764. var pointcloud = new ExtendPointCloudOctree(geometry);
  88765. //loaded(pointcloud);
  88766. resolve({
  88767. type: 'pointcloud_loaded',
  88768. pointcloud: pointcloud
  88769. });
  88770. }
  88771. });
  88772. } else if (path.indexOf('cloud.js') > 0) {
  88773. POCLoader.load(path, timeStamp, function (geometry) {
  88774. if (!geometry) {
  88775. //callback({type: 'loading_failed'});
  88776. console.error(new Error("failed to load point cloud from URL: ".concat(path)));
  88777. onError && onError();
  88778. } else {
  88779. var pointcloud = new ExtendPointCloudOctree(geometry);
  88780. // loaded(pointcloud);
  88781. resolve({
  88782. type: 'pointcloud_loaded',
  88783. pointcloud: pointcloud
  88784. });
  88785. }
  88786. });
  88787. } /* else if (path.indexOf('metadata.json') > 0) { //部分浏览器(如uc)不支持NodeLoader中的1n的大数据写法
  88788. Potree.OctreeLoader.load(path).then(e => {
  88789. let geometry = e.geometry;
  88790. if(!geometry){
  88791. console.error(new Error(`failed to load point cloud from URL: ${path}`));
  88792. }else{
  88793. let pointcloud = new ExtendPointCloudOctree(geometry);
  88794. let aPosition = pointcloud.getAttribute("position");
  88795. let material = pointcloud.material;
  88796. material.elevationRange = [
  88797. aPosition.range[0][2],
  88798. aPosition.range[1][2],
  88799. ];
  88800. // loaded(pointcloud);
  88801. resolve({type: 'pointcloud_loaded', pointcloud: pointcloud});
  88802. }
  88803. });
  88804. OctreeLoader.load(path, function (geometry) {
  88805. if (!geometry) {
  88806. //callback({type: 'loading_failed'});
  88807. console.error(new Error(`failed to load point cloud from URL: ${path}`));
  88808. } else {
  88809. let pointcloud = new ExtendPointCloudOctree(geometry);
  88810. // loaded(pointcloud);
  88811. resolve({type: 'pointcloud_loaded', pointcloud: pointcloud});
  88812. }
  88813. });
  88814. } */else if (path.indexOf('.vpc') > 0) {
  88815. PointCloudArena4DGeometry.load(path, function (geometry) {
  88816. if (!geometry) {
  88817. //callback({type: 'loading_failed'});
  88818. console.error(new Error("failed to load point cloud from URL: ".concat(path)));
  88819. } else {
  88820. var pointcloud = new PointCloudArena4D(geometry);
  88821. // loaded(pointcloud);
  88822. resolve({
  88823. type: 'pointcloud_loaded',
  88824. pointcloud: pointcloud
  88825. });
  88826. }
  88827. });
  88828. } else {
  88829. //callback({'type': 'loading_failed'});
  88830. console.error(new Error("failed to load point cloud from URL: ".concat(path)));
  88831. }
  88832. });
  88833. if (callback) {
  88834. promise.then(pointcloud => {
  88835. loaded(pointcloud);
  88836. });
  88837. } else {
  88838. return promise;
  88839. }
  88840. }
  88841. ;
  88842. // add selectgroup
  88843. (function ($) {
  88844. $.fn.extend({
  88845. selectgroup: function selectgroup() {
  88846. var args = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  88847. var elGroup = $(this);
  88848. var rootID = elGroup.prop("id");
  88849. var groupID = "".concat(rootID);
  88850. var groupTitle = args.title !== undefined ? args.title : "";
  88851. var elButtons = [];
  88852. elGroup.find("option").each((index, value) => {
  88853. var buttonID = $(value).prop("id");
  88854. var label = $(value).html();
  88855. var optionValue = $(value).prop("value");
  88856. var elButton = $("\n\t\t\t\t\t<span style=\"flex-grow: 1; display: inherit\">\n\t\t\t\t\t<label for=\"".concat(buttonID, "\" class=\"ui-button\" style=\"width: 100%; padding: .4em .1em\">").concat(label, "</label>\n\t\t\t\t\t<input type=\"radio\" name=\"").concat(groupID, "\" id=\"").concat(buttonID, "\" value=\"").concat(optionValue, "\" style=\"display: none\"/>\n\t\t\t\t\t</span>\n\t\t\t\t"));
  88857. var elLabel = elButton.find("label");
  88858. var elInput = elButton.find("input");
  88859. elInput.change(() => {
  88860. elGroup.find("label").removeClass("ui-state-active");
  88861. elGroup.find("label").addClass("ui-state-default");
  88862. if (elInput.is(":checked")) {
  88863. elLabel.addClass("ui-state-active");
  88864. } else {
  88865. //elLabel.addClass("ui-state-default");
  88866. }
  88867. });
  88868. elButtons.push(elButton);
  88869. });
  88870. var elFieldset = $("\n\t\t\t\t<fieldset style=\"border: none; margin: 0px; padding: 0px\">\n\t\t\t\t\t<legend>".concat(groupTitle, "</legend>\n\t\t\t\t\t<span style=\"display: flex\">\n\n\t\t\t\t\t</span>\n\t\t\t\t</fieldset>\n\t\t\t"));
  88871. var elButtonContainer = elFieldset.find("span");
  88872. for (var elButton of elButtons) {
  88873. elButtonContainer.append(elButton);
  88874. }
  88875. elButtonContainer.find("label").each((index, value) => {
  88876. $(value).css("margin", "0px");
  88877. $(value).css("border-radius", "0px");
  88878. $(value).css("border", "1px solid black");
  88879. $(value).css("border-left", "none");
  88880. });
  88881. elButtonContainer.find("label:first").each((index, value) => {
  88882. $(value).css("border-radius", "4px 0px 0px 4px");
  88883. });
  88884. elButtonContainer.find("label:last").each((index, value) => {
  88885. $(value).css("border-radius", "0px 4px 4px 0px");
  88886. $(value).css("border-left", "none");
  88887. });
  88888. elGroup.empty();
  88889. elGroup.append(elFieldset);
  88890. }
  88891. });
  88892. })(jQuery);
  88893. //在这之后export的内容才赋值到Potree中
  88894. exports.Action = Action;
  88895. exports.Annotation = Annotation;
  88896. exports.Box3Helper = Box3Helper$1;
  88897. exports.BoxVolume = BoxVolume$1;
  88898. exports.CameraAnimation = CameraAnimation$1;
  88899. exports.CameraMode = CameraMode;
  88900. exports.ClassificationScheme = ClassificationScheme;
  88901. exports.ClipMethod = ClipMethod;
  88902. exports.ClipTask = ClipTask;
  88903. exports.ClipVolume = ClipVolume;
  88904. exports.ClippingTool = ClippingTool;
  88905. exports.ElevationGradientRepeat = ElevationGradientRepeat;
  88906. exports.Enum = Enum;
  88907. exports.EnumItem = EnumItem;
  88908. exports.EptBinaryLoader = EptBinaryLoader;
  88909. exports.EptKey = EptKey;
  88910. exports.EptLaszipLoader = EptLaszipLoader;
  88911. exports.EptLazBatcher = EptLazBatcher;
  88912. exports.EptLoader = EptLoader;
  88913. exports.EptZstandardLoader = EptZstandardLoader;
  88914. exports.EventDispatcher = EventDispatcher$1;
  88915. exports.ExtendPointCloudMaterial = ExtendPointCloudMaterial;
  88916. exports.ExtendPointCloudOctree = ExtendPointCloudOctree;
  88917. exports.ExtendScene = ExtendScene;
  88918. exports.EyeDomeLightingMaterial = EyeDomeLightingMaterial;
  88919. exports.Features = Features;
  88920. exports.FirstPersonControls = FirstPersonControls$1;
  88921. exports.GeoPackageLoader = GeoPackageLoader;
  88922. exports.Geopackage = Geopackage$1;
  88923. exports.Gradients = Gradients;
  88924. exports.HierarchicalSlider = HierarchicalSlider;
  88925. exports.Images360 = Images360;
  88926. exports.KeyCodes = KeyCodes;
  88927. exports.LRU = LRU;
  88928. exports.LRUItem = LRUItem;
  88929. exports.LengthUnits = LengthUnits;
  88930. exports.LineDraw = LineDraw;
  88931. exports.Log = Log$1;
  88932. exports.MOUSE = MOUSE$1;
  88933. exports.MapViewer = MapViewer;
  88934. exports.Measure = Measure$1;
  88935. exports.MeasuringTool = MeasuringTool;
  88936. exports.MeshDraw = MeshDraw;
  88937. exports.Message = Message;
  88938. exports.NodeLoader = NodeLoader;
  88939. exports.NormalizationEDLMaterial = NormalizationEDLMaterial;
  88940. exports.NormalizationMaterial = NormalizationMaterial;
  88941. exports.OctreeLoader = OctreeLoader;
  88942. exports.OrbitControls = OrbitControls$2;
  88943. exports.OrientedImage = OrientedImage;
  88944. exports.OrientedImageLoader = OrientedImageLoader;
  88945. exports.OrientedImages = OrientedImages;
  88946. exports.POCLoader = POCLoader;
  88947. exports.PointAttribute = PointAttribute;
  88948. exports.PointAttributeTypes = PointAttributeTypes;
  88949. exports.PointAttributes = PointAttributes;
  88950. exports.PointCloudEptGeometry = PointCloudEptGeometry;
  88951. exports.PointCloudEptGeometryNode = PointCloudEptGeometryNode;
  88952. exports.PointCloudOctreeGeometry = PointCloudOctreeGeometry;
  88953. exports.PointCloudOctreeGeometryNode = PointCloudOctreeGeometryNode;
  88954. exports.PointCloudSM = PointCloudSM;
  88955. exports.PointCloudTree = PointCloudTree;
  88956. exports.PointCloudTreeNode = PointCloudTreeNode;
  88957. exports.PointShape = PointShape$1;
  88958. exports.PointSizeType = PointSizeType;
  88959. exports.Points = Points$1;
  88960. exports.PolygonClipVolume = PolygonClipVolume;
  88961. exports.Profile = Profile;
  88962. exports.ProfileData = ProfileData;
  88963. exports.ProfileRequest = ProfileRequest;
  88964. exports.ProfileTool = ProfileTool;
  88965. exports.Renderer = Renderer;
  88966. exports.ScreenBoxSelectTool = ScreenBoxSelectTool;
  88967. exports.ShapefileLoader = ShapefileLoader;
  88968. exports.SphereVolume = SphereVolume$2;
  88969. exports.SpotLightHelper = SpotLightHelper$1;
  88970. exports.TextSprite = TextSprite$2;
  88971. exports.TransformationTool = TransformationTool;
  88972. exports.TreeType = TreeType;
  88973. exports.Utils = Utils;
  88974. exports.Version = Version;
  88975. exports.Viewer = Viewer$1;
  88976. exports.Volume = Volume$1;
  88977. exports.VolumeTool = VolumeTool;
  88978. exports.WorkerPool = WorkerPool;
  88979. exports.XHRFactory = XHRFactory;
  88980. exports.config = config$1;
  88981. exports.debug = debug;
  88982. exports.framenumber = framenumber;
  88983. exports.load4dkkPanos = load4dkkPanos;
  88984. exports.loadDatasets = loadDatasets;
  88985. exports.loadFile = loadFile;
  88986. exports.loadImgVersion = loadImgVersion;
  88987. exports.loadMapEntity = loadMapEntity;
  88988. exports.loadPanos = loadPanos;
  88989. exports.loadPanosInfo = loadPanosInfo;
  88990. exports.loadPointCloud = loadPointCloud$1;
  88991. exports.loadProject = loadProject;
  88992. exports.lru = lru;
  88993. exports.maxNodesLoading = maxNodesLoading;
  88994. exports.mergeEditStart = mergeEditStart;
  88995. exports.numNodesLoading = numNodesLoading;
  88996. exports.panoEditStart = panoEditStart;
  88997. exports.pointBudget = pointBudget;
  88998. exports.resourcePath = resourcePath;
  88999. exports.saveProject = saveProject;
  89000. exports.setLonlat = setLonlat;
  89001. exports.settings = settings;
  89002. exports.start = start;
  89003. exports.version = version;
  89004. exports.workerPool = workerPool;
  89005. Object.defineProperty(exports, '__esModule', { value: true });
  89006. })));
  89007. //# sourceMappingURL=potree.js.map